55 template <
int dim,
typename CoefficientType>
60 for (
unsigned int d = 0;
d < dim; ++
d)
87 std::pair<bool, unsigned int>
91 for (
unsigned int i = 0; i < dim; ++i)
94 return std::make_pair((v < N), v);
100 template <
int dim,
int spacedim,
typename VectorType>
104 const VectorType & solution,
107 const double smallest_abs_coefficient,
108 const bool only_flagged_cells)
110 using number =
typename VectorType::value_type;
114 smoothness_indicators.
reinit(
117 unsigned int n_modes;
121 std::vector<double> converted_indices;
122 std::pair<std::vector<unsigned int>, std::vector<double>> res;
126 if (!only_flagged_cells || cell->refine_flag_set() ||
127 cell->coarsen_flag_set())
130 cell->active_fe_index());
131 resize(expansion_coefficients, n_modes);
133 local_dof_values.
reinit(cell->get_fe().n_dofs_per_cell());
134 cell->get_dof_values(solution, local_dof_values);
137 cell->active_fe_index(),
138 expansion_coefficients);
144 res = FESeries::process_coefficients<dim>(
145 expansion_coefficients,
147 return index_sum_less_than_N(indices, n_modes);
150 smallest_abs_coefficient);
155 float regularity = std::numeric_limits<float>::infinity();
156 if (res.first.size() > 1)
160 converted_indices.assign(res.first.begin(), res.first.end());
162 for (
auto &residual_element : res.second)
163 residual_element =
std::log(residual_element);
165 const std::pair<double, double> fit =
167 regularity =
static_cast<float>(-fit.first);
170 smoothness_indicators(cell->active_cell_index()) = regularity;
173 smoothness_indicators(cell->active_cell_index()) =
174 numbers::signaling_nan<float>();
180 template <
int dim,
int spacedim,
typename VectorType>
185 const VectorType & solution,
188 const double smallest_abs_coefficient,
189 const bool only_flagged_cells)
191 Assert(smallest_abs_coefficient >= 0.,
192 ExcMessage(
"smallest_abs_coefficient should be non-negative."));
194 using number =
typename VectorType::value_type;
198 smoothness_indicators.
reinit(
201 unsigned int n_modes;
206 const unsigned int max_degree =
209 std::vector<double> x, y;
210 x.reserve(max_degree);
211 y.reserve(max_degree);
216 if (!only_flagged_cells || cell->refine_flag_set() ||
217 cell->coarsen_flag_set())
220 cell->active_fe_index());
221 resize(expansion_coefficients, n_modes);
223 const unsigned int pe = cell->get_fe().degree;
231 local_dof_values.
reinit(cell->get_fe().n_dofs_per_cell());
232 cell->get_dof_values(solution, local_dof_values);
235 cell->active_fe_index(),
236 expansion_coefficients);
240 double k_v = std::numeric_limits<double>::infinity();
241 for (
unsigned int d = 0; d < dim; ++d)
248 for (
unsigned int i = 0; i <= pe; ++i)
249 if (coefficients_predicate[i])
253 const double coeff_abs =
254 std::abs(expansion_coefficients(ind));
256 if (coeff_abs > smallest_abs_coefficient)
268 const std::pair<double, double> fit =
276 smoothness_indicators(cell->active_cell_index()) =
277 static_cast<float>(k_v);
280 smoothness_indicators(cell->active_cell_index()) =
281 numbers::signaling_nan<float>();
287 template <
int dim,
int spacedim>
290 const unsigned int component)
297 std::vector<unsigned int> n_coefficients_per_direction;
298 for (
unsigned int i = 0; i < fe_collection.
size(); ++i)
299 n_coefficients_per_direction.push_back(fe_collection[i].degree + 2);
317 for (
unsigned int i = 0; i < fe_collection.
size(); ++i)
319 const QGauss<dim> quadrature(n_coefficients_per_direction[i]);
321 q_collection.
push_back(quadrature_sorted);
352 std::pair<bool, unsigned int>
353 index_norm_greater_than_zero_and_less_than_N_squared(
355 const unsigned int N)
358 for (
unsigned int i = 0; i < dim; ++i)
359 v += ind[i] * ind[i];
361 return std::make_pair((v > 0 && v < N * N), v);
367 template <
int dim,
int spacedim,
typename VectorType>
371 const VectorType & solution,
374 const double smallest_abs_coefficient,
375 const bool only_flagged_cells)
377 using number =
typename VectorType::value_type;
381 smoothness_indicators.
reinit(
384 unsigned int n_modes;
388 std::vector<double> ln_k;
389 std::pair<std::vector<unsigned int>, std::vector<double>> res;
393 if (!only_flagged_cells || cell->refine_flag_set() ||
394 cell->coarsen_flag_set())
397 cell->active_fe_index());
398 resize(expansion_coefficients, n_modes);
404 local_dof_values.
reinit(cell->get_fe().n_dofs_per_cell());
405 cell->get_dof_values(solution, local_dof_values);
408 cell->active_fe_index(),
409 expansion_coefficients);
415 res = FESeries::process_coefficients<dim>(
416 expansion_coefficients,
418 return index_norm_greater_than_zero_and_less_than_N_squared(
422 smallest_abs_coefficient);
427 float regularity = std::numeric_limits<float>::infinity();
428 if (res.first.size() > 1)
439 ln_k.resize(res.first.size());
440 for (
unsigned int f = 0; f < res.first.size(); ++f)
441 ln_k[f] = 0.5 *
std::log(
static_cast<double>(res.first[f]));
444 for (
auto &residual_element : res.second)
445 residual_element =
std::log(residual_element);
447 const std::pair<double, double> fit =
450 regularity =
static_cast<float>(-fit.first) -
451 ((dim > 1) ? (.5 * dim) : 0);
455 smoothness_indicators(cell->active_cell_index()) = regularity;
458 smoothness_indicators(cell->active_cell_index()) =
459 numbers::signaling_nan<float>();
465 template <
int dim,
int spacedim,
typename VectorType>
470 const VectorType & solution,
473 const double smallest_abs_coefficient,
474 const bool only_flagged_cells)
476 Assert(smallest_abs_coefficient >= 0.,
477 ExcMessage(
"smallest_abs_coefficient should be non-negative."));
479 using number =
typename VectorType::value_type;
483 smoothness_indicators.
reinit(
486 unsigned int n_modes;
491 const unsigned int max_degree =
494 std::vector<double> x, y;
495 x.reserve(max_degree);
496 y.reserve(max_degree);
501 if (!only_flagged_cells || cell->refine_flag_set() ||
502 cell->coarsen_flag_set())
505 cell->active_fe_index());
506 resize(expansion_coefficients, n_modes);
508 const unsigned int pe = cell->get_fe().degree;
516 local_dof_values.
reinit(cell->get_fe().n_dofs_per_cell());
517 cell->get_dof_values(solution, local_dof_values);
520 cell->active_fe_index(),
521 expansion_coefficients);
525 double k_v = std::numeric_limits<double>::infinity();
526 for (
unsigned int d = 0; d < dim; ++d)
535 for (
unsigned int i = 1; i <= pe; ++i)
536 if (coefficients_predicate[i])
540 const double coeff_abs =
541 std::abs(expansion_coefficients(ind));
543 if (coeff_abs > smallest_abs_coefficient)
555 const std::pair<double, double> fit =
563 smoothness_indicators(cell->active_cell_index()) =
564 static_cast<float>(k_v);
567 smoothness_indicators(cell->active_cell_index()) =
568 numbers::signaling_nan<float>();
574 template <
int dim,
int spacedim>
577 const unsigned int component)
586 std::vector<unsigned int> n_coefficients_per_direction;
587 for (
unsigned int i = 0; i < fe_collection.
size(); ++i)
588 n_coefficients_per_direction.push_back(fe_collection[i].degree + 2);
606 for (
unsigned int i = 0; i < fe_collection.
size(); ++i)
609 n_coefficients_per_direction[i] - 1);
611 q_collection.
push_back(quadrature_sorted);
624#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 > &)