Sierra Toolkit Version of the Day
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 
00065 template< class FieldType > struct BucketArray {};
00066 
00071 template< class FieldType > struct EntityArray {};
00072 
00073 //----------------------------------------------------------------------
00079 bool field_data_valid( const FieldBase & f ,
00080                        const Bucket & k ,
00081                        unsigned ord = 0,
00082                        const char * required_by = NULL );
00083 
00089 inline
00090 bool field_data_valid( const FieldBase & f ,
00091                        const Entity & e ,
00092                        const char * required_by = NULL )
00093 { return field_data_valid( f, e.bucket(), e.bucket_ordinal(), required_by ); }
00094 
00095 //----------------------------------------------------------------------
00096 
00098 inline
00099 unsigned field_data_size( const FieldBase & f , const Bucket & k )
00100 {
00101   return k.field_data_size(f);
00102 }
00103 
00105 inline
00106 unsigned field_data_size( const FieldBase & f , const Entity & e )
00107 { return field_data_size( f , e.bucket() ); }
00108 
00109 //----------------------------------------------------------------------
00110 
00111 
00113 template< class field_type >
00114 inline
00115 typename FieldTraits< field_type >::data_type *
00116 field_data( const field_type & f , const Bucket::iterator &i ) 
00117 {
00118   return i.m_bucket_ptr->field_data( f, *i );
00119 }
00120 
00121 
00123 template< class field_type >
00124 inline
00125 typename FieldTraits< field_type >::data_type *
00126 field_data( const field_type & f , const Entity & e )
00127 {
00128   return e.bucket().field_data( f, e );
00129 }
00130 
00131 //----------------------------------------------------------------------
00132 
00133 #ifndef DOXYGEN_COMPILE
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     if (b.field_data_size(f)) {
00180       array_type::assign_stride(
00181           (ScalarType*)(b.field_data_location(f, e ) ), 
00182           b.field_data_stride(f)
00183           );
00184     }
00185   }
00186 #endif /* DOXYGEN_COMPILE */
00187 };
00188 
00189 //----------------------------------------------------------------------
00196 struct EntityDimension : public shards::ArrayDimTag {
00197    
00198   const char * name() const ;
00199    
00200   static const EntityDimension & tag(); 
00201  
00202 private: 
00203   EntityDimension() {} 
00204   EntityDimension( const EntityDimension & ); 
00205   EntityDimension & operator = ( const EntityDimension & );
00206 };
00207 
00208 
00212 template< typename ScalarType >
00213 struct BucketArray< Field<ScalarType,void,void,void,void,void,void,void> >
00214   : public
00215 shards::Array<ScalarType,shards::FortranOrder,EntityDimension,void,void,void,void,void,void> 
00216 {
00217 #ifndef DOXYGEN_COMPILE
00218 private:
00219   typedef unsigned char * byte_p ;
00220   BucketArray();
00221   BucketArray( const BucketArray & );
00222   BucketArray & operator = ( const BucketArray & );
00223 
00224 public:
00225 
00226   typedef Field<ScalarType,void,void,void,void,void,void,void> field_type ;
00227   typedef
00228   shards::Array<ScalarType,shards::FortranOrder,EntityDimension,void,void,void,void,void,void> 
00229   array_type ;
00230 
00231   BucketArray( const field_type & f , const Bucket & k )
00232   {
00233     if (k.field_data_size(f)) {
00234       array_type::assign( (ScalarType*)( k.field_data_location(f,k[0]) ) ,
00235                           k.size() );
00236 
00237     }
00238   }
00239 
00240   BucketArray( const field_type & f,
00241                const Bucket::iterator & i,
00242                const Bucket::iterator & j) 
00243   {
00244     const ptrdiff_t n = j - i ;
00245 
00246     if ( i.m_bucket_ptr->field_data_size(f) && 0 < n ) {
00247       array_type::assign(
00248         (ScalarType*)( i.m_bucket_ptr->field_data_location( f, *i ) ),
00249         (typename array_type::size_type) n );
00250     }
00251   }
00252 
00253 #endif /* DOXYGEN_COMPILE */
00254 };
00255 
00256 //----------------------------------------------------------------------
00260 template< typename ScalarType ,
00261           class Tag1 , class Tag2 , class Tag3 , class Tag4 ,
00262           class Tag5 , class Tag6 , class Tag7 >
00263 struct BucketArray< Field<ScalarType,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> >
00264   : public shards::ArrayAppend<
00265   shards::Array<ScalarType,shards::FortranOrder,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> ,
00266   EntityDimension >::type
00267 {
00268 private:
00269 #ifndef DOXYGEN_COMPILE
00270   typedef unsigned char * byte_p ;
00271   BucketArray();
00272   BucketArray( const BucketArray & );
00273   BucketArray & operator = ( const BucketArray & );
00274 public:
00275 
00276   typedef Field<ScalarType,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> field_type ;
00277 
00278   typedef typename shards::ArrayAppend<
00279     shards::Array<ScalarType,shards::FortranOrder,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> ,
00280     EntityDimension >::type array_type ;
00281 
00282   BucketArray( const field_type & f , const Bucket & b )
00283   {
00284     if ( b.field_data_size(f) ) {
00285       array_type::assign_stride(
00286         (ScalarType*)( b.field_data_location(f,b[0]) ),
00287         b.field_data_stride(f) , (typename array_type::size_type) b.size() );
00288     }
00289   }
00290 
00291   BucketArray( const field_type & f,
00292                const Bucket::iterator & i,
00293                const Bucket::iterator & j) 
00294   {
00295     const ptrdiff_t distance = j - i ;
00296 
00297     if ( 0 < distance ) {
00298 
00299       const Bucket          & b  = * i.m_bucket_ptr ;
00300 
00301       if ( b.field_data_size(f) ) {
00302         array_type::assign_stride(
00303           (ScalarType*)( b.field_data_location(f,*i) ),
00304           b.field_data_stride(f) , (typename array_type::size_type) distance );
00305       }
00306     }
00307   }
00308 
00309 
00310 #endif /* DOXYGEN_COMPILE */
00311 };
00312 
00313 //----------------------------------------------------------------------
00314 
00317 } // namespace mesh
00318 } // namespace stk
00319 
00320 #endif /* stk_mesh_FieldData_hpp */
00321 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends