MOAB: Mesh Oriented datABase  (version 5.2.1)
nongradient_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 /** \file main.cpp
00029  * \brief test NonGradient Solver (barrier and non-barrier).
00030  * \author Boyd Tidwell
00031  */
00032 #include "Mesquite.hpp"
00033 #include "MeshImpl.hpp"
00034 #include "MsqError.hpp"
00035 #include "InstructionQueue.hpp"
00036 #include "TerminationCriterion.hpp"
00037 #include "QualityAssessor.hpp"
00038 #include "PlanarDomain.hpp"
00039 #include "XYPlanarDomain.hpp"
00040 #include "MeshInterface.hpp"
00041 
00042 #include "TShapeNB1.hpp"
00043 #include "TShapeB1.hpp"
00044 #include "TQualityMetric.hpp"
00045 #include "IdealShapeTarget.hpp"
00046 #include "MaxTemplate.hpp"
00047 #include "PMeanPTemplate.hpp"
00048 #include "ElementMaxQM.hpp"
00049 #include "ElementAvgQM.hpp"
00050 #include "ElementPMeanP.hpp"
00051 #include "ElemSampleQM.hpp"
00052 #include "TargetCalculator.hpp"
00053 #include "PMeanPTemplate.hpp"
00054 #include "LPtoPTemplate.hpp"
00055 #include "ElementPMeanP.hpp"
00056 #include "NonGradient.hpp"
00057 #include "TestUtil.hpp"
00058 
00059 using namespace MBMesquite;
00060 
00061 int main()
00062 {
00063     MsqPrintError err( std::cout );
00064     PlanarDomain xyPlane( PlanarDomain::XY, -5 );
00065 
00066 #define FILE_NAME1 "bad_circle_tri.vtk"
00067 #define FILE_NAME2 "tangled_tri.vtk"
00068     std::string file_name1 = TestDir + "/2D/vtk/tris/untangled/" FILE_NAME1;
00069     std::string file_name2 = TestDir + "/2D/vtk/tris/tangled/" FILE_NAME2;
00070 
00071     // Barrier / Max Objective Function Test
00072 
00073     MBMesquite::MeshImpl mesh_max;
00074     mesh_max.read_vtk( file_name1.c_str(), err );
00075     if( err )
00076     {
00077         std::cerr << "NonGradient Barrier test: failed to read file." << std::endl;
00078         return 1;
00079     }
00080 
00081     IdealShapeTarget target_max;
00082 
00083     TShapeB1 mu;
00084     TQualityMetric tqMetric_max( &target_max, &mu );
00085     ElemSampleQM* sampleMetric( &tqMetric_max );
00086     ElementMaxQM maxMetric( &tqMetric_max );
00087     ElementPMeanP meanpMetric( 1.0, sampleMetric );
00088 
00089     MaxTemplate maxObjFunction( &maxMetric );  // max(max)
00090     NonGradient max_opt( &maxObjFunction );    // optimization procedure
00091 
00092     PMeanPTemplate pmeanpObjFunction( 1.0, sampleMetric );
00093     NonGradient pmeanp_opt( &pmeanpObjFunction );
00094 
00095     LPtoPTemplate PtoPObjMaxfunction( &maxMetric, (short int)1.0, err );  // max(max)
00096 
00097     // Processing for Max Objective Function
00098 
00099     max_opt.setSimplexDiameterScale( 0 );
00100     max_opt.use_element_on_vertex_patch();  // local patch
00101     max_opt.set_debugging_level( 0 );
00102 
00103     // Construct and register the Quality Assessor instances
00104     QualityAssessor max_initial_qa        = QualityAssessor( &maxMetric, 10 );
00105     QualityAssessor maxObj_max_optimal_qa = QualityAssessor( &maxMetric, 10 );
00106 
00107     //**************Set stopping criterion****************
00108     TerminationCriterion innerTC, outerTC;
00109 
00110     outerTC.add_iteration_limit( 40 );
00111     innerTC.add_iteration_limit( 20 );
00112     max_opt.set_outer_termination_criterion( &outerTC );
00113     max_opt.set_inner_termination_criterion( &innerTC );
00114 
00115     // test for barrier violation
00116     PlanarDomain xyPlane2( PlanarDomain::XY, 5 );
00117     MBMesquite::MeshImpl mesh_bv;
00118     mesh_bv.read_vtk( file_name2.c_str(), err );
00119     if( err )
00120     {
00121         std::cerr << "NonGradient Barrier Violation test: failed to read file." << std::endl;
00122         return 1;
00123     }
00124 
00125     InstructionQueue queue1;
00126     queue1.add_quality_assessor( &max_initial_qa, err );
00127     if( err ) return 1;
00128 
00129     queue1.set_master_quality_improver( &max_opt, err );  // max
00130     if( err ) return 1;
00131 
00132     queue1.add_quality_assessor( &maxObj_max_optimal_qa, err );
00133     if( err ) return 1;
00134 
00135     MBMesquite::MeshDomainAssoc mesh_and_domain = MeshDomainAssoc( &mesh_max, &xyPlane );
00136     queue1.run_instructions( &mesh_and_domain, err );
00137     if( err ) return 1;
00138 
00139     // Non-Barrier / Ave Objective Function Test
00140 
00141     MBMesquite::MeshImpl mesh_mean;
00142     mesh_mean.read_vtk( file_name1.c_str(), err );
00143     if( err )
00144     {
00145         std::cerr << "NonGradient Non-barrier test: failed to read file." << std::endl;
00146         return 1;
00147     }
00148 
00149     TShapeNB1 nonBarrier;
00150     TargetCalculator* target;
00151     IdealShapeTarget ident_target;
00152 
00153     target = &ident_target;
00154 
00155     TQualityMetric tqMetric( target, &nonBarrier );
00156 
00157     ElementPMeanP mean_metric( 1.0, &tqMetric );
00158     PMeanPTemplate meanObjfunction( 1.0, &mean_metric );  // ave(ave)
00159 
00160     // Processing for Mean Objective Function
00161     NonGradient mean_opt( &meanObjfunction );   // optimization procedure
00162     mean_opt.setExactPenaltyFunction( false );  // allow infeasible
00163     mean_opt.use_element_on_vertex_patch();     // local patch
00164 
00165     // Set Termination Criteria
00166     TerminationCriterion innerTC_mean, outerTC_mean;
00167     outerTC_mean.add_iteration_limit( 10 );
00168     innerTC_mean.add_iteration_limit( 30 );
00169     mean_opt.set_outer_termination_criterion( &outerTC_mean );
00170     mean_opt.set_inner_termination_criterion( &innerTC_mean );
00171     mean_opt.set_debugging_level( 0 );
00172 
00173     // Construct and register the meanObj Quality Assessor instance
00174     QualityAssessor mean_qa = QualityAssessor( &mean_metric, 10 );
00175 
00176     InstructionQueue queue2;
00177     queue2.add_quality_assessor( &mean_qa, err );
00178     if( err ) return 1;
00179     queue2.set_master_quality_improver( &mean_opt, err );
00180     if( err ) return 1;
00181     queue2.add_quality_assessor( &mean_qa, err );
00182     if( err ) return 1;
00183 
00184     queue2.run_instructions( &mesh_and_domain, err );
00185     if( err ) return 1;
00186 
00187     // Test barrier target metric using objective function MaxTemplate with inverted mesh
00188     InstructionQueue queue3;
00189     queue3.add_quality_assessor( &max_initial_qa, err );
00190     if( err ) return 1;
00191     queue3.set_master_quality_improver( &max_opt, err );
00192     if( err ) return 1;
00193     MBMesquite::MeshDomainAssoc mesh_and_domain2 = MeshDomainAssoc( &mesh_bv, &xyPlane2 );
00194     queue3.run_instructions( &mesh_and_domain2, err );
00195     if( err.error_code() == err.BARRIER_VIOLATED )
00196     {
00197         std::cerr << std::endl << "MaxTemplate OF with inverted mesh test passed" << std::endl;
00198         err.clear();
00199     }
00200     else
00201         return 1;
00202 
00203     // Test barrier target metric using objective function PMeanPTemplate with inverted mesh
00204     InstructionQueue queue4;
00205     queue4.set_master_quality_improver( &pmeanp_opt, err );
00206     if( err ) return 1;
00207     queue4.run_instructions( &mesh_and_domain2, err );
00208     if( err.error_code() == err.BARRIER_VIOLATED )
00209     {
00210         std::cerr << std::endl << "PMeanPTemplate OF with inverted mesh test passed" << std::endl << std::endl;
00211         err.clear();
00212     }
00213     else
00214         return 1;
00215 
00216     return 0;
00217 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines