MOAB: Mesh Oriented datABase  (version 5.4.1)
laplacian_test.cpp File Reference
#include <iostream>
#include <cstdlib>
#include "Mesquite.hpp"
#include "MsqError.hpp"
#include "MeshImpl.hpp"
#include "Vector3D.hpp"
#include "InstructionQueue.hpp"
#include "PatchData.hpp"
#include "TerminationCriterion.hpp"
#include "QualityAssessor.hpp"
#include "PlanarDomain.hpp"
#include "MsqTimer.hpp"
#include "TestUtil.hpp"
#include "ConditionNumberQualityMetric.hpp"
#include "LInfTemplate.hpp"
#include "SteepestDescent.hpp"
#include "LaplacianSmoother.hpp"
#include "EdgeLengthQualityMetric.hpp"
+ Include dependency graph for laplacian_test.cpp:

Go to the source code of this file.

Functions

void help (const char *argv0)
int main (int argc, char *argv[])

Variables

std::string DEFAULT_INPUT = "unittest/mesquite/2D/vtk/quads/untangled/square_quad_2.vtk"

Function Documentation

void help ( const char *  argv0)

Definition at line 74 of file laplacian_test.cpp.

References DEFAULT_INPUT.

{
    std::cerr << "Usage: " << argv0 << " [<input_file>] [<output_file>]" << std::endl
              << "  default input file is: " << DEFAULT_INPUT << std::endl
              << "  defualt is no output file" << std::endl
              << "  Warning: input mesh is assumed to lie in Z=5 plane" << std::endl;
    exit( 1 );
}
int main ( int  argc,
char *  argv[] 
)

Definition at line 83 of file laplacian_test.cpp.

References MBMesquite::TerminationCriterion::add_iteration_limit(), MBMesquite::QualityAssessor::add_quality_assessment(), MBMesquite::InstructionQueue::add_quality_assessor(), MBMesquite::arrptr(), DEFAULT_INPUT, dist(), MBMesquite::MeshImpl::get_all_vertices(), help(), input_file, mesh, MBMesquite::MeshImpl::read_vtk(), MBMesquite::QualityMetric::RMS, MBMesquite::IQInterface::run_instructions(), MBMesquite::AveragingQM::set_averaging_method(), MBMesquite::InstructionQueue::set_master_quality_improver(), MBMesquite::QualityImprover::set_outer_termination_criterion(), MBMesquite::Timer::since_birth(), t, MBMesquite::MeshImpl::vertices_get_coordinates(), MBMesquite::MeshImpl::vertices_get_fixed_flag(), and MBMesquite::MeshImpl::write_vtk().

{
    const char* input_file  = DEFAULT_INPUT.c_str();
    const char* output_file = NULL;
    switch( argc )
    {
        default:
            help( argv[0] );
        case 3:
            if( !strcmp( argv[2], "-h" ) ) help( argv[0] );
            output_file = argv[2];
        case 2:
            if( !strcmp( argv[1], "-h" ) ) help( argv[0] );
            input_file = argv[1];
        case 1:;
    }

    /* Read a VTK Mesh file */
    MsqPrintError err( cout );
    MBMesquite::MeshImpl mesh;
    mesh.read_vtk( input_file, err );
    if( err ) return 1;

    // creates an intruction queue
    InstructionQueue queue1;

    // creates a mean ratio quality metric ...
    ConditionNumberQualityMetric shape_metric;
    EdgeLengthQualityMetric lapl_met;
    lapl_met.set_averaging_method( QualityMetric::RMS );

    // creates the laplacian smoother  procedures
    LaplacianSmoother lapl1;
    QualityAssessor stop_qa = QualityAssessor( &shape_metric );
    stop_qa.add_quality_assessment( &lapl_met );

    //**************Set stopping criterion****************
    TerminationCriterion sc2;
    sc2.add_iteration_limit( 10 );
    if( err ) return 1;
    lapl1.set_outer_termination_criterion( &sc2 );

    // adds 1 pass of pass1 to mesh_set1
    queue1.add_quality_assessor( &stop_qa, err );
    if( err ) return 1;
    queue1.set_master_quality_improver( &lapl1, err );
    if( err ) return 1;
    queue1.add_quality_assessor( &stop_qa, err );
    if( err ) return 1;
    // adds 1 passes of pass2 to mesh_set1
    //  mesh_set1.add_quality_pass(pass2);

    // writeVtkMesh("original_mesh", mesh, err); MSQ_CHKERR(err);

    PlanarDomain plane( Vector3D( 0, 0, 1 ), Vector3D( 0, 0, 5 ) );

    // launches optimization on mesh_set1
    MeshDomainAssoc mesh_and_domain = MeshDomainAssoc( &mesh, &plane );
    Timer t;
    queue1.run_instructions( &mesh_and_domain, err );
    if( err ) return 1;
    double secs = t.since_birth();
    std::cout << "Optimization completed in " << secs << " seconds" << std::endl;

    if( output_file )
    {
        mesh.write_vtk( output_file, err );
        if( err ) return 1;
        std::cout << "Wrote file: " << output_file << std::endl;
    }

    // check that smoother is working:
    // the one free vertex must be at the origin
    if( !DEFAULT_INPUT.compare( input_file ) )
    {
        std::vector< Mesh::VertexHandle > vertices;
        mesh.get_all_vertices( vertices, err );
        if( err ) return 1;

        std::vector< bool > fixed_flags;
        mesh.vertices_get_fixed_flag( arrptr( vertices ), fixed_flags, vertices.size(), err );
        if( err ) return 1;

        // find one free vertex
        int idx = -1;
        for( unsigned i = 0; i < vertices.size(); ++i )
        {
            if( fixed_flags[i] == true ) continue;
            if( idx != -1 )
            {
                std::cerr << "Multiple free vertices in mesh." << std::endl;
                return 1;
            }
            idx = i;
        }

        if( idx == -1 )
        {
            std::cerr << "No free vertex in mesh!!!!!" << std::endl;
            return 1;
        }

        Mesh::VertexHandle vertex = vertices[idx];
        MsqVertex coords;
        mesh.vertices_get_coordinates( &vertex, &coords, 1, err );
        if( err ) return 1;

        // calculate distance from origin
        double dist = sqrt( coords[0] * coords[0] + coords[1] * coords[1] );
        if( dist > 1e-8 )
        {
            std::cerr << "Free vertex not at origin after Laplace smooth." << std::endl
                      << "Expected location: (0,0)" << std::endl
                      << "Actual location: (" << coords[0] << "," << coords[1] << ")" << std::endl;
            return 2;
        }
    }

    return 0;
}

Variable Documentation

std::string DEFAULT_INPUT = "unittest/mesquite/2D/vtk/quads/untangled/square_quad_2.vtk"

Definition at line 72 of file laplacian_test.cpp.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines