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

Compare targets to mapping function Jacobian matrices. More...

#include <TMPQualityMetric.hpp>

+ Inheritance diagram for MBMesquite::TMPQualityMetric:
+ Collaboration diagram for MBMesquite::TMPQualityMetric:

Public Member Functions

 TMPQualityMetric (TargetCalculator *tc, WeightCalculator *wc)
virtual MESQUITE_EXPORT int get_negate_flag () const
 1 if metric should be minimized, -1 if metric should be maximized.
virtual MESQUITE_EXPORT void get_evaluations (PatchData &pd, std::vector< size_t > &handles, bool free_vertices_only, MsqError &err)
 Get locations at which metric can be evaluated.
virtual MESQUITE_EXPORT void get_element_evaluations (PatchData &pd, size_t elem_index, std::vector< size_t > &handles, MsqError &err)
 Get evaluation point handles for a given element.
virtual MESQUITE_EXPORT bool evaluate (PatchData &pd, size_t handle, double &value, MsqError &err)
 Get metric value at a logical location in the patch.
virtual MESQUITE_EXPORT 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.
MESQUITE_EXPORT void set_target_calculator (TargetCalculator *tc)
MESQUITE_EXPORT void set_weight_calculator (WeightCalculator *wc)
MESQUITE_EXPORT TargetCalculatorget_target_calculator () const
MESQUITE_EXPORT WeightCalculatorget_weight_calculator () const
virtual MESQUITE_EXPORT void initialize_queue (MeshDomainAssoc *mesh_and_domain, const Settings *settings, MsqError &err)
 Called at start of instruction queue processing.

Static Public Member Functions

static MESQUITE_EXPORT void get_patch_evaluations (PatchData &pd, std::vector< size_t > &handles, bool free_vertices_only, MsqError &err)

Protected Types

enum  { MAX_ELEM_NODES = 27 }

Protected Member Functions

virtual MESQUITE_EXPORT bool evaluate_internal (PatchData &pd, size_t handle, double &value, size_t *indices, size_t &num_indices, MsqError &err)=0
MESQUITE_EXPORT bool evaluate_surface_common (PatchData &pd, Sample sample, size_t element_index, const NodeSet &bits, size_t *indices, size_t &num_indices, MsqVector< 2 > *derivs, MsqMatrix< 2, 2 > &W, MsqMatrix< 2, 2 > &A, MsqMatrix< 3, 2 > &S_a_transpose_Theta, MsqError &err)
MESQUITE_EXPORT void weight (PatchData &pd, Sample sample, size_t elem, int num_points, double &value, Vector3D *grad, SymMatrix3D *diag, Matrix3D *hess, MsqError &err)

Protected Attributes

size_t mIndices [MAX_ELEM_NODES]
std::vector< MsqMatrix< 2, 2 > > hess2d
MsqVector< 3 > mDerivs3D [MAX_ELEM_NODES]
MsqVector< 2 > mDerivs2D [MAX_ELEM_NODES]
TargetCalculatortargetCalc

Private Attributes

WeightCalculatorweightCalc

Detailed Description

Compare targets to mapping function Jacobian matrices.

Base class for various TMP QualityMetric implementations

Definition at line 55 of file TMPQualityMetric.hpp.


Member Enumeration Documentation

anonymous enum [protected]
Enumerator:
MAX_ELEM_NODES 

Definition at line 147 of file TMPQualityMetric.hpp.

    {
        MAX_ELEM_NODES = 27
    };

Constructor & Destructor Documentation

Parameters:
tcThe target calculator
wcThe weight calculator

Definition at line 62 of file TMPQualityMetric.hpp.

: targetCalc( tc ), weightCalc( wc ) {}

Member Function Documentation

bool MBMesquite::TMPQualityMetric::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.

Parameters:
pdThe patch.
handleThe location in the patch (as passed back from get_evaluations).
valueThe output metric value.

Implements MBMesquite::QualityMetric.

Definition at line 79 of file TMPQualityMetric.cpp.

References MBMesquite::ElemSampleQM::elem(), evaluate_internal(), MBMesquite::WeightCalculator::get_weight(), mIndices, MSQ_CHKERR, MSQ_ERRZERO, MBMesquite::ElemSampleQM::sample(), and weightCalc.

Referenced by MBMesquite::VertexMover::loop_over_mesh().

{
    size_t num_idx;
    bool valid = evaluate_internal( pd, p_handle, value, mIndices, num_idx, err );
    if( MSQ_CHKERR( err ) || !valid ) return false;

    // apply target weight to value
    if( weightCalc )
    {
        const Sample s = ElemSampleQM::sample( p_handle );
        const size_t e = ElemSampleQM::elem( p_handle );
        double ck      = weightCalc->get_weight( pd, e, s, err );
        MSQ_ERRZERO( err );
        value *= ck;
    }
    return true;
}
virtual MESQUITE_EXPORT bool MBMesquite::TMPQualityMetric::evaluate_internal ( PatchData pd,
size_t  handle,
double &  value,
size_t *  indices,
size_t &  num_indices,
MsqError err 
) [protected, pure virtual]
bool MBMesquite::TMPQualityMetric::evaluate_surface_common ( PatchData pd,
Sample  sample,
size_t  element_index,
const NodeSet bits,
size_t *  indices,
size_t &  num_indices,
MsqVector< 2 > *  derivs,
MsqMatrix< 2, 2 > &  W,
MsqMatrix< 2, 2 > &  A,
MsqMatrix< 3, 2 > &  S_a_transpose_Theta,
MsqError err 
) [protected]

Definition at line 249 of file TMPQualityMetric.cpp.

References MBMesquite::MsqMatrix< R, C >::column(), MBMesquite::MsqMatrix< R, C >::data(), MBMesquite::PatchData::domain_set(), MBMesquite::PatchData::element_by_index(), MBMesquite::TargetCalculator::get_2D_target(), MBMesquite::PatchData::get_domain_normal_at_sample(), MBMesquite::MsqMeshEntity::get_element_type(), MBMesquite::PatchData::get_mapping_function_2D(), MBMesquite::TargetCalculator::get_surface_target(), MBMesquite::TargetCalculator::have_surface_orient(), MBMesquite::MappingFunction2D::jacobian(), MSQ_ERRZERO, MSQ_SETERR, n, MBMesquite::project_to_matrix_plane(), MBMesquite::project_to_perp_plane(), MBMesquite::MsqMatrix< R, C >::row(), MBMesquite::MsqMatrix< R, C >::set_column(), MBMesquite::MsqMatrix< R, C >::set_row(), targetCalc, u, and MBMesquite::MsqError::UNSUPPORTED_ELEMENT.

Referenced by MBMesquite::AWQualityMetric::evaluate_internal(), MBMesquite::TQualityMetric::evaluate_internal(), MBMesquite::AWQualityMetric::evaluate_with_gradient(), MBMesquite::TQualityMetric::evaluate_with_gradient(), MBMesquite::TQualityMetric::evaluate_with_Hessian(), MBMesquite::AWQualityMetric::evaluate_with_Hessian(), MBMesquite::AWQualityMetric::evaluate_with_Hessian_diagonal(), and MBMesquite::TQualityMetric::evaluate_with_Hessian_diagonal().

{
    EntityTopology type = pd.element_by_index( e ).get_element_type();

    const MappingFunction2D* mf = pd.get_mapping_function_2D( type );
    if( !mf )
    {
        MSQ_SETERR( err )( "No mapping function for element type", MsqError::UNSUPPORTED_ELEMENT );
        return false;
    }

    MsqMatrix< 3, 2 > J;
    mf->jacobian( pd, e, bits, s, indices, derivs, num_indices, J, err );

    // If we have a 3x2 target matrix
    if( targetCalc->have_surface_orient() )
    {
        MsqVector< 3 > u, u_perp;
        MsqMatrix< 3, 2 > W_hat;
        targetCalc->get_surface_target( pd, e, s, W_hat, err );
        MSQ_ERRZERO( err );
        // Use the cross product of the columns of W as the normal of the
        // plane to work in (i.e. u.).  W should have been constructed such
        // that said cross product is in the direction of (n_s)_init.  And if
        // for some reason it as not, then using something other than said
        // cross product is likely to produce very wrong results.
        project_to_matrix_plane( W_hat, W, u, u_perp );
        // Do the transforms on A to align it with W and project into the plane.
        if( !project_to_perp_plane( J, u, u_perp, A, S_a_transpose_Theta ) ) return false;
    }
    // Otherwise if we have a 2x2 target matrix (i.e. the target does
    // not contain orientation information), project into the plane
    // tangent to J.
    else
    {
        MsqVector< 3 > u, u_perp;
        targetCalc->get_2D_target( pd, e, s, W, err );
        MSQ_ERRZERO( err );
        project_to_matrix_plane( J, A, u, u_perp );
        S_a_transpose_Theta.set_column( 0, u_perp );
        S_a_transpose_Theta.set_column( 1, u * u_perp );
        // If the domain is set, adjust the sign of things correctly
        // for the case where the element is inverted with respect
        // to the domain.
        if( pd.domain_set() )
        {
            Vector3D n;
            pd.get_domain_normal_at_sample( e, s, n, err );
            MSQ_ERRZERO( err );
            // if sigma == -1
            if( Vector3D( u.data() ) % n < 0.0 )
            {
                // flip u
                u = -u;
                // S_a_transpose_Theta == Theta, because S_a == I here.
                // u_perp is unaffected by flipping u, so only the second
                // column of S_a_transpose_Theta and the second row of A
                // are flipped because u x u_perp will be flipped.
                S_a_transpose_Theta.set_column( 1, -S_a_transpose_Theta.column( 1 ) );
                A.set_row( 1, -A.row( 1 ) );
            }
        }
    }

    return true;
}
bool MBMesquite::TMPQualityMetric::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.

Parameters:
pdThe patch.
handleThe location in the patch (as passed back from get_evaluations).
valueThe output metric value.
indicesThe free vertices that the evaluation is a function of, specified as vertex indices in the PatchData.

Implements MBMesquite::QualityMetric.

Definition at line 97 of file TMPQualityMetric.cpp.

References MBMesquite::arrptr(), MBMesquite::ElemSampleQM::elem(), evaluate_internal(), MBMesquite::WeightCalculator::get_weight(), MAX_ELEM_NODES, MSQ_CHKERR, MSQ_ERRZERO, MBMesquite::ElemSampleQM::sample(), and weightCalc.

{
    indices.resize( MAX_ELEM_NODES );
    size_t num_idx = 0;
    bool result    = evaluate_internal( pd, p_handle, value, arrptr( indices ), num_idx, err );
    if( MSQ_CHKERR( err ) || !result ) return false;

    indices.resize( num_idx );

    // apply target weight to value
    if( weightCalc )
    {
        const Sample s = ElemSampleQM::sample( p_handle );
        const size_t e = ElemSampleQM::elem( p_handle );
        double ck      = weightCalc->get_weight( pd, e, s, err );
        MSQ_ERRZERO( err );
        value *= ck;
    }

    return true;
}
void MBMesquite::TMPQualityMetric::get_element_evaluations ( PatchData pd,
size_t  elem_index,
std::vector< size_t > &  handles,
MsqError err 
) [virtual]

Get evaluation point handles for a given element.

Similar to QualityMetric::get_evaluations, this method returns a list of handles corresponding to sample points at which the metric may be evaluated. While QualityMetric::get_evaluations returns sample points for all elements in a PatchData, this method returns only the subset corresponding to a single element.

Implements MBMesquite::ElemSampleQM.

Definition at line 71 of file TMPQualityMetric.cpp.

References MBMesquite::get_elem_sample_points().

{
    get_elem_sample_points( pd, p_elem, handles, err );
}
void MBMesquite::TMPQualityMetric::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.

Parameters:
pdThe patch
handlesOutput list of handles
free_vertices_onlyIf true, only pass back evaluation points that depend on at least one free vertex.

Implements MBMesquite::QualityMetric.

Definition at line 61 of file TMPQualityMetric.cpp.

References MBMesquite::get_sample_pt_evaluations().

Referenced by TQualityMetricTest::regression_inverse_mean_ratio_grad(), and TQualityMetricTest::regression_inverse_mean_ratio_hess().

{
    get_sample_pt_evaluations( pd, handles, free, err );
}

1 if metric should be minimized, -1 if metric should be maximized.

Implements MBMesquite::QualityMetric.

Definition at line 56 of file TMPQualityMetric.cpp.

{
    return 1;
}
void MBMesquite::TMPQualityMetric::get_patch_evaluations ( PatchData pd,
std::vector< size_t > &  handles,
bool  free_vertices_only,
MsqError err 
) [static]

Definition at line 66 of file TMPQualityMetric.cpp.

References MBMesquite::get_sample_pt_evaluations().

Referenced by MBMesquite::MeshUtil::lambda_distribution().

{
    get_sample_pt_evaluations( pd, handles, free, err );
}
void MBMesquite::TMPQualityMetric::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. Default implementation does nothing.

Reimplemented from MBMesquite::QualityMetric.

Definition at line 358 of file TMPQualityMetric.cpp.

References MBMesquite::WeightCalculator::initialize_queue(), MBMesquite::TargetCalculator::initialize_queue(), MSQ_ERRRTN, targetCalc, and weightCalc.

{
    targetCalc->initialize_queue( mesh_and_domain, settings, err );MSQ_ERRRTN( err );
    if( weightCalc )
    {
        weightCalc->initialize_queue( mesh_and_domain, settings, err );MSQ_ERRRTN( err );
    }
}
void MBMesquite::TMPQualityMetric::weight ( PatchData pd,
Sample  sample,
size_t  elem,
int  num_points,
double &  value,
Vector3D grad,
SymMatrix3D diag,
Matrix3D hess,
MsqError err 
) [protected]

Definition at line 326 of file TMPQualityMetric.cpp.

References MBMesquite::WeightCalculator::get_weight(), MSQ_ERRRTN, n, and weightCalc.

Referenced by MBMesquite::AWQualityMetric::evaluate_with_gradient(), MBMesquite::TQualityMetric::evaluate_with_gradient(), MBMesquite::TQualityMetric::evaluate_with_Hessian(), MBMesquite::AWQualityMetric::evaluate_with_Hessian(), MBMesquite::AWQualityMetric::evaluate_with_Hessian_diagonal(), and MBMesquite::TQualityMetric::evaluate_with_Hessian_diagonal().

{
    if( !weightCalc ) return;

    double ck = weightCalc->get_weight( pd, p_elem, p_sample, err );MSQ_ERRRTN( err );
    value *= ck;
    if( grad )
    {
        for( int i = 0; i < num_idx; ++i )
            grad[i] *= ck;
    }
    if( diag )
    {
        for( int i = 0; i < num_idx; ++i )
            diag[i] *= ck;
    }
    if( hess )
    {
        const int n = num_idx * ( num_idx + 1 ) / 2;
        for( int i = 0; i < n; ++i )
            hess[i] *= ck;
    }
}

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