v0.15.0
Loading...
Searching...
No Matches
FieldEvaluator.hpp
Go to the documentation of this file.
1/** \file FieldEvaluator.hpp
2 * \brief Field Evaluator
3 *
4 * Evaluate field at given coordinate
5 *
6 *
7 * \ingroup field_evaluator
8 */
9
10#ifndef __FIELD_EVALUATOR_HPP__
11 #define __FIELD_EVALUATOR_HPP__
12
13 #include "UnknownInterface.hpp"
14
15namespace MoFEM {
16
17/** \brief Field evaluator interface
18
19 * \ingroup field_evaluator
20 */
22
25
26 /**
27 * @brief Default evaluator for setting integration points
28 *
29 */
31
32 MoFEMErrorCode query_interface(boost::typeindex::type_index type_index,
33 UnknownInterface **iface) const;
34
36
37 /**
38 * @brief Get the Data object
39 *
40 * Pack pointers with data structures for field evaluator and finite
41 * element. Function return shared pointer if returned shared pointer
42 * is reset; all data are destroyed. The idea is to pack all data in
43 * one structure, create shared pointer to it and return aliased shared
44 * pointer to one of the elements of the data structure. It is a bit
45 * complicated, but has great flexibility.
46 *
47 * @tparam VE
48 * @tparam SetIntegrationPtsMethodData
49 * @tparam SetIntegrationPtsMethod
50 * @param ptr
51 * @param nb_eval_points
52 * @param eps
53 * @param verb
54 * @return boost::shared_ptr<SPD>
55 */
56 template <typename VE, typename SPD = SetIntegrationPtsMethodData,
57 typename SP = SetIntegrationPtsMethod>
58 boost::shared_ptr<SPD>
59 getData(const double *ptr = nullptr, const int nb_eval_points = 0,
60 const double eps = 1e-12, VERBOSITY_LEVELS verb = QUIET);
61
62 /**
63 * @brief Build spatial tree
64 *
65 * @param finite_element finite element name
66 * @return MoFEMErrorCode
67 */
68 template <int D>
69 inline MoFEMErrorCode
70 buildTree(boost::shared_ptr<SetIntegrationPtsMethodData> spd_ptr,
71 const std::string finite_element) {
72 return buildTree<D>(spd_ptr, finite_element, BitRefLevel(), BitRefLevel());
73 }
74
75 /**
76 * @brief Build spatial tree
77 *
78 * @param finite_element finite element name
79 * @param bit bit reference level
80 * @param mask mask reference level
81 * @return MoFEMErrorCode
82 */
83 template <int D>
85 buildTree(boost::shared_ptr<SetIntegrationPtsMethodData> spd_ptr,
86 const std::string finite_element, BitRefLevel bit,
87 BitRefLevel mask);
88
89 /**
90 * @brief Evaluate field at arbitrary position
91 *
92 * \code
93
94 std::array<double, 3> point = {0, 0, 0};
95 const double dist = 0.3;
96 std::array<double, 6> eval_points = {-1., -1., -1., 1., 1., 1. };
97
98 using VolEle = VolumeElementForcesAndSourcesCore;
99 auto data_ptr =
100 m_field.getInterface<FieldEvaluatorInterface>()->
101 getData<VolEle>(point.data(), point.size/3);
102
103 if(auto vol_ele = data_ptr->feMethod.lock()) {
104 // push operators to finite element instance, e.g.
105 vol_ele->getOpPtrVector().push_back(new MyOp());
106 // iterate over elemnts with evaluated points
107 auto cache_ptr = boost::make_shared<CacheTuple>();
108 CHKERR m_field.cache_problem_entities(prb_ptr->getName(), cache_ptr);
109 // SPACE_DIM is 3 in this example
110 CHKERR m_field.getInterface<FieldEvaluatorInterface>()
111 ->evalFEAtThePoint<3>(point.data(), dist, prb_ptr->getName(),
112 "FINITE_ELEMENT_NAME",
113 data_ptr, m_field.get_comm_rank(),
114 m_field.get_comm_rank(), cache_ptr);
115 }
116
117 * \endcode
118 *
119 * @param point point used to find tetrahedrons
120 * @param distance distance from the point where tetrahedrons are searched
121 * @param problem problem name
122 * @param finite_element finite element name
123 * @param data_ptr pointer to data abut gauss points
124 * @param lower_rank lower processor
125 * @param upper_rank upper process
126 * @param cache_ptr cache or problem entities
127 * @param bh control looping over entities, e.g. throwing error if element not
128 found
129 * @param verb verbosity level
130 * @return MoFEMErrorCode
131 */
132 template <int D>
133 inline MoFEMErrorCode
134 evalFEAtThePoint(const double *const point, const double distance,
135 const std::string problem, const std::string finite_element,
136 boost::shared_ptr<SetIntegrationPtsMethodData> data_ptr,
137 int lower_rank, int upper_rank,
138 boost::shared_ptr<CacheTuple> cache_ptr,
140 return evalFEAtThePoint<D>(point, distance, problem, finite_element,
141 data_ptr, lower_rank, upper_rank, BitRefLevel(),
142 BitRefLevel(), cache_ptr, bh, verb);
143 }
144
145 using MatDataPts = std::vector<
146
147 std::pair<boost::shared_ptr<MatrixDouble>,
148 boost::shared_ptr<MatrixDouble>>
149
150 >;
151
152 /**
153 * @brief Evaluate field values at integration points of finite elements
154 * to which operator is pushed
155 *
156 * @param vec_data_pts vector of data shared between physical and post
157 * proc elements
158 * @param mat_data_pts matrix of data shared between physical and post
159 * proc elements
160 * @param finite_element finite element name on which field is evaluated
161 * @param data_ptr data about field evaluator
162 * @param bh control looping over entities, e.g. throwing error if element not
163 * found
164 *
165 */
166 template <int D>
168 getDataOperator(MatDataPts mat_data_pts, const std::string finite_element,
169 boost::shared_ptr<SetIntegrationPtsMethodData> data_ptr,
170 int lower_rank, int upper_rank, BitRefLevel bit,
172 VERBOSITY_LEVELS verb = QUIET);
173
174 /** @brief Evaluate field at arbitrary position
175 *
176 * @param point point used to find tetrahedrons
177 * @param distance distance from the point where tetrahedrons are searched
178 * @param problem problem name
179 * @param finite_element finite element name
180 * @param data_ptr pointer to data abut gauss points
181 * @param lower_rank lower processor
182 * @param upper_rank upper process
183 * @param bit bit reference level
184 * @param mask mask reference level
185 * @param cache_ptr cache or problem entities
186 * @param bh control looping over entities, e.g. throwing error if element not
187 found
188 * @param verb verbosity level
189 * @return MoFEMErrorCode
190 */
191 template <int D>
193 evalFEAtThePoint(const double *const point, const double distance,
194 const std::string problem, const std::string finite_element,
195 boost::shared_ptr<SetIntegrationPtsMethodData> data_ptr,
196 int lower_rank, int upper_rank, BitRefLevel bit,
197 BitRefLevel mask, boost::shared_ptr<CacheTuple> cache_ptr,
199
200private:
202
203 template <int D>
205 buildTreeImpl(boost::shared_ptr<SetIntegrationPtsMethodData> spd_ptr,
206 const std::string finite_element, BitRefLevel bit,
207 BitRefLevel mask);
208
209 template <int D>
211 const double *const point, const double distance,
212 const std::string problem, const std::string finite_element,
213 boost::shared_ptr<SetIntegrationPtsMethodData> data_ptr, int lower_rank,
214 int upper_rank, BitRefLevel bit, BitRefLevel mask,
215 boost::shared_ptr<CacheTuple> cache_ptr, MoFEMTypes bh = MF_EXIST,
216 VERBOSITY_LEVELS verb = QUIET);
217
218 template <int D>
220 getDataOperatorImpl(MatDataPts mat_data_pts, const std::string finite_element,
221 boost::shared_ptr<SetIntegrationPtsMethodData> data_ptr,
222 int lower_rank, int upper_rank, BitRefLevel bit,
224 VERBOSITY_LEVELS verb = QUIET);
225};
226
227template <>
228MoFEMErrorCode FieldEvaluatorInterface::buildTree<2>(
229 boost::shared_ptr<SetIntegrationPtsMethodData> spd_ptr,
230 const std::string finite_element, BitRefLevel bit, BitRefLevel mask);
231
232template <>
233MoFEMErrorCode FieldEvaluatorInterface::buildTree<3>(
234 boost::shared_ptr<SetIntegrationPtsMethodData> spd_ptr,
235 const std::string finite_element, BitRefLevel bit, BitRefLevel mask);
236
237template <>
238MoFEMErrorCode FieldEvaluatorInterface::evalFEAtThePoint<2>(
239 const double *const point, const double distance, const std::string problem,
240 const std::string finite_element,
241 boost::shared_ptr<SetIntegrationPtsMethodData> data_ptr, int lower_rank,
242 int upper_rank, BitRefLevel bit, BitRefLevel mask,
243 boost::shared_ptr<CacheTuple> cache_ptr, MoFEMTypes bh,
244 VERBOSITY_LEVELS verb);
245
246template <>
247MoFEMErrorCode FieldEvaluatorInterface::evalFEAtThePoint<3>(
248 const double *const point, const double distance, const std::string problem,
249 const std::string finite_element,
250 boost::shared_ptr<SetIntegrationPtsMethodData> data_ptr, int lower_rank,
251 int upper_rank, BitRefLevel bit, BitRefLevel mask,
252 boost::shared_ptr<CacheTuple> cache_ptr, MoFEMTypes bh,
253 VERBOSITY_LEVELS verb);
254
255template <>
257FieldEvaluatorInterface::getDataOperator<2>(
259 const std::string finite_element,
260 boost::shared_ptr<SetIntegrationPtsMethodData> data_ptr, int lower_rank,
261 int upper_rank, BitRefLevel bit, BitRefLevel mask, MoFEMTypes bh,
262 VERBOSITY_LEVELS verb);
263
264template <>
266FieldEvaluatorInterface::getDataOperator<3>(
268 const std::string finite_element,
269 boost::shared_ptr<SetIntegrationPtsMethodData> data_ptr, int lower_rank,
270 int upper_rank, BitRefLevel bit, BitRefLevel mask, MoFEMTypes bh,
271 VERBOSITY_LEVELS verb);
272
274
276
277 /**
278 * @brief Set the Gauss Pts data
279 *
280 * @param fe_method_ptr pointer to finite element instance
281 * @param eval_points pointer to array with evaluation points
282 * @param nb_eval_points number of evaluated points
283 * @param eps tolerance used to find if point is in the element
284 * @param verb
285 */
287 boost::shared_ptr<MoFEM::ForcesAndSourcesCore> fe_method_ptr,
288 const double *eval_points, const int nb_eval_points, const double eps,
290
291 void setEvalPoints(const double *ptr, const int nb_eval_points);
292
293 boost::weak_ptr<MoFEM::ForcesAndSourcesCore> feMethodPtr;
295 boost::scoped_ptr<AdaptiveKDTree> treePtr;
296
297protected:
298 const double *evalPoints;
300 double eps;
302
305 std::vector<EntityHandle> evalPointEntityHandle;
306
309};
310
314 boost::shared_ptr<SetIntegrationPtsMethodData> data_ptr);
315 MoFEMErrorCode operator()(ForcesAndSourcesCore *fe_raw_ptr, int order_row,
316 int order_col, int order_data);
317
318private:
319 boost::weak_ptr<SetIntegrationPtsMethodData> dataPtr;
320};
321
322template <typename VE, typename SPD, typename SP>
323boost::shared_ptr<SPD>
324FieldEvaluatorInterface::getData(const double *ptr, const int nb_eval_points,
325 const double eps, VERBOSITY_LEVELS verb) {
326
327 struct PackData {
328 boost::scoped_ptr<VE> elePtr; //< finite element pointer
329 boost::scoped_ptr<SPD> setPtsDataPtr; //< integration pts data
330 boost::scoped_ptr<SP> setPtsPtr; //< integration pts method
331 };
332 boost::shared_ptr<PackData> pack_data(new PackData());
333 MoFEM::Interface &m_field = cOre;
334 pack_data->elePtr.reset(new VE(m_field));
335
336 pack_data->setPtsDataPtr.reset(
337 new SPD(boost::shared_ptr<VE>(pack_data, pack_data->elePtr.get()), ptr,
338 nb_eval_points, eps, verb));
339 pack_data->setPtsPtr.reset(new SP(
340 boost::shared_ptr<SPD>(pack_data, pack_data->setPtsDataPtr.get())));
341 pack_data->elePtr->setRuleHook = boost::ref(*pack_data->setPtsPtr);
342 boost::shared_ptr<SPD> data(pack_data, pack_data->setPtsDataPtr.get());
343 return data;
344}
345
346} // namespace MoFEM
347
348#endif // __FIELD_EVALUATOR_HPP__
349
350/**
351 * \defgroup field_evaluator Field Evaluator
352 * \brief Evaluate field at the point
353 *
354 * \ingroup mofem
355 */
MoFEM interface.
static const double eps
VERBOSITY_LEVELS
Verbosity levels.
@ QUIET
MoFEMTypes
Those types control how functions respond on arguments, f.e. error handling.
@ MF_EXIST
auto bit
set bit
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition Types.hpp:40
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
Core (interface) class.
Definition Core.hpp:82
Deprecated interface functions.
void setEvalPoints(const double *ptr, const int nb_eval_points)
boost::weak_ptr< MoFEM::ForcesAndSourcesCore > feMethodPtr
MoFEMErrorCode operator()(ForcesAndSourcesCore *fe_raw_ptr, int order_row, int order_col, int order_data)
boost::weak_ptr< SetIntegrationPtsMethodData > dataPtr
Field evaluator interface.
ForcesAndSourcesCore::UserDataOperator * getDataOperator(MatDataPts mat_data_pts, const std::string finite_element, boost::shared_ptr< SetIntegrationPtsMethodData > data_ptr, int lower_rank, int upper_rank, BitRefLevel bit, BitRefLevel mask, MoFEMTypes bh=MF_EXIST, VERBOSITY_LEVELS verb=QUIET)
Evaluate field values at integration points of finite elements to which operator is pushed.
MoFEMErrorCode evalFEAtThePoint(const double *const point, const double distance, const std::string problem, const std::string finite_element, boost::shared_ptr< SetIntegrationPtsMethodData > data_ptr, int lower_rank, int upper_rank, boost::shared_ptr< CacheTuple > cache_ptr, MoFEMTypes bh=MF_EXIST, VERBOSITY_LEVELS verb=QUIET)
Evaluate field at arbitrary position.
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
MoFEMErrorCode evalFEAtThePoint(const double *const point, const double distance, const std::string problem, const std::string finite_element, boost::shared_ptr< SetIntegrationPtsMethodData > data_ptr, int lower_rank, int upper_rank, BitRefLevel bit, BitRefLevel mask, boost::shared_ptr< CacheTuple > cache_ptr, MoFEMTypes bh=MF_EXIST, VERBOSITY_LEVELS verb=QUIET)
Evaluate field at arbitrary position.
std::vector< std::pair< boost::shared_ptr< MatrixDouble >, boost::shared_ptr< MatrixDouble > > > MatDataPts
boost::shared_ptr< SPD > getData(const double *ptr=nullptr, const int nb_eval_points=0, const double eps=1e-12, VERBOSITY_LEVELS verb=QUIET)
Get the Data object.
MoFEMErrorCode buildTreeImpl(boost::shared_ptr< SetIntegrationPtsMethodData > spd_ptr, const std::string finite_element, BitRefLevel bit, BitRefLevel mask)
MoFEMErrorCode buildTree(boost::shared_ptr< SetIntegrationPtsMethodData > spd_ptr, const std::string finite_element)
Build spatial tree.
MoFEMErrorCode buildTree(boost::shared_ptr< SetIntegrationPtsMethodData > spd_ptr, const std::string finite_element, BitRefLevel bit, BitRefLevel mask)
Build spatial tree.
MoFEMErrorCode evalFEAtThePointImpl(const double *const point, const double distance, const std::string problem, const std::string finite_element, boost::shared_ptr< SetIntegrationPtsMethodData > data_ptr, int lower_rank, int upper_rank, BitRefLevel bit, BitRefLevel mask, boost::shared_ptr< CacheTuple > cache_ptr, MoFEMTypes bh=MF_EXIST, VERBOSITY_LEVELS verb=QUIET)
ForcesAndSourcesCore::UserDataOperator * getDataOperatorImpl(MatDataPts mat_data_pts, const std::string finite_element, boost::shared_ptr< SetIntegrationPtsMethodData > data_ptr, int lower_rank, int upper_rank, BitRefLevel bit, BitRefLevel mask, MoFEMTypes bh=MF_EXIST, VERBOSITY_LEVELS verb=QUIET)
structure to get information from mofem into EntitiesFieldData
base class for all interface classes