# PhasicFlow: src/phasicFlow/structuredData/sphere/sphere.cpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

sphere.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 "sphere.hpp"
FUNCTION_H
pFlow::sphere::sphere(
const realx3& center,
const real radius)
:
center_(center),
radius2_(radius*radius)
{
}
FUNCTION_H
pFlow::sphere::sphere
(
const dictionary & dict
)
:
center_
(
dict.getVal<realx3>("center")
)
{
auto rad = dict.getVal<real>("radius");
radius2_= rad*rad;
}
FUNCTION_H
pFlow::sphere::sphere
(
iIstream& is
)
{
if( !read(is))
{
ioErrorInFile(is.name(), is.lineNumber())<<
"error in reading sphere from file. \n";
fatalExit;
}
}
FUNCTION_H
bool pFlow::sphere::read(iIstream & is)
{
if(!is.nextData<realx3>("center", center_)) return false;
real rad;
if(!is.nextData<real>("radius", rad)) return false;
radius2_ =rad*rad;
return true;
}
FUNCTION_H
bool pFlow::sphere::write(iOstream& os)const
{
os.writeWordEntry("center", center_);
os.writeWordEntry("radius", sqrt(radius2_));
return os.check(FUNCTION_NAME);
}
FUNCTION_H
bool pFlow::sphere::read
(
const dictionary& dict
)
{
center_ = dict.getVal<realx3>("center");
auto rad = dict.getVal<real>("radius");
radius2_ = rad*rad;
return true;
}
FUNCTION_H
bool pFlow::sphere::write
(
dictionary& dict
)const
{
if(!dict.add("center", center_))
{
fatalErrorInFunction<<
" error in writing center 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, sphere& b)
{
if(! b.read(is))
{
ioErrorInFile(is.name(), is.lineNumber())<<
"error in reading sphere. \n";
fatalExit;
}
return is;
}
FUNCTION_H
pFlow::iOstream& pFlow::operator << (iOstream& os, const sphere& b)
{
if(! b.write(os))
{
ioErrorInFile(os.name(), os.lineNumber())<<
"error in writing sphere. \n";
fatalExit;
}
return os;
}
pFlow::real
float real
Definition: builtinTypes.hpp:45
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::sphere::write
FUNCTION_H bool write(iOstream &os) const
Definition: sphere.cpp:77
pFlow::sqrt
Vector< T, Allocator > sqrt(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:90
FUNCTION_NAME
#define FUNCTION_NAME
Definition: pFlowMacros.hpp:29
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
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
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::sphere::read
FUNCTION_H bool read(iIstream &is)
Definition: sphere.cpp:67
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::IOstream::name
virtual const word & name() const
Return the name of the stream.
Definition: IOstream.cpp:31
sphere.hpp
pFlow::dictionary::getVal
T getVal(const word &keyword) const
get the value of data entry
Definition: dictionary.hpp:379
pFlow::sphere::sphere
FUNCTION_H sphere(const realx3 &center, const real radius)
Definition: sphere.cpp:26
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Report an error in file operation with supplied fileName and lineNumber.
Definition: error.hpp:87
pFlow::sphere
Definition: sphere.hpp:32
pFlow::IOstream::lineNumber
int32 lineNumber() const
Const access to the current stream line number.
Definition: IOstream.hpp:223
pFlow::triple< real >
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