From bcc5169ddc27f8eba9af8f08779fbbbcb6b7cb1e Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Wed, 28 Jun 2023 11:53:14 +0100 Subject: [PATCH] fvMesh: Added meshPhi to the geometricFields set Also provide fields and curFields functions which return the list of registered fields not including the geometryFields and current registered fields not including the geometryFields or old-time fields to simplify mapping code for NCC, mesh-to-mesh mapping and load-balancing. --- .../DimensionedField/MapDimensionedFields.H | 4 +- .../GeometricField/MapGeometricFields.H | 2 + src/OpenFOAM/meshes/pointMesh/pointMesh.C | 4 +- src/OpenFOAM/meshes/pointMesh/pointMesh.H | 14 +- src/OpenFOAM/meshes/polyMesh/polyMesh.C | 5 +- src/OpenFOAM/meshes/polyMesh/polyMesh.H | 12 +- .../fvMeshAdder/fvMeshAdderTemplates.C | 6 + .../fvMeshDistribute/fvMeshDistribute.C | 223 +++++++++--------- .../fvMeshDistribute/fvMeshDistribute.H | 6 +- .../fvMeshDistributeTemplates.C | 179 ++++++-------- .../fvMeshTools/fvMeshToolsTemplates.C | 32 +-- .../singleRegionSolutionControlTemplates.C | 15 +- src/finiteVolume/fvMesh/fvMesh.C | 20 +- src/finiteVolume/fvMesh/fvMesh.H | 22 +- .../fvMeshDistributor/fvMeshDistributor.C | 7 - src/finiteVolume/fvMesh/fvMeshGeometry.C | 10 +- .../fvMeshStitcher/fvMeshStitcherTemplates.C | 148 +++++------- src/finiteVolume/fvMesh/fvMeshTemplates.C | 44 +++- .../field/nearWallFields/nearWallFields.C | 8 +- .../nearWallFields/nearWallFieldsTemplates.C | 61 ++--- .../fvMeshDistributorsDistributor.C | 3 - .../moving/fvMeshStitchersMoving.C | 10 +- .../meshToMesh/MeshToMeshMapGeometricFields.H | 86 ++----- .../meshToMesh/fvMeshTopoChangersMeshToMesh.C | 10 +- .../refiner/fvMeshTopoChangersRefiner.C | 62 +++-- 25 files changed, 478 insertions(+), 515 deletions(-) diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/MapDimensionedFields.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/MapDimensionedFields.H index 529dddaf1c..6f8556fe8f 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/MapDimensionedFields.H +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/MapDimensionedFields.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -49,6 +49,8 @@ void MapDimensionedFields(const MeshMapper& mapper) forAllConstIter(typename TableType, fields, fieldIter) { + if (fvMesh::geometryFields.found(fieldIter()->name())) continue; + FieldType& field = const_cast(*fieldIter()); if (&field.mesh() == &mapper.mesh()) diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/MapGeometricFields.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/MapGeometricFields.H index d53ea688d6..980781fd5b 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/MapGeometricFields.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/MapGeometricFields.H @@ -86,6 +86,8 @@ void MapGeometricFields ++fieldIter ) { + if (GeoMesh::Mesh::geometryFields.found(fieldIter()->name())) continue; + GeometricField& field = const_cast&> (*fieldIter()); diff --git a/src/OpenFOAM/meshes/pointMesh/pointMesh.C b/src/OpenFOAM/meshes/pointMesh/pointMesh.C index f9f5af7af7..e7ffe92876 100644 --- a/src/OpenFOAM/meshes/pointMesh/pointMesh.C +++ b/src/OpenFOAM/meshes/pointMesh/pointMesh.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -36,6 +36,8 @@ namespace Foam defineTypeNameAndDebug(pointMesh, 0); } +const Foam::HashSet Foam::pointMesh::geometryFields; + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/meshes/pointMesh/pointMesh.H b/src/OpenFOAM/meshes/pointMesh/pointMesh.H index 8a23965820..4babed02a5 100644 --- a/src/OpenFOAM/meshes/pointMesh/pointMesh.H +++ b/src/OpenFOAM/meshes/pointMesh/pointMesh.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -69,12 +69,20 @@ protected: public: + // Public Typedefs + + typedef pointMesh Mesh; + typedef pointBoundaryMesh BoundaryMesh; + + // Declare name of the class and its debug switch ClassName("pointMesh"); - typedef pointMesh Mesh; - typedef pointBoundaryMesh BoundaryMesh; + // Static data + + //- Set of names of registered geometric fields + const static HashSet geometryFields; // Constructors diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.C b/src/OpenFOAM/meshes/polyMesh/polyMesh.C index 2cbb8c8bba..a6bf559568 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.C @@ -41,11 +41,10 @@ License namespace Foam { defineTypeNameAndDebug(polyMesh, 0); - - word polyMesh::defaultRegion = "region0"; - word polyMesh::meshSubDir = "polyMesh"; } +Foam::word Foam::polyMesh::defaultRegion = "region0"; +Foam::word Foam::polyMesh::meshSubDir = "polyMesh"; // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.H b/src/OpenFOAM/meshes/polyMesh/polyMesh.H index aa927486b5..bbc26e37d7 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.H @@ -263,11 +263,15 @@ public: //- Runtime type information TypeName("polyMesh"); - //- Return the default region name - static word defaultRegion; - //- Return the mesh sub-directory name (usually "polyMesh") - static word meshSubDir; + // Static data + + //- Return the default region name + static word defaultRegion; + + //- Return the mesh sub-directory name (usually "polyMesh") + static word meshSubDir; + // Constructors diff --git a/src/dynamicMesh/fvMeshAdder/fvMeshAdderTemplates.C b/src/dynamicMesh/fvMeshAdder/fvMeshAdderTemplates.C index d6b5f3dcc3..911e7d4b29 100644 --- a/src/dynamicMesh/fvMeshAdder/fvMeshAdderTemplates.C +++ b/src/dynamicMesh/fvMeshAdder/fvMeshAdderTemplates.C @@ -276,6 +276,8 @@ void Foam::fvMeshAdder::MapVolFields ++fieldIter ) { + if (fvMesh::geometryFields.found(fieldIter()->name())) continue; + VolField& fld = const_cast&> ( @@ -569,6 +571,8 @@ void Foam::fvMeshAdder::MapSurfaceFields ++fieldIter ) { + if (fvMesh::geometryFields.found(fieldIter()->name())) continue; + SurfaceField& fld = const_cast&>(*fieldIter()); if (fieldsToAdd.found(fld.name())) @@ -870,6 +874,8 @@ void Foam::fvMeshAdder::MapPointFields ++fieldIter ) { + if (fvMesh::geometryFields.found(fieldIter()->name())) continue; + PointField& fld = const_cast&>(*fieldIter()); if (fieldsToAdd.found(fld.name())) diff --git a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C index 3cb9c38c9d..70c600842a 100644 --- a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C +++ b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C @@ -24,24 +24,15 @@ License \*---------------------------------------------------------------------------*/ #include "fvMeshDistribute.H" -#include "PstreamCombineReduceOps.H" #include "fvMeshAdder.H" -#include "faceCoupleInfo.H" -#include "processorFvPatchField.H" -#include "processorFvsPatchField.H" -#include "processorCyclicPolyPatch.H" #include "processorCyclicFvPatchField.H" #include "polyTopoChange.H" #include "removeCells.H" #include "polyModifyFace.H" -#include "polyRemovePoint.H" #include "polyDistributionMap.H" -#include "surfaceFields.H" -#include "pointFields.H" #include "syncTools.H" #include "CompactListList.H" #include "fvMeshTools.H" -#include "ListOps.H" #include "globalIndex.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -218,9 +209,29 @@ Foam::labelList Foam::fvMeshDistribute::select } +Foam::wordList Foam::fvMeshDistribute::fieldNames +( + const word& typeName, + label& nFields +) const +{ + wordList fieldNames(mesh_.names(typeName)); + + if (fieldNames.size()) + { + HashSet fieldSet(fieldNames); + fieldSet -= fvMesh::geometryFields; + fieldNames = fieldSet.toc(); + nFields += checkEqualWordList(typeName, fieldNames); + } + + return fieldNames; +} + + Foam::label Foam::fvMeshDistribute::checkEqualWordList ( - const string& msg, + const word& typeName, const wordList& lst ) { @@ -234,10 +245,11 @@ Foam::label Foam::fvMeshDistribute::checkEqualWordList if (allNames[proci] != allNames[0]) { FatalErrorInFunction - << "When checking for equal " << msg.c_str() << " :" << endl - << "processor0 has:" << allNames[0] << endl - << "processor" << proci << " has:" << allNames[proci] << endl - << msg.c_str() << " need to be synchronised on all processors." + << "When checking for equal numbers of " << typeName + << " :" << nl + << "processor0 has:" << allNames[0] << nl + << "processor" << proci << " has:" << allNames[proci] << nl + << typeName << " need to be synchronised on all processors." << exit(FatalError); } } @@ -561,16 +573,16 @@ Foam::autoPtr Foam::fvMeshDistribute::repatch // is currently not supported by topoChange. // Store boundary fields (we only do this for surfaceFields) - PtrList> sFlds; - saveBoundaryFields(sFlds); - PtrList> vFlds; - saveBoundaryFields(vFlds); - PtrList> sptFlds; - saveBoundaryFields(sptFlds); - PtrList> sytFlds; - saveBoundaryFields(sytFlds); - PtrList> tFlds; - saveBoundaryFields(tFlds); + PtrList> sFields; + saveBoundaryFields(sFields); + PtrList> vFields; + saveBoundaryFields(vFields); + PtrList> sptFields; + saveBoundaryFields(sptFields); + PtrList> sytFields; + saveBoundaryFields(sytFields); + PtrList> tFields; + saveBoundaryFields(tFields); // Change the mesh (no inflation). Note: parallel comms allowed. // @@ -586,11 +598,11 @@ Foam::autoPtr Foam::fvMeshDistribute::repatch // Map patch fields using stored boundary fields. Note: assumes order // of fields has not changed in object registry! - mapBoundaryFields(map, sFlds); - mapBoundaryFields(map, vFlds); - mapBoundaryFields(map, sptFlds); - mapBoundaryFields(map, sytFlds); - mapBoundaryFields(map, tFlds); + mapBoundaryFields(map, sFields); + mapBoundaryFields(map, vFields); + mapBoundaryFields(map, sptFields); + mapBoundaryFields(map, sytFields); + mapBoundaryFields(map, tFields); // Adapt constructMaps. @@ -1257,16 +1269,16 @@ Foam::autoPtr Foam::fvMeshDistribute::doRemoveCells // Save surface fields. This is not done as GeometricField as these would // get mapped. Fields are flattened for convenience. - PtrList> sFlds; - PtrList> vFlds; - PtrList> sptFlds; - PtrList> sytFlds; - PtrList> tFlds; - initMapExposedFaces(sFlds); - initMapExposedFaces(vFlds); - initMapExposedFaces(sptFlds); - initMapExposedFaces(sytFlds); - initMapExposedFaces(tFlds); + PtrList> sFields; + PtrList> vFields; + PtrList> sptFields; + PtrList> sytFields; + PtrList> tFields; + initMapExposedFaces(sFields); + initMapExposedFaces(vFields); + initMapExposedFaces(sptFields); + initMapExposedFaces(sytFields); + initMapExposedFaces(tFields); // Change the mesh. No inflation. Note: no parallel comms allowed. autoPtr map = meshMod.changeMesh(mesh_, false, false); @@ -1277,11 +1289,11 @@ Foam::autoPtr Foam::fvMeshDistribute::doRemoveCells // Any exposed faces in a surfaceField will not be mapped. Map the value // of these separately (until there is support in all PatchFields for // mapping from internal faces ...) - mapExposedFaces(map(), sFlds); - mapExposedFaces(map(), vFlds); - mapExposedFaces(map(), sptFlds); - mapExposedFaces(map(), sytFlds); - mapExposedFaces(map(), tFlds); + mapExposedFaces(map(), sFields); + mapExposedFaces(map(), vFields); + mapExposedFaces(map(), sptFields); + mapExposedFaces(map(), sytFields); + mapExposedFaces(map(), tFields); return map; } @@ -1609,10 +1621,6 @@ Foam::autoPtr Foam::fvMeshDistribute::receiveMesh labelList domainAllNeighbour(fromNbr); PtrList patchEntries(fromNbr); - //*** Read the old-time volumes if present - // scalarField V0(fromNbr); - // scalarField V00(fromNbr); - CompactListList