libMesh
Public Member Functions | Private Attributes | List of all members
libMesh::SystemNorm Class Reference

This class defines a norm/seminorm to be applied to a NumericVector which contains coefficients in a finite element space. More...

#include <system_norm.h>

Public Member Functions

 SystemNorm ()
 Constructor, defaults to DISCRETE_L2 with weight of 1.0. More...
 
 SystemNorm (const FEMNormType &t)
 Constructor, for discrete vector norms, systems with one variable, and systems for which the same norm type should be used with a weight of one on each variable. More...
 
 SystemNorm (std::vector< FEMNormType > norms)
 Constructor, for unweighted sobolev norms on systems with multiple variables. More...
 
 SystemNorm (std::vector< FEMNormType > norms, std::vector< Real > &weights)
 Constructor, for weighted sobolev norms on systems with multiple variables. More...
 
 SystemNorm (std::vector< FEMNormType > norms, std::vector< std::vector< Real >> &weights)
 Constructor, for weighted sobolev norms on systems with multiple variables and their adjoints. More...
 
 SystemNorm (const SystemNorm &)=default
 Copy/move ctor, copy/move assignment operator, and destructor are all explicitly defaulted for this simple class. More...
 
 SystemNorm (SystemNorm &&)=default
 
SystemNormoperator= (const SystemNorm &)=default
 
SystemNormoperator= (SystemNorm &&)=default
 
virtual ~SystemNorm ()=default
 
bool is_discrete () const
 
Real calculate_norm (const std::vector< Real > &v)
 
Real calculate_norm (const std::vector< Real > &v1, const std::vector< Real > &v2)
 
bool is_identity ()
 
FEMNormType type (unsigned int var) const
 
void set_type (unsigned int var, const FEMNormType &t)
 Sets the type of the norm in variable var, as well as for any unset variables with index less than var. More...
 
Real weight (unsigned int var) const
 
void set_weight (unsigned int var, Real w)
 Sets the weight corresponding to the norm in variable var, as well as for any unset variables with index less than var. More...
 
void set_off_diagonal_weight (unsigned int i, unsigned int j, Real w)
 Sets the weight corresponding to the norm from the variable pair v1(var1) coming from v2(var2). More...
 
Real weight_sq (unsigned int var) const
 

Private Attributes

std::vector< FEMNormType_norms
 
std::vector< Real_weights
 
std::vector< Real_weights_sq
 
std::vector< std::vector< Real > > _off_diagonal_weights
 One more data structure needed to store the off diagonal components for the generalize SystemNorm case. More...
 

Detailed Description

This class defines a norm/seminorm to be applied to a NumericVector which contains coefficients in a finite element space.

Discrete vector norms and weighted l2 combinations of Sobolev norms and seminorms are representable.

For ease of use, if a norm or weight is queried for variable n but has not been set for variable n, then the norm or weight set for the highest-numbered variable below n is returned.

Author
Roy H. Stogner
Date
2008

Definition at line 49 of file system_norm.h.

Constructor & Destructor Documentation

◆ SystemNorm() [1/7]

libMesh::SystemNorm::SystemNorm ( )

Constructor, defaults to DISCRETE_L2 with weight of 1.0.

Definition at line 27 of file system_norm.C.

27  :
28  _norms(1, DISCRETE_L2), _weights(1, 1.0), _weights_sq(1, 1.0)
29 {
30 }
std::vector< FEMNormType > _norms
Definition: system_norm.h:174
std::vector< Real > _weights_sq
Definition: system_norm.h:177
std::vector< Real > _weights
Definition: system_norm.h:176

◆ SystemNorm() [2/7]

libMesh::SystemNorm::SystemNorm ( const FEMNormType t)

Constructor, for discrete vector norms, systems with one variable, and systems for which the same norm type should be used with a weight of one on each variable.

This is deliberately an implicit constructor; we want user code to be able to include lines like "error_norm = L2"

Definition at line 33 of file system_norm.C.

33  :
34  _norms(1, t), _weights(1, 1.0), _weights_sq(1, 1.0)
35 {
36 }
std::vector< FEMNormType > _norms
Definition: system_norm.h:174
std::vector< Real > _weights_sq
Definition: system_norm.h:177
std::vector< Real > _weights
Definition: system_norm.h:176

◆ SystemNorm() [3/7]

libMesh::SystemNorm::SystemNorm ( std::vector< FEMNormType norms)
explicit

Constructor, for unweighted sobolev norms on systems with multiple variables.

For a system with n variables, the final norm will be the l2 norm of the n-vector of the norms in each variable.

Definition at line 39 of file system_norm.C.

References _norms, and libMesh::DISCRETE_L2.

39  :
40  _norms(std::move(norms)), _weights(1, 1.0), _weights_sq(1, 1.0)
41 {
42  if (_norms.empty())
43  _norms.push_back(DISCRETE_L2);
44 }
std::vector< FEMNormType > _norms
Definition: system_norm.h:174
std::vector< Real > _weights_sq
Definition: system_norm.h:177
std::vector< Real > _weights
Definition: system_norm.h:176

◆ SystemNorm() [4/7]

libMesh::SystemNorm::SystemNorm ( std::vector< FEMNormType norms,
std::vector< Real > &  weights 
)

Constructor, for weighted sobolev norms on systems with multiple variables.

For a system with n variables, the final norm will be the l2 norm of the n-vector of the norms in each variable, each multiplied by weight.

Definition at line 47 of file system_norm.C.

References _norms, _weights, _weights_sq, libMesh::DISCRETE_L2, and libMesh::index_range().

48  :
49  _norms(std::move(norms)), _weights(weights),
50  _weights_sq(_weights.size(), 0.0)
51 {
52  if (_norms.empty())
53  _norms.push_back(DISCRETE_L2);
54 
55  if (_weights.empty())
56  {
57  _weights.push_back(1.0);
58  _weights_sq.push_back(1.0);
59  }
60  else
61  for (auto i : index_range(_weights))
62  _weights_sq[i] = _weights[i] * _weights[i];
63 }
std::vector< FEMNormType > _norms
Definition: system_norm.h:174
std::vector< Real > _weights_sq
Definition: system_norm.h:177
std::vector< Real > _weights
Definition: system_norm.h:176
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:117

◆ SystemNorm() [5/7]

libMesh::SystemNorm::SystemNorm ( std::vector< FEMNormType norms,
std::vector< std::vector< Real >> &  weights 
)

Constructor, for weighted sobolev norms on systems with multiple variables and their adjoints.

For a system with n variables, the final norm computed will be of the form norm_u^T*R*norm_z where R is a scaling matrix

Definition at line 65 of file system_norm.C.

References _norms, _off_diagonal_weights, _weights, _weights_sq, libMesh::DISCRETE_L2, and libMesh::index_range().

66  :
67  _norms(std::move(norms)),
68  _weights(weights.size()),
69  _weights_sq(weights.size()),
70  _off_diagonal_weights(weights)
71 {
72  if (_norms.empty())
73  _norms.push_back(DISCRETE_L2);
74 
75  if (_weights.empty())
76  {
77  _weights.push_back(1.0);
78  _weights_sq.push_back(1.0);
79  }
80  else
81  {
82  // Loop over the entries of the user provided matrix and store its entries in
83  // the _off_diagonal_weights or _diagonal_weights
84  for (auto i : index_range(_off_diagonal_weights))
85  {
86  if (_off_diagonal_weights[i].size() > i)
87  {
89  _off_diagonal_weights[i][i] = 0;
90  }
91  else
92  _weights[i] = 1.0;
93  }
94  for (auto i : index_range(_weights))
95  _weights_sq[i] = _weights[i] * _weights[i];
96  }
97 }
std::vector< FEMNormType > _norms
Definition: system_norm.h:174
std::vector< Real > _weights_sq
Definition: system_norm.h:177
std::vector< std::vector< Real > > _off_diagonal_weights
One more data structure needed to store the off diagonal components for the generalize SystemNorm cas...
Definition: system_norm.h:183
std::vector< Real > _weights
Definition: system_norm.h:176
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:117

◆ SystemNorm() [6/7]

libMesh::SystemNorm::SystemNorm ( const SystemNorm )
default

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

◆ SystemNorm() [7/7]

libMesh::SystemNorm::SystemNorm ( SystemNorm &&  )
default

◆ ~SystemNorm()

virtual libMesh::SystemNorm::~SystemNorm ( )
virtualdefault

Member Function Documentation

◆ calculate_norm() [1/2]

Real libMesh::SystemNorm::calculate_norm ( const std::vector< Real > &  v)
Returns
The weighted norm v^T*W*v where W represents our weights matrix or weights vector times identity matrix.

Definition at line 232 of file system_norm.C.

Referenced by libMesh::AdjointResidualErrorEstimator::estimate_error().

233 {
234  return this->calculate_norm(v1,v1);
235 }
Real calculate_norm(const std::vector< Real > &v)
Definition: system_norm.C:232

◆ calculate_norm() [2/2]

Real libMesh::SystemNorm::calculate_norm ( const std::vector< Real > &  v1,
const std::vector< Real > &  v2 
)
Returns
The weighted inner product v1^T*W*v2 where R is our weights

Definition at line 185 of file system_norm.C.

References _off_diagonal_weights, _weights, and libMesh::Real.

187 {
188  // The vectors are assumed to both be vectors of the (same number
189  // of) components
190  std::size_t vsize = v1.size();
191  libmesh_assert_equal_to (vsize, v2.size());
192 
193  // We'll support implicitly defining weights, but if the user sets
194  // more weights than he uses then something's probably wrong
195  std::size_t diagsize = this->_weights.size();
196  libmesh_assert_greater_equal (vsize, diagsize);
197 
198  // Initialize the variable val
199  Real val = 0.;
200 
201  // Loop over all the components of the system with explicit
202  // weights
203  for (std::size_t i = 0; i != diagsize; i++)
204  {
205  val += this->_weights[i] * v1[i] * v2[i];
206  }
207  // Loop over all the components of the system with implicit
208  // weights
209  for (std::size_t i = diagsize; i < vsize; i++)
210  {
211  val += v1[i] * v2[i];
212  }
213 
214  // Loop over the components of the system
215  std::size_t nrows = this->_off_diagonal_weights.size();
216  libmesh_assert_less_equal (vsize, nrows);
217 
218  for (std::size_t i = 0; i != nrows; i++)
219  {
220  std::size_t ncols = this->_off_diagonal_weights[i].size();
221  for (std::size_t j=0; j != ncols; j++)
222  {
223  // The diagonal weights here were set to zero in the
224  // constructor.
225  val += this->_off_diagonal_weights[i][j] * v1[i] * v2[j];
226  }
227  }
228 
229  return(val);
230 }
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< std::vector< Real > > _off_diagonal_weights
One more data structure needed to store the off diagonal components for the generalize SystemNorm cas...
Definition: system_norm.h:183
std::vector< Real > _weights
Definition: system_norm.h:176

◆ is_discrete()

bool libMesh::SystemNorm::is_discrete ( ) const
Returns
true if this is purely a discrete norm

Definition at line 99 of file system_norm.C.

References _norms, libMesh::DISCRETE_L1, libMesh::DISCRETE_L2, libMesh::DISCRETE_L_INF, and libMesh::libmesh_assert().

100 {
101  libmesh_assert (!_norms.empty());
102 
103  if (_norms[0] == DISCRETE_L1 ||
104  _norms[0] == DISCRETE_L2 ||
105  _norms[0] == DISCRETE_L_INF)
106  return true;
107 
108  return false;
109 }
std::vector< FEMNormType > _norms
Definition: system_norm.h:174
libmesh_assert(ctx)

◆ is_identity()

bool libMesh::SystemNorm::is_identity ( )
Returns
true if no weight matrix W is specified or an identity matrix is specified, otherwise returns false

Definition at line 237 of file system_norm.C.

References _off_diagonal_weights, and _weights.

Referenced by libMesh::AdjointResidualErrorEstimator::estimate_error().

238 {
239  std::size_t nrows = this->_off_diagonal_weights.size();
240 
241  // If any of the off-diagonal elements is not 0, then we are in the non-identity case
242  for (std::size_t i = 0; i != nrows; i++)
243  {
244  std::size_t ncols = this->_off_diagonal_weights[i].size();
245  for (std::size_t j = 0; j != ncols; j++)
246  {
247  if (_off_diagonal_weights[i][j] != 0)
248  {
249  return(false);
250  }
251  }
252  }
253 
254  // If any of the diagonal elements is not 1, then we are in the non-identity case
255  nrows = this->_weights.size();
256  for (std::size_t i = 0; i != nrows; i++)
257  if (_weights[i] != 1)
258  return(false);
259 
260  // If all the off-diagonals elements are 0, and diagonal elements 1, then we are in an identity case
261  return(true);
262 }
std::vector< std::vector< Real > > _off_diagonal_weights
One more data structure needed to store the off diagonal components for the generalize SystemNorm cas...
Definition: system_norm.h:183
std::vector< Real > _weights
Definition: system_norm.h:176

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ set_off_diagonal_weight()

void libMesh::SystemNorm::set_off_diagonal_weight ( unsigned int  i,
unsigned int  j,
Real  w 
)

Sets the weight corresponding to the norm from the variable pair v1(var1) coming from v2(var2).

See calculate_norm

Definition at line 156 of file system_norm.C.

References _off_diagonal_weights, _weights, and libMesh::libmesh_assert().

159 {
160  libmesh_assert (!_weights.empty());
161 
162  if (i >= _off_diagonal_weights.size())
163  {
164  _off_diagonal_weights.resize(i+1);
165  }
166 
167  if (j >= _off_diagonal_weights[i].size())
168  {
169  _off_diagonal_weights[i].resize(j+1, 0.);
170  }
171 
172  _off_diagonal_weights[i][j] = w;
173 
174 }
libmesh_assert(ctx)
std::vector< std::vector< Real > > _off_diagonal_weights
One more data structure needed to store the off diagonal components for the generalize SystemNorm cas...
Definition: system_norm.h:183
std::vector< Real > _weights
Definition: system_norm.h:176

◆ set_type()

void libMesh::SystemNorm::set_type ( unsigned int  var,
const FEMNormType t 
)

Sets the type of the norm in variable var, as well as for any unset variables with index less than var.

Definition at line 123 of file system_norm.C.

References _norms, and libMesh::libmesh_assert().

Referenced by main().

124 {
125  libmesh_assert (!_norms.empty());
126 
127  if (var >= _norms.size())
128  _norms.resize(var+1, t);
129 
130  _norms[var] = t;
131 }
std::vector< FEMNormType > _norms
Definition: system_norm.h:174
libmesh_assert(ctx)

◆ set_weight()

void libMesh::SystemNorm::set_weight ( unsigned int  var,
Real  w 
)

Sets the weight corresponding to the norm in variable var, as well as for any unset variables with index less than var.

Definition at line 142 of file system_norm.C.

References _weights, _weights_sq, and libMesh::libmesh_assert().

Referenced by main().

143 {
144  libmesh_assert (!_weights.empty());
145 
146  if (var >= _weights.size())
147  {
148  _weights.resize(var+1, 1.0);
149  _weights_sq.resize(var+1, 1.0);
150  }
151 
152  _weights[var] = w;
153  _weights_sq[var] = w*w;
154 }
std::vector< Real > _weights_sq
Definition: system_norm.h:177
libmesh_assert(ctx)
std::vector< Real > _weights
Definition: system_norm.h:176

◆ type()

FEMNormType libMesh::SystemNorm::type ( unsigned int  var) const
Returns
The type of the norm in variable var

If no norm has been explicitly set for var, then the highest-index norm explicitly set is returned, or DISCRETE_L2 is returned if no norms have been explicitly set.

Definition at line 112 of file system_norm.C.

References _norms, and libMesh::libmesh_assert().

Referenced by libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::ErrorEstimator::estimate_errors(), libMesh::ExactErrorEstimator::find_squared_element_error(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), and libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()().

113 {
114  libmesh_assert (!_norms.empty());
115 
116  std::size_t i = (var < _norms.size()) ? var : _norms.size() - 1;
117 
118  return _norms[i];
119 }
std::vector< FEMNormType > _norms
Definition: system_norm.h:174
libmesh_assert(ctx)

◆ weight()

Real libMesh::SystemNorm::weight ( unsigned int  var) const

◆ weight_sq()

Real libMesh::SystemNorm::weight_sq ( unsigned int  var) const
Returns
The squared weight corresponding to the norm in variable var. We cache that at construction time to save a few flops.

Definition at line 177 of file system_norm.C.

References _weights_sq, and libMesh::libmesh_assert().

Referenced by libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), and libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()().

178 {
179  libmesh_assert (!_weights_sq.empty());
180 
181  return (var < _weights_sq.size()) ? _weights_sq[var] : 1.0;
182 }
std::vector< Real > _weights_sq
Definition: system_norm.h:177
libmesh_assert(ctx)

Member Data Documentation

◆ _norms

std::vector<FEMNormType> libMesh::SystemNorm::_norms
private

Definition at line 174 of file system_norm.h.

Referenced by is_discrete(), set_type(), SystemNorm(), and type().

◆ _off_diagonal_weights

std::vector<std::vector<Real> > libMesh::SystemNorm::_off_diagonal_weights
private

One more data structure needed to store the off diagonal components for the generalize SystemNorm case.

Definition at line 183 of file system_norm.h.

Referenced by calculate_norm(), is_identity(), set_off_diagonal_weight(), and SystemNorm().

◆ _weights

std::vector<Real> libMesh::SystemNorm::_weights
private

◆ _weights_sq

std::vector<Real> libMesh::SystemNorm::_weights_sq
private

Definition at line 177 of file system_norm.h.

Referenced by set_weight(), SystemNorm(), and weight_sq().


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