Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QualityMetric/Untangle/UntangleBetaQualityMetric.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  ***************************************************************** */
36 #include "Vector3D.hpp"
37 #include "QualityMetric.hpp"
38 #include "MsqMeshEntity.hpp"
39 
40 #ifdef MSQ_USE_OLD_STD_HEADERS
41 # include <vector.h>
42 #else
43 # include <vector>
44  using std::vector;
45 #endif
46 
47 using namespace Mesquite;
48 
54 {
55  MsqError err;
59  feasible=0;
60  set_name("Untangle Beta");
62  mBeta=bet;
63 }
64 
68  MsqMeshEntity *element,
69  double &fval,
70  MsqError &err){
71 
72  double met_vals[MSQ_MAX_NUM_VERT_PER_ENT];
73  fval=MSQ_MAX_CAP;
74  const size_t* v_i = element->get_vertex_index_array();
75  size_t e_ind = pd.get_element_index(element);
76  //only 3 temp_vec will be sent to untangle calculator, but the
77  //additional vector3Ds may be needed during the calculations
78  Vector3D temp_vec[6];
79  MsqVertex *vertices=pd.get_vertex_array(err); MSQ_ERRZERO(err);
80  switch(element->get_element_type()){
81  case TRIANGLE:
82  temp_vec[0]=vertices[v_i[1]]-vertices[v_i[0]];
83  temp_vec[2]=vertices[v_i[2]]-vertices[v_i[0]];
84  //make relative to equilateral
85  temp_vec[1]=((2*temp_vec[2])-temp_vec[0])*MSQ_SQRT_THREE_INV;
86  untangle_function_2d(temp_vec,e_ind,pd,fval,err);
87  return true;
88  case QUADRILATERAL:
89  temp_vec[0]=vertices[v_i[1]]-vertices[v_i[0]];
90  temp_vec[1]=vertices[v_i[3]]-vertices[v_i[0]];
91  untangle_function_2d(temp_vec,e_ind,pd,met_vals[0],err); MSQ_ERRZERO(err);
92 
93  temp_vec[0]=vertices[v_i[2]]-vertices[v_i[1]];
94  temp_vec[1]=vertices[v_i[0]]-vertices[v_i[1]];
95  untangle_function_2d(temp_vec,e_ind,pd,met_vals[1],err); MSQ_ERRZERO(err);
96 
97  temp_vec[0]=vertices[v_i[3]]-vertices[v_i[2]];
98  temp_vec[1]=vertices[v_i[1]]-vertices[v_i[2]];
99  untangle_function_2d(temp_vec,e_ind,pd,met_vals[2],err); MSQ_ERRZERO(err);
100 
101  temp_vec[0]=vertices[v_i[0]]-vertices[v_i[3]];
102  temp_vec[1]=vertices[v_i[2]]-vertices[v_i[3]];
103  untangle_function_2d(temp_vec,e_ind,pd,met_vals[3],err); MSQ_ERRZERO(err);
104  fval=average_metrics(met_vals, 4, err); MSQ_ERRZERO(err);
105  return true;
106  case TETRAHEDRON:
107  temp_vec[0]=vertices[v_i[1]]-vertices[v_i[0]];
108  temp_vec[3]=vertices[v_i[2]]-vertices[v_i[0]];
109  temp_vec[4]=vertices[v_i[3]]-vertices[v_i[0]];
110  //transform to equilateral tet
111  temp_vec[1]=((2*temp_vec[3])-temp_vec[0])/MSQ_SQRT_THREE;
112  temp_vec[2]=((3*temp_vec[4])-temp_vec[0]-temp_vec[3])/
114  untangle_function_3d(temp_vec,fval,err); MSQ_ERRZERO(err);
115  return true;
116  case HEXAHEDRON:
117  //transform to v_i[0]
118  temp_vec[0]=vertices[v_i[1]]-vertices[v_i[0]];
119  temp_vec[1]=vertices[v_i[3]]-vertices[v_i[0]];
120  temp_vec[2]=vertices[v_i[4]]-vertices[v_i[0]];
121  untangle_function_3d(temp_vec,met_vals[0],err); MSQ_ERRZERO(err);
122 
123  temp_vec[0]=vertices[v_i[2]]-vertices[v_i[1]];
124  temp_vec[1]=vertices[v_i[0]]-vertices[v_i[1]];
125  temp_vec[2]=vertices[v_i[5]]-vertices[v_i[1]];
126  untangle_function_3d(temp_vec,met_vals[1],err); MSQ_ERRZERO(err);
127 
128  temp_vec[0]=vertices[v_i[3]]-vertices[v_i[2]];
129  temp_vec[1]=vertices[v_i[1]]-vertices[v_i[2]];
130  temp_vec[2]=vertices[v_i[6]]-vertices[v_i[2]];
131  untangle_function_3d(temp_vec,met_vals[2],err); MSQ_ERRZERO(err);
132 
133  temp_vec[0]=vertices[v_i[0]]-vertices[v_i[3]];
134  temp_vec[1]=vertices[v_i[2]]-vertices[v_i[3]];
135  temp_vec[2]=vertices[v_i[7]]-vertices[v_i[3]];
136  untangle_function_3d(temp_vec,met_vals[3],err); MSQ_ERRZERO(err);
137 
138  temp_vec[0]=vertices[v_i[7]]-vertices[v_i[4]];
139  temp_vec[1]=vertices[v_i[5]]-vertices[v_i[4]];
140  temp_vec[2]=vertices[v_i[0]]-vertices[v_i[4]];
141  untangle_function_3d(temp_vec,met_vals[4],err); MSQ_ERRZERO(err);
142 
143  temp_vec[0]=vertices[v_i[4]]-vertices[v_i[5]];
144  temp_vec[1]=vertices[v_i[6]]-vertices[v_i[5]];
145  temp_vec[2]=vertices[v_i[1]]-vertices[v_i[5]];
146  untangle_function_3d(temp_vec,met_vals[5],err); MSQ_ERRZERO(err);
147 
148  temp_vec[0]=vertices[v_i[5]]-vertices[v_i[6]];
149  temp_vec[1]=vertices[v_i[7]]-vertices[v_i[6]];
150  temp_vec[2]=vertices[v_i[2]]-vertices[v_i[6]];
151  untangle_function_3d(temp_vec,met_vals[6],err); MSQ_ERRZERO(err);
152 
153  temp_vec[0]=vertices[v_i[6]]-vertices[v_i[7]];
154  temp_vec[1]=vertices[v_i[4]]-vertices[v_i[7]];
155  temp_vec[2]=vertices[v_i[3]]-vertices[v_i[7]];
156  untangle_function_3d(temp_vec,met_vals[7],err); MSQ_ERRZERO(err);
157  fval=average_metrics(met_vals, 8, err); MSQ_ERRZERO(err);
158  return true;
159  default:
160  MSQ_SETERR(err)("Element of incorrect type sent to "
161  "UntangleBetaQualityMetric",
163  return false;
164  }// end switch over element type
165 
166 
167 }
168 
169 
170 
171 
172 
173 
#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.
void untangle_function_3d(Vector3D temp_vec[], double &fval, MsqError &err)
requested functionality is not (yet) implemented
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...
const int MSQ_MAX_NUM_VERT_PER_ENT
Definition: Mesquite.hpp:120
UntangleBetaQualityMetric(double bet=0.05)
For untangle beta, the constructor defaults to the SUM averaging method, and to the ELEMENT_VERTICES ...
static const double MSQ_SQRT_TWO
Definition: Mesquite.hpp:122
void set_element_evaluation_mode(ElementEvaluationMode mode, MsqError &err)
Sets the evaluation mode for the ELEMENT_BASED metrics.
#define MSQ_CHKERR(err)
Mesquite&#39;s Error Checking macro.
size_t get_element_index(MsqMeshEntity *element)
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
void untangle_function_2d(Vector3D temp_vec[], size_t e_ind, PatchData &pd, double &fval, MsqError &err)
const MsqVertex * get_vertex_array(MsqError &err) const
Returns a pointer to the start of the vertex array.
EntityTopology get_element_type() const
Returns element type.
void set_gradient_type(GRADIENT_TYPE grad)
Sets gradType for this metric.
const msq_stdc::size_t * get_vertex_index_array() const
Very efficient retrieval of vertices indexes (corresponding to the PatchData vertex array)...
void set_metric_type(MetricType t)
This function should be used in the constructor of every concrete quality metric. ...
bool evaluate_element(PatchData &pd, MsqMeshEntity *element, double &fval, MsqError &err)
static const double MSQ_SQRT_THREE_INV
Definition: Mesquite.hpp:125
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...
void set_name(msq_std::string st)
Sets the name of this metric.
static const double MSQ_SQRT_THREE
Definition: Mesquite.hpp:123