14#ifndef dealii_vector_tools_evaluation_h
15#define dealii_vector_tools_evaluation_h
137 template <
int n_components,
138 template <
int,
int>
class MeshType,
151 const MeshType<dim, spacedim> &mesh,
152 const VectorType &vector,
160 const
unsigned int first_selected_component = 0);
177 template <
int n_components,
178 template <
int,
int> class MeshType,
183 (
concepts::is_dealii_vector_type<VectorType> &&
184 concepts::is_triangulation_or_dof_handler<MeshType<dim, spacedim>>))
189 typename VectorType::value_type>::
191 RemotePointEvaluation<dim, spacedim> &cache,
192 const MeshType<dim, spacedim> &mesh,
193 const VectorType &vector,
196 const
unsigned int first_selected_component = 0);
211 template <
int n_components,
212 template <
int,
int> class MeshType,
217 (
concepts::is_dealii_vector_type<VectorType> &&
218 concepts::is_triangulation_or_dof_handler<MeshType<dim, spacedim>>))
223 typename VectorType::value_type>::
225 const MeshType<dim, spacedim> &mesh,
226 const VectorType &vector,
235 first_selected_component = 0);
251 template <
int n_components,
252 template <
int,
int> class MeshType,
257 (
concepts::is_dealii_vector_type<VectorType> &&
258 concepts::is_triangulation_or_dof_handler<MeshType<dim, spacedim>>))
263 typename VectorType::value_type>::
265 RemotePointEvaluation<dim, spacedim>
267 const MeshType<dim, spacedim> &mesh,
268 const VectorType &vector,
272 first_selected_component = 0);
280 template <
int n_components,
281 template <
int,
int>
class MeshType,
292 typename VectorType::value_type>::
294 const MeshType<dim, spacedim> &mesh,
295 const VectorType &vector,
302 const
unsigned int first_selected_component)
304 cache.
reinit(evaluation_points, mesh.get_triangulation(), mapping);
306 return point_values<n_components>(
307 cache, mesh, vector, flags, first_selected_component);
312 template <
int n_components,
313 template <
int,
int>
class MeshType,
326 const MeshType<dim, spacedim> &mesh,
327 const VectorType &vector,
336 first_selected_component)
338 cache.
reinit(evaluation_points, mesh.get_triangulation(), mapping);
340 return point_gradients<n_components>(
341 cache, mesh, vector, flags, first_selected_component);
351 template <
typename T>
358 case EvaluationFlags::avg:
360 return std::accumulate(
values.begin(),
values.end(), T{}) /
363 case EvaluationFlags::max:
365 case EvaluationFlags::min:
367 case EvaluationFlags::insert:
380 template <
int rank,
int dim,
typename Number>
387 case EvaluationFlags::avg:
389 return std::accumulate(
values.begin(),
394 case EvaluationFlags::insert:
408 template <
int n_components,
int rank,
int dim,
typename Number>
417 case EvaluationFlags::avg:
421 for (
unsigned int j = 0; j <
values.size(); ++j)
422 for (
unsigned int i = 0; i < n_components; ++i)
423 temp[i] = temp[i] + values[j][i];
425 for (
unsigned int i = 0; i < n_components; ++i)
430 case EvaluationFlags::insert:
440 template <
int n_components,
447 const unsigned int i,
453 const VectorType &vector,
455 const ::EvaluationFlags::EvaluationFlags evaluation_flags,
456 const unsigned int first_selected_component,
461 typename VectorType::value_type> &,
462 const unsigned int &)> process_quadrature_point,
464 std::vector<typename VectorType::value_type> &solution_values,
469 typename VectorType::value_type>>>
472 if (evaluators.empty())
477 cell_data.cells[i].first,
478 cell_data.cells[i].second,
482 cell_data.reference_point_values.data() +
483 cell_data.reference_point_ptrs[i],
484 cell_data.reference_point_ptrs[i + 1] -
485 cell_data.reference_point_ptrs[i]);
487 solution_values.resize(
489 cell->get_dof_values(vector,
490 solution_values.begin(),
491 solution_values.end());
493 if (evaluators[cell->active_fe_index()] ==
nullptr)
494 evaluators[cell->active_fe_index()] =
498 typename VectorType::value_type>>(
502 first_selected_component);
503 auto &evaluator = *evaluators[cell->active_fe_index()];
505 evaluator.reinit(cell, unit_points);
506 evaluator.evaluate(solution_values, evaluation_flags);
508 for (
unsigned int q = 0; q < unit_points.size(); ++q)
509 values[q + cell_data.reference_point_ptrs[i]] =
510 process_quadrature_point(evaluator, q);
515 template <
int dim,
int spacedim,
typename Number>
523 return vector[cell->active_cell_index()];
528 template <
int dim,
int spacedim,
typename Number>
535 const auto distributed_tria =
538 const bool use_distributed_path =
539 (distributed_tria ==
nullptr) ?
541 (vector.get_partitioner().get() ==
542 distributed_tria->global_active_cell_index_partitioner()
546 if (use_distributed_path)
548 return vector[cell->global_active_cell_index()];
553 return vector[cell->active_cell_index()];
559 template <
typename Number,
typename Number2>
561 set_value(Number &dst,
const Number2 &src)
568 template <
typename Number,
int rank,
int dim,
typename Number2>
574 "A cell-data vector can only have a single component."));
579 template <
int n_components,
586 const unsigned int i,
592 const VectorType &vector,
594 const ::EvaluationFlags::EvaluationFlags evaluation_flags,
595 const unsigned int first_selected_component,
600 typename VectorType::value_type> &,
601 const unsigned int &)>,
603 std::vector<typename VectorType::value_type> &,
608 typename VectorType::value_type>>> &)
610 Assert(n_components == 1 && first_selected_component == 0,
612 "A cell-data vector can only have a single component."));
614 Assert(evaluation_flags ==
616 ExcMessage(
"For cell-data vectors, only values can be queried."));
619 &triangulation, cell_data.cells[i].first, cell_data.cells[i].second};
623 for (
unsigned int q = cell_data.reference_point_ptrs[i];
624 q < cell_data.reference_point_ptrs[i + 1];
631 template <
int n_components,
640 inline std::vector<value_type> evaluate_at_points(
642 const MeshType &mesh,
643 const VectorType &vector,
645 const unsigned int first_selected_component,
647 const ::EvaluationFlags::EvaluationFlags evaluation_flags,
652 typename VectorType::value_type> &,
653 const unsigned int &)> process_quadrature_point)
657 "Utilities::MPI::RemotePointEvaluation is not ready yet! "
658 "Please call Utilities::MPI::RemotePointEvaluation::reinit() "
659 "yourself or another function that does this for you."));
664 "The provided Utilities::MPI::RemotePointEvaluation and DoFHandler "
665 "object have been set up with different Triangulation objects, "
666 "a scenario not supported!"));
669 const auto evaluation_point_results = [&]() {
672 const auto evaluation_function = [&](
auto &
values,
673 const auto &cell_data) {
674 std::vector<typename VectorType::value_type> solution_values;
680 typename VectorType::value_type>>>
683 for (
unsigned int i = 0; i < cell_data.cells.size(); ++i)
684 process_cell<n_components, dim, spacedim, VectorType, value_type>(
692 first_selected_component,
693 process_quadrature_point,
699 std::vector<value_type> evaluation_point_results;
700 std::vector<value_type> buffer;
702 cache.template evaluate_and_process<value_type>(
703 evaluation_point_results, buffer, evaluation_function);
705 return evaluation_point_results;
711 return evaluation_point_results;
717 std::vector<value_type> unique_evaluation_point_results(
722 for (
unsigned int i = 0; i < ptr.size() - 1; ++i)
724 const auto n_entries = ptr[i + 1] - ptr[i];
728 unique_evaluation_point_results[i] =
731 evaluation_point_results.data() + ptr[i], n_entries));
734 return unique_evaluation_point_results;
739 template <
int n_components,
740 template <
int,
int>
class MeshType,
753 RemotePointEvaluation<dim, spacedim> &cache,
754 const MeshType<dim, spacedim> &mesh,
755 const VectorType &vector,
757 const
unsigned int first_selected_component)
759 return internal::evaluate_at_points<
763 MeshType<dim, spacedim>,
773 first_selected_component,
776 [](
const auto &evaluator,
const auto &q) {
777 return evaluator.get_value(q);
783 template <
int n_components,
784 template <
int,
int>
class MeshType,
797 RemotePointEvaluation<dim, spacedim>
799 const MeshType<dim, spacedim> &mesh,
800 const VectorType &vector,
804 first_selected_component)
806 return internal::evaluate_at_points<
810 MeshType<dim, spacedim>,
816 typename VectorType::value_type>::gradient_type>(
821 first_selected_component,
824 [](
const auto &evaluator,
const unsigned &q) {
825 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
Communicate values between a mesh and arbitrary points.
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
virtual size_type size() const override
unsigned int size() const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_CXX20_REQUIRES(condition)
#define DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NOT_IMPLEMENTED()
#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.
Tpetra::Vector< Number, LO, GO, NodeType< MemorySpace > > VectorType
* * * * ValueType TimeRateRequest< ValueType, dim, Number > get_value() const
* * * RotationFunction< dim, Number >::RotationFunction Number(dim)
* * * * void TimeRateRequest< ValueType, dim, Number > set_value(const ValueType &value)
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)