MOAB: Mesh Oriented datABase  (version 5.2.1)
MBMesquite::WeightReader Class Reference

Read targets from tag data. More...

#include <WeightReader.hpp>

+ Inheritance diagram for MBMesquite::WeightReader:
+ Collaboration diagram for MBMesquite::WeightReader:

Public Member Functions

MESQUITE_EXPORT WeightReader (std::string tag_base_name="MSQ_TARGET_WEIGHT")
virtual MESQUITE_EXPORT ~WeightReader ()
virtual MESQUITE_EXPORT double get_weight (PatchData &pd, size_t element, Sample Sample, MsqError &err)
 Get target metric weight.

Private Member Functions

virtual void notify_patch_destroyed (WeightReaderData &data)
virtual void notify_new_patch (PatchData &pd, WeightReaderData &data)
virtual void notify_sub_patch (PatchData &pd, WeightReaderData &data, PatchData &subpatch, const size_t *vertex_map, const size_t *element_map, MsqError &err)

Private Attributes

std::string tagBaseName

Detailed Description

Read targets from tag data.

Definition at line 61 of file WeightReader.hpp.


Constructor & Destructor Documentation

MBMesquite::WeightReader::WeightReader ( std::string  tag_base_name = "MSQ_TARGET_WEIGHT")

Definition at line 66 of file WeightReader.cpp.

: tagBaseName( name ) {}

Definition at line 68 of file WeightReader.cpp.

{}

Member Function Documentation

double MBMesquite::WeightReader::get_weight ( PatchData pd,
size_t  element,
Sample  sample,
MsqError err 
) [virtual]

Get target metric weight.

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

Implements MBMesquite::WeightCalculator.

Definition at line 70 of file WeightReader.cpp.

References MBMesquite::WeightReaderData::elementIndex, MBMesquite::ExtraDataUser< WeightReaderData >::get_data(), MBMesquite::PatchData::get_element_handles_array(), MBMesquite::PatchData::get_mesh(), MBMesquite::PatchData::get_samples(), MBMesquite::get_tag(), MBMesquite::WeightReaderData::handles, MSQ_CHKERR, MSQ_ERRZERO, MBMesquite::NodeSet::num_before(), MBMesquite::NodeSet::num_nodes(), MBMesquite::Mesh::tag_get_element_data(), tagBaseName, and MBMesquite::WeightReaderData::weights.

Referenced by TargetReadWriteTest::read_write_weights().

{
    WeightReaderData& data = get_data( pd );

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

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

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

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

    data.elementIndex = element;

    assert( offset < num_samples );
    return data.weights[offset];
}
void MBMesquite::WeightReader::notify_new_patch ( PatchData pd,
WeightReaderData data 
) [private, virtual]

Implements MBMesquite::ExtraDataUser< WeightReaderData >.

Definition at line 119 of file WeightReader.cpp.

References MBMesquite::WeightReaderData::weights.

{
    data.weights.clear();
}

Implements MBMesquite::ExtraDataUser< WeightReaderData >.

Definition at line 113 of file WeightReader.cpp.

References MBMesquite::WeightReaderData::handles, and MBMesquite::WeightReaderData::weights.

{
    data.handles.clear();
    data.weights.clear();
}
void MBMesquite::WeightReader::notify_sub_patch ( PatchData pd,
WeightReaderData data,
PatchData subpatch,
const size_t *  vertex_map,
const size_t *  element_map,
MsqError err 
) [private, virtual]

Implements MBMesquite::ExtraDataUser< WeightReaderData >.

Definition at line 124 of file WeightReader.cpp.

References MBMesquite::ExtraDataUser< WeightReaderData >::get_data(), and MBMesquite::WeightReaderData::handles.

{
    WeightReaderData& other = get_data( subpatch );
    if( other.handles.empty() ) other.handles = data.handles;
}

Member Data Documentation

Definition at line 77 of file WeightReader.hpp.

Referenced by get_weight().

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