Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
includeLinks/GeneralizedConditionNumberQualityMetric.hpp
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  ***************************************************************** */
27 // -*- Mode : c++; tab-width: 3; c-tab-always-indent: t; indent-tabs-mode: nil; c-basic-offset: 3 -*-
28 
38 #ifndef GeneralizedConditionNumberQualityMetric_hpp
39 #define GeneralizedConditionNumberQualityMetric_hpp
40 
41 
42 #include "Mesquite.hpp"
43 #include "MsqMeshEntity.hpp"
44 #include "MsqError.hpp"
45 #include "ShapeQualityMetric.hpp"
46 #include "Vector3D.hpp"
47 #include "PatchData.hpp"
48 
49 namespace Mesquite
50 {
62  {
63  public:
64 
66 
69  {}
70 
72  bool evaluate_element(PatchData &pd, MsqMeshEntity *element, double &fval,
73  MsqError &err);
74 
76  bool evaluate_vertex(PatchData &pd, MsqVertex *vertex, double &fval,
77  MsqError &err);
78 
79  protected:
80 
82  Vector3D* jacobian_vectors,
83  int num_jacobian_vectors,
84  double &fval,
85  MsqError &err);
86  };
87 
88 //BEGIN INLINE FUNCTIONS
89 
91  PatchData &pd, MsqMeshEntity *element, Vector3D* jacobian_vectors,
92  int num_jacobian_vectors, double &fval, MsqError &err)
93  {
94  //PRINT_INFO("INSIDE CONDITION NUMBER COMPUTE_CON\n");
95  double temp_var=0;
96  if(num_jacobian_vectors==2){
97  size_t vert=element->get_vertex_index(0);
98  Vector3D cross_vec=jacobian_vectors[0]*jacobian_vectors[1];
99  if ( pd.domain_set() ) {
100  Vector3D norm_vec;
101  pd.get_domain_normal_at_vertex(vert,false,norm_vec,err);MSQ_ERRZERO(err);
102  if(cross_vec%norm_vec<0.0){
103  return false;
104  }
105  }
106 
107  temp_var=fabs((cross_vec).length());
108  fval=jacobian_vectors[0].length_squared();
109  fval+=jacobian_vectors[1].length_squared();
110  if(temp_var>=MSQ_MIN){ //if not degenerate
111  fval/=(2.0*temp_var);
112  }
113  else{
114  fval=MSQ_MAX_CAP;
115  }
116  return true;
117  }
118 
119  //if three jacobian vectors (3D elem)
120  else if(num_jacobian_vectors==3){
121  //norm squared of J
122  double term1=jacobian_vectors[0]%jacobian_vectors[0]+
123  jacobian_vectors[1]%jacobian_vectors[1]+
124  jacobian_vectors[2]%jacobian_vectors[2];
125  //norm squared of adjoint of J
126  double term2=(jacobian_vectors[0]*jacobian_vectors[1])%
127  (jacobian_vectors[0]*jacobian_vectors[1])+
128  (jacobian_vectors[1]*jacobian_vectors[2])%
129  (jacobian_vectors[1]*jacobian_vectors[2])+
130  (jacobian_vectors[2]*jacobian_vectors[0])%
131  (jacobian_vectors[2]*jacobian_vectors[0]);
132  //det of J
133  temp_var=jacobian_vectors[0]%(jacobian_vectors[1]*jacobian_vectors[2]);
134  if(temp_var<=0.0){
135  return false;
136  }
137 
138  fval=sqrt(term1*term2);
139  if(fval>MSQ_MIN){
140  //if not degenerate or inverted???
141  fval/=(3*temp_var);
142  }
143  else{
144  fval=MSQ_MAX_CAP;
145  }
146  }
147 
148  else{
149  fval=MSQ_MAX_CAP;
150  }
151 
152  return true;
153  }
154 
155 } //namespace
156 
157 
158 #endif // GeneralizedConditionNumberQualityMetric_hpp
159 
160 
msq_stdc::size_t get_vertex_index(msq_stdc::size_t vertex_in_element) const
#define MSQ_ERRZERO(err)
Return zero/NULL on error.
Computes the condition number of given element. The``condition number" is scaled between one and infi...
const double MSQ_MAX_CAP
Definition: Mesquite.hpp:173
Used to hold the error state and return it to the application.
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)
bool evaluate_element(PatchData &pd, MsqMeshEntity *element, double &fval, MsqError &err)
evaluate using mesquite objects
void get_domain_normal_at_vertex(size_t vertex_index, bool normalize, Vector3D &surf_norm, MsqError &err)
bool evaluate_vertex(PatchData &pd, MsqVertex *vertex, double &fval, MsqError &err)
Evaluate the &quot;condition number&quot; for a vertex.
MsqVertex is the Mesquite object that stores information about the vertices in the mesh...
virtual ~GeneralizedConditionNumberQualityMetric()
virtual destructor ensures use of polymorphism during destruction
const double MSQ_MIN
Definition: Mesquite.hpp:160
bool compute_condition_number(PatchData &pd, MsqMeshEntity *elem, Vector3D *jacobian_vectors, int num_jacobian_vectors, double &fval, MsqError &err)