12 auto core_log = logging::core::get();
15 "FieldEvaluatorWorld"));
17 "FieldEvaluatorSync"));
19 "FieldEvaluatorSelf"));
30 MOFEM_LOG(
"FieldEvaluatorWorld", Sev::noisy) <<
"Field evaluator intreface";
43 const std::string finite_element) {
49 CHKERR m_field.
get_moab().get_entities_by_dimension(fe_meshset,
D, entities,
51 spd_ptr->treePtr.reset(
new AdaptiveKDTree(&m_field.
get_moab()));
52 CHKERR spd_ptr->treePtr->build_tree(entities, &spd_ptr->rooTreeSet);
58 FieldEvaluatorInterface::buildTree<2>(boost::shared_ptr<SetPtsData> spd_ptr,
59 const std::string finite_element) {
60 return buildTreeImpl<2>(spd_ptr, finite_element);
65 FieldEvaluatorInterface::buildTree<3>(boost::shared_ptr<SetPtsData> spd_ptr,
66 const std::string finite_element) {
67 return buildTreeImpl<3>(spd_ptr, finite_element);
72 const std::string finite_element) {
73 return buildTree<3>(spd_ptr, finite_element);
78 const std::string finite_element) {
79 return buildTree<2>(spd_ptr, finite_element);
84 int order_row,
int order_col,
88 if (
auto data_ptr =
dataPtr.lock()) {
90 const auto nb_eval_points = data_ptr->nbEvalPoints;
91 const auto &shape_functions = data_ptr->shapeFunctions;
92 const auto &eval_pointentity_handle = data_ptr->evalPointEntityHandle;
94 if (
auto fe_ptr = data_ptr->feMethodPtr.lock()) {
99 if (fe_ptr.get() != fe_raw_ptr)
103 const auto fe_ent = fe.numeredEntFiniteElementPtr->getEnt();
105 const auto fe_dim = moab::CN::Dimension(fe_type);
107 auto &gauss_pts = fe.gaussPts;
111 gauss_pts.resize(4, nb_eval_points,
false);
113 &shape_functions(0, 0), &shape_functions(0, 1),
114 &shape_functions(0, 2), &shape_functions(0, 3)};
116 &gauss_pts(0, 0), &gauss_pts(1, 0), &gauss_pts(2, 0)};
119 for (
int nn = 0; nn != nb_eval_points; ++nn) {
120 if (eval_pointentity_handle[nn] == fe_ent) {
121 for (
const int i : {0, 1, 2}) {
122 t_gauss_pts(
i) = t_shape(
i + 1);
124 gauss_pts(3, nb_gauss_pts) = nn;
130 gauss_pts.resize(4, nb_gauss_pts,
true);
131 }
else if (fe_dim == 2) {
132 gauss_pts.resize(3, nb_eval_points,
false);
134 &shape_functions(0, 0), &shape_functions(0, 1),
135 &shape_functions(0, 2)};
137 &gauss_pts(0, 0), &gauss_pts(1, 0)};
139 for (
int nn = 0; nn != nb_eval_points; ++nn) {
140 if (eval_pointentity_handle[nn] == fe_ent) {
141 for (
const int i : {0, 1}) {
142 t_gauss_pts(
i) = t_shape(
i + 1);
144 gauss_pts(2, nb_gauss_pts) = nn;
150 gauss_pts.resize(3, nb_gauss_pts,
true);
153 "Dimension not implemented");
158 <<
"nbEvalOPoints / nbGau_sspt_s: " << nb_eval_points <<
" / "
160 MOFEM_LOG(
"SELF", Sev::noisy) <<
"gauss pts: " << gauss_pts;
165 "Pointer to element does not exists");
169 "Pointer to data does not exists");
176 const double *
const point,
const double distance,
const std::string problem,
177 const std::string finite_element, boost::shared_ptr<SetPtsData> data_ptr,
178 int lower_rank,
int upper_rank, boost::shared_ptr<CacheTuple> cache_ptr,
183 std::vector<EntityHandle> leafs_out;
184 CHKERR data_ptr->treePtr->distance_search(point, distance, leafs_out);
186 for (
auto lit : leafs_out)
191 MOFEM_LOG(
"SELF", Sev::noisy) <<
"tree entities: " << tree_ents;
193 data_ptr->evalPointEntityHandle.resize(data_ptr->nbEvalPoints);
194 std::fill(data_ptr->evalPointEntityHandle.begin(),
195 data_ptr->evalPointEntityHandle.end(), 0);
197 std::vector<double> local_coords;
198 std::vector<double> shape;
200 auto nb_eval_points = data_ptr->nbEvalPoints;
202 for (
auto tet : tree_ents) {
205 CHKERR m_field.
get_moab().get_connectivity(tet, conn, num_nodes,
true);
207 if constexpr (
D == 3) {
209 local_coords.resize(3 * nb_eval_points);
210 shape.resize(4 * nb_eval_points);
212 std::array<double, 12> coords;
213 CHKERR m_field.
get_moab().get_coords(conn, num_nodes, coords.data());
216 coords.data(), &data_ptr->evalPoints[0], nb_eval_points,
218 CHKERR Tools::shapeFunMBTET<3>(&shape[0], &local_coords[0],
219 &local_coords[1], &local_coords[2],
224 &shape[0], &shape[1], &shape[2], &shape[3]};
226 &data_ptr->shapeFunctions(0, 0), &data_ptr->shapeFunctions(0, 1),
227 &data_ptr->shapeFunctions(0, 2), &data_ptr->shapeFunctions(0, 3)};
231 &local_coords[0], &local_coords[1], &local_coords[2]};
233 &(data_ptr->localCoords(0, 0)), &(data_ptr->localCoords(0, 1)),
234 &(data_ptr->localCoords(0, 2))};
236 for (
int n = 0;
n != nb_eval_points; ++
n) {
238 const double eps = data_ptr->eps;
239 if (t_shape(0) >= 0 -
eps && t_shape(0) <= 1 +
eps &&
241 t_shape(1) >= 0 -
eps && t_shape(1) <= 1 +
eps &&
243 t_shape(2) >= 0 -
eps && t_shape(2) <= 1 +
eps &&
245 t_shape(3) >= 0 -
eps && t_shape(3) <= 1 +
eps) {
247 data_ptr->evalPointEntityHandle[
n] = tet;
248 t_shape_data(i4) = t_shape(i4);
249 t_local_data(j3) = t_local(j3);
259 if constexpr (
D == 2) {
261 local_coords.resize(2 * nb_eval_points);
262 shape.resize(3 * nb_eval_points);
264 std::array<double, 9> coords;
265 CHKERR m_field.
get_moab().get_coords(conn, num_nodes, coords.data());
268 coords.data(), &data_ptr->evalPoints[0], nb_eval_points,
270 CHKERR Tools::shapeFunMBTRI<2>(&shape[0], &local_coords[0],
271 &local_coords[1], nb_eval_points);
275 &shape[0], &shape[1], &shape[2]};
277 &data_ptr->shapeFunctions(0, 0), &data_ptr->shapeFunctions(0, 1),
278 &data_ptr->shapeFunctions(0, 2)};
282 &local_coords[0], &local_coords[1]};
283 data_ptr->localCoords.resize(nb_eval_points, 2);
285 &(data_ptr->localCoords(0, 0)), &(data_ptr->localCoords(0, 1))};
287 for (
int n = 0;
n != nb_eval_points; ++
n) {
289 const double eps = data_ptr->eps;
290 if (t_shape(0) >= 0 -
eps && t_shape(0) <= 1 +
eps &&
292 t_shape(1) >= 0 -
eps && t_shape(1) <= 1 +
eps &&
294 t_shape(2) >= 0 -
eps && t_shape(2) <= 1 +
eps) {
296 data_ptr->evalPointEntityHandle[
n] = tet;
297 t_shape_data(i3) = t_shape(i3);
298 t_local_data(j2) = t_local(j2);
311 boost::shared_ptr<NumeredEntFiniteElement_multiIndex> numered_fes(
315 in_tets.insert_list(data_ptr->evalPointEntityHandle.begin(),
316 data_ptr->evalPointEntityHandle.end());
317 in_tets = in_tets.subset_by_dimension(
D);
320 MOFEM_LOG(
"SELF", Sev::noisy) <<
"in tets: " << in_tets << endl;
328 for (
auto peit = in_tets.pair_begin(); peit != in_tets.pair_end(); ++peit) {
333 peit->first, (*fe_miit)->getFEUId()));
337 peit->second, (*fe_miit)->getFEUId()));
338 numered_fes->insert(lo, hi);
341 std::cerr <<
"numered elements:" << std::endl;
342 for (; lo != hi; ++lo)
344 std::cerr << **lo << endl;
347 std::cerr << std::endl;
349 if (
auto fe_ptr = data_ptr->feMethodPtr.lock()) {
352 "Number elements %d to evaluate at proc %d",
357 cache_ptr = boost::make_shared<CacheTuple>();
360 MOFEM_LOG(
"FieldEvaluatorSync", Sev::noisy)
361 <<
"If you call that function many times in the loop consider to "
363 "cache_ptr outside of the loop. Otherwise code can be slow.";
367 lower_rank, upper_rank, numered_fes,
368 bh, cache_ptr, verb);
372 "Pointer to element does not exists");
380 const double *
const point,
const double distance,
const std::string problem,
381 const std::string finite_element, boost::shared_ptr<SetPtsData> data_ptr,
382 int lower_rank,
int upper_rank, boost::shared_ptr<CacheTuple> cache_ptr,
384 return evalFEAtThePointImpl<2>(point, distance, problem, finite_element,
385 data_ptr, lower_rank, upper_rank, cache_ptr,
391 const double *
const point,
const double distance,
const std::string problem,
392 const std::string finite_element, boost::shared_ptr<SetPtsData> data_ptr,
393 int lower_rank,
int upper_rank, boost::shared_ptr<CacheTuple> cache_ptr,
395 return evalFEAtThePointImpl<3>(point, distance, problem, finite_element,
396 data_ptr, lower_rank, upper_rank, cache_ptr,
401 const double *
const point,
const double distance,
const std::string problem,
402 const std::string finite_element, boost::shared_ptr<SetPtsData> data_ptr,
403 int lower_rank,
int upper_rank, boost::shared_ptr<CacheTuple> cache_ptr,
405 return evalFEAtThePoint<3>(point, distance, problem, finite_element, data_ptr,
406 lower_rank, upper_rank, cache_ptr, bh, verb);
410 const double *
const point,
const double distance,
const std::string problem,
411 const std::string finite_element, boost::shared_ptr<SetPtsData> data_ptr,
412 int lower_rank,
int upper_rank, boost::shared_ptr<CacheTuple> cache_ptr,
414 return evalFEAtThePoint<2>(point, distance, problem, finite_element, data_ptr,
415 lower_rank, upper_rank, cache_ptr, bh, verb);