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 &s)
 Copy Constructor. More...
 
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 43 of file system_norm.h.

Constructor & Destructor Documentation

libMesh::SystemNorm::SystemNorm ( )

Constructor, defaults to DISCRETE_L2.

Definition at line 171 of file system_norm.h.

171  :
172  _norms(1, DISCRETE_L2), _weights(1, 1.0), _weights_sq(1, 1.0)
173 {
174 }
std::vector< FEMNormType > _norms
Definition: system_norm.h:153
std::vector< Real > _weights_sq
Definition: system_norm.h:156
std::vector< Real > _weights
Definition: system_norm.h:155
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 178 of file system_norm.h.

178  :
179  _norms(1, t), _weights(1, 1.0), _weights_sq(1, 1.0)
180 {
181 }
std::vector< FEMNormType > _norms
Definition: system_norm.h:153
std::vector< Real > _weights_sq
Definition: system_norm.h:156
std::vector< Real > _weights
Definition: system_norm.h:155
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 185 of file system_norm.h.

References _norms, and libMesh::DISCRETE_L2.

185  :
186  _norms(norms), _weights(1, 1.0), _weights_sq(1, 1.0)
187 {
188  if (_norms.empty())
189  _norms.push_back(DISCRETE_L2);
190 }
std::vector< FEMNormType > _norms
Definition: system_norm.h:153
std::vector< Real > _weights_sq
Definition: system_norm.h:156
std::vector< Real > _weights
Definition: system_norm.h:155
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 194 of file system_norm.h.

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

195  :
196  _norms(norms), _weights(weights), _weights_sq(_weights.size(), 0.0)
197 {
198  if (_norms.empty())
199  _norms.push_back(DISCRETE_L2);
200 
201  if (_weights.empty())
202  {
203  _weights.push_back(1.0);
204  _weights_sq.push_back(1.0);
205  }
206  else
207  for (std::size_t i=0; i != _weights.size(); ++i)
208  _weights_sq[i] = _weights[i] * _weights[i];
209 }
std::vector< FEMNormType > _norms
Definition: system_norm.h:153
std::vector< Real > _weights_sq
Definition: system_norm.h:156
std::vector< Real > _weights
Definition: system_norm.h:155
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 212 of file system_norm.h.

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

213  :
214  _norms(norms),
215  _weights(weights.size()),
216  _weights_sq(weights.size()),
217  _off_diagonal_weights(weights)
218 {
219  if (_norms.empty())
220  _norms.push_back(DISCRETE_L2);
221 
222  if (_weights.empty())
223  {
224  _weights.push_back(1.0);
225  _weights_sq.push_back(1.0);
226  }
227  else
228  {
229  // Loop over the entries of the user provided matrix and store its entries in
230  // the _off_diagonal_weights or _diagonal_weights
231  for (std::size_t i=0; i!=_off_diagonal_weights.size(); ++i)
232  {
233  if (_off_diagonal_weights[i].size() > i)
234  {
235  _weights[i] = _off_diagonal_weights[i][i];
236  _off_diagonal_weights[i][i] = 0;
237  }
238  else
239  _weights[i] = 1.0;
240  }
241  for (std::size_t i=0; i != _weights.size(); ++i)
242  _weights_sq[i] = _weights[i] * _weights[i];
243  }
244 }
std::vector< FEMNormType > _norms
Definition: system_norm.h:153
std::vector< Real > _weights_sq
Definition: system_norm.h:156
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:162
std::vector< Real > _weights
Definition: system_norm.h:155
libMesh::SystemNorm::SystemNorm ( const SystemNorm s)

Copy Constructor.

Definition at line 247 of file system_norm.h.

247  :
248  _norms(s._norms), _weights(s._weights), _weights_sq(s._weights_sq)
249 {
250 }
std::vector< FEMNormType > _norms
Definition: system_norm.h:153
std::vector< Real > _weights_sq
Definition: system_norm.h:156
std::vector< Real > _weights
Definition: system_norm.h:155

Member Function Documentation

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 395 of file system_norm.h.

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

396 {
397  return this->calculate_norm(v1,v1);
398 }
Real calculate_norm(const std::vector< Real > &v)
Definition: system_norm.h:395
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 347 of file system_norm.h.

References _off_diagonal_weights, _weights, and libMesh::Real.

349 {
350  // The vectors are assumed to both be vectors of the (same number
351  // of) components
352  std::size_t vsize = v1.size();
353  libmesh_assert_equal_to (vsize, v2.size());
354 
355  // We'll support implicitly defining weights, but if the user sets
356  // more weights than he uses then something's probably wrong
357  std::size_t diagsize = this->_weights.size();
358  libmesh_assert_greater_equal (vsize, diagsize);
359 
360  // Initialize the variable val
361  Real val = 0.;
362 
363  // Loop over all the components of the system with explicit
364  // weights
365  for (std::size_t i = 0; i != diagsize; i++)
366  {
367  val += this->_weights[i] * v1[i] * v2[i];
368  }
369  // Loop over all the components of the system with implicit
370  // weights
371  for (std::size_t i = diagsize; i < vsize; i++)
372  {
373  val += v1[i] * v2[i];
374  }
375 
376  // Loop over the components of the system
377  std::size_t nrows = this->_off_diagonal_weights.size();
378  libmesh_assert_less_equal (vsize, nrows);
379 
380  for (std::size_t i = 0; i != nrows; i++)
381  {
382  std::size_t ncols = this->_off_diagonal_weights[i].size();
383  for (std::size_t j=0; j != ncols; j++)
384  {
385  // The diagonal weights here were set to zero in the
386  // constructor.
387  val += this->_off_diagonal_weights[i][j] * v1[i] * v2[j];
388  }
389  }
390 
391  return(val);
392 }
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:162
std::vector< Real > _weights
Definition: system_norm.h:155
bool libMesh::SystemNorm::is_discrete ( ) const
Returns
true if this is purely a discrete norm

Definition at line 254 of file system_norm.h.

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

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

255 {
256  libmesh_assert (!_norms.empty());
257 
258  if (_norms[0] == DISCRETE_L1 ||
259  _norms[0] == DISCRETE_L2 ||
260  _norms[0] == DISCRETE_L_INF)
261  return true;
262 
263  return false;
264 }
std::vector< FEMNormType > _norms
Definition: system_norm.h:153
libmesh_assert(j)
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 401 of file system_norm.h.

References _off_diagonal_weights, and _weights.

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

402 {
403  std::size_t nrows = this->_off_diagonal_weights.size();
404 
405  // If any of the off-diagonal elements is not 0, then we are in the non-identity case
406  for (std::size_t i = 0; i != nrows; i++)
407  {
408  std::size_t ncols = this->_off_diagonal_weights[i].size();
409  for (std::size_t j = 0; j != ncols; j++)
410  {
411  if (_off_diagonal_weights[i][j] != 0)
412  {
413  return(false);
414  }
415  }
416  }
417 
418  // If any of the diagonal elements is not 1, then we are in the non-identity case
419  nrows = this->_weights.size();
420  for (std::size_t i = 0; i != nrows; i++)
421  if (_weights[i] != 1)
422  return(false);
423 
424  // If all the off-diagonals elements are 0, and diagonal elements 1, then we are in an identity case
425  return(true);
426 }
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:162
std::vector< Real > _weights
Definition: system_norm.h:155
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 316 of file system_norm.h.

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

319 {
320  libmesh_assert (!_weights.empty());
321 
322  if (i >= _off_diagonal_weights.size())
323  {
324  _off_diagonal_weights.resize(i+1);
325  }
326 
327  if (j >= _off_diagonal_weights[i].size())
328  {
329  _off_diagonal_weights[i].resize(j+1, 0.);
330  }
331 
332  _off_diagonal_weights[i][j] = w;
333 
334 }
libmesh_assert(j)
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:162
std::vector< Real > _weights
Definition: system_norm.h:155
void libMesh::SystemNorm::set_type ( unsigned int  var,
const FEMNormType t 
)

Sets the type of the norm in variable var.

Definition at line 280 of file system_norm.h.

References _norms, and libMesh::libmesh_assert().

281 {
282  libmesh_assert (!_norms.empty());
283 
284  if (var >= _norms.size())
285  _norms.resize(var+1, t);
286 
287  _norms[var] = t;
288 }
std::vector< FEMNormType > _norms
Definition: system_norm.h:153
libmesh_assert(j)
void libMesh::SystemNorm::set_weight ( unsigned int  var,
Real  w 
)

Sets the weight corresponding to the norm in variable var.

Definition at line 301 of file system_norm.h.

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

302 {
303  libmesh_assert (!_weights.empty());
304 
305  if (var >= _weights.size())
306  {
307  _weights.resize(var+1, 1.0);
308  _weights_sq.resize(var+1, 1.0);
309  }
310 
311  _weights[var] = w;
312  _weights_sq[var] = w*w;
313 }
std::vector< Real > _weights_sq
Definition: system_norm.h:156
libmesh_assert(j)
std::vector< Real > _weights
Definition: system_norm.h:155
FEMNormType libMesh::SystemNorm::type ( unsigned int  var) const
Returns
The type of the norm in variable var

Definition at line 268 of file system_norm.h.

References _norms, and libMesh::libmesh_assert().

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

269 {
270  libmesh_assert (!_norms.empty());
271 
272  std::size_t i = (var < _norms.size()) ? var : _norms.size() - 1;
273 
274  return _norms[i];
275 }
std::vector< FEMNormType > _norms
Definition: system_norm.h:153
libmesh_assert(j)
Real libMesh::SystemNorm::weight ( unsigned int  var) const
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 338 of file system_norm.h.

References _weights_sq, and libMesh::libmesh_assert().

Referenced by libMesh::UniformRefinementEstimator::_estimate_error(), and libMesh::System::calculate_norm().

339 {
340  libmesh_assert (!_weights_sq.empty());
341 
342  return (var < _weights_sq.size()) ? _weights_sq[var] : 1.0;
343 }
std::vector< Real > _weights_sq
Definition: system_norm.h:156
libmesh_assert(j)

Member Data Documentation

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

Definition at line 153 of file system_norm.h.

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

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 162 of file system_norm.h.

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

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

Definition at line 156 of file system_norm.h.

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


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