MOAB: Mesh Oriented datABase
(version 5.4.1)
|
Per-metric QualityAssessor data. More...
#include <QualityAssessor.hpp>
Per-metric QualityAssessor data.
The Assessor class holds QualityAssessor data for each metric added by the calling application, including a pointer to the metric instance, QAFunction flags dictating what is to be calculated and output, histogram parameters, and the variables used to accumulate results as the QualityAssessor is running. It also provides methods to access the calculated data once the QualityAssessor pass is completed.
Definition at line 416 of file QualityAssessor.hpp.
MBMesquite::QualityAssessor::Assessor::Assessor | ( | QualityMetric * | metric, |
const char * | name = 0 |
||
) |
Definition at line 1151 of file QualityAssessor.cpp.
References reset_data().
: qualMetric( metric ), mLabel( label ? std::string( label ) : metric->get_name() ), pMean( 0.0 ), haveHistRange( false ), histMin( 1.0 ), histMax( 0.0 ), tagHandle( 0 ), stoppingFunction( false ), referenceCount( 0 ), assessScheme( NO_SCHEME ) { reset_data(); }
void MBMesquite::QualityAssessor::Assessor::add_hist_value | ( | double | metric_value | ) |
Add a value to the hisogram data
Definition at line 1229 of file QualityAssessor.cpp.
{ // First and last values in array are counts of values // outside the user-specified range of the histogram // (below and above, respectively.) if( metric_value < histMin ) ++histogram[0]; else if( metric_value > histMax ) ++histogram[histogram.size() - 1]; else { // Calculate which interval the value is in. Add one // because first entry is for values below user-specifed // minimum value for histogram. double range = histMax - histMin; double fract; if( range > DBL_EPSILON ) fract = ( metric_value - histMin ) / range; else fract = 0.0; unsigned cell; if( fabs( fract - 1.0 ) < histMax * DBL_EPSILON ) cell = histogram.size() - 1; else cell = 1 + (int)( ( fract * ( histogram.size() - 2 ) ) ); // Add value to interval. ++histogram[cell]; } }
void MBMesquite::QualityAssessor::Assessor::add_value | ( | double | metric_value | ) |
Add a value to the running counts
Definition at line 1207 of file QualityAssessor.cpp.
References moab::sum().
{ sum += metric_value; sqrSum += metric_value * metric_value; if( metric_value > maximum ) maximum = metric_value; if( metric_value < minimum ) minimum = metric_value; // Only add value to histogram data from this function if // the user has specified the range. If user has not // specified the range, QualityAssessor will call add_hist_value() // directly once the range has been calculated. if( have_histogram() && haveHistRange ) add_hist_value( metric_value ); if( have_power_mean() ) pSum += pow( metric_value, pMean ); ++count; }
If range of histogram has not yet been determined, calculate it from the min/max values.
Definition at line 1260 of file QualityAssessor.cpp.
References size.
{ double lower_bound = minimum; int num_intervals = histogram.size(); double step = ( maximum - lower_bound ) / num_intervals; if( step == 0 ) step = 1.0; double size = pow( 10.0, floor( log10( step / ( num_intervals - 1 ) ) ) ); if( size < 1e-6 ) size = 1.0; histMin = lower_bound; histMax = lower_bound + num_intervals * size * ceil( step / size ); }
double MBMesquite::QualityAssessor::Assessor::get_average | ( | ) | const |
MESQUITE_EXPORT int MBMesquite::QualityAssessor::Assessor::get_count | ( | ) | const [inline] |
Definition at line 437 of file QualityAssessor.hpp.
References count.
Referenced by QualityAssessorTest::test_free_only().
{ return count; }
void MBMesquite::QualityAssessor::Assessor::get_histogram | ( | double & | lower_bound_out, |
double & | upper_bound_out, | ||
std::vector< int > & | counts_out, | ||
MsqError & | err | ||
) | const |
Get historgram of data, if calculated.
lower_bound_out | The lower bound of the histogram |
upper_bound_out | The upper bound of the histogram |
counts_out | An array of counts of elements where the first entry is the number of elements for which the metric is below the lower bound, the last entry is the number of elements above the upper bound, and all other values are the counts for histogram intervals between the lower and upper bounds. |
Definition at line 1175 of file QualityAssessor.cpp.
References MBMesquite::MsqError::INVALID_STATE, and MSQ_SETERR.
Referenced by QualityAssessorTest::test_histogram_known_range(), and QualityAssessorTest::test_histogram_unknown_range().
{ if( !have_histogram() ) { MSQ_SETERR( err )( "No histogram calculated.", MsqError::INVALID_STATE ); return; } lower_bound_out = histMin; upper_bound_out = histMax; counts_out = histogram; }
MESQUITE_EXPORT int MBMesquite::QualityAssessor::Assessor::get_invalid_element_count | ( | ) | const [inline] |
Definition at line 447 of file QualityAssessor.hpp.
References numInvalid.
Referenced by ParShapeImprover::count_invalid_elements(), MBMesquite::ViscousCFDTetShapeWrapper::run_wrapper(), and QualityAssessorTest::test_invalid_count().
{ return numInvalid; }
MESQUITE_EXPORT const std::string& MBMesquite::QualityAssessor::Assessor::get_label | ( | ) | const [inline] |
MESQUITE_EXPORT double MBMesquite::QualityAssessor::Assessor::get_maximum | ( | ) | const [inline] |
MESQUITE_EXPORT QualityMetric* MBMesquite::QualityAssessor::Assessor::get_metric | ( | ) | const [inline] |
Get the QualityMetric
Definition at line 476 of file QualityAssessor.hpp.
References qualMetric.
{ return qualMetric; }
MESQUITE_EXPORT double MBMesquite::QualityAssessor::Assessor::get_minimum | ( | ) | const [inline] |
MESQUITE_EXPORT double MBMesquite::QualityAssessor::Assessor::get_power | ( | ) | const [inline] |
Definition at line 433 of file QualityAssessor.hpp.
References pMean.
Referenced by QualityAssessorTest::test_power_mean().
{ return pMean; }
double MBMesquite::QualityAssessor::Assessor::get_power_mean | ( | ) | const |
Definition at line 219 of file QualityAssessor.cpp.
Referenced by QualityAssessorTest::test_power_mean().
double MBMesquite::QualityAssessor::Assessor::get_rms | ( | ) | const |
Definition at line 208 of file QualityAssessor.cpp.
double MBMesquite::QualityAssessor::Assessor::get_stddev | ( | ) | const |
MESQUITE_EXPORT bool MBMesquite::QualityAssessor::Assessor::have_histogram | ( | ) | const [inline] |
Definition at line 495 of file QualityAssessor.hpp.
References histogram.
Referenced by QualityAssessorTest::test_histogram_known_range(), QualityAssessorTest::test_histogram_unknown_range(), and QualityAssessorTest::test_modify_metric().
{ return !histogram.empty(); }
MESQUITE_EXPORT bool MBMesquite::QualityAssessor::Assessor::have_power_mean | ( | ) | const [inline] |
Definition at line 442 of file QualityAssessor.hpp.
References pMean.
Referenced by QualityAssessorTest::test_modify_metric(), and QualityAssessorTest::test_power_mean().
{ return 0.0 != pMean; }
void MBMesquite::QualityAssessor::Assessor::print_histogram | ( | std::ostream & | stream, |
int | width = 0 |
||
) | const |
Print the histogram
Definition at line 1473 of file QualityAssessor.cpp.
References MBMesquite::arrptr(), and MBMesquite::QualityAssessor::round_to_3_significant_digits().
{ // Portability notes: // Use log10 rather than log10f because the float variations require // including platform-dependent headers on some platforms. // Explicitly cast log10 argument to double because some platforms // have overloaded float and double variations in C++ making an // implicit cast from an integer ambiguous. const char indent[] = " "; const char GRAPH_CHAR = '='; // Character used to create bar graphs const int TOTAL_WIDTH = termwidth > 30 ? termwidth : 70; // Width of histogram int GRAPHW = TOTAL_WIDTH - sizeof( indent ); // range is either user-specified (histMin & histMax) or // calculated (minimum & maximum) double min, max; min = histMin; max = histMax; // Witdh of one interval of histogram double step = ( max - min ) / ( histogram.size() - 2 ); // round step to 3 significant digits if( step >= 0.001 ) step = round_to_3_significant_digits( step ); // Find maximum value for an interval bin of the histogram unsigned i; int max_bin_value = 1; for( i = 0; i < histogram.size(); ++i ) if( histogram[i] > max_bin_value ) max_bin_value = histogram[i]; if( 0 == max_bin_value ) return; // no data // Calculate width of field containing counts for // histogram intervals (log10(max_bin_value)). int num_width = 1; for( int temp = max_bin_value; temp > 0; temp /= 10 ) ++num_width; GRAPHW -= num_width; // Create an array of bar graph characters for use in output std::vector< char > graph_chars( GRAPHW + 1, GRAPH_CHAR ); // Check if bar-graph should be linear or log10 plot // Do log plot if standard deviation is less that 1.5 // histogram intervals. bool log_plot = false; double stddev = get_stddev(); if( stddev > 0 && stddev < 2.0 * step ) { int new_interval = (int)( log10( (double)( 1 + max_bin_value ) ) ); if( new_interval > 0 ) { log_plot = true; max_bin_value = new_interval; } } // Write title stream << indent << get_label() << " histogram:"; if( log_plot ) stream << " (log10 plot)"; stream << std::endl; // Calculate width of a single quality interval value double interval_value = 0.0; int max_interval_width = 0; std::stringstream str_stream; std::string interval_string; for( i = 0; i < histogram.size(); ++i ) { interval_value = min + (i)*step; if( step >= 0.001 ) interval_value = round_to_3_significant_digits( interval_value ); str_stream.clear(); str_stream.str( "" ); interval_string = ""; str_stream << interval_value; interval_string = str_stream.str(); if( interval_string.length() > (size_t)max_interval_width ) max_interval_width = interval_string.length(); } // adjust graph width for actual size of interval values GRAPHW = GRAPHW - ( max_interval_width * 2 ) - 5; // For each interval of histogram for( i = 0; i < histogram.size(); ++i ) { // First value is the count of the number of values that // were below the minimum value of the histogram. if( 0 == i ) { if( 0 == histogram[i] ) continue; stream << indent << std::setw( max_interval_width ) << "under min"; } // Last value is the count of the number of values that // were above the maximum value of the histogram. else if( i + 1 == histogram.size() ) { if( 0 == histogram[i] ) continue; stream << indent << std::setw( max_interval_width ) << "over max"; } // Anything else is a valid interval of the histogram. // Print the range for each interval. else { double start_value = min + ( i - 1 ) * step; double end_value = min + (i)*step; if( step >= 0.001 ) { start_value = round_to_3_significant_digits( start_value ); end_value = round_to_3_significant_digits( end_value ); } stream << indent << "(" << std::setw( max_interval_width ) << std::right << start_value << "-" << std::setw( max_interval_width ) << std::left << end_value << ") |"; // reset stream alignment to right (the default) stream << std::right; } // Print bar graph // First calculate the number of characters to output int num_graph; if( log_plot ) num_graph = GRAPHW * (int)log10( (double)( 1 + histogram[i] ) ) / max_bin_value; else num_graph = GRAPHW * histogram[i] / max_bin_value; // print num_graph characters using array of fill characters. graph_chars[num_graph] = '\0'; stream << arrptr( graph_chars ); graph_chars[num_graph] = GRAPH_CHAR; // Print interval count. stream << histogram[i] << std::endl; } stream << " metric was evaluated " << count << " times." << std::endl << std::endl; }
Reset all calculated data
Definition at line 1191 of file QualityAssessor.cpp.
References MBMesquite::NO_SCHEME, and moab::sum().
Referenced by Assessor().
MESQUITE_EXPORT void MBMesquite::QualityAssessor::Assessor::set_stopping_function | ( | bool | value | ) | [inline] |
Definition at line 510 of file QualityAssessor.hpp.
References stoppingFunction, and value().
{ stoppingFunction = value; }
MESQUITE_EXPORT bool MBMesquite::QualityAssessor::Assessor::stopping_function | ( | ) | const [inline] |
Definition at line 515 of file QualityAssessor.hpp.
References stoppingFunction.
{ return stoppingFunction; }
double MBMesquite::QualityAssessor::Assessor::stopping_function_value | ( | ) | const |
Definition at line 1710 of file QualityAssessor.cpp.
{ return have_power_mean() ? get_power_mean() : get_average(); }
MESQUITE_EXPORT bool MBMesquite::QualityAssessor::Assessor::write_to_tag | ( | ) | const [inline] |
Definition at line 505 of file QualityAssessor.hpp.
References tagName.
{ return !tagName.empty(); }
friend class QualityAssessor [friend] |
Definition at line 523 of file QualityAssessor.hpp.
enum AssessSchemes MBMesquite::QualityAssessor::Assessor::assessScheme [private] |
Definition at line 558 of file QualityAssessor.hpp.
unsigned long MBMesquite::QualityAssessor::Assessor::count [private] |
Definition at line 528 of file QualityAssessor.hpp.
Referenced by get_average(), and get_count().
bool MBMesquite::QualityAssessor::Assessor::haveHistRange [private] |
The histogram counts, where the first and last values are counts of values below the lower bound and above the upper bound, respectively. The remaining values are the histogram counts.
Definition at line 544 of file QualityAssessor.hpp.
double MBMesquite::QualityAssessor::Assessor::histMax [private] |
Definition at line 546 of file QualityAssessor.hpp.
double MBMesquite::QualityAssessor::Assessor::histMin [private] |
Definition at line 545 of file QualityAssessor.hpp.
std::vector< int > MBMesquite::QualityAssessor::Assessor::histogram [private] |
Definition at line 547 of file QualityAssessor.hpp.
Referenced by have_histogram().
double MBMesquite::QualityAssessor::Assessor::maximum [private] |
Definition at line 531 of file QualityAssessor.hpp.
Referenced by get_maximum().
double MBMesquite::QualityAssessor::Assessor::minimum [private] |
Definition at line 532 of file QualityAssessor.hpp.
Referenced by get_minimum().
std::string MBMesquite::QualityAssessor::Assessor::mLabel [private] |
Definition at line 526 of file QualityAssessor.hpp.
Referenced by get_label().
unsigned long MBMesquite::QualityAssessor::Assessor::numInvalid [private] |
Definition at line 535 of file QualityAssessor.hpp.
Referenced by get_invalid_element_count().
double MBMesquite::QualityAssessor::Assessor::pMean [private] |
Definition at line 537 of file QualityAssessor.hpp.
Referenced by get_power(), and have_power_mean().
double MBMesquite::QualityAssessor::Assessor::pSum [private] |
Definition at line 534 of file QualityAssessor.hpp.
QualityMetric* const MBMesquite::QualityAssessor::Assessor::qualMetric [private] |
Definition at line 525 of file QualityAssessor.hpp.
Referenced by get_metric().
int MBMesquite::QualityAssessor::Assessor::referenceCount [private] |
Definition at line 556 of file QualityAssessor.hpp.
Referenced by MBMesquite::QualityAssessor::find_or_add(), MBMesquite::QualityAssessor::operator=(), and MBMesquite::QualityAssessor::~QualityAssessor().
double MBMesquite::QualityAssessor::Assessor::sqrSum [private] |
Definition at line 533 of file QualityAssessor.hpp.
bool MBMesquite::QualityAssessor::Assessor::stoppingFunction [private] |
Value is return value for all of QualityAssessor
Definition at line 554 of file QualityAssessor.hpp.
Referenced by set_stopping_function(), and stopping_function().
double MBMesquite::QualityAssessor::Assessor::sum [private] |
Definition at line 530 of file QualityAssessor.hpp.
Referenced by get_average().
Cached tag handle
Definition at line 551 of file QualityAssessor.hpp.
std::string MBMesquite::QualityAssessor::Assessor::tagName [private] |
Definition at line 549 of file QualityAssessor.hpp.
Referenced by write_to_tag().