17#ifndef dealii_vector_tools_evaluation_h
18#define dealii_vector_tools_evaluation_h
137 template <
int n_components,
150 typename VectorType::value_type>::
152 const MeshType<dim, spacedim> &mesh,
153 const VectorType & vector,
156 Utilities::MPI::RemotePointEvaluation<dim,
161 const
unsigned int first_selected_component = 0);
178 template <
int n_components,
185 (
concepts::is_dealii_vector_type<VectorType> &&
186 concepts::is_triangulation_or_dof_handler<MeshType<dim, spacedim>>))
191 typename VectorType::value_type>::
193 RemotePointEvaluation<dim, spacedim> &cache,
194 const MeshType<dim, spacedim> & mesh,
195 const VectorType & vector,
198 const
unsigned int first_selected_component = 0);
213 template <
int n_components,
220 (
concepts::is_dealii_vector_type<VectorType> &&
221 concepts::is_triangulation_or_dof_handler<MeshType<dim, spacedim>>))
226 typename VectorType::value_type>::
228 const MeshType<dim, spacedim> &mesh,
229 const VectorType & vector,
238 first_selected_component = 0);
254 template <
int n_components,
261 (
concepts::is_dealii_vector_type<VectorType> &&
262 concepts::is_triangulation_or_dof_handler<MeshType<dim, spacedim>>))
267 typename VectorType::value_type>::
269 RemotePointEvaluation<dim, spacedim>
271 const MeshType<dim, spacedim> &mesh,
272 const VectorType & vector,
276 first_selected_component = 0);
284 template <
int n_components,
297 typename VectorType::value_type>::
299 const MeshType<dim, spacedim> &mesh,
300 const VectorType & vector,
303 Utilities::MPI::RemotePointEvaluation<dim,
307 const
unsigned int first_selected_component)
309 cache.reinit(evaluation_points, mesh.get_triangulation(), mapping);
311 return point_values<n_components>(
312 cache, mesh, vector, flags, first_selected_component);
317 template <
int n_components,
330 typename VectorType::value_type>::
332 const MeshType<dim, spacedim> &mesh,
333 const VectorType & vector,
342 first_selected_component)
344 cache.reinit(evaluation_points, mesh.get_triangulation(), mapping);
346 return point_gradients<n_components>(
347 cache, mesh, vector, flags, first_selected_component);
357 template <
typename T>
364 case EvaluationFlags::avg:
366 return std::accumulate(
values.begin(),
values.end(), T{}) /
369 case EvaluationFlags::max:
371 case EvaluationFlags::min:
373 case EvaluationFlags::insert:
386 template <
int rank,
int dim,
typename Number>
393 case EvaluationFlags::avg:
395 return std::accumulate(
values.begin(),
398 (Number(1.0) *
values.size());
400 case EvaluationFlags::insert:
414 template <
int n_components,
int rank,
int dim,
typename Number>
423 case EvaluationFlags::avg:
427 for (
unsigned int j = 0; j <
values.size(); ++j)
428 for (
unsigned int i = 0; i < n_components; ++i)
429 temp[i] = temp[i] + values[j][i];
431 for (
unsigned int i = 0; i < n_components; ++i)
432 temp[i] /= Number(
values.size());
436 case EvaluationFlags::insert:
446 template <
int n_components,
453 const unsigned int i,
459 const VectorType & vector,
461 const ::EvaluationFlags::EvaluationFlags evaluation_flags,
462 const unsigned int first_selected_component,
467 typename VectorType::value_type> &,
468 const unsigned int &)> process_quadrature_point,
470 std::vector<typename VectorType::value_type> &solution_values,
475 typename VectorType::value_type>>>
478 if (evaluators.size() == 0)
483 cell_data.cells[i].first,
484 cell_data.cells[i].second,
488 cell_data.reference_point_values.data() +
489 cell_data.reference_point_ptrs[i],
490 cell_data.reference_point_ptrs[i + 1] -
491 cell_data.reference_point_ptrs[i]);
493 solution_values.resize(
495 cell->get_dof_values(vector,
496 solution_values.begin(),
497 solution_values.end());
499 if (evaluators[cell->active_fe_index()] ==
nullptr)
500 evaluators[cell->active_fe_index()] =
504 typename VectorType::value_type>>(
508 first_selected_component);
509 auto &evaluator = *evaluators[cell->active_fe_index()];
511 evaluator.
reinit(cell, unit_points);
512 evaluator.evaluate(solution_values, evaluation_flags);
514 for (
unsigned int q = 0; q < unit_points.size(); ++q)
515 values[q + cell_data.reference_point_ptrs[i]] =
516 process_quadrature_point(evaluator, q);
521 template <
int dim,
int spacedim,
typename Number>
530 return vector[cell->active_cell_index()];
535 template <
int dim,
int spacedim,
typename Number>
542 const auto distributed_tria =
545 const bool use_distributed_path =
546 (distributed_tria ==
nullptr) ?
548 (vector.get_partitioner().get() ==
549 distributed_tria->global_active_cell_index_partitioner()
553 if (use_distributed_path)
555 return vector[cell->global_active_cell_index()];
560 return vector[cell->active_cell_index()];
566 template <
typename Number,
typename Number2>
568 set_value(Number &dst,
const Number2 &src)
575 template <
typename Number,
int rank,
int dim,
typename Number2>
581 "A cell-data vector can only have a single component."));
586 template <
int n_components,
593 const unsigned int i,
599 const VectorType & vector,
601 const ::EvaluationFlags::EvaluationFlags evaluation_flags,
602 const unsigned int first_selected_component,
607 typename VectorType::value_type> &,
608 const unsigned int &)>,
610 std::vector<typename VectorType::value_type> &,
615 typename VectorType::value_type>>> &)
617 (void)evaluation_flags;
618 (void)first_selected_component;
620 Assert(n_components == 1 && first_selected_component == 0,
622 "A cell-data vector can only have a single component."));
624 Assert(evaluation_flags ==
626 ExcMessage(
"For cell-data vectors, only values can be queried."));
629 &
triangulation, cell_data.cells[i].first, cell_data.cells[i].second};
633 for (
unsigned int q = cell_data.reference_point_ptrs[i];
634 q < cell_data.reference_point_ptrs[i + 1];
636 set_value(values[q], value);
641 template <
int n_components,
650 inline std::vector<value_type> evaluate_at_points(
652 const MeshType & mesh,
653 const VectorType & vector,
655 const unsigned int first_selected_component,
657 const ::EvaluationFlags::EvaluationFlags evaluation_flags,
662 typename VectorType::value_type> &,
663 const unsigned int &)> process_quadrature_point)
667 "Utilities::MPI::RemotePointEvaluation is not ready yet! "
668 "Please call Utilities::MPI::RemotePointEvaluation::reinit() "
669 "yourself or another function that does this for you."));
674 "The provided Utilities::MPI::RemotePointEvaluation and DoFHandler "
675 "object have been set up with different Triangulation objects, "
676 "a scenario not supported!"));
679 const auto evaluation_point_results = [&]() {
682 const auto evaluation_function = [&](
auto &
values,
683 const auto &cell_data) {
684 std::vector<typename VectorType::value_type> solution_values;
690 typename VectorType::value_type>>>
693 for (
unsigned int i = 0; i < cell_data.cells.size(); ++i)
694 process_cell<n_components, dim, spacedim, VectorType, value_type>(
702 first_selected_component,
703 process_quadrature_point,
709 std::vector<value_type> evaluation_point_results;
710 std::vector<value_type> buffer;
712 cache.template evaluate_and_process<value_type>(
713 evaluation_point_results, buffer, evaluation_function);
715 return evaluation_point_results;
721 return evaluation_point_results;
727 std::vector<value_type> unique_evaluation_point_results(
732 for (
unsigned int i = 0; i < ptr.size() - 1; ++i)
734 const auto n_entries = ptr[i + 1] - ptr[i];
738 unique_evaluation_point_results[i] =
741 evaluation_point_results.data() + ptr[i], n_entries));
744 return unique_evaluation_point_results;
749 template <
int n_components,
762 typename VectorType::value_type>::
764 RemotePointEvaluation<dim, spacedim> &cache,
765 const MeshType<dim, spacedim> & mesh,
766 const VectorType & vector,
768 const
unsigned int first_selected_component)
770 return internal::evaluate_at_points<
774 MeshType<dim, spacedim>,
779 typename VectorType::value_type>::value_type>(
784 first_selected_component,
787 [](
const auto &evaluator,
const auto &q) {
788 return evaluator.get_value(q);
794 template <
int n_components,
807 typename VectorType::value_type>::
809 RemotePointEvaluation<dim, spacedim>
811 const MeshType<dim, spacedim> &mesh,
812 const VectorType & vector,
816 first_selected_component)
818 return internal::evaluate_at_points<
822 MeshType<dim, spacedim>,
828 typename VectorType::value_type>::gradient_type>(
833 first_selected_component,
836 [](
const auto &evaluator,
const unsigned &q) {
837 return evaluator.get_gradient(q);
const hp::FECollection< dim, spacedim > & get_fe_collection() const
const FiniteElement< dim, spacedim > & get_fe(const types::fe_index index=0) const
void reinit(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const ArrayView< const Point< dim > > &unit_points)
unsigned int n_dofs_per_cell() const
size_type locally_owned_size() const
Abstract base class for mapping classes.
unsigned int n_active_cells() const
const Triangulation< dim, spacedim > & get_triangulation() const
const std::vector< unsigned int > & get_point_ptrs() const
bool is_map_unique() const
const Mapping< dim, spacedim > & get_mapping() const
unsigned int size() const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_CXX20_REQUIRES(condition)
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcMessage(std::string arg1)
typename ActiveSelector::active_cell_iterator active_cell_iterator
@ update_values
Shape function values.
@ update_gradients
Shape function gradients.
The namespace for the EvaluationFlags enum.
EvaluationFlags
The EvaluationFlags enum.
T reduce(const T &local_value, const MPI_Comm comm, const std::function< T(const T &, const T &)> &combiner, const unsigned int root_process=0)
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation
const ::Triangulation< dim, spacedim > & tria