hyper.deal
Loading...
Searching...
No Matches
fe_evaluation_cell.h
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2020 by the hyper.deal authors
4//
5// This file is part of the hyper.deal library.
6//
7// The hyper.deal library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 3.0 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.MD at
12// the top level directory of hyper.deal.
13//
14// ---------------------------------------------------------------------
15
16#ifndef HYPERDEAL_NDIM_FEEVALUATION_CELL
17#define HYPERDEAL_NDIM_FEEVALUATION_CELL
18
19#include <hyper.deal/base/config.h>
20
21#include <deal.II/matrix_free/fe_evaluation.h>
22
23#include <hyper.deal/matrix_free/fe_evaluation_base.h>
24#include <hyper.deal/matrix_free/read_write_operation.h>
25#include <hyper.deal/matrix_free/vector_access_internal.h>
26
27namespace hyperdeal
28{
35 template <int dim_x,
36 int dim_v,
37 int degree,
38 int n_points,
39 typename Number,
40 typename VectorizedArrayType>
41 class FEEvaluation : public FEEvaluationBase<dim_x,
42 dim_v,
43 degree,
44 n_points,
45 Number,
46 VectorizedArrayType>
47 {
48 public:
49 // clang-format off
50 static const unsigned int dim = dim_x + dim_v;
51 static const unsigned int static_dofs_per_cell_x = dealii::Utilities::pow(degree + 1, dim_x);
52 static const unsigned int static_dofs_per_cell_v = dealii::Utilities::pow(degree + 1, dim_v);
53 static const unsigned int static_dofs_per_cell = static_dofs_per_cell_x * static_dofs_per_cell_v;
54 static const unsigned int n_q_points_x = dealii::Utilities::pow(n_points, dim_x);
55 static const unsigned int n_q_points_v = dealii::Utilities::pow(n_points, dim_v);
56 static const unsigned int n_q_points = n_q_points_x * n_q_points_v;
57 // clang-format on
58
59 using PARENT = FEEvaluationBase<dim_x,
60 dim_v,
61 degree,
62 n_points,
63 Number,
64 VectorizedArrayType>;
65
66 static const unsigned int n_vectors = PARENT::n_vectors;
67 static const unsigned int n_vectors_v = PARENT::n_vectors_v;
68
85 const unsigned int dof_no_x,
86 const unsigned int dof_no_v,
87 const unsigned int quad_no_x,
88 const unsigned int quad_no_v)
90 , phi_x(this->matrix_free_x, dof_no_x, quad_no_x)
91 , phi_v(this->matrix_free_v, dof_no_v, quad_no_v)
92 {
93 this->shape_values = &phi_x.get_shape_info().data[0].shape_values_eo;
94 this->shape_gradients =
95 &phi_x.get_shape_info().data[0].shape_gradients_collocation_eo;
96 }
97
98
102 void
104 cell_index) override
105 {
106 PARENT::reinit(cell_index);
107 phi_x.reinit(this->macro_cell_x);
108 phi_v.reinit(this->macro_cell_v);
109 }
110
111
115 void
117 const dealii::LinearAlgebra::distributed::Vector<Number> &src,
118 VectorizedArrayType * data) const
119 {
122 this->matrix_free.get_face_info(),
123 this->matrix_free.get_shape_info())
124 .template process_cell<dim, degree>(
126 VectorizedArrayType>(),
127 src.shared_vector_data(),
128 data,
129 this->macro);
130 }
131
132
133
137 void
139 const dealii::LinearAlgebra::distributed::Vector<Number> &src)
140 {
141 read_dof_values(src, &this->data[0]);
142 }
143
144
145
149 void
151 dealii::LinearAlgebra::distributed::Vector<Number> &dst) const
152 {
155 this->matrix_free.get_face_info(),
156 this->matrix_free.get_shape_info())
157 .template process_cell<dim, degree>(
159 VectorizedArrayType>(),
160 dst.shared_vector_data(),
161 &this->data[0],
162 this->macro);
163 }
164
165
166
170 inline unsigned int
172 {
173 return this->matrix_free_x.n_active_entries_per_cell_batch(
174 this->macro_cell_x);
175 }
176
177
183 inline VectorizedArrayType
184 submit_inplace(const VectorizedArrayType data, const unsigned int q) const
185 {
186 return submit_inplace(data, q, q % n_q_points_x, q / n_q_points_x);
187 }
188
189
190
196 inline VectorizedArrayType
197 submit_inplace(const VectorizedArrayType data,
198 unsigned int /*q*/,
199 unsigned int qx,
200 unsigned int qv) const
201 {
202 return data * phi_x.JxW(qx) *
203 phi_v.JxW(qv)[n_vectors_v == 1 ? 0 : this->lane_y];
204 }
205
206
207 inline DEAL_II_ALWAYS_INLINE //
208 VectorizedArrayType
209 JxW(unsigned int qx, unsigned int qv) const
210 {
211 return phi_x.JxW(qx) * phi_v.JxW(qv)[n_vectors_v == 1 ? 0 : this->lane_y];
212 }
213
214
215
219 inline DEAL_II_ALWAYS_INLINE //
220 dealii::Tensor<1, dim_x, VectorizedArrayType>
221 get_gradient_x(const VectorizedArrayType *__restrict grad_in,
222 const unsigned int q,
223 const unsigned int qx,
224 const unsigned int qv) const
225 {
226 (void)qv;
227
228 dealii::Tensor<1, dim_x, VectorizedArrayType> result;
229
230 const auto jacobian = phi_x.inverse_jacobian(qx);
231
232 for (auto d = 0u; d < dim_x; d++)
233 {
234 result[d] = jacobian[d][0] * grad_in[q];
235 for (auto e = 1u; e < dim_x; ++e)
236 result[d] +=
237 (jacobian[d][e] * grad_in[q + e * n_q_points_x * n_q_points_v]);
238 }
239
240 return result;
241 }
242
243
244
248 inline DEAL_II_ALWAYS_INLINE //
249 dealii::Tensor<1, dim_v, VectorizedArrayType>
250 get_gradient_v(const VectorizedArrayType *__restrict grad_in,
251 const unsigned int q,
252 const unsigned int qx,
253 const unsigned int qv) const
254 {
255 (void)qx;
256
257 dealii::Tensor<1, dim_v, VectorizedArrayType> result;
258
259 const auto jacobian = phi_v.inverse_jacobian(qv);
260
261 for (auto d = 0u; d < dim_v; d++)
262 {
263 result[d] =
264 jacobian[d][0][n_vectors_v == 1 ? 0 : this->lane_y] * grad_in[q];
265 for (auto e = 1u; e < dim_v; ++e)
266 result[d] += (jacobian[d][e][n_vectors_v == 1 ? 0 : this->lane_y] *
267 grad_in[q + e * n_q_points_x * n_q_points_v]);
268 }
269
270 return result;
271 }
272
273
274
278 template <bool do_add>
279 inline DEAL_II_ALWAYS_INLINE //
280 void
281 submit_value(VectorizedArrayType *__restrict data_ptr_out,
282 const VectorizedArrayType values_in,
283 const unsigned int q,
284 const unsigned int qx,
285 const unsigned int qv) const
286 {
287 const auto jxw =
288 phi_x.JxW(qx) * phi_v.JxW(qv)[n_vectors_v == 1 ? 0 : this->lane_y];
289
290 if (do_add)
291 data_ptr_out[q] += values_in * jxw;
292 else
293 data_ptr_out[q] = values_in * jxw;
294 }
295
296
297
301 inline DEAL_II_ALWAYS_INLINE //
302 void
303 submit_gradient_x(VectorizedArrayType *__restrict data_ptr_out,
304 const VectorizedArrayType *__restrict grad_in,
305 const unsigned int q,
306 const unsigned int qx,
307 const unsigned int qv) const
308 {
309 const auto jxw =
310 phi_x.JxW(qx) * phi_v.JxW(qv)[n_vectors_v == 1 ? 0 : this->lane_y];
311 const auto jacobian = phi_x.inverse_jacobian(qx);
312
313 for (auto d = 0u; d < dim_x; d++)
314 {
315 auto new_val = jacobian[0][d] * grad_in[0];
316 for (auto e = 1u; e < dim_x; ++e)
317 new_val += (jacobian[e][d] * grad_in[e]);
318 data_ptr_out[q + d * n_q_points_x * n_q_points_v] = new_val * jxw;
319 }
320 }
321
322
323
327 inline DEAL_II_ALWAYS_INLINE //
328 void
329 submit_gradient_v(VectorizedArrayType *__restrict data_ptr_out,
330 const VectorizedArrayType *__restrict grad_in,
331 const unsigned int q,
332 const unsigned int qx,
333 const unsigned int qv) const
334 {
335 const auto jxw =
336 phi_x.JxW(qx) * phi_v.JxW(qv)[n_vectors_v == 1 ? 0 : this->lane_y];
337 const auto jacobian = phi_v.inverse_jacobian(qv);
338
339 for (auto d = 0u; d < dim_v; d++)
340 {
341 auto new_val =
342 jacobian[0][d][n_vectors_v == 1 ? 0 : this->lane_y] * grad_in[0];
343 for (auto e = 1u; e < dim_v; ++e)
344 new_val += (jacobian[e][d][n_vectors_v == 1 ? 0 : this->lane_y] *
345 grad_in[e]);
346 data_ptr_out[q + d * n_q_points_x * n_q_points_v] = new_val * jxw;
347 }
348 }
349
350
351
357 inline dealii::Point<dim, VectorizedArrayType>
358 get_quadrature_point(const unsigned int q) const
359 {
360 dealii::Point<dim, VectorizedArrayType> temp;
361
362 auto t1 = this->phi_x.quadrature_point(q % n_q_points_x);
363 for (int i = 0; i < dim_x; i++)
364 temp[i] = t1[i];
365 auto t2 = this->phi_v.quadrature_point(q / n_q_points_x);
366 for (int i = 0; i < dim_v; i++)
367 temp[i + dim_x] = t2[i][n_vectors_v == 1 ? 0 : this->lane_y];
368
369 return temp;
370 }
371
372 inline dealii::Point<dim, VectorizedArrayType>
373 get_quadrature_point(const unsigned int qx, const unsigned int qv) const
374 {
375 dealii::Point<dim, VectorizedArrayType> temp;
376
377 auto t1 = this->phi_x.quadrature_point(qx);
378 for (int i = 0; i < dim_x; i++)
379 temp[i] = t1[i];
380 auto t2 = this->phi_v.quadrature_point(qv);
381 for (int i = 0; i < dim_v; i++)
382 temp[i + dim_x] = t2[i][n_vectors_v == 1 ? 0 : this->lane_y];
383
384 return temp;
385 }
386
387 inline dealii::Point<dim_v, VectorizedArrayType>
388 get_quadrature_point_v(const unsigned int qv) const
389 {
390 dealii::Point<dim_v, VectorizedArrayType> temp;
391
392 auto t2 = this->phi_v.quadrature_point(qv);
393 for (int i = 0; i < dim_v; i++)
394 temp[i] = t2[i][n_vectors_v == 1 ? 0 : this->lane_y];
395
396 return temp;
397 }
398
399 protected:
400 // clang-format off
401 dealii::FEEvaluation<dim_x, degree, n_points, 1, Number, typename PARENT::VectorizedArrayTypeX> phi_x;
402 dealii::FEEvaluation<dim_v, degree, n_points, 1, Number, typename PARENT::VectorizedArrayTypeV> phi_v;
403 // clang-format on
404 };
405
406} // namespace hyperdeal
407
408#endif
Definition fe_evaluation_base.h:35
virtual void reinit(typename MatrixFree< dim_x, dim_v, Number, VectorizedArrayType >::ID cell_index)
Definition fe_evaluation_base.h:168
const dealii::AlignedVector< Number > * shape_values
Definition fe_evaluation_base.h:122
dealii::AlignedVector< VectorizedArrayType > data
Definition fe_evaluation_base.h:93
const MF & matrix_free
Definition fe_evaluation_base.h:98
const dealii::MatrixFree< dim_v, Number, VectorizedArrayTypeV > & matrix_free_v
Definition fe_evaluation_base.h:110
const dealii::MatrixFree< dim_x, Number, VectorizedArrayTypeX > & matrix_free_x
Definition fe_evaluation_base.h:104
const dealii::AlignedVector< Number > * shape_gradients
Definition fe_evaluation_base.h:127
Definition fe_evaluation_cell.h:47
DEAL_II_ALWAYS_INLINE dealii::Tensor< 1, dim_x, VectorizedArrayType > get_gradient_x(const VectorizedArrayType *__restrict grad_in, const unsigned int q, const unsigned int qx, const unsigned int qv) const
Definition fe_evaluation_cell.h:221
void reinit(typename MatrixFree< dim_x, dim_v, Number, VectorizedArrayType >::ID cell_index) override
Definition fe_evaluation_cell.h:103
unsigned int n_vectorization_lanes_filled() const
Definition fe_evaluation_cell.h:171
DEAL_II_ALWAYS_INLINE void submit_value(VectorizedArrayType *__restrict data_ptr_out, const VectorizedArrayType values_in, const unsigned int q, const unsigned int qx, const unsigned int qv) const
Definition fe_evaluation_cell.h:281
dealii::Point< dim, VectorizedArrayType > get_quadrature_point(const unsigned int q) const
Definition fe_evaluation_cell.h:358
void read_dof_values(const dealii::LinearAlgebra::distributed::Vector< Number > &src)
Definition fe_evaluation_cell.h:138
DEAL_II_ALWAYS_INLINE void submit_gradient_x(VectorizedArrayType *__restrict data_ptr_out, const VectorizedArrayType *__restrict grad_in, const unsigned int q, const unsigned int qx, const unsigned int qv) const
Definition fe_evaluation_cell.h:303
void read_dof_values(const dealii::LinearAlgebra::distributed::Vector< Number > &src, VectorizedArrayType *data) const
Definition fe_evaluation_cell.h:116
DEAL_II_ALWAYS_INLINE dealii::Tensor< 1, dim_v, VectorizedArrayType > get_gradient_v(const VectorizedArrayType *__restrict grad_in, const unsigned int q, const unsigned int qx, const unsigned int qv) const
Definition fe_evaluation_cell.h:250
DEAL_II_ALWAYS_INLINE void submit_gradient_v(VectorizedArrayType *__restrict data_ptr_out, const VectorizedArrayType *__restrict grad_in, const unsigned int q, const unsigned int qx, const unsigned int qv) const
Definition fe_evaluation_cell.h:329
VectorizedArrayType submit_inplace(const VectorizedArrayType data, const unsigned int q) const
Definition fe_evaluation_cell.h:184
VectorizedArrayType submit_inplace(const VectorizedArrayType data, unsigned int, unsigned int qx, unsigned int qv) const
Definition fe_evaluation_cell.h:197
void set_dof_values(dealii::LinearAlgebra::distributed::Vector< Number > &dst) const
Definition fe_evaluation_cell.h:150
FEEvaluation(const MatrixFree< dim_x, dim_v, Number, VectorizedArrayType > &matrix_free, const unsigned int dof_no_x, const unsigned int dof_no_v, const unsigned int quad_no_x, const unsigned int quad_no_v)
Definition fe_evaluation_cell.h:83
Definition matrix_free.h:40
const internal::MatrixFreeFunctions::DoFInfo & get_dof_info() const
Definition matrix_free.templates.h:1872
Definition id.h:27
Definition vector_access_internal.h:29
Definition vector_access_internal.h:74