line.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 "line.hpp"
23 #include "dictionary.hpp"
24 
25 
28 (
29  const realx3 &lp1,
30  const realx3 &lp2
31 )
32 {
33  set(lp1, lp2);
34 }
35 
38 (
39  const dictionary& dict
40 )
41 {
42  if(!read(dict))
43  {
44  fatalExit;
45  }
46 }
47 
50 (
51  const dictionary& dict
52 )
53 {
54  realx3 p1 = dict.getVal<realx3>("p1");
55  realx3 p2 = dict.getVal<realx3>("p2");
56  set(p1, p2);
57  return true;
58 }
59 
61 bool pFlow::line::write(dictionary& dict) const
62 {
63  if(!dict.add("p1", point1()))
64  {
66  " error in writing p1 to dictionary " << dict.globalName()<<endl;
67  return false;
68  }
69 
70  if(!dict.add("p2", point2()))
71  {
73  " error in writing p2 to dictionary " << dict.globalName()<<endl;
74  return false;
75  }
76 
77  return true;
78 }
79 
82 (
83  iIstream& is
84 )
85 {
86  word p1w;
87  realx3 p1;
88  is >> p1w >> p1;
89  if( !is.check(FUNCTION_NAME))
90  {
91  ioErrorInFile(is.name(), is.lineNumber());
92  return false;
93  }
94  if(p1w != "p1")
95  {
96  ioErrorInFile(is.name(), is.lineNumber())<<
97  " expected p1 but found "<< p1w<<endl;
98  return false;
99  }
101 
102  word p2w;
103  realx3 p2;
104  is >> p2w >> p2;
105 
106  if( !is.check(FUNCTION_NAME))
107  {
108  ioErrorInFile(is.name(), is.lineNumber());
109  return false;
110  }
111  if(p2w != "p2")
112  {
113  ioErrorInFile(is.name(), is.lineNumber())<<
114  " expected p2 but found "<< p2w<<endl;
115  return false;
116  }
118  set(p1,p2);
119  return true;
120 }
121 
124 (
125  iOstream& os
126 )const
127 {
128  os.writeWordEntry("p1", point1());
129  os.writeWordEntry("p2", point2());
130  return os.check(FUNCTION_NAME);
131 }
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::line::write
FUNCTION_H bool write(dictionary &ditc) const
Definition: line.cpp:61
pFlow::iIstream::readEndStatement
char readEndStatement(const char *funcName)
Definition: iIstream.cpp:324
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::line::line
FUNCTION_HD line()
Definition: line.hpp:52
pFlow::IOstream::check
virtual bool check(const char *operation) const
Definition: IOstream.cpp:42
FUNCTION_H
#define FUNCTION_H
Definition: pFlowMacros.hpp:58
pFlow::line::read
FUNCTION_H bool read(const dictionary &dict)
Definition: line.cpp:50
pFlow::iIstream
Definition: iIstream.hpp:33
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::line::point2
INLINE_FUNCTION_HD realx3 point2() const
Definition: line.hpp:90
dictionary.hpp
FUNCTION_HD
#define FUNCTION_HD
Definition: pFlowMacros.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::line::point1
INLINE_FUNCTION_HD realx3 point1() const
Definition: line.hpp:86
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Definition: error.hpp:49
pFlow::IOstream::lineNumber
int32 lineNumber() const
Definition: IOstream.hpp:187
pFlow::triple< real >
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::iOstream::writeWordEntry
iOstream & writeWordEntry(const word &key, const T &value)
Definition: iOstream.hpp:217
line.hpp
pFlow::dictionary
Definition: dictionary.hpp:38