Sierra Toolkit Version of the Day
stk_generic_mesh_functions.hpp
00001 #ifndef STK_MESH_GENERIC_MESH_FUNCTIONS_HPP
00002 #define STK_MESH_GENERIC_MESH_FUNCTIONS_HPP
00003 
00004 #include "stk_mesh/generic_mesh/stk_generic_mesh_traits.hpp"
00005 
00006 namespace stk {
00007 namespace mesh {
00008 
00009 // Not supported by stk_mesh.
00010 inline STKGenericMesh::entity_local_id
00011 add_entity( STKGenericMesh & mesh )
00012 {
00013   ThrowRequireMsg(false, "Error!  STK_Mesh only supports add_entity with a stk::mesh::EntityKey!");
00014   return NULL;
00015 }
00016 
00017 // An API that is almost the same as the Generic Mesh API:
00018 inline STKGenericMesh::entity_local_id
00019 add_entity( const EntityKey & entity_key, STKGenericMesh & mesh )
00020 {
00021   PartVector empty_part_vector;
00022   Entity & entity = mesh.m_bulk_data.declare_entity( entity_rank(entity_key), entity_id(entity_key), empty_part_vector );
00023   return & entity;
00024 }
00025 
00026 
00027 // Not supported by stk_mesh.
00028 template <typename PartInputIterator>
00029 inline STKGenericMesh::entity_local_id
00030 add_entity(  PartInputIterator first, PartInputIterator last,
00031               STKGenericMesh & mesh )
00032 {
00033   ThrowRequireMsg(false, "Error!  STK_Mesh only supports add_entity with a stk::mesh::EntityKey!");
00034   return NULL;
00035 }
00036 
00037 // An API that is almost the same as the Generic Mesh API:
00038 template <typename PartInputIterator>
00039 inline STKGenericMesh::entity_local_id
00040 add_entity( const EntityKey & entity_key,
00041               PartInputIterator first, PartInputIterator last,
00042               STKGenericMesh & mesh )
00043 {
00044   PartVector part_vector;
00045   std::copy(first,last,std::back_inserter(part_vector));
00046   Entity & entity = mesh.m_bulk_data.declare_entity( entity_rank(entity_key), entity_id(entity_key), part_vector );
00047   STKGenericMesh::entity_descriptor entity_lid = & entity;
00048   return entity_lid;
00049 }
00050 
00051 // destroy_entity:
00052 inline void remove_entity( STKGenericMesh::entity_local_id entity_lid, STKGenericMesh & mesh )
00053 {
00054   mesh.m_bulk_data.destroy_entity(entity_lid);
00055 }
00056 
00057 
00058 // Not supported by stk_mesh.
00059 inline STKGenericMesh::relation_descriptor add_relation(
00060     STKGenericMesh::entity_local_id entity_from,
00061     STKGenericMesh::entity_local_id entity_to,
00062     STKGenericMesh & mesh
00063     )
00064 {
00065   ThrowRequireMsg(false, "Error!  STK_Mesh only supports add_relation with a stk::mesh::RelationIdentifier!");
00066   return NULL;
00067 }
00068 
00069 
00070 // An API that is almost the same as the Generic Mesh API:
00071 inline STKGenericMesh::relation_descriptor add_relation(
00072     STKGenericMesh::entity_local_id x_entity_from,
00073     STKGenericMesh::entity_local_id x_entity_to,
00074     const RelationIdentifier & relation_id,
00075     STKGenericMesh & mesh
00076     )
00077 {
00078   const Entity & entity_from = get_entity(x_entity_from,mesh);
00079   const Entity & entity_to   = get_entity(x_entity_to,mesh);
00080   Entity & nonconst_entity_from = const_cast<Entity&>(entity_from);
00081   Entity & nonconst_entity_to = const_cast<Entity&>(entity_to);
00082   mesh.m_bulk_data.declare_relation(nonconst_entity_from,nonconst_entity_to,relation_id);
00083   Internal_STK_Relation_Descriptor_Adapter relation_d(x_entity_from, x_entity_to, relation_id);
00084   return relation_d;
00085 }
00086 
00087 // Remove this relation from the mesh.
00088 inline void remove_relation( STKGenericMesh::relation_descriptor relation_d, STKGenericMesh & mesh )
00089 {
00090   mesh.m_bulk_data.destroy_relation(*relation_d.m_entity_from, *relation_d.m_entity_to, relation_d.m_relation_id );
00091 }
00092 
00093 
00094 // Generic API:  Get an entity_descriptor from an entity_local_id
00095 inline STKGenericMesh::entity_local_id entity_descriptor_to_local_id(
00096     STKGenericMesh::entity_descriptor entity_d,
00097     const STKGenericMesh & mesh
00098     )
00099 {
00100   return entity_d;
00101 }
00102 
00103 
00104 // Generic API:  Get an entity_local_id from an entity_descriptor.
00105 inline STKGenericMesh::entity_descriptor entity_local_id_to_descriptor(
00106     STKGenericMesh::entity_local_id entity_lid,
00107     const STKGenericMesh & mesh
00108     )
00109 {
00110   return entity_lid;
00111 }
00112 
00113 
00114 
00115 // Generic API:  Get a range to all entities in the mesh.
00116 inline std::pair<
00117                   STKGenericMesh::entity_descriptor_iterator,
00118                   STKGenericMesh::entity_descriptor_iterator
00119                 >
00120   get_entities(STKGenericMesh & mesh)
00121 {
00122   ThrowRequireMsg(false, "Error!  This function is not implemented yet!");
00123   return std::pair<STKGenericMesh::entity_descriptor_iterator,STKGenericMesh::entity_descriptor_iterator>(NULL,NULL);
00124 }
00125 
00126 
00127 // Generic API:
00128 inline
00129 std::pair<
00130           STKGenericMesh::bucket_entity_descriptor_iterator,
00131           STKGenericMesh::bucket_entity_descriptor_iterator
00132          >
00133   get_entities( STKGenericMesh::bucket_descriptor bucket_descriptor,
00134                 STKGenericMesh & mesh
00135               )
00136 {
00137   ThrowRequireMsg(false, "Error!  This function is not implemented yet!");
00138   return std::pair<STKGenericMesh::bucket_entity_descriptor_iterator,STKGenericMesh::bucket_entity_descriptor_iterator>(NULL,NULL);
00139 }
00140 
00141 
00142 
00143 // Generic API:  Get a range to all the relations for this entity_local_id
00144 inline std::pair<
00145                   STKGenericMesh::relation_descriptor_iterator,
00146                   STKGenericMesh::relation_descriptor_iterator
00147                 >
00148   get_relations( STKGenericMesh::entity_local_id entity_lid, STKGenericMesh & mesh )
00149 {
00150   ThrowRequireMsg(false, "Error!  This function is not implemented yet!");
00151   return std::pair<STKGenericMesh::relation_descriptor_iterator,STKGenericMesh::relation_descriptor_iterator>(NULL,NULL);
00152 }
00153 
00154 
00155 // Generic API:  Get a range to all the relations for this entity_descriptor
00156 //inline std::pair<
00157 //                  STKGenericMesh::relation_descriptor_iterator,
00158 //                  STKGenericMesh::relation_descriptor_iterator
00159 //                >
00160 //  get_relations( STKGenericMesh::entity_descriptor entity_d, STKGenericMesh & mesh )
00161 //{
00162 //  ThrowRequireMsg(false, "Error!  This function is not implemented yet!");
00163 //  return std::pair<STKGenericMesh::relation_descriptor_iterator,STKGenericMesh::relation_descriptor_iterator>(NULL,NULL);
00164 //}
00165 
00166 
00167 
00168 // Generic API:  Get a range to selected relations for this entity_local_id
00169 // Selector is a unary-predicate that takes a relation_descriptor and returns true/false
00170 template <typename Selector>
00171 inline std::pair<
00172                   STKGenericMesh::selected_relation_descriptor_iterator,
00173                   STKGenericMesh::selected_relation_descriptor_iterator
00174                 >
00175   get_relations(
00176       STKGenericMesh::entity_local_id entity_lid,
00177       Selector & selector,
00178       STKGenericMesh & mesh
00179       )
00180 {
00181   ThrowRequireMsg(false, "Error!  This function is not implemented yet!");
00182   return std::pair<STKGenericMesh::selected_relation_descriptor_iterator,STKGenericMesh::selected_relation_descriptor_iterator>(NULL,NULL);
00183 }
00184 
00185 
00186 // Generic API:  Get a range to selected relations for this entity_descriptor
00187 // Selector is a unary-predicate that takes a relation_descriptor and returns true/false
00188 //template <typename Selector>
00189 //inline std::pair<
00190 //                  STKGenericMesh::selected_relation_descriptor_iterator,
00191 //                  STKGenericMesh::selected_relation_descriptor_iterator
00192 //                >
00193 //  get_relations(
00194 //      STKGenericMesh::entity_descriptor entity_d,
00195 //      Selector & selector,
00196 //      STKGenericMesh & mesh
00197 //      )
00198 //{
00199 //  ThrowRequireMsg(false, "Error!  This function is not implemented yet!");
00200 //  return std::pair<STKGenericMesh::selected_relation_descriptor_iterator,STKGenericMesh::selected_relation_descriptor_iterator>(NULL,NULL);
00201 //}
00202 
00203 
00204 // Generic API:  Get a bucket for an entity_descriptor
00205 inline STKGenericMesh::bucket_descriptor
00206 get_bucket( STKGenericMesh::entity_descriptor entity, STKGenericMesh & mesh )
00207 {
00208   return &entity->bucket();
00209 }
00210 
00211 
00212 // Not supported by stk_mesh:
00213 inline
00214 std::pair<
00215           STKGenericMesh::bucket_descriptor_iterator,
00216           STKGenericMesh::bucket_descriptor_iterator
00217          >
00218 get_buckets( const STKGenericMesh & mesh )
00219 {
00220   ThrowRequireMsg(false, "Error!  STK_Mesh only supports get_buckets with an EntityRank specification!");
00221   return std::pair<STKGenericMesh::bucket_descriptor_iterator,STKGenericMesh::bucket_descriptor_iterator>(NULL,NULL);
00222 }
00223 
00224 // An API that is almost the same as the Generic Mesh API:
00225 inline
00226 std::pair<
00227           STKGenericMesh::bucket_descriptor_iterator,
00228           STKGenericMesh::bucket_descriptor_iterator
00229          >
00230 get_buckets( EntityRank entity_rank, const STKGenericMesh & mesh )
00231 {
00232   //const BucketVector & buckets = mesh.m_bulk_data.buckets(entity_rank);
00233   //return std::make_pair(buckets.begin(),buckets.end());
00234   ThrowRequireMsg(false, "Error!  This function is not implemented yet!");
00235   return std::pair<STKGenericMesh::bucket_descriptor_iterator,STKGenericMesh::bucket_descriptor_iterator>(NULL,NULL);
00236 }
00237 
00238 // Generic API:  Get buckets associated with a Selector.
00239 // Selector is a unary-predicate that takes a bucket_descriptor and returns true/false
00240 template <typename Selector >
00241 inline
00242 std::pair<
00243           STKGenericMesh::selected_bucket_descriptor_iterator,
00244           STKGenericMesh::selected_bucket_descriptor_iterator
00245          >
00246 get_buckets( const Selector & selector, STKGenericMesh & mesh )
00247 {
00248   ThrowRequireMsg(false, "Error!  This function is not implemented yet!");
00249   return std::pair<STKGenericMesh::selected_relation_descriptor_iterator,STKGenericMesh::selected_relation_descriptor_iterator>(NULL,NULL);
00250 }
00251 
00252 
00253 // Generic API:  Get buckets for a particular part_descriptor.
00254 inline
00255 std::pair<
00256           STKGenericMesh::part_bucket_descriptor_iterator,
00257           STKGenericMesh::part_bucket_descriptor_iterator
00258          >
00259 get_buckets( STKGenericMesh::part_descriptor part_descriptor, STKGenericMesh & mesh )
00260 {
00261   ThrowRequireMsg(false, "Error!  This function is not implemented yet!");
00262   return std::pair<STKGenericMesh::part_bucket_descriptor_iterator,STKGenericMesh::part_bucket_descriptor_iterator>(NULL,NULL);
00263 }
00264 
00265 
00266 // Generic API:  add this part to the Mesh.
00267 inline STKGenericMesh::part_descriptor
00268 add_part( const STKGenericMesh::part_descriptor & part, STKGenericMesh & mesh )
00269 {
00270   ThrowRequireMsg(false, "Error!  This function is not implemented yet!");
00271   return NULL;
00272 }
00273 
00274 
00275 // Generic API:  remove this part from the Mesh.
00276 inline void
00277 remove_part( STKGenericMesh::part_descriptor part_descriptor, STKGenericMesh & mesh )
00278 {
00279   ThrowRequireMsg(false, "Error!  This function is not implemented yet!");
00280 }
00281 
00282 
00283 // Move entity so it
00284 // sits in Parts defined by AddPartInputIterator and
00285 // so it does not sit in Parts defined by RemovePartInputIterator
00286 template <typename AddPartInputIterator, typename RemovePartInputIterator>
00287 inline STKGenericMesh::bucket_descriptor
00288 move_entity( STKGenericMesh::entity_descriptor entity_descriptor,
00289               AddPartInputIterator add_first, AddPartInputIterator add_last,
00290               RemovePartInputIterator remove_first, RemovePartInputIterator remove_last,
00291               STKGenericMesh & mesh )
00292 {
00293   PartVector add_parts;
00294   PartVector remove_parts;
00295   std::copy(add_first,add_last,std::back_inserter(add_parts));
00296   std::copy(remove_first,remove_last,std::back_inserter(remove_parts));
00297   Entity & entity = get_entity(entity_descriptor, mesh);
00298   mesh.m_bulk_data.change_entity_parts( entity, add_parts, remove_parts );
00299   Bucket & bucket = entity.bucket();
00300   STKGenericMesh::bucket_descriptor bucket_d = &bucket;
00301   return bucket_d;
00302 }
00303 
00304 
00305 // Generic API:  Get all parts on the mesh.
00306 inline
00307 std::pair<
00308           STKGenericMesh::part_descriptor_iterator,
00309           STKGenericMesh::part_descriptor_iterator
00310          >
00311 get_parts( const STKGenericMesh & mesh )
00312 {
00313   ThrowRequireMsg(false, "Error!  This function is not implemented yet!");
00314   return std::pair<STKGenericMesh::part_descriptor_iterator,STKGenericMesh::part_descriptor_iterator>(NULL,NULL);
00315 }
00316 
00317 
00318 // Generic API:  Get all Parts associated with a bucket.
00319 inline
00320 std::pair<
00321           STKGenericMesh::bucket_part_descriptor_iterator,
00322           STKGenericMesh::bucket_part_descriptor_iterator
00323          >
00324 get_parts(
00325     STKGenericMesh::bucket_descriptor bucket_descriptor, STKGenericMesh & mesh
00326     )
00327 {
00328   return bucket_descriptor->superset_part_ordinals();
00329 }
00330 
00331 inline
00332 STKGenericMesh::part_descriptor
00333 get_part_descriptor(STKGenericMesh::bucket_part_descriptor descriptor, STKGenericMesh & mesh)
00334 {
00335   return &(mesh.m_bulk_data.mesh_meta_data().get_part(descriptor));
00336 }
00337 
00338 // Generic API:  Begin modification cycle. Returns true if cycle was not already in progress
00339 inline
00340 bool
00341 modification_begin( STKGenericMesh & mesh )
00342 {
00343   return mesh.m_bulk_data.modification_begin();
00344 }
00345 
00346 // Generic API:  End modification cycle. Returns true if cycle was in progress.
00347 inline
00348 bool
00349 modification_end( STKGenericMesh & mesh )
00350 {
00351   return mesh.m_bulk_data.modification_end();
00352 }
00353 
00354 // Generic API:  Query if we are in a modification cycle
00355 inline
00356 bool
00357 is_modifiable( const STKGenericMesh & mesh )
00358 {
00359   return mesh.m_bulk_data.synchronized_state() == stk::mesh::BulkData::MODIFIABLE;
00360 }
00361 
00362 // Generic API:  Rotate the field data of multistate fields.
00363 inline
00364 void
00365 rotate_multistate_fields( STKGenericMesh & mesh )
00366 {
00367   mesh.m_bulk_data.update_field_data_states();
00368 }
00369 
00370 } // namespace mesh
00371 } // namespace stk
00372 
00373 #endif // STK_MESH_GENERIC_MESH_FUNCTIONS_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends