libMesh
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
DirichletConstraintValuesTest Class Reference
Inheritance diagram for DirichletConstraintValuesTest:
[legend]

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (DirichletConstraintValuesTest)
 
 CPPUNIT_TEST (testUpdateMatchesRebuild)
 
 CPPUNIT_TEST (testSplineConstraintRows)
 
 CPPUNIT_TEST_SUITE_END ()
 

Private Member Functions

void testUpdateMatchesRebuild ()
 
void testSplineConstraintRows ()
 Checks that System::reinit_dirichlet_constraint_values() gives exactly the result of System::reinit_constraints() on a mesh with spline constraint rows.
 
void checkUpdate (const unsigned int n)
 Checks that System::reinit_dirichlet_constraint_values() gives exactly the result of System::reinit_constraints().
 

Detailed Description

Definition at line 115 of file dirichlet_constraint_values_test.C.

Member Function Documentation

◆ checkUpdate()

void DirichletConstraintValuesTest::checkUpdate ( const unsigned int  n)
inlineprivate

Checks that System::reinit_dirichlet_constraint_values() gives exactly the result of System::reinit_constraints().

The mesh is an n x n grid of QUAD9 elements with hanging nodes and a periodic boundary. The periodic partners meet overlapping time-dependent Dirichlet boundaries.

Definition at line 210 of file dirichlet_constraint_values_test.C.

211 {
212 Mesh mesh(*TestCommWorld);
213
214 // Keep all neighbors until the periodic boundary is attached. The
215 // periodic boundary needs them.
217 MeshTools::Generation::build_square(mesh, n, n, 0., 1., 0., 1., QUAD9);
218
220 auto & sys = es.add_system<ExplicitSystem>("sys");
221 const auto u = sys.add_variable("u", SECOND, HIERARCHIC);
222 const auto v = sys.add_variable("v", SECOND, LAGRANGE);
223
224 // The mesh is periodic in y. Thus periodic partners meet the
225 // Dirichlet boundaries at the corners.
226 PeriodicBoundary periodic(RealVectorValue(0., 1.));
227 periodic.myboundary = bottom_id;
228 periodic.pairedboundary = top_id;
229 sys.get_dof_map().add_periodic_boundary(periodic);
230
233
234 // Add two overlapping time-dependent boundaries. The first claims u
235 // and v on the left. The second claims u on the left and right.
236 // The first boundary keeps the left side.
237 sys.get_dof_map().add_dirichlet_boundary(
238 DirichletBoundary({left_id}, {u, v}, RampFunction(1.)));
239 sys.get_dof_map().add_dirichlet_boundary(
240 DirichletBoundary({left_id, right_id}, {u}, RampFunction(-3.)));
241
242#ifdef LIBMESH_ENABLE_AMR // We can do more testing here
243 // Refine the elements near the left boundary. Then the hanging
244 // nodes on the refined/unrefined interface reach the Dirichlet and
245 // periodic boundaries.
246 MeshRefinement refinement(mesh);
247 for (auto & elem : mesh.active_element_ptr_range())
248 {
249 if (elem->vertex_average()(0) < 0.3)
250 elem->set_refinement_flag(Elem::REFINE);
251 }
252 refinement.refine_elements();
253#endif // LIBMESH_ENABLE_AMR
254
255 es.init();
256
257 auto & dof_map = sys.get_dof_map();
258
259 for (const Real time : {0., 0.25, 1., 2.5})
260 {
261 sys.time = time;
262
263 sys.reinit_constraints();
264 const auto rebuilt_rows = gather_local_rows(dof_map);
265 const auto rebuilt_rhs = gather_local_rhs(dof_map);
266
267 // The update must give the same result from any state that the
268 // last processing left
269 sys.reinit_dirichlet_constraint_values();
270 assert_constraints_equal(rebuilt_rows, rebuilt_rhs, dof_map);
271 const auto updated_rhs = gather_local_rhs(dof_map);
272
273 // The values must change with time. Otherwise the comparison
274 // above could pass on stale values.
275 bool any_nonzero = false;
276 for (const auto & [dof, value] : updated_rhs)
277 {
278 libmesh_ignore(dof);
279 any_nonzero = any_nonzero || value != Number(0);
280 }
281 TestCommWorld->max(any_nonzero);
282 CPPUNIT_ASSERT(any_nonzero);
283 }
284
285 // Two consecutive updates, with no full rebuild between them, must
286 // also agree with a new full rebuild
287 sys.time = 4.;
288 sys.reinit_dirichlet_constraint_values();
289 sys.reinit_dirichlet_constraint_values();
290 const auto twice_updated_rows = gather_local_rows(dof_map);
291 const auto twice_updated_rhs = gather_local_rhs(dof_map);
292 sys.reinit_constraints();
293 assert_constraints_equal(twice_updated_rows, twice_updated_rhs, dof_map);
294 }
This class allows one to associate Dirichlet boundary values with a given set of mesh boundary ids an...
This is the EquationSystems class.
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems.
void allow_remote_element_removal(bool allow)
If false is passed in then this mesh will no longer have remote elements deleted when being prepared ...
Definition mesh_base.h:1390
void prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
Prepare a newly created (or read) mesh for use.
Definition mesh_base.C:901
Implements (adaptive) mesh refinement algorithms for a MeshBase.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition mesh.h:51
The definition of a periodic boundary.
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:1400
static const boundary_id_type left_id
static const boundary_id_type right_id
Communicator * TestCommWorld
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.
void libmesh_ignore(const Args &...)
VectorValue< Real > RealVectorValue
Useful typedefs to allow transparent switching between Real and Complex data types.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const boundary_id_type top_id
const boundary_id_type bottom_id
static const bool value
Definition xdr_io.C:55

References libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshBase::allow_remote_element_removal(), bottom_id, libMesh::MeshTools::Generation::build_square(), libMesh::HIERARCHIC, libMesh::EquationSystems::init(), libMesh::LAGRANGE, left_id, libMesh::libmesh_ignore(), mesh, libMesh::PeriodicBoundaryBase::myboundary, libMesh::PeriodicBoundaryBase::pairedboundary, libMesh::MeshBase::prepare_for_use(), libMesh::QUAD9, libMesh::Real, libMesh::Elem::REFINE, libMesh::MeshRefinement::refine_elements(), right_id, libMesh::SECOND, TestCommWorld, top_id, and value.

Referenced by testUpdateMatchesRebuild().

◆ CPPUNIT_TEST() [1/2]

DirichletConstraintValuesTest::CPPUNIT_TEST ( testSplineConstraintRows  )

◆ CPPUNIT_TEST() [2/2]

DirichletConstraintValuesTest::CPPUNIT_TEST ( testUpdateMatchesRebuild  )

◆ CPPUNIT_TEST_SUITE_END()

DirichletConstraintValuesTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

DirichletConstraintValuesTest::LIBMESH_CPPUNIT_TEST_SUITE ( DirichletConstraintValuesTest  )

◆ testSplineConstraintRows()

void DirichletConstraintValuesTest::testSplineConstraintRows ( )
inlineprivate

Checks that System::reinit_dirichlet_constraint_values() gives exactly the result of System::reinit_constraints() on a mesh with spline constraint rows.

The mesh is a line of 10 EDGE2 elements. The constraint rows tie its nodes to 6 spline nodes. The Dirichlet boundary is on a constrained node. Thus the processing of the constraint rows projects the Dirichlet value onto the spline nodes.

Definition at line 147 of file dirichlet_constraint_values_test.C.

148 {
149 LOG_UNIT_TEST;
150
151 Mesh mesh(*TestCommWorld);
153 auto & sys = es.add_system<ExplicitSystem>("sys");
154 const auto u = sys.add_variable("u", FIRST);
155
156 // The constraint operator below uses the node numbering of
157 // build_line
158 mesh.allow_renumbering(false);
160
161 // Each interior even node is a spline node. Each odd node takes
162 // the mean of its two neighbors. The left node takes a combination
163 // of a new spline node and the next spline node, and the right node
164 // is a spline node. Processor 0 owns all rows of the operator.
165 auto matrix = SparseMatrix<Number>::build(mesh.comm());
166 const bool rank0 = !mesh.comm().rank();
167 matrix->init(11, 6, rank0 ? 11 : 0, rank0 ? 6 : 0, rank0 ? 6 : 0, 0);
168 if (rank0)
169 {
170 matrix->set(0, 0, 0.75);
171 matrix->set(0, 1, 0.25);
172 for (const auto i : make_range(5))
173 {
174 if (i)
175 matrix->set(i*2, i, 1);
176 matrix->set(i*2+1, i, 0.5);
177 matrix->set(i*2+1, i+1, 0.5);
178 }
179 matrix->set(10, 5, 1);
180 }
181 matrix->close();
182 mesh.copy_constraint_rows(*matrix);
184
185 // build_line's left boundary id
186 sys.get_dof_map().add_dirichlet_boundary(DirichletBoundary({0}, {u}, RampFunction(1.)));
187
188 es.init();
189
190 auto & dof_map = sys.get_dof_map();
191 for (const Real time : {0., 0.5, 2.})
192 {
193 sys.time = time;
194 sys.reinit_constraints();
195 const auto rebuilt_rows = gather_local_rows(dof_map);
196 const auto rebuilt_rhs = gather_local_rhs(dof_map);
197
198 sys.reinit_dirichlet_constraint_values();
199 assert_constraints_equal(rebuilt_rows, rebuilt_rhs, dof_map);
200 }
201 }
processor_id_type rank() const
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:1367
void copy_constraint_rows(const MeshBase &other_mesh)
Copy the constraints from the other mesh to this mesh.
Definition mesh_base.C:2838
const Parallel::Communicator & comm() const
static std::unique_ptr< SparseMatrix< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package(), const MatrixBuildType matrix_build_type=MatrixBuildType::AUTOMATIC)
Builds a SparseMatrix<T> using the linear solver package specified by solver_package.
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.
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:176

References libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshBase::allow_renumbering(), libMesh::SparseMatrix< T >::build(), libMesh::MeshTools::Generation::build_line(), libMesh::ParallelObject::comm(), libMesh::MeshBase::copy_constraint_rows(), libMesh::EDGE2, libMesh::FIRST, libMesh::EquationSystems::init(), libMesh::make_range(), mesh, libMesh::MeshBase::prepare_for_use(), libMesh::Parallel::Communicator::rank(), libMesh::Real, and TestCommWorld.

◆ testUpdateMatchesRebuild()

void DirichletConstraintValuesTest::testUpdateMatchesRebuild ( )
inlineprivate

Definition at line 132 of file dirichlet_constraint_values_test.C.

133 {
134 LOG_UNIT_TEST;
135 checkUpdate(4);
136 }
void checkUpdate(const unsigned int n)
Checks that System::reinit_dirichlet_constraint_values() gives exactly the result of System::reinit_c...

References checkUpdate().


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