fei_ReverseMapper.cpp

00001 /*--------------------------------------------------------------------*/
00002 /*    Copyright 2009 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 <fei_ReverseMapper.hpp>
00010 #include <stdexcept>
00011 #include <sstream>
00012 #include <vector>
00013 #include <fei_VectorSpace.hpp>
00014 #include <snl_fei_RecordCollection.hpp>
00015 
00016 namespace fei {
00017 
00018 ReverseMapper::ReverseMapper(const VectorSpace& vspace)
00019  : eqnmap_()
00020 {
00021   std::vector<int> idTypes;
00022   vspace.getIDTypes(idTypes);
00023 
00024   const std::vector<int>& eqnNumbers = vspace.getEqnNumbers();
00025 
00026   for(size_t idt=0; idt<idTypes.size(); ++idt) {
00027     const snl_fei::RecordCollection* recordcollection = NULL;
00028     int err = vspace.getRecordCollection(idTypes[idt], recordcollection);
00029     if (err != 0) {
00030       throw std::runtime_error("fei::ReverseMapper ERROR, failed to retrieve record-collection.");
00031     }
00032 
00033     const snl_fei::RecordCollection::map_type&
00034         recordmap = recordcollection->getRecords();
00035 
00036     snl_fei::RecordCollection::map_type::const_iterator
00037       r_iter = recordmap.begin(),
00038       r_end  = recordmap.end();
00039 
00040     for(; r_iter != r_end; ++r_iter) {
00041       const fei::Record* record = r_iter->second;
00042 
00043       const fei::FieldMask* fm = record->getFieldMask();
00044       const std::vector<int>& fieldIDs = fm->getFieldIDs();
00045       const std::vector<int>& fieldSizes = fm->getFieldSizes();
00046 
00047       int offsetIntoEqnNumbers = record->getOffsetIntoEqnNumbers();
00048 
00049       for(size_t i=0; i<fieldIDs.size(); ++i) {
00050         int offset2 = 0, numInstances = 1;
00051         fm->getFieldEqnOffset(fieldIDs[i], offset2, numInstances);
00052 
00053         EqnRecord erec;
00054         erec.IDType = idTypes[idt];
00055         erec.ID = record->getID();
00056         erec.fieldID = fieldIDs[i];
00057 
00058         for(int j=0; j<fieldSizes[i]; ++j) {
00059           erec.offset = j;
00060           erec.global_eqn = eqnNumbers[offsetIntoEqnNumbers+offset2+j];
00061           eqnmap_.insert(std::make_pair(erec.global_eqn, erec));
00062         }
00063       }
00064     }
00065   }
00066 }
00067 
00068 ReverseMapper::~ReverseMapper()
00069 {
00070 }
00071 
00072 EqnRecord ReverseMapper::getEqnRecord(int global_eqn)
00073 {
00074   std::map<int,EqnRecord>::iterator
00075     iter = eqnmap_.find(global_eqn);
00076 
00077   if (iter == eqnmap_.end()) {
00078     std::ostringstream osstr;
00079     osstr << "fei::ReverseMapper::getEqnRecord ERROR, global_eqn="<<global_eqn
00080        << " not found.";
00081     throw std::runtime_error(osstr.str());
00082   }
00083 
00084   return iter->second;
00085 }
00086 
00087 }//namespace fei
00088 

Generated on Wed May 12 21:30:41 2010 for FEI by  doxygen 1.4.7