diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.H b/src/OpenFOAM/meshes/polyMesh/polyMesh.H index 46210bb085..b9968d7b4f 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017, 2020 OpenFOAM Foundation - Copyright (C) 2018-2022 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -454,13 +454,13 @@ public: virtual const pointField& oldCellCentres() const; //- Return boundary mesh - const polyBoundaryMesh& boundaryMesh() const + const polyBoundaryMesh& boundaryMesh() const noexcept { return boundary_; } //- Return mesh bounding box - const boundBox& bounds() const + const boundBox& bounds() const noexcept { return bounds_; } diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C index 081c7d0f83..4cb3d72089 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C @@ -307,13 +307,14 @@ Foam::wordList Foam::polyPatch::constraintTypes() } -Foam::label Foam::polyPatch::offset() const +Foam::label Foam::polyPatch::offset() const noexcept { - return start_ - boundaryMesh().start(); + // Same as start_ - polyMesh::nInternalFaces() + return start_ - boundaryMesh_.start(); } -const Foam::polyBoundaryMesh& Foam::polyPatch::boundaryMesh() const +const Foam::polyBoundaryMesh& Foam::polyPatch::boundaryMesh() const noexcept { return boundaryMesh_; } diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H index 5d2d148128..42104698df 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2015-2020 OpenCFD Ltd. + Copyright (C) 2015-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -359,10 +359,10 @@ public: //- The offset where this patch starts in the boundary face list // The value is the same as patch.start() - mesh.nInternalFaces() - label offset() const; + label offset() const noexcept; //- Return start label of this patch in the polyMesh face list - label start() const + label start() const noexcept { return start_; } @@ -374,7 +374,7 @@ public: } //- Return boundaryMesh reference - const polyBoundaryMesh& boundaryMesh() const; + const polyBoundaryMesh& boundaryMesh() const noexcept; //- Return true if this patch is geometrically coupled (i.e. faces and // points correspondence) @@ -399,18 +399,30 @@ public: return UIndirectList(internalValues, faceCells()); } - //- Slice List to patch, using the number of patch faces + //- This patch slice from the complete list, which has size + //- mesh::nFaces(), using the number of patch faces. template - const typename List::subList patchSlice(const UList& l) const + const typename List::subList + patchSlice(const UList& values) const { - return typename List::subList(l, this->size(), start_); + return typename List::subList(values, this->size(), start_); } - //- Slice Field to patch, using the number of patch faces + //- This patch slice from the list of boundary values, which has size + //- mesh::nBoundaryFaces(), using the number of patch faces. template - const typename Field::subField patchSlice(const Field& l) const + const typename List::subList + boundarySlice(const List& values) const { - return typename Field::subField(l, this->size(), start_); + return typename List::subList(values, this->size(), offset()); + } + + //- Slice Field to patch, using the number of patch faces. + template + const typename Field::subField + patchSlice(const Field& values) const + { + return typename Field::subField(values, this->size(), start_); } diff --git a/src/finiteArea/faMesh/faPatches/faPatch/faPatch.C b/src/finiteArea/faMesh/faPatches/faPatch/faPatch.C index 8aeca30837..578c943b59 100644 --- a/src/finiteArea/faMesh/faPatches/faPatch/faPatch.C +++ b/src/finiteArea/faMesh/faPatches/faPatch/faPatch.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016-2017 Wikki Ltd - Copyright (C) 2019-2022 OpenCFD Ltd. + Copyright (C) 2019-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -194,6 +194,17 @@ const Foam::faBoundaryMesh& Foam::faPatch::boundaryMesh() const noexcept } +Foam::label Foam::faPatch::offset() const +{ + return max + ( + 0, + boundaryMesh().mesh().patchStarts()[index()] + - boundaryMesh().mesh().nInternalEdges() + ); +} + + Foam::label Foam::faPatch::start() const { return boundaryMesh().mesh().patchStarts()[index()]; diff --git a/src/finiteArea/faMesh/faPatches/faPatch/faPatch.H b/src/finiteArea/faMesh/faPatches/faPatch/faPatch.H index 625b940cce..ae8670da53 100644 --- a/src/finiteArea/faMesh/faPatches/faPatch/faPatch.H +++ b/src/finiteArea/faMesh/faPatches/faPatch/faPatch.H @@ -305,6 +305,10 @@ public: return false; } + //- The offset where this patch starts in the boundary edge list. + // The value is the same as patch.start() - mesh.nInternalEdges() + label offset() const; + //- Patch start in edge list label start() const; @@ -320,18 +324,26 @@ public: return edgei - start(); } - //- Slice List to patch, using the virtual patch size + //- This patch slice from the complete list of values, which has + //- size mesh::nEdges(), using the virtual patch size. template - typename List::subList patchSlice(const List& l) const + const typename List::subList patchSlice(const List& values) const { - return typename List::subList(l, size(), start()); + return typename List::subList(values, size(), start()); } - //- Slice List to patch, using the number of patch edges + //- This patch slice from the list of boundary values, which has + //- size mesh::nBoundaryEdges(), using the virtual patch size. template - typename List::subList patchRawSlice(const List& l) const + const typename List::subList + boundarySlice(const List& values) const { - return typename List::subList(l, nEdges(), start()); + return typename List::subList + ( + values, + size(), + offset() + ); } diff --git a/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.C index 5a2d5ba0d1..f444464af0 100644 --- a/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -35,13 +35,22 @@ Foam::slicedFvPatchField::slicedFvPatchField ( const fvPatch& p, const DimensionedField& iF, - const Field& completeField + const Field& completeOrBoundaryField, + const bool isBoundaryOnly ) : fvPatchField(p, iF, Field()) { - // Set fvPatchField to a slice of the given complete field - UList::shallowCopy(p.patchSlice(completeField)); + if (isBoundaryOnly) + { + // Set to a slice of the boundary field + UList::shallowCopy(p.boundarySlice(completeOrBoundaryField)); + } + else + { + // Set to a slice of the complete field + UList::shallowCopy(p.patchSlice(completeOrBoundaryField)); + } } @@ -64,8 +73,11 @@ Foam::slicedFvPatchField::slicedFvPatchField const dictionary& dict ) : - fvPatchField(p, iF, dict, false) + fvPatchField(p, iF) // bypass dictionary constructor { + fvPatchFieldBase::readDict(dict); + // Read "value" if present... + NotImplemented; } @@ -142,10 +154,12 @@ Foam::slicedFvPatchField::clone } +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + template Foam::slicedFvPatchField::~slicedFvPatchField() { - // Set fvPatchField to nullptr to avoid deletion of underlying field + // Set to nullptr to avoid deletion of underlying field UList::shallowCopy(UList()); } diff --git a/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.H index 32c8fe3811..8d1d515251 100644 --- a/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2017 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -47,10 +47,11 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef slicedFvPatchField_H -#define slicedFvPatchField_H +#ifndef Foam_slicedFvPatchField_H +#define Foam_slicedFvPatchField_H #include "fvPatchField.H" +#include "processorFvPatch.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -58,7 +59,7 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class slicedFvPatch Declaration + Class slicedFvPatchField Declaration \*---------------------------------------------------------------------------*/ template @@ -66,9 +67,12 @@ class slicedFvPatchField : public fvPatchField { - public: + //- The mesh processor patch type + typedef processorFvPatch processorPatchType; + + //- Runtime type information TypeName("sliced"); @@ -80,7 +84,8 @@ public: ( const fvPatch&, const DimensionedField&, - const Field& + const Field& completeOrBoundaryField, + const bool isBoundaryOnly = false ); //- Construct from patch and internal field. Assign value later. diff --git a/src/finiteVolume/fields/fvsPatchFields/basic/sliced/slicedFvsPatchField.C b/src/finiteVolume/fields/fvsPatchFields/basic/sliced/slicedFvsPatchField.C index 86d682c5a5..239814c185 100644 --- a/src/finiteVolume/fields/fvsPatchFields/basic/sliced/slicedFvsPatchField.C +++ b/src/finiteVolume/fields/fvsPatchFields/basic/sliced/slicedFvsPatchField.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -34,13 +35,22 @@ Foam::slicedFvsPatchField::slicedFvsPatchField ( const fvPatch& p, const DimensionedField& iF, - const Field& completeField + const Field& completeOrBoundaryField, + const bool isBoundaryOnly ) : fvsPatchField(p, iF, Field()) { - // Set fvsPatchField to a slice of the given complete field - UList::shallowCopy(p.patchSlice(completeField)); + if (isBoundaryOnly) + { + // Set to a slice of the boundary field + UList::shallowCopy(p.boundarySlice(completeOrBoundaryField)); + } + else + { + // Set to a slice of the complete field + UList::shallowCopy(p.patchSlice(completeOrBoundaryField)); + } } @@ -63,8 +73,11 @@ Foam::slicedFvsPatchField::slicedFvsPatchField const dictionary& dict ) : - fvsPatchField(p, iF, Field("value", dict, p.size())) + fvsPatchField(p, iF) // bypass dictionary constructor { + fvsPatchFieldBase::readDict(dict); + // Read "value" if present... + NotImplemented; } @@ -141,10 +154,12 @@ Foam::slicedFvsPatchField::clone } +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + template Foam::slicedFvsPatchField::~slicedFvsPatchField() { - // Set fvsPatchField to nullptr to avoid deletion of underlying field + // Set to nullptr to avoid deletion of underlying field UList::shallowCopy(UList()); } diff --git a/src/finiteVolume/fields/fvsPatchFields/basic/sliced/slicedFvsPatchField.H b/src/finiteVolume/fields/fvsPatchFields/basic/sliced/slicedFvsPatchField.H index 28a7f95313..1f185b83f4 100644 --- a/src/finiteVolume/fields/fvsPatchFields/basic/sliced/slicedFvsPatchField.H +++ b/src/finiteVolume/fields/fvsPatchFields/basic/sliced/slicedFvsPatchField.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,10 +41,11 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef slicedFvsPatchField_H -#define slicedFvsPatchField_H +#ifndef Foam_slicedFvsPatchField_H +#define Foam_slicedFvsPatchField_H #include "fvsPatchField.H" +#include "processorFvPatch.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -51,7 +53,7 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class slicedFvsPatch Declaration + Class slicedFvsPatchField Declaration \*---------------------------------------------------------------------------*/ template @@ -59,9 +61,12 @@ class slicedFvsPatchField : public fvsPatchField { - public: + //- The mesh processor patch type + typedef processorFvPatch processorPatchType; + + //- Runtime type information TypeName("sliced"); @@ -73,7 +78,8 @@ public: ( const fvPatch&, const DimensionedField&, - const Field& + const Field& completeOrBoundaryField, + const bool isBoundaryOnly = false ); //- Construct from patch and internal field diff --git a/src/finiteVolume/fvMesh/fvMesh.C b/src/finiteVolume/fvMesh/fvMesh.C index b5a79252a4..655b870a50 100644 --- a/src/finiteVolume/fvMesh/fvMesh.C +++ b/src/finiteVolume/fvMesh/fvMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017,2022 OpenFOAM Foundation - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -201,7 +201,7 @@ void Foam::fvMesh::storeOldVol(const scalarField& V) scalarField& V0 = *V0Ptr_; // Note: V0 now sized with current mesh, not with (potentially // different size) V. - V0.setSize(V.size()); + V0.resize_nocopy(V.size()); V0 = V; } @@ -665,7 +665,6 @@ void Foam::fvMesh::removeFvBoundary() // Remove fvBoundaryMesh data first. boundary_.clear(); - boundary_.setSize(0); polyMesh::removeBoundary(); clearOut(); @@ -709,12 +708,6 @@ Foam::polyMesh::readUpdateState Foam::fvMesh::readUpdate() } -const Foam::fvBoundaryMesh& Foam::fvMesh::boundary() const -{ - return boundary_; -} - - const Foam::lduAddressing& Foam::fvMesh::lduAddr() const { if (!lduPtr_) @@ -814,7 +807,7 @@ void Foam::fvMesh::mapFields(const mapPolyMesh& meshMap) scalarField& V0 = *V0Ptr_; scalarField savedV0(V0); - V0.setSize(nCells()); + V0.resize_nocopy(nCells()); forAll(V0, i) { @@ -856,7 +849,7 @@ void Foam::fvMesh::mapFields(const mapPolyMesh& meshMap) scalarField& V00 = *V00Ptr_; scalarField savedV00(V00); - V00.setSize(nCells()); + V00.resize_nocopy(nCells()); forAll(V00, i) { diff --git a/src/finiteVolume/fvMesh/fvMesh.H b/src/finiteVolume/fvMesh/fvMesh.H index aa8d6f494c..4b76ea8515 100644 --- a/src/finiteVolume/fvMesh/fvMesh.H +++ b/src/finiteVolume/fvMesh/fvMesh.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017,2022 OpenFOAM Foundation - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -97,6 +97,7 @@ protected: //- Boundary mesh fvBoundaryMesh boundary_; + // Demand-driven data mutable fvMeshLduAddressing* lduPtr_; @@ -314,7 +315,10 @@ public: } //- Return reference to boundary mesh - const fvBoundaryMesh& boundary() const; + const fvBoundaryMesh& boundary() const noexcept + { + return boundary_; + } //- Return ldu addressing virtual const lduAddressing& lduAddr() const; diff --git a/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H b/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H index b787c0e920..537eec7c9c 100644 --- a/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H +++ b/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H @@ -166,78 +166,79 @@ public: // Access - //- Return the polyPatch - const polyPatch& patch() const noexcept - { - return polyPatch_; - } + //- Return the polyPatch + const polyPatch& patch() const noexcept + { + return polyPatch_; + } - //- Return name - virtual const word& name() const - { - return polyPatch_.name(); - } + //- Return name + virtual const word& name() const + { + return polyPatch_.name(); + } - //- Return start label of this patch in the polyMesh face list - virtual label start() const - { - return polyPatch_.start(); - } + //- The index of this patch in the boundary mesh + label index() const noexcept + { + return polyPatch_.index(); + } - //- Return size - virtual label size() const - { - return polyPatch_.size(); - } + //- The patch start within the polyMesh face list + label start() const noexcept + { + return polyPatch_.start(); + } - //- Return true if this patch is coupled - virtual bool coupled() const - { - return polyPatch_.coupled(); - } + //- Patch size is the number of faces, but can be overloaded + virtual label size() const + { + return polyPatch_.size(); + } - //- Return true if the given type is a constraint type - static bool constraintType(const word& patchType); + //- Return true if this patch is coupled + virtual bool coupled() const + { + return polyPatch_.coupled(); + } - //- Return a list of all the constraint patch types - static wordList constraintTypes(); + //- Return true if the given type is a constraint type + static bool constraintType(const word& patchType); - //- Return the index of this patch in the fvBoundaryMesh - label index() const noexcept - { - return polyPatch_.index(); - } + //- Return a list of all the constraint patch types + static wordList constraintTypes(); - //- Return boundaryMesh reference - const fvBoundaryMesh& boundaryMesh() const noexcept - { - return boundaryMesh_; - } + //- Return boundaryMesh reference + const fvBoundaryMesh& boundaryMesh() const noexcept + { + return boundaryMesh_; + } - //- Slice List to patch, using the virtual patch size - template - const typename List::subList patchSlice(const List& l) const - { - return typename List::subList(l, size(), start()); - } + //- This patch slice from the complete list, which has size + //- mesh::nFaces(), using the virtual patch size. + template + const typename List::subList + patchSlice(const List& values) const + { + return typename List::subList(values, size(), start()); + } - //- Slice List to patch, using the underlying polyPatch information - template - const typename List::subList patchRawSlice + //- This patch slice from the list of boundary values, which has size + //- mesh::nBoundaryFaces(), using the virtual patch size. + template + const typename List::subList + boundarySlice(const List& values) const + { + return typename List::subList ( - const List& l - ) const - { - return typename List::subList - ( - l, - polyPatch_.size(), - polyPatch_.start() - ); - } + values, + size(), + polyPatch_.offset() + ); + } - //- Return faceCells - virtual const labelUList& faceCells() const; + //- Return faceCells + virtual const labelUList& faceCells() const; // Access functions for geometrical data