MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 /* ***************************************************************** 00002 MESQUITE -- The Mesh Quality Improvement Toolkit 00003 00004 Copyright 2006 Sandia National Laboratories. Developed at the 00005 University of Wisconsin--Madison under SNL contract number 00006 624796. The U.S. Government and the University of Wisconsin 00007 retain certain rights to 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 ***************************************************************** */ 00024 00025 /** \file ElementAvgQM.cpp 00026 * \brief 00027 * \author Boyd Tidwell 00028 */ 00029 00030 #include "Mesquite.hpp" 00031 #include "ElementAvgQM.hpp" 00032 #include "ElemSampleQM.hpp" 00033 #include "MsqError.hpp" 00034 #include "PatchData.hpp" 00035 #include <limits> 00036 00037 namespace MBMesquite 00038 { 00039 00040 ElementAvgQM::ElementAvgQM( ElemSampleQM* metric ) : mMetric( metric ) {} 00041 00042 ElementAvgQM::~ElementAvgQM() {} 00043 00044 std::string ElementAvgQM::get_name() const 00045 { 00046 std::string result( "ElementAvgQM(" ); 00047 result += mMetric->get_name(); 00048 result += ")"; 00049 return result; 00050 } 00051 00052 int ElementAvgQM::get_negate_flag() const 00053 { 00054 return get_quality_metric()->get_negate_flag(); 00055 } 00056 00057 bool ElementAvgQM::evaluate( PatchData& pd, size_t handle, double& value, MsqError& err ) 00058 { 00059 ElemSampleQM* qm = get_quality_metric(); 00060 mHandles.clear(); 00061 qm->get_element_evaluations( pd, handle, mHandles, err ); 00062 MSQ_ERRFALSE( err ); 00063 00064 bool valid = true; 00065 double tmpval; 00066 double accumulate = 0.0; 00067 int num_values = 0; 00068 bool tmpvalid; 00069 00070 value = -std::numeric_limits< double >::infinity(); 00071 for( std::vector< size_t >::iterator h = mHandles.begin(); h != mHandles.end(); ++h ) 00072 { 00073 tmpvalid = qm->evaluate( pd, *h, tmpval, err ); 00074 MSQ_ERRZERO( err ); 00075 if( !tmpvalid ) 00076 { 00077 valid = false; 00078 break; 00079 } 00080 else 00081 { 00082 accumulate += tmpval; 00083 num_values++; 00084 } 00085 } 00086 if( valid ) value = accumulate / num_values; 00087 00088 return valid; 00089 } 00090 00091 } // namespace MBMesquite