ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / sampling / sampledSurface / isoSurface / sampledIsoSurfaceCell.C
blob239217a352c365316da312e91a14992ea8a2fd0c
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "sampledIsoSurfaceCell.H"
27 #include "dictionary.H"
28 #include "volFields.H"
29 #include "volPointInterpolation.H"
30 #include "addToRunTimeSelectionTable.H"
31 #include "fvMesh.H"
32 #include "isoSurfaceCell.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 namespace Foam
38     defineTypeNameAndDebug(sampledIsoSurfaceCell, 0);
39     addNamedToRunTimeSelectionTable
40     (
41         sampledSurface,
42         sampledIsoSurfaceCell,
43         word,
44         isoSurfaceCell
45     );
48 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
50 bool Foam::sampledIsoSurfaceCell::updateGeometry() const
52     const fvMesh& fvm = static_cast<const fvMesh&>(mesh());
54     // no update needed
55     if (fvm.time().timeIndex() == prevTimeIndex_)
56     {
57         return false;
58     }
60     prevTimeIndex_ = fvm.time().timeIndex();
62     // Clear any stored topo
63     facesPtr_.clear();
65     // Clear derived data
66     sampledSurface::clearGeom();
68     // Optionally read volScalarField
69     autoPtr<volScalarField> readFieldPtr_;
71     // 1. see if field in database
72     // 2. see if field can be read
73     const volScalarField* cellFldPtr = NULL;
74     if (fvm.foundObject<volScalarField>(isoField_))
75     {
76         if (debug)
77         {
78             Info<< "sampledIsoSurfaceCell::updateGeometry() : lookup "
79                 << isoField_ << endl;
80         }
82         cellFldPtr = &fvm.lookupObject<volScalarField>(isoField_);
83     }
84     else
85     {
86         // Bit of a hack. Read field and store.
88         if (debug)
89         {
90             Info<< "sampledIsoSurfaceCell::updateGeometry() : reading "
91                 << isoField_ << " from time " <<fvm.time().timeName()
92                 << endl;
93         }
95         readFieldPtr_.reset
96         (
97             new volScalarField
98             (
99                 IOobject
100                 (
101                     isoField_,
102                     fvm.time().timeName(),
103                     fvm,
104                     IOobject::MUST_READ,
105                     IOobject::NO_WRITE,
106                     false
107                 ),
108                 fvm
109             )
110         );
112         cellFldPtr = readFieldPtr_.operator->();
113     }
114     const volScalarField& cellFld = *cellFldPtr;
116     tmp<pointScalarField> pointFld
117     (
118         volPointInterpolation::New(fvm).interpolate(cellFld)
119     );
121     if (average_)
122     {
123         //- From point field and interpolated cell.
124         scalarField cellAvg(fvm.nCells(), scalar(0.0));
125         labelField nPointCells(fvm.nCells(), 0);
126         {
127             for (label pointI = 0; pointI < fvm.nPoints(); pointI++)
128             {
129                 const labelList& pCells = fvm.pointCells(pointI);
131                 forAll(pCells, i)
132                 {
133                     label cellI = pCells[i];
135                     cellAvg[cellI] += pointFld().internalField()[pointI];
136                     nPointCells[cellI]++;
137                 }
138             }
139         }
140         forAll(cellAvg, cellI)
141         {
142             cellAvg[cellI] /= nPointCells[cellI];
143         }
145         const isoSurfaceCell iso
146         (
147             fvm,
148             cellAvg,
149             pointFld().internalField(),
150             isoVal_,
151             regularise_
152         );
154         const_cast<sampledIsoSurfaceCell&>
155         (
156             *this
157         ).triSurface::operator=(iso);
158         meshCells_ = iso.meshCells();
159     }
160     else
161     {
162         //- Direct from cell field and point field. Gives bad continuity.
163         const isoSurfaceCell iso
164         (
165             fvm,
166             cellFld.internalField(),
167             pointFld().internalField(),
168             isoVal_,
169             regularise_
170         );
172         const_cast<sampledIsoSurfaceCell&>
173         (
174             *this
175         ).triSurface::operator=(iso);
176         meshCells_ = iso.meshCells();
177     }
180     if (debug)
181     {
182         Pout<< "sampledIsoSurfaceCell::updateGeometry() : constructed iso:"
183             << nl
184             << "    regularise     : " << regularise_ << nl
185             << "    average        : " << average_ << nl
186             << "    isoField       : " << isoField_ << nl
187             << "    isoValue       : " << isoVal_ << nl
188             << "    points         : " << points().size() << nl
189             << "    tris           : " << triSurface::size() << nl
190             << "    cut cells      : " << meshCells_.size() << endl;
191     }
193     return true;
197 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
199 Foam::sampledIsoSurfaceCell::sampledIsoSurfaceCell
201     const word& name,
202     const polyMesh& mesh,
203     const dictionary& dict
206     sampledSurface(name, mesh, dict),
207     isoField_(dict.lookup("isoField")),
208     isoVal_(readScalar(dict.lookup("isoValue"))),
209     regularise_(dict.lookupOrDefault("regularise", true)),
210     average_(dict.lookupOrDefault("average", true)),
211     zoneKey_(keyType::null),
212     facesPtr_(NULL),
213     prevTimeIndex_(-1),
214     meshCells_(0)
216 //    dict.readIfPresent("zone", zoneKey_);
218 //    if (debug && zoneKey_.size() && mesh.cellZones().findZoneID(zoneKey_) < 0)
219 //    {
220 //        Info<< "cellZone " << zoneKey_
221 //            << " not found - using entire mesh" << endl;
222 //    }
226 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
228 Foam::sampledIsoSurfaceCell::~sampledIsoSurfaceCell()
232 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
234 bool Foam::sampledIsoSurfaceCell::needsUpdate() const
236     const fvMesh& fvm = static_cast<const fvMesh&>(mesh());
238     return fvm.time().timeIndex() != prevTimeIndex_;
242 bool Foam::sampledIsoSurfaceCell::expire()
244     facesPtr_.clear();
246     // Clear derived data
247     sampledSurface::clearGeom();
249     // already marked as expired
250     if (prevTimeIndex_ == -1)
251     {
252         return false;
253     }
255     // force update
256     prevTimeIndex_ = -1;
257     return true;
261 bool Foam::sampledIsoSurfaceCell::update()
263     return updateGeometry();
267 Foam::tmp<Foam::scalarField>
268 Foam::sampledIsoSurfaceCell::sample
270     const volScalarField& vField
271 ) const
273     return sampleField(vField);
277 Foam::tmp<Foam::vectorField>
278 Foam::sampledIsoSurfaceCell::sample
280     const volVectorField& vField
281 ) const
283     return sampleField(vField);
287 Foam::tmp<Foam::sphericalTensorField>
288 Foam::sampledIsoSurfaceCell::sample
290     const volSphericalTensorField& vField
291 ) const
293     return sampleField(vField);
297 Foam::tmp<Foam::symmTensorField>
298 Foam::sampledIsoSurfaceCell::sample
300     const volSymmTensorField& vField
301 ) const
303     return sampleField(vField);
307 Foam::tmp<Foam::tensorField>
308 Foam::sampledIsoSurfaceCell::sample
310     const volTensorField& vField
311 ) const
313     return sampleField(vField);
317 Foam::tmp<Foam::scalarField>
318 Foam::sampledIsoSurfaceCell::interpolate
320     const interpolation<scalar>& interpolator
321 ) const
323     return interpolateField(interpolator);
327 Foam::tmp<Foam::vectorField>
328 Foam::sampledIsoSurfaceCell::interpolate
330     const interpolation<vector>& interpolator
331 ) const
333     return interpolateField(interpolator);
336 Foam::tmp<Foam::sphericalTensorField>
337 Foam::sampledIsoSurfaceCell::interpolate
339     const interpolation<sphericalTensor>& interpolator
340 ) const
342     return interpolateField(interpolator);
346 Foam::tmp<Foam::symmTensorField>
347 Foam::sampledIsoSurfaceCell::interpolate
349     const interpolation<symmTensor>& interpolator
350 ) const
352     return interpolateField(interpolator);
356 Foam::tmp<Foam::tensorField>
357 Foam::sampledIsoSurfaceCell::interpolate
359     const interpolation<tensor>& interpolator
360 ) const
362     return interpolateField(interpolator);
366 void Foam::sampledIsoSurfaceCell::print(Ostream& os) const
368     os  << "sampledIsoSurfaceCell: " << name() << " :"
369         << "  field:" << isoField_
370         << "  value:" << isoVal_;
371         //<< "  faces:" << faces().size()   // possibly no geom yet
372         //<< "  points:" << points().size();
376 // ************************************************************************* //