16#ifndef NDIM_INTERPOLATION
17#define NDIM_INTERPOLATION
19#include <hyper.deal/base/config.h>
21#include <deal.II/base/function.h>
23#include <hyper.deal/matrix_free/fe_evaluation_cell.h>
24#include <hyper.deal/matrix_free/matrix_free.h>
37 typename VectorizedArrayType,
41 interpolate(FEEvaluation<dim_x,
46 VectorizedArrayType> &phi,
47 const VectorType & src,
50 static const int dim = dim_x + dim_v;
52 static const dealii::internal::EvaluatorVariant tensorproduct =
53 dealii::internal::EvaluatorVariant::evaluate_evenodd;
57 VectorizedArrayType *data_ptr = phi.get_data_ptr();
61 phi.read_dof_values(src);
63 dealii::internal::FEEvaluationImplBasisChange<
65 dealii::internal::EvaluatorQuantity::value,
68 n_points>::do_forward(1, *phi.get_shape_values(), data_ptr, data_ptr);
87 typename VectorizedArrayType>
90 const std::shared_ptr<dealii::Function<dim_x + dim_v, Number>>
92 const MatrixFree<dim_x, dim_v, Number, VectorizedArrayType> &matrix_free,
94 const unsigned int dof_no_x,
95 const unsigned int dof_no_v,
96 const unsigned int quad_no_x,
97 const unsigned int quad_no_v)
99 const static int dim = dim_x + dim_v;
101 FEEvaluation<dim_x, dim_v, degree, n_points, Number, VectorizedArrayType>
102 phi(matrix_free, dof_no_x, dof_no_v, quad_no_x, quad_no_v);
106 matrix_free.template cell_loop<VectorType, int>(
107 [&](
const auto &,
auto &dst,
const auto &,
const auto cell)
mutable {
108 VectorizedArrayType *data_ptr = phi.get_data_ptr();
113 for (
unsigned int qv = 0, q = 0; qv < phi.n_q_points_v; qv++)
114 for (
unsigned int qx = 0; qx < phi.n_q_points_x; qx++, q++)
117 const auto q_point = phi.get_quadrature_point(qx, qv);
119 for (
unsigned int v = 0; v < phi.n_vectorization_lanes_filled();
123 dealii::Point<dim, Number> p;
124 for (
unsigned int d = 0; d < dim; ++d)
125 p[d] = q_point[d][v];
127 data_ptr[q][v] = analytical_solution->value(p);
131 phi.set_dof_values(dst);
144 template <
int degree,
150 typename VectorizedArrayType>
151 std::array<Number, 2>
153 const std::shared_ptr<dealii::Function<dim_x + dim_v, Number>>
155 const MatrixFree<dim_x, dim_v, Number, VectorizedArrayType> &matrix_free,
156 const VectorType & src,
157 const unsigned int dof_no_x,
158 const unsigned int dof_no_v,
159 const unsigned int quad_no_x,
160 const unsigned int quad_no_v)
162 const static int dim = dim_x + dim_v;
164 FEEvaluation<dim_x, dim_v, degree, n_points, Number, VectorizedArrayType>
165 phi(matrix_free, dof_no_x, dof_no_v, quad_no_x, quad_no_v);
167 std::array<Number, 2> result{{0.0, 0.0}};
171 matrix_free.template cell_loop<int, VectorType>(
173 const auto &,
int &,
const VectorType &src,
const auto cell)
mutable {
174 const VectorizedArrayType *f_ptr =
175 VectorTools::internal::interpolate(phi, src, cell);
177 std::array<VectorizedArrayType, 2> temp;
178 std::fill(temp.begin(), temp.end(), 0.);
180 for (
unsigned int qv = 0, q = 0; qv < phi.n_q_points_v; qv++)
181 for (
unsigned int qx = 0; qx < phi.n_q_points_x; qx++, q++)
184 VectorizedArrayType solution_q;
185 const auto q_point = phi.get_quadrature_point(qx, qv);
187 for (
unsigned int v = 0; v < phi.n_vectorization_lanes_filled();
190 dealii::Point<dim> p;
191 for (
unsigned int d = 0; d < dim; ++d)
192 p[d] = q_point[d][v];
193 solution_q[v] = analytical_solution->value(p);
196 const auto f = f_ptr[q];
197 const auto e = f - solution_q;
198 const auto JxW = phi.JxW(qx, qv);
200 temp[0] += f * f * JxW;
201 temp[1] += e * e * JxW;
205 for (
unsigned int v = 0; v < phi.n_vectorization_lanes_filled(); v++)
206 for (
unsigned int i = 0; i < temp.size(); i++)
207 result[i] += temp[i][v];
212 MPI_Allreduce(MPI_IN_PLACE,
217 matrix_free.get_communicator());
219 result[0] = std::sqrt(result[0]);
220 result[1] = std::sqrt(result[1]);
230 template <
int degree,
235 typename VectorizedArrayType,
239 velocity_space_integration(
240 const MatrixFree<dim_x, dim_v, Number, VectorizedArrayType> &data,
242 const Vector_In & src,
243 const unsigned int dof_no_x,
244 const unsigned int dof_no_v,
245 const unsigned int quad_no_v)
250 using VectorizedArrayTypeX =
typename MF::VectorizedArrayTypeX;
251 using VectorizedArrayTypeV =
typename MF::VectorizedArrayTypeV;
253 FEEvaluation<dim_x, dim_v, degree, n_points, Number, VectorizedArrayType>
254 phi(
const_cast<MatrixFree<dim_x, dim_v, Number, VectorizedArrayType> &
>(
262 FEEvaluation<dim_x, degree, n_points, 1, Number, VectorizedArrayTypeX>
263 phi_x(data.get_matrix_free_x(), dof_no_x, 0 );
265 FEEvaluation<dim_v, degree, n_points, 1, Number, VectorizedArrayTypeV>
266 phi_v(data.get_matrix_free_v(), dof_no_v, quad_no_v);
270 data.template cell_loop<Vector_Out, Vector_In>(
273 const Vector_In &src,
274 const auto cell)
mutable {
276 phi.read_dof_values(src);
278 phi_x.reinit(cell.x);
280 unsigned int index_v = cell.v / VectorizedArrayTypeV::size();
281 unsigned int lane_v = cell.v % VectorizedArrayTypeV::size();
282 phi_v.reinit(index_v);
285 const VectorizedArrayType *data_ptr_src = phi.get_data_ptr();
286 VectorizedArrayTypeX * data_ptr_dst = phi_x.begin_dof_values();
289 for (
unsigned int qx = 0; qx < phi_x.n_q_points; ++qx)
291 VectorizedArrayType sum_v = VectorizedArrayType();
292 for (
unsigned int qv = 0;
293 qv < dealii::Utilities::pow<unsigned int>(n_points, dim_v);
297 dealii::Utilities::pow(n_points, dim_v) * qv] *
298 phi_v.JxW(qv)[lane_v];
299 data_ptr_dst[qx] = sum_v;
302 phi_x.distribute_local_to_global(dst);
311 dst.locally_owned_size(),
314 data.get_matrix_free_v().get_dof_handler().get_communicator());
322 template <
int degree,
327 typename VectorizedArrayType,
331 coordinate_space_integration(
332 const MatrixFree<dim_x, dim_v, Number, VectorizedArrayType> &data,
334 const Vector_In & src,
335 const unsigned int dof_no_x,
336 const unsigned int dof_no_v,
337 const unsigned int quad_no_x)
341 using VectorizedArrayTypeX =
typename MF::VectorizedArrayTypeX;
342 using VectorizedArrayTypeV =
typename MF::VectorizedArrayTypeV;
343 static_assert(VectorizedArrayTypeV::size() == 1);
345 FEEvaluation<dim_x, dim_v, degree, n_points, Number, VectorizedArrayType>
346 phi(data, dof_no_x, dof_no_v, 0 , 0 );
348 FEEvaluation<dim_x, degree, n_points, 1, Number, VectorizedArrayTypeX>
349 phi_x(data.get_matrix_free_x(), dof_no_x, quad_no_x);
351 FEEvaluation<dim_v, degree, n_points, 1, Number, VectorizedArrayTypeV>
352 phi_v(data.get_matrix_free_v(), dof_no_v, 0 );
357 constexpr auto N_v_points = dealii::Utilities::pow(n_points, dim_v);
359 dealii::AlignedVector<VectorizedArrayTypeX> scratch(N_v_points);
361 data.template cell_loop<Vector_Out, Vector_In>(
364 const Vector_In &src,
365 const auto cell)
mutable {
367 phi.read_dof_values(src);
368 phi_x.reinit(cell.x);
369 phi_v.reinit(cell.v);
371 const VectorizedArrayType *data_ptr_src = phi.get_data_ptr();
372 VectorizedArrayTypeV * data_ptr_dst = phi_v.begin_dof_values();
374 const auto N_lanes_x = phi.n_vectorization_lanes_filled();
377 for (
unsigned int qv = 0; qv < phi_v.n_q_points; ++qv)
380 for (
unsigned int qx = 0; qx < phi_x.n_q_points; ++qx)
382 data_ptr_src[qx + qv * N_v_points] * phi_x.JxW(qx);
386 for (
unsigned int qv = 0; qv < phi_v.n_q_points; ++qv)
388 data_ptr_dst[qv] = 0.0;
389 for (
unsigned int lane = 0; lane < N_lanes_x; ++lane)
390 data_ptr_dst[qv] += scratch[qv][lane];
393 phi_v.distribute_local_to_global(dst);
400 data.get_matrix_free_x().get_dof_handler().get_communicator();
401 MPI_Allreduce(MPI_IN_PLACE,
403 dst.locally_owned_size(),
Definition matrix_free.h:40