libMesh
Loading...
Searching...
No Matches
dof_object_test.h
Go to the documentation of this file.
1#ifndef __dof_object_test_h__
2#define __dof_object_test_h__
3
4#include "libmesh_cppunit.h"
5
6#define DOFOBJECTTEST \
7 CPPUNIT_TEST( testSetId ); \
8 CPPUNIT_TEST( testValidId ); \
9 CPPUNIT_TEST( testInvalidateId ); \
10 CPPUNIT_TEST( testSetProcId ); \
11 CPPUNIT_TEST( testValidProcId ); \
12 CPPUNIT_TEST( testInvalidateProcId ); \
13 CPPUNIT_TEST( testSetNSystems ); \
14 CPPUNIT_TEST( testSetNVariableGroups ); \
15 CPPUNIT_TEST( testAddExtraData ); \
16 CPPUNIT_TEST( testAddSystemExtraInts ); \
17 CPPUNIT_TEST( testSetNSystemsExtraInts ); \
18 CPPUNIT_TEST( testSetNVariableGroupsExtraInts ); \
19 CPPUNIT_TEST( testManualDofCalculation ); \
20 CPPUNIT_TEST( testJensEftangBug );
21
22using namespace libMesh;
23
24template <class DerivedClass>
26
27private:
28 DerivedClass * instance;
29
30protected:
31 std::string libmesh_suite_name;
32
33public:
34 void setUp(DerivedClass * derived_instance)
35 {
36 instance=derived_instance;
37 }
38
39 void testSetId()
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 }
48
50 {
51 LOG_UNIT_TEST;
52
53 DofObject & aobject(*instance);
54
55 aobject.set_id(1);
56 CPPUNIT_ASSERT( aobject.valid_id() );
57
59 CPPUNIT_ASSERT( !aobject.valid_id() );
60 }
61
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 }
73
75 {
76 LOG_UNIT_TEST;
77
78 DofObject & aobject(*instance);
79
81 CPPUNIT_ASSERT_EQUAL(static_cast<processor_id_type>(libMesh::global_processor_id()), aobject.processor_id());
82 }
83
85 {
86 LOG_UNIT_TEST;
87
88 DofObject & aobject(*instance);
89
91 CPPUNIT_ASSERT(aobject.valid_processor_id());
92
94 CPPUNIT_ASSERT(!aobject.valid_processor_id());
95 }
96
98 {
99 LOG_UNIT_TEST;
100
101 DofObject & aobject(*instance);
102
104 aobject.invalidate_processor_id();
105
106 CPPUNIT_ASSERT( !aobject.valid_processor_id() );
107 }
108
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 }
119
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 }
146
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 }
195
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 }
260
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 }
310
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 }
351
352
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 }
396
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 }
420};
421
422#endif // #ifdef __dof_object_test_h__
std::string libmesh_suite_name
void setUp(DerivedClass *derived_instance)
void testAddSystemExtraInts()
void testSetNVariableGroups()
void testSetNSystemsExtraInts()
void testInvalidateProcId()
void testInvalidateId()
void testManualDofCalculation()
DerivedClass * instance
void testSetNVariableGroupsExtraInts()
The DofObject defines an abstract base class for objects that have degrees of freedom associated with...
Definition dof_object.h:55
void invalidate_processor_id()
Sets the processor id to invalid_processor_id.
Definition dof_object.h:771
dof_id_type vg_dof_base(const unsigned int s, const unsigned int vg) const
VariableGroup DoF indices are indexed as id = base + var_in_vg*ncomp + comp This method allows for di...
unsigned int n_systems() const
Definition dof_object.h:913
bool valid_id() const
Definition dof_object.h:861
bool has_extra_integers() const
Returns whether extra integers are associated to the DofObject.
dof_id_type get_extra_integer(const unsigned int index) const
Gets the value on this object of the extra integer associated with index, which should have been obta...
void set_n_comp_group(const unsigned int s, const unsigned int vg, const unsigned int ncomp)
Sets the number of components for VariableGroup vg of system s associated with this DofObject.
Definition dof_object.C:389
dof_id_type dof_number(const unsigned int s, const unsigned int var, const unsigned int comp) const
unsigned int n_extra_integers() const
Returns how many extra integers are associated to the DofObject.
void invalidate_id()
Sets the id to invalid_id.
Definition dof_object.h:763
void set_buffer(const std::vector< dof_id_type > &buf)
Definition dof_object.h:708
void set_n_vars_per_group(const unsigned int s, const std::vector< unsigned int > &nvpg)
Sets number of variables in each group associated with system s for this DofObject.
Definition dof_object.C:239
void add_system()
Adds an additional system to the DofObject.
Definition dof_object.C:187
processor_id_type processor_id() const
Definition dof_object.h:881
dof_id_type & set_id()
Definition dof_object.h:827
unsigned int n_var_groups(const unsigned int s) const
Definition dof_object.h:933
void add_extra_integers(const unsigned int n_integers)
Assigns a set of extra integers to this DofObject.
Definition dof_object.C:482
static constexpr dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
Definition dof_object.h:473
bool valid_processor_id() const
Definition dof_object.h:905
T get_extra_datum(const unsigned int index) const
Gets the value on this object of the extra datum associated with index, which should have been obtain...
void set_extra_datum(const unsigned int index, const T value)
Sets the value on this object of the extra datum associated with index, which should have been obtain...
dof_id_type id() const
Definition dof_object.h:819
void set_vg_dof_base(const unsigned int s, const unsigned int vg, const dof_id_type db)
VariableGroup DoF indices are indexed as id = base + var_in_vg*ncomp + comp This method allows for di...
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
unsigned int n_vars(const unsigned int s, const unsigned int vg) const
Definition dof_object.h:943
void set_extra_integer(const unsigned int index, const dof_id_type value)
Sets the value on this object of the extra integer associated with index, which should have been obta...
void set_n_systems(const unsigned int s)
Sets the number of systems for this DofObject.
Definition dof_object.C:142
The libMesh namespace provides an interface to certain functionality in the library.
processor_id_type global_processor_id()
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
uint8_t processor_id_type
Definition id_types.h:104