26#include "libmesh/libmesh.h"
27#include "libmesh/dof_map.h"
28#include "libmesh/enum_norm_type.h"
29#include "libmesh/equation_systems.h"
30#include "libmesh/getpot.h"
31#include "libmesh/mesh.h"
32#include "libmesh/mesh_tools.h"
33#include "libmesh/newton_solver.h"
34#include "libmesh/numeric_vector.h"
35#include "libmesh/parsed_fem_function.h"
36#include "libmesh/parsed_function.h"
37#include "libmesh/point.h"
38#include "libmesh/sparse_matrix.h"
39#include "libmesh/steady_solver.h"
40#include "libmesh/wrapped_functor.h"
41#include "libmesh/elem.h"
42#include "libmesh/parallel_implementation.h"
43#include "libmesh/string_to_enum.h"
46#include "libmesh/error_vector.h"
47#include "libmesh/exact_solution.h"
48#include "libmesh/discontinuity_measure.h"
49#include "libmesh/kelly_error_estimator.h"
50#include "libmesh/fourth_error_estimators.h"
64 <<
" --dim d mesh dimension [default: autodetect]\n"
65 <<
" --inmesh filename input mesh file\n"
66 <<
" --inmat filename input constraint matrix [default: none]\n"
67 <<
" --mattol filename constraint tolerance when testing mesh connectivity\n"
69 <<
" --insoln filename input solution file\n"
70 <<
" --calc func function to calculate\n"
71 <<
" --insys sysnum input system number [default: 0]\n"
72 <<
" --outsoln filename output solution file [default: out_<insoln>]\n"
73 <<
" --family famname output FEM family [default: LAGRANGE]\n"
74 <<
" --order p output FEM order [default: 1]\n"
75 <<
" --subdomain \"sbd_ids\" each subdomain to check [default: all subdomains]\n"
76 <<
" --hilbert order Hilbert space to project in [default: 0 => H0]\n"
77 <<
" --fdm_eps eps Central diff for dfunc/dx [default: " <<
TOLERANCE <<
"]\n"
78 <<
" --error_q extra_q integrate projection error, with adjusted\n"
79 <<
" (extra) quadrature order [default: off, suggested: 0]\n"
80 <<
" --jump_error order calculate jump error indicator, for specified\n"
81 <<
" Hilbert order [default: off]\n"
82 <<
" --jump_slits calculate jumps across slits [default: off]\n"
83 <<
" --integral only calculate func integral, not projection\n"
92 const char * progname,
97 libMesh::err << (
"No " + argname +
" argument found!") << std::endl;
115 FEBase * elem_fe =
nullptr;
118 const std::vector<Real> & JxW = elem_fe->
get_JxW();
119 const std::vector<Point> & xyz = elem_fe->
get_xyz();
121 _f->init_context(context);
130 for (
const auto & elem : range)
132 if (elem->dim() < mesh_dim)
140 const Number output = (*_f)(context, xyz[qp]);
157 std::unique_ptr<FEMFunctionBase<Number>>
_f;
163int main(
int argc,
char ** argv)
169 const unsigned char requested_dim =
175 Mesh old_mesh(init.comm(), requested_dim);
177 const std::string meshname =
180 libMesh::out <<
"Reading mesh " << meshname << std::endl;
181 old_mesh.
read(meshname);
183 const std::string matname =
188 libMesh::out <<
"Reading matrix " << matname << std::endl;
194 matrix->read(matname);
195 matrix->get_transpose(*matrix);
211 libMesh::out <<
"Mesh has " << n_components <<
" connected components." << std::endl;
214 const std::string solnname =
222 const std::string calcfunc =
225 const std::string family =
230 std::unique_ptr<FEMFunctionBase<Number>> goal_function;
234 libMesh::out <<
"Reading solution " << solnname << std::endl;
236 old_es.
read(solnname,
244 const unsigned int sysnum =
247 libmesh_assert_less(sysnum, old_es.
n_systems());
254 std::make_unique<ParsedFEMFunction<Number>>(old_sys, calcfunc);
267 Utility::string_to_enum<FEFamily>(family));
280 std::vector<libMesh::subdomain_id_type> subdomain_vec;
282 std::set<libMesh::subdomain_id_type> subdomains_list(subdomain_vec.begin(),
283 subdomain_vec.end());
285 std::string default_outsolnname =
"out_soln.xda";
287 default_outsolnname =
"out_"+solnname;
288 const std::string outsolnname =
292 libMesh::out << std::setprecision(std::numeric_limits<Real>::max_digits10);
297 Mesh new_mesh(init.comm(), requested_dim);
298 new_mesh.
read(meshname);
309 std::make_unique<SteadySolver>(new_sys);
326 solver.
quiet =
false;
335 const unsigned int error_q =
374 const unsigned int jump_error_hilbert =
379 std::unique_ptr<JumpErrorEstimator> error_estimator;
385 if (jump_error_hilbert == 0)
387 error_estimator = std::make_unique<DiscontinuityMeasure>();
390 else if (jump_error_hilbert == 1)
392 error_estimator = std::make_unique<KellyErrorEstimator>();
395 else if (jump_error_hilbert == 2)
397 error_estimator = std::make_unique<LaplacianErrorEstimator>();
401 libmesh_not_implemented();
404 error_estimator->integrate_slits =
true;
407 error_estimator->error_norm = error_norm;
408 error_estimator->estimate_error(new_sys, error_per_cell);
416 for (
auto cell_error : error_per_cell)
417 total_error += cell_error;
419 if (jump_error_hilbert == 0)
424 libMesh::out <<
" error estimate for " << var_name <<
": " <<
425 total_error << std::endl;
430 new_es.
write(outsolnname.c_str(),
433 libMesh::out <<
"Wrote solution " << outsolnname << std::endl;
441 (old_mesh.active_local_elements_begin(),
442 old_mesh.active_local_elements_end());
444 Integrate integrate(old_sys, *goal_function);
451 libMesh::out <<
"Integral is " << integral << std::endl;
void usage_error(const char *progname)
T assert_argument(const std::string &argname, const char *progname, const T &defaultarg)
std::set< libMesh::subdomain_id_type > & subdomains_list()
libMesh::System * input_system
void set_fdm_eps(libMesh::Real eps)
void set_goal_func(libMesh::FEMFunctionBase< libMesh::Number > &goal)
unsigned int & fe_order()
std::string & fe_family()
unsigned int & hilbert_order()
This is a generic class that defines a solver to handle ImplicitSystem classes, including NonlinearIm...
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.
bool quiet
The DiffSolver should not print anything to libMesh::out unless quiet is set to false; default is tru...
std::unique_ptr< TimeSolver > time_solver
A pointer to the solver object we're going to use.
virtual bool is_serial_on_zero() const override final
This is the EquationSystems class.
void print_info(std::ostream &os=libMesh::out) const
Prints information about the equation systems, by default to libMesh::out.
void write(std::string_view name, const XdrMODE, const unsigned int write_flags=(WRITE_DATA), bool partition_agnostic=true) const
Write the systems to disk using the XDR data format.
unsigned int n_systems() const
void read(std::string_view name, const XdrMODE, const unsigned int read_flags=(READ_HEADER|READ_DATA), bool partition_agnostic=true)
Read & initialize the systems from disk using the XDR data format.
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.
const T_sys & get_system(std::string_view name) const
The ErrorVector is a specialization of the StatisticsVector for error data computed on a finite eleme...
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)
Real h1_error(std::string_view sys_name, std::string_view unknown_name)
void attach_exact_deriv(unsigned int sys_num, FunctionBase< Gradient > *g)
Clone and attach an arbitrary functor which computes the exact gradient of the system sys_num solutio...
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(...
void extra_quadrature_order(const int extraorder)
Increases or decreases the order of the quadrature rule used for numerical integration.
virtual_for_inffe const std::vector< Real > & get_JxW() const
virtual_for_inffe const std::vector< Point > & get_xyz() const
This class forms the foundation from which generic finite elements may be derived.
This class provides all data required for a physics package (e.g.
virtual void pre_fe_reinit(const System &, const Elem *e)
Reinitializes local data vectors/matrices on the current geometric element.
virtual void elem_fe_reinit(const std::vector< Point > *const pts=nullptr)
Reinitializes interior FE objects on the current geometric element.
void get_element_fe(unsigned int var, FEGenericBase< OutputShape > *&fe) const
Accessor for interior finite element object for variable var for the largest dimension in the mesh.
FEMFunctionBase is a base class from which users can derive in order to define "function-like" object...
virtual void solve() override
Invokes the solver associated with the system.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
unsigned int mesh_dimension() const
void copy_constraint_rows(const MeshBase &other_mesh)
Copy the constraints from the other mesh to this mesh.
void print_info(std::ostream &os=libMesh::out, const unsigned int verbosity=0, const bool global=true) const
Prints relevant information about the mesh.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
const Parallel::Communicator & comm() const
A Function generated (via FParser) by parsing a mathematical expression.
static std::unique_ptr< SparseMatrix< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package(), const MatrixBuildType matrix_build_type=MatrixBuildType::AUTOMATIC)
Builds a SparseMatrix<T> using the linear solver package specified by solver_package.
The StoredRange class defines a contiguous, divisible set of objects.
This class defines a norm/seminorm to be applied to a NumericVector which contains coefficients in a ...
void set_type(unsigned int var, const FEMNormType &t)
Sets the type of the norm in variable var, as well as for any unset variables with index less than va...
void set_weight(unsigned int var, Real w)
Sets the weight corresponding to the norm in variable var, as well as for any unset variables with in...
Manages consistently variables, degrees of freedom, and coefficient vectors.
const std::string & name() const
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.
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
const std::string & variable_name(const unsigned int i) const
Real calculate_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=nullptr) const
unsigned int n_vars() const
const MeshBase & get_mesh() const
Dummy "splitting object" used to distinguish splitting constructors from copy constructors.
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false, bool skip_detect_interior_parents=false) override
Reads the file specified by name.
void parallel_reduce(const Range &range, Body &body, unsigned int n_threads=libMesh::n_threads())
Execute the provided reduction operation in parallel on the specified range.
The libMesh namespace provides an interface to certain functionality in the library.
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
void command_line_vector(const std::string &, std::vector< T > &)
T command_line_next(std::string name, T default_value)
Use GetPot's search()/next() functions to get following arguments from the command line.
static constexpr Real TOLERANCE
bool on_command_line(std::string arg)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
std::string current_sys_name
Integrate(Integrate &other, Threads::split)
std::unique_ptr< FEMFunctionBase< Number > > _f
void operator()(const ConstElemRange &range)
Integrate(const System &sys, const FEMFunctionBase< Number > &f)
void join(const Integrate &other)