MOAB: Mesh Oriented datABase  (version 5.4.0)
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 + "unittest/mesquite/3D/vtk/hexes/untangled/large_box_hex_1000.vtk";
00079     double OF_value       = 0.;
00080 
00081     if( argc == 1 )
00082     {
00083         cerr << "Warning: No file specified, using default: " << file_name << endl;
00084     }
00085 
00086     if( argc > 1 )
00087     {
00088         file_name = argv[1];
00089     }
00090     if( argc > 2 )
00091     {
00092         char* end_ptr;
00093         OF_value = strtod( argv[2], &end_ptr );
00094         if( !*argv[2] || *end_ptr ) usage();
00095     }
00096     if( argc > 3 )
00097     {
00098         usage();
00099     }
00100 
00101     MBMesquite::MeshImpl mesh;
00102     mesh.read_vtk( file_name.c_str(), err );
00103     if( err ) return 1;
00104 
00105     // creates an intruction queue
00106     InstructionQueue queue1;
00107 
00108     // creates a mean ratio quality metric ...
00109     //   SmoothnessQualityMetric* mean_ratio = new EdgeLengthQualityMetric;
00110     IdealWeightInverseMeanRatio mean_ratio( err );
00111     if( err ) return 1;
00112     //  mean_ratio->set_gradient_type(QualityMetric::NUMERICAL_GRADIENT);
00113     //   mean_ratio->set_hessian_type(QualityMetric::NUMERICAL_HESSIAN);
00114     mean_ratio.set_averaging_method( QualityMetric::SUM );
00115 
00116     // ... and builds an objective function with it
00117     LPtoPTemplate obj_func( &mean_ratio, 1, err );
00118     if( err ) return 1;
00119 
00120     // creates the steepest descentfeas newt optimization procedures
00121     //  ConjugateGradient* pass1 = new ConjugateGradient( obj_func, err );
00122     FeasibleNewton pass1( &obj_func );
00123     pass1.use_global_patch();
00124     if( err ) return 1;
00125 
00126     QualityAssessor stop_qa = QualityAssessor( &mean_ratio );
00127 
00128     // **************Set stopping criterion****************
00129     TerminationCriterion tc_inner;
00130     if( OF_value != 0 )
00131     {
00132         tc_inner.add_absolute_quality_improvement( OF_value );
00133         pass1.set_inner_termination_criterion( &tc_inner );
00134     }
00135     TerminationCriterion tc_outer;
00136     tc_outer.add_iteration_limit( 1 );
00137     pass1.set_outer_termination_criterion( &tc_outer );
00138 
00139     queue1.add_quality_assessor( &stop_qa, err );
00140     if( err ) return 1;
00141 
00142     // adds 1 pass of pass1 to mesh_set1
00143     queue1.set_master_quality_improver( &pass1, err );
00144     if( err ) return 1;
00145 
00146     queue1.add_quality_assessor( &stop_qa, err );
00147     if( err ) return 1;
00148 
00149     // mesh.write_vtk("original_mesh",err); MSQ_CHKERR(err);
00150 
00151     // launches optimization on mesh_set1
00152     queue1.run_instructions( &mesh, err );
00153     if( err ) return 1;
00154 
00155     // mesh.write_vtk("smoothed_mesh", err); MSQ_CHKERR(err);
00156     print_timing_diagnostics( cout );
00157     return 0;
00158 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines