56 template <
int dim,
typename CoefficientType>
61 for (
unsigned int d = 0;
d < dim; ++
d)
88 std::pair<bool, unsigned int>
92 for (
unsigned int i = 0; i < dim; ++i)
95 return std::make_pair((v < N), v);
101 template <
int dim,
int spacedim,
typename VectorType>
105 const VectorType & solution,
108 const double smallest_abs_coefficient,
109 const bool only_flagged_cells)
111 using number =
typename VectorType::value_type;
115 smoothness_indicators.
reinit(
118 unsigned int n_modes;
122 std::vector<double> converted_indices;
123 std::pair<std::vector<unsigned int>, std::vector<double>> res;
127 if (!only_flagged_cells || cell->refine_flag_set() ||
128 cell->coarsen_flag_set())
131 cell->active_fe_index());
132 resize(expansion_coefficients, n_modes);
134 local_dof_values.
reinit(cell->get_fe().n_dofs_per_cell());
135 cell->get_dof_values(solution, local_dof_values);
138 cell->active_fe_index(),
139 expansion_coefficients);
145 res = FESeries::process_coefficients<dim>(
146 expansion_coefficients,
148 return index_sum_less_than_N(indices, n_modes);
151 smallest_abs_coefficient);
156 float regularity = std::numeric_limits<float>::infinity();
157 if (res.first.size() > 1)
161 converted_indices.assign(res.first.begin(), res.first.end());
163 for (
auto &residual_element : res.second)
164 residual_element =
std::log(residual_element);
166 const std::pair<double, double> fit =
168 regularity =
static_cast<float>(-fit.first);
171 smoothness_indicators(cell->active_cell_index()) = regularity;
174 smoothness_indicators(cell->active_cell_index()) =
175 numbers::signaling_nan<float>();
181 template <
int dim,
int spacedim,
typename VectorType>
186 const VectorType & solution,
189 const double smallest_abs_coefficient,
190 const bool only_flagged_cells)
192 Assert(smallest_abs_coefficient >= 0.,
193 ExcMessage(
"smallest_abs_coefficient should be non-negative."));
195 using number =
typename VectorType::value_type;
199 smoothness_indicators.
reinit(
202 unsigned int n_modes;
207 const unsigned int max_degree =
210 std::vector<double> x, y;
211 x.reserve(max_degree);
212 y.reserve(max_degree);
217 if (!only_flagged_cells || cell->refine_flag_set() ||
218 cell->coarsen_flag_set())
221 cell->active_fe_index());
222 resize(expansion_coefficients, n_modes);
224 const unsigned int pe = cell->get_fe().degree;
232 local_dof_values.
reinit(cell->get_fe().n_dofs_per_cell());
233 cell->get_dof_values(solution, local_dof_values);
236 cell->active_fe_index(),
237 expansion_coefficients);
241 double k_v = std::numeric_limits<double>::infinity();
242 for (
unsigned int d = 0; d < dim; ++d)
249 for (
unsigned int i = 0; i <= pe; ++i)
250 if (coefficients_predicate[i])
254 const double coeff_abs =
255 std::abs(expansion_coefficients(ind));
257 if (coeff_abs > smallest_abs_coefficient)
269 const std::pair<double, double> fit =
277 smoothness_indicators(cell->active_cell_index()) =
278 static_cast<float>(k_v);
281 smoothness_indicators(cell->active_cell_index()) =
282 numbers::signaling_nan<float>();
288 template <
int dim,
int spacedim>
291 const unsigned int component)
298 std::vector<unsigned int> n_coefficients_per_direction;
299 for (
unsigned int i = 0; i < fe_collection.
size(); ++i)
300 n_coefficients_per_direction.push_back(fe_collection[i].degree + 2);
318 for (
unsigned int i = 0; i < fe_collection.
size(); ++i)
320 const QGauss<dim> quadrature(n_coefficients_per_direction[i]);
322 q_collection.
push_back(quadrature_sorted);
353 std::pair<bool, unsigned int>
354 index_norm_greater_than_zero_and_less_than_N_squared(
356 const unsigned int N)
359 for (
unsigned int i = 0; i < dim; ++i)
360 v += ind[i] * ind[i];
362 return std::make_pair((v > 0 && v < N * N), v);
368 template <
int dim,
int spacedim,
typename VectorType>
372 const VectorType & solution,
375 const double smallest_abs_coefficient,
376 const bool only_flagged_cells)
378 using number =
typename VectorType::value_type;
382 smoothness_indicators.
reinit(
385 unsigned int n_modes;
389 std::vector<double> ln_k;
390 std::pair<std::vector<unsigned int>, std::vector<double>> res;
394 if (!only_flagged_cells || cell->refine_flag_set() ||
395 cell->coarsen_flag_set())
398 cell->active_fe_index());
399 resize(expansion_coefficients, n_modes);
405 local_dof_values.
reinit(cell->get_fe().n_dofs_per_cell());
406 cell->get_dof_values(solution, local_dof_values);
409 cell->active_fe_index(),
410 expansion_coefficients);
416 res = FESeries::process_coefficients<dim>(
417 expansion_coefficients,
419 return index_norm_greater_than_zero_and_less_than_N_squared(
423 smallest_abs_coefficient);
428 float regularity = std::numeric_limits<float>::infinity();
429 if (res.first.size() > 1)
440 ln_k.resize(res.first.size());
441 for (
unsigned int f = 0; f < res.first.size(); ++f)
442 ln_k[f] = 0.5 *
std::log(
static_cast<double>(res.first[f]));
445 for (
auto &residual_element : res.second)
446 residual_element =
std::log(residual_element);
448 const std::pair<double, double> fit =
451 regularity =
static_cast<float>(-fit.first) -
452 ((dim > 1) ? (.5 * dim) : 0);
456 smoothness_indicators(cell->active_cell_index()) = regularity;
459 smoothness_indicators(cell->active_cell_index()) =
460 numbers::signaling_nan<float>();
466 template <
int dim,
int spacedim,
typename VectorType>
471 const VectorType & solution,
474 const double smallest_abs_coefficient,
475 const bool only_flagged_cells)
477 Assert(smallest_abs_coefficient >= 0.,
478 ExcMessage(
"smallest_abs_coefficient should be non-negative."));
480 using number =
typename VectorType::value_type;
484 smoothness_indicators.
reinit(
487 unsigned int n_modes;
492 const unsigned int max_degree =
495 std::vector<double> x, y;
496 x.reserve(max_degree);
497 y.reserve(max_degree);
502 if (!only_flagged_cells || cell->refine_flag_set() ||
503 cell->coarsen_flag_set())
506 cell->active_fe_index());
507 resize(expansion_coefficients, n_modes);
509 const unsigned int pe = cell->get_fe().degree;
517 local_dof_values.
reinit(cell->get_fe().n_dofs_per_cell());
518 cell->get_dof_values(solution, local_dof_values);
521 cell->active_fe_index(),
522 expansion_coefficients);
526 double k_v = std::numeric_limits<double>::infinity();
527 for (
unsigned int d = 0; d < dim; ++d)
536 for (
unsigned int i = 1; i <= pe; ++i)
537 if (coefficients_predicate[i])
541 const double coeff_abs =
542 std::abs(expansion_coefficients(ind));
544 if (coeff_abs > smallest_abs_coefficient)
556 const std::pair<double, double> fit =
564 smoothness_indicators(cell->active_cell_index()) =
565 static_cast<float>(k_v);
568 smoothness_indicators(cell->active_cell_index()) =
569 numbers::signaling_nan<float>();
575 template <
int dim,
int spacedim>
578 const unsigned int component)
587 std::vector<unsigned int> n_coefficients_per_direction;
588 for (
unsigned int i = 0; i < fe_collection.
size(); ++i)
589 n_coefficients_per_direction.push_back(fe_collection[i].degree + 2);
607 for (
unsigned int i = 0; i < fe_collection.
size(); ++i)
610 n_coefficients_per_direction[i] - 1);
612 q_collection.
push_back(quadrature_sorted);
625#include "smoothness_estimator.inst"
const hp::FECollection< dim, spacedim > & get_fe_collection() const
const Triangulation< dim, spacedim > & get_triangulation() const
void calculate(const ::Vector< Number > &local_dof_values, const unsigned int cell_active_fe_index, Table< dim, CoefficientType > &fourier_coefficients)
typename std::complex< double > CoefficientType
unsigned int get_n_coefficients_per_direction(const unsigned int index) const
unsigned int get_n_coefficients_per_direction(const unsigned int index) const
void calculate(const ::Vector< Number > &local_dof_values, const unsigned int cell_active_fe_index, Table< dim, CoefficientType > &legendre_coefficients)
unsigned int n_active_cells() const
virtual void reinit(const size_type N, const bool omit_zeroing_entries=false)
unsigned int size() const
unsigned int max_degree() const
void push_back(const Quadrature< dim_in > &new_quadrature)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
IteratorRange< active_cell_iterator > active_cell_iterators() const
#define Assert(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
std::pair< double, double > linear_regression(const std::vector< double > &x, const std::vector< double > &y)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
void coefficient_decay_per_direction(FESeries::Fourier< dim, spacedim > &fe_fourier, const DoFHandler< dim, spacedim > &dof_handler, const VectorType &solution, Vector< float > &smoothness_indicators, const ComponentMask &coefficients_predicate=ComponentMask(), const double smallest_abs_coefficient=1e-10, const bool only_flagged_cells=false)
FESeries::Fourier< dim, spacedim > default_fe_series(const hp::FECollection< dim, spacedim > &fe_collection, const unsigned int component=numbers::invalid_unsigned_int)
void coefficient_decay(FESeries::Fourier< dim, spacedim > &fe_fourier, const DoFHandler< dim, spacedim > &dof_handler, const VectorType &solution, Vector< float > &smoothness_indicators, const VectorTools::NormType regression_strategy=VectorTools::Linfty_norm, const double smallest_abs_coefficient=1e-10, const bool only_flagged_cells=false)
void coefficient_decay_per_direction(FESeries::Legendre< dim, spacedim > &fe_legendre, const DoFHandler< dim, spacedim > &dof_handler, const VectorType &solution, Vector< float > &smoothness_indicators, const ComponentMask &coefficients_predicate=ComponentMask(), const double smallest_abs_coefficient=1e-10, const bool only_flagged_cells=false)
FESeries::Legendre< dim, spacedim > default_fe_series(const hp::FECollection< dim, spacedim > &fe_collection, const unsigned int component=numbers::invalid_unsigned_int)
void coefficient_decay(FESeries::Legendre< dim, spacedim > &fe_legendre, const DoFHandler< dim, spacedim > &dof_handler, const VectorType &solution, Vector< float > &smoothness_indicators, const VectorTools::NormType regression_strategy=VectorTools::Linfty_norm, const double smallest_abs_coefficient=1e-10, const bool only_flagged_cells=false)
::VectorizedArray< Number, width > log(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)