Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
includeLinks/DistanceFromTarget.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 
37 #ifndef DistanceFromTarget_hpp
38 #define DistanceFromTarget_hpp
39 
40 #include "Mesquite.hpp"
41 #include "MsqError.hpp"
42 #include "PatchData.hpp"
43 #include "QualityMetric.hpp"
44 #include "TargetMatrix.hpp"
45 
46 namespace Mesquite
47 {
48 
54  {
55  public:
56 
59  {};
60 
61  protected:
65  Matrix3D T[], size_t num_T, double c_k[], MsqError &err);
66 
67  bool get_barrier_function(PatchData& pd, const double &tau, double &h, MsqError &err);
68 
69  private:
70 
71  };
72 
73 
75  Matrix3D T[], size_t num_T, double c_k[], MsqError &err)
76  {
77  // Gets the element corner matrices.
78  elem.compute_corner_matrices(pd, T, num_T, err);
79 
80 // for (size_t i=0; i<num_T; ++i)
81 // std::cout << "A["<<i<<"]:\n" << T[i] << std::endl;
82 
83  int elem_idx = pd.get_element_index(&elem);
84  const TargetMatrix* W = pd.targetMatrices.get_element_corner_tags(&pd, elem_idx, err );
85 
86 // for (size_t i=0; i<num_T; ++i)
87 // std::cout << "W["<<i<<"]:\n" << W[i] << std::endl;
88 
89  for (size_t i=0; i<num_T; ++i) {
90  timesInvA(T[i], W[i]);
91  c_k[i] = W[i].get_cK();
92  }
93  }
94 
95 
98  inline bool DistanceFromTarget::get_barrier_function(PatchData& pd, const double &tau, double &h, MsqError &err)
99  {
100 
101  double delta=pd.get_barrier_delta(err); MSQ_ERRZERO(err);
102 
103  // Note: technically, we want delta=eta*tau-max
104  // whereas the function above gives delta=eta*alpha-max
105  //
106  // Because the only requirement on eta is eta << 1,
107  // and because tau-max = alpha-max/0.707 we can
108  // ignore the discrepancy
109 
110  if (delta==0) {
111  if (tau < MSQ_DBL_MIN ) {
112  return false;
113  }
114  else {
115  h=tau;
116  }
117 
118  // Note: when delta=0, the vertex_barrier_function
119  // formally gives h=tau as well.
120  // We just do it this way to avoid any
121  // roundoff issues.
122  // Also: when delta=0, this metric is identical
123  // to the original condition number with
124  // the barrier at tau=0
125 
126  }
127  else {
128  h = 0.5*(tau+sqrt(tau*tau+4*delta*delta));
129 
130  if (h<MSQ_DBL_MIN && fabs(tau) > MSQ_DBL_MIN ) {
131  h = delta*delta/fabs(tau); }
132 
133  // Note: Analytically, h is strictly positive, but
134  // it can be zero numerically if tau
135  // is a large negative number
136  // In the h=0 case, we use a different analytic
137  // approximation to compute h.
138  }
139  if (h<MSQ_DBL_MIN) {
140  MSQ_SETERR(err)("Barrier function is zero due to excessively large "
141  "negative area compared to delta.\nTry to untangle "
142  "mesh another way.", MsqError::INVALID_MESH);
143  return false;
144  }
145  return true;
146  }
147 
148 } //namespace
149 
150 
151 #endif // DistanceFromTarget_hpp
#define MSQ_ERRZERO(err)
Return zero/NULL on error.
const double MSQ_DBL_MIN
Definition: Mesquite.hpp:158
Base class for the computation of the distance from target between the target matrices W and the actu...
CornerTag< TargetMatrix > targetMatrices
Target matrix data.
Used to hold the error state and return it to the application.
Base class for concrete quality metrics.
virtual ~DistanceFromTarget()
virtual destructor ensures use of polymorphism during destruction
MsqMeshEntity is the Mesquite object that stores information about the elements in the mesh...
double sqrt(double d)
Definition: double.h:73
double get_barrier_delta(MsqError &err)
Returns delta based on the minimum and maximum corner determinant over all elements in the patch This...
size_t get_element_index(MsqMeshEntity *element)
3*3 Matric class, row-oriented, 0-based [i][j] indexing.
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
blockLoc i
Definition: read.cpp:79
void timesInvA(Matrix3D &B, const Matrix3D &A)
void compute_T_matrices(MsqMeshEntity &elem, PatchData &pd, Matrix3D T[], size_t num_T, double c_k[], MsqError &err)
For a given element, compute each corner matrix A, and given a target corner matrix W...
Class containing the target corner matrices for the context based smoothing.
bool get_barrier_function(PatchData &pd, const double &tau, double &h, MsqError &err)
void compute_corner_matrices(PatchData &pd, Matrix3D A[], int num_m3d, MsqError &err)
Compute matrices which column are the vectors issued from a corner.