OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

curve.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "curve.H"
00030 //#include "curveTools.H"
00031 #include "Ostream.H"
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 namespace Foam
00036 {
00037 
00038 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00039 
00040 // construct as interpolation
00041 /*
00042 curve::curve(const curve& Curve, const label nFacets)
00043 :
00044     Name("Interpolated" + Curve.Name),
00045     Style(Curve.Style),
00046     X(2*nFacets),
00047     Y(2*nFacets)
00048 {
00049     // Calculate curve length
00050     scalar curveLength=0;
00051     register label i;
00052     for (i=0; i<Curve.size()-1; i++)
00053     {
00054         curveLength += distance(Curve[i], Curve[i+1]);
00055     }
00056 
00057     scalar stepLength = curveLength/nFacets;
00058     label nPoints = 0;
00059     label previous=0, next=1;
00060     bool endOfCurve;
00061     vector presentPoint=Curve[0], nextPoint;
00062 
00063     do
00064     {
00065         endOfCurve =
00066         stepForwardsToNextPoint
00067         (
00068             presentPoint,
00069             nextPoint,
00070             previous,
00071             next,
00072             stepLength,
00073             Curve
00074         );
00075 
00076         if (!endOfCurve)
00077         {
00078             if (nPoints >= size()-1)
00079             {
00080                 setSize(label(1.5*size()));
00081             }
00082 
00083             presentPoint = nextPoint;
00084 
00085             x()[nPoints] = nextPoint.x();
00086             y()[nPoints] = nextPoint.y();
00087 
00088             nPoints++;
00089         }
00090 
00091     } while (!endOfCurve);
00092 
00093     setSize(nPoints);
00094 }
00095 */
00096 
00097 
00098 // construct given name, style and size
00099 curve::curve
00100 (
00101     const string& name,
00102     const curveStyle& style,
00103     const label l
00104 )
00105 :
00106     scalarField(l, 0.0),
00107     name_(name),
00108     style_(style)
00109 {}
00110 
00111 
00112 // construct from the bits
00113 curve::curve
00114 (
00115     const string& name,
00116     const curveStyle& style,
00117     const scalarField& y
00118 )
00119 :
00120     scalarField(y),
00121     name_(name),
00122     style_(style)
00123 {}
00124 
00125 
00126 // * * * * * * * * * * * * * * * Friend Functions  * * * * * * * * * * * * * //
00127 
00128 // Gradient operation
00129 /*
00130 curve grad(const curve& Curve)
00131 {
00132     curve gradCurve(Curve);
00133 
00134     register label i;
00135     for (i=1; i<Curve.size()-1; i++)
00136     {
00137         scalar deltaIm1 = Curve[i].x() - Curve[i-1].x();
00138         scalar deltaI = Curve[i+1].x() - Curve[i].x();
00139 
00140         scalar deltaAv = 1.0/deltaIm1 + 1.0/deltaI;
00141 
00142         gradCurve.y()[i] =
00143             (
00144                 (Curve[i+1].y() - Curve[i].y())/sqr(deltaI)
00145               + (Curve[i].y() - Curve[i-1].y())/sqr(deltaIm1)
00146             )/deltaAv;
00147     }
00148 
00149     gradCurve.y()[0] =
00150         (Curve[1].y() - Curve[0].y())/(Curve[1].x() - Curve[0].x());
00151 
00152     label n = Curve.size()-1;
00153 
00154     gradCurve.y()[n] =
00155         (Curve[n].y() - Curve[n-1].y())/(Curve[n].x() - Curve[n-1].x());
00156 
00157     return gradCurve;
00158 }
00159 */
00160 
00161 
00162 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
00163 
00164 Ostream& operator<<(Ostream& os, const curve& c)
00165 {
00166     os  << nl
00167         << c.name_ << nl
00168         << c.style_ << nl
00169         << static_cast<const scalarField&>(c);
00170 
00171     os.check("Ostream& operator>>(Ostream&, const curve&)");
00172 
00173     return os;
00174 }
00175 
00176 
00177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00178 
00179 } // End namespace Foam
00180 
00181 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd