Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ObjectiveFunction/CompositeOFScalarMultiply.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 <math.h>
37 #include "MsqTimer.hpp"
38 #include "MsqError.hpp"
39 #include "MsqDebug.hpp"
40 #include "PatchData.hpp"
41 
42 namespace Mesquite {
43 
44 
54 
56  objFunc=Obj;
57  mAlpha=alp;
58  if(alp<0)
59  set_negate_flag(-1);
60  else if (alp>0)
61  set_negate_flag(1);
62  else
63  MSQ_DBGOUT(1) << "ObjectiveFunction being scaled by zero.";
65 }
66 
67 //Michael: need to clean up here
69 
70 }
71 
80  double &fval, MsqError &err){
81  //if invalid return false without calculating fval
82  bool b = objFunc->evaluate(patch, fval, err);
83  if (MSQ_CHKERR(err) || !b){
84  fval = 0.0;
85  return false;
86 
87  }
88  fval*=mAlpha;
89  return true;
90 }
91 
95 }
96 
97 
111  Vector3D *const
112  &grad,
113  double &OF_val,
114  MsqError &err,
115  size_t array_size)
116 {
117  MSQ_FUNCTION_TIMER( "CompositeOFScalarMultiply::compute_analytical_gradient" );
118 
119  double scale_factor=(get_negate_flag()*mAlpha);
120  bool rval=objFunc->compute_gradient(patch, grad, OF_val, err, array_size); MSQ_ERRZERO(err);
121  int num_vert=patch.num_vertices();
122  int i=0;
123  //If the objFunc was successful in calculating the gradient
124  if(rval){
125  //scale the gradient by alpha
126  for(i=0;i<num_vert;++i){
127  grad[i]*=scale_factor;
128  }
129  //scale the OF_val
130  OF_val*=mAlpha;
131  }
132  else{
133  OF_val=0.0;
134  }
135  return rval;
136 }
137 
138 } // namespace Mesquite
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.
Used to hold the error state and return it to the application.
bool evaluate(PatchData &patch, double &fval, MsqError &err)
Vector3D is the object that effeciently stores information about about three-deminsional vectors...
every differentiable function should have an analytical gradient implemented.
virtual msq_std::list< QualityMetric * > get_quality_metric_list()
Returns the QualityMetric list assossiated with objFunc.
bool compute_analytical_gradient(PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size)
Implement the scalar multiply analytic gradient.
virtual msq_std::list< QualityMetric * > get_quality_metric_list()
Definition: patch.h:74
#define MSQ_CHKERR(err)
Mesquite&#39;s Error Checking macro.
bool compute_gradient(PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size=0)
Calls either compute_numerical_gradient or compute_analytical_gradient depending on the value of grad...
blockLoc i
Definition: read.cpp:79
void set_negate_flag(int neg)
Set the value of ObjectiveFunction&#39;s negateFlag. Unless composite, concrete ObjectiveFunctions should...
size_t num_vertices() const
number of vertices in the patch.
virtual bool concrete_evaluate(PatchData &patch, double &fval, MsqError &err)
#define MSQ_DBGOUT(flag)
Check debug flag and return ostream associated with flag.
Base class for concrete Objective Functions ObjectiveFunction contains a pointer to a QualityMetric...