1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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
27 \*---------------------------------------------------------------------------*/
30 //#include "curveTools.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
40 // construct as interpolation
42 curve::curve(const curve& Curve, const label nFacets)
44 Name("Interpolated" + Curve.Name),
49 // Calculate curve length
52 for (i=0; i<Curve.size()-1; i++)
54 curveLength += distance(Curve[i], Curve[i+1]);
57 scalar stepLength = curveLength/nFacets;
59 label previous=0, next=1;
61 vector presentPoint=Curve[0], nextPoint;
66 stepForwardsToNextPoint
78 if (nPoints >= size()-1)
80 setSize(label(1.5*size()));
83 presentPoint = nextPoint;
85 x()[nPoints] = nextPoint.x();
86 y()[nPoints] = nextPoint.y();
91 } while (!endOfCurve);
98 // construct given name, style and size
102 const curveStyle& style,
112 // construct from the bits
116 const curveStyle& style,
126 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
128 // Gradient operation
130 curve grad(const curve& Curve)
132 curve gradCurve(Curve);
135 for (i=1; i<Curve.size()-1; i++)
137 scalar deltaIm1 = Curve[i].x() - Curve[i-1].x();
138 scalar deltaI = Curve[i+1].x() - Curve[i].x();
140 scalar deltaAv = 1.0/deltaIm1 + 1.0/deltaI;
144 (Curve[i+1].y() - Curve[i].y())/sqr(deltaI)
145 + (Curve[i].y() - Curve[i-1].y())/sqr(deltaIm1)
150 (Curve[1].y() - Curve[0].y())/(Curve[1].x() - Curve[0].x());
152 label n = Curve.size()-1;
155 (Curve[n].y() - Curve[n-1].y())/(Curve[n].x() - Curve[n-1].x());
162 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
164 Ostream& operator<<(Ostream& os, const curve& c)
169 << static_cast<const scalarField&>(c);
171 os.check("Ostream& operator>>(Ostream&, const curve&)");
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179 } // End namespace Foam
181 // ************************************************************************* //