MOAB: Mesh Oriented datABase
(version 5.4.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 [email protected], [email protected], [email protected], 00024 [email protected], [email protected], [email protected] 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&, 00064 double cpu_time, 00065 double grad_norm, 00066 int parallel_iterations ) 00067 : maxTime( cpu_time ), gradNorm( grad_norm ), untBeta( DEF_UNT_BETA ), successiveEps( DEF_SUC_EPS ), 00068 parallelIterations( parallel_iterations ) 00069 { 00070 } 00071 00072 ShapeImprovementWrapper::ShapeImprovementWrapper( double cpu_time, double grad_norm, int parallel_iterations ) 00073 : maxTime( cpu_time ), gradNorm( grad_norm ), untBeta( DEF_UNT_BETA ), successiveEps( DEF_SUC_EPS ), 00074 parallelIterations( parallel_iterations ) 00075 { 00076 } 00077 00078 void ShapeImprovementWrapper::run_wrapper( MeshDomainAssoc* mesh_and_domain, 00079 ParallelMesh* pmesh, 00080 Settings* settings, 00081 QualityAssessor* qa, 00082 MsqError& err ) 00083 { 00084 // Define an untangler 00085 UntangleBetaQualityMetric untangle_metric( untBeta ); 00086 LPtoPTemplate untangle_func( 2, &untangle_metric ); 00087 ConjugateGradient untangle_global( &untangle_func ); 00088 TerminationCriterion untangle_inner, untangle_outer; 00089 untangle_global.use_global_patch(); 00090 untangle_inner.add_absolute_quality_improvement( 0.0 ); 00091 untangle_inner.add_absolute_successive_improvement( successiveEps ); 00092 untangle_outer.add_iteration_limit( 1 ); 00093 untangle_global.set_inner_termination_criterion( &untangle_inner ); 00094 untangle_global.set_outer_termination_criterion( &untangle_outer ); 00095 00096 // define shape improver 00097 IdealWeightInverseMeanRatio inverse_mean_ratio; 00098 inverse_mean_ratio.set_averaging_method( QualityMetric::LINEAR ); 00099 LPtoPTemplate obj_func( 2, &inverse_mean_ratio ); 00100 FeasibleNewton feas_newt( &obj_func ); 00101 TerminationCriterion term_inner, term_outer; 00102 feas_newt.use_global_patch(); 00103 qa->add_quality_assessment( &inverse_mean_ratio ); 00104 term_inner.add_absolute_gradient_L2_norm( gradNorm ); 00105 term_inner.add_relative_successive_improvement( successiveEps ); 00106 term_outer.add_iteration_limit( pmesh ? parallelIterations : 1 ); 00107 feas_newt.set_inner_termination_criterion( &term_inner ); 00108 feas_newt.set_outer_termination_criterion( &term_outer ); 00109 00110 // Apply CPU time limit to untangler 00111 if( maxTime > 0.0 ) untangle_inner.add_cpu_time( maxTime ); 00112 00113 // Run untangler 00114 InstructionQueue q1; 00115 Timer totalTimer; 00116 q1.set_master_quality_improver( &untangle_global, err );MSQ_ERRRTN( err ); 00117 q1.add_quality_assessor( qa, err );MSQ_ERRRTN( err ); 00118 q1.run_common( mesh_and_domain, pmesh, settings, err );MSQ_ERRRTN( err ); 00119 00120 // If limited by CPU time, limit next step to remaning time 00121 if( maxTime > 0.0 ) 00122 { 00123 double remaining = maxTime - totalTimer.since_birth(); 00124 if( remaining <= 0.0 ) 00125 { 00126 MSQ_DBGOUT( 2 ) << "Optimization is terminating without perfoming shape improvement." << std::endl; 00127 remaining = 0.0; 00128 } 00129 term_inner.add_cpu_time( remaining ); 00130 } 00131 00132 // Run shape improver 00133 InstructionQueue q2; 00134 q2.set_master_quality_improver( &feas_newt, err );MSQ_ERRRTN( err ); 00135 q2.add_quality_assessor( qa, err );MSQ_ERRRTN( err ); 00136 q2.run_common( mesh_and_domain, pmesh, settings, err );MSQ_ERRRTN( err ); 00137 } 00138 00139 } // namespace MBMesquite