libMesh
Functions
vector_fe_ex4.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 47 of file vector_fe_ex4.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_cube(), libMesh::LibMeshInit::comm(), 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::solver, libMesh::DifferentiableSystem::time_solver, libMesh::System::variable_number(), libMesh::DiffSolver::verbose, and libMesh::MeshOutput< MT >::write_equation_systems().

48 {
49  // Initialize libMesh.
50  LibMeshInit init (argc, argv);
51 
52  // This example requires a linear solver package.
53  libmesh_example_requires(libMesh::default_solver_package() != INVALID_SOLVER_PACKAGE,
54  "--enable-petsc, --enable-trilinos, or --enable-eigen");
55 
56  // Parse the input file
57  GetPot infile("vector_fe_ex4.in");
58 
59  // Read in parameters from the input file
60  const unsigned int grid_size = infile("grid_size", 2);
61 
62  // Skip higher-dimensional examples on a lower-dimensional libMesh build
63  libmesh_example_requires(3 <= LIBMESH_DIM, "2D/3D support");
64 
65  // Create a mesh, with dimension to be overridden later, on the
66  // default MPI communicator.
67  Mesh mesh(init.comm());
68 
69  // Use the MeshTools::Generation mesh generator to create a uniform
70  // grid on the square [-1,1]^D. We must use TRI6 elements for the
71  // Nedelec triangle elements.
72 
73  std::string elem_str =
74  command_line_value(std::string("element_type"),
75  std::string("HEX27"));
76 
77  if (elem_str != "HEX20" && elem_str != "HEX27")
78  libmesh_error_msg("You entered: " \
79  << elem_str \
80  << " but this example must be run with HEX20 or HEX27.");
81 
83  grid_size,
84  grid_size,
85  grid_size,
86  -1., 1,
87  -1., 1.,
88  -1., 1,
89  Utility::string_to_enum<ElemType>(elem_str));
90 
91 
92  // Print information about the mesh to the screen.
93  mesh.print_info();
94 
95  // Create an equation systems object.
96  EquationSystems equation_systems (mesh);
97 
98  // Declare the system "Navier-Stokes" and its variables.
99  CurlCurlSystem & system =
100  equation_systems.add_system<CurlCurlSystem> ("CurlCurl");
101 
102  // This example only implements the steady-state problem
103  system.time_solver =
104  UniquePtr<TimeSolver>(new SteadySolver(system));
105 
106  // Initialize the system
107  equation_systems.init();
108 
109  // And the nonlinear solver options
110  DiffSolver & solver = *(system.time_solver->diff_solver().get());
111  solver.quiet = infile("solver_quiet", true);
112  solver.verbose = !solver.quiet;
113  solver.max_nonlinear_iterations = infile("max_nonlinear_iterations", 15);
114  solver.relative_step_tolerance = infile("relative_step_tolerance", 1.e-3);
115  solver.relative_residual_tolerance = infile("relative_residual_tolerance", 1.0e-13);
116  solver.absolute_residual_tolerance = infile("absolute_residual_tolerance", 0.0);
117 
118  // And the linear solver options
119  solver.max_linear_iterations = infile("max_linear_iterations", 50000);
120  solver.initial_linear_tolerance = infile("initial_linear_tolerance", 1.e-10);
121 
122  // Print information about the system to the screen.
123  equation_systems.print_info();
124 
125  system.solve();
126 
127  ExactSolution exact_sol(equation_systems);
128 
129  SolutionFunction soln_func(system.variable_number("u"));
130  SolutionGradient soln_grad(system.variable_number("u"));
131 
132  // Build FunctionBase* containers to attach to the ExactSolution object.
133  std::vector<FunctionBase<Number> *> sols(1, &soln_func);
134  std::vector<FunctionBase<Gradient> *> grads(1, &soln_grad);
135 
136  exact_sol.attach_exact_values(sols);
137  exact_sol.attach_exact_derivs(grads);
138 
139  // Use higher quadrature order for more accurate error results
140  int extra_error_quadrature = infile("extra_error_quadrature", 2);
141  exact_sol.extra_quadrature_order(extra_error_quadrature);
142 
143  // Compute the error.
144  exact_sol.compute_error("CurlCurl", "u");
145 
146  // Print out the error values
147  libMesh::out << "L2-Error is: "
148  << exact_sol.l2_error("CurlCurl", "u")
149  << std::endl;
150  libMesh::out << "HCurl semi-norm error is: "
151  << exact_sol.error_norm("CurlCurl", "u", HCURL_SEMINORM)
152  << std::endl;
153  libMesh::out << "HCurl-Error is: "
154  << exact_sol.hcurl_error("CurlCurl", "u")
155  << std::endl;
156 
157 #ifdef LIBMESH_HAVE_EXODUS_API
158 
159  // We write the file in the ExodusII format.
160  ExodusII_IO(mesh).write_equation_systems("out.e", equation_systems);
161 
162 #endif // #ifdef LIBMESH_HAVE_EXODUS_API
163 
164  // All done.
165  return 0;
166 }
This class handles the computation of the L2 and/or H1 error for the Systems in the EquationSystems o...
UniquePtr< TimeSolver > time_solver
A pointer to the solver object we&#39;re going to use.
Definition: diff_system.h:221
This is the EquationSystems class.
bool quiet
The DiffSolver should not print anything to libMesh::out unless quiet is set to false; default is tru...
Definition: diff_solver.h:162
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:156
Real absolute_residual_tolerance
The DiffSolver should exit after the residual is reduced to either less than absolute_residual_tolera...
Definition: diff_solver.h:191
MeshBase & mesh
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:62
Real initial_linear_tolerance
Any required linear solves will at first be done with this tolerance; the DiffSolver may tighten the ...
Definition: diff_solver.h:210
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
PetscDiffSolver & solver
SolverPackage default_solver_package()
Definition: libmesh.C:995
This is a generic class that defines a solver to handle ImplicitSystem classes, including NonlinearIm...
Definition: diff_solver.h:70
unsigned short int variable_number(const std::string &var) const
Definition: system.C:1263
virtual void solve() libmesh_override
Invokes the solver associated with the system.
Definition: fem_system.C:1056
T command_line_value(const std::string &, T)
Definition: libmesh.C:932
unsigned int max_linear_iterations
Each linear solver step should exit after max_linear_iterations is exceeded.
Definition: diff_solver.h:148
void init(triangulateio &t)
Initializes the fields of t to NULL/0 as necessary.
This class implements a TimeSolver which does a single solve of the steady state problem.
Definition: steady_solver.h:47
FEMSystem, TimeSolver and NewtonSolver will handle most tasks, but we must specify element residuals...
virtual void write_equation_systems(const std::string &, const EquationSystems &, const std::set< std::string > *system_names=libmesh_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 verbose
The DiffSolver may print a lot more to libMesh::out if verbose is set to true; default is false...
Definition: diff_solver.h:168
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
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.
Real relative_residual_tolerance
Definition: diff_solver.h:192