stabilise expansion calculation for if no point on arc
[OpenFOAM-1.5.x.git] / applications / utilities / mesh / generation / blockMesh / setEdge.C
blob3b5c9ea90b91ed25c9d80b0b7d887233b76a700c
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Description
26     from the list of curved edges creates a list
27     of edges that are not curved. It is assumed
28     that all other edges are straight lines
30 \*---------------------------------------------------------------------------*/
32 #include "error.H"
34 #include "blockDescriptor.H"
35 #include "lineEdge.H"
36 #include "lineDivide.H"
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 namespace Foam
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 scalar calcGexp(const scalar expRatio, const label dim)
47     if (dim == 1)
48     {
49         return 0.0;
50     }
51     else
52     {
53         return pow(expRatio, 1.0/(dim - 1));
54     }
58 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
60 void blockDescriptor::setEdge(label edgeI, label start, label end, label dim)
62     // for all edges check the list of curved edges. If the edge is curved,
63     // add it to the list. If the edge is not found, create is as a line
65     bool found = false;
67     // set reference to the list of labels defining the block
68     const labelList& blockLabels = blockShape_;
70     // set reference to global list of points
71     const pointField blockPoints = blockShape_.points(blockMeshPoints_);
73     // x1
74     found = false;
76     forAll (curvedEdges_, nCEI)
77     {
78         if (curvedEdges_[nCEI].compare(blockLabels[start], blockLabels[end]))
79         {
80             found = true;
82             // check the orientation:
83             // if the starting point of the curve is the same as the starting
84             // point of the edge, do the parametrisation and pick up the points
85             if (blockLabels[start] == curvedEdges_[nCEI].start())
86             {
87                 // calculate the geometric expension factor out of the
88                 // expansion ratio
89                 scalar gExp = calcGexp(expand_[edgeI], dim);
91                 // divide the line
92                 lineDivide divEdge(curvedEdges_[nCEI], dim, gExp);
94                 edgePoints_[edgeI] = divEdge.points();
95                 edgeWeights_[edgeI] = divEdge.lambdaDivisions();
96             }
97             else
98             {
99                 // the curve has got the opposite orientation
100                 scalar gExp = calcGexp(expand_[edgeI], dim);
102                 // divide the line
103                 lineDivide divEdge(curvedEdges_[nCEI], dim, 1.0/(gExp+SMALL));
105                 pointField p = divEdge.points();
106                 scalarList d = divEdge.lambdaDivisions();
108                 edgePoints_[edgeI].setSize(p.size());
109                 edgeWeights_[edgeI].setSize(d.size());
111                 label pMax = p.size() - 1;
112                 forAll (p, pI)
113                 {
114                     edgePoints_[edgeI][pI] = p[pMax - pI];
115                     edgeWeights_[edgeI][pI] = 1.0 - d[pMax - pI];
116                 }
117             }
119             break;
120         }
121     }
123     if (!found)
124     {
125         // edge is a straight line
126         scalar gExp = calcGexp(expand_[edgeI], dim);
128         // divide the line
129         lineDivide divEdge
130         (
131             lineEdge(blockPoints, start, end),
132             dim,
133             gExp
134         );
136         edgePoints_[edgeI] = divEdge.points();
137         edgeWeights_[edgeI] = divEdge.lambdaDivisions();
138     }
142 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
144 } // End namespace Foam
146 // ************************************************************************* //