本文整理汇总了C++中QualityMetric::compute_element_hessian方法的典型用法代码示例。如果您正苦于以下问题:C++ QualityMetric::compute_element_hessian方法的具体用法?C++ QualityMetric::compute_element_hessian怎么用?C++ QualityMetric::compute_element_hessian使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QualityMetric
的用法示例。
在下文中一共展示了QualityMetric::compute_element_hessian方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: function
/*! \fn LPtoPTemplate::compute_analytical_hessian(PatchData &pd, MsqHessian &hessian, MsqError &err)
For each element, each entry to be accumulated in the Hessian for
this objective function (\f$ \sum_{e \in E} Q(e)^p \f$ where \f$ E \f$
is the set of all elements in the patch) has the form:
\f$ pQ(e)^{p-1} \nabla^2 Q(e) + p(p-1)Q(e)^{p-2} \nabla Q(e) [\nabla Q(e)]^T \f$.
For \f$ p=2 \f$, this simplifies to
\f$ 2Q(e) \nabla^2 Q(e) + 2 \nabla Q(e) [\nabla Q(e)]^T \f$.
For \f$ p=1 \f$, this simplifies to \f$ \nabla^2 Q(e) \f$.
The \f$ p=1 \f$ simplified version is implemented directly
to speed up computation.
This function does not support vertex-based metrics.
\param pd The PatchData object for which the objective function
hessian is computed.
\param hessian: this object must have been previously initialized.
*/
bool LPtoPTemplate::compute_analytical_hessian(PatchData &pd,
MsqHessian &hessian,
Vector3D *const &grad,
double &OF_val,
MsqError &err)
{
double scaling_value=1.0;
MSQ_FUNCTION_TIMER( "LPtoPTemplate::compute_analytical_hessian" );
MsqMeshEntity* elements = pd.get_element_array(err); MSQ_ERRZERO(err);
MsqVertex* vertices = pd.get_vertex_array(err); MSQ_ERRZERO(err);
size_t num_elems = pd.num_elements();
//if scaling divide by the number of elements.
if(dividingByN){
if(num_elems<=0) {
MSQ_SETERR(err)("LPtoP is attempting to divide by zero in analytical Hessian.",
MsqError::INVALID_MESH);
return false;
}
scaling_value/=num_elems;
}
size_t num_vertices = pd.num_vertices();
Matrix3D elem_hessian[MSQ_MAX_NUM_VERT_PER_ENT*(MSQ_MAX_NUM_VERT_PER_ENT+1)/2];
Matrix3D elem_outer_product;
Vector3D grad_vec[MSQ_MAX_NUM_VERT_PER_ENT];
double QM_val;
double fac1, fac2;
Matrix3D grad_outprod;
bool qm_bool;
QualityMetric* currentQM = get_quality_metric();
MsqVertex* ele_free_vtces[MSQ_MAX_NUM_VERT_PER_ENT];
short i;
for (i=0; i<MSQ_MAX_NUM_VERT_PER_ENT; ++i) ele_free_vtces[i]=NULL;
const size_t* vtx_indices;
size_t e, v;
size_t nfve; // number of free vertices in element
short j,n;
hessian.zero_out();
for (v=0; v<num_vertices; ++v) grad[v] = 0.;
OF_val = 0.;
// Loops over all elements in the patch.
for (e=0; e<num_elems; ++e) {
short nve = elements[e].vertex_count();
// Gets a list of free vertices in the element.
vtx_indices = elements[e].get_vertex_index_array();
nfve=0;
for (i=0; i<nve; ++i) {
if ( vertices[vtx_indices[i]].is_free_vertex() ) {
ele_free_vtces[nfve] = vertices + vtx_indices[i];
++nfve;
}
}
// Computes \nabla^2 Q(e). Only the free vertices will have non-zero entries.
qm_bool = currentQM->compute_element_hessian(pd,
elements+e, ele_free_vtces,
grad_vec, elem_hessian,
nfve, QM_val, err);
if (MSQ_CHKERR(err) || !qm_bool) return false;
// **** Computes Hessian ****
double QM_pow=1.;
if (pVal == 1) {
n=0;
for (i=0; i<nve; ++i) {
for (j=i; j<nve; ++j) {
//negate if necessary
elem_hessian[n] *= (scaling_value * get_negate_flag());
++n;
}
//.........这里部分代码省略.........