fvModels: zeroDimensionalMassSource model

This fvModel applies a mass source to the continuity equation and to all
field equations, in a zero-dimensional case. Correction is made to
account for the mass that exits the domain due to expansion in space, so
that the model correctly applies a total mass flow rate. It is
implemented as a light wrapper around the massSource model.
This commit is contained in:
Will Bainbridge
2023-02-28 12:32:20 +00:00
parent da062f389d
commit efabb9c935
9 changed files with 320 additions and 34 deletions

View File

@ -67,11 +67,17 @@ void Foam::fvCellSet::writeFileHeader
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fvCellSet::fvCellSet Foam::fvCellSet::fvCellSet(const fvMesh& mesh)
( :
const fvMesh& mesh, polyCellSet(mesh),
const dictionary& dict mesh_(mesh),
) V_(NaN)
{
setV();
}
Foam::fvCellSet::fvCellSet(const fvMesh& mesh, const dictionary& dict)
: :
polyCellSet(mesh, dict), polyCellSet(mesh, dict),
mesh_(mesh), mesh_(mesh),

View File

@ -118,12 +118,11 @@ public:
// Constructors // Constructors
//- Construct from mesh. Will select all.
fvCellSet(const fvMesh& mesh);
//- Construct from mesh and dictionary //- Construct from mesh and dictionary
fvCellSet fvCellSet(const fvMesh& mesh, const dictionary& dict);
(
const fvMesh& mesh,
const dictionary& dict
);
//- Destructor //- Destructor

View File

@ -44,5 +44,6 @@ zeroDimensional/zeroDimensionalFvModel/zeroDimensionalFvModel.C
zeroDimensional/constraintSource/constraintSource.C zeroDimensional/constraintSource/constraintSource.C
zeroDimensional/densityConstraintSource/densityConstraintSource.C zeroDimensional/densityConstraintSource/densityConstraintSource.C
zeroDimensional/pressureConstraintSource/pressureConstraintSource.C zeroDimensional/pressureConstraintSource/pressureConstraintSource.C
zeroDimensional/zeroDimensionalMassSource/zeroDimensionalMassSource.C
LIB = $(FOAM_LIBBIN)/libfvModels LIB = $(FOAM_LIBBIN)/libfvModels

View File

@ -40,7 +40,7 @@ namespace fv
} }
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::fv::massSource::readCoeffs() void Foam::fv::massSource::readCoeffs()
{ {
@ -85,6 +85,12 @@ void Foam::fv::massSource::readCoeffs()
} }
Foam::scalar Foam::fv::massSource::massFlowRate() const
{
return massFlowRate_->value(mesh().time().userTimeValue());
}
template<class Type> template<class Type>
void Foam::fv::massSource::addGeneralSupType void Foam::fv::massSource::addGeneralSupType
( (
@ -92,9 +98,9 @@ void Foam::fv::massSource::addGeneralSupType
const word& fieldName const word& fieldName
) const ) const
{ {
const scalar t = mesh().time().userTimeValue(); const scalar massFlowRate = this->massFlowRate();
const scalar massFlowRate = massFlowRate_->value(t); const Type value =
const Type value = fieldValues_[fieldName]->value<Type>(t); fieldValues_[fieldName]->value<Type>(mesh().time().userTimeValue());
const labelUList cells = set_.cells(); const labelUList cells = set_.cells();
@ -127,8 +133,7 @@ void Foam::fv::massSource::addSupType
if (fieldName == rhoName_) if (fieldName == rhoName_)
{ {
const scalar t = mesh().time().userTimeValue(); const scalar massFlowRate = this->massFlowRate();
const scalar massFlowRate = massFlowRate_->value(t);
forAll(cells, i) forAll(cells, i)
{ {
@ -146,9 +151,9 @@ void Foam::fv::massSource::addSupType
<< endl; << endl;
} }
const scalar t = mesh().time().userTimeValue(); const scalar massFlowRate = this->massFlowRate();
const scalar massFlowRate = massFlowRate_->value(t); const scalar T =
const scalar T = fieldValues_[TName_]->value<scalar>(t); fieldValues_[TName_]->value<scalar>(mesh().time().userTimeValue());
const basicThermo& thermo = const basicThermo& thermo =
mesh().lookupObject<basicThermo> mesh().lookupObject<basicThermo>
( (
@ -204,11 +209,12 @@ Foam::fv::massSource::massSource
const word& name, const word& name,
const word& modelType, const word& modelType,
const fvMesh& mesh, const fvMesh& mesh,
const dictionary& dict const dictionary& dict,
const bool all
) )
: :
fvModel(name, modelType, mesh, dict), fvModel(name, modelType, mesh, dict),
set_(mesh, coeffs()), set_(all ? fvCellSet(mesh) : fvCellSet(mesh, coeffs())),
phaseName_(), phaseName_(),
rhoName_(), rhoName_(),
heName_(), heName_(),

View File

@ -83,7 +83,9 @@ class massSource
: :
public fvModel public fvModel
{ {
// Private Data protected:
// Protected Data
//- The set of cells the fvConstraint applies to //- The set of cells the fvConstraint applies to
fvCellSet set_; fvCellSet set_;
@ -107,11 +109,14 @@ class massSource
HashPtrTable<unknownTypeFunction1> fieldValues_; HashPtrTable<unknownTypeFunction1> fieldValues_;
// Private Member Functions // Protected Member Functions
//- Non-virtual read //- Non-virtual read
void readCoeffs(); void readCoeffs();
//- Return the mass flow rate
virtual scalar massFlowRate() const;
// Sources // Sources
@ -164,7 +169,8 @@ public:
const word& name, const word& name,
const word& modelType, const word& modelType,
const fvMesh& mesh, const fvMesh& mesh,
const dictionary& dict const dictionary& dict,
const bool all=false
); );
//- Disallow default bitwise copy construction //- Disallow default bitwise copy construction

View File

@ -0,0 +1,130 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2021-2023 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 "zeroDimensionalMassSource.H"
#include "basicThermo.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
namespace Foam
{
namespace fv
{
defineTypeNameAndDebug(zeroDimensionalMassSource, 0);
addToRunTimeSelectionTable(fvModel, zeroDimensionalMassSource, dictionary);
}
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::fv::zeroDimensionalMassSource::readCoeffs()
{
const basicThermo& thermo =
mesh().lookupObject<basicThermo>
(
IOobject::groupName(physicalProperties::typeName, phaseName_)
);
rho0Ptr_.reset
(
new volScalarField::Internal
(
IOobject
(
typedName("rho0"),
mesh().time().timeName(),
mesh(),
IOobject::READ_IF_PRESENT,
IOobject::AUTO_WRITE
),
thermo.rho()().internalField()
)
);
}
Foam::scalar Foam::fv::zeroDimensionalMassSource::massFlowRate() const
{
const scalar t = mesh().time().userTimeValue();
const scalar t0 = mesh().time().beginTime().value();
const scalar mDot = massFlowRate_->value(t);
const scalar sumMDot = massFlowRate_->integral(t0, t);
const basicThermo& thermo =
mesh().lookupObject<basicThermo>
(
IOobject::groupName(physicalProperties::typeName, phaseName_)
);
return mDot*thermo.rho()()[0]/(rho0Ptr_()[0] + sumMDot/mesh().V()[0]);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fv::zeroDimensionalMassSource::zeroDimensionalMassSource
(
const word& name,
const word& modelType,
const fvMesh& mesh,
const dictionary& dict
)
:
massSource(name, modelType, mesh, dict, true),
rho0Ptr_()
{
if (mesh.nGeometricD() != 0)
{
FatalIOErrorInFunction(dict)
<< "Zero-dimensional fvModel applied to a "
<< mesh.nGeometricD() << "-dimensional mesh"
<< exit(FatalIOError);
}
readCoeffs();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fv::zeroDimensionalMassSource::read(const dictionary& dict)
{
if (fvModel::read(dict))
{
massSource::readCoeffs();
readCoeffs();
return true;
}
else
{
return false;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,135 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2021-2023 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/>.
Class
Foam::fv::zeroDimensionalMassSource
Description
This fvModel applies a mass source to the continuity equation and to all
field equations, in a zero-dimensional case. Correction is made to account
for the mass that exits the domain due to expansion in space, so that the
model correctly applies a total mass flow rate.
Usage
Example usage:
\verbatim
zeroDimensionalMassSource
{
type zeroDimensionalMassSource;
massFlowRate 1e-4;
fieldValues
{
U (10 0 0);
T 300;
k 0.375;
epsilon 14.855;
}
}
\endverbatim
Values should be provided for all solved for fields. Warnings will be
issued if values are not provided for fields for which transport equations
are solved. Warnings will also be issued if values are provided for fields
which are not solved for.
SourceFiles
zeroDimensionalMassSource.C
\*---------------------------------------------------------------------------*/
#ifndef zeroDimensionalMassSource_H
#define zeroDimensionalMassSource_H
#include "massSource.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fv
{
/*---------------------------------------------------------------------------*\
Class zeroDimensionalMassSource Declaration
\*---------------------------------------------------------------------------*/
class zeroDimensionalMassSource
:
public massSource
{
protected:
// Protected Data
//- Cached initial density field
autoPtr<volScalarField::Internal> rho0Ptr_;
// Protected Member Functions
//- Non-virtual read
void readCoeffs();
//- Return the mass flow rate
virtual scalar massFlowRate() const;
public:
//- Runtime type information
TypeName("zeroDimensionalMassSource");
// Constructors
//- Construct from explicit source name and mesh
zeroDimensionalMassSource
(
const word& name,
const word& modelType,
const fvMesh& mesh,
const dictionary& dict
);
// Member Functions
// IO
//- Read source dictionary
virtual bool read(const dictionary& dict);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fv
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -145,11 +145,15 @@ Foam::labelUList Foam::polyCellSet::identityMap(const label len) const
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::polyCellSet::polyCellSet Foam::polyCellSet::polyCellSet(const polyMesh& mesh)
( :
const polyMesh& mesh, mesh_(mesh),
const dictionary& dict selectionType_(selectionTypes::all),
) cellSetName_(word::null)
{}
Foam::polyCellSet::polyCellSet(const polyMesh& mesh, const dictionary& dict)
: :
mesh_(mesh), mesh_(mesh),
selectionType_(selectionTypes::all), selectionType_(selectionTypes::all),

View File

@ -131,12 +131,11 @@ public:
// Constructors // Constructors
//- Construct from mesh. Will select all.
polyCellSet(const polyMesh& mesh);
//- Construct from mesh and dictionary //- Construct from mesh and dictionary
polyCellSet polyCellSet(const polyMesh& mesh, const dictionary& dict);
(
const polyMesh& mesh,
const dictionary& dict
);
//- Destructor //- Destructor