diff --git a/applications/utilities/preProcessing/PDR/pdrFields/obstacles/PDRobstacle.C b/applications/utilities/preProcessing/PDR/pdrFields/obstacles/PDRobstacle.C index 1625ad1d3f..7c4e663b08 100644 --- a/applications/utilities/preProcessing/PDR/pdrFields/obstacles/PDRobstacle.C +++ b/applications/utilities/preProcessing/PDR/pdrFields/obstacles/PDRobstacle.C @@ -629,12 +629,10 @@ void Foam::PDRobstacle::generateVtk { label pieceId = 0; - meshedSurf::emptySurface dummy; - vtk::surfaceWriter surfWriter ( - dummy.points(), - dummy.faces(), + pointField::null(), + faceList::null(), // vtk::formatType::INLINE_ASCII, (outputDir / "Obstacles"), false // serial only diff --git a/src/mesh/blockMesh/blockMesh/blockMesh.C b/src/mesh/blockMesh/blockMesh/blockMesh.C index 6894f89033..1393271291 100644 --- a/src/mesh/blockMesh/blockMesh/blockMesh.C +++ b/src/mesh/blockMesh/blockMesh/blockMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -147,41 +147,21 @@ bool Foam::blockMesh::readPointTransforms(const dictionary& dict) { transformType_ = transformTypes::NO_TRANSFORM; + const dictionary* dictptr; + // Optional cartesian coordinate system transform, since JUL-2021 - if (const dictionary* dictptr = dict.findDict("transform")) + if ((dictptr = dict.findDict("transform", keyType::LITERAL)) != nullptr) { transform_ = coordSystem::cartesian(*dictptr); - constexpr scalar tol = VSMALL; - - // Check for non-zero origin - const vector& o = transform_.origin(); - if - ( - (mag(o.x()) > tol) - || (mag(o.y()) > tol) - || (mag(o.z()) > tol) - ) + // Non-zero origin? + if (magSqr(transform_.origin()) > ROOTVSMALL) { transformType_ |= transformTypes::TRANSLATION; } - // Check for non-identity rotation - const tensor& r = transform_.R(); - if - ( - (mag(r.xx() - 1) > tol) - || (mag(r.xy()) > tol) - || (mag(r.xz()) > tol) - - || (mag(r.yx()) > tol) - || (mag(r.yy() - 1) > tol) - || (mag(r.yz()) > tol) - - || (mag(r.zx()) > tol) - || (mag(r.zy()) > tol) - || (mag(r.zz() - 1) > tol) - ) + // Non-identity rotation? + if (!transform_.R().is_identity(ROOTVSMALL)) { transformType_ |= transformTypes::ROTATION; } diff --git a/src/sampling/surface/isoSurface/isoSurfacePoint.C b/src/sampling/surface/isoSurface/isoSurfacePoint.C index 514dddf753..caae144e79 100644 --- a/src/sampling/surface/isoSurface/isoSurfacePoint.C +++ b/src/sampling/surface/isoSurface/isoSurfacePoint.C @@ -105,21 +105,6 @@ static bool isCollocatedPatch(const coupledPolyPatch& pp) // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -bool Foam::isoSurfacePoint::noTransform(const tensor& tt) const -{ - return - (mag(tt.xx()-1) < mergeDistance_) - && (mag(tt.yy()-1) < mergeDistance_) - && (mag(tt.zz()-1) < mergeDistance_) - && (mag(tt.xy()) < mergeDistance_) - && (mag(tt.xz()) < mergeDistance_) - && (mag(tt.yx()) < mergeDistance_) - && (mag(tt.yz()) < mergeDistance_) - && (mag(tt.zx()) < mergeDistance_) - && (mag(tt.zy()) < mergeDistance_); -} - - Foam::bitSet Foam::isoSurfacePoint::collocatedFaces ( const coupledPolyPatch& pp diff --git a/src/sampling/surface/isoSurface/isoSurfacePoint.H b/src/sampling/surface/isoSurface/isoSurfacePoint.H index 571e5d96cf..c11241d228 100644 --- a/src/sampling/surface/isoSurface/isoSurfacePoint.H +++ b/src/sampling/surface/isoSurface/isoSurfacePoint.H @@ -124,9 +124,6 @@ class isoSurfacePoint // Point synchronisation - //- Does tensor differ (to within mergeTolerance) from identity - bool noTransform(const tensor& tt) const; - //- Per face whether is collocated static bitSet collocatedFaces(const coupledPolyPatch& cpp); diff --git a/src/surfMesh/meshedSurf/meshedSurf.H b/src/surfMesh/meshedSurf/meshedSurf.H index 6933b5eed2..626239a6c8 100644 --- a/src/surfMesh/meshedSurf/meshedSurf.H +++ b/src/surfMesh/meshedSurf/meshedSurf.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -31,8 +31,8 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef meshedSurf_H -#define meshedSurf_H +#ifndef Foam_meshedSurf_H +#define Foam_meshedSurf_H #include "pointField.H" #include "faceList.H" @@ -51,7 +51,7 @@ class meshedSurf { public: - // Forward declarations + // Forward Declarations class emptySurface; diff --git a/src/surfMesh/meshedSurf/meshedSurfRef.H b/src/surfMesh/meshedSurf/meshedSurfRef.H index c52d35363b..a9c8a007ae 100644 --- a/src/surfMesh/meshedSurf/meshedSurfRef.H +++ b/src/surfMesh/meshedSurf/meshedSurfRef.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,14 +27,19 @@ Class Foam::meshedSurfRef Description - Implements a meshed surface by referencing existing faces and points. + Implements a meshed surface by referencing another meshed surface + or faces/points components. + + In addition to the referencing, supports simple moving/scaling + of points (uses a deep-copy). \*---------------------------------------------------------------------------*/ -#ifndef meshedSurfRef_H -#define meshedSurfRef_H +#ifndef Foam_meshedSurfRef_H +#define Foam_meshedSurfRef_H #include "meshedSurf.H" +#include "refPtr.H" #include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -50,10 +55,19 @@ class meshedSurfRef : public meshedSurf { - std::reference_wrapper points_; - std::reference_wrapper faces_; - std::reference_wrapper zoneIds_; - std::reference_wrapper faceIds_; + // Private Data + + //- An external surface reference + refPtr surf_; + + //- Components + std::reference_wrapper points_; + std::reference_wrapper faces_; + std::reference_wrapper zoneIds_; + std::reference_wrapper faceIds_; + + //- Locations of moved/scaled points (if any) + pointField newPoints_; public: @@ -69,20 +83,27 @@ public: faceIds_(std::cref(labelList::null())) {} + //- Construct as reference to a meshedSurf + explicit meshedSurfRef(const meshedSurf& s) + : + meshedSurfRef() + { + surf_.cref(s); + } //- Construct from components meshedSurfRef ( - const pointField& pointLst, - const faceList& faceLst, - const labelList& zoneIdLst = labelList::null(), - const labelList& faceIdLst = labelList::null() + const pointField& points, + const faceList& faces, + const labelList& zoneIds = labelList::null(), + const labelList& faceIds = labelList::null() ) : - points_(std::cref(pointLst)), - faces_(std::cref(faceLst)), - zoneIds_(std::cref(zoneIdLst)), - faceIds_(std::cref(faceIdLst)) + points_(std::cref(points)), + faces_(std::cref(faces)), + zoneIds_(std::cref(zoneIds)), + faceIds_(std::cref(faceIds)) {} @@ -92,52 +113,112 @@ public: // Member Functions + //- Contains a valid reference? + bool valid() const + { + return (surf_ || notNull(points_.get())); + } + + //- The original points used for the surface + const pointField& points0() const + { + return (surf_ ? surf_.cref().points() : points_.get()); + } + //- The points used for the surface virtual const pointField& points() const { - return points_.get(); + return (newPoints_.empty() ? points0() : newPoints_); } //- The faces used for the surface virtual const faceList& faces() const { - return faces_.get(); + return (surf_ ? surf_.cref().faces() : faces_.get()); } - //- Per-face zone/region information. + //- Per-face zone/region information virtual const labelList& zoneIds() const { - return zoneIds_.get(); + return (surf_ ? surf_.cref().zoneIds() : zoneIds_.get()); } //- Per-face identifier (eg, element Id) virtual const labelList& faceIds() const { - return faceIds_.get(); + return (surf_ ? surf_.cref().faceIds() : faceIds_.get()); } - //- Remove all references by redirecting to null objects + //- Invalid by redirecting to null objects void clear() { + surf_.reset(); points_ = std::cref(pointField::null()); faces_ = std::cref(faceList::null()); zoneIds_ = std::cref(labelList::null()); faceIds_ = std::cref(labelList::null()); + newPoints_.clear(); + } + + //- Reset surface + void reset(const meshedSurf& s) + { + clear(); + surf_.cref(s); } //- Reset components void reset ( - const pointField& pointLst, - const faceList& faceLst, - const labelList& zoneIdLst = labelList::null(), - const labelList& faceIdLst = labelList::null() + const pointField& points, + const faceList& faces, + const labelList& zoneIds = labelList::null(), + const labelList& faceIds = labelList::null() ) { - points_ = std::cref(pointLst); - faces_ = std::cref(faceLst); - zoneIds_ = std::cref(zoneIdLst); - faceIds_ = std::cref(faceIdLst); + surf_.reset(); + points_ = std::cref(points); + faces_ = std::cref(faces); + zoneIds_ = std::cref(zoneIds); + faceIds_ = std::cref(faceIds); + newPoints_.clear(); + } + + + //- Reset changes in point positions + void resetPoints() + { + newPoints_.clear(); + } + + //- Change point positions + void movePoints(pointField&& pts) + { + newPoints_.transfer(pts); + } + + //- Change point positions + void movePoints(const tmp& tpts) + { + newPoints_.clear(); + if (tpts) + { + newPoints_ = tpts; + } + tpts.clear(); + } + + //- Scale points: ignore unity and non-positive factors + void scalePoints(const scalar scaleFactor) + { + if (scaleFactor > SMALL && !equal(scaleFactor, 1)) + { + if (newPoints_.empty()) + { + newPoints_ = points0(); + } + newPoints_ *= scaleFactor; + } } };