FEI  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fei_ReverseMapper.cpp
1 /*--------------------------------------------------------------------*/
2 /* Copyright 2009 Sandia Corporation. */
3 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
4 /* non-exclusive license for use of this work by or on behalf */
5 /* of the U.S. Government. Export of this program may require */
6 /* a license from the United States Government. */
7 /*--------------------------------------------------------------------*/
8 
9 #include <fei_ReverseMapper.hpp>
10 #include <stdexcept>
11 #include <sstream>
12 #include <vector>
13 #include <fei_VectorSpace.hpp>
14 #include <snl_fei_RecordCollection.hpp>
15 
16 namespace fei {
17 
19  : eqnmap_()
20 {
21  std::vector<int> idTypes;
22  vspace.getIDTypes(idTypes);
23 
24  const std::vector<int>& eqnNumbers = vspace.getEqnNumbers();
25 
26  for(size_t idt=0; idt<idTypes.size(); ++idt) {
27  const snl_fei::RecordCollection* recordcollection = NULL;
28  int err = vspace.getRecordCollection(idTypes[idt], recordcollection);
29  if (err != 0) {
30  throw std::runtime_error("fei::ReverseMapper ERROR, failed to retrieve record-collection.");
31  }
32 
33  const std::vector<fei::Record<int> >&
34  records = recordcollection->getRecords();
35 
36  for(size_t i=0; i<records.size(); ++i) {
37  const fei::Record<int>* record = &records[i];
38 
39  const fei::FieldMask* fm = record->getFieldMask();
40  const std::vector<int>& fieldIDs = fm->getFieldIDs();
41  const std::vector<int>& fieldSizes = fm->getFieldSizes();
42 
43  int offsetIntoEqnNumbers = record->getOffsetIntoEqnNumbers();
44 
45  for(size_t i=0; i<fieldIDs.size(); ++i) {
46  int offset2 = 0;
47  int err = fm->getFieldEqnOffset(fieldIDs[i], offset2);
48  if (err != 0) {
49  continue;
50  }
51 
52  EqnRecord erec;
53  erec.IDType = idTypes[idt];
54  erec.ID = record->getID();
55  erec.fieldID = fieldIDs[i];
56 
57  for(int j=0; j<fieldSizes[i]; ++j) {
58  erec.offset = j;
59  erec.global_eqn = eqnNumbers[offsetIntoEqnNumbers+offset2+j];
60  eqnmap_.insert(std::make_pair(erec.global_eqn, erec));
61  }
62  }
63  }
64  }
65 }
66 
68 {
69 }
70 
71 EqnRecord ReverseMapper::getEqnRecord(int global_eqn, int option) const
72 {
73  std::map<int,EqnRecord>::const_iterator
74  iter = eqnmap_.find(global_eqn);
75 
76  if (iter == eqnmap_.end()) {
77  if (option == 1) {
78  EqnRecord erec;
79  erec.IDType = -1;
80  erec.ID = -1;
81  erec.fieldID = -1;
82  erec.offset = -1;
83  erec.global_eqn = -1;
84  return erec;
85  }
86 
87  std::ostringstream osstr;
88  osstr << "fei::ReverseMapper::getEqnRecord ERROR, global_eqn="<<global_eqn
89  << " not found.";
90  throw std::runtime_error(osstr.str());
91  }
92 
93  return iter->second;
94 }
95 
96 }//namespace fei
97 
std::vector< fei::Record< int > > & getRecords()
void getIDTypes(std::vector< int > &idTypes) const
ReverseMapper(const VectorSpace &vspace)
std::vector< int > & getFieldSizes()
std::vector< int > & getFieldIDs()
int getFieldEqnOffset(int fieldID, int &offset) const
GlobalIDType getID() const
Definition: fei_Record.hpp:46
int getOffsetIntoEqnNumbers() const
Definition: fei_Record.hpp:126
fei::FieldMask * getFieldMask()
Definition: fei_Record.hpp:106
int getRecordCollection(int idType, snl_fei::RecordCollection *&records)
std::vector< int > & getEqnNumbers()