diff --git a/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/BlockSAMGInterfaceField/BlockSAMGInterfaceField.C b/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/BlockSAMGInterfaceField/BlockSAMGInterfaceField.C new file mode 100644 index 000000000..eed21a98e --- /dev/null +++ b/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/BlockSAMGInterfaceField/BlockSAMGInterfaceField.C @@ -0,0 +1,100 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "BlockSAMGInterfaceField.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +Foam::tmp > +Foam::BlockSAMGInterfaceField::selectBlockCoeffs +( + const Foam::CoeffField& fineCoeffs +) const +{ + tmp > tcoarseCoeffs + ( + new CoeffField(interface_.size()) + ); + CoeffField& coarseCoeffs = tcoarseCoeffs(); + /* HJ, code missing + typedef CoeffField TypeCoeffField; + + typedef typename TypeCoeffField::linearTypeField linearTypeField; + typedef typename TypeCoeffField::squareTypeField squareTypeField; + + // Get addressing from the fine interface + const labelField& fineAddressing = interface_.fineAddressing(); + const labelField& restrictAddressing = interface_.restrictAddressing(); + const scalarField& restrictWeights = interface_.restrictWeights(); + + // Added weights to account for non-integral matching + if (fineCoeffs.activeType() == blockCoeffBase::SQUARE) + { + squareTypeField& activeCoarseCoeffs = coarseCoeffs.asSquare(); + const squareTypeField& activeFineCoeffs = fineCoeffs.asSquare(); + + activeCoarseCoeffs *= 0.0; + + // Added weights to account for non-integral matching + forAll (restrictAddressing, ffi) + { + activeCoarseCoeffs[restrictAddressing[ffi]] += + restrictWeights[ffi]*activeFineCoeffs[fineAddressing[ffi]]; + } + } + else if (fineCoeffs.activeType() == blockCoeffBase::LINEAR) + { + linearTypeField& activeCoarseCoeffs = coarseCoeffs.asLinear(); + const linearTypeField& activeFineCoeffs = fineCoeffs.asLinear(); + + activeCoarseCoeffs *= 0.0; + + // Added weights to account for non-integral matching + forAll (restrictAddressing, ffi) + { + activeCoarseCoeffs[restrictAddressing[ffi]] += + restrictWeights[ffi]*activeFineCoeffs[fineAddressing[ffi]]; + } + } + else + { + FatalErrorIn + ( + "Foam::tmp >\n" + "Foam::BlockSAMGInterfaceField::selectBlockCoeffs\n" + "(\n" + " const Foam::CoeffField& fineCoeffs\n" + ") const" + ) << "Scalar type selection currently not handled" + << abort(FatalError); + } + */ + return tcoarseCoeffs; +} + + +// ************************************************************************* // diff --git a/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/BlockSAMGInterfaceField/BlockSAMGInterfaceField.H b/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/BlockSAMGInterfaceField/BlockSAMGInterfaceField.H new file mode 100644 index 000000000..404d06eb1 --- /dev/null +++ b/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/BlockSAMGInterfaceField/BlockSAMGInterfaceField.H @@ -0,0 +1,169 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +Class + Foam::BlockSAMGInterfaceField + +Description + Abstract base class for AMG selected interface fields. + +Author + Hrvoje Jasak. All rights reserved + +SourceFiles + BlockSAMGInterfaceField.C + newBlockSAMGInterfaceField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef BlockSAMGInterfaceField_H +#define BlockSAMGInterfaceField_H + +#include "BlockLduInterfaceField.H" +#include "SAMGInterface.H" +#include "autoPtr.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class BlockSAMGInterfaceField Declaration +\*---------------------------------------------------------------------------*/ + +template +class BlockSAMGInterfaceField +: + public BlockLduInterfaceField +{ + // Private data + + //- Local reference cast into the interface + const SAMGInterface& interface_; + + + // Private Member Functions + + //- Disallow default bitwise copy construct + BlockSAMGInterfaceField(const BlockSAMGInterfaceField&); + + //- Disallow default bitwise assignment + void operator=(const BlockSAMGInterfaceField&); + + +public: + + //- Runtime type information + TypeName("BlockSAMGInterfaceField"); + + + // Declare run-time constructor selection tables + + declareRunTimeSelectionTable + ( + autoPtr, + BlockSAMGInterfaceField, + lduInterface, + ( + const SAMGInterface& SAMGCp, + const BlockLduInterfaceField& fineInterface + ), + (SAMGCp, fineInterface) + ); + + + // Selectors + + //- Return a pointer to a new interface created on freestore given + // the fine interface + static autoPtr > New + ( + const SAMGInterface& SAMGCp, + const BlockLduInterfaceField& fineInterface + ); + + + // Constructors + + //- Construct from AMG interface and fine level interface field + BlockSAMGInterfaceField + ( + const SAMGInterface& SAMGCp, + const BlockLduInterfaceField& + ) + : + BlockLduInterfaceField(SAMGCp), + interface_(SAMGCp) + {} + + + //- Destructor + virtual ~BlockSAMGInterfaceField() + {} + + + // Member Functions + + // Agglomeration + + //- Select the CoeffField fine-level coefficients + // for the coarse level + virtual tmp > selectBlockCoeffs + ( + const CoeffField& fineCoeffs + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "BlockSAMGInterfaceField.C" +# include "newBlockSAMGInterfaceField.C" +#endif + +#define makeBlockSAMGInterfaceField(BlockSAMGInterfaceFieldType, typeBlockSAMGInterfaceFieldType) \ + \ +defineNamedTemplateTypeNameAndDebug(typeBlockSAMGInterfaceFieldType, 0); \ + \ +addToRunTimeSelectionTable(BlockSAMGInterfaceFieldType, typeBlockSAMGInterfaceFieldType, lduInterface); + +#define makeBlockSAMGInterfaceFields(blockSAMGInterfaceFieldType) \ + \ +makeBlockSAMGInterfaceField(blockScalarSAMGInterfaceField, blockSAMGInterfaceFieldType##Scalar); \ +makeBlockSAMGInterfaceField(blockVectorSAMGInterfaceField, blockSAMGInterfaceFieldType##Vector); \ + +//HJ, hacked! Needs terminal specialisation. HJ, 16/Mar/2016 +// makeBlockSAMGInterfaceField(blockTensorSAMGInterfaceField, blockSAMGInterfaceFieldType##Tensor); + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/BlockSAMGInterfaceField/blockSAMGInterfaceFields.C b/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/BlockSAMGInterfaceField/blockSAMGInterfaceFields.C new file mode 100644 index 000000000..153e69ad2 --- /dev/null +++ b/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/BlockSAMGInterfaceField/blockSAMGInterfaceFields.C @@ -0,0 +1,61 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "blockSAMGInterfaceFields.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +defineNamedTemplateTypeNameAndDebug(blockScalarSAMGInterfaceField, 0); +defineNamedTemplateTypeNameAndDebug(blockVectorSAMGInterfaceField, 0); +defineNamedTemplateTypeNameAndDebug(blockTensorSAMGInterfaceField, 0); + +defineTemplateRunTimeSelectionTable +( + blockScalarSAMGInterfaceField, + lduInterface +); + +defineTemplateRunTimeSelectionTable +( + blockVectorSAMGInterfaceField, + lduInterface +); + +defineTemplateRunTimeSelectionTable +( + blockTensorSAMGInterfaceField, + lduInterface +); + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// ************************************************************************* // diff --git a/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/BlockSAMGInterfaceField/blockSAMGInterfaceFields.H b/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/BlockSAMGInterfaceField/blockSAMGInterfaceFields.H new file mode 100644 index 000000000..e20ec3b0a --- /dev/null +++ b/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/BlockSAMGInterfaceField/blockSAMGInterfaceFields.H @@ -0,0 +1,63 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +Class + BlockSAMGInterfaceField + +Description + Typedefs for block SAMG interface fields. + +Author + Hrvoje Jasak + +SourceFiles + blockSAMGInterfaceFields.C + +\*---------------------------------------------------------------------------*/ + +#ifndef blockSAMGInterfaceFields_H +#define blockSAMGInterfaceFields_H + +#include "BlockSAMGInterfaceField.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +typedef BlockSAMGInterfaceField blockScalarSAMGInterfaceField; +typedef BlockSAMGInterfaceField blockVectorSAMGInterfaceField; +typedef BlockSAMGInterfaceField blockTensorSAMGInterfaceField; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/BlockSAMGInterfaceField/blockVectorNSAMGInterfaceFields.C b/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/BlockSAMGInterfaceField/blockVectorNSAMGInterfaceFields.C new file mode 100644 index 000000000..a0e031e02 --- /dev/null +++ b/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/BlockSAMGInterfaceField/blockVectorNSAMGInterfaceFields.C @@ -0,0 +1,64 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +Class + blockVectorNSAMGInterfaceFields + +Description + Macros for VectorN types for AMG interface fields with block coeffs + +Author + Hrvoje Jasak + +\*---------------------------------------------------------------------------*/ + +#include "BlockSAMGInterfaceField.H" +#include "ProcessorBlockSAMGInterfaceField.H" +#include "VectorNFieldTypes.H" +#include "ExpandTensorNField.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +#define makeTemplateTypeNameAndDebug(type, Type, args...) \ + \ +typedef BlockSAMGInterfaceField block##Type##SAMGInterfaceField; \ +defineNamedTemplateTypeNameAndDebug(block##Type##SAMGInterfaceField, 0); \ +defineTemplateRunTimeSelectionTable(block##Type##SAMGInterfaceField, lduInterface); \ + \ +typedef ProcessorBlockSAMGInterfaceField block##Type##ProcessorSAMGInterfaceField; \ +makeBlockSAMGInterfaceField(block##Type##SAMGInterfaceField, block##Type##ProcessorSAMGInterfaceField); \ + +forAllVectorNTypes(makeTemplateTypeNameAndDebug); + +#undef makeTemplateTypeNameAndDebug + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// ************************************************************************* // diff --git a/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/BlockSAMGInterfaceField/newBlockSAMGInterfaceField.C b/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/BlockSAMGInterfaceField/newBlockSAMGInterfaceField.C new file mode 100644 index 000000000..872a9c313 --- /dev/null +++ b/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/BlockSAMGInterfaceField/newBlockSAMGInterfaceField.C @@ -0,0 +1,70 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "BlockSAMGInterfaceField.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // + +template +Foam::autoPtr > +Foam::BlockSAMGInterfaceField::New +( + const SAMGInterface& SAMGCp, + const BlockLduInterfaceField& fineInterface +) +{ + word coupleType(fineInterface.interfaceFieldType()); + + typename lduInterfaceConstructorTable::iterator cstrIter = + lduInterfaceConstructorTablePtr_->find(coupleType); + + if (cstrIter == lduInterfaceConstructorTablePtr_->end()) + { + FatalErrorIn + ( + "BlockSAMGInterfaceField::New\n" + "(\n" + " const SAMGInterface& SAMGCp,\n" + " const BlockLduInterfaceField& fineInterface\n" + ")" + ) << "Unknown BlockSAMGInterfaceField type " << coupleType << ".\n" + << "Valid BlockSAMGInterfaceField types are :" + << lduInterfaceConstructorTablePtr_->sortedToc() + << exit(FatalError); + } + + return autoPtr > + ( + cstrIter() + ( + SAMGCp, + fineInterface + ) + ); +} + + +// ************************************************************************* // diff --git a/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/ProcessorBlockSAMGInterfaceField/ProcessorBlockSAMGInterfaceField.C b/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/ProcessorBlockSAMGInterfaceField/ProcessorBlockSAMGInterfaceField.C new file mode 100644 index 000000000..33459912a --- /dev/null +++ b/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/ProcessorBlockSAMGInterfaceField/ProcessorBlockSAMGInterfaceField.C @@ -0,0 +1,217 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "ProcessorBlockSAMGInterfaceField.H" +#include "processorLduInterfaceField.H" +#include "addToRunTimeSelectionTable.H" +#include "lduMatrix.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::ProcessorBlockSAMGInterfaceField::ProcessorBlockSAMGInterfaceField +( + const SAMGInterface& AMGCp, + const BlockLduInterfaceField& fineInterfaceField +) +: + BlockSAMGInterfaceField(AMGCp, fineInterfaceField), + procInterface_(refCast(AMGCp)), + doTransform_(false), + outstandingSendRequest_(-1), + outstandingRecvRequest_(-1), + sendBuf_(0), + receiveBuf_(0) +{ + // If the interface based on a patch this must be taken care specially of + if (isA >(fineInterfaceField)) + { + const ProcessorBlockLduInterfaceField& p = + refCast > + ( + fineInterfaceField + ); + + doTransform_ = p.doTransform(); + } + else if (isA(fineInterfaceField)) + { + const processorLduInterfaceField& p = + refCast(fineInterfaceField); + + doTransform_ = p.doTransform(); + } + else + { + FatalErrorIn("ProcessorBlockSAMGInterfaceField Constructor") + << "fineInterface must be of processor type and either" << endl + << " ProcessorBlockLduInterfaceField or " << endl + << " processorFvPatchField " << endl + << abort(FatalError); + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template +Foam::ProcessorBlockSAMGInterfaceField:: +~ProcessorBlockSAMGInterfaceField() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +void Foam::ProcessorBlockSAMGInterfaceField::initInterfaceMatrixUpdate +( + const Field& psiInternal, + Field&, + const BlockLduMatrix&, + const CoeffField&, + const Pstream::commsTypes commsType, + const bool switchToLhs +) const +{ + label oldWarn = Pstream::warnComm; + Pstream::warnComm = comm(); + + sendBuf_ = procInterface_.interfaceInternalField(psiInternal); + + if (commsType == Pstream::nonBlocking) + { + // Fast path. + receiveBuf_.setSize(sendBuf_.size()); + outstandingRecvRequest_ = Pstream::nRequests(); + IPstream::read + ( + Pstream::nonBlocking, + procInterface_.neighbProcNo(), + reinterpret_cast(receiveBuf_.begin()), + receiveBuf_.byteSize(), + procInterface_.tag(), + comm() + ); + + outstandingSendRequest_ = Pstream::nRequests(); + OPstream::write + ( + Pstream::nonBlocking, + procInterface_.neighbProcNo(), + reinterpret_cast(sendBuf_.begin()), + sendBuf_.byteSize(), + procInterface_.tag(), + comm() + ); + } + else + { + procInterface_.send + ( + commsType, + procInterface_.interfaceInternalField(psiInternal)() + ); + } + + // Mark as ready for update + const_cast&>(*this).updatedMatrix() = + false; + + Pstream::warnComm = oldWarn; +} + + +template +void Foam::ProcessorBlockSAMGInterfaceField::updateInterfaceMatrix +( + const Field& psiInternal, + Field& result, + const BlockLduMatrix&, + const CoeffField& coeffs, + const Pstream::commsTypes commsType, + const bool switchToLhs +) const +{ + if (this->updatedMatrix()) + { + return; + } + + if (commsType == Pstream::nonBlocking) + { + // Fast path. + if + ( + outstandingRecvRequest_ >= 0 + && outstandingRecvRequest_ < Pstream::nRequests() + ) + { + Pstream::waitRequest(outstandingRecvRequest_); + } + + // Recv finished so assume sending finished as well. + outstandingSendRequest_ = -1; + outstandingRecvRequest_ = -1; + } + else + { + // Check size + receiveBuf_.setSize(sendBuf_.size()); + + procInterface_.receive(commsType, receiveBuf_); + } + + // The data is now in receiveBuf_ for both cases + + // Transformation missing. Is it needed? HJ, 28/Nov/2016 + + // Multiply neighbour field with coeffs and re-use buffer for result + // of multiplication + multiply(receiveBuf_, coeffs, receiveBuf_); + + const unallocLabelList& faceCells = procInterface_.faceCells(); + + if (switchToLhs) + { + forAll(faceCells, elemI) + { + result[faceCells[elemI]] += receiveBuf_[elemI]; + } + } + else + { + forAll(faceCells, elemI) + { + result[faceCells[elemI]] -= receiveBuf_[elemI]; + } + } + + // Mark as updated + const_cast&>(*this).updatedMatrix() = + true; +} + + +// ************************************************************************* // diff --git a/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/ProcessorBlockSAMGInterfaceField/ProcessorBlockSAMGInterfaceField.H b/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/ProcessorBlockSAMGInterfaceField/ProcessorBlockSAMGInterfaceField.H new file mode 100644 index 000000000..44dab15c9 --- /dev/null +++ b/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/ProcessorBlockSAMGInterfaceField/ProcessorBlockSAMGInterfaceField.H @@ -0,0 +1,220 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +Class + Foam::ProcessorBlockSAMGInterfaceField + +Description + AMG selected processor interface field. + +SourceFiles + ProcessorBlockSAMGInterfaceField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef ProcessorBlockSAMGInterfaceField_H +#define ProcessorBlockSAMGInterfaceField_H + +#include "BlockSAMGInterfaceField.H" +#include "processorSAMGInterface.H" +#include "ProcessorBlockLduInterfaceField.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class ProcessorBlockSAMGInterfaceField Declaration +\*---------------------------------------------------------------------------*/ + +template +class ProcessorBlockSAMGInterfaceField +: + public BlockSAMGInterfaceField, + public ProcessorBlockLduInterfaceField +{ + // Private data + + //- Local reference cast into the processor interface + const processorSAMGInterface& procInterface_; + + //- Is the transform required + bool doTransform_; + + + // Sending and receiving + + //- Outstanding request + mutable label outstandingSendRequest_; + + //- Outstanding request + mutable label outstandingRecvRequest_; + + //- Send buffer. + mutable Field sendBuf_; + + //- Receive buffer. + mutable Field receiveBuf_; + + + // Private Member Functions + + //- Disallow default bitwise copy construct + ProcessorBlockSAMGInterfaceField + ( + const ProcessorBlockSAMGInterfaceField& + ); + + //- Disallow default bitwise assignment + void operator=(const ProcessorBlockSAMGInterfaceField&); + + +public: + + //- Runtime type information + TypeName("processor"); + + + // Constructors + + //- Construct from AMG interface and fine level interface field + ProcessorBlockSAMGInterfaceField + ( + const SAMGInterface& AMGCp, + const BlockLduInterfaceField& fineInterfaceField + ); + + + //- Destructor + virtual ~ProcessorBlockSAMGInterfaceField(); + + + // Member Functions + + // Access + + //- Return size + label size() const + { + return procInterface_.size(); + } + + + // Block coupled interface matrix update + + //- Transform given patch component field + virtual void transformCoupleField + ( + scalarField& f, + const direction cmpt + ) const + { + ProcessorBlockLduInterfaceField::transformCoupleField + ( + f, + cmpt + ); + } + + //- Transform neighbour field + virtual void transformCoupleField + ( + Field& f + ) const + { + ProcessorBlockLduInterfaceField::transformCoupleField(f); + } + + //- Initialise neighbour matrix update + virtual void initInterfaceMatrixUpdate + ( + const Field&, + Field&, + const BlockLduMatrix&, + const CoeffField&, + const Pstream::commsTypes commsType, + const bool switchToLhs + ) const; + + //- Update result field based on interface functionality + virtual void updateInterfaceMatrix + ( + const Field&, + Field&, + const BlockLduMatrix&, + const CoeffField&, + const Pstream::commsTypes commsType, + const bool switchToLhs + ) const; + + + //- Processor interface functions + + //- Return communicator used for comms + virtual label comm() const + { + return procInterface_.comm(); + } + + //- Return processor number + virtual int myProcNo() const + { + return procInterface_.myProcNo(); + } + + //- Return neigbour processor number + virtual int neighbProcNo() const + { + return procInterface_.neighbProcNo(); + } + + //- Does the interface field perform the transfromation + virtual bool doTransform() const + { + return doTransform_; + } + + //- Return face transformation tensor + virtual const tensorField& forwardT() const + { + return procInterface_.forwardT(); + } +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "ProcessorBlockSAMGInterfaceField.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/ProcessorBlockSAMGInterfaceField/ProcessorBlockSAMGInterfaceFields.C b/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/ProcessorBlockSAMGInterfaceField/ProcessorBlockSAMGInterfaceFields.C new file mode 100644 index 000000000..01c2a8b19 --- /dev/null +++ b/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/ProcessorBlockSAMGInterfaceField/ProcessorBlockSAMGInterfaceFields.C @@ -0,0 +1,42 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "ProcessorBlockSAMGInterfaceFields.H" +#include "blockSAMGInterfaceFields.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +makeBlockSAMGInterfaceFields(ProcessorBlockSAMGInterfaceField); + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// ************************************************************************* // diff --git a/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/ProcessorBlockSAMGInterfaceField/ProcessorBlockSAMGInterfaceFields.H b/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/ProcessorBlockSAMGInterfaceField/ProcessorBlockSAMGInterfaceFields.H new file mode 100644 index 000000000..b8904e925 --- /dev/null +++ b/src/foam/matrices/blockLduMatrix/BlockAMG/BlockSAMGInterfaceFields/ProcessorBlockSAMGInterfaceField/ProcessorBlockSAMGInterfaceFields.H @@ -0,0 +1,68 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +Class + ProcessorBlockSAMGInterfaceField + +Description + Typedefs for block coefficient processor AMG interface fields + +Author + Klas Jareteg, 2013-02-08 + +SourceFiles + ProcessorBlockSAMGInterfaceFields.C + +\*---------------------------------------------------------------------------*/ + +#ifndef ProcessorBlockSAMGInterfaceFields_H +#define ProcessorBlockSAMGInterfaceFields_H + +#include "ProcessorBlockSAMGInterfaceField.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +typedef ProcessorBlockSAMGInterfaceField +ProcessorBlockSAMGInterfaceFieldScalar; + +typedef ProcessorBlockSAMGInterfaceField +ProcessorBlockSAMGInterfaceFieldVector; + +typedef ProcessorBlockSAMGInterfaceField +ProcessorBlockSAMGInterfaceFieldTensor; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/foam/matrices/lduMatrix/solvers/AMG/interfaceFields/SAMGInterfaceFields/SAMGInterfaceField/SAMGInterfaceField.C b/src/foam/matrices/lduMatrix/solvers/AMG/interfaceFields/SAMGInterfaceFields/SAMGInterfaceField/SAMGInterfaceField.C new file mode 100644 index 000000000..7303e7a72 --- /dev/null +++ b/src/foam/matrices/lduMatrix/solvers/AMG/interfaceFields/SAMGInterfaceFields/SAMGInterfaceField/SAMGInterfaceField.C @@ -0,0 +1,37 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "SAMGInterfaceField.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(SAMGInterfaceField, 0); + defineRunTimeSelectionTable(SAMGInterfaceField, lduInterface); +} + +// ************************************************************************* // diff --git a/src/foam/matrices/lduMatrix/solvers/AMG/interfaceFields/SAMGInterfaceFields/SAMGInterfaceField/SAMGInterfaceField.H b/src/foam/matrices/lduMatrix/solvers/AMG/interfaceFields/SAMGInterfaceFields/SAMGInterfaceField/SAMGInterfaceField.H new file mode 100644 index 000000000..495c6a77a --- /dev/null +++ b/src/foam/matrices/lduMatrix/solvers/AMG/interfaceFields/SAMGInterfaceFields/SAMGInterfaceField/SAMGInterfaceField.H @@ -0,0 +1,126 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +Class + Foam::SAMGInterfaceField + +Description + Abstract base class for AMG selected interface fields. + +SourceFiles + SAMGInterfaceField.C + newAmgInterfaceField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef SAMGInterfaceField_H +#define SAMGInterfaceField_H + +#include "lduInterfaceField.H" +#include "SAMGInterface.H" +#include "autoPtr.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class SAMGInterfaceField Declaration +\*---------------------------------------------------------------------------*/ + +class SAMGInterfaceField +: + public lduInterfaceField +{ + // Private data + + //- Local reference cast into the interface + const SAMGInterface& interface_; + + + // Private Member Functions + + //- Disallow default bitwise copy construct + SAMGInterfaceField(const SAMGInterfaceField&); + + //- Disallow default bitwise assignment + void operator=(const SAMGInterfaceField&); + + +public: + + //- Runtime type information + TypeName("SAMGInterfaceField"); + + + // Declare run-time constructor selection tables + + declareRunTimeSelectionTable + ( + autoPtr, + SAMGInterfaceField, + lduInterface, + ( + const SAMGInterface& SAMGCp, + const lduInterfaceField& fineInterface + ), + (SAMGCp, fineInterface) + ); + + + // Selectors + + //- Return a pointer to a new interface created on freestore given + // the fine interface + static autoPtr New + ( + const SAMGInterface& SAMGCp, + const lduInterfaceField& fineInterface + ); + + + // Constructors + + //- Construct from AMG interface and fine level interface field + SAMGInterfaceField + ( + const SAMGInterface& SAMGCp, + const lduInterfaceField& + ) + : + lduInterfaceField(SAMGCp), + interface_(SAMGCp) + {} +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/foam/matrices/lduMatrix/solvers/AMG/interfaceFields/SAMGInterfaceFields/SAMGInterfaceField/newSAMGInterfaceField.C b/src/foam/matrices/lduMatrix/solvers/AMG/interfaceFields/SAMGInterfaceFields/SAMGInterfaceField/newSAMGInterfaceField.C new file mode 100644 index 000000000..d7548222a --- /dev/null +++ b/src/foam/matrices/lduMatrix/solvers/AMG/interfaceFields/SAMGInterfaceFields/SAMGInterfaceField/newSAMGInterfaceField.C @@ -0,0 +1,60 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "SAMGInterfaceField.H" + +// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // + +Foam::autoPtr Foam::SAMGInterfaceField::New +( + const SAMGInterface& SAMGCp, + const lduInterfaceField& fineInterface +) +{ + word coupleType(fineInterface.interfaceFieldType()); + + lduInterfaceConstructorTable::iterator cstrIter = + lduInterfaceConstructorTablePtr_->find(coupleType); + + if (cstrIter == lduInterfaceConstructorTablePtr_->end()) + { + FatalErrorIn + ( + "SAMGInterfaceField::New\n" + "(\n" + " const SAMGInterface& SAMGCp,\n" + " const lduInterfaceField& fineInterface\n" + ")" + ) << "Unknown SAMGInterfaceField type " << coupleType << ".\n" + << "Valid SAMGInterfaceField types are :" + << lduInterfaceConstructorTablePtr_->sortedToc() + << exit(FatalError); + } + + return autoPtr(cstrIter()(SAMGCp, fineInterface)); +} + + +// ************************************************************************* // diff --git a/src/foam/matrices/lduMatrix/solvers/AMG/interfaceFields/SAMGInterfaceFields/processorSAMGInterfaceField/processorSAMGInterfaceField.C b/src/foam/matrices/lduMatrix/solvers/AMG/interfaceFields/SAMGInterfaceFields/processorSAMGInterfaceField/processorSAMGInterfaceField.C new file mode 100644 index 000000000..a6d789753 --- /dev/null +++ b/src/foam/matrices/lduMatrix/solvers/AMG/interfaceFields/SAMGInterfaceFields/processorSAMGInterfaceField/processorSAMGInterfaceField.C @@ -0,0 +1,204 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "processorSAMGInterfaceField.H" +#include "addToRunTimeSelectionTable.H" +#include "lduMatrix.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(processorSAMGInterfaceField, 0); + addToRunTimeSelectionTable + ( + SAMGInterfaceField, + processorSAMGInterfaceField, + lduInterface + ); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::processorSAMGInterfaceField::processorSAMGInterfaceField +( + const SAMGInterface& AMGCp, + const lduInterfaceField& fineInterfaceField +) +: + SAMGInterfaceField(AMGCp, fineInterfaceField), + procInterface_(refCast(AMGCp)), + doTransform_(false), + rank_(0), + outstandingSendRequest_(-1), + outstandingRecvRequest_(-1), + scalarSendBuf_(0), + scalarReceiveBuf_(0) +{ + const processorLduInterfaceField& p = + refCast(fineInterfaceField); + + doTransform_ = p.doTransform(); + rank_ = p.rank(); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::processorSAMGInterfaceField::~processorSAMGInterfaceField() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::processorSAMGInterfaceField::initInterfaceMatrixUpdate +( + const scalarField& psiInternal, + scalarField&, + const lduMatrix&, + const scalarField&, + const direction, + const Pstream::commsTypes commsType, + const bool switchToLhs +) const +{ + label oldWarn = Pstream::warnComm; + Pstream::warnComm = comm(); + + scalarSendBuf_ = procInterface_.interfaceInternalField(psiInternal); + + if (commsType == Pstream::nonBlocking) + { + // Fast path. + scalarReceiveBuf_.setSize(scalarSendBuf_.size()); + outstandingRecvRequest_ = Pstream::nRequests(); + IPstream::read + ( + Pstream::nonBlocking, + procInterface_.neighbProcNo(), + reinterpret_cast(scalarReceiveBuf_.begin()), + scalarReceiveBuf_.byteSize(), + procInterface_.tag(), + comm() + ); + + outstandingSendRequest_ = Pstream::nRequests(); + OPstream::write + ( + Pstream::nonBlocking, + procInterface_.neighbProcNo(), + reinterpret_cast(scalarSendBuf_.begin()), + scalarSendBuf_.byteSize(), + procInterface_.tag(), + comm() + ); + } + else + { + procInterface_.send + ( + commsType, + procInterface_.interfaceInternalField(psiInternal)() + ); + } + + // Mark as ready for update + const_cast(*this).updatedMatrix() = false; + + Pstream::warnComm = oldWarn; +} + + +void Foam::processorSAMGInterfaceField::updateInterfaceMatrix +( + const scalarField&, + scalarField& result, + const lduMatrix&, + const scalarField& coeffs, + const direction cmpt, + const Pstream::commsTypes commsType, + const bool switchToLhs +) const +{ + if (this->updatedMatrix()) + { + return; + } + + if (commsType == Pstream::nonBlocking) + { + // Fast path. + if + ( + outstandingRecvRequest_ >= 0 + && outstandingRecvRequest_ < Pstream::nRequests() + ) + { + Pstream::waitRequest(outstandingRecvRequest_); + } + + // Recv finished so assume sending finished as well. + outstandingSendRequest_ = -1; + outstandingRecvRequest_ = -1; + } + else + { + // Check size + scalarReceiveBuf_.setSize(scalarSendBuf_.size()); + + procInterface_.receive(commsType, scalarReceiveBuf_); + } + + // The data is now in scalarReceiveBuf_ for both cases + + // Transform according to the transformation tensor + transformCoupleField(scalarReceiveBuf_, cmpt); + + // Multiply the field by coefficients and add into the result + + const unallocLabelList& faceCells = procInterface_.faceCells(); + + if (switchToLhs) + { + forAll(faceCells, elemI) + { + result[faceCells[elemI]] += coeffs[elemI]*scalarReceiveBuf_[elemI]; + } + } + else + { + forAll(faceCells, elemI) + { + result[faceCells[elemI]] -= coeffs[elemI]*scalarReceiveBuf_[elemI]; + } + } + + // Mark as updated + const_cast(*this).updatedMatrix() = true; +} + + +// ************************************************************************* // diff --git a/src/foam/matrices/lduMatrix/solvers/AMG/interfaceFields/SAMGInterfaceFields/processorSAMGInterfaceField/processorSAMGInterfaceField.H b/src/foam/matrices/lduMatrix/solvers/AMG/interfaceFields/SAMGInterfaceFields/processorSAMGInterfaceField/processorSAMGInterfaceField.H new file mode 100644 index 000000000..8a5f0a9c6 --- /dev/null +++ b/src/foam/matrices/lduMatrix/solvers/AMG/interfaceFields/SAMGInterfaceFields/processorSAMGInterfaceField/processorSAMGInterfaceField.H @@ -0,0 +1,208 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +Class + Foam::processorSAMGInterfaceField + +Description + AMG selected processor interface field. + +SourceFiles + processorSAMGInterfaceField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef processorSAMGInterfaceField_H +#define processorSAMGInterfaceField_H + +#include "SAMGInterfaceField.H" +#include "processorSAMGInterface.H" +#include "processorLduInterfaceField.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class processorSAMGInterfaceField Declaration +\*---------------------------------------------------------------------------*/ + +class processorSAMGInterfaceField +: + public SAMGInterfaceField, + public processorLduInterfaceField +{ + // Private data + + //- Local reference cast into the processor interface + const processorSAMGInterface& procInterface_; + + //- Is the transform required + bool doTransform_; + + //- Rank of component for transformation + int rank_; + + + // Sending and receiving + + //- Outstanding request + mutable label outstandingSendRequest_; + + //- Outstanding request + mutable label outstandingRecvRequest_; + + //- Scalar send buffer + mutable Field scalarSendBuf_; + + //- Scalar receive buffer + mutable Field scalarReceiveBuf_; + + + // Private Member Functions + + //- Disallow default bitwise copy construct + processorSAMGInterfaceField(const processorSAMGInterfaceField&); + + //- Disallow default bitwise assignment + void operator=(const processorSAMGInterfaceField&); + + +public: + + //- Runtime type information + TypeName("processor"); + + + // Constructors + + //- Construct from AMG interface and fine level interface field + processorSAMGInterfaceField + ( + const SAMGInterface& AMGCp, + const lduInterfaceField& fineInterfaceField + ); + + + //- Destructor + virtual ~processorSAMGInterfaceField(); + + + // Member Functions + + // Access + + //- Return size + label size() const + { + return procInterface_.size(); + } + + + // Coupled interface matrix update + + //- Transform neighbour field + virtual void transformCoupleField + ( + scalarField& pnf, + const direction cmpt + ) const + { + processorLduInterfaceField::transformCoupleField(pnf, cmpt); + } + + //- Initialise neighbour matrix update + virtual void initInterfaceMatrixUpdate + ( + const scalarField& psiInternal, + scalarField& result, + const lduMatrix& m, + const scalarField& coeffs, + const direction cmpt, + const Pstream::commsTypes commsType, + const bool switchToLhs + ) const; + + //- Update result field based on interface functionality + virtual void updateInterfaceMatrix + ( + const scalarField& psiInternal, + scalarField& result, + const lduMatrix&, + const scalarField& coeffs, + const direction cmpt, + const Pstream::commsTypes commsType, + const bool switchToLhs + ) const; + + + //- Processor interface functions + + //- Return communicator used for comms + virtual label comm() const + { + return procInterface_.comm(); + } + + //- Return processor number + virtual int myProcNo() const + { + return procInterface_.myProcNo(); + } + + //- Return neigbour processor number + virtual int neighbProcNo() const + { + return procInterface_.neighbProcNo(); + } + + //- Does the interface field perform the transfromation + virtual bool doTransform() const + { + return doTransform_; + } + + //- Return face transformation tensor + virtual const tensorField& forwardT() const + { + return procInterface_.forwardT(); + } + + //- Return rank of component for transform + virtual int rank() const + { + return rank_; + } +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/foam/matrices/lduMatrix/solvers/AMG/interfaces/SAMGInterfaces/SAMGInterface/SAMGInterface.C b/src/foam/matrices/lduMatrix/solvers/AMG/interfaces/SAMGInterfaces/SAMGInterface/SAMGInterface.C new file mode 100644 index 000000000..19fd718b9 --- /dev/null +++ b/src/foam/matrices/lduMatrix/solvers/AMG/interfaces/SAMGInterfaces/SAMGInterface/SAMGInterface.C @@ -0,0 +1,66 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | foam-extend: Open Source CFD + \\ / O peration | Version: 4.0 + \\ / A nd | Web: http://www.foam-extend.org + \\/ M anipulation | For copyright notice see file Copyright +------------------------------------------------------------------------------- +License + This file is part of foam-extend. + + foam-extend 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. + + foam-extend 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 foam-extend. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "SAMGInterface.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(SAMGInterface, 0); + defineRunTimeSelectionTable(SAMGInterface, lduInterface); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::tmp Foam::SAMGInterface::interfaceInternalField +( + const unallocLabelList& internalData +) const +{ + return interfaceInternalField