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-2021 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  correct();
55 }
56 
57 
59 (
60  const scalar expansionRatio
61 )
62 :
63  blockFraction_(1),
64  nDivFraction_(1),
65  expansionRatio_(expansionRatio)
66 {
67  correct();
68 }
69 
70 
72 {
73  is >> *this;
74 }
75 
76 
77 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
78 
80 {
81  if (expansionRatio_ < 0)
82  {
83  expansionRatio_ = 1.0/(-expansionRatio_);
84  }
85 }
86 
87 
89 {
90  return gradingDescriptor
91  (
92  blockFraction_,
93  nDivFraction_,
94  1.0/expansionRatio_
95  );
96 }
97 
98 
99 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
100 
102 {
103  return
104  equal(blockFraction_, gd.blockFraction_)
105  && equal(nDivFraction_, gd.nDivFraction_)
106  && equal(expansionRatio_, gd.expansionRatio_);
107 }
108 
109 
111 {
112  return !operator==(gd);
113 }
114 
115 
116 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
117 
119 {
120  // Examine next token
121  token t(is);
122 
123  if (t.isNumber())
124  {
125  gd.blockFraction_ = 1.0;
126  gd.nDivFraction_ = 1.0;
127  gd.expansionRatio_ = t.number();
128  }
129  else if (t.isPunctuation(token::BEGIN_LIST))
130  {
131  is >> gd.blockFraction_ >> gd.nDivFraction_ >> gd.expansionRatio_;
132  is.readEnd("gradingDescriptor");
133  }
134 
135  gd.correct();
136 
137  is.check(FUNCTION_NAME);
138  return is;
139 }
140 
141 
143 {
144  if (equal(gd.blockFraction_, 1))
145  {
146  os << gd.expansionRatio_;
147  }
148  else
149  {
151  << gd.blockFraction_ << token::SPACE
152  << gd.nDivFraction_ << token::SPACE
153  << gd.expansionRatio_
154  << token::END_LIST;
155  }
156 
157  return os;
158 }
159 
160 
161 // ************************************************************************* //
token.H
gradingDescriptor.H
Foam::gradingDescriptor::inv
gradingDescriptor inv() const
Return the inverse gradingDescriptor with 1/expansionRatio.
Definition: gradingDescriptor.C:88
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::token
A token holds an item read from Istream.
Definition: token.H:68
Foam::Istream::readEnd
bool readEnd(const char *funcName)
End read of data chunk, ends with ')'.
Definition: Istream.C:129
Foam::token::isNumber
bool isNumber() const noexcept
Token is LABEL, FLOAT or DOUBLE.
Definition: tokenI.H:587
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::token::number
scalar number() const
Return label, float or double value.
Definition: tokenI.H:593
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
correct
fvOptions correct(rho)
IOstream.H
Foam::token::isPunctuation
bool isPunctuation() const noexcept
Token is PUNCTUATION.
Definition: tokenI.H:459
Foam::gradingDescriptor::operator!=
bool operator!=(const gradingDescriptor &) const
Definition: gradingDescriptor.C:110
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
os
OBJstream os(runTime.globalPath()/outputName)
Foam::gradingDescriptor::gradingDescriptor
gradingDescriptor()
Default construct (1, 1, 1)
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:101
Foam::token::SPACE
Space [isspace].
Definition: token.H:125
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
Foam::token::END_LIST
End list [isseparator].
Definition: token.H:156
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::token::BEGIN_LIST
Begin list [isseparator].
Definition: token.H:155
Foam::equal
bool equal(const T &s1, const T &s2)
Compare two values for equality.
Definition: doubleFloat.H:46
Foam::gradingDescriptor::correct
void correct()
Adjust expansion ratio.
Definition: gradingDescriptor.C:79