www.cemf.ir
sphere.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 "sphere.hpp"
23 
24 
27  const realx3& center,
28  const real radius)
29 :
30  center_(center),
31  radius2_(radius*radius)
32 {
33 
34 }
35 
38 (
39  const dictionary & dict
40 )
41 :
42  center_
43  (
44  dict.getVal<realx3>("center")
45  )
46 {
47  auto rad = dict.getVal<real>("radius");
48  radius2_= rad*rad;
49 }
50 
53 (
54  iIstream& is
55 )
56 {
57  if( !read(is))
58  {
59  ioErrorInFile(is.name(), is.lineNumber())<<
60  "error in reading sphere from file. \n";
61  fatalExit;
62  }
63 }
64 
65 
68 {
69  if(!is.nextData<realx3>("center", center_)) return false;
70  real rad;
71  if(!is.nextData<real>("radius", rad)) return false;
72  radius2_ =rad*rad;
73  return true;
74 }
75 
78 {
79  os.writeWordEntry("center", center_);
80  os.writeWordEntry("radius", sqrt(radius2_));
81  return os.check(FUNCTION_NAME);
82 }
83 
86 (
87  const dictionary& dict
88 )
89 {
90  center_ = dict.getVal<realx3>("center");
91  auto rad = dict.getVal<real>("radius");
92  radius2_ = rad*rad;
93  return true;
94 }
95 
98 (
99  dictionary& dict
100 )const
101 {
102  if(!dict.add("center", center_))
103  {
105  " error in writing center to dictionary "<<dict.globalName()<<endl;
106  return false;
107  }
108 
109 
110  if(!dict.add("radius", sqrt(radius2_)) )
111  {
113  " error in writing radius to dictionary "<<dict.globalName()<<endl;
114  return false;
115  }
116 
117  return true;
118 }
119 
122 {
123  if(! b.read(is))
124  {
125  ioErrorInFile(is.name(), is.lineNumber())<<
126  "error in reading sphere. \n";
127  fatalExit;
128  }
129  return is;
130 }
131 
134 {
135 
136  if(! b.write(os))
137  {
138  ioErrorInFile(os.name(), os.lineNumber())<<
139  "error in writing sphere. \n";
140  fatalExit;
141  }
142  return os;
143 }
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