Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QualityMetric/Smoothness/ASMQualityMetric.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  ***************************************************************** */
34 #include "ASMQualityMetric.hpp"
35 #include "Vector3D.hpp"
36 #include "ShapeQualityMetric.hpp"
37 #include "QualityMetric.hpp"
38 
39 #ifdef MSQ_USE_OLD_STD_HEADERS
40 # include <vector.h>
41 #else
42 # include <vector>
43  using std::vector;
44 #endif
45 
46 using namespace Mesquite;
47 
48 
50 {
51  MsqError err;
54  MSQ_CHKERR(err);
56  feasible=0;
57  set_name("Area Smoothness");
58 }
59 
61  MsqMeshEntity *element,
62  double &fval,
63  MsqError &err)
64 {
65  double temp_double;
66  size_t elem_ind=pd.get_element_index(element);
67  vector<size_t> adj_elems;
68 
69  MsqMeshEntity *elems = pd.get_element_array(err);
70  switch(element->get_element_type()){
71  case TRIANGLE:
72  case QUADRILATERAL:
73  pd.get_adjacent_entities_via_n_dim(1,elem_ind,adj_elems,err); MSQ_ERRZERO(err);
74  break;
75  case TETRAHEDRON:
76  case HEXAHEDRON:
77  pd.get_adjacent_entities_via_n_dim(2,elem_ind,adj_elems,err); MSQ_ERRZERO(err);
78  break;
79  default:
80  MSQ_SETERR(err)("ASM quality metric not implemented for this "
81  "element type.", MsqError::NOT_IMPLEMENTED);
82  return false;
83  };
84  int num_samp=adj_elems.size();
85  if(num_samp < 1){
86  fval=0.0;
87  }
88  else{
89  double* met_vals = new double [num_samp];
90  int i=0;
91  switch(element->get_element_type()){
92  case TRIANGLE:
93  case QUADRILATERAL:
94  temp_double=element->compute_unsigned_area(pd,err); MSQ_ERRZERO(err);
95  //PRINT_INFO("\nunsigned area = %f",temp_double);
96  for(i=0;i<num_samp;++i){
97  met_vals[i]=elems[adj_elems[i]].compute_unsigned_area(pd,err); MSQ_ERRZERO(err);
98  //PRINT_INFO("neighboring nunsigned area = %f",met_vals[i]);
99  if((temp_double+met_vals[i])>MSQ_MIN){
100  met_vals[i]=fabs((temp_double-met_vals[i])/(temp_double+
101  met_vals[i]));
102  }
103  else
104  met_vals[i]=0.0;
105  }
106  break;
107 
108  case TETRAHEDRON:
109  case HEXAHEDRON:
110  temp_double=element->compute_unsigned_volume(pd,err); MSQ_ERRZERO(err);
111  for(i=0;i<num_samp;++i){
112  met_vals[i]=elems[adj_elems[i]].compute_unsigned_volume(pd,err); MSQ_ERRZERO(err);
113  if((temp_double+met_vals[i])>MSQ_MIN){
114  met_vals[i]=fabs((temp_double-met_vals[i])/(temp_double+
115  met_vals[i]));
116  }
117  else
118  met_vals[i]=0.0;
119  }
120  break;
121  default:
122  MSQ_SETERR(err)("ASM quality metric not implemented for this "
123  "element type.", MsqError::NOT_IMPLEMENTED);
124  return false;
125  };
126  fval=average_metrics(met_vals,num_samp,err); MSQ_ERRZERO(err);
127  //PRINT_INFO("\nRETURNING %f \n",fval);
128  delete []met_vals;
129  }
130  return true;
131 }
132 
133 
#define MSQ_ERRZERO(err)
Return zero/NULL on error.
bool evaluate_element(PatchData &pd, MsqMeshEntity *element, double &fval, MsqError &err)
evaluate using mesquite objects
Used to hold the error state and return it to the application.
requested functionality is not (yet) implemented
MsqMeshEntity is the Mesquite object that stores information about the elements in the mesh...
double compute_unsigned_volume(PatchData &pd, MsqError &err)
Computes the volume of the element.
void get_adjacent_entities_via_n_dim(int n, size_t ent_ind, msq_std::vector< size_t > &adj_ents, MsqError &err)
Get the indices of entities attached to entity (given by ent_ind). adj_ents is filled with the indice...
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.
blockLoc i
Definition: read.cpp:79
double compute_unsigned_area(PatchData &pd, MsqError &err)
Computes the area of the element.
EntityTopology get_element_type() const
Returns element type.
void set_metric_type(MetricType t)
This function should be used in the constructor of every concrete quality metric. ...
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.
void set_name(msq_std::string st)
Sets the name of this metric.
const double MSQ_MIN
Definition: Mesquite.hpp:160