Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
inks/MaxTemplate.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  ***************************************************************** */
36 #include <math.h>
37 #include "MaxTemplate.hpp"
38 #include "QualityMetric.hpp"
39 #include "PatchData.hpp"
40 
41 namespace Mesquite {
42 
43 MaxTemplate::MaxTemplate(QualityMetric *qualitymetric){
44  set_quality_metric(qualitymetric);
45  set_negate_flag(qualitymetric->get_negate_flag());
47 }
48 
49 //Lori: need to clean up here
51 
52 }
53 
54 bool MaxTemplate::concrete_evaluate(PatchData &patch, double &fval,
55  MsqError &err){
56 
57  //Total value of objective function
58  fval = 0.0;
59  double temp_value=0;
60  bool obj_bool = true;
61  //For elements in Patch
62  int index;
63  QualityMetric* currentQM = get_quality_metric();
64  if(currentQM->get_metric_type()==QualityMetric::ELEMENT_BASED){
65 
66  int num_elements=patch.num_elements();
67  MsqMeshEntity* elems=patch.get_element_array(err); MSQ_ERRZERO(err);
68 
69  for (index=0; index<num_elements; index++){
70 
71  //evaluate metric for this elem
72  obj_bool = currentQM->evaluate_element(patch, &elems[index],
73  temp_value, err);
74  //if invalid patch
75  if(MSQ_CHKERR(err) || !obj_bool ){
76  fval = 0.0;
77  return false;
78  }
79 
80  if(temp_value>fval )
81  fval=temp_value;
82 
83  }//end loop over elements
84  }//end if not VERTEX
85 
86  else if (currentQM->get_metric_type()==QualityMetric::VERTEX_BASED) {
87 
88  int num_vertices=patch.num_vertices();
89  MsqVertex* vertices=patch.get_vertex_array(err); MSQ_ERRZERO(err);
90 
91  for (index=0; index<num_vertices;index++){
92 
93  //evaluate metric for this vertex
94  obj_bool=currentQM->evaluate_vertex(patch, &vertices[index],
95  temp_value, err);
96  //if invalid patch
97  if(MSQ_CHKERR(err) || !obj_bool ){
98  fval = 0.0;
99  return false;
100  }
101  if(temp_value>fval)
102  fval=temp_value;
103 
104  }//end loop over vertices
105  }//end else VERTEX
106  else {
107  MSQ_SETERR(err)("Make sure MetricType is initialised in concrete "
108  "QualityMetric constructor.", MsqError::INVALID_STATE);
109  return false;
110  }
111 
112  return true;
113 }
114 
115  bool MaxTemplate::compute_analytical_gradient(PatchData &patch,
116  Vector3D *const &grad,
117  double &OF_val,
118  MsqError &err,
119  size_t array_size)
120  {
121  MSQ_SETERR(err)("The MaxTemplate is not sufficient for methods requiring\n"
122  " gradient information. If you neeed to try this anyway, \n"
123  " set the gradient type to numerical.\n",
125  return false;
126  }
127 } // namespace Mesquite
128 
129 
void set_gradient_type(GRADIENT_TYPE grad)
Set gradType to either NUMERICAL_GRADIENT or ANALYTICAL_GRADIENT.
#define MSQ_ERRZERO(err)
Return zero/NULL on error.
void set_quality_metric(QualityMetric *qm)
Set the value of qMetric.
virtual bool compute_analytical_gradient(PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size)
virtual bool concrete_evaluate(PatchData &patch, double &fval, MsqError &err)
every differentiable function should have an analytical gradient implemented.
Definition: patch.h:74
NVec< 3, double > Vector3D
#define MSQ_CHKERR(err)
Mesquite&#39;s Error Checking macro.
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
void set_negate_flag(int neg)
Set the value of ObjectiveFunction&#39;s negateFlag. Unless composite, concrete ObjectiveFunctions should...
object is in an invalid state