diff --git a/src/OpenFOAM/fields/pointPatchFields/constraint/processorCyclic/processorCyclicPointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/constraint/processorCyclic/processorCyclicPointPatchField.C index 554b8a4685717030a699f591fd24171d47d03063..522df9ac77c39139258f3276d2d7169499b73599 100644 --- a/src/OpenFOAM/fields/pointPatchFields/constraint/processorCyclic/processorCyclicPointPatchField.C +++ b/src/OpenFOAM/fields/pointPatchFields/constraint/processorCyclic/processorCyclicPointPatchField.C @@ -98,6 +98,10 @@ void Foam::processorCyclicPointPatchField<Type>::initSwapAddSeparated // Get internal field into correct order for opposite side. Note use // of member data buffer since using non-blocking. Could be optimised // out if not using non-blocking... + + sendBuf_.resize_nocopy(this->size()); // <- presize buffer + recvBuf_.resize_nocopy(this->size()); + this->patchInternalField ( pField, @@ -107,8 +111,6 @@ void Foam::processorCyclicPointPatchField<Type>::initSwapAddSeparated if (commsType == Pstream::commsTypes::nonBlocking) { - recvBuf_.resize_nocopy(sendBuf_.size()); - UIPstream::read ( commsType, @@ -118,6 +120,7 @@ void Foam::processorCyclicPointPatchField<Type>::initSwapAddSeparated procPatch_.comm() ); } + UOPstream::write ( commsType, @@ -143,7 +146,8 @@ void Foam::processorCyclicPointPatchField<Type>::swapAddSeparated if (commsType != Pstream::commsTypes::nonBlocking) { - recvBuf_.resize_nocopy(this->size()); + recvBuf_.resize_nocopy(this->size()); // In general a no-op + UIPstream::read ( commsType, @@ -156,8 +160,7 @@ void Foam::processorCyclicPointPatchField<Type>::swapAddSeparated if (doTransform()) { - const processorCyclicPolyPatch& ppp = - procPatch_.procCyclicPolyPatch(); + const auto& ppp = procPatch_.procCyclicPolyPatch(); const tensor& forwardT = ppp.forwardT()[0]; transform(recvBuf_, forwardT, recvBuf_); diff --git a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.C index ad66d1aca7a5ad312fddfe554e14061916d3bbd2..dca617651a722b8d8bd99df44349b2e438c1e6a4 100644 --- a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.C +++ b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.C @@ -114,11 +114,10 @@ void Foam::pointPatchField<Type>::patchInternalField ( const UList<Type1>& internalData, const labelUList& addressing, - Field<Type1>& pfld + UList<Type1>& pfld ) const { - // Check size - if (internalData.size() != primitiveField().size()) + if (FOAM_UNLIKELY(internalData.size() != primitiveField().size())) { FatalErrorInFunction << "Internal field size: " << internalData.size() @@ -126,9 +125,24 @@ void Foam::pointPatchField<Type>::patchInternalField << abort(FatalError); } - const label len = this->size(); + // For v2412 and earlier this was a field: + // const label len = this->size(); + // pfld.resize_nocopy(len); + // + // Now uses pre-sized storage - pfld.resize_nocopy(len); + const label len = pfld.size(); + + #ifdef FULLDEBUG + if (FOAM_UNLIKELY((addressing.size() < len) || (this->size() < len))) + { + FatalErrorInFunction + << "patchField size = " << len + << " but patch size = " << this->size() + << " and addressing size = " << addressing.size() << nl + << abort(FatalError); + } + #endif for (label i = 0; i < len; ++i) { @@ -182,8 +196,7 @@ void Foam::pointPatchField<Type>::addToInternalField const Field<Type1>& pF ) const { - // Check size - if (iF.size() != primitiveField().size()) + if (FOAM_UNLIKELY(iF.size() != primitiveField().size())) { FatalErrorInFunction << "Internal field size: " << iF.size() @@ -191,7 +204,7 @@ void Foam::pointPatchField<Type>::addToInternalField << abort(FatalError); } - if (pF.size() != size()) + if (FOAM_UNLIKELY(pF.size() != size())) { FatalErrorInFunction << "Patch field size: " << pF.size() @@ -218,8 +231,7 @@ void Foam::pointPatchField<Type>::addToInternalField const labelUList& points ) const { - // Check size - if (iF.size() != primitiveField().size()) + if (FOAM_UNLIKELY(iF.size() != primitiveField().size())) { FatalErrorInFunction << "Internal field size: " << iF.size() @@ -227,7 +239,7 @@ void Foam::pointPatchField<Type>::addToInternalField << abort(FatalError); } - if (pF.size() != size()) + if (FOAM_UNLIKELY(pF.size() != size())) { FatalErrorInFunction << "Patch field size: " << pF.size() @@ -255,8 +267,7 @@ void Foam::pointPatchField<Type>::setInInternalField const labelUList& meshPoints ) const { - // Check size - if (iF.size() != primitiveField().size()) + if (FOAM_UNLIKELY(iF.size() != primitiveField().size())) { FatalErrorInFunction << "Internal field size: " << iF.size() @@ -264,7 +275,7 @@ void Foam::pointPatchField<Type>::setInInternalField << abort(FatalError); } - if (pF.size() != meshPoints.size()) + if (FOAM_UNLIKELY(pF.size() != meshPoints.size())) { FatalErrorInFunction << "Patch field size: " << pF.size() diff --git a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.H b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.H index dea8560919ea6fb46086de81155e6972fb9d2c41..14487c013c5f9f0fffbc9decec9d8e29b712d694 100644 --- a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.H +++ b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2019-2024 OpenCFD Ltd. + Copyright (C) 2019-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -475,14 +475,14 @@ public: // \param internalData The internal field to extract from // \param addressing Addressing (mesh-points) into internal field // \param [out] pfld The extracted patch field. - // It is always resized according to the patch size(), + // Should normally be sized according to the patch size(), // which can be smaller than the addressing size template<class Type1> void patchInternalField ( const UList<Type1>& internalData, const labelUList& addressing, - Field<Type1>& pfld + UList<Type1>& pfld ) const; //- Return field created from selected internal field values @@ -490,7 +490,8 @@ public: // \param internalData The internal field to extract from // \param addressing Addressing (mesh-points) into internal field template<class Type1> - tmp<Field<Type1>> patchInternalField + [[nodiscard]] tmp<Field<Type1>> + patchInternalField ( const UList<Type1>& internalData, const labelUList& addressing @@ -499,7 +500,8 @@ public: //- Return field created from appropriate internal field values //- given internal field reference template<class Type1> - tmp<Field<Type1>> patchInternalField + [[nodiscard]] tmp<Field<Type1>> + patchInternalField ( const UList<Type1>& internalData ) const; diff --git a/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterface/lduCalculatedProcessorField/lduCalculatedProcessorField.C b/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterface/lduCalculatedProcessorField/lduCalculatedProcessorField.C index 2eba61fb8f8cb9fc5471215977fbac0b8af6e723..159174539eddfed51f49ba25626dfa99535db64b 100644 --- a/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterface/lduCalculatedProcessorField/lduCalculatedProcessorField.C +++ b/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterface/lduCalculatedProcessorField/lduCalculatedProcessorField.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2022-2023 OpenCFD Ltd. + Copyright (C) 2022-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -101,13 +101,15 @@ void Foam::lduCalculatedProcessorField<Type>::initInterfaceMatrixUpdate // Bypass patchInternalField since uses fvPatch addressing const labelUList& fc = lduAddr.patchAddr(patchId); - scalarSendBuf_.resize_nocopy(fc.size()); - forAll(fc, i) { - scalarSendBuf_[i] = psiInternal[fc[i]]; - } + scalarSendBuf_.resize_nocopy(fc.size()); + scalarRecvBuf_.resize_nocopy(fc.size()); - scalarRecvBuf_.resize_nocopy(scalarSendBuf_.size()); + forAll(fc, i) + { + scalarSendBuf_[i] = psiInternal[fc[i]]; + } + } recvRequest_ = UPstream::nRequests(); UIPstream::read diff --git a/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterface/lduCalculatedProcessorField/lduCalculatedProcessorField.H b/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterface/lduCalculatedProcessorField/lduCalculatedProcessorField.H index c9af9ec11d4f91e09c3fa25e8d0776855dc7d70f..b530486b81b7f9c2c8523ce68d6a3177ed40efbf 100644 --- a/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterface/lduCalculatedProcessorField/lduCalculatedProcessorField.H +++ b/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterface/lduCalculatedProcessorField/lduCalculatedProcessorField.H @@ -69,7 +69,7 @@ protected: // Protected Data //- Local reference cast into the interface - const lduPrimitiveProcessorInterface& procInterface_; + const lduPrimitiveProcessorInterface& procInterface_; // Sending and receiving diff --git a/src/finiteArea/faMesh/faPatches/faPatch/faPatch.H b/src/finiteArea/faMesh/faPatches/faPatch/faPatch.H index 6bb87df10f1aa728d102834c86975d934fd33bd1..bb897124aaa92d4df8cc391e2b1ac98695bb1721 100644 --- a/src/finiteArea/faMesh/faPatches/faPatch/faPatch.H +++ b/src/finiteArea/faMesh/faPatches/faPatch/faPatch.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016-2017 Wikki Ltd - Copyright (C) 2020-2023 OpenCFD Ltd. + Copyright (C) 2020-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -447,34 +447,35 @@ public: // \param internalData The internal field to extract from // \param addressing Addressing from patch into internal field // \param [out] pfld The extracted patch field. - // It is always resized according to the patch size(), + // Should normally be sized according to the patch size(), // which can be smaller than the addressing size template<class Type> inline void patchInternalField ( const UList<Type>& internalData, const labelUList& addressing, - Field<Type>& pfld + UList<Type>& pfld ) const; //- Extract internal field next to patch as patch field //- using edgeFaces() mapping. // \param internalData The internal field to extract from // \param [out] pfld The extracted patch field. - // It is always resized according to the patch size(), + // Should normally be sized according to the patch size(), // which can be smaller than the edgeFaces() size template<class Type> void patchInternalField ( const UList<Type>& internalData, - Field<Type>& pfld + UList<Type>& pfld ) const; //- Return given internal field next to patch as patch field //- using edgeFaces() mapping. // \param internalData The internal field to extract from template<class Type> - tmp<Field<Type>> patchInternalField + [[nodiscard]] tmp<Field<Type>> + patchInternalField ( const UList<Type>& internalData ) const; diff --git a/src/finiteArea/faMesh/faPatches/faPatch/faPatchTemplates.C b/src/finiteArea/faMesh/faPatches/faPatch/faPatchTemplates.C index e1ca5cbe8f0e6293e5e48f89a6ee0a2a46a634dc..9fd80efa921f36c771f667436096708e6ab97a71 100644 --- a/src/finiteArea/faMesh/faPatches/faPatch/faPatchTemplates.C +++ b/src/finiteArea/faMesh/faPatches/faPatch/faPatchTemplates.C @@ -35,12 +35,27 @@ void Foam::faPatch::patchInternalField ( const UList<Type>& internalData, const labelUList& addressing, - Field<Type>& pfld + UList<Type>& pfld ) const { - const label len = this->size(); + // For v2412 and earlier this was a field and was resized here: + // const label len = this->size(); + // pfld.resize_nocopy(len); + // + // Now uses pre-sized storage (note: behaves like a static method) - pfld.resize_nocopy(len); + const label len = pfld.size(); + + #ifdef FULLDEBUG + if (FOAM_UNLIKELY((addressing.size() < len) || (this->size() < len))) + { + FatalErrorInFunction + << "patchField size = " << len + << " but patch size = " << this->size() + << " and addressing size = " << addressing.size() << nl + << abort(FatalError); + } + #endif for (label i = 0; i < len; ++i) { @@ -53,10 +68,14 @@ template<class Type> void Foam::faPatch::patchInternalField ( const UList<Type>& internalData, - Field<Type>& pfld + UList<Type>& pfld ) const { - pfld.resize_nocopy(this->size()); // In general this is a no-op + // For v2412 and earlier this was a field and was resized here: + // pfld.resize_nocopy(this->size()); + // + // Now uses pre-sized storage + patchInternalField(internalData, this->edgeFaces(), pfld); } diff --git a/src/finiteArea/fields/faPatchFields/constraint/processor/processorFaPatchField.C b/src/finiteArea/fields/faPatchFields/constraint/processor/processorFaPatchField.C index 54db9e5dd91fc0ecdd0aa769e45e79183984236e..9ebadac4bcb7993ad9b48230142375e14630f883 100644 --- a/src/finiteArea/fields/faPatchFields/constraint/processor/processorFaPatchField.C +++ b/src/finiteArea/fields/faPatchFields/constraint/processor/processorFaPatchField.C @@ -308,7 +308,17 @@ void Foam::processorFaPatchField<Type>::initInterfaceMatrixUpdate const Pstream::commsTypes commsType ) const { - this->patch().patchInternalField(psiInternal, scalarSendBuf_); + const labelUList& faceCells = lduAddr.patchAddr(patchId); + + { + scalarSendBuf_.resize_nocopy(faceCells.size()); + scalarRecvBuf_.resize_nocopy(faceCells.size()); + + forAll(faceCells, i) + { + scalarSendBuf_[i] = psiInternal[faceCells[i]]; + } + } if (commsType == UPstream::commsTypes::nonBlocking) { @@ -320,8 +330,6 @@ void Foam::processorFaPatchField<Type>::initInterfaceMatrixUpdate << abort(FatalError); } - scalarRecvBuf_.resize_nocopy(scalarSendBuf_.size()); - recvRequest_ = UPstream::nRequests(); UIPstream::read ( @@ -382,7 +390,7 @@ void Foam::processorFaPatchField<Type>::updateInterfaceMatrix } else { - scalarRecvBuf_.resize_nocopy(this->size()); + scalarRecvBuf_.resize_nocopy(faceCells.size()); // In general a no-op procPatch_.receive(commsType, scalarRecvBuf_); } @@ -412,7 +420,18 @@ void Foam::processorFaPatchField<Type>::initInterfaceMatrixUpdate const Pstream::commsTypes commsType ) const { - this->patch().patchInternalField(psiInternal, sendBuf_); + const labelUList& faceCells = lduAddr.patchAddr(patchId); + + { + sendBuf_.resize_nocopy(faceCells.size()); + recvBuf_.resize_nocopy(faceCells.size()); + + forAll(faceCells, i) + { + sendBuf_[i] = psiInternal[faceCells[i]]; + } + } + if (commsType == UPstream::commsTypes::nonBlocking) { @@ -424,8 +443,6 @@ void Foam::processorFaPatchField<Type>::initInterfaceMatrixUpdate << abort(FatalError); } - recvBuf_.resize_nocopy(sendBuf_.size()); - recvRequest_ = UPstream::nRequests(); UIPstream::read ( @@ -485,7 +502,7 @@ void Foam::processorFaPatchField<Type>::updateInterfaceMatrix } else { - recvBuf_.resize_nocopy(this->size()); + recvBuf_.resize_nocopy(faceCells.size()); // In general a no-op procPatch_.receive(commsType, recvBuf_); } diff --git a/src/finiteArea/fields/faPatchFields/faPatchField/faPatchField.C b/src/finiteArea/fields/faPatchFields/faPatchField/faPatchField.C index 9b0ff823a6d0df7c9b6cafe74f63c62a43d0f493..8245b3041712a285482e044fc3660b0d612b670f 100644 --- a/src/finiteArea/fields/faPatchFields/faPatchField/faPatchField.C +++ b/src/finiteArea/fields/faPatchFields/faPatchField/faPatchField.C @@ -210,10 +210,6 @@ template<class Type> Foam::tmp<Foam::Field<Type>> Foam::faPatchField<Type>::patchInternalField() const { - // const auto& p = faPatchFieldBase::patch(); - // auto tpfld = tmp<Field<Type>>::New(p.size()); - // p.patchInternalField(internalField_, tpfld.ref()); - // return tpfld; return patch().patchInternalField(internalField_); } diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/calculatedProcessor/calculatedProcessorFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/constraint/calculatedProcessor/calculatedProcessorFvPatchField.C index d89655e902e778931dfe3e9674c2b612ad027185..e86ea1db6e1781d59dabd1ba6eaa8e69ff65ca20 100644 --- a/src/finiteVolume/fields/fvPatchFields/constraint/calculatedProcessor/calculatedProcessorFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/constraint/calculatedProcessor/calculatedProcessorFvPatchField.C @@ -125,22 +125,23 @@ void Foam::calculatedProcessorFvPatchField<Type>::initEvaluate << abort(FatalError); } - //this->patchInternalField(sendBuf_); // Bypass patchInternalField since uses fvPatch addressing + + Field<Type>& self = *this; // Receive straight into *this + { - const Field<Type>& iF = this->internalField(); - const labelUList& fc = procInterface_.faceCells(); - sendBuf_.resize_nocopy(fc.size()); - forAll(fc, i) + const Field<Type>& psiInternal = this->internalField(); + const labelUList& faceCells = procInterface_.faceCells(); + + sendBuf_.resize_nocopy(faceCells.size()); + self.resize_nocopy(faceCells.size()); + + forAll(faceCells, i) { - sendBuf_[i] = iF[fc[i]]; + sendBuf_[i] = psiInternal[faceCells[i]]; } } - // Receive straight into *this - Field<Type>& self = *this; - self.resize_nocopy(sendBuf_.size()); - recvRequest_ = UPstream::nRequests(); UIPstream::read ( @@ -202,15 +203,17 @@ void Foam::calculatedProcessorFvPatchField<Type>::initInterfaceMatrixUpdate } // Bypass patchInternalField since uses fvPatch addressing - const labelUList& fc = lduAddr.patchAddr(patchId); + const labelUList& faceCells = lduAddr.patchAddr(patchId); - scalarSendBuf_.resize_nocopy(fc.size()); - forAll(fc, i) { - scalarSendBuf_[i] = psiInternal[fc[i]]; - } + scalarSendBuf_.resize_nocopy(faceCells.size()); + scalarRecvBuf_.resize_nocopy(faceCells.size()); - scalarRecvBuf_.resize_nocopy(scalarSendBuf_.size()); + forAll(faceCells, i) + { + scalarSendBuf_[i] = psiInternal[faceCells[i]]; + } + } recvRequest_ = UPstream::nRequests(); UIPstream::read diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.C index f095684a0bd957a51fb4458db4f289f2a58a6a90..b814b4de9babdafea5e0611c696e8c9c2b69c742 100644 --- a/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.C @@ -321,14 +321,16 @@ void Foam::processorFvPatchField<Type>::initInterfaceMatrixUpdate const Pstream::commsTypes commsType ) const { - //this->patch().patchInternalField(psiInternal, scalarSendBuf_); - const labelUList& faceCells = lduAddr.patchAddr(patchId); - scalarSendBuf_.resize_nocopy(this->patch().size()); - forAll(scalarSendBuf_, facei) { - scalarSendBuf_[facei] = psiInternal[faceCells[facei]]; + scalarSendBuf_.resize_nocopy(faceCells.size()); + scalarRecvBuf_.resize_nocopy(faceCells.size()); + + forAll(faceCells, i) + { + scalarSendBuf_[i] = psiInternal[faceCells[i]]; + } } if @@ -345,8 +347,6 @@ void Foam::processorFvPatchField<Type>::initInterfaceMatrixUpdate << abort(FatalError); } - scalarRecvBuf_.resize_nocopy(scalarSendBuf_.size()); - recvRequest_ = UPstream::nRequests(); UIPstream::read ( @@ -411,7 +411,7 @@ void Foam::processorFvPatchField<Type>::updateInterfaceMatrix } else { - scalarRecvBuf_.resize_nocopy(this->size()); + scalarRecvBuf_.resize_nocopy(faceCells.size()); // In general a no-op procPatch_.compressedReceive(commsType, scalarRecvBuf_); } @@ -441,13 +441,16 @@ void Foam::processorFvPatchField<Type>::initInterfaceMatrixUpdate const Pstream::commsTypes commsType ) const { - sendBuf_.resize_nocopy(this->patch().size()); - const labelUList& faceCells = lduAddr.patchAddr(patchId); - forAll(sendBuf_, facei) { - sendBuf_[facei] = psiInternal[faceCells[facei]]; + sendBuf_.resize_nocopy(faceCells.size()); + recvBuf_.resize_nocopy(faceCells.size()); + + forAll(faceCells, i) + { + sendBuf_[i] = psiInternal[faceCells[i]]; + } } if @@ -464,8 +467,6 @@ void Foam::processorFvPatchField<Type>::initInterfaceMatrixUpdate << abort(FatalError); } - recvBuf_.resize_nocopy(sendBuf_.size()); - recvRequest_ = UPstream::nRequests(); UIPstream::read ( @@ -529,7 +530,7 @@ void Foam::processorFvPatchField<Type>::updateInterfaceMatrix } else { - recvBuf_.resize_nocopy(this->size()); + recvBuf_.resize_nocopy(faceCells.size()); // In general a no-op procPatch_.compressedReceive(commsType, recvBuf_); } diff --git a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C index 373e5e2419f51a63971a769d1ea248b05e38bb7a..9cd5defc1e264488ada70190eff8e5af8cf4f0eb 100644 --- a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C @@ -229,10 +229,6 @@ template<class Type> Foam::tmp<Foam::Field<Type>> Foam::fvPatchField<Type>::patchInternalField() const { - // const auto& p = fvPatchFieldBase::patch(); - // auto tpfld = tmp<Field<Type>>::New(p.size()); - // p.patchInternalField(internalField_, tpfld.ref()); - // return tpfld; return patch().patchInternalField(internalField_); } diff --git a/src/finiteVolume/fvMesh/fvPatches/constraint/empty/emptyFvPatch.C b/src/finiteVolume/fvMesh/fvPatches/constraint/empty/emptyFvPatch.C index 8bb14b6fd6d0e497c7620f4fa6d7839227e04a4f..e20c09b75afc861951ba4d909917cf3f907f68b9 100644 --- a/src/finiteVolume/fvMesh/fvPatches/constraint/empty/emptyFvPatch.C +++ b/src/finiteVolume/fvMesh/fvPatches/constraint/empty/emptyFvPatch.C @@ -30,42 +30,25 @@ License #include "fvMesh.H" #include "addToRunTimeSelectionTable.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -defineTypeNameAndDebug(emptyFvPatch, 0); -addToRunTimeSelectionTable(fvPatch, emptyFvPatch, polyPatch); - + defineTypeNameAndDebug(emptyFvPatch, 0); + addToRunTimeSelectionTable(fvPatch, emptyFvPatch, polyPatch); +} // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -emptyFvPatch::emptyFvPatch(const polyPatch& patch, const fvBoundaryMesh& bm) +Foam::emptyFvPatch::emptyFvPatch +( + const polyPatch& patch, + const fvBoundaryMesh& bm +) : fvPatch(patch, bm), - faceCells_ - ( - labelList::subList - ( - boundaryMesh().mesh().faceOwner(), 0, patch.start() - ) - ) + faceCells_(boundaryMesh().mesh().faceOwner(), 0, patch.start()) {} -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -const labelUList& emptyFvPatch::faceCells() const -{ - return faceCells_; -} - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/src/finiteVolume/fvMesh/fvPatches/constraint/empty/emptyFvPatch.H b/src/finiteVolume/fvMesh/fvPatches/constraint/empty/emptyFvPatch.H index 132ca6aac4a9788232e4285ad232b0342c7a1485..b41406cb7f370d7a69629d278cadd811707fa53f 100644 --- a/src/finiteVolume/fvMesh/fvPatches/constraint/empty/emptyFvPatch.H +++ b/src/finiteVolume/fvMesh/fvPatches/constraint/empty/emptyFvPatch.H @@ -35,8 +35,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef emptyFvPatch_H -#define emptyFvPatch_H +#ifndef Foam_emptyFvPatch_H +#define Foam_emptyFvPatch_H #include "fvPatch.H" #include "emptyPolyPatch.H" @@ -54,9 +54,9 @@ class emptyFvPatch : public fvPatch { - // Private data + // Private Data - //- face-cell addressing + //- Empty face-cell addressing const labelList::subList faceCells_; @@ -74,15 +74,11 @@ public: // Member Functions - // Access + //- Empty patch has zero size + virtual label size() const { return 0; } - virtual label size() const - { - return 0; - } - - //- Return faceCells - virtual const labelUList& faceCells() const; + //- Return faceCells + virtual const labelUList& faceCells() const { return faceCells_; } }; diff --git a/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H b/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H index e303ec950e8b01ad0e0c2019dbed14a01e928c19..d1f73e5e9396609392c97fa00804db5c2303ac76 100644 --- a/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H +++ b/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H @@ -292,34 +292,35 @@ public: // \param internalData The internal field to extract from // \param addressing Addressing from patch into internal field // \param [out] pfld The extracted patch field. - // It is always resized according to the patch size(), + // Should normally be sized according to the patch size(), // which can be smaller than the addressing size template<class Type> inline void patchInternalField ( const UList<Type>& internalData, const labelUList& addressing, - Field<Type>& pfld + UList<Type>& pfld ) const; //- Extract internal field next to patch as patch field //- using faceCells() mapping. // \param internalData The internal field to extract from // \param [out] pfld The extracted patch field. - // It is always resized according to the patch size(), + // Should normally be sized according to the patch size(), // which can be smaller than the faceCells() size template<class Type> void patchInternalField ( const UList<Type>& internalData, - Field<Type>& pfld + UList<Type>& pfld ) const; //- Return given internal field next to patch as patch field //- using faceCells() mapping. // \param internalData The internal field to extract from template<class Type> - tmp<Field<Type>> patchInternalField + [[nodiscard]] tmp<Field<Type>> + patchInternalField ( const UList<Type>& internalData ) const; diff --git a/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatchTemplates.C b/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatchTemplates.C index 6d998a7bdb87530b449f53c84e66ed1b52b38fd4..f820fced7001e2437c7e380678f9b6b9d97aef1e 100644 --- a/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatchTemplates.C +++ b/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatchTemplates.C @@ -35,12 +35,27 @@ void Foam::fvPatch::patchInternalField ( const UList<Type>& internalData, const labelUList& addressing, - Field<Type>& pfld + UList<Type>& pfld ) const { - const label len = this->size(); + // For v2412 and earlier this was a field and was resized here: + // const label len = this->size(); + // pfld.resize_nocopy(len); + // + // Now uses pre-sized storage (note: behaves like a static method) - pfld.resize_nocopy(len); + const label len = pfld.size(); + + #ifdef FULLDEBUG + if (FOAM_UNLIKELY((addressing.size() < len) || (this->size() < len))) + { + FatalErrorInFunction + << "patchField size = " << len + << " but patch size = " << this->size() + << " and addressing size = " << addressing.size() << nl + << abort(FatalError); + } + #endif for (label i = 0; i < len; ++i) { @@ -53,10 +68,14 @@ template<class Type> void Foam::fvPatch::patchInternalField ( const UList<Type>& internalData, - Field<Type>& pfld + UList<Type>& pfld ) const { - pfld.resize_nocopy(this->size()); // In general this is a no-op + // For v2412 and earlier this was a field and was resized here: + // pfld.resize_nocopy(this->size()); + // + // Now uses pre-sized storage + patchInternalField(internalData, this->faceCells(), pfld); }