Field.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_Field_hpp
00011 #define stk_mesh_Field_hpp
00012 
00013 //----------------------------------------------------------------------
00014 
00015 #include <iosfwd>
00016 #include <string>
00017 #include <vector>
00018 
00019 #include <Shards_Array.hpp>
00020 
00021 #include <stk_util/util/SimpleArrayOps.hpp>
00022 #include <stk_util/util/CSet.hpp>
00023 
00024 #include <stk_mesh/base/Types.hpp>
00025 #include <stk_mesh/base/DataTraits.hpp>
00026 
00027 //----------------------------------------------------------------------
00028 
00029 namespace stk {
00030 namespace mesh {
00031 
00048 enum FieldState {
00049   StateNone = 0,  
00050   StateNew  = 0,  
00051   StateNP1  = 0,  
00052   StateOld  = 1,  
00053   StateN    = 1,  
00054   StateNM1  = 2,  
00055   StateNM2  = 3,  
00056   StateNM3  = 4,  
00057   StateNM4  = 5   
00058 };
00059 
00063 enum { MaximumFieldStates = 6 };
00064 
00066 const char * field_state_name( FieldState );
00067 
00069 //----------------------------------------------------------------------
00070 //----------------------------------------------------------------------
00075 template<>
00076 class Field< void , void , void , void , void , void , void , void > {
00077 public:
00081   MetaData & mesh_meta_data() const { return *m_mesh_meta_data ; }
00082 
00086   unsigned mesh_meta_data_ordinal() const { return m_mesh_meta_data_ordinal ; }
00087 
00089   const std::string & name() const { return m_name ; }
00090 
00092   template<class Type> bool type_is() const
00093   { return m_data_traits.type_info == typeid(Type) ; }
00094 
00098   const DataTraits & data_traits() const { return m_data_traits ; }
00099 
00101   unsigned number_of_states() const { return m_num_states ; }
00102 
00104   FieldState state() const { return m_this_state ; }
00105 
00109   unsigned rank() const { return m_rank ; }
00110 
00115   const shards::ArrayDimTag * const * dimension_tags() const
00116   { return m_dim_tags ; }
00117 
00121   unsigned max_size( unsigned entity_type) const ;
00122 
00123   //----------------------------------------
00124 
00126   template<class A>
00127   const A * attribute() const { return m_attribute.template get<A>(); }
00128 
00133   struct Restriction {
00134     typedef shards::array_traits::int_t size_type ;
00135 
00137     EntityKey key ;
00138 
00140     size_type stride[ MaximumFieldDimension ];
00141 
00142 #ifndef DOXYGEN_COMPILE
00143 
00144     Restriction();
00145     Restriction( const Restriction & rhs );
00146     Restriction & operator = ( const Restriction & rhs );
00147 
00148     Restriction( unsigned t , unsigned );
00149     unsigned type()    const { return entity_type( key ); }
00150     unsigned ordinal() const { return entity_id( key ); }
00151 #endif /* DOXYGEN_COMPILE */
00152   };
00153 
00155   typedef std::vector<Restriction> RestrictionVector;
00156   
00160   const RestrictionVector &restrictions() const ;
00161 
00165   const Restriction & restriction( unsigned , const Part & ) const ;
00166 
00167   //----------------------------------------
00168 
00169 private:
00170 
00171   /* \brief  A field is owned by a MetaData, as such only the owning
00172    *         MetaData can create, delete, or modify a field.
00173    *         The owner-modifies rule is enforced by all non-const
00174    *         methods being private and the MetaData be a friend.
00175    */
00176   friend class ::stk::mesh::MetaData ;
00177  
00179   friend class ::stk::mesh::UnitTestMetaData ;
00180 
00181   template< typename Scalar ,
00182             class Tag1 , class Tag2 , class Tag3 , class Tag4 ,
00183             class Tag5 , class Tag6 , class Tag7 >
00184   friend class stk::mesh::Field ;
00185 
00186 #ifndef DOXYGEN_COMPILE
00187 
00188   ~Field();
00189 
00190   Field();
00191   Field( const Field & );
00192   Field & operator = ( const Field & );
00193 
00194   Field( MetaData * , unsigned arg_ordinal ,
00195          const std::string & ,
00196          const DataTraits & ,
00197          unsigned arg_number_of_states , FieldState arg_this_state );
00198 
00199   static FieldBase *
00200     declare_field( const std::string                 & arg_name ,
00201                    const DataTraits                  & arg_traits ,
00202                    unsigned                            arg_rank ,
00203                    const shards::ArrayDimTag * const * arg_dim_tags ,
00204                    unsigned                            arg_num_states ,
00205                    MetaData                          * arg_meta_data ,
00206                    std::vector<FieldBase*>           & arg_meta_data_fields );
00207 
00208   void insert_restriction( const char *       arg_method ,
00209                            EntityType           arg_entity_type ,
00210                            const Part       & arg_part ,
00211                            const unsigned   * arg_stride );
00212 
00213   void verify_and_clean_restrictions( const char       * arg_method ,
00214                                       const PartVector & arg_all_parts );
00215 
00216   RestrictionVector & restrictions();
00217 
00218   //----------------------------------
00219 
00220   const std::string  m_name ;                    
00221   CSet               m_attribute ;               
00222   const DataTraits & m_data_traits ;             
00223   MetaData * const   m_mesh_meta_data ;          
00224   const unsigned     m_mesh_meta_data_ordinal ;  
00225   const unsigned     m_num_states ;              
00226   const FieldState   m_this_state ;              
00227   unsigned           m_rank ;                    
00228   RestrictionVector  m_dim_map ;                 
00229   Field *            m_field_states[ MaximumFieldStates ];
00230   const shards::ArrayDimTag * m_dim_tags[ MaximumFieldDimension ];
00231 
00232 #endif /* DOXYGEN_COMPILE */
00233 };
00234 
00235 //----------------------------------------------------------------------
00236  
00237 void print_field_type( std::ostream                      & arg_msg ,
00238                        unsigned                            arg_scalar_type ,
00239                        unsigned                            arg_rank ,
00240                        const shards::ArrayDimTag * const * arg_tags );
00241 
00246 FieldBase * get_field(  
00247   const char                        * arg_method ,
00248   const std::string                 & arg_name ,
00249   const DataTraits                  & arg_traits ,
00250   unsigned                            arg_rank , 
00251   const shards::ArrayDimTag * const * arg_dim_tags ,
00252   unsigned                            arg_num_states ,
00253   const std::vector<FieldBase*>     & arg_meta_data_fields );
00254 
00256 std::ostream & operator << ( std::ostream & , const FieldBase & );
00257 
00259 std::ostream & print( std::ostream & ,
00260                       const char * const , const FieldBase & );
00261 
00262 //----------------------------------------------------------------------
00263 
00267 template< typename Scalar , class Tag1 , class Tag2 , class Tag3 , class Tag4 ,
00268           class Tag5 , class Tag6 , class Tag7 >
00269 class Field : public FieldBase {
00270 public:
00271 
00273   const Field & field_of_state( FieldState state ) const
00274   { return static_cast<Field &>( * FieldBase::m_field_states[state] ); }
00275 
00277   Field & field_of_state( FieldState state )
00278   { return static_cast<Field &>( * FieldBase::m_field_states[state] ); }
00279 
00280 private:
00281 
00282 #ifndef DOXYGEN_COMPILE
00283 
00284   ~Field();
00285   Field();
00286   Field( const Field & );
00287   Field & operator = ( const Field & );
00288 
00289 #endif /* DOXYGEN_COMPILE */
00290 };
00291 
00292 
00293 //----------------------------------------------------------------------
00294 
00295 } // namespace mesh
00296 } // namespace stk
00297 
00298 //----------------------------------------------------------------------
00299 // Internal implementation details to follow.
00300 //----------------------------------------------------------------------
00301 
00302 namespace stk {
00303 namespace mesh {
00304 
00306 template< typename Scalar >
00307 struct FieldTraits< Field<Scalar,void,void,void,void,void,void,void> >
00308 {
00309 public:
00310   typedef shards::array_traits::Helper<Scalar,shards::RankZero,
00311                                        void,void,void,void,void,void,void,void>
00312     Helper ;
00313 
00314   typedef Scalar data_type ; 
00315   typedef void   tag1 ;      
00316   typedef void   tag2 ;      
00317   typedef void   tag3 ;      
00318   typedef void   tag4 ;      
00319   typedef void   tag5 ;      
00320   typedef void   tag6 ;      
00321   typedef void   tag7 ;      
00322 
00324   enum { Rank = 0 };
00325 
00326   static void assign_tags( const shards::ArrayDimTag ** tags ) {}
00327 };
00328 
00330 template< typename Scalar ,
00331           class Tag1 , class Tag2 , class Tag3 , class Tag4 ,
00332           class Tag5 , class Tag6 , class Tag7 >
00333 struct FieldTraits< Field<Scalar,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> >
00334 {
00335 public:
00336   typedef shards::array_traits::Helper<Scalar,shards::FortranOrder,
00337                                        Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7,void>
00338     Helper ;
00339   
00340   typedef Scalar data_type ; 
00341   typedef Tag1   tag1 ;      
00342   typedef Tag2   tag2 ;      
00343   typedef Tag3   tag3 ;      
00344   typedef Tag4   tag4 ;      
00345   typedef Tag5   tag5 ;      
00346   typedef Tag6   tag6 ;      
00347   typedef Tag7   tag7 ;      
00348 
00350   enum { Rank = Helper::Rank };
00351 
00352   static void assign_tags( const shards::ArrayDimTag ** tags )
00353     { Helper::assign_tags( tags ); }
00354 };
00355 
00356 //----------------------------------------------------------------------
00357 //----------------------------------------------------------------------
00358 
00359 #ifndef DOXYGEN_COMPILE
00360 
00361 inline
00362 FieldBase::Restriction::Restriction()
00363   : key() { Copy<MaximumFieldDimension>( stride , size_type(0) ); }
00364 
00365 inline
00366 FieldBase::Restriction::Restriction( const FieldBase::Restriction & rhs )
00367   : key( rhs.key ) { Copy< MaximumFieldDimension >( stride , rhs.stride ); }
00368 
00369 inline
00370 FieldBase::Restriction &
00371 FieldBase::Restriction::operator = ( const FieldBase::Restriction & rhs )
00372   {
00373     key = rhs.key ;
00374     Copy< MaximumFieldDimension >( stride , rhs.stride );
00375     return *this ;
00376   }
00377 
00378 inline
00379 FieldBase::Restriction::Restriction( unsigned t , unsigned ord )
00380   : key( EntityKey( t , ord ) )
00381     { Copy< MaximumFieldDimension >( stride , size_type(0) ); }
00382 
00383 #endif /* DOXYGEN_COMPILE */
00384 
00385 //----------------------------------------------------------------------
00417 struct FieldRelation {
00419   FieldBase          * m_root ;
00420 
00422   FieldBase          * m_target ;
00423 
00425   relation_stencil_ptr m_function ;
00426 
00427 #ifndef DOXYGEN_COMPILE
00428 
00429   FieldRelation() : m_root( NULL ), m_target( NULL ), m_function( NULL ) {}
00430 
00431   FieldRelation( const FieldRelation & rhs )
00432     : m_root( rhs.m_root ),
00433       m_target( rhs.m_target ),
00434       m_function( rhs.m_function ) {}
00435 
00436   FieldRelation & operator = ( const FieldRelation & rhs )
00437     {
00438       m_root = rhs.m_root ;
00439       m_target = rhs.m_target ;
00440       m_function = rhs.m_function ;
00441       return *this ;
00442     }
00443 
00444 #endif /* DOXYGEN_COMPILE */
00445 };
00446 
00447 } // namespace mesh
00448 } // namespace stk
00449 
00450 //----------------------------------------------------------------------
00451 //----------------------------------------------------------------------
00452 
00453 #endif /* stk_mesh_Field_hpp */
00454 

Generated on Tue Jul 13 09:27:32 2010 for Sierra Toolkit by  doxygen 1.4.7