From 3cbb932be84f1b81a29cc97c77d9b1ad8c8a25d1 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Fri, 12 Apr 2019 18:44:32 +0100 Subject: [PATCH] Added support for patch manipulation of pointFields e.g. during createBaffles Added a test application and test case for meshTools: test/fvMeshTools Patch contributed by Mattijs Janssens --- .../createBaffles/createBaffles.C | 3 +- .../redistributePar/redistributePar.C | 62 +++- .../containers/Lists/PtrList/PtrList.C | 21 +- .../containers/Lists/PtrList/PtrList.H | 9 +- .../containers/Lists/UPtrList/UPtrList.C | 21 +- .../containers/Lists/UPtrList/UPtrList.H | 7 +- .../GeometricField/MapGeometricFields.H | 79 ++++- src/OpenFOAM/meshes/MeshObject/MeshObject.C | 95 +++++- src/OpenFOAM/meshes/MeshObject/MeshObject.H | 42 ++- .../pointBoundaryMesh/pointBoundaryMesh.C | 44 ++- .../pointBoundaryMesh/pointBoundaryMesh.H | 16 +- src/OpenFOAM/meshes/pointMesh/pointMesh.C | 88 ++++- src/OpenFOAM/meshes/pointMesh/pointMesh.H | 24 +- .../polyBoundaryMesh/polyBoundaryMesh.C | 23 +- .../polyBoundaryMesh/polyBoundaryMesh.H | 4 +- src/OpenFOAM/meshes/polyMesh/polyMesh.C | 121 +++++++ src/OpenFOAM/meshes/polyMesh/polyMesh.H | 19 ++ .../fvMeshAdder/directPointPatchFieldMapper.H | 111 ++++++ src/dynamicMesh/fvMeshAdder/fvMeshAdder.C | 64 +++- src/dynamicMesh/fvMeshAdder/fvMeshAdder.H | 25 +- .../fvMeshAdder/fvMeshAdderTemplates.C | 315 +++++++++++++++++- .../fvMeshDistribute/fvMeshDistribute.C | 141 +++++++- .../fvMeshDistribute/fvMeshDistribute.H | 4 +- .../fvMeshDistributeTemplates.C | 8 +- src/dynamicMesh/fvMeshTools/fvMeshTools.C | 277 +++------------ src/dynamicMesh/fvMeshTools/fvMeshTools.H | 25 +- .../fvMeshTools/fvMeshToolsTemplates.C | 119 +------ src/dynamicMesh/polyMeshAdder/polyMeshAdder.C | 70 ++-- .../fvMesh/fvBoundaryMesh/fvBoundaryMesh.C | 13 +- .../fvMesh/fvBoundaryMesh/fvBoundaryMesh.H | 8 +- src/finiteVolume/fvMesh/fvMesh.C | 189 ++++++++++- src/finiteVolume/fvMesh/fvMesh.H | 21 +- .../meshRefinement/meshRefinement.C | 239 +++---------- .../meshRefinement/meshRefinement.H | 23 +- .../meshRefinement/meshRefinementTemplates.C | 55 +-- .../snappyHexMeshDriver/snappyLayerDriver.C | 31 +- test/fvMeshTools/Allrun | 11 + test/fvMeshTools/Test-fvMeshTools/Make/files | 3 + .../fvMeshTools/Test-fvMeshTools/Make/options | 11 + .../Test-fvMeshTools/Test-fvMeshTools.C | 217 ++++++++++++ test/fvMeshTools/cavity/0/U | 45 +++ test/fvMeshTools/cavity/0/p | 44 +++ test/fvMeshTools/cavity/0/pointDisplacement | 46 +++ test/fvMeshTools/cavity/Allrun | 23 ++ test/fvMeshTools/cavity/system/blockMeshDict | 82 +++++ test/fvMeshTools/cavity/system/controlDict | 49 +++ .../cavity/system/decomposeParDict | 21 ++ test/fvMeshTools/cavity/system/fvSchemes | 55 +++ test/fvMeshTools/cavity/system/fvSolution | 52 +++ 49 files changed, 2296 insertions(+), 779 deletions(-) create mode 100644 src/dynamicMesh/fvMeshAdder/directPointPatchFieldMapper.H create mode 100755 test/fvMeshTools/Allrun create mode 100644 test/fvMeshTools/Test-fvMeshTools/Make/files create mode 100644 test/fvMeshTools/Test-fvMeshTools/Make/options create mode 100644 test/fvMeshTools/Test-fvMeshTools/Test-fvMeshTools.C create mode 100644 test/fvMeshTools/cavity/0/U create mode 100644 test/fvMeshTools/cavity/0/p create mode 100644 test/fvMeshTools/cavity/0/pointDisplacement create mode 100755 test/fvMeshTools/cavity/Allrun create mode 100644 test/fvMeshTools/cavity/system/blockMeshDict create mode 100644 test/fvMeshTools/cavity/system/controlDict create mode 100644 test/fvMeshTools/cavity/system/decomposeParDict create mode 100644 test/fvMeshTools/cavity/system/fvSchemes create mode 100644 test/fvMeshTools/cavity/system/fvSolution diff --git a/applications/utilities/mesh/manipulation/createBaffles/createBaffles.C b/applications/utilities/mesh/manipulation/createBaffles/createBaffles.C index 863d88ceb5..807cd43925 100644 --- a/applications/utilities/mesh/manipulation/createBaffles/createBaffles.C +++ b/applications/utilities/mesh/manipulation/createBaffles/createBaffles.C @@ -46,6 +46,7 @@ Description #include "ReadFields.H" #include "volFields.H" #include "surfaceFields.H" +#include "pointFields.H" #include "fvMeshMapper.H" #include "faceSelection.H" @@ -504,7 +505,7 @@ int main(int argc, char *argv[]) #include "readVolFields.H" #include "readSurfaceFields.H" - // #include "readPointFields.H" + #include "readPointFields.H" // Creating (if necessary) faceZones diff --git a/applications/utilities/parallelProcessing/redistributePar/redistributePar.C b/applications/utilities/parallelProcessing/redistributePar/redistributePar.C index 2967dce673..73b9f6a4d1 100644 --- a/applications/utilities/parallelProcessing/redistributePar/redistributePar.C +++ b/applications/utilities/parallelProcessing/redistributePar/redistributePar.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -254,7 +254,7 @@ template void readFields ( const boolList& haveMesh, - const fvMesh& mesh, + const typename GeoField::Mesh& mesh, const autoPtr& subsetterPtr, IOobjectList& allObjects, PtrList& fields @@ -335,8 +335,8 @@ void readFields IOobject ( name, - mesh.time().timeName(), - mesh, + mesh.thisDb().time().timeName(), + mesh.thisDb(), IOobject::NO_READ, IOobject::AUTO_WRITE ), @@ -723,6 +723,60 @@ int main(int argc, char *argv[]) ); + // pointFields + + pointMesh& pMesh = + const_cast(pointMesh::New(mesh)); + PtrList pointScalarFields; + readFields + ( + haveMesh, + pMesh, + subsetterPtr, + objects, + pointScalarFields + ); + + PtrList pointVectorFields; + readFields + ( + haveMesh, + pMesh, + subsetterPtr, + objects, + pointVectorFields + ); + + PtrList pointSphereTensorFields; + readFields + ( + haveMesh, + pMesh, + subsetterPtr, + objects, + pointSphereTensorFields + ); + + PtrList pointSymmTensorFields; + readFields + ( + haveMesh, + pMesh, + subsetterPtr, + objects, + pointSymmTensorFields + ); + + PtrList pointTensorFields; + readFields + ( + haveMesh, + pMesh, + subsetterPtr, + objects, + pointTensorFields + ); + // Debugging: Create additional volField that will be mapped. // Used to test correctness of mapping // volVectorField mapCc("mapCc", 1*mesh.C()); diff --git a/src/OpenFOAM/containers/Lists/PtrList/PtrList.C b/src/OpenFOAM/containers/Lists/PtrList/PtrList.C index aa4d03d28e..38ad30c7b3 100644 --- a/src/OpenFOAM/containers/Lists/PtrList/PtrList.C +++ b/src/OpenFOAM/containers/Lists/PtrList/PtrList.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -244,6 +244,25 @@ void Foam::PtrList::reorder(const labelUList& oldToNew) } +template +void Foam::PtrList::shuffle(const labelUList& newToOld) +{ + List newPtrs_(newToOld.size(), reinterpret_cast(0)); + + forAll(newToOld, newI) + { + label oldI = newToOld[newI]; + + if (oldI >= 0 && oldI < this->size()) + { + newPtrs_[newI] = this->ptrs_[oldI]; + } + } + + this->ptrs_.transfer(newPtrs_); +} + + // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template diff --git a/src/OpenFOAM/containers/Lists/PtrList/PtrList.H b/src/OpenFOAM/containers/Lists/PtrList/PtrList.H index 5a0b347b0c..697fe738ef 100644 --- a/src/OpenFOAM/containers/Lists/PtrList/PtrList.H +++ b/src/OpenFOAM/containers/Lists/PtrList/PtrList.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -165,7 +165,12 @@ public: //- Reorders elements. Ordering does not have to be done in // ascending or descending order. Reordering has to be unique. // (is shuffle) - void reorder(const labelUList&); + void reorder(const labelUList& oldToNew); + + //- Reorders elements. Ordering does not have to be done in + // ascending or descending order. Reordering has to be unique. + // Note: can create unset elements + void shuffle(const labelUList& newToOld); // Member operators diff --git a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.C b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.C index 25bca39adf..5ccbb15e22 100644 --- a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.C +++ b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -145,6 +145,25 @@ void Foam::UPtrList::reorder(const labelUList& oldToNew) } +template +void Foam::UPtrList::shuffle(const labelUList& newToOld) +{ + List newPtrs_(newToOld.size(), reinterpret_cast(0)); + + forAll(newToOld, newI) + { + label oldI = newToOld[newI]; + + if (oldI >= 0 && oldI < this->size()) + { + newPtrs_[newI] = this->ptrs_[oldI]; + } + } + + this->ptrs_.transfer(newPtrs_); +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #include "UPtrListIO.C" diff --git a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H index 9753fe57f2..af78b0735a 100644 --- a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H +++ b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.H @@ -148,7 +148,12 @@ public: //- Reorders elements. Ordering does not have to be done in // ascending or descending order. Reordering has to be unique. // (is shuffle) - void reorder(const labelUList&); + void reorder(const labelUList& oldToNew); + + //- Reorders elements. Ordering does not have to be done in + // ascending or descending order. Reordering has to be unique. + // Note: can create unset elements + void shuffle(const labelUList& newToOld); // Member operators diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/MapGeometricFields.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/MapGeometricFields.H index 2f8b4f38e6..17857d8dbd 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/MapGeometricFields.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/MapGeometricFields.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -155,6 +155,83 @@ void MapGeometricFields } +template +void AddPatchFields +( + objectRegistry& obr, + const label insertPatchi, + const dictionary& patchFieldDict, + const word& defaultPatchFieldType, + const typename GeoField::value_type& defaultPatchValue +) +{ + HashTable flds(obr.lookupClass()); + + const wordList fldNames(flds.sortedToc()); + + forAll(fldNames, i) + { + GeoField& fld = *flds[fldNames[i]]; + + typename GeoField::Boundary& bfld = fld.boundaryFieldRef(); + + if (bfld.size() != fld.mesh().boundary().size()) + { + FatalErrorInFunction << "bfld size:" << bfld.size() + << " mesh size:" << fld.mesh().boundary().size() + << exit(FatalError); + } + + if (patchFieldDict.found(fld.name())) + { + bfld.set + ( + insertPatchi, + GeoField::Patch::New + ( + fld.mesh().boundary()[insertPatchi], + fld(), + patchFieldDict.subDict(fld.name()) + ) + ); + } + else + { + bfld.set + ( + insertPatchi, + GeoField::Patch::New + ( + defaultPatchFieldType, + fld.mesh().boundary()[insertPatchi], + fld() + ) + ); + bfld[insertPatchi] == defaultPatchValue; + } + } +} + + +template +void ReorderPatchFields +( + objectRegistry& obr, + const labelUList& newToOld +) +{ + HashTable flds(obr.lookupClass()); + const wordList fldNames(flds.sortedToc()); + forAll(fldNames, i) + { + GeoField& fld = *flds[fldNames[i]]; + typename GeoField::Boundary& bfld = fld.boundaryFieldRef(); + + bfld.shuffle(newToOld); + } +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/meshes/MeshObject/MeshObject.C b/src/OpenFOAM/meshes/MeshObject/MeshObject.C index 4486544d8c..f77a84a8a3 100644 --- a/src/OpenFOAM/meshes/MeshObject/MeshObject.C +++ b/src/OpenFOAM/meshes/MeshObject/MeshObject.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -366,6 +366,99 @@ void Foam::meshObject::updateMesh(objectRegistry& obr, const mapPolyMesh& mpm) } +template +void Foam::meshObject::addPatch(objectRegistry& obr, const label patchi) +{ + HashTable*> meshObjects + ( + obr.lookupClass>() + ); + + if (meshObject::debug) + { + Pout<< "meshObject::addPatch(objectRegistry&, " + "const label patchi) : updating " << Mesh::typeName + << " meshObjects for region " << obr.name() << endl; + } + + forAllIter + ( + typename HashTable*>, + meshObjects, + iter + ) + { + if (isA>(*iter())) + { + if (meshObject::debug) + { + Pout<< " Adding patch to " << iter()->name() << endl; + } + dynamic_cast*>(iter())->addPatch(patchi); + } + else + { + if (meshObject::debug) + { + Pout<< " Destroying " << iter()->name() << endl; + } + obr.checkOut(*iter()); + } + } +} + + +template +void Foam::meshObject::reorderPatches +( + objectRegistry& obr, + const labelUList& newToOld, + const bool validBoundary +) +{ + HashTable*> meshObjects + ( + obr.lookupClass>() + ); + + if (meshObject::debug) + { + Pout<< "meshObject::addPatch(objectRegistry&, " + "const labelUList&, const bool) : updating " << Mesh::typeName + << " meshObjects for region " << obr.name() << endl; + } + + forAllIter + ( + typename HashTable*>, + meshObjects, + iter + ) + { + if (isA>(*iter())) + { + if (meshObject::debug) + { + Pout<< " Adding patch to " << iter()->name() << endl; + } + dynamic_cast*>(iter())->reorderPatches + ( + newToOld, + validBoundary + ); + } + else + { + if (meshObject::debug) + { + Pout<< " Destroying " << iter()->name() << endl; + } + obr.checkOut(*iter()); + } + } +} + + template class MeshObjectType> void Foam::meshObject::clear(objectRegistry& obr) { diff --git a/src/OpenFOAM/meshes/MeshObject/MeshObject.H b/src/OpenFOAM/meshes/MeshObject/MeshObject.H index f76fd3985e..746c5c335e 100644 --- a/src/OpenFOAM/meshes/MeshObject/MeshObject.H +++ b/src/OpenFOAM/meshes/MeshObject/MeshObject.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -53,6 +53,7 @@ Description - MoveableMeshObject: mesh object to be updated in movePoints - UpdateableMeshObject: mesh object to be updated in updateMesh or movePoints + - PatchMeshObject: mesh object to be additionally updated patch changes Note movePoints must be provided for MeshObjects of type MoveableMeshObject @@ -184,6 +185,16 @@ public: template static void updateMesh(objectRegistry&, const mapPolyMesh&); + template + static void addPatch(objectRegistry&, const label patchi); + template + static void reorderPatches + ( + objectRegistry&, + const labelUList& newToOld, + const bool validBoundary + ); + template class MeshObjectType> static void clear(objectRegistry&); @@ -275,6 +286,35 @@ public: }; +/*---------------------------------------------------------------------------*\ + Class PatchMeshObject Declaration +\*---------------------------------------------------------------------------*/ + +template +class PatchMeshObject +: + public UpdateableMeshObject +{ +public: + + PatchMeshObject(const word& typeName, const objectRegistry& obr) + : + UpdateableMeshObject(typeName, obr) + {} + + //- Reordered/removed trailing patches. If validBoundary call is parallel + // synced and all add the same patch with same settings + virtual void reorderPatches + ( + const labelUList& newToOld, + const bool validBoundary + ) = 0; + + //- Inserted patch at patchi + virtual void addPatch(const label patchi) = 0; +}; + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/meshes/pointMesh/pointBoundaryMesh/pointBoundaryMesh.C b/src/OpenFOAM/meshes/pointMesh/pointBoundaryMesh/pointBoundaryMesh.C index 2d5b83d524..0a0526f2b6 100644 --- a/src/OpenFOAM/meshes/pointMesh/pointBoundaryMesh/pointBoundaryMesh.C +++ b/src/OpenFOAM/meshes/pointMesh/pointBoundaryMesh/pointBoundaryMesh.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -42,17 +42,7 @@ Foam::pointBoundaryMesh::pointBoundaryMesh pointPatchList(basicBdry.size()), mesh_(m) { - // Set boundary patches - pointPatchList& Patches = *this; - - forAll(Patches, patchi) - { - Patches.set - ( - patchi, - facePointPatch::New(basicBdry[patchi], *this).ptr() - ); - } + reset(basicBdry); } @@ -212,4 +202,34 @@ void Foam::pointBoundaryMesh::updateMesh() } +void Foam::pointBoundaryMesh::reset(const polyBoundaryMesh& basicBdry) +{ + // Set boundary patches + pointPatchList& Patches = *this; + + forAll(Patches, patchi) + { + Patches.set + ( + patchi, + facePointPatch::New(basicBdry[patchi], *this).ptr() + ); + } +} + + +void Foam::pointBoundaryMesh::shuffle +( + const labelUList& newToOld, + const bool validBoundary +) +{ + pointPatchList::shuffle(newToOld); + if (validBoundary) + { + updateMesh(); + } +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/meshes/pointMesh/pointBoundaryMesh/pointBoundaryMesh.H b/src/OpenFOAM/meshes/pointMesh/pointBoundaryMesh/pointBoundaryMesh.H index 2c25feb1de..88cfb8ac02 100644 --- a/src/OpenFOAM/meshes/pointMesh/pointBoundaryMesh/pointBoundaryMesh.H +++ b/src/OpenFOAM/meshes/pointMesh/pointBoundaryMesh/pointBoundaryMesh.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -102,11 +102,21 @@ public: //- Find patch indices given a name labelList findIndices(const keyType&, const bool useGroups) const; - //- Correct polyBoundaryMesh after moving points + //- Correct pointBoundaryMesh after moving points void movePoints(const pointField&); - //- Correct polyBoundaryMesh after topology update + //- Correct pointBoundaryMesh after topology update void updateMesh(); + + //- Create pointBoundaryMesh from polyBoundaryMesh + void reset(const polyBoundaryMesh&); + + //- Reorders patches. Ordering does not have to be done in + // ascending or descending order. Reordering has to be unique. + // (is shuffle). If validBoundary calls updateMesh() + // after reordering to recalculate data (so call needs to be parallel + // sync in that case) + void shuffle(const labelUList& newToOld, const bool validBoundary); }; diff --git a/src/OpenFOAM/meshes/pointMesh/pointMesh.C b/src/OpenFOAM/meshes/pointMesh/pointMesh.C index 0889cb7e84..3d2a11cdc4 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-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -29,7 +29,7 @@ License #include "pointFields.H" #include "MapGeometricFields.H" #include "MapPointField.H" - +#include "facePointPatch.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -72,7 +72,7 @@ void Foam::pointMesh::mapFields(const mapPolyMesh& mpm) Foam::pointMesh::pointMesh(const polyMesh& pMesh) : - MeshObject(pMesh), + MeshObject(pMesh), GeoMesh(pMesh), boundary_(*this, pMesh.boundaryMesh()) { @@ -96,12 +96,31 @@ Foam::pointMesh::~pointMesh() { Pout<< "~pointMesh::pointMesh()" << endl; + error::printStack(Pout); } } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +void Foam::pointMesh::reset(const bool validBoundary) +{ + const polyMesh& pm = operator()(); + if (debug) + { + Pout<< "pointMesh::reset(const bool validBoundary): " + << "Resetting from polyMesh " << pm.name() << endl; + } + + boundary_.reset(pm.boundaryMesh()); + if (validBoundary) + { + // Calculate the geometry for the patches (transformation tensors etc.) + boundary_.calcGeometry(); + } +} + + bool Foam::pointMesh::movePoints() { if (debug) @@ -131,4 +150,67 @@ void Foam::pointMesh::updateMesh(const mapPolyMesh& mpm) } +void Foam::pointMesh::reorderPatches +( + const labelUList& newToOld, + const bool validBoundary +) +{ + if (debug) + { + Pout<< "pointMesh::reorderPatches( const labelUList&, const bool): " + << "Updating for reordered patches." << endl; + Pout<< endl; + } + + boundary_.shuffle(newToOld, validBoundary); + + objectRegistry& db = const_cast(thisDb()); + ReorderPatchFields(db, newToOld); + ReorderPatchFields(db, newToOld); + ReorderPatchFields(db, newToOld); + ReorderPatchFields(db, newToOld); + ReorderPatchFields(db, newToOld); +} + + +void Foam::pointMesh::addPatch(const label patchi) +{ + if (debug) + { + Pout<< "pointMesh::addPatch(const label): " + << "Adding patch at " << patchi << endl; + Pout<< endl; + } + + const polyBoundaryMesh& pbm = mesh().boundaryMesh(); + if (pbm.size() != boundary_.size()) + { + FatalErrorInFunction << "Problem :" + << " pointBoundaryMesh size :" << boundary_.size() + << " polyBoundaryMesh size :" << pbm.size() + << exit(FatalError); + } + + boundary_.set(patchi, facePointPatch::New(pbm[patchi], boundary_).ptr()); + + objectRegistry& db = const_cast(thisDb()); + const dictionary d; + const word patchFieldType("calculated"); + + AddPatchFields(db, patchi, d, patchFieldType, Zero); + AddPatchFields(db, patchi, d, patchFieldType, Zero); + AddPatchFields + ( + db, + patchi, + d, + patchFieldType, + Zero + ); + AddPatchFields(db, patchi, d, patchFieldType, Zero); + AddPatchFields(db, patchi, d, patchFieldType, Zero); +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/meshes/pointMesh/pointMesh.H b/src/OpenFOAM/meshes/pointMesh/pointMesh.H index 5c0d882b9d..353a8af5c8 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-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -48,7 +48,7 @@ namespace Foam class pointMesh : - public MeshObject, + public MeshObject, public GeoMesh { // Permanent data @@ -121,14 +121,28 @@ public: return GeoMesh::mesh_.thisDb(); } + //- Reset for changed polyMesh + void reset(const bool validBoundary); - // Mesh motion + + // Mesh callbacks //- Move points - bool movePoints(); + virtual bool movePoints(); //- Update the mesh corresponding to given map - void updateMesh(const mapPolyMesh& mpm); + virtual void updateMesh(const mapPolyMesh& mpm); + + //- Reordered/removed trailing patches. If validBoundary call is + // parallel synced and all add the same patch with same settings + virtual void reorderPatches + ( + const labelUList& newToOld, + const bool validBoundary + ); + + //- Inserted patch at patchi + virtual void addPatch(const label patchi); // Member Operators diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C index 5016713e58..1ad854aa03 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -197,7 +197,10 @@ void Foam::polyBoundaryMesh::clearGeom() { forAll(*this, patchi) { - operator[](patchi).clearGeom(); + if (this->set(patchi)) + { + operator[](patchi).clearGeom(); + } } } @@ -210,7 +213,10 @@ void Foam::polyBoundaryMesh::clearAddressing() forAll(*this, patchi) { - operator[](patchi).clearAddressing(); + if (this->set(patchi)) + { + operator[](patchi).clearAddressing(); + } } } @@ -1100,21 +1106,24 @@ void Foam::polyBoundaryMesh::updateMesh() } -void Foam::polyBoundaryMesh::reorder +void Foam::polyBoundaryMesh::shuffle ( - const labelUList& oldToNew, + const labelUList& newToOld, const bool validBoundary ) { // Change order of patches - polyPatchList::reorder(oldToNew); + polyPatchList::shuffle(newToOld); // Adapt indices polyPatchList& patches = *this; forAll(patches, patchi) { - patches[patchi].index() = patchi; + if (patches.set(patchi)) + { + patches[patchi].index() = patchi; + } } if (validBoundary) diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H index 06bd7ffacb..6a9bf1cc58 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -226,7 +226,7 @@ public: // (is shuffle) If validBoundary calls updateMesh() // after reordering to recalculate data (so call needs to be parallel // sync in that case) - void reorder(const labelUList&, const bool validBoundary); + void shuffle(const labelUList& newToOld, const bool validBoundary); //- writeData member function required by regIOobject bool writeData(Ostream&) const; diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.C b/src/OpenFOAM/meshes/polyMesh/polyMesh.C index 053aa1668e..ef61acb450 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.C @@ -1006,6 +1006,127 @@ void Foam::polyMesh::addZones } +void Foam::polyMesh::reorderPatches +( + const labelUList& newToOld, + const bool validBoundary +) +{ + // Clear local fields and e.g. polyMesh parallelInfo. Do not clearGeom + // so we keep PatchMeshObjects intact. + boundary_.clearGeom(); + clearAddressing(true); + // Clear all but PatchMeshObjects + meshObject::clearUpto + < + polyMesh, + TopologicalMeshObject, + PatchMeshObject + > + ( + *this + ); + meshObject::clearUpto + < + pointMesh, + TopologicalMeshObject, + PatchMeshObject + > + ( + *this + ); + + boundary_.shuffle(newToOld, validBoundary); + + // Warn mesh objects + meshObject::reorderPatches(*this, newToOld, validBoundary); + meshObject::reorderPatches(*this, newToOld, validBoundary); +} + + +void Foam::polyMesh::addPatch +( + const label insertPatchi, + const polyPatch& patch, + const dictionary& patchFieldDict, + const word& defaultPatchFieldType, + const bool validBoundary +) +{ + const label sz = boundary_.size(); + + label startFacei = nFaces(); + if (insertPatchi < sz) + { + startFacei = boundary_[insertPatchi].start(); + } + + // Create reordering list + // patches before insert position stay as is + // patches after insert position move one up + labelList newToOld(boundary_.size()+1); + for (label i = 0; i < insertPatchi; i++) + { + newToOld[i] = i; + } + for (label i = insertPatchi; i < sz; i++) + { + newToOld[i+1] = i; + } + newToOld[insertPatchi] = -1; + + reorderPatches(newToOld, false); + + // Clear local fields and e.g. polyMesh parallelInfo. + //clearGeom(); // would clear out pointMesh as well + boundary_.clearGeom(); + clearAddressing(true); + + // Clear all but PatchMeshObjects + meshObject::clearUpto + < + polyMesh, + TopologicalMeshObject, + PatchMeshObject + > + ( + *this + ); + meshObject::clearUpto + < + pointMesh, + TopologicalMeshObject, + PatchMeshObject + > + ( + *this + ); + + + // Insert polyPatch + boundary_.set + ( + insertPatchi, + patch.clone + ( + boundary_, + insertPatchi, // index + 0, // size + startFacei // start + ) + ); + + if (validBoundary) + { + boundary_.updateMesh(); + } + + // Warn mesh objects + meshObject::addPatch(*this, insertPatchi); + meshObject::addPatch(*this, insertPatchi); +} + + const Foam::pointField& Foam::polyMesh::points() const { if (clearedPrimitives_) diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.H b/src/OpenFOAM/meshes/polyMesh/polyMesh.H index f1f27c53f0..310ecd6094 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.H @@ -587,6 +587,25 @@ public: const List& cz ); + //- Add/insert single patch. If validBoundary the new situation + // is consistent across processors. + virtual void addPatch + ( + const label insertPatchi, + const polyPatch& patch, + const dictionary& patchFieldDict, + const word& defaultPatchFieldType, + const bool validBoundary + ); + + //- Reorder and trim existing patches. If validBoundary the new + // situation is consistent across processors + virtual void reorderPatches + ( + const labelUList& newToOld, + const bool validBoundary + ); + //- Update the mesh based on the mesh files saved in // time directories virtual readUpdateState readUpdate(); diff --git a/src/dynamicMesh/fvMeshAdder/directPointPatchFieldMapper.H b/src/dynamicMesh/fvMeshAdder/directPointPatchFieldMapper.H new file mode 100644 index 0000000000..ecb7859579 --- /dev/null +++ b/src/dynamicMesh/fvMeshAdder/directPointPatchFieldMapper.H @@ -0,0 +1,111 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2019 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::directPointPatchFieldMapper + +Description + direct PointPatchFieldMapper + +\*---------------------------------------------------------------------------*/ + +#ifndef directPointPatchFieldMapper_H +#define directPointPatchFieldMapper_H + +#include "pointPatchFieldMapper.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class directPointPatchFieldMapper Declaration +\*---------------------------------------------------------------------------*/ + +class directPointPatchFieldMapper +: + public pointPatchFieldMapper +{ + + //- Addressing from new back to old + const labelUList& directAddressing_; + + //- Does map contain any unmapped values + bool hasUnmapped_; + + +public: + + // Constructors + + //- Construct given addressing + directPointPatchFieldMapper(const labelUList& directAddressing) + : + directAddressing_(directAddressing), + hasUnmapped_(false) + { + if (directAddressing_.size() && min(directAddressing_) < 0) + { + hasUnmapped_ = true; + } + } + + //- Destructor + virtual ~directPointPatchFieldMapper() + {} + + + // Member Functions + + label size() const + { + return directAddressing_.size(); + } + + bool direct() const + { + return true; + } + + bool hasUnmapped() const + { + return hasUnmapped_; + } + + const labelUList& directAddressing() const + { + return directAddressing_; + } +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/dynamicMesh/fvMeshAdder/fvMeshAdder.C b/src/dynamicMesh/fvMeshAdder/fvMeshAdder.C index 81267812de..c9ad717cf9 100644 --- a/src/dynamicMesh/fvMeshAdder/fvMeshAdder.C +++ b/src/dynamicMesh/fvMeshAdder/fvMeshAdder.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -75,7 +75,19 @@ Foam::autoPtr Foam::fvMeshAdder::add const bool validBoundary ) { - mesh0.clearOut(); + // Store old mesh0 point maps + labelListList oldMeshPoints0; + const bool havePointMesh = + mesh0.foundObject(pointMesh::typeName); + if (havePointMesh) + { + const polyBoundaryMesh& pbm0 = mesh0.boundaryMesh(); + oldMeshPoints0.setSize(pbm0.size()); + forAll(pbm0, patchi) + { + oldMeshPoints0[patchi] = pbm0[patchi].meshPoints(); + } + } // Resulting merged mesh (polyMesh only!) autoPtr mapPtr @@ -101,23 +113,41 @@ Foam::autoPtr Foam::fvMeshAdder::add // Do the mapping of the stored fields // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - fvMeshAdder::MapVolFields(mapPtr, mesh0, mesh1); - fvMeshAdder::MapVolFields(mapPtr, mesh0, mesh1); - fvMeshAdder::MapVolFields(mapPtr, mesh0, mesh1); - fvMeshAdder::MapVolFields(mapPtr, mesh0, mesh1); - fvMeshAdder::MapVolFields(mapPtr, mesh0, mesh1); + MapVolFields(mapPtr, mesh0, mesh1); + MapVolFields(mapPtr, mesh0, mesh1); + MapVolFields(mapPtr, mesh0, mesh1); + MapVolFields(mapPtr, mesh0, mesh1); + MapVolFields(mapPtr, mesh0, mesh1); - fvMeshAdder::MapSurfaceFields(mapPtr, mesh0, mesh1); - fvMeshAdder::MapSurfaceFields(mapPtr, mesh0, mesh1); - fvMeshAdder::MapSurfaceFields(mapPtr, mesh0, mesh1); - fvMeshAdder::MapSurfaceFields(mapPtr, mesh0, mesh1); - fvMeshAdder::MapSurfaceFields(mapPtr, mesh0, mesh1); + MapSurfaceFields(mapPtr, mesh0, mesh1); + MapSurfaceFields(mapPtr, mesh0, mesh1); + MapSurfaceFields(mapPtr, mesh0, mesh1); + MapSurfaceFields(mapPtr, mesh0, mesh1); + MapSurfaceFields(mapPtr, mesh0, mesh1); - fvMeshAdder::MapDimFields(mapPtr, mesh0, mesh1); - fvMeshAdder::MapDimFields(mapPtr, mesh0, mesh1); - fvMeshAdder::MapDimFields(mapPtr, mesh0, mesh1); - fvMeshAdder::MapDimFields(mapPtr, mesh0, mesh1); - fvMeshAdder::MapDimFields(mapPtr, mesh0, mesh1); + if (havePointMesh) + { + // Recreate point mesh + const pointMesh& pointMesh0 = pointMesh::New(mesh0); + + MapPointFields(mapPtr, pointMesh0, oldMeshPoints0, mesh1); + MapPointFields(mapPtr, pointMesh0, oldMeshPoints0, mesh1); + MapPointFields + ( + mapPtr, + pointMesh0, + oldMeshPoints0, + mesh1 + ); + MapPointFields(mapPtr, pointMesh0, oldMeshPoints0, mesh1); + MapPointFields(mapPtr, pointMesh0, oldMeshPoints0, mesh1); + } + + MapDimFields(mapPtr, mesh0, mesh1); + MapDimFields(mapPtr, mesh0, mesh1); + MapDimFields(mapPtr, mesh0, mesh1); + MapDimFields(mapPtr, mesh0, mesh1); + MapDimFields(mapPtr, mesh0, mesh1); return mapPtr; } diff --git a/src/dynamicMesh/fvMeshAdder/fvMeshAdder.H b/src/dynamicMesh/fvMeshAdder/fvMeshAdder.H index ecfff2cbfb..70947e68ce 100644 --- a/src/dynamicMesh/fvMeshAdder/fvMeshAdder.H +++ b/src/dynamicMesh/fvMeshAdder/fvMeshAdder.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -43,6 +43,7 @@ SourceFiles #include "fvsPatchFieldsFwd.H" #include "fvPatchFieldMapper.H" #include "DimensionedField.H" +#include "pointFieldsFwd.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -102,6 +103,18 @@ private: const GeometricField& fldToAdd ); + //- Update single pointField. + template + static void MapPointField + ( + const pointMesh& mesh, + const mapAddedPolyMesh& meshMap, + const labelListList& oldMeshPoints, + + GeometricField& fld, + const GeometricField& fldToAdd + ); + //- Update single dimensionedField. template static void MapDimField @@ -147,6 +160,16 @@ public: const fvMesh& meshToAdd ); + //- Map all surfaceFields of Type + template + static void MapPointFields + ( + const mapAddedPolyMesh&, + const pointMesh& mesh, + const labelListList& oldMeshPoints, + const objectRegistry& meshToAdd + ); + //- Map all DimensionedFields of Type template static void MapDimFields diff --git a/src/dynamicMesh/fvMeshAdder/fvMeshAdderTemplates.C b/src/dynamicMesh/fvMeshAdder/fvMeshAdderTemplates.C index fd85c3b331..59da43701b 100644 --- a/src/dynamicMesh/fvMeshAdder/fvMeshAdderTemplates.C +++ b/src/dynamicMesh/fvMeshAdder/fvMeshAdderTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,8 +25,9 @@ License #include "volFields.H" #include "surfaceFields.H" -#include "emptyFvPatchField.H" +#include "pointFields.H" #include "directFvPatchFieldMapper.H" +#include "directPointPatchFieldMapper.H" // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // @@ -640,6 +641,316 @@ void Foam::fvMeshAdder::MapSurfaceFields } +template +void Foam::fvMeshAdder::MapPointField +( + const pointMesh& mesh, + const mapAddedPolyMesh& meshMap, + const labelListList& oldMeshPoints, + + GeometricField& fld, + const GeometricField& fldToAdd +) +{ + // This is a bit tricky: + // - mesh pointed to by fld is invalid + // - pointPatches pointed to be fld are invalid + + typename GeometricField:: + Boundary& bfld = fld.boundaryFieldRef(); + + // Internal field + // ~~~~~~~~~~~~~~ + + // Store old internal field + { + Field oldField(fld); + + // Modify internal field + Field& intFld = fld.primitiveFieldRef(); + + intFld.setSize(mesh.size()); + + intFld.rmap(oldField, meshMap.oldPointMap()); + intFld.rmap(fldToAdd, meshMap.addedPointMap()); + } + + + // Patch fields from old mesh + // ~~~~~~~~~~~~~~~~~~~~~~~~~~ + + { + const labelList& oldPatchMap = meshMap.oldPatchMap(); + + // Reorder old patches in order of new ones. Put removed patches at end. + + label unusedPatchi = 0; + + forAll(oldPatchMap, patchi) + { + label newPatchi = oldPatchMap[patchi]; + + if (newPatchi != -1) + { + unusedPatchi++; + } + } + + label nUsedPatches = unusedPatchi; + + // Reorder list for patchFields + labelList oldToNew(oldPatchMap.size()); + + forAll(oldPatchMap, patchi) + { + label newPatchi = oldPatchMap[patchi]; + + if (newPatchi != -1) + { + oldToNew[patchi] = newPatchi; + } + else + { + oldToNew[patchi] = unusedPatchi++; + } + } + + + // Sort deleted ones last so is now in newPatch ordering + bfld.reorder(oldToNew); + // Extend to covers all patches + bfld.setSize(mesh.boundary().size()); + // Delete unused patches + for + ( + label newPatchi = nUsedPatches; + newPatchi < bfld.size(); + newPatchi++ + ) + { + bfld.set(newPatchi, nullptr); + } + + + // Map old values + // ~~~~~~~~~~~~~~ + + forAll(oldPatchMap, patchi) + { + label newPatchi = oldPatchMap[patchi]; + + if (newPatchi != -1) + { + const labelList& oldMp = oldMeshPoints[patchi]; + const pointPatch& newPp = mesh.boundary()[newPatchi]; + const labelList& newMeshPoints = newPp.meshPoints(); + Map