MOAB: Mesh Oriented datABase  (version 5.3.1)
MBMesquite::TargetReader Class Reference

Read targets from tag data. More...

#include <TargetReader.hpp>

+ Inheritance diagram for MBMesquite::TargetReader:
+ Collaboration diagram for MBMesquite::TargetReader:

Public Member Functions

MESQUITE_EXPORT TargetReader (bool oriented_2D_targets, std::string tag_base_name="MSQ_TARGET_MATRIX")
virtual MESQUITE_EXPORT ~TargetReader ()
virtual MESQUITE_EXPORT bool get_3D_target (PatchData &pd, size_t element, Sample sample, MsqMatrix< 3, 3 > &W_out, MsqError &err)
 Get a target matrix.
virtual MESQUITE_EXPORT bool get_2D_target (PatchData &pd, size_t element, Sample sample, MsqMatrix< 2, 2 > &W_out, MsqError &err)
 Get a target matrix.
virtual MESQUITE_EXPORT bool get_surface_target (PatchData &pd, size_t element, Sample sample, MsqMatrix< 3, 2 > &W_out, MsqError &err)
 Get a target matrix.
virtual MESQUITE_EXPORT bool have_surface_orient () const
 Use 3x2 W for surface elements if true, 2x2 W if false.

Private Member Functions

virtual void notify_patch_destroyed (TargetReaderData &data)
virtual void notify_new_patch (PatchData &pd, TargetReaderData &data)
virtual void notify_sub_patch (PatchData &pd, TargetReaderData &data, PatchData &subpatch, const size_t *vert_map, const size_t *elem_map, MsqError &err)

Private Attributes

std::string tagBaseName
 Base name for tags used to store targets.
bool orient2D
 2D targets included orientation (3x2 rather than 2x2)

Detailed Description

Read targets from tag data.

Definition at line 63 of file TargetReader.hpp.


Constructor & Destructor Documentation

MBMesquite::TargetReader::TargetReader ( bool  oriented_2D_targets,
std::string  tag_base_name = "MSQ_TARGET_MATRIX" 
)

Definition at line 74 of file TargetReader.cpp.

: tagBaseName( name ), orient2D( orient2d ) {}

Definition at line 76 of file TargetReader.cpp.

{}

Member Function Documentation

bool MBMesquite::TargetReader::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 129 of file TargetReader.cpp.

References dim, MBMesquite::PatchData::element_by_index(), MBMesquite::TargetReaderData::elementIndex, MBMesquite::ExtraDataUser< TargetReaderData >::get_data(), MBMesquite::PatchData::get_element_handles_array(), MBMesquite::MsqMeshEntity::get_element_type(), MBMesquite::PatchData::get_mesh(), MBMesquite::PatchData::get_samples(), MBMesquite::get_tag(), MBMesquite::TargetReaderData::handles2D, INTERNAL_ERROR, MBMesquite::MsqError::INVALID_STATE, MSQ_CHKERR, MSQ_ERRZERO, MSQ_SETERR, MBMesquite::NodeSet::num_before(), MBMesquite::NodeSet::num_nodes(), orient2D, MBMesquite::Mesh::tag_get_element_data(), tagBaseName, and MBMesquite::TargetReaderData::targets2D.

Referenced by TargetReadWriteTest::read_write_2D_targets().

{
    // which type of 2D target do we actually have
    if( orient2D )
    {
        MSQ_SETERR( err )( "Incorrect surface mesh target type", MsqError::INTERNAL_ERROR );
        return false;
    }

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

    int dim = TopologyInfo::dimension( pd.element_by_index( element ).get_element_type() );
    if( dim == 3 )
    {
        MSQ_SETERR( err )
        ( "Attempt to read surface target for region element", MsqError::INVALID_STATE );
        return false;
    }

    TargetReaderData& data = get_data( pd );
    if( !data.targets2D.empty() && data.elementIndex == element )
    {
        assert( offset < data.targets2D.size() );
        W_out = data.targets2D[offset];
        return true;
    }
    const unsigned num_samples = all_samples.num_nodes();
    const unsigned handle_idx  = num_samples - 1;

    // get the tag handle
    const size_t INVALID_HANDLE = (size_t)-1;
    if( data.handles2D.size() <= handle_idx ) data.handles2D.resize( handle_idx + 1, (TagHandle)INVALID_HANDLE );
    TagHandle& tag_handle = data.handles2D[handle_idx];
    if( tag_handle == (TagHandle)INVALID_HANDLE )
    {
        tag_handle = get_tag( pd.get_mesh(), num_samples, 2, tagBaseName.c_str(), orient2D, err );
        MSQ_ERRZERO( err );
        assert( tag_handle != (TagHandle)INVALID_HANDLE );
    }

    // get the tag data
    data.targets2D.resize( num_samples );
    pd.get_mesh()->tag_get_element_data( tag_handle, 1, pd.get_element_handles_array() + element, &data.targets2D[0],
                                         err );
    if( MSQ_CHKERR( err ) )
    {
        data.targets2D.clear();
        return false;
    }

    data.elementIndex = element;
    W_out             = data.targets2D[offset];
    return true;
}
bool MBMesquite::TargetReader::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 78 of file TargetReader.cpp.

References dim, MBMesquite::PatchData::element_by_index(), MBMesquite::TargetReaderData::elementIndex, MBMesquite::ExtraDataUser< TargetReaderData >::get_data(), MBMesquite::PatchData::get_element_handles_array(), MBMesquite::MsqMeshEntity::get_element_type(), MBMesquite::PatchData::get_mesh(), MBMesquite::PatchData::get_samples(), MBMesquite::get_tag(), MBMesquite::TargetReaderData::handles3D, MBMesquite::MsqError::INVALID_STATE, MSQ_CHKERR, MSQ_ERRZERO, MSQ_SETERR, MBMesquite::NodeSet::num_before(), MBMesquite::NodeSet::num_nodes(), orient2D, MBMesquite::Mesh::tag_get_element_data(), tagBaseName, and MBMesquite::TargetReaderData::targets3D.

Referenced by TargetReadWriteTest::read_write_3D_targets().

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

    int dim = TopologyInfo::dimension( pd.element_by_index( element ).get_element_type() );
    if( dim == 2 )
    {
        MSQ_SETERR( err )
        ( "Attempt to read 3D target for surface element", MsqError::INVALID_STATE );
        return false;
    }

    TargetReaderData& data = get_data( pd );
    if( !data.targets3D.empty() && data.elementIndex == element )
    {
        assert( offset < data.targets3D.size() );
        W_out = data.targets3D[offset];
        return true;
    }
    const unsigned num_samples = all_samples.num_nodes();
    const unsigned handle_idx  = num_samples - 1;

    // get the tag handle
    const size_t INVALID_HANDLE = (size_t)-1;
    if( data.handles3D.size() <= handle_idx ) data.handles3D.resize( handle_idx + 1, (TagHandle)INVALID_HANDLE );
    TagHandle& tag_handle = data.handles3D[handle_idx];
    if( tag_handle == (TagHandle)INVALID_HANDLE )
    {
        tag_handle = get_tag( pd.get_mesh(), num_samples, 3, tagBaseName.c_str(), orient2D, err );
        MSQ_ERRZERO( err );
        assert( tag_handle != (TagHandle)INVALID_HANDLE );
    }

    // get the tag data
    data.targets3D.resize( num_samples );
    pd.get_mesh()->tag_get_element_data( tag_handle, 1, pd.get_element_handles_array() + element, &data.targets3D[0],
                                         err );
    if( MSQ_CHKERR( err ) )
    {
        data.targets3D.clear();
        return false;
    }

    data.elementIndex = element;
    W_out             = data.targets3D[offset];
    return true;
}
bool MBMesquite::TargetReader::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 187 of file TargetReader.cpp.

References dim, MBMesquite::PatchData::element_by_index(), MBMesquite::TargetReaderData::elementIndex, MBMesquite::ExtraDataUser< TargetReaderData >::get_data(), MBMesquite::PatchData::get_element_handles_array(), MBMesquite::MsqMeshEntity::get_element_type(), MBMesquite::PatchData::get_mesh(), MBMesquite::PatchData::get_samples(), MBMesquite::get_tag(), MBMesquite::TargetReaderData::handles2D, INTERNAL_ERROR, MBMesquite::MsqError::INVALID_STATE, MSQ_CHKERR, MSQ_ERRZERO, MSQ_SETERR, MBMesquite::NodeSet::num_before(), MBMesquite::NodeSet::num_nodes(), orient2D, MBMesquite::Mesh::tag_get_element_data(), tagBaseName, and MBMesquite::TargetReaderData::targetsSurface.

Referenced by TargetReadWriteTest::read_write_surface_targets().

{
    // which type of 2D target do we actually have
    if( !orient2D )
    {
        MSQ_SETERR( err )( "Incorrect surface mesh target type", MsqError::INTERNAL_ERROR );
        return false;
    }

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

    int dim = TopologyInfo::dimension( pd.element_by_index( element ).get_element_type() );
    if( dim == 3 )
    {
        MSQ_SETERR( err )
        ( "Attempt to read surface target for region element", MsqError::INVALID_STATE );
        return false;
    }

    TargetReaderData& data = get_data( pd );
    if( !data.targetsSurface.empty() && data.elementIndex == element )
    {
        assert( offset < data.targetsSurface.size() );
        W_out = data.targetsSurface[offset];
        return true;
    }
    const unsigned num_samples = all_samples.num_nodes();
    const unsigned handle_idx  = num_samples - 1;

    // get the tag handle
    const size_t INVALID_HANDLE = (size_t)-1;
    if( data.handles2D.size() <= handle_idx ) data.handles2D.resize( handle_idx + 1, (TagHandle)INVALID_HANDLE );
    TagHandle& tag_handle = data.handles2D[handle_idx];
    if( tag_handle == (TagHandle)INVALID_HANDLE )
    {
        tag_handle = get_tag( pd.get_mesh(), num_samples, 2, tagBaseName.c_str(), orient2D, err );
        MSQ_ERRZERO( err );
        assert( tag_handle != (TagHandle)INVALID_HANDLE );
    }

    // get the tag data
    data.targetsSurface.resize( num_samples );
    pd.get_mesh()->tag_get_element_data( tag_handle, 1, pd.get_element_handles_array() + element,
                                         &data.targetsSurface[0], err );
    if( MSQ_CHKERR( err ) )
    {
        data.targetsSurface.clear();
        return false;
    }

    data.elementIndex = element;
    W_out             = data.targetsSurface[offset];
    return true;
}
virtual MESQUITE_EXPORT bool MBMesquite::TargetReader::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 80 of file TargetReader.hpp.

References orient2D.

    {
        return orient2D;
    }
void MBMesquite::TargetReader::notify_new_patch ( PatchData pd,
TargetReaderData data 
) [private, virtual]

Implements MBMesquite::ExtraDataUser< TargetReaderData >.

Definition at line 254 of file TargetReader.cpp.

References MBMesquite::TargetReaderData::targets2D, MBMesquite::TargetReaderData::targets3D, and MBMesquite::TargetReaderData::targetsSurface.

{
    data.targets3D.clear();
    data.targets2D.clear();
    data.targetsSurface.clear();
}

Implements MBMesquite::ExtraDataUser< TargetReaderData >.

Definition at line 245 of file TargetReader.cpp.

References MBMesquite::TargetReaderData::handles2D, MBMesquite::TargetReaderData::handles3D, MBMesquite::TargetReaderData::targets2D, MBMesquite::TargetReaderData::targets3D, and MBMesquite::TargetReaderData::targetsSurface.

{
    data.handles2D.clear();
    data.handles3D.clear();
    data.targets3D.clear();
    data.targets2D.clear();
    data.targetsSurface.clear();
}
void MBMesquite::TargetReader::notify_sub_patch ( PatchData pd,
TargetReaderData data,
PatchData subpatch,
const size_t *  vert_map,
const size_t *  elem_map,
MsqError err 
) [private, virtual]

Implements MBMesquite::ExtraDataUser< TargetReaderData >.

Definition at line 261 of file TargetReader.cpp.

References MBMesquite::ExtraDataUser< TargetReaderData >::get_data(), MBMesquite::TargetReaderData::handles2D, and MBMesquite::TargetReaderData::handles3D.

{
    TargetReaderData& other = get_data( subpatch );
    if( other.handles2D.empty() && other.handles3D.empty() )
    {
        other.handles2D = data.handles2D;
        other.handles3D = data.handles3D;
    }
}

Member Data Documentation

2D targets included orientation (3x2 rather than 2x2)

Definition at line 92 of file TargetReader.hpp.

Referenced by get_2D_target(), get_3D_target(), get_surface_target(), and have_surface_orient().

Base name for tags used to store targets.

Definition at line 91 of file TargetReader.hpp.

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

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