1#include <libmesh/equation_systems.h>
2#include <libmesh/mesh.h>
3#include <libmesh/mesh_generation.h>
4#include <libmesh/edge_edge2.h>
5#include <libmesh/face_quad4.h>
6#include <libmesh/cell_hex8.h>
7#include <libmesh/dof_map.h>
8#include <libmesh/linear_implicit_system.h>
9#include <libmesh/mesh_refinement.h>
11#include <libmesh/discontinuity_measure.h>
12#include <libmesh/error_vector.h>
13#include <libmesh/overlap_coupling.h>
31 virtual std::unique_ptr<FEMFunctionBase<Number>>
34 return std::make_unique<SlitFunc>();
39 const Real = 0.)
override
43 const Real & x = p(0);
44 const Real & y = p(1);
46 const Real sign = centroid(1)/std::abs(centroid(1));
50 return (abs(x) + abs(2-x) - 2*abs(1-x)) * (1-abs(y)) * sign;
58 for (
unsigned int i=0; i != output.
size(); ++i)
59 output(i) = (*this)(c, p, time);
108 _mesh->set_mesh_dimension(2);
179 _mesh->allow_renumbering(
false);
181 _mesh->prepare_for_use();
206 if (
_mesh->query_elem_ptr(0) &&
_mesh->query_elem_ptr(1))
207 CPPUNIT_ASSERT(
_mesh->elem_ref(0).node_id(1) !=
_mesh->elem_ref(1).node_id(2) );
208 if (
_mesh->query_elem_ptr(2) &&
_mesh->query_elem_ptr(3))
209 CPPUNIT_ASSERT(
_mesh->elem_ref(2).node_id(0) !=
_mesh->elem_ref(3).node_id(3) );
213 if (
_mesh->query_elem_ptr(0) &&
_mesh->query_elem_ptr(2))
214 CPPUNIT_ASSERT_EQUAL(
_mesh->elem_ref(0).node_id(1),
215 _mesh->elem_ref(2).node_id(0) );
216 if (
_mesh->query_elem_ptr(1) &&
_mesh->query_elem_ptr(3))
217 CPPUNIT_ASSERT_EQUAL(
_mesh->elem_ref(1).node_id(2),
218 _mesh->elem_ref(3).node_id(3) );
247#ifdef LIBMESH_ENABLE_AMR
257#ifdef LIBMESH_ENABLE_AMR
282#ifdef LIBMESH_ENABLE_UNIQUE_ID
292 std::unique_ptr<EquationSystems>
_es;
303 _mesh->allow_renumbering(
true);
305 _es = std::make_unique<EquationSystems>(*
_mesh);
313 (std::make_shared<OverlapCoupling>());
314 _mesh->delete_remote_elements();
320#ifdef LIBMESH_ENABLE_AMR
335#ifdef LIBMESH_ENABLE_AMR
338 CPPUNIT_ASSERT_EQUAL(
static_cast<dof_id_type>(128),
_mesh->n_active_elem());
351 unsigned int dim = 2;
358 const std::vector<Point> & xyz = fe->
get_xyz();
361 for (
const auto & elem :
_mesh->active_local_element_ptr_range())
366 const unsigned int n_qp = xyz.size();
368 for (
unsigned int qp=0; qp != n_qp; ++qp)
370 const Number exact_val = slitfunc(context, xyz[qp]);
374 LIBMESH_ASSERT_NUMBERS_EQUAL
384 const Real mean_connected_disc = connected_err.
mean();
385 CPPUNIT_ASSERT_LESS(
Real(1e-14), mean_connected_disc);
392 const Real mean_slit_disc = slit_disc.
mean();
393 CPPUNIT_ASSERT_GREATER(
Real(1e-3), mean_slit_disc);
402 _mesh->write(
"slit_mesh.xda");
403 _es->write(
"slit_solution.xda",
408 mesh2.
read(
"slit_mesh.xda");
410 es2.
read(
"slit_solution.xda");
414 unsigned int dim = 2;
416 CPPUNIT_ASSERT_EQUAL( sys2.
n_vars(), 1u );
421 const std::vector<Point> & xyz = fe->
get_xyz();
426 std::unique_ptr<PointLocatorBase> locator =
_mesh->sub_point_locator();
428 if (!
_mesh->is_serial())
429 locator->enable_out_of_mesh_mode();
431 for (
const auto & elem : mesh2.active_local_element_ptr_range())
433 const Elem * mesh1_elem = (*locator)(elem->vertex_average());
436 CPPUNIT_ASSERT_EQUAL( elem->unique_id(),
439 for (
unsigned int n=0; n != elem->n_nodes(); ++n)
441 const Node & node = elem->node_ref(n);
451 const unsigned int n_qp = xyz.size();
453 for (
unsigned int qp=0; qp != n_qp; ++qp)
455 const Number exact_val = slitfunc(context, xyz[qp]);
459 LIBMESH_ASSERT_NUMBERS_EQUAL
virtual void init_context(const FEMContext &) override
Prepares a context object for use.
virtual std::unique_ptr< FEMFunctionBase< Number > > clone() const override
virtual Number operator()(const FEMContext &c, const Point &p, const Real=0.) override
LIBMESH_CPPUNIT_TEST_SUITE(SlitMeshRefinedMeshTest)
The goal of this test is the same as the previous, but now we do a uniform refinement and make sure t...
std::unique_ptr< EquationSystems > _es
CPPUNIT_TEST(testRestart)
LIBMESH_CPPUNIT_TEST_SUITE(SlitMeshRefinedSystemTest)
The goal of this test is the same as the previous, but now we create a system and set dof values to m...
std::unique_ptr< Mesh > _mesh
LIBMESH_CPPUNIT_TEST_SUITE(SlitMeshTest)
The goal of this test is to ensure that a 2D mesh with nodes overlapping on opposite sides of an inte...
Defines a dense vector for use in Finite Element-type computations.
virtual unsigned int size() const override final
This class measures discontinuities between elements for debugging purposes.
void add_algebraic_ghosting_functor(GhostingFunctor &evaluable_functor, bool to_mesh=true)
Adds a functor which can specify algebraic ghosting requirements for use with distributed vectors.
unique_id_type unique_id() const
This is the base class from which all geometric element types are derived.
virtual Node *& set_node(const unsigned int i)
const Node & node_ref(const unsigned int i) const
static std::unique_ptr< Elem > build_with_id(const ElemType type, dof_id_type id)
Calls the build() method above with a nullptr parent, and additionally sets the newly-created Elem's ...
Point vertex_average() const
This is the EquationSystems class.
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.
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...
virtual Real mean() const override
virtual_for_inffe const std::vector< Point > & get_xyz() const
This class forms the foundation from which generic finite elements may be derived.
const std::vector< std::vector< OutputShape > > & get_phi() const
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.
Number interior_value(unsigned int var, unsigned int qp) const
const Elem & get_elem() const
Accessor for current Elem object.
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...
bool integrate_slits
A boolean flag, by default false, to be set to true if integrations should be performed on "slits" wh...
virtual void estimate_error(const System &system, ErrorVector &error_per_cell, const NumericVector< Number > *solution_vector=nullptr, bool estimate_parent_error=false) override
This function uses the derived class's jump error estimate formula to estimate the error on each cell...
Implements (adaptive) mesh refinement algorithms for a MeshBase.
void uniformly_refine(unsigned int n=1)
Uniformly refines the mesh n times.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
A Node is like a Point, but with more information.
A Point defines a location in LIBMESH_DIM dimensional Real space.
Manages consistently variables, degrees of freedom, and coefficient vectors.
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, std::optional< ConstElemRange > active_local_range=std::nullopt, std::optional< std::vector< unsigned int > > variable_numbers=std::nullopt) const
Projects arbitrary functions onto the current solution.
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.
unsigned int n_vars() const
const DofMap & get_dof_map() const
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.
Communicator * TestCommWorld
The libMesh namespace provides an interface to certain functionality in the library.
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
CPPUNIT_TEST_SUITE_REGISTRATION(SlitMeshTest)