Sierra Toolkit Version of the Day
ImplDetails.cpp
00001 /*------------------------------------------------------------------------*/
00002 /*                 Copyright 2010 Sandia Corporation.                     */
00003 /*  Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive   */
00004 /*  license for use of this work by or on behalf of the U.S. Government.  */
00005 /*  Export of this program may require a license from the                 */
00006 /*  United States Government.                                             */
00007 /*------------------------------------------------------------------------*/
00008 
00009 
00010 #include <limits>
00011 #include <sstream>
00012 #include <stdexcept>
00013 
00014 #include <stk_linsys/ImplDetails.hpp>
00015 
00016 namespace stk {
00017 namespace linsys {
00018 namespace impl {
00019 
00020 int
00021 map_field_to_int(FieldIdMap& field_id_map,
00022                  const stk::mesh::FieldBase& field)
00023 {
00024   FieldIdMap::iterator iter = field_id_map.find(&field);
00025 
00026   if (iter == field_id_map.end()) {
00027     iter = field_id_map.insert(iter, std::make_pair(&field,field_id_map.size()));
00028   }
00029 
00030   return iter->second;
00031 }
00032 
00033 int
00034 query_field_to_int_mapping(const FieldIdMap& field_id_map,
00035                            const stk::mesh::FieldBase& field)
00036 {
00037   FieldIdMap::const_iterator iter = field_id_map.find(&field);
00038 
00039   if (iter == field_id_map.end()) {
00040     std::ostringstream msg;
00041     msg << "stk::linsys::query_field_to_int_mapping ERROR: "
00042         << " field with name '"<<field.name()<<"' not found in field-to-int map.";
00043     std::string str = msg.str();
00044     throw std::runtime_error(str);
00045   }
00046 
00047   return iter->second;
00048 }
00049 
00050 const stk::mesh::FieldBase*
00051 get_field(const FieldIdMap& field_id_map,
00052           int field_id)
00053 {
00054   FieldIdMap::const_iterator
00055     iter = field_id_map.begin(), iter_end = field_id_map.end();
00056 
00057   while(iter!=iter_end && iter->second != field_id) ++iter;
00058 
00059   if (iter == iter_end) {
00060     std::ostringstream msg;
00061     msg << "stk::linsys::get_dof ERROR: "
00062      << "field_id ("<<field_id<<") returned from fei query is not mapped to a stk::mesh::Field.";
00063     std::string str = msg.str();
00064     throw std::runtime_error(str);
00065   }
00066 
00067   return iter->first;
00068 }
00069 
00070 int entitytype_to_int(stk::mesh::EntityRank entity_rank)
00071 {
00072   int int_type = static_cast<int>(entity_rank);
00073 
00074   verify_convertible_to_int(entity_rank, "stk::linsys::entitytype_to_int");
00075 
00076   return int_type;
00077 }
00078 
00079 int entityid_to_int(stk::mesh::EntityId id)
00080 {
00081   int int_id = static_cast<int>(id);
00082 
00083   verify_convertible_to_int(id, "stk::linsys::entityid_to_int");
00084 
00085   return int_id;
00086 }
00087 
00088 }//namespace impl
00089 }//namespace linsys
00090 }//namespace stk
00091 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends