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 
118 Foam::Istream& Foam::operator>>(Istream& is, gradingDescriptor& gd)
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 
142 Foam::Ostream& Foam::operator<<(Ostream& os, const gradingDescriptor& gd)
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 // ************************************************************************* //
void correct()
Adjust expansion ratio.
bool equal(const T &a, const T &b)
Compare two values for equality.
Definition: label.H:164
bool operator==(const gradingDescriptor &) const
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
Begin list [isseparator].
Definition: token.H:161
gradingDescriptor()
Default construct (1, 1, 1)
Istream & operator>>(Istream &, directionInfo &)
Space [isspace].
Definition: token.H:131
Handles the specification for grading within a section of a block.
End list [isseparator].
Definition: token.H:162
bool operator!=(const gradingDescriptor &) const
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
Info<< "Predicted p max-min : "<< max(p).value()<< " "<< min(p).value()<< endl;rho==max(psi *p+alphal *rhol0+((alphav *psiv+alphal *psil) - psi) *pSat, rhoMin);# 1 "/home/chef2/andy/OpenFOAM/release/v2312/OpenFOAM-v2312/applications/solvers/multiphase/cavitatingFoam/alphavPsi.H" 1{ alphav=clamp((rho - rholSat)/(rhovSat - rholSat), zero_one{});alphal=1.0 - alphav;Info<< "max-min alphav: "<< max(alphav).value()<< " "<< min(alphav).value()<< endl;psiModel-> correct()
Definition: pEqn.H:63
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:77
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)