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 "sampledCuttingPlane.H"
00028 #include "dictionary.H"
00029 #include "volFields.H"
00030 #include "volPointInterpolation.H"
00031 #include "addToRunTimeSelectionTable.H"
00032 #include "fvMesh.H"
00033 #include "isoSurface.H"
00034
00035
00036
00037 namespace Foam
00038 {
00039 defineTypeNameAndDebug(sampledCuttingPlane, 0);
00040 addNamedToRunTimeSelectionTable
00041 (
00042 sampledSurface,
00043 sampledCuttingPlane,
00044 word,
00045 cuttingPlane
00046 );
00047 }
00048
00049
00050
00051 void Foam::sampledCuttingPlane::createGeometry()
00052 {
00053 if (debug)
00054 {
00055 Pout<< "sampledCuttingPlane::createGeometry :updating geometry."
00056 << endl;
00057 }
00058
00059
00060 facesPtr_.clear();
00061 isoSurfPtr_.ptr();
00062 pointDistance_.clear();
00063 cellDistancePtr_.clear();
00064
00065
00066
00067 if (zoneID_.index() != -1 && !subMeshPtr_.valid())
00068 {
00069 const polyBoundaryMesh& patches = mesh().boundaryMesh();
00070
00071
00072 label exposedPatchI = patches.findPatchID(exposedPatchName_);
00073
00074 if (debug)
00075 {
00076 Info<< "Allocating subset of size "
00077 << mesh().cellZones()[zoneID_.index()].size()
00078 << " with exposed faces into patch "
00079 << patches[exposedPatchI].name() << endl;
00080 }
00081
00082 subMeshPtr_.reset
00083 (
00084 new fvMeshSubset(static_cast<const fvMesh&>(mesh()))
00085 );
00086 subMeshPtr_().setLargeCellSubset
00087 (
00088 labelHashSet(mesh().cellZones()[zoneID_.index()]),
00089 exposedPatchI
00090 );
00091 }
00092
00093
00094
00095 const fvMesh& fvm =
00096 (
00097 subMeshPtr_.valid()
00098 ? subMeshPtr_().subMesh()
00099 : static_cast<const fvMesh&>(mesh())
00100 );
00101
00102
00103
00104
00105
00106 cellDistancePtr_.reset
00107 (
00108 new volScalarField
00109 (
00110 IOobject
00111 (
00112 "cellDistance",
00113 fvm.time().timeName(),
00114 fvm.time(),
00115 IOobject::NO_READ,
00116 IOobject::NO_WRITE,
00117 false
00118 ),
00119 fvm,
00120 dimensionedScalar("zero", dimLength, 0)
00121 )
00122 );
00123 volScalarField& cellDistance = cellDistancePtr_();
00124
00125
00126 {
00127 const pointField& cc = fvm.cellCentres();
00128 scalarField& fld = cellDistance.internalField();
00129
00130 forAll(cc, i)
00131 {
00132
00133 fld[i] = (cc[i] - plane_.refPoint()) & plane_.normal();
00134 }
00135 }
00136
00137
00138 {
00139 forAll(cellDistance.boundaryField(), patchI)
00140 {
00141 if
00142 (
00143 isA<emptyFvPatchScalarField>
00144 (
00145 cellDistance.boundaryField()[patchI]
00146 )
00147 )
00148 {
00149 cellDistance.boundaryField().set
00150 (
00151 patchI,
00152 new calculatedFvPatchScalarField
00153 (
00154 fvm.boundary()[patchI],
00155 cellDistance
00156 )
00157 );
00158
00159 const polyPatch& pp = fvm.boundary()[patchI].patch();
00160 pointField::subField cc = pp.patchSlice(fvm.faceCentres());
00161
00162 fvPatchScalarField& fld = cellDistance.boundaryField()[patchI];
00163 fld.setSize(pp.size());
00164 forAll(fld, i)
00165 {
00166 fld[i] = (cc[i] - plane_.refPoint()) & plane_.normal();
00167 }
00168 }
00169 else
00170 {
00171 const pointField& cc = fvm.C().boundaryField()[patchI];
00172 fvPatchScalarField& fld = cellDistance.boundaryField()[patchI];
00173
00174 forAll(fld, i)
00175 {
00176 fld[i] = (cc[i] - plane_.refPoint()) & plane_.normal();
00177 }
00178 }
00179 }
00180 }
00181
00182
00183
00184
00185
00186
00187
00188 pointDistance_.setSize(fvm.nPoints());
00189 {
00190 const pointField& pts = fvm.points();
00191
00192 forAll(pointDistance_, i)
00193 {
00194 pointDistance_[i] = (pts[i] - plane_.refPoint()) & plane_.normal();
00195 }
00196 }
00197
00198
00199 if (debug)
00200 {
00201 Pout<< "Writing cell distance:" << cellDistance.objectPath() << endl;
00202 cellDistance.write();
00203 pointScalarField pDist
00204 (
00205 IOobject
00206 (
00207 "pointDistance",
00208 fvm.time().timeName(),
00209 fvm.time(),
00210 IOobject::NO_READ,
00211 IOobject::NO_WRITE,
00212 false
00213 ),
00214 pointMesh::New(fvm),
00215 dimensionedScalar("zero", dimLength, 0)
00216 );
00217 pDist.internalField() = pointDistance_;
00218
00219 Pout<< "Writing point distance:" << pDist.objectPath() << endl;
00220 pDist.write();
00221 }
00222
00223
00224
00225 isoSurfPtr_.reset
00226 (
00227 new isoSurface
00228 (
00229 cellDistance,
00230 pointDistance_,
00231 0.0,
00232 regularise_
00233 )
00234 );
00235
00236 if (debug)
00237 {
00238 print(Pout);
00239 Pout<< endl;
00240 }
00241 }
00242
00243
00244
00245
00246 Foam::sampledCuttingPlane::sampledCuttingPlane
00247 (
00248 const word& name,
00249 const polyMesh& mesh,
00250 const dictionary& dict
00251 )
00252 :
00253 sampledSurface(name, mesh, dict),
00254 plane_(dict),
00255 mergeTol_(dict.lookupOrDefault("mergeTol", 1E-6)),
00256 regularise_(dict.lookupOrDefault("regularise", true)),
00257 zoneID_(dict.lookupOrDefault("zone", word::null), mesh.cellZones()),
00258 exposedPatchName_(word::null),
00259 needsUpdate_(true),
00260 subMeshPtr_(NULL),
00261 cellDistancePtr_(NULL),
00262 isoSurfPtr_(NULL),
00263 facesPtr_(NULL)
00264 {
00265 if (zoneID_.index() != -1)
00266 {
00267 dict.lookup("exposedPatchName") >> exposedPatchName_;
00268
00269 if (mesh.boundaryMesh().findPatchID(exposedPatchName_) == -1)
00270 {
00271 FatalErrorIn
00272 (
00273 "sampledCuttingPlane::sampledCuttingPlane"
00274 "(const word&, const polyMesh&, const dictionary&)"
00275 ) << "Cannot find patch " << exposedPatchName_
00276 << " in which to put exposed faces." << endl
00277 << "Valid patches are " << mesh.boundaryMesh().names()
00278 << exit(FatalError);
00279 }
00280
00281 if (debug && zoneID_.index() != -1)
00282 {
00283 Info<< "Restricting to cellZone " << zoneID_.name()
00284 << " with exposed internal faces into patch "
00285 << exposedPatchName_ << endl;
00286 }
00287 }
00288 }
00289
00290
00291
00292
00293 Foam::sampledCuttingPlane::~sampledCuttingPlane()
00294 {}
00295
00296
00297
00298
00299 bool Foam::sampledCuttingPlane::needsUpdate() const
00300 {
00301 return needsUpdate_;
00302 }
00303
00304
00305 bool Foam::sampledCuttingPlane::expire()
00306 {
00307 if (debug)
00308 {
00309 Pout<< "sampledCuttingPlane::expire :"
00310 << " have-facesPtr_:" << facesPtr_.valid()
00311 << " needsUpdate_:" << needsUpdate_ << endl;
00312 }
00313
00314
00315 facesPtr_.clear();
00316
00317
00318 if (needsUpdate_)
00319 {
00320 return false;
00321 }
00322
00323 needsUpdate_ = true;
00324 return true;
00325 }
00326
00327
00328 bool Foam::sampledCuttingPlane::update()
00329 {
00330 if (debug)
00331 {
00332 Pout<< "sampledCuttingPlane::update :"
00333 << " have-facesPtr_:" << facesPtr_.valid()
00334 << " needsUpdate_:" << needsUpdate_ << endl;
00335 }
00336
00337 if (!needsUpdate_)
00338 {
00339 return false;
00340 }
00341
00342 createGeometry();
00343
00344 needsUpdate_ = false;
00345 return true;
00346 }
00347
00348
00349 Foam::tmp<Foam::scalarField>
00350 Foam::sampledCuttingPlane::sample
00351 (
00352 const volScalarField& vField
00353 ) const
00354 {
00355 return sampleField(vField);
00356 }
00357
00358
00359 Foam::tmp<Foam::vectorField>
00360 Foam::sampledCuttingPlane::sample
00361 (
00362 const volVectorField& vField
00363 ) const
00364 {
00365 return sampleField(vField);
00366 }
00367
00368
00369 Foam::tmp<Foam::sphericalTensorField>
00370 Foam::sampledCuttingPlane::sample
00371 (
00372 const volSphericalTensorField& vField
00373 ) const
00374 {
00375 return sampleField(vField);
00376 }
00377
00378
00379 Foam::tmp<Foam::symmTensorField>
00380 Foam::sampledCuttingPlane::sample
00381 (
00382 const volSymmTensorField& vField
00383 ) const
00384 {
00385 return sampleField(vField);
00386 }
00387
00388
00389 Foam::tmp<Foam::tensorField>
00390 Foam::sampledCuttingPlane::sample
00391 (
00392 const volTensorField& vField
00393 ) const
00394 {
00395 return sampleField(vField);
00396 }
00397
00398
00399 Foam::tmp<Foam::scalarField>
00400 Foam::sampledCuttingPlane::interpolate
00401 (
00402 const interpolation<scalar>& interpolator
00403 ) const
00404 {
00405 return interpolateField(interpolator);
00406 }
00407
00408
00409 Foam::tmp<Foam::vectorField>
00410 Foam::sampledCuttingPlane::interpolate
00411 (
00412 const interpolation<vector>& interpolator
00413 ) const
00414 {
00415 return interpolateField(interpolator);
00416 }
00417
00418 Foam::tmp<Foam::sphericalTensorField>
00419 Foam::sampledCuttingPlane::interpolate
00420 (
00421 const interpolation<sphericalTensor>& interpolator
00422 ) const
00423 {
00424 return interpolateField(interpolator);
00425 }
00426
00427
00428 Foam::tmp<Foam::symmTensorField>
00429 Foam::sampledCuttingPlane::interpolate
00430 (
00431 const interpolation<symmTensor>& interpolator
00432 ) const
00433 {
00434 return interpolateField(interpolator);
00435 }
00436
00437
00438 Foam::tmp<Foam::tensorField>
00439 Foam::sampledCuttingPlane::interpolate
00440 (
00441 const interpolation<tensor>& interpolator
00442 ) const
00443 {
00444 return interpolateField(interpolator);
00445 }
00446
00447
00448 void Foam::sampledCuttingPlane::print(Ostream& os) const
00449 {
00450 os << "sampledCuttingPlane: " << name() << " :"
00451 << " plane:" << plane_
00452 << " faces:" << faces().size()
00453 << " points:" << points().size();
00454 }
00455
00456
00457