libMesh::SystemNorm Class Reference

#include <system_norm.h>

Public Member Functions

 SystemNorm ()
 
 SystemNorm (const FEMNormType &t)
 
 SystemNorm (const std::vector< FEMNormType > &norms)
 
 SystemNorm (const std::vector< FEMNormType > &norms, std::vector< Real > &weights)
 
 SystemNorm (const std::vector< FEMNormType > &norms, std::vector< std::vector< Real >> &weights)
 
 SystemNorm (const SystemNorm &)=default
 
 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)
 
Real weight (unsigned int var) const
 
void set_weight (unsigned int var, Real w)
 
void set_off_diagonal_weight (unsigned int i, unsigned int j, Real w)
 
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
 

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.

Author
Roy H. Stogner
Date
2008

Definition at line 51 of file system_norm.h.

Constructor & Destructor Documentation

◆ SystemNorm() [1/7]

libMesh::SystemNorm::SystemNorm ( )

Constructor, defaults to DISCRETE_L2

Definition at line 26 of file system_norm.C.

26  :
27  _norms(1, DISCRETE_L2), _weights(1, 1.0), _weights_sq(1, 1.0)
28 {
29 }
std::vector< FEMNormType > _norms
Definition: system_norm.h:166
std::vector< Real > _weights_sq
Definition: system_norm.h:169
std::vector< Real > _weights
Definition: system_norm.h:168

◆ 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 32 of file system_norm.C.

32  :
33  _norms(1, t), _weights(1, 1.0), _weights_sq(1, 1.0)
34 {
35 }
std::vector< FEMNormType > _norms
Definition: system_norm.h:166
std::vector< Real > _weights_sq
Definition: system_norm.h:169
std::vector< Real > _weights
Definition: system_norm.h:168

◆ SystemNorm() [3/7]

libMesh::SystemNorm::SystemNorm ( const 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 38 of file system_norm.C.

References _norms, and libMesh::DISCRETE_L2.

38  :
39  _norms(norms), _weights(1, 1.0), _weights_sq(1, 1.0)
40 {
41  if (_norms.empty())
42  _norms.push_back(DISCRETE_L2);
43 }
std::vector< FEMNormType > _norms
Definition: system_norm.h:166
std::vector< Real > _weights_sq
Definition: system_norm.h:169
std::vector< Real > _weights
Definition: system_norm.h:168

◆ SystemNorm() [4/7]

libMesh::SystemNorm::SystemNorm ( const 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 46 of file system_norm.C.

References _norms, _weights, _weights_sq, and libMesh::DISCRETE_L2.

47  :
48  _norms(norms), _weights(weights), _weights_sq(_weights.size(), 0.0)
49 {
50  if (_norms.empty())
51  _norms.push_back(DISCRETE_L2);
52 
53  if (_weights.empty())
54  {
55  _weights.push_back(1.0);
56  _weights_sq.push_back(1.0);
57  }
58  else
59  for (std::size_t i=0; i != _weights.size(); ++i)
60  _weights_sq[i] = _weights[i] * _weights[i];
61 }
std::vector< FEMNormType > _norms
Definition: system_norm.h:166
std::vector< Real > _weights_sq
Definition: system_norm.h:169
std::vector< Real > _weights
Definition: system_norm.h:168

◆ SystemNorm() [5/7]

libMesh::SystemNorm::SystemNorm ( const 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 63 of file system_norm.C.

References _norms, _off_diagonal_weights, _weights, _weights_sq, and libMesh::DISCRETE_L2.

64  :
65  _norms(norms),
66  _weights(weights.size()),
67  _weights_sq(weights.size()),
68  _off_diagonal_weights(weights)
69 {
70  if (_norms.empty())
71  _norms.push_back(DISCRETE_L2);
72 
73  if (_weights.empty())
74  {
75  _weights.push_back(1.0);
76  _weights_sq.push_back(1.0);
77  }
78  else
79  {
80  // Loop over the entries of the user provided matrix and store its entries in
81  // the _off_diagonal_weights or _diagonal_weights
82  for (std::size_t i=0; i!=_off_diagonal_weights.size(); ++i)
83  {
84  if (_off_diagonal_weights[i].size() > i)
85  {
87  _off_diagonal_weights[i][i] = 0;
88  }
89  else
90  _weights[i] = 1.0;
91  }
92  for (std::size_t i=0; i != _weights.size(); ++i)
93  _weights_sq[i] = _weights[i] * _weights[i];
94  }
95 }
std::vector< FEMNormType > _norms
Definition: system_norm.h:166
std::vector< Real > _weights_sq
Definition: system_norm.h:169
std::vector< std::vector< Real > > _off_diagonal_weights
Definition: system_norm.h:175
std::vector< Real > _weights
Definition: system_norm.h:168

◆ 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 230 of file system_norm.C.

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

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

◆ 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 183 of file system_norm.C.

References _off_diagonal_weights, _weights, and libMesh::Real.

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

◆ is_discrete()

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

Definition at line 97 of file system_norm.C.

References _norms, libMesh::DISCRETE_L1, libMesh::DISCRETE_L2, and libMesh::DISCRETE_L_INF.

Referenced by libMesh::System::calculate_norm().

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

◆ 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 235 of file system_norm.C.

References _off_diagonal_weights, and _weights.

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

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

◆ 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 154 of file system_norm.C.

References _off_diagonal_weights, and _weights.

157 {
158  libmesh_assert (!_weights.empty());
159 
160  if (i >= _off_diagonal_weights.size())
161  {
162  _off_diagonal_weights.resize(i+1);
163  }
164 
165  if (j >= _off_diagonal_weights[i].size())
166  {
167  _off_diagonal_weights[i].resize(j+1, 0.);
168  }
169 
170  _off_diagonal_weights[i][j] = w;
171 
172 }
std::vector< std::vector< Real > > _off_diagonal_weights
Definition: system_norm.h:175
std::vector< Real > _weights
Definition: system_norm.h:168

◆ set_type()

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

Sets the type of the norm in variable var

Definition at line 121 of file system_norm.C.

References _norms.

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

◆ set_weight()

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

Sets the weight corresponding to the norm in variable var

Definition at line 140 of file system_norm.C.

References _weights, and _weights_sq.

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

◆ type()

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

Definition at line 110 of file system_norm.C.

References _norms.

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

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

◆ weight()

◆ 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 175 of file system_norm.C.

References _weights_sq.

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

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

Member Data Documentation

◆ _norms

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

Definition at line 166 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 175 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 169 of file system_norm.h.

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


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