LCOV - code coverage report
Current view: top level - src/mesquite/QualityAssessor - QualityAssessor.hpp (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 40 45 88.9 %
Date: 2020-07-18 00:09:26 Functions: 18 20 90.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       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                 :            :     [email protected], [email protected], [email protected],
      24                 :            :     [email protected], [email protected], [email protected]
      25                 :            : 
      26                 :            :     (2006) [email protected]
      27                 :            : 
      28                 :            :   ***************************************************************** */
      29                 :            : // -*- Mode : c++; tab-width: 3; c-tab-always-indent: t; indent-tabs-mode: nil; c-basic-offset: 3
      30                 :            : // -*-
      31                 :            : 
      32                 :            : /*! \file QualityAssessor.hpp
      33                 :            : 
      34                 :            : Header file for the MBMesquite::QualityAssessor class
      35                 :            : 
      36                 :            :   \author Thomas Leurent
      37                 :            :   \date   2002-05-01
      38                 :            :   \author Jason Kraftcheck
      39                 :            :   \date   2005-03-09
      40                 :            :  */
      41                 :            : 
      42                 :            : #ifndef MSQ_QUALITYASSESSOR_HPP
      43                 :            : #define MSQ_QUALITYASSESSOR_HPP
      44                 :            : 
      45                 :            : #include "Mesquite.hpp"
      46                 :            : #include "Instruction.hpp"
      47                 :            : #include "MeshInterface.hpp"
      48                 :            : 
      49                 :            : #include <list>
      50                 :            : #include <string>
      51                 :            : #include <vector>
      52                 :            : #include <iosfwd>
      53                 :            : 
      54                 :            : namespace MBMesquite
      55                 :            : {
      56                 :            : 
      57                 :            : class QualityMetric;
      58                 :            : class MsqError;
      59                 :            : class ParallelHelper;
      60                 :            : 
      61                 :            : /*! \class QualityAssessor
      62                 :            : 
      63                 :            :     \brief A QualityAssessor instance can be inserted into an
      64                 :            :     InstructionQueue to calculate and summarize registered
      65                 :            :     QualityMetric or QualityMetrics for the mesh.
      66                 :            : 
      67                 :            :     QualityAssessor provides a summary of the mesh quality.  An
      68                 :            :     instance of QualityAssessor may be inserted in the InstructionQueue
      69                 :            :     at any point to print a summary of the mesh quality at that
      70                 :            :     time during the optimization.  The application is expected to
      71                 :            :     register QualityMetric instances to be used in assessing the
      72                 :            :     mesh quality.  If no QualityMetrics are registered, the only
      73                 :            :     assessment that will be performed is a simple count of inverted
      74                 :            :     elements.
      75                 :            : 
      76                 :            :     The "stopping assessor" and "stopping function", if set,
      77                 :            :     determinte the value reported to Mesquite for the overall
      78                 :            :     run of of the QualityAssessor.
      79                 :            : 
      80                 :            :     All summary data except the histogram and custom power-means is
      81                 :            :     accumulated for all registered metrics.  QualityAssessment data
      82                 :            :     can be obtained through three different mechanisms:
      83                 :            :       - QualityAssessor can print a summary to std::out or a specified
      84                 :            :         output stream after they are calculated.
      85                 :            :       - The get_results and get_all_results methods can be used to
      86                 :            :         obtain the sumary data programatically.
      87                 :            :       - Quality measures for element-based or vertex-based metrics can
      88                 :            :         be stored on the corresponding entities using "tags".
      89                 :            : 
      90                 :            : */
      91                 :            : class QualityAssessor : public Instruction
      92                 :            : {
      93                 :            :   public:
      94                 :            :     /**\brief Simple consturctor.  Metrics registered separately.
      95                 :            :      *\param print_summary_to_std_out If true, summary of mesh quality
      96                 :            :      *                will be written to std::out.  If false, quality
      97                 :            :      *                assessment will be available via the get_results
      98                 :            :      *                and get_all_results methods, but will not be printed.
      99                 :            :      *\param free_elements_only If true, only quality values that depend
     100                 :            :      *                on at least one free vertex will be uses.
     101                 :            :      *\param  inverted_element_tag_name  If a non-null value is specified,
     102                 :            :      *                an integer tag with the specified name will be used
     103                 :            :      *                it store value of 0 for normal elements and 1 for
     104                 :            :      *                inverted elements.
     105                 :            :      *\param  name    Name to include in output.  Useful if several QualityAssessors
     106                 :            :      *                are in use at the same time.
     107                 :            :      */
     108                 :            :     MESQUITE_EXPORT
     109                 :            :     QualityAssessor( bool print_summary_to_std_out = true, bool free_elements_only = true,
     110                 :            :                      const char* inverted_element_tag_name = 0, std::string name = std::string() );
     111                 :            : 
     112                 :            :     /**\brief Simple consturctor.  Metrics registered separately.
     113                 :            :      *\param output_stream IO stream to which to write a summary of the
     114                 :            :      *                mesh quality.
     115                 :            :      *\param free_elements_only If true, only quality values that depend
     116                 :            :      *                on at least one free vertex will be uses.
     117                 :            :      *\param  inverted_element_tag_name  If a non-null value is specified,
     118                 :            :      *                an integer tag with the specified name will be used
     119                 :            :      *                it store value of 0 for normal elements and 1 for
     120                 :            :      *                inverted elements.
     121                 :            :      *\param  name    Name to include in output.  Useful if several QualityAssessors
     122                 :            :      *                are in use at the same time.
     123                 :            :      */
     124                 :            :     MESQUITE_EXPORT
     125                 :            :     QualityAssessor( std::ostream& output_stream, bool free_elements_only = true,
     126                 :            :                      const char* inverted_element_tag_name = 0, std::string name = std::string() );
     127                 :            : 
     128                 :            :     /**\brief Construct and register a QualityMetric
     129                 :            :      *\param output_stream IO stream to which to write a summary of the
     130                 :            :      *                mesh quality.
     131                 :            :      *\param metric   QualtiyMetric to register for use in assessing mesh
     132                 :            :      *                quality.  Will also be used as the "stopping assessment".
     133                 :            :      *\param historgram_intervals If non-zero, a histogram of quality metric
     134                 :            :      *                values composed of the specified number of intervals
     135                 :            :      *                will be generated.
     136                 :            :      *\param power_mean If non-zero, in addition to the normal summary
     137                 :            :      *                statistics for the quality metric, an additional
     138                 :            :      *                general power mean with the specified power will
     139                 :            :      *                be calculated.
     140                 :            :      *\param metric_value_tag_name  If a non-null value is specified,
     141                 :            :      *                a tag with the specified name will be populated
     142                 :            :      *                with quality values for individual elements or
     143                 :            :      *                vertices if metric is an element-based or vertex-
     144                 :            :      *                based metric.  If metric is not element-based or
     145                 :            :      *                vertex-based, this argument has no effect.
     146                 :            :      *\param free_elements_only If true, only quality values that depend
     147                 :            :      *                on at least one free vertex will be uses.
     148                 :            :      *\param inverted_element_tag_name  If a non-null value is specified,
     149                 :            :      *                an integer tag with the specified name will be used
     150                 :            :      *                it store value of 0 for normal elements and 1 for
     151                 :            :      *                inverted elements.
     152                 :            :      *\param  name    Name to include in output.  Useful if several QualityAssessors
     153                 :            :      *                are in use at the same time.
     154                 :            :      */
     155                 :            :     MESQUITE_EXPORT
     156                 :            :     QualityAssessor( std::ostream& output_stream, QualityMetric* metric, int histogram_intervals = 0,
     157                 :            :                      double power_mean = 0.0, bool free_elements_only = true, const char* metric_value_tag_name = 0,
     158                 :            :                      const char* inverted_element_tag_name = 0, std::string name = std::string() );
     159                 :            : 
     160                 :            :     /**\brief Construct and register a QualityMetric
     161                 :            :      *\param print_summary_to_std_out If true, summary of mesh quality
     162                 :            :      *                will be written to std::out.  If false, quality
     163                 :            :      *                assessment will be available via the get_results
     164                 :            :      *                and get_all_results methods, but will not be printed.
     165                 :            :      *\param metric   QualtiyMetric to register for use in assessing mesh
     166                 :            :      *                quality.  Will also be used as the "stopping assessment".
     167                 :            :      *\param historgram_intervals If non-zero, a histogram of quality metric
     168                 :            :      *                values composed of the specified number of intervals
     169                 :            :      *                will be generated.
     170                 :            :      *\param power_mean If non-zero, in addition to the normal summary
     171                 :            :      *                statistics for the quality metric, an additional
     172                 :            :      *                general power mean with the specified power will
     173                 :            :      *                be calculated.
     174                 :            :      *\param metric_value_tag_name  If a non-null value is specified,
     175                 :            :      *                a tag with the specified name will be populated
     176                 :            :      *                with quality values for individual elements or
     177                 :            :      *                vertices if metric is an element-based or vertex-
     178                 :            :      *                based metric.  If metric is not element-based or
     179                 :            :      *                vertex-based, this argument has no effect.
     180                 :            :      *\param free_elements_only If true, only quality values that depend
     181                 :            :      *                on at least one free vertex will be uses.
     182                 :            :      *\param  inverted_element_tag_name  If a non-null value is specified,
     183                 :            :      *                an integer tag with the specified name will be used
     184                 :            :      *                it store value of 0 for normal elements and 1 for
     185                 :            :      *                inverted elements.
     186                 :            :      *\param  name    Name to include in output.  Useful if several QualityAssessors
     187                 :            :      *                are in use at the same time.
     188                 :            :      */
     189                 :            :     MESQUITE_EXPORT
     190                 :            :     QualityAssessor( QualityMetric* metric, int histogram_intervals = 0, double power_mean = 0.0,
     191                 :            :                      bool free_elements_only = true, const char* metric_value_tag_name = 0,
     192                 :            :                      bool print_summary_to_std_out = true, const char* inverted_element_tag_name = 0,
     193                 :            :                      std::string name = std::string() );
     194                 :            : 
     195                 :            :     MESQUITE_EXPORT virtual ~QualityAssessor();
     196                 :            : 
     197                 :            :     //! Provides a name to the QualityAssessor (use it for default name in constructor).
     198                 :            :     MESQUITE_EXPORT void set_name( std::string name )
     199                 :            :     {
     200                 :            :         qualityAssessorName = name;
     201                 :            :     };
     202                 :            :     //! Retrieves the QualityAssessor name. A default name should be set in the constructor.
     203                 :          1 :     MESQUITE_EXPORT virtual std::string get_name() const
     204                 :            :     {
     205                 :          1 :         return qualityAssessorName;
     206                 :            :     }
     207                 :            : 
     208                 :            :     /**\brief All elements or only improvable ones.
     209                 :            :      *
     210                 :            :      * If set to true, the quality assessment results will include
     211                 :            :      * quality values only for those elements (or more precisely metric
     212                 :            :      * sample points) which are influenced by at least one free vertex.
     213                 :            :      * That is, quality for elements (or sample points) that the sovler
     214                 :            :      * cannot improve (e.g. an element with all vertices fixed) will not
     215                 :            :      * be included in the quality assessment.
     216                 :            :      *
     217                 :            :      * If set to false, quality for all elements will be assessed.
     218                 :            :      */
     219                 :            :     MESQUITE_EXPORT void measure_free_samples_only( bool yesno )
     220                 :            :     {
     221                 :            :         skipFixedSamples = yesno;
     222                 :            :     }
     223                 :            : 
     224                 :            :     /**\brief All elements or only improvable ones.
     225                 :            :      *
     226                 :            :      * If set to true, the quality assessment results will include
     227                 :            :      * quality values only for those elements (or more precisely metric
     228                 :            :      * sample points) which are influenced by at least one free vertex.
     229                 :            :      * That is, quality for elements (or sample points) that the sovler
     230                 :            :      * cannot improve (e.g. an element with all vertices fixed) will not
     231                 :            :      * be included in the quality assessment.
     232                 :            :      *
     233                 :            :      * If set to false, quality for all elements will be assessed.
     234                 :            :      */
     235                 :            :     MESQUITE_EXPORT bool measuring_free_samples_only() const
     236                 :            :     {
     237                 :            :         return skipFixedSamples;
     238                 :            :     }
     239                 :            : 
     240                 :            :     /**\brief Register a QualityMetric for use in quality assessment.
     241                 :            :      *
     242                 :            :      * Add a quality metric to the list of metrics used to assess
     243                 :            :      * the quality of the mesh.
     244                 :            :      *
     245                 :            :      *\param metric   QualtiyMetric to register for use in assessing mesh
     246                 :            :      *                quality.  Will also be used as the "stopping assessment".
     247                 :            :      *\param historgram_intervals If non-zero, a histogram of quality metric
     248                 :            :      *                values composed of the specified number of intervals
     249                 :            :      *                will be generated.
     250                 :            :      *\param power_mean If non-zero, in addition to the normal summary
     251                 :            :      *                statistics for the quality metric, an additional
     252                 :            :      *                general power mean with the specified power will
     253                 :            :      *                be calculated.
     254                 :            :      *\param metric_value_tag_name  If a non-null value is specified,
     255                 :            :      *                a tag with the specified name will be populated
     256                 :            :      *                with quality values for individual elements or
     257                 :            :      *                vertices if metric is an element-based or vertex-
     258                 :            :      *                based metric.  If metric is not element-based or
     259                 :            :      *                vertex-based, this argument has no effect.
     260                 :            :      *\param  inverted_element_tag_name  If a non-null value is specified,
     261                 :            :      *                an integer tag with the specified name will be used
     262                 :            :      *                it store value of 0 for normal elements and 1 for
     263                 :            :      *                inverted elements.
     264                 :            :      */
     265                 :            :     MESQUITE_EXPORT
     266                 :            :     void add_quality_assessment( QualityMetric* metric, int histogram_intervals = 0, double power_mean = 0.0,
     267                 :            :                                  const char* metric_value_tag_name = 0, const char* metric_label = 0 );
     268                 :            : 
     269                 :            :     /**\brief Same as add_quality_assessment, except that the average
     270                 :            :      *        metric value is also used as the return value from loop_over_mesh.
     271                 :            :      *        Specify a power_mean value to control which average is used.
     272                 :            :      */
     273                 :            :     MESQUITE_EXPORT
     274                 :            :     void set_stopping_assessment( QualityMetric* metric, int histogram_intervals = 0, double power_mean = 0.0,
     275                 :            :                                   const char* metric_value_tag_name = 0, const char* metric_label = 0 );
     276                 :            : 
     277                 :            :     /**\brief Register a QualityMetric for use in quality assessment.
     278                 :            :      *
     279                 :            :      * Add a quality metric to the list of metrics used to assess
     280                 :            :      * the quality of the mesh.  Specify more parameters controlling
     281                 :            :      * histogram.
     282                 :            :      *
     283                 :            :      *\param metric   QualtiyMetric to register for use in assessing mesh
     284                 :            :      *                quality.  Will also be used as the "stopping assessment".
     285                 :            :      *\param min      Minimum of histogram rnage.
     286                 :            :      *\param max      Maximum of histogram range.
     287                 :            :      *\param intervals Histogram intervals.
     288                 :            :      *\param power_mean If non-zero, in addition to the normal summary
     289                 :            :      *                statistics for the quality metric, an additional
     290                 :            :      *                general power mean with the specified power will
     291                 :            :      *                be calculated.
     292                 :            :      *\param metric_value_tag_name  If a non-null value is specified,
     293                 :            :      *                a tag with the specified name will be populated
     294                 :            :      *                with quality values for individual elements or
     295                 :            :      *                vertices if metric is an element-based or vertex-
     296                 :            :      *                based metric.  If metric is not element-based or
     297                 :            :      *                vertex-based, this argument has no effect.
     298                 :            :      *\param  inverted_element_tag_name  If a non-null value is specified,
     299                 :            :      *                an integer tag with the specified name will be used
     300                 :            :      *                it store value of 0 for normal elements and 1 for
     301                 :            :      *                inverted elements.
     302                 :            :      */
     303                 :            :     MESQUITE_EXPORT
     304                 :            :     void add_histogram_assessment( QualityMetric* qm, double min, double max, int intervals, double power_mean = 0.0,
     305                 :            :                                    const char* metric_value_tag_name = 0, const char* metric_label = 0 );
     306                 :            : 
     307                 :            :     virtual MESQUITE_EXPORT void initialize_queue( MeshDomainAssoc* mesh_and_domain, const Settings* settings,
     308                 :            :                                                    MsqError& err );
     309                 :            : 
     310                 :            :     //! Does one sweep over the mesh and assess the quality with the metrics previously added.
     311                 :            :     virtual MESQUITE_EXPORT double loop_over_mesh( MeshDomainAssoc* mesh_and_domain, const Settings* settings,
     312                 :            :                                                    MsqError& err );
     313                 :            : 
     314                 :            :     //! Does one sweep over the mesh and assess the quality with the metrics previously added.
     315                 :            :     virtual MESQUITE_EXPORT double loop_over_mesh( ParallelMesh* mesh, MeshDomain* domain, const Settings* settings,
     316                 :            :                                                    MsqError& err );
     317                 :            : 
     318                 :            :     //! Do not print results of assessment.
     319                 :          3 :     MESQUITE_EXPORT void disable_printing_results()
     320                 :            :     {
     321                 :          3 :         printSummary = false;
     322                 :          3 :     }
     323                 :            : 
     324                 :            :     //! Print accumulated summary data to specified stream.
     325                 :            :     MESQUITE_EXPORT void print_summary( std::ostream& stream ) const;
     326                 :            : 
     327                 :            :     //! True if any metric evaluated to an invalid value
     328                 :            :     //! for any element
     329                 :            :     MESQUITE_EXPORT bool invalid_elements() const;
     330                 :            : 
     331                 :            :     //! Provides the number of inverted elements, inverted_elmes,
     332                 :            :     //!  and the number of elements whose orientation can not be
     333                 :            :     //!  determined, undefined_elems.
     334                 :            :     //! Returns false if this information is not yet available.
     335                 :            :     //! Returns true, otherwise.
     336                 :            :     MESQUITE_EXPORT bool get_inverted_element_count( int& inverted_elems, int& inverted_samples, MsqError& err );
     337                 :            : 
     338                 :            :     //! Reset calculated data
     339                 :            :     MESQUITE_EXPORT void reset_data();
     340                 :            : 
     341                 :            :     //! Produces two historgrams on a single scale from a before
     342                 :            :     //! optimization histogram and an after optimization histogram.
     343                 :            :     //! The histogram intervals are adjusted to include the enitre
     344                 :            :     //! range of both histograms, the horizontal interval value bars
     345                 :            :     //! are adjusted to be on the same scale, and the metric quality
     346                 :            :     //! values are placed in the correct quality value 'bin' based
     347                 :            :     //! on the new interval scale.
     348                 :            : 
     349                 :            :     MESQUITE_EXPORT void scale_histograms( QualityAssessor* optimal );
     350                 :            : 
     351                 :          0 :     MESQUITE_EXPORT void tag_inverted_elements( std::string tagname )
     352                 :            :     {
     353                 :          0 :         invertedTagName = tagname;
     354                 :          0 :     }
     355                 :            :     MESQUITE_EXPORT void dont_tag_inverted_elements()
     356                 :            :     {
     357                 :            :         invertedTagName.clear();
     358                 :            :     }
     359                 :     258673 :     MESQUITE_EXPORT bool tagging_inverted_elements() const
     360                 :            :     {
     361                 :     258673 :         return !invertedTagName.empty();
     362                 :            :     }
     363                 :            : 
     364                 :            :     MESQUITE_EXPORT void tag_fixed_elements( std::string tagname )
     365                 :            :     {
     366                 :            :         fixedTagName = tagname;
     367                 :            :     }
     368                 :            :     MESQUITE_EXPORT void dont_tag_fixed_elements()
     369                 :            :     {
     370                 :            :         fixedTagName.clear();
     371                 :            :     }
     372                 :       1727 :     MESQUITE_EXPORT bool tagging_fixed_elements() const
     373                 :            :     {
     374                 :       1727 :         return !fixedTagName.empty();
     375                 :            :     }
     376                 :            : 
     377                 :            :     /** \brief Per-metric QualityAssessor data
     378                 :            :      *
     379                 :            :      * The Assessor class holds QualityAssessor data for
     380                 :            :      * each metric added by the calling application, including
     381                 :            :      * a pointer to the metric instance, QAFunction flags
     382                 :            :      * dictating what is to be calculated and output, histogram
     383                 :            :      * parameters, and the variables used to accumulate results as
     384                 :            :      * the QualityAssessor is running.  It also provides
     385                 :            :      * methods to access the calculated data once the QualityAssessor
     386                 :            :      * pass is completed.
     387                 :            :      */
     388                 :        156 :     class Assessor
     389                 :            :     {
     390                 :            :       public:
     391                 :            :         MESQUITE_EXPORT Assessor( QualityMetric* metric, const char* name = 0 );
     392                 :            : 
     393                 :            :         MESQUITE_EXPORT double get_average() const;
     394                 :        141 :         MESQUITE_EXPORT double get_maximum() const
     395                 :            :         {
     396                 :        141 :             return maximum;
     397                 :            :         }
     398                 :        141 :         MESQUITE_EXPORT double get_minimum() const
     399                 :            :         {
     400                 :        141 :             return minimum;
     401                 :            :         }
     402                 :            :         MESQUITE_EXPORT double get_rms() const;
     403                 :            :         MESQUITE_EXPORT double get_stddev() const;
     404                 :            :         MESQUITE_EXPORT double get_power_mean() const;
     405                 :          0 :         MESQUITE_EXPORT double get_power() const
     406                 :            :         {
     407                 :          0 :             return pMean;
     408                 :            :         }
     409                 :        144 :         MESQUITE_EXPORT int get_count() const
     410                 :            :         {
     411                 :        144 :             return count;
     412                 :            :         }
     413                 :            : 
     414                 :     491375 :         MESQUITE_EXPORT bool have_power_mean() const
     415                 :            :         {
     416                 :     491375 :             return 0.0 != pMean;
     417                 :            :         }
     418                 :            : 
     419                 :        147 :         MESQUITE_EXPORT int get_invalid_element_count() const
     420                 :            :         {
     421                 :        147 :             return numInvalid;
     422                 :            :         }
     423                 :            : 
     424                 :            :         /** Get historgram of data, if calculated.
     425                 :            :          *\param lower_bound_out  The lower bound of the histogram
     426                 :            :          *\param upper_bound_out  The upper bound of the histogram
     427                 :            :          *\param counts_out       An array of counts of elements where
     428                 :            :          *              the first entry is the number of elements for
     429                 :            :          *              which the metric is below the lower bound, the
     430                 :            :          *              last entry is the number of elements above the
     431                 :            :          *              upper bound, and all other values are the counts
     432                 :            :          *              for histogram intervals between the lower and
     433                 :            :          *              upper bounds.
     434                 :            :          */
     435                 :            :         MESQUITE_EXPORT
     436                 :            :         void get_histogram( double& lower_bound_out, double& upper_bound_out, std::vector< int >& counts_out,
     437                 :            :                             MsqError& err ) const;
     438                 :            : 
     439                 :            :         /** Reset all calculated data */
     440                 :            :         MESQUITE_EXPORT void reset_data();
     441                 :            : 
     442                 :            :         /** Print the histogram */
     443                 :            :         MESQUITE_EXPORT void print_histogram( std::ostream&, int width = 0 ) const;
     444                 :            : 
     445                 :            :         /** Get the QualityMetric */
     446                 :     873002 :         MESQUITE_EXPORT QualityMetric* get_metric() const
     447                 :            :         {
     448                 :     873002 :             return qualMetric;
     449                 :            :         }
     450                 :            : 
     451                 :        414 :         MESQUITE_EXPORT const std::string& get_label() const
     452                 :            :         {
     453                 :        414 :             return mLabel;
     454                 :            :         }
     455                 :            : 
     456                 :            :         /** Add a value to the running counts */
     457                 :            :         MESQUITE_EXPORT void add_value( double metric_value );
     458                 :            : 
     459                 :            :         /** Add a value to the hisogram data */
     460                 :            :         MESQUITE_EXPORT void add_hist_value( double metric_value );
     461                 :            : 
     462                 :            :         /** Note invalid result */
     463                 :            :         MESQUITE_EXPORT void add_invalid_value();
     464                 :            : 
     465                 :     491865 :         MESQUITE_EXPORT bool have_histogram() const
     466                 :            :         {
     467                 :     491865 :             return !histogram.empty();
     468                 :            :         }
     469                 :            : 
     470                 :            :         /** If range of histogram has not yet been determined,
     471                 :            :          * calculate it from the min/max values.
     472                 :            :          */
     473                 :            :         MESQUITE_EXPORT void calculate_histogram_range();
     474                 :            : 
     475                 :     380735 :         MESQUITE_EXPORT bool write_to_tag() const
     476                 :            :         {
     477                 :     380735 :             return !tagName.empty();
     478                 :            :         }
     479                 :            : 
     480                 :         20 :         MESQUITE_EXPORT void set_stopping_function( bool value )
     481                 :            :         {
     482                 :         20 :             stoppingFunction = value;
     483                 :         20 :         }
     484                 :            : 
     485                 :        144 :         MESQUITE_EXPORT bool stopping_function() const
     486                 :            :         {
     487                 :        144 :             return stoppingFunction;
     488                 :            :         }
     489                 :            : 
     490                 :            :         MESQUITE_EXPORT double stopping_function_value() const;
     491                 :            : 
     492                 :            :       private:
     493                 :            :         friend class QualityAssessor;
     494                 :            : 
     495                 :            :         QualityMetric* const qualMetric;  //< The quality metric
     496                 :            :         std::string mLabel;
     497                 :            : 
     498                 :            :         unsigned long count;  //< The total number of times the metric was evaluated
     499                 :            : 
     500                 :            :         double sum;                //< The sum of the metric over all elements
     501                 :            :         double maximum;            //< The maximum of the metric
     502                 :            :         double minimum;            //< The minimum value of the metric
     503                 :            :         double sqrSum;             //< The sum of the square of the metric values
     504                 :            :         double pSum;               //< The sum of the metric values raised to the pMean power
     505                 :            :         unsigned long numInvalid;  //< Count of invalid metric values
     506                 :            : 
     507                 :            :         double pMean;  //< Power for general power-mean.
     508                 :            : 
     509                 :            :         /** The histogram counts, where the first and last values are
     510                 :            :          * counts of values below the lower bound and above the upper
     511                 :            :          * bound, respectively.  The remaining values are the histogram
     512                 :            :          * counts.
     513                 :            :          */
     514                 :            :         bool haveHistRange;
     515                 :            :         double histMin;  //< Lower bound of histogram
     516                 :            :         double histMax;  //< Upper bound of histogram
     517                 :            :         std::vector< int > histogram;
     518                 :            : 
     519                 :            :         std::string tagName;  //< Tag to which to write metric values.
     520                 :            :         /** Cached tag handle */
     521                 :            :         TagHandle tagHandle;
     522                 :            : 
     523                 :            :         /** Value is return value for all of QualityAssessor */
     524                 :            :         bool stoppingFunction;
     525                 :            : 
     526                 :            :         int referenceCount;
     527                 :            : 
     528                 :            :         enum AssessSchemes assessScheme;
     529                 :            :     };
     530                 :            : 
     531                 :            :     typedef std::list< Assessor* > list_type;
     532                 :            : 
     533                 :            :     /** \brief Request summary data for a specific QualityMetric
     534                 :            :      * This method allows the application to request the summary
     535                 :            :      * data for a metric it has registered with the QualityAssessor.
     536                 :            :      * If the passed QualityMetric has not been registered with the
     537                 :            :      * QualityAssessor instance, NULL is returned.
     538                 :            :      */
     539                 :            :     MESQUITE_EXPORT
     540                 :            :     const Assessor* get_results( QualityMetric* metric ) const;
     541                 :            : 
     542                 :            :     /** \brief Request summary data for a specific QualityMetric
     543                 :            :      * This method allows the application to request the summary
     544                 :            :      * data for a metric it has registered with the QualityAssessor.
     545                 :            :      * If the passed QualityMetric has not been registered with the
     546                 :            :      * QualityAssessor instance, NULL is returned.
     547                 :            :      */
     548                 :            :     MESQUITE_EXPORT
     549                 :            :     const Assessor* get_results( const char* metric_name ) const;
     550                 :            : 
     551                 :            :     /** \brief Get list of all summary data.
     552                 :            :      *  Return a const reference to the internal list of
     553                 :            :      *  calculated data.
     554                 :            :      */
     555                 :            :     const list_type& get_all_results() const
     556                 :            :     {
     557                 :            :         return assessList;
     558                 :            :     }
     559                 :            : 
     560                 :            :     MESQUITE_EXPORT
     561                 :            :     QualityAssessor( const QualityAssessor& copy );
     562                 :            : 
     563                 :            :     MESQUITE_EXPORT
     564                 :            :     QualityAssessor& operator=( const QualityAssessor& copy );
     565                 :            : 
     566                 :            :   private:
     567                 :            :     struct Data
     568                 :            :     {
     569                 :            :         /** Count of inverted elements. */
     570                 :            :         int invertedElementCount;
     571                 :            : 
     572                 :            :         /** Count of inverted Jacobians within elements.*/
     573                 :            :         int invertedSampleCount;
     574                 :            : 
     575                 :            :         /** Number of elements */
     576                 :            :         size_t elementCount;
     577                 :            : 
     578                 :            :         /** Total number of element Jacobians tested for inversion */
     579                 :            :         size_t sampleCount;
     580                 :            : 
     581                 :            :         /** Number of elements with at least one free vertex */
     582                 :            :         size_t freeElementCount;
     583                 :            : 
     584                 :            :         int referenceCount;
     585                 :            : 
     586                 :         57 :         Data() : referenceCount( 1 )
     587                 :            :         {
     588                 :         57 :             clear();
     589                 :         57 :         }
     590                 :            : 
     591                 :         57 :         void clear()
     592                 :            :         {
     593                 :         57 :             invertedElementCount = invertedSampleCount = -1;
     594                 :         57 :             elementCount = sampleCount = freeElementCount = 0;
     595                 :         57 :         }
     596                 :            :     };
     597                 :            : 
     598                 :            :     Data* myData;
     599                 :            : 
     600                 :            :     //! Common code for serial and parallel loop_over_mesh
     601                 :            :     double loop_over_mesh_internal( MeshDomainAssoc* mesh_and_domain, const Settings* settings, ParallelHelper* helper,
     602                 :            :                                     MsqError& err );
     603                 :            : 
     604                 :            :     /** Find an Assessor corresponding to the passed
     605                 :            :      *  QualityMetric, or create it if is not found in
     606                 :            :      *  the list.
     607                 :            :      */
     608                 :            :     list_type::iterator find_or_add( QualityMetric* qm, const char* label = 0 );
     609                 :            : 
     610                 :            :     /** Find an Assessor corresponding to the passed
     611                 :            :      *  QualityMetric, or create it if is not found in
     612                 :            :      *  the list.
     613                 :            :      */
     614                 :            :     list_type::iterator find_stopping_assessment();
     615                 :            : 
     616                 :            :     /** Find or create tag */
     617                 :            :     TagHandle get_tag( Mesh* mesh, std::string name, Mesh::TagType type, unsigned size, MsqError& err );
     618                 :            : 
     619                 :            :     /** Try to determine if output stream is a terminal and if so,
     620                 :            :         the width of that terminal.  Returns zero if width cannot
     621                 :            :         be determined. */
     622                 :            :     int get_terminal_width() const;
     623                 :            : 
     624                 :            :     static std::string element_name_as_string( int enum_name );
     625                 :            : 
     626                 :            :     static double round_to_3_significant_digits( double number );
     627                 :            : 
     628                 :            :     /** Name */
     629                 :            :     std::string qualityAssessorName;
     630                 :            : 
     631                 :            :     /** List of quality metrics and corresponding data */
     632                 :            :     list_type assessList;
     633                 :            : 
     634                 :            :     /** Stream to which to write summary of metric data */
     635                 :            :     std::ostream& outputStream;
     636                 :            :     /** Disable printing */
     637                 :            :     bool printSummary;
     638                 :            : 
     639                 :            :     std::string invertedTagName, fixedTagName;
     640                 :            : 
     641                 :            :     bool skipFixedSamples;
     642                 :            : 
     643                 :            :     int elementTypeCount[MIXED - POLYGON + 1];
     644                 :            : 
     645                 :            :     bool invalid_values;  // set to true when a target metric contains inverted elements
     646                 :            : };
     647                 :            : 
     648                 :            : }  // namespace MBMesquite
     649                 :            : 
     650                 :            : #endif  // QualityAssessor_hpp

Generated by: LCOV version 1.11