Project 3- Adding a temperature dictionary to the incompressible icoFoam case to solve the energy equation
The Latex code :
\documentclass{report}
\usepackage{graphicx} % Required for inserting images
\title{Project 3}
\author{Thomas Abraham}
\date{July 2024}
\begin{document}
\maketitle
\section{Obective}
The objective of this challenge is make changes to the ``icoFoam" solver such that it also solves for the Temperature diffusion equation along with the momentum diffusion equation.
\begin{equation} \label{eqn:Temperature Diffusion Equation to be solved by the modified solver.}
\frac{\partial \rho U}{\partial t }+(U \cdot \nabla)T=\kappa \nabla^2 T
\end{equation}
Here, "$\kappa$" is the heat diffusion coefficient.
\section{Procedure for compiling the new solver}
The \verb|"icoFoam"| solver was copied over from \verb|"$FOAM_SOLVERS/incompressible/icoFoam"| and was renamed \verb|"project_3"|.
\\
The \verb|"icoFoam.C"| name was changed to \verb|"icoTempFoam.C"| using the \verb|"mv"| command.
In this \verb|".C"| file, a new \verb|"fvScalarMatrix"| matrix was defined for solving the temperature equation. This was named \verb|"TEqn"|.
The \verb|"solve()"| function was to be run on this matrix.
\\
In the \verb|"createFields.H"| file, a new \verb|"dimensionedScalar"| for ``$\kappa$" was created such that it could be read from the ``transportProperties'' dictionary file. The ``IOdictionary object was already conveniently defined in the original ``createFields.H" file.
A ``VolScalarField T" also had to be defined in the ``createFields.H" to create the scalar field for temperature. The constructor of the ``volScalarField T'' was written with an ``IOobject" nested in it so as to enable the memory management of this newly created field which is vital for running any simulation that now involved ``T".
\\
In ``Make/files", appropriate changes were made so that the executable was created from the ``icoTempFoam.C" file and would be created in the \verb|"$FOAM_USER_APPBIN"| with the name ``icoTempFoam".
\\
The solver was compiled by running the ``wmake" command.
\section{Procedure for preparing and running the case}
The \verb|"FOAM_TUTORIALS/incompressible/icoFoam/cavity/cavity"| tutorial was copied into the run folder and under the name ``cavityTemp".
\\
The dictionary file ``transportProperties" was modified to also include ``k'' along with ``nu".
The ``\verb|0/p|" was copied into a new file under the name ``T" and modifications were made so that this file detailed the initial conditions of the temperature profile as detailed in the challenge. In the ``fvSchemes" file, a divergence scheme for ``\verb|div(phi,T)|'' was specified as ``Gauss linear".In the ``fvSolutions" file, a ``smoothSolver" with the smoother as ``symGaussSeidel" was defined for solving ``T" with the tolerance criteria given in the problem statement of the challenge.
\\
In the ``controlDict" file, the application was changed to ``icoTempFoam" from ``icoFoam".
\\
This concludes the case preparation. ``blockMesh" and ``icoTempFoam" command were sequentially run to perform the simulation.
\section{Results and Plots}
The resulting temperature contour:
\\
\includegraphics[scale=0.5]{tempProfile.png}
\section{Codes of the relevant files in the solver compilation}
\verb|icoTempFoam.C|:
\begin{verbatim}
/*---------------------------------------------------------------------------*\
========= |
\\ / 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) 2019 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 <http://www.gnu.org/licenses/>.
Application
icoFoam
Group
grpIncompressibleSolvers
Description
Transient solver for incompressible, laminar flow of Newtonian fluids.
\heading Solver details
The solver uses the PISO algorithm to solve the continuity equation:
\f[
\div \vec{U} = 0
\f]
and momentum equation:
\f[
\ddt{\vec{U}}
+ \div \left( \vec{U} \vec{U} \right)
- \div \left(\nu \grad \vec{U} \right)
= - \grad p
\f]
Where:
\vartable
\vec{U} | Velocity
p | Pressure
\endvartable
\heading Required fields
\plaintable
U | Velocity [m/s]
p | Kinematic pressure, p/rho [m2/s2]
\endplaintable
\*---------------------------------------------------------------------------*/
#include "fvCFD.H"
#include "pisoControl.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
argList::addNote(
"Transient solver for incompressible, laminar flow"
" of Newtonian fluids.");
#include "postProcess.H"
#include "addCheckCaseOptions.H"
#include "setRootCaseLists.H"
#include "createTime.H"
#include "createMesh.H"
pisoControl piso(mesh);
#include "createFields.H"
#include "initContinuityErrs.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Info << "\nStarting time loop\n"
<< endl;
while (runTime.loop())
{
Info << "Time = " << runTime.timeName() << nl << endl;
#include "CourantNo.H"
// Momentum predictor
fvVectorMatrix UEqn(
fvm::ddt(U) + fvm::div(phi, U) - fvm::laplacian(nu, U));
if (piso.momentumPredictor())
{
solve(UEqn == -fvc::grad(p));
}
// --- PISO loop
while (piso.correct())
{
volScalarField rAU(1.0 / UEqn.A());
volVectorField HbyA(constrainHbyA(rAU * UEqn.H(), U, p));
surfaceScalarField phiHbyA(
"phiHbyA",
fvc::flux(HbyA) + fvc::interpolate(rAU) * fvc::ddtCorr(U, phi));
adjustPhi(phiHbyA, U, p);
// Update the pressure BCs to ensure flux consistency
constrainPressure(p, U, phiHbyA, rAU);
// Non-orthogonal pressure corrector loop
while (piso.correctNonOrthogonal())
{
// Pressure corrector
fvScalarMatrix pEqn(
fvm::laplacian(rAU, p) == fvc::div(phiHbyA));
pEqn.setReference(pRefCell, pRefValue);
pEqn.solve(p.select(piso.finalInnerIter()));
if (piso.finalNonOrthogonalIter())
{
phi = phiHbyA - pEqn.flux();
}
}
#include "continuityErrs.H"
U = HbyA - rAU * fvc::grad(p);
U.correctBoundaryConditions();
}
// fvScalarMatrix for temperature:
fvScalarMatrix TEqn(
fvm::ddt(T) // Momentum diffusion equation adapted for temperature.
+ fvm::div(phi, T) - fvm::laplacian(k, T)
);
solve(TEqn); // to solve for TEqn...
runTime.write();
runTime.printExecutionTime(Info);
}
Info << "End\n"
<< endl;
return 0;
}
// ************************************************************************* //
\end{verbatim}
\\
\\
\verb|createFields.H|:
\begin{verbatim}
Info << "Reading transportProperties\n"
<< endl;
IOdictionary transportProperties // IOobject to read transport properties... (already in the file)
(
IOobject(
"transportProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE));
dimensionedScalar nu(
"nu",
dimViscosity,
transportProperties);
dimensionedScalar k // defined to read k from transportproperties Dictionary file
(
"k", // What to read
dimensionSet(0, 2, -1, 0, 0, 0, 0), // defining the dimensions of thermal diffusivity
transportProperties // which dictionary to read from... requires IOobject transportproperties.
);
Info << "Reading field p\n"
<< endl;
volScalarField p(
IOobject(
"p",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE),
mesh);
Info << "Reading field U\n"
<< endl;
volVectorField U(
IOobject(
"U",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE),
mesh);
Info << "Reading scalar field T\n"
<< endl;
volScalarField T(
IOobject(
"T",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE),
mesh);
#include "createPhi.H"
label pRefCell = 0;
scalar pRefValue = 0.0;
setRefCell(p, mesh.solutionDict().subDict("PISO"), pRefCell, pRefValue);
mesh.setFluxRequired(p.name());
\end{verbatim}
\\
\\
Make/files:
\begin{verbatim}
icoTempFoam.C
EXE = $(FOAM_USER_APPBIN)/icoTempFoam
\end{verbatim}
\section{Codes of the relevant files for the case preparation}
\verb|0/T|:
\begin{verbatim}
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2312 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
object T;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 0 0 1 0 0 0];
internalField uniform 300;
boundaryField
{
movingWall
{
type fixedValue;
value uniform 400;
}
fixedWalls
{
type fixedValue;
value uniform 300;
}
frontAndBack
{
type empty;
}
}
// ************************************************************************* //
\end{verbatim}
\\
\\
transportProperties:
\begin{verbatim}
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2312 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object transportProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
nu 0.01;
k [0 2 -1 0 0 0 0] 0.001;
// ************************************************************************* //
\end{verbatim}
\\
\\
fvSchemes:
\begin{verbatim}
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2312 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object fvSchemes;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
ddtSchemes
{
default Euler;
}
gradSchemes
{
default Gauss linear;
grad(p) Gauss linear;
}
divSchemes
{
default none;
div(phi,U) Gauss linear;
div(phi,T) Gauss linear; //added div scheme for Temp.
}
laplacianSchemes
{
default Gauss linear orthogonal;
}
interpolationSchemes
{
default linear;
}
snGradSchemes
{
default orthogonal;
}
// ************************************************************************* //
\end{verbatim}
\\
\\
fvSolutions:
\begin{verbatim}
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2312 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object fvSolution;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
solvers
{
p
{
solver PCG;
preconditioner DIC;
tolerance 1e-06;
relTol 0.05;
}
pFinal
{
$p;
relTol 0;
}
U
{
solver smoothSolver;
smoother symGaussSeidel;
tolerance 1e-05;
relTol 0;
}
T //smooth solver added for temperature...
{
solver smoothSolver;
smoother symGaussSeidel;
tolerance 1e-07;
relTol 0;
}
}
PISO
{
nCorrectors 2;
nNonOrthogonalCorrectors 0;
pRefCell 0;
pRefValue 0;
}
// ************************************************************************* //
\end{verbatim}
\\
\\
controlDict:
\begin{verbatim}
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2312 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application icoTempFoam; //changed from icoFoam...
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 0.5;
deltaT 0.005;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //
\end{verbatim}
\end{document}