Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QualityMetric/Shape/VertexConditionNumberQualityMetric.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 "Vector3D.hpp"
36 #include "ShapeQualityMetric.hpp"
37 #include "QualityMetric.hpp"
38 
39 #include <math.h>
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 
50 {
53  feasible=1;
54  set_name("Vertex Condition Number");
55 }
56 
58  MsqVertex* vert,
59  double &fval,
60  MsqError &err)
61 {
62  //pd.generate_vertex_to_element_data();
63  bool return_flag;
64  fval=MSQ_MAX_CAP;
65  //get the element array
66  MsqMeshEntity* elems = pd.get_element_array(err);
67  //convert the MsqVertex pointer into an index
68  size_t this_vert = pd.get_vertex_index(vert);
69  //get the vertex to element array and the offset array
70  //const size_t* elem_offset = pd.get_vertex_to_elem_offset(err); MSQ_ERRZERO(err);
71  //const size_t* v_to_e_array = pd.get_vertex_to_elem_array(err); MSQ_ERRZERO(err);
72  //find the offset for this vertex
73  //size_t this_offset = elem_offset[this_vert];
74  //get the number of elements attached to this vertex (given by the
75  //first entry in the vertex to element array)
76  //size_t num_elems = v_to_e_array[this_offset];
77  //PRINT_INFO("\nIN LOCAL SIZE CPP, num_elements = %i",num_elems);
78  //if no elements, then return true
79  size_t num_elems, *v_to_e_array;
80  v_to_e_array = pd.get_vertex_element_adjacencies( this_vert, num_elems, err );
81  MSQ_ERRZERO(err);
82 
83  if(num_elems <= 0){
84  return true;
85  }
86 
87  //create an array to store the local metric values before averaging
88  //Can we remove this dynamic allocatio?
89  double* met_vals = new double[num_elems];
90  //vector to hold the other verts which form a corner.
91  vector<size_t> other_vertices;
92  other_vertices.reserve(4);
93  size_t i=0;
94  //only 3 temp_vec will be sent to cond-num calculator, but the
95  //additional vector3Ds may be needed during the calculations
96  Vector3D temp_vec[6];
97  MsqVertex *vertices=pd.get_vertex_array(err);
98  //loop over the elements attached to this vertex
99  for(i=0;i<num_elems;++i){
100  //get the vertices connected to this vertex for this element
101  elems[v_to_e_array[i]].get_connected_vertices(this_vert,
102  other_vertices,
103  err); MSQ_ERRZERO(err);
104  //switch over the element type of this element
105  switch(elems[v_to_e_array[i]].get_element_type()){
106 
107  case TRIANGLE:
108  temp_vec[0]=vertices[other_vertices[0]]-vertices[this_vert];
109  temp_vec[2]=vertices[other_vertices[1]]-vertices[this_vert];
110  //make relative to equilateral
111  temp_vec[1]=((2*temp_vec[2])-temp_vec[0])*MSQ_SQRT_THREE_INV;
112  return_flag=condition_number_2d(temp_vec,this_vert,pd,met_vals[i],err); MSQ_ERRZERO(err);
113  if(!return_flag)
114  return return_flag;
115  break;
116  case QUADRILATERAL:
117  temp_vec[0]=vertices[other_vertices[0]]-vertices[this_vert];
118  temp_vec[1]=vertices[other_vertices[1]]-vertices[this_vert];
119  return_flag=condition_number_2d(temp_vec,this_vert,pd,met_vals[i],err); MSQ_ERRZERO(err);
120  if(!return_flag)
121  return return_flag;
122  break;
123  case TETRAHEDRON:
124  temp_vec[0]=vertices[other_vertices[0]]-vertices[this_vert];
125  temp_vec[3]=vertices[other_vertices[1]]-vertices[this_vert];
126  temp_vec[4]=vertices[other_vertices[2]]-vertices[this_vert];
127  //transform to equilateral tet
128  temp_vec[1]=((2*temp_vec[3])-temp_vec[0])/MSQ_SQRT_THREE;
129  temp_vec[2]=((3*temp_vec[4])-temp_vec[0]-temp_vec[3])/
131  return_flag=condition_number_3d(temp_vec,pd,met_vals[i],err); MSQ_ERRZERO(err);
132  if(!return_flag)
133  return return_flag;
134  break;
135  case HEXAHEDRON:
136  temp_vec[0]=vertices[other_vertices[0]]-vertices[this_vert];
137  temp_vec[1]=vertices[other_vertices[1]]-vertices[this_vert];
138  temp_vec[2]=vertices[other_vertices[2]]-vertices[this_vert];
139  return_flag=condition_number_3d(temp_vec,pd,met_vals[i],err); MSQ_ERRZERO(err);
140  if(!return_flag)
141  return return_flag;
142  break;
143  default:
144  fval=MSQ_MAX_CAP;
145  return false;
146 
147  }// end switch over element type
148  other_vertices.clear();
149  }//end loop over elements
150  fval = average_metrics(met_vals, num_elems, err); MSQ_ERRZERO(err);
151  delete []met_vals;
152  return true;
153 }
154 
155 
bool condition_number_3d(Vector3D temp_vec[], PatchData &pd, double &fval, MsqError &err)
Given the 3-d jacobian matrix, compute the condition number, fval.
#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.
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...
static const double MSQ_SQRT_TWO
Definition: Mesquite.hpp:122
bool condition_number_2d(Vector3D temp_vec[], size_t v_ind, PatchData &pd, double &fval, MsqError &err)
Given the 2-d jacobian matrix, compute the condition number, fval.
size_t get_vertex_index(MsqVertex *vertex)
blockLoc i
Definition: read.cpp:79
void get_connected_vertices(msq_stdc::size_t vertex_index, msq_std::vector< msq_stdc::size_t > &vert_indices, MsqError &err)
Fills a vector&lt;size_t&gt; with vertices connected to the given vertex through the edges of this MsqMeshE...
bool evaluate_vertex(PatchData &pd, MsqVertex *vert, double &fval, MsqError &err)
evaluate using mesquite objects
const MsqVertex * get_vertex_array(MsqError &err) const
Returns a pointer to the start of the vertex array.
void set_metric_type(MetricType t)
This function should be used in the constructor of every concrete quality metric. ...
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 ...
const MsqMeshEntity * get_element_array(MsqError &err) const
Returns a pointer to the start of the element array.
MsqVertex is the Mesquite object that stores information about the vertices in the mesh...
size_t * get_vertex_element_adjacencies(size_t vertex_index, size_t &array_len_out, MsqError &err)
void set_name(msq_std::string st)
Sets the name of this metric.
static const double MSQ_SQRT_THREE
Definition: Mesquite.hpp:123