Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
inks/EdgeLengthRangeQualityMetric.cpp
Go to the documentation of this file.
1 /* *****************************************************************
2  MESQUITE -- The Mesh Quality Improvement Toolkit
3 
4  Copyright 2004 Sandia Corporation and Argonne National
5  Laboratory. Under the terms of Contract DE-AC04-94AL85000
6  with Sandia Corporation, the U.S. Government retains certain
7  rights in this software.
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  (lgpl.txt) along with this library; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 
23  diachin2@llnl.gov, djmelan@sandia.gov, mbrewer@sandia.gov,
24  pknupp@sandia.gov, tleurent@mcs.anl.gov, tmunson@mcs.anl.gov
25 
26  ***************************************************************** */
35 #include "EdgeLengthRangeQualityMetric.hpp"
36 #include "Vector3D.hpp"
37 #include "QualityMetric.hpp"
38 #include "MsqVertex.hpp"
39 #include "PatchData.hpp"
40 #include "MsqDebug.hpp"
41 
42 #ifdef MSQ_USE_OLD_STD_HEADERS
43 # include <vector.h>
44 #else
45 # include <vector>
46  using std::vector;
47 #endif
48 
49 
50 using namespace Mesquite;
51 
52 
60  double &fval, MsqError &err)
61 {
62  fval=0.0;
63  size_t this_vert = pd.get_vertex_index(vert);
64  size_t other_vert;
65  vector<size_t> adj_verts;
66  Vector3D edg;
67  pd.get_adjacent_vertex_indices(this_vert,adj_verts,err); MSQ_ERRZERO(err);
68  int num_sample_points=adj_verts.size();
69  double *metric_values=new double[num_sample_points];
70  MsqVertex* verts = pd.get_vertex_array(err); MSQ_ERRZERO(err);
71  int point_counter=0;
72  //store the length of the edge, and the first and second component of
73  //metric values, respectively.
74  double temp_length=0.0;
75  double temp_first=0.0;
76  double temp_second=0.0;
77  //PRINT_INFO("INSIDE ELR, vertex = %f,%f,%f\n",verts[this_vert][0],verts[this_vert][1],verts[this_vert][2]);
78  //loop while there are still more adjacent vertices.
79  while(!adj_verts.empty()){
80  other_vert=adj_verts.back();
81  adj_verts.pop_back();
82  edg[0]=verts[this_vert][0]-verts[other_vert][0];
83  edg[1]=verts[this_vert][1]-verts[other_vert][1];
84  edg[2]=verts[this_vert][2]-verts[other_vert][2];
85  //compute the edge length
86  temp_length=edg.length();
87  //get the first component
88  temp_first = temp_length - lowVal;
89  temp_first = fabs(temp_first) - (temp_first);
90  temp_first*=temp_first;
91  //get the second component
92  temp_second = highVal - temp_length;
93  temp_second = fabs(temp_second) - (temp_second);
94  temp_second*=temp_second;
95  //combine the two components
96  metric_values[point_counter]=temp_first+temp_second;
97  //increment the counter
98  ++point_counter;
99  }
100  //average the metric values of the edges
101  fval=average_metrics(metric_values,num_sample_points,err); MSQ_ERRZERO(err);
102  //clean up
103  delete[] metric_values;
104  //always return true because mesh is always valid wrt this metric.
105  return true;
106 
107 }
108 
#define MSQ_ERRZERO(err)
Return zero/NULL on error.
bool evaluate_vertex(PatchData &pd, MsqVertex *vert, double &fval, MsqError &err)
Used to hold the error state and return it to the application.
Vector3D is the object that effeciently stores information about about three-deminsional vectors...
size_t get_vertex_index(MsqVertex *vertex)
void get_adjacent_vertex_indices(size_t vertex_index, msq_std::vector< size_t > &vert_indices, MsqError &err)
const MsqVertex * get_vertex_array(MsqError &err) const
Returns a pointer to the start of the vertex array.
double average_metrics(const double metric_values[], const int &num_values, MsqError &err)
average_metrics takes an array of length num_values and averages the contents using averaging method ...
MsqVertex is the Mesquite object that stores information about the vertices in the mesh...