/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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 "processorFvPatchField.H"
#include "processorFvPatch.H"
#include "demandDrivenData.H"
#include "transformField.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template
Foam::processorFvPatchField::processorFvPatchField
(
const fvPatch& p,
const DimensionedField& iF
)
:
coupledFvPatchField(p, iF),
procPatch_(refCast(p)),
sendBuf_(0),
receiveBuf_(0),
outstandingSendRequest_(-1),
outstandingRecvRequest_(-1),
scalarSendBuf_(0),
scalarReceiveBuf_(0)
{}
template
Foam::processorFvPatchField::processorFvPatchField
(
const fvPatch& p,
const DimensionedField& iF,
const Field& f
)
:
coupledFvPatchField(p, iF, f),
procPatch_(refCast(p)),
sendBuf_(0),
receiveBuf_(0),
outstandingSendRequest_(-1),
outstandingRecvRequest_(-1),
scalarSendBuf_(0),
scalarReceiveBuf_(0)
{}
// Construct by mapping given processorFvPatchField
template
Foam::processorFvPatchField::processorFvPatchField
(
const processorFvPatchField& ptf,
const fvPatch& p,
const DimensionedField& iF,
const fvPatchFieldMapper& mapper
)
:
coupledFvPatchField(ptf, p, iF, mapper),
procPatch_(refCast(p)),
sendBuf_(0),
receiveBuf_(0),
outstandingSendRequest_(-1),
outstandingRecvRequest_(-1),
scalarSendBuf_(0),
scalarReceiveBuf_(0)
{
if (!isA(this->patch()))
{
FatalErrorIn
(
"processorFvPatchField::processorFvPatchField\n"
"(\n"
" const processorFvPatchField& ptf,\n"
" const fvPatch& p,\n"
" const DimensionedField& iF,\n"
" const fvPatchFieldMapper& mapper\n"
")\n"
) << "\n patch type '" << p.type()
<< "' not constraint type '" << typeName << "'"
<< "\n for patch " << p.name()
<< " of field " << this->dimensionedInternalField().name()
<< " in file " << this->dimensionedInternalField().objectPath()
<< exit(FatalIOError);
}
if (debug && !ptf.ready())
{
FatalErrorIn("processorFvPatchField::processorFvPatchField(..)")
<< "On patch " << procPatch_.name() << " outstanding request."
<< abort(FatalError);
}
}
template
Foam::processorFvPatchField::processorFvPatchField
(
const fvPatch& p,
const DimensionedField& iF,
const dictionary& dict
)
:
coupledFvPatchField(p, iF, dict),
procPatch_(refCast(p)),
sendBuf_(0),
receiveBuf_(0),
outstandingSendRequest_(-1),
outstandingRecvRequest_(-1),
scalarSendBuf_(0),
scalarReceiveBuf_(0)
{
if (!isA(p))
{
FatalIOErrorIn
(
"processorFvPatchField::processorFvPatchField\n"
"(\n"
" const fvPatch& p,\n"
" const Field& field,\n"
" const dictionary& dict\n"
")\n",
dict
) << "\n patch type '" << p.type()
<< "' not constraint type '" << typeName << "'"
<< "\n for patch " << p.name()
<< " of field " << this->dimensionedInternalField().name()
<< " in file " << this->dimensionedInternalField().objectPath()
<< exit(FatalIOError);
}
}
template
Foam::processorFvPatchField::processorFvPatchField
(
const processorFvPatchField& ptf
)
:
processorLduInterfaceField(),
coupledFvPatchField(ptf),
procPatch_(refCast(ptf.patch())),
sendBuf_(ptf.sendBuf_.xfer()),
receiveBuf_(ptf.receiveBuf_.xfer()),
outstandingSendRequest_(-1),
outstandingRecvRequest_(-1),
scalarSendBuf_(ptf.scalarSendBuf_.xfer()),
scalarReceiveBuf_(ptf.scalarReceiveBuf_.xfer())
{
if (debug && !ptf.ready())
{
FatalErrorIn("processorFvPatchField::processorFvPatchField(..)")
<< "On patch " << procPatch_.name() << " outstanding request."
<< abort(FatalError);
}
}
template
Foam::processorFvPatchField::processorFvPatchField
(
const processorFvPatchField& ptf,
const DimensionedField& iF
)
:
coupledFvPatchField(ptf, iF),
procPatch_(refCast(ptf.patch())),
sendBuf_(0),
receiveBuf_(0),
outstandingSendRequest_(-1),
outstandingRecvRequest_(-1),
scalarSendBuf_(0),
scalarReceiveBuf_(0)
{
if (debug && !ptf.ready())
{
FatalErrorIn("processorFvPatchField::processorFvPatchField(..)")
<< "On patch " << procPatch_.name() << " outstanding request."
<< abort(FatalError);
}
}
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
template
Foam::processorFvPatchField::~processorFvPatchField()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
Foam::tmp >
Foam::processorFvPatchField::patchNeighbourField() const
{
if (debug && !this->ready())
{
FatalErrorIn("processorFvPatchField::patchNeighbourField()")
<< "On patch " << procPatch_.name()
<< " outstanding request."
<< abort(FatalError);
}
return *this;
}
template
void Foam::processorFvPatchField::initEvaluate
(
const Pstream::commsTypes commsType
)
{
if (Pstream::parRun())
{
this->patchInternalField(sendBuf_);
if (commsType == Pstream::nonBlocking && !Pstream::floatTransfer)
{
// Fast path. Receive into *this
this->setSize(sendBuf_.size());
outstandingRecvRequest_ = UPstream::nRequests();
IPstream::read
(
Pstream::nonBlocking,
procPatch_.neighbProcNo(),
reinterpret_cast(this->begin()),
this->byteSize(),
procPatch_.tag()
);
outstandingSendRequest_ = UPstream::nRequests();
OPstream::write
(
Pstream::nonBlocking,
procPatch_.neighbProcNo(),
reinterpret_cast(sendBuf_.begin()),
this->byteSize(),
procPatch_.tag()
);
}
else
{
procPatch_.compressedSend(commsType, sendBuf_);
}
}
}
template
void Foam::processorFvPatchField::evaluate
(
const Pstream::commsTypes commsType
)
{
if (Pstream::parRun())
{
if (commsType == Pstream::nonBlocking && !Pstream::floatTransfer)
{
// Fast path. Received into *this
if
(
outstandingRecvRequest_ >= 0
&& outstandingRecvRequest_ < Pstream::nRequests()
)
{
UPstream::waitRequest(outstandingRecvRequest_);
}
outstandingSendRequest_ = -1;
outstandingRecvRequest_ = -1;
}
else
{
procPatch_.compressedReceive(commsType, *this);
}
if (doTransform())
{
transform(*this, procPatch_.forwardT(), *this);
}
}
}
template
Foam::tmp >
Foam::processorFvPatchField::snGrad
(
const scalarField& deltaCoeffs
) const
{
return deltaCoeffs*(*this - this->patchInternalField());
}
template
void Foam::processorFvPatchField::initInterfaceMatrixUpdate
(
scalarField&,
const scalarField& psiInternal,
const scalarField&,
const direction,
const Pstream::commsTypes commsType
) const
{
this->patch().patchInternalField(psiInternal, scalarSendBuf_);
if (commsType == Pstream::nonBlocking && !Pstream::floatTransfer)
{
// Fast path.
if (debug && !this->ready())
{
FatalErrorIn
(
"processorFvPatchField::initInterfaceMatrixUpdate(..)"
) << "On patch " << procPatch_.name()
<< " outstanding request."
<< abort(FatalError);
}
scalarReceiveBuf_.setSize(scalarSendBuf_.size());
outstandingRecvRequest_ = UPstream::nRequests();
IPstream::read
(
Pstream::nonBlocking,
procPatch_.neighbProcNo(),
reinterpret_cast(scalarReceiveBuf_.begin()),
scalarReceiveBuf_.byteSize(),
procPatch_.tag()
);
outstandingSendRequest_ = UPstream::nRequests();
OPstream::write
(
Pstream::nonBlocking,
procPatch_.neighbProcNo(),
reinterpret_cast(scalarSendBuf_.begin()),
scalarSendBuf_.byteSize(),
procPatch_.tag()
);
}
else
{
procPatch_.compressedSend(commsType, scalarSendBuf_);
}
const_cast&>(*this).updatedMatrix() = false;
}
template
void Foam::processorFvPatchField::updateInterfaceMatrix
(
scalarField& result,
const scalarField&,
const scalarField& coeffs,
const direction cmpt,
const Pstream::commsTypes commsType
) const
{
if (this->updatedMatrix())
{
return;
}
const labelUList& faceCells = this->patch().faceCells();
if (commsType == Pstream::nonBlocking && !Pstream::floatTransfer)
{
// Fast path.
if
(
outstandingRecvRequest_ >= 0
&& outstandingRecvRequest_ < Pstream::nRequests()
)
{
UPstream::waitRequest(outstandingRecvRequest_);
}
// Recv finished so assume sending finished as well.
outstandingSendRequest_ = -1;
outstandingRecvRequest_ = -1;
// Consume straight from scalarReceiveBuf_
// Transform according to the transformation tensor
transformCoupleField(scalarReceiveBuf_, cmpt);
// Multiply the field by coefficients and add into the result
forAll(faceCells, elemI)
{
result[faceCells[elemI]] -= coeffs[elemI]*scalarReceiveBuf_[elemI];
}
}
else
{
scalarField pnf
(
procPatch_.compressedReceive(commsType, this->size())()
);
// Transform according to the transformation tensor
transformCoupleField(pnf, cmpt);
// Multiply the field by coefficients and add into the result
forAll(faceCells, elemI)
{
result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
}
}
const_cast&>(*this).updatedMatrix() = true;
}
template
void Foam::processorFvPatchField::initInterfaceMatrixUpdate
(
Field&,
const Field& psiInternal,
const scalarField&,
const Pstream::commsTypes commsType
) const
{
this->patch().patchInternalField(psiInternal, sendBuf_);
if (commsType == Pstream::nonBlocking && !Pstream::floatTransfer)
{
// Fast path.
if (debug && !this->ready())
{
FatalErrorIn
(
"processorFvPatchField::initInterfaceMatrixUpdate(..)"
) << "On patch " << procPatch_.name()
<< " outstanding request."
<< abort(FatalError);
}
receiveBuf_.setSize(sendBuf_.size());
outstandingRecvRequest_ = UPstream::nRequests();
IPstream::read
(
Pstream::nonBlocking,
procPatch_.neighbProcNo(),
reinterpret_cast(receiveBuf_.begin()),
receiveBuf_.byteSize(),
procPatch_.tag()
);
outstandingSendRequest_ = UPstream::nRequests();
OPstream::write
(
Pstream::nonBlocking,
procPatch_.neighbProcNo(),
reinterpret_cast(sendBuf_.begin()),
sendBuf_.byteSize(),
procPatch_.tag()
);
}
else
{
procPatch_.compressedSend(commsType, sendBuf_);
}
const_cast&>(*this).updatedMatrix() = false;
}
template
void Foam::processorFvPatchField::updateInterfaceMatrix
(
Field& result,
const Field&,
const scalarField& coeffs,
const Pstream::commsTypes commsType
) const
{
if (this->updatedMatrix())
{
return;
}
const labelUList& faceCells = this->patch().faceCells();
if (commsType == Pstream::nonBlocking && !Pstream::floatTransfer)
{
// Fast path.
if
(
outstandingRecvRequest_ >= 0
&& outstandingRecvRequest_ < Pstream::nRequests()
)
{
UPstream::waitRequest(outstandingRecvRequest_);
}
// Recv finished so assume sending finished as well.
outstandingSendRequest_ = -1;
outstandingRecvRequest_ = -1;
// Consume straight from receiveBuf_
// Transform according to the transformation tensor
transformCoupleField(receiveBuf_);
// Multiply the field by coefficients and add into the result
forAll(faceCells, elemI)
{
result[faceCells[elemI]] -= coeffs[elemI]*receiveBuf_[elemI];
}
}
else
{
Field pnf
(
procPatch_.compressedReceive(commsType, this->size())()
);
// Transform according to the transformation tensor
transformCoupleField(pnf);
// Multiply the field by coefficients and add into the result
forAll(faceCells, elemI)
{
result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
}
}
const_cast&>(*this).updatedMatrix() = true;
}
template
bool Foam::processorFvPatchField::ready() const
{
if
(
outstandingSendRequest_ >= 0
&& outstandingSendRequest_ < Pstream::nRequests()
)
{
bool finished = UPstream::finishedRequest(outstandingSendRequest_);
if (!finished)
{
return false;
}
}
outstandingSendRequest_ = -1;
if
(
outstandingRecvRequest_ >= 0
&& outstandingRecvRequest_ < Pstream::nRequests()
)
{
bool finished = UPstream::finishedRequest(outstandingRecvRequest_);
if (!finished)
{
return false;
}
}
outstandingRecvRequest_ = -1;
return true;
}
// ************************************************************************* //