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 /*! 00028 \file LInfTemplate.cpp 00029 \brief 00030 00031 This Objective Function is evaluated using an L-infinity norm. 00032 total=max (abs(x)) 00033 \author Michael Brewer 00034 \date 2002-07-3 00035 */ 00036 #include <cmath> 00037 #include "LInfTemplate.hpp" 00038 #include "QualityMetric.hpp" 00039 #include "MsqError.hpp" 00040 00041 namespace MBMesquite 00042 { 00043 00044 LInfTemplate::LInfTemplate( QualityMetric* qualitymetric ) : ObjectiveFunctionTemplate( qualitymetric ) {} 00045 00046 // Michael: need to clean up here 00047 LInfTemplate::~LInfTemplate() {} 00048 00049 ObjectiveFunction* LInfTemplate::clone() const 00050 { 00051 return new LInfTemplate( get_quality_metric() ); 00052 } 00053 00054 void LInfTemplate::clear() {} 00055 00056 bool LInfTemplate::evaluate( EvalType type, PatchData& pd, double& value_out, bool free, MsqError& err ) 00057 { 00058 if( type != ObjectiveFunction::CALCULATE ) 00059 { 00060 MSQ_SETERR( err ) 00061 ( "LInfTemplate does not support block coodinate descent algoritms", MsqError::INVALID_STATE ); 00062 return false; 00063 } 00064 00065 QualityMetric* qm = get_quality_metric(); 00066 qm->get_evaluations( pd, qmHandles, free, err ); 00067 MSQ_ERRFALSE( err ); 00068 const double negate = qm->get_negate_flag(); 00069 00070 // calculate OF value for just the patch 00071 std::vector< size_t >::const_iterator i; 00072 double value; 00073 value_out = -HUGE_VAL; 00074 for( i = qmHandles.begin(); i != qmHandles.end(); ++i ) 00075 { 00076 bool result = qm->evaluate( pd, *i, value, err ); 00077 if( MSQ_CHKERR( err ) || !result ) return false; 00078 00079 value = negate * fabs( value ); 00080 if( value > value_out ) value_out = value; 00081 } 00082 00083 return true; 00084 } 00085 00086 } // namespace MBMesquite