diff --git a/src/finiteVolume/fvMesh/wallDist/patchDistMethods/Poisson/PoissonPatchDistMethod.H b/src/finiteVolume/fvMesh/wallDist/patchDistMethods/Poisson/PoissonPatchDistMethod.H index 1e70b3f140f9c77f6e2a7173a055c8476b738e99..98259f7b4250318f8c2ce325e14b73012130a0cb 100644 --- a/src/finiteVolume/fvMesh/wallDist/patchDistMethods/Poisson/PoissonPatchDistMethod.H +++ b/src/finiteVolume/fvMesh/wallDist/patchDistMethods/Poisson/PoissonPatchDistMethod.H @@ -58,6 +58,10 @@ Description wallDist { method Poisson; + + // Optional entry enabling the calculation + // of the normal-to-wall field + nRequired false; } \endverbatim Also the solver specification for yPsi is required in fvSolution, e.g. diff --git a/src/finiteVolume/fvMesh/wallDist/patchDistMethods/advectionDiffusion/advectionDiffusionPatchDistMethod.C b/src/finiteVolume/fvMesh/wallDist/patchDistMethods/advectionDiffusion/advectionDiffusionPatchDistMethod.C index a3797f1fa2e7e5cbd65535ea6711ec6beaf35e40..88955afa565ef0b68f9b116a90b21d2525b3cfd6 100644 --- a/src/finiteVolume/fvMesh/wallDist/patchDistMethods/advectionDiffusion/advectionDiffusionPatchDistMethod.C +++ b/src/finiteVolume/fvMesh/wallDist/patchDistMethods/advectionDiffusion/advectionDiffusionPatchDistMethod.C @@ -99,7 +99,10 @@ bool Foam::patchDistMethods::advectionDiffusion::correct ( "ny", mesh_.time().timeName(), - mesh_ + mesh_, + IOobject::NO_READ, + IOobject::NO_WRITE, + false ), mesh_, dimensionedVector("ny", dimless, vector::zero), diff --git a/src/finiteVolume/fvMesh/wallDist/patchDistMethods/advectionDiffusion/advectionDiffusionPatchDistMethod.H b/src/finiteVolume/fvMesh/wallDist/patchDistMethods/advectionDiffusion/advectionDiffusionPatchDistMethod.H index c62f7e79f9f50051925d90821494798bb2b12209..22a8cd07a2a770b148aff8e5fa5e210e8c6abf13 100644 --- a/src/finiteVolume/fvMesh/wallDist/patchDistMethods/advectionDiffusion/advectionDiffusionPatchDistMethod.H +++ b/src/finiteVolume/fvMesh/wallDist/patchDistMethods/advectionDiffusion/advectionDiffusionPatchDistMethod.H @@ -58,6 +58,10 @@ Description { method advectionDiffusion; + // Optional entry enabling the calculation + // of the normal-to-wall field + nRequired false; + advectionDiffusionCoeffs { method Poisson; diff --git a/src/finiteVolume/fvMesh/wallDist/patchDistMethods/meshWave/meshWavePatchDistMethod.H b/src/finiteVolume/fvMesh/wallDist/patchDistMethods/meshWave/meshWavePatchDistMethod.H index 235dab7c11347be68a6792a7f3e5c37bc05027f0..0a309038081559ac28ea146f6c53fedcebb8340e 100644 --- a/src/finiteVolume/fvMesh/wallDist/patchDistMethods/meshWave/meshWavePatchDistMethod.H +++ b/src/finiteVolume/fvMesh/wallDist/patchDistMethods/meshWave/meshWavePatchDistMethod.H @@ -39,6 +39,10 @@ Description wallDist { method meshWave; + + // Optional entry enabling the calculation + // of the normal-to-wall field + nRequired false; } \endverbatim diff --git a/src/finiteVolume/fvMesh/wallDist/wallDist/wallDist.C b/src/finiteVolume/fvMesh/wallDist/wallDist/wallDist.C index d5c9e31b4e16e9081683fd4bc9eba10598bbee42..ae2ba96a1ff54f9f9d58cb0a3a642a05d16412bc 100644 --- a/src/finiteVolume/fvMesh/wallDist/wallDist/wallDist.C +++ b/src/finiteVolume/fvMesh/wallDist/wallDist/wallDist.C @@ -34,6 +34,37 @@ namespace Foam } +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::wallDist::constructn() const +{ + n_ = tmp<volVectorField> + ( + new volVectorField + ( + IOobject + ( + "nWall", + mesh().time().timeName(), + mesh() + ), + mesh(), + dimensionedVector("nWall", dimless, vector::zero), + patchDistMethod::patchTypes<vector>(mesh(), pdm_->patchIDs()) + ) + ); + + const labelHashSet& patchIDs = pdm_->patchIDs(); + const fvPatchList& patches = mesh().boundary(); + + forAllConstIter(labelHashSet, patchIDs, iter) + { + label patchi = iter.key(); + n_().boundaryField()[patchi] == patches[patchi].nf(); + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::wallDist::wallDist(const fvMesh& mesh) @@ -60,33 +91,16 @@ Foam::wallDist::wallDist(const fvMesh& mesh) dimensionedScalar("yWall", dimLength, SMALL), patchDistMethod::patchTypes<scalar>(mesh, pdm_->patchIDs()) ), - n_(NULL) -{ - // Temporarily always construct n - // until the demand-driven interface is complete - n_ = tmp<volVectorField> + nRequired_ ( - new volVectorField - ( - IOobject - ( - "nWall", - mesh.time().timeName(), - mesh - ), - mesh, - dimensionedVector("nWall", dimless, vector::zero), - patchDistMethod::patchTypes<vector>(mesh, pdm_->patchIDs()) - ) - ); - - const labelHashSet& patchIDs = pdm_->patchIDs(); - const fvPatchList& patches = mesh.boundary(); - - forAllConstIter(labelHashSet, patchIDs, iter) + static_cast<const fvSchemes&>(mesh).subDict("wallDist") + .lookupOrDefault<Switch>("nRequired", false) + ), + n_(volVectorField::null()) +{ + if (nRequired_) { - label patchi = iter.key(); - n_().boundaryField()[patchi] == patches[patchi].nf(); + constructn(); } movePoints(); @@ -101,6 +115,24 @@ Foam::wallDist::~wallDist() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +const Foam::volVectorField& Foam::wallDist::n() const +{ + if (isNull(n_())) + { + WarningIn("Foam::wallDist::n()") + << "n requested but 'nRequired' not specified in the wallDist " + "dictionary" << nl + << " Recalculating y and n fields." << endl; + + nRequired_ = true; + constructn(); + pdm_->correct(y_, n_()); + } + + return n_(); +} + + bool Foam::wallDist::movePoints() { if (pdm_->movePoints()) diff --git a/src/finiteVolume/fvMesh/wallDist/wallDist/wallDist.H b/src/finiteVolume/fvMesh/wallDist/wallDist/wallDist.H index 683a8c095facbf3db28aed0b14e317d0306ccec5..a609c903b974fa9e63041c33149bb9deec3df7a1 100644 --- a/src/finiteVolume/fvMesh/wallDist/wallDist/wallDist.H +++ b/src/finiteVolume/fvMesh/wallDist/wallDist/wallDist.H @@ -26,7 +26,24 @@ Class Description Interface to run-time selectable methods to calculate the distance-to-wall - field. + and normal-to-wall fields. + + Example of the wallDist specification in fvSchemes: + \verbatim + wallDist + { + method meshWave; + + // Optional entry enabling the calculation + // of the normal-to-wall field + nRequired false; + } + \endverbatim + +SeeAlso + Foam::patchDistMethod::meshWave + Foam::patchDistMethod::Poisson + Foam::patchDistMethod::advectionDiffusion SourceFiles wallDist.C @@ -57,17 +74,23 @@ class wallDist // Private data //- Run-time selected method to generate the distance-to-wall field - autoPtr<patchDistMethod> pdm_; + mutable autoPtr<patchDistMethod> pdm_; //- Distance-to-wall field - volScalarField y_; + mutable volScalarField y_; - //- Distance-to-wall field - tmp<volVectorField> n_; + //- Flag to indicate if the distance-to-wall field is required + mutable bool nRequired_; + + //- Normal-to-wall field + mutable tmp<volVectorField> n_; // Private Member Functions + //- Construct the normal-to-wall field as required + void constructn() const; + //- Disallow default bitwise copy construct wallDist(const wallDist&); @@ -100,10 +123,7 @@ public: } //- Return reference to cached normal-to-wall field - const volVectorField& n() const - { - return n_(); - } + const volVectorField& n() const; //- Update the y-field when the mesh moves virtual bool movePoints();