41 #ifndef DTK_STKMESHFIELD_IMPL_HPP 42 #define DTK_STKMESHFIELD_IMPL_HPP 48 #include <Teuchos_DefaultMpiComm.hpp> 50 #include <stk_mesh/base/FieldParallel.hpp> 51 #include <stk_mesh/base/FieldRestriction.hpp> 52 #include <stk_mesh/base/GetEntities.hpp> 53 #include <stk_mesh/base/MetaData.hpp> 54 #include <stk_mesh/base/Selector.hpp> 60 template <
class Scalar,
class FieldType>
62 const Teuchos::RCP<stk::mesh::BulkData> &bulk_data,
63 const Teuchos::Ptr<FieldType> &field,
const int field_dim )
64 : d_bulk_data( bulk_data )
66 , d_field_dim( field_dim )
69 const stk::mesh::FieldRestrictionVector field_restrictions =
70 d_field->restrictions();
73 stk::mesh::Selector field_selector;
74 for ( stk::mesh::FieldRestriction r : field_restrictions )
76 field_selector = field_selector | r.selector();
80 const stk::mesh::BucketVector &field_buckets =
81 field_selector.get_buckets( d_field->entity_rank() );
84 stk::mesh::get_selected_entities( field_selector, field_buckets,
88 int num_entities = d_field_entities.size();
89 for (
int n = 0; n < num_entities; ++n )
91 d_id_map.emplace( d_bulk_data->identifier( d_field_entities[n] ), n );
95 for (
int n = 0; n < num_entities; ++n )
97 if ( d_bulk_data->parallel_owner_rank( d_field_entities[n] ) ==
98 d_bulk_data->parallel_rank() )
100 d_support_ids.push_back(
101 d_bulk_data->identifier( d_field_entities[n] ) );
108 template <
class Scalar,
class FieldType>
116 template <
class Scalar,
class FieldType>
117 Teuchos::ArrayView<const SupportId>
120 return d_support_ids();
126 template <
class Scalar,
class FieldType>
131 DTK_REQUIRE( d_id_map.count( support_id ) );
132 int local_id = d_id_map.find( support_id )->second;
133 return stk::mesh::field_data( *d_field,
140 template <
class Scalar,
class FieldType>
144 DTK_REQUIRE( d_id_map.count( support_id ) );
145 int local_id = d_id_map.find( support_id )->second;
146 stk::mesh::field_data( *d_field, d_field_entities[local_id] )[
dimension] =
152 template <
class Scalar,
class FieldType>
155 stk::mesh::copy_owned_to_shared(
157 std::vector<const stk::mesh::FieldBase *>( 1, d_field.getRawPtr() ) );
166 #endif // end DTK_STKMESHFIELD_IMPL_HPP double readFieldData(const SupportId support_id, const int dimension) const override
Given a local support id and a dimension, read data from the application field.
STKMeshField(const Teuchos::RCP< stk::mesh::BulkData > &bulk_data, const Teuchos::Ptr< FieldType > &field, const int field_dim)
Constructor.
unsigned long int SupportId
Support id type.
void finalizeAfterWrite() override
Finalize a field after writing into it.
Assertions and Design-by-Contract for error handling.
void writeFieldData(const SupportId support_id, const int dimension, const double data) override
Given a local support id, dimension, and field value, write data into the application field...
int dimension() const override
Get the dimension of the field.
Teuchos::ArrayView< const SupportId > getLocalSupportIds() const override
Get the locally-owned entity support location ids of the field.