Sierra Toolkit Version of the Day
BulkData.hpp
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 #ifndef stk_mesh_BulkData_hpp
00011 #define stk_mesh_BulkData_hpp
00012 
00013 //----------------------------------------------------------------------
00014 
00015 #include <map>
00016 
00017 #include <stk_util/parallel/Parallel.hpp>
00018 #include <stk_util/parallel/DistributedIndex.hpp>
00019 
00020 #include <stk_mesh/base/Types.hpp>
00021 #include <stk_mesh/base/Field.hpp>
00022 #include <stk_mesh/base/MetaData.hpp>
00023 #include <stk_mesh/baseImpl/EntityRepository.hpp>
00024 #include <stk_mesh/base/Ghosting.hpp>
00025 #include <stk_mesh/base/Selector.hpp>
00026 #include <stk_mesh/baseImpl/BucketRepository.hpp>
00027 
00028 //----------------------------------------------------------------------
00029 
00030 namespace stk {
00031 namespace mesh {
00032 
00037 //----------------------------------------------------------------------
00046 class BulkData {
00047 public:
00048 
00049   enum BulkDataSyncState { MODIFIABLE = 1 , SYNCHRONIZED = 2 };
00050 
00051   ~BulkData();
00052 
00060   BulkData( const MetaData & mesh_meta_data ,
00061             ParallelMachine parallel ,
00062             unsigned bucket_max_size = 1000 );
00063 
00064   //------------------------------------
00066   const MetaData & mesh_meta_data() const { return m_mesh_meta_data ; }
00067 
00069   ParallelMachine parallel() const { return m_parallel_machine ; }
00070 
00072   unsigned parallel_size()   const { return m_parallel_size ; }
00073 
00075   unsigned parallel_rank()   const { return m_parallel_rank ; }
00076 
00077   //------------------------------------
00081   unsigned bucket_capacity() const { return m_bucket_repository.bucket_capacity(); }
00082 
00083   //------------------------------------
00088   BulkDataSyncState synchronized_state() const { return m_sync_state ; }
00089 
00094   size_t synchronized_count() const { return m_sync_count ; }
00095 
00107   bool modification_begin();
00108 
00126   bool modification_end();
00127 
00143   void change_entity_owner( const std::vector<EntityProc> & );
00144 
00156   void update_field_data_states() const { m_bucket_repository.update_field_data_states(); }
00157 
00158 
00165   void copy_entity_fields( const Entity & src, Entity & dest) {
00166     //TODO fix const correctness for src
00167     Entity & non_const_src = const_cast<Entity &>(src);
00168     m_bucket_repository.copy_fields(
00169         dest.bucket(),
00170         dest.bucket_ordinal(),
00171         non_const_src.bucket(),
00172         non_const_src.bucket_ordinal()
00173     );
00174   }
00175 
00176   //------------------------------------
00178   const std::vector<Bucket*> & buckets( EntityRank type ) const
00179   { return m_bucket_repository.buckets(type); }
00180 
00182 
00183   Entity * get_entity( EntityRank entity_rank , EntityId entity_id , const char * /* required_by */ = NULL  ) const {
00184     verify_type_and_id("BulkData::get_entity", entity_rank, entity_id);
00185     return m_entity_repo.get_entity( EntityKey(entity_rank, entity_id));
00186   }
00187 
00189   Entity * get_entity( const EntityKey key ) const  {
00190     return m_entity_repo.get_entity(key);
00191   }
00192   //------------------------------------
00206   Entity & declare_entity( EntityRank ent_type ,
00207                            EntityId ent_id , const std::vector<Part*> & parts);
00208 
00218   void change_entity_parts( Entity & ,
00219                             const std::vector<Part*> & add_parts ,
00220                             const std::vector<Part*> & remove_parts =
00221                                   std::vector<Part*>() );
00222 
00256   bool destroy_entity( Entity * & );
00257 
00258   //------------------------------------
00259 
00269   void generate_new_entities(const std::vector<size_t>& requests,
00270                          std::vector<Entity *>& requested_entities);
00271 
00272   //------------------------------------
00289   void declare_relation( Entity & e_from ,
00290                          Entity & e_to ,
00291                          const unsigned local_id );
00292 
00296   void declare_relation( Entity & , const std::vector<Relation> & );
00297 
00308   void destroy_relation( Entity & e_from , Entity & e_to );
00309 
00310   //------------------------------------
00311   //------------------------------------
00313   const std::vector<Entity*> & entity_comm() const
00314     { return m_entity_comm ; }
00315 
00316   //------------------------------------
00321   Ghosting & shared_aura() const { return * m_ghosting[1] ; }
00322 
00328   Ghosting & create_ghosting( const std::string & name );
00329 
00347   void change_ghosting( Ghosting & ,
00348                         const std::vector<EntityProc> & add_send ,
00349                         const std::vector<Entity*> & remove_receive );
00350 
00355   void destroy_all_ghosting();
00356 
00358   const std::vector<Ghosting*> & ghostings() const { return m_ghosting ; }
00359 
00360   //------------------------------------
00362   void assert_ok_to_modify( const char * ) const ;
00363 
00364   void assert_entity_owner( const char * , const Entity & , unsigned ) const ;
00365 
00366   void assert_good_key( const char * , const EntityKey & ) const ;
00367 
00368   //------------------------------------
00369 private:
00370   void verify_type_and_id(const char* calling_method,
00371                           EntityRank ent_type, EntityId ent_id) const;
00372 
00373 #ifndef DOXYGEN_COMPILE
00374 
00375 
00376   BulkData();
00377   BulkData( const BulkData & );
00378   BulkData & operator = ( const BulkData & );
00379 
00380 
00382   parallel::DistributedIndex          m_entities_index ;
00383   impl::EntityRepository              m_entity_repo ;
00384   impl::BucketRepository              m_bucket_repository ;
00385   std::vector<Entity*>                m_entity_comm ;
00386   std::vector<Ghosting*>              m_ghosting ; 
00388   // Other information:
00389   const MetaData &   m_mesh_meta_data ;
00390   ParallelMachine    m_parallel_machine ;
00391   unsigned           m_parallel_size ;
00392   unsigned           m_parallel_rank ;
00393   size_t             m_sync_count ;
00394   BulkDataSyncState  m_sync_state ;
00395   bool               m_meta_data_verified ;
00396 
00397   unsigned determine_new_owner( Entity & ) const ;
00398 
00399   /*  Entity modification consequences:
00400    *  1) Change entity relation => update via part relation => change parts
00401    *  2) Change parts => update forward relations via part relation
00402    *                  => update via field relation
00403    */
00404   void internal_change_entity_parts( Entity & ,
00405                                      const PartVector & add_parts ,
00406                                      const PartVector & remove_parts );
00407 
00408   void internal_propagate_part_changes( Entity & , const PartVector & removed );
00409 
00410   void internal_change_ghosting( Ghosting & ,
00411                                  const std::vector<EntityProc> & add_send ,
00412                                  const std::vector<Entity*> & remove_receive );
00413 
00414   bool internal_modification_end( bool regenerate_aura );
00415     void internal_resolve_shared_modify_delete();
00416     void internal_resolve_ghosted_modify_delete();
00417     void internal_resolve_parallel_create();
00418     void internal_resolve_shared_membership();
00419 
00420   void internal_update_distributed_index( std::vector<Entity*> & shared_new );
00421 
00425   void owner_send_to_all( Entity * , std::vector<EntityProc> & ) const ;
00426 
00432   void internal_regenerate_shared_aura();
00433 
00434   friend class UnitTestBulkData ;
00435 #endif /* DOXYGEN_COMPILE */
00436 };
00437 
00444 void set_field_relations( Entity & e_from ,
00445                           Entity & e_to ,
00446                           const unsigned ident );
00447 
00448 } // namespace mesh
00449 } // namespace stk
00450 
00451 //----------------------------------------------------------------------
00452 //----------------------------------------------------------------------
00453 
00454 #endif //  stk_mesh_BulkData_hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends