FEI Version of the Day
driverData.cpp
00001 /*--------------------------------------------------------------------*/
00002 /*    Copyright 2005 Sandia Corporation.                              */
00003 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00004 /*    non-exclusive license for use of this work by or on behalf      */
00005 /*    of the U.S. Government.  Export of this program may require     */
00006 /*    a license from the United States Government.                    */
00007 /*--------------------------------------------------------------------*/
00008 
00009 
00010 #include <fei_fstream.hpp>
00011 
00012 #include <FEI.hpp>
00013 #include <fei_defs.h>
00014 
00015 #include <snl_fei_Utils.hpp>
00016 #include <test_utils/DataReader.hpp>
00017 
00018 #include <test_utils/driverData.hpp>
00019 
00020 #include <cstring>
00021 
00022 #ifdef CHK_ERR
00023 #undef CHK_ERR
00024 #endif
00025 #define CHK_ERR(a) {int chkerr; if ((chkerr = a) != 0) { \
00026                     fei::console_out() << "file " << __FILE__ << ", line " << __LINE__ \
00027                          << ", err " << chkerr << FEI_ENDL; \
00028                     return(chkerr); } }
00029 
00030 driverData::driverData()
00031   :
00032   methodNames(),
00033   temp_(NULL),
00034   tempLen_(0),
00035   initFields_fieldSizes_(NULL),
00036   initFields_fieldIDs_(NULL),
00037   initElemBlock_ints_(NULL),
00038   initElemBlock_fieldsPerNode_(NULL),
00039   initElemBlock_fieldIDs_(NULL),
00040   initElemBlock_elemDofFieldIDs_(NULL),
00041   initElems_(),
00042   initElemCounter_(0),
00043   sumInElems_(),
00044   sumInElemCounter_(0),
00045   sumInElemMatrix_(),
00046   sumInElemMatrixCounter_(0),
00047   sumInElemRHS_(),
00048   sumInElemRHSCounter_(0),
00049   loadNodeBCs_(),
00050   loadNodeBCsCounter_(0),
00051   initCRMult_(),
00052   initCRMultCounter_(0),
00053   loadCRMult_(),
00054   loadCRMultCounter_(0),
00055   initSharedNodes_(),
00056   initSharedNodesCounter_(0),
00057   parameters_(),
00058   parametersCounter_(0),
00059   setIDLists_(),
00060   setIDListsCounter_(0),
00061   setCurrentMatrix_(),
00062   setCurrentMatrixCounter_(0),
00063   setCurrentRHS_(),
00064   setCurrentRHSCounter_(0),
00065   putBlockFieldNodeSolution_(),
00066   putBlockFieldNodeSolutionCounter_(0)
00067 {
00068   tempLen_ = 512;
00069   temp_ = new char[tempLen_];
00070 }
00071 
00072 driverData::~driverData()
00073 {
00074   tempLen_ = 0;
00075   delete [] temp_;
00076 
00077   for(size_t i=0; i<methodNames.size(); i++) {
00078     delete [] methodNames[i];
00079   }
00080 
00081   delete [] initFields_fieldSizes_;
00082   delete [] initFields_fieldIDs_;
00083 
00084   if (initElemBlock_numInts_ > 0 && initElemBlock_ints_ != NULL) {
00085     int len = initElemBlock_ints_[2];
00086     for(int j=0; j<len; ++j) delete [] initElemBlock_fieldIDs_[j];
00087     delete [] initElemBlock_fieldIDs_;
00088     delete [] initElemBlock_fieldsPerNode_;
00089     delete [] initElemBlock_ints_;
00090     initElemBlock_ints_ = NULL;
00091   }
00092 
00093   for(size_t i=0; i<initElems_.size(); ++i) delete initElems_[i];
00094   for(size_t i=0; i<sumInElems_.size(); ++i) delete sumInElems_[i];
00095   for(size_t i=0; i<sumInElemMatrix_.size(); ++i) delete sumInElemMatrix_[i];
00096   for(size_t i=0; i<sumInElemRHS_.size(); ++i) delete sumInElemRHS_[i];
00097   for(size_t i=0; i<loadNodeBCs_.size(); ++i) delete loadNodeBCs_[i];
00098   for(size_t i=0; i<initCRMult_.size(); ++i) delete initCRMult_[i];
00099   for(size_t i=0; i<loadCRMult_.size(); ++i) delete loadCRMult_[i];
00100   for(size_t i=0; i<initSharedNodes_.size(); ++i) delete initSharedNodes_[i];
00101   for(size_t i=0; i<parameters_.size(); ++i) delete parameters_[i];
00102   for(size_t i=0; i<setIDLists_.size(); ++i) delete setIDLists_[i];
00103 }
00104 
00105 int driverData::readData(const char* fileName)
00106 {
00107   FEI_IFSTREAM* instr = NULL;
00108   instr = new FEI_IFSTREAM(fileName);
00109 
00110   if (instr->bad()) {
00111     fei::console_out() << "driverData::readData: ERROR opening " << fileName << FEI_ENDL;
00112     return(-1);
00113   }
00114   FEI_COUT << "driverData reading from " << fileName << FEI_ENDL;
00115   char* keyword = NULL;
00116 
00117   int err = getKeyword(instr, keyword);
00118   while (!instr->eof() && !err) {
00119     FEI_COUT << "driverData read keyword: " << keyword << FEI_ENDL;
00120     err = readData(instr, keyword);
00121     if (err != 0) {
00122       fei::console_out() << "driverData: ERROR reading data for keyword: " << keyword << FEI_ENDL;
00123       break;
00124     }
00125     delete [] keyword;
00126     err = getKeyword(instr, keyword);
00127   }
00128 
00129   delete instr;
00130 
00131   return(0);
00132 }
00133 
00134 int driverData::call_fei_method(const char* method, FEI* fei)
00135 {
00136   if (!std::strcmp("setSolveType", method)) {
00137     return( fei->setSolveType(solveType_) );
00138   }
00139 
00140   if (!std::strcmp("setIDLists", method)) {
00141     if (setIDListsCounter_ >= (int)setIDLists_.size()) {
00142       fei::console_out() << "driverData ERROR, can't call setIDLists again" << FEI_ENDL;
00143       return(-1);
00144     }
00145 
00146     setIDLists* sidl = setIDLists_[setIDListsCounter_++];
00147 
00148     return( fei->setIDLists(sidl->numMatrices, sidl->matrixIDs,
00149              sidl->numRHSs, sidl->rhsIDs) );
00150   }
00151 
00152   if (!std::strcmp("setCurrentMatrix", method)) {
00153     if (setCurrentMatrixCounter_ >= (int)setCurrentMatrix_.size()) {
00154       fei::console_out() << "driverData ERROR, can't call setCurrentMatrix again" << FEI_ENDL;
00155       return(-1);
00156     }
00157 
00158     int matID = setCurrentMatrix_[setCurrentMatrixCounter_++];
00159 
00160     return( fei->setCurrentMatrix(matID) );
00161   }
00162 
00163   if (!std::strcmp("setCurrentRHS", method)) {
00164     if (setCurrentRHSCounter_ >= (int)setCurrentRHS_.size()) {
00165       fei::console_out() << "driverData ERROR, can't call setCurrentRHS again" << FEI_ENDL;
00166       return(-1);
00167     }
00168 
00169     int rhsID = setCurrentRHS_[setCurrentRHSCounter_++];
00170 
00171     return( fei->setCurrentMatrix(rhsID) );
00172   }
00173 
00174   if (!std::strcmp("initFields", method)) {
00175     return( fei->initFields(initFields_numFields_,
00176              initFields_fieldSizes_,
00177              initFields_fieldIDs_) );
00178   }
00179 
00180   if (!std::strcmp("initElemBlock", method)) {
00181     return( fei->initElemBlock((GlobalID)initElemBlock_ints_[0],
00182           initElemBlock_ints_[1],
00183           initElemBlock_ints_[2],
00184           initElemBlock_fieldsPerNode_,
00185           initElemBlock_fieldIDs_,
00186           initElemBlock_ints_[3],
00187           initElemBlock_elemDofFieldIDs_,
00188           initElemBlock_ints_[4]) );
00189 
00190   }
00191 
00192   if (!std::strcmp("parameters", method)) {
00193     if (parametersCounter_ >= (int)parameters_.size()) {
00194       fei::console_out() << "driverData ERROR, can't call parameters again" << FEI_ENDL;
00195       return(-1);
00196     }
00197 
00198     parameters* param = parameters_[parametersCounter_++];
00199 
00200     return( fei->parameters(param->paramList.size(),
00201           &param->paramList[0]) );
00202   }
00203 
00204   if (!std::strcmp("initCRMult", method)) {
00205     if (initCRMultCounter_ >= (int)initCRMult_.size()) {
00206       fei::console_out() << "driverData ERROR, can't call initCRMult again" << FEI_ENDL;
00207       return(-1);
00208     }
00209 
00210     initCR* icr = initCRMult_[initCRMultCounter_++];
00211 
00212     return( fei->initCRMult(icr->numNodes, icr->nodeIDs,
00213              icr->fieldIDs, icr->CRID) );
00214   }
00215 
00216   if (!std::strcmp("initSharedNodes", method)) {
00217     if (initSharedNodesCounter_ >= (int)initSharedNodes_.size()) {
00218       fei::console_out() << "driverData ERROR, can't call initSharedNodes again" << FEI_ENDL;
00219       return(-1);
00220     }
00221 
00222     sharedNodes* sn = initSharedNodes_[initSharedNodesCounter_++];
00223 
00224     return( fei->initSharedNodes(sn->numNodes, sn->nodeIDs,
00225              sn->numProcsPerNode, sn->sharedProcIDs) );
00226   }
00227 
00228   if (!std::strcmp("loadCRMult", method)) {
00229     if (loadCRMultCounter_ >= (int)loadCRMult_.size()) {
00230       fei::console_out() << "driverData ERROR, can't call loadCRMult again" << FEI_ENDL;
00231       return(-1);
00232     }
00233 
00234     loadCR* lcr = loadCRMult_[loadCRMultCounter_++];
00235 
00236     return( fei->loadCRMult(lcr->CRID, lcr->numNodes, lcr->nodeIDs,
00237              lcr->fieldIDs, lcr->weights, lcr->CRValue) );
00238   }
00239 
00240   if (!std::strcmp("deleteMultCRs", method)) {
00241     return( fei->deleteMultCRs() );
00242   }
00243 
00244   if (!std::strcmp("initElem", method)) {
00245     if (initElemCounter_ >= (int)initElems_.size()) {
00246       fei::console_out() << "driverData ERROR, can't call initElem again" << FEI_ENDL;
00247       return(-1);
00248     }
00249 
00250     initElem* ie = initElems_[initElemCounter_++];
00251 
00252     return( fei->initElem(ie->elemBlockID, ie->elemID, ie->nodeIDs) );
00253   }
00254 
00255   if (!std::strcmp("initComplete", method)) {
00256     return( fei->initComplete() );
00257   }
00258 
00259   if (!std::strcmp("resetSystem", method)) {
00260     return( fei->resetSystem(resetSystem_) );
00261   }
00262 
00263   if (!std::strcmp("resetMatrix", method)) {
00264     return( fei->resetMatrix(resetMatrix_) );
00265   }
00266 
00267   if (!std::strcmp("resetRHSVector", method)) {
00268     return( fei->resetRHSVector(resetRHSVector_) );
00269   }
00270 
00271   if (!std::strcmp("resetInitialGuess", method)) {
00272     return( fei->resetInitialGuess(resetInitialGuess_) );
00273   }
00274 
00275   if (!std::strcmp("sumInElem", method)) {
00276     if (sumInElemCounter_ >= (int)sumInElems_.size()) {
00277       fei::console_out() << "driverData ERROR, can't call sumInElem again" << FEI_ENDL;
00278       return(-1);
00279     }
00280 
00281     sumInElem* sie = sumInElems_[sumInElemCounter_++];
00282 
00283     return( fei->sumInElem(sie->elemBlockID, sie->elemID, sie->nodeIDs,
00284             sie->stiffness, sie->load, sie->elemFormat) );
00285   }
00286 
00287   if (!std::strcmp("sumInElemMatrix", method)) {
00288     if (sumInElemMatrixCounter_ >= (int)sumInElemMatrix_.size()) {
00289       fei::console_out() << "driverData ERROR, can't call sumInElemMatrix again" << FEI_ENDL;
00290       return(-1);
00291     }
00292 
00293     sumInElem* sie = sumInElemMatrix_[sumInElemMatrixCounter_++];
00294 
00295     return( fei->sumInElemMatrix(sie->elemBlockID, sie->elemID, sie->nodeIDs,
00296             sie->stiffness, sie->elemFormat) );
00297   }
00298 
00299   if (!std::strcmp("sumInElemRHS", method)) {
00300     if (sumInElemRHSCounter_ >= (int)sumInElemRHS_.size()) {
00301       fei::console_out() << "driverData ERROR, can't call sumInElemRHS again" << FEI_ENDL;
00302       return(-1);
00303     }
00304 
00305     sumInElem* sie = sumInElemRHS_[sumInElemRHSCounter_++];
00306 
00307     return( fei->sumInElemRHS(sie->elemBlockID, sie->elemID, sie->nodeIDs,
00308                sie->load) );
00309   }
00310 
00311   if (!std::strcmp("putBlockFieldNodeSolution", method)) {
00312     if (putBlockFieldNodeSolutionCounter_ >=
00313   (int)putBlockFieldNodeSolution_.size()) {
00314       fei::console_out() << "driverData ERROR, can't call putBlockFieldNodeSolution again"
00315      << FEI_ENDL;
00316       return(-1);
00317     }
00318 
00319     putBlockFieldNodeSolution* pbfns =
00320       putBlockFieldNodeSolution_[putBlockFieldNodeSolutionCounter_++];
00321 
00322     return( fei->putBlockFieldNodeSolution(pbfns->elemBlockID,
00323                 pbfns->fieldID,
00324                 pbfns->numNodes,
00325                 pbfns->nodeIDs,
00326                 pbfns->estimates) );
00327   }
00328 
00329   if (!std::strcmp("loadNodeBCs", method)) {
00330     if (loadNodeBCsCounter_ >= (int)loadNodeBCs_.size()) {
00331       fei::console_out() << "driverData ERROR, can't call loadNodeBCs again" << FEI_ENDL;
00332       return(-1);
00333     }
00334 
00335     fei::console_out() << "driverData: ERROR, loadNodeBCs needs to be re-examined..." << FEI_ENDL;
00336     return( -1 );
00337   }
00338 
00339   if (!std::strcmp("loadComplete", method)) {
00340     return( fei->loadComplete() );
00341   }
00342 
00343   if (!std::strcmp("solve", method)) {
00344     int status;
00345     return( fei->solve(status) );
00346   }
00347 
00348   if (!std::strcmp("getBlockNodeIDList", method) ||
00349       !std::strcmp("residualNorm",       method) ||
00350       !std::strcmp("getBlockFieldNodeSolution", method)) {
00351     return(0);
00352   }
00353 
00354   fei::console_out() << "driverData: ERROR unrecognized method name '" << method << "'"<<FEI_ENDL;
00355   return(1);
00356 }
00357 
00358 int driverData::readData(FEI_ISTREAM* instr, char* keyword)
00359 {
00360   if (!std::strcmp("setSolveType", keyword)) {
00361     CHK_ERR( appendName(keyword) );
00362     return(readData(instr, solveType_));
00363   }
00364 
00365   if (!std::strcmp("setIDLists", keyword)) {
00366     int numMatrices = 0;
00367     CHK_ERR( readData(instr, numMatrices) );
00368     setIDLists* sidl = new setIDLists;
00369     sidl->numMatrices = numMatrices;
00370     sidl->matrixIDs = new int[numMatrices];
00371     int i;
00372     for(i=0; i<numMatrices; ++i) {
00373       CHK_ERR( readData(instr, sidl->matrixIDs[i]) );
00374     }
00375     int numRHSs = 0;
00376     CHK_ERR( readData(instr, numRHSs) );
00377     sidl->numRHSs = numRHSs;
00378     sidl->rhsIDs = new int[numRHSs];
00379     for(i=0; i<numRHSs; ++i) {
00380       CHK_ERR( readData(instr, sidl->rhsIDs[i]) );
00381     }
00382 
00383     setIDLists_.push_back(sidl);
00384     return( appendName(keyword) );
00385   }
00386 
00387   if (!std::strcmp("setCurrentMatrix", keyword)) {
00388     int matID = 0;
00389     CHK_ERR( readData(instr, matID) );
00390     setCurrentMatrix_.push_back(matID);
00391     return( appendName(keyword) );
00392   }
00393 
00394   if (!std::strcmp("setCurrentRHS", keyword)) {
00395     int rhsID = 0;
00396     CHK_ERR( readData(instr, rhsID) );
00397     setCurrentRHS_.push_back(rhsID);
00398     return( appendName(keyword) );
00399   }
00400 
00401   if (!std::strcmp("initFields", keyword)) {
00402     int i;
00403     CHK_ERR( readData(instr, initFields_numFields_) );
00404     initFields_fieldSizes_ = new int[initFields_numFields_];
00405     initFields_fieldIDs_ = new int[initFields_numFields_];
00406 
00407     for(i=0; i<initFields_numFields_; ++i) {
00408       CHK_ERR( readData(instr, initFields_fieldSizes_[i]) );
00409     } 
00410     for(i=0; i<initFields_numFields_; ++i) {
00411       CHK_ERR( readData(instr, initFields_fieldIDs_[i]) );
00412     }
00413 
00414     return( appendName(keyword) );
00415   }
00416 
00417   if (!std::strcmp("parameters", keyword)) {
00418     int numParams = 0;
00419     CHK_ERR( readData(instr, numParams) );
00420     parameters* param = new parameters;
00421     param->paramList.resize(numParams);
00422     CHK_ERR( skipWhite(instr) );
00423     for(int i=0; i<numParams; ++i) {
00424       char* line = new char[512];
00425       instr->getline(line, 512);
00426       param->paramList[i] = line;
00427     }
00428     parameters_.push_back(param);
00429     return( appendName(keyword) );
00430   }
00431 
00432   if (!std::strcmp("initElemBlock", keyword)) {
00433     initElemBlock_numInts_ = 5;
00434     int i, intOffset = 0;
00435     initElemBlock_ints_ = new int[initElemBlock_numInts_];
00436     //elemBlockID
00437     CHK_ERR( readData(instr, initElemBlock_ints_[intOffset++]) );
00438     //numElements
00439     CHK_ERR( readData(instr, initElemBlock_ints_[intOffset++]) );
00440     //numNodesPerElement
00441     CHK_ERR( readData(instr, initElemBlock_ints_[intOffset++]) );
00442     //now loop and read numFieldsPerNode
00443     int len = initElemBlock_ints_[intOffset-1];
00444     initElemBlock_fieldsPerNode_ = new int[len];
00445     initElemBlock_fieldIDs_ = new int*[len];
00446     for(i=0; i<len; ++i) {
00447       CHK_ERR( readData(instr, initElemBlock_fieldsPerNode_[i]) );
00448     }
00449     //now double-loop and read nodalFieldIDs
00450     for(i=0; i<len; ++i) {
00451       int len2 = initElemBlock_fieldsPerNode_[i];
00452       initElemBlock_fieldIDs_[i] = new int[len2];
00453       for(int ii=0; ii<len2; ++ii) {
00454   CHK_ERR( readData(instr, initElemBlock_fieldIDs_[i][ii]) );
00455       }
00456     }
00457     //numElemDOFPerElement
00458     CHK_ERR( readData(instr, initElemBlock_ints_[intOffset++]) );
00459     //now loop and read elemDOFFieldIDs
00460     len = initElemBlock_ints_[intOffset-1];
00461     if (len > 0) {
00462       initElemBlock_elemDofFieldIDs_ = new int[len];
00463       for(i=0; i<len; ++i) {
00464   CHK_ERR( readData(instr, initElemBlock_elemDofFieldIDs_[i]) );
00465       }
00466     }
00467     //interleaveStrategy
00468     CHK_ERR( readData(instr, initElemBlock_ints_[intOffset++]) );
00469     return( appendName(keyword) );
00470   }
00471 
00472   if (!std::strcmp("initElem", keyword) ) {
00473     initElem* ie = new initElem;
00474     int tmp;
00475     CHK_ERR( readData(instr, tmp) );
00476     ie->elemBlockID = (GlobalID)tmp;
00477     CHK_ERR( readData(instr, tmp) );
00478     ie->elemID = (GlobalID)tmp;
00479     CHK_ERR( readData(instr, tmp) );
00480     ie->nodeIDs = new GlobalID[tmp];
00481     ie->numNodes = tmp;
00482     for(int i=0; i<ie->numNodes; ++i) {
00483       CHK_ERR( readData(instr, tmp) );
00484       ie->nodeIDs[i] = (GlobalID)tmp;
00485     }
00486     initElems_.push_back(ie);
00487     return( appendName(keyword) );
00488   }
00489 
00490   if (!std::strcmp("initCRMult", keyword) ) {
00491     initCR* icr = new initCR;
00492     CHK_ERR( readData(instr, icr->numNodes) );
00493     if (icr->numNodes > 0) {
00494       icr->nodeIDs = new GlobalID[icr->numNodes];
00495       icr->fieldIDs = new int[icr->numNodes];
00496       int i, tmp;
00497       //read the nodeIDs
00498       for(i=0; i<icr->numNodes; ++i) {
00499   CHK_ERR( readData(instr, tmp) ); icr->nodeIDs[i] = (GlobalID)tmp;
00500       }
00501       //read the fieldIDs
00502       for(i=0; i<icr->numNodes; ++i) {
00503   CHK_ERR( readData(instr, icr->fieldIDs[i]) );
00504       }
00505     }
00506     //read the CRID
00507     CHK_ERR( readData(instr, icr->CRID) );
00508 
00509     initCRMult_.push_back(icr);
00510     return( appendName(keyword) );
00511   }
00512 
00513   if (!std::strcmp("loadCRMult", keyword) ) {
00514     loadCR* lcr = new loadCR;
00515     CHK_ERR( readData(instr, lcr->numNodes) );
00516     if (lcr->numNodes > 0) {
00517       lcr->nodeIDs = new GlobalID[lcr->numNodes];
00518       lcr->fieldIDs = new int[lcr->numNodes];
00519       lcr->fieldSizes = new int[lcr->numNodes];
00520       int i, tmp;
00521       //read the nodeIDs
00522       for(i=0; i<lcr->numNodes; ++i) {
00523   CHK_ERR( readData(instr, tmp) ); lcr->nodeIDs[i] = (GlobalID)tmp;
00524       }
00525       //read the fieldIDs
00526       for(i=0; i<lcr->numNodes; ++i) {
00527   CHK_ERR( readData(instr, lcr->fieldIDs[i]) );
00528       }
00529       //read the field-sizes
00530       tmp = 0;
00531       for(i=0; i<lcr->numNodes; ++i) {
00532   CHK_ERR( readData(instr, lcr->fieldSizes[i]) );
00533   tmp += lcr->fieldSizes[i];
00534       }
00535       //read the weights
00536       lcr->weights = new double[tmp];
00537       int offset = 0;
00538       for(i=0; i<lcr->numNodes; ++i) {
00539   int size = lcr->fieldSizes[i];
00540   for(int j=0; j<size; ++j) {
00541     CHK_ERR( readData(instr, lcr->weights[offset++]) );
00542   }
00543       }
00544       //read the CRValue
00545       CHK_ERR( readData(instr, lcr->CRValue) );
00546     }
00547     //read the CRID
00548     CHK_ERR( readData(instr, lcr->CRID) );
00549 
00550     loadCRMult_.push_back(lcr);
00551     return( appendName(keyword) );
00552   }
00553 
00554   if (!std::strcmp("deleteMultCRs", keyword) ) {
00555     return( appendName(keyword) );
00556   }
00557 
00558   if (!std::strcmp("initSharedNodes", keyword) ) {
00559     sharedNodes* sn = new sharedNodes;
00560     CHK_ERR( readData(instr, sn->numNodes) );
00561     if (sn->numNodes > 0) {
00562       sn->nodeIDs = new GlobalID[sn->numNodes];
00563       sn->numProcsPerNode = new int[sn->numNodes];
00564       sn->sharedProcIDs = new int*[sn->numNodes];
00565       int i, tmp;
00566       //read the numProcsPerNode list
00567       for(i=0; i<sn->numNodes; ++i) {
00568   CHK_ERR( readData(instr, sn->numProcsPerNode[i]) );
00569   sn->sharedProcIDs[i] = new int[sn->numProcsPerNode[i]];
00570       }
00571       //read the nodeIDs and sharing-proc-ids
00572       for(i=0; i<sn->numNodes; ++i) {
00573   CHK_ERR( readData(instr, tmp) ); sn->nodeIDs[i] = (GlobalID)tmp;
00574   for(int j=0; j<sn->numProcsPerNode[i]; ++j) {
00575     CHK_ERR( readData(instr, sn->sharedProcIDs[i][j]) );
00576   }
00577       }
00578     }
00579 
00580     initSharedNodes_.push_back(sn);
00581     return( appendName(keyword) );
00582   }
00583 
00584   if (!std::strcmp("initComplete", keyword) ) {
00585     return( appendName(keyword) );
00586   }
00587 
00588   if (!std::strcmp("sumInElem", keyword) ) {
00589     sumInElem* sie = new sumInElem;
00590     int tmp;
00591     double dtmp;
00592     CHK_ERR( readData(instr, tmp) );
00593     sie->elemBlockID = (GlobalID)tmp;
00594     CHK_ERR( readData(instr, tmp) );
00595     sie->elemID = (GlobalID)tmp;
00596     CHK_ERR( readData(instr, tmp) );
00597     sie->nodeIDs = new GlobalID[tmp];
00598     sie->numNodes = tmp;
00599     int i;
00600     for(i=0; i<sie->numNodes; ++i) {
00601       CHK_ERR( readData(instr, tmp) );
00602       sie->nodeIDs[i] = (GlobalID)tmp;
00603     }
00604 
00605     CHK_ERR( readData(instr, tmp) );
00606     sie->numRows = tmp;
00607     sie->stiff1D = new double[tmp*tmp];
00608     sie->load = new double[tmp];
00609     sie->stiffness = new double*[tmp];
00610     int offset = 0;
00611     for(i=0; i<sie->numRows; ++i) {
00612       for(int j=0; j<sie->numRows; ++j) {
00613   CHK_ERR( readData(instr, dtmp) );
00614   sie->stiff1D[offset++] = dtmp;
00615       }
00616       sie->stiffness[i] = &(sie->stiff1D[i*sie->numRows]);
00617     }
00618 
00619     for(int j=0; j<sie->numRows; ++j) {
00620       CHK_ERR( readData(instr, dtmp) );
00621       sie->load[j] = dtmp;
00622     }
00623 
00624     CHK_ERR( readData(instr, tmp) );
00625     sie->elemFormat = tmp;
00626 
00627     sumInElems_.push_back(sie);
00628     return( appendName(keyword) );
00629   }
00630 
00631   if (!std::strcmp("sumInElemMatrix", keyword) ) {
00632     sumInElem* sie = new sumInElem;
00633     int tmp;
00634     double dtmp;
00635     CHK_ERR( readData(instr, tmp) );
00636     sie->elemBlockID = (GlobalID)tmp;
00637     CHK_ERR( readData(instr, tmp) );
00638     sie->elemID = (GlobalID)tmp;
00639     CHK_ERR( readData(instr, tmp) );
00640     sie->nodeIDs = new GlobalID[tmp];
00641     sie->numNodes = tmp;
00642     int i;
00643     for(i=0; i<sie->numNodes; ++i) {
00644       CHK_ERR( readData(instr, tmp) );
00645       sie->nodeIDs[i] = (GlobalID)tmp;
00646     }
00647 
00648     CHK_ERR( readData(instr, tmp) );
00649     sie->numRows = tmp;
00650     sie->stiff1D = new double[tmp*tmp];
00651     sie->load = new double[tmp];
00652     sie->stiffness = new double*[tmp];
00653     int offset = 0;
00654     for(i=0; i<sie->numRows; ++i) {
00655       for(int j=0; j<sie->numRows; ++j) {
00656   CHK_ERR( readData(instr, dtmp) );
00657   sie->stiff1D[offset++] = dtmp;
00658       }
00659       sie->stiffness[i] = &(sie->stiff1D[i*sie->numRows]);
00660     }
00661 
00662     CHK_ERR( readData(instr, tmp) );
00663     sie->elemFormat = tmp;
00664 
00665     sumInElemMatrix_.push_back(sie);
00666     return( appendName(keyword) );
00667   }
00668 
00669   if (!std::strcmp("sumInElemRHS", keyword) ) {
00670     sumInElem* sie = new sumInElem;
00671     int tmp;
00672     double dtmp;
00673     CHK_ERR( readData(instr, tmp) );
00674     sie->elemBlockID = (GlobalID)tmp;
00675     CHK_ERR( readData(instr, tmp) );
00676     sie->elemID = (GlobalID)tmp;
00677     CHK_ERR( readData(instr, tmp) );
00678     sie->nodeIDs = new GlobalID[tmp];
00679     sie->numNodes = tmp;
00680     for(int i=0; i<sie->numNodes; ++i) {
00681       CHK_ERR( readData(instr, tmp) );
00682       sie->nodeIDs[i] = (GlobalID)tmp;
00683     }
00684 
00685     CHK_ERR( readData(instr, tmp) );
00686     sie->numRows = tmp;
00687 
00688     sie->load = new double[sie->numRows];
00689     for(int j=0; j<sie->numRows; ++j) {
00690       CHK_ERR( readData(instr, dtmp) );
00691       sie->load[j] = dtmp;
00692     }
00693 
00694     sumInElemRHS_.push_back(sie);
00695     return( appendName(keyword) );
00696   }
00697 
00698   if (!std::strcmp("resetSystem", keyword) ) {
00699     CHK_ERR( readData(instr, resetSystem_) );
00700     return( appendName(keyword) );
00701   }
00702 
00703   if (!std::strcmp("resetMatrix", keyword) ) {
00704     CHK_ERR( readData(instr, resetMatrix_) );
00705     return( appendName(keyword) );
00706   }
00707 
00708   if (!std::strcmp("resetRHSVector", keyword) ) {
00709     CHK_ERR( readData(instr, resetRHSVector_) );
00710     return( appendName(keyword) );
00711   }
00712 
00713   if (!std::strcmp("resetInitialGuess", keyword) ) {
00714     CHK_ERR( readData(instr, resetInitialGuess_) );
00715     return( appendName(keyword) );
00716   }
00717 
00718   if (!std::strcmp("putBlockFieldNodeSolution", keyword) ) {
00719     putBlockFieldNodeSolution* pbfns = new putBlockFieldNodeSolution;
00720     CHK_ERR( readData(instr, pbfns->elemBlockID) );
00721     CHK_ERR( readData(instr, pbfns->fieldID) );
00722     CHK_ERR( readData(instr, pbfns->fieldSize) );
00723     CHK_ERR( readData(instr, pbfns->numNodes) );
00724     if (pbfns->numNodes > 0) {
00725       pbfns->nodeIDs = new GlobalID[pbfns->numNodes];
00726 
00727       int i=0;
00728       for(i=0; i<pbfns->numNodes; ++i) {
00729   CHK_ERR( readData(instr, pbfns->nodeIDs[i]) );
00730       }
00731       int len = pbfns->numNodes * pbfns->fieldSize;
00732       pbfns->estimates = new double[len];
00733 
00734       for(i=0; i<pbfns->numNodes * pbfns->fieldSize; ++i) {
00735   CHK_ERR( readData(instr, pbfns->estimates[i]) );
00736       }
00737     }
00738 
00739     putBlockFieldNodeSolution_.push_back(pbfns);
00740     return( appendName(keyword) );
00741   }
00742 
00743   if (!std::strcmp("loadNodeBCs", keyword) ) {
00744     nodeBC* nbc = new nodeBC;
00745     CHK_ERR( readData(instr, nbc->numNodes) );
00746     CHK_ERR( readData(instr, nbc->fieldID) );
00747     CHK_ERR( readData(instr, nbc->fieldSize) );
00748 
00749     if (nbc->numNodes > 0) {
00750       nbc->nodeIDs = new GlobalID[nbc->numNodes];
00751       nbc->alpha = new double*[nbc->numNodes];
00752       nbc->beta = new double*[nbc->numNodes];
00753       nbc->gamma = new double*[nbc->numNodes];
00754 
00755       int i, j, tmp;
00756       for(i=0; i<nbc->numNodes; ++i) {
00757   nbc->alpha[i] = new double[nbc->fieldSize];
00758   nbc->beta[i] = new double[nbc->fieldSize];
00759   nbc->gamma[i] = new double[nbc->fieldSize];
00760 
00761   CHK_ERR( readData(instr, tmp) );
00762   nbc->nodeIDs[i] = (GlobalID)tmp;
00763 
00764   for(j=0; j<nbc->fieldSize; ++j) {
00765     CHK_ERR( readData(instr, nbc->alpha[i][j]));
00766   }
00767   for(j=0; j<nbc->fieldSize; ++j) {
00768     CHK_ERR( readData(instr, nbc->beta[i][j]));
00769   }
00770   for(j=0; j<nbc->fieldSize; ++j) {
00771     CHK_ERR( readData(instr, nbc->gamma[i][j]));
00772   }
00773       }
00774     }
00775 
00776     loadNodeBCs_.push_back(nbc);
00777     return( appendName(keyword) );
00778   }
00779 
00780   if (!std::strcmp("loadComplete",       keyword) ||
00781       !std::strcmp("solve",              keyword) ||
00782       !std::strcmp("destructor",         keyword) ||
00783       !std::strcmp("getBlockNodeIDList", keyword) ||
00784       !std::strcmp("getBlockFieldNodeSolution", keyword) ||
00785       !std::strcmp("residualNorm",       keyword)) {
00786     return( appendName(keyword) );
00787   }
00788 
00789   return(-1);
00790 }
00791 
00792 int driverData::appendName(const char* name)
00793 {
00794   if (name == NULL) return(-1);
00795   char* str = new char[strlen(name)+1];
00796   strcpy(str, name);
00797   methodNames.push_back(str);
00798   return(0);
00799 }
00800 
00801 int driverData::getKeyword(FEI_ISTREAM* instr, char*& keyword)
00802 {
00803   int err = skipWhite(instr);
00804   if (err) return(err);
00805 
00806   for(int i=0; i<tempLen_; i++) temp_[i] = '\0';
00807 
00808   do {
00809     instr->getline(temp_, tempLen_);
00810   } while ((strlen(temp_) == 0) && (!instr->eof()));
00811 
00812   if (instr->eof() || strlen(temp_) == 0) return(-1);
00813 
00814   keyword = new char[strlen(temp_)+1];
00815   const char* temp2 = snl_fei::getParamValue("FEI:", 1, &temp_);
00816 
00817   if (temp2 != NULL) {
00818     strcpy(keyword, temp2);
00819     return(0);
00820   }
00821 
00822   return(-1);
00823 }
00824 
00825 //==============================================================================
00826 int driverData::is_reg_char(char c) {
00827    int i = (int)c;
00828    if (i<1 || i>126) return(0);
00829 
00830    return(1);
00831 }
00832 
00833 //==============================================================================
00834 int driverData::skipWhite(FEI_ISTREAM* instr) {
00835    char c = '\0';
00836    instr->get(c);
00837 
00838    if (!is_reg_char(c)) {
00839       return(-1);
00840    }
00841 
00842    while(c == '#' || c == '\n' || c == ' ') {
00843       if (c=='#') {
00844          char* buf = new char[128];
00845          for(int i=0; i<128; i++) buf[i] = '\0';
00846          instr->getline(buf, 128);
00847          delete [] buf;
00848       }
00849 
00850       instr->get(c);
00851 
00852       if (instr->eof()) return(1);
00853       if ((int)c == EOF) return(1);
00854 
00855       if (!is_reg_char(c)) {
00856          return(-1);
00857       }
00858    }
00859 
00860    instr->putback(c);
00861    return(0);
00862 }
00863 
00864 //==============================================================================
00865 int driverData::readData(FEI_ISTREAM* instr, int& n) {
00866   int err = skipWhite(instr);
00867   if (err) return(err);
00868   (*instr) >> n;
00869   return(0);
00870 }
00871 
00872 //==============================================================================
00873 int driverData::readData(FEI_ISTREAM* instr, double& val) {
00874   int err = skipWhite(instr);
00875   if (err) return(err);
00876   (*instr) >> val;
00877   return(0);
00878 }
00879 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends