libMesh
Loading...
Searching...
No Matches
Functions
introduction_ex1.C File Reference

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 39 of file introduction_ex1.C.

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 libmesh_error_msg_if(argc < 4, "Usage: " << argv[0] << " -d 2 in.mesh [-o out.mesh]");
54
55 // Get the dimensionality of the mesh from the "-d" argument
56 const unsigned int dim =
58 libmesh_error_msg_if(dim > 3, "Usage: " << argv[0] << " -d 2 in.mesh [-o out.mesh]");
59
60 // Skip higher-dimensional examples on a lower-dimensional libMesh build
61 libmesh_example_requires(dim <= LIBMESH_DIM, "2D/3D support");
62
63 // Create a mesh, with dimension to be overridden later, on the
64 // default MPI communicator.
65 Mesh mesh(init.comm());
66
67 // We may need XDR support compiled in to read binary .xdr files
68 const std::string input_filename = argv[3];
69#ifndef LIBMESH_HAVE_XDR
70 libmesh_example_requires(input_filename.rfind(".xdr") >=
71 input_filename.size(), "XDR support");
72#endif
73
74 // Read the input mesh.
75 mesh.read (input_filename);
76
77 // Print information about the mesh to the screen.
79
80 // Write the output mesh if the user specified an
81 // output file name.
83 {
84 // We may need XDR support compiled in to read binary .xdr files
85 const std::string output_filename =
86 libMesh::command_line_next("-o",std::string());
87#ifndef LIBMESH_HAVE_XDR
88 libmesh_example_requires(output_filename.rfind(".xdr") >=
89 output_filename.size(), "XDR support");
90#endif
91
92 mesh.write (output_filename);
93 }
94
95 // All done. libMesh objects are destroyed here. Because the
96 // LibMeshInit object was created first, its destruction occurs
97 // last, and it's destructor finalizes any external libraries and
98 // checks for leaked memory.
99 return 0;
100}
unsigned int dim
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition libmesh.h:92
virtual void write(const std::string &name) const =0
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false, bool skip_detect_interior_parents=false)=0
Interfaces for reading/writing a mesh to/from a file.
void print_info(std::ostream &os=libMesh::out, const unsigned int verbosity=0, const bool global=true) const
Prints relevant information about the mesh.
Definition mesh_base.C:1755
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition mesh.h:51
MeshBase & mesh
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
Definition libmesh.h:303
T command_line_next(std::string name, T default_value)
Use GetPot's search()/next() functions to get following arguments from the command line.
Definition libmesh.C:1025
bool on_command_line(std::string arg)
Definition libmesh.C:934

References libMesh::command_line_next(), dim, libMesh::invalid_uint, main(), mesh, libMesh::on_command_line(), libMesh::MeshBase::print_info(), libMesh::MeshBase::read(), and libMesh::MeshBase::write().