From 27888bf7aae988f4afc9ae5747afec0aa99476d6 Mon Sep 17 00:00:00 2001 From: Andrew Heather <a.heather@opencfd.co.uk> Date: Tue, 22 May 2018 10:10:48 +0100 Subject: [PATCH] ENH: Updated mechanism to create empty sets and zones --- .../meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C | 48 ++++++++++++++++++- .../meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H | 4 ++ src/meshTools/sets/topoSets/topoSet.C | 17 ++++++- src/meshTools/sets/topoSets/topoSet.H | 3 ++ 4 files changed, 68 insertions(+), 4 deletions(-) diff --git a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C index 9dc2bcc03fc..1abac79a9ad 100644 --- a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C @@ -29,6 +29,18 @@ License #include "stringListOps.H" #include "Pstream.H" +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + template<class ZoneType, class MeshType> + int Foam::ZoneMesh<ZoneType, MeshType>::disallowGenericZones + ( + debug::debugSwitch("disallowGenericZones", 0) + ); +} + + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template<class ZoneType, class MeshType> @@ -429,8 +441,40 @@ Foam::label Foam::ZoneMesh<ZoneType, MeshType>::findZoneID << "List of available zone names: " << names() << endl; } - // Not found - return -1; + if (disallowGenericZones != 0) + { + // Create a new ... + Info<< "Creating dummy zone " << zoneName << endl; + dictionary dict; + dict.set("type", ZoneType::typeName); + dict.set(ZoneType::labelsName, labelList()); + + // flipMap only really applicable for face zones, but should not get + // in the way for cell- and point-zones... + dict.set("flipMap", boolList()); + label newZonei = zones.size(); + + ZoneMesh<ZoneType, MeshType>& zm = + const_cast<ZoneMesh<ZoneType, MeshType>&>(*this); + + zm.append + ( + new ZoneType + ( + zoneName, + dict, + newZonei, + zm + ) + ); + + return newZonei; + } + else + { + // Not found + return -1; + } } diff --git a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H index 94a8aa483c5..59d1d220526 100644 --- a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H @@ -102,6 +102,10 @@ class ZoneMesh public: + //- Debug switch to disallow the use of generic zones + static int disallowGenericZones; + + // Constructors //- Read constructor given IOobject and a MeshType reference diff --git a/src/meshTools/sets/topoSets/topoSet.C b/src/meshTools/sets/topoSets/topoSet.C index 8caf02d3ba6..754100d1dc2 100644 --- a/src/meshTools/sets/topoSets/topoSet.C +++ b/src/meshTools/sets/topoSets/topoSet.C @@ -37,6 +37,11 @@ namespace Foam defineRunTimeSelectionTable(topoSet, word); defineRunTimeSelectionTable(topoSet, size); defineRunTimeSelectionTable(topoSet, set); + + int Foam::topoSet::disallowGenericSets + ( + debug::debugSwitch("disallowGenericSets", 0) + ); } @@ -297,14 +302,14 @@ Foam::IOobject Foam::topoSet::findIOobject writeOption w ) { - return IOobject + IOobject io ( name, mesh.time().findInstance ( mesh.dbDir()/polyMesh::meshSubDir/"sets", word::null, - r, + IOobject::READ_IF_PRESENT, mesh.facesInstance() ), polyMesh::meshSubDir/"sets", @@ -312,6 +317,14 @@ Foam::IOobject Foam::topoSet::findIOobject r, w ); + + if (!io.typeHeaderOk<topoSet>(false) && disallowGenericSets != 0) + { + DebugInfo<< "Setting no read for set " << name << endl; + io.readOpt() = IOobject::NO_READ; + } + + return io; } diff --git a/src/meshTools/sets/topoSets/topoSet.H b/src/meshTools/sets/topoSets/topoSet.H index 82ca3e42ee9..55bd7941cf7 100644 --- a/src/meshTools/sets/topoSets/topoSet.H +++ b/src/meshTools/sets/topoSets/topoSet.H @@ -142,6 +142,9 @@ public: //- Name of file set will use. static fileName localPath(const polyMesh& mesh, const word& name); + //- Debug switch to disallow the use of generic sets + static int disallowGenericSets; + // Declare run-time constructor selection table -- GitLab