Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QualityMetric/Shape/GeneralizedConditionNumberQualityMetric.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 namespace std;
45 #endif
46 
47 
48 
49 using namespace Mesquite;
50 
51 GeneralizedConditionNumberQualityMetric::GeneralizedConditionNumberQualityMetric()
52 {
53  MsqError err;
54  set_metric_type(ELEMENT_BASED);
55  set_element_evaluation_mode(ELEMENT_VERTICES, err); MSQ_CHKERR(err);
56  avgMethod=QualityMetric::LINEAR;
57  feasible=1;
58  set_name("Generalized Condition Number");
59 }
60 /*
61 #undef __FUNC__
62 #define __FUNC__ "GeneralizedConditionNumberQualityMetric::evaluate_element"
63 
64 double GeneralizedConditionNumberQualityMetric::evaluate_element(PatchData *pd, int element_index,
65  MsqError &err)
66 {
67  // THIS FUNCTION SHOULD EVENTUALLY BE MADE VERY EFFICIENT BY USING
68  // RAW ARRAYS DIRECTLY. RIGHT NOW IT IS A HACK TO PORT OPT-MS
69 
70  if ( pd->get_storage_mode() != PatchData::RAW_ARRAYS ) {
71  err.set_msg("Need raw arrays in evaluate element function taking pd as argument\n");
72  return(0.0);
73  }
74  if (element_index >= pd->get_element_array_size()) {
75  err.set_msg("element index exceeds element array size\n");
76  return(0.0);
77  }
78 
79  Vector3D* coords = pd->get_coords_array(err);
80  ConnectivityArrayT element_connectivity = (pd->get_connectivity_array(err))[element_index];
81 
82  switch (element_connectivity.entity_type) {
83  case TRIANGLE:
84  MsqNode node1(coords[element_connectivity.indices[0]][0],
85  coords[element_connectivity.indices[0]][1],
86  coords[element_connectivity.indices[0]][2]);
87  MsqNode node2(coords[element_connectivity.indices[1]][0],
88  coords[element_connectivity.indices[1]][1],
89  coords[element_connectivity.indices[1]][2]);
90  MsqNode node3(coords[element_connectivity.indices[2]][0],
91  coords[element_connectivity.indices[2]][1],
92  coords[element_connectivity.indices[2]][2]);
93  MsqTri tri(&node1,&node2,&node3);
94  return( this->evaluate_element(&tri, err) );
95  break;
96  // default:
97  // err.set_msg("only supporting triangles in evaluate element for now\n");
98  // return(0.0);
99  }
100 }
101 */
102 
103 bool GeneralizedConditionNumberQualityMetric::evaluate_element(PatchData &pd,
104  MsqMeshEntity *element,
105  double &fval,
106  MsqError &err)
107 {
108  int num_sample_points;
109  bool return_flag;
110  vector<Vector3D> sample_points;
111  ElementEvaluationMode eval_mode = get_element_evaluation_mode();
112  element->get_sample_points(eval_mode,sample_points,err); MSQ_ERRZERO(err);
113  vector<Vector3D>::iterator iter=sample_points.begin();
114  // loop over sample points
115  Vector3D jacobian_vectors[3];
116  short num_jacobian_vectors;
117  int i=0;
118  num_sample_points=sample_points.size();
119  std::vector<double> metric_values(num_sample_points);
120  //Vector3D* current_sample_point;
121  for(i=0;i<num_sample_points;++i){
122  // compute weighted jacobian
123  element->compute_weighted_jacobian(pd, (*iter),
124  jacobian_vectors,
125  num_jacobian_vectors, err); MSQ_ERRZERO(err);
126  // evaluate condition number at ith sample point
127  //if 2 jacobian vectors (2D elem)
128 
129  return_flag=compute_condition_number(pd, element, jacobian_vectors,
130  num_jacobian_vectors,
131  metric_values[i],err);
132  if(MSQ_CHKERR(err) || !return_flag){
133  return false;
134  }
135 
136  ++iter;
137  }// end loop over sample points
138  fval=average_metrics(&metric_values[0],num_sample_points,err); MSQ_ERRZERO(err);
139  return true;
140 }
141 
142 bool GeneralizedConditionNumberQualityMetric::evaluate_vertex(PatchData &/*pd*/,
143  MsqVertex* /*vertex*/,
144  double &fval,
145  MsqError &err)
146 {
147  MSQ_SETERR(err)("Condition Number's evaluate_vertex is currently "
148  "being implemented", MsqError::NOT_IMPLEMENTED);
149  fval=0.0;
150  return false;
151 
152  /*
153  fval=0.0;
154  size_t this_vert = pd.get_vertex_index(vert);
155  vector<size_t> adj_elems;
156  pd.get_vertex_element_indices(this_vert, adg_elems, err);
157  double num_elems = adj_elems.size();
158  double *metric_values=new double[ num_elems ];
159  int num_jacobian_vectors;
160  Vector3D sample_point;
161  Vecotr3D jacobian_vectors[3];
162 
163  int i;
164  for ( i = 0; i<num_elems; i++){
165  elems[i]->get_sample_point(vertex, sample_point, err); MSQ_CHKERR(err);
166  elems[i]->compute_weighted_jacobian(&current_sample_point,
167  jacobian_vectors,
168  num_jacobian_vectors, err);
169  MSQ_CHKERR(err);
170  metric_values[i]=compute_condition_number(jacobian_vectors,
171  num_jacobian_vectors, err);
172  MSQ_CHKERR(err);
173  }
174  total_metric=average_metrics(metric_values, num_elems, err);
175  MSQ_CHKERR(err);
176  delete metric_values;
177  */
178 }
179 
#define MSQ_ERRZERO(err)
Return zero/NULL on error.
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...
#define MSQ_CHKERR(err)
Mesquite&#39;s Error Checking macro.
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
blockLoc i
Definition: read.cpp:79
void compute_weighted_jacobian(PatchData &pd, Vector3D &sample_point, Vector3D jacobian_vectors[], short &num_jacobian_vectors, MsqError &err)
void get_sample_points(QualityMetric::ElementEvaluationMode mode, msq_std::vector< Vector3D > &coords, MsqError &err)
Returns a list of sample points given an evaluationmode.
MsqVertex is the Mesquite object that stores information about the vertices in the mesh...