9 #ifndef stk_algsup_AlgorithmRunSimple_hpp 10 #define stk_algsup_AlgorithmRunSimple_hpp 14 #include <Shards_ArrayVector.hpp> 16 #include <stk_mesh/base/Types.hpp> 17 #include <stk_mesh/base/FieldData.hpp> 18 #include <stk_algsup/AlgorithmRunner.hpp> 26 template<
class F,
class R >
28 :
public Field<typename FieldTraits<F>::data_type *, R>
30 #ifndef DOXYGEN_COMPILE 35 typedef F RelatedField;
58 typedef std::vector<AlgField *> AlgFieldVector;
65 : m_metaData(meta_data)
71 void add_field(AlgField *field) {
72 m_fieldVector.push_back(field);
75 virtual void apply(
const AlgorithmWork & ) = 0 ;
88 AlgFieldVector m_fieldVector;
93 struct AlgFieldPtr :
public AlgField
95 typedef typename stk_classic::mesh::FieldTraits<T>::data_type Scalar;
97 AlgFieldPtr(Algorithm *algorithm,
const char *name)
98 : m_field(*algorithm->m_metaData.
get_field<T>(name))
100 algorithm->add_field(
this);
104 : m_field(algorithm->m_metaData.
get_field<T>(name)->field_of_state(field_state))
106 algorithm->add_field(
this);
109 AlgFieldPtr(Algorithm *algorithm, T &field)
112 algorithm->add_field(
this);
116 : m_field(field.field_of_state(field_state))
118 algorithm->add_field(
this);
121 virtual ~AlgFieldPtr()
125 m_ptr = stk_classic::mesh::field_data<T>(m_field, bucket.begin());
133 template<
class ArrayType >
138 template<
typename Scalar , shards::ArrayOrder Order ,
139 class Tag1 ,
class Tag2 ,
class Tag3 ,
class Tag4 ,
140 class Tag5 ,
class Tag6 ,
class Tag7>
141 struct ToArrayVector< shards::Array<Scalar,Order,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7,void> >
143 typedef shards::ArrayVector<Scalar,Order,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7,void> ArrayVectorType;
161 struct DimTagInfo<void>
169 template <
class RelationField>
170 class AlgFieldGather;
173 template<
typename Scalar ,
174 class Tag1 ,
class Tag2 ,
class Tag3 ,
class Tag4 ,
175 class Tag5 ,
class Tag6 ,
class Tag7,
class Relation>
176 struct AlgFieldGather<
stk_classic::mesh::GatherField <stk_classic::mesh::Field<Scalar,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7>, Relation> > :
public AlgField
180 typedef typename ToArrayVector<typename shards::ArrayAppend< typename shards::ArrayAppend< shards::Array<Scalar,shards::FortranOrder,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7>, Relation>::type,
stk_classic::mesh::EntityDimension >::type>::ArrayVectorType ScratchArray;
182 AlgFieldGather(Algorithm *algorithm,
const char *name)
183 : m_field(*algorithm->m_metaData.
get_field<PtrField>(name)),
186 algorithm->add_field(
this);
190 : m_field(algorithm->m_metaData.
get_field<PtrField>(name)->field_of_state(field_state)),
193 algorithm->add_field(
this);
210 virtual ~AlgFieldGather()
214 m_begin = stk_classic::mesh::field_data<PtrField>(m_field, bucket.begin());
215 m_end = stk_classic::mesh::field_data<PtrField>(m_field, bucket.end());
218 dims[0] = DimTagInfo<Tag1>::value(bucket);
219 dims[1] = DimTagInfo<Tag2>::value(bucket);
220 dims[2] = DimTagInfo<Tag3>::value(bucket);
221 dims[3] = DimTagInfo<Tag4>::value(bucket);
222 dims[4] = DimTagInfo<Tag5>::value(bucket);
223 dims[5] = DimTagInfo<Tag6>::value(bucket);
224 dims[6] = DimTagInfo<Tag7>::value(bucket);
229 dims[stk_classic::mesh::FieldTraits<T>::Rank] = gather_array.dimension(0);
230 dims[stk_classic::mesh::FieldTraits<T>::Rank + 1] = gather_array.dimension(1);
232 m_array.resize(&dims[0]);
234 for (
int i = 0; i < ScratchArray::Rank - 2; ++i)
235 m_size *= m_array.dimension(i);
237 m_ptr = m_array.contiguous_data();
240 void fill(
const Scalar &value) {
242 for (Scalar **p = m_begin; p != m_end; ++p)
243 for (Scalar *q = *p; q != *p + m_size; ++q)
249 for (Scalar **p = m_begin; p != m_end; ++p)
250 for (Scalar *q = *p; q != *p + m_size; ++q)
257 for (Scalar **p = m_begin; p != m_end; ++p)
258 for (Scalar *q = *p; q != *p + m_size; ++q)
265 for (Scalar **p = m_begin; p != m_end; ++p)
266 for (Scalar *q = *p; q != *p + m_size; ++q)
275 ScratchArray m_array;
279 template <
class RelationField>
283 template<
typename Scalar ,
284 class Tag1 ,
class Tag2 ,
class Tag3 ,
class Tag4 ,
285 class Tag5 ,
class Tag6 ,
class Tag7,
class Relation>
286 struct AlgFieldX<
stk_classic::mesh::GatherField <stk_classic::mesh::Field<Scalar,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7>, Relation> > :
public AlgField
290 typedef typename shards::ArrayAppend< typename shards::ArrayAppend< shards::Array<Scalar,shards::FortranOrder,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7>, Relation>::type,
stk_classic::mesh::EntityDimension >::type Array;
292 AlgFieldX(Algorithm *algorithm,
const char *name)
293 : m_field(*algorithm->m_metaData.
get_field<PtrField>(name)),
298 algorithm->add_field(
this);
302 : m_field(algorithm->m_metaData.
get_field<PtrField>(name)->field_of_state(field_state)),
307 algorithm->add_field(
this);
328 m_begin = stk_classic::mesh::field_data<PtrField>(m_field, bucket.begin());
329 m_end = stk_classic::mesh::field_data<PtrField>(m_field, bucket.end());
352 AlgFieldArray(Algorithm *algorithm,
const char *name)
353 : m_field(*algorithm->m_metaData.
get_field<T>(name))
355 algorithm->add_field(
this);
359 : m_field(algorithm->m_metaData.
get_field<T>(name)->field_of_state(field_state))
361 algorithm->add_field(
this);
364 AlgFieldArray(Algorithm *algorithm, T &field)
367 algorithm->add_field(
this);
371 : m_field(field.field_of_state(field_state))
373 algorithm->add_field(
this);
377 Array::setup(m_field, bucket);
384 template <
class Field>
385 class FillFieldAlgorithm;
387 template<
typename Scalar ,
388 class Tag1 ,
class Tag2 ,
class Tag3 ,
class Tag4 ,
389 class Tag5 ,
class Tag6 ,
class Tag7>
390 class FillFieldAlgorithm<
stk_classic::mesh::Field<Scalar,Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> >
394 typedef shards::ArrayVector<Scalar,shards::FortranOrder, Tag1,Tag2,Tag3,Tag4,Tag5,Tag6,Tag7> FillArray;
396 FillFieldAlgorithm(Field &field,
const FillArray &fill_value)
401 std::vector<unsigned> dims;
402 fill_value.dimensions(dims);
404 m_fillValue.resize(&dims[0]);
405 std::copy(fill_value.contiguous_data(), fill_value.contiguous_data() + fill_value.size(), m_fillValue.contiguous_data());
408 FillFieldAlgorithm(Field &field,
const Scalar &value)
414 enum { chunk_size = 0 };
416 void apply(
const stk_classic::AlgorithmWork & work )
419 if (m_fillValue.size()) {
420 Scalar *begin_p = stk_classic::mesh::field_data<Field>(m_field, work.bucket_slice_begin);
421 Scalar *end_p = stk_classic::mesh::field_data<Field>(m_field, work.bucket_slice_end);
422 for (Scalar *p = begin_p; p != end_p; p += m_fillValue.size())
423 std::copy(m_fillValue.contiguous_data(), m_fillValue.contiguous_data() + m_fillValue.size(), p);
426 Scalar *begin_p = stk_classic::mesh::field_data<Field>(m_field, work.bucket_slice_begin);
427 Scalar *end_p = stk_classic::mesh::field_data<Field>(m_field, work.bucket_slice_end);
428 std::fill(begin_p, end_p, m_value);
434 FillArray m_fillValue;
const stk_classic::mesh::FieldBase * get_field(const FieldIdMap &field_id_map, int field_id)
Field with defined data type and multi-dimensions (if any)
Field with defined data type and multi-dimensions (if any)
A relation between two mesh entities with a relation identifier and kind .
Implement ArrayDimTag for the entity count dimension of a BucketArray.
void fill(ForwardIterator first, ForwardIterator last, const T &value)
A container for the field data of a homogeneous collection of entities.
Field data Array for a given array field and bucket
FieldState
Enumeration of states for multi-state fields.