Poster of Linux kernelThe best gift for a Linux geek
ErrorVector

ErrorVector

Section: C Library Functions (3) Updated: Thu Apr 7 2011
Local index Up
 

NAME

ErrorVector -  

SYNOPSIS


#include <error_vector.h>

Inherits StatisticsVector< ErrorVectorReal >.  

Public Member Functions


ErrorVector (unsigned int i=0, MeshBase *mesh=NULL)

ErrorVector (unsigned int i, ErrorVectorReal val)

virtual ErrorVectorReal minimum () const

virtual Real mean () const

virtual Real median ()

virtual Real median () const

virtual Real variance () const

virtual Real variance (const Real mean) const

virtual std::vector< unsigned int > cut_below (Real cut) const

virtual std::vector< unsigned int > cut_above (Real cut) const

void plot_error (const std::string &filename, const MeshBase &mesh) const

virtual Real l2_norm () const

virtual ErrorVectorReal maximum () const

virtual Real stddev () const

virtual Real stddev (const Real mean) const

void normalize ()

virtual void histogram (std::vector< unsigned int > &bin_members, unsigned int n_bins=10)

virtual void histogram (std::vector< unsigned int > &bin_members, unsigned int n_bins=10) const

void plot_histogram (const std::string &filename, unsigned int n_bins)
 

Protected Member Functions


bool is_active_elem (unsigned int i) const
 

Protected Attributes


MeshBase * _mesh
 

Detailed Description

The ErrorVector is a specialization of the StatisticsVector for error data computed on a finite element mesh. In general, when computing the error on a mesh only the active elements are considered, but the ErrorVector is sized according to the total number of elements in the mesh. The ErrorVector is thus padded with zeros for all the inactive elements, and this must be taken into account when calculating the statistics. Since the error is a positive quantity this class assumes it contains positive data (i.e. min_val >= 0.).

Author:

Benjamin S. Kirk, 2003.

Definition at line 50 of file error_vector.h.  

Constructor & Destructor Documentation

 

ErrorVector::ErrorVector (unsigned inti = 0, MeshBase *mesh = NULL) [inline]ErrorVector constructor; sets initial length to i.

If mesh is not null, MeshBase::elem() and Elem::is_active() will be used to distinguish active and inactive elements. If mesh is null, ErrorVector will assume that all 0.0 error values correspond to inactive elements and all non-zero error values correspond to active elements.

Definition at line 63 of file error_vector.h.

: StatisticsVector<ErrorVectorReal> (i), _mesh(mesh) {}
 

ErrorVector::ErrorVector (unsigned inti, ErrorVectorRealval) [inline]ErrorVector constructor; sets initial length to i and initial values to val.

If mesh is not null, MeshBase::elem() and Elem::is_active() will be used to distinguish active and inactive elements. If mesh is null, ErrorVector will assume that all 0.0 error values correspond to inactive elements and all non-zero error values correspond to active elements.

Definition at line 73 of file error_vector.h.

                                                   :
      StatisticsVector<ErrorVectorReal> (i,val) {}
 

Member Function Documentation

 

std::vector< unsigned int > ErrorVector::cut_above (Realcut) const [virtual]Returns a vector of unsigned ints which correspond to the indices of every member of the data set above the cutoff value cut ignoring inactive elements.

Reimplemented from StatisticsVector< ErrorVectorReal >.

Definition at line 177 of file error_vector.C.

References is_active_elem().

{
  START_LOG ('cut_above()', 'ErrorVector');

  const unsigned int n   = this->size();
  
  std::vector<unsigned int> cut_indices;
  cut_indices.reserve(n/2);  // Arbitrary 
  
  for (unsigned int i=0; i<n; i++)
    if (this->is_active_elem(i))
      {
        if ((*this)[i] > cut)
          {
            cut_indices.push_back(i);
          }
      }
  
  STOP_LOG ('cut_above()', 'ErrorVector');
  
  return cut_indices;
}
 

std::vector< unsigned int > ErrorVector::cut_below (Realcut) const [virtual]Returns a vector of unsigned ints which correspond to the indices of every member of the data set below the cutoff value cut ignoring inactive elements.

Reimplemented from StatisticsVector< ErrorVectorReal >.

Definition at line 151 of file error_vector.C.

References is_active_elem().

{
  START_LOG ('cut_below()', 'ErrorVector');
  
  const unsigned int n = this->size();
  
  std::vector<unsigned int> cut_indices;
  cut_indices.reserve(n/2);  // Arbitrary 
  
  for (unsigned int i=0; i<n; i++)
    if (this->is_active_elem(i))
      {
        if ((*this)[i] < cut)
          {
            cut_indices.push_back(i);
          }
      }
  
  STOP_LOG ('cut_below()', 'ErrorVector');
  
  return cut_indices;
}
 

virtual void StatisticsVector< ErrorVectorReal >::histogram (std::vector< unsigned int > &bin_members, unsigned intn_bins = 10) [virtual, inherited]Computes and returns a histogram with n_bins bins for the data set. For simplicity, the bins are assumed to be of uniform size. Upon return, the bin_members vector will contain unsigned integers which give the number of members in each bin. WARNING: This non-const function sorts the vector, changing its order. Source: GNU Scientific Library

 

virtual void StatisticsVector< ErrorVectorReal >::histogram (std::vector< unsigned int > &bin_members, unsigned intn_bins = 10) const [virtual, inherited]A const version of the histogram function.

 

bool ErrorVector::is_active_elem (unsigned inti) const [protected]Utility function to decide whether element i is active

Definition at line 202 of file error_vector.C.

References _mesh, Elem::active(), and MeshBase::elem().

Referenced by cut_above(), cut_below(), mean(), median(), minimum(), and variance().

{
  libmesh_assert (i < this->size());

  if (_mesh)
    {
      libmesh_assert(_mesh->elem(i));
      return _mesh->elem(i)->active();
    }
  else
    return ((*this)[i] != 0.);
}
 

virtual Real StatisticsVector< ErrorVectorReal >::l2_norm () const [virtual, inherited]Returns the l2 norm of the data set.

 

virtual ErrorVectorReal StatisticsVector< ErrorVectorReal >::maximum () const [virtual, inherited]Returns the maximum value in the data set.

 

Real ErrorVector::mean () const [virtual]Returns the mean value of the data set. Ignores zero values.

Reimplemented from StatisticsVector< ErrorVectorReal >.

Definition at line 66 of file error_vector.C.

References is_active_elem(), and mean().

Referenced by MeshRefinement::flag_elements_by_mean_stddev(), mean(), and variance().

{
  START_LOG ('mean()', 'ErrorVector');
  
  const unsigned int n = this->size();

  Real mean  = 0;
  unsigned int nnz = 0;
  
  for (unsigned int i=0; i<n; i++)
    if (this->is_active_elem(i))
      {
        mean += ( static_cast<Real>((*this)[i]) - mean ) / (nnz + 1);

        nnz++;
      }
  
  STOP_LOG ('mean()', 'ErrorVector');
  
  return mean;
}
 

Real ErrorVector::median () const [virtual]A const version of the median funtion. Requires twice the memory of original data set but does not change the original.

Reimplemented from StatisticsVector< ErrorVectorReal >.

Definition at line 115 of file error_vector.C.

References median().

{
  ErrorVector ev = (*this);

  return ev.median();
}
 

Real ErrorVector::median () [virtual]Returns the median (e.g. the middle) value of the data set, ignoring inactive elements. This function modifies the original data by sorting, so it can't be called on const objects. Source: GNU Scientific Library

Reimplemented from StatisticsVector< ErrorVectorReal >.

Definition at line 91 of file error_vector.C.

References is_active_elem(), and StatisticsVector< T >::median().

Referenced by median().

{
  const unsigned int n   = this->size();
  
  if (n == 0)
    return 0.;
  

  // Build a StatisticsVector<ErrorVectorReal> containing
  // only our active entries and take its mean
  StatisticsVector<ErrorVectorReal> sv;

  sv.reserve (n);

  for (unsigned int i=0; i<n; i++)
    if(this->is_active_elem(i))
      sv.push_back((*this)[i]);
  
  return sv.median();
}
 

ErrorVectorReal ErrorVector::minimum () const [virtual]Returns the minimum nonzero value in the data set.

Reimplemented from StatisticsVector< ErrorVectorReal >.

Definition at line 42 of file error_vector.C.

References ErrorVectorReal, is_active_elem(), std::max(), and std::min().

{
  START_LOG ('minimum()', 'ErrorVector');

  const unsigned int n = this->size();
  ErrorVectorReal min = std::numeric_limits<ErrorVectorReal>::max();
  
  for (unsigned int i=0; i<n; i++)
    {
      // Only positive (or zero) values in the error vector
      libmesh_assert((*this)[i] >= 0.);
      if (this->is_active_elem(i))
        min = std::min (min, (*this)[i]);
    }
  STOP_LOG ('minimum()', 'ErrorVector');

  // ErrorVectors are for positive values
  libmesh_assert (min >= 0.);
  
  return min;
}
 

void StatisticsVector< ErrorVectorReal >::normalize () [inherited]Divides all entries by the largest entry and stores the result

 

void ErrorVector::plot_error (const std::string &filename, const MeshBase &mesh) constPlots a data file, of a type determined by looking at the file extension in filename, of the error values on the active elements of mesh.

Definition at line 216 of file error_vector.C.

References MeshBase::active_local_elements_begin(), MeshBase::active_local_elements_end(), EquationSystems::add_system(), System::add_variable(), MeshBase::all_first_order(), MeshBase::clone(), libMeshEnums::CONSTANT, DofMap::dof_indices(), System::get_dof_map(), DofObject::id(), EquationSystems::init(), libMeshEnums::MONOMIAL, System::solution, GMVIO::write_discontinuous_gmv(), and MeshOutput< MT >::write_equation_systems().

Referenced by AdjointResidualErrorEstimator::estimate_error().

{
  AutoPtr<MeshBase> meshptr = oldmesh.clone();
  MeshBase &mesh = *meshptr;
  mesh.all_first_order();
  EquationSystems temp_es (mesh);
  ExplicitSystem& error_system
    = temp_es.add_system<ExplicitSystem> ('Error');
  error_system.add_variable('e', CONSTANT, MONOMIAL);
  temp_es.init();

  const DofMap& error_dof_map = error_system.get_dof_map();

  MeshBase::const_element_iterator       el     =
    mesh.active_local_elements_begin();
  const MeshBase::const_element_iterator end_el =
    mesh.active_local_elements_end();
  std::vector<unsigned int> dof_indices;

  for ( ; el != end_el; ++el)
  {
    Elem* elem = *el;

    error_dof_map.dof_indices(elem, dof_indices);

    const unsigned int elem_id = elem->id();

    //0 for the monomial basis
    const unsigned int solution_index = dof_indices[0];
    // std::cout << 'elem_number=' << elem_number << std::endl;
    libmesh_assert (elem_id < (*this).size());
//  We may have zero error values in special circumstances
//    libmesh_assert ((*this)[elem_id] > 0.);
    error_system.solution->set(solution_index, (*this)[elem_id]);
  }

  if (filename.rfind('.gmv') < filename.size())
    {
//      GMVIO(mesh).write_equation_systems(filename,
//                                         temp_es);
// write_discontinuous_gmv doesn't work on second order meshes??
// [RHS]
      GMVIO(mesh).write_discontinuous_gmv(filename,
                                          temp_es, false);
    }
  else if (filename.rfind('.plt') < filename.size())
    {
      TecplotIO (mesh).write_equation_systems
        (filename, temp_es);
    }
  else
    {
      libmesh_here();
      std::cerr << 'Warning: ErrorVector::plot_error currently only'
                << ' supports .gmv and .plt output;' << std::endl;
      std::cerr << 'Could not recognize filename: ' << filename
                << std::endl;
    }
}
 

void StatisticsVector< ErrorVectorReal >::plot_histogram (const std::string &filename, unsigned intn_bins) [inherited]Generates a Matlab/Octave style file which can be used to make a plot of the histogram having the desired number of bins. Uses the histogram(...) function in this class WARNING: The histogram(...) function is non-const, and changes the order of the vector.

 

virtual Real StatisticsVector< ErrorVectorReal >::stddev (const Realmean) const [inline, virtual, inherited]Computes the standard deviation of the data set, which is simply the square-root of the variance. This method can be used for efficiency when the mean has already been computed.

Definition at line 170 of file statistics.h.

References StatisticsVector< T >::variance().

  { return std::sqrt(this->variance(mean)); }
 

virtual Real StatisticsVector< ErrorVectorReal >::stddev () const [inline, virtual, inherited]Computes the standard deviation of the data set, which is simply the square-root of the variance.

Definition at line 161 of file statistics.h.

References StatisticsVector< T >::variance().

  { return std::sqrt(this->variance()); }
 

virtual Real ErrorVector::variance () const [inline, virtual]Computes the variance of the data set ignoring inactive elements. Uses a recurrence relation to prevent data overflow for large sums. Note: The variance is equal to the standard deviation squared. The variance is normalized by N in this case. Source: GNU Scientific Library

Reimplemented from StatisticsVector< ErrorVectorReal >.

Definition at line 114 of file error_vector.h.

References mean(), and variance().

Referenced by MeshRefinement::flag_elements_by_mean_stddev(), and variance().

  { return this->variance(this->mean()); }
 

Real ErrorVector::variance (const Realmean) const [virtual]Computes the variance of the data set ignoring inactive elements. where the mean is provided. This is useful for efficiency when you have already calculated the mean. Uses a recurrence relation to prevent data overflow for large sums. Note: The variance is equal to the standard deviation squared. Source: GNU Scientific Library

Reimplemented from StatisticsVector< ErrorVectorReal >.

Definition at line 125 of file error_vector.C.

References is_active_elem(), and variance().

{
  const unsigned int n   = this->size();
  
  START_LOG ('variance()', 'ErrorVector');
  
  Real variance = 0;
  unsigned int nnz = 0;
  
  for (unsigned int i=0; i<n; i++)
    if (this->is_active_elem(i))
      {
        const Real delta = ( static_cast<Real>((*this)[i]) - mean );
        variance += (delta * delta - variance) / (nnz + 1);

        nnz++;
      }
  
  STOP_LOG ('variance()', 'ErrorVector');
  
  return variance;
}
 

Member Data Documentation

 

MeshBase* ErrorVector::_mesh [protected]Pointer to the mesh, which may be used to decide which elements are active

Definition at line 162 of file error_vector.h.

Referenced by is_active_elem().

 

Author

Generated automatically by Doxygen for libMesh from the source code.


 

Index

NAME
SYNOPSIS
Public Member Functions
Protected Member Functions
Protected Attributes
Detailed Description
Constructor & Destructor Documentation
ErrorVector::ErrorVector (unsigned inti = 0, MeshBase *mesh = NULL) [inline]ErrorVector constructor; sets initial length to i.
ErrorVector::ErrorVector (unsigned inti, ErrorVectorRealval) [inline]ErrorVector constructor; sets initial length to i and initial values to val.
Member Function Documentation
std::vector< unsigned int > ErrorVector::cut_above (Realcut) const [virtual]Returns a vector of unsigned ints which correspond to the indices of every member of the data set above the cutoff value cut ignoring inactive elements.
std::vector< unsigned int > ErrorVector::cut_below (Realcut) const [virtual]Returns a vector of unsigned ints which correspond to the indices of every member of the data set below the cutoff value cut ignoring inactive elements.
virtual void StatisticsVector< ErrorVectorReal >::histogram (std::vector< unsigned int > &bin_members, unsigned intn_bins = 10) [virtual, inherited]Computes and returns a histogram with n_bins bins for the data set. For simplicity, the bins are assumed to be of uniform size. Upon return, the bin_members vector will contain unsigned integers which give the number of members in each bin. WARNING: This non-const function sorts the vector, changing its order. Source: GNU Scientific Library
virtual void StatisticsVector< ErrorVectorReal >::histogram (std::vector< unsigned int > &bin_members, unsigned intn_bins = 10) const [virtual, inherited]A const version of the histogram function.
bool ErrorVector::is_active_elem (unsigned inti) const [protected]Utility function to decide whether element i is active
virtual Real StatisticsVector< ErrorVectorReal >::l2_norm () const [virtual, inherited]Returns the l2 norm of the data set.
virtual ErrorVectorReal StatisticsVector< ErrorVectorReal >::maximum () const [virtual, inherited]Returns the maximum value in the data set.
Real ErrorVector::mean () const [virtual]Returns the mean value of the data set. Ignores zero values.
Real ErrorVector::median () const [virtual]A const version of the median funtion. Requires twice the memory of original data set but does not change the original.
Real ErrorVector::median () [virtual]Returns the median (e.g. the middle) value of the data set, ignoring inactive elements. This function modifies the original data by sorting, so it can't be called on const objects. Source: GNU Scientific Library
ErrorVectorReal ErrorVector::minimum () const [virtual]Returns the minimum nonzero value in the data set.
void StatisticsVector< ErrorVectorReal >::normalize () [inherited]Divides all entries by the largest entry and stores the result
void ErrorVector::plot_error (const std::string &filename, const MeshBase &mesh) constPlots a data file, of a type determined by looking at the file extension in filename, of the error values on the active elements of mesh.
void StatisticsVector< ErrorVectorReal >::plot_histogram (const std::string &filename, unsigned intn_bins) [inherited]Generates a Matlab/Octave style file which can be used to make a plot of the histogram having the desired number of bins. Uses the histogram(...) function in this class WARNING: The histogram(...) function is non-const, and changes the order of the vector.
virtual Real StatisticsVector< ErrorVectorReal >::stddev (const Realmean) const [inline, virtual, inherited]Computes the standard deviation of the data set, which is simply the square-root of the variance. This method can be used for efficiency when the mean has already been computed.
virtual Real StatisticsVector< ErrorVectorReal >::stddev () const [inline, virtual, inherited]Computes the standard deviation of the data set, which is simply the square-root of the variance.
virtual Real ErrorVector::variance () const [inline, virtual]Computes the variance of the data set ignoring inactive elements. Uses a recurrence relation to prevent data overflow for large sums. Note: The variance is equal to the standard deviation squared. The variance is normalized by N in this case. Source: GNU Scientific Library
Real ErrorVector::variance (const Realmean) const [virtual]Computes the variance of the data set ignoring inactive elements. where the mean is provided. This is useful for efficiency when you have already calculated the mean. Uses a recurrence relation to prevent data overflow for large sums. Note: The variance is equal to the standard deviation squared. Source: GNU Scientific Library
Member Data Documentation
MeshBase* ErrorVector::_mesh [protected]Pointer to the mesh, which may be used to decide which elements are active
Author

This document was created by man2html, using the manual pages.
Time: 21:45:40 GMT, April 16, 2011