initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / graph / curve / curve.C
bloba692ea7c29e4112b7630d4d365635c5a591af609
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
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 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
19     for more details.
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
25 Description
27 \*---------------------------------------------------------------------------*/
29 #include "curve.H"
30 //#include "curveTools.H"
31 #include "Ostream.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 namespace Foam
38 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
40 // construct as interpolation
42 curve::curve(const curve& Curve, const label nFacets)
44     Name("Interpolated" + Curve.Name),
45     Style(Curve.Style),
46     X(2*nFacets),
47     Y(2*nFacets)
49     // Calculate curve length
50     scalar curveLength=0;
51     register label i;
52     for (i=0; i<Curve.size()-1; i++)
53     {
54         curveLength += distance(Curve[i], Curve[i+1]);
55     }
57     scalar stepLength = curveLength/nFacets;
58     label nPoints = 0;
59     label previous=0, next=1;
60     bool endOfCurve;
61     vector presentPoint=Curve[0], nextPoint;
63     do
64     {
65         endOfCurve =
66         stepForwardsToNextPoint
67         (
68             presentPoint,
69             nextPoint,
70             previous,
71             next,
72             stepLength,
73             Curve
74         );
76         if (!endOfCurve)
77         {
78             if (nPoints >= size()-1)
79             {
80                 setSize(label(1.5*size()));
81             }
83             presentPoint = nextPoint;
85             x()[nPoints] = nextPoint.x();
86             y()[nPoints] = nextPoint.y();
88             nPoints++;
89         }
91     } while (!endOfCurve);
93     setSize(nPoints);
98 // construct given name, style and size
99 curve::curve
101     const string& name,
102     const curveStyle& style,
103     const label l
106     scalarField(l, 0.0),
107     name_(name),
108     style_(style)
112 // construct from the bits
113 curve::curve
115     const string& name,
116     const curveStyle& style,
117     const scalarField& y
120     scalarField(y),
121     name_(name),
122     style_(style)
126 // * * * * * * * * * * * * * * * Friend Functions  * * * * * * * * * * * * * //
128 // Gradient operation
130 curve grad(const curve& Curve)
132     curve gradCurve(Curve);
134     register label i;
135     for (i=1; i<Curve.size()-1; i++)
136     {
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;
142         gradCurve.y()[i] =
143             (
144                 (Curve[i+1].y() - Curve[i].y())/sqr(deltaI)
145               + (Curve[i].y() - Curve[i-1].y())/sqr(deltaIm1)
146             )/deltaAv;
147     }
149     gradCurve.y()[0] =
150         (Curve[1].y() - Curve[0].y())/(Curve[1].x() - Curve[0].x());
152     label n = Curve.size()-1;
154     gradCurve.y()[n] =
155         (Curve[n].y() - Curve[n-1].y())/(Curve[n].x() - Curve[n-1].x());
157     return gradCurve;
162 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
164 Ostream& operator<<(Ostream& os, const curve& c)
166     os  << nl
167         << c.name_ << nl
168         << c.style_ << nl
169         << static_cast<const scalarField&>(c);
171     os.check("Ostream& operator>>(Ostream&, const curve&)");
173     return os;
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
179 } // End namespace Foam
181 // ************************************************************************* //