libMesh
Functions
introduction_ex2.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 69 of file introduction_ex2.C.

70 {
71  LibMeshInit init (argc, argv);
72 
73  // Skip this 2D example if libMesh was compiled as 1D-only.
74  libmesh_example_requires(2 <= LIBMESH_DIM, "2D support");
75 
76  // This example requires a linear solver package.
77  libmesh_example_requires(libMesh::default_solver_package() != INVALID_SOLVER_PACKAGE,
78  "--enable-petsc, --enable-trilinos, or --enable-eigen");
79 
80  // A brief message to the user to inform her of the
81  // exact name of the program being run, and its command line.
82  libMesh::out << "Running " << argv[0];
83  for (int i=1; i<argc; i++)
84  libMesh::out << " " << argv[i];
85  libMesh::out << std::endl << std::endl;
86 
87  // Create a mesh, with dimension to be overridden later, distributed
88  // across the default MPI communicator.
89  Mesh mesh(init.comm());
90 
91  // Use the MeshTools::Generation mesh generator to create a uniform
92  // 2D grid on the unit square. By default a mesh of QUAD4
93  // elements will be created. We instruct the mesh generator
94  // to build a mesh of 5x5 elements.
96 
97  // Create an equation systems object. This object can
98  // contain multiple systems of different
99  // flavors for solving loosely coupled physics. Each system can
100  // contain multiple variables of different approximation orders.
101  // Here we will simply create a single system with one variable.
102  // Later on, other flavors of systems will be introduced. For the
103  // moment, we use the general system.
104  // The EquationSystems object needs a reference to the mesh
105  // object, so the order of construction here is important.
106  EquationSystems equation_systems (mesh);
107 
108  // Add a flag "test" that is visible for all systems. This
109  // helps in inter-system communication.
110  equation_systems.parameters.set<bool> ("test") = true;
111 
112  // Set a simulation-specific parameter visible for all systems.
113  // This helps in inter-system-communication.
114  equation_systems.parameters.set<Real> ("dummy") = 42.;
115 
116  // Set another simulation-specific parameter
117  equation_systems.parameters.set<Real> ("nobody") = 0.;
118 
119  // Now we declare the system and its variables.
120  // We begin by adding a "TransientLinearImplicitSystem" to the
121  // EquationSystems object, and we give it the name
122  // "Simple System".
123  equation_systems.add_system<TransientLinearImplicitSystem> ("Simple System");
124 
125  // Adds the variable "u" to "Simple System". "u"
126  // will be approximated using first-order approximation.
127  equation_systems.get_system("Simple System").add_variable("u", FIRST);
128 
129  // Next we'll by add an "ExplicitSystem" to the
130  // EquationSystems object, and we give it the name
131  // "Complex System".
132  equation_systems.add_system<ExplicitSystem> ("Complex System");
133 
134  // Give "Complex System" three variables -- each with a different approximation
135  // order. Variables "c" and "T" will use first-order Lagrange approximation,
136  // while variable "dv" will use a second-order discontinuous
137  // approximation space.
138  equation_systems.get_system("Complex System").add_variable("c", FIRST);
139  equation_systems.get_system("Complex System").add_variable("T", FIRST);
140  equation_systems.get_system("Complex System").add_variable("dv", SECOND, MONOMIAL);
141 
142  // Initialize the data structures for the equation system.
143  equation_systems.init();
144 
145  // Print information about the mesh to the screen.
146  mesh.print_info();
147  // Prints information about the system to the screen.
148  equation_systems.print_info();
149 
150  // Write the equation system if the user specified an
151  // output file name. Note that there are two possible
152  // formats to write to. Specifying WRITE will
153  // create a formatted ASCII file. Optionally, you can specify
154  // ENCODE and get an XDR-encoded binary file.
155  //
156  // We will write the data, clear the object, and read the file
157  // we just wrote. This is simply to demonstrate capability.
158  // Note that you might use this in an application to periodically
159  // dump the state of your simulation. You can then restart from
160  // this data later.
161  if (argc > 1)
162  if (argv[1][0] != '-')
163  {
164  libMesh::out << "<<< Writing system to file " << argv[1]
165  << std::endl;
166 
167  // Write the system.
168  equation_systems.write (argv[1], WRITE);
169 
170  // Clear the equation systems data structure.
171  equation_systems.clear ();
172 
173  libMesh::out << ">>> Reading system from file " << argv[1]
174  << std::endl << std::endl;
175 
176  // Read the file we just wrote. This better
177  // work!
178  equation_systems.read (argv[1], READ);
179 
180  // Print the information again.
181  equation_systems.print_info();
182  }
183 
184  // All done. libMesh objects are destroyed here. Because the
185  // LibMeshInit object was created first, its destruction occurs
186  // last, and it's destructor finalizes any external libraries and
187  // checks for leaked memory.
188  return 0;
189 }

References libMesh::EquationSystems::add_system(), libMesh::MeshTools::Generation::build_square(), libMesh::EquationSystems::clear(), libMesh::default_solver_package(), libMesh::FIRST, libMesh::EquationSystems::get_system(), libMesh::TriangleWrapper::init(), libMesh::EquationSystems::init(), libMesh::INVALID_SOLVER_PACKAGE, mesh, libMesh::MONOMIAL, libMesh::out, libMesh::EquationSystems::parameters, libMesh::EquationSystems::print_info(), libMesh::MeshBase::print_info(), libMesh::READ, libMesh::EquationSystems::read(), libMesh::Real, libMesh::SECOND, libMesh::Parameters::set(), libMesh::WRITE, and libMesh::EquationSystems::write().

libMesh::Mesh
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
libMesh::TransientSystem
Manages storage and variables for transient systems.
Definition: transient_system.h:57
libMesh::default_solver_package
SolverPackage default_solver_package()
Definition: libmesh.C:993
libMesh::WRITE
Definition: enum_xdr_mode.h:40
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::SECOND
Definition: enum_order.h:43
libMesh::TriangleWrapper::init
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
libMesh::MeshTools::Generation::build_square
void build_square(UnstructuredMesh &mesh, const unsigned int nx, const unsigned int ny, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 2D meshes.
Definition: mesh_generation.C:1501
libMesh::INVALID_SOLVER_PACKAGE
Definition: enum_solver_package.h:43
libMesh::System::add_variable
unsigned int add_variable(const std::string &var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1069
libMesh::LibMeshInit
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:83
libMesh::READ
Definition: enum_xdr_mode.h:41
libMesh::MONOMIAL
Definition: enum_fe_family.h:39
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::ExplicitSystem
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems.
Definition: explicit_system.h:48
libMesh::MeshBase::print_info
void print_info(std::ostream &os=libMesh::out) const
Prints relevant information about the mesh.
Definition: mesh_base.C:585
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::out
OStreamProxy out
libMesh::FIRST
Definition: enum_order.h:42