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 &s)
 
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 2008

Definition at line 48 of file system_norm.h.

Constructor & Destructor Documentation

libMesh::SystemNorm::SystemNorm ( )
inline

Constructor, defaults to DISCRETE_L2

Definition at line 173 of file system_norm.h.

173  :
174  _norms(1, DISCRETE_L2), _weights(1, 1.0), _weights_sq(1, 1.0)
175 {
176 }
libMesh::SystemNorm::SystemNorm ( const FEMNormType &  t)
inline

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

180  :
181  _norms(1, t), _weights(1, 1.0), _weights_sq(1, 1.0)
182 {
183 }
libMesh::SystemNorm::SystemNorm ( const std::vector< FEMNormType > &  norms)
inlineexplicit

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

References _norms, and libMeshEnums::DISCRETE_L2.

187  :
188  _norms(norms), _weights(1, 1.0), _weights_sq(1, 1.0)
189 {
190  if (_norms.empty())
191  _norms.push_back(DISCRETE_L2);
192 }
libMesh::SystemNorm::SystemNorm ( const std::vector< FEMNormType > &  norms,
std::vector< Real > &  weights 
)
inline

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

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

197  :
198  _norms(norms), _weights(weights), _weights_sq(_weights.size(), 0.0)
199 {
200  if (_norms.empty())
201  _norms.push_back(DISCRETE_L2);
202 
203  if (_weights.empty())
204  {
205  _weights.push_back(1.0);
206  _weights_sq.push_back(1.0);
207  }
208  else
209  for (std::size_t i=0; i != _weights.size(); ++i)
210  _weights_sq[i] = _weights[i] * _weights[i];
211 }
libMesh::SystemNorm::SystemNorm ( const std::vector< FEMNormType > &  norms,
std::vector< std::vector< Real > > &  weights 
)
inline

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

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

215  :
216  _norms(norms), _weights(weights.size()), _off_diagonal_weights(weights)
217 {
218  if(_norms.empty())
219  _norms.push_back(DISCRETE_L2);
220 
221  if (_weights.empty())
222  {
223  _weights.push_back(1.0);
224  _weights_sq.push_back(1.0);
225  }
226  else
227  {
228  // Loop over the entries of the user provided matrix and store its entries in
229  // the _off_diagonal_weights or _diagonal_weights
230  for(std::size_t i=0; i!=_off_diagonal_weights.size(); ++i)
231  {
232  if(_off_diagonal_weights[i].size() > i)
233  {
234  _weights[i] = _off_diagonal_weights[i][i];
235  _off_diagonal_weights[i][i] = 0;
236  }
237  else
238  _weights[i] = 1.0;
239  }
240  for (std::size_t i=0; i != _weights.size(); ++i)
241  _weights_sq[i] = _weights[i] * _weights[i];
242  }
243 }
libMesh::SystemNorm::SystemNorm ( const SystemNorm s)
inline

Copy Constructor

Definition at line 246 of file system_norm.h.

246  :
247  _norms(s._norms), _weights(s._weights), _weights_sq(s._weights_sq)
248 {
249 }

Member Function Documentation

Real libMesh::SystemNorm::calculate_norm ( const std::vector< Real > &  v)
inline

Returns the weighted norm v^T*W*v where W represents our weights matrix or weights vector times identity matrix.

Definition at line 391 of file system_norm.h.

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

392 {
393  return this->calculate_norm(v1,v1);
394 }
Real libMesh::SystemNorm::calculate_norm ( const std::vector< Real > &  v1,
const std::vector< Real > &  v2 
)
inline

Returns the weighted inner product v1^T*W*v2 where R is our weights

Definition at line 344 of file system_norm.h.

References _off_diagonal_weights, _weights, and libMesh::Real.

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

Returns true if this is purely a discrete norm

Definition at line 253 of file system_norm.h.

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

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

254 {
255  libmesh_assert (!_norms.empty());
256 
257  if (_norms[0] == DISCRETE_L1 ||
258  _norms[0] == DISCRETE_L2 ||
259  _norms[0] == DISCRETE_L_INF)
260  return true;
261 
262  return false;
263 }
bool libMesh::SystemNorm::is_identity ( )
inline

Returns true if no weight matrix W is specified or an identiy matrix is specified, otherwise returns false

Definition at line 397 of file system_norm.h.

References _off_diagonal_weights, and _weights.

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

398 {
399  std::size_t nrows = this->_off_diagonal_weights.size();
400 
401  // If any of the off-diagonal elements is not 0, then we are in the non-identity case
402  for(std::size_t i = 0; i != nrows; i++)
403  {
404  std::size_t ncols = this->_off_diagonal_weights[i].size();
405  for(std::size_t j = 0; j != ncols; j++)
406  {
407  if(_off_diagonal_weights[i][j] != 0)
408  {
409  return(false);
410  }
411  }
412  }
413 
414  // If any of the diagonal elements is not 1, then we are in the non-identity case
415  nrows = this->_weights.size();
416  for(std::size_t i = 0; i != nrows; i++)
417  if(_weights[i] != 1)
418  return(false);
419 
420  // If all the off-diagonals elements are 0, and diagonal elements 1, then we are in an identity case
421  return(true);
422 }
void libMesh::SystemNorm::set_off_diagonal_weight ( unsigned int  i,
unsigned int  j,
Real  w 
)
inline

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

Definition at line 315 of file system_norm.h.

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

316 {
317  libmesh_assert (!_weights.empty());
318 
319  if (i >= _off_diagonal_weights.size())
320  {
321  _off_diagonal_weights.resize(i+1);
322  }
323 
324  if (j >= _off_diagonal_weights[i].size())
325  {
326  _off_diagonal_weights[i].resize(j+1, 0.);
327  }
328 
329  _off_diagonal_weights[i][j] = w;
330 
331 }
void libMesh::SystemNorm::set_type ( unsigned int  var,
const FEMNormType &  t 
)
inline

Sets the type of the norm in variable var

Definition at line 279 of file system_norm.h.

References _norms, and libMesh::libmesh_assert().

280 {
281  libmesh_assert (!_norms.empty());
282 
283  if (var >= _norms.size())
284  _norms.resize(var+1, t);
285 
286  _norms[var] = t;
287 }
void libMesh::SystemNorm::set_weight ( unsigned int  var,
Real  w 
)
inline

Sets the weight corresponding to the norm in variable var

Definition at line 300 of file system_norm.h.

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

301 {
302  libmesh_assert (!_weights.empty());
303 
304  if (var >= _weights.size())
305  {
306  _weights.resize(var+1, 1.0);
307  _weights_sq.resize(var+1, 1.0);
308  }
309 
310  _weights[var] = w;
311  _weights_sq[var] = w*w;
312 }
FEMNormType libMesh::SystemNorm::type ( unsigned int  var) const
inline
Real libMesh::SystemNorm::weight_sq ( unsigned int  var) const
inline

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

References _weights_sq, and libMesh::libmesh_assert().

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

336 {
337  libmesh_assert (!_weights_sq.empty());
338 
339  return (var < _weights_sq.size()) ? _weights_sq[var] : 1.0;
340 }

Member Data Documentation

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

Definition at line 155 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 164 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 158 of file system_norm.h.

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


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

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:32 UTC

Hosted By:
SourceForge.net Logo