libMesh
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Private Attributes | List of all members
DofObjectTest< DerivedClass > Class Template Reference

#include <dof_object_test.h>

Public Member Functions

void setUp (DerivedClass *derived_instance)
 
void testSetId ()
 
void testValidId ()
 
void testInvalidateId ()
 
void testSetProcId ()
 
void testValidProcId ()
 
void testInvalidateProcId ()
 
void testSetNSystems ()
 
void testSetNVariableGroups ()
 
void testAddExtraData ()
 
void testAddSystemExtraInts ()
 
void testSetNSystemsExtraInts ()
 
void testSetNVariableGroupsExtraInts ()
 
void testManualDofCalculation ()
 
void testJensEftangBug ()
 

Protected Attributes

std::string libmesh_suite_name
 

Private Attributes

DerivedClass * instance
 

Detailed Description

template<class DerivedClass>
class DofObjectTest< DerivedClass >

Definition at line 25 of file dof_object_test.h.

Member Function Documentation

◆ setUp()

template<class DerivedClass >
void DofObjectTest< DerivedClass >::setUp ( DerivedClass *  derived_instance)
inline

Definition at line 34 of file dof_object_test.h.

35 {
36 instance=derived_instance;
37 }
DerivedClass * instance

References DofObjectTest< DerivedClass >::instance.

Referenced by NodeTest::setUp().

◆ testAddExtraData()

template<class DerivedClass >
void DofObjectTest< DerivedClass >::testAddExtraData ( )
inline

Definition at line 147 of file dof_object_test.h.

148 {
149 LOG_UNIT_TEST;
150
151 DofObject & aobject(*instance);
152
153 aobject.add_extra_integers (9);
154
155 CPPUNIT_ASSERT(aobject.has_extra_integers());
156
157 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(9), aobject.n_extra_integers());
158
159 unsigned int ints_per_Real = (sizeof(Real)-1)/sizeof(dof_id_type) + 1;
160
161 for (unsigned int i=0; i != 9; ++i)
162 CPPUNIT_ASSERT_EQUAL( DofObject::invalid_id, aobject.get_extra_integer(i) );
163
164 for (unsigned int i=0; i != 9; ++i)
165 {
166 // Try out a char at i=1
167 if (i == 1)
168 aobject.set_extra_datum<char>(i, '1');
169 // Try out an extra Real at i=2 if we'll have room
170 if (i == 2 && ints_per_Real <= 4)
171 aobject.set_extra_datum<Real>(i, pi);
172 if (i < 1 || i >= (2 + ints_per_Real))
173 {
174 aobject.set_extra_integer(i, i);
175 CPPUNIT_ASSERT_EQUAL( static_cast<dof_id_type>(i), aobject.get_extra_integer(i) );
176 }
177 }
178
179 aobject.add_extra_integers (6);
180
181 CPPUNIT_ASSERT(aobject.has_extra_integers());
182
183 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(6), aobject.n_extra_integers());
184
185 for (unsigned int i=0; i != 6; ++i)
186 {
187 if (i == 1)
188 CPPUNIT_ASSERT_EQUAL(aobject.get_extra_datum<char>(i), '1');
189 if (i == 2 && ints_per_Real <= 4)
190 CPPUNIT_ASSERT_EQUAL(aobject.get_extra_datum<Real>(i), pi);
191 if (i < 1 || i >= (2 + ints_per_Real))
192 CPPUNIT_ASSERT_EQUAL( static_cast<dof_id_type>(i), aobject.get_extra_integer(i) );
193 }
194 }
The DofObject defines an abstract base class for objects that have degrees of freedom associated with...
Definition dof_object.h:55
static constexpr dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
Definition dof_object.h:473
const Real pi
.
Definition libmesh.h:292
uint8_t dof_id_type
Definition id_types.h:67
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

References libMesh::DofObject::add_extra_integers(), libMesh::DofObject::get_extra_datum(), libMesh::DofObject::get_extra_integer(), libMesh::DofObject::has_extra_integers(), DofObjectTest< DerivedClass >::instance, libMesh::DofObject::invalid_id, libMesh::DofObject::n_extra_integers(), libMesh::pi, libMesh::Real, libMesh::DofObject::set_extra_datum(), and libMesh::DofObject::set_extra_integer().

◆ testAddSystemExtraInts()

template<class DerivedClass >
void DofObjectTest< DerivedClass >::testAddSystemExtraInts ( )
inline

Definition at line 196 of file dof_object_test.h.

197 {
198 LOG_UNIT_TEST;
199
200 DofObject & aobject(*instance);
201
202 aobject.add_extra_integers (1);
203
204 aobject.add_system();
205
206 CPPUNIT_ASSERT(aobject.has_extra_integers());
207
208 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(1), aobject.n_extra_integers());
209 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(1), aobject.n_systems());
210 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(0), aobject.n_vars(0));
211
212 aobject.add_extra_integers (4);
213
214 aobject.add_system();
215
216 CPPUNIT_ASSERT(aobject.has_extra_integers());
217
218 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(4), aobject.n_extra_integers());
219 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(2), aobject.n_systems());
220 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(0), aobject.n_vars(0));
221 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(0), aobject.n_vars(1));
222
223 for (unsigned int i=0; i != 4; ++i)
224 {
225 CPPUNIT_ASSERT_EQUAL( DofObject::invalid_id, aobject.get_extra_integer(i) );
226 aobject.set_extra_integer(i, i);
227 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(i), aobject.get_extra_integer(i));
228 }
229
230 aobject.add_extra_integers (7);
231
232 for (unsigned int i=0; i != 4; ++i)
233 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(i), aobject.get_extra_integer(i));
234
235 for (unsigned int i=4; i != 7; ++i)
236 CPPUNIT_ASSERT_EQUAL( DofObject::invalid_id, aobject.get_extra_integer(i) );
237
238 aobject.add_system();
239
240 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(7), aobject.n_extra_integers());
241
242 for (unsigned int i=0; i != 4; ++i)
243 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(i), aobject.get_extra_integer(i));
244
245 for (unsigned int i=4; i != 7; ++i)
246 {
247 CPPUNIT_ASSERT_EQUAL( DofObject::invalid_id, aobject.get_extra_integer(i) );
248 aobject.set_extra_integer(i, i);
249 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(i), aobject.get_extra_integer(i));
250 }
251
252 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(3), aobject.n_systems());
253 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(0), aobject.n_vars(0));
254 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(0), aobject.n_vars(1));
255 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(0), aobject.n_vars(2));
256
257 for (unsigned int i=0; i != 7; ++i)
258 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(i), aobject.get_extra_integer(i));
259 }

References libMesh::DofObject::add_extra_integers(), libMesh::DofObject::add_system(), libMesh::DofObject::get_extra_integer(), libMesh::DofObject::has_extra_integers(), DofObjectTest< DerivedClass >::instance, libMesh::DofObject::invalid_id, libMesh::DofObject::n_extra_integers(), libMesh::DofObject::n_systems(), libMesh::DofObject::n_vars(), and libMesh::DofObject::set_extra_integer().

◆ testInvalidateId()

template<class DerivedClass >
void DofObjectTest< DerivedClass >::testInvalidateId ( )
inline

Definition at line 62 of file dof_object_test.h.

63 {
64 LOG_UNIT_TEST;
65
66 DofObject & aobject(*instance);
67
68 aobject.set_id(1);
69 aobject.invalidate_id();
70
71 CPPUNIT_ASSERT( !aobject.valid_id() );
72 }

References DofObjectTest< DerivedClass >::instance, libMesh::DofObject::invalidate_id(), libMesh::DofObject::set_id(), and libMesh::DofObject::valid_id().

◆ testInvalidateProcId()

template<class DerivedClass >
void DofObjectTest< DerivedClass >::testInvalidateProcId ( )
inline

Definition at line 97 of file dof_object_test.h.

98 {
99 LOG_UNIT_TEST;
100
101 DofObject & aobject(*instance);
102
103 aobject.processor_id(libMesh::global_processor_id());
104 aobject.invalidate_processor_id();
105
106 CPPUNIT_ASSERT( !aobject.valid_processor_id() );
107 }
processor_id_type global_processor_id()

References libMesh::global_processor_id(), DofObjectTest< DerivedClass >::instance, libMesh::DofObject::invalidate_processor_id(), libMesh::DofObject::processor_id(), and libMesh::DofObject::valid_processor_id().

◆ testJensEftangBug()

template<class DerivedClass >
void DofObjectTest< DerivedClass >::testJensEftangBug ( )
inline

Definition at line 397 of file dof_object_test.h.

398 {
399 LOG_UNIT_TEST;
400
401 // For more information on this bug, see the following email thread:
402 // https://sourceforge.net/p/libmesh/mailman/libmesh-users/thread/50C8EE7C.8090405@gmail.com/
403 DofObject & aobject(*instance);
404 dof_id_type buf0[] = {2, 8, 257, 0, 257, 96, 257, 192, 257, 0};
405 aobject.set_buffer(std::vector<dof_id_type>(buf0, buf0+10));
406
407 CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,0,0), static_cast<dof_id_type>( 0));
408 CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,1,0), static_cast<dof_id_type>( 96));
409 CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,2,0), static_cast<dof_id_type>(192));
410 CPPUNIT_ASSERT_EQUAL (aobject.dof_number(1,0,0), static_cast<dof_id_type>( 0));
411
412 dof_id_type buf1[] = {2, 8, 257, 1, 257, 97, 257, 193, 257, 1};
413 aobject.set_buffer(std::vector<dof_id_type>(buf1, buf1+10));
414
415 CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,0,0), static_cast<dof_id_type>( 1));
416 CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,1,0), static_cast<dof_id_type>( 97));
417 CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,2,0), static_cast<dof_id_type>(193));
418 CPPUNIT_ASSERT_EQUAL (aobject.dof_number(1,0,0), static_cast<dof_id_type>( 1));
419 }

References libMesh::DofObject::dof_number(), DofObjectTest< DerivedClass >::instance, and libMesh::DofObject::set_buffer().

◆ testManualDofCalculation()

template<class DerivedClass >
void DofObjectTest< DerivedClass >::testManualDofCalculation ( )
inline

Definition at line 353 of file dof_object_test.h.

354 {
355 LOG_UNIT_TEST;
356
357 DofObject & aobject(*instance);
358
359 aobject.set_n_systems (2);
360
361 std::vector<unsigned int> nvpg;
362
363 nvpg.push_back(2);
364 nvpg.push_back(3);
365
366 aobject.set_n_vars_per_group (0, nvpg);
367 aobject.set_n_vars_per_group (1, nvpg);
368
369 aobject.set_n_comp_group (0, 0, 1);
370 aobject.set_n_comp_group (0, 1, 3);
371
372 aobject.set_n_comp_group (1, 0, 2);
373 aobject.set_n_comp_group (1, 1, 1);
374
375 aobject.set_vg_dof_base(0, 0, 0);
376 aobject.set_vg_dof_base(0, 1, 120);
377
378 aobject.set_vg_dof_base(1, 0, 20);
379 aobject.set_vg_dof_base(1, 1, 220);
380
381 // Make sure the first dof is sane
382 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(0), aobject.dof_number(0, 0, 0));
383
384 // Check that we can manually index dofs of variables based on the first dof in a variable group
385 // Using: id = base + var_in_vg*ncomp + comp
386 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(aobject.vg_dof_base(0, 0) + 1*1 + 0), aobject.dof_number(0, 1, 0));
387
388 // Another Check that we can manually index dofs of variables based on the first dof in a variable group
389 // Using: id = base + var_in_vg*ncomp + comp
390 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(aobject.vg_dof_base(0, 1) + 2*3 + 2), aobject.dof_number(0, 4, 2));
391
392 // One More Check that we can manually index dofs of variables based on the first dof in a variable group
393 // Using: id = base + var_in_vg*ncomp + comp
394 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(aobject.vg_dof_base(1, 1) + 0*3 + 0), aobject.dof_number(1, 2, 0));
395 }

References libMesh::DofObject::dof_number(), DofObjectTest< DerivedClass >::instance, libMesh::DofObject::set_n_comp_group(), libMesh::DofObject::set_n_systems(), libMesh::DofObject::set_n_vars_per_group(), libMesh::DofObject::set_vg_dof_base(), and libMesh::DofObject::vg_dof_base().

◆ testSetId()

template<class DerivedClass >
void DofObjectTest< DerivedClass >::testSetId ( )
inline

Definition at line 39 of file dof_object_test.h.

40 {
41 LOG_UNIT_TEST;
42
43 DofObject & aobject(*instance);
44
45 aobject.set_id(1);
46 CPPUNIT_ASSERT_EQUAL( static_cast<dof_id_type>(1) , aobject.id() );
47 }

References libMesh::DofObject::id(), DofObjectTest< DerivedClass >::instance, and libMesh::DofObject::set_id().

◆ testSetNSystems()

template<class DerivedClass >
void DofObjectTest< DerivedClass >::testSetNSystems ( )
inline

Definition at line 109 of file dof_object_test.h.

110 {
111 LOG_UNIT_TEST;
112
113 DofObject & aobject(*instance);
114
115 aobject.set_n_systems (10);
116
117 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(10), aobject.n_systems());
118 }

References DofObjectTest< DerivedClass >::instance, libMesh::DofObject::n_systems(), and libMesh::DofObject::set_n_systems().

◆ testSetNSystemsExtraInts()

template<class DerivedClass >
void DofObjectTest< DerivedClass >::testSetNSystemsExtraInts ( )
inline

Definition at line 261 of file dof_object_test.h.

262 {
263 LOG_UNIT_TEST;
264
265 DofObject & aobject(*instance);
266
267 aobject.add_extra_integers (5);
268
269 aobject.set_n_systems (10);
270
271 CPPUNIT_ASSERT(aobject.has_extra_integers());
272
273 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(5), aobject.n_extra_integers());
274 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(10), aobject.n_systems());
275
276 for (unsigned int i=0; i != 5; ++i)
277 {
278 CPPUNIT_ASSERT_EQUAL( DofObject::invalid_id, aobject.get_extra_integer(i) );
279 aobject.set_extra_integer(i, i);
280 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(i), aobject.get_extra_integer(i));
281 }
282
283 aobject.add_extra_integers (9);
284
285 for (unsigned int i=0; i != 5; ++i)
286 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(i), aobject.get_extra_integer(i));
287
288 for (unsigned int i=5; i != 9; ++i)
289 CPPUNIT_ASSERT_EQUAL( DofObject::invalid_id, aobject.get_extra_integer(i) );
290
291 aobject.set_n_systems (6);
292
293 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(9), aobject.n_extra_integers());
294
295 for (unsigned int i=0; i != 5; ++i)
296 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(i), aobject.get_extra_integer(i));
297
298 for (unsigned int i=5; i != 9; ++i)
299 {
300 CPPUNIT_ASSERT_EQUAL( DofObject::invalid_id, aobject.get_extra_integer(i) );
301 aobject.set_extra_integer(i, i);
302 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(i), aobject.get_extra_integer(i));
303 }
304
305 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(6), aobject.n_systems());
306
307 for (unsigned int i=0; i != 9; ++i)
308 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(i), aobject.get_extra_integer(i));
309 }

References libMesh::DofObject::add_extra_integers(), libMesh::DofObject::get_extra_integer(), libMesh::DofObject::has_extra_integers(), DofObjectTest< DerivedClass >::instance, libMesh::DofObject::invalid_id, libMesh::DofObject::n_extra_integers(), libMesh::DofObject::n_systems(), libMesh::DofObject::set_extra_integer(), and libMesh::DofObject::set_n_systems().

◆ testSetNVariableGroups()

template<class DerivedClass >
void DofObjectTest< DerivedClass >::testSetNVariableGroups ( )
inline

Definition at line 120 of file dof_object_test.h.

121 {
122 LOG_UNIT_TEST;
123
124 DofObject & aobject(*instance);
125
126 aobject.set_n_systems (2);
127
128 std::vector<unsigned int> nvpg;
129
130 nvpg.push_back(10);
131 nvpg.push_back(20);
132 nvpg.push_back(30);
133
134 aobject.set_n_vars_per_group (0, nvpg);
135 aobject.set_n_vars_per_group (1, nvpg);
136
137 for (unsigned int s=0; s<2; s++)
138 {
139 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(60), aobject.n_vars(s));
140 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(3), aobject.n_var_groups(s));
141
142 for (unsigned int vg=0; vg<3; vg++)
143 CPPUNIT_ASSERT_EQUAL( nvpg[vg], aobject.n_vars(s,vg) );
144 }
145 }

References DofObjectTest< DerivedClass >::instance, libMesh::DofObject::n_var_groups(), libMesh::DofObject::n_vars(), libMesh::DofObject::set_n_systems(), and libMesh::DofObject::set_n_vars_per_group().

◆ testSetNVariableGroupsExtraInts()

template<class DerivedClass >
void DofObjectTest< DerivedClass >::testSetNVariableGroupsExtraInts ( )
inline

Definition at line 311 of file dof_object_test.h.

312 {
313 LOG_UNIT_TEST;
314
315 DofObject & aobject(*instance);
316
317 aobject.set_n_systems (2);
318
319 aobject.add_extra_integers (5);
320
321 for (unsigned int i=0; i != 5; ++i)
322 {
323 CPPUNIT_ASSERT_EQUAL( DofObject::invalid_id, aobject.get_extra_integer(i) );
324 aobject.set_extra_integer(i, i);
325 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(i), aobject.get_extra_integer(i));
326 }
327
328 std::vector<unsigned int> nvpg;
329
330 nvpg.push_back(10);
331 nvpg.push_back(20);
332 nvpg.push_back(30);
333
334 aobject.set_n_vars_per_group (0, nvpg);
335 aobject.set_n_vars_per_group (1, nvpg);
336
337 for (unsigned int s=0; s<2; s++)
338 {
339 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(60), aobject.n_vars(s));
340 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(3), aobject.n_var_groups(s));
341
342 for (unsigned int vg=0; vg<3; vg++)
343 CPPUNIT_ASSERT_EQUAL( nvpg[vg], aobject.n_vars(s,vg) );
344 }
345
346 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(5), aobject.n_extra_integers());
347
348 for (unsigned int i=0; i != 5; ++i)
349 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(i), aobject.get_extra_integer(i));
350 }

References libMesh::DofObject::add_extra_integers(), libMesh::DofObject::get_extra_integer(), DofObjectTest< DerivedClass >::instance, libMesh::DofObject::invalid_id, libMesh::DofObject::n_extra_integers(), libMesh::DofObject::n_var_groups(), libMesh::DofObject::n_vars(), libMesh::DofObject::set_extra_integer(), libMesh::DofObject::set_n_systems(), and libMesh::DofObject::set_n_vars_per_group().

◆ testSetProcId()

template<class DerivedClass >
void DofObjectTest< DerivedClass >::testSetProcId ( )
inline

Definition at line 74 of file dof_object_test.h.

75 {
76 LOG_UNIT_TEST;
77
78 DofObject & aobject(*instance);
79
80 aobject.processor_id(libMesh::global_processor_id());
81 CPPUNIT_ASSERT_EQUAL(static_cast<processor_id_type>(libMesh::global_processor_id()), aobject.processor_id());
82 }
uint8_t processor_id_type
Definition id_types.h:104

References libMesh::global_processor_id(), DofObjectTest< DerivedClass >::instance, and libMesh::DofObject::processor_id().

◆ testValidId()

template<class DerivedClass >
void DofObjectTest< DerivedClass >::testValidId ( )
inline

Definition at line 49 of file dof_object_test.h.

50 {
51 LOG_UNIT_TEST;
52
53 DofObject & aobject(*instance);
54
55 aobject.set_id(1);
56 CPPUNIT_ASSERT( aobject.valid_id() );
57
58 aobject.set_id(DofObject::invalid_id);
59 CPPUNIT_ASSERT( !aobject.valid_id() );
60 }

References DofObjectTest< DerivedClass >::instance, libMesh::DofObject::invalid_id, libMesh::DofObject::set_id(), and libMesh::DofObject::valid_id().

◆ testValidProcId()

template<class DerivedClass >
void DofObjectTest< DerivedClass >::testValidProcId ( )
inline

Definition at line 84 of file dof_object_test.h.

85 {
86 LOG_UNIT_TEST;
87
88 DofObject & aobject(*instance);
89
90 aobject.processor_id(libMesh::global_processor_id());
91 CPPUNIT_ASSERT(aobject.valid_processor_id());
92
93 aobject.processor_id(DofObject::invalid_processor_id);
94 CPPUNIT_ASSERT(!aobject.valid_processor_id());
95 }
static constexpr processor_id_type invalid_processor_id
An invalid processor_id to distinguish DoFs that have not been assigned to a processor.
Definition dof_object.h:484

References libMesh::global_processor_id(), DofObjectTest< DerivedClass >::instance, libMesh::DofObject::invalid_processor_id, libMesh::DofObject::processor_id(), and libMesh::DofObject::valid_processor_id().

Member Data Documentation

◆ instance

template<class DerivedClass >
DerivedClass* DofObjectTest< DerivedClass >::instance
private

◆ libmesh_suite_name

template<class DerivedClass >
std::string DofObjectTest< DerivedClass >::libmesh_suite_name
protected

Definition at line 31 of file dof_object_test.h.


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