34#include "libmesh/elem.h"
35#include "libmesh/equation_systems.h"
36#include "libmesh/error_vector.h"
37#include "libmesh/exact_solution.h"
38#include "libmesh/getpot.h"
39#include "libmesh/gmv_io.h"
40#include "libmesh/exodusII_io.h"
41#include "libmesh/kelly_error_estimator.h"
42#include "libmesh/mesh.h"
43#include "libmesh/mesh_generation.h"
44#include "libmesh/mesh_refinement.h"
45#include "libmesh/parsed_function.h"
46#include "libmesh/uniform_refinement_estimator.h"
47#include "libmesh/enum_solver_package.h"
48#include "libmesh/enum_norm_type.h"
51#include "heatsystem.h"
52#include "libmesh/diff_solver.h"
53#include "libmesh/euler_solver.h"
54#include "libmesh/steady_solver.h"
60int main (
int argc,
char ** argv)
67 "--enable-petsc, --enable-trilinos, or --enable-eigen");
69#ifndef LIBMESH_ENABLE_AMR
70 libmesh_example_requires(
false,
"--enable-amr");
74#ifndef LIBMESH_ENABLE_DIRICHLET
75 libmesh_example_requires(
false,
"--enable-dirichlet");
79 libmesh_example_requires(
sizeof(
Real) > 4,
"--disable-singleprecision");
82 GetPot infile(
"fem_system_ex4.in");
85 infile.parse_command_line(argc, argv);
88 const Real global_tolerance = infile(
"global_tolerance", 0.);
89 const unsigned int nelem_target = infile(
"n_elements", 400);
90 const Real deltat = infile(
"deltat", 0.005);
91 const unsigned int coarsegridsize = infile(
"coarsegridsize", 20);
92 const unsigned int coarserefinements = infile(
"coarserefinements", 0);
93 const unsigned int max_adaptivesteps = infile(
"max_adaptivesteps", 10);
94 const unsigned int dim = infile(
"dimension", 2);
97 libmesh_example_requires(
dim <= LIBMESH_DIM,
"2D/3D support");
146 std::set<boundary_id_type> bcids;
156 for (
auto & elem :
mesh.element_ptr_range())
157 if (elem->dim() <
dim)
158 elem->subdomain_id() = 1;
176 system.
time_solver = std::make_unique<SteadySolver>(system);
179 equation_systems.
init ();
186 solver.
quiet = infile(
"solver_quiet",
true);
201 unsigned int a_step = 0;
202 for (; a_step != max_adaptivesteps; ++a_step)
210 std::unique_ptr<ErrorEstimator> error_estimator;
214 if (global_tolerance != 0.)
218 libmesh_assert_equal_to (nelem_target, 0);
220 auto u = std::make_unique<UniformRefinementEstimator>();
225 error_estimator = std::move(u);
231 libmesh_assert_greater (nelem_target, 0);
237 error_estimator = std::make_unique<KellyErrorEstimator>();
240 error_estimator->estimate_error(system, error);
249 if (global_tolerance != 0.)
254 if (global_tolerance != 0.)
261 if (global_tolerance != 0.)
265 if (global_error < global_tolerance)
276 equation_systems.
reinit();
277 a_step = max_adaptivesteps;
284 equation_systems.
reinit();
288 <<
" active elements and "
294 if (a_step == max_adaptivesteps)
302#ifdef LIBMESH_HAVE_EXODUS_API
304 (
"out.e", equation_systems);
307#ifdef LIBMESH_HAVE_GMV
309 (
"out.gmv", equation_systems);
312#ifdef LIBMESH_HAVE_FPARSER
315 const std::string exact_str = (
dim == 2) ?
316 "sin(pi*x)*sin(pi*y)" :
"sin(pi*x)*sin(pi*y)*sin(pi*z)";
326 libmesh_assert_less(
err, 2e-3);
void add_elements(const std::set< boundary_id_type > &requested_boundary_ids, UnstructuredMesh &boundary_mesh, bool store_parent_side_ids=false, const std::vector< subdomain_id_type > &new_subdomain_ids={})
Generates elements along the boundary of our _mesh, which use pre-existing nodes on the boundary_mesh...
This is a generic class that defines a solver to handle ImplicitSystem classes, including NonlinearIm...
Real absolute_residual_tolerance
The DiffSolver should exit after the residual is reduced to either less than absolute_residual_tolera...
unsigned int max_linear_iterations
Each linear solver step should exit after max_linear_iterations is exceeded.
double initial_linear_tolerance
Any required linear solves will at first be done with this tolerance; the DiffSolver may tighten the ...
Real relative_residual_tolerance
Real relative_step_tolerance
bool verbose
The DiffSolver may print a lot more to libMesh::out if verbose is set to true; default is false.
unsigned int max_nonlinear_iterations
The DiffSolver should exit in failure if max_nonlinear_iterations is exceeded and continue_after_max_...
bool quiet
The DiffSolver should not print anything to libMesh::out unless quiet is set to false; default is tru...
Real deltat
For time-dependent problems, this is the amount delta t to advance the solution in time.
std::unique_ptr< TimeSolver > time_solver
A pointer to the solver object we're going to use.
This is the EquationSystems class.
virtual void reinit()
Handle any mesh changes and reinitialize all the systems on the updated mesh.
void print_info(std::ostream &os=libMesh::out) const
Prints information about the equation systems, by default to libMesh::out.
std::size_t n_active_dofs() const
virtual void init()
Initialize all the systems.
virtual System & add_system(std::string_view system_type, std::string_view name)
Add the system of type system_type named name to the systems array.
The ErrorVector is a specialization of the StatisticsVector for error data computed on a finite eleme...
virtual Real mean() const override
This class handles the computation of the L2 and/or H1 error for the Systems in the EquationSystems o...
Real l2_error(std::string_view sys_name, std::string_view unknown_name)
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...
void compute_error(std::string_view sys_name, std::string_view unknown_name)
Computes and stores the error in the solution value e = u-u_h, the gradient grad(e) = grad(u) - grad(...
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
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.
virtual void solve() override
Invokes the solver associated with the system.
virtual void postprocess() override
Runs a postprocessing loop over all elements, and if postprocess_sides is true over all sides.
This class implements writing meshes in the GMV format.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
void prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
Prepare a newly created (or read) mesh for use.
void print_info(std::ostream &os=libMesh::out, const unsigned int verbosity=0, const bool global=true) const
Prints relevant information about the mesh.
virtual dof_id_type n_active_elem() const =0
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 ...
Implements (adaptive) mesh refinement algorithms for a MeshBase.
void flag_elements_by_error_tolerance(const ErrorVector &error_per_cell)
Flags elements for coarsening and refinement based on the computed error passed in error_per_cell.
Real & absolute_global_tolerance()
If absolute_global_tolerance is set to a nonzero value, methods like flag_elements_by_global_toleranc...
void uniformly_refine(unsigned int n=1)
Uniformly refines the mesh n times.
bool & coarsen_by_parents()
If coarsen_by_parents is true, complete groups of sibling elements (elements with the same parent) wi...
bool flag_elements_by_nelem_target(const ErrorVector &error_per_cell)
Flags elements for coarsening and refinement based on the computed error passed in error_per_cell.
Real & coarsen_threshold()
The coarsen_threshold provides hysteresis in AMR/C strategies.
dof_id_type & nelem_target()
If nelem_target is set to a nonzero value, methods like flag_elements_by_nelem_target() will attempt ...
bool refine_and_coarsen_elements()
Refines and coarsens user-requested elements.
Real & refine_fraction()
The refine_fraction sets either a desired target or a desired maximum number of elements to flag for ...
Real & coarsen_fraction()
The coarsen_fraction sets either a desired target or a desired maximum number of elements to flag for...
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
A Function generated (via FParser) by parsing a mathematical expression.
virtual T maximum() const
virtual Real l2_norm() const
The libMesh namespace provides an interface to certain functionality in the library.
SolverPackage default_solver_package()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real