Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
includeLinks/QualityAssessor.hpp
Go to the documentation of this file.
1 /* *****************************************************************
2  MESQUITE -- The Mesh Quality Improvement Toolkit
3 
4  Copyright 2004 Sandia Corporation and Argonne National
5  Laboratory. Under the terms of Contract DE-AC04-94AL85000
6  with Sandia Corporation, the U.S. Government retains certain
7  rights in this software.
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  (lgpl.txt) along with this library; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 
23  diachin2@llnl.gov, djmelan@sandia.gov, mbrewer@sandia.gov,
24  pknupp@sandia.gov, tleurent@mcs.anl.gov, tmunson@mcs.anl.gov
25 
26  ***************************************************************** */
27 // -*- Mode : c++; tab-width: 3; c-tab-always-indent: t; indent-tabs-mode: nil; c-basic-offset: 3 -*-
28 
40 #ifndef MSQ_QUALITYASSESSOR_HPP
41 #define MSQ_QUALITYASSESSOR_HPP
42 
43 #include <math.h>
44 
45 #include "Mesquite.hpp"
46 #include "PatchDataUser.hpp"
47 
48 #ifdef MSQ_USE_OLD_STD_HEADERS
49 # include <list.h>
50 # include <string.h>
51 #else
52 # include <list>
53 # include <string>
54 #endif
55 
56 #ifdef MSQ_USE_OLD_IO_HEADERS
57 # include <ostream.h>
58 #else
59 # include <iosfwd>
60 #endif
61 
62 
63 namespace Mesquite
64 {
65 
66  class QualityMetric;
67  class MsqError;
68  class MeshSet;
69 
98  {
99  public:
100 
101 
104  enum QAFunction {
110  RMS=16,
111  STDDEV=32,
113  };
114 
115  static msq_std::string get_QAFunction_name(enum QualityAssessor::QAFunction);
116 
118  QualityAssessor( msq_std::string name = "QualityAssessor" );
119 
121  QualityAssessor( msq_stdio::ostream& output_stream,
122  msq_std::string name = "QualityAssessor" );
123 
126  msq_stdio::ostream& output_stream,
127  MsqError& err,
128  msq_std::string name = "QualityAssessor" );
129 
130 
133  MsqError& err,
134  msq_std::string name = "QualityAssessor" );
135 
138 
140  void set_name(msq_std::string name) { qualityAssessorName = name; };
142  virtual msq_std::string get_name() { return qualityAssessorName; }
143 
145 
148  int function_flags,
149  MsqError &err);
150 
155  QAFunction func,
156  MsqError &err );
157 
161  double min,
162  double max,
163  int intervals,
164  MsqError& err );
165 
167  virtual double loop_over_mesh(MeshSet &ms, MsqError &err);
168 
171  {
172  printSummary = false;
173  }
174 
176  void print_summary( msq_stdio::ostream& stream ) const;
177 
180  bool invalid_elements() const;
181 
183  void reset_data();
184 
196  class Assessor
197  {
198  public:
199 
201 
202  double get_average() const ;
203  double get_maximum() const { return maximum; }
204  double get_minimum() const { return minimum; }
205  double get_rms() const ;
206  double get_stddev() const ;
207  int get_count() const { return count; }
208 
209  int get_invalid_element_count() const { return numInvalid; }
210 
222  void get_histogram( double& lower_bound_out,
223  double& upper_bound_out,
224  msq_std::vector<int>& counts_out,
225  MsqError& err ) const;
226 
228  void reset_data();
229 
231  void print_histogram( msq_stdio::ostream& ) const;
232 
234  QualityMetric* get_metric() const { return qualMetric; }
235 
237  void add_value( double metric_value );
238 
240  void add_hist_value( double metric_value );
241 
243  void add_invalid_value() ;
244 
249 
250  private:
251 
252  friend class QualityAssessor;
253 
254  QualityMetric *const qualMetric; //< The quality metric
255  unsigned funcFlags; //< What to calculate
256 
257  unsigned long count; //< The total number of times the metric was evaluated
258 
259  double sum; //< The sum of the metric over all elements
260  double maximum; //< The maximum of the metric
261  double minimum; //< The minimum value of the metric
262  double sqrSum; //< The sum of the square of the metric values
263  unsigned long numInvalid; //< Count of invalid metric values
264 
271  double histMin; //< Lower bound of histogram
272  double histMax; //< Upper bound of histogram
273  msq_std::vector<int> histogram;
274  };
275 
282  const Assessor* get_results( QualityMetric* metric ) const;
283 
288  const msq_std::list<Assessor>& get_all_results() const
289  { return assessList; }
290 
291  private:
292 
297  msq_std::list<Assessor>::iterator find_or_add( QualityMetric* qm );
298 
300  msq_std::string qualityAssessorName;
301 
303  msq_std::list<Assessor> assessList;
304 
306  msq_stdio::ostream& outputStream;
309 
311  msq_std::list<Assessor>::iterator stoppingMetric;
314  };
315 
316 
317 } //namespace
318 
319 
320 #endif // QualityAssessor_hpp
void reset_data()
Reset calculated data.
msq_stdio::ostream & outputStream
Stream to which to write summary of metric data.
Used to hold the error state and return it to the application.
static msq_std::string get_QAFunction_name(enum QualityAssessor::QAFunction)
Base class for concrete quality metrics.
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
QualityMetric * get_metric() const
Get the QualityMetric.
virtual AlgorithmType get_algorithm_type()
Return the algorithm type (to avoid RTTI use).
void print_histogram(msq_stdio::ostream &) const
Print the histogram.
This should be the parent class of all algorithms retrieving information from a MeshSet object...
void print_summary(msq_stdio::ostream &stream) const
Print accumulated summary data to specified stream.
const msq_std::list< Assessor > & get_all_results() const
Get list of all summary data.
virtual double loop_over_mesh(MeshSet &ms, MsqError &err)
Does one sweep over the mesh and assess the quality with the metrics previously added.
A QualityAssessor instance can be inserted into an InstructionQueue to calculate and summarize regist...
void add_quality_assessment(QualityMetric *qm, int function_flags, MsqError &err)
Adds a quality metric and a wrapper function (min, max, ...).
msq_std::list< Assessor >::iterator find_or_add(QualityMetric *qm)
Find an Assessor corresponding to the passed QualityMetric, or create it if is not found in the list...
void set_name(msq_std::string name)
Provides a name to the QualityAssessor (use it for default name in constructor).
msq_std::list< Assessor >::iterator stoppingMetric
Metric in assessList to use as return value for loop_over_mesh.
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346
virtual msq_std::string get_name()
Retrieves the QualityAssessor name. A default name should be set in the constructor.
bool haveHistRange
The histogram counts, where the first and last values are counts of values below the lower bound and ...
void get_histogram(double &lower_bound_out, double &upper_bound_out, msq_std::vector< int > &counts_out, MsqError &err) const
Get historgram of data, if calculated.
msq_std::list< Assessor > assessList
List of quality metrics and corresponding data.
void add_histogram_assessment(QualityMetric *qm, double min, double max, int intervals, MsqError &err)
Add a quality metric for which the histogram is to be calculated, and set histogram parameters...
void add_hist_value(double metric_value)
Add a value to the hisogram data.
QAFunction stoppingFunction
Value to use as return value for loop_over_mesh.
void set_stopping_assessment(QualityMetric *qm, QAFunction func, MsqError &err)
void add_value(double metric_value)
Add a value to the running counts.
Definition: metric.h:35
QualityAssessor(msq_std::string name="QualityAssessor")
Constructor - output to std::cout.
void disable_printing_results()
Do not print results of assessment.
The MeshSet class stores one or more Mesquite::Mesh pointers and manages access to the mesh informati...
void calculate_histogram_range()
If range of histogram has not yet been determined, calculate it from the min/max values.
const Assessor * get_results(QualityMetric *metric) const
Request summary data for a specific QualityMetric This method allows the application to request the s...
bool invalid_elements() const
True if any metric evaluated to an invalid value for any element.