#include <error_vector.h>
Inherits StatisticsVector< ErrorVectorReal >.
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)
bool is_active_elem (unsigned int i) const
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:
Definition at line 50 of file error_vector.h.
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) {}
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) {}
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;
}
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;
}
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.);
}
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;
}
Reimplemented from StatisticsVector< ErrorVectorReal >.
Definition at line 115 of file error_vector.C.
References median().
{
ErrorVector ev = (*this);
return ev.median();
}
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();
}
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;
}
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;
}
}
Definition at line 170 of file statistics.h.
References StatisticsVector< T >::variance().
{ return std::sqrt(this->variance(mean)); }
Definition at line 161 of file statistics.h.
References StatisticsVector< T >::variance().
{ return std::sqrt(this->variance()); }
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()); }
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;
}
Definition at line 162 of file error_vector.h.
Referenced by is_active_elem().
Generated automatically by Doxygen for libMesh from the source code.