lineDivide.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) 2011-2019 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 "lineDivide.H"
27 #include "blockEdge.H"
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  //- Calculate the geometric expansion factor from the expansion ratio
34  inline scalar calcGexp(const scalar expRatio, const label nDiv)
35  {
36  return nDiv > 1 ? pow(expRatio, 1.0/(nDiv - 1)) : 0.0;
37  }
38 }
39 
40 
41 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 
44 (
45  const blockEdge& cedge,
46  const label nDiv,
47  const gradingDescriptors& gd
48 )
49 :
50  points_(nDiv + 1),
51  divisions_(nDiv + 1)
52 {
53  divisions_[0] = 0.0;
54  divisions_[nDiv] = 1.0;
55 
56  scalar secStart = divisions_[0];
57  label secnStart = 1;
58 
59  // Check that there are more divisions than sections
60  if (nDiv >= gd.size())
61  {
62  // Calculate distribution of divisions to be independent
63  // of the order of the sections
64  labelList secnDivs(gd.size());
65  label sumSecnDivs = 0;
66  label secnMaxDivs = 0;
67 
68  forAll(gd, sectioni)
69  {
70  scalar nDivFrac = gd[sectioni].nDivFraction();
71  secnDivs[sectioni] = label(nDivFrac*nDiv + 0.5);
72  sumSecnDivs += secnDivs[sectioni];
73 
74  // Find the section with the largest number of divisions
75  if (nDivFrac > gd[secnMaxDivs].nDivFraction())
76  {
77  secnMaxDivs = sectioni;
78  }
79  }
80 
81  // Adjust the number of divisions on the section with the largest
82  // number so that the total is nDiv
83  if (sumSecnDivs != nDiv)
84  {
85  secnDivs[secnMaxDivs] += (nDiv - sumSecnDivs);
86  }
87 
88  forAll(gd, sectioni)
89  {
90  scalar blockFrac = gd[sectioni].blockFraction();
91  scalar expRatio = gd[sectioni].expansionRatio();
92 
93  label secnDiv = secnDivs[sectioni];
94  label secnEnd = secnStart + secnDiv;
95 
96  // Calculate the spacing
97  if (expRatio == 1.0)
98  {
99  for (label i = secnStart; i < secnEnd; i++)
100  {
101  divisions_[i] =
102  secStart
103  + blockFrac*scalar(i - secnStart + 1)/secnDiv;
104  }
105  }
106  else
107  {
108  // Calculate geometric expansion factor from the expansion ratio
109  const scalar expFact = calcGexp(expRatio, secnDiv);
110 
111  for (label i = secnStart; i < secnEnd; i++)
112  {
113  divisions_[i] =
114  secStart
115  + blockFrac*(1.0 - pow(expFact, i - secnStart + 1))
116  /(1.0 - pow(expFact, secnDiv));
117  }
118  }
119 
120  secStart = divisions_[secnEnd - 1];
121  secnStart = secnEnd;
122  }
123  }
124  // Otherwise mesh uniformly
125  else
126  {
127  for (label i=1; i < nDiv; i++)
128  {
129  divisions_[i] = scalar(i)/nDiv;
130  }
131  }
132 
133  // Calculate the points
134  points_ = cedge.position(divisions_);
135 }
136 
137 
138 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
139 
141 {
142  return points_;
143 }
144 
145 
147 {
148  return divisions_;
149 }
150 
151 
152 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
virtual point position(const scalar) const =0
Return the point position corresponding to the curve parameter.
const scalarList & lambdaDivisions() const
Return the list of lambda values.
Definition: lineDivide.C:146
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
lineDivide(const blockEdge &, const label ndiv, const gradingDescriptors &gd=gradingDescriptors())
Construct from components.
Definition: lineDivide.C:44
scalar calcGexp(const scalar expRatio, const label nDiv)
Calculate the geometric expansion factor from the expansion ratio.
Definition: lineDivide.C:34
const pointField & points() const
Return the points.
Definition: lineDivide.C:140
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Define a curved edge that is parameterised for 0<lambda<1 between the start and end point...
Definition: blockEdge.H:56
List of gradingDescriptor for the sections of a block with additional IO functionality.
Namespace for OpenFOAM.