Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
includeLinks/TargetCalculator.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 
39 #ifndef TargetCalculator_hpp
40 #define TargetCalculator_hpp
41 
42 #include "Mesquite.hpp"
43 #include "MsqError.hpp"
44 #include "Matrix3D.hpp"
45 #include "PatchData.hpp"
46 #include "PatchDataUser.hpp"
47 
48 #ifdef HAVE_IEEEFP
49 # include <ieeefp.h>
50 #endif
51 
52 namespace Mesquite
53 {
54  class PatchDataParameters;
55 
56 
75  {
76  public:
77 
80 
83  {};
84 
85  static void initialize_default_target_matrices(Matrix3D &tri_M3D, Matrix3D &quad_M3D,
86  Matrix3D &tet_M3D, Matrix3D &hex_M3D);
87 
90  enum Lambda_type {
93  };
94 
96  enum guide_type {
97  Ad,
98  AK,
99  A0,
100  Ar,
101  As,
102  Ab,
103  Ac,
104  Ap,
105  Ae,
106  Af,
107  Ax
108  };
110  void compute_guide_matrices(enum guide_type type, PatchData &ref_pd, size_t elem_ind,
111  Matrix3D A[], int num, MsqError &err);
112 
113  static double compute_Lambda(const Matrix3D &A, MsqError &err);
114  Matrix3D compute_V_3D(const Matrix3D &A, MsqError &err);
115  Matrix3D compute_Q_3D(const Matrix3D &A, MsqError &err);
117 
122 
127 
131 
134 
140  virtual void compute_target_matrices(PatchData& pd, MsqError& err) =0;
141 
142  virtual double loop_over_mesh( MeshSet& ms, MsqError& err );
143 
144  virtual msq_std::string get_name();
145 
147 
148  protected:
150  };
151 
152 
154  Matrix3D &quad_M3D,
155  Matrix3D &tet_M3D,
156  Matrix3D &hex_M3D)
157  {
158  static const double SIXTH_ROOT_OF_TWO = msq_stdc::pow(2., 1./6.);
159 
160  const double v_tri[] = {1., 0.5, 0., 0., MSQ_SQRT_THREE/2., 0., 0., 0., 1.};
161  Matrix3D m1(v_tri);
162  tri_M3D = m1 * MSQ_3RT_2_OVER_6RT_3;
163 
164 // const double v_tri[] = {1., 0.5, 0., 0., MSQ_SQRT_THREE/2., 0., 0., 0., sqrt(MSQ_SQRT_THREE/2.)};
165 // Matrix3D m1(v_tri);
166 // tri_M3D = m1 * sqrt(2./MSQ_SQRT_THREE);
167 
168  const double v_quad[] = {1., 0., 0., 0., 1., 0., 0., 0., 1.};
169  Matrix3D m2(v_quad);
170  quad_M3D = m2;
171 
172  const double v_tet[] = {1., 0.5, 0.5, 0., MSQ_SQRT_THREE/2., MSQ_SQRT_THREE/6., 0., 0., MSQ_SQRT_TWO/MSQ_SQRT_THREE};
173  Matrix3D m3(v_tet);
174  tet_M3D = m3 * SIXTH_ROOT_OF_TWO;
175 
176  const double v_hex[] = {1., 0., 0., 0., 1., 0., 0., 0., 1.};
177  Matrix3D m4(v_hex);
178  hex_M3D = m4;
179  }
180 
181 
184  {
185  return Mesquite::cbrt(fabs(det(A)));
186  }
187 
188 
189 
192  {
193  Vector3D a1(A[0][0], A[1][0], A[2][0]);
194  Vector3D a2(A[0][1], A[1][1], A[2][1]);
195  Vector3D a3(A[0][2], A[1][2], A[2][2]);
196 
197  double a1_norm = A.column_length(0);
198  double a2_norm = A.column_length(1);
199  double a3_norm = A.column_length(2);
200 
201  Vector3D a1_x_a2 = a1 * a2;
202  double a1_x_a2_norm = a1_x_a2.length();
203  Vector3D a1_x_a3 = a1 * a3;
204 
205  double nu = Mesquite::cbrt(a1_norm*a2_norm*a3_norm);
206  double det_A = det(A);
207  double fac = nu / Mesquite::cbrt(fabs(det_A));
208 
209  Matrix3D Q;
210 
211  Q[0][0] = fac * 1.;
212  Q[0][1] = fac * a1%a2 / (a1_norm*a2_norm);
213  Q[0][2] = fac * a1%a3 / (a1_norm*a3_norm);
214  Q[1][1] = fac * a1_x_a2_norm / (a1_norm*a2_norm);
215  Q[1][2] = fac * a1_x_a2 % a1_x_a3 / (a1_x_a2_norm * a1_norm * a3_norm);
216  Q[2][2] = fac * det_A / (a1_x_a2_norm*a3_norm);
217 
218  if (!finite(Q[0][0]) || !finite(Q[0][1]) || !finite(Q[0][2]) ||
219  !finite(Q[1][0]) || !finite(Q[1][2]) || !finite(Q[2][2])) {
220  MSQ_SETERR(err)("Numerical error", MsqError::INVALID_STATE);
221  }
222 
223  return Q;
224  }
225 
228  {
229  double a1_norm = A.column_length(0);
230  double a2_norm = A.column_length(1);
231  double a3_norm = A.column_length(2);
232 
233  double nu = Mesquite::cbrt(a1_norm*a2_norm*a3_norm);
234  double fac = 1./nu ;
235  if (!finite(fac)) {
236  MSQ_SETERR(err)("Numerical error", MsqError::INVALID_STATE);
237  }
238 
239  Matrix3D Delta;
240 
241  Delta[0][0] = fac * a1_norm;
242  Delta[1][1] = fac * a2_norm;
243  Delta[2][2] = fac * a3_norm;
244 
245  return Delta;
246  }
247 
248 
249 } //namespace
250 
251 
252 #endif // TargetCalculator_hpp
void compute_default_target_matrices(PatchData &pd, MsqError &err)
Compute the default &quot;isotropic&quot; target matrices that are often used in the computation of reference-b...
virtual AlgorithmType get_algorithm_type()
Return the algorithm type (to avoid RTTI use).
virtual msq_std::string get_name()
Returns the algorithm name.
The Lambda coefficient is the average on the mesh.
Used to hold the error state and return it to the application.
PatchDataParameters & get_all_parameters()
Returns the PatchDataParameters object.
void compute_guide_matrices(enum guide_type type, PatchData &ref_pd, size_t elem_ind, Matrix3D A[], int num, MsqError &err)
Computes the guide corner matrices A for a given element index in the reference patch.
Vector3D is the object that effeciently stores information about about three-deminsional vectors...
Matrix3D compute_V_3D(const Matrix3D &A, MsqError &err)
Each element has a lambda coefficient.
This should be the parent class of all algorithms retrieving information from a MeshSet object...
Matrix3D compute_Q_3D(const Matrix3D &A, MsqError &err)
static double compute_Lambda(const Matrix3D &A, MsqError &err)
Note that this function is static, i.e. it can be used independently of an object.
static const double MSQ_SQRT_TWO
Definition: Mesquite.hpp:122
static void initialize_default_target_matrices(Matrix3D &tri_M3D, Matrix3D &quad_M3D, Matrix3D &tet_M3D, Matrix3D &hex_M3D)
rational * A
Definition: vinci_lass.c:67
void compute_reference_corner_matrices(PatchData &pd, MsqError &err)
Compute the corner matrices for the reference mesh refMesh.
3*3 Matric class, row-oriented, 0-based [i][j] indexing.
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
double column_length(int i) const
returns the column length – i is 0-based.
Base class that provides the interface for computing the target corner matrices used in the context b...
void compute_target_matrices_and_check_det(PatchData &pd, MsqError &err)
This function wraps compute_target_matrices and checks that the determinant of each target is positiv...
double det(const Matrix3D &A)
Matrix3D compute_Delta_3D(const Matrix3D &A, MsqError &err)
object is in an invalid state
double cbrt(double d)
Definition: Mesquite.hpp:182
void reset_reference_meshset(MsqError &err)
Reset the reference mesh so it starts from the first vertex again.
double pow(double value, const Exponent &exp)
The MeshSet class stores one or more Mesquite::Mesh pointers and manages access to the mesh informati...
static const double MSQ_3RT_2_OVER_6RT_3
Definition: Mesquite.hpp:130
virtual ~TargetCalculator()
virtual destructor ensures use of polymorphism during destruction
virtual void compute_target_matrices(PatchData &pd, MsqError &err)=0
This function provides the corner matrices for all elements on the Patch.
virtual double loop_over_mesh(MeshSet &ms, MsqError &err)
This is the &quot;run&quot; function of PatchDataUser. It can do anything really.
static const double MSQ_SQRT_THREE
Definition: Mesquite.hpp:123