SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TriCubicHmtScaleFactors.h
Go to the documentation of this file.
1 //
2 // For more information, please see: http://software.sci.utah.edu
3 //
4 // The MIT License
5 //
6 // Copyright (c) 2009 Scientific Computing and Imaging Institute,
7 // University of Utah.
8 //
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 // DEALINGS IN THE SOFTWARE.
27 //
28 /// @file TriCubicHmtScaleFactors.h
29 /// @author Martin Cole, Frank B. Sachse
30 /// @date Mar 01 2005
31 
32 
33 // NOTE: THIS FILE NEEDS TO BE CHANGED: SCALEFACTORS NEED TO BE COMPUTED
34 // AUTOMATICALLY FROM THE MESH. THIS WILL CHANGE IN FUTURE
35 
36 
37 #ifndef CORE_BASIS_TRICUBICHMTSCALEFACTORS_H
38 #define CORE_BASIS_TRICUBICHMTSCALEFACTORS_H 1
39 
42 
43 namespace SCIRun {
44 namespace Core {
45 namespace Basis {
46 
47 /// Class for describing unit geometry of TetCubicHmt
49 public:
52 
53  static int dofs() { return 12; } ///< return degrees of freedom
54 };
55 
56 
57 /// Class for handling of element of type triangle with
58 /// cubic hermitian interpolation with scale factors
59 template <class T>
61  public TriApprox,
62  public TriGaussian3<double>,
63  public TriSamplingSchemes,
65  public TriElementWeights
66 {
67 public:
68  typedef T value_type;
69 
72 
73  static int polynomial_order() { return 3; }
74 
75  /// Note: these are correct for Point interpolation but not for value
76  /// interpolation (Scale factors are missing)
77  template<class VECTOR>
78  inline void get_weights(const VECTOR& coords, double *w) const
79  { get_cubic_weights(coords,w); }
80 
81  template<class VECTOR>
82  inline void get_derivate_weights(const VECTOR& coords, double *w) const
83  { get_cubic_derivate_weights(coords,w); }
84 
85 
86  /// get value at parametric coordinate
87  template <class ElemData, class VECTOR>
88  T interpolate(const VECTOR &coords, const ElemData &cd) const
89  {
90  double w[12];
91  unsigned int elem=cd.elem_index();
92  const double x=static_cast<double>(coords[0]), y=static_cast<double>(coords[1]);
93  const double x2=x*x, x3=x2*x, y2=y*y, y3=y2*y;
94 
95  const double sdx0=this->scalefactors_[elem][0];
96  const double sdx1=this->scalefactors_[elem][0];
97  const double sdx2=this->scalefactors_[elem][0];
98 
99  const double sdy0=this->scalefactors_[elem][1];
100  const double sdy1=this->scalefactors_[elem][1];
101  const double sdy2=this->scalefactors_[elem][1];
102 
103  const double sdxy0=this->scalefactors_[elem][0]*this->scalefactors_[elem][1];
104  const double sdxy1=this->scalefactors_[elem][0]*this->scalefactors_[elem][1];
105  const double sdxy2=this->scalefactors_[elem][0]*this->scalefactors_[elem][1];
106 
107 
108  w[0] = (-1 + x + y)*(-1 - x + 2*x2 - y - 2*x*y + 2*y2);
109  w[1] = x*(1 - 2*x + x2 - 3*y2 + 2*y3)*sdx0;
110  w[2] = y*(1 - 3*x2 + 2*x3 - 2*y + y2)*sdy0;
111  w[3] = x*y*(1 - 2*x + x2 - 2*y + y2)*sdxy0;
112  w[4] = -(x2*(-3 + 2*x));
113  w[5] = (-1 + x)*x2*sdx1;
114  w[6] = -(x2*(-3 + 2*x)*y)*sdy1;
115  w[7] = (-1 + x)*x2*y*sdxy1;
116  w[8] = -y2*(-3 + 2*y);
117  w[9] = -(x*y2*(-3 + 2*y))*sdx2;
118  w[10] = (-1 + y)*y2*sdy2;
119  w[11] = x*(-1 + y)*y2*sdxy2;
120 
121  return (T)(w[0] * cd.node0()
122  +w[1] * this->derivs_[cd.node0_index()][0]
123  +w[2] * this->derivs_[cd.node0_index()][1]
124  +w[3] * this->derivs_[cd.node0_index()][2]
125  +w[4] * cd.node1()
126  +w[5] * this->derivs_[cd.node1_index()][0]
127  +w[6] * this->derivs_[cd.node1_index()][1]
128  +w[7] * this->derivs_[cd.node1_index()][2]
129  +w[8] * cd.node2()
130  +w[9] * this->derivs_[cd.node2_index()][0]
131  +w[10] * this->derivs_[cd.node2_index()][1]
132  +w[11] * this->derivs_[cd.node2_index()][2]);
133  }
134 
135 
136 
137  /// get first derivative at parametric coordinate
138  template <class ElemData, class VECTOR1, class VECTOR2>
139  void derivate(const VECTOR1 &coords, const ElemData &cd,
140  VECTOR2 &derivs) const
141  {
142  double w[24];
143  unsigned elem=cd.elem_index();
144  const double x=static_cast<double>(coords[0]), y=static_cast<double>(coords[1]);
145  const double x2=x*x, x3=x2*x, y2=y*y;
146  const double y12=(y-1)*(y-1);
147 
148  const double sdx0=this->scalefactors_[elem][0];
149  const double sdx1=this->scalefactors_[elem][0];
150  const double sdx2=this->scalefactors_[elem][0];
151 
152  const double sdy0=this->scalefactors_[elem][1];
153  const double sdy1=this->scalefactors_[elem][1];
154  const double sdy2=this->scalefactors_[elem][1];
155 
156  const double sdxy0=this->scalefactors_[elem][0]*this->scalefactors_[elem][1];
157  const double sdxy1=this->scalefactors_[elem][0]*this->scalefactors_[elem][1];
158  const double sdxy2=this->scalefactors_[elem][0]*this->scalefactors_[elem][1];
159 
160  w[0] = 6*(-1 + x)*x;
161  w[1] = (-4*x + 3*x2 + y12*(1 + 2*y))*sdx0;
162  w[2] = 6*(-1 + x)*x*y*sdy0;
163  w[3] = (-4*x + 3*x2 + y12)*y*sdxy0;
164  w[4] = -6*(-1 + x)*x;
165  w[5] = x*(-2 + 3*x)*sdx1;
166  w[6] = -6*(-1 + x)*x*y*sdy1;
167  w[7] = x*(-2 + 3*x)*y*sdxy1;
168  w[8] = 0;
169  w[9] = (3 - 2*y)*y2*sdx2;
170  w[10] = 0;
171  w[11] = (-1 + y)*y2*sdxy2;
172 
173  w[12] = 6*(-1 + y)*y;
174  w[13] = 6*x*(-1 + y)*y*sdx0;
175  w[14] = (1 - 3*x2 + 2*x3 - 4*y + 3*y2)*sdy0;
176  w[15] = x*(1 - 2*x + x2 - 4*y + 3*y2)*sdxy0;
177  w[16] = 0;
178  w[17] = 0;
179  w[18] = (3 - 2*x)*x2*sdy1;
180  w[19] = (-1 + x)*x2*sdxy1;
181  w[20] = -6*(-1 + y)*y;
182  w[21] = -6*x*(-1 + y)*sdx2;
183  w[22] = y*(-2 + 3*y)*sdy2;
184  w[23] = x*y*(-2 + 3*y)*sdxy2;
185  derivs.resize(2);
186 
187  derivs[0]=static_cast<typename VECTOR2::value_type>(w[0] * cd.node0()
188  +w[1] * this->derivs_[cd.node0_index()][0]
189  +w[2] * this->derivs_[cd.node0_index()][1]
190  +w[3] * this->derivs_[cd.node0_index()][2]
191  +w[4] * cd.node1()
192  +w[5] * this->derivs_[cd.node1_index()][0]
193  +w[6] * this->derivs_[cd.node1_index()][1]
194  +w[7] * this->derivs_[cd.node1_index()][2]
195  +w[8] * cd.node2()
196  +w[9] * this->derivs_[cd.node2_index()][0]
197  +w[10] * this->derivs_[cd.node2_index()][1]
198  +w[11] * this->derivs_[cd.node2_index()][2]);
199 
200  derivs[1]=static_cast<typename VECTOR2::value_type>(w[12] * cd.node0()
201  +w[13] * this->derivs_[cd.node0_index()][0]
202  +w[14] * this->derivs_[cd.node0_index()][1]
203  +w[15] * this->derivs_[cd.node0_index()][2]
204  +w[16] * cd.node1()
205  +w[17] * this->derivs_[cd.node1_index()][0]
206  +w[18] * this->derivs_[cd.node1_index()][1]
207  +w[19] * this->derivs_[cd.node1_index()][2]
208  +w[20] * cd.node2()
209  +w[21] * this->derivs_[cd.node2_index()][0]
210  +w[22] * this->derivs_[cd.node2_index()][1]
211  +w[23] * this->derivs_[cd.node2_index()][2]);
212  }
213 
214  /// get the parametric coordinate for value within the element.
215  template <class ElemData, class VECTOR>
216  bool get_coords(VECTOR &coords, const T& value,
217  const ElemData &cd) const
218  {
220  return CL.get_coords(this, coords, value, cd);
221  }
222 
223  /// get arc length for edge
224  template <class ElemData>
225  double get_arc_length(const unsigned edge, const ElemData &cd) const
226  {
227  return get_arc2d_length<CrvGaussian2<double> >(this, edge, cd);
228  }
229 
230  /// get area
231  template <class ElemData>
232  double get_area(const unsigned face, const ElemData &cd) const
233  {
234  return get_area2<TriGaussian3<double> >(this, face, cd);
235  }
236 
237  /// get volume
238  template <class ElemData>
239  double get_volume(const ElemData & /* cd */) const
240  {
241  return 0.;
242  }
243 
244 
245  static const std::string type_name(int n = -1);
246 
247 
248  virtual void io (Piostream& str);
249 
250 };
251 
252 
253 
254 
255 
256 template <class T>
257 const std::string
259 {
260  ASSERT((n >= -1) && n <= 1);
261  if (n == -1)
262  {
263  static const std::string name = TypeNameGenerator::make_template_id(type_name(0), type_name(1));
264  return name;
265  }
266  else if (n == 0)
267  {
268  static const std::string nm("TriCubicHmtScaleFactors");
269  return nm;
270  } else {
271  return find_type_name((T *)0);
272  }
273 }
274 
275 
276 
277 
278 
279 }}
280 
281 template <class T>
283 {
284  static TypeDescription* td = 0;
285  if(!td){
286  const TypeDescription *sub = get_type_description((T*)0);
288  (*subs)[0] = sub;
289  td = new TypeDescription("TriCubicHmtScaleFactors", subs,
290  std::string(__FILE__),
291  "SCIRun",
293  }
294  return td;
295 }
296 
298 template <class T>
299 void
301 {
302  stream.begin_class(get_type_description(this)->get_name(),
304  Pio(stream, this->derivs_);
305  Pio(stream, this->scalefactors_);
306  stream.end_class();
307 }
308 }
309 
310 #endif
const int TRICUBICHMTSCALEFACTORS_VERSION
Definition: TriCubicHmtScaleFactors.h:297
void get_cubic_derivate_weights(const VECTOR &coords, double *w) const
get derivative weight factors at parametric coordinate
Definition: TriElementWeights.h:116
void get_weights(const VECTOR &coords, double *w) const
Definition: TriCubicHmtScaleFactors.h:78
bool get_coords(const ElemBasis *pEB, VECTOR &coords, const T &value, const ElemData &cd) const
find value in interpolation for given value
Definition: TriLinearLgn.h:194
void derivate(const VECTOR1 &coords, const ElemData &cd, VECTOR2 &derivs) const
get first derivative at parametric coordinate
Definition: TriCubicHmtScaleFactors.h:139
Definition: Persistent.h:89
Class for creating geometrical approximations of Tri meshes.
Definition: TriLinearLgn.h:109
T interpolate(const VECTOR &coords, const ElemData &cd) const
get value at parametric coordinate
Definition: TriCubicHmtScaleFactors.h:88
Definition: TypeDescription.h:45
std::vector< const TypeDescription * > td_vec
Definition: TypeDescription.h:56
#define ASSERT(condition)
Definition: Assert.h:110
Class for describing unit geometry of TetCubicHmt.
Definition: TriCubicHmtScaleFactors.h:48
virtual int begin_class(const std::string &name, int current_version)
Definition: Persistent.cc:143
static int dofs()
return degrees of freedom
Definition: TriCubicHmtScaleFactors.h:53
const string find_type_name(float *)
Definition: TypeName.cc:63
const char * name[]
Definition: BoostGraphExampleTests.cc:87
Persistent i/o for STL containers.
std::vector< std::vector< double > > scalefactors_
Definition: Basis.h:161
static int polynomial_order()
Definition: TriCubicHmtScaleFactors.h:73
void get_cubic_weights(const VECTOR &coords, double *w) const
Definition: TriElementWeights.h:95
void get_derivate_weights(const VECTOR &coords, double *w) const
Definition: TriCubicHmtScaleFactors.h:82
static const std::string type_name(int n=-1)
Definition: TriCubicHmtScaleFactors.h:258
static const std::string make_template_id(const std::string &templateName, const std::string &templateParam)
Definition: TypeName.h:62
double get_arc_length(const unsigned edge, const ElemData &cd) const
get arc length for edge
Definition: TriCubicHmtScaleFactors.h:225
double get_area(const unsigned face, const ElemData &cd) const
get area
Definition: TriCubicHmtScaleFactors.h:232
Class for describing unit geometry of TriLinearLgn.
Definition: TriLinearLgn.h:46
T value_type
Definition: TriCubicHmtScaleFactors.h:68
Definition: TriElementWeights.h:36
double get_volume(const ElemData &) const
get volume
Definition: TriCubicHmtScaleFactors.h:239
void Pio(Piostream &stream, Array1< T > &array)
Definition: Array1.h:65
std::vector< std::vector< T > > derivs_
Definition: Basis.h:160
virtual void end_class()
Definition: Persistent.cc:178
TriCubicHmtScaleFactors()
Definition: TriCubicHmtScaleFactors.h:70
virtual ~TriCubicScaleFactorsHmtUnitElement()
Definition: TriCubicHmtScaleFactors.h:51
Definition: TriSamplingSchemes.h:43
int n
Definition: eab.py:9
virtual void io(Piostream &str)
Definition: TriCubicHmtScaleFactors.h:300
bool get_coords(VECTOR &coords, const T &value, const ElemData &cd) const
get the parametric coordinate for value within the element.
Definition: TriCubicHmtScaleFactors.h:216
Class with weights and coordinates for 3rd order Gaussian integration.
Definition: TriLinearLgn.h:292
virtual ~TriCubicHmtScaleFactors()
Definition: TriCubicHmtScaleFactors.h:71
Definition: TriLinearLgn.h:185
Definition: TriCubicHmtScaleFactors.h:60
TriCubicScaleFactorsHmtUnitElement()
Definition: TriCubicHmtScaleFactors.h:50
Definition: TypeDescription.h:49
const TypeDescription * get_type_description(Core::Basis::ConstantBasis< T > *)
Definition: Constant.h:209