zAxis.cpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 
22 #include "zAxis.hpp"
23 
24 
25 pFlow::zAxis::zAxis(const realx3 &p1, const realx3 &p2) :
26 p1_(p1),
27 p2_(p2)
28 {
29  n_ = p2-p1;
30  auto len = pFlow::length(n_);
31 
32  if(len < smallValue )
33  {
34  fatalExit;
35  }
36  n_ /= len;
37 
39 }
40 
42 {
43  real pp[4][1] = {p.x(), p.y(), p.z(), 1.0};
44  real pn[4][1];
45 
46  MatMul(Trans_z_xz_P1_, pp, pn);
47 
48  return realx3(
49  pn[0][0],
50  pn[1][0],
51  pn[2][0]
52  );
53 
54 }
55 
57 {
58  real pp[4][1] = { p.x(), p.y(), p.z(), 1.0 };
59  real pn[4][1];
60 
61  MatMul(ITrans_P1_xz_z_, pp, pn);
62 
63  return realx3(
64  pn[0][0],
65  pn[1][0],
66  pn[2][0]
67  );
68 }
69 
70 
72 {
73 
74  // transfering point p1 to the origin
75  real TransP1[4][4] =
76  {
77  1.0, 0.0, 0.0, -p1_.x(),
78  0.0, 1.0, 0.0, -p1_.y(),
79  0.0, 0.0, 1.0, -p1_.z(),
80  0.0, 0.0, 0.0, 1.0
81  };
82 
83  // for transformation back
84  real ITransP1[4][4] =
85  {
86  1.0, 0.0, 0.0, p1_.x(),
87  0.0, 1.0, 0.0, p1_.y(),
88  0.0, 0.0, 1.0, p1_.z(),
89  0.0, 0.0, 0.0, 1.0
90  };
91 
92 
93  real u = n_.x();
94  real v = n_.y();
95  real w = n_.z();
96  real u2v2 = sqrt(u*u + v*v);
97 
98  //correcting the transformation matrix in the case of coincidence with z - axis
99  if ( equal(w,1.0) )
100  {
101  assignMat(TransP1 , Trans_z_xz_P1_);
102  assignMat(ITransP1, ITrans_P1_xz_z_);
103  return;
104  }
105 
106  u2v2 = max(smallValue, u2v2);
107 
108  real TransXZ[4][4] =
109  {
110  u / u2v2, v / u2v2, 0.0, 0.0,
111  -v / u2v2, u / u2v2, 0.0, 0.0,
112  0.0, 0.0, 1.0, 0.0,
113  0.0, 0.0, 0.0, 1.0
114  };
115 
116  real TransZ[4][4] =
117  {
118  w, 0.0, -u2v2, 0.0,
119  0.0, 1.0, 0.0, 0.0,
120  u2v2, 0.0, w, 0.0,
121  0.0, 0.0, 0.0, 1.0
122  };
123 
124  real temp[4][4];
125  // creat transformation matrix to transfer point from line axis to z-axis
126  MatMul(TransXZ, TransP1, temp);
127  MatMul(TransZ, temp, Trans_z_xz_P1_);
128 
129 
130  real ITransXZ[4][4] =
131  {
132  u / u2v2, -v / u2v2, 0.0, 0.0,
133  +v / u2v2, u / u2v2, 0.0, 0.0,
134  0.0, 0.0, 1.0, 0.0,
135  0.0, 0.0, 0.0, 1.0
136  };
137 
138  real ITransZ[4][4] =
139  {
140  w, 0.0, +u2v2, 0.0,
141  0.0, 1.0, 0.0, 0.0,
142  -u2v2, 0.0, w, 0.0,
143  0.0, 0.0, 0.0, 1.0
144  };
145 
146  // creat transformation matrix to transfer point to from z-axis to line axis
147  MatMul(ITransXZ, ITransZ, temp);
148  MatMul(ITransP1, temp, ITrans_P1_xz_z_);
149 
150 }
pFlow::MatMul
void MatMul(T(&A)[nRow][nInner], T(&B)[nInner][nCol], T(&C)[nRow][nCol])
Definition: zAxis.hpp:73
pFlow::zAxis::makeTransMatrix
void makeTransMatrix()
Definition: zAxis.cpp:71
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::smallValue
const real smallValue
Definition: numericConstants.hpp:33
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::zAxis::transferBackZ
realx3 transferBackZ(const realx3 &p)
Definition: zAxis.cpp:56
pFlow::zAxis::zAxis
zAxis(const realx3 &lp1, const realx3 &lp2)
Definition: zAxis.cpp:25
pFlow::realx3
triple< real > realx3
Definition: types.hpp:48
pFlow::triple::y
INLINE_FUNCTION_HD T & y()
Definition: triple.hpp:141
length
INLINE_FUNCTION_HD T length(const triple< T > &v1)
pFlow::zAxis::transferToZ
realx3 transferToZ(const realx3 &p)
Definition: zAxis.cpp:41
pFlow::triple::z
INLINE_FUNCTION_HD T & z()
Definition: triple.hpp:144
pFlow::max
T max(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:164
pFlow::zAxis::n_
realx3 n_
Definition: zAxis.hpp:63
pFlow::triple::x
INLINE_FUNCTION_HD T & x()
Definition: triple.hpp:138
pFlow::sqrt
INLINE_FUNCTION_HD real sqrt(real x)
Definition: math.hpp:148
pFlow::triple< real >
zAxis.hpp
pFlow::equal
INLINE_FUNCTION_HD bool equal(const real &s1, const real &s2)
Definition: bTypesFunctions.hpp:188
pFlow::assignMat
void assignMat(T(&A)[nRow][nCol], T(&B)[nRow][nCol])
Definition: zAxis.hpp:91