Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ObjectiveFunction/CompositeOFMultiply.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>
36 #include "CompositeOFMultiply.hpp"
37 #include "MsqTimer.hpp"
38 #include "PatchData.hpp"
39 
40 namespace Mesquite {
41 
42 
57  if(Obj1->get_quality_metric()==Obj2->get_quality_metric()){
59  }
60  else
61  set_quality_metric(NULL);
62  objFunc1=Obj1;
63  objFunc2=Obj2;
64  //if both obj1 and ob2 have been negated
65  if(Obj1->get_negate_flag()-Obj2->get_negate_flag()==-2)
66  set_negate_flag(-1);
67  else
68  set_negate_flag(1);
70 }
71 
72 //Michael: need to clean up here
74 
75 }
76 
81 msq_std::list<QualityMetric*> CompositeOFMultiply::get_quality_metric_list()
82 {
83  msq_std::list<QualityMetric*> temp_list=objFunc1->get_quality_metric_list();
84  msq_std::list<QualityMetric*> temp_list2=objFunc2->get_quality_metric_list();
85  temp_list.merge(temp_list2);
86  return temp_list;
87 }
88 
89 
100  MsqError &err){
101  double second_val;
102  //if invalid, return false without calculating fval.
103  bool b = objFunc1->evaluate(patch, fval, err);
104  if(MSQ_CHKERR(err) || !b){
105  fval=0.0;
106  return false;
107  }
108 
109  b = objFunc2->evaluate(patch, second_val, err);
110  if(MSQ_CHKERR(err) || !b){
111  fval=0.0;
112  return false;
113  }
114  fval*=second_val;
115  return true;
116 }
117 
129  Vector3D *const &grad,
130  double &OF_val,
131  MsqError &err,
132  size_t array_size)
133 {
134  MSQ_FUNCTION_TIMER( "CompositeOFMultiply::compute_analytical_gradient" );
135 
136  double obj_2_val=0.0;
137  //get the first gradient and objective function value
138  bool rval=objFunc1->compute_gradient(patch, grad, OF_val, err, array_size); MSQ_ERRZERO(err);
139  //if the above is valid, get the second gradient
140  if(rval){
141  int num_vert=patch.num_vertices();
142  Vector3D* second_grad = new Vector3D[num_vert];
143  //get second objective function's gradient
144  rval=objFunc2->compute_gradient(patch, second_grad,obj_2_val,
145  err, num_vert);
146  //if both objective functions gradients were successfully computed,
147  //use the multiplaction rule to get the complete gradient.
148  if(rval){
149  int i=0;
150  for(i=0;i<num_vert;++i){
151  grad[i]*=obj_2_val;
152  grad[i]+=(second_grad[i]*OF_val);
153  }
154  }
155  //delete the dynamically allocated space for the second gradient
156  delete []second_grad;
157  }
158 
159  //true if both gradient and both evaluate were successful.
160  //compute the objective function value by mulitiplying
161  //OF_val and obj_2_val
162  if(rval)
163  OF_val*=obj_2_val;
164  else
165  OF_val=0.0;
166  return rval;
167 }
168 
169 
170 } // 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.
virtual msq_std::list< QualityMetric * > get_quality_metric_list()
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.
CompositeOFMultiply(ObjectiveFunction *, ObjectiveFunction *)
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)
Base class for concrete Objective Functions ObjectiveFunction contains a pointer to a QualityMetric...
bool compute_analytical_gradient(PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size)
Implement the scalar multiply analytic gradient.