22#ifndef INCLUDE_EXADG_POSTPROCESSOR_SOLUTION_INTERPOLATION_H_
23#define INCLUDE_EXADG_POSTPROCESSOR_SOLUTION_INTERPOLATION_H_
26#include <deal.II/base/point.h>
27#include <deal.II/dofs/dof_handler.h>
28#include <deal.II/fe/fe_values.h>
29#include <deal.II/fe/mapping.h>
30#include <deal.II/grid/grid_tools.h>
31#include <deal.II/lac/la_parallel_vector.h>
35template<
int dim,
typename Number>
37my_point_value(dealii::Vector<Number> & result,
38 dealii::Mapping<dim>
const & mapping,
39 dealii::DoFHandler<dim>
const & dof_handler,
40 dealii::LinearAlgebra::distributed::Vector<Number>
const & dof_vector,
41 typename dealii::DoFHandler<dim>::active_cell_iterator
const & cell,
42 dealii::Point<dim>
const & point_in_ref_coord)
45 dof_handler.get_triangulation().all_reference_cells_are_hyper_cube(),
47 "This functionality is only available for meshes consisting of hypercube elements."));
49 Assert(dealii::GeometryInfo<dim>::distance_to_unit_cell(point_in_ref_coord) < 1e-10,
50 dealii::ExcInternalError());
52 dealii::Quadrature<dim>
const quadrature(
53 dealii::GeometryInfo<dim>::project_to_unit_cell(point_in_ref_coord));
55 dealii::FiniteElement<dim>
const & fe = dof_handler.get_fe();
56 dealii::FEValues<dim> fe_values(mapping, fe, quadrature, dealii::update_values);
57 fe_values.reinit(cell);
60 std::vector<dealii::Vector<Number>> solution_vector(1, dealii::Vector<Number>(fe.n_components()));
61 fe_values.get_function_values(dof_vector, solution_vector);
62 result = solution_vector[0];
65template<
int dim,
typename Number>
67evaluate_scalar_quantity_in_point(
68 Number & solution_value,
69 dealii::DoFHandler<dim>
const & dof_handler,
70 dealii::Mapping<dim>
const & mapping,
71 dealii::LinearAlgebra::distributed::Vector<Number>
const & numerical_solution,
72 dealii::Point<dim>
const & point,
73 MPI_Comm
const & mpi_comm,
74 double const tolerance = 1.e-10)
76 typedef std::pair<typename dealii::DoFHandler<dim>::active_cell_iterator, dealii::Point<dim>>
79 std::vector<Pair> adjacent_cells =
80 dealii::GridTools::find_all_active_cells_around_point(mapping, dof_handler, point, tolerance);
83 unsigned int counter = 0;
87 for(
auto cell : adjacent_cells)
90 if(cell.first->is_locally_owned())
92 dealii::Vector<Number> value(1);
93 my_point_value(value, mapping, dof_handler, numerical_solution, cell.first, cell.second);
95 solution_value += value(0);
101 counter = dealii::Utilities::MPI::sum(counter, mpi_comm);
102 AssertThrow(counter > 0, dealii::ExcMessage(
"No points found."));
104 solution_value = dealii::Utilities::MPI::sum(solution_value, mpi_comm);
105 solution_value /= (double)counter;
108template<
int dim,
typename Number>
110evaluate_vectorial_quantity_in_point(
111 dealii::Tensor<1, dim, Number> & solution_value,
112 dealii::DoFHandler<dim>
const & dof_handler,
113 dealii::Mapping<dim>
const & mapping,
114 dealii::LinearAlgebra::distributed::Vector<Number>
const & numerical_solution,
115 dealii::Point<dim>
const & point,
116 MPI_Comm
const & mpi_comm,
117 double const tolerance = 1.e-10)
119 typedef std::pair<typename dealii::DoFHandler<dim>::active_cell_iterator, dealii::Point<dim>>
122 std::vector<Pair> adjacent_cells =
123 dealii::GridTools::find_all_active_cells_around_point(mapping, dof_handler, point, tolerance);
126 unsigned int counter = 0;
127 solution_value = 0.0;
130 for(
auto cell : adjacent_cells)
133 if(cell.first->is_locally_owned())
135 dealii::Vector<Number> value(dim);
136 my_point_value(value, mapping, dof_handler, numerical_solution, cell.first, cell.second);
138 for(
unsigned int d = 0; d < dim; ++d)
139 solution_value[d] += value(d);
146 counter = dealii::Utilities::MPI::sum(counter, mpi_comm);
147 AssertThrow(counter > 0, dealii::ExcMessage(
"No points found."));
149 for(
unsigned int d = 0; d < dim; ++d)
150 solution_value[d] = dealii::Utilities::MPI::sum(solution_value[d], mpi_comm);
151 solution_value /= (double)counter;
159template<
int dim,
typename Number>
160std::vector<std::pair<std::vector<dealii::types::global_dof_index>, std::vector<Number>>>
161get_dof_indices_and_shape_values(
162 std::vector<std::pair<
typename dealii::Triangulation<dim>::active_cell_iterator,
163 dealii::Point<dim>>>
const & adjacent_cells,
164 dealii::DoFHandler<dim>
const & dof_handler,
165 dealii::Mapping<dim>
const & mapping,
166 dealii::LinearAlgebra::distributed::Vector<Number>
const & solution)
169 dof_handler.get_triangulation().all_reference_cells_are_hyper_cube(),
171 "This functionality is only available for meshes consisting of hypercube elements."));
174 std::vector<std::pair<std::vector<dealii::types::global_dof_index>, std::vector<Number>>>
175 dof_indices_and_shape_values;
177 for(
auto cell_tria : adjacent_cells)
181 typename dealii::DoFHandler<dim>::active_cell_iterator cell_dof = {
182 &dof_handler.get_triangulation(),
183 cell_tria.first->level(),
184 cell_tria.first->index(),
187 typedef std::pair<typename dealii::DoFHandler<dim>::active_cell_iterator, dealii::Point<dim>>
189 PairDof cell_and_point(cell_dof, cell_tria.second);
192 if(cell_and_point.first->is_locally_owned())
194 const dealii::Quadrature<dim> quadrature(
195 dealii::GeometryInfo<dim>::project_to_unit_cell(cell_and_point.second));
197 const dealii::FiniteElement<dim> & fe = dof_handler.get_fe();
198 dealii::FEValues<dim> fe_values(mapping, fe, quadrature, dealii::update_values);
199 fe_values.reinit(cell_and_point.first);
200 std::vector<dealii::types::global_dof_index> dof_indices(fe.dofs_per_cell);
201 cell_and_point.first->get_dof_indices(dof_indices);
203 std::vector<dealii::types::global_dof_index> dof_indices_global(fe.dofs_per_cell);
204 for(
unsigned int i = 0; i < fe.dofs_per_cell; ++i)
205 dof_indices_global[i] = solution.get_partitioner()->global_to_local(dof_indices[i]);
207 std::vector<Number> fe_shape_values(fe.dofs_per_cell);
208 for(
unsigned int i = 0; i < fe.dofs_per_cell; ++i)
209 fe_shape_values[i] = fe_values.shape_value(i, 0);
211 dof_indices_and_shape_values.emplace_back(dof_indices_global, fe_shape_values);
215 return dof_indices_and_shape_values;
221template<
int rank,
int dim,
typename Number>
224 static inline DEAL_II_ALWAYS_INLINE
225 dealii::Tensor<rank, dim, Number>
226 value(dealii::DoFHandler<dim>
const & dof_handler,
227 dealii::LinearAlgebra::distributed::Vector<Number>
const & solution,
228 std::vector<dealii::types::global_dof_index>
const & dof_indices,
229 std::vector<Number>
const & fe_shape_values)
234 (void)fe_shape_values;
236 AssertThrow(
false, dealii::ExcMessage(
"not implemented."));
238 dealii::Tensor<rank, dim, Number> result;
246template<
int dim,
typename Number>
249 static inline DEAL_II_ALWAYS_INLINE
250 dealii::Tensor<0, dim, Number>
251 value(dealii::DoFHandler<dim>
const & dof_handler,
252 dealii::LinearAlgebra::distributed::Vector<Number>
const & solution,
253 std::vector<dealii::types::global_dof_index>
const & dof_indices,
254 std::vector<Number>
const & fe_shape_values)
256 Assert(dof_handler.get_fe().dofs_per_cell == fe_shape_values.size(),
257 dealii::ExcMessage(
"Vector fe_shape_values has wrong size."));
259 Number result = Number(0.0);
261 dealii::FiniteElement<dim>
const & fe = dof_handler.get_fe();
262 for(
unsigned int i = 0; i < fe.dofs_per_cell; ++i)
263 result += solution.local_element(dof_indices[i]) * fe_shape_values[i];
265 dealii::Tensor<0, dim, Number> result_tensor = result;
267 return result_tensor;
274template<
int dim,
typename Number>
277 static inline DEAL_II_ALWAYS_INLINE
278 dealii::Tensor<1, dim, Number>
279 value(dealii::DoFHandler<dim>
const & dof_handler,
280 dealii::LinearAlgebra::distributed::Vector<Number>
const & solution,
281 std::vector<dealii::types::global_dof_index>
const & dof_indices,
282 std::vector<Number>
const & fe_shape_values)
284 Assert(dof_handler.get_fe().dofs_per_cell == fe_shape_values.size(),
285 dealii::ExcMessage(
"Vector fe_shape_values has wrong size."));
287 dealii::Tensor<1, dim, Number> result;
289 dealii::FiniteElement<dim>
const & fe = dof_handler.get_fe();
290 for(
unsigned int i = 0; i < fe.dofs_per_cell; ++i)
291 result[fe.system_to_component_index(i).first] +=
292 solution.local_element(dof_indices[i]) * fe_shape_values[i];
Definition solution_interpolation.h:223