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

sampledPlane.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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "sampledPlane.H"
00028 #include "dictionary.H"
00029 #include "polyMesh.H"
00030 #include "volFields.H"
00031 
00032 #include "addToRunTimeSelectionTable.H"
00033 
00034 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00035 
00036 namespace Foam
00037 {
00038     defineTypeNameAndDebug(sampledPlane, 0);
00039     addNamedToRunTimeSelectionTable(sampledSurface, sampledPlane, word, plane);
00040 }
00041 
00042 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00043 
00044 Foam::sampledPlane::sampledPlane
00045 (
00046     const word& name,
00047     const polyMesh& mesh,
00048     const plane& planeDesc,
00049     const word& zoneName
00050 )
00051 :
00052     sampledSurface(name, mesh),
00053     cuttingPlane(planeDesc),
00054     zoneName_(zoneName),
00055     needsUpdate_(true)
00056 {
00057     if (debug && zoneName_.size())
00058     {
00059         if (mesh.cellZones().findZoneID(zoneName_) < 0)
00060         {
00061             Info<< "cellZone \"" << zoneName_
00062                 << "\" not found - using entire mesh" << endl;
00063         }
00064     }
00065 }
00066 
00067 
00068 Foam::sampledPlane::sampledPlane
00069 (
00070     const word& name,
00071     const polyMesh& mesh,
00072     const dictionary& dict
00073 )
00074 :
00075     sampledSurface(name, mesh, dict),
00076     cuttingPlane(plane(dict.lookup("basePoint"), dict.lookup("normalVector"))),
00077     zoneName_(word::null),
00078     needsUpdate_(true)
00079 {
00080     // make plane relative to the coordinateSystem (Cartesian)
00081     // allow lookup from global coordinate systems
00082     if (dict.found("coordinateSystem"))
00083     {
00084         coordinateSystem cs(dict, mesh);
00085 
00086         point  base = cs.globalPosition(planeDesc().refPoint());
00087         vector norm = cs.globalVector(planeDesc().normal());
00088 
00089         // assign the plane description
00090         static_cast<plane&>(*this) = plane(base, norm);
00091     }
00092 
00093     dict.readIfPresent("zone", zoneName_);
00094 
00095     if (debug && zoneName_.size())
00096     {
00097         if (mesh.cellZones().findZoneID(zoneName_) < 0)
00098         {
00099             Info<< "cellZone \"" << zoneName_
00100                 << "\" not found - using entire mesh" << endl;
00101         }
00102     }
00103 
00104 }
00105 
00106 
00107 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00108 
00109 Foam::sampledPlane::~sampledPlane()
00110 {}
00111 
00112 
00113 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00114 
00115 bool Foam::sampledPlane::needsUpdate() const
00116 {
00117     return needsUpdate_;
00118 }
00119 
00120 
00121 bool Foam::sampledPlane::expire()
00122 {
00123     // already marked as expired
00124     if (needsUpdate_)
00125     {
00126         return false;
00127     }
00128 
00129     sampledSurface::clearGeom();
00130 
00131     needsUpdate_ = true;
00132     return true;
00133 }
00134 
00135 
00136 bool Foam::sampledPlane::update()
00137 {
00138     if (!needsUpdate_)
00139     {
00140         return false;
00141     }
00142 
00143     sampledSurface::clearGeom();
00144 
00145     label zoneId = -1;
00146     if (zoneName_.size())
00147     {
00148         zoneId = mesh().cellZones().findZoneID(zoneName_);
00149     }
00150 
00151     if (zoneId < 0)
00152     {
00153         reCut(mesh());
00154     }
00155     else
00156     {
00157         reCut(mesh(), mesh().cellZones()[zoneId]);
00158     }
00159 
00160     if (debug)
00161     {
00162         print(Pout);
00163         Pout << endl;
00164     }
00165 
00166     needsUpdate_ = false;
00167     return true;
00168 }
00169 
00170 
00171 Foam::tmp<Foam::scalarField>
00172 Foam::sampledPlane::sample
00173 (
00174     const volScalarField& vField
00175 ) const
00176 {
00177     return sampleField(vField);
00178 }
00179 
00180 
00181 Foam::tmp<Foam::vectorField>
00182 Foam::sampledPlane::sample
00183 (
00184     const volVectorField& vField
00185 ) const
00186 {
00187     return sampleField(vField);
00188 }
00189 
00190 
00191 Foam::tmp<Foam::sphericalTensorField>
00192 Foam::sampledPlane::sample
00193 (
00194     const volSphericalTensorField& vField
00195 ) const
00196 {
00197     return sampleField(vField);
00198 }
00199 
00200 
00201 Foam::tmp<Foam::symmTensorField>
00202 Foam::sampledPlane::sample
00203 (
00204     const volSymmTensorField& vField
00205 ) const
00206 {
00207     return sampleField(vField);
00208 }
00209 
00210 
00211 Foam::tmp<Foam::tensorField>
00212 Foam::sampledPlane::sample
00213 (
00214     const volTensorField& vField
00215 ) const
00216 {
00217     return sampleField(vField);
00218 }
00219 
00220 
00221 Foam::tmp<Foam::scalarField>
00222 Foam::sampledPlane::interpolate
00223 (
00224     const interpolation<scalar>& interpolator
00225 ) const
00226 {
00227     return interpolateField(interpolator);
00228 }
00229 
00230 
00231 Foam::tmp<Foam::vectorField>
00232 Foam::sampledPlane::interpolate
00233 (
00234     const interpolation<vector>& interpolator
00235 ) const
00236 {
00237     return interpolateField(interpolator);
00238 }
00239 
00240 Foam::tmp<Foam::sphericalTensorField>
00241 Foam::sampledPlane::interpolate
00242 (
00243     const interpolation<sphericalTensor>& interpolator
00244 ) const
00245 {
00246     return interpolateField(interpolator);
00247 }
00248 
00249 
00250 Foam::tmp<Foam::symmTensorField>
00251 Foam::sampledPlane::interpolate
00252 (
00253     const interpolation<symmTensor>& interpolator
00254 ) const
00255 {
00256     return interpolateField(interpolator);
00257 }
00258 
00259 
00260 Foam::tmp<Foam::tensorField>
00261 Foam::sampledPlane::interpolate
00262 (
00263     const interpolation<tensor>& interpolator
00264 ) const
00265 {
00266     return interpolateField(interpolator);
00267 }
00268 
00269 
00270 void Foam::sampledPlane::print(Ostream& os) const
00271 {
00272     os  << "sampledPlane: " << name() << " :"
00273         << "  base:" << refPoint()
00274         << "  normal:" << normal()
00275         << "  faces:" << faces().size()
00276         << "  points:" << points().size();
00277 }
00278 
00279 
00280 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd