MOAB: Mesh Oriented datABase  (version 5.2.1)
feasible_newton_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     diachin2@llnl.gov, djmelan@sandia.gov, mbrewer@sandia.gov,
00024     pknupp@sandia.gov, tleurent@mcs.anl.gov, tmunson@mcs.anl.gov
00025 
00026   ***************************************************************** */
00027 //
00028 //   SUMMARY:
00029 //     USAGE:
00030 //
00031 // ORIG-DATE: 19-Feb-02 at 10:57:52
00032 //  LAST-MOD: 18-Oct-04 by J.Kraftcheck
00033 //
00034 //
00035 // DESCRIPTION:
00036 // ============
00037 /*! \file main.cpp
00038 
00039 describe main.cpp here
00040 
00041  */
00042 // DESCRIP-END.
00043 //
00044 
00045 #include <iostream>
00046 using std::cerr;
00047 using std::cout;
00048 using std::endl;
00049 #include <cstdlib>
00050 
00051 #include "Mesquite.hpp"
00052 #include "MeshImpl.hpp"
00053 #include "MsqError.hpp"
00054 #include "InstructionQueue.hpp"
00055 #include "TerminationCriterion.hpp"
00056 #include "QualityAssessor.hpp"
00057 
00058 // algorithms
00059 #include "IdealWeightInverseMeanRatio.hpp"
00060 #include "EdgeLengthQualityMetric.hpp"
00061 #include "LPtoPTemplate.hpp"
00062 #include "FeasibleNewton.hpp"
00063 #include "ConjugateGradient.hpp"
00064 #include "TestUtil.hpp"
00065 
00066 using namespace MBMesquite;
00067 
00068 void usage()
00069 {
00070     cerr << "Usage: main [filename] [objective function val]" << endl;
00071     exit( 1 );
00072 }
00073 
00074 int main( int argc, char* argv[] )
00075 {
00076     MBMesquite::MsqPrintError err( cout );
00077 
00078     std::string file_name = TestDir + "/3D/vtk/hexes/untangled/large_box_hex_1000.vtk";
00079     double OF_value       = 0.;
00080 
00081     if( argc == 1 ) { cerr << "Warning: No file specified, using default: " << file_name << endl; }
00082 
00083     if( argc > 1 ) { file_name = argv[1]; }
00084     if( argc > 2 )
00085     {
00086         char* end_ptr;
00087         OF_value = strtod( argv[2], &end_ptr );
00088         if( !*argv[2] || *end_ptr ) usage();
00089     }
00090     if( argc > 3 ) { usage(); }
00091 
00092     MBMesquite::MeshImpl mesh;
00093     mesh.read_vtk( file_name.c_str(), err );
00094     if( err ) return 1;
00095 
00096     // creates an intruction queue
00097     InstructionQueue queue1;
00098 
00099     // creates a mean ratio quality metric ...
00100     //   SmoothnessQualityMetric* mean_ratio = new EdgeLengthQualityMetric;
00101     IdealWeightInverseMeanRatio mean_ratio( err );
00102     if( err ) return 1;
00103     //  mean_ratio->set_gradient_type(QualityMetric::NUMERICAL_GRADIENT);
00104     //   mean_ratio->set_hessian_type(QualityMetric::NUMERICAL_HESSIAN);
00105     mean_ratio.set_averaging_method( QualityMetric::SUM );
00106 
00107     // ... and builds an objective function with it
00108     LPtoPTemplate obj_func( &mean_ratio, 1, err );
00109     if( err ) return 1;
00110 
00111     // creates the steepest descentfeas newt optimization procedures
00112     //  ConjugateGradient* pass1 = new ConjugateGradient( obj_func, err );
00113     FeasibleNewton pass1( &obj_func );
00114     pass1.use_global_patch();
00115     if( err ) return 1;
00116 
00117     QualityAssessor stop_qa = QualityAssessor( &mean_ratio );
00118 
00119     // **************Set stopping criterion****************
00120     TerminationCriterion tc_inner;
00121     if( OF_value != 0 )
00122     {
00123         tc_inner.add_absolute_quality_improvement( OF_value );
00124         pass1.set_inner_termination_criterion( &tc_inner );
00125     }
00126     TerminationCriterion tc_outer;
00127     tc_outer.add_iteration_limit( 1 );
00128     pass1.set_outer_termination_criterion( &tc_outer );
00129 
00130     queue1.add_quality_assessor( &stop_qa, err );
00131     if( err ) return 1;
00132 
00133     // adds 1 pass of pass1 to mesh_set1
00134     queue1.set_master_quality_improver( &pass1, err );
00135     if( err ) return 1;
00136 
00137     queue1.add_quality_assessor( &stop_qa, err );
00138     if( err ) return 1;
00139 
00140     // mesh.write_vtk("original_mesh",err); MSQ_CHKERR(err);
00141 
00142     // launches optimization on mesh_set1
00143     queue1.run_instructions( &mesh, err );
00144     if( err ) return 1;
00145 
00146     // mesh.write_vtk("smoothed_mesh", err); MSQ_CHKERR(err);
00147     print_timing_diagnostics( cout );
00148     return 0;
00149 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines