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