FEI Version of the Day
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 std::vector<fei::Record<int> >&
00034         records = recordcollection->getRecords();
00035 
00036     for(size_t i=0; i<records.size(); ++i) {
00037       const fei::Record<int>* record = &records[i];
00038 
00039       const fei::FieldMask* fm = record->getFieldMask();
00040       const std::vector<int>& fieldIDs = fm->getFieldIDs();
00041       const std::vector<int>& fieldSizes = fm->getFieldSizes();
00042 
00043       int offsetIntoEqnNumbers = record->getOffsetIntoEqnNumbers();
00044 
00045       for(size_t i=0; i<fieldIDs.size(); ++i) {
00046         int offset2 = 0;
00047         fm->getFieldEqnOffset(fieldIDs[i], offset2);
00048 
00049         EqnRecord erec;
00050         erec.IDType = idTypes[idt];
00051         erec.ID = record->getID();
00052         erec.fieldID = fieldIDs[i];
00053 
00054         for(int j=0; j<fieldSizes[i]; ++j) {
00055           erec.offset = j;
00056           erec.global_eqn = eqnNumbers[offsetIntoEqnNumbers+offset2+j];
00057           eqnmap_.insert(std::make_pair(erec.global_eqn, erec));
00058         }
00059       }
00060     }
00061   }
00062 }
00063 
00064 ReverseMapper::~ReverseMapper()
00065 {
00066 }
00067 
00068 EqnRecord ReverseMapper::getEqnRecord(int global_eqn) const
00069 {
00070   std::map<int,EqnRecord>::const_iterator
00071     iter = eqnmap_.find(global_eqn);
00072 
00073   if (iter == eqnmap_.end()) {
00074     std::ostringstream osstr;
00075     osstr << "fei::ReverseMapper::getEqnRecord ERROR, global_eqn="<<global_eqn
00076        << " not found.";
00077     throw std::runtime_error(osstr.str());
00078   }
00079 
00080   return iter->second;
00081 }
00082 
00083 }//namespace fei
00084 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends