53 template <
int dim,
typename CoefficientType>
58 for (
unsigned int d = 0;
d < dim;
d++)
85 std::pair<bool, unsigned int>
89 for (
unsigned int i = 0; i < dim; ++i)
92 return std::make_pair((v <
N), v);
98 template <
int dim,
int spacedim,
typename VectorType>
102 const VectorType & solution,
105 const double smallest_abs_coefficient,
106 const bool only_flagged_cells)
108 using number =
typename VectorType::value_type;
112 smoothness_indicators.
reinit(
115 unsigned int n_modes;
119 std::vector<double> converted_indices;
120 std::pair<std::vector<unsigned int>, std::vector<double>> res;
122 if (cell->is_locally_owned())
124 if (!only_flagged_cells || cell->refine_flag_set() ||
125 cell->coarsen_flag_set())
128 cell->active_fe_index());
129 resize(expansion_coefficients, n_modes);
131 local_dof_values.
reinit(cell->get_fe().n_dofs_per_cell());
132 cell->get_dof_values(solution, local_dof_values);
135 cell->active_fe_index(),
136 expansion_coefficients);
142 res = FESeries::process_coefficients<dim>(
143 expansion_coefficients,
145 return index_sum_less_than_N(indices, n_modes);
148 smallest_abs_coefficient);
150 Assert(res.first.size() == res.second.size(),
154 float regularity = std::numeric_limits<float>::infinity();
155 if (res.first.size() > 1)
159 converted_indices.assign(res.first.begin(),
162 for (
auto &residual_element : res.second)
163 residual_element =
std::log(residual_element);
165 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);
215 if (cell->is_locally_owned())
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;
392 if (cell->is_locally_owned())
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);
425 Assert(res.first.size() == res.second.size(),
429 float regularity = std::numeric_limits<float>::infinity();
430 if (res.first.size() > 1)
441 ln_k.resize(res.first.size());
442 for (
unsigned int f = 0; f < res.first.size(); ++f)
444 0.5 *
std::log(
static_cast<double>(res.first[f]));
447 for (
auto &residual_element : res.second)
448 residual_element =
std::log(residual_element);
450 const std::pair<double, double> fit =
453 regularity =
static_cast<float>(-fit.first) -
454 ((dim > 1) ? (.5 * dim) : 0);
458 smoothness_indicators(cell->active_cell_index()) = regularity;
461 smoothness_indicators(cell->active_cell_index()) =
462 numbers::signaling_nan<float>();
468 template <
int dim,
int spacedim,
typename VectorType>
473 const VectorType & solution,
476 const double smallest_abs_coefficient,
477 const bool only_flagged_cells)
479 Assert(smallest_abs_coefficient >= 0.,
480 ExcMessage(
"smallest_abs_coefficient should be non-negative."));
482 using number =
typename VectorType::value_type;
486 smoothness_indicators.
reinit(
489 unsigned int n_modes;
494 const unsigned int max_degree =
497 std::vector<double> x, y;
498 x.reserve(max_degree);
499 y.reserve(max_degree);
502 if (cell->is_locally_owned())
504 if (!only_flagged_cells || cell->refine_flag_set() ||
505 cell->coarsen_flag_set())
508 cell->active_fe_index());
509 resize(expansion_coefficients, n_modes);
511 const unsigned int pe = cell->get_fe().degree;
519 local_dof_values.
reinit(cell->get_fe().n_dofs_per_cell());
520 cell->get_dof_values(solution, local_dof_values);
523 cell->active_fe_index(),
524 expansion_coefficients);
528 double k_v = std::numeric_limits<double>::infinity();
529 for (
unsigned int d = 0;
d < dim; ++
d)
538 for (
unsigned int i = 1; i <= pe; ++i)
539 if (coefficients_predicate[i])
543 const double coeff_abs =
544 std::abs(expansion_coefficients(ind));
546 if (coeff_abs > smallest_abs_coefficient)
558 const std::pair<double, double> fit =
566 smoothness_indicators(cell->active_cell_index()) =
567 static_cast<float>(k_v);
570 smoothness_indicators(cell->active_cell_index()) =
571 numbers::signaling_nan<float>();
577 template <
int dim,
int spacedim>
580 const unsigned int component)
589 std::vector<unsigned int> n_coefficients_per_direction;
590 for (
unsigned int i = 0; i < fe_collection.
size(); ++i)
591 n_coefficients_per_direction.push_back(fe_collection[i].degree + 2);
609 for (
unsigned int i = 0; i < fe_collection.
size(); ++i)
612 n_coefficients_per_direction[i] - 1);
614 q_collection.
push_back(quadrature_sorted);
627#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
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)
virtual void reinit(const size_type N, const bool omit_zeroing_entries=false)
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 > &)