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