libMesh::ErrorVector Class Reference
#include <error_vector.h>

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_type > | cut_below (Real cut) const |
| virtual std::vector< dof_id_type > | 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 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 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.).
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.
| 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.
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().
00179 { 00180 START_LOG ("cut_above()", "ErrorVector"); 00181 00182 const dof_id_type n = this->size(); 00183 00184 std::vector<dof_id_type> cut_indices; 00185 cut_indices.reserve(n/2); // Arbitrary 00186 00187 for (dof_id_type i=0; i<n; i++) 00188 if (this->is_active_elem(i)) 00189 { 00190 if ((*this)[i] > cut) 00191 { 00192 cut_indices.push_back(i); 00193 } 00194 } 00195 00196 STOP_LOG ("cut_above()", "ErrorVector"); 00197 00198 return cut_indices; 00199 }
| 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().
00153 { 00154 START_LOG ("cut_below()", "ErrorVector"); 00155 00156 const dof_id_type n = this->size(); 00157 00158 std::vector<dof_id_type> cut_indices; 00159 cut_indices.reserve(n/2); // Arbitrary 00160 00161 for (dof_id_type i=0; i<n; i++) 00162 if (this->is_active_elem(i)) 00163 { 00164 if ((*this)[i] < cut) 00165 { 00166 cut_indices.push_back(i); 00167 } 00168 } 00169 00170 STOP_LOG ("cut_below()", "ErrorVector"); 00171 00172 return cut_indices; 00173 }
| 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.
| 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
| 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(), and libMesh::MeshBase::elem().
Referenced by cut_above(), cut_below(), mean(), median(), minimum(), and variance().
| 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(), and libMesh::Real.
Referenced by libMesh::MeshRefinement::flag_elements_by_mean_stddev(), and variance().
00068 { 00069 START_LOG ("mean()", "ErrorVector"); 00070 00071 const dof_id_type n = this->size(); 00072 00073 Real the_mean = 0; 00074 dof_id_type nnz = 0; 00075 00076 for (dof_id_type i=0; i<n; i++) 00077 if (this->is_active_elem(i)) 00078 { 00079 the_mean += ( static_cast<Real>((*this)[i]) - the_mean ) / (nnz + 1); 00080 00081 nnz++; 00082 } 00083 00084 STOP_LOG ("mean()", "ErrorVector"); 00085 00086 return the_mean; 00087 }
| 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().
00117 { 00118 ErrorVector ev = (*this); 00119 00120 return ev.median(); 00121 }
| Real libMesh::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 libMesh::StatisticsVector< ErrorVectorReal >.
Definition at line 92 of file error_vector.C.
References is_active_elem(), and libMesh::StatisticsVector< T >::median().
Referenced by median().
00093 { 00094 const dof_id_type n = this->size(); 00095 00096 if (n == 0) 00097 return 0.; 00098 00099 00100 // Build a StatisticsVector<ErrorVectorReal> containing 00101 // only our active entries and take its mean 00102 StatisticsVector<ErrorVectorReal> sv; 00103 00104 sv.reserve (n); 00105 00106 for (dof_id_type i=0; i<n; i++) 00107 if(this->is_active_elem(i)) 00108 sv.push_back((*this)[i]); 00109 00110 return sv.median(); 00111 }
| ErrorVectorReal libMesh::ErrorVector::minimum | ( | ) | const [virtual] |
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(), and std::min().
00044 { 00045 START_LOG ("minimum()", "ErrorVector"); 00046 00047 const dof_id_type n = this->size(); 00048 ErrorVectorReal min = std::numeric_limits<ErrorVectorReal>::max(); 00049 00050 for (dof_id_type i=0; i<n; i++) 00051 { 00052 // Only positive (or zero) values in the error vector 00053 libmesh_assert_greater_equal ((*this)[i], 0.); 00054 if (this->is_active_elem(i)) 00055 min = std::min (min, (*this)[i]); 00056 } 00057 STOP_LOG ("minimum()", "ErrorVector"); 00058 00059 // ErrorVectors are for positive values 00060 libmesh_assert_greater_equal (min, 0.); 00061 00062 return min; 00063 }
| void libMesh::StatisticsVector< ErrorVectorReal >::normalize | ( | ) | [inherited] |
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(), libMeshEnums::CONSTANT, libMesh::DofMap::dof_indices(), elem_id, libMesh::err, libMesh::System::get_dof_map(), libMesh::DofObject::id(), libMesh::EquationSystems::init(), libMesh::MeshBase::max_elem_id(), libMesh::MeshBase::max_node_id(), mesh, libMeshEnums::MONOMIAL, libMesh::MeshBase::n_elem(), libMesh::MeshBase::n_nodes(), libMesh::MeshBase::renumber_nodes_and_elements(), libMesh::System::solution, libMesh::ExodusII_IO::write(), and libMesh::ExodusII_IO::write_element_data().
Referenced by libMesh::AdjointResidualErrorEstimator::estimate_error().
00219 { 00220 AutoPtr<MeshBase> meshptr = oldmesh.clone(); 00221 MeshBase &mesh = *meshptr; 00222 mesh.all_first_order(); 00223 EquationSystems temp_es (mesh); 00224 ExplicitSystem& error_system 00225 = temp_es.add_system<ExplicitSystem> ("Error"); 00226 error_system.add_variable("error", CONSTANT, MONOMIAL); 00227 temp_es.init(); 00228 00229 const DofMap& error_dof_map = error_system.get_dof_map(); 00230 00231 MeshBase::const_element_iterator el = 00232 mesh.active_local_elements_begin(); 00233 const MeshBase::const_element_iterator end_el = 00234 mesh.active_local_elements_end(); 00235 std::vector<dof_id_type> dof_indices; 00236 00237 for ( ; el != end_el; ++el) 00238 { 00239 const Elem* elem = *el; 00240 00241 error_dof_map.dof_indices(elem, dof_indices); 00242 00243 const dof_id_type elem_id = elem->id(); 00244 00245 //0 for the monomial basis 00246 const dof_id_type solution_index = dof_indices[0]; 00247 00248 // libMesh::out << "elem_number=" << elem_number << std::endl; 00249 libmesh_assert_less (elem_id, (*this).size()); 00250 00251 // We may have zero error values in special circumstances 00252 // libmesh_assert_greater ((*this)[elem_id], 0.); 00253 error_system.solution->set(solution_index, (*this)[elem_id]); 00254 } 00255 00256 // We may have to renumber if the original numbering was not 00257 // contiguous. Since this is just a temporary mesh, that's probably 00258 // fine. 00259 if (mesh.max_elem_id() != mesh.n_elem() || 00260 mesh.max_node_id() != mesh.n_nodes()) 00261 { 00262 mesh.allow_renumbering(true); 00263 mesh.renumber_nodes_and_elements(); 00264 } 00265 00266 if (filename.rfind(".gmv") < filename.size()) 00267 { 00268 GMVIO(mesh).write_discontinuous_gmv(filename, 00269 temp_es, false); 00270 } 00271 else if (filename.rfind(".plt") < filename.size()) 00272 { 00273 TecplotIO (mesh).write_equation_systems 00274 (filename, temp_es); 00275 } 00276 #ifdef LIBMESH_HAVE_EXODUS_API 00277 else if( (filename.rfind(".exo") < filename.size()) || 00278 (filename.rfind(".e") < filename.size()) ) 00279 { 00280 ExodusII_IO io(mesh); 00281 io.write(filename); 00282 io.write_element_data(temp_es); 00283 } 00284 #endif 00285 else 00286 { 00287 libmesh_here(); 00288 libMesh::err << "Warning: ErrorVector::plot_error currently only" 00289 << " supports .gmv and .plt and .exo/.e (if enabled) output;" << std::endl; 00290 libMesh::err << "Could not recognize filename: " << filename 00291 << std::endl; 00292 } 00293 }
| void libMesh::StatisticsVector< ErrorVectorReal >::plot_histogram | ( | 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 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().
00175 { return std::sqrt(this->variance(known_mean)); }
| 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().
00166 { return std::sqrt(this->variance()); }
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(), and libMesh::Real.
00127 { 00128 const dof_id_type n = this->size(); 00129 00130 START_LOG ("variance()", "ErrorVector"); 00131 00132 Real the_variance = 0; 00133 dof_id_type nnz = 0; 00134 00135 for (dof_id_type i=0; i<n; i++) 00136 if (this->is_active_elem(i)) 00137 { 00138 const Real delta = ( static_cast<Real>((*this)[i]) - mean_in ); 00139 the_variance += (delta * delta - the_variance) / (nnz + 1); 00140 00141 nnz++; 00142 } 00143 00144 STOP_LOG ("variance()", "ErrorVector"); 00145 00146 return the_variance; 00147 }
| 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().
Member Data Documentation
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:
Site Created By: libMesh Developers
Last modified: February 05 2013 19:55:18 UTC
Hosted By: