gradingDescriptor.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2015 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "gradingDescriptor.H"
30 #include "IOstream.H"
31 #include "token.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
36 :
37  blockFraction_(1),
38  nDivFraction_(1),
39  expansionRatio_(1)
40 {}
41 
42 
44 (
45  const scalar blockFraction,
46  const scalar nDivFraction,
47  const scalar expansionRatio
48 )
49 :
50  blockFraction_(blockFraction),
51  nDivFraction_(nDivFraction),
52  expansionRatio_(expansionRatio)
53 {
54  if (expansionRatio_ < 0)
55  {
56  expansionRatio_ = 1.0/(-expansionRatio_);
57  }
58 }
59 
60 
62 (
63  const scalar expansionRatio
64 )
65 :
66  blockFraction_(1),
67  nDivFraction_(1),
68  expansionRatio_(expansionRatio)
69 {
70  if (expansionRatio_ < 0)
71  {
72  expansionRatio_ = 1.0/(-expansionRatio_);
73  }
74 }
75 
76 
78 {
79  is >> *this;
80 }
81 
82 
83 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
84 
86 {
87  return gradingDescriptor
88  (
89  blockFraction_,
90  nDivFraction_,
91  1.0/expansionRatio_
92  );
93 }
94 
95 
96 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
97 
99 {
100  return
101  equal(blockFraction_, gd.blockFraction_)
102  && equal(nDivFraction_, gd.nDivFraction_)
103  && equal(expansionRatio_, gd.expansionRatio_);
104 }
105 
106 
108 {
109  return !operator==(gd);
110 }
111 
112 
113 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
114 
116 {
117  // Examine next token
118  token t(is);
119 
120  if (t.isNumber())
121  {
122  gd.blockFraction_ = 1.0;
123  gd.nDivFraction_ = 1.0;
124  gd.expansionRatio_ = t.number();
125  }
126  else if (t.isPunctuation() && t.pToken() == token::BEGIN_LIST)
127  {
128  is >> gd.blockFraction_ >> gd.nDivFraction_ >> gd.expansionRatio_;
129  is.readEnd("gradingDescriptor");
130  }
131 
132  is.check(FUNCTION_NAME);
133  return is;
134 }
135 
136 
138 {
139  if (equal(gd.blockFraction_, 1))
140  {
141  os << gd.expansionRatio_;
142  }
143  else
144  {
145  os << token::BEGIN_LIST
146  << gd.blockFraction_ << token::SPACE
147  << gd.nDivFraction_ << token::SPACE
148  << gd.expansionRatio_
149  << token::END_LIST;
150  }
151 
152  return os;
153 }
154 
155 
156 // ************************************************************************* //
token.H
gradingDescriptor.H
Foam::gradingDescriptor::inv
gradingDescriptor inv() const
Return the inverse gradingDescriptor with 1/expansionRatio.
Definition: gradingDescriptor.C:85
Foam::token::isNumber
bool isNumber() const
Token is LABEL, FLOAT_SCALAR or DOUBLE_SCALAR.
Definition: tokenI.H:530
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:228
Foam::token
A token holds an item read from Istream.
Definition: token.H:69
Foam::Istream::readEnd
bool readEnd(const char *funcName)
End read of data chunk, ends with ')'.
Definition: Istream.C:127
Foam::token::pToken
punctuationToken pToken() const
Return punctuation character.
Definition: tokenI.H:428
Foam::token::number
scalar number() const
Return label, float or double value.
Definition: tokenI.H:536
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
IOstream.H
Foam::gradingDescriptor::operator!=
bool operator!=(const gradingDescriptor &) const
Definition: gradingDescriptor.C:107
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:51
Foam::gradingDescriptor::gradingDescriptor
gradingDescriptor()
Default constructor.
Definition: gradingDescriptor.C:35
Foam::gradingDescriptor
Handles the specification for grading within a section of a block.
Definition: gradingDescriptor.H:72
Foam::gradingDescriptor::operator==
bool operator==(const gradingDescriptor &) const
Definition: gradingDescriptor.C:98
Foam::token::SPACE
Space [isspace].
Definition: token.H:112
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:261
Foam::token::END_LIST
End list [isseparator].
Definition: token.H:118
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::token::isPunctuation
bool isPunctuation() const
Token is PUNCTUATION.
Definition: tokenI.H:422
Foam::token::BEGIN_LIST
Begin list [isseparator].
Definition: token.H:117
Foam::equal
bool equal(const T &s1, const T &s2)
Compare two values for equality.
Definition: doubleFloat.H:46
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &)
Definition: boundaryPatch.C:102