Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QualityMetric/Shape/AspectRatioGammaQualityMetric.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  ***************************************************************** */
37 #include <math.h>
38 #include "Vector3D.hpp"
39 #include "MsqMeshEntity.hpp"
40 #include "PatchData.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 using namespace Mesquite;
50 
51 
52 //note that we can define this metric for other element types?
55  MsqMeshEntity* element,
56  double &fval,
57  MsqError &err)
58 {
59  EntityTopology entity = element->get_element_type();
60  double vol=0;
61  Vector3D temp_vec(0,0,0);
62  bool return_val = true;
63 
64  //get element's nodes
65  vector<Vector3D> vert;
66  size_t elem_index = pd.get_element_index(element);
67  pd.get_element_vertex_coordinates(elem_index, vert, err); MSQ_ERRZERO(err);
68 
69  switch(entity)
70  {
71  case TRIANGLE:
72  //area
73  vol=(((vert[1]-vert[0])*(vert[2]-vert[0])).length())/2.0;
74  vol=fabs(vol);
75  if(vol<MSQ_MIN){
76  fval=MSQ_MAX_CAP;
77  }
78  else{
79  //sum of edges squared
80  temp_vec=vert[1]-vert[0];
81  fval=temp_vec.length_squared();
82  temp_vec=vert[2]-vert[0];
83  fval+=temp_vec.length_squared();
84  temp_vec=vert[1]-vert[2];
85  fval+=temp_vec.length_squared();
86  //average sum of edges squared
87  fval/=3.0;
88  //normalize to equil. and div by area
89  // 2.309... is 4/sqrt(3) (inverse of the area of an equil. tri
90  fval/=(vol*fourDivRootThree);
91  }
92 
93  break;
94  case TETRAHEDRON:
95  vol=(vert[1]-vert[0])%((vert[2]-vert[0])*(vert[3]-vert[0]))/6.0;
96  //sum of edges squared
97  if(fabs(vol)<MSQ_MIN){
98  fval=MSQ_MAX_CAP;
99  }
100  else{
101  temp_vec=vert[1]-vert[0];
102  fval=temp_vec.length_squared();
103  temp_vec=vert[2]-vert[0];
104  fval+=temp_vec.length_squared();
105  temp_vec=vert[3]-vert[0];
106  fval+=temp_vec.length_squared();
107  temp_vec=vert[2]-vert[1];
108  fval+=temp_vec.length_squared();
109  temp_vec=vert[3]-vert[1];
110  fval+=temp_vec.length_squared();
111  temp_vec=vert[3]-vert[2];
112  fval+=temp_vec.length_squared();
113  //average sum of edges squared
114  fval/=6.0;
115  fval=sqrt(fval);
116  fval*=(fval);
117  fval*=(fval);
118  //normalize to equil. and div by area
119  fval/=(vol*twelveDivRootTwo);
120  }
121  break;
122  default:
123  fval=MSQ_MAX_CAP;
125  "Entity type %d is not valid for Aspect Ratio Gamma\n",
126  (int)entity);
127  return_val = false;
128  break;
129  };
130 
131  return return_val;
132 }
#define MSQ_ERRZERO(err)
Return zero/NULL on error.
const double MSQ_MAX_CAP
Definition: Mesquite.hpp:173
Used to hold the error state and return it to the application.
EntityTopology
Definition: Mesquite.hpp:92
MsqMeshEntity is the Mesquite object that stores information about the elements in the mesh...
Vector3D is the object that effeciently stores information about about three-deminsional vectors...
double sqrt(double d)
Definition: double.h:73
double length(Vector3D *const v, int n)
invalid function argument passed
size_t get_element_index(MsqMeshEntity *element)
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
bool evaluate_element(PatchData &pd, MsqMeshEntity *element, double &fval, MsqError &err)
Computes the aspect ratio gamma of element.
double length_squared() const
EntityTopology get_element_type() const
Returns element type.
void get_element_vertex_coordinates(size_t elem_index, msq_std::vector< Vector3D > &coords, MsqError &err)
Get the coordinates of vertices attached to the specified element.
const double MSQ_MIN
Definition: Mesquite.hpp:160