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

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (ConstraintOperatorTest)
 
 CPPUNIT_TEST (test1DCoarseningOperator)
 
 CPPUNIT_TEST (test1DCoarseningNewNodes)
 
 CPPUNIT_TEST (testCoreformGeom2)
 
 CPPUNIT_TEST (testCoreformGeom4)
 
 CPPUNIT_TEST (testCoreformGeom8)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void test1DCoarseningOperator ()
 
void testCoreform (const std::string &meshfile, const std::string &matrixfile, Real expected_norm, Order order=FIRST)
 
void testCoreformGeom2 ()
 
void testCoreformGeom4 ()
 
void testCoreformGeom8 ()
 
void test1DCoarseningNewNodes ()
 

Detailed Description

Definition at line 99 of file constraint_operator_test.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/5]

ConstraintOperatorTest::CPPUNIT_TEST ( test1DCoarseningNewNodes  )

◆ CPPUNIT_TEST() [2/5]

ConstraintOperatorTest::CPPUNIT_TEST ( test1DCoarseningOperator  )

◆ CPPUNIT_TEST() [3/5]

ConstraintOperatorTest::CPPUNIT_TEST ( testCoreformGeom2  )

◆ CPPUNIT_TEST() [4/5]

ConstraintOperatorTest::CPPUNIT_TEST ( testCoreformGeom4  )

◆ CPPUNIT_TEST() [5/5]

ConstraintOperatorTest::CPPUNIT_TEST ( testCoreformGeom8  )

◆ CPPUNIT_TEST_SUITE_END()

ConstraintOperatorTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

ConstraintOperatorTest::LIBMESH_CPPUNIT_TEST_SUITE ( ConstraintOperatorTest  )

◆ setUp()

void ConstraintOperatorTest::setUp ( )
inline

Definition at line 129 of file constraint_operator_test.C.

130 {}

◆ tearDown()

void ConstraintOperatorTest::tearDown ( )
inline

Definition at line 132 of file constraint_operator_test.C.

133 {}

◆ test1DCoarseningNewNodes()

void ConstraintOperatorTest::test1DCoarseningNewNodes ( )
inline

Definition at line 316 of file constraint_operator_test.C.

317 {
318 LOG_UNIT_TEST;
319
320 Mesh mesh(*TestCommWorld);
322
323 ExplicitSystem &sys =
324 es.add_system<LinearImplicitSystem> ("test");
325
326 sys.add_variable("u", FIRST);
328
329 // Make sure numbering matches our constraint operator matrix
330 mesh.allow_renumbering(false);
331
333 10,
334 0., 1.,
335 EDGE2);
336
337 // We should be prepared at this point
338 CPPUNIT_ASSERT(mesh.is_prepared());
339 CPPUNIT_ASSERT(MeshTools::valid_is_prepared(mesh));
340
341 auto matrix = SparseMatrix<Number>::build (mesh.comm());
342
343 // Create a projection matrix from 10 elements to 4. We'll only
344 // be leaving the end nodes and one central node unconstrained, so
345 // we should see two new unconstrained NodeElem added.
346 matrix->read_matlab("meshes/constrain10to4.m");
347
348 mesh.copy_constraint_rows(*matrix);
349
350 // We should still be prepared at this point
351 CPPUNIT_ASSERT(mesh.is_prepared());
352 CPPUNIT_ASSERT(MeshTools::valid_is_prepared(mesh));
353
354 // Do a redundant prepare-for-use to catch any issues there
356
357 es.init ();
358 sys.solve();
359
360 const DofMap & dof_map = sys.get_dof_map();
361
362 CPPUNIT_ASSERT_EQUAL(dof_id_type(11+2), mesh.n_nodes());
363 CPPUNIT_ASSERT_EQUAL(dof_id_type(10+2), mesh.n_elem());
364 CPPUNIT_ASSERT_EQUAL(dof_id_type(8), dof_map.n_constrained_dofs());
365 }
This class handles the numbering of degrees of freedom on a mesh.
Definition dof_map.h:181
dof_id_type n_constrained_dofs() const
This is the EquationSystems class.
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems.
virtual void solve() override
For explicit systems, just assemble the system which should directly compute A*x.
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
bool is_prepared() const
Definition mesh_base.C:1064
virtual dof_id_type n_elem() const =0
void allow_renumbering(bool allow)
If false is passed in then this mesh will no longer be renumbered when being prepared for use.
Definition mesh_base.h:1355
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:824
virtual dof_id_type n_nodes() const =0
void copy_constraint_rows(const MeshBase &other_mesh)
Copy the constraints from the other mesh to this mesh.
Definition mesh_base.C:2490
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition mesh.h:51
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 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:1959
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:1344
const DofMap & get_dof_map() const
Definition system.h:2417
MeshBase & mesh
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.
bool valid_is_prepared(const MeshBase &mesh)
A function for testing whether a mesh's cached is_prepared() setting is not a false positive.
uint8_t dof_id_type
Definition id_types.h:67
void assemble_matrix_and_rhs(EquationSystems &es, const std::string &)

References libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshBase::allow_renumbering(), assemble_matrix_and_rhs(), libMesh::System::attach_assemble_function(), libMesh::SparseMatrix< T >::build(), libMesh::MeshTools::Generation::build_line(), libMesh::ParallelObject::comm(), libMesh::MeshBase::copy_constraint_rows(), libMesh::EDGE2, libMesh::FIRST, libMesh::System::get_dof_map(), libMesh::EquationSystems::init(), libMesh::MeshBase::is_prepared(), mesh, libMesh::DofMap::n_constrained_dofs(), libMesh::MeshBase::n_elem(), libMesh::MeshBase::n_nodes(), libMesh::MeshBase::prepare_for_use(), libMesh::SparseMatrix< T >::read_matlab(), libMesh::ExplicitSystem::solve(), TestCommWorld, and libMesh::MeshTools::valid_is_prepared().

◆ test1DCoarseningOperator()

void ConstraintOperatorTest::test1DCoarseningOperator ( )
inline

Definition at line 136 of file constraint_operator_test.C.

137 {
138 LOG_UNIT_TEST;
139
140 Mesh mesh(*TestCommWorld);
142
143 ExplicitSystem &sys =
144 es.add_system<LinearImplicitSystem> ("test");
145
146 sys.add_variable("u", FIRST);
148
149 // Make sure numbering matches our constraint operator matrix
150 mesh.allow_renumbering(false);
151
153 10,
154 0., 1.,
155 EDGE2);
156
157 // We should be prepared at this point
158 CPPUNIT_ASSERT(mesh.is_prepared());
159 CPPUNIT_ASSERT(MeshTools::valid_is_prepared(mesh));
160
161 auto matrix = SparseMatrix<Number>::build (mesh.comm());
162
163 // Create a projection matrix from 10 elements to 5. We might as
164 // well just make it on processor 0.
165 processor_id_type my_rank = mesh.comm().rank();
166 matrix->init(11, 6,
167 (my_rank ? 0 : 11),
168 (my_rank ? 0 : 6),
169 (my_rank ? 0 : 6),
170 0);
171
172 if (!my_rank)
173 {
174 for (auto i : make_range(5))
175 {
176 matrix->set(i*2, i, 1);
177 matrix->set(i*2+1, i, 0.5);
178 matrix->set(i*2+1, i+1, 0.5);
179 }
180 matrix->set(10, 5, 1);
181 }
182 matrix->close();
183
184 mesh.copy_constraint_rows(*matrix);
185
186 // We should still be prepared at this point
187 CPPUNIT_ASSERT(mesh.is_prepared());
188 CPPUNIT_ASSERT(MeshTools::valid_is_prepared(mesh));
189
190 // Do a redundant prepare-for-use to catch any issues there
192
193 es.init ();
194 sys.solve();
195
196 const DofMap & dof_map = sys.get_dof_map();
197
198 CPPUNIT_ASSERT_EQUAL(dof_id_type(5), dof_map.n_constrained_dofs());
199
200 // Now compare the results to just solving on 5 elements.
201
202 // Matching up partitioning is hard, so just replicate+serialize
203 ReplicatedMesh mesh2(*TestCommWorld);
205
206 ExplicitSystem &sys2 =
207 es2.add_system<LinearImplicitSystem> ("test");
208
209 sys2.add_variable("u", FIRST);
211
213 5,
214 0., 1.,
215 EDGE2);
216
217 es2.init ();
218 sys2.solve();
219
220 // Integrate any differences on the fine grid
221 ExactSolution exact(es);
222
223 // Serialize rather than figure out proper ghosting for an
224 // arbitrary partitioning mix
225 auto serialized_solution2 =
226 NumericVector<Number>::build(*TestCommWorld);
227 serialized_solution2->init(sys2.solution->size(), false, SERIAL);
228 sys2.solution->localize(*serialized_solution2);
229
230 MeshFunction coarse_solution
231 (es2, *serialized_solution2, sys2.get_dof_map(), 0);
232
233 exact.attach_exact_value(0, &coarse_solution);
234 exact.compute_error("test", "u");
235 Real err = exact.l2_error("test", "u");
236 CPPUNIT_ASSERT_LESS(Real(TOLERANCE*TOLERANCE), err);
237 }
processor_id_type rank() const
This class handles the computation of the L2 and/or H1 error for the Systems in the EquationSystems o...
This class provides function-like objects for data distributed over a mesh.
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, SolverPackage solver_package=libMesh::default_solver_package(), ParallelType parallel_type=AUTOMATIC)
Builds a NumericVector on the processors in communicator comm using the linear solver package specifi...
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition system.h:1655
OStreamProxy err
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t processor_id_type
Definition id_types.h:104
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(), assemble_matrix_and_rhs(), libMesh::System::attach_assemble_function(), libMesh::ExactSolution::attach_exact_value(), libMesh::SparseMatrix< T >::build(), libMesh::NumericVector< T >::build(), libMesh::MeshTools::Generation::build_line(), libMesh::SparseMatrix< T >::close(), libMesh::ParallelObject::comm(), libMesh::ExactSolution::compute_error(), libMesh::MeshBase::copy_constraint_rows(), libMesh::EDGE2, libMesh::err, libMesh::FIRST, libMesh::System::get_dof_map(), libMesh::EquationSystems::init(), libMesh::SparseMatrix< T >::init(), libMesh::MeshBase::is_prepared(), libMesh::ExactSolution::l2_error(), libMesh::make_range(), mesh, libMesh::DofMap::n_constrained_dofs(), libMesh::MeshBase::prepare_for_use(), libMesh::Parallel::Communicator::rank(), libMesh::Real, libMesh::SERIAL, libMesh::SparseMatrix< T >::set(), libMesh::System::solution, libMesh::ExplicitSystem::solve(), TestCommWorld, libMesh::TOLERANCE, and libMesh::MeshTools::valid_is_prepared().

◆ testCoreform()

void ConstraintOperatorTest::testCoreform ( const std::string &  meshfile,
const std::string &  matrixfile,
Real  expected_norm,
Order  order = FIRST 
)
inline

Definition at line 240 of file constraint_operator_test.C.

244 {
245 Mesh mesh(*TestCommWorld);
247
248 ExplicitSystem &sys =
249 es.add_system<LinearImplicitSystem> ("test");
250
251 sys.add_variable("u", order);
253
254 // Make sure numbering matches our constraint operator matrix
255 mesh.allow_renumbering(false);
256
257 mesh.read(meshfile);
258
259 CPPUNIT_ASSERT(mesh.is_prepared());
260
261 // For these matrices Coreform has been experimenting with PETSc
262 // solvers which take the transpose of what we expect, so we'll
263 // un-transpose here.
264 auto matrix = SparseMatrix<Number>::build (mesh.comm());
265 matrix->read_matlab(matrixfile);
266 matrix->get_transpose(*matrix);
267
268 mesh.copy_constraint_rows(*matrix);
269
270 // We should be prepared at this point
271 CPPUNIT_ASSERT(mesh.is_prepared());
272 CPPUNIT_ASSERT(MeshTools::valid_is_prepared(mesh));
273
274 // Do a redundant prepare-for-use to catch any issues there
276
277 es.init ();
278 sys.solve();
279
280 // Skip norm calculations on NodeElems
281 std::set<unsigned int> skip_dimensions {0};
282 Real h1_norm = sys.calculate_norm(*sys.solution, 0, H1,
283 &skip_dimensions);
284
285 LIBMESH_ASSERT_FP_EQUAL(h1_norm, expected_norm, TOLERANCE*std::sqrt(TOLERANCE));
286 }
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false, bool skip_detect_interior_parents=false)=0
Interfaces for reading/writing a mesh to/from a file.
Real calculate_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=nullptr) const
Definition system.C:1511

References libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshBase::allow_renumbering(), assemble_matrix_and_rhs(), libMesh::System::attach_assemble_function(), libMesh::SparseMatrix< T >::build(), libMesh::System::calculate_norm(), libMesh::ParallelObject::comm(), libMesh::MeshBase::copy_constraint_rows(), libMesh::SparseMatrix< T >::get_transpose(), libMesh::H1, libMesh::EquationSystems::init(), libMesh::MeshBase::is_prepared(), mesh, libMesh::MeshBase::prepare_for_use(), libMesh::MeshBase::read(), libMesh::SparseMatrix< T >::read_matlab(), libMesh::Real, libMesh::System::solution, libMesh::ExplicitSystem::solve(), TestCommWorld, libMesh::TOLERANCE, and libMesh::MeshTools::valid_is_prepared().

Referenced by testCoreformGeom2(), testCoreformGeom4(), and testCoreformGeom8().

◆ testCoreformGeom2()

void ConstraintOperatorTest::testCoreformGeom2 ( )
inline

Definition at line 289 of file constraint_operator_test.C.

290 {
291 LOG_UNIT_TEST;
292 testCoreform("meshes/geom_2.exo",
293 "matrices/geom_2_extraction_op.m",
294 0.09598270393980124874069039295234223854_R);
295 }
void testCoreform(const std::string &meshfile, const std::string &matrixfile, Real expected_norm, Order order=FIRST)

References testCoreform().

◆ testCoreformGeom4()

void ConstraintOperatorTest::testCoreformGeom4 ( )
inline

Definition at line 298 of file constraint_operator_test.C.

299 {
300 LOG_UNIT_TEST;
301 testCoreform("meshes/geom_4.exo",
302 "matrices/geom_4_extraction_op.m",
303 0.1040405127939275102143852084416339522_R);
304 }

References testCoreform().

◆ testCoreformGeom8()

void ConstraintOperatorTest::testCoreformGeom8 ( )
inline

Definition at line 307 of file constraint_operator_test.C.

308 {
309 LOG_UNIT_TEST;
310 testCoreform("meshes/geom_8.exo",
311 "matrices/geom_8_extraction_op.m",
312 0.103252835327032837145271735988790535_R);
313 }

References testCoreform().


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