00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2010 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 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your 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, see <http://www.gnu.org/licenses/>. 00023 00024 Description 00025 00026 \*---------------------------------------------------------------------------*/ 00027 00028 #include "curve.H" 00029 //#include "curveTools.H" 00030 #include <OpenFOAM/Ostream.H> 00031 00032 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00033 00034 namespace Foam 00035 { 00036 00037 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // 00038 00039 // construct as interpolation 00040 /* 00041 curve::curve(const curve& Curve, const label nFacets) 00042 : 00043 Name("Interpolated" + Curve.Name), 00044 Style(Curve.Style), 00045 X(2*nFacets), 00046 Y(2*nFacets) 00047 { 00048 // Calculate curve length 00049 scalar curveLength=0; 00050 register label i; 00051 for (i=0; i<Curve.size()-1; i++) 00052 { 00053 curveLength += distance(Curve[i], Curve[i+1]); 00054 } 00055 00056 scalar stepLength = curveLength/nFacets; 00057 label nPoints = 0; 00058 label previous=0, next=1; 00059 bool endOfCurve; 00060 vector presentPoint=Curve[0], nextPoint; 00061 00062 do 00063 { 00064 endOfCurve = 00065 stepForwardsToNextPoint 00066 ( 00067 presentPoint, 00068 nextPoint, 00069 previous, 00070 next, 00071 stepLength, 00072 Curve 00073 ); 00074 00075 if (!endOfCurve) 00076 { 00077 if (nPoints >= size()-1) 00078 { 00079 setSize(label(1.5*size())); 00080 } 00081 00082 presentPoint = nextPoint; 00083 00084 x()[nPoints] = nextPoint.x(); 00085 y()[nPoints] = nextPoint.y(); 00086 00087 nPoints++; 00088 } 00089 00090 } while (!endOfCurve); 00091 00092 setSize(nPoints); 00093 } 00094 */ 00095 00096 00097 // construct given name, style and size 00098 curve::curve 00099 ( 00100 const string& name, 00101 const curveStyle& style, 00102 const label l 00103 ) 00104 : 00105 scalarField(l, 0.0), 00106 name_(name), 00107 style_(style) 00108 {} 00109 00110 00111 // construct from the bits 00112 curve::curve 00113 ( 00114 const string& name, 00115 const curveStyle& style, 00116 const scalarField& y 00117 ) 00118 : 00119 scalarField(y), 00120 name_(name), 00121 style_(style) 00122 {} 00123 00124 00125 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * // 00126 00127 // Gradient operation 00128 /* 00129 curve grad(const curve& Curve) 00130 { 00131 curve gradCurve(Curve); 00132 00133 register label i; 00134 for (i=1; i<Curve.size()-1; i++) 00135 { 00136 scalar deltaIm1 = Curve[i].x() - Curve[i-1].x(); 00137 scalar deltaI = Curve[i+1].x() - Curve[i].x(); 00138 00139 scalar deltaAv = 1.0/deltaIm1 + 1.0/deltaI; 00140 00141 gradCurve.y()[i] = 00142 ( 00143 (Curve[i+1].y() - Curve[i].y())/sqr(deltaI) 00144 + (Curve[i].y() - Curve[i-1].y())/sqr(deltaIm1) 00145 )/deltaAv; 00146 } 00147 00148 gradCurve.y()[0] = 00149 (Curve[1].y() - Curve[0].y())/(Curve[1].x() - Curve[0].x()); 00150 00151 label n = Curve.size()-1; 00152 00153 gradCurve.y()[n] = 00154 (Curve[n].y() - Curve[n-1].y())/(Curve[n].x() - Curve[n-1].x()); 00155 00156 return gradCurve; 00157 } 00158 */ 00159 00160 00161 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // 00162 00163 Ostream& operator<<(Ostream& os, const curve& c) 00164 { 00165 os << nl 00166 << c.name_ << nl 00167 << c.style_ << nl 00168 << static_cast<const scalarField&>(c); 00169 00170 os.check("Ostream& operator>>(Ostream&, const curve&)"); 00171 00172 return os; 00173 } 00174 00175 00176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00177 00178 } // End namespace Foam 00179 00180 // ************************ vim: set sw=4 sts=4 et: ************************ //