DataReader.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 #include <cstring>
00010 
00011 #include <fei_fstream.hpp>
00012 #include <fei_iostream.hpp>
00013 #include <fei_defs.h>
00014 #include <test_utils/BCNodeSet.hpp>
00015 #include <test_utils/CRSet.hpp>
00016 #include <test_utils/CommNodeSet.hpp>
00017 #include <test_utils/ElemBlock.hpp>
00018 #include <test_utils/AccessPattern.hpp>
00019 #include <test_utils/DataReader.hpp>
00020 
00021 //==============================================================================
00022 DataReader::DataReader()
00023  : 
00024    solveType_(0),
00025    solverLibraryName_(),
00026    numFields_(0),
00027    fieldIDs_(NULL),
00028    fieldSizes_(NULL),
00029    numParams_(0),
00030    paramStrings_(NULL),
00031    numElemBlocks_(0),
00032    elemBlocks_(NULL),
00033    numCoefAccessPatterns_(0),
00034    accessPatterns_(NULL),
00035    numCoefAccesses_(0),
00036    coefAccesses_(NULL),
00037    numCRMultSets_(0),
00038    crMultSets_(NULL),
00039    numSlaveVars_(0),
00040    slaveVars_(NULL),
00041    numCRPenSets_(0),
00042    crPenSets_(NULL),
00043    numBCNodeSets_(0),
00044    bcNodeSets_(NULL),
00045    numSharedNodeSets_(0),
00046    sharedNodeSets_(NULL),
00047    numFieldsRead_(false),
00048    numElemBlocksRead_(false),
00049    currentElemBlockIndex_(0),
00050    currentElemIndex_(0),
00051    currentShIndex_(0),
00052    currentExtIndex_(0),
00053    currentBCIndex_(0)
00054 {
00055 }
00056 
00057 //==============================================================================
00058 DataReader::~DataReader() {
00059    deleteMemory();
00060 
00061    numElemBlocksRead_ = false;
00062    numFieldsRead_ = false;
00063 }
00064 
00065 //==============================================================================
00066 void DataReader::deleteMemory() {
00067    for(int i=0; i<numParams_; i++) {
00068       delete [] paramStrings_[i];
00069    }
00070    delete [] paramStrings_;
00071    numParams_ = 0;
00072 
00073    delete [] accessPatterns_;
00074    numCoefAccessPatterns_ = 0;
00075 
00076    delete [] coefAccesses_;
00077    numCoefAccesses_ = 0;
00078 
00079    delete [] elemBlocks_;
00080    numElemBlocks_ = 0;
00081 
00082    delete [] fieldIDs_;
00083    delete [] fieldSizes_;
00084    numFields_ = 0;
00085 
00086    delete [] sharedNodeSets_;
00087    numSharedNodeSets_ = 0;
00088 
00089    delete [] crMultSets_;
00090    numCRMultSets_ = 0;
00091 
00092    delete [] slaveVars_;
00093    numSlaveVars_ = 0;
00094 
00095    delete [] crPenSets_;
00096    numCRPenSets_ = 0;
00097 
00098    delete [] bcNodeSets_;
00099    numBCNodeSets_ = 0;
00100 }
00101 
00102 //==============================================================================
00103 int DataReader::readData(const char* fileName) {
00104 
00105    FEI_IFSTREAM* instr = new FEI_IFSTREAM(fileName);
00106 
00107    if (instr->bad()) {
00108       FEI_CERR << "DataReader::readData: ERROR opening " << fileName << FEI_ENDL;
00109       return(1);
00110    }
00111 // FEI_COUT << "DataReader reading from " << fileName << FEI_ENDL;
00112    char* keyword = NULL;
00113 
00114    int err = getKeyword(instr, keyword);
00115 
00116    while (!instr->eof() && !err) {
00117       readData(instr, keyword);
00118       delete [] keyword;
00119       keyword = NULL;
00120 
00121       err = getKeyword(instr, keyword);
00122    }
00123 
00124    delete instr;
00125    delete [] keyword;
00126 
00127    return(0);
00128 }
00129 
00130 //==============================================================================
00131 int DataReader::getKeyword(FEI_ISTREAM* instr, char*& keyword) {
00132    int err = skipWhite(instr);
00133    if (err) return(err);
00134 
00135    char *temp = new char[256];
00136    for(int i=0; i<256; i++) temp[i] = '\0';
00137 
00138    do {
00139       (*instr) >> temp;
00140    } while ((std::strlen(temp) == 0) && (!instr->eof()));
00141 
00142    keyword = new char[std::strlen(temp)+1];
00143    std::strcpy(keyword, temp);
00144 
00145    delete [] temp;
00146 
00147    return(0);
00148 }
00149 
00150 //==============================================================================
00151 int DataReader::is_reg_char(char c) {
00152    int i = (int)c;
00153    if (i<1 || i>126) return(0);
00154 
00155    return(1);
00156 }
00157 
00158 //==============================================================================
00159 int DataReader::skipWhite(FEI_ISTREAM* instr) {
00160    char c = '\0';
00161    instr->get(c);
00162 
00163    if (!is_reg_char(c)) {
00164       return(1);
00165    }
00166 
00167    while(c == '#' || c == '\n' || c == ' ') {
00168       if (c=='#') {
00169          char* buf = new char[128];
00170          for(int i=0; i<128; i++) buf[i] = '\0';
00171          instr->getline(buf, 128);
00172          delete [] buf;
00173       }
00174 
00175       instr->get(c);
00176 
00177       if (instr->eof()) return(1);
00178       if ((int)c == EOF) return(1);
00179 
00180       if (!is_reg_char(c)) {
00181          return(1);
00182       }
00183    }
00184 
00185    instr->putback(c);
00186    return(0);
00187 }
00188 
00189 //==============================================================================
00190 void DataReader::readData(FEI_ISTREAM* instr, char* keyword) {
00191 
00192    if (!std::strcmp("solveType", keyword)) {
00193       readData(instr, solveType_);
00194       return;
00195    }
00196 
00197    if (!std::strcmp("parameters", keyword)) {
00198       int tmp = 0;
00199       readData(instr, tmp);
00200 
00201       char** newParams = new char*[numParams_ + tmp];
00202       for(int pp=0; pp<numParams_; pp++) newParams[pp] = paramStrings_[pp];
00203 
00204       for(int i=numParams_; i<numParams_+tmp; i++) {
00205          char* buf = new char[256];
00206          for(int j=0; j<256; j++) buf[j] = '\0';
00207 
00208          skipWhite(instr);
00209          instr->getline(buf, 128);
00210 
00211          newParams[i] = new char[std::strlen(buf)+2];
00212          std::strcpy(newParams[i], buf);
00213 
00214          delete [] buf;
00215       }
00216 
00217       delete [] paramStrings_;
00218       paramStrings_ = newParams;
00219       numParams_ += tmp;
00220 
00221       return;
00222    }
00223 
00224    if (!std::strcmp("numFields", keyword)) {
00225       readData(instr, numFields_);
00226 
00227       fieldSizes_ = new int[numFields_];
00228       fieldIDs_ = new int[numFields_];
00229 
00230       numFieldsRead_ = true;
00231       return;
00232    }
00233 
00234    if (!std::strcmp("fieldIDs", keyword)) {
00235       for(int i=0; i<numFields_; i++) readData(instr, fieldIDs_[i]);
00236       return;
00237    }
00238 
00239    if (!std::strcmp("fieldSizes", keyword)) {
00240       for(int i=0; i<numFields_; i++) readData(instr, fieldSizes_[i]);
00241       return;
00242    }
00243 
00244    if (!std::strcmp("numElemBlocks", keyword)) {
00245       if (numElemBlocks_ > 0) {
00246          FEI_COUT << "DataReader: Caution, re-setting numElemBlocks." << FEI_ENDL;
00247          delete [] elemBlocks_;
00248       }
00249 
00250       readData(instr, numElemBlocks_);
00251 
00252       elemBlocks_ = new ElemBlock[numElemBlocks_];
00253 
00254       numElemBlocksRead_ = true;
00255       currentElemBlockIndex_ = -1;
00256 
00257       return;
00258    }
00259 
00260    if (!std::strcmp("blockID", keyword)) {
00261       currentElemBlockIndex_++;
00262       currentElemIndex_ = 0;
00263 
00264       if (!numElemBlocksRead_) {
00265          FEI_COUT << "DataReader: ERROR, numElemBlocks not read before blockID."
00266             << FEI_ENDL;
00267          return;
00268       }
00269 
00270       ElemBlock& eb1 = elemBlocks_[currentElemBlockIndex_];
00271 
00272       int tmp;
00273       readData(instr, tmp);
00274       eb1.blockID_ = (GlobalID)tmp;
00275 
00276       return;
00277    }
00278 
00279    if (!std::strcmp("interleaveStrategy", keyword)) {
00280       ElemBlock& eb2 = elemBlocks_[currentElemBlockIndex_];
00281       int interleave;
00282 
00283       readData(instr, interleave);
00284 
00285       eb2.interleaveStrategy_ = interleave;
00286 
00287       return;
00288    }
00289 
00290    if (!std::strcmp("numElements", keyword)) {
00291       ElemBlock& eb3 = elemBlocks_[currentElemBlockIndex_];
00292       int numElems;
00293 
00294       readData(instr, numElems);
00295 
00296       eb3.numElements_ = numElems;
00297       eb3.elemIDs_ = new GlobalID[numElems];
00298       eb3.elemConn_ = new GlobalID*[numElems];
00299       eb3.elemStiff_ = new double**[numElems];
00300       eb3.elemLoad_ = new double*[numElems];
00301 
00302       return;
00303    }
00304 
00305    if (!std::strcmp("numNodesPerElement", keyword)) {
00306       ElemBlock& eb4 = elemBlocks_[currentElemBlockIndex_];
00307       int numNodes;
00308 
00309       readData(instr, numNodes);
00310 
00311       eb4.numNodesPerElement_ = numNodes;
00312       eb4.numFieldsPerNode_ = new int[numNodes];
00313       eb4.nodalFieldIDs_ = new int*[numNodes];
00314 
00315       for(int i=0; i<eb4.numElements_; i++) {
00316          eb4.elemConn_[i] = new GlobalID[numNodes];
00317       }
00318       
00319       return;
00320    }
00321 
00322    if (!std::strcmp("numElemDOF", keyword)) {
00323       ElemBlock& eb5 = elemBlocks_[currentElemBlockIndex_];
00324       int edof;
00325       readData(instr, edof);
00326       eb5.numElemDOF_ = edof;
00327 
00328       if (edof > 0) {
00329          eb5.elemDOFFieldIDs_ = new int[edof];
00330       }
00331 
00332       return;
00333    }
00334 
00335    if (!std::strcmp("elemDOFFieldIDs", keyword)) {
00336       ElemBlock& eb6 = elemBlocks_[currentElemBlockIndex_];
00337       int edof = eb6.numElemDOF_;
00338 
00339       for(int i=0; i<edof; i++) {
00340          int eDofFieldID;
00341          readData(instr, eDofFieldID);
00342          eb6.elemDOFFieldIDs_[i] = eDofFieldID;
00343       }
00344       return;
00345    }
00346 
00347    if (!std::strcmp("elemFormat", keyword)) {
00348       ElemBlock& eb7 = elemBlocks_[currentElemBlockIndex_];
00349       int ef;
00350       readData(instr, ef);
00351 
00352       eb7.elemFormat_ = ef;
00353       return;
00354    }
00355 
00356    if (!std::strcmp("numFieldsPerNode", keyword)) {
00357       ElemBlock& eb8 = elemBlocks_[currentElemBlockIndex_];
00358 
00359       int i;
00360       for(i=0; i<eb8.numNodesPerElement_; i++) {
00361          int nf;
00362          readData(instr, nf);
00363          eb8.numFieldsPerNode_[i] = nf;
00364          eb8.nodalFieldIDs_[i] = new int[nf];
00365       }
00366 
00367       return;
00368    }
00369 
00370    if (!std::strcmp("nodalFieldIDs", keyword)) {
00371       ElemBlock& eb9 = elemBlocks_[currentElemBlockIndex_];
00372 
00373       int i, numStiffRows = 0;
00374       for(i=0; i<eb9.numNodesPerElement_; i++) {
00375          for(int j=0; j<eb9.numFieldsPerNode_[i]; j++) {
00376             int nfid;
00377             readData(instr, nfid);
00378             eb9.nodalFieldIDs_[i][j] = nfid;
00379 
00380             numStiffRows += getFieldSize(nfid);
00381          }
00382       }
00383 
00384       numStiffRows += eb9.numElemDOF_;
00385 
00386       eb9.numStiffRows_ = numStiffRows;
00387 
00388       for(i=0; i<eb9.numElements_; i++) {
00389          eb9.elemStiff_[i] = new double*[numStiffRows];
00390          eb9.elemLoad_[i] = new double[numStiffRows];
00391          for(int j=0; j<numStiffRows; j++) {
00392             eb9.elemStiff_[i][j] = new double[numStiffRows];
00393          }
00394       }
00395 
00396       return;
00397    }
00398 
00399    if (!std::strcmp("elemID", keyword)) {
00400       ElemBlock& eb10 = elemBlocks_[currentElemBlockIndex_];
00401 
00402       int i, tmp;
00403       readData(instr, tmp);
00404       eb10.elemIDs_[currentElemIndex_] = (GlobalID)tmp;
00405 
00406       int* conn = eb10.elemConn_[currentElemIndex_];
00407 
00408       for(i=0; i<eb10.numNodesPerElement_; i++) {
00409          readData(instr, conn[i]);
00410       }
00411 
00412       double** stiff = eb10.elemStiff_[currentElemIndex_];
00413 
00414       for(i=0; i<eb10.numStiffRows_; i++) {
00415          for(int j=0; j<eb10.numStiffRows_; j++) {
00416             readData(instr, stiff[i][j]);
00417          }
00418       }
00419 
00420       double* load = eb10.elemLoad_[currentElemIndex_];
00421 
00422       for(i=0; i<eb10.numStiffRows_; i++) {
00423          readData(instr, load[i]);
00424       }
00425 
00426       currentElemIndex_++;
00427 
00428       return;
00429    }
00430 
00431    if (!std::strcmp("numSharedNodeSets", keyword)) {
00432       readData(instr, numSharedNodeSets_);
00433 
00434       if (numSharedNodeSets_ == 0) return;
00435 
00436       sharedNodeSets_ = new CommNodeSet[numSharedNodeSets_];
00437 
00438       currentShIndex_ = 0;
00439 
00440       for(int i=0; i<numSharedNodeSets_; i++) {
00441          CommNodeSet& shSet = sharedNodeSets_[currentShIndex_++];
00442 
00443          int j, nn;
00444          readData(instr, nn);
00445          shSet.numNodes_ = nn;
00446 
00447          shSet.nodeIDs_ = new GlobalID[nn];
00448 
00449          for(j=0; j<nn; j++) {
00450             int tmp;
00451             readData(instr, tmp);
00452             shSet.nodeIDs_[j] = (GlobalID)tmp;
00453          }
00454 
00455          shSet.procsPerNode_ = new int[nn];
00456 
00457          for(j=0; j<nn; j++) {
00458             int tmp;
00459             readData(instr, tmp);
00460             shSet.procsPerNode_[j] = tmp;
00461          }
00462 
00463          shSet.procs_ = new int*[nn];
00464 
00465          for(j=0; j<nn; j++) {
00466             shSet.procs_[j] = new int[shSet.procsPerNode_[j]];
00467             for(int k=0; k<shSet.procsPerNode_[j]; k++) {
00468                readData(instr, shSet.procs_[j][k]);
00469             }
00470          }
00471       }
00472 
00473       return;
00474    }
00475 
00476    if (!std::strcmp("numBCNodeSets", keyword)) {
00477       readData(instr, numBCNodeSets_);
00478 
00479       if (numBCNodeSets_ == 0) return;
00480 
00481       bcNodeSets_ = new BCNodeSet[numBCNodeSets_];
00482 
00483       currentBCIndex_ = 0;
00484 
00485       for(int i=0; i<numBCNodeSets_; i++) {
00486          BCNodeSet& bcSet = bcNodeSets_[currentBCIndex_++];
00487 
00488          int j, nn;
00489          readData(instr, nn);
00490          bcSet.numNodes_ = nn;
00491 
00492          readData(instr, bcSet.fieldID_);
00493 
00494          int field_offset;
00495          readData(instr, field_offset);
00496          
00497          bcSet.nodeIDs_ = new GlobalID[nn];
00498          bcSet.offsetsIntoField_ = new int[nn];
00499          bcSet.prescribed_values_ = new double[nn];
00500 
00501          for(j=0; j<nn; ++j) bcSet.offsetsIntoField_[j] = field_offset;
00502 
00503          for(j=0; j<nn; j++) {
00504             readData(instr, bcSet.nodeIDs_[j]);
00505             readData(instr, bcSet.prescribed_values_[j]);
00506          }
00507       }
00508 
00509       return;
00510    }
00511 
00512    if (!std::strcmp("numCRMultSets", keyword)) {
00513       readData(instr, numCRMultSets_);
00514 
00515       if (numCRMultSets_ == 0) return;
00516 
00517       crMultSets_ = new CRSet[numCRMultSets_];
00518 
00519       for(int i=0; i<numCRMultSets_; i++) {
00520          CRSet& cr1 = crMultSets_[i];
00521 
00522    int dummy;
00523          readData(instr, dummy);//used to be numCRs_
00524          readData(instr, cr1.numNodes_);
00525 
00526          cr1.nodeIDs_ = new GlobalID*[1];
00527          cr1.fieldIDs_ = new int[cr1.numNodes_];
00528 
00529          int j;
00530          for(j=0; j<1; j++) {
00531             cr1.nodeIDs_[j] = new GlobalID[cr1.numNodes_];
00532 
00533             for(int k=0; k<cr1.numNodes_; k++) {
00534                readData(instr, cr1.nodeIDs_[j][k]);
00535             }
00536          }
00537 
00538          for(j=0; j<cr1.numNodes_; j++) {
00539             readData(instr, cr1.fieldIDs_[j]);
00540          }
00541 
00542          int len = 0;
00543          for(j=0; j<cr1.numNodes_; j++) {
00544             len += getFieldSize(cr1.fieldIDs_[j]);
00545          }
00546          cr1.weights_ = new double[len];
00547 
00548          int offset = 0;
00549          for(j=0; j<cr1.numNodes_; j++) {
00550             int size = getFieldSize(cr1.fieldIDs_[j]);
00551 
00552             for(int k=0; k<size; k++) {
00553                readData(instr, cr1.weights_[offset++]);
00554             }
00555          }
00556 
00557          cr1.values_ = new double[1];
00558          for(j=0; j<1; j++) {
00559             readData(instr, cr1.values_[j]);
00560          }
00561       }
00562 
00563       return;
00564    }
00565 
00566    if (!std::strcmp("numCoefAccessPatterns", keyword)) {
00567      readData(instr, numCoefAccessPatterns_);
00568 
00569      if (numCoefAccessPatterns_ == 0) return;
00570 
00571      accessPatterns_ = new AccessPattern[numCoefAccessPatterns_];
00572      for(int i=0; i<numCoefAccessPatterns_; i++) {
00573        AccessPattern& patt = accessPatterns_[i];
00574 
00575        readData(instr, patt.ID_);
00576        readData(instr, patt.numRowIDs_);
00577        if (patt.numRowIDs_ <= 0) {
00578    FEI_CERR << "DataReader ERROR, numRowIDs_ <=0"<<FEI_ENDL;
00579    return;
00580        }
00581 
00582        patt.numFieldsPerRow_ = new int[patt.numRowIDs_];
00583        int j;
00584        for(j=0; j<patt.numRowIDs_; j++) {
00585    readData(instr, patt.numFieldsPerRow_[j]);
00586        }
00587 
00588        patt.rowFieldIDs_ = new int*[patt.numRowIDs_];
00589        for(j=0; j<patt.numRowIDs_; j++) {
00590    patt.rowFieldIDs_[j] = new int[patt.numFieldsPerRow_[j]];
00591        }
00592 
00593        for(int r=0; r<patt.numRowIDs_; r++) {
00594    for(int c=0; c<patt.numFieldsPerRow_[r]; c++) {
00595      readData(instr, patt.rowFieldIDs_[r][c]);
00596    }
00597        }
00598 
00599        readData(instr, patt.numColIDsPerRow_);
00600        if (patt.numColIDsPerRow_ <= 0) {
00601    FEI_CERR << "DataReader ERROR, numColIDsPerRow_ <=0"<<FEI_ENDL;
00602    return;
00603        }
00604        
00605        patt.numFieldsPerCol_ = new int[patt.numColIDsPerRow_];
00606        for(j=0; j<patt.numColIDsPerRow_; j++) {
00607    readData(instr, patt.numFieldsPerCol_[j]);
00608        }
00609 
00610        patt.colFieldIDs_ = new int*[patt.numColIDsPerRow_];
00611        for(j=0; j<patt.numColIDsPerRow_; j++) {
00612    patt.colFieldIDs_[j] = new int[patt.numFieldsPerCol_[j]];
00613        }
00614 
00615        for(int rr=0; rr<patt.numColIDsPerRow_; rr++) {
00616    for(int c=0; c<patt.numFieldsPerCol_[rr]; c++) {
00617      readData(instr, patt.colFieldIDs_[rr][c]);
00618    }
00619        }
00620 
00621        readData(instr, patt.interleaveStrategy_);
00622      }
00623 
00624      return;
00625    }
00626 
00627    if (!std::strcmp("coefAccess", keyword)) {
00628      int i, patternID = -1;
00629      readData(instr, patternID);
00630 
00631      //find the access-pattern corresponding to this coef-access.
00632      int index = -1;
00633      for(i=0; i<numCoefAccessPatterns_; i++) {
00634        if (accessPatterns_[i].ID_ == patternID) index = i;
00635      }
00636 
00637      if (index < 0) {
00638        FEI_CERR << "DataReader ERROR, patternID " << patternID << " not found."<<FEI_ENDL;
00639        return;
00640      }
00641 
00642      AccessPattern& patt = accessPatterns_[index];
00643 
00644      //now lengthen the list of coef-accesses.
00645      CoefAccess* newAccesses = new CoefAccess[numCoefAccesses_+1];
00646      for(i=0; i<numCoefAccesses_; i++) newAccesses[i] = coefAccesses_[i];
00647 
00648      delete [] coefAccesses_;
00649      coefAccesses_ = newAccesses;
00650 
00651      CoefAccess& coefAcc = coefAccesses_[numCoefAccesses_];
00652 
00653      coefAcc.patternID_ = patternID;
00654 
00655      coefAcc.numRowIDs_ = patt.numRowIDs_;
00656      coefAcc.numColIDsPerRow_ = patt.numColIDsPerRow_;
00657 
00658      if (coefAcc.numRowIDs_ <= 0 || coefAcc.numColIDsPerRow_ <= 0) {
00659        FEI_CERR << "DataReader ERROR, coef-access has 0 rows or cols." << FEI_ENDL;
00660        return;
00661      }
00662 
00663      coefAcc.rowIDs_ = new GlobalID[coefAcc.numRowIDs_];
00664      for(i=0; i<coefAcc.numRowIDs_; i++) {
00665        readData(instr, coefAcc.rowIDs_[i]);
00666      }
00667 
00668      int len = coefAcc.numRowIDs_ * coefAcc.numColIDsPerRow_;
00669      coefAcc.colIDs_ = new GlobalID[len];
00670      for(i=0; i<len; i++) {
00671        readData(instr, coefAcc.colIDs_[i]);
00672      }
00673 
00674      //calculate numRowCoefs.
00675      coefAcc.numRowCoefs_ = 0;
00676      for(i=0; i<coefAcc.numRowIDs_; i++) {
00677        for(int j=0; j<patt.numFieldsPerRow_[i]; j++) {
00678    coefAcc.numRowCoefs_ += getFieldSize(patt.rowFieldIDs_[i][j]);
00679        }
00680      }
00681 
00682      //calculate numColCoefs.
00683      coefAcc.numColCoefs_ = 0;
00684      for(i=0; i<coefAcc.numColIDsPerRow_; i++) {
00685        for(int j=0; j<patt.numFieldsPerCol_[i]; j++) {
00686    coefAcc.numColCoefs_ += getFieldSize(patt.colFieldIDs_[i][j]);
00687        }
00688      }
00689 
00690      len = coefAcc.numRowCoefs_*coefAcc.numColCoefs_;
00691      coefAcc.coefs_ = new double[len];
00692      int offset = 0;
00693      //now read the coefficients-table.
00694      for(i=0; i<len; i++) {
00695        readData(instr, coefAcc.coefs_[offset++]);
00696      }
00697 
00698      numCoefAccesses_++;
00699      return;
00700    }
00701 
00702    if (!std::strcmp("numSlaveVariables", keyword)) {
00703       readData(instr, numSlaveVars_);
00704 
00705       if (numSlaveVars_ == 0) return;
00706 
00707       slaveVars_ = new CRSet[numSlaveVars_];
00708 
00709       for(int i=0; i<numSlaveVars_; i++) {
00710          CRSet& cr2 = slaveVars_[i];
00711 
00712          readData(instr, cr2.slaveNodeID_);
00713          readData(instr, cr2.slaveFieldID_);
00714    readData(instr, cr2.slaveOffset_);
00715 
00716    readData(instr, cr2.numNodes_);
00717          cr2.nodeIDs_ = new GlobalID*[1];
00718    cr2.nodeIDs_[0] = new GlobalID[cr2.numNodes_];
00719          cr2.fieldIDs_ = new int[cr2.numNodes_];
00720 
00721          int j;
00722    for(int k=0; k<cr2.numNodes_; k++) {
00723      readData(instr, cr2.nodeIDs_[0][k]);
00724    }
00725 
00726          for(j=0; j<cr2.numNodes_; j++) {
00727             readData(instr, cr2.fieldIDs_[j]);
00728          }
00729 
00730          int len = 0;
00731          for(j=0; j<cr2.numNodes_; j++) {
00732             len += getFieldSize(cr2.fieldIDs_[j]);
00733          }
00734          cr2.weights_ = new double[len];
00735 
00736          int offset = 0;
00737          for(j=0; j<cr2.numNodes_; j++) {
00738             int size = getFieldSize(cr2.fieldIDs_[j]);
00739 
00740             for(int k=0; k<size; k++) {
00741                readData(instr, cr2.weights_[offset++]);
00742             }
00743          }
00744 
00745    cr2.values_ = new double[1];
00746    readData(instr, cr2.values_[0]);
00747       }
00748 
00749       return;
00750    }
00751 
00752    if (!std::strcmp("numCRPenSets", keyword)) {
00753       readData(instr, numCRPenSets_);
00754 
00755       if (numCRPenSets_ == 0) return;
00756 
00757       crPenSets_ = new CRSet[numCRPenSets_];
00758 
00759       for(int i=0; i<numCRPenSets_; i++) {
00760          CRSet& cr3 = crPenSets_[i];
00761 
00762    int dummy;
00763          readData(instr, dummy);//used to be numCRs_
00764          readData(instr, cr3.numNodes_);
00765 
00766          cr3.nodeIDs_ = new GlobalID*[1];
00767          cr3.fieldIDs_ = new int[cr3.numNodes_];
00768 
00769          int j;
00770          for(j=0; j<1; j++) {
00771             cr3.nodeIDs_[j] = new GlobalID[cr3.numNodes_];
00772 
00773             for(int k=0; k<cr3.numNodes_; k++) {
00774                readData(instr, cr3.nodeIDs_[j][k]);
00775             }
00776          }
00777 
00778          for(j=0; j<cr3.numNodes_; j++) {
00779             readData(instr, cr3.fieldIDs_[j]);
00780          }
00781 
00782          int len3 = 0;
00783          for(j=0; j<cr3.numNodes_; j++) {
00784             len3 += getFieldSize(cr3.fieldIDs_[j]);
00785          }
00786          cr3.weights_ = new double[len3];
00787 
00788          int offset3 = 0;
00789          for(j=0; j<cr3.numNodes_; j++) {
00790             int size3 = getFieldSize(cr3.fieldIDs_[j]);
00791 
00792             for(int k=0; k<size3; k++) {
00793         double dummy3;
00794         readData(instr, dummy3);
00795         cr3.weights_[offset3++] = dummy3;
00796             }
00797          }
00798 
00799          cr3.values_ = new double[1];
00800          for(j=0; j<1; j++) {
00801             readData(instr, cr3.values_[j]);
00802          }
00803 
00804          cr3.penValues_ = new double[1];
00805          for(j=0; j<1; j++) {
00806             readData(instr, cr3.penValues_[j]);
00807          }
00808       }
00809 
00810       return;
00811    }
00812 }
00813 
00814 //==============================================================================
00815 int DataReader::getFieldSize(int fieldID) {
00816    for(int i=0; i<numFields_; i++) {
00817       if (fieldID == fieldIDs_[i]) return(fieldSizes_[i]);
00818    }
00819 
00820    FEI_CERR << "DataReader: ERROR, trying to find size of non-existent field."
00821         << FEI_ENDL;
00822    return(0);
00823 }
00824 
00825 //==============================================================================
00826 void DataReader::readData(FEI_ISTREAM* instr, int& n) {
00827    int err = skipWhite(instr);
00828    if (err) return;
00829    (*instr) >> n;
00830 }
00831 
00832 //==============================================================================
00833 void DataReader::readData(FEI_ISTREAM* instr, double& val) {
00834    int err = skipWhite(instr);
00835    if (err) return;
00836    (*instr) >> val;
00837 }
00838 

Generated on Tue Jul 13 09:27:44 2010 for FEI by  doxygen 1.4.7