Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ObjectiveFunction/CompositeOFAdd.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 "ObjectiveFunction.hpp"
37 #include "CompositeOFAdd.hpp"
38 #include "MsqTimer.hpp"
39 #include "PatchData.hpp"
40 
41 namespace Mesquite {
42 
43 
55  ObjectiveFunction* Obj2){
56  if(Obj1->get_quality_metric()==Obj2->get_quality_metric()){
58  }
59  else
60  set_quality_metric(NULL);
61  objFunc1=Obj1;
62  objFunc2=Obj2;
63  set_negate_flag(1);
65 }
66 
67 //Michael: need to clean up here
69 
70 }
71 
76 msq_std::list<QualityMetric*> CompositeOFAdd::get_quality_metric_list()
77 {
78  msq_std::list<QualityMetric*> temp_list=objFunc1->get_quality_metric_list();
79  msq_std::list<QualityMetric*> temp_list2=objFunc2->get_quality_metric_list();
80  temp_list.merge(temp_list2);
81  return temp_list;
82 
83 }
84 
96  MsqError &err){
97  double second_val=0.0;
98  //If patch is invalid
99  bool b = objFunc1->evaluate( patch, fval, err );
100  if (MSQ_CHKERR(err) || !b) {
101  fval=0.0;
102  return false;
103  }
104  b = objFunc2->evaluate(patch, second_val, err);
105  if (MSQ_CHKERR(err) || !b) {
106  fval=0.0;
107  return false;
108  }
109  fval+=second_val;
110  return true;
111 }
112 
113 
126  Vector3D *const &grad,
127  double &OF_val,
128  MsqError &err,
129  size_t array_size)
130 {
131  MSQ_FUNCTION_TIMER( "CompositeOFAdd::compute_analytical_gradient" );
132  double second_val=0.0;//store the second objective function val
133  OF_val=0.0;
134  //get first objective function's gradient
135  bool rval=objFunc1->compute_gradient(patch, grad, OF_val,
136  err, array_size); MSQ_ERRZERO(err);
137  if(rval){
138  int num_vert=patch.num_vertices();
139  Vector3D* second_grad = new Vector3D[num_vert];
140  //get second objective function's gradient
141  rval=objFunc2->compute_gradient(patch, second_grad, second_val,
142  err, num_vert);
143  //if both objective functions were successfully computed, add them
144  if(rval){
145  //add the two objective function values.
146  OF_val+=second_val;
147  int i=0;
148  for(i=0;i<num_vert;++i){
149  grad[i]+=second_grad[i];
150  }
151  //delete the dynamically allocated space for the second gradient
152  delete []second_grad;
153  }
154  }
155  //true if both of the above compute gradient's were successful.
156  if(!rval)
157  OF_val=0.0;
158  return rval;
159 }
160 
161 } //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.
CompositeOFAdd(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...
bool compute_analytical_gradient(PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size)
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...
virtual msq_std::list< QualityMetric * > get_quality_metric_list()