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

Public Member Functions

void setUp ()
 
void tearDown ()
 
 LIBMESH_CPPUNIT_TEST_SUITE (CouplingMatrixTest)
 
 CPPUNIT_TEST (testSimpleAPI)
 
 CPPUNIT_TEST (testIteratorAPI)
 
 CPPUNIT_TEST_SUITE_END ()
 

Private Member Functions

void testSimpleAPI ()
 
void testIteratorAPI ()
 

Detailed Description

Definition at line 9 of file coupling_matrix_test.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/2]

CouplingMatrixTest::CPPUNIT_TEST ( testIteratorAPI  )

◆ CPPUNIT_TEST() [2/2]

CouplingMatrixTest::CPPUNIT_TEST ( testSimpleAPI  )

◆ CPPUNIT_TEST_SUITE_END()

CouplingMatrixTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

CouplingMatrixTest::LIBMESH_CPPUNIT_TEST_SUITE ( CouplingMatrixTest  )

◆ setUp()

void CouplingMatrixTest::setUp ( )
inline

Definition at line 12 of file coupling_matrix_test.C.

12{}

◆ tearDown()

void CouplingMatrixTest::tearDown ( )
inline

Definition at line 14 of file coupling_matrix_test.C.

14{}

◆ testIteratorAPI()

void CouplingMatrixTest::testIteratorAPI ( )
inlineprivate

Definition at line 119 of file coupling_matrix_test.C.

120 {
121 LOG_UNIT_TEST;
122
123 CouplingMatrix cm(8);
124
125 // Set some elements true, in a weird order.
126 for (unsigned i=6; i>0; --i)
127 {
128 const unsigned int pi = i + (i > 4);
129 for (unsigned j=0; j<6; ++j)
130 {
131 const unsigned int pj = j + (j > 3);
132 cm(pi, pj) = true;
133 }
134 }
135
136 // Now the tensor product of {1,2,3,4,6,7} with {0,1,2,3,5,6}
137 // should be 1.
138
139 // Set some elements to false.
140 for (unsigned k=0; k<8; ++k)
141 {
142 cm(3, k) = false;
143 cm(k, 0) = false;
144 }
145
146 // Now the tensor product of {1,2,4,6,7} with {1,2,3,5,6}
147 // should be 1.
148 const unsigned int ivals[] = {1,2,4,6,7};
149 const unsigned int non_ivals[] = {0,3,5};
150 const unsigned int jvals[] = {1,2,3,5,6};
151 // const unsigned int non_jvals[] = {0,4,7};
152
153 const unsigned int isize = sizeof(unsigned int);
154
155 for (unsigned int pi = 0; pi != sizeof(non_ivals)/isize; ++pi)
156 {
157 unsigned int i = non_ivals[pi];
158 ConstCouplingRow ccr(i,cm);
159 CPPUNIT_ASSERT(ccr.begin() == ccr.end());
160 }
161
162 for (unsigned int pi = 0; pi != sizeof(ivals)/isize; ++pi)
163 {
164 unsigned int i = ivals[pi];
165 ConstCouplingRow ccr(i,cm);
166
167 ConstCouplingRow::const_iterator ccr_it = ccr.begin();
168
169 for (unsigned int pj = 0; pj != sizeof(jvals)/isize; ++pj)
170 {
171 CPPUNIT_ASSERT(ccr_it != ccr.end());
172 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(*ccr_it), jvals[pj]);
173 ++ccr_it;
174 }
175
176 CPPUNIT_ASSERT(ccr_it == ccr.end());
177 }
178 }
void ErrorVector unsigned int
This proxy class acts like a container of indices from a single coupling row.
This class defines a coupling matrix.
const Real pi
.
Definition libmesh.h:292

References libMesh::ConstCouplingRow::begin(), libMesh::ConstCouplingRow::end(), int, and libMesh::pi.

◆ testSimpleAPI()

void CouplingMatrixTest::testSimpleAPI ( )
inlineprivate

Definition at line 26 of file coupling_matrix_test.C.

27 {
28 LOG_UNIT_TEST;
29
30 CouplingMatrix cm(2);
31
32 // Use a constant reference to make sure we test both const and
33 // non-const operator() implementations
34 const CouplingMatrix& cmr = cm;
35
36 cm(0,1) = 1;
37
38 bool cm01 = cm(0,1);
39 CPPUNIT_ASSERT_EQUAL(cm01, true);
40
41 cm(1,0) = 1;
42
43 for (unsigned i=0; i<2; ++i)
44 for (unsigned j=0; j<2; ++j)
45 {
46 bool cmij = cm(i,j);
47 bool cmrij = cmr(i,j);
48 CPPUNIT_ASSERT_EQUAL(cmij, cmrij);
49 CPPUNIT_ASSERT_EQUAL(cmij, (i != j));
50 }
51
52 cm.resize(8);
53
54 for (unsigned i=0; i<8; ++i)
55 for (unsigned j=0; j<8; ++j)
56 {
57 bool cmij = cm(i,j);
58 bool cmrij = cmr(i,j);
59 CPPUNIT_ASSERT_EQUAL(cmij, cmrij);
60 CPPUNIT_ASSERT_EQUAL(cmij, false);
61 }
62
63 // Set some elements true, in a weird order.
64 for (unsigned i=6; i>0; --i)
65 {
66 const unsigned int pi = i + (i > 4);
67 for (unsigned j=0; j<6; ++j)
68 {
69 const unsigned int pj = j + (j > 3);
70 cm(pi, pj) = true;
71 }
72 }
73
74 // Now the tensor product of {1,2,3,4,6,7} with {0,1,2,3,5,6}
75 // should be 1.
76 for (unsigned i=0; i<8; ++i)
77 for (unsigned j=0; j<8; ++j)
78 {
79 bool cmij = cm(i,j);
80 bool cmrij = cmr(i,j);
81 CPPUNIT_ASSERT_EQUAL(cmij, cmrij);
82 if ((i != 0) && (i != 5) && (j != 4) && (j != 7))
83 {
84 CPPUNIT_ASSERT_EQUAL(cmij, true);
85 }
86 else
87 {
88 CPPUNIT_ASSERT_EQUAL(cmij, false);
89 }
90 }
91
92 // Set some elements to false.
93 for (unsigned k=0; k<8; ++k)
94 {
95 cm(3, k) = false;
96 cm(k, 0) = false;
97 }
98
99 // Now the tensor product of {1,2,4,6,7} with {1,2,3,5,6}
100 // should be 1.
101 for (unsigned i=0; i<8; ++i)
102 for (unsigned j=0; j<8; ++j)
103 {
104 bool cmij = cm(i,j);
105 bool cmrij = cmr(i,j);
106 CPPUNIT_ASSERT_EQUAL(cmij, cmrij);
107 if ((i != 0) && (i != 3) && (i != 5) &&
108 (j != 0) && (j != 4) && (j != 7))
109 {
110 CPPUNIT_ASSERT_EQUAL(cmij, true);
111 }
112 else
113 {
114 CPPUNIT_ASSERT_EQUAL(cmij, false);
115 }
116 }
117 }

References libMesh::pi, and libMesh::CouplingMatrix::resize().


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