diff --git a/applications/utilities/postProcessing/sampling/sample/sampleDict b/applications/utilities/postProcessing/sampling/sample/sampleDict index d0ce98158c4ff9610270135a3ee9888cc4670c5e..9a77a6641738e71c7cb209a4b9548ffbc9ed5018 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/dynamicFvMesh/dynamicRefineFvMesh/dynamicRefineFvMesh.C b/src/dynamicFvMesh/dynamicRefineFvMesh/dynamicRefineFvMesh.C index a6a6545e9f3ee6bffdd39a53a3dc83665d312dd9..0af332a336de54520688e2108e15e03c61dd7b7d 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<Pair<word> >(refineDict.lookup("correctFluxes")); + List<Pair<word> > fluxVelocities = List<Pair<word> > + ( + 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<const surfaceScalarField*> fluxes + ( + lookupClass<surfaceScalarField>() + ); + forAllConstIter(HashTable<const surfaceScalarField*>, 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<surfaceScalarField&> - ( - lookupObject<surfaceScalarField>(correctFluxes_[i][0]) - ); + + surfaceScalarField& phi = const_cast<surfaceScalarField&>(*iter()); const surfaceScalarField phiU ( fvc::interpolate ( - lookupObject<volVectorField>(correctFluxes_[i][1]) + lookupObject<volVectorField>(UName) ) & Sf() ); @@ -482,27 +514,51 @@ Foam::dynamicRefineFvMesh::unrefine const labelList& reversePointMap = map().reversePointMap(); const labelList& reverseFaceMap = map().reverseFaceMap(); - forAll(correctFluxes_, i) + HashTable<const surfaceScalarField*> fluxes + ( + lookupClass<surfaceScalarField>() + ); + forAllConstIter(HashTable<const surfaceScalarField*>, 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<surfaceScalarField&> - ( - lookupObject<surfaceScalarField>(correctFluxes_[i][0]) - ); - surfaceScalarField phiU + + surfaceScalarField& phi = const_cast<surfaceScalarField&>(*iter()); + const surfaceScalarField phiU ( fvc::interpolate ( - lookupObject<volVectorField>(correctFluxes_[i][1]) + lookupObject<volVectorField>(UName) ) & Sf() ); + forAllConstIter(Map<label>, faceToSplitPoint, iter) { label oldFaceI = iter.key(); diff --git a/src/dynamicFvMesh/dynamicRefineFvMesh/dynamicRefineFvMesh.H b/src/dynamicFvMesh/dynamicRefineFvMesh/dynamicRefineFvMesh.H index 06dfbd666d107ae2c1557908928210e94151deb4..2dfe09d07554706ef6246eca8d3a904f82fc0fdd 100644 --- a/src/dynamicFvMesh/dynamicRefineFvMesh/dynamicRefineFvMesh.H +++ b/src/dynamicFvMesh/dynamicRefineFvMesh/dynamicRefineFvMesh.H @@ -64,7 +64,7 @@ protected: Switch dumpLevel_; //- Fluxes to map - List<Pair<word> > correctFluxes_; + HashTable<word> correctFluxes_; //- Number of refinement/unrefinement steps done so far. label nRefinementIterations_; diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.H index 79c5d6d8ade46d6a750e07613f5650fc529c8706..3afb9d8c4b67824509e38506fd377a4766d5885c 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<sampleMode, 4> sampleModeNames_; + + static const NamedEnum<offsetMode, 3> offsetModeNames_; + //- Helper class for finding nearest // Nearest: @@ -146,10 +150,6 @@ private: // Private data - static const NamedEnum<sampleMode, 4> sampleModeNames_; - - static const NamedEnum<offsetMode, 3> offsetModeNames_; - //- Patch to sample const polyPatch& patch_; diff --git a/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalField.C b/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalField.C index b9618f866a617ec42ebc0b808fd020a48975b5e8..4f16bbed599c089df6ba2f46789ed59f5d8e7888 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; + } } diff --git a/tutorials/multiphase/interDyMFoam/ras/damBreakWithObstacle/constant/dynamicMeshDict b/tutorials/multiphase/interDyMFoam/ras/damBreakWithObstacle/constant/dynamicMeshDict index 91232bba6fd17de29ef21790acdbcdbfa6c3c903..105d0818dd5d21194c8f8ff5ebcc27b01ab597cf 100644 --- a/tutorials/multiphase/interDyMFoam/ras/damBreakWithObstacle/constant/dynamicMeshDict +++ b/tutorials/multiphase/interDyMFoam/ras/damBreakWithObstacle/constant/dynamicMeshDict @@ -35,13 +35,14 @@ dynamicRefineFvMeshCoeffs // Stop refinement if maxCells reached maxCells 200000; // Flux field and corresponding velocity field. Fluxes on changed - // faces get recalculated by interpolating the velocity. + // faces get recalculated by interpolating the velocity. Use 'none' + // on surfaceScalarFields that do not need to be reinterpolated. correctFluxes ( - ( - phi - U - ) + (phi U) + (nHatf none) + (rho*phi none) + (ghf none) ); // Write the refinement level as a volScalarField dumpLevel true;