libMesh::ErrorVector Class Reference

#include <error_vector.h>

Inheritance diagram for libMesh::ErrorVector:

Public Member Functions

 ErrorVector (dof_id_type i=0, MeshBase *mesh=nullptr)
 
 ErrorVector (dof_id_type i, ErrorVectorReal val)
 
virtual ErrorVectorReal minimum () const override
 
virtual Real mean () const override
 
virtual Real median () override
 
virtual Real median () const override
 
virtual Real variance () const override
 
virtual Real variance (const Real mean) const override
 
virtual std::vector< dof_id_typecut_below (Real cut) const override
 
virtual std::vector< dof_id_typecut_above (Real cut) const override
 
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
Date
2003

Definition at line 50 of file error_vector.h.

Constructor & Destructor Documentation

◆ ErrorVector() [1/2]

libMesh::ErrorVector::ErrorVector ( dof_id_type  i = 0,
MeshBase mesh = nullptr 
)
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 62 of file error_vector.h.

62  :
63  StatisticsVector<ErrorVectorReal> (i),
64  _mesh(mesh)
65  {}
MeshBase & mesh

◆ ErrorVector() [2/2]

libMesh::ErrorVector::ErrorVector ( dof_id_type  i,
ErrorVectorReal  val 
)
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 75 of file error_vector.h.

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

Member Function Documentation

◆ cut_above()

std::vector< dof_id_type > libMesh::ErrorVector::cut_above ( Real  cut) const
overridevirtual
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 174 of file error_vector.C.

References is_active_elem().

175 {
176  LOG_SCOPE ("cut_above()", "ErrorVector");
177 
178  const dof_id_type n = cast_int<dof_id_type>(this->size());
179 
180  std::vector<dof_id_type> cut_indices;
181  cut_indices.reserve(n/2); // Arbitrary
182 
183  for (dof_id_type i=0; i<n; i++)
184  if (this->is_active_elem(i))
185  {
186  if ((*this)[i] > cut)
187  {
188  cut_indices.push_back(i);
189  }
190  }
191 
192  return cut_indices;
193 }
bool is_active_elem(dof_id_type i) const
Definition: error_vector.C:197
uint8_t dof_id_type
Definition: id_types.h:64

◆ cut_below()

std::vector< dof_id_type > libMesh::ErrorVector::cut_below ( Real  cut) const
overridevirtual
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 150 of file error_vector.C.

References is_active_elem().

151 {
152  LOG_SCOPE ("cut_below()", "ErrorVector");
153 
154  const dof_id_type n = cast_int<dof_id_type>(this->size());
155 
156  std::vector<dof_id_type> cut_indices;
157  cut_indices.reserve(n/2); // Arbitrary
158 
159  for (dof_id_type i=0; i<n; i++)
160  if (this->is_active_elem(i))
161  {
162  if ((*this)[i] < cut)
163  {
164  cut_indices.push_back(i);
165  }
166  }
167 
168  return cut_indices;
169 }
bool is_active_elem(dof_id_type i) const
Definition: error_vector.C:197
uint8_t dof_id_type
Definition: id_types.h:64

◆ histogram() [1/2]

void libMesh::StatisticsVector< ErrorVectorReal >::histogram ( std::vector< dof_id_type > &  bin_members,
unsigned int  n_bins = 10 
)
virtualinherited
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.

Definition at line 178 of file statistics.C.

References end, std::max(), std::min(), libMesh::out, and libMesh::Real.

180 {
181  // Must have at least 1 bin
182  libmesh_assert (n_bins>0);
183 
184  const dof_id_type n = cast_int<dof_id_type>(this->size());
185 
186  std::sort(this->begin(), this->end());
187 
188  // The StatisticsVector can hold both integer and float types.
189  // We will define all the bins, etc. using Reals.
190  Real min = static_cast<Real>(this->minimum());
191  Real max = static_cast<Real>(this->maximum());
192  Real bin_size = (max - min) / static_cast<Real>(n_bins);
193 
194  LOG_SCOPE ("histogram()", "StatisticsVector");
195 
196  std::vector<Real> bin_bounds(n_bins+1);
197  for (std::size_t i=0; i<bin_bounds.size(); i++)
198  bin_bounds[i] = min + Real(i) * bin_size;
199 
200  // Give the last bin boundary a little wiggle room: we don't want
201  // it to be just barely less than the max, otherwise our bin test below
202  // may fail.
203  bin_bounds.back() += 1.e-6 * bin_size;
204 
205  // This vector will store the number of members each bin has.
206  bin_members.resize(n_bins);
207 
208  dof_id_type data_index = 0;
209  for (std::size_t j=0; j<bin_members.size(); j++) // bin vector indexing
210  {
211  // libMesh::out << "(debug) Filling bin " << j << std::endl;
212 
213  for (dof_id_type i=data_index; i<n; i++) // data vector indexing
214  {
215  //libMesh::out << "(debug) Processing index=" << i << std::endl;
216  Real current_val = static_cast<Real>( (*this)[i] );
217 
218  // There may be entries in the vector smaller than the value
219  // reported by this->minimum(). (e.g. inactive elements in an
220  // ErrorVector.) We just skip entries like that.
221  if (current_val < min)
222  {
223  // libMesh::out << "(debug) Skipping entry v[" << i << "]="
224  // << (*this)[i]
225  // << " which is less than the min value: min="
226  // << min << std::endl;
227  continue;
228  }
229 
230  if (current_val > bin_bounds[j+1]) // if outside the current bin (bin[j] is bounded
231  // by bin_bounds[j] and bin_bounds[j+1])
232  {
233  // libMesh::out.precision(16);
234  // libMesh::out.setf(std::ios_base::fixed);
235  // libMesh::out << "(debug) (*this)[i]= " << (*this)[i]
236  // << " is greater than bin_bounds[j+1]="
237  // << bin_bounds[j+1] << std::endl;
238  data_index = i; // start searching here for next bin
239  break; // go to next bin
240  }
241 
242  // Otherwise, increment current bin's count
243  bin_members[j]++;
244  // libMesh::out << "(debug) Binned index=" << i << std::endl;
245  }
246  }
247 
248 #ifdef DEBUG
249  // Check the number of binned entries
250  const dof_id_type n_binned = std::accumulate(bin_members.begin(),
251  bin_members.end(),
252  static_cast<dof_id_type>(0),
253  std::plus<dof_id_type>());
254 
255  if (n != n_binned)
256  {
257  libMesh::out << "Warning: The number of binned entries, n_binned="
258  << n_binned
259  << ", did not match the total number of entries, n="
260  << n << "." << std::endl;
261  }
262 #endif
263 }
virtual ErrorVectorReal maximum() const
Definition: statistics.C:61
IterBase * end
long double max(long double a, double b)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual ErrorVectorReal minimum() const
Definition: statistics.C:48
OStreamProxy out(std::cout)
long double min(long double a, double b)
uint8_t dof_id_type
Definition: id_types.h:64

◆ histogram() [2/2]

void libMesh::StatisticsVector< ErrorVectorReal >::histogram ( std::vector< dof_id_type > &  bin_members,
unsigned int  n_bins = 10 
) const
virtualinherited

A const version of the histogram function.

Definition at line 313 of file statistics.C.

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

315 {
316  StatisticsVector<T> sv = (*this);
317 
318  return sv.histogram(bin_members, n_bins);
319 }

◆ is_active_elem()

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

Utility function to decide whether element i is active

Definition at line 197 of file error_vector.C.

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

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

198 {
199  libmesh_assert_less (i, this->size());
200 
201  if (_mesh)
202  {
203  return _mesh->elem_ptr(i)->active();
204  }
205  else
206  return ((*this)[i] != 0.);
207 }
virtual const Elem * elem_ptr(const dof_id_type i) const =0
bool active() const
Definition: elem.h:2390

◆ l2_norm()

Real libMesh::StatisticsVector< ErrorVectorReal >::l2_norm ( ) const
virtualinherited
Returns
The l2 norm of the data set.

Definition at line 36 of file statistics.C.

References libMesh::Real.

37 {
38  Real normsq = 0.;
39  const dof_id_type n = cast_int<dof_id_type>(this->size());
40  for (dof_id_type i = 0; i != n; ++i)
41  normsq += ((*this)[i] * (*this)[i]);
42 
43  return std::sqrt(normsq);
44 }
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t dof_id_type
Definition: id_types.h:64

◆ maximum()

ErrorVectorReal libMesh::StatisticsVector< ErrorVectorReal >::maximum ( ) const
virtualinherited
Returns
The maximum value in the data set.

Definition at line 61 of file statistics.C.

References end, and std::max().

62 {
63  LOG_SCOPE ("maximum()", "StatisticsVector");
64 
65  const T max = *(std::max_element(this->begin(), this->end()));
66 
67  return max;
68 }
IterBase * end
long double max(long double a, double b)

◆ mean()

Real libMesh::ErrorVector::mean ( ) const
overridevirtual
Returns
The mean value of the data set. Ignores zero values.

Reimplemented from libMesh::StatisticsVector< ErrorVectorReal >.

Definition at line 69 of file error_vector.C.

References is_active_elem(), and libMesh::Real.

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

70 {
71  LOG_SCOPE ("mean()", "ErrorVector");
72 
73  const dof_id_type n = cast_int<dof_id_type>(this->size());
74 
75  Real the_mean = 0;
76  dof_id_type nnz = 0;
77 
78  for (dof_id_type i=0; i<n; i++)
79  if (this->is_active_elem(i))
80  {
81  the_mean += ( static_cast<Real>((*this)[i]) - the_mean ) / (nnz + 1);
82 
83  nnz++;
84  }
85 
86  return the_mean;
87 }
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
bool is_active_elem(dof_id_type i) const
Definition: error_vector.C:197
uint8_t dof_id_type
Definition: id_types.h:64

◆ median() [1/2]

Real libMesh::ErrorVector::median ( )
overridevirtual
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().

93 {
94  const dof_id_type n = cast_int<dof_id_type>(this->size());
95 
96  if (n == 0)
97  return 0.;
98 
99 
100  // Build a StatisticsVector<ErrorVectorReal> containing
101  // only our active entries and take its mean
102  StatisticsVector<ErrorVectorReal> sv;
103 
104  sv.reserve (n);
105 
106  for (dof_id_type i=0; i<n; i++)
107  if (this->is_active_elem(i))
108  sv.push_back((*this)[i]);
109 
110  return sv.median();
111 }
bool is_active_elem(dof_id_type i) const
Definition: error_vector.C:197
uint8_t dof_id_type
Definition: id_types.h:64

◆ median() [2/2]

Real libMesh::ErrorVector::median ( ) const
overridevirtual

A const version of the median function. 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().

117 {
118  ErrorVector ev = (*this);
119 
120  return ev.median();
121 }
ErrorVector(dof_id_type i=0, MeshBase *mesh=nullptr)
Definition: error_vector.h:62

◆ minimum()

ErrorVectorReal libMesh::ErrorVector::minimum ( ) const
overridevirtual
Returns
The minimum nonzero value in the data set.

Reimplemented from libMesh::StatisticsVector< ErrorVectorReal >.

Definition at line 46 of file error_vector.C.

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

47 {
48  LOG_SCOPE ("minimum()", "ErrorVector");
49 
50  const dof_id_type n = cast_int<dof_id_type>(this->size());
52 
53  for (dof_id_type i=0; i<n; i++)
54  {
55  // Only positive (or zero) values in the error vector
56  libmesh_assert_greater_equal ((*this)[i], 0.);
57  if (this->is_active_elem(i))
58  min = std::min (min, (*this)[i]);
59  }
60 
61  // ErrorVectors are for positive values
62  libmesh_assert_greater_equal (min, 0.);
63 
64  return min;
65 }
long double max(long double a, double b)
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
bool is_active_elem(dof_id_type i) const
Definition: error_vector.C:197
long double min(long double a, double b)
uint8_t dof_id_type
Definition: id_types.h:64

◆ normalize()

void libMesh::StatisticsVector< ErrorVectorReal >::normalize ( )
inherited

Divides all entries by the largest entry and stores the result.

Definition at line 164 of file statistics.C.

References std::max(), and libMesh::Real.

165 {
166  const dof_id_type n = cast_int<dof_id_type>(this->size());
167  const Real max = this->maximum();
168 
169  for (dof_id_type i=0; i<n; i++)
170  (*this)[i] = static_cast<T>((*this)[i] / max);
171 }
virtual ErrorVectorReal maximum() const
Definition: statistics.C:61
long double max(long double a, double b)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t dof_id_type
Definition: id_types.h:64

◆ plot_error()

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

References libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshBase::clone(), libMesh::CONSTANT, libMesh::Elem::DO_NOTHING, libMesh::DofMap::dof_indices(), libMesh::ENCODE, libMesh::err, libMesh::System::get_dof_map(), libMesh::EquationSystems::init(), mesh, libMesh::MONOMIAL, libMesh::System::solution, libMesh::WRITE, libMesh::Nemesis_IO::write(), libMesh::ExodusII_IO::write(), libMesh::XdrIO::write(), libMesh::EquationSystems::write(), libMesh::EquationSystems::WRITE_ADDITIONAL_DATA, libMesh::EquationSystems::WRITE_DATA, libMesh::GMVIO::write_discontinuous_gmv(), libMesh::Nemesis_IO::write_element_data(), libMesh::ExodusII_IO::write_element_data(), and libMesh::MeshOutput< MT >::write_equation_systems().

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

212 {
213  std::unique_ptr<MeshBase> meshptr = oldmesh.clone();
214  MeshBase & mesh = *meshptr;
215 
216  // The all_first_order routine will prepare_for_use(), which would
217  // break our ordering if elements get changed.
218  mesh.allow_renumbering(false);
219  mesh.all_first_order();
220 
221 #ifdef LIBMESH_ENABLE_AMR
222  // We don't want p elevation when plotting a single constant value
223  // per element
224  for (auto & elem : mesh.element_ptr_range())
225  {
226  elem->set_p_refinement_flag(Elem::DO_NOTHING);
227  elem->set_p_level(0);
228  }
229 #endif // LIBMESH_ENABLE_AMR
230 
231  EquationSystems temp_es (mesh);
232  ExplicitSystem & error_system
233  = temp_es.add_system<ExplicitSystem> ("Error");
234  error_system.add_variable("error", CONSTANT, MONOMIAL);
235  temp_es.init();
236 
237  const DofMap & error_dof_map = error_system.get_dof_map();
238  std::vector<dof_id_type> dof_indices;
239 
240  for (const auto & elem : mesh.active_local_element_ptr_range())
241  {
242  error_dof_map.dof_indices(elem, dof_indices);
243 
244  const dof_id_type elem_id = elem->id();
245 
246  //0 for the monomial basis
247  const dof_id_type solution_index = dof_indices[0];
248 
249  // libMesh::out << "elem_number=" << elem_number << std::endl;
250  libmesh_assert_less (elem_id, (*this).size());
251 
252  // We may have zero error values in special circumstances
253  // libmesh_assert_greater ((*this)[elem_id], 0.);
254  error_system.solution->set(solution_index, (*this)[elem_id]);
255  }
256 
257  error_system.solution->close();
258 
259  // We may have to renumber if the original numbering was not
260  // contiguous. Since this is just a temporary mesh, that's probably
261  // fine.
262  if (mesh.max_elem_id() != mesh.n_elem() ||
263  mesh.max_node_id() != mesh.n_nodes())
264  {
265  mesh.allow_renumbering(true);
266  mesh.renumber_nodes_and_elements();
267  }
268 
269  if (filename.rfind(".gmv") < filename.size())
270  {
271  GMVIO(mesh).write_discontinuous_gmv(filename,
272  temp_es, false);
273  }
274  else if (filename.rfind(".plt") < filename.size())
275  {
276  TecplotIO (mesh).write_equation_systems
277  (filename, temp_es);
278  }
279 #if defined(LIBMESH_HAVE_EXODUS_API) && defined(LIBMESH_HAVE_NEMESIS_API)
280  else if ((filename.rfind(".nem") < filename.size()) ||
281  (filename.rfind(".n") < filename.size()))
282  {
283  Nemesis_IO io(mesh);
284  io.write(filename);
285  io.write_element_data(temp_es);
286  }
287 #endif
288 #ifdef LIBMESH_HAVE_EXODUS_API
289  else if ((filename.rfind(".exo") < filename.size()) ||
290  (filename.rfind(".e") < filename.size()))
291  {
292  ExodusII_IO io(mesh);
293  io.write(filename);
294  io.write_element_data(temp_es);
295  }
296 #endif
297  else if (filename.rfind(".xda") < filename.size())
298  {
299  XdrIO(mesh).write("mesh-"+filename);
300  temp_es.write("soln-"+filename,WRITE,
303  }
304  else if (filename.rfind(".xdr") < filename.size())
305  {
306  XdrIO(mesh,true).write("mesh-"+filename);
307  temp_es.write("soln-"+filename,ENCODE,
310  }
311  else
312  {
313  libmesh_here();
314  libMesh::err << "Warning: ErrorVector::plot_error currently only"
315  << " supports .gmv, .plt, .xdr/.xda, and .exo/.e (if enabled) output;" << std::endl;
316  libMesh::err << "Could not recognize filename: " << filename
317  << std::endl;
318  }
319 }
MeshBase & mesh
OStreamProxy err(std::cerr)
uint8_t dof_id_type
Definition: id_types.h:64

◆ plot_histogram()

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.

Definition at line 270 of file statistics.C.

References std::max(), std::min(), and libMesh::Real.

273 {
274  // First generate the histogram with the desired number of bins
275  std::vector<dof_id_type> bin_members;
276  this->histogram(bin_members, n_bins);
277 
278  // The max, min and bin size are used to generate x-axis values.
279  T min = this->minimum();
280  T max = this->maximum();
281  T bin_size = (max - min) / static_cast<T>(n_bins);
282 
283  // On processor 0: Write histogram to file
284  if (my_procid==0)
285  {
286  std::ofstream out_stream (filename.c_str());
287 
288  out_stream << "clear all\n";
289  out_stream << "clf\n";
290  //out_stream << "x=linspace(" << min << "," << max << "," << n_bins+1 << ");\n";
291 
292  // abscissa values are located at the center of each bin.
293  out_stream << "x=[";
294  for (std::size_t i=0; i<bin_members.size(); ++i)
295  {
296  out_stream << min + (Real(i)+0.5)*bin_size << " ";
297  }
298  out_stream << "];\n";
299 
300  out_stream << "y=[";
301  for (std::size_t i=0; i<bin_members.size(); ++i)
302  {
303  out_stream << bin_members[i] << " ";
304  }
305  out_stream << "];\n";
306  out_stream << "bar(x,y);\n";
307  }
308 }
virtual ErrorVectorReal maximum() const
Definition: statistics.C:61
long double max(long double a, double b)
virtual void histogram(std::vector< dof_id_type > &bin_members, unsigned int n_bins=10)
Definition: statistics.C:178
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual ErrorVectorReal minimum() const
Definition: statistics.C:48
long double min(long double a, double b)

◆ stddev() [1/2]

virtual Real libMesh::StatisticsVector< ErrorVectorReal >::stddev ( ) const
inlinevirtualinherited
Returns
The standard deviation of the data set, which is simply the square-root of the variance.

Definition at line 154 of file statistics.h.

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

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

◆ stddev() [2/2]

virtual Real libMesh::StatisticsVector< ErrorVectorReal >::stddev ( const Real  known_mean) const
inlinevirtualinherited
Returns
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 164 of file statistics.h.

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

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

◆ variance() [1/2]

virtual Real libMesh::ErrorVector::variance ( ) const
inlineoverridevirtual
Returns
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 115 of file error_vector.h.

References mean().

Referenced by libMesh::MeshRefinement::flag_elements_by_mean_stddev().

116  { return this->variance(this->mean()); }
virtual Real variance() const override
Definition: error_vector.h:115
virtual Real mean() const override
Definition: error_vector.C:69

◆ variance() [2/2]

Real libMesh::ErrorVector::variance ( const Real  mean) const
overridevirtual
Returns
The variance of the data set ignoring inactive elements and given the mean.

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(), and libMesh::Real.

127 {
128  const dof_id_type n = cast_int<dof_id_type>(this->size());
129 
130  LOG_SCOPE ("variance()", "ErrorVector");
131 
132  Real the_variance = 0;
133  dof_id_type nnz = 0;
134 
135  for (dof_id_type i=0; i<n; i++)
136  if (this->is_active_elem(i))
137  {
138  const Real delta = ( static_cast<Real>((*this)[i]) - mean_in );
139  the_variance += (delta * delta - the_variance) / (nnz + 1);
140 
141  nnz++;
142  }
143 
144  return the_variance;
145 }
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
bool is_active_elem(dof_id_type i) const
Definition: error_vector.C:197
uint8_t dof_id_type
Definition: id_types.h:64

Member Data Documentation

◆ _mesh

MeshBase* libMesh::ErrorVector::_mesh
protected

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

Definition at line 163 of file error_vector.h.

Referenced by is_active_elem().


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