libMesh
Functions
vector_fe_ex3.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 54 of file vector_fe_ex3.C.

References libMesh::DiffSolver::absolute_residual_tolerance, libMesh::EquationSystems::add_system(), libMesh::ExactSolution::attach_exact_derivs(), libMesh::ExactSolution::attach_exact_values(), libMesh::MeshTools::Generation::build_square(), libMesh::ExactSolution::compute_error(), libMesh::default_solver_package(), libMesh::ExactSolution::error_norm(), libMesh::ExactSolution::extra_quadrature_order(), libMesh::FIFTH, libMesh::ExactSolution::hcurl_error(), libMesh::HCURL_SEMINORM, libMesh::TriangleWrapper::init(), libMesh::EquationSystems::init(), libMesh::DiffSolver::initial_linear_tolerance, libMesh::INVALID_SOLVER_PACKAGE, libMesh::ExactSolution::l2_error(), libMesh::DiffSolver::max_linear_iterations, libMesh::DiffSolver::max_nonlinear_iterations, mesh, CurlCurlSystem::order(), libMesh::out, libMesh::MeshTools::Modification::permute_elements(), libMesh::EquationSystems::print_info(), libMesh::MeshBase::print_info(), libMesh::DiffSolver::quiet, libMesh::Real, libMesh::DiffSolver::relative_residual_tolerance, libMesh::DiffSolver::relative_step_tolerance, CurlCurlExactSolution::RM(), libMesh::MeshTools::Modification::rotate(), libMesh::FEMSystem::solve(), libMesh::DifferentiableSystem::time_solver, libMesh::MeshRefinement::uniformly_refine(), libMesh::System::variable_number(), libMesh::DiffSolver::verbose, and libMesh::ExodusII_IO::write_equation_systems().

55 {
56  // Initialize libMesh.
57  LibMeshInit init (argc, argv);
58 
59  // This example requires a linear solver package.
60  libmesh_example_requires(libMesh::default_solver_package() != INVALID_SOLVER_PACKAGE,
61  "--enable-petsc, --enable-trilinos, or --enable-eigen");
62 
63  // Parse the input file
64  GetPot infile("vector_fe_ex3.in");
65 
66  // But allow the command line to override it.
67  infile.parse_command_line(argc, argv);
68 
69  // hypre AMS requires PETSc 3.12.2 or above with hypre support enabled
70 #if PETSC_VERSION_LESS_THAN(3, 12, 2) || !defined(LIBMESH_HAVE_PETSC_HYPRE)
71  libmesh_example_requires(!infile.search("ams"),
72  "PETSc 3.12.2 or above with hypre support enabled");
73 #endif
74 
75  // Read in parameters from the input file
76  const unsigned int grid_size = infile("grid_size", 2);
77 
78  // Skip higher-dimensional examples on a lower-dimensional libMesh build
79  libmesh_example_requires(2 <= LIBMESH_DIM, "2D support");
80 
81  // Create a mesh, with dimension to be overridden later, on the
82  // default MPI communicator.
83  Mesh mesh(init.comm());
84 
85  // Use the MeshTools::Generation mesh generator to create a uniform
86  // grid on the square [-1,1]^D. We must use at least TRI6 or QUAD8 elements
87  // for the Nedelec triangle or quadrilateral elements, respectively.
88  const std::string elem_str = infile("element_type", std::string("TRI6"));
89 
90  libmesh_error_msg_if(elem_str != "TRI6" && elem_str != "TRI7" && elem_str != "QUAD8" && elem_str != "QUAD9",
91  "You selected: " << elem_str <<
92  " but this example must be run with TRI6, TRI7, QUAD8, or QUAD9.");
93 
95  grid_size,
96  grid_size,
97  -1., 1.,
98  -1., 1.,
99  Utility::string_to_enum<ElemType>(elem_str));
100 
101  // Make sure the code is robust against nodal reorderings.
103 
104 #ifdef LIBMESH_ENABLE_AMR
105  // Make sure the code is robust against mesh refinements.
106  MeshRefinement mesh_refinement(mesh);
107  mesh_refinement.uniformly_refine(infile("refine", 0));
108 #endif
109 
110  // Make sure the code is robust against solves on 2d meshes rotated out of
111  // the xy plane. By default, all Euler angles are zero, the rotation matrix
112  // is the identity, and the mesh stays in place.
113  const Real phi = infile("phi", 0.), theta = infile("theta", 0.), psi = infile("psi", 0.);
115 
116  // Print information about the mesh to the screen.
117  mesh.print_info();
118 
119  // Create an equation systems object.
120  EquationSystems equation_systems (mesh);
121 
122  // Declare the system "CurlCurl" and its variables.
123  CurlCurlSystem & system =
124  equation_systems.add_system<CurlCurlSystem> ("CurlCurl");
125 
126  // Set the FE approximation order.
127  const Order order = static_cast<Order>(infile("order", 1u));
128 
129  libmesh_error_msg_if(order < FIRST || order > FIFTH,
130  "You selected: " << order <<
131  " but this example must be run with 1 <= order <= 5.");
132 
133  system.order(order);
134 
135  // This example only implements the steady-state problem
136  system.time_solver = std::make_unique<SteadySolver>(system);
137 
138  // Initialize the system
139  equation_systems.init();
140 
141  // And the nonlinear solver options
142  DiffSolver & solver = *(system.time_solver->diff_solver().get());
143  solver.quiet = infile("solver_quiet", true);
144  solver.verbose = !solver.quiet;
145  solver.max_nonlinear_iterations = infile("max_nonlinear_iterations", 15);
146  solver.relative_step_tolerance = infile("relative_step_tolerance", 1.e-3);
147  solver.relative_residual_tolerance = infile("relative_residual_tolerance", 1.0e-13);
148  solver.absolute_residual_tolerance = infile("absolute_residual_tolerance", 0.0);
149 
150  // And the linear solver options
151  solver.max_linear_iterations = infile("max_linear_iterations", 50000);
152  solver.initial_linear_tolerance = infile("initial_linear_tolerance", 1.e-10);
153 
154  // Print information about the system to the screen.
155  equation_systems.print_info();
156 
157  // Solve the system.
158  system.solve();
159 
160  ExactSolution exact_sol(equation_systems);
161 
162  SolutionFunction soln_func(system.variable_number("u"));
163  SolutionGradient soln_grad(system.variable_number("u"));
164 
165  // Build FunctionBase* containers to attach to the ExactSolution object.
166  std::vector<FunctionBase<Number> *> sols(1, &soln_func);
167  std::vector<FunctionBase<Gradient> *> grads(1, &soln_grad);
168 
169  exact_sol.attach_exact_values(sols);
170  exact_sol.attach_exact_derivs(grads);
171 
172  // Use higher quadrature order for more accurate error results
173  int extra_error_quadrature = infile("extra_error_quadrature", 2);
174  exact_sol.extra_quadrature_order(extra_error_quadrature);
175 
176  // Compute the error.
177  exact_sol.compute_error("CurlCurl", "u");
178 
179  // Print out the error values
180  libMesh::out << "L2-Error is: "
181  << exact_sol.l2_error("CurlCurl", "u")
182  << std::endl;
183  libMesh::out << "HCurl semi-norm error is: "
184  << exact_sol.error_norm("CurlCurl", "u", HCURL_SEMINORM)
185  << std::endl;
186  libMesh::out << "HCurl-Error is: "
187  << exact_sol.hcurl_error("CurlCurl", "u")
188  << std::endl;
189 
190 #ifdef LIBMESH_HAVE_EXODUS_API
191 
192  // We write the file in the ExodusII format.
193  ExodusII_IO(mesh).write_equation_systems("out.e", equation_systems);
194 
195 #endif // #ifdef LIBMESH_HAVE_EXODUS_API
196 
197  // All done.
198  return 0;
199 }
This class handles the computation of the L2 and/or H1 error for the Systems in the EquationSystems o...
This is the EquationSystems class.
Order
defines an enum for polynomial orders.
Definition: enum_order.h:40
bool quiet
The DiffSolver should not print anything to libMesh::out unless quiet is set to false; default is tru...
Definition: diff_solver.h:160
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition: exodusII_io.h:50
unsigned int max_nonlinear_iterations
The DiffSolver should exit in failure if max_nonlinear_iterations is exceeded and continue_after_max_...
Definition: diff_solver.h:154
Real absolute_residual_tolerance
The DiffSolver should exit after the residual is reduced to either less than absolute_residual_tolera...
Definition: diff_solver.h:189
std::unique_ptr< TimeSolver > time_solver
A pointer to the solver object we&#39;re going to use.
Definition: diff_system.h:245
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
static void RM(RealTensor T)
unsigned int variable_number(std::string_view var) const
Definition: system.C:1398
void permute_elements(MeshBase &mesh)
Randomly permute the nodal ordering of each element (without twisting the element mapping)...
SolverPackage default_solver_package()
Definition: libmesh.C:1064
This is a generic class that defines a solver to handle ImplicitSystem classes, including NonlinearIm...
Definition: diff_solver.h:68
Implements (adaptive) mesh refinement algorithms for a MeshBase.
unsigned int max_linear_iterations
Each linear solver step should exit after max_linear_iterations is exceeded.
Definition: diff_solver.h:146
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.
RealTensorValue rotate(MeshBase &mesh, const Real phi, const Real theta=0., const Real psi=0.)
Rotates the mesh in the xy plane.
FEMSystem, TimeSolver and NewtonSolver will handle most tasks, but we must specify element residuals...
bool verbose
The DiffSolver may print a lot more to libMesh::out if verbose is set to true; default is false...
Definition: diff_solver.h:166
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
OStreamProxy out
virtual void solve() override
Invokes the solver associated with the system.
Definition: fem_system.C:1070
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
double initial_linear_tolerance
Any required linear solves will at first be done with this tolerance; the DiffSolver may tighten the ...
Definition: diff_solver.h:208
Real relative_residual_tolerance
Definition: diff_solver.h:190
void order(const Order &order)