libMesh
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
libMesh::ErrorVector Class Reference

The ErrorVector is a specialization of the StatisticsVector for error data computed on a finite element mesh. More...

#include <error_vector.h>

Inheritance diagram for libMesh::ErrorVector:
[legend]

Public Member Functions

 ErrorVector (dof_id_type i=0, MeshBase *mesh=nullptr)
 ErrorVector constructor; sets initial length to i.
 
 ErrorVector (dof_id_type i, ErrorVectorReal val)
 ErrorVector constructor; sets initial length to i and initial values to val.
 
virtual ErrorVectorReal minimum () const override
 
virtual Real mean () const override
 
virtual Real median () override
 
virtual Real median () const override
 A const version of the median function.
 
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 std::string &data_type="error") 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.
 
virtual Real l2_norm () const
 
virtual ErrorVectorReal maximum () const
 
virtual Real stddev () const
 
virtual Real stddev (const Real known_mean) const
 
void normalize ()
 Divides all entries by the largest entry and stores the result.
 
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
 A const version of the histogram function.
 
void plot_histogram (const processor_id_type my_procid, const std::string &filename, unsigned int n_bins)
 Generates a Matlab/Octave style file which can be used to make a plot of the histogram having the desired number of bins.
 

Protected Member Functions

bool is_active_elem (dof_id_type i) const
 Utility function to decide whether element i is active.
 

Protected Attributes

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

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
Pointer to the mesh, which may be used to decide which elements are active.
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.

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
Utility function to decide whether element i is active.
uint8_t dof_id_type
Definition id_types.h:67

References is_active_elem().

◆ 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.

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}

References is_active_elem().

◆ 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 181 of file statistics.C.

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

◆ 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 198 of file statistics.C.

330{
331 StatisticsVector<T> sv = (*this);
332
333 return sv.histogram(bin_members, n_bins);
334}

◆ 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.

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}
bool active() const
Definition elem.h:2958
virtual const Elem * elem_ptr(const dof_id_type i) const =0

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

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

◆ l2_norm()

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

Definition at line 91 of file statistics.C.

38{
39 Real normsq = 0.;
40 const dof_id_type n = cast_int<dof_id_type>(this->size());
41 for (dof_id_type i = 0; i != n; ++i)
42 normsq += ((*this)[i] * (*this)[i]);
43
44 return std::sqrt(normsq);
45}

◆ maximum()

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

Definition at line 101 of file statistics.C.

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

◆ 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.

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}

References is_active_elem(), and libMesh::Real.

Referenced by libMesh::MeshRefinement::flag_elements_by_mean_stddev(), main(), libMesh::HPCoarsenTest::select_refinement(), SlitMeshRefinedSystemTest::testSystem(), and variance().

◆ median() [1/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.

117{
118 ErrorVector ev = (*this);
119
120 return ev.median();
121}
ErrorVector(dof_id_type i=0, MeshBase *mesh=nullptr)
ErrorVector constructor; sets initial length to i.

References median().

◆ median() [2/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.

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}

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

Referenced by median().

◆ 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.

47{
48 LOG_SCOPE ("minimum()", "ErrorVector");
49
50 const dof_id_type n = cast_int<dof_id_type>(this->size());
51 ErrorVectorReal min = std::numeric_limits<ErrorVectorReal>::max();
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}
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal

References libMesh::ErrorVectorReal, and is_active_elem().

◆ normalize()

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

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

Definition at line 170 of file statistics.C.

166{
167 const dof_id_type n = cast_int<dof_id_type>(this->size());
168 const Real max = this->maximum();
169
170 for (dof_id_type i=0; i<n; i++)
171 (*this)[i] = static_cast<T>((*this)[i] / max);
172}

◆ plot_error()

void libMesh::ErrorVector::plot_error ( const std::string &  filename,
const MeshBase mesh,
const std::string &  data_type = "error" 
) 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.

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

References libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshBase::allow_renumbering(), libMesh::MeshBase::clone(), libMesh::CONSTANT, libMesh::Utility::contains(), 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::System::update(), libMesh::WRITE, libMesh::XdrIO::write(), libMesh::Nemesis_IO::write(), libMesh::ExodusII_IO::write(), libMesh::EquationSystems::write(), libMesh::EquationSystems::WRITE_ADDITIONAL_DATA, libMesh::EquationSystems::WRITE_DATA, libMesh::GMVIO::write_discontinuous_gmv(), libMesh::ExodusII_IO::write_element_data(), libMesh::Nemesis_IO::write_element_data(), and libMesh::MeshOutput< MT >::write_equation_systems().

Referenced by libMesh::AdjointResidualErrorEstimator::estimate_error(), and main().

◆ 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 191 of file statistics.C.

288{
289 // First generate the histogram with the desired number of bins
290 std::vector<dof_id_type> bin_members;
291 this->histogram(bin_members, n_bins);
292
293 // The max, min and bin size are used to generate x-axis values.
294 T min = this->minimum();
295 T max = this->maximum();
296 T bin_size = (max - min) / static_cast<T>(n_bins);
297
298 // On processor 0: Write histogram to file
299 if (my_procid==0)
300 {
301 std::ofstream out_stream (filename.c_str());
302
303 out_stream << "clear all\n";
304 out_stream << "clf\n";
305 //out_stream << "x=linspace(" << min << "," << max << "," << n_bins+1 << ");\n";
306
307 // abscissa values are located at the center of each bin.
308 out_stream << "x=[";
309 for (auto i : index_range(bin_members))
310 {
311 out_stream << min + (Real(i)+0.5)*bin_size << " ";
312 }
313 out_stream << "];\n";
314
315 out_stream << "y=[";
316 for (auto bmi : bin_members)
317 {
318 out_stream << bmi << " ";
319 }
320 out_stream << "];\n";
321 out_stream << "bar(x,y);\n";
322 }
323}
virtual void histogram(std::vector< dof_id_type > &bin_members, unsigned int n_bins=10)
Definition statistics.C:179

◆ 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.

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.

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.

116 { return this->variance(this->mean()); }
virtual Real variance() const override
virtual Real mean() const override

References mean(), and variance().

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

◆ 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.

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}

References is_active_elem(), and libMesh::Real.

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

Referenced by is_active_elem().


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