www.cemf.ir
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("r1P",numDiv + 1), r2P("r1P",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
get the value of data entry or if not found, set the value to setVal
Definition: dictionary.hpp:415
pFlow::real
float real
Definition: builtinTypes.hpp:45
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::line
Definition: line.hpp:36
pFlow::zAxis
Definition: zAxis.hpp:38
pFlow::cos
Vector< T, Allocator > cos(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:93
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)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::realx3
triple< real > realx3
Definition: types.hpp:43
pFlow::cylinderWall::cylinderWall
cylinderWall()
Definition: cylinderWall.cpp:106
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::line::point
INLINE_FUNCTION_HD realx3 point(real t) const
Definition: line.hpp:102
pFlow::cylinderWall::readCylinderWall
bool readCylinderWall(const dictionary &dict)
Definition: cylinderWall.cpp:6
pFlow::realx3x3
triple< realx3 > realx3x3
Definition: types.hpp:47
pFlow::zAxis::transferBackZ
realx3 transferBackZ(const realx3 &p) const
Definition: zAxis.cpp:50
pFlow::dictionary::getVal
T getVal(const word &keyword) const
get the value of data entry
Definition: dictionary.hpp:379
cylinderWall.hpp
pFlow::sin
Vector< T, Allocator > sin(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:92
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:66
pFlow::Pi
const real Pi
Definition: numericConstants.hpp:30
pFlow::triple< real >
pFlow::Vector< realx3 >
pFlow::Wall
Definition: Wall.hpp:41
line.hpp
pFlow::dictionary
Dictionary holds a set of data entries or sub-dictionaries that are enclosed in a curely braces or ar...
Definition: dictionary.hpp:67