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

sampledThresholdCellFaces.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 "sampledThresholdCellFaces.H"
00028 
00029 #include "dictionary.H"
00030 #include "volFields.H"
00031 #include "volPointInterpolation.H"
00032 #include "addToRunTimeSelectionTable.H"
00033 #include "fvMesh.H"
00034 #include "thresholdCellFaces.H"
00035 
00036 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00037 
00038 namespace Foam
00039 {
00040     defineTypeNameAndDebug(sampledThresholdCellFaces, 0);
00041     addNamedToRunTimeSelectionTable
00042     (
00043         sampledSurface,
00044         sampledThresholdCellFaces,
00045         word,
00046         thresholdCellFaces
00047     );
00048 }
00049 
00050 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00051 
00052 bool Foam::sampledThresholdCellFaces::updateGeometry() const
00053 {
00054     const fvMesh& fvm = static_cast<const fvMesh&>(mesh());
00055 
00056     // no update needed
00057     if (fvm.time().timeIndex() == prevTimeIndex_)
00058     {
00059         return false;
00060     }
00061 
00062     prevTimeIndex_ = fvm.time().timeIndex();
00063 
00064     // Optionally read volScalarField
00065     autoPtr<volScalarField> readFieldPtr_;
00066 
00067     // 1. see if field in database
00068     // 2. see if field can be read
00069     const volScalarField* cellFldPtr = NULL;
00070     if (fvm.foundObject<volScalarField>(fieldName_))
00071     {
00072         if (debug)
00073         {
00074             Info<< "sampledThresholdCellFaces::updateGeometry() : lookup "
00075                 << fieldName_ << endl;
00076         }
00077 
00078         cellFldPtr = &fvm.lookupObject<volScalarField>(fieldName_);
00079     }
00080     else
00081     {
00082         // Bit of a hack. Read field and store.
00083 
00084         if (debug)
00085         {
00086             Info<< "sampledThresholdCellFaces::updateGeometry() : reading "
00087                 << fieldName_ << " from time " << fvm.time().timeName()
00088                 << endl;
00089         }
00090 
00091         readFieldPtr_.reset
00092         (
00093             new volScalarField
00094             (
00095                 IOobject
00096                 (
00097                     fieldName_,
00098                     fvm.time().timeName(),
00099                     fvm,
00100                     IOobject::MUST_READ,
00101                     IOobject::NO_WRITE,
00102                     false
00103                 ),
00104                 fvm
00105             )
00106         );
00107 
00108         cellFldPtr = readFieldPtr_.operator->();
00109     }
00110     const volScalarField& cellFld = *cellFldPtr;
00111 
00112 
00113     thresholdCellFaces surf
00114     (
00115         fvm,
00116         cellFld.internalField(),
00117         lowerThreshold_,
00118         upperThreshold_,
00119         triangulate_
00120     );
00121 
00122     const_cast<sampledThresholdCellFaces&>
00123     (
00124         *this
00125     ).MeshedSurface<face>::transfer(surf);
00126     meshCells_.transfer(surf.meshCells());
00127 
00128 
00129     if (debug)
00130     {
00131         Pout<< "sampledThresholdCellFaces::updateGeometry() : constructed"
00132             << nl
00133             << "    field         : " << fieldName_ << nl
00134             << "    lowerLimit    : " << lowerThreshold_ << nl
00135             << "    upperLimit    : " << upperThreshold_ << nl
00136             << "    point         : " << points().size() << nl
00137             << "    faces         : " << faces().size() << nl
00138             << "    cut cells     : " << meshCells_.size() << endl;
00139     }
00140 
00141     return true;
00142 }
00143 
00144 
00145 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00146 
00147 Foam::sampledThresholdCellFaces::sampledThresholdCellFaces
00148 (
00149     const word& name,
00150     const polyMesh& mesh,
00151     const dictionary& dict
00152 )
00153 :
00154     sampledSurface(name, mesh, dict),
00155     fieldName_(dict.lookup("field")),
00156     lowerThreshold_(dict.lookupOrDefault<scalar>("lowerLimit", -VGREAT)),
00157     upperThreshold_(dict.lookupOrDefault<scalar>("upperLimit", VGREAT)),
00158     zoneName_(word::null),
00159     triangulate_(dict.lookupOrDefault("triangulate", false)),
00160     prevTimeIndex_(-1),
00161     meshCells_(0)
00162 {
00163     if (!dict.found("lowerLimit") && !dict.found("upperLimit"))
00164     {
00165         FatalErrorIn
00166             (
00167                 "sampledThresholdCellFaces::sampledThresholdCellFaces(..)"
00168             )
00169             << "require at least one of 'lowerLimit' or 'upperLimit'" << endl
00170             << abort(FatalError);
00171     }
00172 
00173 
00174 //    dict.readIfPresent("zone", zoneName_);
00175 //
00176 //    if (debug && zoneName_.size())
00177 //    {
00178 //        if (mesh.cellZones().findZoneID(zoneName_) < 0)
00179 //        {
00180 //            Info<< "cellZone \"" << zoneName_
00181 //                << "\" not found - using entire mesh" << endl;
00182 //        }
00183 //    }
00184 }
00185 
00186 
00187 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00188 
00189 Foam::sampledThresholdCellFaces::~sampledThresholdCellFaces()
00190 {}
00191 
00192 
00193 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00194 
00195 bool Foam::sampledThresholdCellFaces::needsUpdate() const
00196 {
00197     const fvMesh& fvm = static_cast<const fvMesh&>(mesh());
00198 
00199     return fvm.time().timeIndex() != prevTimeIndex_;
00200 }
00201 
00202 
00203 bool Foam::sampledThresholdCellFaces::expire()
00204 {
00205     // already marked as expired
00206     if (prevTimeIndex_ == -1)
00207     {
00208         return false;
00209     }
00210 
00211     // force update
00212     prevTimeIndex_ = -1;
00213     return true;
00214 }
00215 
00216 
00217 bool Foam::sampledThresholdCellFaces::update()
00218 {
00219     return updateGeometry();
00220 }
00221 
00222 
00223 Foam::tmp<Foam::scalarField>
00224 Foam::sampledThresholdCellFaces::sample
00225 (
00226     const volScalarField& vField
00227 ) const
00228 {
00229     return sampleField(vField);
00230 }
00231 
00232 
00233 Foam::tmp<Foam::vectorField>
00234 Foam::sampledThresholdCellFaces::sample
00235 (
00236     const volVectorField& vField
00237 ) const
00238 {
00239     return sampleField(vField);
00240 }
00241 
00242 
00243 Foam::tmp<Foam::sphericalTensorField>
00244 Foam::sampledThresholdCellFaces::sample
00245 (
00246     const volSphericalTensorField& vField
00247 ) const
00248 {
00249     return sampleField(vField);
00250 }
00251 
00252 
00253 Foam::tmp<Foam::symmTensorField>
00254 Foam::sampledThresholdCellFaces::sample
00255 (
00256     const volSymmTensorField& vField
00257 ) const
00258 {
00259     return sampleField(vField);
00260 }
00261 
00262 
00263 Foam::tmp<Foam::tensorField>
00264 Foam::sampledThresholdCellFaces::sample
00265 (
00266     const volTensorField& vField
00267 ) const
00268 {
00269     return sampleField(vField);
00270 }
00271 
00272 
00273 Foam::tmp<Foam::scalarField>
00274 Foam::sampledThresholdCellFaces::interpolate
00275 (
00276     const interpolation<scalar>& interpolator
00277 ) const
00278 {
00279     return interpolateField(interpolator);
00280 }
00281 
00282 
00283 Foam::tmp<Foam::vectorField>
00284 Foam::sampledThresholdCellFaces::interpolate
00285 (
00286     const interpolation<vector>& interpolator
00287 ) const
00288 {
00289     return interpolateField(interpolator);
00290 }
00291 
00292 Foam::tmp<Foam::sphericalTensorField>
00293 Foam::sampledThresholdCellFaces::interpolate
00294 (
00295     const interpolation<sphericalTensor>& interpolator
00296 ) const
00297 {
00298     return interpolateField(interpolator);
00299 }
00300 
00301 
00302 Foam::tmp<Foam::symmTensorField>
00303 Foam::sampledThresholdCellFaces::interpolate
00304 (
00305     const interpolation<symmTensor>& interpolator
00306 ) const
00307 {
00308     return interpolateField(interpolator);
00309 }
00310 
00311 
00312 Foam::tmp<Foam::tensorField>
00313 Foam::sampledThresholdCellFaces::interpolate
00314 (
00315     const interpolation<tensor>& interpolator
00316 ) const
00317 {
00318     return interpolateField(interpolator);
00319 }
00320 
00321 
00322 void Foam::sampledThresholdCellFaces::print(Ostream& os) const
00323 {
00324     os  << "sampledThresholdCellFaces: " << name() << " :"
00325         << "  field:" << fieldName_
00326         << "  lowerLimit:" << lowerThreshold_
00327         << "  upperLimit:" << upperThreshold_;
00328         //<< "  faces:" << faces().size()   // possibly no geom yet
00329         //<< "  points:" << points().size();
00330 }
00331 
00332 
00333 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd