MOAB: Mesh Oriented datABase  (version 5.4.1)
untangle_test.cpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2004 Sandia Corporation and Argonne National
00005     Laboratory.  Under the terms of Contract DE-AC04-94AL85000
00006     with Sandia Corporation, the U.S. Government retains certain
00007     rights in 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     [email protected], [email protected], [email protected],
00024     [email protected], [email protected], [email protected]
00025 
00026   ***************************************************************** */
00027 // -*- Mode : c++; tab-width: 2; c-tab-always-indent: t; indent-tabs-mode: nil; c-basic-offset: 2
00028 // -*-
00029 //
00030 //   SUMMARY:
00031 //     USAGE:
00032 //
00033 // ORIG-DATE: 19-Feb-02 at 10:57:52
00034 //  LAST-MOD: 23-Jul-03 at 18:08:13 by Thomas Leurent
00035 //
00036 //
00037 // DESCRIPTION:
00038 // ============
00039 /*! \file main.cpp
00040 
00041 describe main.cpp here
00042 
00043  */
00044 // DESCRIP-END.
00045 //
00046 
00047 #include "MeshImpl.hpp"
00048 #include "MsqTimer.hpp"
00049 #include "Mesquite.hpp"
00050 #include "MsqError.hpp"
00051 #include "Vector3D.hpp"
00052 #include "InstructionQueue.hpp"
00053 #include "PatchData.hpp"
00054 #include "TerminationCriterion.hpp"
00055 #include "QualityAssessor.hpp"
00056 #include "TestUtil.hpp"
00057 
00058 // algorithms
00059 #include "Randomize.hpp"
00060 #include "ConditionNumberQualityMetric.hpp"
00061 #include "UntangleBetaQualityMetric.hpp"
00062 #include "LPtoPTemplate.hpp"
00063 #include "LInfTemplate.hpp"
00064 #include "SteepestDescent.hpp"
00065 #include "ConjugateGradient.hpp"
00066 #include "PlanarDomain.hpp"
00067 
00068 #include <iostream>
00069 using std::cout;
00070 using std::endl;
00071 #include <cstdlib>
00072 
00073 using namespace MBMesquite;
00074 
00075 std::string DEFAULT_MESH = TestDir + "unittest/mesquite/2D/vtk/quads/tangled/tangled_quad.vtk";
00076 
00077 const bool brief_output = true;
00078 const bool write_output = false;
00079 
00080 int main()
00081 {
00082     MBMesquite::MeshImpl mesh;
00083     MsqPrintError err( cout );
00084     mesh.read_vtk( DEFAULT_MESH.c_str(), err );
00085     if( err ) return 1;
00086 
00087     // Set Domain Constraint
00088     Vector3D pnt( 0, 0, 5 );
00089     Vector3D s_norm( 0, 0, 1 );
00090     PlanarDomain msq_geom( s_norm, pnt );
00091 
00092     // creates an intruction queue
00093     InstructionQueue queue1;
00094 
00095     // creates a mean ratio quality metric ...
00096     ConditionNumberQualityMetric shape_metric;
00097     UntangleBetaQualityMetric untangle( 2 );
00098     Randomize pass0( .05 );
00099     // ... and builds an objective function with it
00100     // LInfTemplate* obj_func = new LInfTemplate(shape_metric);
00101     LInfTemplate obj_func( &untangle );
00102     LPtoPTemplate obj_func2( &shape_metric, 2, err );
00103     if( err ) return 1;
00104     // creates the steepest descent optimization procedures
00105     ConjugateGradient pass1( &obj_func, err );
00106     if( err ) return 1;
00107 
00108     // SteepestDescent* pass2 = new SteepestDescent( obj_func2 );
00109     ConjugateGradient pass2( &obj_func2, err );
00110     if( err ) return 1;
00111     pass2.use_element_on_vertex_patch();
00112     if( err ) return 1;
00113     pass2.use_global_patch();
00114     if( err ) return 1;
00115     QualityAssessor stop_qa  = QualityAssessor( &shape_metric );
00116     QualityAssessor stop_qa2 = QualityAssessor( &shape_metric );
00117     if( brief_output )
00118     {
00119         stop_qa.disable_printing_results();
00120         stop_qa2.disable_printing_results();
00121     }
00122 
00123     stop_qa.add_quality_assessment( &untangle );
00124     // **************Set stopping criterion**************
00125     // untangle beta should be 0 when untangled
00126     TerminationCriterion sc1;
00127     sc1.add_relative_quality_improvement( 0.000001 );
00128     TerminationCriterion sc3;
00129     sc3.add_iteration_limit( 10 );
00130     TerminationCriterion sc_rand;
00131     sc_rand.add_iteration_limit( 1 );
00132 
00133     // StoppingCriterion sc1(&stop_qa,-1.0,.0000001);
00134     // StoppingCriterion sc3(&stop_qa2,.9,1.00000001);
00135     // StoppingCriterion sc2(StoppingCriterion::NUMBER_OF_PASSES,10);
00136     // StoppingCriterion sc_rand(StoppingCriterion::NUMBER_OF_PASSES,1);
00137     // either until untangled or 10 iterations
00138     pass0.set_outer_termination_criterion( &sc_rand );
00139     pass1.set_outer_termination_criterion( &sc1 );
00140     pass2.set_inner_termination_criterion( &sc3 );
00141 
00142     // adds 1 pass of pass1 to mesh_set1
00143     queue1.add_quality_assessor( &stop_qa, err );
00144     if( err ) return 1;
00145     // queue1.add_preconditioner(pass0,err);MSQ_CHKERR(err);
00146     // queue1.add_preconditioner(pass1,err);MSQ_CHKERR(err);
00147     // queue1.set_master_quality_improver(pass2, err); MSQ_CHKERR(err);
00148     queue1.set_master_quality_improver( &pass1, err );
00149     if( err ) return 1;
00150     queue1.add_quality_assessor( &stop_qa2, err );
00151     if( err ) return 1;
00152     if( write_output ) mesh.write_vtk( "original_mesh.vtk", err );
00153     if( err ) return 1;
00154 
00155     // launches optimization on mesh_set1
00156     MeshDomainAssoc mesh_and_domain = MeshDomainAssoc( &mesh, &msq_geom );
00157     queue1.run_instructions( &mesh_and_domain, err );
00158     if( err ) return 1;
00159 
00160     if( write_output ) mesh.write_vtk( "smoothed_mesh.vtk", err );
00161     if( err ) return 1;
00162 
00163     if( !brief_output ) print_timing_diagnostics( cout );
00164     return 0;
00165 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines