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