cylinder.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 "cylinder.hpp"
23 #include "zAxis.hpp"
24 
27 {
28 
29  auto p1p2 = p2_ - p1_;
30 
31  if( p1p2.length() > smallValue )
32  {
33  axisVector2_ = dot(p1p2,p1p2);
34  axisVector_ = p1p2;
35 
36  }else
37  {
38  return false;
39  }
40 
41  zAxis zA(p1_,p2_);
42 
43  realx3 minPinZ(-sqrt(radius2_), -sqrt(radius2_), 0.0);
45 
46  minPoint_ = zA.transferBackZ(minPinZ);
47  maxPoint_ = zA.transferBackZ(maxPinZ);
48 
49  return true;
50 }
51 
54  const realx3& p1,
55  const realx3& p2,
56  const real radius)
57 :
58  p1_(p1),
59  p2_(p2),
60  radius2_(radius*radius)
61 {
62  if(!calculateParams())
63  {
65  "error in the input parameters for cylinder"<<endl;
66  fatalExit;
67  }
68 }
69 
72 (
73  const dictionary & dict
74 )
75 :
76  p1_
77  (
78  dict.getVal<realx3>("p1")
79  ),
80  p2_
81  (
82  dict.getVal<realx3>("p2")
83  )
84 {
85  auto rad = dict.getVal<real>("radius");
86  radius2_= rad*rad;
87 
88  if(!calculateParams())
89  {
91  "error in the input parameters for cylinder in dictionary "<< dict.globalName()<<endl;
92  fatalExit;
93  }
94 
95 }
96 
99 (
100  iIstream& is
101 )
102 {
103  if( !read(is))
104  {
105  ioErrorInFile(is.name(), is.lineNumber())<<
106  "error in reading cylinder from file. \n";
107  fatalExit;
108  }
109 }
110 
111 
114 {
115  if(!is.nextData<realx3>("p1", p1_)) return false;
116  if(!is.nextData<realx3>("p2", p2_)) return false;
117  real rad;
118  if(!is.nextData<real>("radius", rad)) return false;
119  radius2_ =rad*rad;
120  return true;
121 }
122 
125 {
126  os.writeWordEntry("p1", p1_);
127  os.writeWordEntry("p2", p2_);
128  os.writeWordEntry("radius", sqrt(radius2_));
129  return os.check(FUNCTION_NAME);
130 }
131 
134 (
135  const dictionary& dict
136 )
137 {
138  p1_ = dict.getVal<realx3>("p1");
139  p2_ = dict.getVal<realx3>("p2");
140  auto rad = dict.getVal<real>("radius");
141  radius2_ = rad*rad;
142  return true;
143 }
144 
147 (
148  dictionary& dict
149 )const
150 {
151  if(!dict.add("p1", p1_))
152  {
154  " error in writing p1 to dictionary "<<dict.globalName()<<endl;
155  return false;
156  }
157 
158  if(!dict.add("p2", p2_))
159  {
161  " error in writing p2 to dictionary "<<dict.globalName()<<endl;
162  return false;
163  }
164 
165  if(!dict.add("radius", sqrt(radius2_)) )
166  {
168  " error in writing radius to dictionary "<<dict.globalName()<<endl;
169  return false;
170  }
171 
172  return true;
173 }
174 
177 {
178  if(! b.read(is))
179  {
180  ioErrorInFile(is.name(), is.lineNumber())<<
181  "error in reading cylinder. \n";
182  fatalExit;
183  }
184  return is;
185 }
186 
189 {
190 
191  if(! b.write(os))
192  {
193  ioErrorInFile(os.name(), os.lineNumber())<<
194  "error in writing cylinder. \n";
195  fatalExit;
196  }
197  return os;
198 }
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::cylinder::write
FUNCTION_H bool write(iOstream &os) const
Definition: cylinder.cpp:124
pFlow::zAxis
Definition: zAxis.hpp:42
pFlow::zAxis::transferBackZ
realx3 transferBackZ(const realx3 &p)
Definition: zAxis.cpp:56
pFlow::cylinder::maxPoint_
realx3 maxPoint_
Definition: cylinder.hpp:51
FUNCTION_NAME
#define FUNCTION_NAME
Definition: pFlowMacros.hpp:29
pFlow::dictionary::globalName
virtual word globalName() const
Definition: dictionary.cpp:349
pFlow::dictionary::add
bool add(const word &keyword, const float &v)
Definition: dictionary.cpp:422
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
pFlow::IOstream::check
virtual bool check(const char *operation) const
Definition: IOstream.cpp:42
FUNCTION_H
#define FUNCTION_H
Definition: pFlowMacros.hpp:58
dot
INLINE_FUNCTION_HD T dot(const quadruple< T > &oprnd1, const quadruple< T > &oprnd2)
pFlow::cylinder
Definition: cylinder.hpp:32
pFlow::cylinder::axisVector2_
real axisVector2_
Definition: cylinder.hpp:47
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::cylinder::p2_
realx3 p2_
Definition: cylinder.hpp:40
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::iIstream::nextData
bool nextData(const word &keyword, T &data)
Definition: iIstreamI.hpp:81
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
pFlow::cylinder::cylinder
FUNCTION_H cylinder(const realx3 &p1, const realx3 &p2, const real radius)
Definition: cylinder.cpp:53
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::IOstream::name
virtual const word & name() const
Definition: IOstream.cpp:31
pFlow::dictionary::getVal
T getVal(const word &keyword) const
Definition: dictionary.hpp:309
pFlow::cylinder::radius2_
real radius2_
Definition: cylinder.hpp:43
pFlow::cylinder::p1_
realx3 p1_
Definition: cylinder.hpp:37
pFlow::cylinder::read
FUNCTION_H bool read(iIstream &is)
Definition: cylinder.cpp:113
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Definition: error.hpp:49
pFlow::cylinder::calculateParams
FUNCTION_H bool calculateParams()
Definition: cylinder.cpp:26
pFlow::cylinder::axisVector_
realx3 axisVector_
Definition: cylinder.hpp:45
pFlow::IOstream::lineNumber
int32 lineNumber() const
Definition: IOstream.hpp:187
pFlow::cylinder::minPoint_
realx3 minPoint_
Definition: cylinder.hpp:49
cylinder.hpp
pFlow::sqrt
INLINE_FUNCTION_HD real sqrt(real x)
Definition: math.hpp:148
pFlow::triple< real >
zAxis.hpp
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::iOstream::writeWordEntry
iOstream & writeWordEntry(const word &key, const T &value)
Definition: iOstream.hpp:217
pFlow::dictionary
Definition: dictionary.hpp:38