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

Miscelanions operations performed on an entire Mesh without the conveinience of a PatchData. More...

#include <MeshUtil.hpp>

+ Collaboration diagram for MBMesquite::MeshUtil:

Public Member Functions

 MeshUtil (Mesh *mesh, Settings *settings=0)
 ~MeshUtil ()
void edge_length_distribution (SimpleStats &result, MsqError &err)
 Calcluate statistics for mesh edge lengths.
void lambda_distribution (SimpleStats &result, MsqError &err)

Static Public Member Functions

static bool meshes_are_different (Mesh &mesh1, Mesh &mesh2, MsqError &err, double tol=1.e-5, bool do_print=false)
 Given two meshes, check if they are different, return true if they are.

Protected Member Functions

PatchDataget_global_patch (MsqError &err)

Private Attributes

MeshmyMesh
SettingsmySettings
PatchDataglobalPatch

Detailed Description

Miscelanions operations performed on an entire Mesh without the conveinience of a PatchData.

Definition at line 48 of file MeshUtil.hpp.


Constructor & Destructor Documentation

MBMesquite::MeshUtil::MeshUtil ( Mesh mesh,
Settings settings = 0 
) [inline]

Definition at line 59 of file MeshUtil.hpp.

Definition at line 50 of file MeshUtil.cpp.

References globalPatch.

{
    delete globalPatch;
}

Member Function Documentation

Definition at line 89 of file MeshUtil.cpp.

References MBMesquite::SimpleStats::add_value(), MBMesquite::ElemSampleQM::elem(), MBMesquite::PatchData::element_by_index(), MBMesquite::SimpleStats::empty(), MBMesquite::MsqMeshEntity::get_element_type(), get_global_patch(), MBMesquite::PatchData::get_mapping_function_2D(), MBMesquite::PatchData::get_mapping_function_3D(), MBMesquite::TMPQualityMetric::get_patch_evaluations(), MBMesquite::MsqError::INVALID_MESH, MBMesquite::MappingFunction2D::jacobian(), MBMesquite::MappingFunction3D::jacobian(), MSQ_ERRRTN, MSQ_SETERR, N, MBMesquite::PatchData::non_slave_node_set(), sample, size, and MBMesquite::MsqError::UNSUPPORTED_ELEMENT.

Referenced by MBMesquite::PaverMinEdgeLengthWrapper::run_wrapper(), MeshUtilTest::test_lambda_distribution(), and MeshUtilTest::test_lambda_distribution_empty().

{
    PatchData& pd = *get_global_patch( err );MSQ_ERRRTN( err );

    std::vector< size_t > handles;
    TMPQualityMetric::get_patch_evaluations( pd, handles, false, err );

    const size_t N = 64;
    size_t count;
    size_t indices[N];
    MsqVector< 2 > derivs2D[N];
    MsqVector< 3 > derivs3D[N];

    for( size_t i = 0; i < handles.size(); ++i )
    {
        double lambda;
        const Sample s      = ElemSampleQM::sample( handles[i] );
        const size_t e      = ElemSampleQM::elem( handles[i] );
        EntityTopology type = pd.element_by_index( e ).get_element_type();
        const NodeSet bits  = pd.non_slave_node_set( e );

        if( TopologyInfo::dimension( type ) == 3 )
        {
            const MappingFunction3D* mf = pd.get_mapping_function_3D( type );
            if( !mf )
            {
                MSQ_SETERR( err )
                ( "No mapping function for element type", MsqError::UNSUPPORTED_ELEMENT );
                return;
            }

            MsqMatrix< 3, 3 > W;
            mf->jacobian( pd, e, bits, s, indices, derivs3D, count, W, err );MSQ_ERRRTN( err );
            assert( N >= count );
            lambda = TargetCalculator::size( W );
        }
        else
        {
            assert( TopologyInfo::dimension( type ) == 2 );
            const MappingFunction2D* mf = pd.get_mapping_function_2D( type );
            if( !mf )
            {
                MSQ_SETERR( err )
                ( "No mapping function for element type", MsqError::UNSUPPORTED_ELEMENT );
                return;
            }

            MsqMatrix< 3, 2 > W;
            mf->jacobian( pd, e, bits, s, indices, derivs2D, count, W, err );MSQ_ERRRTN( err );
            assert( N >= count );
            lambda = TargetCalculator::size( W );
        }

        results.add_value( lambda );
    }

    if( results.empty() )
    {  // no mesh
        MSQ_SETERR( err )( "Mesh contains no elements", MsqError::INVALID_MESH );
    }
}
bool MBMesquite::MeshUtil::meshes_are_different ( Mesh mesh1,
Mesh mesh2,
MsqError err,
double  tol = 1.e-5,
bool  do_print = false 
) [static]

Given two meshes, check if they are different, return true if they are.

Parameters:
mesh1the first mesh to compare
mesh2the second mesh to compare
tola relative tolerance for coordinates
do_printflag for printing differences

Only basic mesh properties are checked, number of vertices & elements, element connectivity, and coordinates (within the given relative tolerance).

Definition at line 151 of file MeshUtil.cpp.

References MBMesquite::arrptr(), dist(), MBMesquite::Vector3D::distance_between(), MBMesquite::Mesh::elements_get_attached_vertices(), MBMesquite::Mesh::elements_get_topologies(), MBMesquite::Mesh::get_all_elements(), MBMesquite::Mesh::get_all_vertices(), MBMesquite::Vector3D::length(), MDRET, MSQ_ERRZERO, and MBMesquite::Mesh::vertices_get_coordinates().

Referenced by main(), and test().

{
    // MsqError& err = (do_print ? MsqPrintError(cout) : MsqError());

    // mesh 1
    std::vector< Mesh::ElementHandle > elements1;
    std::vector< Mesh::VertexHandle > vertices1;
    std::vector< Mesh::VertexHandle > connectivity1;
    std::vector< size_t > offsets1;

    mesh1.get_all_elements( elements1, err );
    MSQ_ERRZERO( err );
    mesh1.get_all_vertices( vertices1, err );
    MSQ_ERRZERO( err );
    mesh1.elements_get_attached_vertices( arrptr( elements1 ), elements1.size(), connectivity1, offsets1, err );
    MSQ_ERRZERO( err );
    std::vector< EntityTopology > types1( elements1.size() );
    mesh1.elements_get_topologies( arrptr( elements1 ), arrptr( types1 ), elements1.size(), err );
    MSQ_ERRZERO( err );

    // mesh 2
    std::vector< Mesh::ElementHandle > elements2;
    std::vector< Mesh::VertexHandle > vertices2;
    std::vector< Mesh::VertexHandle > connectivity2;
    std::vector< size_t > offsets2;

    mesh2.get_all_elements( elements2, err );
    MSQ_ERRZERO( err );
    mesh2.get_all_vertices( vertices2, err );
    MSQ_ERRZERO( err );
    mesh2.elements_get_attached_vertices( arrptr( elements2 ), elements2.size(), connectivity2, offsets2, err );
    MSQ_ERRZERO( err );
    std::vector< EntityTopology > types2( elements2.size() );
    mesh2.elements_get_topologies( arrptr( elements2 ), arrptr( types2 ), elements2.size(), err );
    MSQ_ERRZERO( err );

#define MDRET( msg )                                                                                      \
    do                                                                                                    \
    {                                                                                                     \
        if( do_print ) std::cout << "MeshUtil::mesh_diff meshes are different: " << ( msg ) << std::endl; \
        return true;                                                                                      \
    } while( 0 )
    if( elements1.size() != elements2.size() ) MDRET( "elements sizes differ" );
    if( vertices1.size() != vertices2.size() ) MDRET( "vertices sizes differ" );
    if( offsets1.size() != offsets2.size() ) MDRET( "offsets sizes differ" );
    if( connectivity1.size() != connectivity2.size() ) MDRET( "connectivity sizes differ" );

    for( unsigned i = 0; i < offsets1.size(); i++ )
    {
        if( offsets1[i] != offsets2[i] ) MDRET( "offets differ" );
    }

    for( unsigned i = 0; i < vertices1.size(); i++ )
    {
        MsqVertex vert1, vert2;
        mesh1.vertices_get_coordinates( &vertices1[i], &vert1, 1, err );
        MSQ_ERRZERO( err );
        mesh2.vertices_get_coordinates( &vertices2[i], &vert2, 1, err );
        MSQ_ERRZERO( err );
        double dist = Vector3D::distance_between( vert1, vert2 );
        double v1   = vert1.length();
        double v2   = vert2.length();
        if( dist > 0.5 * ( v1 + v2 ) * tol )
        {
            std::ostringstream ost;
            ost << "vertices coordinates differ more than tolerance [" << tol << "], vert1= " << vert1
                << " vert2= " << vert2;
            MDRET( ost.str() );
        }
    }

    for( unsigned i = 0; i < connectivity1.size(); i++ )
    {
        MsqVertex vert1, vert2;
        mesh1.vertices_get_coordinates( &connectivity1[i], &vert1, 1, err );
        MSQ_ERRZERO( err );
        mesh2.vertices_get_coordinates( &connectivity2[i], &vert2, 1, err );
        MSQ_ERRZERO( err );
        double dist = Vector3D::distance_between( vert1, vert2 );
        double v1   = vert1.length();
        double v2   = vert2.length();
        if( dist > 0.5 * ( v1 + v2 ) * tol )
        {
            std::ostringstream ost;
            ost << "connectivity coordinates differ more than tolerance [" << tol << "], vert1= " << vert1
                << " vert2= " << vert2;
            MDRET( ost.str() );
        }
    }

    return false;
}

Member Data Documentation

Definition at line 53 of file MeshUtil.hpp.

Referenced by get_global_patch(), and ~MeshUtil().

Definition at line 51 of file MeshUtil.hpp.

Referenced by get_global_patch().

Definition at line 52 of file MeshUtil.hpp.

Referenced by get_global_patch().

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