Sierra Toolkit  Version of the Day
FEMHelpers.hpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010, 2011 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 #ifndef stk_mesh_FEMHelpers_hpp
10 #define stk_mesh_FEMHelpers_hpp
11 
12 #include <stk_mesh/base/Types.hpp>
13 
14 #include <stk_mesh/fem/FEMMetaData.hpp>
15 #include <stk_mesh/fem/CellTopology.hpp>
16 // This is needed for ElementNode class
17 #include <stk_mesh/fem/TopologyDimensions.hpp>
18 
19 namespace stk_classic {
20 namespace mesh {
21 
22 class Bucket;
23 class Entity;
24 
25 namespace fem {
26 
31 //----------------------------------------------------------------------
35 Entity & declare_element( BulkData & mesh ,
36  Part & part ,
37  const EntityId elem_id ,
38  const EntityId node_id[] );
39 
40 
45 Entity & declare_element_side( BulkData & mesh ,
46  const stk_classic::mesh::EntityId global_side_id ,
47  Entity & elem ,
48  const unsigned local_side_id ,
49  Part * part = NULL );
50 
55 Entity & declare_element_edge( BulkData & mesh ,
56  const stk_classic::mesh::EntityId global_side_id ,
57  Entity & elem ,
58  const unsigned local_side_id ,
59  Part * part = NULL );
60 
64 bool element_side_polarity( const Entity & elem ,
65  const Entity & side , int local_side_id = -1 );
66 
71 Entity & declare_element_side( Entity & elem ,
72  Entity & side ,
73  const unsigned local_side_id ,
74  Part * part = NULL );
75 
76 
77 
82 Entity & declare_element_edge( Entity & elem ,
83  Entity & edge ,
84  const unsigned local_edge_id ,
85  Part * part = NULL );
86 
87 
88 
92 template< class Top >
93 Part &declare_part(FEMMetaData& meta_data, const std::string &name) {
94  return meta_data.declare_part(name, shards::getCellTopologyData<Top>());
95 }
96 
108 const CellTopologyData * get_subcell_nodes(
109  const Entity & entity ,
110  EntityRank subcell_rank ,
111  unsigned subcell_identifier ,
112  EntityVector & subcell_nodes
113  );
114 
119 int get_entity_subcell_id( const Entity & entity ,
120  const EntityRank subcell_rank,
121  const CellTopologyData * side_topology,
122  const EntityVector & side_nodes );
123 
125 bool comm_mesh_counts( BulkData & ,
126  std::vector<size_t> & counts ,
127  bool = false );
128 
130 
133 template< class NodeField >
134 inline
137  FEMMetaData & fmd , const std::string & s ,
138  NodeField & node_field )
139 {
140  const unsigned num_states = node_field.number_of_states();
141 
143  fmd.template declare_field< ElementNodePointerField >( s, num_states );
144 
145  for ( unsigned i = 0 ; i < num_states ; ++i ) {
146  FieldState state = (FieldState) i;
148  f.field_of_state( state ) ,
149  fem::get_element_node_stencil(fmd.spatial_dimension()) ,
150  node_field.field_of_state( state ) );
151  }
152 
153  return f ;
154 }
155 
156 template< class Traits >
157 void get_parts_with_topology(stk_classic::mesh::BulkData& mesh,
159  bool skip_topology_root_parts=false)
160 {
161  parts.clear();
162 
164 
165  const stk_classic::mesh::PartVector& all_parts = fem_meta.get_parts();
166 
167  stk_classic::mesh::PartVector::const_iterator
168  iter = all_parts.begin(),
169  iter_end = all_parts.end();
170 
171  const CellTopologyData* topology = shards::getCellTopologyData<Traits>();
172 
173  for(; iter!=iter_end; ++iter) {
174  stk_classic::mesh::Part* part = *iter;
175  if (fem_meta.get_cell_topology(*part).getCellTopologyData() == topology) {
176  if (skip_topology_root_parts && stk_classic::mesh::fem::is_cell_topology_root_part(*part)) {
177  continue;
178  }
179  parts.push_back(part);
180  }
181  }
182 }
183 
184 inline
185 unsigned get_spatial_dimension(const Entity& entity)
186 {
187  // expose some dot-chain to ensure everything inlined
188  return entity.bucket().mesh().mesh_meta_data().get_spatial_dimension();
189 }
190 
191 /* The Fmwk uses an enum to identify nodes, edges, faces and elements. The
192  toolkit is similar, but the the toolkit rank depends on the spatial
193  dimension. For 3D parts they are identical. With 2D, the element rank is
194  2 (not 3). etc.
195 */
196 
197 #ifdef SIERRA_MIGRATION
198 
199 inline
200 unsigned convert_fmwk_rank_to_stk(unsigned fmwk_rank, unsigned spatial_dim)
201 {
202  ThrowAssert(spatial_dim > 0);
203  ThrowAssert(spatial_dim < 4);
204  ThrowAssert(fmwk_rank <= 4); // up to four basic entities types and constraints
205  static int map2Stk[4][5] = { {-1,-1,-1,-1, 4},
206  { 0,-1,-1, 1, 4},
207  { 0, 1,-1, 2, 4},
208  { 0, 1, 2, 3, 4}};
209  int stk_rank = map2Stk[spatial_dim][fmwk_rank];
210 
211  return static_cast<unsigned>(stk_rank);
212 }
213 
214 inline
215 unsigned convert_stk_rank_to_fmwk(unsigned stk_rank, unsigned spatial_dim)
216 {
217  ThrowAssert(spatial_dim > 0);
218  ThrowAssert(spatial_dim < 4);
219  ThrowAssert(stk_rank <= 4); // up to four basic entities types and constraints
220  static int map2Fmwk[4][5]={ {-1,-1,-1,-1, 4},
221  { 0, 3,-1,-1, 4},
222  { 0, 1, 3,-1, 4},
223  { 0, 1, 2, 3, 4}};
224  int fmwk_rank=map2Fmwk[spatial_dim][stk_rank];
225 
226  return static_cast<unsigned>(fmwk_rank);
227 }
228 
229 inline
230 unsigned get_derived_type(const Entity& entity)
231 {
232  return convert_stk_rank_to_fmwk(entity.entity_rank(), get_spatial_dimension(entity));
233 }
234 
235 #endif
236 
239 } //namespace fem
240 } //namespace mesh
241 } //namespace stk_classic
242 #endif
unsigned number_of_states() const
Number of states of this field.
Definition: FieldBase.hpp:78
FEMMetaData is a class that implements a Finite Element Method skin on top of the Sierra Tool Kit Met...
Definition: FEMMetaData.hpp:54
bool comm_mesh_counts(BulkData &M, std::vector< size_t > &counts, bool local_flag)
Global counts for a mesh&#39;s entities.
Definition: Comm.cpp:26
int get_entity_subcell_id(const Entity &entity, const EntityRank subcell_rank, const CellTopologyData *side_topology, const EntityVector &side_nodes)
Given an entity and collection of nodes, return the local id of the subcell that contains those nodes...
Entity & declare_element(BulkData &mesh, Part &part, const EntityId elem_id, const EntityId node_id[])
Declare an element member of a Part with a CellTopology and nodes conformal to that topology...
Definition: FEMHelpers.cpp:72
const PartVector & get_parts() const
Query all parts of the mesh ordered by the parts&#39; ordinal.
Field with defined data type and multi-dimensions (if any)
Definition: Field.hpp:118
An application-defined subset of a problem domain.
Definition: Part.hpp:49
Part & declare_part(const std::string &name, fem::CellTopology cell_topology)
Declare a part with a given cell topology.
const CellTopologyData * get_subcell_nodes(const Entity &entity, EntityRank subcell_rank, unsigned subcell_identifier, EntityVector &subcell_nodes)
Definition: FEMHelpers.cpp:239
Entity & declare_element_edge(Entity &elem, Entity &edge, const unsigned local_edge_id, Part *part)
Create (or find) an element edge.
Definition: FEMHelpers.cpp:145
Manager for an integrated collection of entities, entity relations, and buckets of field data...
Definition: BulkData.hpp:49
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
Definition: Entity.hpp:120
Part & declare_part(FEMMetaData &meta_data, const std::string &name)
Declare a part with a given cell topology. This is just a convenient function that wraps FEMMetaData&#39;...
Definition: FEMHelpers.hpp:93
Sierra Toolkit.
Field & field_of_state(FieldState input_state) const
Query this field for a given field state.
Definition: Field.hpp:122
ElementNodePointerField & declare_element_node_pointer_field(FEMMetaData &fmd, const std::string &s, NodeField &node_field)
Declare an element-to-node-data pointer field.
Definition: FEMHelpers.hpp:136
size_t spatial_dimension() const
Returns the spatial dimension that was passed in through FEM_initialize.
std::vector< Part *> PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
Definition: Types.hpp:31
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.
bool element_side_polarity(const Entity &elem, const Entity &side, int local_side_id)
Determine the polarity of the local side, more efficient if the local_side_id is known.
Definition: FEMHelpers.cpp:401
Entity & declare_element_side(Entity &elem, Entity &side, const unsigned local_side_id, Part *part)
Create (or find) an element side.
Definition: FEMHelpers.cpp:104
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...
FieldState
Enumeration of states for multi-state fields.
Definition: FieldState.hpp:34