libMesh
Public Member Functions | Private Member Functions | List of all members
SystemsTest Class Reference
Inheritance diagram for SystemsTest:
[legend]

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (SystemsTest)
 
 CPPUNIT_TEST (test100KVariables)
 
 CPPUNIT_TEST (testPostInitAddVector)
 
 CPPUNIT_TEST (testAddVectorProjChange)
 
 CPPUNIT_TEST (testAddVectorTypeChange)
 
 CPPUNIT_TEST (testPostInitAddVectorTypeChange)
 
 CPPUNIT_TEST (testProjectHierarchicEdge3)
 
 CPPUNIT_TEST (testProjectHierarchicQuad9)
 
 CPPUNIT_TEST (testProjectHierarchicTri6)
 
 CPPUNIT_TEST (testProjectHierarchicTri7)
 
 CPPUNIT_TEST (test2DProjectVectorFETri3)
 
 CPPUNIT_TEST (test2DProjectVectorFEQuad4)
 
 CPPUNIT_TEST (test2DProjectVectorFETri6)
 
 CPPUNIT_TEST (test2DProjectVectorFETri7)
 
 CPPUNIT_TEST (test2DProjectVectorFEQuad8)
 
 CPPUNIT_TEST (test2DProjectVectorFEQuad9)
 
 CPPUNIT_TEST (testBlockRestrictedVarNDofs)
 
 CPPUNIT_TEST (testProjectHierarchicHex27)
 
 CPPUNIT_TEST (testProjectMeshFunctionHex27)
 
 CPPUNIT_TEST (testBoundaryProjectCube)
 
 CPPUNIT_TEST (test3DProjectVectorFETet4)
 
 CPPUNIT_TEST (test3DProjectVectorFEHex8)
 
 CPPUNIT_TEST (test3DProjectVectorFETet10)
 
 CPPUNIT_TEST (test3DProjectVectorFETet14)
 
 CPPUNIT_TEST (test3DProjectVectorFEHex20)
 
 CPPUNIT_TEST (test3DProjectVectorFEHex27)
 
 CPPUNIT_TEST (testSetSystemParameterOverEquationSystem)
 
 CPPUNIT_TEST (testAssemblyWithDgFemContext)
 
 CPPUNIT_TEST (testDofCouplingWithVarGroups)
 
 CPPUNIT_TEST (testProjectMatrixEdge2)
 
 CPPUNIT_TEST (testProjectMatrixQuad4)
 
 CPPUNIT_TEST (testProjectMatrixTri3)
 
 CPPUNIT_TEST (testProjectMatrixHex8)
 
 CPPUNIT_TEST (testProjectMatrixTet4)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
ExplicitSystemsimpleSetup (UnstructuredMesh &mesh, EquationSystems &es)
 
void test100KVariables ()
 
void testPostInitAddVector ()
 
void testAddVectorProjChange ()
 
void testAddVectorTypeChange ()
 
void testPostInitAddVectorTypeChange ()
 
void testProjectLine (const ElemType elem_type)
 
void test2DProjectVectorFE (const ElemType elem_type)
 
void test3DProjectVectorFE (const ElemType elem_type)
 
void testProjectSquare (const ElemType elem_type)
 
void testProjectCube (const ElemType elem_type)
 
void testProjectCubeWithMeshFunction (const ElemType elem_type)
 
void testBoundaryProjectCube ()
 
void testDofCouplingWithVarGroups ()
 
void testSetSystemParameterOverEquationSystem ()
 
void testAssemblyWithDgFemContext ()
 
void testBlockRestrictedVarNDofs ()
 
void testProjectMatrix1D (const ElemType elem_type)
 
void testProjectMatrix2D (const ElemType elem_type)
 
void testProjectMatrix3D (const ElemType elem_type)
 
void testProjectHierarchicEdge3 ()
 
void testProjectHierarchicQuad9 ()
 
void testProjectHierarchicTri6 ()
 
void testProjectHierarchicTri7 ()
 
void testProjectHierarchicHex27 ()
 
void testProjectMeshFunctionHex27 ()
 
void test2DProjectVectorFETri3 ()
 
void test2DProjectVectorFEQuad4 ()
 
void test2DProjectVectorFETri6 ()
 
void test2DProjectVectorFETri7 ()
 
void test2DProjectVectorFEQuad8 ()
 
void test2DProjectVectorFEQuad9 ()
 
void test3DProjectVectorFETet4 ()
 
void test3DProjectVectorFEHex8 ()
 
void test3DProjectVectorFETet10 ()
 
void test3DProjectVectorFETet14 ()
 
void test3DProjectVectorFEHex20 ()
 
void test3DProjectVectorFEHex27 ()
 
void testProjectMatrixEdge2 ()
 
void testProjectMatrixQuad4 ()
 
void testProjectMatrixTri3 ()
 
void testProjectMatrixHex8 ()
 
void testProjectMatrixTet4 ()
 

Private Member Functions

void tripleValueTest (const Point &p, const TransientExplicitSystem &sys, const PointLocatorBase &locator, std::set< subdomain_id_type > &u_subdomains, std::set< subdomain_id_type > &v_subdomains, std::set< subdomain_id_type > &w_subdomains, const Parameters &param)
 

Detailed Description

Definition at line 437 of file systems_test.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/33]

SystemsTest::CPPUNIT_TEST ( test100KVariables  )

◆ CPPUNIT_TEST() [2/33]

SystemsTest::CPPUNIT_TEST ( testPostInitAddVector  )

◆ CPPUNIT_TEST() [3/33]

SystemsTest::CPPUNIT_TEST ( testAddVectorProjChange  )

◆ CPPUNIT_TEST() [4/33]

SystemsTest::CPPUNIT_TEST ( testAddVectorTypeChange  )

◆ CPPUNIT_TEST() [5/33]

SystemsTest::CPPUNIT_TEST ( testPostInitAddVectorTypeChange  )

◆ CPPUNIT_TEST() [6/33]

SystemsTest::CPPUNIT_TEST ( testProjectHierarchicEdge3  )

◆ CPPUNIT_TEST() [7/33]

SystemsTest::CPPUNIT_TEST ( testProjectHierarchicQuad9  )

◆ CPPUNIT_TEST() [8/33]

SystemsTest::CPPUNIT_TEST ( testProjectHierarchicTri6  )

◆ CPPUNIT_TEST() [9/33]

SystemsTest::CPPUNIT_TEST ( testProjectHierarchicTri7  )

◆ CPPUNIT_TEST() [10/33]

SystemsTest::CPPUNIT_TEST ( test2DProjectVectorFETri3  )

◆ CPPUNIT_TEST() [11/33]

SystemsTest::CPPUNIT_TEST ( test2DProjectVectorFEQuad4  )

◆ CPPUNIT_TEST() [12/33]

SystemsTest::CPPUNIT_TEST ( test2DProjectVectorFETri6  )

◆ CPPUNIT_TEST() [13/33]

SystemsTest::CPPUNIT_TEST ( test2DProjectVectorFETri7  )

◆ CPPUNIT_TEST() [14/33]

SystemsTest::CPPUNIT_TEST ( test2DProjectVectorFEQuad8  )

◆ CPPUNIT_TEST() [15/33]

SystemsTest::CPPUNIT_TEST ( test2DProjectVectorFEQuad9  )

◆ CPPUNIT_TEST() [16/33]

SystemsTest::CPPUNIT_TEST ( testBlockRestrictedVarNDofs  )

◆ CPPUNIT_TEST() [17/33]

SystemsTest::CPPUNIT_TEST ( testProjectHierarchicHex27  )

◆ CPPUNIT_TEST() [18/33]

SystemsTest::CPPUNIT_TEST ( testProjectMeshFunctionHex27  )

◆ CPPUNIT_TEST() [19/33]

SystemsTest::CPPUNIT_TEST ( testBoundaryProjectCube  )

◆ CPPUNIT_TEST() [20/33]

SystemsTest::CPPUNIT_TEST ( test3DProjectVectorFETet4  )

◆ CPPUNIT_TEST() [21/33]

SystemsTest::CPPUNIT_TEST ( test3DProjectVectorFEHex8  )

◆ CPPUNIT_TEST() [22/33]

SystemsTest::CPPUNIT_TEST ( test3DProjectVectorFETet10  )

◆ CPPUNIT_TEST() [23/33]

SystemsTest::CPPUNIT_TEST ( test3DProjectVectorFETet14  )

◆ CPPUNIT_TEST() [24/33]

SystemsTest::CPPUNIT_TEST ( test3DProjectVectorFEHex20  )

◆ CPPUNIT_TEST() [25/33]

SystemsTest::CPPUNIT_TEST ( test3DProjectVectorFEHex27  )

◆ CPPUNIT_TEST() [26/33]

SystemsTest::CPPUNIT_TEST ( testSetSystemParameterOverEquationSystem  )

◆ CPPUNIT_TEST() [27/33]

SystemsTest::CPPUNIT_TEST ( testAssemblyWithDgFemContext  )

◆ CPPUNIT_TEST() [28/33]

SystemsTest::CPPUNIT_TEST ( testDofCouplingWithVarGroups  )

◆ CPPUNIT_TEST() [29/33]

SystemsTest::CPPUNIT_TEST ( testProjectMatrixEdge2  )

◆ CPPUNIT_TEST() [30/33]

SystemsTest::CPPUNIT_TEST ( testProjectMatrixQuad4  )

◆ CPPUNIT_TEST() [31/33]

SystemsTest::CPPUNIT_TEST ( testProjectMatrixTri3  )

◆ CPPUNIT_TEST() [32/33]

SystemsTest::CPPUNIT_TEST ( testProjectMatrixHex8  )

◆ CPPUNIT_TEST() [33/33]

SystemsTest::CPPUNIT_TEST ( testProjectMatrixTet4  )

◆ CPPUNIT_TEST_SUITE_END()

SystemsTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

SystemsTest::LIBMESH_CPPUNIT_TEST_SUITE ( SystemsTest  )

◆ setUp()

void SystemsTest::setUp ( )
inline

Definition at line 558 of file systems_test.C.

559  {}

◆ simpleSetup()

ExplicitSystem& SystemsTest::simpleSetup ( UnstructuredMesh mesh,
EquationSystems es 
)
inline

Definition at line 565 of file systems_test.C.

References libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshTools::Generation::build_line(), libMesh::EDGE3, libMesh::FIRST, and mesh.

567  {
568  ExplicitSystem &sys =
569  es.add_system<ExplicitSystem> ("Simple");
570 
571  sys.add_variable("u", FIRST);
572 
574  10,
575  0., 1.,
576  EDGE3);
577 
578  return sys;
579  }
MeshBase & mesh
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.
Definition: system.C:1357
void build_line(UnstructuredMesh &mesh, const unsigned int nx, const Real xmin=0., const Real xmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 1D meshes.
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.
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems...

◆ tearDown()

void SystemsTest::tearDown ( )
inline

Definition at line 561 of file systems_test.C.

562  {}

◆ test100KVariables()

void SystemsTest::test100KVariables ( )
inline

Definition at line 582 of file systems_test.C.

References libMesh::EquationSystems::add_system(), libMesh::System::add_variables(), libMesh::MeshTools::Generation::build_line(), libMesh::EDGE3, libMesh::FIRST, libMesh::System::get_dof_map(), libMesh::EquationSystems::init(), libMesh::make_range(), mesh, libMesh::DofMap::n_dofs(), libMesh::System::n_dofs(), libMesh::DofMap::n_dofs_per_processor(), and TestCommWorld.

583  {
585  EquationSystems es(mesh);
586  ExplicitSystem &sys =
587  es.add_system<ExplicitSystem> ("100KVars");
588 
589  dof_id_type n_dofs = 100000;
590 
591  // This takes 16 seconds in opt mode for me, 200 in dbg!?
592  /*
593  for (auto i : make_range(n_dofs))
594  sys.add_variable(std::to_string(i), FIRST);
595  */
596 
597  std::vector<std::string> var_names(n_dofs);
598  for (auto i : make_range(n_dofs))
599  var_names[i] = std::to_string(i);
600 
601  sys.add_variables(var_names, FIRST);
602 
604  4,
605  0., 1.,
606  EDGE3);
607 
608  es.init();
609 
610  CPPUNIT_ASSERT_EQUAL(sys.n_dofs(), n_dofs*5);
611  for (const Node * node : mesh.node_ptr_range())
612  CPPUNIT_ASSERT_EQUAL(dof_id_type(node->n_vars(0)), n_dofs);
613 
614  std::vector<dof_id_type> each = sys.get_dof_map().n_dofs_per_processor(888);
615  CPPUNIT_ASSERT_EQUAL(std::accumulate(each.begin(), each.end(), dof_id_type(0)), dof_id_type(5));
616  CPPUNIT_ASSERT_EQUAL(sys.get_dof_map().n_dofs(888), dof_id_type(5));
617  }
unsigned int add_variables(const std::vector< std::string > &vars, 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.
Definition: system.C:1471
This is the EquationSystems class.
A Node is like a Point, but with more information.
Definition: node.h:52
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
MeshBase & mesh
dof_id_type n_dofs(const unsigned int vn) const
Definition: dof_map.h:675
dof_id_type n_dofs() const
Definition: system.C:121
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...
Definition: int_range.h:140
void build_line(UnstructuredMesh &mesh, const unsigned int nx, const Real xmin=0., const Real xmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 1D meshes.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
const DofMap & get_dof_map() const
Definition: system.h:2374
std::vector< dof_id_type > n_dofs_per_processor(const unsigned int vn) const
Definition: dof_map.h:704
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems...
uint8_t dof_id_type
Definition: id_types.h:67

◆ test2DProjectVectorFE()

void SystemsTest::test2DProjectVectorFE ( const ElemType  elem_type)
inline

Definition at line 773 of file systems_test.C.

References libMesh::EquationSystems::add_system(), libMesh::MeshTools::Generation::build_square(), libMesh::EquationSystems::init(), libMesh::LAGRANGE_VEC, libMesh::make_range(), mesh, libMesh::Elem::REFINE, libMesh::EquationSystems::reinit(), TestCommWorld, libMesh::TOLERANCE, libMesh::Elem::type_to_default_order_map, libMesh::Elem::type_to_dim_map, and value.

774  {
776 
777  EquationSystems es(mesh);
779  es.add_system<TransientExplicitSystem> ("SimpleSystem");
780 
781  auto u_var = sys.add_variable("u", Elem::type_to_default_order_map[elem_type], LAGRANGE_VEC);
782 
784  1, 1,
785  0., 1., 0., 1.,
786  elem_type);
787 
788  es.init();
789 
790  // Manually set-up the solution because I'm too lazy to set-up all the generic
791  // function projection code right now
792  for (const auto & node : mesh.local_node_ptr_range())
793  {
794  for (unsigned int i : make_range(Elem::type_to_dim_map[elem_type]))
795  {
796  auto dof_index = node->dof_number(sys.number(), u_var, i);
797  sys.solution->set(dof_index, (*node)(i));
798  }
799  }
800 
801  // After setting values, we need to assemble
802  sys.solution->close();
803 
804 
805 #ifdef LIBMESH_ENABLE_AMR
806  for (auto & elem : mesh.element_ptr_range())
807  elem->set_refinement_flag(Elem::REFINE);
808  es.reinit();
809 #endif
810 
811  for (const auto & node : mesh.local_node_ptr_range())
812  {
813  // 2D element here
814  for (unsigned int i : make_range(Elem::type_to_dim_map[elem_type]))
815  {
816  auto dof_index = node->dof_number(sys.number(), u_var, i);
817  auto value = (*sys.solution)(dof_index);
818  LIBMESH_ASSERT_NUMBERS_EQUAL(value, (*node)(i), TOLERANCE*TOLERANCE);
819  }
820  }
821  }
This is the EquationSystems class.
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
static constexpr Real TOLERANCE
MeshBase & mesh
Manages storage and variables for transient systems.
void build_square(UnstructuredMesh &mesh, const unsigned int nx, const unsigned int ny, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 2D meshes.
static const bool value
Definition: xdr_io.C:55
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...
Definition: int_range.h:140
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50

◆ test2DProjectVectorFEQuad4()

void SystemsTest::test2DProjectVectorFEQuad4 ( )
inline

Definition at line 1887 of file systems_test.C.

References libMesh::QUAD4.

1887 { LOG_UNIT_TEST; test2DProjectVectorFE(QUAD4); }
void test2DProjectVectorFE(const ElemType elem_type)
Definition: systems_test.C:773

◆ test2DProjectVectorFEQuad8()

void SystemsTest::test2DProjectVectorFEQuad8 ( )
inline

Definition at line 1890 of file systems_test.C.

References libMesh::QUAD8.

1890 { LOG_UNIT_TEST; test2DProjectVectorFE(QUAD8); }
void test2DProjectVectorFE(const ElemType elem_type)
Definition: systems_test.C:773

◆ test2DProjectVectorFEQuad9()

void SystemsTest::test2DProjectVectorFEQuad9 ( )
inline

Definition at line 1891 of file systems_test.C.

References libMesh::QUAD9.

1891 { LOG_UNIT_TEST; test2DProjectVectorFE(QUAD9); }
void test2DProjectVectorFE(const ElemType elem_type)
Definition: systems_test.C:773

◆ test2DProjectVectorFETri3()

void SystemsTest::test2DProjectVectorFETri3 ( )
inline

Definition at line 1886 of file systems_test.C.

References libMesh::TRI3.

1886 { LOG_UNIT_TEST; test2DProjectVectorFE(TRI3); }
void test2DProjectVectorFE(const ElemType elem_type)
Definition: systems_test.C:773

◆ test2DProjectVectorFETri6()

void SystemsTest::test2DProjectVectorFETri6 ( )
inline

Definition at line 1888 of file systems_test.C.

References libMesh::TRI6.

1888 { LOG_UNIT_TEST; test2DProjectVectorFE(TRI6); }
void test2DProjectVectorFE(const ElemType elem_type)
Definition: systems_test.C:773

◆ test2DProjectVectorFETri7()

void SystemsTest::test2DProjectVectorFETri7 ( )
inline

Definition at line 1889 of file systems_test.C.

References libMesh::TRI7.

1889 { LOG_UNIT_TEST; test2DProjectVectorFE(TRI7); }
void test2DProjectVectorFE(const ElemType elem_type)
Definition: systems_test.C:773

◆ test3DProjectVectorFE()

void SystemsTest::test3DProjectVectorFE ( const ElemType  elem_type)
inline

Definition at line 823 of file systems_test.C.

References libMesh::EquationSystems::add_system(), libMesh::MeshTools::Generation::build_cube(), libMesh::EquationSystems::init(), libMesh::LAGRANGE_VEC, libMesh::make_range(), mesh, libMesh::Elem::REFINE, libMesh::EquationSystems::reinit(), TestCommWorld, libMesh::TOLERANCE, libMesh::Elem::type_to_default_order_map, libMesh::Elem::type_to_dim_map, and value.

824  {
826 
827  EquationSystems es(mesh);
829  es.add_system<TransientExplicitSystem> ("SimpleSystem");
830 
831  auto u_var = sys.add_variable
832  ("u", Elem::type_to_default_order_map[elem_type], LAGRANGE_VEC);
833 
835  1, 1, 1,
836  0., 1., 0., 1., 0., 1.,
837  elem_type);
838 
839  es.init();
840 
841  // Manually set-up the solution because I'm too lazy to set-up all the generic
842  // function projection code right now
843  for (const auto & node : mesh.local_node_ptr_range())
844  {
845  for (unsigned int i : make_range(Elem::type_to_dim_map[elem_type]))
846  {
847  auto dof_index = node->dof_number(sys.number(), u_var, i);
848  sys.solution->set(dof_index, (*node)(i));
849  }
850  }
851 
852  // After setting values, we need to assemble
853  sys.solution->close();
854 
855 
856 #ifdef LIBMESH_ENABLE_AMR
857  for (auto & elem : mesh.element_ptr_range())
858  elem->set_refinement_flag(Elem::REFINE);
859  es.reinit();
860 #endif
861 
862  for (const auto & node : mesh.local_node_ptr_range())
863  {
864  for (unsigned int i : make_range(Elem::type_to_dim_map[elem_type]))
865  {
866  auto dof_index = node->dof_number(sys.number(), u_var, i);
867  auto value = (*sys.solution)(dof_index);
868  LIBMESH_ASSERT_NUMBERS_EQUAL(value, (*node)(i), TOLERANCE*TOLERANCE);
869  }
870  }
871  }
This is the EquationSystems class.
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
static constexpr Real TOLERANCE
MeshBase & mesh
Manages storage and variables for transient systems.
static const bool value
Definition: xdr_io.C:55
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...
Definition: int_range.h:140
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.

◆ test3DProjectVectorFEHex20()

void SystemsTest::test3DProjectVectorFEHex20 ( )
inline

Definition at line 1896 of file systems_test.C.

References libMesh::HEX20.

1896 { LOG_UNIT_TEST; test3DProjectVectorFE(HEX20); }
void test3DProjectVectorFE(const ElemType elem_type)
Definition: systems_test.C:823

◆ test3DProjectVectorFEHex27()

void SystemsTest::test3DProjectVectorFEHex27 ( )
inline

Definition at line 1897 of file systems_test.C.

References libMesh::HEX27.

1897 { LOG_UNIT_TEST; test3DProjectVectorFE(HEX27); }
void test3DProjectVectorFE(const ElemType elem_type)
Definition: systems_test.C:823

◆ test3DProjectVectorFEHex8()

void SystemsTest::test3DProjectVectorFEHex8 ( )
inline

Definition at line 1893 of file systems_test.C.

References libMesh::HEX8.

1893 { LOG_UNIT_TEST; test3DProjectVectorFE(HEX8); }
void test3DProjectVectorFE(const ElemType elem_type)
Definition: systems_test.C:823

◆ test3DProjectVectorFETet10()

void SystemsTest::test3DProjectVectorFETet10 ( )
inline

Definition at line 1894 of file systems_test.C.

References libMesh::TET10.

1894 { LOG_UNIT_TEST; test3DProjectVectorFE(TET10); }
void test3DProjectVectorFE(const ElemType elem_type)
Definition: systems_test.C:823

◆ test3DProjectVectorFETet14()

void SystemsTest::test3DProjectVectorFETet14 ( )
inline

Definition at line 1895 of file systems_test.C.

References libMesh::TET14.

1895 { LOG_UNIT_TEST; test3DProjectVectorFE(TET14); }
void test3DProjectVectorFE(const ElemType elem_type)
Definition: systems_test.C:823

◆ test3DProjectVectorFETet4()

void SystemsTest::test3DProjectVectorFETet4 ( )
inline

Definition at line 1892 of file systems_test.C.

References libMesh::TET4.

1892 { LOG_UNIT_TEST; test3DProjectVectorFE(TET4); }
void test3DProjectVectorFE(const ElemType elem_type)
Definition: systems_test.C:823

◆ testAddVectorProjChange()

void SystemsTest::testAddVectorProjChange ( )
inline

Definition at line 637 of file systems_test.C.

References libMesh::System::add_vector(), mesh, TestCommWorld, and libMesh::System::vector_preservation().

638  {
640  EquationSystems es(mesh);
641  ExplicitSystem & sys = simpleSetup(mesh, es);
642 
643  sys.add_vector("late", /* projections = */ false);
644  CPPUNIT_ASSERT_EQUAL(sys.vector_preservation("late"), false);
645 
646  sys.add_vector("late");
647  CPPUNIT_ASSERT_EQUAL(sys.vector_preservation("late"), true);
648  }
This is the EquationSystems class.
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
MeshBase & mesh
NumericVector< Number > & add_vector(std::string_view vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
Definition: system.C:768
ExplicitSystem & simpleSetup(UnstructuredMesh &mesh, EquationSystems &es)
Definition: systems_test.C:565
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
bool vector_preservation(std::string_view vec_name) const
Definition: system.C:1148
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems...

◆ testAddVectorTypeChange()

void SystemsTest::testAddVectorTypeChange ( )
inline

Definition at line 651 of file systems_test.C.

References libMesh::System::add_vector(), libMesh::GHOSTED, mesh, libMesh::PARALLEL, TIMPI::Communicator::size(), TestCommWorld, and libMesh::System::vector_preservation().

652  {
653  // Vector types are all pretty much equivalent in serial.
654  if (TestCommWorld->size() == 1)
655  return;
656 
658  EquationSystems es(mesh);
659  ExplicitSystem & sys = simpleSetup(mesh, es);
660 
661  auto & late_vec = sys.add_vector("late");
662  CPPUNIT_ASSERT_EQUAL(late_vec.type(), PARALLEL);
663  CPPUNIT_ASSERT_EQUAL(sys.vector_preservation("late"), true);
664 
665  // We should never downgrade projection settings, so "false"
666  // should be safely ignored here
667  sys.add_vector("late", false, GHOSTED);
668  CPPUNIT_ASSERT_EQUAL(late_vec.type(), GHOSTED);
669  CPPUNIT_ASSERT_EQUAL(sys.vector_preservation("late"), true);
670 
671  // We should never downgrade storage settings, so this should be a
672  // no-op.
673  sys.add_vector("late", true, PARALLEL);
674  CPPUNIT_ASSERT_EQUAL(late_vec.type(), GHOSTED);
675  CPPUNIT_ASSERT_EQUAL(sys.vector_preservation("late"), true);
676  }
This is the EquationSystems class.
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
MeshBase & mesh
NumericVector< Number > & add_vector(std::string_view vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
Definition: system.C:768
processor_id_type size() const
ExplicitSystem & simpleSetup(UnstructuredMesh &mesh, EquationSystems &es)
Definition: systems_test.C:565
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
bool vector_preservation(std::string_view vec_name) const
Definition: system.C:1148
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems...

◆ testAssemblyWithDgFemContext()

void SystemsTest::testAssemblyWithDgFemContext ( )
inline

Definition at line 1330 of file systems_test.C.

References libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), assembly_with_dg_fem_context(), libMesh::System::attach_assemble_function(), libMesh::MeshTools::Generation::build_cube(), libMesh::FIRST, libMesh::HEX8, libMesh::EquationSystems::init(), libMesh::L2_LAGRANGE, mesh, libMesh::System::solve(), and TestCommWorld.

1331  {
1332  LOG_UNIT_TEST;
1333 
1335 
1336  EquationSystems es(mesh);
1337  System &sys = es.add_system<LinearImplicitSystem> ("test");
1338 
1339  // We must use a discontinuous variable type in this test or
1340  // else the sparsity pattern will not be correct
1341  sys.add_variable("u", FIRST, L2_LAGRANGE);
1342 
1344  5, 5, 5,
1345  0., 1., 0., 1., 0., 1.,
1346  HEX8);
1347 
1348  es.init();
1350  sys.solve();
1351 
1352  // We don't actually assert anything in this test. We just want to check that
1353  // the assembly and solve do not encounter any errors.
1354  }
This is the EquationSystems class.
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
MeshBase & mesh
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:96
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.
Definition: system.C:1357
void attach_assemble_function(void fptr(EquationSystems &es, const std::string &name))
Register a user function to use in assembling the system matrix and RHS.
Definition: system.C:2161
virtual void solve()
Solves the system.
Definition: system.h:347
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
void assembly_with_dg_fem_context(EquationSystems &es, const std::string &)
Definition: systems_test.C:203
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.

◆ testBlockRestrictedVarNDofs()

void SystemsTest::testBlockRestrictedVarNDofs ( )
inline

Definition at line 1356 of file systems_test.C.

References libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), TIMPI::Communicator::allgather(), libMesh::MeshTools::Generation::build_cube(), libMesh::ParallelObject::comm(), libMesh::FIRST, libMesh::System::get_dof_map(), libMesh::EquationSystems::init(), libMesh::System::local_dof_indices(), libMesh::DofMap::local_variable_indices(), mesh, libMesh::MeshBase::prepare_for_use(), libMesh::QUAD4, TIMPI::Communicator::set_union(), and TestCommWorld.

1357  {
1358  LOG_UNIT_TEST;
1359 
1361 
1363  4,
1364  4,
1365  0,
1366  0., 1.,
1367  0., 1.,
1368  0., 0.,
1369  QUAD4);
1370 
1371  for (const auto & elem : mesh.element_ptr_range())
1372  {
1373  Point c = elem->vertex_average();
1374  if (c(0) <= 0.5 && c(1) <= 0.5)
1375  elem->subdomain_id() = 0;
1376  else
1377  elem->subdomain_id() = 1;
1378  }
1379 
1381 
1382  // Create an equation systems object.
1383  EquationSystems equation_systems (mesh);
1384  ExplicitSystem& system =
1385  equation_systems.add_system<LinearImplicitSystem> ("test");
1386 
1387  std::set<subdomain_id_type> block0;
1388  std::set<subdomain_id_type> block1;
1389  block0.insert(0);
1390  block1.insert(1);
1391  auto u0 = system.add_variable ("u0", libMesh::FIRST, &block0);
1392  auto u1 = system.add_variable ("u1", libMesh::FIRST, &block1);
1393  equation_systems.init();
1394 
1395  std::vector<dof_id_type> u0_dofs;
1396  system.get_dof_map().local_variable_indices(u0_dofs, mesh, u0);
1397  std::vector<dof_id_type> u1_dofs;
1398  system.get_dof_map().local_variable_indices(u1_dofs, mesh, u1);
1399 
1400  std::set<dof_id_type> sys_u0_dofs;
1401  system.local_dof_indices(u0, sys_u0_dofs);
1402  std::set<dof_id_type> sys_u1_dofs;
1403  system.local_dof_indices(u1, sys_u1_dofs);
1404 
1405  // Get local indices from other processors too
1406  mesh.comm().allgather(u0_dofs);
1407  mesh.comm().allgather(u1_dofs);
1408  mesh.comm().set_union(sys_u0_dofs);
1409  mesh.comm().set_union(sys_u1_dofs);
1410 
1411  const std::size_t c9 = 9;
1412  const std::size_t c21 = 21;
1413  CPPUNIT_ASSERT_EQUAL(c9, u0_dofs.size());
1414  CPPUNIT_ASSERT_EQUAL(c21, u1_dofs.size());
1415  CPPUNIT_ASSERT_EQUAL(c9, sys_u0_dofs.size());
1416  CPPUNIT_ASSERT_EQUAL(c21, sys_u1_dofs.size());
1417  }
void local_dof_indices(const unsigned int var, std::set< dof_id_type > &var_indices) const
Fills the std::set with the degrees of freedom on the local processor corresponding the the variable ...
Definition: system.C:1627
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
This is the EquationSystems class.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
void local_variable_indices(T &idx, const MeshBase &mesh, unsigned int var_num) const
If T == dof_id_type, counts, if T == std::vector<dof_id_type>, fills an array of, those dof indices w...
Definition: dof_map.C:1151
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
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.
Definition: mesh_base.C:759
MeshBase & mesh
const Parallel::Communicator & comm() 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.
Definition: system.C:1357
const DofMap & get_dof_map() const
Definition: system.h:2374
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems...
void set_union(T &data, const unsigned int root_id) const

◆ testBoundaryProjectCube()

void SystemsTest::testBoundaryProjectCube ( )
inline

Definition at line 1048 of file systems_test.C.

References libMesh::BoundaryInfo::add_edge(), libMesh::BoundaryInfo::add_node(), libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::BoundaryInfo::boundary_ids(), libMesh::System::boundary_project_solution(), libMesh::MeshTools::Generation::build_cube(), libMesh::FIRST, libMesh::MeshBase::get_boundary_info(), libMesh::BoundaryInfo::has_boundary_id(), libMesh::HEX8, libMesh::EquationSystems::init(), libMesh::LAGRANGE, mesh, libMesh::MeshBase::n_nodes(), libMesh::Real, TIMPI::Communicator::set_union(), libMesh::System::solution, TestCommWorld, and libMesh::TOLERANCE.

1049  {
1050  LOG_UNIT_TEST;
1051 
1053 
1054  // const boundary_id_type BOUNDARY_ID_MIN_Z = 0;
1055  const boundary_id_type BOUNDARY_ID_MIN_Y = 1;
1056  const boundary_id_type BOUNDARY_ID_MAX_X = 2;
1057  const boundary_id_type BOUNDARY_ID_MAX_Y = 3;
1058  const boundary_id_type BOUNDARY_ID_MIN_X = 4;
1059  const boundary_id_type BOUNDARY_ID_MAX_Z = 5;
1060  const boundary_id_type NODE_BOUNDARY_ID = 10;
1061  const boundary_id_type EDGE_BOUNDARY_ID = 20;
1062  const boundary_id_type SIDE_BOUNDARY_ID = BOUNDARY_ID_MIN_X;
1063 
1064  EquationSystems es(mesh);
1065  System &sys = es.add_system<System> ("SimpleSystem");
1066  unsigned int u_var = sys.add_variable("u", FIRST, LAGRANGE);
1067 
1069  3, 3, 3,
1070  0., 1., 0., 1., 0., 1.,
1071  HEX8);
1072 
1073  // Count the number of nodes on SIDE_BOUNDARY_ID
1074  std::set<dof_id_type> projected_nodes_set;
1075 
1076  for (const auto & elem : mesh.element_ptr_range())
1077  {
1078  for (auto side : elem->side_index_range())
1079  {
1080  std::vector<boundary_id_type> vec_to_fill;
1081  mesh.get_boundary_info().boundary_ids(elem, side, vec_to_fill);
1082 
1083  auto vec_it = std::find(vec_to_fill.begin(), vec_to_fill.end(), SIDE_BOUNDARY_ID);
1084  if (vec_it != vec_to_fill.end())
1085  {
1086  for (unsigned int node_index=0; node_index<elem->n_nodes(); node_index++)
1087  {
1088  if( elem->is_node_on_side(node_index, side))
1089  {
1090  projected_nodes_set.insert(elem->node_id(node_index));
1091  }
1092  }
1093  }
1094  }
1095  }
1096 
1097  // Also add some edge and node boundary IDs
1098  for (const auto & elem : mesh.element_ptr_range())
1099  {
1100  unsigned int
1101  side_max_x = 0, side_min_y = 0,
1102  side_max_y = 0, side_max_z = 0;
1103 
1104  bool
1105  found_side_max_x = false, found_side_max_y = false,
1106  found_side_min_y = false, found_side_max_z = false;
1107 
1108  for (auto side : elem->side_index_range())
1109  {
1110  if (mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MAX_X))
1111  {
1112  side_max_x = side;
1113  found_side_max_x = true;
1114  }
1115 
1116  if (mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MIN_Y))
1117  {
1118  side_min_y = side;
1119  found_side_min_y = true;
1120  }
1121 
1122  if (mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MAX_Y))
1123  {
1124  side_max_y = side;
1125  found_side_max_y = true;
1126  }
1127 
1128  if (mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MAX_Z))
1129  {
1130  side_max_z = side;
1131  found_side_max_z = true;
1132  }
1133  }
1134 
1135  // If elem has sides on boundaries
1136  // BOUNDARY_ID_MAX_X, BOUNDARY_ID_MAX_Y, BOUNDARY_ID_MAX_Z
1137  // then let's set a node boundary condition
1138  if (found_side_max_x && found_side_max_y && found_side_max_z)
1139  for (auto n : elem->node_index_range())
1140  if (elem->is_node_on_side(n, side_max_x) &&
1141  elem->is_node_on_side(n, side_max_y) &&
1142  elem->is_node_on_side(n, side_max_z))
1143  {
1144  projected_nodes_set.insert(elem->node_id(n));
1145  mesh.get_boundary_info().add_node(elem->node_ptr(n), NODE_BOUNDARY_ID);
1146  }
1147 
1148  // If elem has sides on boundaries
1149  // BOUNDARY_ID_MAX_X and BOUNDARY_ID_MIN_Y
1150  // then let's set an edge boundary condition
1151  if (found_side_max_x && found_side_min_y)
1152  for (auto e : elem->edge_index_range())
1153  if (elem->is_edge_on_side(e, side_max_x) &&
1154  elem->is_edge_on_side(e, side_min_y))
1155  {
1156  mesh.get_boundary_info().add_edge(elem, e, EDGE_BOUNDARY_ID);
1157 
1158  for (unsigned int node_index=0; node_index<elem->n_nodes(); node_index++)
1159  {
1160  if (elem->is_node_on_edge(node_index, e))
1161  {
1162  projected_nodes_set.insert(elem->node_id(node_index));
1163  }
1164  }
1165  }
1166  }
1167 
1168  es.init();
1169 
1170  sys.solution->add(1.0);
1171 
1172  std::set<boundary_id_type> boundary_ids;
1173  boundary_ids.insert(NODE_BOUNDARY_ID);
1174  boundary_ids.insert(EDGE_BOUNDARY_ID);
1175  boundary_ids.insert(SIDE_BOUNDARY_ID);
1176  std::vector<unsigned int> variables;
1177  variables.push_back(u_var);
1178  ZeroFunction<> zf;
1179  sys.boundary_project_solution(boundary_ids, variables, &zf);
1180 
1181  // On a distributed mesh we may not have every node on every
1182  // processor
1183  TestCommWorld->set_union(projected_nodes_set);
1184 
1185  // We set the solution to be 1 everywhere and then zero on specific boundary
1186  // nodes, so the final l1 norm of the solution is the difference between the
1187  // number of nodes in the mesh and the number of nodes we zero on.
1188  Real ref_l1_norm = static_cast<Real>(mesh.n_nodes()) - static_cast<Real>(projected_nodes_set.size());
1189 
1190  LIBMESH_ASSERT_FP_EQUAL(sys.solution->l1_norm(), ref_l1_norm, TOLERANCE*TOLERANCE);
1191  }
This is the EquationSystems class.
bool has_boundary_id(const Node *const node, const boundary_id_type id) const
ConstFunction that simply returns 0.
Definition: zero_function.h:38
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
static constexpr Real TOLERANCE
MeshBase & mesh
void boundary_ids(const Node *node, std::vector< boundary_id_type > &vec_to_fill) const
Fills a user-provided std::vector with the boundary ids associated with Node node.
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
Definition: mesh_base.h:165
void add_node(const Node *node, const boundary_id_type id)
Add Node node with boundary id id to the boundary information data structures.
int8_t boundary_id_type
Definition: id_types.h:51
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:96
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1593
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.
Definition: system.C:1357
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void boundary_project_solution(const std::set< boundary_id_type > &b, const std::vector< unsigned int > &variables, FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr)
Projects arbitrary boundary functions onto a vector of degree of freedom values for the current syste...
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.
virtual dof_id_type n_nodes() const =0
void add_edge(const dof_id_type elem, const unsigned short int edge, const boundary_id_type id)
Add edge edge of element number elem with boundary id id to the boundary information data structure...
void set_union(T &data, const unsigned int root_id) const

◆ testDofCouplingWithVarGroups()

void SystemsTest::testDofCouplingWithVarGroups ( )
inline

Definition at line 1193 of file systems_test.C.

References libMesh::DofMap::add_coupling_functor(), libMesh::MeshBase::add_elem(), libMesh::MeshBase::add_point(), libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), assemble_matrix_and_rhs(), libMesh::System::attach_assemble_function(), libMesh::Elem::build(), libMesh::MeshTools::Generation::build_cube(), libMesh::EDGE2, libMesh::MeshBase::elem_ref(), libMesh::FIRST, libMesh::System::get_dof_map(), libMesh::LinearImplicitSystem::get_linear_solver(), libMesh::IDENTITY_PRECOND, libMesh::EquationSystems::init(), libMesh::JACOBI, mesh, libMesh::MeshBase::n_nodes(), libMesh::System::n_vars(), libMesh::Elem::node_ptr(), libMesh::NODEELEM, libMesh::MeshBase::prepare_for_use(), libMesh::Real, libMesh::Elem::set_node(), libMesh::LinearSolver< T >::set_preconditioner_type(), libMesh::LinearSolver< T >::set_solver_type(), libMesh::System::solution, libMesh::LinearImplicitSystem::solve(), libMesh::Elem::subdomain_id(), TestCommWorld, and libMesh::TOLERANCE.

1194  {
1195  LOG_UNIT_TEST;
1196 
1198 
1200  1,
1201  0,
1202  0,
1203  0., 1.,
1204  0., 0.,
1205  0., 0.,
1206  EDGE2);
1207 
1208  Point new_point_a(2.);
1209  Point new_point_b(3.);
1210  Node* new_node_a = mesh.add_point( new_point_a );
1211  Node* new_node_b = mesh.add_point( new_point_b );
1212  auto new_edge_elem = mesh.add_elem(Elem::build(EDGE2));
1213  new_edge_elem->set_node(0, new_node_a);
1214  new_edge_elem->set_node(1, new_node_b);
1215 
1216  mesh.elem_ref(0).subdomain_id() = 10;
1217  mesh.elem_ref(1).subdomain_id() = 10;
1218 
1219  // Add NodeElems for coupling purposes
1220  auto node_elem_1 = mesh.add_elem(Elem::build(NODEELEM));
1221  node_elem_1->set_node(0, mesh.elem_ref(0).node_ptr(1));
1222  auto node_elem_2 = mesh.add_elem(Elem::build(NODEELEM));
1223  node_elem_2->set_node(0, new_node_a);
1224 
1226 
1227  // Create an equation systems object.
1228  EquationSystems equation_systems (mesh);
1229  LinearImplicitSystem & system =
1230  equation_systems.add_system<LinearImplicitSystem> ("test");
1231 
1232  system.add_variable ("u", libMesh::FIRST);
1233  system.add_variable ("v", libMesh::FIRST);
1234  system.add_variable ("w", libMesh::FIRST);
1235 
1236  std::set<subdomain_id_type> theta_subdomains;
1237  theta_subdomains.insert(10);
1238  system.add_variable ("theta_x", libMesh::FIRST, &theta_subdomains);
1239  system.add_variable ("theta_y", libMesh::FIRST, &theta_subdomains);
1240  system.add_variable ("theta_z", libMesh::FIRST, &theta_subdomains);
1241 
1243 
1244  AugmentSparsityOnNodes augment_sparsity(mesh);
1245  system.get_dof_map().add_coupling_functor(augment_sparsity);
1246 
1247  // LASPACK GMRES + ILU defaults don't like this problem, but it's
1248  // small enough to just use a simpler iteration.
1251 
1252  equation_systems.init ();
1253 
1254  system.solve();
1255 
1256  // We set the solution to be 1 everywhere, so the final l1 norm of the
1257  // solution is the product of the number of variables and number of nodes.
1258  Real ref_l1_norm = static_cast<Real>(mesh.n_nodes() * system.n_vars());
1259 
1260  LIBMESH_ASSERT_FP_EQUAL(system.solution->l1_norm(), ref_l1_norm, TOLERANCE*TOLERANCE);
1261  }
This is the EquationSystems class.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
virtual Node *& set_node(const unsigned int i)
Definition: elem.h:2558
A Node is like a Point, but with more information.
Definition: node.h:52
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
static constexpr Real TOLERANCE
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
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.
Definition: mesh_base.C:759
MeshBase & mesh
virtual LinearSolver< Number > * get_linear_solver() const override
virtual void solve() override
Assembles & solves the linear system A*x=b.
void add_coupling_functor(GhostingFunctor &coupling_functor, bool to_mesh=true)
Adds a functor which can specify coupling requirements for creation of sparse matrices.
Definition: dof_map.C:2033
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id)=0
Add a new Node at Point p to the end of the vertex array, with processor_id procid.
void assemble_matrix_and_rhs(EquationSystems &es, const std::string &)
Definition: systems_test.C:123
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
void set_preconditioner_type(const PreconditionerType pct)
Sets the type of preconditioner to use.
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1593
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.
Definition: system.C:1357
void set_solver_type(const SolverType st)
Sets the type of solver to use.
void attach_assemble_function(void fptr(EquationSystems &es, const std::string &name))
Register a user function to use in assembling the system matrix and RHS.
Definition: system.C:2161
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
subdomain_id_type subdomain_id() const
Definition: elem.h:2582
const Node * node_ptr(const unsigned int i) const
Definition: elem.h:2507
virtual const Elem & elem_ref(const dof_id_type i) const
Definition: mesh_base.h:639
unsigned int n_vars() const
Definition: system.h:2430
const DofMap & get_dof_map() const
Definition: system.h:2374
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.
virtual dof_id_type n_nodes() const =0

◆ testPostInitAddVector()

void SystemsTest::testPostInitAddVector ( )
inline

Definition at line 620 of file systems_test.C.

References libMesh::System::add_vector(), libMesh::EquationSystems::init(), mesh, libMesh::System::n_dofs(), libMesh::System::solution, and TestCommWorld.

621  {
623  EquationSystems es(mesh);
624  ExplicitSystem & sys = simpleSetup(mesh, es);
625  es.init();
626 
627  auto & late_vec = sys.add_vector("late");
628 
629  CPPUNIT_ASSERT_EQUAL(sys.n_dofs(), dof_id_type(11));
630 
631  // late_vec should be initialized
632  CPPUNIT_ASSERT_EQUAL(late_vec.size(), dof_id_type(11));
633  CPPUNIT_ASSERT_EQUAL(late_vec.local_size(), sys.solution->local_size());
634  }
This is the EquationSystems class.
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
MeshBase & mesh
NumericVector< Number > & add_vector(std::string_view vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
Definition: system.C:768
dof_id_type n_dofs() const
Definition: system.C:121
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1593
ExplicitSystem & simpleSetup(UnstructuredMesh &mesh, EquationSystems &es)
Definition: systems_test.C:565
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems...
uint8_t dof_id_type
Definition: id_types.h:67

◆ testPostInitAddVectorTypeChange()

void SystemsTest::testPostInitAddVectorTypeChange ( )
inline

Definition at line 679 of file systems_test.C.

References libMesh::System::add_vector(), libMesh::System::get_dof_map(), libMesh::GHOSTED, libMesh::EquationSystems::init(), libMesh::make_range(), mesh, libMesh::System::n_dofs(), libMesh::PARALLEL, TIMPI::Communicator::size(), TestCommWorld, and libMesh::System::vector_preservation().

680  {
681  // Vector types are all pretty much equivalent in serial.
682  if (TestCommWorld->size() == 1)
683  return;
684 
686  EquationSystems es(mesh);
687  ExplicitSystem & sys = simpleSetup(mesh, es);
688 
689  auto & late_vec = sys.add_vector("late");
690  CPPUNIT_ASSERT_EQUAL(late_vec.type(), PARALLEL);
691  CPPUNIT_ASSERT_EQUAL(sys.vector_preservation("late"), true);
692 
693  es.init();
694 
695  auto & dof_map = sys.get_dof_map();
696 
697  // Set some data to make sure it's preserved
698  CPPUNIT_ASSERT_EQUAL(sys.n_dofs(), dof_id_type(11));
699  for (auto i : make_range(dof_map.first_dof(),
700  dof_map.end_dof()))
701  late_vec.set(i, 2.0*i);
702  late_vec.close();
703 
704  sys.add_vector("late", false, GHOSTED);
705  CPPUNIT_ASSERT_EQUAL(late_vec.type(), GHOSTED);
706 
707  std::vector<dof_id_type> dof_indices;
708  for (auto & elem : mesh.active_local_element_ptr_range())
709  {
710  dof_map.dof_indices (elem, dof_indices);
711 
712  for (auto d : dof_indices)
713  CPPUNIT_ASSERT_EQUAL(late_vec(d), Number(2.0*d));
714  }
715  }
This is the EquationSystems class.
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
MeshBase & mesh
NumericVector< Number > & add_vector(std::string_view vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
Definition: system.C:768
virtual void init(const numeric_index_type n, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC)=0
Change the dimension of the vector to n.
dof_id_type n_dofs() const
Definition: system.C:121
processor_id_type size() const
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...
Definition: int_range.h:140
ExplicitSystem & simpleSetup(UnstructuredMesh &mesh, EquationSystems &es)
Definition: systems_test.C:565
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
bool vector_preservation(std::string_view vec_name) const
Definition: system.C:1148
const DofMap & get_dof_map() const
Definition: system.h:2374
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems...
uint8_t dof_id_type
Definition: id_types.h:67

◆ testProjectCube()

void SystemsTest::testProjectCube ( const ElemType  elem_type)
inline

Definition at line 929 of file systems_test.C.

References libMesh::EquationSystems::add_system(), libMesh::MeshTools::Generation::build_cube(), libMesh::CONSTANT, libMesh::FIRST, libMesh::HIERARCHIC, libMesh::EquationSystems::init(), libMesh::LAGRANGE, mesh, libMesh::MONOMIAL, TripleFunction::offset, libMesh::TransientSystem< Base >::old_local_solution, libMesh::TransientSystem< Base >::older_local_solution, libMesh::EquationSystems::parameters, libMesh::Real, libMesh::Elem::REFINE, libMesh::EquationSystems::reinit(), libMesh::MeshBase::sub_point_locator(), TestCommWorld, and libMesh::THIRD.

930  {
932 
933  EquationSystems es(mesh);
935  es.add_system<TransientExplicitSystem> ("SimpleSystem");
936 
937  std::set<subdomain_id_type> u_subdomains {0, 1, 4, 5},
938  v_subdomains {1, 2, 3, 4},
939  w_subdomains {0, 1, 2, 3, 4};
940 
941  sys.add_variable("u", THIRD, HIERARCHIC, &u_subdomains);
942  sys.add_variable("v", FIRST, LAGRANGE, &v_subdomains);
943  sys.add_variable("w", CONSTANT, MONOMIAL, &w_subdomains);
944 
946  3, 3, 3,
947  0., 1., 0., 1., 0., 1.,
948  elem_type);
949 
950  for (auto & elem : mesh.element_ptr_range())
951  elem->subdomain_id() = elem->id()/6;
952 
953  es.init();
954  TripleFunction tfunc;
955  sys.project_solution(&tfunc);
956  tfunc.offset = 10;
957  sys.project_vector(*sys.old_local_solution, &tfunc);
958  tfunc.offset = 20;
959  sys.project_vector(*sys.older_local_solution, &tfunc);
960 
961  std::unique_ptr<PointLocatorBase> locator = mesh.sub_point_locator();
962  locator->enable_out_of_mesh_mode();
963  for (Real x = 0.1; x < 1; x += 0.2)
964  for (Real y = 0.1; y < 1; y += 0.2)
965  for (Real z = 0.1; z < 1; z += 0.2)
966  tripleValueTest(Point(x,y,z), sys, *locator,
967  u_subdomains, v_subdomains, w_subdomains,
968  es.parameters);
969 
970  #ifdef LIBMESH_ENABLE_AMR
971  for (auto & elem : mesh.element_ptr_range())
972  if ((elem->id()/2)%2)
973  elem->set_refinement_flag(Elem::REFINE);
974  es.reinit();
975 
976  locator = mesh.sub_point_locator();
977  locator->enable_out_of_mesh_mode();
978  for (Real x = 0.1; x < 1; x += 0.2)
979  for (Real y = 0.1; y < 1; y += 0.2)
980  for (Real z = 0.1; z < 1; z += 0.2)
981  tripleValueTest(Point(x,y,z), sys, *locator,
982  u_subdomains, v_subdomains, w_subdomains,
983  es.parameters);
984  #endif
985  }
This is the EquationSystems class.
void tripleValueTest(const Point &p, const TransientExplicitSystem &sys, const PointLocatorBase &locator, std::set< subdomain_id_type > &u_subdomains, std::set< subdomain_id_type > &v_subdomains, std::set< subdomain_id_type > &w_subdomains, const Parameters &param)
Definition: systems_test.C:501
std::unique_ptr< PointLocatorBase > sub_point_locator() const
Definition: mesh_base.C:1675
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
MeshBase & mesh
Manages storage and variables for transient systems.
NumericVector< Number > * old_local_solution
All the values I need to compute my contribution to the simulation at hand.
NumericVector< Number > * older_local_solution
All the values I need to compute my contribution to the simulation at hand.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.

◆ testProjectCubeWithMeshFunction()

void SystemsTest::testProjectCubeWithMeshFunction ( const ElemType  elem_type)
inline

Definition at line 987 of file systems_test.C.

References libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::NumericVector< T >::build(), libMesh::MeshTools::Generation::build_cube(), libMesh::ParallelObject::comm(), cubic_test(), libMesh::System::get_all_variable_numbers(), libMesh::System::get_dof_map(), libMesh::HIERARCHIC, libMesh::MeshFunction::init(), libMesh::EquationSystems::init(), mesh, libMesh::MONOMIAL, libMesh::System::n_dofs(), libMesh::EquationSystems::parameters, libMesh::System::point_value(), libMesh::System::project_solution(), libMesh::Real, libMesh::SERIAL, libMesh::System::solution, TestCommWorld, libMesh::THIRD, and libMesh::TOLERANCE.

988  {
989  // The source mesh needs to exist everywhere it's queried, so we
990  // use a ReplicatedMesh
992 
993  EquationSystems es(mesh);
994  System &sys = es.add_system<System> ("SimpleSystem");
995  sys.add_variable("u", THIRD, MONOMIAL);
996 
998  3, 3, 3,
999  0., 1., 0., 1., 0., 1.,
1000  elem_type);
1001 
1002  es.init();
1003  sys.project_solution(cubic_test, nullptr, es.parameters);
1004 
1005  std::vector<unsigned int> variables;
1006  sys.get_all_variable_numbers(variables);
1007  std::sort(variables.begin(),variables.end());
1008 
1009  std::unique_ptr< NumericVector<Number> > mesh_function_vector =
1010  NumericVector<Number>::build(es.comm());
1011  mesh_function_vector->init(sys.n_dofs(), false, SERIAL);
1012  sys.solution->localize( *mesh_function_vector );
1013 
1014  MeshFunction mesh_function(es,
1015  *mesh_function_vector,
1016  sys.get_dof_map(),
1017  variables);
1018  mesh_function.init();
1019 
1020  // Make a second system and project onto it using a MeshFunction
1021  Mesh proj_mesh(*TestCommWorld);
1022  EquationSystems proj_es(proj_mesh);
1023 
1024  System &proj_sys = proj_es.add_system<System> ("ProjectionSystem");
1025 
1026  // use 3rd order again so we can expect exact results
1027  proj_sys.add_variable("u", THIRD, HIERARCHIC);
1028 
1030  5, 5, 5,
1031  0., 1., 0., 1., 0., 1.,
1032  elem_type);
1033 
1034  proj_es.init();
1035  proj_sys.project_solution(&mesh_function);
1036 
1037  for (Real x = 0.1; x < 1; x += 0.2)
1038  for (Real y = 0.1; y < 1; y += 0.2)
1039  for (Real z = 0.1; z < 1; z += 0.2)
1040  {
1041  Point p(x,y,z);
1042  LIBMESH_ASSERT_NUMBERS_EQUAL
1043  (cubic_test(p,es.parameters,"",""),
1044  proj_sys.point_value(0,p), TOLERANCE*TOLERANCE);
1045  }
1046  }
Number cubic_test(const Point &p, const Parameters &, const std::string &, const std::string &)
Definition: systems_test.C:351
This is the EquationSystems class.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
static constexpr Real TOLERANCE
MeshBase & mesh
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:2421
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
Definition: vector_fe_ex5.C:44
void get_all_variable_numbers(std::vector< unsigned int > &all_variable_numbers) const
Fills all_variable_numbers with all the variable numbers for the variables that have been added to th...
Definition: system.C:1617
virtual void init(const numeric_index_type n, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC)=0
Change the dimension of the vector to n.
dof_id_type n_dofs() const
Definition: system.C:121
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr) const
Projects arbitrary functions onto the current solution.
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:96
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1593
virtual void init() override
Override the FunctionBase::init() member function.
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.
Definition: system.C:1357
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
This class provides function-like objects for data distributed over a mesh.
Definition: mesh_function.h:54
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
const DofMap & get_dof_map() const
Definition: system.h:2374
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.

◆ testProjectHierarchicEdge3()

void SystemsTest::testProjectHierarchicEdge3 ( )
inline

Definition at line 1880 of file systems_test.C.

References libMesh::EDGE3.

1880 { LOG_UNIT_TEST; testProjectLine(EDGE3); }
void testProjectLine(const ElemType elem_type)
Definition: systems_test.C:719

◆ testProjectHierarchicHex27()

void SystemsTest::testProjectHierarchicHex27 ( )
inline

Definition at line 1884 of file systems_test.C.

References libMesh::HEX27.

1884 { LOG_UNIT_TEST; testProjectCube(HEX27); }
void testProjectCube(const ElemType elem_type)
Definition: systems_test.C:929

◆ testProjectHierarchicQuad9()

void SystemsTest::testProjectHierarchicQuad9 ( )
inline

Definition at line 1881 of file systems_test.C.

References libMesh::QUAD9.

1881 { LOG_UNIT_TEST; testProjectSquare(QUAD9); }
void testProjectSquare(const ElemType elem_type)
Definition: systems_test.C:873

◆ testProjectHierarchicTri6()

void SystemsTest::testProjectHierarchicTri6 ( )
inline

Definition at line 1882 of file systems_test.C.

References libMesh::TRI6.

1882 { LOG_UNIT_TEST; testProjectSquare(TRI6); }
void testProjectSquare(const ElemType elem_type)
Definition: systems_test.C:873

◆ testProjectHierarchicTri7()

void SystemsTest::testProjectHierarchicTri7 ( )
inline

Definition at line 1883 of file systems_test.C.

References libMesh::TRI7.

1883 { LOG_UNIT_TEST; testProjectSquare(TRI7); }
void testProjectSquare(const ElemType elem_type)
Definition: systems_test.C:873

◆ testProjectLine()

void SystemsTest::testProjectLine ( const ElemType  elem_type)
inline

Definition at line 719 of file systems_test.C.

References libMesh::EquationSystems::add_system(), libMesh::MeshTools::Generation::build_line(), libMesh::CONSTANT, libMesh::FIRST, libMesh::HIERARCHIC, libMesh::EquationSystems::init(), libMesh::LAGRANGE, mesh, libMesh::MONOMIAL, TripleFunction::offset, libMesh::TransientSystem< Base >::old_local_solution, libMesh::TransientSystem< Base >::older_local_solution, libMesh::EquationSystems::parameters, libMesh::Real, libMesh::Elem::REFINE, libMesh::EquationSystems::reinit(), libMesh::MeshBase::sub_point_locator(), TestCommWorld, and libMesh::THIRD.

720  {
722 
723  EquationSystems es(mesh);
725  es.add_system<TransientExplicitSystem> ("SimpleSystem");
726 
727  std::set<subdomain_id_type> u_subdomains {0, 1, 4, 5},
728  v_subdomains {1, 2, 3, 4},
729  w_subdomains {0, 1, 2, 3, 4};
730 
731  sys.add_variable("u", THIRD, HIERARCHIC, &u_subdomains);
732  sys.add_variable("v", FIRST, LAGRANGE, &v_subdomains);
733  sys.add_variable("w", CONSTANT, MONOMIAL, &w_subdomains);
734 
736  6,
737  0., 1.,
738  elem_type);
739 
740  for (auto & elem : mesh.element_ptr_range())
741  elem->subdomain_id() = elem->id();
742 
743  es.init();
744  TripleFunction tfunc;
745  sys.project_solution(&tfunc);
746  tfunc.offset = 10;
747  sys.project_vector(*sys.old_local_solution, &tfunc);
748  tfunc.offset = 20;
749  sys.project_vector(*sys.older_local_solution, &tfunc);
750 
751  std::unique_ptr<PointLocatorBase> locator = mesh.sub_point_locator();
752  locator->enable_out_of_mesh_mode();
753  for (Real x = 0.1; x < 1; x += 0.2)
754  tripleValueTest(Point(x), sys, *locator,
755  u_subdomains, v_subdomains, w_subdomains,
756  es.parameters);
757 
758 #ifdef LIBMESH_ENABLE_AMR
759  for (auto & elem : mesh.element_ptr_range())
760  if ((elem->id()/2)%2)
761  elem->set_refinement_flag(Elem::REFINE);
762  es.reinit();
763 
764  locator = mesh.sub_point_locator();
765  locator->enable_out_of_mesh_mode();
766  for (Real x = 0.1; x < 1; x += 0.2)
767  tripleValueTest(Point(x), sys, *locator,
768  u_subdomains, v_subdomains, w_subdomains,
769  es.parameters);
770 #endif
771  }
This is the EquationSystems class.
void tripleValueTest(const Point &p, const TransientExplicitSystem &sys, const PointLocatorBase &locator, std::set< subdomain_id_type > &u_subdomains, std::set< subdomain_id_type > &v_subdomains, std::set< subdomain_id_type > &w_subdomains, const Parameters &param)
Definition: systems_test.C:501
std::unique_ptr< PointLocatorBase > sub_point_locator() const
Definition: mesh_base.C:1675
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
MeshBase & mesh
Manages storage and variables for transient systems.
NumericVector< Number > * old_local_solution
All the values I need to compute my contribution to the simulation at hand.
NumericVector< Number > * older_local_solution
All the values I need to compute my contribution to the simulation at hand.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void build_line(UnstructuredMesh &mesh, const unsigned int nx, const Real xmin=0., const Real xmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 1D meshes.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39

◆ testProjectMatrix1D()

void SystemsTest::testProjectMatrix1D ( const ElemType  elem_type)
inline

Definition at line 1422 of file systems_test.C.

References libMesh::SparseMatrix< T >::add(), libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshBase::allow_renumbering(), libMesh::SparseMatrix< T >::build(), libMesh::MeshTools::Generation::build_line(), libMesh::SparseMatrix< T >::close(), libMesh::DofMap::distribute_dofs(), libMesh::DofMapBase::end_old_dof(), libMesh::FIRST, libMesh::DofMapBase::first_old_dof(), libMesh::System::get_dof_map(), libMesh::EquationSystems::init(), libMesh::SparseMatrix< T >::init(), libMesh::LAGRANGE, libMesh::SparseMatrix< T >::linfty_norm(), mesh, libMesh::System::n_dofs(), libMesh::DofMap::n_local_dofs(), libMesh::MeshTools::Subdivision::next, libMesh::MeshTools::Subdivision::prev, libMesh::System::projection_matrix(), libMesh::Real, libMesh::SparseMatrix< T >::row_start(), libMesh::SparseMatrix< T >::row_stop(), libMesh::SparseMatrix< T >::set(), TestCommWorld, libMesh::TOLERANCE, and libMesh::MeshRefinement::uniformly_refine().

1423  {
1424  // Use ReplicatedMesh to get consistent child element node
1425  // numbering during refinement
1427 
1428  // fix the node numbering to resolve dof_id numbering issues in parallel tests
1429  mesh.allow_renumbering(false);
1430 
1431  // init a simple 1d system
1432  EquationSystems es(mesh);
1433  System &sys = es.add_system<System> ("SimpleSystem");
1434  sys.add_variable("u", FIRST, LAGRANGE);
1435 
1437  4, 0., 1.,
1438  elem_type);
1439 
1440  es.init();
1441 
1442  // static set of coarse nodes / order of fine grid nodes from x=0 to x=1 going left to right
1443  std::set<dof_id_type> coarse_nodes({0,1,2,3,4});
1444  std::vector<dof_id_type> node_order_f({0,5,1,6,2,7,3,8,4});
1445 
1446  // stash number of dofs on coarse grid for projection sizing
1447  int n_old_dofs = sys.n_dofs();
1448 
1449  // save old coarse dof_ids in order of coarse nodes
1450  std::map <dof_id_type, dof_id_type> node2dof_c;
1451  for ( const auto & node : mesh.node_ptr_range() )
1452  {
1453  dof_id_type cdof_id = node->dof_number(0,0,0);
1454  node2dof_c.insert( std::pair<dof_id_type,dof_id_type>( node->id() , cdof_id) );
1455  }
1456 
1457  // refine the mesh so we can utilize old_dof_indices for projection_matrix
1458  MeshRefinement mr(mesh);
1459  mr.uniformly_refine(1);
1461 
1462  // fine node to dof map
1463  std::map <dof_id_type, dof_id_type> node2dof_f;
1464  for ( const auto & node : mesh.local_node_ptr_range() )
1465  {
1466  dof_id_type fdof_id = node->dof_number(0,0,0);
1467  node2dof_f.insert( std::pair<dof_id_type,dof_id_type>(node->id() , fdof_id) );
1468  }
1469 
1470  // local and global projection_matrix sizes infos
1471  int n_new_dofs = sys.n_dofs();
1472  int n_new_dofs_local = sys.get_dof_map().n_local_dofs();
1473  int ndofs_old_first = sys.get_dof_map().first_old_dof();
1474  int ndofs_old_end = sys.get_dof_map().end_old_dof();
1475  int n_old_dofs_local = ndofs_old_end - ndofs_old_first;
1476 
1477  // init and compute the projection matrix using GenericProjector
1478  std::unique_ptr<SparseMatrix<Number> > proj_mat_ptr =
1480  SparseMatrix<Number> & proj_mat = *proj_mat_ptr;
1481  proj_mat.init(n_new_dofs, n_old_dofs, n_new_dofs_local, n_old_dofs_local);
1482  sys.projection_matrix(proj_mat);
1483  proj_mat.close();
1484 
1485  // init the gold standard projection matrix
1486  std::unique_ptr<SparseMatrix<Number> > gold_mat_ptr =
1488  SparseMatrix<Number> & gold_mat = *gold_mat_ptr;
1489  gold_mat.init(n_new_dofs, n_old_dofs, n_new_dofs_local, n_old_dofs_local);
1490 
1491  // construct the gold projection matrix using static node numbering as reference info
1492  for ( const auto & node : mesh.local_node_ptr_range() )
1493  {
1494  dof_id_type node_id = node->id();
1495  dof_id_type fdof_id = (node2dof_f.find(node_id))->second;
1496 
1497  if (coarse_nodes.find(node_id) != coarse_nodes.end() )
1498  { //direct inject coarse nodes
1499  if (fdof_id >= gold_mat.row_start() && fdof_id < gold_mat.row_stop())
1500  {
1501  auto cdof_id = node2dof_c.find(node_id);
1502  gold_mat.set(fdof_id, cdof_id->second, 1.0);
1503  }
1504  }
1505  else
1506  { // new nodes with old_dof neighbor contributions
1507  if (fdof_id >= gold_mat.row_start() && fdof_id < gold_mat.row_stop())
1508  {
1509  auto node_loc = std::find(node_order_f.begin(), node_order_f.end(), node_id);
1510  auto node_n = *std::next(node_loc, 1);
1511  auto node_p = *std::prev(node_loc, 1);
1512  auto dof_p = node2dof_c.find(node_p);
1513  auto dof_n = node2dof_c.find(node_n);
1514 
1515  gold_mat.set(fdof_id, dof_p->second, 0.5);
1516  gold_mat.set(fdof_id, dof_n->second, 0.5);
1517  }
1518  }
1519  } // end gold mat build
1520  gold_mat.close();
1521 
1522  // calculate relative difference norm between the two projection matrices
1523  Real gold_norm = gold_mat.linfty_norm();
1524  gold_mat.add(-1.0, proj_mat);
1525  Real diff_norm = gold_mat.linfty_norm();
1526  CPPUNIT_ASSERT(diff_norm/gold_norm < TOLERANCE*TOLERANCE);
1527  }
This is the EquationSystems class.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
void allow_renumbering(bool allow)
If false is passed in then this mesh will no longer be renumbered when being prepared for use...
Definition: mesh_base.h:1196
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
static constexpr Real TOLERANCE
std::size_t distribute_dofs(MeshBase &)
Distribute dofs on the current mesh.
Definition: dof_map.C:978
dof_id_type end_old_dof(const processor_id_type proc) const
Definition: dof_map_base.h:210
void projection_matrix(SparseMatrix< Number > &proj_mat) const
This method creates a projection matrix which corresponds to the operation of project_vector between ...
static const unsigned int prev[3]
A lookup table for the decrement modulo 3 operation, for iterating through the three nodes per elemen...
MeshBase & mesh
dof_id_type n_local_dofs(const unsigned int vn) const
Definition: dof_map.h:693
dof_id_type n_dofs() const
Definition: system.C:121
virtual numeric_index_type row_stop() const =0
virtual void set(const numeric_index_type i, const numeric_index_type j, const T value)=0
Set the element (i,j) to value.
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value)=0
Add value to the element (i,j).
Generic sparse matrix.
Definition: vector_fe_ex5.C:46
Implements (adaptive) mesh refinement algorithms for a MeshBase.
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:96
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.
Definition: system.C:1357
static const unsigned int next[3]
A lookup table for the increment modulo 3 operation, for iterating through the three nodes per elemen...
virtual void close()=0
Calls the SparseMatrix&#39;s internal assembly routines, ensuring that the values are consistent across p...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual numeric_index_type row_start() const =0
void build_line(UnstructuredMesh &mesh, const unsigned int nx, const Real xmin=0., const Real xmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 1D meshes.
virtual Real linfty_norm() const =0
dof_id_type first_old_dof(const processor_id_type proc) const
Definition: dof_map_base.h:204
const DofMap & get_dof_map() const
Definition: system.h:2374
uint8_t dof_id_type
Definition: id_types.h:67
virtual void init(const numeric_index_type m, const numeric_index_type n, const numeric_index_type m_l, const numeric_index_type n_l, const numeric_index_type nnz=30, const numeric_index_type noz=10, const numeric_index_type blocksize=1)=0
Initialize SparseMatrix with the specified sizes.

◆ testProjectMatrix2D()

void SystemsTest::testProjectMatrix2D ( const ElemType  elem_type)
inline

Definition at line 1529 of file systems_test.C.

References libMesh::SparseMatrix< T >::add(), libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshBase::allow_renumbering(), libMesh::SparseMatrix< T >::build(), libMesh::MeshTools::Generation::build_square(), libMesh::SparseMatrix< T >::close(), libMesh::DofMap::distribute_dofs(), libMesh::DofMapBase::end_old_dof(), libMesh::FIRST, libMesh::DofMapBase::first_old_dof(), libMesh::System::get_dof_map(), libMesh::EquationSystems::init(), libMesh::SparseMatrix< T >::init(), libMesh::LAGRANGE, libMesh::SparseMatrix< T >::linfty_norm(), mesh, libMesh::System::n_dofs(), libMesh::DofMap::n_local_dofs(), libMesh::System::projection_matrix(), libMesh::Real, libMesh::SparseMatrix< T >::row_start(), libMesh::SparseMatrix< T >::row_stop(), libMesh::SparseMatrix< T >::set(), TestCommWorld, libMesh::TOLERANCE, and libMesh::MeshRefinement::uniformly_refine().

1530  {
1531  // Use ReplicatedMesh to get consistent child element node
1532  // numbering during refinement
1534 
1535  // fix the node numbering to resolve dof_id numbering issues in parallel tests
1536  mesh.allow_renumbering(false);
1537 
1538  // init a simple 1d system
1539  EquationSystems es(mesh);
1540  System &sys = es.add_system<System> ("SimpleSystem");
1541  sys.add_variable("u", FIRST, LAGRANGE);
1542 
1543  if (elem_type == Utility::string_to_enum<ElemType>("QUAD4"))
1545  2, 2,
1546  0., 1., 0., 1.,
1547  elem_type);
1548  else if (elem_type == Utility::string_to_enum<ElemType>("TRI3"))
1550  1, 1,
1551  0., 1., 0., 1.,
1552  elem_type);
1553 
1554  es.init();
1555 
1556  // static sets of nodes and their neighbors
1557  std::set<dof_id_type> coarse_nodes;
1558  std::map<dof_id_type, std::vector<dof_id_type>> side_nbr_nodes;
1559  std::map<dof_id_type, std::vector<dof_id_type>> int_nbr_nodes;
1560 
1561  // fill neighbor maps based on static node numbering
1562  if (elem_type == Utility::string_to_enum<ElemType>("QUAD4"))
1563  {
1564  coarse_nodes.insert({0,1,2,3,4,5,6,7,8});
1565 
1566  side_nbr_nodes.insert({9, {0,1}});
1567  side_nbr_nodes.insert({14, {1,2}});
1568  side_nbr_nodes.insert({11, {0,3}});
1569  side_nbr_nodes.insert({12, {1,4}});
1570  side_nbr_nodes.insert({16, {2,5}});
1571  side_nbr_nodes.insert({13, {3,4}});
1572  side_nbr_nodes.insert({17, {4,5}});
1573  side_nbr_nodes.insert({19, {3,6}});
1574  side_nbr_nodes.insert({20, {4,7}});
1575  side_nbr_nodes.insert({23, {5,8}});
1576  side_nbr_nodes.insert({21, {6,7}});
1577  side_nbr_nodes.insert({24, {7,8}});
1578 
1579  int_nbr_nodes.insert({10, {0,1,3,4}});
1580  int_nbr_nodes.insert({15, {1,2,4,5}});
1581  int_nbr_nodes.insert({18, {3,4,6,7}});
1582  int_nbr_nodes.insert({22, {4,5,7,8}});
1583  }
1584  else if (elem_type == Utility::string_to_enum<ElemType>("TRI3"))
1585  {
1586  coarse_nodes.insert({0,1,2,3});
1587 
1588  side_nbr_nodes.insert({4, {0,1}});
1589  side_nbr_nodes.insert({5, {0,3}});
1590  side_nbr_nodes.insert({6, {1,3}});
1591  side_nbr_nodes.insert({7, {0,2}});
1592  side_nbr_nodes.insert({8, {2,3}});
1593  }
1594 
1595  // stash number of dofs on coarse grid for projection sizing
1596  int n_old_dofs = sys.n_dofs();
1597 
1598  // save old coarse dof_ids in order of coarse nodes
1599  std::map <dof_id_type, dof_id_type> node2dof_c;
1600  for ( const auto & node : mesh.node_ptr_range() )
1601  {
1602  dof_id_type cdof_id = node->dof_number(0,0,0);
1603  node2dof_c.insert( std::pair<dof_id_type,dof_id_type>( node->id() , cdof_id) );
1604  }
1605 
1606  // refine the mesh so we can utilize old_dof_indices for projection_matrix
1607  MeshRefinement mr(mesh);
1608  mr.uniformly_refine(1);
1610 
1611  // fine node to dof map
1612  std::map <dof_id_type, dof_id_type> node2dof_f;
1613  for ( const auto & node : mesh.local_node_ptr_range() )
1614  {
1615  dof_id_type fdof_id = node->dof_number(0,0,0);
1616  node2dof_f.insert( std::pair<dof_id_type,dof_id_type>(node->id() , fdof_id) );
1617  }
1618 
1619  // local and global projection_matrix sizes infos
1620  int n_new_dofs = sys.n_dofs();
1621  int n_new_dofs_local = sys.get_dof_map().n_local_dofs();
1622  int ndofs_old_first = sys.get_dof_map().first_old_dof();
1623  int ndofs_old_end = sys.get_dof_map().end_old_dof();
1624  int n_old_dofs_local = ndofs_old_end - ndofs_old_first;
1625 
1626  // init and compute the projection matrix using GenericProjector
1627  std::unique_ptr<SparseMatrix<Number> > proj_mat_ptr =
1629  SparseMatrix<Number> & proj_mat = *proj_mat_ptr;
1630  proj_mat.init(n_new_dofs, n_old_dofs, n_new_dofs_local, n_old_dofs_local);
1631  sys.projection_matrix(proj_mat);
1632  proj_mat.close();
1633 
1634  // init the gold standard projection matrix
1635  std::unique_ptr<SparseMatrix<Number> > gold_mat_ptr =
1637  SparseMatrix<Number> & gold_mat = *gold_mat_ptr;
1638  gold_mat.init(n_new_dofs, n_old_dofs, n_new_dofs_local, n_old_dofs_local);
1639 
1640  // construct the gold projection matrix using static node numbering as reference info
1641  for ( const auto & node : mesh.local_node_ptr_range() )
1642  {
1643  dof_id_type node_id = node->id();
1644  dof_id_type fdof_id = (node2dof_f.find(node_id))->second;
1645 
1646  if (coarse_nodes.find(node_id) != coarse_nodes.end() )
1647  { // direct inject coarse nodes
1648  if (fdof_id >= gold_mat.row_start() && fdof_id < gold_mat.row_stop())
1649  {
1650  auto cdof_id = node2dof_c.find(node_id);
1651  gold_mat.set(fdof_id, cdof_id->second, 1.0);
1652  }
1653  }
1654  else if ( side_nbr_nodes.find(node_id) != side_nbr_nodes.end() )
1655  { // new side nodes with old_dof neighbor contributions
1656  if (fdof_id >= gold_mat.row_start() && fdof_id < gold_mat.row_stop())
1657  {
1658  auto node_nbrs = side_nbr_nodes.find(node_id);
1659  for (auto nbr : node_nbrs->second)
1660  {
1661  auto nbr_dof = node2dof_c.find(nbr);
1662  gold_mat.set(fdof_id, nbr_dof->second, 0.5);
1663  }
1664  }
1665  }
1666  else
1667  { // new interior nodes with old_dof neighbor contributions
1668  if (fdof_id >= gold_mat.row_start() && fdof_id < gold_mat.row_stop())
1669  {
1670  auto node_nbrs = int_nbr_nodes.find(node_id);
1671  for (auto nbr : node_nbrs->second)
1672  {
1673  auto nbr_dof = node2dof_c.find(nbr);
1674  gold_mat.set(fdof_id, nbr_dof->second, 0.25);
1675  }
1676  }
1677  }
1678  } // end gold mat build
1679  gold_mat.close();
1680 
1681  // calculate relative difference norm between the two projection matrices
1682  Real gold_norm = gold_mat.linfty_norm();
1683  proj_mat.add(-1.0, gold_mat);
1684  Real diff_norm = proj_mat.linfty_norm();
1685  CPPUNIT_ASSERT(diff_norm/gold_norm < TOLERANCE*TOLERANCE);
1686  }
This is the EquationSystems class.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
void allow_renumbering(bool allow)
If false is passed in then this mesh will no longer be renumbered when being prepared for use...
Definition: mesh_base.h:1196
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
static constexpr Real TOLERANCE
std::size_t distribute_dofs(MeshBase &)
Distribute dofs on the current mesh.
Definition: dof_map.C:978
dof_id_type end_old_dof(const processor_id_type proc) const
Definition: dof_map_base.h:210
void projection_matrix(SparseMatrix< Number > &proj_mat) const
This method creates a projection matrix which corresponds to the operation of project_vector between ...
MeshBase & mesh
void build_square(UnstructuredMesh &mesh, const unsigned int nx, const unsigned int ny, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 2D meshes.
dof_id_type n_local_dofs(const unsigned int vn) const
Definition: dof_map.h:693
dof_id_type n_dofs() const
Definition: system.C:121
virtual numeric_index_type row_stop() const =0
virtual void set(const numeric_index_type i, const numeric_index_type j, const T value)=0
Set the element (i,j) to value.
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value)=0
Add value to the element (i,j).
Generic sparse matrix.
Definition: vector_fe_ex5.C:46
Implements (adaptive) mesh refinement algorithms for a MeshBase.
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:96
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.
Definition: system.C:1357
virtual void close()=0
Calls the SparseMatrix&#39;s internal assembly routines, ensuring that the values are consistent across p...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual numeric_index_type row_start() const =0
virtual Real linfty_norm() const =0
dof_id_type first_old_dof(const processor_id_type proc) const
Definition: dof_map_base.h:204
const DofMap & get_dof_map() const
Definition: system.h:2374
uint8_t dof_id_type
Definition: id_types.h:67
virtual void init(const numeric_index_type m, const numeric_index_type n, const numeric_index_type m_l, const numeric_index_type n_l, const numeric_index_type nnz=30, const numeric_index_type noz=10, const numeric_index_type blocksize=1)=0
Initialize SparseMatrix with the specified sizes.

◆ testProjectMatrix3D()

void SystemsTest::testProjectMatrix3D ( const ElemType  elem_type)
inline

Definition at line 1688 of file systems_test.C.

References libMesh::SparseMatrix< T >::add(), libMesh::MeshBase::add_elem(), libMesh::MeshBase::add_point(), libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshBase::allow_renumbering(), libMesh::SparseMatrix< T >::build(), libMesh::MeshTools::Generation::build_cube(), libMesh::Elem::build_with_id(), libMesh::SparseMatrix< T >::close(), libMesh::DofMap::distribute_dofs(), libMesh::DofMapBase::end_old_dof(), libMesh::FIRST, libMesh::DofMapBase::first_old_dof(), libMesh::System::get_dof_map(), libMesh::EquationSystems::init(), libMesh::SparseMatrix< T >::init(), libMesh::LAGRANGE, libMesh::SparseMatrix< T >::linfty_norm(), mesh, libMesh::System::n_dofs(), libMesh::DofMapBase::n_dofs_on_processor(), libMesh::MeshBase::node_ptr(), libMesh::MeshBase::prepare_for_use(), libMesh::ParallelObject::processor_id(), libMesh::System::projection_matrix(), libMesh::Real, libMesh::SparseMatrix< T >::row_start(), libMesh::SparseMatrix< T >::row_stop(), libMesh::SparseMatrix< T >::set(), libMesh::Elem::set_node(), TestCommWorld, libMesh::TET4, libMesh::TOLERANCE, and libMesh::MeshRefinement::uniformly_refine().

1689  {
1690  // Use ReplicatedMesh to get consistent child element node
1691  // numbering during refinement
1693 
1694  // fix the node numbering to resolve dof_id numbering issues in parallel tests
1695  mesh.allow_renumbering(false);
1696 
1697  // init a simple 1d system
1698  EquationSystems es(mesh);
1699  System &sys = es.add_system<System> ("SimpleSystem");
1700  sys.add_variable("u", FIRST, LAGRANGE);
1701 
1702  if (elem_type == Utility::string_to_enum<ElemType>("HEX8"))
1704  1, 1, 1,
1705  0., 1., 0., 1., 0., 1.,
1706  elem_type);
1707  else if (elem_type == Utility::string_to_enum<ElemType>("TET4"))
1708  {
1709  // manually build a Tet4 element
1710  mesh.add_point( Point(0,0,0), 0 );
1711  mesh.add_point( Point(1,0,0), 1 );
1712  mesh.add_point( Point(0,1,0), 2 );
1713  mesh.add_point( Point(1./3.,1./3.,1), 3 );
1714 
1715  Elem * elem = mesh.add_elem(Elem::build_with_id(TET4, 0));
1716  elem->set_node(0, mesh.node_ptr(0));
1717  elem->set_node(1, mesh.node_ptr(1));
1718  elem->set_node(2, mesh.node_ptr(2));
1719  elem->set_node(3, mesh.node_ptr(3));
1720 
1722  }
1723  es.init();
1724 
1725  // static sets of nodes and their neighbors
1726  std::set<dof_id_type> coarse_nodes;
1727  std::map<dof_id_type, std::vector<dof_id_type>> side_nbr_nodes;
1728  std::map<dof_id_type, std::vector<dof_id_type>> face_nbr_nodes;
1729  std::map<dof_id_type, std::vector<dof_id_type>> int_nbr_nodes;
1730 
1731  if (elem_type == Utility::string_to_enum<ElemType>("HEX8"))
1732  {
1733  coarse_nodes.insert({0,1,2,3,4,5,6,7});
1734 
1735  // fill neighbor maps based on static node numbering
1736  side_nbr_nodes.insert({8, {0,1}});
1737  side_nbr_nodes.insert({10, {0,2}});
1738  side_nbr_nodes.insert({15, {1,3}});
1739  side_nbr_nodes.insert({18, {2,3}});
1740  side_nbr_nodes.insert({11, {0,4}});
1741  side_nbr_nodes.insert({16, {1,5}});
1742  side_nbr_nodes.insert({21, {3,7}});
1743  side_nbr_nodes.insert({20, {2,6}});
1744  side_nbr_nodes.insert({22, {4,5}});
1745  side_nbr_nodes.insert({24, {4,6}});
1746  side_nbr_nodes.insert({25, {5,7}});
1747  side_nbr_nodes.insert({26, {6,7}});
1748 
1749  face_nbr_nodes.insert({12, {0,1,4,5}});
1750  face_nbr_nodes.insert({9 , {0,1,2,3}});
1751  face_nbr_nodes.insert({14, {0,2,4,6}});
1752  face_nbr_nodes.insert({17, {1,3,5,7}});
1753  face_nbr_nodes.insert({19, {2,3,6,7}});
1754  face_nbr_nodes.insert({23, {4,5,6,7}});
1755 
1756  int_nbr_nodes.insert({13, {0,1,2,3,4,5,6,7}});
1757  }
1758  else if (elem_type == Utility::string_to_enum<ElemType>("TET4"))
1759  {
1760  coarse_nodes.insert({0,1,2,3});
1761 
1762  // fill neighbor maps based on static node numbering
1763  side_nbr_nodes.insert({4, {0,1}});
1764  side_nbr_nodes.insert({5, {0,2}});
1765  side_nbr_nodes.insert({6, {0,3}});
1766  side_nbr_nodes.insert({7, {1,2}});
1767  side_nbr_nodes.insert({8, {1,3}});
1768  side_nbr_nodes.insert({9, {2,3}});
1769  }
1770 
1771  // stash number of dofs on coarse grid for projection sizing
1772  int n_old_dofs = sys.n_dofs();
1773 
1774  // save old coarse dof_ids in order of coarse nodes
1775  std::map <dof_id_type, dof_id_type> node2dof_c;
1776  for ( const auto & node : mesh.node_ptr_range() )
1777  {
1778  dof_id_type cdof_id = node->dof_number(0,0,0);
1779  node2dof_c.insert( std::pair<dof_id_type,dof_id_type>( node->id() , cdof_id) );
1780  }
1781 
1782  // refine the mesh so we can utilize old_dof_indices for projection_matrix
1783  MeshRefinement mr(mesh);
1784  mr.uniformly_refine(1);
1786 
1787  // fine node to dof map
1788  std::map <dof_id_type, dof_id_type> node2dof_f;
1789  for ( const auto & node : mesh.local_node_ptr_range() )
1790  {
1791  dof_id_type fdof_id = node->dof_number(0,0,0);
1792  node2dof_f.insert( std::pair<dof_id_type,dof_id_type>(node->id() , fdof_id) );
1793  }
1794 
1795  // local and global projection_matrix sizes infos
1796  int n_new_dofs = sys.n_dofs();
1797  int n_new_dofs_local = sys.get_dof_map().n_dofs_on_processor(sys.processor_id());
1798  int ndofs_old_first = sys.get_dof_map().first_old_dof(sys.processor_id());
1799  int ndofs_old_end = sys.get_dof_map().end_old_dof(sys.processor_id());
1800  int n_old_dofs_local = ndofs_old_end - ndofs_old_first;
1801 
1802  // init and compute the projection matrix using GenericProjector
1803  std::unique_ptr<SparseMatrix<Number> > proj_mat_ptr =
1805  SparseMatrix<Number> & proj_mat = *proj_mat_ptr;
1806  proj_mat.init(n_new_dofs, n_old_dofs, n_new_dofs_local, n_old_dofs_local);
1807  sys.projection_matrix(proj_mat);
1808  proj_mat.close();
1809 
1810  // init the gold standard projection matrix
1811  std::unique_ptr<SparseMatrix<Number> > gold_mat_ptr =
1813  SparseMatrix<Number> & gold_mat = *gold_mat_ptr;
1814  gold_mat.init(n_new_dofs, n_old_dofs, n_new_dofs_local, n_old_dofs_local);
1815 
1816  // construct the gold projection matrix using static node numbering as reference info
1817  for ( const auto & node : mesh.local_node_ptr_range() )
1818  {
1819  dof_id_type node_id = node->id();
1820  dof_id_type fdof_id = (node2dof_f.find(node_id))->second;
1821 
1822  if (coarse_nodes.find(node_id) != coarse_nodes.end() )
1823  { // direct inject coarse nodes
1824  if (fdof_id >= gold_mat.row_start() && fdof_id < gold_mat.row_stop())
1825  {
1826  auto cdof_id = node2dof_c.find(node_id);
1827  gold_mat.set(fdof_id, cdof_id->second, 1.0);
1828  }
1829  }
1830  else if ( side_nbr_nodes.find(node_id) != side_nbr_nodes.end() )
1831  { // new side nodes with old_dof neighbor contributions
1832  if (fdof_id >= gold_mat.row_start() && fdof_id < gold_mat.row_stop())
1833  {
1834  auto node_nbrs = side_nbr_nodes.find(node_id);
1835  for (auto nbr : node_nbrs->second)
1836  {
1837  auto nbr_dof = node2dof_c.find(nbr);
1838  gold_mat.set(fdof_id, nbr_dof->second, 0.5);
1839  }
1840  }
1841  }
1842  else if ( face_nbr_nodes.find(node_id) != face_nbr_nodes.end() )
1843  { // new face nodes with old_dof neighbor contributions
1844  if (fdof_id >= gold_mat.row_start() && fdof_id < gold_mat.row_stop())
1845  {
1846  auto node_nbrs = face_nbr_nodes.find(node_id);
1847  for (auto nbr : node_nbrs->second)
1848  {
1849  auto nbr_dof = node2dof_c.find(nbr);
1850  gold_mat.set(fdof_id, nbr_dof->second, 0.25);
1851  }
1852  }
1853  }
1854  else
1855  { // new interior nodes with old_dof neighbor contributions
1856  if (fdof_id >= gold_mat.row_start() && fdof_id < gold_mat.row_stop())
1857  {
1858  auto node_nbrs = int_nbr_nodes.find(node_id);
1859  for (auto nbr : node_nbrs->second)
1860  {
1861  auto nbr_dof = node2dof_c.find(nbr);
1862  gold_mat.set(fdof_id, nbr_dof->second, 0.125);
1863  }
1864  }
1865  }
1866  } // end gold mat build
1867  gold_mat.close();
1868 
1869  // calculate relative difference norm between the two projection matrices
1870  Real gold_norm = gold_mat.linfty_norm();
1871  proj_mat.add(-1.0, gold_mat);
1872  Real diff_norm = proj_mat.linfty_norm();
1873  CPPUNIT_ASSERT(diff_norm/gold_norm < TOLERANCE*TOLERANCE);
1874  }
This is the EquationSystems class.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
virtual Node *& set_node(const unsigned int i)
Definition: elem.h:2558
void allow_renumbering(bool allow)
If false is passed in then this mesh will no longer be renumbered when being prepared for use...
Definition: mesh_base.h:1196
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
static constexpr Real TOLERANCE
std::size_t distribute_dofs(MeshBase &)
Distribute dofs on the current mesh.
Definition: dof_map.C:978
dof_id_type end_old_dof(const processor_id_type proc) const
Definition: dof_map_base.h:210
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.
Definition: mesh_base.C:759
void projection_matrix(SparseMatrix< Number > &proj_mat) const
This method creates a projection matrix which corresponds to the operation of project_vector between ...
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
MeshBase & mesh
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id)=0
Add a new Node at Point p to the end of the vertex array, with processor_id procid.
dof_id_type n_dofs() const
Definition: system.C:121
virtual numeric_index_type row_stop() const =0
virtual void set(const numeric_index_type i, const numeric_index_type j, const T value)=0
Set the element (i,j) to value.
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value)=0
Add value to the element (i,j).
Generic sparse matrix.
Definition: vector_fe_ex5.C:46
Implements (adaptive) mesh refinement algorithms for a MeshBase.
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:96
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
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.
Definition: system.C:1357
dof_id_type n_dofs_on_processor(const processor_id_type proc) const
Definition: dof_map_base.h:197
virtual void close()=0
Calls the SparseMatrix&#39;s internal assembly routines, ensuring that the values are consistent across p...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual numeric_index_type row_start() const =0
virtual Real linfty_norm() const =0
dof_id_type first_old_dof(const processor_id_type proc) const
Definition: dof_map_base.h:204
virtual const Node * node_ptr(const dof_id_type i) const =0
processor_id_type processor_id() const
const DofMap & get_dof_map() const
Definition: system.h:2374
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.
uint8_t dof_id_type
Definition: id_types.h:67
virtual void init(const numeric_index_type m, const numeric_index_type n, const numeric_index_type m_l, const numeric_index_type n_l, const numeric_index_type nnz=30, const numeric_index_type noz=10, const numeric_index_type blocksize=1)=0
Initialize SparseMatrix with the specified sizes.

◆ testProjectMatrixEdge2()

void SystemsTest::testProjectMatrixEdge2 ( )
inline

Definition at line 1903 of file systems_test.C.

References libMesh::EDGE2.

1903 { LOG_UNIT_TEST; testProjectMatrix1D(EDGE2); }
void testProjectMatrix1D(const ElemType elem_type)

◆ testProjectMatrixHex8()

void SystemsTest::testProjectMatrixHex8 ( )
inline

Definition at line 1906 of file systems_test.C.

References libMesh::HEX8.

1906 { LOG_UNIT_TEST; testProjectMatrix3D(HEX8); }
void testProjectMatrix3D(const ElemType elem_type)

◆ testProjectMatrixQuad4()

void SystemsTest::testProjectMatrixQuad4 ( )
inline

Definition at line 1904 of file systems_test.C.

References libMesh::QUAD4.

1904 { LOG_UNIT_TEST; testProjectMatrix2D(QUAD4); }
void testProjectMatrix2D(const ElemType elem_type)

◆ testProjectMatrixTet4()

void SystemsTest::testProjectMatrixTet4 ( )
inline

Definition at line 1907 of file systems_test.C.

References libMesh::TET4.

1907 { LOG_UNIT_TEST; testProjectMatrix3D(TET4); }
void testProjectMatrix3D(const ElemType elem_type)

◆ testProjectMatrixTri3()

void SystemsTest::testProjectMatrixTri3 ( )
inline

Definition at line 1905 of file systems_test.C.

References libMesh::TRI3.

1905 { LOG_UNIT_TEST; testProjectMatrix2D(TRI3); }
void testProjectMatrix2D(const ElemType elem_type)

◆ testProjectMeshFunctionHex27()

void SystemsTest::testProjectMeshFunctionHex27 ( )
inline

Definition at line 1885 of file systems_test.C.

References libMesh::HEX27.

1885 { LOG_UNIT_TEST; testProjectCubeWithMeshFunction(HEX27); }
void testProjectCubeWithMeshFunction(const ElemType elem_type)
Definition: systems_test.C:987

◆ testProjectSquare()

void SystemsTest::testProjectSquare ( const ElemType  elem_type)
inline

Definition at line 873 of file systems_test.C.

References libMesh::EquationSystems::add_system(), libMesh::MeshTools::Generation::build_square(), libMesh::CONSTANT, libMesh::FIRST, libMesh::HIERARCHIC, libMesh::EquationSystems::init(), libMesh::LAGRANGE, mesh, libMesh::MONOMIAL, TripleFunction::offset, libMesh::TransientSystem< Base >::old_local_solution, libMesh::TransientSystem< Base >::older_local_solution, libMesh::EquationSystems::parameters, libMesh::Real, libMesh::Elem::REFINE, libMesh::EquationSystems::reinit(), libMesh::MeshBase::sub_point_locator(), TestCommWorld, and libMesh::THIRD.

874  {
876 
877  EquationSystems es(mesh);
879  es.add_system<TransientExplicitSystem> ("SimpleSystem");
880 
881  std::set<subdomain_id_type> u_subdomains {0, 1, 4, 5},
882  v_subdomains {1, 2, 3, 4},
883  w_subdomains {0, 1, 2, 3, 4};
884 
885  sys.add_variable("u", THIRD, HIERARCHIC, &u_subdomains);
886  sys.add_variable("v", FIRST, LAGRANGE, &v_subdomains);
887  sys.add_variable("w", CONSTANT, MONOMIAL, &w_subdomains);
888 
890  3, 3,
891  0., 1., 0., 1.,
892  elem_type);
893 
894  for (auto & elem : mesh.element_ptr_range())
895  elem->subdomain_id() = elem->id()/2;
896 
897  es.init();
898  TripleFunction tfunc;
899  sys.project_solution(&tfunc);
900  tfunc.offset = 10;
901  sys.project_vector(*sys.old_local_solution, &tfunc);
902  tfunc.offset = 20;
903  sys.project_vector(*sys.older_local_solution, &tfunc);
904 
905  std::unique_ptr<PointLocatorBase> locator = mesh.sub_point_locator();
906  locator->enable_out_of_mesh_mode();
907  for (Real x = 0.1; x < 1; x += 0.2)
908  for (Real y = 0.1; y < 1; y += 0.2)
909  tripleValueTest(Point(x,y), sys, *locator,
910  u_subdomains, v_subdomains, w_subdomains,
911  es.parameters);
912 
913 #ifdef LIBMESH_ENABLE_AMR
914  for (auto & elem : mesh.element_ptr_range())
915  if ((elem->id()/2)%2)
916  elem->set_refinement_flag(Elem::REFINE);
917  es.reinit();
918 
919  locator = mesh.sub_point_locator();
920  locator->enable_out_of_mesh_mode();
921  for (Real x = 0.1; x < 1; x += 0.2)
922  for (Real y = 0.1; y < 1; y += 0.2)
923  tripleValueTest(Point(x,y), sys, *locator,
924  u_subdomains, v_subdomains, w_subdomains,
925  es.parameters);
926 #endif
927  }
This is the EquationSystems class.
void tripleValueTest(const Point &p, const TransientExplicitSystem &sys, const PointLocatorBase &locator, std::set< subdomain_id_type > &u_subdomains, std::set< subdomain_id_type > &v_subdomains, std::set< subdomain_id_type > &w_subdomains, const Parameters &param)
Definition: systems_test.C:501
std::unique_ptr< PointLocatorBase > sub_point_locator() const
Definition: mesh_base.C:1675
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
MeshBase & mesh
Manages storage and variables for transient systems.
void build_square(UnstructuredMesh &mesh, const unsigned int nx, const unsigned int ny, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 2D meshes.
NumericVector< Number > * old_local_solution
All the values I need to compute my contribution to the simulation at hand.
NumericVector< Number > * older_local_solution
All the values I need to compute my contribution to the simulation at hand.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39

◆ testSetSystemParameterOverEquationSystem()

void SystemsTest::testSetSystemParameterOverEquationSystem ( )
inline

Definition at line 1264 of file systems_test.C.

References libMesh::MeshBase::add_elem(), libMesh::MeshBase::add_point(), libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), assembly_with_dg_fem_context(), libMesh::Elem::build(), libMesh::MeshTools::Generation::build_cube(), libMesh::EDGE2, libMesh::MeshBase::elem_ref(), libMesh::FIRST, libMesh::GMRES, libMesh::HEX8, libMesh::IDENTITY_PRECOND, libMesh::EquationSystems::init(), libMesh::L2_LAGRANGE, mesh, libMesh::EquationSystems::parameters, libMesh::MeshBase::prepare_for_use(), libMesh::Real, libMesh::Parameters::set(), libMesh::Elem::set_node(), libMesh::Elem::subdomain_id(), and TestCommWorld.

1265  {
1266  LOG_UNIT_TEST;
1267 
1269 
1271  1,
1272  0,
1273  0,
1274  0., 1.,
1275  0., 0.,
1276  0., 0.,
1277  EDGE2);
1278 
1279  Point new_point_a(2.);
1280  Point new_point_b(3.);
1281  Node* new_node_a = mesh.add_point( new_point_a );
1282  Node* new_node_b = mesh.add_point( new_point_b );
1283  auto new_edge_elem = mesh.add_elem(Elem::build(EDGE2));
1284  new_edge_elem->set_node(0, new_node_a);
1285  new_edge_elem->set_node(1, new_node_b);
1286 
1287  mesh.elem_ref(0).subdomain_id() = 10;
1288  mesh.elem_ref(1).subdomain_id() = 10;
1289 
1291 
1292  // Create an equation systems object.
1293  EquationSystems equation_systems (mesh);
1294 
1295  // Set some parameters to the equation system that would cause a failed test
1296  equation_systems.parameters.set<unsigned int>("linear solver maximum iterations") = 0;
1297 
1298  // Setup Linear Implicit system
1299  LinearImplicitSystem & li_system =
1300  equation_systems.add_system<LinearImplicitSystem> ("test");
1301 
1302  // We must use a discontinuous variable type in this test or
1303  // else the sparsity pattern will not be correct
1304  li_system.add_variable("u", FIRST, L2_LAGRANGE);
1305 
1307  5, 5, 5,
1308  0., 1., 0., 1., 0., 1.,
1309  HEX8);
1310 
1311  li_system.attach_assemble_function (assembly_with_dg_fem_context);
1312  li_system.get_linear_solver()->set_solver_type(GMRES);
1313  // Need 5 iterations, dont overdo the preconditioning
1314  li_system.get_linear_solver()->set_preconditioner_type(IDENTITY_PRECOND);
1315 
1316  // Set some parameters to the system that work for the solve
1317  li_system.parameters.set<unsigned int>("linear solver maximum iterations") = 5;
1318  li_system.parameters.set<Real>("linear solver tolerance") = 1e-100;
1319 
1320  // Need to init before we can access the system matrix
1321  equation_systems.init ();
1322 
1323  // See the solve pass, indicating system parameters are used over equation system parameters
1324  li_system.solve();
1325 
1326  // Check that the number of iterations from the systems got obeyed
1327  CPPUNIT_ASSERT_EQUAL(li_system.n_linear_iterations(), 5u);
1328 }
This is the EquationSystems class.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
virtual Node *& set_node(const unsigned int i)
Definition: elem.h:2558
A Node is like a Point, but with more information.
Definition: node.h:52
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
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.
Definition: mesh_base.C:759
MeshBase & mesh
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id)=0
Add a new Node at Point p to the end of the vertex array, with processor_id procid.
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
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.
Definition: system.C:1357
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
subdomain_id_type subdomain_id() const
Definition: elem.h:2582
virtual const Elem & elem_ref(const dof_id_type i) const
Definition: mesh_base.h:639
void assembly_with_dg_fem_context(EquationSystems &es, const std::string &)
Definition: systems_test.C:203
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.

◆ tripleValueTest()

void SystemsTest::tripleValueTest ( const Point p,
const TransientExplicitSystem sys,
const PointLocatorBase locator,
std::set< subdomain_id_type > &  u_subdomains,
std::set< subdomain_id_type > &  v_subdomains,
std::set< subdomain_id_type > &  w_subdomains,
const Parameters param 
)
inlineprivate

Definition at line 501 of file systems_test.C.

References cubic_test(), disc_thirds_test(), TIMPI::Communicator::max(), new_linear_test(), libMesh::TransientSystem< Base >::old_local_solution, libMesh::TransientSystem< Base >::older_local_solution, libMesh::Elem::subdomain_id(), TestCommWorld, and libMesh::TOLERANCE.

508  {
509  const Elem * elem = locator(p);
510  subdomain_id_type sbd_id = elem ? elem->subdomain_id() : 0;
511  TestCommWorld->max(sbd_id);
512 
513  if (u_subdomains.count(sbd_id))
514  {
515  LIBMESH_ASSERT_NUMBERS_EQUAL(cubic_test(p,param,"",""),
516  sys.point_value(0,p),
517  TOLERANCE*TOLERANCE*10);
518  LIBMESH_ASSERT_NUMBERS_EQUAL
519  (cubic_test(p,param,"","") + Number(10),
520  sys.point_value(0,p,sys.old_local_solution),
521  TOLERANCE*TOLERANCE*100);
522  LIBMESH_ASSERT_NUMBERS_EQUAL
523  (cubic_test(p,param,"","") + Number(20),
524  sys.point_value(0,p,sys.older_local_solution),
525  TOLERANCE*TOLERANCE*100);
526  }
527  if (v_subdomains.count(sbd_id))
528  {
529  LIBMESH_ASSERT_NUMBERS_EQUAL
530  (new_linear_test(p,param,"",""), sys.point_value(1,p),
531  TOLERANCE*TOLERANCE*10);
532  LIBMESH_ASSERT_NUMBERS_EQUAL
533  (new_linear_test(p,param,"","") + Number(10),
534  sys.point_value(1,p,sys.old_local_solution),
535  TOLERANCE*TOLERANCE*100);
536  LIBMESH_ASSERT_NUMBERS_EQUAL
537  (new_linear_test(p,param,"","") + Number(20),
538  sys.point_value(1,p,sys.older_local_solution),
539  TOLERANCE*TOLERANCE*100);
540  }
541  if (w_subdomains.count(sbd_id))
542  {
543  LIBMESH_ASSERT_NUMBERS_EQUAL
544  (disc_thirds_test(p,param,"",""), sys.point_value(2,p),
545  TOLERANCE*TOLERANCE*10);
546  LIBMESH_ASSERT_NUMBERS_EQUAL
547  (disc_thirds_test(p,param,"","") + Number(10),
548  sys.point_value(2,p,sys.old_local_solution),
549  TOLERANCE*TOLERANCE*100);
550  LIBMESH_ASSERT_NUMBERS_EQUAL
551  (disc_thirds_test(p,param,"","") + Number(20),
552  sys.point_value(2,p,sys.older_local_solution),
553  TOLERANCE*TOLERANCE*100);
554  }
555  }
Number cubic_test(const Point &p, const Parameters &, const std::string &, const std::string &)
Definition: systems_test.C:351
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
static constexpr Real TOLERANCE
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
Number disc_thirds_test(const Point &p, const Parameters &, const std::string &, const std::string &)
Definition: systems_test.C:377
NumericVector< Number > * old_local_solution
All the values I need to compute my contribution to the simulation at hand.
NumericVector< Number > * older_local_solution
All the values I need to compute my contribution to the simulation at hand.
Number new_linear_test(const Point &p, const Parameters &, const std::string &, const std::string &)
Definition: systems_test.C:364
subdomain_id_type subdomain_id() const
Definition: elem.h:2582
void max(const T &r, T &o, Request &req) const

The documentation for this class was generated from the following file: