$extrastylesheet
libMesh::ErrorVector Class Reference

#include <error_vector.h>

Inheritance diagram for libMesh::ErrorVector:

List of all members.

Public Member Functions

 ErrorVector (dof_id_type i=0, MeshBase *mesh=NULL)
 ErrorVector (dof_id_type 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< dof_id_typecut_below (Real cut) const
virtual std::vector< dof_id_typecut_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 known_mean) const
void normalize ()
virtual void histogram (std::vector< dof_id_type > &bin_members, unsigned int n_bins=10)
virtual void histogram (std::vector< dof_id_type > &bin_members, unsigned int n_bins=10) const
void plot_histogram (const processor_id_type my_procid, const std::string &filename, unsigned int n_bins)

Protected Member Functions

bool is_active_elem (dof_id_type 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 52 of file error_vector.h.


Constructor & Destructor Documentation

libMesh::ErrorVector::ErrorVector ( dof_id_type  i = 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 65 of file error_vector.h.

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

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 75 of file error_vector.h.

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

Member Function Documentation

std::vector< dof_id_type > libMesh::ErrorVector::cut_above ( Real  cut) const [virtual]

Returns a vector of dof_id_types which correspond to the indices of every member of the data set above the cutoff value cut ignoring inactive elements.

Reimplemented from libMesh::StatisticsVector< ErrorVectorReal >.

Definition at line 178 of file error_vector.C.

References is_active_elem(), and libMesh::START_LOG().

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

  const dof_id_type n = cast_int<dof_id_type>(this->size());

  std::vector<dof_id_type> cut_indices;
  cut_indices.reserve(n/2);  // Arbitrary

  for (dof_id_type 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< dof_id_type > libMesh::ErrorVector::cut_below ( Real  cut) const [virtual]

Returns a vector of dof_id_types which correspond to the indices of every member of the data set below the cutoff value cut ignoring inactive elements.

Reimplemented from libMesh::StatisticsVector< ErrorVectorReal >.

Definition at line 152 of file error_vector.C.

References is_active_elem(), and libMesh::START_LOG().

{
  START_LOG ("cut_below()", "ErrorVector");

  const dof_id_type n = cast_int<dof_id_type>(this->size());

  std::vector<dof_id_type> cut_indices;
  cut_indices.reserve(n/2);  // Arbitrary

  for (dof_id_type 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 libMesh::StatisticsVector< ErrorVectorReal >::histogram ( std::vector< dof_id_type > &  bin_members,
unsigned int  n_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 libMesh::StatisticsVector< ErrorVectorReal >::histogram ( std::vector< dof_id_type > &  bin_members,
unsigned int  n_bins = 10 
) const [virtual, inherited]

A const version of the histogram function.

bool libMesh::ErrorVector::is_active_elem ( dof_id_type  i) const [protected]

Utility function to decide whether element i is active

Definition at line 203 of file error_vector.C.

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

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

{
  libmesh_assert_less (i, this->size());

  if (_mesh)
    {
      libmesh_assert(_mesh->elem(i));
      return _mesh->elem(i)->active();
    }
  else
    return ((*this)[i] != 0.);
}
virtual Real libMesh::StatisticsVector< ErrorVectorReal >::l2_norm ( ) const [virtual, inherited]

Returns the l2 norm of the data set.

virtual ErrorVectorReal libMesh::StatisticsVector< ErrorVectorReal >::maximum ( ) const [virtual, inherited]

Returns the maximum value in the data set.

Real libMesh::ErrorVector::mean ( ) const [virtual]

Returns the mean value of the data set. Ignores zero values.

Reimplemented from libMesh::StatisticsVector< ErrorVectorReal >.

Definition at line 67 of file error_vector.C.

References is_active_elem(), libMesh::Real, and libMesh::START_LOG().

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

{
  START_LOG ("mean()", "ErrorVector");

  const dof_id_type n = cast_int<dof_id_type>(this->size());

  Real the_mean  = 0;
  dof_id_type nnz = 0;

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

        nnz++;
      }

  STOP_LOG ("mean()", "ErrorVector");

  return the_mean;
}

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 libMesh::StatisticsVector< ErrorVectorReal >.

Definition at line 92 of file error_vector.C.

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

Referenced by median().

{
  const dof_id_type n = cast_int<dof_id_type>(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 (dof_id_type i=0; i<n; i++)
    if(this->is_active_elem(i))
      sv.push_back((*this)[i]);

  return sv.median();
}
Real libMesh::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 libMesh::StatisticsVector< ErrorVectorReal >.

Definition at line 116 of file error_vector.C.

References median().

{
  ErrorVector ev = (*this);

  return ev.median();
}

Returns the minimum nonzero value in the data set.

Reimplemented from libMesh::StatisticsVector< ErrorVectorReal >.

Definition at line 43 of file error_vector.C.

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

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

  const dof_id_type n = cast_int<dof_id_type>(this->size());
  ErrorVectorReal min = std::numeric_limits<ErrorVectorReal>::max();

  for (dof_id_type i=0; i<n; i++)
    {
      // Only positive (or zero) values in the error vector
      libmesh_assert_greater_equal ((*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_greater_equal (min, 0.);

  return min;
}

Divides all entries by the largest entry and stores the result

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

Plots 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 217 of file error_vector.C.

References libMesh::MeshBase::active_local_elements_begin(), libMesh::MeshBase::active_local_elements_end(), libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshBase::all_first_order(), libMesh::MeshBase::allow_renumbering(), libMesh::MeshBase::clone(), libMesh::CONSTANT, libMesh::DofMap::dof_indices(), libMesh::err, libMesh::System::get_dof_map(), libMesh::DofObject::id(), libMesh::EquationSystems::init(), libMesh::MeshBase::max_elem_id(), libMesh::MeshBase::max_node_id(), mesh, libMesh::MONOMIAL, libMesh::MeshBase::n_elem(), libMesh::MeshBase::n_nodes(), libMesh::MeshBase::renumber_nodes_and_elements(), libMesh::System::solution, libMesh::ExodusII_IO::write(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::ExodusII_IO::write_element_data(), and libMesh::MeshOutput< MT >::write_equation_systems().

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

{
  UniquePtr<MeshBase> meshptr = oldmesh.clone();
  MeshBase &mesh = *meshptr;

  // The all_first_order routine requires that renumbering be allowed
  mesh.allow_renumbering(true);

  mesh.all_first_order();
  EquationSystems temp_es (mesh);
  ExplicitSystem& error_system
    = temp_es.add_system<ExplicitSystem> ("Error");
  error_system.add_variable("error", 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<dof_id_type> dof_indices;

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

      error_dof_map.dof_indices(elem, dof_indices);

      const dof_id_type elem_id = elem->id();

      //0 for the monomial basis
      const dof_id_type solution_index = dof_indices[0];

      // libMesh::out << "elem_number=" << elem_number << std::endl;
      libmesh_assert_less (elem_id, (*this).size());

      // We may have zero error values in special circumstances
      // libmesh_assert_greater ((*this)[elem_id], 0.);
      error_system.solution->set(solution_index, (*this)[elem_id]);
    }

  // We may have to renumber if the original numbering was not
  // contiguous.  Since this is just a temporary mesh, that's probably
  // fine.
  if (mesh.max_elem_id() != mesh.n_elem() ||
      mesh.max_node_id() != mesh.n_nodes())
    {
      mesh.allow_renumbering(true);
      mesh.renumber_nodes_and_elements();
    }

  if (filename.rfind(".gmv") < filename.size())
    {
      GMVIO(mesh).write_discontinuous_gmv(filename,
                                          temp_es, false);
    }
  else if (filename.rfind(".plt") < filename.size())
    {
      TecplotIO (mesh).write_equation_systems
        (filename, temp_es);
    }
#ifdef LIBMESH_HAVE_EXODUS_API
  else if( (filename.rfind(".exo") < filename.size()) ||
           (filename.rfind(".e") < filename.size()) )
    {
      ExodusII_IO io(mesh);
      io.write(filename);
      io.write_element_data(temp_es);
    }
#endif
  else
    {
      libmesh_here();
      libMesh::err << "Warning: ErrorVector::plot_error currently only"
                   << " supports .gmv and .plt and .exo/.e (if enabled) output;" << std::endl;
      libMesh::err << "Could not recognize filename: " << filename
                   << std::endl;
    }
}
void libMesh::StatisticsVector< ErrorVectorReal >::plot_histogram ( const processor_id_type  my_procid,
const std::string &  filename,
unsigned int  n_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 libMesh::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 165 of file statistics.h.

References libMesh::StatisticsVector< T >::variance().

  { return std::sqrt(this->variance()); }
virtual Real libMesh::StatisticsVector< ErrorVectorReal >::stddev ( const Real  known_mean) 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 174 of file statistics.h.

References libMesh::StatisticsVector< T >::variance().

  { return std::sqrt(this->variance(known_mean)); }
virtual Real libMesh::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 libMesh::StatisticsVector< ErrorVectorReal >.

Definition at line 116 of file error_vector.h.

References mean(), and variance().

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

  { return this->variance(this->mean()); }
Real libMesh::ErrorVector::variance ( const Real  mean) 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 libMesh::StatisticsVector< ErrorVectorReal >.

Definition at line 126 of file error_vector.C.

References is_active_elem(), libMesh::Real, and libMesh::START_LOG().

{
  const dof_id_type n = cast_int<dof_id_type>(this->size());

  START_LOG ("variance()", "ErrorVector");

  Real the_variance = 0;
  dof_id_type nnz = 0;

  for (dof_id_type i=0; i<n; i++)
    if (this->is_active_elem(i))
      {
        const Real delta = ( static_cast<Real>((*this)[i]) - mean_in );
        the_variance += (delta * delta - the_variance) / (nnz + 1);

        nnz++;
      }

  STOP_LOG ("variance()", "ErrorVector");

  return the_variance;
}

Member Data Documentation

Pointer to the mesh, which may be used to decide which elements are active

Definition at line 164 of file error_vector.h.

Referenced by is_active_elem().


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