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