ENH: fvOptions: add writeFile functionality

- velocityDampingConstraint
- limitTemperature
- limitVelocity
This commit is contained in:
Kutalmis Bercin
2022-11-23 15:43:16 +00:00
committed by Andrew Heather
parent 4c8fc9dc6e
commit 48f8680941
6 changed files with 250 additions and 87 deletions

View File

@ -49,7 +49,7 @@ namespace fv
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::fv::velocityDampingConstraint::addDamping(fvMatrix<vector>& eqn)
{
@ -89,10 +89,35 @@ void Foam::fv::velocityDampingConstraint::addDamping(fvMatrix<vector>& eqn)
return (denom ? 1e-2*round(1e4*num/denom) : 0);
};
const scalar nDampedPercent = percent(nDamped, nTotCells);
Info<< type() << ' ' << name_ << " damped "
<< nDamped << " ("
<< percent(nDamped, nTotCells)
<< nDampedPercent
<< "%) of cells, with max limit " << UMax_ << endl;
if (canWriteToFile())
{
file()
<< mesh_.time().timeOutputValue() << token::TAB
<< nDamped << token::TAB
<< nDampedPercent
<< endl;
}
}
void Foam::fv::velocityDampingConstraint::writeFileHeader(Ostream& os)
{
writeHeaderValue(os, "UMax", Foam::name(UMax_));
writeCommented(os, "Time");
writeTabbed(os, "nDamped_[count]");
writeTabbed(os, "nDamped_[%]");
os << endl;
writtenHeader_ = true;
}
@ -107,6 +132,8 @@ Foam::fv::velocityDampingConstraint::velocityDampingConstraint
)
:
fv::cellSetOption(name, modelType, dict, mesh),
writeFile(mesh, name, typeName, dict, false),
UMax_(GREAT), // overwritten later
C_(1)
{
read(dict);
@ -133,24 +160,35 @@ void Foam::fv::velocityDampingConstraint::writeData(Ostream& os) const
bool Foam::fv::velocityDampingConstraint::read(const dictionary& dict)
{
if (fv::cellSetOption::read(dict))
if (!(fv::cellSetOption::read(dict) && writeFile::read(dict)))
{
coeffs_.readEntry("UMax", UMax_);
coeffs_.readIfPresent("C", C_);
if (!coeffs_.readIfPresent("UNames", fieldNames_))
{
fieldNames_.resize(1);
fieldNames_.first() = coeffs_.getOrDefault<word>("U", "U");
}
fv::option::resetApplied();
return true;
return false;
}
return false;
coeffs_.readEntry("UMax", UMax_);
coeffs_.readIfPresent("C", C_);
if (!coeffs_.readIfPresent("UNames", fieldNames_))
{
fieldNames_.resize(1);
fieldNames_.first() = coeffs_.getOrDefault<word>("U", "U");
}
fv::option::resetApplied();
if (canResetFile())
{
resetFile(typeName);
}
if (canWriteHeader())
{
writeFileHeader(file());
}
return true;
}

View File

@ -85,8 +85,9 @@ Usage
\endtable
The inherited entries are elaborated in:
- \link fvOption.H \endlink
- \link cellSetOption.H \endlink
- \link fvOption.H \endlink
- \link cellSetOption.H \endlink
- \link writeFile.H \endlink
Note
- When active, this constraint manipulates the system of equations.
@ -102,10 +103,11 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef velocityDampingConstraint_H
#define velocityDampingConstraint_H
#ifndef fv_velocityDampingConstraint_H
#define fv_velocityDampingConstraint_H
#include "cellSetOption.H"
#include "writeFile.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -120,7 +122,8 @@ namespace fv
class velocityDampingConstraint
:
public fv::cellSetOption
public fv::cellSetOption,
public functionObjects::writeFile
{
protected:
@ -138,6 +141,9 @@ protected:
//- Constrain the given velocity fields by a given maximum value
void addDamping(fvMatrix<vector>& eqn);
//- Write file header information
void writeFileHeader(Ostream& os);
public:

View File

@ -43,6 +43,24 @@ namespace fv
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::fv::limitTemperature::writeFileHeader(Ostream& os)
{
writeHeaderValue(os, "Tmin", Foam::name(Tmin_));
writeHeaderValue(os, "Tmax", Foam::name(Tmax_));
writeCommented(os, "Time");
writeTabbed(os, "nDampedCellsMin_[count]");
writeTabbed(os, "nDampedCellsMin_[%]");
writeTabbed(os, "nDampedCellsMax_[count]");
writeTabbed(os, "nDampedCellsMax_[%]");
os << endl;
writtenHeader_ = true;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fv::limitTemperature::limitTemperature
@ -54,23 +72,14 @@ Foam::fv::limitTemperature::limitTemperature
)
:
fv::cellSetOption(name, modelType, dict, mesh),
Tmin_(coeffs_.get<scalar>("min")),
Tmax_(coeffs_.get<scalar>("max")),
phase_(coeffs_.getOrDefault<word>("phase", word::null))
writeFile(mesh, name, typeName, dict, false),
Tmin_(0),
Tmax_(0),
phase_(word::null)
{
if (isActive())
{
// Set the field name to that of the energy
// field from which the temperature is obtained
const auto& thermo =
mesh_.lookupObject<basicThermo>
(
IOobject::groupName(basicThermo::dictName, phase_)
);
fieldNames_.resize(1, thermo.he().name());
fv::option::resetApplied();
read(dict);
}
}
@ -79,32 +88,57 @@ Foam::fv::limitTemperature::limitTemperature
bool Foam::fv::limitTemperature::read(const dictionary& dict)
{
if (fv::cellSetOption::read(dict))
if (!(fv::cellSetOption::read(dict) && writeFile::read(dict)))
{
coeffs_.readEntry("min", Tmin_);
coeffs_.readEntry("max", Tmax_);
if (Tmax_ < Tmin_)
{
FatalIOErrorInFunction(dict)
<< "Minimum temperature limit cannot exceed maximum limit" << nl
<< "min = " << Tmin_ << nl
<< "max = " << Tmax_
<< exit(FatalIOError);
}
if (Tmin_ < 0)
{
FatalIOErrorInFunction(dict)
<< "Minimum temperature limit cannot be negative" << nl
<< "min = " << Tmin_
<< exit(FatalIOError);
}
return true;
return false;
}
return false;
coeffs_.readEntry("min", Tmin_);
coeffs_.readEntry("max", Tmax_);
coeffs_.readIfPresent("phase", phase_);
if (Tmax_ < Tmin_)
{
FatalIOErrorInFunction(dict)
<< "Minimum temperature limit cannot exceed maximum limit" << nl
<< "min = " << Tmin_ << nl
<< "max = " << Tmax_
<< exit(FatalIOError);
}
if (Tmin_ < 0)
{
FatalIOErrorInFunction(dict)
<< "Minimum temperature limit cannot be negative" << nl
<< "min = " << Tmin_
<< exit(FatalIOError);
}
// Set the field name to that of the energy
// field from which the temperature is obtained
const auto& thermo =
mesh_.lookupObject<basicThermo>
(
IOobject::groupName(basicThermo::dictName, phase_)
);
fieldNames_.resize(1, thermo.he().name());
fv::option::resetApplied();
if (canResetFile())
{
resetFile(typeName);
}
if (canWriteHeader())
{
writeFileHeader(file());
}
return true;
}
@ -162,18 +196,33 @@ void Foam::fv::limitTemperature::correct(volScalarField& he)
return (denom ? 1e-2*round(1e4*num/denom) : 0);
};
const scalar nBelowMinPercent = percent(nBelowMin, nTotCells);
const scalar nAboveMaxPercent = percent(nAboveMax, nTotCells);
Info<< type() << ' ' << name_ << " Lower limited " << nBelowMin << " ("
<< percent(nBelowMin, nTotCells)
<< nBelowMinPercent
<< "%) of cells, with min limit " << Tmin_ << endl;
Info<< type() << ' ' << name_ << " Upper limited " << nAboveMax << " ("
<< percent(nAboveMax, nTotCells)
<< nAboveMaxPercent
<< "%) of cells, with max limit " << Tmax_ << endl;
Info<< type() << ' ' << name_ << " Unlimited Tmin " << Tmin0 << endl;
Info<< type() << ' ' << name_ << " Unlimited Tmax " << Tmax0 << endl;
if (canWriteToFile())
{
file()
<< mesh_.time().timeOutputValue() << token::TAB
<< nBelowMin << token::TAB
<< nBelowMinPercent << token::TAB
<< nAboveMax << token::TAB
<< nAboveMaxPercent
<< endl;
}
// Handle boundaries in the case of 'all'
bool changedValues = (nBelowMin || nAboveMax);
if (!cellSetOption::useSubMesh())

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -75,8 +75,9 @@ Usage
\endtable
The inherited entries are elaborated in:
- \link fvOption.H \endlink
- \link cellSetOption.H \endlink
- \link fvOption.H \endlink
- \link cellSetOption.H \endlink
- \link writeFile.H \endlink
See also
- Foam::fv::fixedTemperatureConstraint
@ -86,10 +87,11 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef limitTemperature_H
#define limitTemperature_H
#ifndef fv_limitTemperature_H
#define fv_limitTemperature_H
#include "cellSetOption.H"
#include "writeFile.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -99,12 +101,13 @@ namespace fv
{
/*---------------------------------------------------------------------------*\
Class limitTemperature Declaration
Class limitTemperature Declaration
\*---------------------------------------------------------------------------*/
class limitTemperature
:
public fv::cellSetOption
public fv::cellSetOption,
public functionObjects::writeFile
{
protected:
@ -116,10 +119,16 @@ protected:
//- Maximum temperature limit [K]
scalar Tmax_;
//- Optional phase name [K]
//- Optional phase name
word phase_;
// Protected Member Functions
//- Write file header information
void writeFileHeader(Ostream& os);
public:
//- Runtime type information

View File

@ -42,6 +42,23 @@ namespace fv
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::fv::limitVelocity::writeFileHeader(Ostream& os)
{
writeHeaderValue(os, "UMax", Foam::name(max_));
writeCommented(os, "Time");
writeTabbed(os, "nDampedCells_[count]");
writeTabbed(os, "nDampedCells_[%]");
writeTabbed(os, "nDampedFaces_[count]");
writeTabbed(os, "nDampedFaces_[%]");
os << endl;
writtenHeader_ = true;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fv::limitVelocity::limitVelocity
@ -53,11 +70,11 @@ Foam::fv::limitVelocity::limitVelocity
)
:
fv::cellSetOption(name, modelType, dict, mesh),
UName_(coeffs_.getOrDefault<word>("U", "U")),
max_(coeffs_.get<scalar>("max"))
writeFile(mesh, name, typeName, dict, false),
UName_(word::null),
max_(0)
{
fieldNames_.resize(1, UName_);
fv::option::resetApplied();
read(dict);
}
@ -65,14 +82,32 @@ Foam::fv::limitVelocity::limitVelocity
bool Foam::fv::limitVelocity::read(const dictionary& dict)
{
if (fv::cellSetOption::read(dict))
if (!(fv::cellSetOption::read(dict) && writeFile::read(dict)))
{
coeffs_.readEntry("max", max_);
return true;
return false;
}
return false;
coeffs_.readEntry("max", max_);
coeffs_.readIfPresent("U", UName_);
fieldNames_.resize(1, UName_);
fv::option::resetApplied();
if (canResetFile())
{
resetFile(typeName);
}
if (canWriteHeader())
{
writeFileHeader(file());
}
return true;
}
@ -137,19 +172,24 @@ void Foam::fv::limitVelocity::correct(volVectorField& U)
reduce(nCellsAbove, sumOp<label>());
const scalar nCellsAbovePercent = percent(nCellsAbove, nTotCells);
// Report total numbers and percent
Info<< type() << ' ' << name_ << " Limited ";
Info<< nCellsAbove << " ("
<< percent(nCellsAbove, nTotCells)
<< nCellsAbovePercent
<< "%) of cells";
reduce(nTotFaces, sumOp<label>());
reduce(nFacesAbove, sumOp<label>());
scalar nFacesAbovePercent(0);
if (nTotFaces)
{
nFacesAbovePercent = percent(nFacesAbove, nTotFaces);
Info<< ", " << nFacesAbove << " ("
<< percent(nFacesAbove, nTotFaces)
<< nFacesAbovePercent
<< "%) of faces";
}
Info<< ", with max limit " << max_ << endl;
@ -160,6 +200,18 @@ void Foam::fv::limitVelocity::correct(volVectorField& U)
// boundary conditions opportunity to correct
U.correctBoundaryConditions();
}
if (canWriteToFile())
{
file()
<< mesh_.time().timeOutputValue() << token::TAB
<< nCellsAbove << token::TAB
<< nCellsAbovePercent << token::TAB
<< nFacesAbove << token::TAB
<< nFacesAbovePercent
<< endl;
}
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -69,8 +69,9 @@ Usage
\endtable
The inherited entries are elaborated in:
- \link fvOption.H \endlink
- \link cellSetOption.H \endlink
- \link fvOption.H \endlink
- \link cellSetOption.H \endlink
- \link writeFile.H \endlink
See also
- Foam::fv::velocityDampingConstraint
@ -80,10 +81,11 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef limitVelocity_H
#define limitVelocity_H
#ifndef fv_limitVelocity_H
#define fv_limitVelocity_H
#include "cellSetOption.H"
#include "writeFile.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -93,12 +95,13 @@ namespace fv
{
/*---------------------------------------------------------------------------*\
Class limitVelocity Declaration
Class limitVelocity Declaration
\*---------------------------------------------------------------------------*/
class limitVelocity
:
public fv::cellSetOption
public fv::cellSetOption,
public functionObjects::writeFile
{
protected:
@ -111,6 +114,12 @@ protected:
scalar max_;
// Protected Member Functions
//- Write file header information
void writeFileHeader(Ostream& os);
public:
//- Runtime type information