diff --git a/src/fvOptions/constraints/derived/velocityDampingConstraint/velocityDampingConstraint.C b/src/fvOptions/constraints/derived/velocityDampingConstraint/velocityDampingConstraint.C index a2b92fefd4d24ca78410316619fe869c06a48715..03a7793d5b13a9b77306da47223abedd28cbc89e 100644 --- a/src/fvOptions/constraints/derived/velocityDampingConstraint/velocityDampingConstraint.C +++ b/src/fvOptions/constraints/derived/velocityDampingConstraint/velocityDampingConstraint.C @@ -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_); + return false; + } - coeffs_.readIfPresent("C", C_); + coeffs_.readEntry("UMax", UMax_); + coeffs_.readIfPresent("C", C_); - if (!coeffs_.readIfPresent("UNames", fieldNames_)) - { - fieldNames_.resize(1); - fieldNames_.first() = coeffs_.getOrDefault<word>("U", "U"); - } + if (!coeffs_.readIfPresent("UNames", fieldNames_)) + { + fieldNames_.resize(1); + fieldNames_.first() = coeffs_.getOrDefault<word>("U", "U"); + } + + fv::option::resetApplied(); - fv::option::resetApplied(); - return true; + if (canResetFile()) + { + resetFile(typeName); } - return false; + if (canWriteHeader()) + { + writeFileHeader(file()); + } + + + return true; } diff --git a/src/fvOptions/constraints/derived/velocityDampingConstraint/velocityDampingConstraint.H b/src/fvOptions/constraints/derived/velocityDampingConstraint/velocityDampingConstraint.H index b1f19730675f19c329345996829394c6a460b09b..463f821c8693701355210937b1e359749b74d071 100644 --- a/src/fvOptions/constraints/derived/velocityDampingConstraint/velocityDampingConstraint.H +++ b/src/fvOptions/constraints/derived/velocityDampingConstraint/velocityDampingConstraint.H @@ -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: diff --git a/src/fvOptions/corrections/limitTemperature/limitTemperature.C b/src/fvOptions/corrections/limitTemperature/limitTemperature.C index 1a8fad4b50331e15bc4072946aa922db2331c5f2..610413f5291900206a54fbcf468bcb907c4f4224 100644 --- a/src/fvOptions/corrections/limitTemperature/limitTemperature.C +++ b/src/fvOptions/corrections/limitTemperature/limitTemperature.C @@ -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_); + return false; + } - if (Tmax_ < Tmin_) - { - FatalIOErrorInFunction(dict) - << "Minimum temperature limit cannot exceed maximum limit" << nl - << "min = " << Tmin_ << nl - << "max = " << Tmax_ - << exit(FatalIOError); - } + coeffs_.readEntry("min", Tmin_); + coeffs_.readEntry("max", Tmax_); + coeffs_.readIfPresent("phase", phase_); - if (Tmin_ < 0) - { - FatalIOErrorInFunction(dict) - << "Minimum temperature limit cannot be negative" << nl - << "min = " << Tmin_ - << exit(FatalIOError); - } + 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; + // 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); } - return false; + 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()) diff --git a/src/fvOptions/corrections/limitTemperature/limitTemperature.H b/src/fvOptions/corrections/limitTemperature/limitTemperature.H index 8475bcfdda389c0713de1d5496017ebf6b0ca46a..8b4580925e7a13fea7f82a7ee7d4d4476e853613 100644 --- a/src/fvOptions/corrections/limitTemperature/limitTemperature.H +++ b/src/fvOptions/corrections/limitTemperature/limitTemperature.H @@ -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 diff --git a/src/fvOptions/corrections/limitVelocity/limitVelocity.C b/src/fvOptions/corrections/limitVelocity/limitVelocity.C index 7f0d4a6bf2944ac6051287cc35c7d2bff0a1a728..dc9aef66742428df1f2616e8efa978ed0ac59f68 100644 --- a/src/fvOptions/corrections/limitVelocity/limitVelocity.C +++ b/src/fvOptions/corrections/limitVelocity/limitVelocity.C @@ -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))) + { + return false; + } + + coeffs_.readEntry("max", max_); + coeffs_.readIfPresent("U", UName_); + + + fieldNames_.resize(1, UName_); + + fv::option::resetApplied(); + + + if (canResetFile()) { - coeffs_.readEntry("max", max_); + resetFile(typeName); + } - return true; + if (canWriteHeader()) + { + writeFileHeader(file()); } - return false; + + 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; + } } diff --git a/src/fvOptions/corrections/limitVelocity/limitVelocity.H b/src/fvOptions/corrections/limitVelocity/limitVelocity.H index 3002139fbd878334d48b85513e7e448bc5cbde04..d4ec6f2b67636d11f554e94c928644fac3b6df1f 100644 --- a/src/fvOptions/corrections/limitVelocity/limitVelocity.H +++ b/src/fvOptions/corrections/limitVelocity/limitVelocity.H @@ -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