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;
47#ifdef LIBMESH_ENABLE_AMR
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",
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) {
327 return int(std::distance(sys.get_dof_map().coupling_functors_begin(),
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);
void ErrorVector unsigned int
CPPUNIT_TEST(testRepartitionThenReinit)
void testDisableDefaultGhosting()
CPPUNIT_TEST(testSelectivePRefine)
CPPUNIT_TEST(testPostInitAddElem)
CPPUNIT_TEST(testDisableDefaultGhosting)
void testRefineThenReinitPreserveFlags()
void testPostInitAddSystem()
LIBMESH_CPPUNIT_TEST_SUITE(EquationSystemsTest)
void testSelectivePRefine()
CPPUNIT_TEST(testReinitWithNodeElem)
void testPostInitAddElem()
CPPUNIT_TEST(testAddSystem)
CPPUNIT_TEST(testRefineThenReinitPreserveFlags)
void testRepartitionThenReinit()
void testReinitWithNodeElem()
CPPUNIT_TEST(testBadVarNames)
CPPUNIT_TEST(testPostInitAddSystem)
CPPUNIT_TEST(testConstruction)
void testPostInitAddRealSystem()
unsigned int var_group_from_var_number(unsigned int var_num) const
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.
void add_coupling_functor(GhostingFunctor &coupling_functor, bool to_mesh=true)
Adds a functor which can specify coupling requirements for creation of sparse matrices.
processor_id_type processor_id() const
This is the base class from which all geometric element types are derived.
virtual Node *& set_node(const unsigned int i)
RefinementState refinement_flag() 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 ...
const Elem * child_ptr(unsigned int i) const
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
virtual unsigned int n_children() const =0
void set_refinement_flag(const RefinementState rflag)
Sets the value of the refinement flag for the element.
This is the EquationSystems class.
virtual void reinit()
Handle any mesh changes and reinitialize all the systems on the updated mesh.
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.
Parameters parameters
Data structure holding arbitrary parameters.
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.
virtual void enable_default_ghosting(bool enable)
Enable or disable default ghosting functors on the Mesh and on all Systems.
void disable_refine_in_reinit()
Calls to reinit() will not try to coarsen or refine the mesh.
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
This class implements the original default geometry ghosting requirements in libMesh: point neighbors...
A class to represent the internal "this should never happen" errors, to be thrown by "libmesh_error()...
virtual const Node * node_ptr(const dof_id_type i) const =0
virtual dof_id_type n_elem() const =0
void allow_renumbering(bool allow)
If false is passed in then this mesh will no longer be renumbered when being prepared for use.
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 remove_ghosting_functor(GhostingFunctor &ghosting_functor)
Removes a functor which was previously added to the set of ghosting functors.
GhostingFunctorIterator ghosting_functors_begin() const
Beginning of range of ghosting functors.
virtual const Elem * elem_ptr(const dof_id_type i) const =0
virtual dof_id_type max_elem_id() const =0
virtual const Elem * query_elem_ptr(const dof_id_type i) const =0
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
GhostingFunctorIterator ghosting_functors_end() const
End of range of ghosting functors.
void add_ghosting_functor(GhostingFunctor &ghosting_functor)
Adds a functor which can specify ghosting requirements for use on distributed meshes.
virtual void partition(const unsigned int n_parts)
Call the default partitioner (currently metis_partition()).
Implements (adaptive) mesh refinement algorithms for a MeshBase.
void switch_h_to_p_refinement()
Takes a mesh whose elements are flagged for h refinement and coarsening, and switches those flags to ...
bool refine_elements()
Only refines the user-requested elements.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
This class provides the ability to map between arbitrary, user-defined strings and several data types...
A Point defines a location in LIBMESH_DIM dimensional Real space.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
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.
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
const FEType & variable_type(const unsigned int i) 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.
const DofMap & get_dof_map() const
Communicator * TestCommWorld
CPPUNIT_TEST_SUITE_REGISTRATION(EquationSystemsTest)
The libMesh namespace provides an interface to certain functionality in the library.
const RemoteElem * remote_elem
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real