Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CompositeOFAdd Class Reference

Adds two ObjectiveFunction values together. More...

#include <CompositeOFAdd.hpp>

Inheritance diagram for CompositeOFAdd:
Collaboration diagram for CompositeOFAdd:

Public Member Functions

 CompositeOFAdd (ObjectiveFunction *, ObjectiveFunction *)
 
virtual ~CompositeOFAdd ()
 
virtual bool concrete_evaluate (PatchData &patch, double &fval, MsqError &err)
 
virtual msq_std::list
< QualityMetric * > 
get_quality_metric_list ()
 
 CompositeOFAdd (ObjectiveFunction *, ObjectiveFunction *)
 
virtual ~CompositeOFAdd ()
 
virtual bool concrete_evaluate (PatchData &patch, double &fval, MsqError &err)
 
virtual msq_std::list
< QualityMetric * > 
get_quality_metric_list ()
 
- Public Member Functions inherited from ObjectiveFunction
 ObjectiveFunction ()
 
virtual ~ObjectiveFunction ()
 
bool evaluate (PatchData &patch, double &fval, MsqError &err)
 
void set_gradient_type (GRADIENT_TYPE grad)
 Set gradType to either NUMERICAL_GRADIENT or ANALYTICAL_GRADIENT. More...
 
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 gradType. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'. More...
 
bool compute_hessian (PatchData &patch, MsqHessian &hessian, Vector3D *const &grad, double &OF_val, MsqError &err)
 Calls compute_analytical_hessian. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'. More...
 
QualityMetricget_quality_metric ()
 
void set_quality_metric (QualityMetric *qm)
 Set the value of qMetric. More...
 
void set_negate_flag (int neg)
 Set the value of ObjectiveFunction's negateFlag. Unless composite, concrete ObjectiveFunctions should set this flag to to the value of the associated QualityMetric's negateFLag. More...
 
int get_negate_flag ()
 Returns negateFlag. More...
 
 ObjectiveFunction ()
 
virtual ~ObjectiveFunction ()
 
bool evaluate (PatchData &patch, double &fval, MsqError &err)
 
void set_gradient_type (GRADIENT_TYPE grad)
 Set gradType to either NUMERICAL_GRADIENT or ANALYTICAL_GRADIENT. More...
 
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 gradType. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'. More...
 
bool compute_hessian (PatchData &patch, MsqHessian &hessian, Vector3D *const &grad, double &OF_val, MsqError &err)
 Calls compute_analytical_hessian. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'. More...
 
QualityMetricget_quality_metric ()
 
void set_quality_metric (QualityMetric *qm)
 Set the value of qMetric. More...
 
void set_negate_flag (int neg)
 Set the value of ObjectiveFunction's negateFlag. Unless composite, concrete ObjectiveFunctions should set this flag to to the value of the associated QualityMetric's negateFLag. More...
 
int get_negate_flag ()
 Returns negateFlag. More...
 

Protected Member Functions

bool compute_analytical_gradient (PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size)
 
bool compute_analytical_gradient (PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size)
 
- Protected Member Functions inherited from ObjectiveFunction
bool compute_numerical_gradient (PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size)
 Non-virtual function which numerically computes the gradient of the Objective Function. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'. More...
 
virtual bool compute_analytical_hessian (PatchData &, MsqHessian &, Vector3D *const &, double &, MsqError &)
 
double get_eps (PatchData &pd, double &local_val, int k, MsqVertex *vertex, MsqError &err)
 Returns eps used in the numerical gradient calculation. More...
 
void set_use_local_gradient (bool new_bool)
 Sets useLocalGradient This variable determines whether compute_numercial_gradient can use the most efficient gradient calculation. More...
 
bool compute_numerical_gradient (PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size)
 Non-virtual function which numerically computes the gradient of the Objective Function. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'. More...
 
virtual bool compute_analytical_hessian (PatchData &, MsqHessian &, Vector3D *const &, double &, MsqError &)
 
double get_eps (PatchData &pd, double &local_val, int k, MsqVertex *vertex, MsqError &err)
 Returns eps used in the numerical gradient calculation. More...
 
void set_use_local_gradient (bool new_bool)
 Sets useLocalGradient This variable determines whether compute_numercial_gradient can use the most efficient gradient calculation. More...
 

Private Attributes

ObjectiveFunctionobjFunc1
 
ObjectiveFunctionobjFunc2
 

Additional Inherited Members

- Public Types inherited from ObjectiveFunction
enum  GRADIENT_TYPE { NUMERICAL_GRADIENT, ANALYTICAL_GRADIENT, NUMERICAL_GRADIENT, ANALYTICAL_GRADIENT }
 
enum  GRADIENT_TYPE { NUMERICAL_GRADIENT, ANALYTICAL_GRADIENT, NUMERICAL_GRADIENT, ANALYTICAL_GRADIENT }
 

Detailed Description

Adds two ObjectiveFunction values together.

Definition at line 53 of file includeLinks/CompositeOFAdd.hpp.

Constructor & Destructor Documentation

Sets the QualityMetric pointer to the metric associated with Obj1 and Obj2 if Obj1 and Obj2 are associated with the same metric. Otherwise, it sets the QualityMetric pointer to NULL. The new ObjectiveFunction's negateFlag is always set to one, because the values produced by obj1 and obj2 have already been multiplied by negative one if it was needed. Defaults to the analytical gradient.

Parameters
Obj1(ObjectiveFunction*)
Obj2(ObjectiveFunction*)

Definition at line 54 of file ObjectiveFunction/CompositeOFAdd.cpp.

References ObjectiveFunction::ANALYTICAL_GRADIENT, ObjectiveFunction::get_quality_metric(), CompositeOFAdd::objFunc1, CompositeOFAdd::objFunc2, ObjectiveFunction::set_gradient_type(), ObjectiveFunction::set_negate_flag(), and ObjectiveFunction::set_quality_metric().

55  {
56  if(Obj1->get_quality_metric()==Obj2->get_quality_metric()){
57  set_quality_metric(Obj1->get_quality_metric());
58  }
59  else
60  set_quality_metric(NULL);
61  objFunc1=Obj1;
62  objFunc2=Obj2;
63  set_negate_flag(1);
65 }
void set_gradient_type(GRADIENT_TYPE grad)
Set gradType to either NUMERICAL_GRADIENT or ANALYTICAL_GRADIENT.
void set_quality_metric(QualityMetric *qm)
Set the value of qMetric.
every differentiable function should have an analytical gradient implemented.
void set_negate_flag(int neg)
Set the value of ObjectiveFunction&#39;s negateFlag. Unless composite, concrete ObjectiveFunctions should...

Here is the call graph for this function:

~CompositeOFAdd ( )
virtual

Definition at line 68 of file ObjectiveFunction/CompositeOFAdd.cpp.

68  {
69 
70 }
virtual ~CompositeOFAdd ( )
virtual

Member Function Documentation

bool compute_analytical_gradient ( PatchData patch,
Vector3D *const &  grad,
double &  OF_val,
MsqError err,
size_t  array_size 
)
protectedvirtual

Analytically computes the composite objective function's gradient by combining the gradients returned from objFunc2->compute_gradient() and objFunc2->compute_gradient().

Parameters
patchThe PatchData object for which the objective function gradient is computed.
gradAn array of Vector3D, at least the size of the number of vertices in the patch.
OF_valThe objective function value.
array_sizeis the size of the grad Vector3D[] array and must correspond to the number of vertices in the patch.

Reimplemented from ObjectiveFunction.

Definition at line 125 of file ObjectiveFunction/CompositeOFAdd.cpp.

References ObjectiveFunction::compute_gradient(), i, MSQ_ERRZERO, MSQ_FUNCTION_TIMER, PatchData::num_vertices(), CompositeOFAdd::objFunc1, and CompositeOFAdd::objFunc2.

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 }
#define MSQ_ERRZERO(err)
Return zero/NULL on error.
Definition: patch.h:74
NVec< 3, double > Vector3D
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

Here is the call graph for this function:

bool compute_analytical_gradient ( PatchData patch,
Vector3D *const &  grad,
double &  OF_val,
MsqError err,
size_t  array_size 
)
protectedvirtual

Fills an array of Vector3D, grad, with the gradient of the objective function computed using the gradient of the quality metric. If the function has not been over-riden in the concrete Objective Function, the base class implementation prints a warning and then defaults to numerical gradient. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'.

Parameters
patchThe PatchData object for which the objective function gradient is computed.
gradAn array of Vector3D, at least the size of the number of vertices in the patch.
OF_valis set to the value of the objective function.
array_sizeis the size of the grad Vector3D[] array and must correspond to the number of vertices in the patch.

Reimplemented from ObjectiveFunction.

virtual bool concrete_evaluate ( PatchData patch,
double &  fval,
MsqError err 
)
virtual

Evaluate the objective function on a given patch.

Implements ObjectiveFunction.

bool concrete_evaluate ( PatchData patch,
double &  fval,
MsqError err 
)
virtual

Compute fval= objFunc1->evaluate(patch,err)+objFunc2->evaluate(patch,err). Note that since objFunc1 and objFunc2's evaluate() functions are called (as opposed to their concrete_evaluates) the returned values have already been multiplied by the respective negateFlag (that is, if objFunc1 (or objFunc2) needed to be maximized then the value has been multiplied by negative one so that it may be minimized instead.) Function returns `false' if either objFunc1->concrete_evaluate() or objFunc2->concrete_evaluate() returns `false'; otherwise, function returns `true'.

Implements ObjectiveFunction.

Definition at line 95 of file ObjectiveFunction/CompositeOFAdd.cpp.

References ObjectiveFunction::evaluate(), MSQ_CHKERR, CompositeOFAdd::objFunc1, and CompositeOFAdd::objFunc2.

96  {
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 }
bool evaluate(PatchData &patch, double &fval, MsqError &err)
Definition: patch.h:74
#define MSQ_CHKERR(err)
Mesquite&#39;s Error Checking macro.

Here is the call graph for this function:

msq_std::list< QualityMetric * > get_quality_metric_list ( )
virtual

Returns the QualityMetric list associated with objFunc1 merged with the QualityMetric list associated with objFunc2. The entries in this merged list may not be unique.

Reimplemented from ObjectiveFunction.

Definition at line 76 of file ObjectiveFunction/CompositeOFAdd.cpp.

References ObjectiveFunction::get_quality_metric_list(), CompositeOFAdd::objFunc1, and CompositeOFAdd::objFunc2.

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 }
virtual msq_std::list< QualityMetric * > get_quality_metric_list()

Here is the call graph for this function:

virtual msq_std::list<QualityMetric*> get_quality_metric_list ( )
virtual

returns a list of all associated metrics;

Reimplemented from ObjectiveFunction.

Member Data Documentation


The documentation for this class was generated from the following files: