initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / applications / utilities / mesh / generation / blockMesh / curvedEdges / polyLine.C
blob1d896882562b0257ed71030e55f7ab52f4182fc2
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     polyLineEdge class : defines a curvedEdge in terms of a series of
27     straight line segments
29 \*---------------------------------------------------------------------------*/
31 #include "error.H"
33 #include "polyLine.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 namespace Foam
40 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
42 // calcDistances generates the distances_ lookup table (cumulative
43 // distance along the line) from the individual vectors to the points
45 void polyLine::calcDistances()
47     distances_[0] = 0.0;
49     for (label i=1; i<distances_.size(); i++)
50     {
51         distances_[i] =
52             mag(controlPoints_[i] - controlPoints_[i-1])
53           + distances_[i-1];
54     }
56     lineLength_ = distances_[distances_.size()-1];
58     for (label i=1; i<distances_.size(); i++)
59     {
60         distances_[i] /= lineLength_;
61     }
65 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
67 polyLine::polyLine(const pointField& ps)
69     controlPoints_(ps),
70     distances_(ps.size())
72     if (ps.size())
73     {
74         calcDistances();
75     }
79 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
81 vector polyLine::position(const scalar lambda) const
83     // check range of lambda
85     if (lambda < 0 || lambda > 1)
86     {
87         FatalErrorIn("polyLine::position(const scalar)")
88             << "Parameter out of range, "
89             << "lambda = " << lambda
90             << abort(FatalError);
91     }
93     // Quick calc of endpoints
95     if (lambda < SMALL)
96     {
97         return controlPoints_[0];
98     }
99     else if (lambda > 1 - SMALL)
100     {
101         return controlPoints_[controlPoints_.size()-1];
102     }
105     // search table of cumulative distance to find which linesegment we
106     // are on
108     label i(0);
109     do
110     {
111         i++;
112     } while (distances_[i] < lambda);
114     i--;               // we overshot!
116     // construct position vector
117     scalar offsetDist =
118         (lambda - distances_[i])
119        /(distances_[i+1] - distances_[i]);
121     vector offsetV = controlPoints_[i+1] - controlPoints_[i];
123     return controlPoints_[i] + offsetDist*offsetV;
127 scalar polyLine::length() const
129     return lineLength_;
133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
135 } // End namespace Foam
137 // ************************************************************************* //