MOAB: Mesh Oriented datABase  (version 5.4.1)
randomize.cpp File Reference
#include "Randomize.hpp"
#include "InstructionQueue.hpp"
#include "QualityAssessor.hpp"
#include "MeshImpl.hpp"
#include "PatchData.hpp"
#include "MsqVertex.hpp"
#include "IdealWeightInverseMeanRatio.hpp"
#include "PMeanPTemplate.hpp"
#include "TerminationCriterion.hpp"
#include <cassert>
#include "domain.hpp"
#include <iostream>
#include <iomanip>
#include <memory>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
+ Include dependency graph for randomize.cpp:

Go to the source code of this file.

Classes

class  UnOptimizer

Functions

int main (int argc, char *argv[])

Variables

const char INVALID_FLAG = 'i'
const char PERCENT_FLAG = 'p'
const char UNOPTIMIZE_FLAG = 'u'

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 102 of file randomize.cpp.

References add_domain_args(), MBMesquite::TerminationCriterion::add_iteration_limit(), MBMesquite::InstructionQueue::add_preconditioner(), MBMesquite::InstructionQueue::add_quality_assessor(), CLArgs::add_required_arg(), args, CLArgs::double_flag(), MBMesquite::QualityAssessor::get_inverted_element_count(), input_file, CLArgs::int_flag(), INVALID_FLAG, mesh, CLArgs::parse_options(), PERCENT_FLAG, CLArgs::print_usage(), process_domain_args(), MBMesquite::MeshImpl::read_vtk(), MBMesquite::IQInterface::run_instructions(), CLArgs::ArgIBase::seen(), MBMesquite::InstructionQueue::set_master_quality_improver(), MBMesquite::QualityImprover::set_outer_termination_criterion(), CLArgs::toggle_flag(), UNOPTIMIZE_FLAG, CLArgs::ArgTemplate< T >::value(), CLArgs::IntRangeArg::value(), CLArgs::DoubleRangeArg::value(), and MBMesquite::MeshImpl::write_vtk().

{
    const double default_fraction = 0.05;
    const double zero             = 0.0;
    int one                       = 1;
    CLArgs::ToggleArg allow_invalid( false );
    CLArgs::DoubleRangeArg rand_percent( default_fraction, &zero, 0 );
    CLArgs::IntRangeArg unoptimize( 0, &one, 0 );

    CLArgs args( "vtkrandom", "Randomize mesh vertex locations.",
                 "Read VTK file, randomize locations of containded vertices, and re-write file." );
    args.toggle_flag( INVALID_FLAG, "Allow inverted elements in output", &allow_invalid );
    args.double_flag( PERCENT_FLAG, "fract", "Randomize fraction", &rand_percent );
    args.int_flag( UNOPTIMIZE_FLAG, "N", "Use UnOptimizer with N passes rather than Randomize", &unoptimize );
    add_domain_args( args );
    args.add_required_arg( "input_file" );
    args.add_required_arg( "output_file" );

    std::vector< std::string > files;
    if( !args.parse_options( argc, argv, files, std::cerr ) )
    {
        args.print_usage( std::cerr );
        exit( 1 );
    }
    std::string input_file  = files[0];
    std::string output_file = files[1];

    MsqError err;
    MeshImpl mesh;
    mesh.read_vtk( input_file.c_str(), err );
    if( err )
    {
        std::cerr << "ERROR READING FILE: " << input_file << std::endl << err << std::endl;
        return 2;
    }
    MeshDomain* domain = process_domain_args( &mesh );

    TerminationCriterion tc;
    QualityAssessor qa( false );
    InstructionQueue q;
    Randomize op( rand_percent.value() );
    IdealWeightInverseMeanRatio metric;
    PMeanPTemplate of( 1, &metric );
    UnOptimizer op2( &of );
    if( unoptimize.seen() )
    {
        tc.add_iteration_limit( unoptimize.value() );
        op2.set_outer_termination_criterion( &tc );
        q.add_preconditioner( &op, err );
        q.set_master_quality_improver( &op2, err );
    }
    else
    {
        q.set_master_quality_improver( &op, err );
    }
    q.add_quality_assessor( &qa, err );
    MeshDomainAssoc mesh_and_domain = MeshDomainAssoc( &mesh, domain );
    q.run_instructions( &mesh_and_domain, err );
    if( err )
    {
        std::cerr << err << std::endl;
        return 3;
    }

    int inverted, junk;
    if( qa.get_inverted_element_count( inverted, junk, err ) && inverted )
    {
        if( allow_invalid.value() )
            std::cerr << "Warning: output mesh contains " << inverted << " inverted elements" << std::endl;
        else
        {
            std::cerr << "Error: output mesh contains " << inverted << " inverted elements" << std::endl;
            return 4;
        }
    }

    mesh.write_vtk( output_file.c_str(), err );
    if( err )
    {
        std::cerr << "ERROR WRITING FILE: " << output_file << std::endl << err << std::endl;
        return 2;
    }

    return 0;
}

Variable Documentation

const char INVALID_FLAG = 'i'

Definition at line 25 of file randomize.cpp.

Referenced by main().

const char PERCENT_FLAG = 'p'

Definition at line 26 of file randomize.cpp.

Referenced by main().

const char UNOPTIMIZE_FLAG = 'u'

Definition at line 27 of file randomize.cpp.

Referenced by main().

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines