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. 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 (const std::vector< FEMNormType > &norms)
 Constructor, for unweighted sobolev norms on systems with multiple variables. More...
 
 SystemNorm (const std::vector< FEMNormType > &norms, std::vector< Real > &weights)
 Constructor, for weighted sobolev norms on systems with multiple variables. More...
 
 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. 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. 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. 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.

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

27  :
28  _norms(1, DISCRETE_L2), _weights(1, 1.0), _weights_sq(1, 1.0)
29 {
30 }

◆ 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 }

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

39  :
40  _norms(norms), _weights(1, 1.0), _weights_sq(1, 1.0)
41 {
42  if (_norms.empty())
43  _norms.push_back(DISCRETE_L2);
44 }

References _norms, and libMesh::DISCRETE_L2.

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

48  :
49  _norms(norms), _weights(weights), _weights_sq(_weights.size(), 0.0)
50 {
51  if (_norms.empty())
52  _norms.push_back(DISCRETE_L2);
53 
54  if (_weights.empty())
55  {
56  _weights.push_back(1.0);
57  _weights_sq.push_back(1.0);
58  }
59  else
60  for (auto i : index_range(_weights))
61  _weights_sq[i] = _weights[i] * _weights[i];
62 }

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

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

65  :
66  _norms(norms),
67  _weights(weights.size()),
68  _weights_sq(weights.size()),
69  _off_diagonal_weights(weights)
70 {
71  if (_norms.empty())
72  _norms.push_back(DISCRETE_L2);
73 
74  if (_weights.empty())
75  {
76  _weights.push_back(1.0);
77  _weights_sq.push_back(1.0);
78  }
79  else
80  {
81  // Loop over the entries of the user provided matrix and store its entries in
82  // the _off_diagonal_weights or _diagonal_weights
83  for (auto i : index_range(_off_diagonal_weights))
84  {
85  if (_off_diagonal_weights[i].size() > i)
86  {
88  _off_diagonal_weights[i][i] = 0;
89  }
90  else
91  _weights[i] = 1.0;
92  }
93  for (auto i : index_range(_weights))
94  _weights_sq[i] = _weights[i] * _weights[i];
95  }
96 }

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

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

232 {
233  return this->calculate_norm(v1,v1);
234 }

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

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

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

References _off_diagonal_weights, _weights, and libMesh::Real.

◆ is_discrete()

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

Definition at line 98 of file system_norm.C.

99 {
100  libmesh_assert (!_norms.empty());
101 
102  if (_norms[0] == DISCRETE_L1 ||
103  _norms[0] == DISCRETE_L2 ||
104  _norms[0] == DISCRETE_L_INF)
105  return true;
106 
107  return false;
108 }

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

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

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

References _off_diagonal_weights, and _weights.

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

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

158 {
159  libmesh_assert (!_weights.empty());
160 
161  if (i >= _off_diagonal_weights.size())
162  {
163  _off_diagonal_weights.resize(i+1);
164  }
165 
166  if (j >= _off_diagonal_weights[i].size())
167  {
168  _off_diagonal_weights[i].resize(j+1, 0.);
169  }
170 
171  _off_diagonal_weights[i][j] = w;
172 
173 }

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

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

123 {
124  libmesh_assert (!_norms.empty());
125 
126  if (var >= _norms.size())
127  _norms.resize(var+1, t);
128 
129  _norms[var] = t;
130 }

References _norms, and libMesh::libmesh_assert().

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

142 {
143  libmesh_assert (!_weights.empty());
144 
145  if (var >= _weights.size())
146  {
147  _weights.resize(var+1, 1.0);
148  _weights_sq.resize(var+1, 1.0);
149  }
150 
151  _weights[var] = w;
152  _weights_sq[var] = w*w;
153 }

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

◆ type()

FEMNormType libMesh::SystemNorm::type ( unsigned int  var) const

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

177 {
178  libmesh_assert (!_weights_sq.empty());
179 
180  return (var < _weights_sq.size()) ? _weights_sq[var] : 1.0;
181 }

References _weights_sq, and libMesh::libmesh_assert().

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

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:
libMesh::DISCRETE_L_INF
Definition: enum_norm_type.h:54
libMesh::DISCRETE_L2
Definition: enum_norm_type.h:53
libMesh::index_range
IntRange< std::size_t > index_range(const std::vector< T > &vec)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:106
libMesh::SystemNorm::_weights_sq
std::vector< Real > _weights_sq
Definition: system_norm.h:169
libMesh::SystemNorm::_weights
std::vector< Real > _weights
Definition: system_norm.h:168
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::SystemNorm::_off_diagonal_weights
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:175
libMesh::DISCRETE_L1
Definition: enum_norm_type.h:52
libMesh::SystemNorm::calculate_norm
Real calculate_norm(const std::vector< Real > &v)
Definition: system_norm.C:231
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::SystemNorm::_norms
std::vector< FEMNormType > _norms
Definition: system_norm.h:166