MOAB: Mesh Oriented datABase  (version 5.3.1)
EdgeLengthRangeQualityMetric.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 /*! \file EdgeLengthRangeQualityMetric.cpp
00028   \author Michael Brewer
00029   \date 2002-05-14
00030   Evaluates the lengths of the edges attached to the given vertex.
00031   By default, the averaging method is set to SUM.
00032 */
00033 
00034 #include "EdgeLengthRangeQualityMetric.hpp"
00035 #include "Vector3D.hpp"
00036 #include "QualityMetric.hpp"
00037 #include "MsqVertex.hpp"
00038 #include "PatchData.hpp"
00039 #include "MsqDebug.hpp"
00040 #include "MsqError.hpp"
00041 
00042 #include <vector>
00043 using std::vector;
00044 
00045 using namespace MBMesquite;
00046 
00047 EdgeLengthRangeQualityMetric::EdgeLengthRangeQualityMetric( double low_a, double high_a )
00048     : AveragingQM( SUM ), highVal( high_a ), lowVal( low_a )
00049 {
00050     if( lowVal > highVal ) std::swap( lowVal, highVal );
00051 }
00052 
00053 EdgeLengthRangeQualityMetric::~EdgeLengthRangeQualityMetric() {}
00054 
00055 std::string EdgeLengthRangeQualityMetric::get_name() const
00056 {
00057     return "Edge Length Range Metric";
00058 }
00059 
00060 int EdgeLengthRangeQualityMetric::get_negate_flag() const
00061 {
00062     return 1;
00063 }
00064 
00065 /*!For the given vertex, vert, with connected edges of lengths l_j for
00066   j=1...k, the metric value is the average (where the default average
00067   type is SUM) of
00068         u_j = ( | l_j - lowVal | - (l_j - lowVal) )^2 +
00069               ( | highVal - l_j | - (highVal - l_j) )^2.
00070 */
00071 bool EdgeLengthRangeQualityMetric::evaluate_common( PatchData& pd, size_t this_vert, double& fval,
00072                                                     std::vector< size_t >& adj_verts, MsqError& err )
00073 {
00074     fval = 0.0;
00075     Vector3D edg;
00076     pd.get_adjacent_vertex_indices( this_vert, adj_verts, err );
00077     MSQ_ERRZERO( err );
00078     int num_sample_points  = adj_verts.size();
00079     double* metric_values  = new double[num_sample_points];
00080     const MsqVertex* verts = pd.get_vertex_array( err );
00081     MSQ_ERRZERO( err );
00082     // store the length of the edge, and the first and second component of
00083     // metric values, respectively.
00084     double temp_length = 0.0;
00085     double temp_first  = 0.0;
00086     double temp_second = 0.0;
00087     // PRINT_INFO("INSIDE ELR, vertex =
00088     // %f,%f,%f\n",verts[this_vert][0],verts[this_vert][1],verts[this_vert][2]); loop while there are
00089     // still more adjacent vertices.
00090     for( unsigned i = 0; i < adj_verts.size(); ++i )
00091     {
00092         edg = verts[this_vert] - verts[adj_verts[i]];
00093         // compute the edge length
00094         temp_length = edg.length();
00095         // get the first component
00096         temp_first = temp_length - lowVal;
00097         temp_first = fabs( temp_first ) - ( temp_first );
00098         temp_first *= temp_first;
00099         // get the second component
00100         temp_second = highVal - temp_length;
00101         temp_second = fabs( temp_second ) - ( temp_second );
00102         temp_second *= temp_second;
00103         // combine the two components
00104         metric_values[i] = temp_first + temp_second;
00105     }
00106     // average the metric values of the edges
00107     fval = average_metrics( metric_values, num_sample_points, err );
00108     // clean up
00109     delete[] metric_values;
00110     // always return true because mesh is always valid wrt this metric.
00111     return !MSQ_CHKERR( err );
00112 }
00113 
00114 bool EdgeLengthRangeQualityMetric::evaluate( PatchData& pd, size_t vertex, double& value, MsqError& err )
00115 {
00116     std::vector< size_t > verts;
00117     bool rval = evaluate_common( pd, vertex, value, verts, err );
00118     return !MSQ_CHKERR( err ) && rval;
00119 }
00120 
00121 bool EdgeLengthRangeQualityMetric::evaluate_with_indices( PatchData& pd, size_t vertex, double& value,
00122                                                           std::vector< size_t >& indices, MsqError& err )
00123 {
00124     indices.clear();
00125     bool rval = evaluate_common( pd, vertex, value, indices, err );
00126 
00127     std::vector< size_t >::iterator r, w;
00128     for( r = w = indices.begin(); r != indices.end(); ++r )
00129     {
00130         if( *r < pd.num_free_vertices() )
00131         {
00132             *w = *r;
00133             ++w;
00134         }
00135     }
00136     indices.erase( w, indices.end() );
00137     if( vertex < pd.num_free_vertices() ) indices.push_back( vertex );
00138 
00139     return !MSQ_CHKERR( err ) && rval;
00140 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines