Sierra Toolkit Version of the Day
FEMMetaData.hpp
00001 #ifndef stk_mesh_FEMMetaData_hpp
00002 #define stk_mesh_FEMMetaData_hpp
00003 
00004 #include <stk_util/environment/ReportHandler.hpp>
00005 #include <stk_util/util/string_case_compare.hpp>
00006 #include <stk_mesh/base/Types.hpp>
00007 #include <stk_mesh/base/MetaData.hpp>
00008 #include <stk_mesh/base/BulkData.hpp> // TODO:  Remove!
00009 #include <stk_mesh/fem/CellTopology.hpp>
00010 
00011 #include <vector>
00012 #include <string>
00013 
00014 namespace stk {
00015 namespace mesh {
00016 namespace fem {
00017 
00018 
00044 // 02/10/11 FEMMetaData Todo:
00045 // * Implement get_cell_topology for Part.
00046 // * Implement declare_part with cell topology
00047 // Non-critical:
00048 // * Implement stk::mesh::fem::get namespace to include getters for MetaData,
00049 //   BulkData, FEMMetaData, FEMBulkData, CellTopology from things like Part,
00050 //   Bucket, Entity, etc.
00051 // * Create impl class inside the handle classes to hold their parent pointer
00052 //   and a friend to the getter above.
00053 
00054 class FEMMetaData {
00055   public:
00056 
00058   typedef std::map<fem::CellTopology, std::pair<Part *, EntityRank> > CellTopologyPartEntityRankMap;
00060   typedef std::vector<fem::CellTopology> PartCellTopologyVector;
00061 
00062 
00063 #ifdef SWIG   //SRK from NLM, this is to avoid pulling in a bunch more headers just to define EntityRank
00064   enum
00065   {
00066     INVALID_RANK = stk::mesh::InvalidEntityRank,
00067     NODE_RANK = 0u,
00068     EDGE_RANK = 1u,
00069     FACE_RANK = 2u,
00070     VOLUME_RANK = 3u
00071   };
00072 #else
00073   static const EntityRank INVALID_RANK = stk::mesh::InvalidEntityRank;
00074   static const EntityRank NODE_RANK = 0u;
00075   static const EntityRank EDGE_RANK = 1u;
00076   static const EntityRank FACE_RANK = 2u;
00077   static const EntityRank VOLUME_RANK = 3u;
00078 #endif
00079 
00080   FEMMetaData();
00081   ~FEMMetaData() {}
00082 
00086   FEMMetaData(size_t spatial_dimension,
00087               const std::vector<std::string>& in_entity_rank_names = std::vector<std::string>());
00088 
00089 
00093 
00098   void FEM_initialize(
00099       size_t spatial_dimension,
00100       const std::vector<std::string>& in_entity_rank_names = std::vector<std::string>()
00101       );
00102 
00105   bool is_FEM_initialized() const
00106   {
00107     return m_fem_initialized;
00108   }
00109 
00110   // NOTE: This is a temporary function that will be removed once a FEMBulkData exists.
00113   inline static MetaData & get_meta_data( FEMMetaData & fem_meta )
00114     { return fem_meta.m_meta_data; }
00115 
00118   size_t spatial_dimension() const
00119   {
00120     return m_spatial_dimension;
00121   }
00122 
00125   EntityRank node_rank() const
00126   {
00127     return NODE_RANK;
00128   }
00129 
00132   EntityRank edge_rank() const
00133   {
00134     return EDGE_RANK;
00135   }
00136 
00139   EntityRank face_rank() const
00140   {
00141     return FACE_RANK;
00142   }
00143 
00146   EntityRank volume_rank() const
00147   {
00148     return VOLUME_RANK;
00149   }
00150 
00153   EntityRank side_rank() const
00154   {
00155     return m_side_rank;
00156   }
00157 
00160   EntityRank element_rank() const
00161   {
00162     return m_element_rank;
00163   }
00164   //  void check_topo_db();
00165 
00169   bool check_rank(EntityRank rank) const;
00170 
00177   void register_cell_topology(const fem::CellTopology cell_topology, EntityRank in_entity_rank);
00178 
00182   Part &get_cell_topology_root_part(const fem::CellTopology cell_topology) const;
00183 
00188   fem::CellTopology get_cell_topology( const Part & part) const;
00189 
00190   fem::CellTopology get_cell_topology( const std::string & topology_name) const;
00191 
00196   EntityRank get_entity_rank(const fem::CellTopology cell_topology) const;
00197 
00200   inline static FEMMetaData & get ( const MetaData & meta )
00201     { return *const_cast<FEMMetaData * >(meta.get_attribute<FEMMetaData>()); }
00202 
00205   inline static FEMMetaData & get( const Part & part )
00206     { return FEMMetaData::get(MetaData::get(part)); }
00207 
00210   inline static FEMMetaData & get( const FieldBase & field )
00211     { return FEMMetaData::get(MetaData::get(field)); }
00212 
00215   inline static FEMMetaData & get( const PropertyBase & property )
00216     { return FEMMetaData::get(MetaData::get(property)); }
00217 
00220   inline static FEMMetaData & get( const BulkData & bulk_data )
00221     { return FEMMetaData::get(MetaData::get(bulk_data)); }
00222 
00225   inline static FEMMetaData & get( const Bucket & bucket )
00226     { return FEMMetaData::get(MetaData::get(bucket)); }
00227 
00230   inline static FEMMetaData & get( const Entity & entity )
00231     { return FEMMetaData::get(MetaData::get(entity)); }
00232 
00235   inline static FEMMetaData & get( const Ghosting & ghost )
00236     { return FEMMetaData::get(MetaData::get(ghost)); }
00237 
00240   Part &declare_part( const std::string &name, fem::CellTopology cell_topology)
00241   {
00242     ThrowRequireMsg(is_FEM_initialized(),"FEMMetaData::declare_part: FEM_initialize() must be called before this function");
00243     Part &root_part = get_cell_topology_root_part(cell_topology);
00244     EntityRank primary_entity_rank = root_part.primary_entity_rank();
00245     Part & part = m_meta_data.declare_part(name, primary_entity_rank);
00246     declare_part_subset(root_part, part);
00247     return part;
00248   }
00249 
00252   template< class Top >
00253   Part &declare_part(const std::string &name) {
00254     return declare_part(name, shards::getCellTopologyData<Top>());
00255   }
00256 
00260 
00264 
00265   //------------------------------------
00272   Part & universal_part() const { return m_meta_data.universal_part(); }
00273 
00277   Part & locally_owned_part()  const { return m_meta_data.locally_owned_part(); }
00278 
00282   Part & globally_shared_part() const { return m_meta_data.globally_shared_part(); }
00283 
00284   //------------------------------------
00294 
00295   Part * get_part( const std::string & p_name,
00296                    const char * required_by = NULL ) const
00297     { return m_meta_data.get_part(p_name,required_by); }
00298 
00300   Part & get_part( unsigned ord ) const
00301     { return m_meta_data.get_part(ord); }
00302 
00304   const PartVector & get_parts() const
00305     { return m_meta_data.get_parts(); }
00306 
00314   Part & declare_part( const std::string & p_name, EntityRank rank )
00315     { return m_meta_data.declare_part(p_name,rank); }
00316 
00322   Part & declare_part( const std::string & p_name)
00323     { return m_meta_data.declare_part(p_name); }
00324 
00329   void declare_part_subset( Part & superset , Part & subset );
00330 
00340   void declare_part_relation( Part & root_part ,
00341                               relation_stencil_ptr stencil ,
00342                               Part & target_part )
00343     { m_meta_data.declare_part_relation(root_part, stencil, target_part); }
00344 
00348   void set_entity_rank_names(const std::vector<std::string> &in_entity_rank_names)
00349   {
00350     m_entity_rank_names = in_entity_rank_names;
00351     m_meta_data.set_entity_rank_names(in_entity_rank_names);
00352   }
00353 
00356   EntityRank entity_rank( const std::string &name ) const
00357   {
00358     EntityRank my_entity_rank = InvalidEntityRank;
00359 
00360     for (size_t i = 0; i < m_entity_rank_names.size(); ++i)
00361       if (equal_case(name, m_entity_rank_names[i])) {
00362         my_entity_rank = i;
00363       break;
00364       }
00365     return my_entity_rank;
00366   }
00367 
00370   const std::vector<std::string> & entity_rank_names() const
00371   {
00372     return m_entity_rank_names;
00373   }
00374 
00377   std::vector<std::string>::size_type entity_rank_count() const
00378   {
00379     return m_entity_rank_names.size();
00380   }
00381 
00384   const std::string & entity_rank_name( EntityRank in_entity_rank ) const
00385   {
00386     ThrowErrorMsgIf( in_entity_rank >= m_entity_rank_names.size(),
00387         "entity-rank " << in_entity_rank <<
00388         " out of range. Must be in range 0.." << m_entity_rank_names.size());
00389     return m_entity_rank_names[in_entity_rank];
00390   }
00391 
00394   bool is_valid_entity_rank(EntityRank rank) const
00395   {
00396     return rank < m_entity_rank_names.size();
00397   }
00398 
00399   //------------------------------------
00410   template< class field_type >
00411   field_type * get_field( const std::string & name ) const
00412     { return m_meta_data.get_field<field_type>(name); }
00413 
00415   const FieldVector & get_fields() const {
00416     return m_meta_data.get_fields();
00417   }
00418 
00426   template< class field_type >
00427   field_type & declare_field( const std::string & name ,
00428                               unsigned number_of_states = 1 )
00429     { return m_meta_data.declare_field<field_type>( name, number_of_states ); }
00430 
00448   template< class PointerFieldType , class ReferencedFieldType >
00449   void declare_field_relation( PointerFieldType & pointer_field ,
00450                                relation_stencil_ptr stencil ,
00451                                ReferencedFieldType & referenced_field )
00452     { return m_meta_data.declare_field_relation( pointer_field, stencil, referenced_field ); }
00453 
00455   const std::vector<FieldRelation> & get_field_relations() const
00456     { return m_meta_data.get_field_relations(); }
00457 
00466   void commit()
00467     { m_meta_data.commit(); }
00468 
00470   bool is_commit() const
00471     { return m_meta_data.is_commit(); }
00472 
00473   //------------------------------------
00474 
00480   FieldBase * declare_field_base(
00481     const std::string & arg_name,
00482     const DataTraits  & arg_traits ,
00483     unsigned            arg_rank ,
00484     const shards::ArrayDimTag * const * arg_dim_tags ,
00485     unsigned arg_num_states )
00486     { return m_meta_data.declare_field_base( arg_name, arg_traits, arg_rank, arg_dim_tags, arg_num_states); }
00487 
00490   void declare_field_restriction( FieldBase      & arg_field ,
00491                                   EntityRank       arg_entity_rank ,
00492                                   const Part     & arg_part ,
00493                                   const unsigned * arg_stride ,
00494                                   const void     * arg_init_value = NULL)
00495     { m_meta_data.declare_field_restriction(arg_field, arg_entity_rank, arg_part, arg_stride, arg_init_value); }
00496 
00497   private: // functions
00498 
00499     Part & declare_internal_part( const std::string & p_name, EntityRank rank )
00500     { return m_meta_data.declare_internal_part(p_name,rank); }
00501 
00502     void internal_set_spatial_dimension_and_ranks(size_t spatial_dimension);
00503 
00504     void internal_declare_known_cell_topology_parts();
00505 
00506   private: // data
00507     MetaData                      m_meta_data;
00508     bool                          m_fem_initialized;
00509     size_t                        m_spatial_dimension;
00510     EntityRank                    m_side_rank;
00511     EntityRank                    m_element_rank;
00512     std::vector< std::string >    m_entity_rank_names;
00514     CellTopologyPartEntityRankMap m_cellTopologyPartEntityRankMap;
00516     PartCellTopologyVector        m_partCellTopologyVector;
00517 };
00518 
00521 bool is_cell_topology_root_part(const Part & part);
00522 
00524 void set_cell_topology( Part &part, const fem::CellTopology cell_topology);
00525 
00527 template<class Topology>
00528 inline void set_cell_topology(Part & part)
00529 {
00530   stk::mesh::fem::set_cell_topology(part, fem::CellTopology(shards::getCellTopologyData<Topology>()));
00531 }
00532 
00533 
00535 CellTopology get_cell_topology(const Bucket &bucket);
00536 
00537 
00539 inline CellTopology get_cell_topology(const Entity &entity) {
00540   return get_cell_topology(entity.bucket());
00541 }
00542 
00543 inline
00544 bool FEMMetaData::check_rank(EntityRank rank) const
00545 {
00546   return m_meta_data.check_rank(rank);
00547 }
00548 
00549 
00550 std::vector<std::string> entity_rank_names(size_t spatial_dimension);
00551 
00552 } // namespace fem
00553 } // namespace mesh
00554 } // namespace stk
00555 
00556 #endif //  stk_mesh_FEMMetaData_hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines