/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 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 "mappedFlowRateFvPatchVectorField.H"
#include "volFields.H"
#include "addToRunTimeSelectionTable.H"
#include "fvPatchFieldMapper.H"
#include "mappedPatchBase.H"
#include "surfaceFields.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::mappedFlowRateFvPatchVectorField::mappedFlowRateFvPatchVectorField
(
const fvPatch& p,
const DimensionedField& iF
)
:
fixedValueFvPatchField(p, iF),
nbrPhiName_("none"),
phiName_("phi"),
rhoName_("rho")
{}
Foam::mappedFlowRateFvPatchVectorField::mappedFlowRateFvPatchVectorField
(
const mappedFlowRateFvPatchVectorField& ptf,
const fvPatch& p,
const DimensionedField& iF,
const fvPatchFieldMapper& mapper
)
:
fixedValueFvPatchField(ptf, p, iF, mapper),
nbrPhiName_(ptf.nbrPhiName_),
phiName_(ptf.phiName_),
rhoName_(ptf.rhoName_)
{}
Foam::mappedFlowRateFvPatchVectorField::mappedFlowRateFvPatchVectorField
(
const fvPatch& p,
const DimensionedField& iF,
const dictionary& dict
)
:
fixedValueFvPatchField(p, iF, dict),
nbrPhiName_(dict.getOrDefault("nbrPhi", "phi")),
phiName_(dict.getOrDefault("phi", "phi")),
rhoName_(dict.getOrDefault("rho", "rho"))
{}
Foam::mappedFlowRateFvPatchVectorField::mappedFlowRateFvPatchVectorField
(
const mappedFlowRateFvPatchVectorField& ptf
)
:
fixedValueFvPatchField(ptf),
nbrPhiName_(ptf.nbrPhiName_),
phiName_(ptf.phiName_),
rhoName_(ptf.rhoName_)
{}
Foam::mappedFlowRateFvPatchVectorField::mappedFlowRateFvPatchVectorField
(
const mappedFlowRateFvPatchVectorField& ptf,
const DimensionedField& iF
)
:
fixedValueFvPatchField(ptf, iF),
nbrPhiName_(ptf.nbrPhiName_),
phiName_(ptf.phiName_),
rhoName_(ptf.rhoName_)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::mappedFlowRateFvPatchVectorField::updateCoeffs()
{
if (updated())
{
return;
}
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag+1;
// Get the coupling information from the mappedPatchBase
const mappedPatchBase& mpp = refCast
(
patch().patch()
);
const polyMesh& nbrMesh = mpp.sampleMesh();
const fvPatch& nbrPatch = refCast
(
nbrMesh
).boundary()[mpp.samplePolyPatch().index()];
scalarList phi =
nbrPatch.lookupPatchField(nbrPhiName_);
mpp.distribute(phi);
const surfaceScalarField& phiName =
db().lookupObject(phiName_);
scalarField U(-phi/patch().magSf());
vectorField n(patch().nf());
if (phiName.dimensions() == dimVelocity*dimArea)
{
// volumetric flow-rate
operator==(n*U);
}
else if (phiName.dimensions() == dimDensity*dimVelocity*dimArea)
{
const fvPatchField& rhop =
patch().lookupPatchField(rhoName_);
// mass flow-rate
operator==(n*U/rhop);
if (debug)
{
scalar phi = gSum(rhop*(*this) & patch().Sf());
Info<< patch().boundaryMesh().mesh().name() << ':'
<< patch().name() << ':'
<< this->internalField().name() << " <- "
<< nbrMesh.name() << ':'
<< nbrPatch.name() << ':'
<< this->internalField().name() << " :"
<< " mass flux[Kg/s]:" << -phi
<< endl;
}
}
else
{
FatalErrorInFunction
<< "dimensions of " << phiName_ << " are incorrect" << nl
<< " on patch " << this->patch().name()
<< " of field " << this->internalField().name()
<< " in file " << this->internalField().objectPath()
<< nl << exit(FatalError);
}
// Restore tag
UPstream::msgType() = oldTag;
fixedValueFvPatchField::updateCoeffs();
}
void Foam::mappedFlowRateFvPatchVectorField::write
(
Ostream& os
) const
{
fvPatchField::write(os);
os.writeEntryIfDifferent("phi", "phi", phiName_);
os.writeEntryIfDifferent("rho", "rho", rhoName_);
os.writeEntry("nbrPhi", nbrPhiName_);
writeEntry("value", os);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
makePatchTypeField
(
fvPatchVectorField,
mappedFlowRateFvPatchVectorField
);
}
// ************************************************************************* //