gradingDescriptors.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-2020 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 "gradingDescriptors.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
34 :
36 {}
37 
38 
40 (
41  const label len
42 )
43 :
45 {}
46 
47 
49 :
50  List<gradingDescriptor>(1, gd)
51 {}
52 
53 
54 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
55 
57 {
58  for (gradingDescriptor& gd : *this)
59  {
60  gd.correct();
61  }
62 }
63 
64 
66 {
67  scalar sumBlockFraction = 0;
68  scalar sumNDivFraction = 0;
69 
70  for (const gradingDescriptor& gd : *this)
71  {
72  sumBlockFraction += gd.blockFraction_;
73  sumNDivFraction += gd.nDivFraction_;
74  }
75 
76  for (gradingDescriptor& gd : *this)
77  {
78  gd.blockFraction_ /= sumBlockFraction;
79  gd.nDivFraction_ /= sumNDivFraction;
80  gd.correct();
81  }
82 }
83 
84 
86 {
87  gradingDescriptors ret(*this);
88 
89  forAll(ret, i)
90  {
91  ret[i] = operator[](ret.size() - i - 1).inv();
92  }
93 
94  return ret;
95 }
96 
97 
98 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
99 
101 {
102  // Examine next token
103  token t(is);
104 
105  if (t.isNumber())
106  {
108  gds.correct();
109  }
110  else
111  {
112  is.putBack(t);
113 
114  // Read the list for gradingDescriptors
115  is >> static_cast<List<gradingDescriptor>&>(gds);
116 
117  gds.normalise();
118  }
119 
120  is.check(FUNCTION_NAME);
121  return is;
122 }
123 
124 
125 // ************************************************************************* //
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::gradingDescriptors
List of gradingDescriptor for the sections of a block with additional IO functionality.
Definition: gradingDescriptors.H:58
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
gradingDescriptors.H
Foam::token::isNumber
bool isNumber() const noexcept
Token is LABEL, FLOAT or DOUBLE.
Definition: tokenI.H:587
Foam::gradingDescriptors::gradingDescriptors
gradingDescriptors()
Default construct with a single default gradingDescriptor.
Definition: gradingDescriptors.C:33
Foam::token::number
scalar number() const
Return label, float or double value.
Definition: tokenI.H:593
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::inv
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:73
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
Foam::gradingDescriptors::inv
gradingDescriptors inv() const
Return the inverse gradingDescriptors with 1/expansionRatio.
Definition: gradingDescriptors.C:85
Foam::gradingDescriptor
Handles the specification for grading within a section of a block.
Definition: gradingDescriptor.H:72
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::gradingDescriptors::correct
void correct()
Adjust expansion ratios.
Definition: gradingDescriptors.C:56
Foam::Istream::putBack
void putBack(const token &tok)
Put back a token. Only a single put back is permitted.
Definition: Istream.C:70
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
Foam::gradingDescriptor::correct
void correct()
Adjust expansion ratio.
Definition: gradingDescriptor.C:79
Foam::gradingDescriptors::normalise
void normalise()
Definition: gradingDescriptors.C:65