cylinderWall.cpp
Go to the documentation of this file.
1 #include "cylinderWall.hpp"
2 #include "Vectors.hpp"
3 #include "line.hpp"
4 
5 
7 {
8  auto p1 = dict.getVal<realx3>("p1");
9  auto p2 = dict.getVal<realx3>("p2");
10  auto radius1 = dict.getVal<real>("radius1");
11  auto radius2 = dict.getVal<real>("radius2") ;
12 
13  int32 resolution = dict.getValOrSet("resolution", 24 );
14  int32 zResolution = dict.getValOrSet("zResolution", 1);
15 
16 
17  triangles_.clear();
18  triangles_.reserve(2*resolution*zResolution);
19 
20 
21  line cylAxis(p1, p2);
22  auto lp1 = p1;
23 
24  auto dt = static_cast<real>(1.0/zResolution);
25  real t = 0;
26  for(int32 i=0; i<zResolution; i++)
27  {
28  t += dt;
29  auto lp2 = cylAxis.point(t);
30  if(!createCylinder(lp1, lp2, radius1, radius2, resolution))
31  return false;
32 
33  lp1 = lp2;
34  }
35 
36  return true;
37 }
38 
40  const realx3& p1,
41  const realx3& p2,
42  real rad1,
43  real rad2,
44  int32 numDiv)
45 {
46 
47  zAxis zAx(p1, p2);
48 
49  real L = zAx.length();
50 
51 
52  realx3Vector r1P(numDiv + 1), r2P(numDiv + 1);
53  real dTheta = 2 * Pi / numDiv;
54  real theta = 0;
55 
56  for (int32 i = 0; i < numDiv + 1; i++)
57  {
58  r1P[i] = realx3(rad1*cos(theta), rad1*sin(theta), 0);
59  r2P[i] = realx3(rad2*cos(theta), rad2*sin(theta), L);
60  theta += dTheta;
61  }
62 
63  // transferring back all points to the original axis of cylinder
64  for (int32 i = 0; i < numDiv + 1; i++)
65  {
66  r1P[i] = zAx.transferBackZ(r1P[i]);
67  r2P[i] = zAx.transferBackZ(r2P[i]);
68  }
69 
70  realx3 norm;
71  for (int32 i = 0; i < numDiv; i++)
72  {
73  realx3 p1 = r1P[i];
74  realx3 p2 = r2P[i];
75  realx3 p3 = r2P[i + 1];
76  realx3 p4 = r1P[i + 1];
77 
78  if(checkNormalVec(p1, p2, p3, norm))
79  {
80  triangles_.push_back(realx3x3(p1, p2, p3));
81  }
82  else
83  {
85  "planner input triangle: "<<realx3x3(p1, p2, p3)<<endl;
86  return false;
87  }
88 
89  if (checkNormalVec(p3, p4, p1, norm))
90  {
91  triangles_.push_back(realx3x3(p3, p4, p1));
92  }
93  else
94  {
96  "planner input triangle: "<<realx3x3(p3, p4, p1)<<endl;
97  return false;
98  }
99 
100  }
101 
102  return true;
103 }
104 
105 
107 {}
108 
109 
111  const dictionary& dict
112 )
113 :
114  Wall(dict)
115 {
116  if( !readCylinderWall(dict) )
117  {
118  fatalExit;
119  }
120 }
pFlow::Wall::triangles_
std::vector< realx3x3 > triangles_
Definition: Wall.hpp:45
pFlow::dictionary::getValOrSet
T getValOrSet(const word &keyword, const T &setVal) const
Definition: dictionary.hpp:325
pFlow::real
float real
Definition: builtinTypes.hpp:46
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::line
Definition: line.hpp:36
pFlow::zAxis
Definition: zAxis.hpp:42
pFlow::zAxis::transferBackZ
realx3 transferBackZ(const realx3 &p)
Definition: zAxis.cpp:56
pFlow::cos
INLINE_FUNCTION_HD real cos(real x)
Definition: math.hpp:178
pFlow::sin
INLINE_FUNCTION_HD real sin(real x)
Definition: math.hpp:168
Vectors.hpp
pFlow::checkNormalVec
bool checkNormalVec(const realx3 &p1, const realx3 &p2, const realx3 &p3, realx3 &norm)
Definition: Wall.cpp:88
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
pFlow::realx3
triple< real > realx3
Definition: types.hpp:48
pFlow::cylinderWall::cylinderWall
cylinderWall()
Definition: cylinderWall.cpp:106
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::line::point
INLINE_FUNCTION_HD realx3 point(real t) const
Definition: line.hpp:94
pFlow::cylinderWall::readCylinderWall
bool readCylinderWall(const dictionary &dict)
Definition: cylinderWall.cpp:6
pFlow::realx3x3
triple< realx3 > realx3x3
Definition: types.hpp:54
pFlow::dictionary::getVal
T getVal(const word &keyword) const
Definition: dictionary.hpp:309
cylinderWall.hpp
pFlow::cylinderWall::createCylinder
bool createCylinder(const realx3 &p1, const realx3 &p2, real rad1, real rad2, int32 numDiv)
Definition: cylinderWall.cpp:39
pFlow::zAxis::length
real length() const
Definition: zAxis.hpp:48
pFlow::Pi
const real Pi
Definition: numericConstants.hpp:32
pFlow::triple< real >
pFlow::Vector< realx3 >
pFlow::Wall
Definition: Wall.hpp:41
line.hpp
pFlow::dictionary
Definition: dictionary.hpp:38