11namespace FromTagsImpl {
22 for (
int k = 0;
k != NB; ++
k)
29 static_assert(DIM == 2 || DIM == 3,
30 "Symmetric tensor tags are implemented for DIM = 2, 3");
36 if constexpr (DIM == 2)
39 return {0, 3, 4, 1, 5, 2};
45template <
int DIM0,
int DIM1>
49 return identityMap<DIM0 * DIM1>();
52 if constexpr (DIM0 == 2 &&
DIM1 == 2) {
54 }
else if constexpr (DIM0 == 3 &&
DIM1 == 3) {
55 return {0, 3, 5, 4, 1, 7, 6, 8, 2};
67 const int nb_components,
const bool allow_longer_tag,
68 Tag &
th,
int &tag_length) {
70 if (moab.tag_get_handle(tag_name.c_str(),
th) != MB_SUCCESS)
74 CHKERR moab.tag_get_data_type(
th, data_type);
75 if (data_type != MB_TYPE_DOUBLE)
77 "Tag %s must hold doubles", tag_name.c_str());
78 if (moab.tag_get_length(
th, tag_length) != MB_SUCCESS)
80 "Tag %s must have a fixed length", tag_name.c_str());
81 if (allow_longer_tag ? tag_length < nb_components
82 : tag_length != nb_components)
84 "Tag %s has %d components, expected %s%d", tag_name.c_str(),
85 tag_length, allow_longer_tag ?
"at least " :
"", nb_components);
91 const std::string &tag_name,
const EntityHandle *ents,
92 const int nb_ents,
double *data) {
94 const auto rval = moab.tag_get_data(
th, ents, nb_ents, data);
95 if (
rval == MB_TAG_NOT_FOUND) {
96 for (
int i = 0;
i != nb_ents; ++
i) {
97 if (moab.tag_get_data(
th, &ents[
i], 1, data) == MB_TAG_NOT_FOUND)
99 "Tag %s has no value on %s %lu and no default value",
112 std::vector<double> &shape,
115 const int nb_gauss = gauss_pts.size2();
116 const int dim = moab::CN::Dimension(
type);
117 if (
static_cast<int>(gauss_pts.size1()) < dim)
119 "Integration points have %zu rows, expected at least %d for %s",
120 gauss_pts.size1(), dim, moab::CN::EntityTypeName(
type));
122 auto ksi = [&](
const int d) {
return nb_gauss ? &gauss_pts(
d, 0) :
nullptr; };
126 shape.assign(nb_gauss, 1.);
130 shape.resize(nb_nodes * nb_gauss);
131 CHKERR Tools::shapeFunMBEDGE<1>(shape.data(), ksi(0), nb_gauss);
135 shape.resize(nb_nodes * nb_gauss);
136 CHKERR Tools::shapeFunMBTRI<1>(shape.data(), ksi(0), ksi(1), nb_gauss);
140 shape.resize(nb_nodes * nb_gauss);
141 CHKERR Tools::shapeFunMBQUAD<1>(shape.data(), ksi(0), ksi(1), nb_gauss);
145 shape.resize(nb_nodes * nb_gauss);
146 CHKERR Tools::shapeFunMBTET<1>(shape.data(), ksi(0), ksi(1), ksi(2),
151 shape.resize(nb_nodes * nb_gauss);
152 CHKERR Tools::shapeFunMBHEX<1>(shape.data(), ksi(0), ksi(1), ksi(2),
157 "Vertex tag interpolation is not implemented for %s",
158 moab::CN::EntityTypeName(
type));
170template <
int NB, TagSpace SPACE,
typename OUT>
173 OpFromTags(
const std::string &tag_name, boost::shared_ptr<OUT> data_ptr,
190 const int nb_gauss = gauss_pts.size2();
193 const EntityHandle *nodes = &fe_ent;
197 if (
type != MBVERTEX) {
199 CHKERR moab.get_connectivity(fe_ent, nodes, nb_corners,
true);
200 if (nb_corners != nb_nodes)
202 "%s has %d corners, expected %d",
203 moab::CN::EntityTypeName(
type), nb_corners, nb_nodes);
211 for (
int n = 0;
n != nb_nodes; ++
n)
212 for (
int k = 0;
k != NB; ++
k)
215 auto value_at = [&](
const int gg,
const int k) {
221 for (
int n = 0;
n != nb_nodes; ++
n)
227 if constexpr (std::is_same_v<OUT, VectorDouble>) {
228 static_assert(NB == 1,
"Scalar output takes one component");
230 vec.resize(nb_gauss,
false);
231 for (
int gg = 0; gg != nb_gauss; ++gg)
232 vec[gg] = value_at(gg, 0);
240 auto t_values = get_values();
241 for (
int gg = 0; gg != nb_gauss; ++gg) {
242 for (
int k = 0;
k != NB; ++
k)
243 t_values(
k) = value_at(gg,
k);
262template <
int NB,
typename OUT>
264createOp(
const std::string &tag_name, boost::shared_ptr<OUT> data_ptr,
266 const bool allow_longer_tag) {
272 tag_name, data_ptr, component_map, allow_longer_tag);
275 tag_name, data_ptr, component_map, allow_longer_tag);
283ForcesAndSourcesCore::UserDataOperator *
285 const std::string tag_name, boost::shared_ptr<VectorDouble> data_ptr,
286 const TagSpace space,
const bool allow_longer_tag) {
287 return FromTagsImpl::createOp<1>(tag_name, data_ptr, space,
288 FromTagsImpl::identityMap<1>(),
293ForcesAndSourcesCore::UserDataOperator *
295 const std::string tag_name, boost::shared_ptr<MatrixDouble> data_ptr,
296 const TagSpace space,
const bool allow_longer_tag) {
297 return FromTagsImpl::createOp<DIM>(tag_name, data_ptr, space,
298 FromTagsImpl::identityMap<DIM>(),
303ForcesAndSourcesCore::UserDataOperator *
305 const std::string tag_name, boost::shared_ptr<MatrixDouble> data_ptr,
307 const bool allow_longer_tag) {
309 tag_name, data_ptr, space, FromTagsImpl::symmetricMap<DIM>(notation),
313template <
int DIM0,
int DIM1>
314ForcesAndSourcesCore::UserDataOperator *
316 const std::string tag_name, boost::shared_ptr<MatrixDouble> data_ptr,
318 const bool allow_longer_tag) {
319 return FromTagsImpl::createOp<DIM0 * DIM1>(
320 tag_name, data_ptr, space, FromTagsImpl::fullMap<DIM0, DIM1>(notation),
324#define INSTANTIATE_VECTOR_FROM_TAGS(DIM) \
325 template ForcesAndSourcesCore::UserDataOperator * \
326 createOpCalculateVectorFieldValuesFromTags<DIM>( \
327 const std::string, boost::shared_ptr<MatrixDouble>, const TagSpace, \
330#define INSTANTIATE_SYMMETRIC_FROM_TAGS(DIM) \
331 template ForcesAndSourcesCore::UserDataOperator * \
332 createOpCalculateTensor2SymmetricFieldValuesFromTags<DIM>( \
333 const std::string, boost::shared_ptr<MatrixDouble>, const TagSpace, \
334 const TagNotation, const bool);
336#define INSTANTIATE_TENSOR2_FROM_TAGS(DIM0, DIM1) \
337 template ForcesAndSourcesCore::UserDataOperator * \
338 createOpCalculateTensor2FieldValuesFromTags<DIM0, DIM1>( \
339 const std::string, boost::shared_ptr<MatrixDouble>, const TagSpace, \
340 const TagNotation, const bool);
352#undef INSTANTIATE_VECTOR_FROM_TAGS
353#undef INSTANTIATE_SYMMETRIC_FROM_TAGS
354#undef INSTANTIATE_TENSOR2_FROM_TAGS
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_DATA_INCONSISTENCY
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define THROW_MESSAGE(msg)
Throw MoFEM exception.
TagSpace
Where tag values live and how they are evaluated.
ForcesAndSourcesCore::UserDataOperator * createOpCalculateScalarFieldValuesFromTags(const std::string tag_name, boost::shared_ptr< VectorDouble > data_ptr, const TagSpace space, const bool allow_longer_tag)
Create operator evaluating a scalar tag at integration points.
TagNotation
Component order of a tensor stored on a tag.
ForcesAndSourcesCore::UserDataOperator * createOpCalculateTensor2SymmetricFieldValuesFromTags(const std::string tag_name, boost::shared_ptr< MatrixDouble > data_ptr, const TagSpace space, const TagNotation notation, const bool allow_longer_tag)
Create operator evaluating a symmetric tensor tag at integration points.
ForcesAndSourcesCore::UserDataOperator * createOpCalculateVectorFieldValuesFromTags(const std::string tag_name, boost::shared_ptr< MatrixDouble > data_ptr, const TagSpace space, const bool allow_longer_tag)
Create operator evaluating a vector tag at integration points.
ForcesAndSourcesCore::UserDataOperator * createOpCalculateTensor2FieldValuesFromTags(const std::string tag_name, boost::shared_ptr< MatrixDouble > data_ptr, const TagSpace space, const TagNotation notation, const bool allow_longer_tag)
Create operator evaluating a second-order tensor tag at integration points.
FTensor::Index< 'i', SPACE_DIM > i
FTensor::Index< 'k', 3 > k
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
auto type_from_handle(const EntityHandle h)
get type from entity handle
auto id_from_handle(const EntityHandle h)
decltype(GetFTensor1FromMatImpl< Tensor_Dim, S, DL, M >::get(std::declval< M & >(), 0, 0)) GetFTensor1FromMatType
virtual moab::Interface & get_moab()=0
Data on single entity (This is passed as argument to DataOperator::doWork)
EntityHandle getFEEntityHandle() const
Return finite element entity handle.
ForcesAndSourcesCore * getPtrFE() const
@ OPSPACE
operator do Work is execute on space data
MatrixDouble & getGaussPts()
matrix of integration (Gauss) points for Volume Element