diff --git a/src/OpenFOAM/fields/pointPatchFields/basic/value/valuePointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/basic/value/valuePointPatchField.C index 9718da72b3..d623500b87 100644 --- a/src/OpenFOAM/fields/pointPatchFields/basic/value/valuePointPatchField.C +++ b/src/OpenFOAM/fields/pointPatchFields/basic/value/valuePointPatchField.C @@ -237,7 +237,8 @@ void Foam::valuePointPatchField::operator= const pointPatchField& ptf ) { - Field::operator=(this->patchInternalField()); + // pointPatchField has no values to copy, assign internal values + this->extrapolateInternal(); } @@ -277,7 +278,8 @@ void Foam::valuePointPatchField::operator== const pointPatchField& ptf ) { - Field::operator=(this->patchInternalField()); + // pointPatchField has no values to copy, assign internal values + this->extrapolateInternal(); } diff --git a/src/OpenFOAM/fields/pointPatchFields/constraint/processorCyclic/processorCyclicPointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/constraint/processorCyclic/processorCyclicPointPatchField.C index 0554b28a9c..2d0e1bd140 100644 --- a/src/OpenFOAM/fields/pointPatchFields/constraint/processorCyclic/processorCyclicPointPatchField.C +++ b/src/OpenFOAM/fields/pointPatchFields/constraint/processorCyclic/processorCyclicPointPatchField.C @@ -93,15 +93,16 @@ void Foam::processorCyclicPointPatchField::initSwapAddSeparated Field& pField ) const { - if (Pstream::parRun()) + if (UPstream::parRun()) { // 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_ = this->patchInternalField + this->patchInternalField ( pField, - procPatch_.reverseMeshPoints() + procPatch_.reverseMeshPoints(), + sendBuf_ ); if (commsType == Pstream::commsTypes::nonBlocking) @@ -138,7 +139,7 @@ void Foam::processorCyclicPointPatchField::swapAddSeparated Field& pField ) const { - if (Pstream::parRun()) + if (UPstream::parRun()) { // If nonblocking, data is already in receive buffer diff --git a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.C index f2f775ccc4..cf5fc3fbcd 100644 --- a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.C +++ b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2020-2022 OpenCFD Ltd. + Copyright (C) 2020-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -108,6 +108,64 @@ void Foam::pointPatchField::write(Ostream& os) const } +template +template +void Foam::pointPatchField::patchInternalField +( + const UList& internalData, + const labelUList& addressing, + Field& pfld +) const +{ + // Check size + if (internalData.size() != primitiveField().size()) + { + FatalErrorInFunction + << "Internal field size: " << internalData.size() + << " != mesh size: " << primitiveField().size() << nl + << abort(FatalError); + } + + const label len = this->size(); + + pfld.resize_nocopy(len); + + for (label i = 0; i < len; ++i) + { + pfld[i] = internalData[addressing[i]]; + } +} + + +template +template +Foam::tmp> +Foam::pointPatchField::patchInternalField +( + const UList& internalData, + const labelUList& addressing +) const +{ + auto tpfld = tmp>::New(); + this->patchInternalField(internalData, addressing, tpfld.ref()); + return tpfld; +} + + +template +template +Foam::tmp> +Foam::pointPatchField::patchInternalField +( + const UList& internalData +) const +{ + auto tpfld = tmp>::New(); + this->patchInternalField(internalData, patch().meshPoints(), tpfld.ref()); + return tpfld; +} + + template Foam::tmp> Foam::pointPatchField::patchInternalField() const @@ -116,41 +174,6 @@ Foam::pointPatchField::patchInternalField() const } -template -template -Foam::tmp> -Foam::pointPatchField::patchInternalField -( - const Field& iF, - const labelUList& meshPoints -) const -{ - // Check size - if (iF.size() != primitiveField().size()) - { - FatalErrorInFunction - << "given internal field does not correspond to the mesh. " - << "Field size: " << iF.size() - << " mesh size: " << primitiveField().size() - << abort(FatalError); - } - - return tmp>::New(iF, meshPoints); -} - - -template -template -Foam::tmp> -Foam::pointPatchField::patchInternalField -( - const Field& iF -) const -{ - return patchInternalField(iF, patch().meshPoints()); -} - - template template void Foam::pointPatchField::addToInternalField @@ -163,18 +186,16 @@ void Foam::pointPatchField::addToInternalField if (iF.size() != primitiveField().size()) { FatalErrorInFunction - << "given internal field does not correspond to the mesh. " - << "Field size: " << iF.size() - << " mesh size: " << primitiveField().size() + << "Internal field size: " << iF.size() + << " != mesh size: " << primitiveField().size() << nl << abort(FatalError); } if (pF.size() != size()) { FatalErrorInFunction - << "given patch field does not correspond to the mesh. " - << "Field size: " << pF.size() - << " mesh size: " << size() + << "Patch field size: " << pF.size() + << " != patch size: " << size() << nl << abort(FatalError); } @@ -201,18 +222,16 @@ void Foam::pointPatchField::addToInternalField if (iF.size() != primitiveField().size()) { FatalErrorInFunction - << "given internal field does not correspond to the mesh. " - << "Field size: " << iF.size() - << " mesh size: " << primitiveField().size() + << "Internal field size: " << iF.size() + << " != mesh size: " << primitiveField().size() << nl << abort(FatalError); } if (pF.size() != size()) { FatalErrorInFunction - << "given patch field does not correspond to the mesh. " - << "Field size: " << pF.size() - << " mesh size: " << size() + << "Patch field size: " << pF.size() + << " != patch size: " << size() << nl << abort(FatalError); } @@ -240,18 +259,16 @@ void Foam::pointPatchField::setInInternalField if (iF.size() != primitiveField().size()) { FatalErrorInFunction - << "given internal field does not correspond to the mesh. " - << "Field size: " << iF.size() - << " mesh size: " << primitiveField().size() + << "Internal field size: " << iF.size() + << " != mesh size: " << primitiveField().size() << nl << abort(FatalError); } if (pF.size() != meshPoints.size()) { FatalErrorInFunction - << "given patch field does not correspond to the meshPoints. " - << "Field size: " << pF.size() - << " meshPoints size: " << size() + << "Patch field size: " << pF.size() + << " != meshPoints size: " << meshPoints.size() << nl << abort(FatalError); } diff --git a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.H b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.H index b6b7210d8b..d66463a46d 100644 --- a/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.H +++ b/src/OpenFOAM/fields/pointPatchFields/pointPatchField/pointPatchField.H @@ -431,26 +431,43 @@ public: // Evaluation Functions - //- Return field created from appropriate internal field values - tmp> patchInternalField() const; - - //- Return field created from appropriate internal field values - //- given internal field reference + //- Extract field using specified addressing + // \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(), + // which can be smaller than the addressing size template - tmp> patchInternalField + void patchInternalField ( - const Field& iF + const UList& internalData, + const labelUList& addressing, + Field& pfld ) const; //- Return field created from selected internal field values //- given internal field reference + // \param internalData The internal field to extract from + // \param addressing Addressing (mesh-points) into internal field template tmp> patchInternalField ( - const Field& iF, - const labelUList& meshPoints + const UList& internalData, + const labelUList& addressing ) const; + //- Return field created from appropriate internal field values + //- given internal field reference + template + tmp> patchInternalField + ( + const UList& internalData + ) const; + + //- Return field created from appropriate internal field values + tmp> patchInternalField() const; + + //- Given the internal field and a patch field, //- add the patch field to the internal field template