sampledSurface::distanceSurface: Added zone support using zoneKey

combining functionality from sampledCuttingPlane and sampledPlane.
Updated sampledCuttingPlane to use zoneKey.
This commit is contained in:
Henry Weller
2020-11-24 16:25:47 +00:00
parent c716ff78be
commit a008316870
11 changed files with 134 additions and 107 deletions

View File

@ -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<const fvMesh&>(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<const fvMesh&>(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<const fvMesh&>(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 * * * * * * * * * * * * * * * //

View File

@ -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<fvMeshSubset> subMeshPtr_;
//- Distance to cell centres
autoPtr<volScalarField> 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();

View File

@ -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<Type>& interpolator
) const
{
const fvMesh& fvm = static_cast<const fvMesh&>(mesh());
// Get fields to sample. Assume volPointInterpolation!
const GeometricField<Type, fvPatchField, volMesh>& volFld =
interpolator.psi();
tmp<GeometricField<Type, pointPatchField, pointMesh>> pointFld
(
volPointInterpolation::New(fvm).interpolate(volFld)
);
if (subMeshPtr_.valid())
{
tmp<GeometricField<Type, fvPatchField, volMesh>> tvolSubFld =
subMeshPtr_().interpolate(volFld);
return isoSurfPtr_().interpolate
(
const GeometricField<Type, fvPatchField, volMesh>& volSubFld =
tvolSubFld();
tmp<GeometricField<Type, pointPatchField, pointMesh>> tpointSubFld =
volPointInterpolation::New(volSubFld.mesh()).interpolate(volSubFld);
return isoSurfPtr_().interpolate
(
average_
? pointAverage(pointFld())()
: volFld
),
pointFld()
);
(
average_
? pointAverage(tpointSubFld())()
: volSubFld
),
tpointSubFld()
);
}
else
{
tmp<GeometricField<Type, pointPatchField, pointMesh>> pointFld
(
volPointInterpolation::New(volFld.mesh()).interpolate(volFld)
);
return isoSurfPtr_().interpolate
(
(
average_
? pointAverage(pointFld())()
: volFld
),
pointFld()
);
}
}

View File

@ -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)
{}

View File

@ -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

View File

@ -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<const fvMesh&>(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;
}
}
}

View File

@ -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<fvMeshSubset> subMeshPtr_;

View File

@ -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<GeometricField<Type, pointPatchField, pointMesh>> 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
(
(

View File

@ -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<Foam::plane&>(*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())
{

View File

@ -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<scalar>("lowerLimit", -vGreat)),
upperThreshold_(dict.lookupOrDefault<scalar>("upperLimit", vGreat)),
zoneKey_(keyType::null),
triangulate_(dict.lookupOrDefault("triangulate", false)),
prevTimeIndex_(-1),
meshCells_(0)

View File

@ -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_;