# PhasicFlow: src/phasicFlow/structuredData/cylinder/cylinder.cpp Source File

cylinder.cpp
Go to the documentation of this file.
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#include "cylinder.hpp"
#include "zAxis.hpp"
FUNCTION_H
bool pFlow::cylinder::calculateParams()
{
auto p1p2 = p2_ - p1_;
if( p1p2.length() > smallValue )
{
axisVector2_ = dot(p1p2,p1p2);
axisVector_ = p1p2;
}else
{
return false;
}
zAxis zA(p1_,p2_);
realx3 minPinZ(-sqrt(radius2_), -sqrt(radius2_), 0.0);
realx3 maxPinZ( sqrt(radius2_), sqrt(radius2_), sqrt(axisVector2_));
minPoint_ = zA.transferBackZ(minPinZ);
maxPoint_ = zA.transferBackZ(maxPinZ);
return true;
}
FUNCTION_H
pFlow::cylinder::cylinder(
const realx3& p1,
const realx3& p2,
const real radius)
:
p1_(p1),
p2_(p2),
radius2_(radius*radius)
{
if(!calculateParams())
{
fatalErrorInFunction<<
"error in the input parameters for cylinder"<<endl;
fatalExit;
}
}
FUNCTION_H
pFlow::cylinder::cylinder
(
const dictionary & dict
)
:
p1_
(
dict.getVal<realx3>("p1")
),
p2_
(
dict.getVal<realx3>("p2")
)
{
auto rad = dict.getVal<real>("radius");
radius2_= rad*rad;
if(!calculateParams())
{
fatalErrorInFunction<<
"error in the input parameters for cylinder in dictionary "<< dict.globalName()<<endl;
fatalExit;
}
}
FUNCTION_H
pFlow::cylinder::cylinder
(
iIstream& is
)
{
if( !read(is))
{
ioErrorInFile(is.name(), is.lineNumber())<<
"error in reading cylinder from file. \n";
fatalExit;
}
}
FUNCTION_H
bool pFlow::cylinder::read(iIstream & is)
{
if(!is.nextData<realx3>("p1", p1_)) return false;
if(!is.nextData<realx3>("p2", p2_)) return false;
real rad;
if(!is.nextData<real>("radius", rad)) return false;
radius2_ =rad*rad;
return true;
}
FUNCTION_H
bool pFlow::cylinder::write(iOstream& os)const
{
os.writeWordEntry("p1", p1_);
os.writeWordEntry("p2", p2_);
os.writeWordEntry("radius", sqrt(radius2_));
return os.check(FUNCTION_NAME);
}
FUNCTION_H
bool pFlow::cylinder::read
(
const dictionary& dict
)
{
p1_ = dict.getVal<realx3>("p1");
p2_ = dict.getVal<realx3>("p2");
auto rad = dict.getVal<real>("radius");
radius2_ = rad*rad;
return true;
}
FUNCTION_H
bool pFlow::cylinder::write
(
dictionary& dict
)const
{
if(!dict.add("p1", p1_))
{
fatalErrorInFunction<<
" error in writing p1 to dictionary "<<dict.globalName()<<endl;
return false;
}
if(!dict.add("p2", p2_))
{
fatalErrorInFunction<<
" error in writing p2 to dictionary "<<dict.globalName()<<endl;
return false;
}
if(!dict.add("radius", sqrt(radius2_)) )
{
fatalErrorInFunction<<
" error in writing radius to dictionary "<<dict.globalName()<<endl;
return false;
}
return true;
}
FUNCTION_H
pFlow::iIstream& pFlow::operator >>(iIstream& is, cylinder& b)
{
if(! b.read(is))
{
ioErrorInFile(is.name(), is.lineNumber())<<
"error in reading cylinder. \n";
fatalExit;
}
return is;
}
FUNCTION_H
pFlow::iOstream& pFlow::operator << (iOstream& os, const cylinder& b)
{
if(! b.write(os))
{
ioErrorInFile(os.name(), os.lineNumber())<<
"error in writing cylinder. \n";
fatalExit;
}
return os;
}
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