|
Sierra Toolkit Version of the Day
|
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 return k.field_data_size(f); 00069 } 00070 00072 inline 00073 unsigned field_data_size( const FieldBase & f , const Entity & e ) 00074 { return field_data_size( f , e.bucket() ); } 00075 00076 //---------------------------------------------------------------------- 00077 00078 00080 template< class field_type > 00081 inline 00082 typename FieldTraits< field_type >::data_type * 00083 field_data( const field_type & f , const Bucket::iterator &i ) 00084 { 00085 return i.m_bucket_ptr->field_data( f, *i ); 00086 } 00087 00088 00090 template< class field_type > 00091 inline 00092 typename FieldTraits< field_type >::data_type * 00093 field_data( const field_type & f , const Entity & e ) 00094 { 00095 return e.bucket().field_data( f, e ); 00096 } 00097 00098 //---------------------------------------------------------------------- 00099 00100 #ifndef DOXYGEN_COMPILE 00101 00102 void throw_field_data_array( const FieldBase & , unsigned ); 00103 00104 template< typename ScalarType > 00105 struct EntityArray< Field<ScalarType,void,void,void,void,void,void,void> > 00106 : public shards::Array<ScalarType,shards::RankZero,void,void,void,void,void,void,void> 00107 { 00108 typedef Field<ScalarType,void,void,void,void,void,void,void> field_type ; 00109 typedef shards::Array<ScalarType,shards::RankZero,void,void,void,void,void,void,void> 00110 array_type ; 00111 00112 EntityArray( const field_type & f , const Entity & e ) 00113 : array_type( field_data( f , e ) ) {} 00114 00115 private: 00116 EntityArray(); 00117 EntityArray( const EntityArray & ); 00118 EntityArray & operator = ( const EntityArray & ); 00119 }; 00120 #endif /* DOXYGEN_COMPILE */ 00121 00125 template< typename ScalarType , 00126 class Tag1 , class Tag2 , class Tag3 , class Tag4 , 00127 class Tag5 , class Tag6 , class Tag7 > 00128 struct EntityArray< Field<ScalarType,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> > 00129 : public shards::Array<ScalarType,shards::FortranOrder,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> 00130 { 00131 #ifndef DOXYGEN_COMPILE 00132 private: 00133 typedef unsigned char * byte_p ; 00134 EntityArray(); 00135 EntityArray( const EntityArray & ); 00136 EntityArray & operator = ( const EntityArray & ); 00137 public: 00138 00139 typedef Field<ScalarType,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> field_type ; 00140 00141 typedef 00142 shards::Array<ScalarType,shards::FortranOrder,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> 00143 array_type ; 00144 00145 EntityArray( const field_type & f , const Entity & e ) : array_type() 00146 { 00147 const Bucket & b = e.bucket(); 00148 if (b.field_data_size(f)) { 00149 array_type::assign_stride( 00150 (ScalarType*)(b.field_data_location(f, e ) ), 00151 b.field_data_stride(f) 00152 ); 00153 } 00154 } 00155 #endif /* DOXYGEN_COMPILE */ 00156 }; 00157 00158 //---------------------------------------------------------------------- 00165 struct EntityDimension : public shards::ArrayDimTag { 00166 00167 const char * name() const ; 00168 00169 static const EntityDimension & tag(); 00170 00171 private: 00172 EntityDimension() {} 00173 EntityDimension( const EntityDimension & ); 00174 EntityDimension & operator = ( const EntityDimension & ); 00175 }; 00176 00177 00181 template< typename ScalarType > 00182 struct BucketArray< Field<ScalarType,void,void,void,void,void,void,void> > 00183 : public 00184 shards::Array<ScalarType,shards::FortranOrder,EntityDimension,void,void,void,void,void,void> 00185 { 00186 #ifndef DOXYGEN_COMPILE 00187 private: 00188 typedef unsigned char * byte_p ; 00189 BucketArray(); 00190 BucketArray( const BucketArray & ); 00191 BucketArray & operator = ( const BucketArray & ); 00192 00193 public: 00194 00195 typedef Field<ScalarType,void,void,void,void,void,void,void> field_type ; 00196 typedef 00197 shards::Array<ScalarType,shards::FortranOrder,EntityDimension,void,void,void,void,void,void> 00198 array_type ; 00199 00200 BucketArray( const field_type & f , const Bucket & k ) 00201 { 00202 if (k.field_data_size(f)) { 00203 array_type::assign( (ScalarType*)( k.field_data_location(f,k[0]) ) , 00204 k.size() ); 00205 00206 } 00207 } 00208 00209 BucketArray( const field_type & f, 00210 const Bucket::iterator & i, 00211 const Bucket::iterator & j) 00212 { 00213 const ptrdiff_t n = j - i ; 00214 00215 if ( i.m_bucket_ptr->field_data_size(f) && 0 < n ) { 00216 array_type::assign( 00217 (ScalarType*)( i.m_bucket_ptr->field_data_location( f, *i ) ), 00218 (typename array_type::size_type) n ); 00219 } 00220 } 00221 00222 #endif /* DOXYGEN_COMPILE */ 00223 }; 00224 00225 //---------------------------------------------------------------------- 00229 template< typename ScalarType , 00230 class Tag1 , class Tag2 , class Tag3 , class Tag4 , 00231 class Tag5 , class Tag6 , class Tag7 > 00232 struct BucketArray< Field<ScalarType,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> > 00233 : public shards::ArrayAppend< 00234 shards::Array<ScalarType,shards::FortranOrder,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> , 00235 EntityDimension >::type 00236 { 00237 private: 00238 #ifndef DOXYGEN_COMPILE 00239 typedef unsigned char * byte_p ; 00240 BucketArray(); 00241 BucketArray( const BucketArray & ); 00242 BucketArray & operator = ( const BucketArray & ); 00243 public: 00244 00245 typedef Field<ScalarType,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> field_type ; 00246 00247 typedef typename shards::ArrayAppend< 00248 shards::Array<ScalarType,shards::FortranOrder,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> , 00249 EntityDimension >::type array_type ; 00250 00251 BucketArray( const field_type & f , const Bucket & b ) 00252 { 00253 if ( b.field_data_size(f) ) { 00254 array_type::assign_stride( 00255 (ScalarType*)( b.field_data_location(f,b[0]) ), 00256 b.field_data_stride(f) , (typename array_type::size_type) b.size() ); 00257 } 00258 } 00259 00260 BucketArray( const field_type & f, 00261 const Bucket::iterator & i, 00262 const Bucket::iterator & j) 00263 { 00264 const ptrdiff_t distance = j - i ; 00265 00266 if ( 0 < distance ) { 00267 00268 const Bucket & b = * i.m_bucket_ptr ; 00269 00270 if ( b.field_data_size(f) ) { 00271 array_type::assign_stride( 00272 (ScalarType*)( b.field_data_location(f,*i) ), 00273 b.field_data_stride(f) , (typename array_type::size_type) distance ); 00274 } 00275 } 00276 } 00277 00278 00279 #endif /* DOXYGEN_COMPILE */ 00280 }; 00281 00282 //---------------------------------------------------------------------- 00283 00286 } // namespace mesh 00287 } // namespace stk 00288 00289 #endif /* stk_mesh_FieldData_hpp */ 00290