Skip to content
Permalink
Browse files

functionObjects::age: add optinoal diffusion term and convergence con…

…trol

to enable the calculation of the residence time for a fluid; mainly used in HVAC
analysis. E.g. residence time of air inside a ventilated room, see the new
tutorial roomResidenceTime.

Contributed by Tobias Holzmann
  • Loading branch information...
Henry Weller
Henry Weller committed Oct 8, 2019
1 parent c8ab2a6 commit a2a74cbb7921c2e0de3e5aa1f319e5913b65e771
Showing with 1,064 additions and 31 deletions.
  1. +86 −23 src/functionObjects/field/age/age.C
  2. +16 −8 src/functionObjects/field/age/age.H
  3. +43 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/0/U
  4. +45 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/0/epsilon
  5. +45 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/0/k
  6. +44 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/0/nut
  7. +42 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/0/p
  8. +11 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/Allclean
  9. +16 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/Allrun
  10. +23 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/constant/transportProperties
  11. +30 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/constant/turbulenceProperties
  12. +28 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/system/age
  13. +240 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/system/blockMeshDict
  14. +53 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/system/controlDict
  15. +19 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/system/flowRatePatch
  16. +60 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/system/fvSchemes
  17. +72 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/system/fvSolution
  18. +50 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/system/probes1
  19. +50 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/system/probes2
  20. +2 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/validation/Allclean
  21. +37 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/validation/Allrun
  22. +12 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/validation/measurement_Pos1
  23. +10 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/validation/measurement_Pos2
  24. +15 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/validation/plotPos1Data.gplt
  25. +15 −0 tutorials/incompressible/simpleFoam/roomResidenceTime/validation/plotPos2Data.gplt
@@ -24,8 +24,9 @@ License
\*---------------------------------------------------------------------------*/

#include "age.H"
#include "fvmDdt.H"
#include "fvmDiv.H"
#include "fvmLaplacian.H"
#include "turbulenceModel.H"
#include "inletOutletFvPatchField.H"
#include "wallFvPatch.H"
#include "zeroGradientFvPatchField.H"
@@ -65,6 +66,26 @@ Foam::wordList Foam::functionObjects::age::patchTypes() const
}


bool Foam::functionObjects::age::converged
(
const int nCorr,
const scalar initialResidual
) const
{
if (initialResidual < tolerance_)
{
Info<< "Field " << typeName
<< " converged in " << nCorr << " correctors\n" << endl;

return true;
}
else
{
return false;
}
}


// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

Foam::functionObjects::age::age
@@ -74,12 +95,7 @@ Foam::functionObjects::age::age
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict),
phiName_(),
rhoName_(),
nCorr_(0),
schemesField_()

fvMeshFunctionObject(name, runTime, dict)
{
read(dict);
}
@@ -97,10 +113,10 @@ bool Foam::functionObjects::age::read(const dictionary& dict)
{
phiName_ = dict.lookupOrDefault<word>("phi", "phi");
rhoName_ = dict.lookupOrDefault<word>("rho", "rho");

dict.readIfPresent("nCorr", nCorr_);

nCorr_ = dict.lookupOrDefault<int>("nCorr", 5);
schemesField_ = dict.lookupOrDefault<word>("schemesField", typeName);
diffusion_ = dict.lookupOrDefault<Switch>("diffusion", false);
tolerance_ = dict.lookupOrDefault<scalar>("tolerance", 1e-5);

return true;
}
@@ -114,7 +130,7 @@ bool Foam::functionObjects::age::execute()

bool Foam::functionObjects::age::write()
{
volScalarField t
volScalarField age
(
IOobject
(
@@ -152,36 +168,83 @@ bool Foam::functionObjects::age::write()
const volScalarField& rho =
mesh_.lookupObject<volScalarField>(rhoName_);

for (label i = 0; i <= nCorr_; ++ i)
tmp<volScalarField> tmuEff;
word laplacianScheme;

if (diffusion_)
{
tmuEff =
mesh_.lookupObject<turbulenceModel>
(
turbulenceModel::propertiesName
).muEff();

laplacianScheme =
"laplacian(" + tmuEff().name() + ',' + schemesField_ + ")";
}

for (int i=0; i<=nCorr_; i++)
{
fvScalarMatrix tEqn
fvScalarMatrix ageEqn
(
fvm::div(phi, t, divScheme) == rho
fvm::div(phi, age, divScheme) == rho
);

tEqn.relax(relaxCoeff);
if (diffusion_)
{
ageEqn -= fvm::laplacian(tmuEff(), age, laplacianScheme);
}

tEqn.solve(schemesField_);
ageEqn.relax(relaxCoeff);

if (converged(i, ageEqn.solve(schemesField_).initialResidual()))
{
break;
};
}
}
else
{
for (label i = 0; i <= nCorr_; ++ i)
tmp<volScalarField> tnuEff;
word laplacianScheme;

if (diffusion_)
{
tnuEff =
mesh_.lookupObject<turbulenceModel>
(
turbulenceModel::propertiesName
).nuEff();

laplacianScheme =
"laplacian(" + tnuEff().name() + ',' + schemesField_ + ")";
}

for (int i=0; i<=nCorr_; i++)
{
fvScalarMatrix tEqn
fvScalarMatrix ageEqn
(
fvm::div(phi, t, divScheme) == dimensionedScalar(1)
fvm::div(phi, age, divScheme) == dimensionedScalar(1)
);

tEqn.relax(relaxCoeff);
if (diffusion_)
{
ageEqn -= fvm::laplacian(tnuEff(), age, laplacianScheme);
}

ageEqn.relax(relaxCoeff);

tEqn.solve(schemesField_);
if (converged(i, ageEqn.solve(schemesField_).initialResidual()))
{
break;
}
}
}

Info<< "Min/max age:" << min(t).value() << ' ' << max(t).value() << endl;
Info<< "Min/max age:" << min(age).value()
<< ' ' << max(age).value() << endl;

t.write();
age.write();

return true;
}
@@ -40,12 +40,14 @@ Description
Usage
\table
Property | Description | Required | Default value
phi | The name of the flux field | no | phi
rho | The name of the density field | no | rho
nCorr | The number of correctors | no | 0
Property | Description | Required | Default value
phi | The name of the flux field | no | phi
rho | The name of the density field | no | rho
nCorr | The maximum number of correctors | no | 5
schemesField | The name of the field from which schemes are taken | \\
no | age
diffusion | Switch to turn on/off the diffusion term | no | off
tolerance | Solver residual control | no | 1e-5
\endtable
\verbatim
@@ -57,9 +59,6 @@ Usage
writeControl writeTime;
writeInterval 1;
phi phi;
rho rho;
nCorr 10;
schemesField k;
}
\endverbatim
@@ -99,17 +98,26 @@ class age
word rhoName_;

//- Number of corrections
label nCorr_;
int nCorr_;

//- Name of field from which schemes are taken
word schemesField_;

//- Switch to turn on/off the diffusion term
Switch diffusion_;

//- Convergence tolerance
scalar tolerance_;


// Private Member Functions

//- The list of patch types for the age field
wordList patchTypes() const;

//- Check convergence
bool converged(const int nCorr, const scalar initialResidual) const;


public:

@@ -0,0 +1,43 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volVectorField;
location "0";
object U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions [0 1 -1 0 0 0 0];

internalField uniform (0 0 0);

boundaryField
{
walls
{
type noSlip;
}

inlet
{
type fixedValue;
value uniform (1.68 0 0);
}

outlet
{
type pressureInletOutletVelocity;
value uniform (0 0 0);
}
}


// ************************************************************************* //
@@ -0,0 +1,45 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
location "0";
object epsilon;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions [0 2 -3 0 0 0 0];

internalField uniform 0.23;

boundaryField
{
walls
{
type epsilonWallFunction;
value $internalField;
}

inlet
{
type turbulentMixingLengthDissipationRateInlet;
mixingLength 0.0168;
value $internalField;
}

outlet
{
type inletOutlet;
inletValue $internalField;
}
}


// ************************************************************************* //
@@ -0,0 +1,45 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
location "0";
object k;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions [0 2 -2 0 0 0 0];

internalField uniform 8e-2;

boundaryField
{
walls
{
type kqRWallFunction;
value $internalField;
}

inlet
{
type turbulentIntensityKineticEnergyInlet;
intensity 0.14;
value $internalField;
}

outlet
{
type inletOutlet;
inletValue $internalField;
}
}


// ************************************************************************* //

0 comments on commit a2a74cb

Please sign in to comment.
You can’t perform that action at this time.