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-------------------------------------------------------------------------------
11License
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{
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 }
130 {
131 is >> gd.blockFraction_ >> gd.nDivFraction_ >> gd.expansionRatio_;
132 is.readEnd("gradingDescriptor");
133 }
134
135 gd.correct();
136
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_
155 }
156
157 return os;
158}
159
160
161// ************************************************************************* //
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
bool readEnd(const char *funcName)
End read of data chunk, ends with ')'.
Definition: Istream.C:129
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Handles the specification for grading within a section of a block.
void correct()
Adjust expansion ratio.
gradingDescriptor()
Default construct (1, 1, 1)
gradingDescriptor inv() const
Return the inverse gradingDescriptor with 1/expansionRatio.
friend bool operator!=(const refineCell &rc1, const refineCell &rc2)
Definition: refineCell.H:106
friend bool operator==(const refineCell &rc1, const refineCell &rc2)
Definition: refineCell.H:97
A token holds an item read from Istream.
Definition: token.H:69
bool isNumber() const noexcept
Token is LABEL, FLOAT or DOUBLE.
Definition: tokenI.H:587
bool isPunctuation() const noexcept
Token is PUNCTUATION.
Definition: tokenI.H:459
@ BEGIN_LIST
Begin list [isseparator].
Definition: token.H:155
@ END_LIST
End list [isseparator].
Definition: token.H:156
@ SPACE
Space [isspace].
Definition: token.H:125
scalar number() const
Return label, float or double value.
Definition: tokenI.H:593
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
bool equal(const T &s1, const T &s2)
Compare two values for equality.
Definition: doubleFloat.H:46
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Istream & operator>>(Istream &, directionInfo &)