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 const std::string finite_element) {
59 return buildTree<3>(spd_ptr, finite_element);
64 const std::string finite_element) {
65 return buildTree<2>(spd_ptr, finite_element);
70 int order_row,
int order_col,
74 if (
auto data_ptr =
dataPtr.lock()) {
76 const auto nb_eval_points = data_ptr->nbEvalPoints;
77 const auto &shape_functions = data_ptr->shapeFunctions;
78 const auto &eval_pointentity_handle = data_ptr->evalPointEntityHandle;
80 if (
auto fe_ptr = data_ptr->feMethodPtr.lock()) {
85 if (fe_ptr.get() != fe_raw_ptr)
89 const auto fe_ent = fe.numeredEntFiniteElementPtr->getEnt();
91 const auto fe_dim = moab::CN::Dimension(fe_type);
93 auto &gauss_pts = fe.gaussPts;
97 gauss_pts.resize(4, nb_eval_points,
false);
99 &shape_functions(0, 0), &shape_functions(0, 1),
100 &shape_functions(0, 2), &shape_functions(0, 3)};
102 &gauss_pts(0, 0), &gauss_pts(1, 0), &gauss_pts(2, 0)};
105 for (
int nn = 0; nn != nb_eval_points; ++nn) {
106 if (eval_pointentity_handle[nn] == fe_ent) {
107 for (
const int i : {0, 1, 2}) {
108 t_gauss_pts(
i) = t_shape(
i + 1);
110 gauss_pts(3, nb_gauss_pts) = nn;
116 gauss_pts.resize(4, nb_gauss_pts,
true);
117 }
else if (fe_dim == 2) {
118 gauss_pts.resize(3, nb_eval_points,
false);
120 &shape_functions(0, 0), &shape_functions(0, 1),
121 &shape_functions(0, 2)};
123 &gauss_pts(0, 0), &gauss_pts(1, 0)};
125 for (
int nn = 0; nn != nb_eval_points; ++nn) {
126 if (eval_pointentity_handle[nn] == fe_ent) {
127 for (
const int i : {0, 1}) {
128 t_gauss_pts(
i) = t_shape(
i + 1);
130 gauss_pts(2, nb_gauss_pts) = nn;
136 gauss_pts.resize(3, nb_gauss_pts,
true);
139 "Dimension not implemented");
144 <<
"nbEvalOPoints / nbGau_sspt_s: " << nb_eval_points <<
" / "
146 MOFEM_LOG(
"SELF", Sev::noisy) <<
"gauss pts: " << gauss_pts;
151 "Pointer to element does not exists");
155 "Pointer to data does not exists");
162 const double *
const point,
const double distance,
const std::string problem,
163 const std::string finite_element, boost::shared_ptr<SetPtsData> data_ptr,
164 int lower_rank,
int upper_rank, boost::shared_ptr<CacheTuple> cache_ptr,
169 std::vector<EntityHandle> leafs_out;
170 CHKERR data_ptr->treePtr->distance_search(point, distance, leafs_out);
172 for (
auto lit : leafs_out)
177 MOFEM_LOG(
"SELF", Sev::noisy) <<
"tree entities: " << tree_ents;
179 data_ptr->evalPointEntityHandle.resize(data_ptr->nbEvalPoints);
180 std::fill(data_ptr->evalPointEntityHandle.begin(),
181 data_ptr->evalPointEntityHandle.end(), 0);
183 std::vector<double> local_coords;
184 std::vector<double> shape;
186 auto nb_eval_points = data_ptr->nbEvalPoints;
188 for (
auto tet : tree_ents) {
191 CHKERR m_field.
get_moab().get_connectivity(tet, conn, num_nodes,
true);
193 if constexpr (
D == 3) {
195 local_coords.resize(3 * nb_eval_points);
196 shape.resize(4 * nb_eval_points);
198 std::array<double, 12> coords;
199 CHKERR m_field.
get_moab().get_coords(conn, num_nodes, coords.data());
202 coords.data(), &data_ptr->evalPoints[0], nb_eval_points,
204 CHKERR Tools::shapeFunMBTET<3>(&shape[0], &local_coords[0],
205 &local_coords[1], &local_coords[2],
210 &shape[0], &shape[1], &shape[2], &shape[3]};
212 &data_ptr->shapeFunctions(0, 0), &data_ptr->shapeFunctions(0, 1),
213 &data_ptr->shapeFunctions(0, 2), &data_ptr->shapeFunctions(0, 3)};
217 &local_coords[0], &local_coords[1], &local_coords[2]};
219 &(data_ptr->localCoords(0, 0)), &(data_ptr->localCoords(0, 1)),
220 &(data_ptr->localCoords(0, 2))};
222 for (
int n = 0;
n != nb_eval_points; ++
n) {
224 const double eps = data_ptr->eps;
225 if (t_shape(0) >= 0 -
eps && t_shape(0) <= 1 +
eps &&
227 t_shape(1) >= 0 -
eps && t_shape(1) <= 1 +
eps &&
229 t_shape(2) >= 0 -
eps && t_shape(2) <= 1 +
eps &&
231 t_shape(3) >= 0 -
eps && t_shape(3) <= 1 +
eps) {
233 data_ptr->evalPointEntityHandle[
n] = tet;
234 t_shape_data(i4) = t_shape(i4);
235 t_local_data(j3) = t_local(j3);
245 if constexpr (
D == 2) {
247 local_coords.resize(2 * nb_eval_points);
248 shape.resize(3 * nb_eval_points);
250 std::array<double, 9> coords;
251 CHKERR m_field.
get_moab().get_coords(conn, num_nodes, coords.data());
254 coords.data(), &data_ptr->evalPoints[0], nb_eval_points,
256 CHKERR Tools::shapeFunMBTRI<2>(&shape[0], &local_coords[0],
257 &local_coords[1], nb_eval_points);
261 &shape[0], &shape[1], &shape[2]};
263 &data_ptr->shapeFunctions(0, 0), &data_ptr->shapeFunctions(0, 1),
264 &data_ptr->shapeFunctions(0, 2)};
268 &local_coords[0], &local_coords[1]};
269 data_ptr->localCoords.resize(nb_eval_points, 2);
271 &(data_ptr->localCoords(0, 0)), &(data_ptr->localCoords(0, 1))};
273 for (
int n = 0;
n != nb_eval_points; ++
n) {
275 const double eps = data_ptr->eps;
276 if (t_shape(0) >= 0 -
eps && t_shape(0) <= 1 +
eps &&
278 t_shape(1) >= 0 -
eps && t_shape(1) <= 1 +
eps &&
280 t_shape(2) >= 0 -
eps && t_shape(2) <= 1 +
eps) {
282 data_ptr->evalPointEntityHandle[
n] = tet;
283 t_shape_data(i3) = t_shape(i3);
284 t_local_data(j2) = t_local(j2);
297 boost::shared_ptr<NumeredEntFiniteElement_multiIndex> numered_fes(
301 in_tets.insert_list(data_ptr->evalPointEntityHandle.begin(),
302 data_ptr->evalPointEntityHandle.end());
303 in_tets = in_tets.subset_by_dimension(
D);
306 MOFEM_LOG(
"SELF", Sev::noisy) <<
"in tets: " << in_tets << endl;
314 for (
auto peit = in_tets.pair_begin(); peit != in_tets.pair_end(); ++peit) {
319 peit->first, (*fe_miit)->getFEUId()));
323 peit->second, (*fe_miit)->getFEUId()));
324 numered_fes->insert(lo, hi);
327 std::cerr <<
"numered elements:" << std::endl;
328 for (; lo != hi; ++lo)
330 std::cerr << **lo << endl;
333 std::cerr << std::endl;
335 if (
auto fe_ptr = data_ptr->feMethodPtr.lock()) {
338 "Number elements %d to evaluate at proc %d",
343 cache_ptr = boost::make_shared<CacheTuple>();
346 MOFEM_LOG(
"FieldEvaluatorSync", Sev::noisy)
347 <<
"If you call that function many times in the loop consider to "
349 "cache_ptr outside of the loop. Otherwise code can be slow.";
353 lower_rank, upper_rank, numered_fes,
354 bh, cache_ptr, verb);
358 "Pointer to element does not exists");
365 const double *
const point,
const double distance,
const std::string problem,
366 const std::string finite_element, boost::shared_ptr<SetPtsData> data_ptr,
367 int lower_rank,
int upper_rank, boost::shared_ptr<CacheTuple> cache_ptr,
369 return evalFEAtThePoint<3>(point, distance, problem, finite_element, data_ptr,
370 lower_rank, upper_rank, cache_ptr, bh, verb);
374 const double *
const point,
const double distance,
const std::string problem,
375 const std::string finite_element, boost::shared_ptr<SetPtsData> data_ptr,
376 int lower_rank,
int upper_rank, boost::shared_ptr<CacheTuple> cache_ptr,
378 return evalFEAtThePoint<2>(point, distance, problem, finite_element, data_ptr,
379 lower_rank, upper_rank, cache_ptr, bh, verb);