libMesh
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
libMesh::SmoothnessEstimator Class Reference

This class implements the Smoothness estimate. More...

#include <smoothness_estimator.h>

Classes

class  EstimateSmoothness
 Class to compute the error contribution for a range of elements. More...
 

Public Member Functions

 SmoothnessEstimator ()
 Constructor.
 
 SmoothnessEstimator (const SmoothnessEstimator &)=default
 Copy/move ctor, copy/move assignment operator, and destructor are all explicitly defaulted for this class.
 
 SmoothnessEstimator (SmoothnessEstimator &&)=default
 
SmoothnessEstimatoroperator= (const SmoothnessEstimator &)=default
 
SmoothnessEstimatoroperator= (SmoothnessEstimator &&)=default
 
virtual ~SmoothnessEstimator ()=default
 
virtual void estimate_smoothness (const System &system, ErrorVector &smoothness_per_cell, const NumericVector< Number > *solution_vector=nullptr)
 This function uses the Legendre expansion of solution to estimate coefficient decay to quantify the solution smoothness on each cell.
 
void extra_quadrature_order (const int extraorder)
 Increases or decreases the order of the quadrature rule used for numerical integration.
 

Protected Member Functions

void reduce_smoothness (std::vector< ErrorVectorReal > &error_per_cell, const Parallel::Communicator &comm)
 

Static Protected Member Functions

static std::vector< Reallegepoly (const unsigned int dim, const Order order, const Point p, const unsigned int matsize)
 
static Real compute_slope (int N, Real Sx, Real Sy, Real Sxx, Real Sxy)
 Computes slop in a linear regression.
 

Protected Attributes

int _extra_order
 Extra order to use for quadrature rule.
 

Friends

class EstimateSmoothness
 

Detailed Description

This class implements the Smoothness estimate.

Author
Arjun Kulathuvayal
Varis Carey
Benjamin S. Kirk
Date
2025

Definition at line 48 of file smoothness_estimator.h.

Constructor & Destructor Documentation

◆ SmoothnessEstimator() [1/3]

libMesh::SmoothnessEstimator::SmoothnessEstimator ( )

Constructor.

Definition at line 44 of file smoothness_estimator.C.

44 :
46{
47}
int _extra_order
Extra order to use for quadrature rule.

◆ SmoothnessEstimator() [2/3]

libMesh::SmoothnessEstimator::SmoothnessEstimator ( const SmoothnessEstimator )
default

Copy/move ctor, copy/move assignment operator, and destructor are all explicitly defaulted for this class.

◆ SmoothnessEstimator() [3/3]

libMesh::SmoothnessEstimator::SmoothnessEstimator ( SmoothnessEstimator &&  )
default

◆ ~SmoothnessEstimator()

virtual libMesh::SmoothnessEstimator::~SmoothnessEstimator ( )
virtualdefault

Member Function Documentation

◆ compute_slope()

Real libMesh::SmoothnessEstimator::compute_slope ( int  N,
Real  Sx,
Real  Sy,
Real  Sxx,
Real  Sxy 
)
staticprotected

Computes slop in a linear regression.

Definition at line 124 of file smoothness_estimator.C.

125{
126 const Real denom = (N * Sxx - Sx * Sx);
127 // Triggers for first order polynomials when there only 1 point
128 // available at log |c_k| and log |k| space to fit.
129 if (std::abs(denom) < std::numeric_limits<Real>::epsilon()) {
130 return std::numeric_limits<Real>::max();
131 }
132 return (N * Sxy - Sx * Sy) / denom;
133}
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

References libMesh::Real.

Referenced by libMesh::SmoothnessEstimator::EstimateSmoothness::operator()().

◆ estimate_smoothness()

void libMesh::SmoothnessEstimator::estimate_smoothness ( const System system,
ErrorVector smoothness_per_cell,
const NumericVector< Number > *  solution_vector = nullptr 
)
virtual

This function uses the Legendre expansion of solution to estimate coefficient decay to quantify the solution smoothness on each cell.

The estimated smoothness is output in the vector (for time being, we use ErrorVector) For element order 1, the least square fit of log|order| vs log |coefficients| fails. This leads to pure h refinement. smoothness_per_cell

Definition at line 143 of file smoothness_estimator.C.

146{
147 LOG_SCOPE("estimate_smoothness()", "SmoothnessEstimator");
148
149 // The current mesh
150 const MeshBase & mesh = system.get_mesh();
151
152 // Resize the smoothness_per_cell vector to be
153 // the number of elements, initialize it to 0.
154 smoothness_per_cell.resize (mesh.max_elem_id());
155 std::fill (smoothness_per_cell.begin(), smoothness_per_cell.end(), 0.);
156
157 // Prepare current_local_solution to localize a non-standard
158 // solution vector if necessary
159 if (solution_vector && solution_vector != system.solution.get())
160 {
161 NumericVector<Number> * newsol =
162 const_cast<NumericVector<Number> *>(solution_vector);
163 System & sys = const_cast<System &>(system);
164 newsol->swap(*sys.solution);
165 sys.update();
166 }
167
168 //------------------------------------------------------------
169 // Iterate over all the active elements in the mesh
170 // that live on this processor.
171 Threads::parallel_for (ConstElemRange(mesh.active_local_elements_begin(),
172 mesh.active_local_elements_end(),
173 200),
174 EstimateSmoothness(system,
175 *this,
176 smoothness_per_cell)
177 );
178
179 // Each processor has now computed the smoothness for its local
180 // elements, and smoothness_per_cell contains 0 for all the
181 // non-local elements. Summing the vector will provide the true
182 // value for each element, local or remote
183 this->reduce_smoothness (smoothness_per_cell, system.comm());
184
185 // If we used a non-standard solution before, now is the time to fix
186 // the current_local_solution
187 if (solution_vector && solution_vector != system.solution.get())
188 {
189 NumericVector<Number> * newsol = const_cast<NumericVector<Number> *>(solution_vector);
190 System & sys = const_cast<System &>(system);
191 newsol->swap(*sys.solution);
192 sys.update();
193 }
194}
void reduce_smoothness(std::vector< ErrorVectorReal > &error_per_cell, const Parallel::Communicator &comm)
MeshBase & mesh
void parallel_for(const Range &range, const Body &body, unsigned int n_threads=libMesh::n_threads())
Execute the provided function object in parallel on the specified range.
StoredRange< MeshBase::const_element_iterator, const Elem * > ConstElemRange
Definition elem_range.h:34
template class LIBMESH_EXPORT NumericVector< Number >

References libMesh::ParallelObject::comm(), libMesh::System::get_mesh(), mesh, libMesh::Threads::parallel_for(), reduce_smoothness(), libMesh::System::solution, and libMesh::NumericVector< T >::swap().

Referenced by main(), and libMesh::HPCoarsenTest::select_refinement().

◆ extra_quadrature_order()

void libMesh::SmoothnessEstimator::extra_quadrature_order ( const int  extraorder)
inline

Increases or decreases the order of the quadrature rule used for numerical integration.

The default extraorder is 1, because properly integrating L2 error requires integrating the squares of terms with order p+1, and 2p+2 is 1 higher than what we default to using for reasonable mass matrix integration.

Definition at line 86 of file smoothness_estimator.h.

87 { _extra_order = extraorder; }

References _extra_order.

◆ legepoly()

std::vector< Real > libMesh::SmoothnessEstimator::legepoly ( const unsigned int  dim,
const Order  order,
const Point  p,
const unsigned int  matsize 
)
staticprotected
Returns
The Legendre polynomial basis function values at a point (x,y,z).

Definition at line 51 of file smoothness_estimator.C.

55{
56 std::vector<Real> psi;
57 psi.reserve(matsize);
58
59 // Evaluate 1D Legendre polynomials at x, y, z up to order
60 const int npols = static_cast<int>(order) + 1;
61
62 std::vector<Real> Lx(npols, 0.), Ly(npols, 1.), Lz(npols, 1.);
63 const Real x = p(0);
64 Lx[0] = 1.;
65 if (npols > 1)
66 Lx[1] = x;
67 for (int n = 2; n < npols; ++n)
68 Lx[n] = ((2. * n - 1) * x * Lx[n - 1] - (n - 1) * Lx[n - 2]) / n;
69
70 if (dim > 1)
71 {
72 const Real y = p(1);
73 Ly[0] = 1.;
74 if (npols > 1)
75 Ly[1] = y;
76 for (int n = 2; n < npols; ++n)
77 Ly[n] = ((2. * n - 1) * y * Ly[n - 1] - (n - 1) * Ly[n - 2]) / n;
78 }
79
80 if (dim > 2)
81 {
82 const Real z = p(2);
83 Lz[0] = 1.;
84 if (npols > 1)
85 Lz[1] = z;
86 for (int n = 2; n < npols; ++n)
87 Lz[n] = ((2. * n - 1) * z * Lz[n - 1] - (n - 1) * Lz[n - 2]) / n;
88 }
89
90 // Loop over total degree and build tensor-product Legendre basis
91 for (unsigned int poly_deg = 0; poly_deg <= static_cast<unsigned int>(order); poly_deg++)
92 {
93 switch (dim)
94 {
95 case 3:
96 for (int i = poly_deg; i >= 0; --i)
97 for (int j = poly_deg - i; j >= 0; --j)
98 {
99 int k = poly_deg - i - j;
100 psi.push_back(Lx[i] * Ly[j] * Lz[k]);
101 }
102 break;
103
104 case 2:
105 for (int i = poly_deg; i >= 0; --i)
106 {
107 int j = poly_deg - i;
108 psi.push_back(Lx[i] * Ly[j]);
109 }
110 break;
111
112 case 1:
113 psi.push_back(Lx[poly_deg]);
114 break;
115
116 default:
117 libmesh_error_msg("Invalid dimension dim " << dim);
118 }
119 }
120
121 return psi;
122}
unsigned int dim

References dim, and libMesh::Real.

Referenced by libMesh::SmoothnessEstimator::EstimateSmoothness::operator()().

◆ operator=() [1/2]

SmoothnessEstimator & libMesh::SmoothnessEstimator::operator= ( const SmoothnessEstimator )
default

◆ operator=() [2/2]

SmoothnessEstimator & libMesh::SmoothnessEstimator::operator= ( SmoothnessEstimator &&  )
default

◆ reduce_smoothness()

void libMesh::SmoothnessEstimator::reduce_smoothness ( std::vector< ErrorVectorReal > &  error_per_cell,
const Parallel::Communicator comm 
)
protected

Definition at line 135 of file smoothness_estimator.C.

137{
138 // Aggregates element-wise contributions computed
139 // in parallel across all processors
140 comm.sum(smoothness_per_cell);
141}

References libMesh::Parallel::Communicator::sum().

Referenced by estimate_smoothness().

Friends And Related Symbol Documentation

◆ EstimateSmoothness

friend class EstimateSmoothness
friend

Definition at line 137 of file smoothness_estimator.h.

Member Data Documentation

◆ _extra_order

int libMesh::SmoothnessEstimator::_extra_order
protected

Extra order to use for quadrature rule.

Definition at line 102 of file smoothness_estimator.h.

Referenced by extra_quadrature_order(), and libMesh::SmoothnessEstimator::EstimateSmoothness::operator()().


The documentation for this class was generated from the following files: