MOAB: Mesh Oriented datABase
(version 5.4.1)
|
Miscelanions operations performed on an entire Mesh
without the conveinience of a PatchData
.
More...
#include <MeshUtil.hpp>
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 | |
PatchData * | get_global_patch (MsqError &err) |
Private Attributes | |
Mesh * | myMesh |
Settings * | mySettings |
PatchData * | globalPatch |
Miscelanions operations performed on an entire Mesh
without the conveinience of a PatchData
.
Definition at line 48 of file MeshUtil.hpp.
MBMesquite::MeshUtil::MeshUtil | ( | Mesh * | mesh, |
Settings * | settings = 0 |
||
) | [inline] |
Definition at line 59 of file MeshUtil.hpp.
: myMesh( mesh ), mySettings( settings ), globalPatch( 0 ) {}
void MBMesquite::MeshUtil::edge_length_distribution | ( | SimpleStats & | result, |
MsqError & | err | ||
) |
Calcluate statistics for mesh edge lengths.
Definition at line 72 of file MeshUtil.cpp.
References MBMesquite::SimpleStats::add_squared(), MBMesquite::SimpleStats::empty(), MBMesquite::EdgeIterator::end(), get_global_patch(), MBMesquite::MsqError::INVALID_MESH, MBMesquite::EdgeIterator::is_at_end(), MSQ_ERRRTN, MSQ_SETERR, MBMesquite::EdgeIterator::start(), and MBMesquite::EdgeIterator::step().
Referenced by MBMesquite::TerminationCriterion::initialize_queue(), TerminationCriterionTest::test_absolute_vertex_movement_edge_length(), MeshUtilTest::test_edge_length_distribution_empty(), MeshUtilTest::test_edge_length_distribution_types(), MeshUtilTest::test_edge_length_distribution_unique(), and MeshUtilTest::test_lambda_distribution_mixed().
{ PatchData* pd = get_global_patch( err );MSQ_ERRRTN( err ); EdgeIterator iter( pd, err );MSQ_ERRRTN( err ); while( !iter.is_at_end() ) { Vector3D diff = iter.start() - iter.end(); results.add_squared( diff % diff ); iter.step( err );MSQ_ERRRTN( err ); } if( results.empty() ) { // no mesh MSQ_SETERR( err )( "Mesh contains no elements", MsqError::INVALID_MESH ); } }
PatchData * MBMesquite::MeshUtil::get_global_patch | ( | MsqError & | err | ) | [protected] |
Definition at line 55 of file MeshUtil.cpp.
References MBMesquite::PatchData::attach_settings(), MBMesquite::PatchData::fill_global_patch(), globalPatch, MSQ_CHKERR, myMesh, mySettings, and MBMesquite::PatchData::set_mesh().
Referenced by edge_length_distribution(), and lambda_distribution().
{ if( !globalPatch ) { globalPatch = new PatchData; globalPatch->set_mesh( myMesh ); if( mySettings ) globalPatch->attach_settings( mySettings ); globalPatch->fill_global_patch( err ); if( MSQ_CHKERR( err ) ) { delete globalPatch; globalPatch = 0; } } return globalPatch; }
void MBMesquite::MeshUtil::lambda_distribution | ( | SimpleStats & | result, |
MsqError & | err | ||
) |
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.
mesh1 | the first mesh to compare |
mesh2 | the second mesh to compare |
tol | a relative tolerance for coordinates |
do_print | flag 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; }
PatchData* MBMesquite::MeshUtil::globalPatch [private] |
Definition at line 53 of file MeshUtil.hpp.
Referenced by get_global_patch(), and ~MeshUtil().
Mesh* MBMesquite::MeshUtil::myMesh [private] |
Definition at line 51 of file MeshUtil.hpp.
Referenced by get_global_patch().
Settings* MBMesquite::MeshUtil::mySettings [private] |
Definition at line 52 of file MeshUtil.hpp.
Referenced by get_global_patch().