libMesh
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 ()
 
 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()

CouplingMatrixTest::CPPUNIT_TEST_SUITE ( CouplingMatrixTest  )

◆ CPPUNIT_TEST_SUITE_END()

CouplingMatrixTest::CPPUNIT_TEST_SUITE_END ( )

◆ 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 117 of file coupling_matrix_test.C.

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

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

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


The documentation for this class was generated from the following file:
libMesh::pi
const Real pi
.
Definition: libmesh.h:237
libMesh::ConstCouplingRowConstIterator
Definition: coupling_matrix.h:458
libMesh::ConstCouplingRow
This proxy class acts like a container of indices from a single coupling row.
Definition: coupling_matrix.h:337
libMesh::CouplingMatrix
This class defines a coupling matrix.
Definition: coupling_matrix.h:54
int
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360