MOAB: Mesh Oriented datABase  (version 5.4.1)
shape_improver.cpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2009 Sandia National Laboratories.  Developed at the
00005     University of Wisconsin--Madison under SNL contract number
00006     624796.  The U.S. Government and the University of Wisconsin
00007     retain certain rights to this software.
00008 
00009     This library is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU Lesser General Public
00011     License as published by the Free Software Foundation; either
00012     version 2.1 of the License, or (at your option) any later version.
00013 
00014     This library is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017     Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     (lgpl.txt) along with this library; if not, write to the Free Software
00021     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00023     (2009) [email protected]
00024 
00025   ***************************************************************** */
00026 
00027 /** \file main.cpp
00028  *  \brief
00029  *  \author Jason Kraftcheck
00030  */
00031 
00032 #include "TestUtil.hpp"
00033 #ifdef TEST_OLD_WRAPPER
00034 #include "ShapeImprovementWrapper.hpp"
00035 #else
00036 #include "ShapeImprover.hpp"
00037 #endif
00038 #include "QualityAssessor.hpp"
00039 #include "MeshImpl.hpp"
00040 #include "MsqError.hpp"
00041 #include "PlanarDomain.hpp"
00042 #include "IdealWeightInverseMeanRatio.hpp"
00043 
00044 #include <iostream>
00045 #include <cstdlib>
00046 #include <cstring>
00047 
00048 using namespace MBMesquite;
00049 
00050 std::string DEFAULT_INPUT = TestDir + "unittest/mesquite/2D/vtk/quads/tangled/inverted-hole-1.vtk";
00051 
00052 void usage( const char* argv0, bool help = false )
00053 {
00054     std::ostream& str = help ? std::cout : std::cerr;
00055     str << "Usage: " << argv0 << "[input_file] [output_file]" << std::endl;
00056     str << "Usage: " << argv0 << "-h" << std::endl;
00057     if( help )
00058     {
00059         str << "Default input file: " << DEFAULT_INPUT << std::endl
00060             << "Default output file: (none)" << std::endl
00061             << "Input meshes are expected to lie in the XY-plane" << std::endl
00062             << "Input meshes are expected to be smoothable to ideal elements" << std::endl;
00063     }
00064     exit( !help );
00065 }
00066 
00067 int main( int argc, char* argv[] )
00068 {
00069     const char* input_file  = 0;
00070     const char* output_file = 0;
00071     for( int i = 1; i < argc; ++i )
00072     {
00073         if( !strcmp( "-h", argv[i] ) )
00074             usage( argv[0], true );
00075         else if( !input_file )
00076             input_file = argv[i];
00077         else if( !output_file )
00078             output_file = argv[i];
00079         else
00080             usage( argv[0] );
00081     }
00082     if( !input_file ) input_file = DEFAULT_INPUT.c_str();
00083 
00084     MsqError err;
00085     MeshImpl mesh;
00086     mesh.read_vtk( input_file, err );
00087     if( err )
00088     {
00089         std::cerr << err << std::endl << input_file << ": failed to read file" << std::endl;
00090         return 3;
00091     }
00092 
00093     PlanarDomain plane( PlanarDomain::XY );
00094 #ifdef TEST_OLD_WRAPPER
00095     ShapeImprovementWrapper smoother;
00096 #else
00097     ShapeImprover smoother;
00098 #endif
00099     IdealWeightInverseMeanRatio extra_metric;
00100     smoother.quality_assessor().add_quality_assessment( &extra_metric );
00101     MeshDomainAssoc mesh_and_domain = MeshDomainAssoc( &mesh, &plane );
00102     smoother.run_instructions( &mesh_and_domain, err );
00103     if( err )
00104     {
00105         std::cerr << err << std::endl << input_file << ": smoother failed" << std::endl;
00106         return 2;
00107     }
00108 
00109     if( output_file )
00110     {
00111         mesh.write_vtk( output_file, err );
00112         if( err )
00113         {
00114             std::cerr << err << std::endl << output_file << ": failed to write file" << std::endl;
00115             return 3;
00116         }
00117     }
00118 
00119     if( smoother.quality_assessor().invalid_elements() )
00120     {
00121         std::cerr << "Resulting mesh contains invalid elements: untangler did not succeed" << std::endl;
00122         return 4;
00123     }
00124 
00125     const QualityAssessor::Assessor* quality = smoother.quality_assessor().get_results( &extra_metric );
00126     if( !quality )
00127     {
00128         std::cerr << "Failed to get quality stats for IMR metric" << std::endl;
00129         return 2;
00130     }
00131 
00132     if( fabs( 1 - quality->get_average() ) > 1e-3 )
00133     {
00134         std::cerr << "Average quality is not optimal." << std::endl;
00135         return 4;
00136     }
00137 
00138     if( quality->get_stddev() > 1e-3 )
00139     {
00140         std::cerr << "Not all elements have optimal quality." << std::endl;
00141         return 4;
00142     }
00143 
00144     return 0;
00145 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines