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 (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 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/32]

SystemsTest::CPPUNIT_TEST ( test100KVariables  )

◆ CPPUNIT_TEST() [2/32]

SystemsTest::CPPUNIT_TEST ( testPostInitAddVector  )

◆ CPPUNIT_TEST() [3/32]

SystemsTest::CPPUNIT_TEST ( testAddVectorProjChange  )

◆ CPPUNIT_TEST() [4/32]

SystemsTest::CPPUNIT_TEST ( testAddVectorTypeChange  )

◆ CPPUNIT_TEST() [5/32]

SystemsTest::CPPUNIT_TEST ( testPostInitAddVectorTypeChange  )

◆ CPPUNIT_TEST() [6/32]

SystemsTest::CPPUNIT_TEST ( testProjectHierarchicEdge3  )

◆ CPPUNIT_TEST() [7/32]

SystemsTest::CPPUNIT_TEST ( testProjectHierarchicQuad9  )

◆ CPPUNIT_TEST() [8/32]

SystemsTest::CPPUNIT_TEST ( testProjectHierarchicTri6  )

◆ CPPUNIT_TEST() [9/32]

SystemsTest::CPPUNIT_TEST ( testProjectHierarchicTri7  )

◆ CPPUNIT_TEST() [10/32]

SystemsTest::CPPUNIT_TEST ( test2DProjectVectorFETri3  )

◆ CPPUNIT_TEST() [11/32]

SystemsTest::CPPUNIT_TEST ( test2DProjectVectorFEQuad4  )

◆ CPPUNIT_TEST() [12/32]

SystemsTest::CPPUNIT_TEST ( test2DProjectVectorFETri6  )

◆ CPPUNIT_TEST() [13/32]

SystemsTest::CPPUNIT_TEST ( test2DProjectVectorFETri7  )

◆ CPPUNIT_TEST() [14/32]

SystemsTest::CPPUNIT_TEST ( test2DProjectVectorFEQuad8  )

◆ CPPUNIT_TEST() [15/32]

SystemsTest::CPPUNIT_TEST ( test2DProjectVectorFEQuad9  )

◆ CPPUNIT_TEST() [16/32]

SystemsTest::CPPUNIT_TEST ( testBlockRestrictedVarNDofs  )

◆ CPPUNIT_TEST() [17/32]

SystemsTest::CPPUNIT_TEST ( testProjectHierarchicHex27  )

◆ CPPUNIT_TEST() [18/32]

SystemsTest::CPPUNIT_TEST ( testProjectMeshFunctionHex27  )

◆ CPPUNIT_TEST() [19/32]

SystemsTest::CPPUNIT_TEST ( testBoundaryProjectCube  )

◆ CPPUNIT_TEST() [20/32]

SystemsTest::CPPUNIT_TEST ( test3DProjectVectorFETet4  )

◆ CPPUNIT_TEST() [21/32]

SystemsTest::CPPUNIT_TEST ( test3DProjectVectorFEHex8  )

◆ CPPUNIT_TEST() [22/32]

SystemsTest::CPPUNIT_TEST ( test3DProjectVectorFETet10  )

◆ CPPUNIT_TEST() [23/32]

SystemsTest::CPPUNIT_TEST ( test3DProjectVectorFETet14  )

◆ CPPUNIT_TEST() [24/32]

SystemsTest::CPPUNIT_TEST ( test3DProjectVectorFEHex20  )

◆ CPPUNIT_TEST() [25/32]

SystemsTest::CPPUNIT_TEST ( test3DProjectVectorFEHex27  )

◆ CPPUNIT_TEST() [26/32]

SystemsTest::CPPUNIT_TEST ( testAssemblyWithDgFemContext  )

◆ CPPUNIT_TEST() [27/32]

SystemsTest::CPPUNIT_TEST ( testDofCouplingWithVarGroups  )

◆ CPPUNIT_TEST() [28/32]

SystemsTest::CPPUNIT_TEST ( testProjectMatrixEdge2  )

◆ CPPUNIT_TEST() [29/32]

SystemsTest::CPPUNIT_TEST ( testProjectMatrixQuad4  )

◆ CPPUNIT_TEST() [30/32]

SystemsTest::CPPUNIT_TEST ( testProjectMatrixTri3  )

◆ CPPUNIT_TEST() [31/32]

SystemsTest::CPPUNIT_TEST ( testProjectMatrixHex8  )

◆ CPPUNIT_TEST() [32/32]

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 551 of file systems_test.C.

552  {}

◆ simpleSetup()

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

Definition at line 558 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.

560  {
561  ExplicitSystem &sys =
562  es.add_system<ExplicitSystem> ("Simple");
563 
564  sys.add_variable("u", FIRST);
565 
567  10,
568  0., 1.,
569  EDGE3);
570 
571  return sys;
572  }
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:1305
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 554 of file systems_test.C.

555  {}

◆ test100KVariables()

void SystemsTest::test100KVariables ( )
inline

Definition at line 575 of file systems_test.C.

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

576  {
578  EquationSystems es(mesh);
579  ExplicitSystem &sys =
580  es.add_system<ExplicitSystem> ("100KVars");
581 
582  dof_id_type n_dofs = 100000;
583 
584  // This takes 16 seconds in opt mode for me, 200 in dbg!?
585  /*
586  for (auto i : make_range(n_dofs))
587  sys.add_variable(std::to_string(i), FIRST);
588  */
589 
590  std::vector<std::string> var_names(n_dofs);
591  for (auto i : make_range(n_dofs))
592  var_names[i] = std::to_string(i);
593 
594  sys.add_variables(var_names, FIRST);
595 
597  1,
598  0., 1.,
599  EDGE3);
600 
601  es.init();
602 
603  CPPUNIT_ASSERT_EQUAL(sys.n_dofs(), n_dofs*2);
604  for (const Node * node : mesh.node_ptr_range())
605  CPPUNIT_ASSERT_EQUAL(dof_id_type(node->n_vars(0)), n_dofs);
606  }
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:1419
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:159
MeshBase & mesh
dof_id_type n_dofs() const
Definition: system.C:113
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:134
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
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 762 of file systems_test.C.

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

763  {
765 
766  EquationSystems es(mesh);
768  es.add_system<TransientExplicitSystem> ("SimpleSystem");
769 
770  auto generic_elem = Elem::build(elem_type);
771 
772  auto u_var = sys.add_variable("u", generic_elem->default_order(), LAGRANGE_VEC);
773 
775  1, 1,
776  0., 1., 0., 1.,
777  elem_type);
778 
779  es.init();
780 
781  // Manually set-up the solution because I'm too lazy to set-up all the generic
782  // function projection code right now
783  for (const auto & node : mesh.local_node_ptr_range())
784  {
785  for (unsigned int i = 0; i < generic_elem->dim(); ++i)
786  {
787  auto dof_index = node->dof_number(sys.number(), u_var, i);
788  sys.solution->set(dof_index, (*node)(i));
789  }
790  }
791 
792  // After setting values, we need to assemble
793  sys.solution->close();
794 
795 
796 #ifdef LIBMESH_ENABLE_AMR
797  for (auto & elem : mesh.element_ptr_range())
798  elem->set_refinement_flag(Elem::REFINE);
799  es.reinit();
800 #endif
801 
802  for (const auto & node : mesh.local_node_ptr_range())
803  {
804  // 2D element here
805  for (unsigned int i = 0; i < generic_elem->dim(); ++i)
806  {
807  auto dof_index = node->dof_number(sys.number(), u_var, i);
808  auto value = (*sys.solution)(dof_index);
809  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(value), (*node)(i), TOLERANCE*TOLERANCE);
810  }
811  }
812  }
T libmesh_real(T a)
This is the EquationSystems class.
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:159
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:54
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 1812 of file systems_test.C.

References libMesh::QUAD4.

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

◆ test2DProjectVectorFEQuad8()

void SystemsTest::test2DProjectVectorFEQuad8 ( )
inline

Definition at line 1815 of file systems_test.C.

References libMesh::QUAD8.

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

◆ test2DProjectVectorFEQuad9()

void SystemsTest::test2DProjectVectorFEQuad9 ( )
inline

Definition at line 1816 of file systems_test.C.

References libMesh::QUAD9.

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

◆ test2DProjectVectorFETri3()

void SystemsTest::test2DProjectVectorFETri3 ( )
inline

Definition at line 1811 of file systems_test.C.

References libMesh::TRI3.

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

◆ test2DProjectVectorFETri6()

void SystemsTest::test2DProjectVectorFETri6 ( )
inline

Definition at line 1813 of file systems_test.C.

References libMesh::TRI6.

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

◆ test2DProjectVectorFETri7()

void SystemsTest::test2DProjectVectorFETri7 ( )
inline

Definition at line 1814 of file systems_test.C.

References libMesh::TRI7.

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

◆ test3DProjectVectorFE()

void SystemsTest::test3DProjectVectorFE ( const ElemType  elem_type)
inline

Definition at line 814 of file systems_test.C.

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

815  {
817 
818  EquationSystems es(mesh);
820  es.add_system<TransientExplicitSystem> ("SimpleSystem");
821 
822  auto generic_elem = Elem::build(elem_type);
823 
824  auto u_var = sys.add_variable("u", generic_elem->default_order(), LAGRANGE_VEC);
825 
827  1, 1, 1,
828  0., 1., 0., 1., 0., 1.,
829  elem_type);
830 
831  es.init();
832 
833  // Manually set-up the solution because I'm too lazy to set-up all the generic
834  // function projection code right now
835  for (const auto & node : mesh.local_node_ptr_range())
836  {
837  for (unsigned int i = 0; i < generic_elem->dim(); ++i)
838  {
839  auto dof_index = node->dof_number(sys.number(), u_var, i);
840  sys.solution->set(dof_index, (*node)(i));
841  }
842  }
843 
844  // After setting values, we need to assemble
845  sys.solution->close();
846 
847 
848 #ifdef LIBMESH_ENABLE_AMR
849  for (auto & elem : mesh.element_ptr_range())
850  elem->set_refinement_flag(Elem::REFINE);
851  es.reinit();
852 #endif
853 
854  for (const auto & node : mesh.local_node_ptr_range())
855  {
856  for (unsigned int i = 0; i < generic_elem->dim(); ++i)
857  {
858  auto dof_index = node->dof_number(sys.number(), u_var, i);
859  auto value = (*sys.solution)(dof_index);
860  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(value), (*node)(i), TOLERANCE*TOLERANCE);
861  }
862  }
863  }
T libmesh_real(T a)
This is the EquationSystems class.
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:159
static constexpr Real TOLERANCE
MeshBase & mesh
Manages storage and variables for transient systems.
static const bool value
Definition: xdr_io.C:54
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 1821 of file systems_test.C.

References libMesh::HEX20.

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

◆ test3DProjectVectorFEHex27()

void SystemsTest::test3DProjectVectorFEHex27 ( )
inline

Definition at line 1822 of file systems_test.C.

References libMesh::HEX27.

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

◆ test3DProjectVectorFEHex8()

void SystemsTest::test3DProjectVectorFEHex8 ( )
inline

Definition at line 1818 of file systems_test.C.

References libMesh::HEX8.

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

◆ test3DProjectVectorFETet10()

void SystemsTest::test3DProjectVectorFETet10 ( )
inline

Definition at line 1819 of file systems_test.C.

References libMesh::TET10.

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

◆ test3DProjectVectorFETet14()

void SystemsTest::test3DProjectVectorFETet14 ( )
inline

Definition at line 1820 of file systems_test.C.

References libMesh::TET14.

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

◆ test3DProjectVectorFETet4()

void SystemsTest::test3DProjectVectorFETet4 ( )
inline

Definition at line 1817 of file systems_test.C.

References libMesh::TET4.

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

◆ testAddVectorProjChange()

void SystemsTest::testAddVectorProjChange ( )
inline

Definition at line 626 of file systems_test.C.

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

627  {
629  EquationSystems es(mesh);
630  ExplicitSystem & sys = simpleSetup(mesh, es);
631 
632  sys.add_vector("late", /* projections = */ false);
633  CPPUNIT_ASSERT_EQUAL(sys.vector_preservation("late"), false);
634 
635  sys.add_vector("late");
636  CPPUNIT_ASSERT_EQUAL(sys.vector_preservation("late"), true);
637  }
This is the EquationSystems class.
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:159
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:751
ExplicitSystem & simpleSetup(UnstructuredMesh &mesh, EquationSystems &es)
Definition: systems_test.C:558
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:1097
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems...

◆ testAddVectorTypeChange()

void SystemsTest::testAddVectorTypeChange ( )
inline

Definition at line 640 of file systems_test.C.

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

641  {
642  // Vector types are all pretty much equivalent in serial.
643  if (TestCommWorld->size() == 1)
644  return;
645 
647  EquationSystems es(mesh);
648  ExplicitSystem & sys = simpleSetup(mesh, es);
649 
650  auto & late_vec = sys.add_vector("late");
651  CPPUNIT_ASSERT_EQUAL(late_vec.type(), PARALLEL);
652  CPPUNIT_ASSERT_EQUAL(sys.vector_preservation("late"), true);
653 
654  // We should never downgrade projection settings, so "false"
655  // should be safely ignored here
656  sys.add_vector("late", false, GHOSTED);
657  CPPUNIT_ASSERT_EQUAL(late_vec.type(), GHOSTED);
658  CPPUNIT_ASSERT_EQUAL(sys.vector_preservation("late"), true);
659 
660  // We should never downgrade storage settings, so this should be a
661  // no-op.
662  sys.add_vector("late", true, PARALLEL);
663  CPPUNIT_ASSERT_EQUAL(late_vec.type(), GHOSTED);
664  CPPUNIT_ASSERT_EQUAL(sys.vector_preservation("late"), true);
665  }
This is the EquationSystems class.
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:159
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:751
processor_id_type size() const
ExplicitSystem & simpleSetup(UnstructuredMesh &mesh, EquationSystems &es)
Definition: systems_test.C:558
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:1097
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems...

◆ testAssemblyWithDgFemContext()

void SystemsTest::testAssemblyWithDgFemContext ( )
inline

Definition at line 1255 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.

1256  {
1257  LOG_UNIT_TEST;
1258 
1260 
1261  EquationSystems es(mesh);
1262  System &sys = es.add_system<LinearImplicitSystem> ("test");
1263 
1264  // We must use a discontinuous variable type in this test or
1265  // else the sparsity pattern will not be correct
1266  sys.add_variable("u", FIRST, L2_LAGRANGE);
1267 
1269  5, 5, 5,
1270  0., 1., 0., 1., 0., 1.,
1271  HEX8);
1272 
1273  es.init();
1275  sys.solve();
1276 
1277  // We don't actually assert anything in this test. We just want to check that
1278  // the assembly and solve do not encounter any errors.
1279  }
This is the EquationSystems class.
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:159
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:1305
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:2109
virtual void solve()
Solves the system.
Definition: system.h:344
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 1281 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.

1282  {
1283  LOG_UNIT_TEST;
1284 
1286 
1288  4,
1289  4,
1290  0,
1291  0., 1.,
1292  0., 1.,
1293  0., 0.,
1294  QUAD4);
1295 
1296  for (const auto & elem : mesh.element_ptr_range())
1297  {
1298  Point c = elem->vertex_average();
1299  if (c(0) <= 0.5 && c(1) <= 0.5)
1300  elem->subdomain_id() = 0;
1301  else
1302  elem->subdomain_id() = 1;
1303  }
1304 
1306 
1307  // Create an equation systems object.
1308  EquationSystems equation_systems (mesh);
1309  ExplicitSystem& system =
1310  equation_systems.add_system<LinearImplicitSystem> ("test");
1311 
1312  std::set<subdomain_id_type> block0;
1313  std::set<subdomain_id_type> block1;
1314  block0.insert(0);
1315  block1.insert(1);
1316  auto u0 = system.add_variable ("u0", libMesh::FIRST, &block0);
1317  auto u1 = system.add_variable ("u1", libMesh::FIRST, &block1);
1318  equation_systems.init();
1319 
1320  std::vector<dof_id_type> u0_dofs;
1321  system.get_dof_map().local_variable_indices(u0_dofs, mesh, u0);
1322  std::vector<dof_id_type> u1_dofs;
1323  system.get_dof_map().local_variable_indices(u1_dofs, mesh, u1);
1324 
1325  std::set<dof_id_type> sys_u0_dofs;
1326  system.local_dof_indices(u0, sys_u0_dofs);
1327  std::set<dof_id_type> sys_u1_dofs;
1328  system.local_dof_indices(u1, sys_u1_dofs);
1329 
1330  // Get local indices from other processors too
1331  mesh.comm().allgather(u0_dofs);
1332  mesh.comm().allgather(u1_dofs);
1333  mesh.comm().set_union(sys_u0_dofs);
1334  mesh.comm().set_union(sys_u1_dofs);
1335 
1336  const std::size_t c9 = 9;
1337  const std::size_t c21 = 21;
1338  CPPUNIT_ASSERT_EQUAL(c9, u0_dofs.size());
1339  CPPUNIT_ASSERT_EQUAL(c21, u1_dofs.size());
1340  CPPUNIT_ASSERT_EQUAL(c9, sys_u0_dofs.size());
1341  CPPUNIT_ASSERT_EQUAL(c21, sys_u1_dofs.size());
1342  }
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:1575
void local_variable_indices(std::vector< dof_id_type > &idx, const MeshBase &mesh, unsigned int var_num) const
Fills an array of those dof indices which belong to the given variable number and live on the current...
Definition: dof_map.C:1109
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:159
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:710
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:1305
const DofMap & get_dof_map() const
Definition: system.h:2293
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 1040 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.

1041  {
1042  LOG_UNIT_TEST;
1043 
1045 
1046  // const boundary_id_type BOUNDARY_ID_MIN_Z = 0;
1047  const boundary_id_type BOUNDARY_ID_MIN_Y = 1;
1048  const boundary_id_type BOUNDARY_ID_MAX_X = 2;
1049  const boundary_id_type BOUNDARY_ID_MAX_Y = 3;
1050  const boundary_id_type BOUNDARY_ID_MIN_X = 4;
1051  const boundary_id_type BOUNDARY_ID_MAX_Z = 5;
1052  const boundary_id_type NODE_BOUNDARY_ID = 10;
1053  const boundary_id_type EDGE_BOUNDARY_ID = 20;
1054  const boundary_id_type SIDE_BOUNDARY_ID = BOUNDARY_ID_MIN_X;
1055 
1056  EquationSystems es(mesh);
1057  System &sys = es.add_system<System> ("SimpleSystem");
1058  unsigned int u_var = sys.add_variable("u", FIRST, LAGRANGE);
1059 
1061  3, 3, 3,
1062  0., 1., 0., 1., 0., 1.,
1063  HEX8);
1064 
1065  // Count the number of nodes on SIDE_BOUNDARY_ID
1066  std::set<dof_id_type> projected_nodes_set;
1067 
1068  for (const auto & elem : mesh.element_ptr_range())
1069  {
1070  for (auto side : elem->side_index_range())
1071  {
1072  std::vector<boundary_id_type> vec_to_fill;
1073  mesh.get_boundary_info().boundary_ids(elem, side, vec_to_fill);
1074 
1075  auto vec_it = std::find(vec_to_fill.begin(), vec_to_fill.end(), SIDE_BOUNDARY_ID);
1076  if (vec_it != vec_to_fill.end())
1077  {
1078  for (unsigned int node_index=0; node_index<elem->n_nodes(); node_index++)
1079  {
1080  if( elem->is_node_on_side(node_index, side))
1081  {
1082  projected_nodes_set.insert(elem->node_id(node_index));
1083  }
1084  }
1085  }
1086  }
1087  }
1088 
1089  // Also add some edge and node boundary IDs
1090  for (const auto & elem : mesh.element_ptr_range())
1091  {
1092  unsigned int
1093  side_max_x = 0, side_min_y = 0,
1094  side_max_y = 0, side_max_z = 0;
1095 
1096  bool
1097  found_side_max_x = false, found_side_max_y = false,
1098  found_side_min_y = false, found_side_max_z = false;
1099 
1100  for (auto side : elem->side_index_range())
1101  {
1102  if (mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MAX_X))
1103  {
1104  side_max_x = side;
1105  found_side_max_x = true;
1106  }
1107 
1108  if (mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MIN_Y))
1109  {
1110  side_min_y = side;
1111  found_side_min_y = true;
1112  }
1113 
1114  if (mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MAX_Y))
1115  {
1116  side_max_y = side;
1117  found_side_max_y = true;
1118  }
1119 
1120  if (mesh.get_boundary_info().has_boundary_id(elem, side, BOUNDARY_ID_MAX_Z))
1121  {
1122  side_max_z = side;
1123  found_side_max_z = true;
1124  }
1125  }
1126 
1127  // If elem has sides on boundaries
1128  // BOUNDARY_ID_MAX_X, BOUNDARY_ID_MAX_Y, BOUNDARY_ID_MAX_Z
1129  // then let's set a node boundary condition
1130  if (found_side_max_x && found_side_max_y && found_side_max_z)
1131  for (auto n : elem->node_index_range())
1132  if (elem->is_node_on_side(n, side_max_x) &&
1133  elem->is_node_on_side(n, side_max_y) &&
1134  elem->is_node_on_side(n, side_max_z))
1135  {
1136  projected_nodes_set.insert(elem->node_id(n));
1137  mesh.get_boundary_info().add_node(elem->node_ptr(n), NODE_BOUNDARY_ID);
1138  }
1139 
1140  // If elem has sides on boundaries
1141  // BOUNDARY_ID_MAX_X and BOUNDARY_ID_MIN_Y
1142  // then let's set an edge boundary condition
1143  if (found_side_max_x && found_side_min_y)
1144  for (auto e : elem->edge_index_range())
1145  if (elem->is_edge_on_side(e, side_max_x) &&
1146  elem->is_edge_on_side(e, side_min_y))
1147  {
1148  mesh.get_boundary_info().add_edge(elem, e, EDGE_BOUNDARY_ID);
1149 
1150  for (unsigned int node_index=0; node_index<elem->n_nodes(); node_index++)
1151  {
1152  if (elem->is_node_on_edge(node_index, e))
1153  {
1154  projected_nodes_set.insert(elem->node_id(node_index));
1155  }
1156  }
1157  }
1158  }
1159 
1160  es.init();
1161 
1162  sys.solution->add(1.0);
1163 
1164  std::set<boundary_id_type> boundary_ids;
1165  boundary_ids.insert(NODE_BOUNDARY_ID);
1166  boundary_ids.insert(EDGE_BOUNDARY_ID);
1167  boundary_ids.insert(SIDE_BOUNDARY_ID);
1168  std::vector<unsigned int> variables;
1169  variables.push_back(u_var);
1170  ZeroFunction<> zf;
1171  sys.boundary_project_solution(boundary_ids, variables, &zf);
1172 
1173  // On a distributed mesh we may not have every node on every
1174  // processor
1175  TestCommWorld->set_union(projected_nodes_set);
1176 
1177  // We set the solution to be 1 everywhere and then zero on specific boundary
1178  // nodes, so the final l1 norm of the solution is the difference between the
1179  // number of nodes in the mesh and the number of nodes we zero on.
1180  Real ref_l1_norm = static_cast<Real>(mesh.n_nodes()) - static_cast<Real>(projected_nodes_set.size());
1181 
1182  LIBMESH_ASSERT_FP_EQUAL(sys.solution->l1_norm(), ref_l1_norm, TOLERANCE*TOLERANCE);
1183  }
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:159
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:159
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:1573
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:1305
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 1185 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.

1186  {
1187  LOG_UNIT_TEST;
1188 
1190 
1192  1,
1193  0,
1194  0,
1195  0., 1.,
1196  0., 0.,
1197  0., 0.,
1198  EDGE2);
1199 
1200  Point new_point_a(2.);
1201  Point new_point_b(3.);
1202  Node* new_node_a = mesh.add_point( new_point_a );
1203  Node* new_node_b = mesh.add_point( new_point_b );
1204  auto new_edge_elem = mesh.add_elem(Elem::build(EDGE2));
1205  new_edge_elem->set_node(0) = new_node_a;
1206  new_edge_elem->set_node(1) = new_node_b;
1207 
1208  mesh.elem_ref(0).subdomain_id() = 10;
1209  mesh.elem_ref(1).subdomain_id() = 10;
1210 
1211  // Add NodeElems for coupling purposes
1212  auto node_elem_1 = mesh.add_elem(Elem::build(NODEELEM));
1213  node_elem_1->set_node(0) = mesh.elem_ref(0).node_ptr(1);
1214  auto node_elem_2 = mesh.add_elem(Elem::build(NODEELEM));
1215  node_elem_2->set_node(0) = new_node_a;
1216 
1218 
1219  // Create an equation systems object.
1220  EquationSystems equation_systems (mesh);
1221  LinearImplicitSystem & system =
1222  equation_systems.add_system<LinearImplicitSystem> ("test");
1223 
1224  system.add_variable ("u", libMesh::FIRST);
1225  system.add_variable ("v", libMesh::FIRST);
1226  system.add_variable ("w", libMesh::FIRST);
1227 
1228  std::set<subdomain_id_type> theta_subdomains;
1229  theta_subdomains.insert(10);
1230  system.add_variable ("theta_x", libMesh::FIRST, &theta_subdomains);
1231  system.add_variable ("theta_y", libMesh::FIRST, &theta_subdomains);
1232  system.add_variable ("theta_z", libMesh::FIRST, &theta_subdomains);
1233 
1235 
1236  AugmentSparsityOnNodes augment_sparsity(mesh);
1237  system.get_dof_map().add_coupling_functor(augment_sparsity);
1238 
1239  // LASPACK GMRES + ILU defaults don't like this problem, but it's
1240  // small enough to just use a simpler iteration.
1243 
1244  equation_systems.init ();
1245 
1246  system.solve();
1247 
1248  // We set the solution to be 1 everywhere, so the final l1 norm of the
1249  // solution is the product of the number of variables and number of nodes.
1250  Real ref_l1_norm = static_cast<Real>(mesh.n_nodes() * system.n_vars());
1251 
1252  LIBMESH_ASSERT_FP_EQUAL(system.solution->l1_norm(), ref_l1_norm, TOLERANCE*TOLERANCE);
1253  }
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:2381
A Node is like a Point, but with more information.
Definition: node.h:52
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:159
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:710
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:1861
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:1573
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:1305
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:2109
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
subdomain_id_type subdomain_id() const
Definition: elem.h:2391
const Node * node_ptr(const unsigned int i) const
Definition: elem.h:2331
virtual const Elem & elem_ref(const dof_id_type i) const
Definition: mesh_base.h:618
unsigned int n_vars() const
Definition: system.h:2349
const DofMap & get_dof_map() const
Definition: system.h:2293
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 609 of file systems_test.C.

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

610  {
612  EquationSystems es(mesh);
613  ExplicitSystem & sys = simpleSetup(mesh, es);
614  es.init();
615 
616  auto & late_vec = sys.add_vector("late");
617 
618  CPPUNIT_ASSERT_EQUAL(sys.n_dofs(), dof_id_type(11));
619 
620  // late_vec should be initialized
621  CPPUNIT_ASSERT_EQUAL(late_vec.size(), dof_id_type(11));
622  CPPUNIT_ASSERT_EQUAL(late_vec.local_size(), sys.solution->local_size());
623  }
This is the EquationSystems class.
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:159
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:751
dof_id_type n_dofs() const
Definition: system.C:113
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1573
ExplicitSystem & simpleSetup(UnstructuredMesh &mesh, EquationSystems &es)
Definition: systems_test.C:558
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 668 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().

669  {
670  // Vector types are all pretty much equivalent in serial.
671  if (TestCommWorld->size() == 1)
672  return;
673 
675  EquationSystems es(mesh);
676  ExplicitSystem & sys = simpleSetup(mesh, es);
677 
678  auto & late_vec = sys.add_vector("late");
679  CPPUNIT_ASSERT_EQUAL(late_vec.type(), PARALLEL);
680  CPPUNIT_ASSERT_EQUAL(sys.vector_preservation("late"), true);
681 
682  es.init();
683 
684  auto & dof_map = sys.get_dof_map();
685 
686  // Set some data to make sure it's preserved
687  CPPUNIT_ASSERT_EQUAL(sys.n_dofs(), dof_id_type(11));
688  for (auto i : make_range(dof_map.first_dof(),
689  dof_map.end_dof()))
690  late_vec.set(i, 2.0*i);
691  late_vec.close();
692 
693  sys.add_vector("late", false, GHOSTED);
694  CPPUNIT_ASSERT_EQUAL(late_vec.type(), GHOSTED);
695 
696  std::vector<dof_id_type> dof_indices;
697  for (auto & elem : mesh.active_local_element_ptr_range())
698  {
699  dof_map.dof_indices (elem, dof_indices);
700 
701  for (auto d : dof_indices)
702  CPPUNIT_ASSERT_EQUAL(late_vec(d), Number(2.0*d));
703  }
704  }
This is the EquationSystems class.
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:159
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:751
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:113
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:134
ExplicitSystem & simpleSetup(UnstructuredMesh &mesh, EquationSystems &es)
Definition: systems_test.C:558
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:1097
const DofMap & get_dof_map() const
Definition: system.h:2293
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 921 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.

922  {
924 
925  EquationSystems es(mesh);
927  es.add_system<TransientExplicitSystem> ("SimpleSystem");
928 
929  std::set<subdomain_id_type> u_subdomains {0, 1, 4, 5},
930  v_subdomains {1, 2, 3, 4},
931  w_subdomains {0, 1, 2, 3, 4};
932 
933  sys.add_variable("u", THIRD, HIERARCHIC, &u_subdomains);
934  sys.add_variable("v", FIRST, LAGRANGE, &v_subdomains);
935  sys.add_variable("w", CONSTANT, MONOMIAL, &w_subdomains);
936 
938  3, 3, 3,
939  0., 1., 0., 1., 0., 1.,
940  elem_type);
941 
942  for (auto & elem : mesh.element_ptr_range())
943  elem->subdomain_id() = elem->id()/6;
944 
945  es.init();
946  TripleFunction tfunc;
947  sys.project_solution(&tfunc);
948  tfunc.offset = 10;
949  sys.project_vector(*sys.old_local_solution, &tfunc);
950  tfunc.offset = 20;
951  sys.project_vector(*sys.older_local_solution, &tfunc);
952 
953  std::unique_ptr<PointLocatorBase> locator = mesh.sub_point_locator();
954  locator->enable_out_of_mesh_mode();
955  for (Real x = 0.1; x < 1; x += 0.2)
956  for (Real y = 0.1; y < 1; y += 0.2)
957  for (Real z = 0.1; z < 1; z += 0.2)
958  tripleValueTest(Point(x,y,z), sys, *locator,
959  u_subdomains, v_subdomains, w_subdomains,
960  es.parameters);
961 
962  #ifdef LIBMESH_ENABLE_AMR
963  for (auto & elem : mesh.element_ptr_range())
964  if ((elem->id()/2)%2)
965  elem->set_refinement_flag(Elem::REFINE);
966  es.reinit();
967 
968  locator = mesh.sub_point_locator();
969  locator->enable_out_of_mesh_mode();
970  for (Real x = 0.1; x < 1; x += 0.2)
971  for (Real y = 0.1; y < 1; y += 0.2)
972  for (Real z = 0.1; z < 1; z += 0.2)
973  tripleValueTest(Point(x,y,z), sys, *locator,
974  u_subdomains, v_subdomains, w_subdomains,
975  es.parameters);
976  #endif
977  }
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:500
std::unique_ptr< PointLocatorBase > sub_point_locator() const
Definition: mesh_base.C:1565
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:159
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 979 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(), libMesh::libmesh_real(), 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.

980  {
981  // The source mesh needs to exist everywhere it's queried, so we
982  // use a ReplicatedMesh
984 
985  EquationSystems es(mesh);
986  System &sys = es.add_system<System> ("SimpleSystem");
987  sys.add_variable("u", THIRD, MONOMIAL);
988 
990  3, 3, 3,
991  0., 1., 0., 1., 0., 1.,
992  elem_type);
993 
994  es.init();
995  sys.project_solution(cubic_test, nullptr, es.parameters);
996 
997  std::vector<unsigned int> variables;
998  sys.get_all_variable_numbers(variables);
999  std::sort(variables.begin(),variables.end());
1000 
1001  std::unique_ptr< NumericVector<Number> > mesh_function_vector =
1002  NumericVector<Number>::build(es.comm());
1003  mesh_function_vector->init(sys.n_dofs(), false, SERIAL);
1004  sys.solution->localize( *mesh_function_vector );
1005 
1006  MeshFunction mesh_function(es,
1007  *mesh_function_vector,
1008  sys.get_dof_map(),
1009  variables);
1010  mesh_function.init();
1011 
1012  // Make a second system and project onto it using a MeshFunction
1013  Mesh proj_mesh(*TestCommWorld);
1014  EquationSystems proj_es(proj_mesh);
1015 
1016  System &proj_sys = proj_es.add_system<System> ("ProjectionSystem");
1017 
1018  // use 3rd order again so we can expect exact results
1019  proj_sys.add_variable("u", THIRD, HIERARCHIC);
1020 
1022  5, 5, 5,
1023  0., 1., 0., 1., 0., 1.,
1024  elem_type);
1025 
1026  proj_es.init();
1027  proj_sys.project_solution(&mesh_function);
1028 
1029  for (Real x = 0.1; x < 1; x += 0.2)
1030  for (Real y = 0.1; y < 1; y += 0.2)
1031  for (Real z = 0.1; z < 1; z += 0.2)
1032  {
1033  Point p(x,y,z);
1034  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(cubic_test(p,es.parameters,"","")),
1035  libmesh_real(proj_sys.point_value(0,p)),
1037  }
1038  }
T libmesh_real(T a)
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:159
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:2369
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
Definition: vector_fe_ex5.C:43
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:1565
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:113
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:1573
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:1305
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:2293
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 1805 of file systems_test.C.

References libMesh::EDGE3.

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

◆ testProjectHierarchicHex27()

void SystemsTest::testProjectHierarchicHex27 ( )
inline

Definition at line 1809 of file systems_test.C.

References libMesh::HEX27.

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

◆ testProjectHierarchicQuad9()

void SystemsTest::testProjectHierarchicQuad9 ( )
inline

Definition at line 1806 of file systems_test.C.

References libMesh::QUAD9.

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

◆ testProjectHierarchicTri6()

void SystemsTest::testProjectHierarchicTri6 ( )
inline

Definition at line 1807 of file systems_test.C.

References libMesh::TRI6.

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

◆ testProjectHierarchicTri7()

void SystemsTest::testProjectHierarchicTri7 ( )
inline

Definition at line 1808 of file systems_test.C.

References libMesh::TRI7.

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

◆ testProjectLine()

void SystemsTest::testProjectLine ( const ElemType  elem_type)
inline

Definition at line 708 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.

709  {
711 
712  EquationSystems es(mesh);
714  es.add_system<TransientExplicitSystem> ("SimpleSystem");
715 
716  std::set<subdomain_id_type> u_subdomains {0, 1, 4, 5},
717  v_subdomains {1, 2, 3, 4},
718  w_subdomains {0, 1, 2, 3, 4};
719 
720  sys.add_variable("u", THIRD, HIERARCHIC, &u_subdomains);
721  sys.add_variable("v", FIRST, LAGRANGE, &v_subdomains);
722  sys.add_variable("w", CONSTANT, MONOMIAL, &w_subdomains);
723 
725  6,
726  0., 1.,
727  elem_type);
728 
729  for (auto & elem : mesh.element_ptr_range())
730  elem->subdomain_id() = elem->id();
731 
732  es.init();
733  TripleFunction tfunc;
734  sys.project_solution(&tfunc);
735  tfunc.offset = 10;
736  sys.project_vector(*sys.old_local_solution, &tfunc);
737  tfunc.offset = 20;
738  sys.project_vector(*sys.older_local_solution, &tfunc);
739 
740  std::unique_ptr<PointLocatorBase> locator = mesh.sub_point_locator();
741  locator->enable_out_of_mesh_mode();
742  for (Real x = 0.1; x < 1; x += 0.2)
743  tripleValueTest(Point(x), sys, *locator,
744  u_subdomains, v_subdomains, w_subdomains,
745  es.parameters);
746 
747 #ifdef LIBMESH_ENABLE_AMR
748  for (auto & elem : mesh.element_ptr_range())
749  if ((elem->id()/2)%2)
750  elem->set_refinement_flag(Elem::REFINE);
751  es.reinit();
752 
753  locator = mesh.sub_point_locator();
754  locator->enable_out_of_mesh_mode();
755  for (Real x = 0.1; x < 1; x += 0.2)
756  tripleValueTest(Point(x), sys, *locator,
757  u_subdomains, v_subdomains, w_subdomains,
758  es.parameters);
759 #endif
760  }
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:500
std::unique_ptr< PointLocatorBase > sub_point_locator() const
Definition: mesh_base.C:1565
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:159
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 1347 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::DofMap::end_old_dof(), libMesh::FIRST, libMesh::DofMap::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_dofs_on_processor(), libMesh::MeshTools::Subdivision::next, libMesh::MeshTools::Subdivision::prev, libMesh::ParallelObject::processor_id(), 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().

1348  {
1349  // Use ReplicatedMesh to get consistent child element node
1350  // numbering during refinement
1352 
1353  // fix the node numbering to resolve dof_id numbering issues in parallel tests
1354  mesh.allow_renumbering(false);
1355 
1356  // init a simple 1d system
1357  EquationSystems es(mesh);
1358  System &sys = es.add_system<System> ("SimpleSystem");
1359  sys.add_variable("u", FIRST, LAGRANGE);
1360 
1362  4, 0., 1.,
1363  elem_type);
1364 
1365  es.init();
1366 
1367  // static set of coarse nodes / order of fine grid nodes from x=0 to x=1 going left to right
1368  std::set<dof_id_type> coarse_nodes({0,1,2,3,4});
1369  std::vector<dof_id_type> node_order_f({0,5,1,6,2,7,3,8,4});
1370 
1371  // stash number of dofs on coarse grid for projection sizing
1372  int n_old_dofs = sys.n_dofs();
1373 
1374  // save old coarse dof_ids in order of coarse nodes
1375  std::map <dof_id_type, dof_id_type> node2dof_c;
1376  for ( const auto & node : mesh.node_ptr_range() )
1377  {
1378  dof_id_type cdof_id = node->dof_number(0,0,0);
1379  node2dof_c.insert( std::pair<dof_id_type,dof_id_type>( node->id() , cdof_id) );
1380  }
1381 
1382  // refine the mesh so we can utilize old_dof_indices for projection_matrix
1383  MeshRefinement mr(mesh);
1384  mr.uniformly_refine(1);
1386 
1387  // fine node to dof map
1388  std::map <dof_id_type, dof_id_type> node2dof_f;
1389  for ( const auto & node : mesh.local_node_ptr_range() )
1390  {
1391  dof_id_type fdof_id = node->dof_number(0,0,0);
1392  node2dof_f.insert( std::pair<dof_id_type,dof_id_type>(node->id() , fdof_id) );
1393  }
1394 
1395  // local and global projection_matrix sizes infos
1396  int n_new_dofs = sys.n_dofs();
1397  int n_new_dofs_local = sys.get_dof_map().n_dofs_on_processor(sys.processor_id());
1398  int ndofs_old_first = sys.get_dof_map().first_old_dof(sys.processor_id());
1399  int ndofs_old_end = sys.get_dof_map().end_old_dof(sys.processor_id());
1400  int n_old_dofs_local = ndofs_old_end - ndofs_old_first;
1401 
1402  // init and compute the projection matrix using GenericProjector
1403  std::unique_ptr<SparseMatrix<Number> > proj_mat_ptr =
1405  SparseMatrix<Number> & proj_mat = *proj_mat_ptr;
1406  proj_mat.init(n_new_dofs, n_old_dofs, n_new_dofs_local, n_old_dofs_local);
1407  sys.projection_matrix(proj_mat);
1408  proj_mat.close();
1409 
1410  // init the gold standard projection matrix
1411  std::unique_ptr<SparseMatrix<Number> > gold_mat_ptr =
1413  SparseMatrix<Number> & gold_mat = *gold_mat_ptr;
1414  gold_mat.init(n_new_dofs, n_old_dofs, n_new_dofs_local, n_old_dofs_local);
1415 
1416  // construct the gold projection matrix using static node numbering as reference info
1417  for ( const auto & node : mesh.local_node_ptr_range() )
1418  {
1419  dof_id_type node_id = node->id();
1420  dof_id_type fdof_id = (node2dof_f.find(node_id))->second;
1421 
1422  if (coarse_nodes.find(node_id) != coarse_nodes.end() )
1423  { //direct inject coarse nodes
1424  if (fdof_id >= gold_mat.row_start() && fdof_id < gold_mat.row_stop())
1425  {
1426  auto cdof_id = node2dof_c.find(node_id);
1427  gold_mat.set(fdof_id, cdof_id->second, 1.0);
1428  }
1429  }
1430  else
1431  { // new nodes with old_dof neighbor contributions
1432  if (fdof_id >= gold_mat.row_start() && fdof_id < gold_mat.row_stop())
1433  {
1434  auto node_loc = std::find(node_order_f.begin(), node_order_f.end(), node_id);
1435  auto node_n = *std::next(node_loc, 1);
1436  auto node_p = *std::prev(node_loc, 1);
1437  auto dof_p = node2dof_c.find(node_p);
1438  auto dof_n = node2dof_c.find(node_n);
1439 
1440  gold_mat.set(fdof_id, dof_p->second, 0.5);
1441  gold_mat.set(fdof_id, dof_n->second, 0.5);
1442  }
1443  }
1444  } // end gold mat build
1445  gold_mat.close();
1446 
1447  // calculate relative difference norm between the two projection matrices
1448  Real gold_norm = gold_mat.linfty_norm();
1449  gold_mat.add(-1.0, proj_mat);
1450  Real diff_norm = gold_mat.linfty_norm();
1451  CPPUNIT_ASSERT(diff_norm/gold_norm < TOLERANCE*TOLERANCE);
1452  }
This is the EquationSystems class.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
dof_id_type n_dofs_on_processor(const processor_id_type proc) const
Definition: dof_map.h:675
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:1173
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:159
static constexpr Real TOLERANCE
std::size_t distribute_dofs(MeshBase &)
Distribute dofs on the current mesh.
Definition: dof_map.C:927
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_dofs() const
Definition: system.C:113
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:45
Implements (adaptive) mesh refinement algorithms for a MeshBase.
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:96
dof_id_type end_old_dof(const processor_id_type proc) const
Definition: dof_map.h:731
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:1305
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
processor_id_type processor_id() const
const DofMap & get_dof_map() const
Definition: system.h:2293
dof_id_type first_old_dof(const processor_id_type proc) const
Definition: dof_map.h:694
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 1454 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::DofMap::end_old_dof(), libMesh::FIRST, libMesh::DofMap::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_dofs_on_processor(), libMesh::ParallelObject::processor_id(), 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().

1455  {
1456  // Use ReplicatedMesh to get consistent child element node
1457  // numbering during refinement
1459 
1460  // fix the node numbering to resolve dof_id numbering issues in parallel tests
1461  mesh.allow_renumbering(false);
1462 
1463  // init a simple 1d system
1464  EquationSystems es(mesh);
1465  System &sys = es.add_system<System> ("SimpleSystem");
1466  sys.add_variable("u", FIRST, LAGRANGE);
1467 
1468  if (elem_type == Utility::string_to_enum<ElemType>("QUAD4"))
1470  2, 2,
1471  0., 1., 0., 1.,
1472  elem_type);
1473  else if (elem_type == Utility::string_to_enum<ElemType>("TRI3"))
1475  1, 1,
1476  0., 1., 0., 1.,
1477  elem_type);
1478 
1479  es.init();
1480 
1481  // static sets of nodes and their neighbors
1482  std::set<dof_id_type> coarse_nodes;
1483  std::map<dof_id_type, std::vector<dof_id_type>> side_nbr_nodes;
1484  std::map<dof_id_type, std::vector<dof_id_type>> int_nbr_nodes;
1485 
1486  // fill neighbor maps based on static node numbering
1487  if (elem_type == Utility::string_to_enum<ElemType>("QUAD4"))
1488  {
1489  coarse_nodes.insert({0,1,2,3,4,5,6,7,8});
1490 
1491  side_nbr_nodes.insert({9, {0,1}});
1492  side_nbr_nodes.insert({14, {1,2}});
1493  side_nbr_nodes.insert({11, {0,3}});
1494  side_nbr_nodes.insert({12, {1,4}});
1495  side_nbr_nodes.insert({16, {2,5}});
1496  side_nbr_nodes.insert({13, {3,4}});
1497  side_nbr_nodes.insert({17, {4,5}});
1498  side_nbr_nodes.insert({19, {3,6}});
1499  side_nbr_nodes.insert({20, {4,7}});
1500  side_nbr_nodes.insert({23, {5,8}});
1501  side_nbr_nodes.insert({21, {6,7}});
1502  side_nbr_nodes.insert({24, {7,8}});
1503 
1504  int_nbr_nodes.insert({10, {0,1,3,4}});
1505  int_nbr_nodes.insert({15, {1,2,4,5}});
1506  int_nbr_nodes.insert({18, {3,4,6,7}});
1507  int_nbr_nodes.insert({22, {4,5,7,8}});
1508  }
1509  else if (elem_type == Utility::string_to_enum<ElemType>("TRI3"))
1510  {
1511  coarse_nodes.insert({0,1,2,3});
1512 
1513  side_nbr_nodes.insert({4, {0,1}});
1514  side_nbr_nodes.insert({5, {0,3}});
1515  side_nbr_nodes.insert({6, {1,3}});
1516  side_nbr_nodes.insert({7, {0,2}});
1517  side_nbr_nodes.insert({8, {2,3}});
1518  }
1519 
1520  // stash number of dofs on coarse grid for projection sizing
1521  int n_old_dofs = sys.n_dofs();
1522 
1523  // save old coarse dof_ids in order of coarse nodes
1524  std::map <dof_id_type, dof_id_type> node2dof_c;
1525  for ( const auto & node : mesh.node_ptr_range() )
1526  {
1527  dof_id_type cdof_id = node->dof_number(0,0,0);
1528  node2dof_c.insert( std::pair<dof_id_type,dof_id_type>( node->id() , cdof_id) );
1529  }
1530 
1531  // refine the mesh so we can utilize old_dof_indices for projection_matrix
1532  MeshRefinement mr(mesh);
1533  mr.uniformly_refine(1);
1535 
1536  // fine node to dof map
1537  std::map <dof_id_type, dof_id_type> node2dof_f;
1538  for ( const auto & node : mesh.local_node_ptr_range() )
1539  {
1540  dof_id_type fdof_id = node->dof_number(0,0,0);
1541  node2dof_f.insert( std::pair<dof_id_type,dof_id_type>(node->id() , fdof_id) );
1542  }
1543 
1544  // local and global projection_matrix sizes infos
1545  int n_new_dofs = sys.n_dofs();
1546  int n_new_dofs_local = sys.get_dof_map().n_dofs_on_processor(sys.processor_id());
1547  int ndofs_old_first = sys.get_dof_map().first_old_dof(sys.processor_id());
1548  int ndofs_old_end = sys.get_dof_map().end_old_dof(sys.processor_id());
1549  int n_old_dofs_local = ndofs_old_end - ndofs_old_first;
1550 
1551  // init and compute the projection matrix using GenericProjector
1552  std::unique_ptr<SparseMatrix<Number> > proj_mat_ptr =
1554  SparseMatrix<Number> & proj_mat = *proj_mat_ptr;
1555  proj_mat.init(n_new_dofs, n_old_dofs, n_new_dofs_local, n_old_dofs_local);
1556  sys.projection_matrix(proj_mat);
1557  proj_mat.close();
1558 
1559  // init the gold standard projection matrix
1560  std::unique_ptr<SparseMatrix<Number> > gold_mat_ptr =
1562  SparseMatrix<Number> & gold_mat = *gold_mat_ptr;
1563  gold_mat.init(n_new_dofs, n_old_dofs, n_new_dofs_local, n_old_dofs_local);
1564 
1565  // construct the gold projection matrix using static node numbering as reference info
1566  for ( const auto & node : mesh.local_node_ptr_range() )
1567  {
1568  dof_id_type node_id = node->id();
1569  dof_id_type fdof_id = (node2dof_f.find(node_id))->second;
1570 
1571  if (coarse_nodes.find(node_id) != coarse_nodes.end() )
1572  { // direct inject coarse nodes
1573  if (fdof_id >= gold_mat.row_start() && fdof_id < gold_mat.row_stop())
1574  {
1575  auto cdof_id = node2dof_c.find(node_id);
1576  gold_mat.set(fdof_id, cdof_id->second, 1.0);
1577  }
1578  }
1579  else if ( side_nbr_nodes.find(node_id) != side_nbr_nodes.end() )
1580  { // new side nodes with old_dof neighbor contributions
1581  if (fdof_id >= gold_mat.row_start() && fdof_id < gold_mat.row_stop())
1582  {
1583  auto node_nbrs = side_nbr_nodes.find(node_id);
1584  for (auto nbr : node_nbrs->second)
1585  {
1586  auto nbr_dof = node2dof_c.find(nbr);
1587  gold_mat.set(fdof_id, nbr_dof->second, 0.5);
1588  }
1589  }
1590  }
1591  else
1592  { // new interior nodes with old_dof neighbor contributions
1593  if (fdof_id >= gold_mat.row_start() && fdof_id < gold_mat.row_stop())
1594  {
1595  auto node_nbrs = int_nbr_nodes.find(node_id);
1596  for (auto nbr : node_nbrs->second)
1597  {
1598  auto nbr_dof = node2dof_c.find(nbr);
1599  gold_mat.set(fdof_id, nbr_dof->second, 0.25);
1600  }
1601  }
1602  }
1603  } // end gold mat build
1604  gold_mat.close();
1605 
1606  // calculate relative difference norm between the two projection matrices
1607  Real gold_norm = gold_mat.linfty_norm();
1608  proj_mat.add(-1.0, gold_mat);
1609  Real diff_norm = proj_mat.linfty_norm();
1610  CPPUNIT_ASSERT(diff_norm/gold_norm < TOLERANCE*TOLERANCE);
1611  }
This is the EquationSystems class.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
dof_id_type n_dofs_on_processor(const processor_id_type proc) const
Definition: dof_map.h:675
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:1173
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:159
static constexpr Real TOLERANCE
std::size_t distribute_dofs(MeshBase &)
Distribute dofs on the current mesh.
Definition: dof_map.C:927
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_dofs() const
Definition: system.C:113
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:45
Implements (adaptive) mesh refinement algorithms for a MeshBase.
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:96
dof_id_type end_old_dof(const processor_id_type proc) const
Definition: dof_map.h:731
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:1305
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
processor_id_type processor_id() const
const DofMap & get_dof_map() const
Definition: system.h:2293
dof_id_type first_old_dof(const processor_id_type proc) const
Definition: dof_map.h:694
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 1613 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::DofMap::end_old_dof(), libMesh::FIRST, libMesh::DofMap::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_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().

1614  {
1615  // Use ReplicatedMesh to get consistent child element node
1616  // numbering during refinement
1618 
1619  // fix the node numbering to resolve dof_id numbering issues in parallel tests
1620  mesh.allow_renumbering(false);
1621 
1622  // init a simple 1d system
1623  EquationSystems es(mesh);
1624  System &sys = es.add_system<System> ("SimpleSystem");
1625  sys.add_variable("u", FIRST, LAGRANGE);
1626 
1627  if (elem_type == Utility::string_to_enum<ElemType>("HEX8"))
1629  1, 1, 1,
1630  0., 1., 0., 1., 0., 1.,
1631  elem_type);
1632  else if (elem_type == Utility::string_to_enum<ElemType>("TET4"))
1633  {
1634  // manually build a Tet4 element
1635  mesh.add_point( Point(0,0,0), 0 );
1636  mesh.add_point( Point(1,0,0), 1 );
1637  mesh.add_point( Point(0,1,0), 2 );
1638  mesh.add_point( Point(1./3.,1./3.,1), 3 );
1639 
1640  Elem * elem = mesh.add_elem(Elem::build_with_id(TET4, 0));
1641  elem->set_node(0) = mesh.node_ptr(0);
1642  elem->set_node(1) = mesh.node_ptr(1);
1643  elem->set_node(2) = mesh.node_ptr(2);
1644  elem->set_node(3) = mesh.node_ptr(3);
1645 
1647  }
1648  es.init();
1649 
1650  // static sets of nodes and their neighbors
1651  std::set<dof_id_type> coarse_nodes;
1652  std::map<dof_id_type, std::vector<dof_id_type>> side_nbr_nodes;
1653  std::map<dof_id_type, std::vector<dof_id_type>> face_nbr_nodes;
1654  std::map<dof_id_type, std::vector<dof_id_type>> int_nbr_nodes;
1655 
1656  if (elem_type == Utility::string_to_enum<ElemType>("HEX8"))
1657  {
1658  coarse_nodes.insert({0,1,2,3,4,5,6,7});
1659 
1660  // fill neighbor maps based on static node numbering
1661  side_nbr_nodes.insert({8, {0,1}});
1662  side_nbr_nodes.insert({10, {0,2}});
1663  side_nbr_nodes.insert({15, {1,3}});
1664  side_nbr_nodes.insert({18, {2,3}});
1665  side_nbr_nodes.insert({11, {0,4}});
1666  side_nbr_nodes.insert({16, {1,5}});
1667  side_nbr_nodes.insert({21, {3,7}});
1668  side_nbr_nodes.insert({20, {2,6}});
1669  side_nbr_nodes.insert({22, {4,5}});
1670  side_nbr_nodes.insert({24, {4,6}});
1671  side_nbr_nodes.insert({25, {5,7}});
1672  side_nbr_nodes.insert({26, {6,7}});
1673 
1674  face_nbr_nodes.insert({12, {0,1,4,5}});
1675  face_nbr_nodes.insert({9 , {0,1,2,3}});
1676  face_nbr_nodes.insert({14, {0,2,4,6}});
1677  face_nbr_nodes.insert({17, {1,3,5,7}});
1678  face_nbr_nodes.insert({19, {2,3,6,7}});
1679  face_nbr_nodes.insert({23, {4,5,6,7}});
1680 
1681  int_nbr_nodes.insert({13, {0,1,2,3,4,5,6,7}});
1682  }
1683  else if (elem_type == Utility::string_to_enum<ElemType>("TET4"))
1684  {
1685  coarse_nodes.insert({0,1,2,3});
1686 
1687  // fill neighbor maps based on static node numbering
1688  side_nbr_nodes.insert({4, {0,1}});
1689  side_nbr_nodes.insert({5, {0,2}});
1690  side_nbr_nodes.insert({6, {0,3}});
1691  side_nbr_nodes.insert({7, {1,2}});
1692  side_nbr_nodes.insert({8, {1,3}});
1693  side_nbr_nodes.insert({9, {2,3}});
1694  }
1695 
1696  // stash number of dofs on coarse grid for projection sizing
1697  int n_old_dofs = sys.n_dofs();
1698 
1699  // save old coarse dof_ids in order of coarse nodes
1700  std::map <dof_id_type, dof_id_type> node2dof_c;
1701  for ( const auto & node : mesh.node_ptr_range() )
1702  {
1703  dof_id_type cdof_id = node->dof_number(0,0,0);
1704  node2dof_c.insert( std::pair<dof_id_type,dof_id_type>( node->id() , cdof_id) );
1705  }
1706 
1707  // refine the mesh so we can utilize old_dof_indices for projection_matrix
1708  MeshRefinement mr(mesh);
1709  mr.uniformly_refine(1);
1711 
1712  // fine node to dof map
1713  std::map <dof_id_type, dof_id_type> node2dof_f;
1714  for ( const auto & node : mesh.local_node_ptr_range() )
1715  {
1716  dof_id_type fdof_id = node->dof_number(0,0,0);
1717  node2dof_f.insert( std::pair<dof_id_type,dof_id_type>(node->id() , fdof_id) );
1718  }
1719 
1720  // local and global projection_matrix sizes infos
1721  int n_new_dofs = sys.n_dofs();
1722  int n_new_dofs_local = sys.get_dof_map().n_dofs_on_processor(sys.processor_id());
1723  int ndofs_old_first = sys.get_dof_map().first_old_dof(sys.processor_id());
1724  int ndofs_old_end = sys.get_dof_map().end_old_dof(sys.processor_id());
1725  int n_old_dofs_local = ndofs_old_end - ndofs_old_first;
1726 
1727  // init and compute the projection matrix using GenericProjector
1728  std::unique_ptr<SparseMatrix<Number> > proj_mat_ptr =
1730  SparseMatrix<Number> & proj_mat = *proj_mat_ptr;
1731  proj_mat.init(n_new_dofs, n_old_dofs, n_new_dofs_local, n_old_dofs_local);
1732  sys.projection_matrix(proj_mat);
1733  proj_mat.close();
1734 
1735  // init the gold standard projection matrix
1736  std::unique_ptr<SparseMatrix<Number> > gold_mat_ptr =
1738  SparseMatrix<Number> & gold_mat = *gold_mat_ptr;
1739  gold_mat.init(n_new_dofs, n_old_dofs, n_new_dofs_local, n_old_dofs_local);
1740 
1741  // construct the gold projection matrix using static node numbering as reference info
1742  for ( const auto & node : mesh.local_node_ptr_range() )
1743  {
1744  dof_id_type node_id = node->id();
1745  dof_id_type fdof_id = (node2dof_f.find(node_id))->second;
1746 
1747  if (coarse_nodes.find(node_id) != coarse_nodes.end() )
1748  { // direct inject coarse nodes
1749  if (fdof_id >= gold_mat.row_start() && fdof_id < gold_mat.row_stop())
1750  {
1751  auto cdof_id = node2dof_c.find(node_id);
1752  gold_mat.set(fdof_id, cdof_id->second, 1.0);
1753  }
1754  }
1755  else if ( side_nbr_nodes.find(node_id) != side_nbr_nodes.end() )
1756  { // new side nodes with old_dof neighbor contributions
1757  if (fdof_id >= gold_mat.row_start() && fdof_id < gold_mat.row_stop())
1758  {
1759  auto node_nbrs = side_nbr_nodes.find(node_id);
1760  for (auto nbr : node_nbrs->second)
1761  {
1762  auto nbr_dof = node2dof_c.find(nbr);
1763  gold_mat.set(fdof_id, nbr_dof->second, 0.5);
1764  }
1765  }
1766  }
1767  else if ( face_nbr_nodes.find(node_id) != face_nbr_nodes.end() )
1768  { // new face nodes with old_dof neighbor contributions
1769  if (fdof_id >= gold_mat.row_start() && fdof_id < gold_mat.row_stop())
1770  {
1771  auto node_nbrs = face_nbr_nodes.find(node_id);
1772  for (auto nbr : node_nbrs->second)
1773  {
1774  auto nbr_dof = node2dof_c.find(nbr);
1775  gold_mat.set(fdof_id, nbr_dof->second, 0.25);
1776  }
1777  }
1778  }
1779  else
1780  { // new interior nodes with old_dof neighbor contributions
1781  if (fdof_id >= gold_mat.row_start() && fdof_id < gold_mat.row_stop())
1782  {
1783  auto node_nbrs = int_nbr_nodes.find(node_id);
1784  for (auto nbr : node_nbrs->second)
1785  {
1786  auto nbr_dof = node2dof_c.find(nbr);
1787  gold_mat.set(fdof_id, nbr_dof->second, 0.125);
1788  }
1789  }
1790  }
1791  } // end gold mat build
1792  gold_mat.close();
1793 
1794  // calculate relative difference norm between the two projection matrices
1795  Real gold_norm = gold_mat.linfty_norm();
1796  proj_mat.add(-1.0, gold_mat);
1797  Real diff_norm = proj_mat.linfty_norm();
1798  CPPUNIT_ASSERT(diff_norm/gold_norm < TOLERANCE*TOLERANCE);
1799  }
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:2381
dof_id_type n_dofs_on_processor(const processor_id_type proc) const
Definition: dof_map.h:675
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:1173
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:159
static constexpr Real TOLERANCE
std::size_t distribute_dofs(MeshBase &)
Distribute dofs on the current mesh.
Definition: dof_map.C:927
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:710
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:113
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:45
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.
dof_id_type end_old_dof(const processor_id_type proc) const
Definition: dof_map.h:731
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:1305
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
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:2293
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.
dof_id_type first_old_dof(const processor_id_type proc) const
Definition: dof_map.h:694
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 1828 of file systems_test.C.

References libMesh::EDGE2.

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

◆ testProjectMatrixHex8()

void SystemsTest::testProjectMatrixHex8 ( )
inline

Definition at line 1831 of file systems_test.C.

References libMesh::HEX8.

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

◆ testProjectMatrixQuad4()

void SystemsTest::testProjectMatrixQuad4 ( )
inline

Definition at line 1829 of file systems_test.C.

References libMesh::QUAD4.

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

◆ testProjectMatrixTet4()

void SystemsTest::testProjectMatrixTet4 ( )
inline

Definition at line 1832 of file systems_test.C.

References libMesh::TET4.

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

◆ testProjectMatrixTri3()

void SystemsTest::testProjectMatrixTri3 ( )
inline

Definition at line 1830 of file systems_test.C.

References libMesh::TRI3.

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

◆ testProjectMeshFunctionHex27()

void SystemsTest::testProjectMeshFunctionHex27 ( )
inline

Definition at line 1810 of file systems_test.C.

References libMesh::HEX27.

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

◆ testProjectSquare()

void SystemsTest::testProjectSquare ( const ElemType  elem_type)
inline

Definition at line 865 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.

866  {
868 
869  EquationSystems es(mesh);
871  es.add_system<TransientExplicitSystem> ("SimpleSystem");
872 
873  std::set<subdomain_id_type> u_subdomains {0, 1, 4, 5},
874  v_subdomains {1, 2, 3, 4},
875  w_subdomains {0, 1, 2, 3, 4};
876 
877  sys.add_variable("u", THIRD, HIERARCHIC, &u_subdomains);
878  sys.add_variable("v", FIRST, LAGRANGE, &v_subdomains);
879  sys.add_variable("w", CONSTANT, MONOMIAL, &w_subdomains);
880 
882  3, 3,
883  0., 1., 0., 1.,
884  elem_type);
885 
886  for (auto & elem : mesh.element_ptr_range())
887  elem->subdomain_id() = elem->id()/2;
888 
889  es.init();
890  TripleFunction tfunc;
891  sys.project_solution(&tfunc);
892  tfunc.offset = 10;
893  sys.project_vector(*sys.old_local_solution, &tfunc);
894  tfunc.offset = 20;
895  sys.project_vector(*sys.older_local_solution, &tfunc);
896 
897  std::unique_ptr<PointLocatorBase> locator = mesh.sub_point_locator();
898  locator->enable_out_of_mesh_mode();
899  for (Real x = 0.1; x < 1; x += 0.2)
900  for (Real y = 0.1; y < 1; y += 0.2)
901  tripleValueTest(Point(x,y), sys, *locator,
902  u_subdomains, v_subdomains, w_subdomains,
903  es.parameters);
904 
905 #ifdef LIBMESH_ENABLE_AMR
906  for (auto & elem : mesh.element_ptr_range())
907  if ((elem->id()/2)%2)
908  elem->set_refinement_flag(Elem::REFINE);
909  es.reinit();
910 
911  locator = mesh.sub_point_locator();
912  locator->enable_out_of_mesh_mode();
913  for (Real x = 0.1; x < 1; x += 0.2)
914  for (Real y = 0.1; y < 1; y += 0.2)
915  tripleValueTest(Point(x,y), sys, *locator,
916  u_subdomains, v_subdomains, w_subdomains,
917  es.parameters);
918 #endif
919  }
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:500
std::unique_ptr< PointLocatorBase > sub_point_locator() const
Definition: mesh_base.C:1565
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:159
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

◆ 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 500 of file systems_test.C.

References cubic_test(), disc_thirds_test(), libMesh::libmesh_real(), 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.

507  {
508  const Elem * elem = locator(p);
509  subdomain_id_type sbd_id = elem ? elem->subdomain_id() : 0;
510  TestCommWorld->max(sbd_id);
511 
512  if (u_subdomains.count(sbd_id))
513  {
514  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(cubic_test(p,param,"","")),
515  libmesh_real(sys.point_value(0,p)),
516  TOLERANCE*TOLERANCE*10);
517  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(cubic_test(p,param,"","") + Number(10)),
518  libmesh_real(sys.point_value(0,p,sys.old_local_solution)),
519  TOLERANCE*TOLERANCE*100);
520  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(cubic_test(p,param,"","") + Number(20)),
521  libmesh_real(sys.point_value(0,p,sys.older_local_solution)),
522  TOLERANCE*TOLERANCE*100);
523  }
524  if (v_subdomains.count(sbd_id))
525  {
526  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(new_linear_test(p,param,"","")),
527  libmesh_real(sys.point_value(1,p)),
528  TOLERANCE*TOLERANCE*10);
529  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(new_linear_test(p,param,"","") + Number(10)),
530  libmesh_real(sys.point_value(1,p,sys.old_local_solution)),
531  TOLERANCE*TOLERANCE*100);
532  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(new_linear_test(p,param,"","") + Number(20)),
533  libmesh_real(sys.point_value(1,p,sys.older_local_solution)),
534  TOLERANCE*TOLERANCE*100);
535  }
536  if (w_subdomains.count(sbd_id))
537  {
538  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(disc_thirds_test(p,param,"","")),
539  libmesh_real(sys.point_value(2,p)),
540  TOLERANCE*TOLERANCE*10);
541  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(disc_thirds_test(p,param,"","") + Number(10)),
542  libmesh_real(sys.point_value(2,p,sys.old_local_solution)),
543  TOLERANCE*TOLERANCE*100);
544  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(disc_thirds_test(p,param,"","") + Number(20)),
545  libmesh_real(sys.point_value(2,p,sys.older_local_solution)),
546  TOLERANCE*TOLERANCE*100);
547  }
548  }
T libmesh_real(T a)
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:159
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:2391
void max(const T &r, T &o, Request &req) const

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