MOAB: Mesh Oriented datABase  (version 5.4.1)
MBMesquite::CompositeOFScalarAdd Class Reference

Adds a scalar to a given ObjectiveFunction. More...

#include <CompositeOFScalarAdd.hpp>

+ Inheritance diagram for MBMesquite::CompositeOFScalarAdd:
+ Collaboration diagram for MBMesquite::CompositeOFScalarAdd:

Public Member Functions

 CompositeOFScalarAdd (double, ObjectiveFunction *, bool delete_OF=false)
virtual ~CompositeOFScalarAdd ()
virtual void initialize_queue (MeshDomainAssoc *mesh_and_domain, const Settings *settings, MsqError &err)
 Called at start of instruction queue processing.
virtual bool initialize_block_coordinate_descent (MeshDomainAssoc *mesh_and_domain, const Settings *settings, PatchSet *user_set, MsqError &err)
 Initial accumulated value for block coordinate descent algorithms.
virtual bool evaluate (EvalType type, PatchData &pd, double &value_out, bool free, MsqError &err)
 Evaluate objective function for specified patch.
virtual bool evaluate_with_gradient (EvalType type, PatchData &pd, double &value_out, std::vector< Vector3D > &grad_out, MsqError &err)
 Evaluate objective function and gradient for specified patch.
virtual bool evaluate_with_Hessian_diagonal (EvalType type, PatchData &pd, double &value_out, std::vector< Vector3D > &grad_out, std::vector< SymMatrix3D > &hess_diag_out, MsqError &err)
 Evaluate objective function and diagonal blocks of Hessian for specified patch.
virtual bool evaluate_with_Hessian (EvalType type, PatchData &pd, double &value_out, std::vector< Vector3D > &grad_out, MsqHessian &Hessian_out, MsqError &err)
 Evaluate objective function and Hessian for specified patch.
virtual ObjectiveFunctionclone () const
 Create copy with same state.
virtual void clear ()
virtual int min_patch_layers () const

Private Attributes

double mAlpha
ObjectiveFunctionobjFunc
bool deleteObjFunc

Detailed Description

Adds a scalar to a given ObjectiveFunction.

Definition at line 53 of file CompositeOFScalarAdd.hpp.


Constructor & Destructor Documentation

CompositeOFScalarAdd::CompositeOFScalarAdd ( double  alp,
ObjectiveFunction Obj1,
bool  delete_OF = false 
)

Sets the QualityMetric pointer to the metric associated with Obj1. The new ObjectiveFunction's negateFlag is also the same as that of Obj1. This objective function defaults to the analytical gradient which essentially just calls Obj1's gradient function.

Parameters:
alp(double)
Obj1(ObjectiveFunction*)

Definition at line 49 of file CompositeOFScalarAdd.cpp.

References mAlpha, and objFunc.

Referenced by clone().

    : deleteObjFunc( delete_OF )
{
    objFunc = Obj1;
    mAlpha  = alp;
}

Definition at line 57 of file CompositeOFScalarAdd.cpp.

References deleteObjFunc, and objFunc.

{
    if( deleteObjFunc ) delete objFunc;
}

Member Function Documentation

void CompositeOFScalarAdd::clear ( ) [virtual]

Clear any values accumulated for BCD-related eval calls

Implements MBMesquite::ObjectiveFunction.

Definition at line 67 of file CompositeOFScalarAdd.cpp.

References MBMesquite::ObjectiveFunction::clear(), and objFunc.

{
    objFunc->clear();
}

Create copy with same state.

Create a new instance of the objective function that is a copy of the callee with the same accumulated values, parameters, etc.

Implements MBMesquite::ObjectiveFunction.

Definition at line 62 of file CompositeOFScalarAdd.cpp.

References MBMesquite::ObjectiveFunction::clone(), CompositeOFScalarAdd(), mAlpha, and objFunc.

{
    return new CompositeOFScalarAdd( mAlpha, objFunc->clone(), true );
}
bool CompositeOFScalarAdd::evaluate ( EvalType  type,
PatchData pd,
double &  value_out,
bool  free,
MsqError err 
) [virtual]

Evaluate objective function for specified patch.

Either evaluate the objective function over the passed patch or update the accumulated, global objective function value for changes in the passed patch, depending on the value of the EvalType.

Parameters:
typeEvaluation type.
pdThe patch.
value_outThe passed-back value of the objective fuction.
freeIf true, incorporate the quality metric values only for those metric evaluations that depend on at least one free vertex
Returns:
false if any QualityMetric evaluation returned false, true otherwise.

Implements MBMesquite::ObjectiveFunction.

Definition at line 86 of file CompositeOFScalarAdd.cpp.

References MBMesquite::ObjectiveFunction::evaluate(), mAlpha, MSQ_CHKERR, and objFunc.

{
    bool ok = objFunc->evaluate( type, pd, value_out, free, err );
    value_out += mAlpha;
    return !MSQ_CHKERR( err ) && ok;
}
bool CompositeOFScalarAdd::evaluate_with_gradient ( EvalType  eval_type,
PatchData pd,
double &  OF_val,
std::vector< Vector3D > &  grad,
MsqError err 
) [virtual]

Evaluate objective function and gradient for specified patch.

Either evaluate the objective function over the passed patch or update the accumulated, global objective function value for changes in the passed patch, depending on the value of the EvalType.

The default implementation of this function will use the value-only variation of the evaluate method and numerical approximation to calculate gradients. Whenever possible, objective function implementations should provide more efficient analyical gradient calculations.

Parameters:
typeEvaluation type.
pdThe patch.
value_outThe passed-back value of the objective fuction.
grad_outThe gradient of the OF wrt the coordinates of each *free* vertex in the patch.
Returns:
false if any QualityMetric evaluation returned false, true otherwise.

Numerically Calculates the gradient of the ObjectiveFunction for the free vertices in the patch. Returns 'false' if the patch is outside of a required feasible region, returns 'ture' otherwise. The behavior of the function depends on the value of the boolean useLocalGradient. If useLocalGradient is set to 'true', compute_numerical_gradient creates a sub-patch around a free vertex, and then perturbs that vertex in one of the coordinate directions. Only the ObjectiveFunction value on the local sub-patch is used in the computation of the gradient. Therefore, useLocalGradient should only be set to 'true' for ObjectiveFunctions which can use this method. Unless the concrete ObjectiveFunction sets useLocalGradient to 'true' in its constructor, the value will be 'false'. In this case, the objective function value for the entire patch is used in the calculation of the gradient. This is computationally expensive, but it is numerically correct for all (C_1) functions.

Parameters:
pdPatchData on which the gradient is taken.
gradArray of Vector3D of length the number of vertices used to store gradient.
OF_valwill be set to the objective function value.

Reimplemented from MBMesquite::ObjectiveFunction.

Definition at line 93 of file CompositeOFScalarAdd.cpp.

References MBMesquite::ObjectiveFunction::evaluate_with_gradient(), mAlpha, MSQ_CHKERR, and objFunc.

{
    bool ok = objFunc->evaluate_with_gradient( type, pd, value_out, grad_out, err );
    value_out += mAlpha;
    return !MSQ_CHKERR( err ) && ok;
}
bool CompositeOFScalarAdd::evaluate_with_Hessian ( EvalType  type,
PatchData pd,
double &  value_out,
std::vector< Vector3D > &  grad_out,
MsqHessian Hessian_out,
MsqError err 
) [virtual]

Evaluate objective function and Hessian for specified patch.

Either evaluate the objective function over the passed patch or update the accumulated, global objective function value for changes in the passed patch, depending on the value of the EvalType.

The default implementation of this function will fail.

Parameters:
typeEvaluation type.
pdThe patch.
value_outThe passed-back value of the objective fuction.
grad_outThe gradient of the OF wrt the coordinates of each *free* vertex in the patch.
Hessian_outThe Hessian of the OF wrt the coordinates of each *free* vertex in the patch.
Returns:
false if any QualityMetric evaluation returned false, true otherwise.

Reimplemented from MBMesquite::ObjectiveFunction.

Definition at line 116 of file CompositeOFScalarAdd.cpp.

References MBMesquite::ObjectiveFunction::evaluate_with_Hessian(), mAlpha, MSQ_CHKERR, and objFunc.

{
    bool ok = objFunc->evaluate_with_Hessian( type, pd, value_out, grad_out, Hessian_out, err );
    value_out += mAlpha;
    return !MSQ_CHKERR( err ) && ok;
}
bool CompositeOFScalarAdd::evaluate_with_Hessian_diagonal ( EvalType  type,
PatchData pd,
double &  value_out,
std::vector< Vector3D > &  grad_out,
std::vector< SymMatrix3D > &  hess_diag_out,
MsqError err 
) [virtual]

Evaluate objective function and diagonal blocks of Hessian for specified patch.

Either evaluate the objective function over the passed patch or update the accumulated, global objective function value for changes in the passed patch, depending on the value of the EvalType.

The default implementation of this function evaluate the entire Hessian and discard non-diagonal portions. Concrete objective functions should provide a more efficient implementation that evaluates and accumulates only the required terms.

Parameters:
typeEvaluation type.
pdThe patch.
value_outThe passed-back value of the objective fuction.
grad_outThe gradient of the OF wrt the coordinates of each *free* vertex in the patch.
hess_diag_outThe diagonal blocks of a Hessian. I.e. Decompose the Hessian into 3x3 submatrices and return only the submatrices (blocks) along the diagonal.
Returns:
false if any QualityMetric evaluation returned false, true otherwise.

Reimplemented from MBMesquite::ObjectiveFunction.

Definition at line 104 of file CompositeOFScalarAdd.cpp.

References MBMesquite::ObjectiveFunction::evaluate_with_Hessian_diagonal(), mAlpha, MSQ_CHKERR, and objFunc.

{
    bool ok = objFunc->evaluate_with_Hessian_diagonal( type, pd, value_out, grad_out, diag_out, err );
    value_out += mAlpha;
    return !MSQ_CHKERR( err ) && ok;
}
bool CompositeOFScalarAdd::initialize_block_coordinate_descent ( MeshDomainAssoc mesh_and_domain,
const Settings settings,
PatchSet user_set,
MsqError err 
) [virtual]

Initial accumulated value for block coordinate descent algorithms.

Set accumulated value of objective function to the value for the entire, unmodified mesh. This is the initial state for a block coordinate descent algorithm. The ObjectiveFunction will asked to add or remove values for a specific patch of the mesh during the optimization.

Parameters:
meshThe Mesh
domainThe MeshDomain
user_setUser-defined patch set - not relevant for most OF templates.

Implements MBMesquite::ObjectiveFunction.

Definition at line 77 of file CompositeOFScalarAdd.cpp.

References MBMesquite::ObjectiveFunction::initialize_block_coordinate_descent(), MSQ_CHKERR, and objFunc.

{
    bool rval = objFunc->initialize_block_coordinate_descent( mesh_and_domain, settings, user_set, err );
    return !MSQ_CHKERR( err ) && rval;
}
void CompositeOFScalarAdd::initialize_queue ( MeshDomainAssoc mesh_and_domain,
const Settings settings,
MsqError err 
) [virtual]

Called at start of instruction queue processing.

Do any preliminary global initialization, consistency checking, etc.

Implements MBMesquite::ObjectiveFunction.

Definition at line 72 of file CompositeOFScalarAdd.cpp.

References MBMesquite::ObjectiveFunction::initialize_queue(), MSQ_ERRRTN, and objFunc.

{
    objFunc->initialize_queue( mesh_and_domain, settings, err );MSQ_ERRRTN( err );
}
int CompositeOFScalarAdd::min_patch_layers ( ) const [virtual]

Get the minimum number of layers of adjacent elements required in a patch to evaluate the objective function for a single free vertex.

Implements MBMesquite::ObjectiveFunction.

Definition at line 128 of file CompositeOFScalarAdd.cpp.

References MBMesquite::ObjectiveFunction::min_patch_layers(), and objFunc.

{
    return objFunc->min_patch_layers();
}

Member Data Documentation

List of all members.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines