Sierra Toolkit  Version of the Day
FieldData.hpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010 Sandia Corporation. */
3 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
4 /* license for use of this work by or on behalf of the U.S. Government. */
5 /* Export of this program may require a license from the */
6 /* United States Government. */
7 /*------------------------------------------------------------------------*/
8 
9 
10 #ifndef stk_mesh_FieldData_hpp
11 #define stk_mesh_FieldData_hpp
12 
13 //----------------------------------------------------------------------
14 
15 #include <Shards_Array.hpp>
16 
17 #include <stk_mesh/base/Field.hpp>
18 #include <stk_mesh/base/Bucket.hpp>
19 #include <stk_mesh/base/Entity.hpp>
20 
21 namespace stk_classic {
22 namespace mesh {
23 
65 template< class FieldType > struct BucketArray {};
66 
71 template< class FieldType > struct EntityArray {};
72 
73 //----------------------------------------------------------------------
79 bool field_data_valid( const FieldBase & f ,
80  const Bucket & k ,
81  unsigned ord = 0,
82  const char * required_by = NULL );
83 
89 inline
90 bool field_data_valid( const FieldBase & f ,
91  const Entity & e ,
92  const char * required_by = NULL )
93 { return field_data_valid( f, e.bucket(), e.bucket_ordinal(), required_by ); }
94 
95 //----------------------------------------------------------------------
96 
98 inline
99 unsigned field_data_size( const FieldBase & f , const Bucket & k )
100 {
101  return k.field_data_size(f);
102 }
103 
105 inline
106 unsigned field_data_size( const FieldBase & f , const Entity & e )
107 { return field_data_size( f , e.bucket() ); }
108 
109 //----------------------------------------------------------------------
110 
111 
113 template< class field_type >
114 inline
115 typename FieldTraits< field_type >::data_type *
116 field_data( const field_type & f , const Bucket::iterator i )
117 {
118  return field_data(f,*i);
119 }
120 
121 
123 template< class field_type >
124 inline
125 typename FieldTraits< field_type >::data_type *
126 field_data( const field_type & f , const Entity & e )
127 {
128  return e.bucket().field_data( f, e );
129 }
130 
131 //----------------------------------------------------------------------
132 
133 #ifndef DOXYGEN_COMPILE
134 
135 template< typename ScalarType >
136 struct EntityArray< Field<ScalarType,void,void,void,void,void,void,void> >
137  : public shards::Array<ScalarType,shards::RankZero,void,void,void,void,void,void,void>
138 {
139  typedef Field<ScalarType,void,void,void,void,void,void,void> field_type ;
140  typedef shards::Array<ScalarType,shards::RankZero,void,void,void,void,void,void,void>
141  array_type ;
142 
143  EntityArray( const field_type & f , const Entity & e )
144  : array_type( field_data( f , e ) ) {}
145 
146 private:
147  EntityArray();
148  EntityArray( const EntityArray & );
149  EntityArray & operator = ( const EntityArray & );
150 };
151 #endif /* DOXYGEN_COMPILE */
152 
156 template< typename ScalarType ,
157  class Tag1 , class Tag2 , class Tag3 , class Tag4 ,
158  class Tag5 , class Tag6 , class Tag7 >
159 struct EntityArray< Field<ScalarType,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> >
160  : public shards::Array<ScalarType,shards::FortranOrder,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7>
161 {
162 #ifndef DOXYGEN_COMPILE
163 private:
164  typedef unsigned char * byte_p ;
165  EntityArray();
166  EntityArray( const EntityArray & );
167  EntityArray & operator = ( const EntityArray & );
168 public:
169 
171 
172  typedef
173  shards::Array<ScalarType,shards::FortranOrder,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7>
174  array_type ;
175 
176  EntityArray( const field_type & f , const Entity & e ) : array_type()
177  {
178  const Bucket & b = e.bucket();
179  if (b.field_data_size(f)) {
180  array_type::assign_stride(
181  (ScalarType*)(b.field_data_location(f, e ) ),
182  b.field_data_stride(f)
183  );
184  }
185  }
186 #endif /* DOXYGEN_COMPILE */
187 };
188 
189 //----------------------------------------------------------------------
196 struct EntityDimension : public shards::ArrayDimTag {
197 
198  const char * name() const ;
199 
200  static const EntityDimension & tag();
201 
202 private:
203  EntityDimension() {}
204  EntityDimension( const EntityDimension & );
205  EntityDimension & operator = ( const EntityDimension & );
206 };
207 
208 
212 template< typename ScalarType >
213 struct BucketArray< Field<ScalarType,void,void,void,void,void,void,void> >
214  : public
215 shards::Array<ScalarType,shards::FortranOrder,EntityDimension,void,void,void,void,void,void>
216 {
217 #ifndef DOXYGEN_COMPILE
218 private:
219  typedef unsigned char * byte_p ;
220  BucketArray();
221  BucketArray( const BucketArray & );
222  BucketArray & operator = ( const BucketArray & );
223 
224 public:
225 
227  typedef
228  shards::Array<ScalarType,shards::FortranOrder,EntityDimension,void,void,void,void,void,void>
229  array_type ;
230 
231  BucketArray( const field_type & f , const Bucket & k )
232  {
233  if (k.field_data_size(f)) {
234  array_type::assign( (ScalarType*)( k.field_data_location(f,k[0]) ) ,
235  k.size() );
236 
237  }
238  }
239 
240  BucketArray( const field_type & f,
241  const Bucket::iterator i,
242  const Bucket::iterator j)
243  {
244  const ptrdiff_t n = j - i ;
245 
246  if ( i->bucket().field_data_size(f) && 0 < n ) {
247  array_type::assign(
248  (ScalarType*)( i->bucket().field_data_location( f, *i ) ),
249  (typename array_type::size_type) n );
250  }
251  }
252 
253 #endif /* DOXYGEN_COMPILE */
254 };
255 
256 //----------------------------------------------------------------------
260 template< typename ScalarType ,
261  class Tag1 , class Tag2 , class Tag3 , class Tag4 ,
262  class Tag5 , class Tag6 , class Tag7 >
263 struct BucketArray< Field<ScalarType,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> >
264  : public shards::ArrayAppend<
265  shards::Array<ScalarType,shards::FortranOrder,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> ,
266  EntityDimension >::type
267 {
268 private:
269 #ifndef DOXYGEN_COMPILE
270  typedef unsigned char * byte_p ;
271  BucketArray();
272  BucketArray( const BucketArray & );
273  BucketArray & operator = ( const BucketArray & );
274 public:
275 
277 
278  typedef typename shards::ArrayAppend<
279  shards::Array<ScalarType,shards::FortranOrder,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> ,
280  EntityDimension >::type array_type ;
281 
282  BucketArray( const field_type & f , const Bucket & b )
283  {
284  if ( b.field_data_size(f) ) {
285  array_type::assign_stride(
286  (ScalarType*)( b.field_data_location(f,b[0]) ),
287  b.field_data_stride(f) , (typename array_type::size_type) b.size() );
288  }
289  }
290 
291  BucketArray( const field_type & f,
292  const Bucket::iterator i,
293  const Bucket::iterator j)
294  {
295  const ptrdiff_t distance = j - i ;
296 
297  if ( 0 < distance ) {
298 
299  const Bucket & b = i->bucket();
300 
301  if ( b.field_data_size(f) ) {
302  array_type::assign_stride(
303  (ScalarType*)( b.field_data_location(f,*i) ),
304  b.field_data_stride(f) , (typename array_type::size_type) distance );
305  }
306  }
307  }
308 
309 
310 #endif /* DOXYGEN_COMPILE */
311 };
312 
313 //----------------------------------------------------------------------
314 
317 } // namespace mesh
318 } // namespace stk_classic
319 
320 #endif /* stk_mesh_FieldData_hpp */
321 
unsigned bucket_ordinal() const
The ordinal for this entity within its bucket.
Definition: Entity.hpp:145
Field base class with an anonymous data type and anonymous multi-dimension.
Definition: FieldBase.hpp:53
unsigned field_data_size(const FieldBase &field) const
Query the size of this field data specified by FieldBase.
Definition: Bucket.hpp:128
bool field_data_valid(const FieldBase &f, const Entity &e, const char *required_by=NULL)
Check for existence of field data.
Definition: FieldData.hpp:90
Bucket & bucket() const
The bucket which holds this mesh entity&#39;s field data.
Definition: Entity.hpp:141
const FieldBase::Restriction::size_type * field_data_stride(const FieldBase &field) const
Query the stride of this field data specified by FieldBase.
Definition: Bucket.hpp:132
FieldTraits< field_type >::data_type * field_data(const field_type &f, const Entity &e)
Pointer to the field data array.
Definition: FieldData.hpp:126
static const EntityDimension & tag()
Singleton.
Definition: FieldData.cpp:20
Field with defined data type and multi-dimensions (if any)
Definition: Field.hpp:118
size_t size() const
Number of entities associated with this bucket.
Definition: Bucket.hpp:119
unsigned char * field_data_location(const FieldBase &field, const Entity &entity) const
Query the location of this field data specified by FieldBase and Entity.
Definition: Bucket.hpp:136
Field data Array for a given array field and entity
Definition: FieldData.hpp:71
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
Definition: Entity.hpp:120
Sierra Toolkit.
unsigned field_data_size(const FieldBase &f, const Entity &e)
Size, in bytes, of the field data for each entity.
Definition: FieldData.hpp:106
Implement ArrayDimTag for the entity count dimension of a BucketArray.
Definition: FieldData.hpp:196
A container for the field data of a homogeneous collection of entities.
Definition: Bucket.hpp:94
FieldTraits< field_type >::data_type * field_data(const field_type &field, const Entity &entity) const
Query the location of this field data specified by FieldBase and Entity.
Definition: Bucket.hpp:157
Field data Array for a given array field and bucket
Definition: FieldData.hpp:65