1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
26 \*---------------------------------------------------------------------------*/
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
38 // construct as interpolation
40 curve::curve(const curve& Curve, const label nFacets)
42 Name("Interpolated" + Curve.Name),
47 // Calculate curve length
50 for (i=0; i<Curve.size()-1; i++)
52 curveLength += distance(Curve[i], Curve[i+1]);
55 scalar stepLength = curveLength/nFacets;
57 label previous=0, next=1;
59 vector presentPoint=Curve[0], nextPoint;
64 stepForwardsToNextPoint
76 if (nPoints >= size()-1)
78 setSize(label(1.5*size()));
81 presentPoint = nextPoint;
83 x()[nPoints] = nextPoint.x();
84 y()[nPoints] = nextPoint.y();
89 } while (!endOfCurve);
96 // construct given name, style and size
100 const curveStyle& style,
110 // construct from the bits
114 const curveStyle& style,
124 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
126 // Gradient operation
128 curve grad(const curve& Curve)
130 curve gradCurve(Curve);
133 for (i=1; i<Curve.size()-1; i++)
135 scalar deltaIm1 = Curve[i].x() - Curve[i-1].x();
136 scalar deltaI = Curve[i+1].x() - Curve[i].x();
138 scalar deltaAv = 1.0/deltaIm1 + 1.0/deltaI;
142 (Curve[i+1].y() - Curve[i].y())/sqr(deltaI)
143 + (Curve[i].y() - Curve[i-1].y())/sqr(deltaIm1)
148 (Curve[1].y() - Curve[0].y())/(Curve[1].x() - Curve[0].x());
150 label n = Curve.size()-1;
153 (Curve[n].y() - Curve[n-1].y())/(Curve[n].x() - Curve[n-1].x());
160 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
162 Ostream& operator<<(Ostream& os, const curve& c)
167 << static_cast<const scalarField&>(c);
169 os.check("Ostream& operator>>(Ostream&, const curve&)");
175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177 } // End namespace Foam
179 // ************************************************************************* //