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( testManualDofCalculation ); \
17  CPPUNIT_TEST( testJensEftangBug );
18 
19 using namespace libMesh;
20 
21 template <class DerivedClass>
23 
24 private:
25  DerivedClass * instance;
26 
27 public:
28  void setUp(DerivedClass * derived_instance)
29  {
30  instance=derived_instance;
31  }
32 
33  void testSetId()
34  {
35  DofObject aobject(*instance);
36 
37  aobject.set_id(1);
38  CPPUNIT_ASSERT_EQUAL( static_cast<dof_id_type>(1) , aobject.id() );
39  }
40 
41  void testValidId()
42  {
43  DofObject aobject(*instance);
44 
45  aobject.set_id(1);
46  CPPUNIT_ASSERT( aobject.valid_id() );
47 
49  CPPUNIT_ASSERT( !aobject.valid_id() );
50  }
51 
53  {
54  DofObject aobject(*instance);
55 
56  aobject.set_id(1);
57  aobject.invalidate_id();
58 
59  CPPUNIT_ASSERT( !aobject.valid_id() );
60  }
61 
63  {
64  DofObject aobject(*instance);
65 
67  CPPUNIT_ASSERT_EQUAL( (processor_id_type)libMesh::global_processor_id() , aobject.processor_id() );
68  }
69 
71  {
72  DofObject aobject(*instance);
73 
75  CPPUNIT_ASSERT(aobject.valid_processor_id());
76 
78  CPPUNIT_ASSERT(!aobject.valid_processor_id());
79  }
80 
82  {
83  DofObject aobject(*instance);
84 
86  aobject.invalidate_processor_id();
87 
88  CPPUNIT_ASSERT( !aobject.valid_processor_id() );
89  }
90 
92  {
93  DofObject aobject(*instance);
94 
95  aobject.set_n_systems (10);
96 
97  CPPUNIT_ASSERT_EQUAL( (unsigned int) 10, aobject.n_systems() );
98  }
99 
101  {
102  DofObject aobject(*instance);
103 
104  aobject.set_n_systems (2);
105 
106  std::vector<unsigned int> nvpg;
107 
108  nvpg.push_back(10);
109  nvpg.push_back(20);
110  nvpg.push_back(30);
111 
112  aobject.set_n_vars_per_group (0, nvpg);
113  aobject.set_n_vars_per_group (1, nvpg);
114 
115  for (unsigned int s=0; s<2; s++)
116  {
117  CPPUNIT_ASSERT_EQUAL( (unsigned int) 60, aobject.n_vars(s) );
118  CPPUNIT_ASSERT_EQUAL( (unsigned int) 3, aobject.n_var_groups(s) );
119 
120  for (unsigned int vg=0; vg<3; vg++)
121  CPPUNIT_ASSERT_EQUAL( nvpg[vg], aobject.n_vars(s,vg) );
122  }
123  }
124 
126  {
127  DofObject aobject(*instance);
128 
129  aobject.set_n_systems (2);
130 
131  std::vector<unsigned int> nvpg;
132 
133  nvpg.push_back(2);
134  nvpg.push_back(3);
135 
136  aobject.set_n_vars_per_group (0, nvpg);
137  aobject.set_n_vars_per_group (1, nvpg);
138 
139  aobject.set_n_comp_group (0, 0, 1);
140  aobject.set_n_comp_group (0, 1, 3);
141 
142  aobject.set_n_comp_group (1, 0, 2);
143  aobject.set_n_comp_group (1, 1, 1);
144 
145  aobject.set_vg_dof_base(0, 0, 0);
146  aobject.set_vg_dof_base(0, 1, 120);
147 
148  aobject.set_vg_dof_base(1, 0, 20);
149  aobject.set_vg_dof_base(1, 1, 220);
150 
151  // Make sure the first dof is sane
152  CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(0), aobject.dof_number(0, 0, 0));
153 
154  // Check that we can manually index dofs of variables based on the first dof in a variable group
155  // Using: id = base + var_in_vg*ncomp + comp
156  CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(aobject.vg_dof_base(0, 0) + 1*1 + 0), aobject.dof_number(0, 1, 0));
157 
158  // Another Check that we can manually index dofs of variables based on the first dof in a variable group
159  // Using: id = base + var_in_vg*ncomp + comp
160  CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(aobject.vg_dof_base(0, 1) + 2*3 + 2), aobject.dof_number(0, 4, 2));
161 
162  // One More Check that we can manually index dofs of variables based on the first dof in a variable group
163  // Using: id = base + var_in_vg*ncomp + comp
164  CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(aobject.vg_dof_base(1, 1) + 0*3 + 0), aobject.dof_number(1, 2, 0));
165  }
166 
168  {
169  // For more information on this bug, see the following email thread:
170  // https://sourceforge.net/p/libmesh/mailman/libmesh-users/thread/50C8EE7C.8090405@gmail.com/
171  DofObject aobject(*instance);
172  dof_id_type buf0[] = {2, 8, 257, 0, 257, 96, 257, 192, 257, 0};
173  aobject.set_buffer(std::vector<dof_id_type>(buf0, buf0+10));
174 
175  CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,0,0), static_cast<dof_id_type>( 0));
176  CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,1,0), static_cast<dof_id_type>( 96));
177  CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,2,0), static_cast<dof_id_type>(192));
178  CPPUNIT_ASSERT_EQUAL (aobject.dof_number(1,0,0), static_cast<dof_id_type>( 0));
179 
180  dof_id_type buf1[] = {2, 8, 257, 1, 257, 97, 257, 193, 257, 1};
181  aobject.set_buffer(std::vector<dof_id_type>(buf1, buf1+10));
182 
183  CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,0,0), static_cast<dof_id_type>( 1));
184  CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,1,0), static_cast<dof_id_type>( 97));
185  CPPUNIT_ASSERT_EQUAL (aobject.dof_number(0,2,0), static_cast<dof_id_type>(193));
186  CPPUNIT_ASSERT_EQUAL (aobject.dof_number(1,0,0), static_cast<dof_id_type>( 1));
187  }
188 };
189 
190 #endif // #ifdef __dof_object_test_h__
bool valid_id() const
Definition: dof_object.h:674
void testInvalidateProcId()
unsigned int n_vars(const unsigned int s, const unsigned int vg) const
Definition: dof_object.h:745
void testSetNVariableGroups()
uint8_t processor_id_type
Definition: id_types.h:99
dof_id_type dof_number(const unsigned int s, const unsigned int var, const unsigned int comp) const
Definition: dof_object.h:810
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:902
The libMesh namespace provides an interface to certain functionality in the library.
void testJensEftangBug()
dof_id_type & set_id()
Definition: dof_object.h:641
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:922
bool valid_processor_id() const
Definition: dof_object.h:718
void set_buffer(const std::vector< dof_id_type > &buf)
Definition: dof_object.h:512
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:335
unsigned int n_var_groups(const unsigned int s) const
Definition: dof_object.h:735
void testSetProcId()
void invalidate_id()
Sets the id to invalid_id.
Definition: dof_object.h:572
static const dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
Definition: dof_object.h:324
void invalidate_processor_id()
Sets the processor id to invalid_processor_id.
Definition: dof_object.h:580
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:357
void set_n_systems(const unsigned int s)
Sets the number of systems for this DofObject.
Definition: dof_object.C:165
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:227
processor_id_type global_processor_id()
Definition: libmesh_base.h:114
void testManualDofCalculation()
The DofObject defines an abstract base class for objects that have degrees of freedom associated with...
Definition: dof_object.h:51
DerivedClass * instance
dof_id_type id() const
Definition: dof_object.h:632
unsigned int n_systems() const
Definition: dof_object.h:726
void testValidProcId()
void testSetNSystems()
void setUp(DerivedClass *derived_instance)
uint8_t dof_id_type
Definition: id_types.h:64
processor_id_type processor_id() const
Definition: dof_object.h:694