www.cemf.ir
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 #include "math.hpp"
22 #include "cylinder.hpp"
23 #include "zAxis.hpp"
24 #include "streams.hpp"
25 
28 {
29 
30  auto p1p2 = p2_ - p1_;
31 
32  if( p1p2.length() > smallValue )
33  {
34  axisVector2_ = dot(p1p2,p1p2);
35  axisVector_ = p1p2;
36 
37  }else
38  {
39  return false;
40  }
41 
42  zAxis zA(p1_,p2_);
43 
44  realx3 minPinZ(-sqrt(radius2_), -sqrt(radius2_), 0.0);
46 
47  auto minp = zA.transferBackZ(minPinZ);
48  auto maxp = zA.transferBackZ(maxPinZ);
49 
50  minPoint_ = min(minp, maxp);
51  maxPoint_ = max(minp, maxp);
52 
53  return true;
54 }
55 
58  const realx3& p1,
59  const realx3& p2,
60  const real radius)
61 :
62  p1_(p1),
63  p2_(p2),
64  radius2_(radius*radius)
65 {
66  if(!calculateParams())
67  {
69  "error in the input parameters for cylinder"<<endl;
70  fatalExit;
71  }
72 }
73 
76 (
77  const dictionary & dict
78 )
79 :
80  p1_
81  (
82  dict.getVal<realx3>("p1")
83  ),
84  p2_
85  (
86  dict.getVal<realx3>("p2")
87  )
88 {
89  auto rad = dict.getVal<real>("radius");
90  radius2_= rad*rad;
91 
92  if(!calculateParams())
93  {
95  "error in the input parameters for cylinder in dictionary "<< dict.globalName()<<endl;
96  fatalExit;
97  }
98 
99 }
100 
103 (
104  iIstream& is
105 )
106 {
107  if( !read(is))
108  {
109  ioErrorInFile(is.name(), is.lineNumber())<<
110  "error in reading cylinder from file. \n";
111  fatalExit;
112  }
113 }
114 
115 
118 {
119  if(!is.nextData<realx3>("p1", p1_)) return false;
120  if(!is.nextData<realx3>("p2", p2_)) return false;
121  real rad;
122  if(!is.nextData<real>("radius", rad)) return false;
123  radius2_ =rad*rad;
124  return true;
125 }
126 
129 {
130  os.writeWordEntry("p1", p1_);
131  os.writeWordEntry("p2", p2_);
132  os.writeWordEntry("radius", sqrt(radius2_));
133  return os.check(FUNCTION_NAME);
134 }
135 
138 (
139  const dictionary& dict
140 )
141 {
142  p1_ = dict.getVal<realx3>("p1");
143  p2_ = dict.getVal<realx3>("p2");
144  auto rad = dict.getVal<real>("radius");
145  radius2_ = rad*rad;
146  return true;
147 }
148 
151 (
152  dictionary& dict
153 )const
154 {
155  if(!dict.add("p1", p1_))
156  {
158  " error in writing p1 to dictionary "<<dict.globalName()<<endl;
159  return false;
160  }
161 
162  if(!dict.add("p2", p2_))
163  {
165  " error in writing p2 to dictionary "<<dict.globalName()<<endl;
166  return false;
167  }
168 
169  if(!dict.add("radius", sqrt(radius2_)) )
170  {
172  " error in writing radius to dictionary "<<dict.globalName()<<endl;
173  return false;
174  }
175 
176  return true;
177 }
178 
181 {
182  if(! b.read(is))
183  {
184  ioErrorInFile(is.name(), is.lineNumber())<<
185  "error in reading cylinder. \n";
186  fatalExit;
187  }
188  return is;
189 }
190 
193 {
194 
195  if(! b.write(os))
196  {
197  ioErrorInFile(os.name(), os.lineNumber())<<
198  "error in writing cylinder. \n";
199  fatalExit;
200  }
201  return os;
202 }
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::smallValue
const real smallValue
Definition: numericConstants.hpp:31
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::cylinder::write
FUNCTION_H bool write(iOstream &os) const
Definition: cylinder.cpp:128
pFlow::zAxis
Definition: zAxis.hpp:38
pFlow::sqrt
Vector< T, Allocator > sqrt(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:90
pFlow::cylinder::maxPoint_
realx3 maxPoint_
Definition: cylinder.hpp:51
FUNCTION_NAME
#define FUNCTION_NAME
Definition: pFlowMacros.hpp:29
pFlow::max
T max(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:79
pFlow::dictionary::globalName
virtual word globalName() const
global name of entry, separated with dots
Definition: dictionary.cpp:356
pFlow::dictionary::add
bool add(const word &keyword, const float &v)
add a float dataEntry
Definition: dictionary.cpp:435
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.cpp:42
FUNCTION_H
#define FUNCTION_H
Definition: pFlowMacros.hpp:62
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
Interface class for any input stream
Definition: iIstream.hpp:37
pFlow::cylinder::p2_
realx3 p2_
Definition: cylinder.hpp:40
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::iIstream::nextData
bool nextData(const word &keyword, T &data)
read the data next to keword keyword data; check the keyword is correct or not
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:57
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::min
T min(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:28
pFlow::IOstream::name
virtual const word & name() const
Return the name of the stream.
Definition: IOstream.cpp:31
streams.hpp
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
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:117
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Report an error in file operation with supplied fileName and lineNumber.
Definition: error.hpp:87
pFlow::cylinder::calculateParams
FUNCTION_H bool calculateParams()
Definition: cylinder.cpp:27
pFlow::cylinder::axisVector_
realx3 axisVector_
Definition: cylinder.hpp:45
pFlow::IOstream::lineNumber
int32 lineNumber() const
Const access to the current stream line number.
Definition: IOstream.hpp:223
pFlow::cylinder::minPoint_
realx3 minPoint_
Definition: cylinder.hpp:49
cylinder.hpp
pFlow::triple< real >
math.hpp
zAxis.hpp
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::iOstream::writeWordEntry
iOstream & writeWordEntry(const word &key, const T &value)
Write a keyword/value entry.
Definition: iOstream.hpp:239
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