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

An InstructionQueue object gathers Mesquite Instructions and ensures that the instruction queue is coherent for mesh improvement and/or mesh quality assessment purposes. More...

#include <InstructionQueue.hpp>

+ Inheritance diagram for MBMesquite::InstructionQueue:
+ Collaboration diagram for MBMesquite::InstructionQueue:

Public Member Functions

MESQUITE_EXPORT InstructionQueue ()
MESQUITE_EXPORT InstructionQueue (const Settings &settings)
virtual MESQUITE_EXPORT ~InstructionQueue ()
MESQUITE_EXPORT void add_target_calculator (TargetWriter *tc, MsqError &err)
MESQUITE_EXPORT void add_vertex_slaver (VertexSlaver *slaver, MsqError &err)
MESQUITE_EXPORT void remove_vertex_slaver (VertexSlaver *slaver, MsqError &err)
MESQUITE_EXPORT void add_tag_vertex_mesh (TagVertexMesh *m, MsqError &err)
MESQUITE_EXPORT void remove_tag_vertex_mesh (TagVertexMesh *m, MsqError &err)
MESQUITE_EXPORT void add_preconditioner (QualityImprover *instr, MsqError &err)
 adds a QualityImprover at the end of the instruction list
MESQUITE_EXPORT void remove_preconditioner (size_t index, MsqError &err)
 removes a QualityImprover* from the instruction queue
MESQUITE_EXPORT void insert_preconditioner (QualityImprover *instr, size_t index, MsqError &err)
 inserts a QualityImprover* into the instruction queue.
MESQUITE_EXPORT void add_quality_assessor (QualityAssessor *instr, MsqError &err)
 adds a QualityAssessor to the instruction queue.
MESQUITE_EXPORT void remove_quality_assessor (size_t index, MsqError &err)
 removes a QualityAssessor* from the instruction queue
MESQUITE_EXPORT void insert_quality_assessor (QualityAssessor *instr, size_t index, MsqError &err)
MESQUITE_EXPORT void set_master_quality_improver (QualityImprover *instr, MsqError &err)
MESQUITE_EXPORT void disable_automatic_quality_assessment ()
MESQUITE_EXPORT void enable_automatic_quality_assessment ()
virtual MESQUITE_EXPORT void run_common (MeshDomainAssoc *mesh_and_domain, ParallelMesh *pmesh, Settings *settings, MsqError &err)
 Exectute the instruction queue.
MESQUITE_EXPORT void clear ()

Private Member Functions

std::list< Instruction * >
::iterator 
clear_master (MsqError &err)

Private Attributes

std::list< Instruction * > instructions
bool autoQualAssess
int vertexSlaverCount
size_t nbPreConditionners
bool isMasterSet
size_t masterInstrIndex

Detailed Description

An InstructionQueue object gathers Mesquite Instructions and ensures that the instruction queue is coherent for mesh improvement and/or mesh quality assessment purposes.

The user can instantiate several InstructionQueue objects to be used with various MeshSet objects.

The most commonly used functions are:

  1. add_preconditioner(...)
  2. add_quality_assessor(...)
  3. set_master_quality_improver(...)
  4. run_instructions(...)

Definition at line 76 of file InstructionQueue.hpp.


Constructor & Destructor Documentation

Definition at line 62 of file InstructionQueue.cpp.

{}

Member Function Documentation

adds a QualityImprover at the end of the instruction list

This function cannot be used once the set_master_quality_improver() function has been used.

See also insert_preconditioner().

Definition at line 124 of file InstructionQueue.cpp.

References instructions, MBMesquite::MsqError::INVALID_STATE, isMasterSet, MSQ_SETERR, and nbPreConditionners.

Referenced by main(), smooth_mixed_mesh(), and VertexCullingRegressionTest::test_laplacian_smoothing_with_cull().

{
    if( isMasterSet )
    {
        MSQ_SETERR( err )
        ( "Cannot add preconditioners once the master "
          "QualityImprover has been set.",
          MsqError::INVALID_STATE );
        return;
    }

    instructions.push_back( instr );
    nbPreConditionners++;
}

Definition at line 64 of file InstructionQueue.cpp.

References instructions.

Referenced by run_test().

{
    instructions.push_back( tc );
}

Add a tool mark higher-order nodes as slaved. Note: Implies set_slaved_ho_node_mode( Settings::SLAVE_CALCULATED )

Definition at line 69 of file InstructionQueue.cpp.

References instructions, isMasterSet, masterInstrIndex, MBMesquite::Settings::set_slaved_ho_node_mode(), MBMesquite::Settings::SLAVE_CALCULATED, and vertexSlaverCount.

Referenced by main(), and InstructionQueueTest::test_add_remove_vertex_slaver().

Definition at line 358 of file InstructionQueue.cpp.

References autoQualAssess, instructions, isMasterSet, and masterInstrIndex.

{
    instructions.clear();
    autoQualAssess   = true;
    isMasterSet      = false;
    masterInstrIndex = 0;
}
std::list< Instruction * >::iterator InstructionQueue::clear_master ( MsqError err) [private]

Definition at line 366 of file InstructionQueue.cpp.

References instructions, MBMesquite::MsqError::INVALID_STATE, isMasterSet, masterInstrIndex, and MSQ_SETERR.

Referenced by set_master_quality_improver().

{
    std::list< Instruction* >::iterator instr_iter;
    std::list< Instruction* >::iterator master_pos;

    if( !isMasterSet )
    {
        MSQ_SETERR( err )( "No master quality improver to clear.", MsqError::INVALID_STATE );
        return instr_iter;
    }

    // position the instruction iterator over the master quality improver
    master_pos = instructions.begin();
    std::advance( master_pos, masterInstrIndex );

    // erases the master quality improver
    instr_iter  = instructions.erase( master_pos );
    isMasterSet = false;

    // returns the position where the Master was
    return instr_iter;
}
void InstructionQueue::insert_preconditioner ( QualityImprover instr,
size_t  index,
MsqError err 
)

inserts a QualityImprover* into the instruction queue.

Pre-conditionners can only be inserted before the master QualityImprover.

Parameters:
indexis 0-based. An error is set if the index does not correspond to a valid position in the queue.

Definition at line 183 of file InstructionQueue.cpp.

References instructions, MBMesquite::MsqError::INVALID_ARG, MBMesquite::MsqError::INVALID_STATE, isMasterSet, masterInstrIndex, MSQ_SETERR, and nbPreConditionners.

{
    // checks index is valid
    if( isMasterSet == true && index > masterInstrIndex )
    {
        MSQ_SETERR( err )
        ( "Cannot add a preconditioner after the master "
          "QualityImprover.",
          MsqError::INVALID_STATE );
        return;
    }
    if( index >= instructions.size() )
    {
        MSQ_SETERR( err )( "index", MsqError::INVALID_ARG );
        return;
    }

    // position the instruction iterator
    std::list< Instruction* >::iterator pos;
    pos = instructions.begin();
    std::advance( pos, index );
    // adds the preconditioner
    instructions.insert( pos, instr );
    nbPreConditionners++;
}
void InstructionQueue::insert_quality_assessor ( QualityAssessor instr,
size_t  index,
MsqError err 
)

QualityAssessors can be inserted at any position in the instruction queue.

Parameters:
indexis 0-based. An error is set if the index is past the end of the queue.

Definition at line 256 of file InstructionQueue.cpp.

References instructions, MBMesquite::MsqError::INVALID_ARG, and MSQ_SETERR.

{
    // checks index is valid
    if( index > instructions.size() )
    {
        MSQ_SETERR( err )
        ( "index points two positions beyond end of list.", MsqError::INVALID_ARG );
        return;
    }

    // position the instruction iterator
    std::list< Instruction* >::iterator pos;
    pos = instructions.begin();
    std::advance( pos, index );
    // adds the QualityAssessor
    instructions.insert( pos, instr );
}
void InstructionQueue::remove_preconditioner ( size_t  index,
MsqError err 
)

removes a QualityImprover* from the instruction queue

Parameters:
indexis 0-based. An error is set if the index does not correspond to a valid element in the queue.

Definition at line 145 of file InstructionQueue.cpp.

References instructions, MBMesquite::MsqError::INVALID_ARG, isMasterSet, masterInstrIndex, MSQ_SETERR, and nbPreConditionners.

{
    // checks index is valid
    if( isMasterSet && index == masterInstrIndex )
    {
        MSQ_SETERR( err )( "cannot remove master QualityImprover.", MsqError::INVALID_ARG );
        return;
    }
    else if( index >= instructions.size() )
    {
        MSQ_SETERR( err )( "Index points beyond end of list.", MsqError::INVALID_ARG );
        return;
    }

    // position the instruction iterator over the preconditioner to delete
    std::list< Instruction* >::iterator pos;
    pos = instructions.begin();
    std::advance( pos, index );

    if( !dynamic_cast< QualityImprover* >( *pos ) )
    {
        MSQ_SETERR( err )( "Index does not point to a QualityImprover.", MsqError::INVALID_ARG );
        return;
    }

    std::string name = ( *pos )->get_name();
    instructions.erase( pos );
    nbPreConditionners--;
}
void InstructionQueue::remove_quality_assessor ( size_t  index,
MsqError err 
)

removes a QualityAssessor* from the instruction queue

Parameters:
indexis 0-based. An error is set if the index does not correspond to a valid element in the queue.

Definition at line 225 of file InstructionQueue.cpp.

References instructions, MBMesquite::MsqError::INVALID_ARG, and MSQ_SETERR.

Referenced by MBMesquite::ViscousCFDTetShapeWrapper::run_wrapper().

{
    // checks index is valid
    if( index >= instructions.size() )
    {
        MSQ_SETERR( err )( "index", MsqError::INVALID_ARG );
        return;
    }

    // position the instruction iterator over the QualityAssessor to delete
    std::list< Instruction* >::iterator pos;
    pos = instructions.begin();
    std::advance( pos, index );

    if( !dynamic_cast< QualityAssessor* >( *pos ) )
    {
        MSQ_SETERR( err )( "Index does not point to a QualityImprover.", MsqError::INVALID_ARG );
        return;
    }

    std::string name = ( *pos )->get_name();
    instructions.erase( pos );
}

Definition at line 100 of file InstructionQueue.cpp.

References instructions, MBMesquite::MsqError::INVALID_ARG, isMasterSet, masterInstrIndex, and MSQ_SETERR.

{
    size_t idx = 0;
    for( std::list< Instruction* >::iterator i = instructions.begin(); i != instructions.end(); ++i, ++idx )
    {
        if( *i == vs )
        {
            instructions.erase( i );
            if( isMasterSet && masterInstrIndex > idx ) --masterInstrIndex;
            return;
        }
    }

    MSQ_SETERR( err )( "Not found", MsqError::INVALID_ARG );
}

Remove a tool mark higher-order nodes as slaved. Note: Implies set_slaved_ho_node_mode( Settings::SLAVE_ALL )

Definition at line 77 of file InstructionQueue.cpp.

References instructions, MBMesquite::MsqError::INVALID_ARG, isMasterSet, masterInstrIndex, MSQ_SETERR, MBMesquite::Settings::set_slaved_ho_node_mode(), MBMesquite::Settings::SLAVE_ALL, and vertexSlaverCount.

Referenced by main(), and InstructionQueueTest::test_add_remove_vertex_slaver().

{
    size_t idx = 0;
    for( std::list< Instruction* >::iterator i = instructions.begin(); i != instructions.end(); ++i, ++idx )
    {
        if( *i == vs )
        {
            instructions.erase( i );
            if( isMasterSet && masterInstrIndex > idx ) --masterInstrIndex;
            if( --vertexSlaverCount == 0 ) set_slaved_ho_node_mode( Settings::SLAVE_ALL );
            return;
        }
    }

    MSQ_SETERR( err )( "Not found", MsqError::INVALID_ARG );
}
void InstructionQueue::run_common ( MeshDomainAssoc mesh_and_domain,
ParallelMesh pmesh,
Settings settings,
MsqError err 
) [virtual]

Exectute the instruction queue.

Execute all operations in the instruction queue.

Parameters:
meshThe mesh to run each instruction on.
domainThe domain of the mesh -- may be NULL if no domain.

Implements MBMesquite::IQInterface.

Definition at line 295 of file InstructionQueue.cpp.

References MBMesquite::MeshDomainAssoc::get_domain(), MBMesquite::MeshDomainAssoc::get_mesh(), instructions, MBMesquite::MsqInterrupt::interrupt(), MBMesquite::MsqError::INTERRUPTED, MBMesquite::MsqError::INVALID_STATE, isMasterSet, mesh, MSQ_DBGOUT, MSQ_ERRRTN, MSQ_SETERR, nbPreConditionners, MBMesquite::Settings::trap_floating_point_exception(), and MBMesquite::version_string().

Referenced by ParShapeImprover::count_invalid_elements(), MBMesquite::PaverMinEdgeLengthWrapper::run_wrapper(), MBMesquite::SizeAdaptShapeWrapper::run_wrapper(), MBMesquite::ViscousCFDTetShapeWrapper::run_wrapper(), MBMesquite::ShapeImprover::run_wrapper(), MBMesquite::ShapeImprovementWrapper::run_wrapper(), MBMesquite::LaplaceWrapper::run_wrapper(), MBMesquite::UntangleWrapper::run_wrapper(), ParShapeImprover::ParShapeImprovementWrapper::run_wrapper(), and MBMesquite::DeformingDomainWrapper::run_wrapper().

{
    MSQ_DBGOUT( 1 ) << version_string( false ) << "\n";

    if( nbPreConditionners != 0 && isMasterSet == false )
    {
        MSQ_SETERR( err )
        ( "no pre-conditionners allowed if master QualityImprover "
          "is not set.",
          MsqError::INVALID_STATE );
        return;
    }

#ifdef ENABLE_INTERRUPT
    // Register SIGINT handler
    MsqInterrupt msq_interrupt;
#endif

    Mesh* mesh         = mesh_and_domain->get_mesh();
    MeshDomain* domain = mesh_and_domain->get_domain();

    // Generate SIGFPE on floating point errors
    MsqFPE fpe_trap( settings->trap_floating_point_exception() );

    std::list< Instruction* >::const_iterator instr;

    // Initialize each instruction
    for( instr = instructions.begin(); instr != instructions.end(); ++instr )
    {
        if( MsqInterrupt::interrupt() )
        {
            MSQ_SETERR( err )( MsqError::INTERRUPTED );
            return;
        }

        ( *instr )->initialize_queue( mesh_and_domain, settings, err );MSQ_ERRRTN( err );
    }

    // Run each instruction
    for( instr = instructions.begin(); instr != instructions.end(); ++instr )
    {
        if( MsqInterrupt::interrupt() )
        {
            MSQ_SETERR( err )( MsqError::INTERRUPTED );
            return;
        }

        if( pmesh )
        {
            assert( !mesh || pmesh == mesh );
            ( *instr )->loop_over_mesh( pmesh, domain, settings, err );
        }
        else
        {
            ( *instr )->loop_over_mesh( mesh_and_domain, settings, err );
        }
        MSQ_ERRRTN( err );
    }
}

Definition at line 274 of file InstructionQueue.cpp.

References clear_master(), instructions, isMasterSet, masterInstrIndex, MSQ_DBGOUT, and MSQ_ERRRTN.

Referenced by BCDTest::compare_bcd(), create_instruction_queue(), do_smoother(), main(), run(), run_global_smoother(), run_local_smoother(), run_local_smoother2(), run_quality_optimizer(), run_smoother(), run_solution_mesh_optimizer(), run_test(), MBMesquite::PaverMinEdgeLengthWrapper::run_wrapper(), MBMesquite::SizeAdaptShapeWrapper::run_wrapper(), MBMesquite::ViscousCFDTetShapeWrapper::run_wrapper(), MBMesquite::ShapeImprover::run_wrapper(), MBMesquite::ShapeImprovementWrapper::run_wrapper(), MBMesquite::LaplaceWrapper::run_wrapper(), MBMesquite::UntangleWrapper::run_wrapper(), ParShapeImprover::ParShapeImprovementWrapper::run_wrapper(), MBMesquite::DeformingDomainWrapper::run_wrapper(), smooth_mesh(), smooth_mixed_mesh(), TerminationCriterionTest::test_abs_vtx_movement_culling(), SphericalGeometryTest::test_cg_mesh_cond_sphere(), SphericalGeometryTest::test_lapl_geo_sphere(), VertexCullingRegressionTest::test_laplacian_smoothing_with_cull(), PlanarGeometryTest::test_plane_quad_tangled(), PlanarGeometryTest::test_plane_tri_tangled(), PlanarGeometryTest::test_plane_tri_xz(), and SphericalGeometryTest::test_smart_lapl_sphere().

{
    if( isMasterSet )
    {
        MSQ_DBGOUT( 1 ) << "InstructionQueue::set_master_quality_improver():\n"
                        << "\tOverwriting previously specified master quality improver.\n";
        // if master is already set, clears it and insert the new one at the same position.
        std::list< Instruction* >::iterator master_pos;
        master_pos = this->clear_master( err );MSQ_ERRRTN( err );
        instructions.insert( master_pos, instr );
        isMasterSet = true;
    }
    else
    {
        // if master is not set, add it at the end of the queue.
        instructions.push_back( instr );
        isMasterSet      = true;
        masterInstrIndex = instructions.size() - 1;
    }
}

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