v0.13.2
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
23 MoFEMErrorCode query_interface(boost::typeindex::type_index type_index,
24 UnknownInterface **iface) const;
25
28
29 struct SetPtsData {
30
31 SetPtsData() = delete;
32
33 /**
34 * @brief Set the Gauss Pts data
35 *
36 * @param fe_method_ptr pointer to finite element instance
37 * @param eval_points pointer to array with evaluation points
38 * @param nb_eval_points number of evaluated points
39 * @param eps tolerance used to find if point is in the element
40 * @param verb
41 */
42 SetPtsData(boost::shared_ptr<MoFEM::ForcesAndSourcesCore> fe_method_ptr,
43 const double *eval_points, const int nb_eval_points,
44 const double eps, VERBOSITY_LEVELS verb = QUIET)
45 : feMethodPtr(fe_method_ptr), evalPoints(eval_points),
46 nbEvalPoints(nb_eval_points), eps(eps), verb(verb) {
47 localCoords.resize(nbEvalPoints, 3);
49 }
50
51 inline void setEvalPoints(const double *ptr, const int nb_eval_points) {
52 evalPoints = ptr;
53 nbEvalPoints = nb_eval_points;
54 localCoords.resize(nbEvalPoints, 3, false);
55 shapeFunctions.resize(nbEvalPoints, 4, false);
56 }
57
58 boost::weak_ptr<MoFEM::ForcesAndSourcesCore> feMethodPtr;
59 const double *evalPoints;
61 double eps;
63
66 std::vector<EntityHandle> evalPointEntityHandle;
67
69 boost::scoped_ptr<AdaptiveKDTree> treePtr;
70 };
71
72 /**
73 * @brief Default evaluator for setting integration points
74 *
75 */
76 struct SetPts {
77 SetPts() = delete;
78 SetPts(boost::shared_ptr<SetPtsData> data_ptr) : dataPtr(data_ptr) {}
79 MoFEMErrorCode operator()(ForcesAndSourcesCore *fe_raw_ptr, int order_row,
80 int order_col, int order_data);
81
82 private:
83 boost::weak_ptr<SetPtsData> dataPtr;
84 };
85
86 /**
87 * @brief Get the Data object
88 *
89 * Pack pointers with data structures for field evaluator and finite
90 * element. Function return shared pointer if returned shared pointer
91 * is reset; all data are destroyed. The idea is to pack all data in
92 * one structure, create shared pointer to it and return aliased shared
93 * pointer to one of the elements of the data structure. It is a bit
94 * complicated, but has great flexibility.
95 *
96 * @tparam VE
97 * @tparam SetPtsData
98 * @tparam SetPts
99 * @param ptr
100 * @param nb_eval_points
101 * @param eps
102 * @param verb
103 * @return boost::shared_ptr<SPD>
104 */
105 template <typename VE, typename SPD = SetPtsData, typename SP = SetPts>
106 boost::shared_ptr<SPD>
107 getData(const double *ptr = nullptr, const int nb_eval_points = 0,
108 const double eps = 1e-12, VERBOSITY_LEVELS verb = QUIET) {
109 struct PackData {
110 boost::scoped_ptr<VE> elePtr;
111 boost::scoped_ptr<SPD> setPtsDataPtr;
112 boost::scoped_ptr<SP> setPtsPtr;
113 };
114 boost::shared_ptr<PackData> pack_data(new PackData());
115 MoFEM::Interface &m_field = cOre;
116 pack_data->elePtr.reset(new VE(m_field));
117 pack_data->setPtsDataPtr.reset(
118 new SPD(boost::shared_ptr<VE>(pack_data, pack_data->elePtr.get()), ptr,
119 nb_eval_points, eps, verb));
120 pack_data->setPtsPtr.reset(new SP(
121 boost::shared_ptr<SPD>(pack_data, pack_data->setPtsDataPtr.get())));
122 pack_data->elePtr->setRuleHook = boost::ref(*pack_data->setPtsPtr);
123 boost::shared_ptr<SPD> data(pack_data, pack_data->setPtsDataPtr.get());
124 return data;
125 }
126
127 /**
128 * @brief Build spatial tree
129 *
130 * @param finite_element finite element name
131 * @return MoFEMErrorCode
132 */
133 MoFEMErrorCode buildTree3D(boost::shared_ptr<SetPtsData> spd_ptr,
134 const std::string finite_element);
135
136 /**
137 * @copydoc buildTree3D
138 */
139 MoFEMErrorCode buildTree2D(boost::shared_ptr<SetPtsData> spd_ptr,
140 const std::string finite_element);
141
142 /**
143 * @brief Evaluate field at artbitray position
144 *
145 * \code
146
147 std::array<double, 3> point = {0, 0, 0};
148 const double dist = 0.3;
149 std::array<double, 6> eval_points = {-1., -1., -1., 1., 1., 1. };
150
151 using VolEle = VolumeElementForcesAndSourcesCore;
152 auto data_ptr =
153 m_field.getInterface<FieldEvaluatorInterface>()->
154 getData<VolEle>(point.data(), point.size/3);
155
156 if(auto vol_ele = data_ptr->feMethod.lock()) {
157 // push operators to finite element instance, e.g.
158 vol_ele->getOpPtrVector().push_back(new MyOp());
159 // iterate over elemnts with evaluated points
160 auto cache_ptr = boost::make_shared<CacheTuple>();
161 CHKERR m_field.cache_problem_entities(prb_ptr->getName(), cache_ptr);
162 CHKERR m_field.getInterface<FieldEvaluatorInterface>()
163 ->evalFEAtThePoint3D(point.data(), dist, prb_ptr->getName(),
164 "FINITE_ELEMENT_NAME",
165 data_ptr, m_field.get_comm_rank(),
166 m_field.get_comm_rank(), cache_ptr);
167 }
168
169 * \endcode
170 *
171 * @param point point used to find tetrahedrons
172 * @param distance distance from the point where tetrahedrons are searched
173 * @param problem problem name
174 * @param finite_element finite element name
175 * @param data_ptr pointer to data abut gauss points
176 * @param lower_rank lower processor
177 * @param upper_rank upper process
178 * @param cache_ptr cache or problem entities
179 * @param bh control looping over entities, e.g. throwing error if element not
180 found
181 * @param verb verbosity level
182 * @return MoFEMErrorCode
183 */
185 evalFEAtThePoint3D(const double *const point, const double distance,
186 const std::string problem,
187 const std::string finite_element,
188 boost::shared_ptr<SetPtsData> data_ptr, int lower_rank,
189 int upper_rank, boost::shared_ptr<CacheTuple> cache_ptr,
191
192 /**
193 * @copydoc evalFEAtThePoint3D
194 */
196 evalFEAtThePoint2D(const double *const point, const double distance,
197 const std::string problem,
198 const std::string finite_element,
199 boost::shared_ptr<SetPtsData> data_ptr, int lower_rank,
200 int upper_rank, boost::shared_ptr<CacheTuple> cache_ptr,
202
203private:
204 /**
205 * @copydoc buildTree3D
206 */
207 template <int D>
208 MoFEMErrorCode buildTree(boost::shared_ptr<SetPtsData> spd_ptr,
209 const std::string finite_element);
210
211 /**
212 * @copydoc evalFEAtThePoint3D
213 */
214 template <int D>
216 evalFEAtThePoint(const double *const point, const double distance,
217 const std::string problem,
218 const std::string finite_element,
219 boost::shared_ptr<SetPtsData> data_ptr, int lower_rank,
220 int upper_rank, boost::shared_ptr<CacheTuple> cache_ptr,
222
223};
224
225} // namespace MoFEM
226
227#endif // __FIELD_EVALUATOR_HPP__
228
229/**
230 * \defgroup field_evaluator Field Evaluator
231 * \brief Evaluate field at the point
232 *
233 * \ingroup mofem
234 */
MoFEM interface.
static const double eps
VERBOSITY_LEVELS
Verbosity levels.
Definition: definitions.h:206
@ QUIET
Definition: definitions.h:208
MoFEMTypes
Those types control how functions respond on arguments, f.e. error handling.
Definition: definitions.h:97
@ MF_EXIST
Definition: definitions.h:100
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
Core (interface) class.
Definition: Core.hpp:82
Deprecated interface functions.
boost::weak_ptr< MoFEM::ForcesAndSourcesCore > feMethodPtr
void setEvalPoints(const double *ptr, const int nb_eval_points)
boost::scoped_ptr< AdaptiveKDTree > treePtr
SetPtsData(boost::shared_ptr< MoFEM::ForcesAndSourcesCore > fe_method_ptr, const double *eval_points, const int nb_eval_points, const double eps, VERBOSITY_LEVELS verb=QUIET)
Set the Gauss Pts data.
std::vector< EntityHandle > evalPointEntityHandle
Default evaluator for setting integration points.
MoFEMErrorCode operator()(ForcesAndSourcesCore *fe_raw_ptr, int order_row, int order_col, int order_data)
SetPts(boost::shared_ptr< SetPtsData > data_ptr)
boost::weak_ptr< SetPtsData > dataPtr
Field evaluator interface.
MoFEMErrorCode buildTree3D(boost::shared_ptr< SetPtsData > spd_ptr, const std::string finite_element)
Build spatial tree.
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
MoFEMErrorCode buildTree2D(boost::shared_ptr< SetPtsData > spd_ptr, const std::string finite_element)
Build spatial tree.
MoFEMErrorCode evalFEAtThePoint2D(const double *const point, const double distance, const std::string problem, const std::string finite_element, boost::shared_ptr< SetPtsData > 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 artbitray position.
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 evalFEAtThePoint3D(const double *const point, const double distance, const std::string problem, const std::string finite_element, boost::shared_ptr< SetPtsData > 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 artbitray position.
MoFEMErrorCode buildTree(boost::shared_ptr< SetPtsData > spd_ptr, const std::string finite_element)
Build spatial tree.
MoFEMErrorCode evalFEAtThePoint(const double *const point, const double distance, const std::string problem, const std::string finite_element, boost::shared_ptr< SetPtsData > 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 artbitray position.
structure to get information form mofem into EntitiesFieldData
base class for all interface classes