8#include <kernel/assembly/discrete_evaluator.hpp>
10#include <kernel/global/remote_lambda.hpp>
11#include <kernel/lafem/dense_vector.hpp>
12#include <kernel/trafo/inverse_mapping.hpp>
13#include <kernel/util/dist.hpp>
14#include <kernel/util/math.hpp>
15#include <kernel/util/tiny_algebra.hpp>
24 template<
typename Po
intRange_>
25 static constexpr int dim_from_point_range =
26 std::remove_const_t<std::remove_reference_t<decltype(*std::declval<PointRange_>().begin())>>::n;
39 template<
typename Po
intRange_,
typename VectorType_,
typename Space_,
bool gradient_>
43 template<
typename Po
intRange_,
typename DataType_,
typename IndexType_,
typename Space_>
46 using DataType = DataType_;
47 using IndexType = IndexType_;
48 using PointType = std::remove_const_t<std::remove_reference_t<decltype(*std::declval<PointRange_>().begin())>>;
49 static constexpr int point_dim = PointType::n;
50 using SpaceType = Space_;
51 using MeshType =
typename SpaceType::MeshType;
59 template<
typename Po
intRange_,
typename DataType_,
typename IndexType_,
int dim_,
typename Space_>
62 LAFEM::DenseVectorBlocked<DataType_, IndexType_, dim_>,
66 using DataType = DataType_;
67 using IndexType = IndexType_;
68 using PointType = std::remove_const_t<std::remove_reference_t<decltype(*std::declval<PointRange_>().begin())>>;
69 static constexpr int point_dim = PointType::n;
70 using SpaceType = Space_;
71 using MeshType =
typename SpaceType::MeshType;
76 static_assert(point_dim == dim_);
80 template<
typename Po
intRange_,
typename DataType_,
typename IndexType_,
typename Space_>
83 using DataType = DataType_;
84 using IndexType = IndexType_;
85 using PointType = std::remove_const_t<std::remove_reference_t<decltype(*std::declval<PointRange_>().begin())>>;
86 static constexpr int point_dim = PointType::n;
87 using SpaceType = Space_;
88 using MeshType =
typename SpaceType::MeshType;
95 template<
typename Po
intRange_,
typename DataType_,
typename IndexType_,
int dim_,
typename Space_>
98 LAFEM::DenseVectorBlocked<DataType_, IndexType_, dim_>,
102 using DataType = DataType_;
103 using IndexType = IndexType_;
104 using PointType = std::remove_const_t<std::remove_reference_t<decltype(*std::declval<PointRange_>().begin())>>;
105 static constexpr int point_dim = PointType::n;
106 using SpaceType = Space_;
107 using MeshType =
typename SpaceType::MeshType;
112 static_assert(point_dim == dim_);
154 template<
typename Po
intRange_,
typename DT_,
typename IT_,
typename Space_>
155 static std::vector<Assembly::ScalarDiscreteEvalData<DT_, Intern::dim_from_point_range<PointRange_>>>
158 return _remote_eval<false>(comm, points, vector, space);
187 template<
typename Po
intRange_,
typename DT_,
typename IT_,
typename Space_>
188 static std::vector<Assembly::VectorDiscreteEvalData<DT_, Intern::dim_from_point_range<PointRange_>>>
eval_fe_function(
190 const PointRange_& points,
194 return _remote_eval<false>(comm, points, vector, space);
223 template<
typename Po
intRange_,
typename DT_,
typename IT_,
typename Space_>
224 static std::vector<Assembly::VectorDiscreteEvalData<DT_, Intern::dim_from_point_range<PointRange_>>>
227 return _remote_eval<true>(comm, points, vector, space);
256 template<
typename Po
intRange_,
typename DT_,
typename IT_,
typename Space_>
259 Intern::dim_from_point_range<PointRange_>,
260 Intern::dim_from_point_range<PointRange_>>>
263 const PointRange_& points,
267 return _remote_eval<true>(comm, points, vector, space);
297 template<
bool gradient_,
typename Po
intRange_,
typename VectorType_,
typename Space_>
298 static std::vector<typename Intern::DiscreteEvaluatorTypeHelper<PointRange_, VectorType_, Space_, gradient_>::EvalType>
306 using DataType =
typename Helper::DataType;
307 using BoundingBoxType =
typename Helper::BoundingBoxType;
308 using PointType =
typename Helper::PointType;
309 using EvalType =
typename Helper::EvalType;
310 using EvalValueType =
typename Helper::EvalValueType;
312 const auto total_ranks = std::size_t(comm.
size());
313 const auto rank = std::size_t(comm.
rank());
314 const auto num_points = std::size_t(std::distance(points.begin(), points.end()));
317 std::vector<BoundingBoxType> bbs(
static_cast<std::size_t
>(total_ranks));
318 bbs.at(rank) = get_local_bb<BoundingBoxType>(space.get_mesh());
319 comm.
allgather(bbs.data(), 1, bbs.data(), 1);
322 std::vector<int> ranks;
323 ranks.reserve(num_points);
324 std::vector<Index> indices;
325 ranks.reserve(num_points);
328 for(
auto it = points.begin(); it != points.end(); ++it)
330 const PointType& p = *it;
331 for(std::size_t i(0); i < total_ranks; i++)
333 const BoundingBoxType& bb = bbs[i];
337 ranks.push_back(
int(i));
338 indices.push_back(point_idx);
351 std::vector<EvalValueType> evals = rl.call(
355 [&vector, &space, &inv_mapping](
const PointType& p)
358 if constexpr(gradient_)
369 std::vector<EvalType> result(std::size_t(std::distance(points.begin(), points.end())));
371 for(std::size_t i(0); i < evals.size(); i++)
374 const Index idx = indices[i];
377 result[idx].values.push_back(evals[i]);
384 template<
typename BoundingBoxType_,
typename Po
intType_>
385 static bool is_in_bb(
const BoundingBoxType_& bb,
const PointType_& p)
387 using DataType =
typename BoundingBoxType_::ValueType;
388 constexpr int dim = BoundingBoxType_::m;
390 constexpr DataType bb_eps(1E-2);
391 for(
int i(0); i < dim; i++)
393 if(p[i] > (bb[1][i] + bb_eps) || p[i] < (bb[0][i] - bb_eps))
402 template<
typename BoundingBoxType_,
typename MeshType_>
405 const auto& vertex_set = mesh.get_vertex_set();
407 if(vertex_set.get_num_vertices() == 0)
409 return BoundingBoxType_{0};
413 BoundingBoxType_ local_bb;
415 local_bb[0] = vertex_set[0];
416 local_bb[1] = vertex_set[0];
417 for(
Index vtx_idx(0); vtx_idx < vertex_set.get_num_vertices(); vtx_idx++)
419 const auto& v = vertex_set[vtx_idx];
421 for(
int i(0); i < MeshType_::world_dim; i++)
static VectorDiscreteEvalData< DT_, dim_ > eval_fe_gradient(const Tiny::Vector< DTP_, dim_, s_ > &point, const LAFEM::DenseVector< DT_, IT_ > &vector, const Space_ &space)
Evaluates the gradient of a scalar finite-element function in a given point.
static ScalarDiscreteEvalData< DT_, dim_ > eval_fe_function(const Tiny::Vector< DTP_, dim_, s_ > &point, const LAFEM::DenseVector< DT_, IT_ > &vector, const Space_ &space)
Evaluates a scalar finite-element function in a given point.
Discrete evaluation data for matrix-valued functions.
Discrete evaluation data for scalar functions.
DataType ValueType
the value type
Discrete evaluation data for vector-valued functions.
int size() const
Returns the size of this communicator.
int rank() const
Returns the rank of this process in this communicator.
void allgather(const void *sendbuf, std::size_t sendcount, const Datatype &sendtype, void *recvbuf, std::size_t recvcount, const Datatype &recvtype) const
Blocking gather-to-all.
Global discrete evaluator.
static std::vector< Assembly::ScalarDiscreteEvalData< DT_, Intern::dim_from_point_range< PointRange_ > > > eval_fe_function(const Dist::Comm &comm, const PointRange_ &points, const LAFEM::DenseVector< DT_, IT_ > &vector, const Space_ &space)
Evaluates a scalar finite-element function in all given points.
static std::vector< typename Intern::DiscreteEvaluatorTypeHelper< PointRange_, VectorType_, Space_, gradient_ >::EvalType > _remote_eval(const Dist::Comm &comm, const PointRange_ &points, const VectorType_ &vector, const Space_ &space)
Common function for evaluating a scalar or vector-valued finite-element function on a distributed dom...
static BoundingBoxType_ get_local_bb(const MeshType_ &mesh)
Get bounding box of local part of domain.
static std::vector< Assembly::VectorDiscreteEvalData< DT_, Intern::dim_from_point_range< PointRange_ > > > eval_fe_function(const Dist::Comm &comm, const PointRange_ &points, const LAFEM::DenseVectorBlocked< DT_, IT_, Intern::dim_from_point_range< PointRange_ > > &vector, const Space_ &space)
Evaluates a vector-valued finite-element function in all given points.
static std::vector< Assembly::MatrixDiscreteEvalData< DT_, Intern::dim_from_point_range< PointRange_ >, Intern::dim_from_point_range< PointRange_ > > > eval_fe_gradient(const Dist::Comm &comm, const PointRange_ &points, const LAFEM::DenseVectorBlocked< DT_, IT_, Intern::dim_from_point_range< PointRange_ > > &vector, const Space_ &space)
Evaluates the gradient of a vector-valued finite-element function in all given points.
static std::vector< Assembly::VectorDiscreteEvalData< DT_, Intern::dim_from_point_range< PointRange_ > > > eval_fe_gradient(const Dist::Comm &comm, const PointRange_ &points, const LAFEM::DenseVector< DT_, IT_ > &vector, const Space_ &space)
Evaluates the gradient of a scalar finite-element function in all given points.
static bool is_in_bb(const BoundingBoxType_ &bb, const PointType_ &p)
Check if a point is in a bounding box.
MPI-abstraction for running scalar lambdas on other ranks.
Blocked Dense data vector class template.
Dense data vector class template.
Tiny Matrix class template.
Tiny Vector class template.
Inverse Trafo mapping class template.
InvMapDataType unmap_point(const ImagePointType &img_point, bool ignore_failures=false) const
Unmaps a given image point.
Global linear algebra namespace.
void mini(T_ &xmin, T_ x)
Updates the minimum of a set of values.
void maxi(T_ &xmax, T_ x)
Updates the maximum of a set of values.
std::uint64_t Index
Index data type.
Helper struct for determining types involved in a global evaluation of a finite-element function.