Sierra Toolkit  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FEMMetaData.hpp
1 #ifndef stk_mesh_FEMMetaData_hpp
2 #define stk_mesh_FEMMetaData_hpp
3 
4 #include <stk_util/environment/ReportHandler.hpp>
5 #include <stk_util/util/string_case_compare.hpp>
6 #include <stk_mesh/base/Types.hpp>
7 #include <stk_mesh/base/MetaData.hpp>
8 #include <stk_mesh/base/BulkData.hpp> // TODO: Remove!
9 #include <stk_mesh/fem/CellTopology.hpp>
10 
11 #include <vector>
12 #include <string>
13 
14 namespace stk_classic {
15 namespace mesh {
16 namespace fem {
17 
18 
44 // 02/10/11 FEMMetaData Todo:
45 // * Implement get_cell_topology for Part.
46 // * Implement declare_part with cell topology
47 // Non-critical:
48 // * Implement stk_classic::mesh::fem::get namespace to include getters for MetaData,
49 // BulkData, FEMMetaData, FEMBulkData, CellTopology from things like Part,
50 // Bucket, Entity, etc.
51 // * Create impl class inside the handle classes to hold their parent pointer
52 // and a friend to the getter above.
53 
54 class FEMMetaData {
55  public:
56 
58  typedef std::map<fem::CellTopology, std::pair<Part *, EntityRank> > CellTopologyPartEntityRankMap;
60  typedef std::vector<fem::CellTopology> PartCellTopologyVector;
61 
62 
63 #ifdef SWIG //SRK from NLM, this is to avoid pulling in a bunch more headers just to define EntityRank
64  enum
65  {
66  INVALID_RANK = stk_classic::mesh::InvalidEntityRank,
67  NODE_RANK = 0u,
68  EDGE_RANK = 1u,
69  FACE_RANK = 2u,
70  VOLUME_RANK = 3u
71  };
72 #else
73  static const EntityRank INVALID_RANK = stk_classic::mesh::InvalidEntityRank;
74  static const EntityRank NODE_RANK = 0u;
75  static const EntityRank EDGE_RANK = 1u;
76  static const EntityRank FACE_RANK = 2u;
77  static const EntityRank VOLUME_RANK = 3u;
78 #endif
79 
80  FEMMetaData();
81  ~FEMMetaData() {}
82 
86  FEMMetaData(size_t spatial_dimension,
87  const std::vector<std::string>& in_entity_rank_names = std::vector<std::string>());
88 
89 
93 
98  void FEM_initialize(
99  size_t spatial_dimension,
100  const std::vector<std::string>& in_entity_rank_names = std::vector<std::string>()
101  );
102 
105  bool is_FEM_initialized() const
106  {
107  return m_fem_initialized;
108  }
109 
110  // NOTE: This is a temporary function that will be removed once a FEMBulkData exists.
113  inline static MetaData & get_meta_data( FEMMetaData & fem_meta )
114  { return fem_meta.m_meta_data; }
115 
118  size_t spatial_dimension() const
119  {
120  return m_spatial_dimension;
121  }
122 
125  EntityRank node_rank() const
126  {
127  return NODE_RANK;
128  }
129 
132  EntityRank edge_rank() const
133  {
134  return EDGE_RANK;
135  }
136 
139  EntityRank face_rank() const
140  {
141  return FACE_RANK;
142  }
143 
146  EntityRank volume_rank() const
147  {
148  return VOLUME_RANK;
149  }
150 
153  EntityRank side_rank() const
154  {
155  return m_side_rank;
156  }
157 
160  EntityRank element_rank() const
161  {
162  return m_element_rank;
163  }
164  // void check_topo_db();
165 
169  bool check_rank(EntityRank rank) const;
170 
177  void register_cell_topology(const fem::CellTopology cell_topology, EntityRank in_entity_rank);
178 
182  Part &get_cell_topology_root_part(const fem::CellTopology cell_topology) const;
183 
188  fem::CellTopology get_cell_topology( const Part & part) const;
189 
190  fem::CellTopology get_cell_topology( const std::string & topology_name) const;
191 
196  EntityRank get_entity_rank(const fem::CellTopology cell_topology) const;
197 
200  inline static FEMMetaData & get ( const MetaData & meta )
201  { return *const_cast<FEMMetaData * >(meta.get_attribute<FEMMetaData>()); }
202 
205  inline static FEMMetaData & get( const Part & part )
206  { return FEMMetaData::get(MetaData::get(part)); }
207 
210  inline static FEMMetaData & get( const FieldBase & field )
211  { return FEMMetaData::get(MetaData::get(field)); }
212 
215  inline static FEMMetaData & get( const PropertyBase & property )
216  { return FEMMetaData::get(MetaData::get(property)); }
217 
220  inline static FEMMetaData & get( const BulkData & bulk_data )
221  { return FEMMetaData::get(MetaData::get(bulk_data)); }
222 
225  inline static FEMMetaData & get( const Bucket & bucket )
226  { return FEMMetaData::get(MetaData::get(bucket)); }
227 
230  inline static FEMMetaData & get( const Entity & entity )
231  { return FEMMetaData::get(MetaData::get(entity)); }
232 
235  inline static FEMMetaData & get( const Ghosting & ghost )
236  { return FEMMetaData::get(MetaData::get(ghost)); }
237 
240  Part &declare_part( const std::string &name, fem::CellTopology cell_topology)
241  {
242  ThrowRequireMsg(is_FEM_initialized(),"FEMMetaData::declare_part: FEM_initialize() must be called before this function");
243  Part &root_part = get_cell_topology_root_part(cell_topology);
244  EntityRank primary_entity_rank = root_part.primary_entity_rank();
245  Part & part = m_meta_data.declare_part(name, primary_entity_rank);
246  declare_part_subset(root_part, part);
247  return part;
248  }
249 
252  template< class Top >
253  Part &declare_part(const std::string &name) {
254  return declare_part(name, shards::getCellTopologyData<Top>());
255  }
256 
260 
264 
265  //------------------------------------
272  Part & universal_part() const { return m_meta_data.universal_part(); }
273 
277  Part & locally_owned_part() const { return m_meta_data.locally_owned_part(); }
278 
282  Part & globally_shared_part() const { return m_meta_data.globally_shared_part(); }
283 
284  //------------------------------------
294  Part * get_part( const std::string & p_name,
296  const char * required_by = NULL ) const
297  { return m_meta_data.get_part(p_name,required_by); }
298 
300  Part & get_part( unsigned ord ) const
301  { return m_meta_data.get_part(ord); }
302 
304  const PartVector & get_parts() const
305  { return m_meta_data.get_parts(); }
306 
314  Part & declare_part( const std::string & p_name, EntityRank rank )
315  { return m_meta_data.declare_part(p_name,rank); }
316 
322  Part & declare_part( const std::string & p_name)
323  { return m_meta_data.declare_part(p_name); }
324 
329  void declare_part_subset( Part & superset , Part & subset );
330 
340  void declare_part_relation( Part & root_part ,
341  relation_stencil_ptr stencil ,
342  Part & target_part )
343  { m_meta_data.declare_part_relation(root_part, stencil, target_part); }
344 
348  void set_entity_rank_names(const std::vector<std::string> &in_entity_rank_names)
349  {
350  m_entity_rank_names = in_entity_rank_names;
351  m_meta_data.set_entity_rank_names(in_entity_rank_names);
352  }
353 
356  EntityRank entity_rank( const std::string &name ) const
357  {
358  EntityRank my_entity_rank = InvalidEntityRank;
359 
360  for (size_t i = 0; i < m_entity_rank_names.size(); ++i)
361  if (equal_case(name, m_entity_rank_names[i])) {
362  my_entity_rank = i;
363  break;
364  }
365  return my_entity_rank;
366  }
367 
370  const std::vector<std::string> & entity_rank_names() const
371  {
372  return m_entity_rank_names;
373  }
374 
377  std::vector<std::string>::size_type entity_rank_count() const
378  {
379  return m_entity_rank_names.size();
380  }
381 
384  const std::string & entity_rank_name( EntityRank in_entity_rank ) const
385  {
386  ThrowErrorMsgIf( in_entity_rank >= m_entity_rank_names.size(),
387  "entity-rank " << in_entity_rank <<
388  " out of range. Must be in range 0.." << m_entity_rank_names.size());
389  return m_entity_rank_names[in_entity_rank];
390  }
391 
394  bool is_valid_entity_rank(EntityRank rank) const
395  {
396  return rank < m_entity_rank_names.size();
397  }
398 
399  //------------------------------------
410  template< class field_type >
411  field_type * get_field( const std::string & name ) const
412  { return m_meta_data.get_field<field_type>(name); }
413 
415  const FieldVector & get_fields() const {
416  return m_meta_data.get_fields();
417  }
418 
426  template< class field_type >
427  field_type & declare_field( const std::string & name ,
428  unsigned number_of_states = 1 )
429  { return m_meta_data.declare_field<field_type>( name, number_of_states ); }
430 
448  template< class PointerFieldType , class ReferencedFieldType >
449  void declare_field_relation( PointerFieldType & pointer_field ,
450  relation_stencil_ptr stencil ,
451  ReferencedFieldType & referenced_field )
452  { return m_meta_data.declare_field_relation( pointer_field, stencil, referenced_field ); }
453 
455  const std::vector<FieldRelation> & get_field_relations() const
456  { return m_meta_data.get_field_relations(); }
457 
466  void commit()
467  { m_meta_data.commit(); }
468 
470  bool is_commit() const
471  { return m_meta_data.is_commit(); }
472 
473  //------------------------------------
474 
481  const std::string & arg_name,
482  const DataTraits & arg_traits ,
483  unsigned arg_rank ,
484  const shards::ArrayDimTag * const * arg_dim_tags ,
485  unsigned arg_num_states )
486  { return m_meta_data.declare_field_base( arg_name, arg_traits, arg_rank, arg_dim_tags, arg_num_states); }
487 
491  EntityRank arg_entity_rank ,
492  const Part & arg_part ,
493  const unsigned * arg_stride ,
494  const void * arg_init_value = NULL)
495  { m_meta_data.declare_field_restriction(arg_field, arg_entity_rank, arg_part, arg_stride, arg_init_value); }
496 
497  private: // functions
498 
499  Part & declare_internal_part( const std::string & p_name, EntityRank rank )
500  { return m_meta_data.declare_internal_part(p_name,rank); }
501 
502  void internal_set_spatial_dimension_and_ranks(size_t spatial_dimension);
503 
504  void internal_declare_known_cell_topology_parts();
505 
506  private: // data
507  MetaData m_meta_data;
508  bool m_fem_initialized;
509  size_t m_spatial_dimension;
510  EntityRank m_side_rank;
511  EntityRank m_element_rank;
512  std::vector< std::string > m_entity_rank_names;
514  CellTopologyPartEntityRankMap m_cellTopologyPartEntityRankMap;
516  PartCellTopologyVector m_partCellTopologyVector;
517 };
518 
521 bool is_cell_topology_root_part(const Part & part);
522 
524 void set_cell_topology( Part &part, const fem::CellTopology cell_topology);
525 
527 template<class Topology>
528 inline void set_cell_topology(Part & part)
529 {
530  stk_classic::mesh::fem::set_cell_topology(part, fem::CellTopology(shards::getCellTopologyData<Topology>()));
531 }
532 
533 
535 CellTopology get_cell_topology(const Bucket &bucket);
536 
537 
539 inline CellTopology get_cell_topology(const Entity &entity) {
540  return get_cell_topology(entity.bucket());
541 }
542 
543 inline
544 bool FEMMetaData::check_rank(EntityRank rank) const
545 {
546  return m_meta_data.check_rank(rank);
547 }
548 
549 
550 std::vector<std::string> entity_rank_names(size_t spatial_dimension);
551 
552 } // namespace fem
553 } // namespace mesh
554 } // namespace stk_classic
555 
556 #endif // stk_mesh_FEMMetaData_hpp
const std::vector< FieldRelation > & get_field_relations() const
Get field relations.
EntityRank element_rank() const
Returns the element rank which is always equal to spatial dimension.
Part & locally_owned_part() const
Subset for the problem domain that is owned by the local process. Ghost entities are not members of t...
Definition: MetaData.hpp:93
bool is_commit() const
Query if the meta data manager is committed.
size_t spatial_dimension() const
Returns the spatial dimension that was passed in through FEM_initialize.
Part & locally_owned_part() const
Subset for the problem domain that is owned by the local process. Ghost entities are not members of t...
FEMMetaData is a class that implements a Finite Element Method skin on top of the Sierra Tool Kit Met...
Definition: FEMMetaData.hpp:54
Field base class with an anonymous data type and anonymous multi-dimension.
Definition: FieldBase.hpp:53
Part & declare_part(const std::string &p_name)
Declare a part of the given name and entity rank Redeclaration returns the previously declared part...
The manager of an integrated collection of parts and fields.
Definition: MetaData.hpp:56
int(* relation_stencil_ptr)(unsigned from_type, unsigned to_type, unsigned identifier)
A relation stencil maps entity relationships to ordinals.
Definition: Types.hpp:149
field_type * get_field(const std::string &name) const
Get a field, return NULL if it does not exist.
const std::string & entity_rank_name(EntityRank in_entity_rank) const
Return the name for a given entity rank as was specified in set_entity_rank_names.
Data for ghosting mesh entities.
Definition: Ghosting.hpp:28
void register_cell_topology(const fem::CellTopology cell_topology, EntityRank in_entity_rank)
This function is used to register new cell topologies and their associated ranks with FEMMetaData...
FieldBase * declare_field_base(const std::string &arg_name, const DataTraits &arg_traits, unsigned arg_rank, const shards::ArrayDimTag *const *arg_dim_tags, unsigned arg_num_states)
Declare a field via runtime type information.
EntityRank get_entity_rank(const fem::CellTopology cell_topology) const
Return the EntityRank that is associated with the given cell topology. In several cases...
bool check_rank(EntityRank rank) const
const PartVector & get_parts() const
Query all parts of the mesh ordered by the parts' ordinal.
Definition: MetaData.hpp:120
An application-defined subset of a problem domain.
Definition: Part.hpp:49
field_type * get_field(const std::string &name) const
Get a field, return NULL if it does not exist.
Part & get_cell_topology_root_part(const fem::CellTopology cell_topology) const
Return the root cell topology part associated with the given cell topology. This Part is created in r...
Part & declare_part(const std::string &name, fem::CellTopology cell_topology)
Declare a part with a given cell topology.
void declare_part_relation(Part &root_part, relation_stencil_ptr stencil, Part &target_part)
Declare an entity-relationship between parts.
bool is_valid_entity_rank(EntityRank rank) const
Return true if the given entity rank is valid.
void declare_field_restriction(FieldBase &arg_field, EntityRank arg_entity_rank, const Part &arg_part, const unsigned *arg_stride, const void *arg_init_value=NULL)
Declare a field restriction via runtime type information.
void set_entity_rank_names(const std::vector< std::string > &in_entity_rank_names)
Set the entity rank names in a vector. This also currently sets the maximum entity rank...
Part & globally_shared_part() const
Subset for the problem domain that is shared with another process. Ghost entities are not members of ...
const std::vector< std::string > & entity_rank_names() const
Return the set of entity rank names specified in set_entity_rank_names.
EntityRank side_rank() const
Returns the side rank which changes depending on spatial dimension.
void declare_part_subset(Part &superset, Part &subset)
Declare a superset-subset relationship between parts Note: Cell Topologies are induced through part s...
std::map< fem::CellTopology, std::pair< Part *, EntityRank > > CellTopologyPartEntityRankMap
CellTopologyPartEntityRankMap maps each Cell Topology to its root cell topology part and its associat...
Definition: FEMMetaData.hpp:58
Part & declare_part(const std::string &p_name, EntityRank rank)
Declare a part of the given name and entity rank Redeclaration returns the previously declared part...
Definition: MetaData.cpp:214
FieldBase * declare_field_base(const std::string &arg_name, const DataTraits &arg_traits, unsigned arg_rank, const shards::ArrayDimTag *const *arg_dim_tags, unsigned arg_num_states)
Declare a field via runtime type information.
Definition: MetaData.cpp:284
void declare_field_relation(PointerFieldType &pointer_field, relation_stencil_ptr stencil, ReferencedFieldType &referenced_field)
Declare a field relation.
void set_entity_rank_names(const std::vector< std::string > &entity_rank_names)
entity-rank names
Definition: MetaData.cpp:155
Manager for an integrated collection of entities, entity relations, and buckets of field data...
Definition: BulkData.hpp:49
const std::vector< FieldRelation > & get_field_relations() const
Get all field relations.
Definition: MetaData.hpp:270
static MetaData & get_meta_data(FEMMetaData &fem_meta)
Getter for MetaData off of a FEMMetaData object.
void commit()
Commit the part and field declarations so that the meta data manager can be used to create mesh bulk ...
Part & declare_part(const std::string &p_name, EntityRank rank)
Declare a part of the given name and entity rank Redeclaration returns the previously declared part...
field_type & declare_field(const std::string &name, unsigned number_of_states=1)
Declare a field of the given field_type, test name, and number of states.
const FieldVector & get_fields() const
Get all defined fields.
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
Definition: Entity.hpp:120
std::vector< fem::CellTopology > PartCellTopologyVector
PartCellTopologyVector is a fast-lookup vector of size equal to the number of parts.
Definition: FEMMetaData.hpp:60
Part & universal_part() const
Universal subset for the problem domain. All other parts are a subset of the universal part...
Part & get_part(unsigned ord) const
Get an existing part by its ordinal.
fem::CellTopology get_cell_topology(const Part &part) const
Return the cell topology associated with the given part. The cell topology is set on a part through p...
EntityRank edge_rank() const
Returns the edge rank which changes depending on spatial dimension.
Part * get_part(const std::string &p_name, const char *required_by=NULL) const
Get an existing part by its application-defined text name.
Definition: MetaData.cpp:185
unsigned primary_entity_rank() const
The primary entity type for this part.
Definition: Part.hpp:64
const FieldVector & get_fields() const
Get all defined fields.
Definition: MetaData.hpp:218
bool equal_case(const char *lhs, const char *rhs)
Case-insensitive equality compare.
Part & declare_part(const std::string &name)
Declare a part with a given cell topology.
bool is_FEM_initialized() const
This function returns whether this class has been initialized or not.
Part * get_part(const std::string &p_name, const char *required_by=NULL) const
Get an existing part by its application-defined text name.
EntityRank volume_rank() const
Returns the volume rank which changes depending on spatial dimension.
EntityRank entity_rank(const std::string &name) const
Return the rank for the given name that was provided in set_entity_rank_names.
std::vector< std::string >::size_type entity_rank_count() const
Return the maximum entity rank.
const PartVector & get_parts() const
Query all parts of the mesh ordered by the parts' ordinal.
void declare_part_relation(Part &root_part, relation_stencil_ptr stencil, Part &target_part)
Declare an entity-relationship between parts.
Definition: MetaData.cpp:257
field_type & declare_field(const std::string &name, unsigned number_of_states=1)
Declare a field of the given field_type, test name, and number of states.
std::vector< Part * > PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
Definition: Types.hpp:31
bool is_commit() const
Query if the meta data manager is committed.
Definition: MetaData.hpp:338
EntityRank node_rank() const
Returns the node rank, which is always zero.
static FEMMetaData & get(const MetaData &meta)
Getter for FEMMetaData off of a MetaData object.
void declare_field_relation(PointerFieldType &pointer_field, relation_stencil_ptr stencil, ReferencedFieldType &referenced_field)
Declare a field relation.
Part & globally_shared_part() const
Subset for the problem domain that is shared with another process. Ghost entities are not members of ...
Definition: MetaData.hpp:98
Part & universal_part() const
Universal subset for the problem domain. All other parts are a subset of the universal part...
Definition: MetaData.hpp:88
Property base class with an anonymous data type and anonymous multi-dimension.
A container for the field data of a homogeneous collection of entities.
Definition: Bucket.hpp:94
EntityRank face_rank() const
Returns the face rank which changes depending on spatial dimension.
void commit()
Commit the part and field declarations so that the meta data manager can be used to create mesh bulk ...
Definition: MetaData.cpp:368
bool check_rank(EntityRank rank) const
void declare_field_restriction(FieldBase &arg_field, EntityRank arg_entity_rank, const Part &arg_part, const unsigned *arg_stride, const void *arg_init_value=NULL)
Declare a field restriction via runtime type information.
Definition: MetaData.cpp:303
void FEM_initialize(size_t spatial_dimension, const std::vector< std::string > &in_entity_rank_names=std::vector< std::string >())
Initialize the spatial dimension and an optional list of entity rank names associated with each rank...
Definition: FEMMetaData.cpp:61