libMesh
Functions
introduction_ex1.C File Reference

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 39 of file introduction_ex1.C.

References libMesh::LibMeshInit::comm(), dim, libMesh::TriangleWrapper::init(), mesh, libMesh::MeshBase::print_info(), libMesh::MeshBase::read(), and libMesh::MeshBase::write().

40 {
41  // Initialize the library. This is necessary because the library
42  // may depend on a number of other libraries (i.e. MPI and PETSc)
43  // that require initialization before use. When the LibMeshInit
44  // object goes out of scope, other libraries and resources are
45  // finalized.
46  LibMeshInit init (argc, argv);
47 
48  // Check for proper usage. The program is designed to be run
49  // as follows:
50  // ./ex1 -d DIM input_mesh_name [-o output_mesh_name]
51  // where [output_mesh_name] is an optional parameter giving
52  // a filename to write the mesh into.
53  if (argc < 4)
54  {
55  // This handy function will print the file name, line number,
56  // specified message, and then throw an exception.
57  libmesh_error_msg("Usage: " << argv[0] << " -d 2 in.mesh [-o out.mesh]");
58  }
59 
60  // Get the dimensionality of the mesh from argv[2]
61  const unsigned int dim = std::atoi(argv[2]);
62 
63  // Skip higher-dimensional examples on a lower-dimensional libMesh build
64  libmesh_example_requires(dim <= LIBMESH_DIM, "2D/3D support");
65 
66  // Create a mesh, with dimension to be overridden later, on the
67  // default MPI communicator.
68  Mesh mesh(init.comm());
69 
70  // We may need XDR support compiled in to read binary .xdr files
71  std::string input_filename = argv[3];
72 #ifndef LIBMESH_HAVE_XDR
73  libmesh_example_requires(input_filename.rfind(".xdr") >=
74  input_filename.size(), "XDR support");
75 #endif
76 
77  // Read the input mesh.
78  mesh.read (argv[3]);
79 
80  // Print information about the mesh to the screen.
81  mesh.print_info();
82 
83  // Write the output mesh if the user specified an
84  // output file name.
85  if (argc >= 6 && std::string("-o") == argv[4])
86  {
87  // We may need XDR support compiled in to read binary .xdr files
88  std::string output_filename = argv[5];
89 #ifndef LIBMESH_HAVE_XDR
90  libmesh_example_requires(output_filename.rfind(".xdr") >=
91  output_filename.size(), "XDR support");
92 #endif
93 
94  mesh.write (argv[5]);
95  }
96 
97  // All done. libMesh objects are destroyed here. Because the
98  // LibMeshInit object was created first, its destruction occurs
99  // last, and it's destructor finalizes any external libraries and
100  // checks for leaked memory.
101  return 0;
102 }
unsigned int dim
MeshBase & mesh
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:62
void init(triangulateio &t)
Initializes the fields of t to NULL/0 as necessary.
virtual void write(const std::string &name)=0
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
virtual void read(const std::string &name, void *mesh_data=libmesh_nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false)=0
Interfaces for reading/writing a mesh to/from a file.
void print_info(std::ostream &os=libMesh::out) const
Prints relevant information about the mesh.
Definition: mesh_base.C:448