Report patch name instead of index in debug
[foam-extend-3.2.git] / src / foam / graph / curve / curve.C
blob6081f7c872d0c4c256bc4303b003e627945a9da4
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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/>.
24 Description
26 \*---------------------------------------------------------------------------*/
28 #include "curve.H"
29 #include "Ostream.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 namespace Foam
36 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
38 // construct as interpolation
40 curve::curve(const curve& Curve, const label nFacets)
42     Name("Interpolated" + Curve.Name),
43     Style(Curve.Style),
44     X(2*nFacets),
45     Y(2*nFacets)
47     // Calculate curve length
48     scalar curveLength=0;
49     register label i;
50     for (i=0; i<Curve.size()-1; i++)
51     {
52         curveLength += distance(Curve[i], Curve[i+1]);
53     }
55     scalar stepLength = curveLength/nFacets;
56     label nPoints = 0;
57     label previous=0, next=1;
58     bool endOfCurve;
59     vector presentPoint=Curve[0], nextPoint;
61     do
62     {
63         endOfCurve =
64         stepForwardsToNextPoint
65         (
66             presentPoint,
67             nextPoint,
68             previous,
69             next,
70             stepLength,
71             Curve
72         );
74         if (!endOfCurve)
75         {
76             if (nPoints >= size()-1)
77             {
78                 setSize(label(1.5*size()));
79             }
81             presentPoint = nextPoint;
83             x()[nPoints] = nextPoint.x();
84             y()[nPoints] = nextPoint.y();
86             nPoints++;
87         }
89     } while (!endOfCurve);
91     setSize(nPoints);
96 // construct given name, style and size
97 curve::curve
99     const string& name,
100     const curveStyle& style,
101     const label l
104     scalarField(l, 0.0),
105     name_(name),
106     style_(style)
110 // construct from the bits
111 curve::curve
113     const string& name,
114     const curveStyle& style,
115     const scalarField& y
118     scalarField(y),
119     name_(name),
120     style_(style)
124 // * * * * * * * * * * * * * * * Friend Functions  * * * * * * * * * * * * * //
126 // Gradient operation
128 curve grad(const curve& Curve)
130     curve gradCurve(Curve);
132     register label i;
133     for (i=1; i<Curve.size()-1; i++)
134     {
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;
140         gradCurve.y()[i] =
141             (
142                 (Curve[i+1].y() - Curve[i].y())/sqr(deltaI)
143               + (Curve[i].y() - Curve[i-1].y())/sqr(deltaIm1)
144             )/deltaAv;
145     }
147     gradCurve.y()[0] =
148         (Curve[1].y() - Curve[0].y())/(Curve[1].x() - Curve[0].x());
150     label n = Curve.size()-1;
152     gradCurve.y()[n] =
153         (Curve[n].y() - Curve[n-1].y())/(Curve[n].x() - Curve[n-1].x());
155     return gradCurve;
160 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
162 Ostream& operator<<(Ostream& os, const curve& c)
164     os  << nl
165         << c.name_ << nl
166         << c.style_ << nl
167         << static_cast<const scalarField&>(c);
169     os.check("Ostream& operator>>(Ostream&, const curve&)");
171     return os;
175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177 } // End namespace Foam
179 // ************************************************************************* //