libMesh
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 <cppunit/extensions/HelperMacros.h>
5 #include <cppunit/TestCase.h>
6 
7 #define DOFOBJECTTEST \
8  CPPUNIT_TEST( testSetId ); \
9  CPPUNIT_TEST( testValidId ); \
10  CPPUNIT_TEST( testInvalidateId ); \
11  CPPUNIT_TEST( testSetProcId ); \
12  CPPUNIT_TEST( testValidProcId ); \
13  CPPUNIT_TEST( testInvalidateProcId ); \
14  CPPUNIT_TEST( testSetNSystems ); \
15  CPPUNIT_TEST( testSetNVariableGroups ); \
16  CPPUNIT_TEST( testAddExtraInts ); \
17  CPPUNIT_TEST( testSetNSystemsExtraInts ); \
18  CPPUNIT_TEST( testSetNVariableGroupsExtraInts ); \
19  CPPUNIT_TEST( testManualDofCalculation ); \
20  CPPUNIT_TEST( testJensEftangBug );
21 
22 using namespace libMesh;
23 
24 template <class DerivedClass>
26 
27 private:
28  DerivedClass * instance;
29 
30 public:
31  void setUp(DerivedClass * derived_instance)
32  {
33  instance=derived_instance;
34  }
35 
36  void testSetId()
37  {
38  DofObject aobject(*instance);
39 
40  aobject.set_id(1);
41  CPPUNIT_ASSERT_EQUAL( static_cast<dof_id_type>(1) , aobject.id() );
42  }
43 
44  void testValidId()
45  {
46  DofObject aobject(*instance);
47 
48  aobject.set_id(1);
49  CPPUNIT_ASSERT( aobject.valid_id() );
50 
52  CPPUNIT_ASSERT( !aobject.valid_id() );
53  }
54 
56  {
57  DofObject aobject(*instance);
58 
59  aobject.set_id(1);
60  aobject.invalidate_id();
61 
62  CPPUNIT_ASSERT( !aobject.valid_id() );
63  }
64 
66  {
67  DofObject aobject(*instance);
68 
70  CPPUNIT_ASSERT_EQUAL( (processor_id_type)libMesh::global_processor_id() , aobject.processor_id() );
71  }
72 
74  {
75  DofObject aobject(*instance);
76 
78  CPPUNIT_ASSERT(aobject.valid_processor_id());
79 
81  CPPUNIT_ASSERT(!aobject.valid_processor_id());
82  }
83 
85  {
86  DofObject aobject(*instance);
87 
89  aobject.invalidate_processor_id();
90 
91  CPPUNIT_ASSERT( !aobject.valid_processor_id() );
92  }
93 
95  {
96  DofObject aobject(*instance);
97 
98  aobject.set_n_systems (10);
99 
100  CPPUNIT_ASSERT_EQUAL( (unsigned int) 10, aobject.n_systems() );
101  }
102 
104  {
105  DofObject aobject(*instance);
106 
107  aobject.set_n_systems (2);
108 
109  std::vector<unsigned int> nvpg;
110 
111  nvpg.push_back(10);
112  nvpg.push_back(20);
113  nvpg.push_back(30);
114 
115  aobject.set_n_vars_per_group (0, nvpg);
116  aobject.set_n_vars_per_group (1, nvpg);
117 
118  for (unsigned int s=0; s<2; s++)
119  {
120  CPPUNIT_ASSERT_EQUAL( (unsigned int) 60, aobject.n_vars(s) );
121  CPPUNIT_ASSERT_EQUAL( (unsigned int) 3, aobject.n_var_groups(s) );
122 
123  for (unsigned int vg=0; vg<3; vg++)
124  CPPUNIT_ASSERT_EQUAL( nvpg[vg], aobject.n_vars(s,vg) );
125  }
126  }
127 
129  {
130  DofObject aobject(*instance);
131 
132  aobject.add_extra_integers (9);
133 
134  CPPUNIT_ASSERT(aobject.has_extra_integers());
135 
136  CPPUNIT_ASSERT_EQUAL( (unsigned int) 9, aobject.n_extra_integers() );
137 
138  for (unsigned int i=0; i != 9; ++i)
139  {
140  CPPUNIT_ASSERT_EQUAL( DofObject::invalid_id, aobject.get_extra_integer(i) );
141  aobject.set_extra_integer(i, i);
142  CPPUNIT_ASSERT_EQUAL( dof_id_type(i), aobject.get_extra_integer(i) );
143  }
144 
145  aobject.add_extra_integers (6);
146 
147  CPPUNIT_ASSERT(aobject.has_extra_integers());
148 
149  CPPUNIT_ASSERT_EQUAL( (unsigned int) 6, aobject.n_extra_integers() );
150 
151  for (unsigned int i=0; i != 6; ++i)
152  CPPUNIT_ASSERT_EQUAL( dof_id_type(i), aobject.get_extra_integer(i) );
153  }
154 
156  {
157  DofObject aobject(*instance);
158 
159  aobject.add_extra_integers (5);
160 
161  aobject.set_n_systems (10);
162 
163  CPPUNIT_ASSERT(aobject.has_extra_integers());
164 
165  CPPUNIT_ASSERT_EQUAL( (unsigned int) 5, aobject.n_extra_integers() );
166 
167  CPPUNIT_ASSERT_EQUAL( (unsigned int) 10, aobject.n_systems() );
168 
169  for (unsigned int i=0; i != 5; ++i)
170  {
171  CPPUNIT_ASSERT_EQUAL( DofObject::invalid_id, aobject.get_extra_integer(i) );
172  aobject.set_extra_integer(i, i);
173  CPPUNIT_ASSERT_EQUAL( dof_id_type(i), aobject.get_extra_integer(i) );
174  }
175 
176  aobject.add_extra_integers (9);
177 
178  for (unsigned int i=0; i != 5; ++i)
179  CPPUNIT_ASSERT_EQUAL( dof_id_type(i), aobject.get_extra_integer(i) );
180 
181  for (unsigned int i=5; i != 9; ++i)
182  CPPUNIT_ASSERT_EQUAL( DofObject::invalid_id, aobject.get_extra_integer(i) );
183 
184  aobject.set_n_systems (6);
185 
186  CPPUNIT_ASSERT_EQUAL( (unsigned int) 9, aobject.n_extra_integers() );
187 
188  for (unsigned int i=0; i != 5; ++i)
189  CPPUNIT_ASSERT_EQUAL( dof_id_type(i), aobject.get_extra_integer(i) );
190 
191  for (unsigned int i=5; i != 9; ++i)
192  {
193  CPPUNIT_ASSERT_EQUAL( DofObject::invalid_id, aobject.get_extra_integer(i) );
194  aobject.set_extra_integer(i, i);
195  CPPUNIT_ASSERT_EQUAL( dof_id_type(i), aobject.get_extra_integer(i) );
196  }
197 
198  CPPUNIT_ASSERT_EQUAL( (unsigned int) 6, aobject.n_systems() );
199 
200  for (unsigned int i=0; i != 9; ++i)
201  CPPUNIT_ASSERT_EQUAL( dof_id_type(i), aobject.get_extra_integer(i) );
202  }
203 
205  {
206  DofObject aobject(*instance);
207 
208  aobject.set_n_systems (2);
209 
210  aobject.add_extra_integers (5);
211 
212  for (unsigned int i=0; i != 5; ++i)
213  {
214  CPPUNIT_ASSERT_EQUAL( DofObject::invalid_id, aobject.get_extra_integer(i) );
215  aobject.set_extra_integer(i, i);
216  CPPUNIT_ASSERT_EQUAL( dof_id_type(i), aobject.get_extra_integer(i) );
217  }
218 
219  std::vector<unsigned int> nvpg;
220 
221  nvpg.push_back(10);
222  nvpg.push_back(20);
223  nvpg.push_back(30);
224 
225  aobject.set_n_vars_per_group (0, nvpg);
226  aobject.set_n_vars_per_group (1, nvpg);
227 
228  for (unsigned int s=0; s<2; s++)
229  {
230  CPPUNIT_ASSERT_EQUAL( (unsigned int) 60, aobject.n_vars(s) );
231  CPPUNIT_ASSERT_EQUAL( (unsigned int) 3, aobject.n_var_groups(s) );
232 
233  for (unsigned int vg=0; vg<3; vg++)
234  CPPUNIT_ASSERT_EQUAL( nvpg[vg], aobject.n_vars(s,vg) );
235  }
236 
237  CPPUNIT_ASSERT_EQUAL( (unsigned int) 5, aobject.n_extra_integers() );
238 
239  for (unsigned int i=0; i != 5; ++i)
240  CPPUNIT_ASSERT_EQUAL( dof_id_type(i), aobject.get_extra_integer(i) );
241  }
242 
243 
245  {
246  DofObject aobject(*instance);
247 
248  aobject.set_n_systems (2);
249 
250  std::vector<unsigned int> nvpg;
251 
252  nvpg.push_back(2);
253  nvpg.push_back(3);
254 
255  aobject.set_n_vars_per_group (0, nvpg);
256  aobject.set_n_vars_per_group (1, nvpg);
257 
258  aobject.set_n_comp_group (0, 0, 1);
259  aobject.set_n_comp_group (0, 1, 3);
260 
261  aobject.set_n_comp_group (1, 0, 2);
262  aobject.set_n_comp_group (1, 1, 1);
263 
264  aobject.set_vg_dof_base(0, 0, 0);
265  aobject.set_vg_dof_base(0, 1, 120);
266 
267  aobject.set_vg_dof_base(1, 0, 20);
268  aobject.set_vg_dof_base(1, 1, 220);
269 
270  // Make sure the first dof is sane
271  CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(0), aobject.dof_number(0, 0, 0));
272 
273  // Check that we can manually index dofs of variables based on the first dof in a variable group
274  // Using: id = base + var_in_vg*ncomp + comp
275  CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(aobject.vg_dof_base(0, 0) + 1*1 + 0), aobject.dof_number(0, 1, 0));
276 
277  // Another Check that we can manually index dofs of variables based on the first dof in a variable group
278  // Using: id = base + var_in_vg*ncomp + comp
279  CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(aobject.vg_dof_base(0, 1) + 2*3 + 2), aobject.dof_number(0, 4, 2));
280 
281  // One More Check that we can manually index dofs of variables based on the first dof in a variable group
282  // Using: id = base + var_in_vg*ncomp + comp
283  CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(aobject.vg_dof_base(1, 1) + 0*3 + 0), aobject.dof_number(1, 2, 0));
284  }
285 
287  {
288  // For more information on this bug, see the following email thread:
289  // https://sourceforge.net/p/libmesh/mailman/libmesh-users/thread/50C8EE7C.8090405@gmail.com/
290  DofObject aobject(*instance);
291  dof_id_type buf0[] = {2, 8, 257, 0, 257, 96, 257, 192, 257, 0};
292  aobject.set_buffer(std::vector<dof_id_type>(buf0, buf0+10));
293 
294  CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,0,0), static_cast<dof_id_type>( 0));
295  CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,1,0), static_cast<dof_id_type>( 96));
296  CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,2,0), static_cast<dof_id_type>(192));
297  CPPUNIT_ASSERT_EQUAL (aobject.dof_number(1,0,0), static_cast<dof_id_type>( 0));
298 
299  dof_id_type buf1[] = {2, 8, 257, 1, 257, 97, 257, 193, 257, 1};
300  aobject.set_buffer(std::vector<dof_id_type>(buf1, buf1+10));
301 
302  CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,0,0), static_cast<dof_id_type>( 1));
303  CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,1,0), static_cast<dof_id_type>( 97));
304  CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,2,0), static_cast<dof_id_type>(193));
305  CPPUNIT_ASSERT_EQUAL (aobject.dof_number(1,0,0), static_cast<dof_id_type>( 1));
306  }
307 };
308 
309 #endif // #ifdef __dof_object_test_h__
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...
Definition: dof_object.h:1159
dof_id_type dof_number(const unsigned int s, const unsigned int var, const unsigned int comp) const
Definition: dof_object.h:927
void testInvalidateProcId()
unsigned int n_var_groups(const unsigned int s) const
Definition: dof_object.h:852
void testSetNVariableGroups()
void testInvalidateId()
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...
Definition: dof_object.h:1139
The libMesh namespace provides an interface to certain functionality in the library.
void testJensEftangBug()
uint8_t processor_id_type
Definition: id_types.h:104
dof_id_type & set_id()
Definition: dof_object.h:747
void set_buffer(const std::vector< dof_id_type > &buf)
Definition: dof_object.h:622
dof_id_type id() const
Definition: dof_object.h:738
void testSetNVariableGroupsExtraInts()
static const 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:404
unsigned int n_vars(const unsigned int s, const unsigned int vg) const
Definition: dof_object.h:862
void testSetProcId()
unsigned int n_systems() const
Definition: dof_object.h:832
bool valid_processor_id() const
Definition: dof_object.h:824
void invalidate_id()
Sets the id to invalid_id.
Definition: dof_object.h:682
static const dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
Definition: dof_object.h:393
bool has_extra_integers() const
Returns whether extra integers are associated to the DofObject.
Definition: dof_object.h:1030
void invalidate_processor_id()
Sets the processor id to invalid_processor_id.
Definition: dof_object.h:690
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...
void set_n_systems(const unsigned int s)
Sets the number of systems for this DofObject.
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.
bool valid_id() const
Definition: dof_object.h:780
processor_id_type global_processor_id()
Definition: libmesh_base.h:85
void testManualDofCalculation()
The DofObject defines an abstract base class for objects that have degrees of freedom associated with...
Definition: dof_object.h:51
void add_extra_integers(const unsigned int n_integers)
Assigns a set of extra integers to this DofObject.
unsigned int n_extra_integers() const
Returns how many extra integers are associated to the DofObject.
Definition: dof_object.h:1012
DerivedClass * instance
void testValidProcId()
void testSetNSystems()
processor_id_type processor_id() const
Definition: dof_object.h:800
void setUp(DerivedClass *derived_instance)
void testSetNSystemsExtraInts()
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...
Definition: dof_object.h:981
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...
Definition: dof_object.h:997
uint8_t dof_id_type
Definition: id_types.h:67
void testAddExtraInts()