sampledIsoSurfaceCell.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "sampledIsoSurfaceCell.H"
00028 #include "dictionary.H"
00029 #include "volFields.H"
00030 #include "volPointInterpolation.H"
00031 #include "addToRunTimeSelectionTable.H"
00032 #include "fvMesh.H"
00033 #include "isoSurfaceCell.H"
00034
00035
00036
00037 namespace Foam
00038 {
00039 defineTypeNameAndDebug(sampledIsoSurfaceCell, 0);
00040 addNamedToRunTimeSelectionTable(sampledSurface, sampledIsoSurfaceCell, word, isoSurfaceCell);
00041 }
00042
00043
00044
00045 bool Foam::sampledIsoSurfaceCell::updateGeometry() const
00046 {
00047 const fvMesh& fvm = static_cast<const fvMesh&>(mesh());
00048
00049
00050 if (fvm.time().timeIndex() == prevTimeIndex_)
00051 {
00052 return false;
00053 }
00054
00055 prevTimeIndex_ = fvm.time().timeIndex();
00056
00057
00058 facesPtr_.clear();
00059
00060
00061 autoPtr<volScalarField> readFieldPtr_;
00062
00063
00064
00065 const volScalarField* cellFldPtr = NULL;
00066 if (fvm.foundObject<volScalarField>(isoField_))
00067 {
00068 if (debug)
00069 {
00070 Info<< "sampledIsoSurfaceCell::updateGeometry() : lookup "
00071 << isoField_ << endl;
00072 }
00073
00074 cellFldPtr = &fvm.lookupObject<volScalarField>(isoField_);
00075 }
00076 else
00077 {
00078
00079
00080 if (debug)
00081 {
00082 Info<< "sampledIsoSurfaceCell::updateGeometry() : reading "
00083 << isoField_ << " from time " <<fvm.time().timeName()
00084 << endl;
00085 }
00086
00087 readFieldPtr_.reset
00088 (
00089 new volScalarField
00090 (
00091 IOobject
00092 (
00093 isoField_,
00094 fvm.time().timeName(),
00095 fvm,
00096 IOobject::MUST_READ,
00097 IOobject::NO_WRITE,
00098 false
00099 ),
00100 fvm
00101 )
00102 );
00103
00104 cellFldPtr = readFieldPtr_.operator->();
00105 }
00106 const volScalarField& cellFld = *cellFldPtr;
00107
00108 tmp<pointScalarField> pointFld
00109 (
00110 volPointInterpolation::New(fvm).interpolate(cellFld)
00111 );
00112
00113 if (average_)
00114 {
00115
00116 scalarField cellAvg(fvm.nCells(), scalar(0.0));
00117 labelField nPointCells(fvm.nCells(), 0);
00118 {
00119 for (label pointI = 0; pointI < fvm.nPoints(); pointI++)
00120 {
00121 const labelList& pCells = fvm.pointCells(pointI);
00122
00123 forAll(pCells, i)
00124 {
00125 label cellI = pCells[i];
00126
00127 cellAvg[cellI] += pointFld().internalField()[pointI];
00128 nPointCells[cellI]++;
00129 }
00130 }
00131 }
00132 forAll(cellAvg, cellI)
00133 {
00134 cellAvg[cellI] /= nPointCells[cellI];
00135 }
00136
00137 const isoSurfaceCell iso
00138 (
00139 fvm,
00140 cellAvg,
00141 pointFld().internalField(),
00142 isoVal_,
00143 regularise_
00144 );
00145
00146 const_cast<sampledIsoSurfaceCell&>
00147 (
00148 *this
00149 ).triSurface::operator=(iso);
00150 meshCells_ = iso.meshCells();
00151 }
00152 else
00153 {
00154
00155 const isoSurfaceCell iso
00156 (
00157 fvm,
00158 cellFld.internalField(),
00159 pointFld().internalField(),
00160 isoVal_,
00161 regularise_
00162 );
00163
00164 const_cast<sampledIsoSurfaceCell&>
00165 (
00166 *this
00167 ).triSurface::operator=(iso);
00168 meshCells_ = iso.meshCells();
00169 }
00170
00171
00172 if (debug)
00173 {
00174 Pout<< "sampledIsoSurfaceCell::updateGeometry() : constructed iso:"
00175 << nl
00176 << " regularise : " << regularise_ << nl
00177 << " average : " << average_ << nl
00178 << " isoField : " << isoField_ << nl
00179 << " isoValue : " << isoVal_ << nl
00180 << " points : " << points().size() << nl
00181 << " tris : " << triSurface::size() << nl
00182 << " cut cells : " << meshCells_.size() << endl;
00183 }
00184
00185 return true;
00186 }
00187
00188
00189
00190
00191 Foam::sampledIsoSurfaceCell::sampledIsoSurfaceCell
00192 (
00193 const word& name,
00194 const polyMesh& mesh,
00195 const dictionary& dict
00196 )
00197 :
00198 sampledSurface(name, mesh, dict),
00199 isoField_(dict.lookup("isoField")),
00200 isoVal_(readScalar(dict.lookup("isoValue"))),
00201 regularise_(dict.lookupOrDefault("regularise", true)),
00202 average_(dict.lookupOrDefault("average", true)),
00203 zoneName_(word::null),
00204 facesPtr_(NULL),
00205 prevTimeIndex_(-1),
00206 meshCells_(0)
00207 {
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 }
00219
00220
00221
00222
00223 Foam::sampledIsoSurfaceCell::~sampledIsoSurfaceCell()
00224 {}
00225
00226
00227
00228
00229 bool Foam::sampledIsoSurfaceCell::needsUpdate() const
00230 {
00231 const fvMesh& fvm = static_cast<const fvMesh&>(mesh());
00232
00233 return fvm.time().timeIndex() != prevTimeIndex_;
00234 }
00235
00236
00237 bool Foam::sampledIsoSurfaceCell::expire()
00238 {
00239 facesPtr_.clear();
00240
00241
00242 if (prevTimeIndex_ == -1)
00243 {
00244 return false;
00245 }
00246
00247
00248 prevTimeIndex_ = -1;
00249 return true;
00250 }
00251
00252
00253 bool Foam::sampledIsoSurfaceCell::update()
00254 {
00255 return updateGeometry();
00256 }
00257
00258
00259 Foam::tmp<Foam::scalarField>
00260 Foam::sampledIsoSurfaceCell::sample
00261 (
00262 const volScalarField& vField
00263 ) const
00264 {
00265 return sampleField(vField);
00266 }
00267
00268
00269 Foam::tmp<Foam::vectorField>
00270 Foam::sampledIsoSurfaceCell::sample
00271 (
00272 const volVectorField& vField
00273 ) const
00274 {
00275 return sampleField(vField);
00276 }
00277
00278
00279 Foam::tmp<Foam::sphericalTensorField>
00280 Foam::sampledIsoSurfaceCell::sample
00281 (
00282 const volSphericalTensorField& vField
00283 ) const
00284 {
00285 return sampleField(vField);
00286 }
00287
00288
00289 Foam::tmp<Foam::symmTensorField>
00290 Foam::sampledIsoSurfaceCell::sample
00291 (
00292 const volSymmTensorField& vField
00293 ) const
00294 {
00295 return sampleField(vField);
00296 }
00297
00298
00299 Foam::tmp<Foam::tensorField>
00300 Foam::sampledIsoSurfaceCell::sample
00301 (
00302 const volTensorField& vField
00303 ) const
00304 {
00305 return sampleField(vField);
00306 }
00307
00308
00309 Foam::tmp<Foam::scalarField>
00310 Foam::sampledIsoSurfaceCell::interpolate
00311 (
00312 const interpolation<scalar>& interpolator
00313 ) const
00314 {
00315 return interpolateField(interpolator);
00316 }
00317
00318
00319 Foam::tmp<Foam::vectorField>
00320 Foam::sampledIsoSurfaceCell::interpolate
00321 (
00322 const interpolation<vector>& interpolator
00323 ) const
00324 {
00325 return interpolateField(interpolator);
00326 }
00327
00328 Foam::tmp<Foam::sphericalTensorField>
00329 Foam::sampledIsoSurfaceCell::interpolate
00330 (
00331 const interpolation<sphericalTensor>& interpolator
00332 ) const
00333 {
00334 return interpolateField(interpolator);
00335 }
00336
00337
00338 Foam::tmp<Foam::symmTensorField>
00339 Foam::sampledIsoSurfaceCell::interpolate
00340 (
00341 const interpolation<symmTensor>& interpolator
00342 ) const
00343 {
00344 return interpolateField(interpolator);
00345 }
00346
00347
00348 Foam::tmp<Foam::tensorField>
00349 Foam::sampledIsoSurfaceCell::interpolate
00350 (
00351 const interpolation<tensor>& interpolator
00352 ) const
00353 {
00354 return interpolateField(interpolator);
00355 }
00356
00357
00358 void Foam::sampledIsoSurfaceCell::print(Ostream& os) const
00359 {
00360 os << "sampledIsoSurfaceCell: " << name() << " :"
00361 << " field:" << isoField_
00362 << " value:" << isoVal_;
00363
00364
00365 }
00366
00367
00368
Copyright © 2000-2009 OpenCFD Ltd