MOAB: Mesh Oriented datABase
(version 5.2.1)
|
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 // -*- Mode : c++; tab-width: 3; c-tab-always-indent: t; indent-tabs-mode: nil; c-basic-offset: 3 00028 // -*- 00029 00030 /*! \file ShapeImprovementWrapper.cpp 00031 00032 Member functions of the MBMesquite::ShapeImprovementWrapper class 00033 00034 \author Michael Brewer 00035 \date June 6, 2003 00036 */ 00037 00038 #include "InstructionQueue.hpp" 00039 #include "ShapeImprovementWrapper.hpp" 00040 #include "MsqTimer.hpp" 00041 #include "MsqDebug.hpp" 00042 #include "UntangleBetaQualityMetric.hpp" 00043 #include "LPtoPTemplate.hpp" 00044 #include "ConjugateGradient.hpp" 00045 #include "TerminationCriterion.hpp" 00046 #include "IdealWeightInverseMeanRatio.hpp" 00047 #include "FeasibleNewton.hpp" 00048 #include "InstructionQueue.hpp" 00049 #include "QualityAssessor.hpp" 00050 00051 namespace MBMesquite 00052 { 00053 00054 const double DEF_UNT_BETA = 1e-8; 00055 const double DEF_SUC_EPS = 1e-4; 00056 00057 /*! The consturctor allows for two values. The first is a 00058 time bound (in seconds) used as a termination criterion. If 00059 this value is non-positive, no time bound will be set. 00060 By default, the value is set to zero and no time bound 00061 is used. The second value is the tolerance for the gradient 00062 norm termination criteria. The default value is 1.e-6.*/ 00063 ShapeImprovementWrapper::ShapeImprovementWrapper( MsqError&, double cpu_time, double grad_norm, 00064 int parallel_iterations ) 00065 : maxTime( cpu_time ), gradNorm( grad_norm ), untBeta( DEF_UNT_BETA ), successiveEps( DEF_SUC_EPS ), 00066 parallelIterations( parallel_iterations ) 00067 { 00068 } 00069 00070 ShapeImprovementWrapper::ShapeImprovementWrapper( double cpu_time, double grad_norm, int parallel_iterations ) 00071 : maxTime( cpu_time ), gradNorm( grad_norm ), untBeta( DEF_UNT_BETA ), successiveEps( DEF_SUC_EPS ), 00072 parallelIterations( parallel_iterations ) 00073 { 00074 } 00075 00076 void ShapeImprovementWrapper::run_wrapper( MeshDomainAssoc* mesh_and_domain, ParallelMesh* pmesh, Settings* settings, 00077 QualityAssessor* qa, MsqError& err ) 00078 { 00079 // Define an untangler 00080 UntangleBetaQualityMetric untangle_metric( untBeta ); 00081 LPtoPTemplate untangle_func( 2, &untangle_metric ); 00082 ConjugateGradient untangle_global( &untangle_func ); 00083 TerminationCriterion untangle_inner, untangle_outer; 00084 untangle_global.use_global_patch(); 00085 untangle_inner.add_absolute_quality_improvement( 0.0 ); 00086 untangle_inner.add_absolute_successive_improvement( successiveEps ); 00087 untangle_outer.add_iteration_limit( 1 ); 00088 untangle_global.set_inner_termination_criterion( &untangle_inner ); 00089 untangle_global.set_outer_termination_criterion( &untangle_outer ); 00090 00091 // define shape improver 00092 IdealWeightInverseMeanRatio inverse_mean_ratio; 00093 inverse_mean_ratio.set_averaging_method( QualityMetric::LINEAR ); 00094 LPtoPTemplate obj_func( 2, &inverse_mean_ratio ); 00095 FeasibleNewton feas_newt( &obj_func ); 00096 TerminationCriterion term_inner, term_outer; 00097 feas_newt.use_global_patch(); 00098 qa->add_quality_assessment( &inverse_mean_ratio ); 00099 term_inner.add_absolute_gradient_L2_norm( gradNorm ); 00100 term_inner.add_relative_successive_improvement( successiveEps ); 00101 term_outer.add_iteration_limit( pmesh ? parallelIterations : 1 ); 00102 feas_newt.set_inner_termination_criterion( &term_inner ); 00103 feas_newt.set_outer_termination_criterion( &term_outer ); 00104 00105 // Apply CPU time limit to untangler 00106 if( maxTime > 0.0 ) untangle_inner.add_cpu_time( maxTime ); 00107 00108 // Run untangler 00109 InstructionQueue q1; 00110 Timer totalTimer; 00111 q1.set_master_quality_improver( &untangle_global, err );MSQ_ERRRTN( err ); 00112 q1.add_quality_assessor( qa, err );MSQ_ERRRTN( err ); 00113 q1.run_common( mesh_and_domain, pmesh, settings, err );MSQ_ERRRTN( err ); 00114 00115 // If limited by CPU time, limit next step to remaning time 00116 if( maxTime > 0.0 ) 00117 { 00118 double remaining = maxTime - totalTimer.since_birth(); 00119 if( remaining <= 0.0 ) 00120 { 00121 MSQ_DBGOUT( 2 ) << "Optimization is terminating without perfoming shape improvement." << std::endl; 00122 remaining = 0.0; 00123 } 00124 term_inner.add_cpu_time( remaining ); 00125 } 00126 00127 // Run shape improver 00128 InstructionQueue q2; 00129 q2.set_master_quality_improver( &feas_newt, err );MSQ_ERRRTN( err ); 00130 q2.add_quality_assessor( qa, err );MSQ_ERRRTN( err ); 00131 q2.run_common( mesh_and_domain, pmesh, settings, err );MSQ_ERRRTN( err ); 00132 } 00133 00134 } // namespace MBMesquite