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

sampledPatch.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 "sampledPatch.H"
00028 #include "dictionary.H"
00029 #include "polyMesh.H"
00030 #include "polyPatch.H"
00031 #include "volFields.H"
00032 
00033 #include "addToRunTimeSelectionTable.H"
00034 
00035 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00036 
00037 namespace Foam
00038 {
00039     defineTypeNameAndDebug(sampledPatch, 0);
00040     addNamedToRunTimeSelectionTable(sampledSurface, sampledPatch, word, patch);
00041 }
00042 
00043 
00044 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00045 
00046 Foam::sampledPatch::sampledPatch
00047 (
00048     const word& name,
00049     const polyMesh& mesh,
00050     const word& patchName,
00051     const bool triangulate
00052 )
00053 :
00054     sampledSurface(name, mesh),
00055     patchName_(patchName),
00056     triangulate_(triangulate),
00057     needsUpdate_(true),
00058     patchFaceLabels_(0)
00059 {}
00060 
00061 
00062 Foam::sampledPatch::sampledPatch
00063 (
00064     const word& name,
00065     const polyMesh& mesh,
00066     const dictionary& dict
00067 )
00068 :
00069     sampledSurface(name, mesh, dict),
00070     patchName_(dict.lookup("patchName")),
00071     triangulate_(dict.lookupOrDefault("triangulate", false)),
00072     needsUpdate_(true),
00073     patchFaceLabels_(0)
00074 {}
00075 
00076 
00077 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00078 
00079 Foam::sampledPatch::~sampledPatch()
00080 {}
00081 
00082 
00083 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00084 
00085 bool Foam::sampledPatch::needsUpdate() const
00086 {
00087     return needsUpdate_;
00088 }
00089 
00090 
00091 bool Foam::sampledPatch::expire()
00092 {
00093     // already marked as expired
00094     if (needsUpdate_)
00095     {
00096         return false;
00097     }
00098 
00099     sampledSurface::clearGeom();
00100     MeshStorage::clear();
00101     patchFaceLabels_.clear();
00102 
00103     needsUpdate_ = true;
00104     return true;
00105 }
00106 
00107 
00108 bool Foam::sampledPatch::update()
00109 {
00110     if (!needsUpdate_)
00111     {
00112         return false;
00113     }
00114 
00115     label patchI = mesh().boundaryMesh().findPatchID(patchName_);
00116 
00117     if (patchI != -1)
00118     {
00119         const polyPatch& p = mesh().boundaryMesh()[patchI];
00120         this->storedPoints() = p.localPoints();
00121         this->storedFaces()  = p.localFaces();
00122 
00123         // an identity map
00124         patchFaceLabels_.setSize(faces().size());
00125         forAll(patchFaceLabels_, i)
00126         {
00127             patchFaceLabels_[i] = i;
00128         }
00129 
00130         // triangulate uses remapFaces()
00131         // - this is somewhat less efficient since it recopies the faces
00132         // that we just created, but we probably don't want to do this
00133         // too often anyhow.
00134         if (triangulate_)
00135         {
00136             MeshStorage::triangulate();
00137         }
00138     }
00139 
00140     if (debug)
00141     {
00142         print(Pout);
00143         Pout << endl;
00144     }
00145 
00146     needsUpdate_ = false;
00147     return true;
00148 }
00149 
00150 
00151 // remap action on triangulation
00152 void Foam::sampledPatch::remapFaces
00153 (
00154     const UList<label>& faceMap
00155 )
00156 {
00157     // recalculate the cells cut
00158     if (&faceMap && faceMap.size())
00159     {
00160         MeshStorage::remapFaces(faceMap);
00161     }
00162 }
00163 
00164 
00165 
00166 Foam::tmp<Foam::scalarField>
00167 Foam::sampledPatch::sample
00168 (
00169     const volScalarField& vField
00170 ) const
00171 {
00172     return sampleField(vField);
00173 }
00174 
00175 
00176 Foam::tmp<Foam::vectorField>
00177 Foam::sampledPatch::sample
00178 (
00179     const volVectorField& vField
00180 ) const
00181 {
00182     return sampleField(vField);
00183 }
00184 
00185 Foam::tmp<Foam::sphericalTensorField>
00186 Foam::sampledPatch::sample
00187 (
00188     const volSphericalTensorField& vField
00189 ) const
00190 {
00191     return sampleField(vField);
00192 }
00193 
00194 
00195 Foam::tmp<Foam::symmTensorField>
00196 Foam::sampledPatch::sample
00197 (
00198     const volSymmTensorField& vField
00199 ) const
00200 {
00201     return sampleField(vField);
00202 }
00203 
00204 
00205 Foam::tmp<Foam::tensorField>
00206 Foam::sampledPatch::sample
00207 (
00208     const volTensorField& vField
00209 ) const
00210 {
00211     return sampleField(vField);
00212 }
00213 
00214 
00215 Foam::tmp<Foam::scalarField>
00216 Foam::sampledPatch::interpolate
00217 (
00218     const interpolation<scalar>& interpolator
00219 ) const
00220 {
00221     return interpolateField(interpolator);
00222 }
00223 
00224 
00225 Foam::tmp<Foam::vectorField>
00226 Foam::sampledPatch::interpolate
00227 (
00228     const interpolation<vector>& interpolator
00229 ) const
00230 {
00231     return interpolateField(interpolator);
00232 }
00233 
00234 Foam::tmp<Foam::sphericalTensorField>
00235 Foam::sampledPatch::interpolate
00236 (
00237     const interpolation<sphericalTensor>& interpolator
00238 ) const
00239 {
00240     return interpolateField(interpolator);
00241 }
00242 
00243 
00244 Foam::tmp<Foam::symmTensorField>
00245 Foam::sampledPatch::interpolate
00246 (
00247     const interpolation<symmTensor>& interpolator
00248 ) const
00249 {
00250     return interpolateField(interpolator);
00251 }
00252 
00253 
00254 Foam::tmp<Foam::tensorField>
00255 Foam::sampledPatch::interpolate
00256 (
00257     const interpolation<tensor>& interpolator
00258 ) const
00259 {
00260     return interpolateField(interpolator);
00261 }
00262 
00263 
00264 void Foam::sampledPatch::print(Ostream& os) const
00265 {
00266     os  << "sampledPatch: " << name() << " :"
00267         << "  patch:" << patchName()
00268         << "  faces:" << faces().size()
00269         << "  points:" << points().size();
00270 }
00271 
00272 
00273 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd