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

#include <AddQualityMetric.hpp>

+ Inheritance diagram for MBMesquite::AddQualityMetric:
+ Collaboration diagram for MBMesquite::AddQualityMetric:

Public Member Functions

 AddQualityMetric (QualityMetric *qm1, QualityMetric *qm2, MsqError &err)
 ~AddQualityMetric ()
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.
QualityMetricget_first_metric () const
QualityMetricget_second_metric () const
virtual 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 bool evaluate (PatchData &pd, size_t handle, double &value, MsqError &err)
 Get metric value at a logical location in the patch.
virtual 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.
virtual 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.
virtual 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

QualityMetricmetric1
QualityMetricmetric2
std::vector< size_t > mHandles
std::vector< size_t > indices1
std::vector< size_t > indices2
std::vector< Vector3Dgrad1
std::vector< Vector3Dgrad2
std::vector< Matrix3DHess1
std::vector< Matrix3DHess2

Detailed Description

Definition at line 41 of file AddQualityMetric.hpp.


Constructor & Destructor Documentation

Definition at line 41 of file AddQualityMetric.cpp.

References MBMesquite::QualityMetric::get_metric_type(), MBMesquite::QualityMetric::get_negate_flag(), MBMesquite::MsqError::INVALID_ARG, and MSQ_SETERR.

    : metric1( *qm1 ), metric2( *qm2 )
{
    if( qm1->get_metric_type() != qm2->get_metric_type() || qm1->get_negate_flag() != qm2->get_negate_flag() )
    {
        MSQ_SETERR( err )( "Incompatible metrics", MsqError::INVALID_ARG );
    }
}

Member Function Documentation

bool MBMesquite::AddQualityMetric::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 77 of file AddQualityMetric.cpp.

References MBMesquite::QualityMetric::evaluate(), metric1, metric2, and MSQ_ERRZERO.

{
    double val1, val2;
    bool rval1, rval2;
    rval1 = metric1.evaluate( pd, handle, val1, err );
    MSQ_ERRZERO( err );
    rval2 = metric2.evaluate( pd, handle, val2, err );
    MSQ_ERRZERO( err );
    value = val1 + val2;
    return rval1 && rval2;
}
bool MBMesquite::AddQualityMetric::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.

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.
gradientThe 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 111 of file AddQualityMetric.cpp.

References MBMesquite::QualityMetric::evaluate_with_gradient(), grad1, grad2, indices1, indices2, metric1, metric2, and MSQ_ERRZERO.

{
    std::vector< size_t >::iterator i;
    size_t j;
    double val1, val2;
    bool rval1, rval2;
    rval1 = metric1.evaluate_with_gradient( pd, handle, val1, indices1, grad1, err );
    MSQ_ERRZERO( err );
    rval2 = metric2.evaluate_with_gradient( pd, handle, val2, indices2, grad2, err );
    MSQ_ERRZERO( err );

    indices.resize( indices1.size() + indices2.size() );
    i = std::copy( indices1.begin(), indices1.end(), indices.begin() );
    std::copy( indices2.begin(), indices2.end(), i );
    std::sort( indices.begin(), indices.end() );
    indices.erase( std::unique( indices.begin(), indices.end() ), indices.end() );

    gradient.clear();
    gradient.resize( indices.size(), Vector3D( 0.0 ) );
    for( j = 0; j < indices1.size(); ++j )
    {
        i        = std::lower_bound( indices.begin(), indices.end(), indices1[j] );
        size_t k = i - indices.begin();
        gradient[k] += grad1[j];
    }
    for( j = 0; j < indices2.size(); ++j )
    {
        i        = std::lower_bound( indices.begin(), indices.end(), indices2[j] );
        size_t k = i - indices.begin();
        gradient[k] += grad2[j];
    }

    value = val1 + val2;
    return rval1 && rval2;
}
bool MBMesquite::AddQualityMetric::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.

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.
gradientThe gradient of the metric as a function of the coordinates of the free vertices passed back in the indices list.
HessianThe 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 152 of file AddQualityMetric.cpp.

References MBMesquite::QualityMetric::evaluate_with_Hessian(), grad1, grad2, Hess1, Hess2, indices1, indices2, metric1, metric2, MSQ_ERRZERO, n, N, and nr.

{
    std::vector< size_t >::iterator i;
    size_t j, r, c, n, h;
    double val1, val2;
    bool rval1, rval2;
    rval1 = metric1.evaluate_with_Hessian( pd, handle, val1, indices1, grad1, Hess1, err );
    MSQ_ERRZERO( err );
    rval2 = metric2.evaluate_with_Hessian( pd, handle, val2, indices2, grad2, Hess2, err );
    MSQ_ERRZERO( err );

    indices.resize( indices1.size() + indices2.size() );
    i = std::copy( indices1.begin(), indices1.end(), indices.begin() );
    std::copy( indices2.begin(), indices2.end(), i );
    std::sort( indices.begin(), indices.end() );
    indices.erase( std::unique( indices.begin(), indices.end() ), indices.end() );

    gradient.clear();
    gradient.resize( indices.size(), Vector3D( 0.0 ) );
    for( j = 0; j < indices1.size(); ++j )
    {
        i           = std::lower_bound( indices.begin(), indices.end(), indices1[j] );
        indices1[j] = i - indices.begin();
        gradient[indices1[j]] += grad1[j];
    }
    for( j = 0; j < indices2.size(); ++j )
    {
        i           = std::lower_bound( indices.begin(), indices.end(), indices2[j] );
        indices2[j] = i - indices.begin();
        gradient[indices2[j]] += grad2[j];
    }

    const size_t N = indices.size();
    Hessian.clear();
    Hessian.resize( N * ( N + 1 ) / 2, Matrix3D( 0.0 ) );

    n = indices1.size();
    h = 0;
    for( r = 0; r < n; ++r )
    {
        const size_t nr = indices1[r];
        for( c = r; c < n; ++c )
        {
            const size_t nc = indices1[c];
            if( nr <= nc )
                Hessian[N * nr - nr * ( nr + 1 ) / 2 + nc] += Hess1[h++];
            else
                Hessian[N * nc - nc * ( nc + 1 ) / 2 + nr].plus_transpose_equal( Hess1[h++] );
        }
    }

    n = indices2.size();
    h = 0;
    for( r = 0; r < n; ++r )
    {
        const size_t nr = indices2[r];
        for( c = r; c < n; ++c )
        {
            const size_t nc = indices2[c];
            if( nr <= nc )
                Hessian[N * nr - nr * ( nr + 1 ) / 2 + nc] += Hess2[h++];
            else
                Hessian[N * nc - nc * ( nc + 1 ) / 2 + nr].plus_transpose_equal( Hess2[h++] );
        }
    }

    value = val1 + val2;
    return rval1 && rval2;
}
bool MBMesquite::AddQualityMetric::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 89 of file AddQualityMetric.cpp.

References MBMesquite::QualityMetric::evaluate_with_indices(), indices1, indices2, metric1, metric2, and MSQ_ERRZERO.

{
    double val1, val2;
    bool rval1, rval2;
    rval1 = metric1.evaluate_with_indices( pd, handle, val1, indices1, err );
    MSQ_ERRZERO( err );
    rval2 = metric2.evaluate_with_indices( pd, handle, val2, indices2, err );
    MSQ_ERRZERO( err );

    indices.clear();
    std::sort( indices1.begin(), indices1.end() );
    std::sort( indices2.begin(), indices2.end() );
    std::set_union( indices1.begin(), indices1.end(), indices2.begin(), indices2.end(), std::back_inserter( indices ) );

    value = val1 + val2;
    return rval1 && rval2;
}
void MBMesquite::AddQualityMetric::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 67 of file AddQualityMetric.cpp.

References MBMesquite::QualityMetric::get_evaluations(), MBMesquite::MsqError::INVALID_STATE, metric1, metric2, mHandles, MSQ_ERRRTN, and MSQ_SETERR.

{
    metric1.get_evaluations( pd, handles, free_only, err );MSQ_ERRRTN( err );
    metric2.get_evaluations( pd, mHandles, free_only, err );MSQ_ERRRTN( err );
    if( handles != mHandles )
    {
        MSQ_SETERR( err )( "Incompatible metrics", MsqError::INVALID_STATE );
    }
}

Definition at line 54 of file AddQualityMetric.hpp.

References metric1.

    {
        return &metric1;
    }
std::string MBMesquite::AddQualityMetric::get_name ( ) const [virtual]

Implements MBMesquite::QualityMetric.

Definition at line 57 of file AddQualityMetric.cpp.

References MBMesquite::QualityMetric::get_name(), metric1, and metric2.

{
    return std::string( "Sum(" ) + metric1.get_name() + ", " + metric2.get_name() + ")";
}

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

Implements MBMesquite::QualityMetric.

Definition at line 62 of file AddQualityMetric.cpp.

References MBMesquite::QualityMetric::get_negate_flag(), and metric1.

{
    return metric1.get_negate_flag();
}

Definition at line 58 of file AddQualityMetric.hpp.

References metric2.

    {
        return &metric2;
    }

Member Data Documentation

std::vector< Vector3D > MBMesquite::AddQualityMetric::grad1 [mutable, private]

Definition at line 95 of file AddQualityMetric.hpp.

Referenced by evaluate_with_gradient(), and evaluate_with_Hessian().

std::vector< Vector3D > MBMesquite::AddQualityMetric::grad2 [mutable, private]

Definition at line 95 of file AddQualityMetric.hpp.

Referenced by evaluate_with_gradient(), and evaluate_with_Hessian().

std::vector< Matrix3D > MBMesquite::AddQualityMetric::Hess1 [mutable, private]

Definition at line 96 of file AddQualityMetric.hpp.

Referenced by evaluate_with_Hessian().

std::vector< Matrix3D > MBMesquite::AddQualityMetric::Hess2 [mutable, private]

Definition at line 96 of file AddQualityMetric.hpp.

Referenced by evaluate_with_Hessian().

std::vector< size_t > MBMesquite::AddQualityMetric::indices1 [mutable, private]
std::vector< size_t > MBMesquite::AddQualityMetric::indices2 [mutable, private]
std::vector< size_t > MBMesquite::AddQualityMetric::mHandles [mutable, private]

Definition at line 93 of file AddQualityMetric.hpp.

Referenced by get_evaluations().

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