libMesh
Loading...
Searching...
No Matches
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 create two systems, the first with one variable and the second
102 // with three variables.
103 // The EquationSystems object needs a reference to the mesh
104 // object, so the order of construction here is important.
105 EquationSystems equation_systems (mesh);
106
107 // Add a flag "test" that is visible for all systems. This
108 // helps in inter-system communication.
109 equation_systems.parameters.set<bool> ("test") = true;
110
111 // Set a simulation-specific parameter visible for all systems.
112 // This helps in inter-system-communication.
113 equation_systems.parameters.set<Real> ("dummy") = 42.;
114
115 // Set another simulation-specific parameter
116 equation_systems.parameters.set<Real> ("nobody") = 0.;
117
118 // Now we declare the system and its variables.
119 // We begin by adding a "TransientLinearImplicitSystem" to the
120 // EquationSystems object, and we give it the name
121 // "Simple System".
122 equation_systems.add_system<TransientLinearImplicitSystem> ("Simple System");
123
124 // Adds the variable "u" to "Simple System". "u"
125 // will be approximated using a first-order approximation.
126 equation_systems.get_system("Simple System").add_variable("u", FIRST);
127
128 // Next we add an "ExplicitSystem" to the
129 // EquationSystems object, and we give it the name
130 // "Complex System".
131 equation_systems.add_system<ExplicitSystem> ("Complex System");
132
133 // Give "Complex System" three variables -- each with a different approximation
134 // order. Variables "c" and "T" will use a first-order Lagrange approximation,
135 // while variable "dv" will use a second-order discontinuous
136 // approximation space.
137 equation_systems.get_system("Complex System").add_variable("c", FIRST);
138 equation_systems.get_system("Complex System").add_variable("T", FIRST);
139 equation_systems.get_system("Complex System").add_variable("dv", SECOND, MONOMIAL);
140
141 // Initialize the data structures for the equation system.
142 equation_systems.init();
143
144 // Print information about the mesh to the screen.
146 // Prints information about the system to the screen.
147 equation_systems.print_info();
148
149 // Write the equation system if the user specified an
150 // output file name. Note that there are two possible
151 // formats to write to. Specifying WRITE will
152 // create a formatted ASCII file. Optionally, you can specify
153 // ENCODE and get an XDR-encoded binary file.
154 //
155 // We will write the data, clear the object, and read the file
156 // we just wrote. This is simply to demonstrate capability.
157 // Note that you might use this in an application to periodically
158 // dump the state of your simulation. You can then restart from
159 // this data later.
160 if (argc > 1)
161 if (argv[1][0] != '-')
162 {
163 libMesh::out << "<<< Writing system to file " << argv[1]
164 << std::endl;
165
166 // Write the system.
167 equation_systems.write (argv[1], WRITE);
168
169 // Clear the equation systems data structure.
170 equation_systems.clear ();
171
172 libMesh::out << ">>> Reading system from file " << argv[1]
173 << std::endl << std::endl;
174
175 // Read the file we just wrote. This better
176 // work!
177 equation_systems.read (argv[1], READ);
178
179 // Print the information again.
180 equation_systems.print_info();
181 }
182
183 // All done. libMesh objects are destroyed here. Because the
184 // LibMeshInit object was created first, its destruction occurs
185 // last, and it's destructor finalizes any external libraries and
186 // checks for leaked memory.
187 return 0;
188}
This is the EquationSystems class.
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition libmesh.h:92
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
unsigned int add_variable(std::string_view 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:1344
Manages storage and variables for transient systems.
MeshBase & mesh
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.
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
SolverPackage default_solver_package()
Definition libmesh.C:1064
OStreamProxy out
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

References libMesh::EquationSystems::add_system(), libMesh::MeshTools::Generation::build_square(), libMesh::EquationSystems::clear(), libMesh::default_solver_package(), libMesh::FIRST, libMesh::EquationSystems::get_system(), libMesh::EquationSystems::init(), libMesh::INVALID_SOLVER_PACKAGE, main(), 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().