v0.16.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 mat_data_pts vector of pairs of pointers to matrices with field
157 * values at integration points
158 * @param finite_element finite element name on which field is evaluated
159 * @param data_ptr data about field evaluator
160 * @param lower_rank lower processor
161 * @param upper_rank upper processor
162 * @param bit bit reference level
163 * @param mask mask reference level
164 * @param bh control looping over entities, e.g. throwing error if element not
165 * found
166 * @param verb verbosity level
167 * @param data_layout layout of evaluated output matrices
168 * @return ForcesAndSourcesCore::UserDataOperator*
169 */
170 template <int D>
172 getDataOperator(MatDataPts mat_data_pts, const std::string finite_element,
173 boost::shared_ptr<SetIntegrationPtsMethodData> data_ptr,
174 int lower_rank, int upper_rank, BitRefLevel bit,
176 VERBOSITY_LEVELS verb = QUIET,
178
179 /** @brief Evaluate field at arbitrary position
180 *
181 * @param point point used to find tetrahedrons
182 * @param distance distance from the point where tetrahedrons are searched
183 * @param problem problem name
184 * @param finite_element finite element name
185 * @param data_ptr pointer to data abut gauss points
186 * @param lower_rank lower processor
187 * @param upper_rank upper process
188 * @param bit bit reference level
189 * @param mask mask reference level
190 * @param cache_ptr cache or problem entities
191 * @param bh control looping over entities, e.g. throwing error if element not
192 found
193 * @param verb verbosity level
194 * @return MoFEMErrorCode
195 */
196 template <int D>
198 evalFEAtThePoint(const double *const point, const double distance,
199 const std::string problem, const std::string finite_element,
200 boost::shared_ptr<SetIntegrationPtsMethodData> data_ptr,
201 int lower_rank, int upper_rank, BitRefLevel bit,
202 BitRefLevel mask, boost::shared_ptr<CacheTuple> cache_ptr,
204
205private:
207
208 template <int D>
210 buildTreeImpl(boost::shared_ptr<SetIntegrationPtsMethodData> spd_ptr,
211 const std::string finite_element, BitRefLevel bit,
212 BitRefLevel mask);
213
214 template <int D>
216 const double *const point, const double distance,
217 const std::string problem, const std::string finite_element,
218 boost::shared_ptr<SetIntegrationPtsMethodData> data_ptr, int lower_rank,
219 int upper_rank, BitRefLevel bit, BitRefLevel mask,
220 boost::shared_ptr<CacheTuple> cache_ptr, MoFEMTypes bh = MF_EXIST,
221 VERBOSITY_LEVELS verb = QUIET);
222
223 template <int D>
225 getDataOperatorImpl(MatDataPts mat_data_pts, const std::string finite_element,
226 boost::shared_ptr<SetIntegrationPtsMethodData> data_ptr,
227 int lower_rank, int upper_rank, BitRefLevel bit,
229 VERBOSITY_LEVELS verb = QUIET,
231};
232
233template <>
234MoFEMErrorCode FieldEvaluatorInterface::buildTree<2>(
235 boost::shared_ptr<SetIntegrationPtsMethodData> spd_ptr,
236 const std::string finite_element, BitRefLevel bit, BitRefLevel mask);
237
238template <>
239MoFEMErrorCode FieldEvaluatorInterface::buildTree<3>(
240 boost::shared_ptr<SetIntegrationPtsMethodData> spd_ptr,
241 const std::string finite_element, BitRefLevel bit, BitRefLevel mask);
242
243template <>
244MoFEMErrorCode FieldEvaluatorInterface::evalFEAtThePoint<2>(
245 const double *const point, const double distance, const std::string problem,
246 const std::string finite_element,
247 boost::shared_ptr<SetIntegrationPtsMethodData> data_ptr, int lower_rank,
248 int upper_rank, BitRefLevel bit, BitRefLevel mask,
249 boost::shared_ptr<CacheTuple> cache_ptr, MoFEMTypes bh,
250 VERBOSITY_LEVELS verb);
251
252template <>
253MoFEMErrorCode FieldEvaluatorInterface::evalFEAtThePoint<3>(
254 const double *const point, const double distance, const std::string problem,
255 const std::string finite_element,
256 boost::shared_ptr<SetIntegrationPtsMethodData> data_ptr, int lower_rank,
257 int upper_rank, BitRefLevel bit, BitRefLevel mask,
258 boost::shared_ptr<CacheTuple> cache_ptr, MoFEMTypes bh,
259 VERBOSITY_LEVELS verb);
260
261template <>
263FieldEvaluatorInterface::getDataOperator<2>(
265 const std::string finite_element,
266 boost::shared_ptr<SetIntegrationPtsMethodData> data_ptr, int lower_rank,
267 int upper_rank, BitRefLevel bit, BitRefLevel mask, MoFEMTypes bh,
268 VERBOSITY_LEVELS verb, DataLayout data_layout);
269
270template <>
272FieldEvaluatorInterface::getDataOperator<3>(
274 const std::string finite_element,
275 boost::shared_ptr<SetIntegrationPtsMethodData> data_ptr, int lower_rank,
276 int upper_rank, BitRefLevel bit, BitRefLevel mask, MoFEMTypes bh,
277 VERBOSITY_LEVELS verb, DataLayout data_layout);
278
280
282
283 /**
284 * @brief Set the Gauss Pts data
285 *
286 * @param fe_method_ptr pointer to finite element instance
287 * @param eval_points pointer to array with evaluation points
288 * @param nb_eval_points number of evaluated points
289 * @param eps tolerance used to find if point is in the element
290 * @param verb
291 */
293 boost::shared_ptr<MoFEM::ForcesAndSourcesCore> fe_method_ptr,
294 const double *eval_points, const int nb_eval_points, const double eps,
296
297 void setEvalPoints(const double *ptr, const int nb_eval_points);
298
299 boost::shared_ptr<MoFEM::ForcesAndSourcesCore> feMethodPtr;
301 boost::shared_ptr<AdaptiveKDTree> treePtr;
302
303protected:
304 const double *evalPoints;
306 double eps;
308
311 std::vector<EntityHandle> evalPointEntityHandle;
312
315};
316
320 boost::shared_ptr<SetIntegrationPtsMethodData> data_ptr);
321 MoFEMErrorCode operator()(ForcesAndSourcesCore *fe_raw_ptr, int order_row,
322 int order_col, int order_data);
323
324private:
325 boost::weak_ptr<SetIntegrationPtsMethodData> dataPtr;
326};
327
328/*
329 template <typename VE, typename SPD = SetIntegrationPtsMethodData,
330 typename SP = SetIntegrationPtsMethod>
331*/
332template <typename VE, typename SPD, typename SP>
333boost::shared_ptr<SPD>
334FieldEvaluatorInterface::getData(const double *ptr, const int nb_eval_points,
335 const double eps, VERBOSITY_LEVELS verb) {
336 MoFEM::Interface &m_field = cOre;
337 auto ve_method_ptr = boost::make_shared<VE>(m_field);
338 auto spd_ptr =
339 boost::make_shared<SPD>(ve_method_ptr, ptr, nb_eval_points, eps, verb);
340 ve_method_ptr->setRuleHook = SP(spd_ptr);
341 return spd_ptr;
342}
343
344} // namespace MoFEM
345
346#endif // __FIELD_EVALUATOR_HPP__
347
348/**
349 * \defgroup field_evaluator Field Evaluator
350 * \brief Evaluate field at the point
351 *
352 * \ingroup mofem
353 */
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:83
Deprecated interface functions.
boost::shared_ptr< MoFEM::ForcesAndSourcesCore > feMethodPtr
void setEvalPoints(const double *ptr, const int nb_eval_points)
MoFEMErrorCode operator()(ForcesAndSourcesCore *fe_raw_ptr, int order_row, int order_col, int order_data)
boost::weak_ptr< SetIntegrationPtsMethodData > dataPtr
Field evaluator interface.
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, DataLayout data_layout=DataLayout::GaussByCoeffs)
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, DataLayout data_layout=DataLayout::GaussByCoeffs)
Evaluate field values at integration points of finite elements to which operator is pushed.
structure to get information from mofem into EntitiesFieldData
base class for all interface classes