v0.14.0
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 
15 namespace 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);
48  shapeFunctions.resize(nbEvalPoints, 4);
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 
118  pack_data->setPtsDataPtr.reset(
119  new SPD(boost::shared_ptr<VE>(pack_data, pack_data->elePtr.get()), ptr,
120  nb_eval_points, eps, verb));
121  pack_data->setPtsPtr.reset(new SP(
122  boost::shared_ptr<SPD>(pack_data, pack_data->setPtsDataPtr.get())));
123  pack_data->elePtr->setRuleHook = boost::ref(*pack_data->setPtsPtr);
124  boost::shared_ptr<SPD> data(pack_data, pack_data->setPtsDataPtr.get());
125  return data;
126  }
127 
128  /**
129  * @brief Build spatial tree
130  *
131  * @param finite_element finite element name
132  * @return MoFEMErrorCode
133  */
134  MoFEMErrorCode buildTree3D(boost::shared_ptr<SetPtsData> spd_ptr,
135  const std::string finite_element);
136 
137  /**
138  * @copydoc buildTree3D
139  */
140  MoFEMErrorCode buildTree2D(boost::shared_ptr<SetPtsData> spd_ptr,
141  const std::string finite_element);
142 
143  /**
144  * @brief Evaluate field at artbitray position
145  *
146  * \code
147 
148  std::array<double, 3> point = {0, 0, 0};
149  const double dist = 0.3;
150  std::array<double, 6> eval_points = {-1., -1., -1., 1., 1., 1. };
151 
152  using VolEle = VolumeElementForcesAndSourcesCore;
153  auto data_ptr =
154  m_field.getInterface<FieldEvaluatorInterface>()->
155  getData<VolEle>(point.data(), point.size/3);
156 
157  if(auto vol_ele = data_ptr->feMethod.lock()) {
158  // push operators to finite element instance, e.g.
159  vol_ele->getOpPtrVector().push_back(new MyOp());
160  // iterate over elemnts with evaluated points
161  auto cache_ptr = boost::make_shared<CacheTuple>();
162  CHKERR m_field.cache_problem_entities(prb_ptr->getName(), cache_ptr);
163  CHKERR m_field.getInterface<FieldEvaluatorInterface>()
164  ->evalFEAtThePoint3D(point.data(), dist, prb_ptr->getName(),
165  "FINITE_ELEMENT_NAME",
166  data_ptr, m_field.get_comm_rank(),
167  m_field.get_comm_rank(), cache_ptr);
168  }
169 
170  * \endcode
171  *
172  * @param point point used to find tetrahedrons
173  * @param distance distance from the point where tetrahedrons are searched
174  * @param problem problem name
175  * @param finite_element finite element name
176  * @param data_ptr pointer to data abut gauss points
177  * @param lower_rank lower processor
178  * @param upper_rank upper process
179  * @param cache_ptr cache or problem entities
180  * @param bh control looping over entities, e.g. throwing error if element not
181  found
182  * @param verb verbosity level
183  * @return MoFEMErrorCode
184  */
186  evalFEAtThePoint3D(const double *const point, const double distance,
187  const std::string problem,
188  const std::string finite_element,
189  boost::shared_ptr<SetPtsData> data_ptr, int lower_rank,
190  int upper_rank, boost::shared_ptr<CacheTuple> cache_ptr,
192 
193  /**
194  * @copydoc evalFEAtThePoint3D
195  */
197  evalFEAtThePoint2D(const double *const point, const double distance,
198  const std::string problem,
199  const std::string finite_element,
200  boost::shared_ptr<SetPtsData> data_ptr, int lower_rank,
201  int upper_rank, boost::shared_ptr<CacheTuple> cache_ptr,
203 
204 private:
205  /**
206  * @copydoc buildTree3D
207  */
208  template <int D>
209  MoFEMErrorCode buildTree(boost::shared_ptr<SetPtsData> spd_ptr,
210  const std::string finite_element);
211 
212  /**
213  * @copydoc evalFEAtThePoint3D
214  */
215  template <int D>
217  evalFEAtThePoint(const double *const point, const double distance,
218  const std::string problem,
219  const std::string finite_element,
220  boost::shared_ptr<SetPtsData> data_ptr, int lower_rank,
221  int upper_rank, boost::shared_ptr<CacheTuple> cache_ptr,
223 
224 };
225 
226 } // namespace MoFEM
227 
228 #endif // __FIELD_EVALUATOR_HPP__
229 
230 /**
231  * \defgroup field_evaluator Field Evaluator
232  * \brief Evaluate field at the point
233  *
234  * \ingroup mofem
235  */
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
MoFEM::FieldEvaluatorInterface::SetPtsData::verb
VERBOSITY_LEVELS verb
Definition: FieldEvaluator.hpp:62
MoFEM::FieldEvaluatorInterface::query_interface
MoFEMErrorCode query_interface(boost::typeindex::type_index type_index, UnknownInterface **iface) const
Definition: FieldEvaluator.cpp:33
EntityHandle
MoFEM::FieldEvaluatorInterface::SetPtsData::localCoords
MatrixDouble localCoords
Definition: FieldEvaluator.hpp:64
MoFEM::FieldEvaluatorInterface::SetPtsData::SetPtsData
SetPtsData()=delete
MoFEM::FieldEvaluatorInterface::buildTree
MoFEMErrorCode buildTree(boost::shared_ptr< SetPtsData > spd_ptr, const std::string finite_element)
Build spatial tree.
Definition: FieldEvaluator.cpp:42
MoFEM::FieldEvaluatorInterface::SetPts::operator()
MoFEMErrorCode operator()(ForcesAndSourcesCore *fe_raw_ptr, int order_row, int order_col, int order_data)
Definition: FieldEvaluator.cpp:69
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
MoFEM::Types::MatrixDouble
UBlasMatrix< double > MatrixDouble
Definition: Types.hpp:77
MoFEM::FieldEvaluatorInterface::FieldEvaluatorInterface
FieldEvaluatorInterface(const MoFEM::Core &core)
Definition: FieldEvaluator.cpp:8
MoFEM::FieldEvaluatorInterface::SetPtsData::rooTreeSet
EntityHandle rooTreeSet
Definition: FieldEvaluator.hpp:68
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
MoFEM::FieldEvaluatorInterface::SetPtsData::shapeFunctions
MatrixDouble shapeFunctions
Definition: FieldEvaluator.hpp:65
MoFEM::FieldEvaluatorInterface::SetPts::dataPtr
boost::weak_ptr< SetPtsData > dataPtr
Definition: FieldEvaluator.hpp:83
MoFEM::FieldEvaluatorInterface::SetPtsData::SetPtsData
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.
Definition: FieldEvaluator.hpp:42
MoFEM::FieldEvaluatorInterface::buildTree3D
MoFEMErrorCode buildTree3D(boost::shared_ptr< SetPtsData > spd_ptr, const std::string finite_element)
Build spatial tree.
Definition: FieldEvaluator.cpp:57
MoFEM::FieldEvaluatorInterface::SetPts
Default evaluator for setting integration points.
Definition: FieldEvaluator.hpp:76
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
VERBOSITY_LEVELS
VERBOSITY_LEVELS
Verbosity levels.
Definition: definitions.h:206
MoFEM::FieldEvaluatorInterface::buildTree2D
MoFEMErrorCode buildTree2D(boost::shared_ptr< SetPtsData > spd_ptr, const std::string finite_element)
Build spatial tree.
Definition: FieldEvaluator.cpp:63
MoFEM::FieldEvaluatorInterface::SetPtsData
Definition: FieldEvaluator.hpp:29
MoFEM::FieldEvaluatorInterface
Field evaluator interface.
Definition: FieldEvaluator.hpp:21
MoFEM::FieldEvaluatorInterface::cOre
MoFEM::Core & cOre
Definition: FieldEvaluator.hpp:26
MoFEM::FieldEvaluatorInterface::evalFEAtThePoint3D
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.
Definition: FieldEvaluator.cpp:364
MoFEM::FieldEvaluatorInterface::SetPts::SetPts
SetPts(boost::shared_ptr< SetPtsData > data_ptr)
Definition: FieldEvaluator.hpp:78
UnknownInterface.hpp
MoFEM interface.
MoFEM::FieldEvaluatorInterface::SetPtsData::evalPointEntityHandle
std::vector< EntityHandle > evalPointEntityHandle
Definition: FieldEvaluator.hpp:66
MoFEM::FieldEvaluatorInterface::getData
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.
Definition: FieldEvaluator.hpp:107
MoFEM::UnknownInterface
base class for all interface classes
Definition: UnknownInterface.hpp:34
MoFEM::ForcesAndSourcesCore
structure to get information form mofem into EntitiesFieldData
Definition: ForcesAndSourcesCore.hpp:22
MoFEM::FieldEvaluatorInterface::SetPtsData::evalPoints
const double * evalPoints
Definition: FieldEvaluator.hpp:59
eps
static const double eps
Definition: check_base_functions_derivatives_on_tet.cpp:11
MoFEM::FieldEvaluatorInterface::evalFEAtThePoint
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.
Definition: FieldEvaluator.cpp:161
MoFEM::FieldEvaluatorInterface::SetPts::SetPts
SetPts()=delete
MoFEMTypes
MoFEMTypes
Those types control how functions respond on arguments, f.e. error handling.
Definition: definitions.h:97
MoFEM::FieldEvaluatorInterface::SetPtsData::setEvalPoints
void setEvalPoints(const double *ptr, const int nb_eval_points)
Definition: FieldEvaluator.hpp:51
MoFEM::FieldEvaluatorInterface::SetPtsData::feMethodPtr
boost::weak_ptr< MoFEM::ForcesAndSourcesCore > feMethodPtr
Definition: FieldEvaluator.hpp:58
QUIET
@ QUIET
Definition: definitions.h:208
MoFEM::FieldEvaluatorInterface::evalFEAtThePoint2D
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.
Definition: FieldEvaluator.cpp:373
MoFEM::FieldEvaluatorInterface::SetPtsData::nbEvalPoints
int nbEvalPoints
Definition: FieldEvaluator.hpp:60
MF_EXIST
@ MF_EXIST
Definition: definitions.h:100
MoFEM::FieldEvaluatorInterface::SetPtsData::treePtr
boost::scoped_ptr< AdaptiveKDTree > treePtr
Definition: FieldEvaluator.hpp:69
MoFEM::FieldEvaluatorInterface::SetPtsData::eps
double eps
Definition: FieldEvaluator.hpp:61