/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016-2017 Wikki Ltd Copyright (C) 2019-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . \*---------------------------------------------------------------------------*/ #include "processorFaPatchField.H" #include "transformField.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template Foam::processorFaPatchField::processorFaPatchField ( const faPatch& p, const DimensionedField& iF ) : coupledFaPatchField(p, iF), procPatch_(refCast(p)), sendRequest_(-1), recvRequest_(-1) {} template Foam::processorFaPatchField::processorFaPatchField ( const faPatch& p, const DimensionedField& iF, const Field& f ) : coupledFaPatchField(p, iF, f), procPatch_(refCast(p)), sendRequest_(-1), recvRequest_(-1) {} template Foam::processorFaPatchField::processorFaPatchField ( const processorFaPatchField& ptf, const faPatch& p, const DimensionedField& iF, const faPatchFieldMapper& mapper ) : coupledFaPatchField(ptf, p, iF, mapper), procPatch_(refCast(p)), sendRequest_(-1), recvRequest_(-1) { if (!isType(this->patch())) { FatalErrorInFunction << "\n patch type '" << p.type() << "' not constraint type '" << typeName << "'" << "\n for patch " << p.name() << " of field " << this->internalField().name() << " in file " << this->internalField().objectPath() << exit(FatalError); } if (debug && !ptf.ready()) { FatalErrorInFunction << "On patch " << procPatch_.name() << " outstanding request." << abort(FatalError); } } template Foam::processorFaPatchField::processorFaPatchField ( const faPatch& p, const DimensionedField& iF, const dictionary& dict ) : coupledFaPatchField(p, iF, dict, IOobjectOption::NO_READ), procPatch_(refCast(p, dict)), sendRequest_(-1), recvRequest_(-1) { if (!isType(p)) { FatalIOErrorInFunction(dict) << "\n patch type '" << p.type() << "' not constraint type '" << typeName << "'" << "\n for patch " << p.name() << " of field " << this->internalField().name() << " in file " << this->internalField().objectPath() << exit(FatalIOError); } // Use 'value' supplied, or set to internal field if (!this->readValueEntry(dict)) { faPatchField::patchInternalField(*this); } } template Foam::processorFaPatchField::processorFaPatchField ( const processorFaPatchField& ptf ) : processorLduInterfaceField(), coupledFaPatchField(ptf), procPatch_(refCast(ptf.patch())), sendRequest_(-1), recvRequest_(-1), sendBuf_(std::move(ptf.sendBuf_)), recvBuf_(std::move(ptf.recvBuf_)), scalarSendBuf_(std::move(ptf.scalarSendBuf_)), scalarRecvBuf_(std::move(ptf.scalarRecvBuf_)) { if (debug && !ptf.ready()) { FatalErrorInFunction << "On patch " << procPatch_.name() << " outstanding request." << abort(FatalError); } } template Foam::processorFaPatchField::processorFaPatchField ( const processorFaPatchField& ptf, const DimensionedField& iF ) : coupledFaPatchField(ptf, iF), procPatch_(refCast(ptf.patch())), sendRequest_(-1), recvRequest_(-1) { if (debug && !ptf.ready()) { FatalErrorInFunction << "On patch " << procPatch_.name() << " outstanding request." << abort(FatalError); } } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template bool Foam::processorFaPatchField::ready() const { if (!UPstream::finishedRequest(sendRequest_)) return false; sendRequest_ = -1; if (!UPstream::finishedRequest(recvRequest_)) return false; recvRequest_ = -1; return true; } template Foam::tmp> Foam::processorFaPatchField::patchNeighbourField() const { if (debug && !this->ready()) { FatalErrorInFunction << "On patch " << procPatch_.name() << " outstanding request." << abort(FatalError); } return *this; } template void Foam::processorFaPatchField::initEvaluate ( const Pstream::commsTypes commsType ) { if (Pstream::parRun()) { this->patchInternalField(sendBuf_); if (commsType == UPstream::commsTypes::nonBlocking) { if (!is_contiguous::value) { FatalErrorInFunction << "Invalid for non-contiguous data types" << abort(FatalError); } // Receive straight into *this this->resize_nocopy(sendBuf_.size()); recvRequest_ = UPstream::nRequests(); UIPstream::read ( UPstream::commsTypes::nonBlocking, procPatch_.neighbProcNo(), this->data_bytes(), this->size_bytes(), procPatch_.tag(), procPatch_.comm() ); sendRequest_ = UPstream::nRequests(); UOPstream::write ( UPstream::commsTypes::nonBlocking, procPatch_.neighbProcNo(), sendBuf_.cdata_bytes(), sendBuf_.size_bytes(), procPatch_.tag(), procPatch_.comm() ); } else { procPatch_.send(commsType, sendBuf_); } } } template void Foam::processorFaPatchField::evaluate ( const Pstream::commsTypes commsType ) { if (Pstream::parRun()) { if (commsType == UPstream::commsTypes::nonBlocking) { // Fast path. Received into *this // Treat send as finished when recv is done UPstream::waitRequest(recvRequest_); recvRequest_ = -1; sendRequest_ = -1; } else { procPatch_.receive(commsType, *this); } if (doTransform()) { transform(*this, procPatch_.forwardT(), *this); } } } template Foam::tmp> Foam::processorFaPatchField::snGrad() const { return this->patch().deltaCoeffs()*(*this - this->patchInternalField()); } template void Foam::processorFaPatchField::initInterfaceMatrixUpdate ( solveScalarField& result, const bool add, const lduAddressing& lduAddr, const label patchId, const solveScalarField& psiInternal, const scalarField& coeffs, const direction, const Pstream::commsTypes commsType ) const { this->patch().patchInternalField(psiInternal, scalarSendBuf_); if (commsType == UPstream::commsTypes::nonBlocking) { // Fast path. if (debug && !this->ready()) { FatalErrorInFunction << "On patch " << procPatch_.name() << " outstanding request." << abort(FatalError); } scalarRecvBuf_.resize_nocopy(scalarSendBuf_.size()); recvRequest_ = UPstream::nRequests(); UIPstream::read ( UPstream::commsTypes::nonBlocking, procPatch_.neighbProcNo(), scalarRecvBuf_.data_bytes(), scalarRecvBuf_.size_bytes(), procPatch_.tag(), procPatch_.comm() ); sendRequest_ = UPstream::nRequests(); UOPstream::write ( UPstream::commsTypes::nonBlocking, procPatch_.neighbProcNo(), scalarSendBuf_.cdata_bytes(), scalarSendBuf_.size_bytes(), procPatch_.tag(), procPatch_.comm() ); } else { procPatch_.send(commsType, scalarSendBuf_); } this->updatedMatrix(false); } template void Foam::processorFaPatchField::updateInterfaceMatrix ( solveScalarField& result, const bool add, const lduAddressing& lduAddr, const label patchId, const solveScalarField&, const scalarField& coeffs, const direction cmpt, const Pstream::commsTypes commsType ) const { if (this->updatedMatrix()) { return; } const labelUList& faceCells = this->patch().edgeFaces(); if (commsType == UPstream::commsTypes::nonBlocking) { // Fast path: consume straight from receive buffer // Treat send as finished when recv is done UPstream::waitRequest(recvRequest_); recvRequest_ = -1; sendRequest_ = -1; } else { scalarRecvBuf_.resize_nocopy(this->size()); procPatch_.receive(commsType, scalarRecvBuf_); } if (pTraits::rank) { // Transform non-scalar data according to the transformation tensor transformCoupleField(scalarRecvBuf_, cmpt); } // Multiply the field by coefficients and add into the result this->addToInternalField(result, !add, faceCells, coeffs, scalarRecvBuf_); this->updatedMatrix(true); } template void Foam::processorFaPatchField::initInterfaceMatrixUpdate ( Field& result, const bool add, const lduAddressing& lduAddr, const label patchId, const Field& psiInternal, const scalarField& coeffs, const Pstream::commsTypes commsType ) const { this->patch().patchInternalField(psiInternal, sendBuf_); if (commsType == UPstream::commsTypes::nonBlocking) { // Fast path. if (debug && !this->ready()) { FatalErrorInFunction << "On patch " << procPatch_.name() << " outstanding request." << abort(FatalError); } recvBuf_.resize_nocopy(sendBuf_.size()); recvRequest_ = UPstream::nRequests(); UIPstream::read ( UPstream::commsTypes::nonBlocking, procPatch_.neighbProcNo(), recvBuf_.data_bytes(), recvBuf_.size_bytes(), procPatch_.tag(), procPatch_.comm() ); sendRequest_ = UPstream::nRequests(); UOPstream::write ( UPstream::commsTypes::nonBlocking, procPatch_.neighbProcNo(), sendBuf_.cdata_bytes(), sendBuf_.size_bytes(), procPatch_.tag(), procPatch_.comm() ); } else { procPatch_.send(commsType, sendBuf_); } this->updatedMatrix(false); } template void Foam::processorFaPatchField::updateInterfaceMatrix ( Field& result, const bool add, const lduAddressing& lduAddr, const label patchId, const Field&, const scalarField& coeffs, const Pstream::commsTypes commsType ) const { if (this->updatedMatrix()) { return; } const labelUList& faceCells = this->patch().edgeFaces(); if (commsType == UPstream::commsTypes::nonBlocking) { // Fast path: consume straight from receive buffer // Treat send as finished when recv is done UPstream::waitRequest(recvRequest_); recvRequest_ = -1; sendRequest_ = -1; } else { recvBuf_.resize_nocopy(this->size()); procPatch_.receive(commsType, recvBuf_); } // Transform according to the transformation tensor transformCoupleField(recvBuf_); // Multiply the field by coefficients and add into the result this->addToInternalField(result, !add, faceCells, coeffs, recvBuf_); this->updatedMatrix(true); } // ************************************************************************* //