diff --git a/src/sampling/sampledSurface/distanceSurface/distanceSurface.C b/src/sampling/sampledSurface/distanceSurface/distanceSurface.C index 9d9b4da312..61a6a8099d 100644 --- a/src/sampling/sampledSurface/distanceSurface/distanceSurface.C +++ b/src/sampling/sampledSurface/distanceSurface/distanceSurface.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -52,7 +52,38 @@ void Foam::sampledSurfaces::distanceSurface::createGeometry() // Clear derived data clearGeom(); - const fvMesh& mesh = static_cast(this->mesh()); + // Get any subMesh + if (zoneKey_.size() && !subMeshPtr_.valid()) + { + const polyBoundaryMesh& patches = mesh().boundaryMesh(); + + // Patch to put exposed internal faces into + const label exposedPatchi = patches.findPatchID(exposedPatchName_); + + subMeshPtr_.reset + ( + new fvMeshSubset(static_cast(mesh())) + ); + subMeshPtr_().setLargeCellSubset + ( + labelHashSet(mesh().cellZones().findMatching(zoneKey_).used()), + exposedPatchi + ); + + DebugInfo + << "Allocating subset of size " << subMeshPtr_().subMesh().nCells() + << " with exposed faces into patch " + << patches[exposedPatchi].name() << endl; + } + + // Select either the submesh or the underlying mesh + const fvMesh& mesh = + ( + subMeshPtr_.valid() + ? subMeshPtr_().subMesh() + : static_cast(this->mesh()) + ); + // Distance to cell centres // ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -317,51 +348,39 @@ Foam::sampledSurfaces::distanceSurface::distanceSurface : isoSurface::filterType::full ), average_(dict.lookupOrDefault("average", false)), - zoneKey_(keyType::null), + zoneKey_(dict.lookupOrDefault("zone", keyType::null)), needsUpdate_(true), + subMeshPtr_(nullptr), isoSurfPtr_(nullptr) -{} +{ + if (zoneKey_.size()) + { + dict.lookup("exposedPatchName") >> exposedPatchName_; + if (mesh.boundaryMesh().findPatchID(exposedPatchName_) == -1) + { + FatalErrorInFunction + << "Cannot find patch " << exposedPatchName_ + << " in which to put exposed faces." << endl + << "Valid patches are " << mesh.boundaryMesh().names() + << exit(FatalError); + } -Foam::sampledSurfaces::distanceSurface::distanceSurface -( - const word& name, - const polyMesh& mesh, - const bool interpolate, - const word& surfaceType, - const word& surfaceName, - const scalar distance, - const bool signedDistance, - const isoSurface::filterType filter, - const Switch average -) -: - sampledSurface(name, mesh, interpolate), - surfPtr_ - ( - searchableSurface::New - ( - surfaceType, - IOobject - ( - surfaceName, // name - mesh.time().constant(), // directory - "triSurface", // instance - mesh.time(), // registry - IOobject::MUST_READ, - IOobject::NO_WRITE - ), - dictionary() - ) - ), - distance_(distance), - signed_(signedDistance), - filter_(filter), - average_(average), - zoneKey_(keyType::null), - needsUpdate_(true), - isoSurfPtr_(nullptr) -{} + if (debug) + { + Info<< "Restricting to cellZone " << zoneKey_ + << " with exposed internal faces into patch " + << exposedPatchName_ << endl; + } + + if (mesh.cellZones().findIndex(zoneKey_) < 0) + { + WarningInFunction + << "cellZone " << zoneKey_ + << " not found - using entire mesh" << endl; + } + } +} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // diff --git a/src/sampling/sampledSurface/distanceSurface/distanceSurface.H b/src/sampling/sampledSurface/distanceSurface/distanceSurface.H index f7c2352432..4876e894aa 100644 --- a/src/sampling/sampledSurface/distanceSurface/distanceSurface.H +++ b/src/sampling/sampledSurface/distanceSurface/distanceSurface.H @@ -67,6 +67,7 @@ SourceFiles #include "sampledSurface.H" #include "searchableSurface.H" #include "isoSurface.H" +#include "fvMeshSubset.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -103,9 +104,14 @@ class distanceSurface //- If restricted to zones, name of this zone or a regular expression keyType zoneKey_; + //- For zones: patch to put exposed faces into + mutable word exposedPatchName_; + //- Track if the surface needs an update mutable bool needsUpdate_; + //- Optional subsetted mesh + autoPtr subMeshPtr_; //- Distance to cell centres autoPtr cellDistancePtr_; @@ -151,20 +157,6 @@ public: const dictionary& dict ); - //- Construct from components - distanceSurface - ( - const word& name, - const polyMesh& mesh, - const bool interpolate, - const word& surfaceType, - const word& surfaceName, - const scalar distance, - const bool signedDistance, - const isoSurface::filterType filter, - const Switch average - ); - //- Destructor virtual ~distanceSurface(); diff --git a/src/sampling/sampledSurface/distanceSurface/distanceSurfaceTemplates.C b/src/sampling/sampledSurface/distanceSurface/distanceSurfaceTemplates.C index 6d01c067c9..3bcd8055e1 100644 --- a/src/sampling/sampledSurface/distanceSurface/distanceSurfaceTemplates.C +++ b/src/sampling/sampledSurface/distanceSurface/distanceSurfaceTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -49,26 +49,48 @@ Foam::sampledSurfaces::distanceSurface::interpolateField const interpolation& interpolator ) const { - const fvMesh& fvm = static_cast(mesh()); - // Get fields to sample. Assume volPointInterpolation! const GeometricField& volFld = interpolator.psi(); - tmp> pointFld - ( - volPointInterpolation::New(fvm).interpolate(volFld) - ); + if (subMeshPtr_.valid()) + { + tmp> tvolSubFld = + subMeshPtr_().interpolate(volFld); - return isoSurfPtr_().interpolate - ( + const GeometricField& volSubFld = + tvolSubFld(); + + tmp> tpointSubFld = + volPointInterpolation::New(volSubFld.mesh()).interpolate(volSubFld); + + return isoSurfPtr_().interpolate ( - average_ - ? pointAverage(pointFld())() - : volFld - ), - pointFld() - ); + ( + average_ + ? pointAverage(tpointSubFld())() + : volSubFld + ), + tpointSubFld() + ); + } + else + { + tmp> pointFld + ( + volPointInterpolation::New(volFld.mesh()).interpolate(volFld) + ); + + return isoSurfPtr_().interpolate + ( + ( + average_ + ? pointAverage(pointFld())() + : volFld + ), + pointFld() + ); + } } diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C index bc7b01c07d..ea45ca9597 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -255,7 +255,6 @@ Foam::sampledSurfaces::isoSurface::isoSurface ? Foam::isoSurface::filterTypeNames_.read(dict.lookup("filtering")) : Foam::isoSurface::filterType::full ), - zoneKey_(keyType::null), prevTimeIndex_(-1), meshCells_(0) {} diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H index 1e3f8248d2..ccd3dfe911 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H @@ -90,8 +90,6 @@ class isoSurface //- Whether to coarsen const Foam::isoSurface::filterType filter_; - //- If restricted to zones, name of this zone or a regular expression - keyType zoneKey_; // Recreated for every isoSurface diff --git a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C index 6c19da2dc3..4158c36219 100644 --- a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C +++ b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -58,30 +58,28 @@ void Foam::sampledSurfaces::cuttingPlane::createGeometry() clearGeom(); // Get any subMesh - if (zoneID_.index() != -1 && !subMeshPtr_.valid()) + if (zoneKey_.size() && !subMeshPtr_.valid()) { const polyBoundaryMesh& patches = mesh().boundaryMesh(); // Patch to put exposed internal faces into const label exposedPatchi = patches.findPatchID(exposedPatchName_); - DebugInfo - << "Allocating subset of size " - << mesh().cellZones()[zoneID_.index()].size() - << " with exposed faces into patch " - << patches[exposedPatchi].name() << endl; - subMeshPtr_.reset ( new fvMeshSubset(static_cast(mesh())) ); subMeshPtr_().setLargeCellSubset ( - labelHashSet(mesh().cellZones()[zoneID_.index()]), + labelHashSet(mesh().cellZones().findMatching(zoneKey_).used()), exposedPatchi ); - } + DebugInfo + << "Allocating subset of size " << subMeshPtr_().subMesh().nCells() + << " with exposed faces into patch " + << patches[exposedPatchi].name() << endl; + } // Select either the submesh or the underlying mesh const fvMesh& mesh = @@ -255,14 +253,14 @@ Foam::sampledSurfaces::cuttingPlane::cuttingPlane : isoSurface::filterType::full ), average_(dict.lookupOrDefault("average", false)), - zoneID_(dict.lookupOrDefault("zone", word::null), mesh.cellZones()), + zoneKey_(dict.lookupOrDefault("zone", keyType::null)), exposedPatchName_(word::null), needsUpdate_(true), subMeshPtr_(nullptr), cellDistancePtr_(nullptr), isoSurfPtr_(nullptr) { - if (zoneID_.index() != -1) + if (zoneKey_.size()) { dict.lookup("exposedPatchName") >> exposedPatchName_; @@ -275,12 +273,19 @@ Foam::sampledSurfaces::cuttingPlane::cuttingPlane << exit(FatalError); } - if (debug && zoneID_.index() != -1) + if (debug) { - Info<< "Restricting to cellZone " << zoneID_.name() + Info<< "Restricting to cellZone " << zoneKey_ << " with exposed internal faces into patch " << exposedPatchName_ << endl; } + + if (mesh.cellZones().findIndex(zoneKey_) < 0) + { + WarningInFunction + << "cellZone " << zoneKey_ + << " not found - using entire mesh" << endl; + } } } diff --git a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H index 4d809f5f04..fd6129cbff 100644 --- a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H +++ b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H @@ -63,8 +63,6 @@ SourceFiles #include "sampledSurface.H" #include "isoSurface.H" -#include "plane.H" -#include "ZoneIDs.H" #include "fvMeshSubset.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -93,8 +91,8 @@ class cuttingPlane //- Whether to recalculate cell values as average of point values const Switch average_; - //- Zone name/index (if restricted to zones) - mutable cellZoneID zoneID_; + //- If restricted to zones, name of this zone or a regular expression + keyType zoneKey_; //- For zones: patch to put exposed faces into mutable word exposedPatchName_; @@ -102,7 +100,6 @@ class cuttingPlane //- Track if the surface needs an update mutable bool needsUpdate_; - //- Optional subsetted mesh autoPtr subMeshPtr_; diff --git a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlaneTemplates.C b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlaneTemplates.C index 7a73a52f6f..5c43ea556d 100644 --- a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlaneTemplates.C +++ b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlaneTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -61,7 +61,6 @@ Foam::sampledSurfaces::cuttingPlane::interpolateField tmp> tpointSubFld = volPointInterpolation::New(volSubFld.mesh()).interpolate(volSubFld); - // Sample. return surface().interpolate ( ( @@ -79,7 +78,6 @@ Foam::sampledSurfaces::cuttingPlane::interpolateField volPointInterpolation::New(volFld.mesh()).interpolate(volFld) ); - // Sample. return surface().interpolate ( ( diff --git a/src/sampling/sampledSurface/sampledPlane/sampledPlane.C b/src/sampling/sampledSurface/sampledPlane/sampledPlane.C index 0eee82316b..5d90550d5b 100644 --- a/src/sampling/sampledSurface/sampledPlane/sampledPlane.C +++ b/src/sampling/sampledSurface/sampledPlane/sampledPlane.C @@ -49,7 +49,7 @@ Foam::sampledSurfaces::plane::plane : sampledSurface(name, mesh, dict), cuttingPlane(Foam::plane(dict)), - zoneKey_(keyType::null), + zoneKey_(dict.lookupOrDefault("zone", keyType::null)), triangulate_(dict.lookupOrDefault("triangulate", true)), needsUpdate_(true) { @@ -69,8 +69,6 @@ Foam::sampledSurfaces::plane::plane static_cast(*this) = Foam::plane(base, norm); } - dict.readIfPresent("zone", zoneKey_); - if (debug && zoneKey_.size() && mesh.cellZones().findIndex(zoneKey_) < 0) { Info<< "cellZone " << zoneKey_ @@ -117,7 +115,10 @@ bool Foam::sampledSurfaces::plane::update() sampledSurface::clearGeom(); - labelList selectedCells = mesh().cellZones().findMatching(zoneKey_).used(); + const labelList selectedCells + ( + mesh().cellZones().findMatching(zoneKey_).used() + ); if (selectedCells.empty()) { diff --git a/src/sampling/sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.C b/src/sampling/sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.C index fd901a8f05..fb3acd5302 100644 --- a/src/sampling/sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.C +++ b/src/sampling/sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -149,7 +149,6 @@ Foam::sampledSurfaces::thresholdCellFaces::thresholdCellFaces fieldName_(dict.lookup("field")), lowerThreshold_(dict.lookupOrDefault("lowerLimit", -vGreat)), upperThreshold_(dict.lookupOrDefault("upperLimit", vGreat)), - zoneKey_(keyType::null), triangulate_(dict.lookupOrDefault("triangulate", false)), prevTimeIndex_(-1), meshCells_(0) diff --git a/src/sampling/sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.H b/src/sampling/sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.H index 92d6282e09..2f6b584c4f 100644 --- a/src/sampling/sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.H +++ b/src/sampling/sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.H @@ -93,9 +93,6 @@ class thresholdCellFaces //- Threshold value const scalar upperThreshold_; - //- If restricted to zones, name of this zone or a regular expression - keyType zoneKey_; - //- Triangulated faces or keep faces as is bool triangulate_;