BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / OpenFOAM / graph / curve / curve.C
blob4e0206ebc9615a9a7ad4a71b2cd82cbfafd90dc7
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
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
19     for more details.
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 \*---------------------------------------------------------------------------*/
26 #include "curve.H"
27 //#include "curveTools.H"
28 #include "Ostream.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 namespace Foam
35 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
37 // construct as interpolation
39 curve::curve(const curve& Curve, const label nFacets)
41     Name("Interpolated" + Curve.Name),
42     Style(Curve.Style),
43     X(2*nFacets),
44     Y(2*nFacets)
46     // Calculate curve length
47     scalar curveLength=0;
48     register label i;
49     for (i=0; i<Curve.size()-1; i++)
50     {
51         curveLength += distance(Curve[i], Curve[i+1]);
52     }
54     scalar stepLength = curveLength/nFacets;
55     label nPoints = 0;
56     label previous=0, next=1;
57     bool endOfCurve;
58     vector presentPoint=Curve[0], nextPoint;
60     do
61     {
62         endOfCurve =
63         stepForwardsToNextPoint
64         (
65             presentPoint,
66             nextPoint,
67             previous,
68             next,
69             stepLength,
70             Curve
71         );
73         if (!endOfCurve)
74         {
75             if (nPoints >= size()-1)
76             {
77                 setSize(label(1.5*size()));
78             }
80             presentPoint = nextPoint;
82             x()[nPoints] = nextPoint.x();
83             y()[nPoints] = nextPoint.y();
85             nPoints++;
86         }
88     } while (!endOfCurve);
90     setSize(nPoints);
95 // construct given name, style and size
96 curve::curve
98     const string& name,
99     const curveStyle& style,
100     const label l
103     scalarField(l, 0.0),
104     name_(name),
105     style_(style)
109 // construct from the bits
110 curve::curve
112     const string& name,
113     const curveStyle& style,
114     const scalarField& y
117     scalarField(y),
118     name_(name),
119     style_(style)
123 // * * * * * * * * * * * * * * * Friend Functions  * * * * * * * * * * * * * //
125 // Gradient operation
127 curve grad(const curve& Curve)
129     curve gradCurve(Curve);
131     register label i;
132     for (i=1; i<Curve.size()-1; i++)
133     {
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;
139         gradCurve.y()[i] =
140             (
141                 (Curve[i+1].y() - Curve[i].y())/sqr(deltaI)
142               + (Curve[i].y() - Curve[i-1].y())/sqr(deltaIm1)
143             )/deltaAv;
144     }
146     gradCurve.y()[0] =
147         (Curve[1].y() - Curve[0].y())/(Curve[1].x() - Curve[0].x());
149     label n = Curve.size()-1;
151     gradCurve.y()[n] =
152         (Curve[n].y() - Curve[n-1].y())/(Curve[n].x() - Curve[n-1].x());
154     return gradCurve;
159 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
161 Ostream& operator<<(Ostream& os, const curve& c)
163     os  << nl
164         << c.name_ << nl
165         << c.style_ << nl
166         << static_cast<const scalarField&>(c);
168     os.check("Ostream& operator>>(Ostream&, const curve&)");
170     return os;
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 } // End namespace Foam
178 // ************************************************************************* //