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

Member Function Documentation

CouplingMatrixTest::CPPUNIT_TEST ( testSimpleAPI  )
CouplingMatrixTest::CPPUNIT_TEST ( testIteratorAPI  )
CouplingMatrixTest::CPPUNIT_TEST_SUITE ( CouplingMatrixTest  )
CouplingMatrixTest::CPPUNIT_TEST_SUITE_END ( )
void CouplingMatrixTest::setUp ( )

Definition at line 25 of file coupling_matrix_test.C.

25 {}
void CouplingMatrixTest::tearDown ( )

Definition at line 27 of file coupling_matrix_test.C.

27 {}
void CouplingMatrixTest::testIteratorAPI ( )
private

Definition at line 130 of file coupling_matrix_test.C.

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

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

Definition at line 39 of file coupling_matrix_test.C.

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

40  {
41  CouplingMatrix cm(2);
42 
43  // Use a constant reference to make sure we test both const and
44  // non-const operator() implementations
45  const CouplingMatrix& cmr = cm;
46 
47  cm(0,1) = 1;
48 
49  bool cm01 = cm(0,1);
50  CPPUNIT_ASSERT_EQUAL(cm01, true);
51 
52  cm(1,0) = 1;
53 
54  for (unsigned i=0; i<2; ++i)
55  for (unsigned j=0; j<2; ++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, (i != j));
61  }
62 
63  cm.resize(8);
64 
65  for (unsigned i=0; i<8; ++i)
66  for (unsigned j=0; j<8; ++j)
67  {
68  bool cmij = cm(i,j);
69  bool cmrij = cmr(i,j);
70  CPPUNIT_ASSERT_EQUAL(cmij, cmrij);
71  CPPUNIT_ASSERT_EQUAL(cmij, false);
72  }
73 
74  // Set some elements true, in a weird order.
75  for (unsigned i=6; i>0; --i)
76  {
77  const unsigned int pi = i + (i > 4);
78  for (unsigned j=0; j<6; ++j)
79  {
80  const unsigned int pj = j + (j > 3);
81  cm(pi, pj) = true;
82  }
83  }
84 
85  // Now the tensor product of {1,2,3,4,6,7} with {0,1,2,3,5,6}
86  // should be 1.
87  for (unsigned i=0; i<8; ++i)
88  for (unsigned j=0; j<8; ++j)
89  {
90  bool cmij = cm(i,j);
91  bool cmrij = cmr(i,j);
92  CPPUNIT_ASSERT_EQUAL(cmij, cmrij);
93  if ((i != 0) && (i != 5) && (j != 4) && (j != 7))
94  {
95  CPPUNIT_ASSERT_EQUAL(cmij, true);
96  }
97  else
98  {
99  CPPUNIT_ASSERT_EQUAL(cmij, false);
100  }
101  }
102 
103  // Set some elements to false.
104  for (unsigned k=0; k<8; ++k)
105  {
106  cm(3, k) = false;
107  cm(k, 0) = false;
108  }
109 
110  // Now the tensor product of {1,2,4,6,7} with {1,2,3,5,6}
111  // should be 1.
112  for (unsigned i=0; i<8; ++i)
113  for (unsigned j=0; j<8; ++j)
114  {
115  bool cmij = cm(i,j);
116  bool cmrij = cmr(i,j);
117  CPPUNIT_ASSERT_EQUAL(cmij, cmrij);
118  if ((i != 0) && (i != 3) && (i != 5) &&
119  (j != 0) && (j != 4) && (j != 7))
120  {
121  CPPUNIT_ASSERT_EQUAL(cmij, true);
122  }
123  else
124  {
125  CPPUNIT_ASSERT_EQUAL(cmij, false);
126  }
127  }
128  }
const Real pi
.
Definition: libmesh.h:172
This class defines a coupling matrix.

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