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 49 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::command_line_value(), libMesh::ExactSolution::compute_error(), libMesh::default_solver_package(), libMesh::ExactSolution::error_norm(), libMesh::ExactSolution::extra_quadrature_order(), 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, libMesh::out, libMesh::EquationSystems::print_info(), libMesh::MeshBase::print_info(), libMesh::DiffSolver::quiet, libMesh::DiffSolver::relative_residual_tolerance, libMesh::DiffSolver::relative_step_tolerance, libMesh::FEMSystem::solve(), libMesh::DifferentiableSystem::time_solver, libMesh::System::variable_number(), libMesh::DiffSolver::verbose, and libMesh::MeshOutput< MT >::write_equation_systems().

50 {
51  // Initialize libMesh.
52  LibMeshInit init (argc, argv);
53 
54  // This example requires a linear solver package.
55  libmesh_example_requires(libMesh::default_solver_package() != INVALID_SOLVER_PACKAGE,
56  "--enable-petsc, --enable-trilinos, or --enable-eigen");
57 
58  // Parse the input file
59  GetPot infile("vector_fe_ex3.in");
60 
61  // Read in parameters from the input file
62  const unsigned int grid_size = infile("grid_size", 2);
63 
64  // Skip higher-dimensional examples on a lower-dimensional libMesh build
65  libmesh_example_requires(3 <= LIBMESH_DIM, "2D/3D support");
66 
67  // Create a mesh, with dimension to be overridden later, on the
68  // default MPI communicator.
69  Mesh mesh(init.comm());
70 
71  // Use the MeshTools::Generation mesh generator to create a uniform
72  // grid on the square [-1,1]^D. We must use at least TRI6 or QUAD8 elements
73  // for the Nedelec triangle or quadrilateral elements, respectively.
74  std::string elem_str =
75  command_line_value(std::string("element_type"),
76  std::string("TRI6"));
77 
78  libmesh_error_msg_if(elem_str != "TRI6" && elem_str != "TRI7" && elem_str != "QUAD8" && elem_str != "QUAD9",
79  "You selected: " << elem_str <<
80  " but this example must be run with TRI6, TRI7, QUAD8, or QUAD9.");
81 
83  grid_size,
84  grid_size,
85  -1., 1.,
86  -1., 1.,
87  Utility::string_to_enum<ElemType>(elem_str));
88 
89 
90  // Print information about the mesh to the screen.
91  mesh.print_info();
92 
93  // Create an equation systems object.
94  EquationSystems equation_systems (mesh);
95 
96  // Declare the system "CurlCurl" and its variables.
97  CurlCurlSystem & system =
98  equation_systems.add_system<CurlCurlSystem> ("CurlCurl");
99 
100  // This example only implements the steady-state problem
101  system.time_solver = std::make_unique<SteadySolver>(system);
102 
103  // Initialize the system
104  equation_systems.init();
105 
106  // And the nonlinear solver options
107  DiffSolver & solver = *(system.time_solver->diff_solver().get());
108  solver.quiet = infile("solver_quiet", true);
109  solver.verbose = !solver.quiet;
110  solver.max_nonlinear_iterations = infile("max_nonlinear_iterations", 15);
111  solver.relative_step_tolerance = infile("relative_step_tolerance", 1.e-3);
112  solver.relative_residual_tolerance = infile("relative_residual_tolerance", 1.0e-13);
113  solver.absolute_residual_tolerance = infile("absolute_residual_tolerance", 0.0);
114 
115  // And the linear solver options
116  solver.max_linear_iterations = infile("max_linear_iterations", 50000);
117  solver.initial_linear_tolerance = infile("initial_linear_tolerance", 1.e-10);
118 
119  // Print information about the system to the screen.
120  equation_systems.print_info();
121 
122  system.solve();
123 
124  ExactSolution exact_sol(equation_systems);
125 
126  SolutionFunction soln_func(system.variable_number("u"));
127  SolutionGradient soln_grad(system.variable_number("u"));
128 
129  // Build FunctionBase* containers to attach to the ExactSolution object.
130  std::vector<FunctionBase<Number> *> sols(1, &soln_func);
131  std::vector<FunctionBase<Gradient> *> grads(1, &soln_grad);
132 
133  exact_sol.attach_exact_values(sols);
134  exact_sol.attach_exact_derivs(grads);
135 
136  // Use higher quadrature order for more accurate error results
137  int extra_error_quadrature = infile("extra_error_quadrature", 2);
138  exact_sol.extra_quadrature_order(extra_error_quadrature);
139 
140  // Compute the error.
141  exact_sol.compute_error("CurlCurl", "u");
142 
143  // Print out the error values
144  libMesh::out << "L2-Error is: "
145  << exact_sol.l2_error("CurlCurl", "u")
146  << std::endl;
147  libMesh::out << "HCurl semi-norm error is: "
148  << exact_sol.error_norm("CurlCurl", "u", HCURL_SEMINORM)
149  << std::endl;
150  libMesh::out << "HCurl-Error is: "
151  << exact_sol.hcurl_error("CurlCurl", "u")
152  << std::endl;
153 
154 #ifdef LIBMESH_HAVE_EXODUS_API
155 
156  // We write the file in the ExodusII format.
157  ExodusII_IO(mesh).write_equation_systems("out.e", equation_systems);
158 
159 #endif // #ifdef LIBMESH_HAVE_EXODUS_API
160 
161  // All done.
162  return 0;
163 }
This class handles the computation of the L2 and/or H1 error for the Systems in the EquationSystems o...
This is the EquationSystems class.
virtual void write_equation_systems(const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
This method implements writing a mesh with data to a specified file where the data is taken from the ...
Definition: mesh_output.C:31
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:52
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:251
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:90
unsigned int variable_number(std::string_view var) const
Definition: system.C:1557
SolverPackage default_solver_package()
Definition: libmesh.C:1050
This is a generic class that defines a solver to handle ImplicitSystem classes, including NonlinearIm...
Definition: diff_solver.h:68
T command_line_value(const std::string &, T)
Definition: libmesh.C:957
unsigned int max_linear_iterations
Each linear solver step should exit after max_linear_iterations is exceeded.
Definition: diff_solver.h:146
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:1489
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
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
OStreamProxy out
virtual void solve() override
Invokes the solver associated with the system.
Definition: fem_system.C:1076
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