1#include <deal.II/base/exceptions.h>
2#include <deal.II/base/tensor.h>
3#include <deal.II/base/vectorization.h>
5#include <deal.II/fe/fe_dgq.h>
14 template <
int dim,
typename number,
template <
typename>
class BinaryOp>
20 indicators_and_weights.emplace_back(std::move(indicator), weight);
23 template <
int dim,
typename number,
template <
typename>
class BinaryOp>
26 const dealii::Triangulation<dim> &tria) ->
VectorType
28 AssertThrow(not indicators_and_weights.empty(),
29 dealii::ExcMessage(
"No AMR indicator has been added to the indicator composite."));
31 auto check_partitioning = [&tria](
const VectorType &indicator) {
33 tria.n_active_cells() == indicator.size(),
35 "The indicator has returned a vector which does not has the same number of elements as the triangulation has local active cells."));
38 VectorType indicator = indicators_and_weights[0].indicator->compute_indicator(tria);
39 indicator *= indicators_and_weights[0].weight;
41 check_partitioning(indicator);
42 for (
unsigned i = 1; i < this->indicators_and_weights.size(); ++i)
44 VectorType temp_indicator = indicators_and_weights[i].indicator->compute_indicator(tria);
45 check_partitioning(temp_indicator);
46 for (
unsigned j = 0; j < indicator.size(); ++j)
48 BinaryOp<number>()(indicator[j], indicators_and_weights[i].weight * temp_indicator[j]);
54 template <
int dim,
typename number,
template <
typename>
class BinaryOp>
58 return indicators_and_weights.empty();
61 template <
int dim,
typename number,
int n_dof_components,
int n_indicator_components>
66 const unsigned fe_index,
67 const unsigned fe_degree)
68 : matrix_free_context(matrix_free_context)
70 , extract_indicator_dof_values(extract_indicator_dof_values)
73 AssertThrow(fe_degree > 1,
74 dealii::ExcMessage(
"The SSED indicator requires an fe degree greater than one."));
76 dealii::FullMatrix<number> transformation_matrix(fe_degree + 1);
77 dealii::FETools::get_projection_matrix(dealii::FE_DGQ<1>(fe_degree),
78 dealii::FE_DGQLegendre<1>(fe_degree),
79 transformation_matrix);
81 for (
unsigned i = 0; i < fe_degree + 1; ++i)
82 for (
unsigned j = 0; j < fe_degree + 1; ++j)
86 template <
int dim,
typename number,
int n_dof_components,
int n_indicator_components>
87 dealii::Vector<number>
89 const dealii::Triangulation<dim> &tria)
91 const unsigned fe_degree =
92 matrix_free_context.mf.get_dof_handler(matrix_free_context.dof_idx).get_fe(fe_index).degree;
94 dealii::AlignedVector<VectorizedArrayType> indicator;
95 matrix_free_context.mf.initialize_cell_data_vector(indicator);
99 std::function<void(
const dealii::MatrixFree<dim, number> &mf,
100 dealii::AlignedVector<VectorizedArrayType> &indicator,
102 const std::pair<unsigned, unsigned> &cell_range)>
103 cell_op = [&](
const dealii::MatrixFree<dim, number> &mf,
104 dealii::AlignedVector<VectorizedArrayType> &indicator,
106 const std::pair<unsigned, unsigned> &cell_range) {
107 local_apply_cell(mf, indicator, solution, cell_range);
110 matrix_free_context.mf.cell_loop(cell_op, indicator, solution);
113 return VectorTools::convert_matrix_free_cell_aligned_vector_to_vector<dim, number, dim + 2>(
114 matrix_free_context, indicator, tria);
117 template <
int dim,
typename number,
int n_dof_components,
int n_indicator_components>
120 const dealii::MatrixFree<dim, number> &,
121 dealii::AlignedVector<VectorizedArrayType> &dst,
123 const std::pair<unsigned, unsigned> &cell_range)
126 matrix_free_context.dof_idx,
127 matrix_free_context.quad_idx);
129 matrix_free_context.dof_idx,
130 matrix_free_context.quad_idx);
132 for (
unsigned int cell = cell_range.first; cell < cell_range.second; ++cell)
135 phi_dgq.reinit(cell);
136 phi_leg.reinit(cell);
138 phi_dgq.read_dof_values(src);
141 const unsigned fe_degree =
142 matrix_free_context.mf.get_dof_handler(matrix_free_context.dof_idx)
143 .get_fe(phi_dgq.get_active_fe_index())
146 dealii::internal::FEEvaluationImplBasisChange<dealii::internal::evaluate_general,
147 dealii::internal::EvaluatorQuantity::value,
154 phi_dgq.begin_dof_values(),
155 phi_leg.begin_dof_values(),
160 for (
unsigned i = 0; i < std::pow(fe_degree, dim); ++i)
161 phi_leg.submit_dof_value(dealii::Tensor<1, n_dof_components, VectorizedArrayType>(), i);
163 phi_leg.evaluate(dealii::EvaluationFlags::values);
166 for (
const unsigned int q : phi_dgq.quadrature_point_indices())
168 const dealii::Tensor<1, n_indicator_components, VectorizedArrayType> u_q =
170 ssed_error += phi_dgq.JxW(q) * u_q * u_q;
171 cell_volume += phi_dgq.JxW(q);
174 ssed_error /= cell_volume;
175 phi_dgq.set_cell_data(dst, std::sqrt(ssed_error));
179 template <
int dim,
typename number,
int n_dof_components,
int n_indicator_components>
184 const unsigned fe_index)
185 : matrix_free_context(matrix_free_context)
187 , extract_indicator_dof_values(extract_indicator_dof_values)
191 for (
unsigned int sub_fe_idx = 0;
196 AssertThrow(
dynamic_cast<const dealii::FE_DGQ<dim> *
>(
199 .get_sub_fe(sub_fe_idx, 1)),
200 dealii::ExcMessage(
"The jump indicator only works with DG elements."));
203 template <
int dim,
typename number,
int n_dof_components,
int n_indicator_components>
204 dealii::Vector<number>
206 const dealii::Triangulation<dim> &tria)
208 using LocalOpType = std::function<void(
const dealii::MatrixFree<dim, number> &mf,
209 dealii::AlignedVector<VectorizedArrayType> &indicator,
211 const std::pair<unsigned, unsigned> &cell_range)>;
213 dealii::AlignedVector<VectorizedArrayType> indicator;
214 matrix_free_context.
mf.initialize_cell_data_vector(indicator);
216 LocalOpType cell_op = [](
const dealii::MatrixFree<dim, number> &,
217 dealii::AlignedVector<VectorizedArrayType> &,
219 const std::pair<unsigned, unsigned> &) {};
221 LocalOpType face_op = std::bind_front(
225 LocalOpType boundary_face_op = [](
const dealii::MatrixFree<dim, number> &,
226 dealii::AlignedVector<VectorizedArrayType> &,
228 const std::pair<unsigned, unsigned> &) {};
230 matrix_free_context.mf.loop(cell_op, face_op, boundary_face_op, indicator, solution);
233 convert_matrix_free_cell_aligned_vector_to_vector<dim, number, n_dof_components>(
234 matrix_free_context, indicator, tria);
237 template <
int dim,
typename number,
int n_dof_components,
int n_indicator_components>
240 const dealii::MatrixFree<dim, number> &,
241 dealii::AlignedVector<VectorizedArrayType> &dst,
243 const std::pair<unsigned, unsigned> &face_range)
const
247 matrix_free_context.dof_idx,
248 matrix_free_context.quad_idx);
251 matrix_free_context.dof_idx,
252 matrix_free_context.quad_idx);
254 for (
unsigned face = face_range.first; face < face_range.second; ++face)
257 phi_p.gather_evaluate(src, dealii::EvaluationFlags::values);
259 phi_m.gather_evaluate(src, dealii::EvaluationFlags::values);
263 for (
const unsigned q : phi_m.quadrature_point_indices())
270 face_jump_error += phi_m.JxW(q) * (w_m - w_p) * (w_m - w_p);
272 face_area += phi_m.JxW(q);
274 constexpr int n_faces = 2 * dim;
276 current_cell_error += 0.25 / n_faces * std::sqrt(face_jump_error / face_area);
277 phi_m.set_cell_data(dst, current_cell_error);
Definition amr_indicators.hpp:30
VectorType compute_indicator(const dealii::Triangulation< dim > &tria) override
Definition amr_indicators.templates.hpp:25
bool empty() const
Definition amr_indicators.templates.hpp:56
dealii::Vector< number > VectorType
Definition amr_indicators.hpp:54
void add_indicator(std::unique_ptr< AMRIndicatorBase< dim, number > > &&indicator, number weight=1.)
Definition amr_indicators.templates.hpp:16
Definition amr_indicators.hpp:214
dealii::Vector< number > compute_indicator(const dealii::Triangulation< dim > &tria) override
Definition amr_indicators.templates.hpp:205
const MatrixFreeContext< dim, number > matrix_free_context
Matrix free object used to compute the solution.
Definition amr_indicators.hpp:266
dealii::LinearAlgebra::distributed::Vector< number > VectorType
Definition amr_indicators.hpp:218
void local_apply_face(const dealii::MatrixFree< dim, number > &, dealii::AlignedVector< VectorizedArrayType > &dst, const VectorType &src, const std::pair< unsigned, unsigned > &face_range) const
Definition amr_indicators.templates.hpp:239
const unsigned fe_index
Relevant fe index for the fe object of the dof handler in the matrix free object.
Definition amr_indicators.hpp:276
dealii::VectorizedArray< number > VectorizedArrayType
Definition amr_indicators.hpp:216
JumpIndicator(const MatrixFreeContext< dim, number > matrix_free_context, const VectorType &solution, const ExtractIndicatorDofValuesFunction extract_indicator_dof_values, const unsigned fe_index=0)
Definition amr_indicators.templates.hpp:180
std::function< dealii::Tensor< 1, n_relevant_components, VectorizedArrayType >(const dealii::Tensor< 1, n_mf_components, VectorizedArrayType > &)> ExtractIndicatorDofValuesFunction
Definition amr_indicators.hpp:221
dealii::Vector< number > compute_indicator(const dealii::Triangulation< dim > &tria) override
Definition amr_indicators.templates.hpp:88
SSEDIndicator(const MatrixFreeContext< dim, number > matrix_free_context, const VectorType &solution, const ExtractIndicatorDofValuesFunction extract_indicator_dof_values, const unsigned fe_index, const unsigned fe_degree)
Definition amr_indicators.templates.hpp:62
dealii::VectorizedArray< number > VectorizedArrayType
Definition amr_indicators.hpp:120
dealii::LinearAlgebra::distributed::Vector< number > VectorType
Definition amr_indicators.hpp:122
void local_apply_cell(const dealii::MatrixFree< dim, number > &, dealii::AlignedVector< VectorizedArrayType > &dst, const VectorType &src, const std::pair< unsigned, unsigned > &cell_range)
Definition amr_indicators.templates.hpp:119
std::function< dealii::Tensor< 1, n_indicator_components, VectorizedArrayType >(const dealii::Tensor< 1, n_dof_components, VectorizedArrayType > &)> ExtractIndicatorDofValuesFunction
Definition amr_indicators.hpp:126
dealii::AlignedVector< VectorizedArrayType > linearized_matrix
Definition amr_indicators.hpp:188
Interface for a general preconditioner.
Definition boundary_condition_functions.hpp:17
dealii::Tensor< 1, FeEval::n_components, dealii::VectorizedArray< typename FeEval::number_type > > fe_evaluation_tensor_value_at_q(const FeEval &fe_eval, const unsigned q_index)
Definition matrix_free_util.hpp:45
dealii::FEFaceEvaluation< dim, -1, 0, n_components, number, VectorizedArrayType > FEFaceIntegrator
Definition fe_integrator.hpp:22
dealii::FEEvaluation< dim, -1, 0, n_components, number, VectorizedArrayType > FECellIntegrator
Definition fe_integrator.hpp:14
Definition matrix_free_util.hpp:21
const dealii::MatrixFree< dim, Number > & mf
Definition matrix_free_util.hpp:22
unsigned int dof_idx
Definition matrix_free_util.hpp:23