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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "lineDivide.H"
29 #include "blockEdge.H"
30 
31 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  //- Calculate the geometric expansion factor from the expansion ratio
36  inline scalar calcGexp(const scalar expRatio, const label nDiv)
37  {
38  return nDiv > 1 ? pow(expRatio, 1.0/(nDiv - 1)) : 0.0;
39  }
40 }
41 
42 
43 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44 
46 (
47  const blockEdge& cedge,
48  const label nDiv,
49  const gradingDescriptors& gd
50 )
51 :
52  points_(nDiv + 1),
53  divisions_(nDiv + 1)
54 {
55  divisions_[0] = 0.0;
56  divisions_[nDiv] = 1.0;
57 
58  scalar secStart = divisions_[0];
59  label secnStart = 1;
60 
61  // Check that there are more divisions than sections
62  if (nDiv >= gd.size())
63  {
64  // Calculate distribution of divisions to be independent
65  // of the order of the sections
66  labelList secnDivs(gd.size());
67  label sumSecnDivs = 0;
68  label secnMaxDivs = 0;
69 
70  forAll(gd, sectioni)
71  {
72  scalar nDivFrac = gd[sectioni].nDivFraction();
73  secnDivs[sectioni] = label(nDivFrac*nDiv + 0.5);
74  sumSecnDivs += secnDivs[sectioni];
75 
76  // Find the section with the largest number of divisions
77  if (nDivFrac > gd[secnMaxDivs].nDivFraction())
78  {
79  secnMaxDivs = sectioni;
80  }
81  }
82 
83  // Adjust the number of divisions on the section with the largest
84  // number so that the total is nDiv
85  if (sumSecnDivs != nDiv)
86  {
87  secnDivs[secnMaxDivs] += (nDiv - sumSecnDivs);
88  }
89 
90  forAll(gd, sectioni)
91  {
92  scalar blockFrac = gd[sectioni].blockFraction();
93  scalar expRatio = gd[sectioni].expansionRatio();
94 
95  label secnDiv = secnDivs[sectioni];
96  label secnEnd = secnStart + secnDiv;
97 
98  // Calculate the spacing
99  if (equal(expRatio, 1))
100  {
101  for (label i = secnStart; i < secnEnd; i++)
102  {
103  divisions_[i] =
104  secStart
105  + blockFrac*scalar(i - secnStart + 1)/secnDiv;
106  }
107  }
108  else
109  {
110  // Calculate geometric expansion factor from the expansion ratio
111  const scalar expFact = calcGexp(expRatio, secnDiv);
112 
113  for (label i = secnStart; i < secnEnd; i++)
114  {
115  divisions_[i] =
116  secStart
117  + blockFrac*(1.0 - pow(expFact, i - secnStart + 1))
118  /(1.0 - pow(expFact, secnDiv));
119  }
120  }
121 
122  secStart = divisions_[secnEnd - 1];
123  secnStart = secnEnd;
124  }
125  }
126  // Otherwise mesh uniformly
127  else
128  {
129  for (label i=1; i < nDiv; i++)
130  {
131  divisions_[i] = scalar(i)/nDiv;
132  }
133  }
134 
135  // Calculate the points
136  points_ = cedge.position(divisions_);
137 }
138 
139 
140 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
141 
143 {
144  return points_;
145 }
146 
147 
149 {
150  return divisions_;
151 }
152 
153 
154 // ************************************************************************* //
Foam::lineDivide::points
const pointField & points() const
The points.
Definition: lineDivide.C:142
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:46
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:36
Foam::blockEdge
Define a curved edge that is parameterized for 0<lambda<1 between the start/end points.
Definition: blockEdge.H:62
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::lineDivide::lambdaDivisions
const scalarList & lambdaDivisions() const
The list of lambda values.
Definition: lineDivide.C:148
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::List< label >
lineDivide.H
blockEdge.H