9 #include <fei_macros.hpp>
11 #include <test_utils/test_EqnBuffer.hpp>
13 #include <fei_CSVec.hpp>
14 #include <fei_EqnBuffer.hpp>
17 #define fei_file "test_EqnBuffer.cpp"
18 #include <fei_ErrMacros.hpp>
20 test_EqnBuffer::test_EqnBuffer(MPI_Comm comm)
25 test_EqnBuffer::~test_EqnBuffer()
29 int test_EqnBuffer::runtests()
38 int test_EqnBuffer::test1()
40 FEI_COUT <<
"testing EqnBuffer...";
44 std::vector<double> eqnCoefs(3);
45 std::vector<int> colIndices(3);
47 eqnCoefs[0] = 0.5; colIndices[0] = 2;
48 eqnCoefs[1] = 0.5; colIndices[1] = 4;
49 eqnCoefs[2] = 0.5; colIndices[2] = 6;
51 CHK_ERR( eqns.
addIndices(1, &colIndices[0], eqnCoefs.size()) );
53 CHK_ERR( eqns.
addEqn(1, &eqnCoefs[0], &colIndices[0],
54 eqnCoefs.size(),
false) );
56 eqnCoefs[0] = 0.5; colIndices[0] = 1;
57 eqnCoefs[1] = 0.5; colIndices[1] = 3;
58 eqnCoefs[2] = 0.5; colIndices[2] = 5;
60 CHK_ERR( eqns.
addEqn(7, &eqnCoefs[0], &colIndices[0],
61 eqnCoefs.size(),
true) );
63 eqnCoefs[0] = 0.25; colIndices[0] = 2;
64 eqnCoefs[1] = 0.25; colIndices[1] = 3;
65 eqnCoefs[2] = 0.5; colIndices[2] = 6;
67 CHK_ERR( eqns.
addEqn(8, &eqnCoefs[0], &colIndices[0],
68 eqnCoefs.size(),
false) );
73 CHK_ERR( eqns.
getCoef(7, 3, coef) );
74 if (std::abs(coef - 0.5) > 1.e-49) ERReturn(-1);
77 int err = eqns.
getCoef(7, 3, coef);
78 if (err != -1) ERReturn(-1);
81 if (std::abs(coef - 0.5) > 1.e-49) ERReturn(-1);
84 if (err != -1) ERReturn(-1);
87 std::vector<int>& eqnNumbers = eqns.
eqnNumbers();
88 std::vector<fei::CSVec*>& rows = eqns.
eqns();
92 std::vector<int>& eqnNumbersCopy = eqnsCopy->
eqnNumbers();
94 if (eqnNumbersCopy != eqnNumbers) {
98 CHK_ERR( eqnsCopy->
addRHS(1, 0, 1.0,
true) );
99 CHK_ERR( eqnsCopy->
addEqns(eqns,
true) );
101 std::vector<double> tempCoefs;
102 std::vector<int> tempIndices;
104 int levelsOfCoupling = 0;
105 bool finished =
false;
107 bool foundCoupling =
false;
108 for(
size_t i=0; i<eqnNumbers.size(); i++) {
111 while(rowIndex >= 0) {
112 foundCoupling =
true;
117 std::vector<int>& indicesRef = rows[i]->indices();
118 std::vector<double>& coefsRef = rows[i]->coefs();
120 int len = indicesRef.size();
121 tempCoefs.resize(len);
122 tempIndices.resize(len);
124 double* tempCoefsPtr = &tempCoefs[0];
125 int* tempIndicesPtr = &tempIndices[0];
126 double* coefsPtr = &coefsRef[0];
127 int* indicesPtr = &indicesRef[0];
129 for(
int j=0; j<len; ++j) {
130 tempIndicesPtr[j] = indicesPtr[j];
131 tempCoefsPtr[j] = coef*coefsPtr[j];
134 CHK_ERR( eqns.
addEqn(eqnNumbers[rowIndex], tempCoefsPtr, tempIndicesPtr,
140 if (foundCoupling) ++levelsOfCoupling;
141 else finished =
true;
144 if (levelsOfCoupling != 1) {
152 FEI_COUT <<
"ok"<<FEI_ENDL;
157 int test_EqnBuffer::test2()
163 int test_EqnBuffer::test3()
168 int test_EqnBuffer::test4()
int addEqn(int eqnNumber, const double *coefs, const int *indices, int len, bool accumulate, bool create_indices_union=false)
std::vector< fei::CSVec * > & eqns()
std::vector< int > & eqnNumbers()
int addRHS(int eqnNumber, int rhsIndex, double value, bool accumulate=true)
int getCoefAndRemoveIndex(int eqnNumber, int colIndex, double &coef)
int addEqns(EqnBuffer &inputEqns, bool accumulate)
int addIndices(int eqnNumber, const int *indices, int len)
int removeIndex(int eqnNumber, int colIndex)
int getCoef(int eqnNumber, int colIndex, double &coef)