From ca358fdc1c5972a9c59b7ed21c0fadc4d1e8a7e1 Mon Sep 17 00:00:00 2001 From: mattijs Date: Wed, 28 Sep 2011 11:33:05 +0100 Subject: [PATCH 1/2] ENH: sampling: add offsetMode to patchInternalField sampleSurface --- .../postProcessing/sampling/sample/sampleDict | 19 ++++- .../mappedPolyPatch/mappedPatchBase.H | 8 +- .../sampledPatchInternalField.C | 84 +++++++++++++++---- 3 files changed, 92 insertions(+), 19 deletions(-) diff --git a/applications/utilities/postProcessing/sampling/sample/sampleDict b/applications/utilities/postProcessing/sampling/sample/sampleDict index d0ce98158c..9a77a66417 100644 --- a/applications/utilities/postProcessing/sampling/sample/sampleDict +++ b/applications/utilities/postProcessing/sampling/sample/sampleDict @@ -188,8 +188,25 @@ surfaces // cell, can be arbitrarily far away. type patchInternalField; patches ( ".*Wall.*" ); - distance 0.0001; interpolate true; + + + // Optional: specify how to obtain sampling points from the patch + // face centres (default is 'normal') + // + // //- Specify distance to offset in normal direction + offsetMode normal; + distance 0.1; + // + // //- Specify single uniform offset + // offsetMode uniform; + // offset (0 0 0.0001); + // + // //- Specify offset per patch face + // offsetMode nonuniform; + // offsets ((0 0 0.0001) (0 0 0.0002)); + + // Optional: whether to leave as faces (=default) or triangulate // triangulate false; } diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H index 34c7fa5479..8ee8022f6c 100644 --- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H +++ b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H @@ -112,6 +112,10 @@ public: NORMAL // use face normal + distance }; + static const NamedEnum sampleModeNames_; + + static const NamedEnum offsetModeNames_; + //- Helper class for finding nearest // Nearest: @@ -146,10 +150,6 @@ private: // Private data - static const NamedEnum sampleModeNames_; - - static const NamedEnum offsetModeNames_; - //- Patch to sample const polyPatch& patch_; diff --git a/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalField.C b/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalField.C index b9618f866a..4f16bbed59 100644 --- a/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalField.C +++ b/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalField.C @@ -58,24 +58,80 @@ Foam::sampledPatchInternalField::sampledPatchInternalField sampledPatch(name, mesh, dict), mappers_(patchIDs().size()) { - const scalar distance = readScalar(dict.lookup("distance")); - - forAll(patchIDs(), i) + mappedPatchBase::offsetMode mode = mappedPatchBase::NORMAL; + if (dict.found("offsetMode")) { - label patchI = patchIDs()[i]; - mappers_.set + mode = mappedPatchBase::offsetModeNames_.read ( - i, - new mappedPatchBase - ( - mesh.boundaryMesh()[patchI], - mesh.name(), // sampleRegion - mappedPatchBase::NEARESTCELL, // sampleMode - word::null, // samplePatch - -distance // sample inside my domain - ) + dict.lookup("offsetMode") ); } + + switch (mode) + { + case mappedPatchBase::NORMAL: + { + const scalar distance = readScalar(dict.lookup("distance")); + forAll(patchIDs(), i) + { + mappers_.set + ( + i, + new mappedPatchBase + ( + mesh.boundaryMesh()[patchIDs()[i]], + mesh.name(), // sampleRegion + mappedPatchBase::NEARESTCELL, // sampleMode + word::null, // samplePatch + -distance // sample inside my domain + ) + ); + } + } + break; + + case mappedPatchBase::UNIFORM: + { + const point offset(dict.lookup("offset")); + forAll(patchIDs(), i) + { + mappers_.set + ( + i, + new mappedPatchBase + ( + mesh.boundaryMesh()[patchIDs()[i]], + mesh.name(), // sampleRegion + mappedPatchBase::NEARESTCELL, // sampleMode + word::null, // samplePatch + offset // sample inside my domain + ) + ); + } + } + break; + + case mappedPatchBase::NONUNIFORM: + { + const pointField offsets(dict.lookup("offsets")); + forAll(patchIDs(), i) + { + mappers_.set + ( + i, + new mappedPatchBase + ( + mesh.boundaryMesh()[patchIDs()[i]], + mesh.name(), // sampleRegion + mappedPatchBase::NEARESTCELL, // sampleMode + word::null, // samplePatch + offsets // sample inside my domain + ) + ); + } + } + break; + } } From b96eb963f9b0059f44a7e38a3888041870f80abc Mon Sep 17 00:00:00 2001 From: mattijs Date: Wed, 28 Sep 2011 12:28:34 +0100 Subject: [PATCH 2/2] ENH: dynamicRefineFvMesh: check all fluxes for interpolation --- .../dynamicRefineFvMesh/dynamicRefineFvMesh.C | 92 +++++++++++++++---- .../dynamicRefineFvMesh/dynamicRefineFvMesh.H | 2 +- .../constant/dynamicMeshDict | 11 ++- 3 files changed, 81 insertions(+), 24 deletions(-) diff --git a/src/dynamicFvMesh/dynamicRefineFvMesh/dynamicRefineFvMesh.C b/src/dynamicFvMesh/dynamicRefineFvMesh/dynamicRefineFvMesh.C index a6a6545e9f..0af332a336 100644 --- a/src/dynamicFvMesh/dynamicRefineFvMesh/dynamicRefineFvMesh.C +++ b/src/dynamicFvMesh/dynamicRefineFvMesh/dynamicRefineFvMesh.C @@ -186,7 +186,16 @@ void Foam::dynamicRefineFvMesh::readDict() ).subDict(typeName + "Coeffs") ); - correctFluxes_ = List >(refineDict.lookup("correctFluxes")); + List > fluxVelocities = List > + ( + refineDict.lookup("correctFluxes") + ); + // Rework into hashtable. + correctFluxes_.resize(fluxVelocities.size()); + forAll(fluxVelocities, i) + { + correctFluxes_.insert(fluxVelocities[i][0], fluxVelocities[i][1]); + } dumpLevel_ = Switch(refineDict.lookup("dumpLevel")); } @@ -289,23 +298,46 @@ Foam::dynamicRefineFvMesh::refine << " split faces " << endl; } - forAll(correctFluxes_, i) + HashTable fluxes + ( + lookupClass() + ); + forAllConstIter(HashTable, fluxes, iter) { + if (!correctFluxes_.found(iter.key())) + { + WarningIn("dynamicRefineFvMesh::refine(const labelList&)") + << "Cannot find surfaceScalarField " << iter.key() + << " in user-provided flux mapping table " + << correctFluxes_ << endl + << " The flux mapping table is used to recreate the" + << " flux on newly created faces." << endl + << " Either add the entry if it is a flux or use (" + << iter.key() << " none) to suppress this warning." + << endl; + continue; + } + + const word& UName = correctFluxes_[iter.key()]; + + if (UName == "none") + { + continue; + } + if (debug) { - Info<< "Mapping flux " << correctFluxes_[i][0] - << " using interpolated flux " << correctFluxes_[i][1] + Info<< "Mapping flux " << iter.key() + << " using interpolated flux " << UName << endl; } - surfaceScalarField& phi = const_cast - ( - lookupObject(correctFluxes_[i][0]) - ); + + surfaceScalarField& phi = const_cast(*iter()); const surfaceScalarField phiU ( fvc::interpolate ( - lookupObject(correctFluxes_[i][1]) + lookupObject(UName) ) & Sf() ); @@ -482,27 +514,51 @@ Foam::dynamicRefineFvMesh::unrefine const labelList& reversePointMap = map().reversePointMap(); const labelList& reverseFaceMap = map().reverseFaceMap(); - forAll(correctFluxes_, i) + HashTable fluxes + ( + lookupClass() + ); + forAllConstIter(HashTable, fluxes, iter) { + if (!correctFluxes_.found(iter.key())) + { + WarningIn("dynamicRefineFvMesh::refine(const labelList&)") + << "Cannot find surfaceScalarField " << iter.key() + << " in user-provided flux mapping table " + << correctFluxes_ << endl + << " The flux mapping table is used to recreate the" + << " flux on newly created faces." << endl + << " Either add the entry if it is a flux or use (" + << iter.key() << " none) to suppress this warning." + << endl; + continue; + } + + const word& UName = correctFluxes_[iter.key()]; + + if (UName == "none") + { + continue; + } + if (debug) { - Info<< "Mapping flux " << correctFluxes_[i][0] - << " using interpolated flux " << correctFluxes_[i][1] + Info<< "Mapping flux " << iter.key() + << " using interpolated flux " << UName << endl; } - surfaceScalarField& phi = const_cast - ( - lookupObject(correctFluxes_[i][0]) - ); - surfaceScalarField phiU + + surfaceScalarField& phi = const_cast(*iter()); + const surfaceScalarField phiU ( fvc::interpolate ( - lookupObject(correctFluxes_[i][1]) + lookupObject(UName) ) & Sf() ); + forAllConstIter(Map