1 #include <libmesh/dof_map.h>     2 #include <libmesh/elem.h>     3 #include <libmesh/equation_systems.h>     4 #include <libmesh/ghost_point_neighbors.h>     5 #include <libmesh/mesh.h>     6 #include <libmesh/mesh_generation.h>     7 #include <libmesh/mesh_refinement.h>     8 #include <libmesh/remote_elem.h>     9 #include <libmesh/replicated_mesh.h>    10 #include <libmesh/node_elem.h>    26   const Real & x = p(0);
    27   const Real & y = p(1);
    29   return 4*x*y - 3*x + 2*y - 1;
    38   CPPUNIT_TEST( testConstruction );
    39   CPPUNIT_TEST( testAddSystem );
    40   CPPUNIT_TEST( testInit );
    41   CPPUNIT_TEST( testPostInitAddSystem );
    42   CPPUNIT_TEST( testPostInitAddElem );
    43   CPPUNIT_TEST( testReinitWithNodeElem );
    44   CPPUNIT_TEST( testBadVarNames );
    46   CPPUNIT_TEST( testRefineThenReinitPreserveFlags );
    47 #ifdef LIBMESH_ENABLE_AMR // needs project_solution, even for reordering    48   CPPUNIT_TEST( testRepartitionThenReinit );
    49   CPPUNIT_TEST( testSelectivePRefine );
    52   CPPUNIT_TEST( testDisableDefaultGhosting );
    54   CPPUNIT_TEST_SUITE_END();
   147 #ifdef LIBMESH_ENABLE_EXCEPTIONS   158     std::vector<std::string> var_names;
   159     std::set<std::string> system_names = {
"SimpleSystem"};
   169     CPPUNIT_ASSERT_THROW_MESSAGE(
"Duplicate var names not detected",
   173 #endif // LIBMESH_ENABLE_EXCEPTIONS   197 #ifdef LIBMESH_ENABLE_AMR   225         for (
unsigned int c=0; c<elem->
n_children(); c++)
   237 #ifdef LIBMESH_ENABLE_AMR   249     const auto vg = dof_map.var_group_from_var_number(vn);
   250     dof_map.should_p_refine(ug, 
false);
   251     dof_map.should_p_refine(vg, 
true);
   267         std::vector<dof_id_type> dof_indices;
   268         dof_map.dof_indices(elem, dof_indices, un);
   269         CPPUNIT_ASSERT_EQUAL(dof_indices.size(), std::size_t(2));
   270         dof_map.dof_indices(elem, dof_indices, vn);
   271         CPPUNIT_ASSERT_EQUAL(dof_indices.size(), std::size_t(2));
   298     for (
Real x = 0.1; x < 1; x += 0.2)
   299       for (
Real y = 0.1; y < 1; y += 0.2)
   302           LIBMESH_ASSERT_NUMBERS_EQUAL
   316     auto n_ghosts = [&
mesh]() {
   321     auto n_evaluables = [](
System &sys) {
   322       return int(
std::distance(sys.get_dof_map().algebraic_ghosting_functors_begin(),
   323                                sys.get_dof_map().algebraic_ghosting_functors_end()));
   326     auto n_couplings = [](
System &sys) {
   328                                sys.get_dof_map().coupling_functors_end()));
   332     CPPUNIT_ASSERT_EQUAL(n_ghosts(), 1);
   335     auto gpn = std::make_shared<GhostPointNeighbors>(
mesh);
   337     CPPUNIT_ASSERT_EQUAL(n_ghosts(), 2);
   341     CPPUNIT_ASSERT_EQUAL(n_ghosts(), 1);
   345     CPPUNIT_ASSERT_EQUAL(n_ghosts(), 0);
   350     CPPUNIT_ASSERT_EQUAL(n_ghosts(), 0);
   351     CPPUNIT_ASSERT_EQUAL(n_evaluables(sys1), 0);
   352     CPPUNIT_ASSERT_EQUAL(n_couplings(sys1), 0);
   361     CPPUNIT_ASSERT_EQUAL(n_ghosts(), 3);
   362     CPPUNIT_ASSERT_EQUAL(n_evaluables(sys1), 1);
   363     CPPUNIT_ASSERT_EQUAL(n_couplings(sys1), 1);
   368     CPPUNIT_ASSERT_EQUAL(n_ghosts(), 5);
   369     CPPUNIT_ASSERT_EQUAL(n_evaluables(sys2), 1);
   370     CPPUNIT_ASSERT_EQUAL(n_couplings(sys2), 1);
   376     CPPUNIT_ASSERT_EQUAL(n_ghosts(), 6);
   377     CPPUNIT_ASSERT_EQUAL(n_evaluables(sys1), 2);
   378     CPPUNIT_ASSERT_EQUAL(n_couplings(sys1), 1);
   381     auto gpn3 = std::make_shared<GhostPointNeighbors>(
mesh);
   383     CPPUNIT_ASSERT_EQUAL(n_ghosts(), 6);
   384     CPPUNIT_ASSERT_EQUAL(n_evaluables(sys1), 2);
   385     CPPUNIT_ASSERT_EQUAL(n_couplings(sys1), 2);
   390     CPPUNIT_ASSERT_EQUAL(n_ghosts(), 1);
   391     CPPUNIT_ASSERT_EQUAL(n_evaluables(sys1), 1);
   392     CPPUNIT_ASSERT_EQUAL(n_couplings(sys1), 1);
   393     CPPUNIT_ASSERT_EQUAL(n_evaluables(sys2), 0);
   394     CPPUNIT_ASSERT_EQUAL(n_couplings(sys2), 0);
 GhostingFunctorIterator ghosting_functors_begin() const
Beginning of range of ghosting functors. 
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
RefinementState refinement_flag() const
This is the EquationSystems class. 
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
void build_variable_names(std::vector< std::string > &var_names, const FEType *type=nullptr, const std::set< std::string > *system_names=nullptr) const
Fill the input vector var_names with the names of the variables for each system. 
virtual Node *& set_node(const unsigned int i)
void testDisableDefaultGhosting()
This class provides the ability to map between arbitrary, user-defined strings and several data types...
void allow_renumbering(bool allow)
If false is passed in then this mesh will no longer be renumbered when being prepared for use...
void testSelectivePRefine()
libMesh::Parallel::Communicator * TestCommWorld
static constexpr Real TOLERANCE
bool refine_elements()
Only refines the user-requested elements. 
void prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
Prepare a newly ecreated (or read) mesh for use. 
void testPostInitAddRealSystem()
void testPostInitAddElem()
void remove_ghosting_functor(GhostingFunctor &ghosting_functor)
Removes a functor which was previously added to the set of ghosting functors. 
This is the base class from which all geometric element types are derived. 
void disable_refine_in_reinit()
Calls to reinit() will not try to coarsen or refine the mesh. 
void set_refinement_flag(const RefinementState rflag)
Sets the value of the refinement flag for the element. 
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
virtual void enable_default_ghosting(bool enable)
Enable or disable default ghosting functors on the Mesh and on all Systems. 
virtual unsigned int n_children() const =0
GhostingFunctorIterator ghosting_functors_end() const
End of range of ghosting functors. 
The libMesh namespace provides an interface to certain functionality in the library. 
Real distance(const Point &p)
void add_coupling_functor(GhostingFunctor &coupling_functor, bool to_mesh=true)
Adds a functor which can specify coupling requirements for creation of sparse matrices. 
unsigned int var_group_from_var_number(unsigned int var_num) const
virtual void partition(const unsigned int n_parts)
Call the default partitioner (currently metis_partition()). 
void switch_h_to_p_refinement()
Takes a mesh whose elements are flagged for h refinement and coarsening, and switches those flags to ...
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr) const
Projects arbitrary functions onto the current solution. 
void testReinitWithNodeElem()
Implements (adaptive) mesh refinement algorithms for a MeshBase. 
void testRefineThenReinitPreserveFlags()
void testRepartitionThenReinit()
Manages consistently variables, degrees of freedom, and coefficient vectors. 
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array. 
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
virtual void reinit()
Handle any mesh changes and reinitialize all the systems on the updated mesh. 
void testPostInitAddSystem()
virtual dof_id_type max_elem_id() const =0
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. 
virtual const Elem * elem_ptr(const dof_id_type i) const =0
CPPUNIT_TEST_SUITE_REGISTRATION(EquationSystemsTest)
const FEType & variable_type(const unsigned int i) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual const Elem * query_elem_ptr(const dof_id_type i) const =0
A class to represent the internal "this should never happen" errors, to be thrown by "libmesh_error()...
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 ...
Parameters parameters
Data structure holding arbitrary parameters. 
virtual void init()
Initialize all the systems. 
virtual dof_id_type n_elem() const =0
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. 
virtual const Node * node_ptr(const dof_id_type i) const =0
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...
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default. 
const DofMap & get_dof_map() const
processor_id_type processor_id() const
A Point defines a location in LIBMESH_DIM dimensional Real space. 
void ErrorVector unsigned int
This class implements the original default geometry ghosting requirements in libMesh: point neighbors...
const Elem * child_ptr(unsigned int i) const
void add_ghosting_functor(GhostingFunctor &ghosting_functor)
Adds a functor which can specify ghosting requirements for use on distributed meshes. 
const RemoteElem * remote_elem