9 #include <fei_sstream.hpp>
10 #include <fei_fstream.hpp>
12 #include <test_utils/fei_test_utils.hpp>
14 #include <test_utils/FEI_tester.hpp>
16 #include <fei_LinearSystemCore.hpp>
17 #include <fei_LibraryWrapper.hpp>
18 #include <snl_fei_Utils.hpp>
20 #include <fei_FEI_Impl.hpp>
22 #include <test_utils/LibraryFactory.hpp>
25 #include <FETI_DP_FiniteElementData.h>
28 #include <test_utils/DataReader.hpp>
29 #include <test_utils/SolnCheck.hpp>
32 #define fei_file "FEI_tester.cpp"
34 #include <fei_ErrMacros.hpp>
38 MPI_Comm comm,
int localProc,
int numProcs,
bool useNewFEI)
43 localProc_(localProc),
54 FEI_tester::~FEI_tester()
61 int FEI_tester::testInitialization()
63 if (data_.get() == NULL) {
67 CHK_ERR( createFEIinstance(data_->solverLibraryName_.c_str()) );
69 const char* feiVersionString;
70 CHK_ERR( fei_->version(feiVersionString) );
72 FEI_COUT <<
"FEI version: " << feiVersionString << FEI_ENDL;
74 fei_->parameters(data_->numParams_, data_->paramStrings_);
82 if (data_->solveType_ == FEI_AGGREGATE_SUM) {
83 CHK_ERR( setIDlists());
86 CHK_ERR( initializationPhase() );
89 for(
int i=0; i<data_->numElemBlocks_; ++i) {
90 ElemBlock& eblk = data_->elemBlocks_[i];
91 int elemBlockID = eblk.blockID_;
92 CHK_ERR( fei_->getNumBlockActNodes(elemBlockID, numBlkActNodes) );
101 int FEI_tester::testLoading()
103 CHK_ERR(fei_->resetRHSVector());
104 CHK_ERR(fei_->resetMatrix());
105 CHK_ERR(fei_->resetSystem());
112 if (data_->solveType_ == FEI_SINGLE_SYSTEM) {
113 CHK_ERR( normalLoadPhase());
115 if (data_->solveType_ == FEI_AGGREGATE_SUM) {
116 CHK_ERR( aggregateLoadPhase());
119 CHK_ERR( fei_->loadComplete() );
121 CHK_ERR( exerciseResidualNorm() );
124 CHK_ERR( exercisePutFunctions() );
130 int FEI_tester::testSolve()
134 std::string sname(data_->solverLibraryName_);
135 if (sname ==
"TEST_LSC") {
140 int err = fei_->solve(status);
144 if (err != 0 || status != 0) {
145 FEI_COUT <<
"!!!! solve returned: err: "<<err<<
", status: "<<status<<FEI_ENDL;
149 if (localProc_ == 0) {
151 CHK_ERR( fei_->iterations(itersTaken));
155 CHK_ERR( exerciseResidualNorm() );
161 void FEI_tester::dumpMatrixFiles()
166 void FEI_tester::setParameter(
const char*)
171 int FEI_tester::testCheckResult()
175 std::string sname(data_->solverLibraryName_);
176 if (sname ==
"TEST_LSC") {
177 return( lsc_matrix_check() );
180 CHK_ERR( save_block_node_soln(*data_, *fei_, data_->solnFileName_.c_str(),
181 numProcs_, localProc_, 1));
183 CHK_ERR( save_block_elem_soln(*data_, *fei_, data_->solnFileName_.c_str(),
184 numProcs_, localProc_, 1));
186 CHK_ERR( save_multiplier_soln(*data_, *fei_, data_->solnFileName_.c_str(),
187 numProcs_, localProc_, 1));
189 int err = SolnCheck::checkSolution(localProc_, numProcs_, data_->solnFileName_.c_str(),
190 data_->checkFileName_.c_str(),
"node", 1);
192 err += SolnCheck::checkSolution(localProc_, numProcs_, data_->solnFileName_.c_str(),
193 data_->checkFileName_.c_str(),
"elem", 1);
195 err += SolnCheck::checkSolution(localProc_, numProcs_, data_->solnFileName_.c_str(),
196 data_->checkFileName_.c_str(),
"mult", 1);
199 if (MPI_SUCCESS != MPI_Allreduce(&err, &globalErr, 1, MPI_INT, MPI_SUM,
202 if (globalErr != 0) {
210 int FEI_tester::createFEIinstance(
const char* solverName)
215 catch(std::runtime_error& exc) {
220 if (wrapper_.get() == NULL) ERReturn(-1);
229 if (fei_.get() == NULL) ERReturn(-1);
235 int FEI_tester::setIDlists()
237 snl_fei::getIntParamValue(
"numMatrices",
239 data_->paramStrings_,
242 matrixIDs =
new int[numMatrices];
247 for(
int i=0; i<numMatrices; i++) {
251 CHK_ERR(fei_->setIDLists(numMatrices, matrixIDs, numRHSs, rhsIDs));
256 int FEI_tester::initializationPhase()
258 if (data_->solveType_ != FEI_SINGLE_SYSTEM &&
259 data_->solveType_ != FEI_AGGREGATE_SUM) {
260 FEI_COUT <<
"FEI_tester: bad solveType: " << data_->solveType_ << FEI_ENDL;
264 CHK_ERR( fei_->setSolveType(data_->solveType_));
266 CHK_ERR(fei_->initFields(data_->numFields_, data_->fieldSizes_, data_->fieldIDs_));
269 for(i=0; i<data_->numElemBlocks_; i++) {
270 ElemBlock& block = data_->elemBlocks_[i];
272 CHK_ERR(fei_->initElemBlock(block.blockID_,
274 block.numNodesPerElement_,
275 block.numFieldsPerNode_,
276 block.nodalFieldIDs_,
278 block.elemDOFFieldIDs_,
279 block.interleaveStrategy_) );
281 for(
int el=0; el<block.numElements_; el++) {
282 CHK_ERR(fei_->initElem(block.blockID_,
284 block.elemConn_[el]));
288 for(i=0; i<data_->numSharedNodeSets_; i++) {
289 CommNodeSet& shNodeSet = data_->sharedNodeSets_[i];
291 CHK_ERR(fei_->initSharedNodes(shNodeSet.numNodes_, shNodeSet.nodeIDs_,
292 shNodeSet.procsPerNode_, shNodeSet.procs_));
297 for(i=0; i<data_->numSlaveVars_; i++) {
298 CRSet& crSet = data_->slaveVars_[i];
312 for(i=0; i<data_->numCRMultSets_; i++) {
313 CRSet& crSet = data_->crMultSets_[i];
315 for(
int j=0; j<1; j++) {
316 CHK_ERR(fei_->initCRMult(crSet.
numNodes_,
323 for(i=0; i<data_->numCRPenSets_; i++) {
324 CRSet& crSet = data_->crPenSets_[i];
326 for(
int j=0; j<1; j++) {
334 CHK_ERR(fei_->initComplete());
339 int FEI_tester::normalLoadPhase()
345 for(i=0; i<data_->numBCNodeSets_; i++) {
346 BCNodeSet& bcSet = data_->bcNodeSets_[i];
348 CHK_ERR(fei_->loadNodeBCs(bcSet.numNodes_,
351 bcSet.offsetsIntoField_,
352 bcSet.prescribed_values_));
355 for(i=0; i<data_->numElemBlocks_; i++) {
356 ElemBlock& block = data_->elemBlocks_[i];
358 for(
int el=0; el<block.numElements_; el++) {
360 CHK_ERR(fei_->sumInElemMatrix(block.blockID_,
363 block.elemStiff_[el],
368 for(i=0; i<data_->numElemBlocks_; i++) {
369 ElemBlock& block = data_->elemBlocks_[i];
371 for(
int el=0; el<block.numElements_; el++) {
373 CHK_ERR(fei_->sumInElemRHS(block.blockID_,
376 block.elemLoad_[el]));
382 for(i=0; i<data_->numCRMultSets_; i++) {
383 CRSet& crSet = data_->crMultSets_[i];
385 for(
int j=0; j<1; j++) {
386 CHK_ERR(fei_->loadCRMult(crSet.
crID_,
395 for(i=0; i<data_->numCRPenSets_; i++) {
396 CRSet& crSet = data_->crPenSets_[i];
398 for(
int j=0; j<1; j++) {
399 CHK_ERR(fei_->loadCRPen(crSet.
crID_,
405 crSet.penValues_[j]))
412 int FEI_tester::aggregateLoadPhase()
416 for(i=0; i<numMatrices; i++) {
417 CHK_ERR(fei_->setCurrentMatrix(matrixIDs[i]))
419 for(
int j=0; j<data_->numElemBlocks_; j++) {
420 ElemBlock& block = data_->elemBlocks_[j];
422 for(
int el=0; el<block.numElements_; el++) {
424 CHK_ERR(fei_->sumInElemMatrix(block.blockID_,
427 block.elemStiff_[el],
433 for(i=0; i<numRHSs; i++) {
434 CHK_ERR(fei_->setCurrentRHS(rhsIDs[i]))
436 for(
int j=0; j<data_->numElemBlocks_; j++) {
437 ElemBlock& block = data_->elemBlocks_[j];
439 for(
int el=0; el<block.numElements_; el++) {
440 CHK_ERR(fei_->sumInElemRHS(block.blockID_,
443 block.elemLoad_[el]))
450 for(i=0; i<data_->numBCNodeSets_; i++) {
451 BCNodeSet& bcSet = data_->bcNodeSets_[i];
453 CHK_ERR(fei_->loadNodeBCs(bcSet.numNodes_,
456 bcSet.offsetsIntoField_,
457 bcSet.prescribed_values_))
460 double* matScalars =
new double[numMatrices];
461 for(i=0; i<numMatrices; i++) {
465 int rhsScaleID = rhsIDs[0];
466 double rhsScalar = 1.0;
468 CHK_ERR(fei_->setMatScalars(numMatrices, matrixIDs, matScalars))
469 CHK_ERR(fei_->setRHSScalars(1, &rhsScaleID, &rhsScalar))
471 delete [] matScalars;
476 int FEI_tester::exerciseResidualNorm()
478 std::string sname(data_->solverLibraryName_);
479 if (sname ==
"TEST_LSC") {
483 double* norms =
new double[data_->numFields_];
484 int *fields =
new int[data_->numFields_];
485 for(
int i=0; i<data_->numFields_; ++i) {
486 fields[i] = data_->fieldIDs_[i];
489 CHK_ERR( fei_->residualNorm(1, data_->numFields_, fields, norms) );
502 int FEI_tester::exercisePutFunctions()
507 CHK_ERR( fei_->getNumLocalNodes(numNodes) );
508 std::vector<int> nodeIDs(numNodes);
509 int* nodeIDsPtr = &nodeIDs[0];
511 CHK_ERR( fei_->getLocalNodeIDList(checkNumNodes, nodeIDsPtr, numNodes) );
513 for(
int i=0; i<data_->numFields_; ++i) {
514 int fieldID = data_->fieldIDs_[i];
515 int fieldSize = data_->fieldSizes_[i];
516 std::vector<double> data(numNodes*fieldSize, 0.0001);
518 CHK_ERR( fei_->putNodalFieldData(fieldID, numNodes, nodeIDsPtr,
526 int FEI_tester::save_block_node_soln(DataReader& data,
FEI& fei,
527 const char* solnFileName,
int numProcs,
528 int localProc,
int solveCounter)
533 int maxNumEqnsPerNode = 0;
534 for(i=0; i<data.numFields_; ++i) {
535 maxNumEqnsPerNode += data.fieldSizes_[i];
538 std::vector<double> soln(maxNumEqnsPerNode);
543 std::vector<GlobalID> nodes(numNodes);
544 int* nodesPtr = &nodes[0];
549 if (checkNumNodes != numNodes) {
553 FEI_OSTRINGSTREAM fileName;
554 fileName << solnFileName<<
".node."<<solveCounter<<
"."<<numProcs<<
"."<<localProc;
555 FEI_OFSTREAM outfile(fileName.str().c_str());
557 if (!outfile || outfile.bad()) {
558 FEI_COUT <<
"ERROR opening solution output file " << fileName.str() << FEI_ENDL;
562 outfile.setf(IOS_SCIENTIFIC, IOS_FLOATFIELD);
564 std::vector<int> offsets(2);
566 for(i=0; i<numNodes; ++i) {
568 &offsets[0], &soln[0]) );
570 int numDOF = offsets[1];
572 outfile << nodesPtr[i] <<
" " << numDOF << FEI_ENDL;
573 for(
int j=0; j<numDOF; j++) {
574 outfile << soln[j] <<
" ";
583 int FEI_tester::save_block_elem_soln(DataReader& data,
FEI& fei,
584 const char* solnFileName,
585 int numProcs,
int localProc,
589 FEI_OSTRINGSTREAM fileName;
590 fileName << solnFileName<<
".elem."<<solveCounter<<
"."<<numProcs<<
"."<<localProc;
591 FEI_OFSTREAM outfile(fileName.str().c_str());
593 if (!outfile || outfile.bad()) {
594 FEI_COUT <<
"ERROR opening elem-solution output file " << fileName.str() << FEI_ENDL;
598 for(
int i=0; i<data.numElemBlocks_; i++) {
599 if (returnValue != 0)
break;
601 ElemBlock& eb = data.elemBlocks_[i];
603 GlobalID blockID = eb.blockID_;
609 int totalNumElemDOF = numElems*dofPerElem;
611 if (totalNumElemDOF < 1) {
615 GlobalID* elemIDs =
new GlobalID[numElems];
616 if (elemIDs==NULL)
return(-1);
619 if (err) returnValue = 1;
621 int* offsets =
new int[numElems+1];
622 if (offsets == NULL)
return(-1);
624 if (totalNumElemDOF > 0) {
625 double* solnValues =
new double[totalNumElemDOF];
626 if (solnValues == NULL)
return(-1);
629 dofPerElem, solnValues);
630 if (err) returnValue = 1;
633 for(
int j=0; j<numElems; j++) {
635 outfile << (int)elemIDs[j] <<
" " << dofPerElem << FEI_ENDL <<
" ";
636 for(
int k=0; k<dofPerElem; k++) {
637 outfile << solnValues[j*dofPerElem + k] <<
" ";
643 delete [] solnValues;
654 int FEI_tester::save_multiplier_soln(DataReader& data,
FEI& fei,
655 const char* solnFileName,
656 int numProcs,
int localProc,
int solveCounter)
662 int* globalNumCRs =
new int[numProcs];
664 if (MPI_Allgather(&numCRs, 1, MPI_INT, globalNumCRs, 1, MPI_INT,
665 comm_) != MPI_SUCCESS) {
670 int localCRStart = 0;
671 for(
int p=0; p<localProc; p++) localCRStart += globalNumCRs[p];
673 delete [] globalNumCRs;
675 FEI_OSTRINGSTREAM fileName;
676 fileName << solnFileName<<
".mult."<<solveCounter<<
"."<<numProcs<<
"."<<localProc;
677 FEI_OFSTREAM outfile(fileName.str().c_str());
679 if (!outfile || outfile.bad()) {
680 FEI_COUT <<
"ERROR opening mult-solution output file " << fileName.str() << FEI_ENDL;
684 int* CRIDs = numCRs > 0 ?
new int[numCRs] : NULL;
685 double* results = numCRs > 0 ?
new double[numCRs] : NULL;
687 if (numCRs > 0 && (CRIDs==NULL || results==NULL)) {
697 std::string sname(data_->solverLibraryName_);
698 if (sname ==
"FETI") {
699 for(
int ii=0; ii<numCRs; ++ii) results[ii] = -999.99;
705 for(
int i=0; i<numCRs; i++) {
706 outfile << localCRStart++ <<
" " << 1 << FEI_ENDL;
708 outfile <<
" " << results[i] << FEI_ENDL;
718 int FEI_tester::lsc_matrix_check()
720 if (localProc_ == 0) {
721 char* current_dir = NULL;
722 CHK_ERR( fei_test_utils::dirname(data_->solnFileName_.c_str(), current_dir));
724 FEI_OSTRINGSTREAM solnMtxName;
725 solnMtxName<< current_dir<<
"/A_TLSC.mtx";
726 fei::FillableMat solnMtx, checkMtx;
727 CHK_ERR( SolnCheck::readMatrix(solnMtxName.str().c_str(), numProcs_, solnMtx) );
728 CHK_ERR( SolnCheck::readMatrix(data_->checkFileName_.c_str(), numProcs_, checkMtx) );
729 int err = SolnCheck::compareMatrices(solnMtx, checkMtx);
730 delete [] current_dir;
732 FEI_COUT <<
"Utst_fei_lsc: TEST PASSED" << FEI_ENDL;
735 FEI_COUT <<
"Utst_fei_lsc: TEST FAILED" << FEI_ENDL;
virtual int getCRMultipliers(int numCRs, const int *CRIDs, double *results)=0
virtual int getBlockElemIDList(GlobalID elemBlockID, int numElems, GlobalID *elemIDs)=0
virtual int getNumCRMultipliers(int &numMultCRs)=0
virtual int getNumBlockElemDOF(GlobalID blockID, int &DOFPerElem) const =0
virtual int getNumLocalNodes(int &numNodes)=0
virtual int getNodalSolution(int numNodes, const GlobalID *nodeIDs, int *offsets, double *results)=0
std::ostream & console_out()
virtual int getBlockElemSolution(GlobalID elemBlockID, int numElems, const GlobalID *elemIDs, int &numElemDOFPerElement, double *results)=0
virtual int getLocalNodeIDList(int &numNodes, GlobalID *nodeIDs, int lenNodeIDs)=0
fei::SharedPtr< LibraryWrapper > create_LibraryWrapper(MPI_Comm comm, const char *libraryName)
virtual int getCRMultIDList(int numMultCRs, int *multIDs)=0
virtual int getNumBlockElements(GlobalID blockID, int &numElems) const =0