11 #include <fei_macros.hpp>
12 #include <fei_sstream.hpp>
14 #include <test_utils/test_FEI_Implementation.hpp>
16 #include <FEI_Implementation.hpp>
17 #ifdef HAVE_FEI_AZTECOO
18 #include <fei_Aztec_LinSysCore.hpp>
20 #include <test_utils/FEData.hpp>
21 #include <fei_LibraryWrapper.hpp>
23 #include <test_utils/testData.hpp>
25 #include <fei_Filter.hpp>
28 #define fei_file "test_FEI_Implementation.cpp"
29 #include <fei_ErrMacros.hpp>
31 test_FEI_Implementation::test_FEI_Implementation(MPI_Comm comm)
36 test_FEI_Implementation::~test_FEI_Implementation()
40 int test_FEI_Implementation::runtests()
43 CHK_ERR( serialtest1() );
53 int test_FEI_Implementation::serialtest1()
56 double** coefs =
new double*[n];
57 double** copy =
new double*[n];
58 double** correct =
new double*[n];
61 coefs[i] =
new double[n];
62 copy[i] =
new double[n];
63 correct[i] =
new double[n];
65 coefs[i][j] = (double)(i+j);
66 correct[i][j] = (double)(i+j);
70 Filter::copyStiffness(coefs, n, FEI_DENSE_ROW, copy);
71 CHK_ERR( compareCoefs(n, correct, copy) );
74 for(j=0; j<n; ++j) coefs[i][j] = 0.0;
76 coefs[i][j-i] = (double)(i+j);
80 Filter::copyStiffness(coefs, n, FEI_UPPER_SYMM_ROW, copy);
81 CHK_ERR( compareCoefs(n, correct, copy) );
84 for(j=0; j<n; ++j) coefs[i][j] = 0.0;
87 coefs[i][j] = (double)(i+j);
91 Filter::copyStiffness(coefs, n, FEI_LOWER_SYMM_ROW, copy);
92 CHK_ERR( compareCoefs(n, correct, copy) );
107 int test_FEI_Implementation::compareCoefs(
int n,
108 const double*
const* coefs1,
109 const double*
const* coefs2)
111 for(
int i=0; i<n; ++i) {
112 for(
int j=0; j<n; ++j) {
113 double diff = coefs1[i][j] - coefs2[i][j];
114 if (diff > 1.e-20 || diff < -1.e-20) {
123 int test_FEI_Implementation::test1()
125 #ifdef HAVE_FEI_AZTECOO
135 char** params =
new char*[numParams];
136 params[0] =
new char[128];
137 strcpy(params[0],
"name test1");
139 params[1] =
new char[32];
140 strcpy(params[1],
"debugOutput .");
143 FEI_OSTRINGSTREAM osstr;
144 osstr <<
"debugOutput " << path_;
145 std::string str = osstr.str();
147 params[1] =
new char[str.size()+1];
148 strcpy(params[1], str.c_str());
153 CHK_ERR( fei->parameters(1, ¶ms[0]) );
154 CHK_ERR( fei->parameters(1, ¶ms[1]) );
155 CHK_ERR( fei->parameters(2, params) );
161 CHK_ERR( fei->setIDLists(1, &(testdata->ids[0]),
162 1, &(testdata->ids[0])) );
164 CHK_ERR( fei->initFields(testdata->fieldIDs.size(),
165 &(testdata->fieldSizes[0]),
166 &(testdata->fieldIDs[0])) );
168 unsigned numNodesPerElem = testdata->ids.size();
169 std::vector<int> numFieldsPerNode(numNodesPerElem, 1);
170 std::vector<int*>nodalFieldIDs(numNodesPerElem, &(testdata->fieldIDs[0]));
172 CHK_ERR( fei->initElemBlock(0,
175 &numFieldsPerNode[0],
181 CHK_ERR( fei->initElem(0,
183 &(testdata->ids[0])) );
185 std::vector<int*> sharingProcs2D(testdata->sharedIDs.size());
187 for(
unsigned i=0; i<testdata->numSharingProcsPerID.size(); ++i) {
188 sharingProcs2D[i] = &(testdata->sharingProcs[offset]);
189 offset += testdata->numSharingProcsPerID[i];
192 if (testdata->sharedIDs.size() > 0) {
193 CHK_ERR( fei->initSharedNodes(testdata->sharedIDs.size(),
194 testdata->sharedIDs.size() ? &(testdata->sharedIDs[0]) : 0,
195 testdata->numSharingProcsPerID.size() ? &(testdata->numSharingProcsPerID[0]) : 0,
196 &sharingProcs2D[0]) );
199 CHK_ERR( fei->initComplete() );
201 std::vector<double> rhsData(testdata->ids.size(), 1.0);
204 CHK_ERR( fei->setMatScalars(1, &(testdata->ids[0]), &one) );
205 CHK_ERR( fei->setRHSScalars(1, &(testdata->ids[0]), &one) );
207 CHK_ERR( fei->setCurrentMatrix(testdata->ids[0]) );
208 CHK_ERR( fei->setCurrentRHS(testdata->ids[0]) );
210 CHK_ERR( fei->putIntoRHS(FEI_NODE, testdata->fieldIDs[0],
211 testdata->ids.size(),
216 GlobalID* BCNodeIDs = &(testdata->ids[0]);
217 int BCFieldID = testdata->fieldIDs[0];
218 double* values =
new double[numBCNodes];
219 int* offsetsIntoField =
new int[numBCNodes];
220 for(
int ii=0; ii<numBCNodes; ++ii) {
222 offsetsIntoField[ii] = 0;
225 CHK_ERR( fei->loadNodeBCs(numBCNodes, BCNodeIDs, BCFieldID,
226 offsetsIntoField, values) );
228 delete [] offsetsIntoField;
231 CHK_ERR( fei->loadComplete() );
233 int numActiveNodes = 0;
234 CHK_ERR( fei->getNumLocalNodes(numActiveNodes) );
235 if (numActiveNodes != (
int)testdata->ids.size()) {
239 GlobalID* localNodes =
new GlobalID[numActiveNodes];
240 CHK_ERR( fei->getLocalNodeIDList(numActiveNodes, localNodes, numActiveNodes) );
242 int totalFieldSize = 0;
243 for(
int ii=0; ii<(int)testdata->fieldSizes.size(); ++ii) {
244 totalFieldSize += testdata->fieldSizes[ii];
247 double* soln =
new double[numActiveNodes*totalFieldSize];
248 int* offsets =
new int[numActiveNodes+1];
250 CHK_ERR( fei->getNodalSolution(numActiveNodes, localNodes,
254 delete [] localNodes;
256 CHK_ERR( fei->resetInitialGuess() );
259 CHK_ERR( fei->getFieldSize(testdata->fieldIDs[0], fieldSize) );
261 double initTime, loadTime, solveTime, solnReturnTime;
262 CHK_ERR( fei->cumulative_cpu_times(initTime, loadTime, solveTime,
268 int test_FEI_Implementation::test2()
278 char** params =
new char*[numParams];
279 params[0] =
new char[128];
280 strcpy(params[0],
"name test1");
282 params[1] =
new char[32];
283 strcpy(params[1],
"debugOutput .");
286 FEI_OSTRINGSTREAM osstr;
287 osstr <<
"debugOutput " << path_;
288 std::string str = osstr.str();
290 params[1] =
new char[str.size()+1];
291 strcpy(params[1], str.c_str());
297 CHK_ERR( fei->parameters(1, ¶ms[0]) );
298 CHK_ERR( fei->parameters(1, ¶ms[1]) );
299 CHK_ERR( fei->parameters(2, params) );
305 CHK_ERR( fei->setIDLists(1, &(testdata->ids[0]),
306 1, &(testdata->ids[0])) );
308 CHK_ERR( fei->initFields(testdata->fieldIDs.size(),
309 &(testdata->fieldSizes[0]),
310 &(testdata->fieldIDs[0])) );
312 unsigned numNodesPerElem = testdata->ids.size();
313 std::vector<int> numFieldsPerNode(numNodesPerElem, 1);
314 std::vector<int*>nodalFieldIDs(numNodesPerElem, &(testdata->fieldIDs[0]));
316 CHK_ERR( fei->initElemBlock(0,
319 &numFieldsPerNode[0],
325 CHK_ERR( fei->initElem(0,
327 &(testdata->ids[0])) );
329 std::vector<int*> sharingProcs2D(testdata->sharedIDs.size());
331 for(
unsigned i=0; i<testdata->numSharingProcsPerID.size(); ++i) {
332 sharingProcs2D[i] = &(testdata->sharingProcs[offset]);
333 offset += testdata->numSharingProcsPerID[i];
336 if (testdata->sharedIDs.size() > 0) {
337 CHK_ERR( fei->initSharedNodes(testdata->sharedIDs.size(),
338 testdata->sharedIDs.size() ? &(testdata->sharedIDs[0]) : 0,
339 testdata->numSharingProcsPerID.size() ? &(testdata->numSharingProcsPerID[0]) : 0,
340 &sharingProcs2D[0]) );
343 CHK_ERR( fei->initComplete() );
345 int numBlkActNodes = 0;
346 CHK_ERR( fei->getNumBlockActNodes(0, numBlkActNodes) );
348 std::vector<double> rhsData(testdata->ids.size(), 1.0);
351 CHK_ERR( fei->setMatScalars(1, &(testdata->ids[0]), &one) );
352 CHK_ERR( fei->setRHSScalars(1, &(testdata->ids[0]), &one) );
354 CHK_ERR( fei->setCurrentMatrix(testdata->ids[0]) );
355 CHK_ERR( fei->setCurrentRHS(testdata->ids[0]) );
357 CHK_ERR( fei->putIntoRHS(FEI_NODE, testdata->fieldIDs[0],
358 testdata->ids.size(),
363 GlobalID* BCNodeIDs = &(testdata->ids[0]);
364 int BCFieldID = testdata->fieldIDs[0];
365 double* values =
new double[numBCNodes];
366 int* offsetsIntoField =
new int[numBCNodes];
367 for(
int ii=0; ii<numBCNodes; ++ii) {
369 offsetsIntoField[ii] = 0;
372 CHK_ERR( fei->loadNodeBCs(numBCNodes, BCNodeIDs, BCFieldID,
373 offsetsIntoField, values) );
375 delete [] offsetsIntoField;
378 CHK_ERR( fei->loadComplete() );
380 int numActiveNodes = 0;
381 CHK_ERR( fei->getNumLocalNodes(numActiveNodes) );
382 if (numActiveNodes != (
int)testdata->ids.size()) {
386 GlobalID* localNodes =
new GlobalID[numActiveNodes];
387 CHK_ERR( fei->getLocalNodeIDList(numActiveNodes, localNodes, numActiveNodes) );
389 int totalFieldSize = 0;
390 for(
int ii=0; ii<(int)testdata->fieldSizes.size(); ++ii) {
391 totalFieldSize += testdata->fieldSizes[ii];
394 double* soln =
new double[numActiveNodes*totalFieldSize];
395 int* offsets =
new int[numActiveNodes+1];
397 CHK_ERR( fei->getNodalSolution(numActiveNodes, localNodes,
401 delete [] localNodes;
403 CHK_ERR( fei->resetInitialGuess() );
406 CHK_ERR( fei->getFieldSize(testdata->fieldIDs[0], fieldSize) );
408 double initTime, loadTime, solveTime, solnReturnTime;
409 CHK_ERR( fei->cumulative_cpu_times(initTime, loadTime, solveTime,
415 int test_FEI_Implementation::test3()
420 int test_FEI_Implementation::test4()