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

References libMesh::EquationSystems::add_system(), libMesh::MeshTools::Generation::build_square(), libMesh::EquationSystems::clear(), libMesh::LibMeshInit::comm(), 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().

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