MOAB: Mesh Oriented datABase  (version 5.3.0)
MBMesquite::CachingTargetCalculator Class Reference

Cache target matrices on PatchData. More...

#include <CachingTargetCalculator.hpp>

+ Inheritance diagram for MBMesquite::CachingTargetCalculator:
+ Collaboration diagram for MBMesquite::CachingTargetCalculator:

Public Member Functions

 CachingTargetCalculator (TargetCalculator *cached)
virtual ~CachingTargetCalculator ()
TargetCalculatorget_cached_calculator () const
virtual bool get_3D_target (PatchData &pd, size_t element, Sample sample, MsqMatrix< 3, 3 > &W_out, MsqError &err)
 Get a target matrix.
virtual bool get_surface_target (PatchData &pd, size_t element, Sample sample, MsqMatrix< 3, 2 > &W_out, MsqError &err)
 Get a target matrix.
virtual bool get_2D_target (PatchData &pd, size_t element, Sample sample, MsqMatrix< 2, 2 > &W_out, MsqError &err)
 Get a target matrix.
virtual bool have_surface_orient () const
 Use 3x2 W for surface elements if true, 2x2 W if false.

Protected Member Functions

void notify_patch_destroyed (CachedTargetData &d)
void notify_sub_patch (PatchData &orig_patch, CachedTargetData &data, PatchData &sub_patch, const size_t *vertex_index_map, const size_t *element_index_map, MsqError &err)
void notify_new_patch (PatchData &patch, CachedTargetData &data)

Private Attributes

TargetCalculator *const cachedCalculator

Detailed Description

Cache target matrices on PatchData.

This class is a decorator for concrete TargetCalculator that caches the previously calculated targets. This class should not be used if the target matrices produced by the concrete target calculator are a function of the vertex positions in the active mesh.

Definition at line 72 of file CachingTargetCalculator.hpp.


Constructor & Destructor Documentation


Member Function Documentation

bool MBMesquite::CachingTargetCalculator::get_2D_target ( PatchData pd,
size_t  element,
Sample  sample,
MsqMatrix< 2, 2 > &  W_out,
MsqError err 
) [virtual]

Get a target matrix.

Parameters:
pdThe current PatchData
elementThe index an element within the patch data.
sampleThe sample point in the element.
W_outThe resulting target matrix.

Implements MBMesquite::TargetCalculator.

Definition at line 234 of file CachingTargetCalculator.cpp.

References cachedCalculator, MBMesquite::CachedTargetData::elementOffsets, MBMesquite::ExtraDataUser< CachedTargetData >::get_data(), MBMesquite::PatchData::get_samples(), have_surface_orient(), INTERNAL_ERROR, MBMesquite::MsqError::INVALID_STATE, MSQ_ERRZERO, MSQ_SETERR, MBMesquite::NodeSet::num_before(), MBMesquite::populate_data(), and MBMesquite::CachedTargetData::targets2D.

{
    CachedTargetData& data = get_data( pd );
    if( data.targets2D.empty() )
    {
        if( have_surface_orient() )
        {
            MSQ_SETERR( err )( "Incorrect surface mesh target type", MsqError::INTERNAL_ERROR );
            return false;
        }

        populate_data( pd, &data, cachedCalculator, err );
        MSQ_ERRZERO( err );
        if( data.targets2D.empty() )
        {
            MSQ_SETERR( err )
            ( "Attempt to get 2D target for 3D element type", MsqError::INVALID_STATE );
            return false;
        }
    }

    // calculate index of sample in array
    NodeSet all_samples = pd.get_samples( element );
    unsigned offset     = all_samples.num_before( sample );

    W_out = data.targets2D[data.elementOffsets[element] + offset];
    return true;
}
bool MBMesquite::CachingTargetCalculator::get_3D_target ( PatchData pd,
size_t  element,
Sample  sample,
MsqMatrix< 3, 3 > &  W_out,
MsqError err 
) [virtual]

Get a target matrix.

Parameters:
pdThe current PatchData
elementThe index an element within the patch data.
sampleThe sample point in the element.
W_outThe resulting target matrix.

Implements MBMesquite::TargetCalculator.

Definition at line 216 of file CachingTargetCalculator.cpp.

References cachedCalculator, MBMesquite::CachedTargetData::elementOffsets, MBMesquite::ExtraDataUser< CachedTargetData >::get_data(), MBMesquite::PatchData::get_samples(), MSQ_ERRZERO, MBMesquite::NodeSet::num_before(), MBMesquite::populate_data(), and MBMesquite::CachedTargetData::targets3D.

{
    CachedTargetData& data = get_data( pd );
    if( data.targets3D.empty() )
    {
        populate_data( pd, &data, cachedCalculator, err );
        MSQ_ERRZERO( err );
    }

    // calculate index of sample in array
    NodeSet all_samples = pd.get_samples( element );
    unsigned offset     = all_samples.num_before( sample );

    W_out = data.targets3D[data.elementOffsets[element] + offset];
    return true;
}
bool MBMesquite::CachingTargetCalculator::get_surface_target ( PatchData pd,
size_t  element,
Sample  sample,
MsqMatrix< 3, 2 > &  W_out,
MsqError err 
) [virtual]

Get a target matrix.

Parameters:
pdThe current PatchData
elementThe index an element within the patch data.
sampleThe sample point in the element.
W_outThe resulting target matrix.

Implements MBMesquite::TargetCalculator.

Definition at line 264 of file CachingTargetCalculator.cpp.

References cachedCalculator, MBMesquite::CachedTargetData::elementOffsets, MBMesquite::ExtraDataUser< CachedTargetData >::get_data(), MBMesquite::PatchData::get_samples(), have_surface_orient(), INTERNAL_ERROR, MBMesquite::MsqError::INVALID_STATE, MSQ_ERRZERO, MSQ_SETERR, MBMesquite::NodeSet::num_before(), MBMesquite::populate_data(), and MBMesquite::CachedTargetData::targetsSurface.

{
    CachedTargetData& data = get_data( pd );
    if( data.targetsSurface.empty() )
    {
        if( !have_surface_orient() )
        {
            MSQ_SETERR( err )( "Incorrect surface mesh target type", MsqError::INTERNAL_ERROR );
            return false;
        }

        populate_data( pd, &data, cachedCalculator, err );
        MSQ_ERRZERO( err );
        if( data.targetsSurface.empty() )
        {
            MSQ_SETERR( err )
            ( "Attempt to get 2D target for 3D element type", MsqError::INVALID_STATE );
            return false;
        }
    }

    // calculate index of sample in array
    NodeSet all_samples = pd.get_samples( element );
    unsigned offset     = all_samples.num_before( sample );

    W_out = data.targetsSurface[data.elementOffsets[element] + offset];
    return true;
}
virtual bool MBMesquite::CachingTargetCalculator::have_surface_orient ( ) const [inline, virtual]

Use 3x2 W for surface elements if true, 2x2 W if false.

If true, then the targets for surface elements attempt some control of orientation and therefore get_surface_target must be used to get the targets. If false, then the target contains no orientation data and is therefore the same as the corresponding 2D target for surface elements. In this case, get_2D_target should be used.

Implements MBMesquite::TargetCalculator.

Definition at line 91 of file CachingTargetCalculator.hpp.

References cachedCalculator, and MBMesquite::TargetCalculator::have_surface_orient().

Referenced by get_2D_target(), get_surface_target(), and notify_sub_patch().

void MBMesquite::CachingTargetCalculator::notify_new_patch ( PatchData patch,
CachedTargetData data 
) [protected, virtual]

Implements MBMesquite::ExtraDataUser< CachedTargetData >.

Definition at line 44 of file CachingTargetCalculator.cpp.

References MBMesquite::CachedTargetData::clear().

{
    data.clear();
}
void MBMesquite::CachingTargetCalculator::notify_sub_patch ( PatchData orig_patch,
CachedTargetData data,
PatchData sub_patch,
const size_t *  vertex_index_map,
const size_t *  element_index_map,
MsqError err 
) [protected, virtual]

Implements MBMesquite::ExtraDataUser< CachedTargetData >.

Definition at line 54 of file CachingTargetCalculator.cpp.

References MBMesquite::CachedTargetData::clear(), MBMesquite::PatchData::element_by_index(), MBMesquite::CachedTargetData::elementOffsets, MBMesquite::ExtraDataUser< CachedTargetData >::get_data(), MBMesquite::MsqMeshEntity::get_element_type(), MBMesquite::PatchData::get_samples(), MBMesquite::CachedTargetData::has_data(), have_surface_orient(), MBMesquite::PatchData::num_elements(), MBMesquite::NodeSet::num_nodes(), MBMesquite::CachedTargetData::targets2D, MBMesquite::CachedTargetData::targets3D, and MBMesquite::CachedTargetData::targetsSurface.

{
    // If no cached data for this patch, just return
    if( data.has_data() ) return;

    // Create a new cached data object on the subpatch
    CachedTargetData& sub_data = get_data( subpatch );
    sub_data.clear();

    // populate the element offset list, and count the total
    // number of cached target matrices.
    sub_data.elementOffsets.resize( subpatch.num_elements() );
    size_t count_2D = 0, count_3D = 0;
    for( size_t i = 0; i < subpatch.num_elements(); ++i )
    {
        EntityTopology type        = subpatch.element_by_index( i ).get_element_type();
        size_t& count              = ( TopologyInfo::dimension( type ) == 2 ) ? count_2D : count_3D;
        sub_data.elementOffsets[i] = count;
        NodeSet samples            = subpatch.get_samples( i );
        count += samples.num_nodes();
    }

    const bool orient = have_surface_orient();
    sub_data.targets3D.resize( count_3D );
    if( orient )
        sub_data.targetsSurface.resize( count_2D );
    else
        sub_data.targets2D.resize( count_2D );

    for( size_t i = 0; i < subpatch.num_elements(); ++i )
    {
        EntityTopology type = subpatch.element_by_index( i ).get_element_type();
        size_t off          = sub_data.elementOffsets[i];
        size_t old_off      = data.elementOffsets[element_map[i]];
        NodeSet samples     = subpatch.get_samples( i );
        size_t count        = samples.num_nodes();

        if( TopologyInfo::dimension( type ) == 3 )
            memcpy( &sub_data.targets3D[off], &data.targets3D[old_off], count * sizeof( MsqMatrix< 3, 3 > ) );
        else if( orient )
            memcpy( &sub_data.targetsSurface[off], &data.targetsSurface[old_off], count * sizeof( MsqMatrix< 3, 2 > ) );
        else
            memcpy( &sub_data.targets2D[off], &data.targets2D[old_off], count * sizeof( MsqMatrix< 2, 2 > ) );
    }
}

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