diff --git a/src/OpenFOAM/containers/Lists/ListOps/ListOps.H b/src/OpenFOAM/containers/Lists/ListOps/ListOps.H index 1ac082a857..78efbc82ec 100644 --- a/src/OpenFOAM/containers/Lists/ListOps/ListOps.H +++ b/src/OpenFOAM/containers/Lists/ListOps/ListOps.H @@ -217,6 +217,10 @@ void uniqueOrder ); +//- Return sorted list with removal of duplicates +template +List uniqueSort(const UList& input); + //- Inplace sorting and removal of duplicates. // Do not use FixedList for the input list, since it doesn't resize. template diff --git a/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C b/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C index 0b4885f957..bcdeb8ea18 100644 --- a/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C +++ b/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C @@ -424,6 +424,33 @@ void Foam::uniqueOrder } +template +Foam::List Foam::uniqueSort(const UList& input) +{ + List output(input); + + const label len = output.size(); + + if (len > 1) + { + Foam::stableSort(output); + + label count = 0; + for (label i = 1; i < len; ++i) + { + if (output[count] != output[i]) + { + output[++count] = output[i]; + } + } + + output.resize(count+1); + } + + return output; +} + + template void Foam::inplaceUniqueSort(ListType& input) { diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.C b/src/OpenFOAM/meshes/polyMesh/polyMesh.C index f9e96254f1..466c82fde1 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.C @@ -1156,10 +1156,7 @@ const Foam::pointField& Foam::polyMesh::oldCellCentres() const } -Foam::tmp Foam::polyMesh::movePoints -( - const pointField& newPoints -) +void Foam::polyMesh::movePoints(const pointField& newPoints) { DebugInFunction << "Moving points for time " << time().value() @@ -1227,11 +1224,17 @@ Foam::tmp Foam::polyMesh::movePoints tetBasePtIsPtr_->eventNo() = getEvent(); } - tmp sweptVols = primitiveMesh::movePoints - ( - points_, - oldPoints() - ); + // Currently a no-op; earlier versions set meshPhi and call + // primitiveMesh::clearGeom + (void)primitiveMesh::movePoints(points_, oldPoints()); + + // Update the mesh geometry (via fvGeometryScheme) + // - updateGeom is virtual -> calls fvMesh::updateGeom (or higher) + // - fvMesh::updateGeom defers to surfaceInterpolation::updateGeom(), + // which defers to fvGeometryScheme::movePoints() + // - set the mesh flux + // - clear out/recalculate stale geometry + updateGeom(); // Adjust parallel shared points if (globalMeshDataPtr_) @@ -1279,8 +1282,6 @@ Foam::tmp Foam::polyMesh::movePoints // e.g. fvMesh::write since meshPhi not yet complete. polyMesh::write(); } - - return sweptVols; } diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.H b/src/OpenFOAM/meshes/polyMesh/polyMesh.H index ac41ac9625..b5512d75fb 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.H @@ -556,8 +556,8 @@ public: return (moving() || topoChanging()); } - //- Move points, returns volumes swept by faces in motion - virtual tmp movePoints(const pointField&); + //- Move points + virtual void movePoints(const pointField&); //- Reset motion void resetMotion() const; diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.C index 997a8113bd..a680acbc8a 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -136,7 +137,7 @@ bool Foam::primitiveMesh::calcPointOrder // Internal points are points that are not used by a boundary face. // Map from old to new position - oldToNew.setSize(nPoints); + oldToNew.resize_nocopy(nPoints); oldToNew = -1; @@ -144,14 +145,12 @@ bool Foam::primitiveMesh::calcPointOrder // from 0 inside oldToNew. (shifted up later on) label nBoundaryPoints = 0; - for (label facei = nInternalFaces; facei < faces.size(); facei++) + for (label facei = nInternalFaces; facei < faces.size(); ++facei) { const face& f = faces[facei]; - forAll(f, fp) + for (label pointi : f) { - label pointi = f[fp]; - if (oldToNew[pointi] == -1) { oldToNew[pointi] = nBoundaryPoints++; @@ -184,10 +183,8 @@ bool Foam::primitiveMesh::calcPointOrder { const face& f = faces[facei]; - forAll(f, fp) + for (label pointi : f) { - label pointi = f[fp]; - if (oldToNew[pointi] == -1) { if (pointi >= nInternalPoints) @@ -318,35 +315,17 @@ void Foam::primitiveMesh::resetGeometry } -Foam::tmp Foam::primitiveMesh::movePoints +void Foam::primitiveMesh::movePoints ( const pointField& newPoints, const pointField& oldPoints ) { - if (newPoints.size() < nPoints() || oldPoints.size() < nPoints()) - { - FatalErrorInFunction - << "Cannot move points: size of given point list smaller " - << "than the number of active points" - << abort(FatalError); - } - - // Create swept volumes - const faceList& fcs = faces(); - - auto tsweptVols = tmp::New(fcs.size()); - auto& sweptVols = tsweptVols.ref(); - - forAll(fcs, facei) - { - sweptVols[facei] = fcs[facei].sweptVol(oldPoints, newPoints); - } + // Note: the following clearout is now handled by the fvGeometryScheme + // triggered by the call to updateGeom() in polyMesh::movePoints // Force recalculation of all geometric data with new points - clearGeom(); - - return tsweptVols; + //clearGeom(); } @@ -361,7 +340,6 @@ const Foam::cellShapeList& Foam::primitiveMesh::cellShapes() const } - void Foam::primitiveMesh::updateGeom() { if (!faceCentresPtr_ || !faceAreasPtr_) diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.H b/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.H index 5bcda5e24d..b369cdc68b 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.H +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -598,8 +598,8 @@ public: // Mesh motion - //- Move points, returns volumes swept by faces in motion - tmp movePoints + //- Move points + void movePoints ( const pointField& p, const pointField& oldP diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellCentresAndVols.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellCentresAndVols.C index 71eb30e7b9..56c83e4306 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellCentresAndVols.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellCentresAndVols.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -52,11 +53,11 @@ void Foam::primitiveMesh::calcCellCentresAndVols() const } // set the accumulated cell centre to zero vector - cellCentresPtr_ = new vectorField(nCells()); + cellCentresPtr_ = new vectorField(nCells(), Zero); vectorField& cellCtrs = *cellCentresPtr_; // Initialise cell volumes to 0 - cellVolumesPtr_ = new scalarField(nCells()); + cellVolumesPtr_ = new scalarField(nCells(), Zero); scalarField& cellVols = *cellVolumesPtr_; // Make centres and volumes diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshTools.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshTools.C index c2e5d1cdd8..a5f93524bf 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshTools.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshTools.C @@ -34,6 +34,172 @@ License // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // +void Foam::primitiveMeshTools::updateFaceCentresAndAreas +( + const primitiveMesh& mesh, + const UList