libMesh
Functions
vector_fe_ex9.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 72 of file vector_fe_ex9.C.

References libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::ExactSolution::attach_exact_value(), libMesh::QBase::build(), libMesh::FEGenericBase< OutputType >::build(), libMesh::MeshTools::Generation::build_square(), libMesh::compute_error(), libMesh::default_solver_package(), libMesh::HDGProblem::dof_map, libMesh::StaticCondensation::dont_condense_vars(), libMesh::FIFTH, libMesh::FIRST, libMesh::TriangleWrapper::init(), libMesh::HDGProblem::init(), libMesh::EquationSystems::init(), libMesh::L2_LAGRANGE, libMesh::L2_LAGRANGE_VEC, libMesh::HDGProblem::lm_fe_face, libMesh::HDGProblem::mesh, mesh, libMesh::HDGProblem::mms, libMesh::out, libMesh::HDGProblem::p_true_soln, libMesh::EquationSystems::parameters, libMesh::PETSC_SOLVERS, libMesh::EquationSystems::print_info(), libMesh::MeshBase::print_info(), libMesh::HDGProblem::qface, libMesh::QGAUSS, libMesh::HDGProblem::qrule, libMesh::Real, libMesh::HDGProblem::sc, libMesh::SCALAR, libMesh::HDGProblem::scalar_fe, libMesh::HDGProblem::scalar_fe_face, libMesh::Parameters::set(), libMesh::SIDE_HIERARCHIC, libMesh::HDGProblem::system, libMesh::HDGProblem::u_true_soln, libMesh::HDGProblem::v_true_soln, libMesh::HDGProblem::vector_fe, libMesh::HDGProblem::vector_fe_face, and libMesh::ExodusII_IO::write_equation_systems().

73 {
74  // Initialize libMesh.
75  LibMeshInit init(argc, argv);
76 
77  // This example requires PETSc
78  libmesh_example_requires(libMesh::default_solver_package() == PETSC_SOLVERS,
79  "--enable-petsc");
80 
81  // Parse the input file.
82  GetPot infile("vector_fe_ex9.in");
83 
84  // But allow the command line to override it.
85  infile.parse_command_line(argc, argv);
86 
87  // Read in parameters from the command line and the input file.
88  const unsigned int dimension = 2;
89  const unsigned int grid_size = infile("grid_size", 2);
90  const bool mms = infile("mms", true);
91  const Real nu = infile("nu", 1.);
92  const bool cavity = infile("cavity", false);
93 
94  // Skip higher-dimensional examples on a lower-dimensional libMesh build.
95  libmesh_example_requires(dimension <= LIBMESH_DIM, dimension << "D support");
96 
97  // Create a mesh, with dimension to be overridden later, distributed
98  // across the default MPI communicator.
99  Mesh mesh(init.comm());
100 
101  // Use the MeshTools::Generation mesh generator to create a uniform
102  // grid on the cube [-1,1]^D. To accomodate first order side hierarchics, we must
103  // use TRI6/7 elements
104  const std::string elem_str = infile("element_type", std::string("TRI6"));
105 
106  libmesh_error_msg_if(elem_str != "TRI6" && elem_str != "TRI7",
107  "You selected "
108  << elem_str
109  << " but this example must be run with TRI6, TRI7, QUAD8, or QUAD9 in 2d"
110  << " or with TET14, or HEX27 in 3d.");
111 
112  if (mms && !cavity)
114  mesh, grid_size, grid_size, 0., 2., -1, 1., Utility::string_to_enum<ElemType>(elem_str));
115  else if (cavity)
117  mesh, grid_size, grid_size, -1, 1, -1, 1., Utility::string_to_enum<ElemType>(elem_str));
118  else
120  5 * grid_size,
121  grid_size,
122  0.,
123  10.,
124  -1,
125  1.,
126  Utility::string_to_enum<ElemType>(elem_str));
127  mesh.print_info();
128 
129  // Create an equation systems object.
130  EquationSystems equation_systems(mesh);
131 
132  // Declare the system "Mixed" and its variables.
133  auto & system = equation_systems.add_system<NonlinearImplicitSystem>("HDG");
134 
135  // Adds the velocity variables and their gradients
136  system.add_variable("qu", FIRST, L2_LAGRANGE_VEC);
137  system.add_variable("qv", FIRST, L2_LAGRANGE_VEC);
138  system.add_variable("vel_x", FIRST, L2_LAGRANGE);
139  system.add_variable("vel_y", FIRST, L2_LAGRANGE);
140 
141  // Add our Lagrange multiplier to the implicit system
142  system.add_variable("lm_u", FIRST, SIDE_HIERARCHIC);
143  system.add_variable("lm_v", FIRST, SIDE_HIERARCHIC);
144  const auto p_num = system.add_variable("pressure", FIRST, L2_LAGRANGE);
145  if (cavity)
146  system.add_variable("global_lm", FIRST, SCALAR);
147 
148  const FEType vector_fe_type(FIRST, L2_LAGRANGE_VEC);
149  const FEType scalar_fe_type(FIRST, L2_LAGRANGE);
150  const FEType lm_fe_type(FIRST, SIDE_HIERARCHIC);
151 
152  StaticCondensation * sc = nullptr;
153  if (system.has_static_condensation())
154  {
155  sc = &system.get_static_condensation();
156  sc->dont_condense_vars({p_num});
157  }
158 
159  HDGProblem hdg(nu, cavity);
160  hdg.mesh = &mesh;
161  hdg.system = &system;
162  hdg.dof_map = &system.get_dof_map();
163  hdg.vector_fe = FEVectorBase::build(dimension, vector_fe_type);
164  hdg.scalar_fe = FEBase::build(dimension, scalar_fe_type);
165  hdg.qrule = QBase::build(QGAUSS, dimension, FIFTH);
166  hdg.qface = QBase::build(QGAUSS, dimension - 1, FIFTH);
167  hdg.vector_fe_face = FEVectorBase::build(dimension, vector_fe_type);
168  hdg.scalar_fe_face = FEBase::build(dimension, scalar_fe_type);
169  hdg.lm_fe_face = FEBase::build(dimension, lm_fe_type);
170  hdg.mms = mms;
171  hdg.sc = sc;
172 
173  system.nonlinear_solver->residual_object = &hdg;
174  system.nonlinear_solver->jacobian_object = &hdg;
175 
176  hdg.init();
177 
178  // Initialize the data structures for the equation system.
179  equation_systems.init();
180  equation_systems.print_info();
181 
182  // Solve the implicit system for the Lagrange multiplier
183  system.solve();
184 
185  if (mms)
186  {
187  //
188  // Now we will compute our solution approximation errors
189  //
190 
191  equation_systems.parameters.set<const ExactSoln *>("vel_x_exact_sol") = &hdg.u_true_soln;
192  equation_systems.parameters.set<const ExactSoln *>("vel_y_exact_sol") = &hdg.v_true_soln;
193  equation_systems.parameters.set<const ExactSoln *>("pressure_exact_sol") = &hdg.p_true_soln;
194  ExactSolution exact_sol(equation_systems);
195  exact_sol.attach_exact_value(&compute_error);
196 
197  // Compute the error.
198  exact_sol.compute_error("HDG", "vel_x");
199  exact_sol.compute_error("HDG", "vel_y");
200  exact_sol.compute_error("HDG", "pressure");
201 
202  // Print out the error values.
203  libMesh::out << "L2 error for u is: " << exact_sol.l2_error("HDG", "vel_x") << std::endl;
204  libMesh::out << "L2 error for v is: " << exact_sol.l2_error("HDG", "vel_y") << std::endl;
205  libMesh::out << "L2 error for pressure is: " << exact_sol.l2_error("HDG", "pressure")
206  << std::endl;
207  }
208 
209 #ifdef LIBMESH_HAVE_EXODUS_API
210 
211  // We write the file in the ExodusII format.
212  ExodusII_IO(mesh).write_equation_systems("out.e", equation_systems);
213 
214 #endif // #ifdef LIBMESH_HAVE_EXODUS_API
215 
216  // All done.
217  return 0;
218 }
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition: fe_type.h:196
This class handles the computation of the L2 and/or H1 error for the Systems in the EquationSystems o...
This is the EquationSystems class.
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition: exodusII_io.h:50
Number compute_error(const Point &p, const Parameters &params, const std::string &, const std::string &unknown_name)
Definition: exact_soln.h:36
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.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:91
void dont_condense_vars(const std::unordered_set< unsigned int > &vars)
Add vars to the list of variables not to condense.
SolverPackage default_solver_package()
Definition: libmesh.C:1064
virtual void init(const numeric_index_type m, const numeric_index_type n, const numeric_index_type m_l, const numeric_index_type n_l, const numeric_index_type nnz=30, const numeric_index_type noz=10, const numeric_index_type blocksize=1) override
Initialize SparseMatrix with the specified sizes.
virtual void write_equation_systems(const std::string &fname, const EquationSystems &es, const std::set< std::string > *system_names=nullptr) override
Writes out the solution for no specific time or timestep.
Definition: exodusII_io.C:2050
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:1748
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and non-linear solv...
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
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
OStreamProxy out
void attach_exact_value(unsigned int sys_num, FunctionBase< Number > *f)
Clone and attach an arbitrary functor which computes the exact value of the system sys_num solution a...
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50