FieldData.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_FieldData_hpp
00011 #define stk_mesh_FieldData_hpp
00012 
00013 //----------------------------------------------------------------------
00014 
00015 #include <Shards_Array.hpp>
00016 
00017 #include <stk_mesh/base/Field.hpp>
00018 #include <stk_mesh/base/Bucket.hpp>
00019 #include <stk_mesh/base/Entity.hpp>
00020 
00021 namespace stk {
00022 namespace mesh {
00023 
00032 template< class FieldType > struct BucketArray {};
00033 
00038 template< class FieldType > struct EntityArray {};
00039 
00040 //----------------------------------------------------------------------
00046 bool field_data_valid( const FieldBase & f ,
00047                        const Bucket & k ,
00048                        unsigned ord = 0,
00049                        const char * required_by = NULL );
00050 
00056 inline
00057 bool field_data_valid( const FieldBase & f ,
00058                        const Entity & e ,
00059                        const char * required_by = NULL )
00060 { return field_data_valid( f, e.bucket(), e.bucket_ordinal(), required_by ); }
00061 
00062 //----------------------------------------------------------------------
00063 
00065 inline
00066 unsigned field_data_size( const FieldBase & f , const Bucket & k )
00067 {
00068   const Bucket::DataMap & pd = k.m_field_map[ f.mesh_meta_data_ordinal() ];
00069   return pd.m_size ;
00070 }
00071 
00073 inline
00074 unsigned field_data_size( const FieldBase & f , const Entity & e )
00075 { return field_data_size( f , e.bucket() ); }
00076 
00077 //----------------------------------------------------------------------
00078 
00079 
00081 template< class field_type >
00082 inline
00083 typename FieldTraits< field_type >::data_type *
00084 field_data( const field_type & f , const Bucket::iterator &i ) 
00085 {
00086   typedef unsigned char * byte_p ;
00087   typedef typename FieldTraits< field_type >::data_type * data_p ;
00088 
00089   data_p ptr = NULL ;
00090 
00091   {
00092     const Bucket          & b  = * i.m_bucket_ptr ;
00093     const Bucket::DataMap & pd = b.m_field_map[ f.mesh_meta_data_ordinal() ];
00094 
00095     if ( pd.m_size ) {
00096       ptr = (data_p)( ((byte_p)(b.m_entities)) +
00097                       pd.m_base + pd.m_size * i.m_current_entity );
00098     }
00099   }
00100   return ptr ;
00101 
00102 }
00103 
00104 
00106 template< class field_type >
00107 inline
00108 typename FieldTraits< field_type >::data_type *
00109 field_data( const field_type & f , const Entity & e )
00110 {
00111   typedef unsigned char * byte_p ;
00112   typedef typename FieldTraits< field_type >::data_type * data_p ;
00113 
00114   data_p ptr = NULL ;
00115 
00116   {
00117     const Bucket & b = e.bucket();
00118 
00119     const Bucket::DataMap & pd = b.m_field_map[ f.mesh_meta_data_ordinal() ];
00120 
00121     if ( pd.m_size ) {
00122       ptr = (data_p)( ((byte_p)(b.m_entities)) +
00123                       pd.m_base + pd.m_size * e.bucket_ordinal() );
00124     }
00125   }
00126   return ptr ;
00127 }
00128 
00129 //----------------------------------------------------------------------
00130 
00131 #ifndef DOXYGEN_COMPILE
00132 
00133 void throw_field_data_array( const FieldBase & , unsigned );
00134 
00135 template< typename ScalarType >
00136 struct EntityArray< Field<ScalarType,void,void,void,void,void,void,void> >
00137   : public shards::Array<ScalarType,shards::RankZero,void,void,void,void,void,void,void>
00138 {
00139   typedef Field<ScalarType,void,void,void,void,void,void,void> field_type ;
00140   typedef shards::Array<ScalarType,shards::RankZero,void,void,void,void,void,void,void>
00141   array_type ;
00142 
00143   EntityArray( const field_type & f , const Entity & e )
00144     : array_type( field_data( f , e ) ) {}
00145 
00146 private:
00147   EntityArray();
00148   EntityArray( const EntityArray & );
00149   EntityArray & operator = ( const EntityArray & );
00150 };
00151 #endif /* DOXYGEN_COMPILE */
00152 
00156 template< typename ScalarType ,
00157           class Tag1 , class Tag2 , class Tag3 , class Tag4 ,
00158           class Tag5 , class Tag6 , class Tag7 >
00159 struct EntityArray< Field<ScalarType,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> >
00160   : public shards::Array<ScalarType,shards::FortranOrder,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7>
00161 {
00162 #ifndef DOXYGEN_COMPILE
00163 private:
00164   typedef unsigned char * byte_p ;
00165   EntityArray();
00166   EntityArray( const EntityArray & );
00167   EntityArray & operator = ( const EntityArray & );
00168 public:
00169 
00170   typedef Field<ScalarType,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> field_type ;
00171 
00172   typedef
00173   shards::Array<ScalarType,shards::FortranOrder,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7>
00174   array_type ;
00175 
00176   EntityArray( const field_type & f , const Entity & e ) : array_type()
00177   {
00178     const Bucket          & b = e.bucket();
00179     const Bucket::DataMap & pd = b.m_field_map[ f.mesh_meta_data_ordinal() ];
00180 
00181     if ( pd.m_size ) {
00182       array_type::assign_stride( 
00183         (ScalarType*)( (byte_p)(b.m_entities) +
00184                        pd.m_base + pd.m_size * e.bucket_ordinal() ),
00185         pd.m_stride );
00186     }
00187   }
00188 #endif /* DOXYGEN_COMPILE */
00189 };
00190 
00191 //----------------------------------------------------------------------
00198 struct EntityDimension : public shards::ArrayDimTag {
00199    
00200   const char * name() const ;
00201    
00202   static const EntityDimension & tag(); 
00203  
00204 private: 
00205   EntityDimension() {} 
00206   EntityDimension( const EntityDimension & ); 
00207   EntityDimension & operator = ( const EntityDimension & );
00208 };
00209 
00210 
00214 template< typename ScalarType >
00215 struct BucketArray< Field<ScalarType,void,void,void,void,void,void,void> >
00216   : public
00217 shards::Array<ScalarType,shards::FortranOrder,EntityDimension,void,void,void,void,void,void> 
00218 {
00219 #ifndef DOXYGEN_COMPILE
00220 private:
00221   typedef unsigned char * byte_p ;
00222   BucketArray();
00223   BucketArray( const BucketArray & );
00224   BucketArray & operator = ( const BucketArray & );
00225 
00226 public:
00227 
00228   typedef Field<ScalarType,void,void,void,void,void,void,void> field_type ;
00229   typedef
00230   shards::Array<ScalarType,shards::FortranOrder,EntityDimension,void,void,void,void,void,void> 
00231   array_type ;
00232 
00233   BucketArray( const field_type & f , const Bucket & k )
00234   {
00235     const Bucket::DataMap & pd = k.m_field_map[ f.mesh_meta_data_ordinal() ];
00236 
00237     if ( pd.m_size ) {
00238       array_type::assign( (ScalarType*)( (byte_p)(k.m_entities) + pd.m_base ) ,
00239                           k.size() );
00240     }
00241   }
00242 
00243   BucketArray( const field_type & f,
00244                const Bucket::iterator & i,
00245                const Bucket::iterator & j) 
00246   {
00247     const Bucket::DataMap & pd =
00248       i.m_bucket_ptr->m_field_map[ f.mesh_meta_data_ordinal() ];
00249 
00250     const ptrdiff_t n = j - i ;
00251 
00252     if ( pd.m_size && 0 < n ) {
00253       array_type::assign(
00254         (ScalarType*)( (byte_p)(i.m_bucket_ptr->m_entities) +
00255                        pd.m_base + pd.m_size * i.m_current_entity ),
00256         (typename array_type::size_type) n );
00257     }
00258   }
00259 
00260 #endif /* DOXYGEN_COMPILE */
00261 };
00262 
00263 //----------------------------------------------------------------------
00267 template< typename ScalarType ,
00268           class Tag1 , class Tag2 , class Tag3 , class Tag4 ,
00269           class Tag5 , class Tag6 , class Tag7 >
00270 struct BucketArray< Field<ScalarType,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> >
00271   : public shards::ArrayAppend<
00272   shards::Array<ScalarType,shards::FortranOrder,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> ,
00273   EntityDimension >::type
00274 {
00275 private:
00276 #ifndef DOXYGEN_COMPILE
00277   typedef unsigned char * byte_p ;
00278   BucketArray();
00279   BucketArray( const BucketArray & );
00280   BucketArray & operator = ( const BucketArray & );
00281 public:
00282 
00283   typedef Field<ScalarType,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> field_type ;
00284 
00285   typedef typename shards::ArrayAppend<
00286     shards::Array<ScalarType,shards::FortranOrder,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> ,
00287     EntityDimension >::type array_type ;
00288 
00289   BucketArray( const field_type & f , const Bucket & b )
00290   {
00291     const Bucket::DataMap & pd = b.m_field_map[ f.mesh_meta_data_ordinal() ];
00292 
00293     if ( pd.m_size ) {
00294       array_type::assign_stride(
00295         (ScalarType*)( ((byte_p) b.m_entities ) + pd.m_base ),
00296         pd.m_stride , (typename array_type::size_type) b.size() );
00297     }
00298   }
00299 
00300   BucketArray( const field_type & f,
00301                const Bucket::iterator & i,
00302                const Bucket::iterator & j) 
00303   {
00304     const ptrdiff_t distance = j - i ;
00305 
00306     if ( 0 < distance ) {
00307 
00308       const Bucket          & b  = * i.m_bucket_ptr ;
00309       const Bucket::DataMap & pd = b.m_field_map[ f.mesh_meta_data_ordinal() ];
00310 
00311       if ( pd.m_size ) {
00312         array_type::assign_stride(
00313           (ScalarType*)( ((byte_p) b.m_entities ) +
00314                          pd.m_base + pd.m_size * i.m_current_entity ),
00315           pd.m_stride , (typename array_type::size_type) distance );
00316       }
00317     }
00318   }
00319 
00320 
00321 #endif /* DOXYGEN_COMPILE */
00322 };
00323 
00324 //----------------------------------------------------------------------
00325 
00328 } // namespace mesh
00329 } // namespace stk
00330 
00331 #endif /* stk_mesh_FieldData_hpp */
00332 

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