52 template <
int dim,
typename CoefficientType>
57 for (
unsigned int d = 0;
d < dim; ++
d)
84 std::pair<bool, unsigned int>
88 for (
unsigned int i = 0; i < dim; ++i)
91 return std::make_pair((v < N), v);
97 template <
int dim,
int spacedim,
typename VectorType>
101 const VectorType &solution,
104 const double smallest_abs_coefficient,
105 const bool only_flagged_cells)
107 using number =
typename VectorType::value_type;
111 smoothness_indicators.
reinit(
114 unsigned int n_modes;
118 std::vector<double> converted_indices;
119 std::pair<std::vector<unsigned int>, std::vector<double>> res;
123 if (!only_flagged_cells || cell->refine_flag_set() ||
124 cell->coarsen_flag_set())
127 cell->active_fe_index());
128 resize(expansion_coefficients, n_modes);
130 local_dof_values.
reinit(cell->get_fe().n_dofs_per_cell());
131 cell->get_dof_values(solution, local_dof_values);
134 cell->active_fe_index(),
135 expansion_coefficients);
141 res = FESeries::process_coefficients<dim>(
142 expansion_coefficients,
144 return index_sum_less_than_N(indices, n_modes);
147 smallest_abs_coefficient);
152 float regularity = std::numeric_limits<float>::infinity();
153 if (res.first.size() > 1)
157 converted_indices.assign(res.first.begin(), res.first.end());
159 for (
auto &residual_element : res.second)
160 residual_element =
std::log(residual_element);
162 const std::pair<double, double> fit =
164 regularity =
static_cast<float>(-fit.first);
167 smoothness_indicators(cell->active_cell_index()) = regularity;
170 smoothness_indicators(cell->active_cell_index()) =
171 numbers::signaling_nan<float>();
177 template <
int dim,
int spacedim,
typename VectorType>
182 const VectorType &solution,
185 const double smallest_abs_coefficient,
186 const bool only_flagged_cells)
188 Assert(smallest_abs_coefficient >= 0.,
189 ExcMessage(
"smallest_abs_coefficient should be non-negative."));
191 using number =
typename VectorType::value_type;
195 smoothness_indicators.
reinit(
198 unsigned int n_modes;
203 const unsigned int max_degree =
206 std::vector<double> x, y;
207 x.reserve(max_degree);
208 y.reserve(max_degree);
213 if (!only_flagged_cells || cell->refine_flag_set() ||
214 cell->coarsen_flag_set())
217 cell->active_fe_index());
218 resize(expansion_coefficients, n_modes);
220 const unsigned int pe = cell->get_fe().degree;
228 local_dof_values.
reinit(cell->get_fe().n_dofs_per_cell());
229 cell->get_dof_values(solution, local_dof_values);
232 cell->active_fe_index(),
233 expansion_coefficients);
237 double k_v = std::numeric_limits<double>::max();
238 for (
unsigned int d = 0; d < dim; ++d)
245 for (
unsigned int i = 0; i <= pe; ++i)
246 if (coefficients_predicate[i])
250 const double coeff_abs =
251 std::abs(expansion_coefficients(ind));
253 if (coeff_abs > smallest_abs_coefficient)
265 const std::pair<double, double> fit =
273 smoothness_indicators(cell->active_cell_index()) =
274 static_cast<float>(k_v);
277 smoothness_indicators(cell->active_cell_index()) =
278 numbers::signaling_nan<float>();
284 template <
int dim,
int spacedim>
287 const unsigned int component)
294 std::vector<unsigned int> n_coefficients_per_direction;
295 n_coefficients_per_direction.reserve(fe_collection.
size());
296 for (
unsigned int i = 0; i < fe_collection.
size(); ++i)
297 n_coefficients_per_direction.push_back(fe_collection[i].degree + 2);
315 for (
unsigned int i = 0; i < fe_collection.
size(); ++i)
317 const QGauss<dim> quadrature(n_coefficients_per_direction[i]);
319 q_collection.
push_back(quadrature_sorted);
350 std::pair<bool, unsigned int>
351 index_norm_greater_than_zero_and_less_than_N_squared(
353 const unsigned int N)
356 for (
unsigned int i = 0; i < dim; ++i)
357 v += ind[i] * ind[i];
359 return std::make_pair((v > 0 && v < N * N), v);
365 template <
int dim,
int spacedim,
typename VectorType>
369 const VectorType &solution,
372 const double smallest_abs_coefficient,
373 const bool only_flagged_cells)
375 using number =
typename VectorType::value_type;
379 smoothness_indicators.
reinit(
382 unsigned int n_modes;
386 std::vector<double> ln_k;
387 std::pair<std::vector<unsigned int>, std::vector<double>> res;
391 if (!only_flagged_cells || cell->refine_flag_set() ||
392 cell->coarsen_flag_set())
395 cell->active_fe_index());
396 resize(expansion_coefficients, n_modes);
402 local_dof_values.
reinit(cell->get_fe().n_dofs_per_cell());
403 cell->get_dof_values(solution, local_dof_values);
406 cell->active_fe_index(),
407 expansion_coefficients);
413 res = FESeries::process_coefficients<dim>(
414 expansion_coefficients,
416 return index_norm_greater_than_zero_and_less_than_N_squared(
420 smallest_abs_coefficient);
425 float regularity = std::numeric_limits<float>::infinity();
426 if (res.first.size() > 1)
437 ln_k.resize(res.first.size());
438 for (
unsigned int f = 0; f < res.first.size(); ++f)
439 ln_k[f] = 0.5 *
std::log(
static_cast<double>(res.first[f]));
442 for (
auto &residual_element : res.second)
443 residual_element =
std::log(residual_element);
445 const std::pair<double, double> fit =
448 regularity =
static_cast<float>(-fit.first) -
449 ((dim > 1) ? (.5 * dim) : 0);
453 smoothness_indicators(cell->active_cell_index()) = regularity;
456 smoothness_indicators(cell->active_cell_index()) =
457 numbers::signaling_nan<float>();
463 template <
int dim,
int spacedim,
typename VectorType>
468 const VectorType &solution,
471 const double smallest_abs_coefficient,
472 const bool only_flagged_cells)
474 Assert(smallest_abs_coefficient >= 0.,
475 ExcMessage(
"smallest_abs_coefficient should be non-negative."));
477 using number =
typename VectorType::value_type;
481 smoothness_indicators.
reinit(
484 unsigned int n_modes;
489 const unsigned int max_degree =
492 std::vector<double> x, y;
493 x.reserve(max_degree);
494 y.reserve(max_degree);
499 if (!only_flagged_cells || cell->refine_flag_set() ||
500 cell->coarsen_flag_set())
503 cell->active_fe_index());
504 resize(expansion_coefficients, n_modes);
506 const unsigned int pe = cell->get_fe().degree;
514 local_dof_values.
reinit(cell->get_fe().n_dofs_per_cell());
515 cell->get_dof_values(solution, local_dof_values);
518 cell->active_fe_index(),
519 expansion_coefficients);
523 double k_v = std::numeric_limits<double>::max();
524 for (
unsigned int d = 0; d < dim; ++d)
533 for (
unsigned int i = 1; i <= pe; ++i)
534 if (coefficients_predicate[i])
538 const double coeff_abs =
539 std::abs(expansion_coefficients(ind));
541 if (coeff_abs > smallest_abs_coefficient)
553 const std::pair<double, double> fit =
561 smoothness_indicators(cell->active_cell_index()) =
562 static_cast<float>(k_v);
565 smoothness_indicators(cell->active_cell_index()) =
566 numbers::signaling_nan<float>();
572 template <
int dim,
int spacedim>
575 const unsigned int component)
584 std::vector<unsigned int> n_coefficients_per_direction;
585 n_coefficients_per_direction.reserve(fe_collection.
size());
586 for (
unsigned int i = 0; i < fe_collection.
size(); ++i)
587 n_coefficients_per_direction.push_back(fe_collection[i].degree + 2);
605 for (
unsigned int i = 0; i < fe_collection.
size(); ++i)
608 n_coefficients_per_direction[i] - 1);
610 q_collection.
push_back(quadrature_sorted);
623#include "numerics/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)
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_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={}, const double smallest_abs_coefficient=1e-10, const bool only_flagged_cells=false)
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)
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)
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={}, 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 > &)