Files
openfoam/src/finiteVolume/fields/fvPatchFields/constraint/cyclic/cyclicFvPatchField.C

268 lines
6.9 KiB
C

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "cyclicFvPatchField.H"
#include "transformField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
cyclicFvPatchField<Type>::cyclicFvPatchField
(
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF
)
:
coupledFvPatchField<Type>(p, iF),
cyclicPatch_(refCast<const cyclicFvPatch>(p))
{}
template<class Type>
cyclicFvPatchField<Type>::cyclicFvPatchField
(
const cyclicFvPatchField<Type>& ptf,
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF,
const fvPatchFieldMapper& mapper
)
:
coupledFvPatchField<Type>(ptf, p, iF, mapper),
cyclicPatch_(refCast<const cyclicFvPatch>(p))
{
if (!isA<cyclicFvPatch>(this->patch()))
{
FatalErrorIn
(
"cyclicFvPatchField<Type>::cyclicFvPatchField"
"("
"const cyclicFvPatchField<Type>& ,"
"const fvPatch&, "
"const DimensionedField<Type, volMesh>&, "
"const fvPatchFieldMapper&"
")"
) << " 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<class Type>
cyclicFvPatchField<Type>::cyclicFvPatchField
(
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF,
const dictionary& dict
)
:
coupledFvPatchField<Type>(p, iF, dict),
cyclicPatch_(refCast<const cyclicFvPatch>(p))
{
if (!isA<cyclicFvPatch>(p))
{
FatalIOErrorIn
(
"cyclicFvPatchField<Type>::cyclicFvPatchField"
"("
"const fvPatch&, "
"const Field<Type>&, "
"const dictionary&"
")",
dict
) << " 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);
}
this->evaluate(Pstream::blocking);
}
template<class Type>
cyclicFvPatchField<Type>::cyclicFvPatchField
(
const cyclicFvPatchField<Type>& ptf
)
:
cyclicLduInterfaceField(),
coupledFvPatchField<Type>(ptf),
cyclicPatch_(ptf.cyclicPatch_)
{}
template<class Type>
cyclicFvPatchField<Type>::cyclicFvPatchField
(
const cyclicFvPatchField<Type>& ptf,
const DimensionedField<Type, volMesh>& iF
)
:
coupledFvPatchField<Type>(ptf, iF),
cyclicPatch_(ptf.cyclicPatch_)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
tmp<Field<Type> > cyclicFvPatchField<Type>::patchNeighbourField() const
{
const Field<Type>& iField = this->internalField();
const labelUList& nbrFaceCells =
cyclicPatch().cyclicPatch().neighbPatch().faceCells();
tmp<Field<Type> > tpnf(new Field<Type>(this->size()));
Field<Type>& pnf = tpnf();
if (doTransform())
{
forAll(pnf, facei)
{
pnf[facei] = transform
(
forwardT()[0], iField[nbrFaceCells[facei]]
);
}
}
else
{
forAll(pnf, facei)
{
pnf[facei] = iField[nbrFaceCells[facei]];
}
}
return tpnf;
}
template<class Type>
const cyclicFvPatchField<Type>& cyclicFvPatchField<Type>::neighbourPatchField()
const
{
const GeometricField<Type, fvPatchField, volMesh>& fld =
static_cast<const GeometricField<Type, fvPatchField, volMesh>&>
(
this->internalField()
);
return refCast<const cyclicFvPatchField<Type> >
(
fld.boundaryField()[this->cyclicPatch().neighbPatchID()]
);
}
template<class Type>
void cyclicFvPatchField<Type>::updateInterfaceMatrix
(
scalarField& result,
const scalarField& psiInternal,
const scalarField& coeffs,
const direction cmpt,
const Pstream::commsTypes
) const
{
scalarField pnf(this->size());
const labelUList& nbrFaceCells =
cyclicPatch().cyclicPatch().neighbPatch().faceCells();
forAll(pnf, facei)
{
pnf[facei] = psiInternal[nbrFaceCells[facei]];
}
// Transform according to the transformation tensors
transformCoupleField(pnf, cmpt);
// Multiply the field by coefficients and add into the result
const labelUList& faceCells = cyclicPatch_.faceCells();
forAll(faceCells, elemI)
{
result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
}
}
template<class Type>
void cyclicFvPatchField<Type>::updateInterfaceMatrix
(
Field<Type>& result,
const Field<Type>& psiInternal,
const scalarField& coeffs,
const Pstream::commsTypes
) const
{
Field<Type> pnf(this->size());
const labelUList& nbrFaceCells =
cyclicPatch().cyclicPatch().neighbPatch().faceCells();
forAll(pnf, facei)
{
pnf[facei] = psiInternal[nbrFaceCells[facei]];
}
// Transform according to the transformation tensors
transformCoupleField(pnf);
// Multiply the field by coefficients and add into the result
const labelUList& faceCells = cyclicPatch_.faceCells();
forAll(faceCells, elemI)
{
result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
}
}
template<class Type>
void cyclicFvPatchField<Type>::write(Ostream& os) const
{
fvPatchField<Type>::write(os);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //