Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
inks/AddQualityMetric.cpp
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  ***************************************************************** */
35 #include "AddQualityMetric.hpp"
36 #include "QualityMetric.hpp"
37 #include "Vector3D.hpp"
38 #include "MsqDebug.hpp"
39 
40 using namespace Mesquite;
41 
43  : qualMetric1( qm1 ),
44  qualMetric2( qm2 )
45 {
46  if(qm1 == NULL || qm2 == NULL){
47  MSQ_SETERR(err)("AddQualityMetric constructor passed NULL pointer.",
49  return;
50  }
52  if(qm2->get_feasible_constraint())
54  int n_flag=qm1->get_negate_flag();
55  if(n_flag!=qm2->get_negate_flag()){
56  MSQ_DBGOUT(1) << "AddQualityMetric is being used to compose a metric "
57  << "that should be minimized\n with a metric that should be "
58  << "maximized.";
59  set_negate_flag(1);
60  }
61  else{
62  set_negate_flag(n_flag);
63  }
64 
65  // Checks that metrics are of the same type
66  if ( qm1->get_metric_type() != qm2->get_metric_type() ) {
67  MSQ_SETERR(err)("Cannot add a vertex-based QM with an element-based QM.",
69  return;
70  } else {
72  }
73 
74  set_name("Composite Add");
75 }
76 
80  MsqMeshEntity *element,
81  double &value,
82  MsqError &err)
83 {
84  bool valid_flag;
85  double metric1, metric2;
86  valid_flag=qualMetric1->evaluate_element(pd, element, metric1, err); MSQ_ERRZERO(err);
87  if(!valid_flag)
88  return false;
89  valid_flag=qualMetric2->evaluate_element(pd, element, metric2, err); MSQ_ERRZERO(err);
90  value = metric1+metric2;
91  //if the first metric was invalid we have already returned
92  //so we return whatever the flag was on the second metric.
93  return valid_flag;
94 }
95 
99  MsqVertex* vert,
100  double &value,
101  MsqError& err)
102 {
103  bool valid_flag;
104  double metric1, metric2;
105  valid_flag=qualMetric1->evaluate_vertex(pd, vert, metric1, err); MSQ_ERRZERO(err);
106  if(!valid_flag)
107  return false;
108  valid_flag=qualMetric2->evaluate_vertex(pd, vert, metric2, err); MSQ_ERRZERO(err);
109  value = metric1+metric2;
110  //if the first metric was invalid we have already returned
111  //so we return whatever the flag was on the second metric.
112  return valid_flag;
113 }
114 
#define MSQ_ERRZERO(err)
Return zero/NULL on error.
int get_negate_flag()
Returns negateFlag.
Used to hold the error state and return it to the application.
Base class for concrete quality metrics.
bool evaluate_element(PatchData &pd, MsqMeshEntity *element, double &value, MsqError &err)
MsqMeshEntity is the Mesquite object that stores information about the elements in the mesh...
AddQualityMetric(QualityMetric *qm1, QualityMetric *qm2, MsqError &err)
invalid function argument passed
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
virtual bool evaluate_element(PatchData &, MsqMeshEntity *, double &, MsqError &err)
Evaluate the metric for an element.
virtual bool evaluate_vertex(PatchData &, MsqVertex *, double &, MsqError &err)
Evaluate the metric for a vertex.
object is in an invalid state
void set_metric_type(MetricType t)
This function should be used in the constructor of every concrete quality metric. ...
bool evaluate_vertex(PatchData &pd, MsqVertex *vertex, double &value, MsqError &err)
#define MSQ_DBGOUT(flag)
Check debug flag and return ostream associated with flag.
MsqVertex is the Mesquite object that stores information about the vertices in the mesh...
int get_feasible_constraint()
Returns the feasible flag for this metric.
void set_name(msq_std::string st)
Sets the name of this metric.