CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Attributes
LinearGridInterpolator3D Class Reference

#include <LinearGridInterpolator3D.h>

Public Types

typedef ValueType ReturnType
 
typedef Grid3D::Scalar Scalar
 
typedef Grid3D::ValueType ValueType
 

Public Member Functions

ReturnType interpolate (Scalar a, Scalar b, Scalar c)
 
 LinearGridInterpolator3D (const Grid3D &g)
 
void throwGridInterpolator3DException (void)
 

Private Attributes

const Grid3Dgrid
 
const Grid1Dgrida
 
const Grid1Dgridb
 
const Grid1Dgridc
 

Detailed Description

Linear interpolation in a regular 3D grid.

Author
T. Todorov

Definition at line 23 of file LinearGridInterpolator3D.h.

Member Typedef Documentation

Definition at line 28 of file LinearGridInterpolator3D.h.

Definition at line 27 of file LinearGridInterpolator3D.h.

Definition at line 26 of file LinearGridInterpolator3D.h.

Constructor & Destructor Documentation

LinearGridInterpolator3D::LinearGridInterpolator3D ( const Grid3D g)
inline

Definition at line 30 of file LinearGridInterpolator3D.h.

30  :
31  grid(g), grida(g.grida()), gridb(g.gridb()), gridc(g.gridc()) {}
const Grid1D & grida() const
Definition: Grid3D.h:67
const Grid1D & gridc() const
Definition: Grid3D.h:69
const Grid1D & gridb() const
Definition: Grid3D.h:68

Member Function Documentation

LinearGridInterpolator3D::ValueType LinearGridInterpolator3D::interpolate ( Scalar  a,
Scalar  b,
Scalar  c 
)

Definition at line 14 of file LinearGridInterpolator3D.cc.

References gather_cfg::cout, InterpolationDebug::debug, f, grid, grida, gridb, gridc, i, Grid1D::index(), Grid3D::index(), j, relval_2017::k, Grid1D::node(), Grid1D::nodes(), Grid1D::normalize(), mps_fire::result, alignCSCRings::s, indexGen::s2, Grid3D::stride1(), Grid3D::stride2(), Grid3D::stride3(), lumiQTWidget::t, findQualityFiles::v, and Basic3DVector< T >::v.

Referenced by grid3d_t(), RectangularCartesianMFGrid::uncheckedValueInTesla(), RectangularCylindricalMFGrid::uncheckedValueInTesla(), TrapezoidalCylindricalMFGrid::uncheckedValueInTesla(), TrapezoidalCartesianMFGrid::uncheckedValueInTesla(), and SpecialCylindricalMFGrid::uncheckedValueInTesla().

15 {
16  /*
17  int i = grida.index(a);
18  int j = gridb.index(b);
19  int k = gridc.index(c);
20 
21  if (i==-1 || j==-1 || k==-1) {
22  // point outside of grid validity!
23  throwGridInterpolator3DException();
24  }
25 
26 
27  Scalar s = (a - grida.node(i)) / grida.step();
28  Scalar t = (b - gridb.node(j)) / gridb.step();
29  Scalar u = (c - gridc.node(k)) / gridc.step();
30 
31  */
32 
33  Scalar s, t, u;
34  int i = grida.index(a,s);
35  int j = gridb.index(b,t);
36  int k = gridc.index(c,u);
37 
38  // test range??
39 
40  grida.normalize(i,s);
41  gridb.normalize(j,t);
42  gridc.normalize(k,u);
43 
44 #ifdef DEBUG_LinearGridInterpolator3D
46  using std::cout;
47  using std::endl;
48  cout << "LinearGridInterpolator3D called with a,b,c " << a << "," << b << "," << c << endl;
49  cout <<" i,j,k = " << i << "," << j << "," << k
50  << " s,t,u = " << s << "," << t << "," << u << endl;
51  cout << "Node positions for " << i << "," << j << "," << k << " : "
52  << grida.node(i) << "," << gridb.node(j) << "," << gridc.node(k) << endl;
53  cout << "Node positions for " << i+1 << "," << j+1 << "," << k+1 << " : "
54  << grida.node(i+1) << "," << gridb.node(j+1) << "," << gridc.node(k+1) << endl;
55  cout << "Grid(" << i << "," << j << "," << k << ") = " << grid(i, j, k) << " ";
56  cout << "Grid(" << i << "," << j << "," << k+1 << ") = " << grid(i,j,k+1) << endl;
57  cout << "Grid(" << i << "," << j+1 << "," << k << ") = " << grid(i,j+1,k) << " ";
58  cout << "Grid(" << i << "," << j+1 << "," << k+1 << ") = " << grid(i,j+1,k+1) << endl;
59  cout << "Grid(" << i+1 << "," << j << "," << k << ") = " << grid(i+1,j,k) << " ";
60  cout << "Grid(" << i+1 << "," << j << "," << k+1 << ") = " << grid(i+1,j,k+1) << endl;
61  cout << "Grid(" << i+1 << "," << j+1 << "," << k << ") = " << grid(i+1,j+1,k) << " ";
62  cout << "Grid(" << i+1 << "," << j+1 << "," << k+1 << ") = " << grid(i+1,j+1,k+1) << endl;
63  cout << "number of nodes: " << grida.nodes() << "," << gridb.nodes() << "," << gridc.nodes() << endl;
64 
65 // cout << (1-s)*(1-t)*(1-u)*grid(i, j, k) << " " << (1-s)*(1-t)*u*grid(i, j, k+1) << endl
66 // << (1-s)* t *(1-u)*grid(i, j+1,k) << " " << (1-s)* t *u*grid(i, j+1,k+1) << endl
67 // << s *(1-t)*(1-u)*grid(i+1,j, k) << " " << s *(1-t)*u*grid(i+1,j, k+1) << endl
68 // << s * t *(1-u)*grid(i+1,j+1,k) << " " << s * t *u*grid(i+1,j+1,k+1) << endl;
69  }
70 
71 #endif
72 
73  int ind = grid.index(i,j,k);
74  int s1 = grid.stride1();
75  int s2 = grid.stride2();
76  int s3 = grid.stride3();
77  //chances are this is more numerically precise this way
78 
79 
80 
81  // this code for test to check properly inline of wrapped math...
82 #if defined(CMS_TEST_RAWSSE)
83 
84  __m128 resultSIMD = _mm_mul_ps(_mm_set1_ps((1.f - s) * (1.f - t) * u), _mm_sub_ps(grid(ind + s3).v.vec, grid(ind ).v.vec));
85  resultSIMD = _mm_add_ps(resultSIMD, _mm_mul_ps(_mm_set1_ps((1.f - s) * t * u), _mm_sub_ps(grid(ind + s2 + s3).v.vec, grid(ind + s2).v.vec)));
86  resultSIMD = _mm_add_ps(resultSIMD, _mm_mul_ps(_mm_set1_ps( s * (1.f - t) * u), _mm_sub_ps(grid(ind + s1 + s3).v.vec, grid(ind + s1 ).v.vec)));
87  resultSIMD = _mm_add_ps(resultSIMD, _mm_mul_ps(_mm_set1_ps( s * t * u), _mm_sub_ps(grid(ind + s1 + s2 + s3).v.vec, grid(ind + s1 + s2).v.vec)));
88  resultSIMD = _mm_add_ps(resultSIMD, _mm_mul_ps(_mm_set1_ps((1.f - s) * t ), _mm_sub_ps(grid(ind + s2 ).v.vec, grid(ind ).v.vec)));
89  resultSIMD = _mm_add_ps(resultSIMD, _mm_mul_ps(_mm_set1_ps( s * t ), _mm_sub_ps(grid(ind + s1 + s2 ).v.vec, grid(ind + s1 ).v.vec)));
90  resultSIMD = _mm_add_ps(resultSIMD, _mm_mul_ps(_mm_set1_ps( s ), _mm_sub_ps(grid(ind + s1 ).v.vec, grid(ind ).v.vec)));
91  resultSIMD = _mm_add_ps(resultSIMD, grid(ind ).v.vec);
92 
93  ValueType result; result.v=resultSIMD;
94 
95 
96 #else
97 
98  ValueType result = ((1.f-s)*(1.f-t)*u)*(grid(ind +s3) - grid(ind ));
99  result = result + ((1.f-s)* t *u)*(grid(ind +s2+s3) - grid(ind +s2));
100  result = result + (s *(1.f-t)*u)*(grid(ind+s1 +s3) - grid(ind+s1 ));
101  result = result + (s * t *u)*(grid(ind+s1+s2+s3) - grid(ind+s1+s2));
102  result = result + ( (1.f-s)*t)*(grid(ind +s2 ) - grid(ind ));
103  result = result + ( s *t)*(grid(ind+s1+s2 ) - grid(ind+s1 ));
104  result = result + ( s)*(grid(ind+s1 ) - grid(ind ));
105  result = result + grid(ind );
106 
107 
108 #endif
109 
110 
111 
112  // (1-s)*(1-t)*(1-u)*grid(i, j, k) + (1-s)*(1-t)*u*grid(i, j, k+1) +
113  // (1-s)* t *(1-u)*grid(i, j+1,k) + (1-s)* t *u*grid(i, j+1,k+1) +
114  // s *(1-t)*(1-u)*grid(i+1,j, k) + s *(1-t)*u*grid(i+1,j, k+1) +
115  // s * t *(1-u)*grid(i+1,j+1,k) + s * t *u*grid(i+1,j+1,k+1);
116 
117 
118  return result;
119 
120 
121 }
int i
Definition: DBlmapReader.cc:9
int stride3() const
Definition: Grid3D.h:58
int stride2() const
Definition: Grid3D.h:57
Scalar node(int i) const
Definition: Grid1D.h:27
int index(int i, int j, int k) const
Definition: Grid3D.h:55
tuple s2
Definition: indexGen.py:106
tuple result
Definition: mps_fire.py:84
int nodes() const
Definition: Grid1D.h:24
int j
Definition: DBlmapReader.cc:9
double f[11][100]
int stride1() const
Definition: Grid3D.h:56
static const bool debug
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
void normalize(int &ind, Scalar &f) const
Definition: Grid1D.h:41
tuple cout
Definition: gather_cfg.py:145
int index(Scalar a, Scalar &f) const
Definition: Grid1D.h:34
void LinearGridInterpolator3D::throwGridInterpolator3DException ( void  )

Definition at line 7 of file LinearGridInterpolator3D.cc.

References grida, gridb, gridc, Grid1D::lower(), and Grid1D::upper().

Member Data Documentation

const Grid3D& LinearGridInterpolator3D::grid
private

Definition at line 39 of file LinearGridInterpolator3D.h.

Referenced by interpolate().

const Grid1D& LinearGridInterpolator3D::grida
private

Definition at line 40 of file LinearGridInterpolator3D.h.

Referenced by interpolate(), and throwGridInterpolator3DException().

const Grid1D& LinearGridInterpolator3D::gridb
private

Definition at line 41 of file LinearGridInterpolator3D.h.

Referenced by interpolate(), and throwGridInterpolator3DException().

const Grid1D& LinearGridInterpolator3D::gridc
private

Definition at line 42 of file LinearGridInterpolator3D.h.

Referenced by interpolate(), and throwGridInterpolator3DException().