MOAB: Mesh Oriented datABase
(version 5.4.1)
|
Use finite difference rather than analytical derivative calculations. More...
#include <NumericalQM.hpp>
Public Member Functions | |
NumericalQM (QualityMetric *real_metric, bool numerical_gradient=true, bool numerical_hessian=true) | |
MetricType | get_metric_type () const |
std::string | get_name () const |
int | get_negate_flag () const |
1 if metric should be minimized, -1 if metric should be maximized. | |
void | get_evaluations (PatchData &pd, std::vector< size_t > &handles, bool free_vertices_only, MsqError &err) |
Get locations at which metric can be evaluated. | |
bool | evaluate (PatchData &pd, size_t handle, double &value, MsqError &err) |
Get metric value at a logical location in the patch. | |
bool | evaluate_with_indices (PatchData &pd, size_t handle, double &value, std::vector< size_t > &indices, MsqError &err) |
Get metric value at a logical location in the patch. | |
bool | evaluate_with_gradient (PatchData &pd, size_t handle, double &value, std::vector< size_t > &indices, std::vector< Vector3D > &gradient, MsqError &err) |
Get metric value and gradient at a logical location in the patch. | |
bool | evaluate_with_Hessian_diagonal (PatchData &pd, size_t handle, double &value, std::vector< size_t > &indices, std::vector< Vector3D > &gradient, std::vector< SymMatrix3D > &Hessian_diagonal, MsqError &err) |
Get metric value and gradient at a logical location in the patch. | |
bool | evaluate_with_Hessian (PatchData &pd, size_t handle, double &value, std::vector< size_t > &indices, std::vector< Vector3D > &gradient, std::vector< Matrix3D > &Hessian, MsqError &err) |
Get metric value and deravitives at a logical location in the patch. | |
Private Attributes | |
QualityMetric * | realMetric |
bool | numericGrad |
bool | numericHess |
Use finite difference rather than analytical derivative calculations.
This class acts as a decorator for (wrapper around) an existing QualityMetric. It bypasses any code provided by the underlying metric for calculation of derivatives, forcing the use of finite difference approximation of the derivatives.
Definition at line 48 of file NumericalQM.hpp.
MBMesquite::NumericalQM::NumericalQM | ( | QualityMetric * | real_metric, |
bool | numerical_gradient = true , |
||
bool | numerical_hessian = true |
||
) |
real_metric | The actual quality metric. |
numerical_gradient | Use finite difference to calculate first derivatives |
numerical_hessian | Use finite difference to calculate second derivatives |
Definition at line 38 of file NumericalQM.cpp.
: realMetric( real_metric ), numericGrad( numerical_gradient ), numericHess( numerical_hessian ) { }
bool MBMesquite::NumericalQM::evaluate | ( | PatchData & | pd, |
size_t | handle, | ||
double & | value, | ||
MsqError & | err | ||
) | [virtual] |
Get metric value at a logical location in the patch.
Evaluate the metric at one location in the PatchData.
pd | The patch. |
handle | The location in the patch (as passed back from get_evaluations). |
value | The output metric value. |
Implements MBMesquite::QualityMetric.
Definition at line 63 of file NumericalQM.cpp.
References MBMesquite::QualityMetric::evaluate(), and realMetric.
{ return realMetric->evaluate( pd, handle, value, err ); }
bool MBMesquite::NumericalQM::evaluate_with_gradient | ( | PatchData & | pd, |
size_t | handle, | ||
double & | value, | ||
std::vector< size_t > & | indices, | ||
std::vector< Vector3D > & | gradient, | ||
MsqError & | err | ||
) | [virtual] |
Get metric value and gradient at a logical location in the patch.
Evaluate the metric at one location in the PatchData.
pd | The patch. |
handle | The location in the patch (as passed back from get_evaluations). |
value | The output metric value. |
indices | The free vertices that the evaluation is a function of, specified as vertex indices in the PatchData. |
gradient | The gradient of the metric as a function of the coordinates of the free vertices passed back in the indices list. |
Reimplemented from MBMesquite::QualityMetric.
Definition at line 77 of file NumericalQM.cpp.
References MBMesquite::QualityMetric::evaluate_with_gradient(), numericGrad, and realMetric.
{ if( numericGrad ) return realMetric->QualityMetric::evaluate_with_gradient( pd, handle, value, indices, gradient, err ); else return realMetric->evaluate_with_gradient( pd, handle, value, indices, gradient, err ); }
bool MBMesquite::NumericalQM::evaluate_with_Hessian | ( | PatchData & | pd, |
size_t | handle, | ||
double & | value, | ||
std::vector< size_t > & | indices, | ||
std::vector< Vector3D > & | gradient, | ||
std::vector< Matrix3D > & | Hessian, | ||
MsqError & | err | ||
) | [virtual] |
Get metric value and deravitives at a logical location in the patch.
Evaluate the metric at one location in the PatchData.
pd | The patch. |
handle | The location in the patch (as passed back from get_evaluations). |
value | The output metric value. |
indices | The free vertices that the evaluation is a function of, specified as vertex indices in the PatchData. |
gradient | The gradient of the metric as a function of the coordinates of the free vertices passed back in the indices list. |
Hessian | The Hessian of the metric as a function of the coordinates. The Hessian is passed back as the upper-triangular portion of the matrix in row-major order, where each Matrix3D is the portion of the Hessian with respect to the vertices at the corresponding positions in the indices list. |
Reimplemented from MBMesquite::QualityMetric.
Definition at line 105 of file NumericalQM.cpp.
References MBMesquite::QualityMetric::evaluate_with_Hessian(), numericHess, and realMetric.
{ if( numericHess ) return realMetric->QualityMetric::evaluate_with_Hessian( pd, handle, value, indices, gradient, Hessian, err ); else return realMetric->evaluate_with_Hessian( pd, handle, value, indices, gradient, Hessian, err ); }
bool MBMesquite::NumericalQM::evaluate_with_Hessian_diagonal | ( | PatchData & | pd, |
size_t | handle, | ||
double & | value, | ||
std::vector< size_t > & | indices, | ||
std::vector< Vector3D > & | gradient, | ||
std::vector< SymMatrix3D > & | Hessian_diagonal, | ||
MsqError & | err | ||
) | [virtual] |
Get metric value and gradient at a logical location in the patch.
Evaluate the metric at one location in the PatchData.
pd | The patch. |
handle | The location in the patch (as passed back from get_evaluations). |
value | The output metric value. |
indices | The free vertices that the evaluation is a function of, specified as vertex indices in the PatchData. |
gradient | The gradient of the metric as a function of the coordinates of the free vertices passed back in the indices list. |
Hessian_diagonal | The 3x3 blocks along the diagonal of the Hessian matrix. |
Reimplemented from MBMesquite::QualityMetric.
Definition at line 90 of file NumericalQM.cpp.
References MBMesquite::QualityMetric::evaluate_with_Hessian_diagonal(), numericHess, and realMetric.
{ if( numericHess ) return realMetric->QualityMetric::evaluate_with_Hessian_diagonal( pd, handle, value, indices, gradient, hess, err ); else return realMetric->evaluate_with_Hessian_diagonal( pd, handle, value, indices, gradient, hess, err ); }
bool MBMesquite::NumericalQM::evaluate_with_indices | ( | PatchData & | pd, |
size_t | handle, | ||
double & | value, | ||
std::vector< size_t > & | indices, | ||
MsqError & | err | ||
) | [virtual] |
Get metric value at a logical location in the patch.
Evaluate the metric at one location in the PatchData.
pd | The patch. |
handle | The location in the patch (as passed back from get_evaluations). |
value | The output metric value. |
indices | The free vertices that the evaluation is a function of, specified as vertex indices in the PatchData. |
Implements MBMesquite::QualityMetric.
Definition at line 68 of file NumericalQM.cpp.
References MBMesquite::QualityMetric::evaluate_with_indices(), and realMetric.
{ return realMetric->evaluate_with_indices( pd, handle, value, indices, err ); }
void MBMesquite::NumericalQM::get_evaluations | ( | PatchData & | pd, |
std::vector< size_t > & | handles, | ||
bool | free_vertices_only, | ||
MsqError & | err | ||
) | [virtual] |
Get locations at which metric can be evaluated.
Different metrics are evaluated for different things within a patch. For example, an element-based metric will be evaluated once for each element in patch, a vertex-based metric once for each veretx, and a target/sample-point based metric will be evaluated once for each samle point in each element. This method returns a list of handles, one for each location in the patch at which the metric can be evaluated. The handle values are used as input to the evaluate methods.
pd | The patch |
handles | Output list of handles |
free_vertices_only | If true, only pass back evaluation points that depend on at least one free vertex. |
Implements MBMesquite::QualityMetric.
Definition at line 58 of file NumericalQM.cpp.
References MBMesquite::QualityMetric::get_evaluations(), and realMetric.
{ return realMetric->get_evaluations( pd, handles, free, err ); }
QualityMetric::MetricType MBMesquite::NumericalQM::get_metric_type | ( | ) | const [virtual] |
Implements MBMesquite::QualityMetric.
Definition at line 43 of file NumericalQM.cpp.
References MBMesquite::QualityMetric::get_metric_type(), and realMetric.
{ return realMetric->get_metric_type(); }
std::string MBMesquite::NumericalQM::get_name | ( | ) | const [virtual] |
Implements MBMesquite::QualityMetric.
Definition at line 48 of file NumericalQM.cpp.
References MBMesquite::QualityMetric::get_name(), and realMetric.
{ return realMetric->get_name(); }
int MBMesquite::NumericalQM::get_negate_flag | ( | ) | const [virtual] |
1 if metric should be minimized, -1 if metric should be maximized.
Implements MBMesquite::QualityMetric.
Definition at line 53 of file NumericalQM.cpp.
References MBMesquite::QualityMetric::get_negate_flag(), and realMetric.
{ return realMetric->get_negate_flag(); }
bool MBMesquite::NumericalQM::numericGrad [private] |
Definition at line 99 of file NumericalQM.hpp.
Referenced by evaluate_with_gradient().
bool MBMesquite::NumericalQM::numericHess [private] |
Definition at line 99 of file NumericalQM.hpp.
Referenced by evaluate_with_Hessian(), and evaluate_with_Hessian_diagonal().
QualityMetric* MBMesquite::NumericalQM::realMetric [private] |
Definition at line 98 of file NumericalQM.hpp.
Referenced by evaluate(), evaluate_with_gradient(), evaluate_with_Hessian(), evaluate_with_Hessian_diagonal(), evaluate_with_indices(), get_evaluations(), get_metric_type(), get_name(), and get_negate_flag().