Sierra Toolkit  Version of the Day
ImplDetails.cpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010 Sandia Corporation. */
3 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
4 /* license for use of this work by or on behalf of the U.S. Government. */
5 /* Export of this program may require a license from the */
6 /* United States Government. */
7 /*------------------------------------------------------------------------*/
8 
9 
10 #include <limits>
11 #include <sstream>
12 #include <stdexcept>
13 
14 #include <stk_linsys/ImplDetails.hpp>
15 
16 namespace stk_classic {
17 namespace linsys {
18 namespace impl {
19 
20 int
22  const stk_classic::mesh::FieldBase& field)
23 {
24  FieldIdMap::iterator iter = field_id_map.find(&field);
25 
26  if (iter == field_id_map.end()) {
27  iter = field_id_map.insert(iter, std::make_pair(&field,field_id_map.size()));
28  }
29 
30  return iter->second;
31 }
32 
33 int
35  const stk_classic::mesh::FieldBase& field)
36 {
37  FieldIdMap::const_iterator iter = field_id_map.find(&field);
38 
39  if (iter == field_id_map.end()) {
40  std::ostringstream msg;
41  msg << "stk_classic::linsys::query_field_to_int_mapping ERROR: "
42  << " field with name '"<<field.name()<<"' not found in field-to-int map.";
43  std::string str = msg.str();
44  throw std::runtime_error(str);
45  }
46 
47  return iter->second;
48 }
49 
51 get_field(const FieldIdMap& field_id_map,
52  int field_id)
53 {
54  FieldIdMap::const_iterator
55  iter = field_id_map.begin(), iter_end = field_id_map.end();
56 
57  while(iter!=iter_end && iter->second != field_id) ++iter;
58 
59  if (iter == iter_end) {
60  std::ostringstream msg;
61  msg << "stk_classic::linsys::get_dof ERROR: "
62  << "field_id ("<<field_id<<") returned from fei query is not mapped to a stk_classic::mesh::Field.";
63  std::string str = msg.str();
64  throw std::runtime_error(str);
65  }
66 
67  return iter->first;
68 }
69 
70 int entitytype_to_int(stk_classic::mesh::EntityRank entity_rank)
71 {
72  int int_type = static_cast<int>(entity_rank);
73 
74  verify_convertible_to_int(entity_rank, "stk_classic::linsys::entitytype_to_int");
75 
76  return int_type;
77 }
78 
79 int entityid_to_int(stk_classic::mesh::EntityId id)
80 {
81  int int_id = static_cast<int>(id);
82 
83  verify_convertible_to_int(id, "stk_classic::linsys::entityid_to_int");
84 
85  return int_id;
86 }
87 
88 }//namespace impl
89 }//namespace linsys
90 }//namespace stk_classic
91 
int entitytype_to_int(stk_classic::mesh::EntityRank entity_rank)
Definition: ImplDetails.cpp:70
const stk_classic::mesh::FieldBase * get_field(const FieldIdMap &field_id_map, int field_id)
Definition: ImplDetails.cpp:51
Field base class with an anonymous data type and anonymous multi-dimension.
Definition: FieldBase.hpp:53
std::map< const stk_classic::mesh::FieldBase *, int > FieldIdMap
Definition: FieldIdMap.hpp:20
int entityid_to_int(stk_classic::mesh::EntityId id)
Definition: ImplDetails.cpp:79
Sierra Toolkit.
int map_field_to_int(FieldIdMap &field_id_map, const stk_classic::mesh::FieldBase &field)
Definition: ImplDetails.cpp:21
int query_field_to_int_mapping(const FieldIdMap &field_id_map, const stk_classic::mesh::FieldBase &field)
Definition: ImplDetails.cpp:34
EntityRank entity_rank(const EntityKey &key)
Given an entity key, return an entity type (rank).
void verify_convertible_to_int(T id, const char *caller)
Definition: ImplDetails.hpp:67