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;
107 _sys(sys), _f(f.clone()), _integral(0) {}
110 _sys(other._sys), _f(other._f->clone()), _integral(0) {}
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);
128 const unsigned int mesh_dim = _sys.get_mesh().mesh_dimension();
130 for (
const auto & elem : range)
132 if (elem->dim() < mesh_dim)
140 const Number output = (*_f)(context, xyz[qp]);
142 _integral += output * JxW[qp];
157 std::unique_ptr<FEMFunctionBase<Number>>
_f;
163 int 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);
197 old_mesh.copy_constraint_rows(*matrix);
201 old_mesh.print_info();
204 if (old_mesh.is_serial_on_zero())
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);
266 dummy_sys.
add_variable(
"dummy", static_cast<Order>(order),
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 libMesh::out <<
"H" << jump_error_hilbert <<
" error estimate for " << var_name <<
": " <<
420 total_error << std::endl;
425 new_es.
write(outsolnname.c_str(),
428 libMesh::out <<
"Wrote solution " << outsolnname << std::endl;
436 (old_mesh.active_local_elements_begin(),
437 old_mesh.active_local_elements_end());
439 Integrate integrate(old_sys, *goal_function);
444 Number integral = integrate.integral();
445 old_mesh.comm().sum(integral);
446 libMesh::out <<
"Integral is " << integral << std::endl;
This class handles the computation of the L2 and/or H1 error for the Systems in the EquationSystems o...
T command_line_next(std::string name, T default_value)
Use GetPot's search()/next() functions to get following arguments from the command line...
std::set< libMesh::subdomain_id_type > & subdomains_list()
This is the EquationSystems class.
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
virtual void pre_fe_reinit(const System &, const Elem *e)
Reinitializes local data vectors/matrices on the current geometric element.
A Function generated (via FParser) by parsing a mathematical expression.
bool quiet
The DiffSolver should not print anything to libMesh::out unless quiet is set to false; default is tru...
static constexpr Real TOLERANCE
void join(const Integrate &other)
The ErrorVector is a specialization of the StatisticsVector for error data computed on a finite eleme...
Dummy "splitting object" used to distinguish splitting constructors from copy constructors.
std::unique_ptr< TimeSolver > time_solver
A pointer to the solver object we're going to use.
void print_info(std::ostream &os=libMesh::out) const
Prints information about the equation systems, by default to libMesh::out.
void extra_quadrature_order(const int extraorder)
Increases or decreases the order of the quadrature rule used for numerical integration.
This class defines a norm/seminorm to be applied to a NumericVector which contains coefficients in a ...
The StoredRange class defines a contiguous, divisible set of objects.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
The libMesh namespace provides an interface to certain functionality in the library.
const T_sys & get_system(std::string_view name) const
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
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.
virtual void elem_fe_reinit(const std::vector< Point > *const pts=nullptr)
Reinitializes interior FE objects on the current geometric element.
This is a generic class that defines a solver to handle ImplicitSystem classes, including NonlinearIm...
void set_goal_func(libMesh::FEMFunctionBase< libMesh::Number > &goal)
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...
T assert_argument(const std::string &argname, const char *progname, const T &defaultarg)
Integrate(const System &sys, const FEMFunctionBase< Number > &f)
Manages consistently variables, degrees of freedom, and coefficient vectors.
Integrate(Integrate &other, Threads::split)
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(...
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Real calculate_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=nullptr) const
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
virtual_for_inffe const std::vector< Real > & get_JxW() const
This class provides all data required for a physics package (e.g.
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.
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.
const std::string & variable_name(const unsigned int i) const
std::string & fe_family()
virtual_for_inffe const std::vector< Point > & get_xyz() const
Real l2_error(std::string_view sys_name, std::string_view unknown_name)
unsigned int & fe_order()
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...
bool verbose
The DiffSolver may print a lot more to libMesh::out if verbose is set to true; default is false...
unsigned int & hilbert_order()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
libMesh::System * input_system
std::string current_sys_name
void command_line_vector(const std::string &, std::vector< T > &)
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...
void parallel_reduce(const Range &range, Body &body)
Execute the provided reduction operation in parallel on the specified range.
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...
virtual void solve() override
Invokes the solver associated with the system.
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...
bool on_command_line(std::string arg)
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...
virtual void init()
Initialize all the systems.
unsigned int n_vars() const
std::unique_ptr< FEMFunctionBase< Number > > _f
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false) override
Reads the file specified by name.
int main(int argc, char **argv)
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 Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Real h1_error(std::string_view sys_name, std::string_view unknown_name)
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
This class forms the foundation from which generic finite elements may be derived.
void set_fdm_eps(libMesh::Real eps)
Real relative_step_tolerance
void usage_error(const char *progname)