1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
27 //#include "curveTools.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
37 // construct as interpolation
39 curve::curve(const curve& Curve, const label nFacets)
41 Name("Interpolated" + Curve.Name),
46 // Calculate curve length
49 for (i=0; i<Curve.size()-1; i++)
51 curveLength += distance(Curve[i], Curve[i+1]);
54 scalar stepLength = curveLength/nFacets;
56 label previous=0, next=1;
58 vector presentPoint=Curve[0], nextPoint;
63 stepForwardsToNextPoint
75 if (nPoints >= size()-1)
77 setSize(label(1.5*size()));
80 presentPoint = nextPoint;
82 x()[nPoints] = nextPoint.x();
83 y()[nPoints] = nextPoint.y();
88 } while (!endOfCurve);
95 // construct given name, style and size
99 const curveStyle& style,
109 // construct from the bits
113 const curveStyle& style,
123 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
125 // Gradient operation
127 curve grad(const curve& Curve)
129 curve gradCurve(Curve);
132 for (i=1; i<Curve.size()-1; i++)
134 scalar deltaIm1 = Curve[i].x() - Curve[i-1].x();
135 scalar deltaI = Curve[i+1].x() - Curve[i].x();
137 scalar deltaAv = 1.0/deltaIm1 + 1.0/deltaI;
141 (Curve[i+1].y() - Curve[i].y())/sqr(deltaI)
142 + (Curve[i].y() - Curve[i-1].y())/sqr(deltaIm1)
147 (Curve[1].y() - Curve[0].y())/(Curve[1].x() - Curve[0].x());
149 label n = Curve.size()-1;
152 (Curve[n].y() - Curve[n-1].y())/(Curve[n].x() - Curve[n-1].x());
159 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
161 Ostream& operator<<(Ostream& os, const curve& c)
166 << static_cast<const scalarField&>(c);
168 os.check("Ostream& operator>>(Ostream&, const curve&)");
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 } // End namespace Foam
178 // ************************************************************************* //