Project 3- Adding a temperature dictionary to the incompressible icoFoam case to solve the energy equation
Project 3- To add a temperature dictionary to the incompressible icoFoam case to solve the energy equation and to test on the tutorial case.
The project report is written in the Latex format. The code of the same is as given below. Also the supporting images are given. The pdf file of the report is attached herewith.
Latex code:
\documentclass{article}
% Language setting
% Replace `english' with e.g. `spanish' to change the document language
\usepackage[english]{babel}
% Set page size and margins
% Replace `letterpaper' with`a4paper' for UK/EU standard size
\usepackage[letterpaper,top=2cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}
% Useful packages
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{subfigure}
\title{\textbf{Project-3:To add a temperature dictionary to the incompressible {\fontfamily{qcr}\selectfont icoFoam} solver to solve the energy equation}}
\author{Kavendra Ashokrao Thakare}
\begin{document}
\maketitle
\begin{abstract}
In this project we are going to add the temperature equation into the existing {\fontfamily{qcr}\selectfont icoFoam} solver and modify it into the {\fontfamily{qcr}\selectfont icoTempFoam}. Steps for the same are described here.
Then this {\fontfamily{qcr}\selectfont icoTempFoam} is tested on the modified tutorial case {\fontfamily{qcr}\selectfont cavityTemp}.The details of the modification of tutorial case are explained in this report.
The results of the successful implementation of the modified solver are presented.
\end{abstract}
\section{Introduction to the new solver {\fontfamily{qcr}\selectfont icoTempFoam}}
The {\fontfamily{qcr}\selectfont icoFoam} solver solves the incompressible flow equations for mass and momentum:
\begin{equation}
\nabla . U = 0
\end{equation}
\begin{equation}
\frac{\partial U}{\partial t} + \nabla . U = - \nabla p + \nabla.(\nu \nabla U) + g
\end{equation}
Our goal is to add an equation for temperature as:
\begin{equation}
\frac{\partial T}{\partial t} + (U.\nabla) T = \nabla.(\kappa \nabla T)
\end{equation}
where $\kappa $ is the heat diffusion coefficient,
\newline into the existing {\fontfamily{qcr}\selectfont icoFoam} solver which then will become the {\fontfamily{qcr}\selectfont icoTempFoam} solver, as the name suggests the temperature equations are added to the {\fontfamily{qcr}\selectfont icoFoam} solver.
\section{Steps in the creation \& compilation of the new solver \\{\fontfamily{qcr}\selectfont icoTempFoam} .}
\subsection{To copy and rename the files from existing {\fontfamily{qcr}\selectfont icoFoam} solver}
Copy the {\fontfamily{qcr}\selectfont icoFoam} solver source code from the {\fontfamily{qcr} \selectfont \$FOAM\_SOLVERS/incompressible/icoFoam} \newline using copy command to the {\fontfamily{qcr} \selectfont \$WM\_PROJECT\_USER\_DIR/my\_solvers}. \newline If {\fontfamily{qcr} \selectfont my\_solvers} directory is not already created then make it and proceed further i.e.
\newline
\newline {\fontfamily{qcr} \selectfont cd \$WM\_PROJECT\_USER\_DIR/my\_solvers}
\newline {\fontfamily{qcr} \selectfont cp -r \$FOAM\_SOLVERS/incompressible/icoFoam icoTempFoam}
\newline
\newline Rename the {\fontfamily{qcr}\selectfont icoFoam.C} file to the {\fontfamily{qcr}\selectfont icoTempFoam.C} by using rename command.
\newline {\fontfamily{qcr} \selectfont cd icoTempFoam}
\newline {\fontfamily{qcr} \selectfont mv icoFoam.C icoTempFoam.C}
\newline Keep the file {\fontfamily{qcr} \selectfont createFields.H} as it is.
\subsection{To modify the file {\fontfamily{qcr}\selectfont Make/files}}
Go to the {\fontfamily{qcr}\selectfont Make} directory and into the file {\fontfamily{qcr}\selectfont files} rename {\fontfamily{qcr}\selectfont icoFoam.C} to {\fontfamily{qcr}\selectfont icoTempFoam.C}.
\newline Also change the {\fontfamily{qcr}\selectfont EXE=\$(FOAM\_APPBIN)/icoFoam} to {\fontfamily{qcr}\selectfont EXE=\$(FOAM\_USER\_APPBIN)/icoTempFoam} as follows:
\begin{verbatim}
icoTempFoam.C
EXE = $(FOAM_USER_APPBIN)/icoTempFoam
\end{verbatim}
Do not make any changes to the {\fontfamily{qcr}\selectfont Make/options}.
\subsection{To add {\fontfamily{qcr}\selectfont fvScalarMatrix TEqn} into the {\fontfamily{qcr}\selectfont icoTempFoam.C}}
The {\fontfamily{qcr}\selectfont icoTempFoam.C} file is modified by adding the {\fontfamily{qcr}\selectfont fvScalarMatrix TEqn} into it. The modified file {\fontfamily{qcr}\selectfont icoTempFoam.C} is as follows:
\begin{verbatim}
\*---------------------------------------------------------------------------*/
#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(mesh.solver(p.select(piso.finalInnerIter())));
if (piso.finalNonOrthogonalIter())
{
phi = phiHbyA - pEqn.flux();
}
}
#include "continuityErrs.H"
U = HbyA - rAU*fvc::grad(p);
U.correctBoundaryConditions();
}
//Temperature equation
fvScalarMatrix TEqn
(
fvm::ddt(T)
+ fvm::div(phi, T)
- fvm::laplacian(kappa, T)
);
{
TEqn.solve();
T.correctBoundaryConditions();
}
runTime.write();
runTime.printExecutionTime(Info);
}
Info<< "End\n" << endl;
return 0;
}
// ************************************************************************* //
\end{verbatim}
\subsection{To add dictionary reader for kappa ($\kappa$) and IOobject for {\fontfamily{qcr}\selectfont volScalarField T} into the {\fontfamily{qcr}\selectfont createFields.H}}
To read the value of kappa ($\kappa$) from the {\fontfamily{qcr}\selectfont constant/transportProperties}, the entry of kappa is added below the entry of nu. Also, to read and write the vaue of {\fontfamily{qcr}\selectfont volScalarField T} the IOobject is written into the {\fontfamily{qcr}\selectfont createFields.H} as shown below:
\begin{verbatim}
Info<< "Reading transportProperties\n" << endl;
IOdictionary transportProperties
(
IOobject
( "transportProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
)
);
dimensionedScalar nu
(
"nu",
dimViscosity,
transportProperties
);
dimensionedScalar kappa
(
"kappa",
dimensionSet (0,2,-1,0,0,0,0),
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 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}
\subsection{Compilation of the newly modified {\fontfamily{qcr}\selectfont icoTempFoam} solver.}
The {\fontfamily{qcr}\selectfont icoTempFoam} solver is compiled by running the {\fontfamily{qcr}\selectfont wmake} command into the \\{\fontfamily{qcr}\selectfont \$WM\_PROJECT\_USER\_DIR/my\_solver/icoTempFoam} directory.
\\ The output message into the terminal after successful compilation of the solver is similar to the shown below in the figure.
\begin{figure}[h]
\centering
\includegraphics[width=\textwidth]{Compilation-message.png}
\caption{\label{fig:Compilation-message}The terminal output message for successful compilation of the{\fontfamily{qcr}\selectfont icoTempFoam} solver.}
\end{figure}
\subsection{To check the {\fontfamily{qcr}\selectfont icoTempFoam} solver in {\fontfamily{qcr}\selectfont \$FOAM\_USER\_APPBIN} }
The {\fontfamily{qcr}\selectfont \$FOAM\_USER\_APPBIN} directory is checked for the presence of newly compiled solver is compiled {\fontfamily{qcr}\selectfont icoTempFoam} by the command {\fontfamily{qcr}\selectfont cd \$FOAM\_USER\_APPBIN} as shown below in the figure.
\begin{figure}[h]
\centering
\includegraphics[scale=1]{UserAppBin.png}
\caption{\label{fig:\$FOAM\_USER\_APPBIN}The List of solvers in present the {\fontfamily{qcr}\selectfont \$FOAM\_USER\_APPBIN}}
\end{figure}
\newpage
\section{Steps to modify the {\fontfamily{qcr}\selectfont icoFoam/cavity/cavity} tutorial case \& to test it for the {\fontfamily{qcr}\selectfont icoTempFoam} solver .}
\subsection{To copy the existing tutorial case to {\fontfamily{qcr}\selectfont \$FOAM\_RUN} directory and rename it to {\fontfamily{qcr}\selectfont cavityTemp}}
To copy the tutorial case from existing {\fontfamily{qcr}\selectfont icoFoam/cavity/cavity} case to {\fontfamily{qcr}\selectfont \$FOAM\_RUN} directory and rename it to {\fontfamily{qcr}\selectfont cavityTemp}. The following sets of command are used.
\newline
\newline {\fontfamily{qcr} \selectfont cd \$FOAM\_RUN}
\newline {\fontfamily{qcr} \selectfont cp -r \$FOAM\_TUTORIALS/incompressible/icoFoam/cavity/cavity cavityTemp}
\newline
\newline Rename the {\fontfamily{qcr}\selectfont icoFoam.C} file to the {\fontfamily{qcr}\selectfont icoTempFoam.C} by using rename command.
\newline {\fontfamily{qcr} \selectfont cd icoTempFoam}
\newline {\fontfamily{qcr} \selectfont mv icoFoam.C icoTempFoam.C}
\newline Keep the file {\fontfamily{qcr} \selectfont createFields.H} as it is.
\subsection{To add the {\fontfamily{qcr}\selectfont 0/T} file to specify the initial and boundary conditions for Temperature.}
The {\fontfamily{qcr}\selectfont 0/p} file is copied and renamed as {\fontfamily{qcr}\selectfont 0/T}. The object entry is changed to {\fontfamily{qcr}\selectfont T} while dimensions of temperature are set as {\fontfamily{qcr}\selectfont [0 0 0 1 0 0 0]}. The {\fontfamily{qcr}\selectfont internalField} value is set to {\fontfamily{qcr}\selectfont uniform 300} and {\fontfamily{qcr}\selectfont boundaryField} type are changed to {\fontfamily{qcr}\selectfont fixedValue}. The details of the {\fontfamily{qcr}\selectfont 0/T} file are as given below.
\begin{verbatim}
\*---------------------------------------------------------------------------*/
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}
\newpage
\subsection {To add the {\fontfamily{qcr}\selectfont kappa} entry into the {\fontfamily{qcr}\selectfont constant/transportProperties}.}
The {\fontfamily{qcr}\selectfont constant/transportProperties} file is modified by adding the value of kappa as 0.001 . The details are as follows:
\begin{verbatim}
\*---------------------------------------------------------------------------*/
FoamFile
{ version 2.0;
format ascii;
class dictionary;
location "constant";
object transportProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
nu 0.01;
kappa [ 0 2 -1 0 0 0 0 ] 0.001;
// ************************************************************************* //
\end{verbatim}
\subsection{To change the solver name into the {\fontfamily{qcr}\selectfont system/controlDict} file.}
In the {\fontfamily{qcr}\selectfont systrm/controlDict} file the solver name is changed to {\fontfamily{qcr}\selectfont icoTempFoam}. The rest of the details are kept as it is except {\fontfamily{qcr}\selectfont endTime} which is increased to 1.
\begin{verbatim}
\*---------------------------------------------------------------------------*/
FoamFile
{ version 2.0;
format ascii;
class dictionary;
location "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application icoTempFoam;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 1;
deltaT 0.005;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //
\end{verbatim}
\subsection {To add the divergence and laplacian scheme for temperature into the {\fontfamily{qcr}\selectfont system/fvSchemes} file.}
To divergence scheme for temperature i.e. {\fontfamily{qcr}\selectfont div(phi, T) Gauss linear} is added into the list of divergence schemes whereas the laplacian scheme for temperature i.e. {\fontfamily{qcr}\selectfont laplacian(kappa, T) Gauss linear orthogonal} is added into the list of laplacian schemes into the {\fontfamily{qcr}\selectfont system/fvSchemes} file.
\begin{verbatim}
\*---------------------------------------------------------------------------*/
FoamFile
{ version 2.0;
format ascii;
class dictionary;
location "system";
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;
}
laplacianSchemes
{
default Gauss linear orthogonal;
laplacian(kappa,T) Gauss linear orthogonal;
}
interpolationSchemes
{
default linear;
}
snGradSchemes
{
default orthogonal;
}
// ************************************************************************* //
\end{verbatim}
\subsection{To add the solver settings for temperature in the {\fontfamily{qcr}\selectfont system/fvSolution} file }
The {\fontfamily{qcr}\selectfont smoothSolver} is set as solver for temperature into the {\fontfamily{qcr}\selectfont system/fvSolution} file as shown below.
\begin{verbatim}
\*---------------------------------------------------------------------------*/
FoamFile
{ version 2.0;
format ascii;
class dictionary;
location "system";
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
{
solver smoothSolver;
smoother GaussSeidel;
tolerance 1e-07;
relTol 0;
}
}
PISO
{
nCorrectors 2;
nNonOrthogonalCorrectors 0;
pRefCell 0;
pRefValue 0;
}
// ************************************************************************* //
\end{verbatim}
\subsection{To test the solver {\fontfamily{qcr}\selectfont icoTempFoam} by running it on the above modified {\fontfamily{qcr}\selectfont cavityTemp} tutorial case. }
Steps to solve the {\fontfamily{qcr}\selectfont cavityTemp} tutorial case with {\fontfamily{qcr}\selectfont icoTempFoam} solver are as follows
\begin{itemize}
\item Run {\fontfamily{qcr}\selectfont blockMesh} command to generate mesh.
\item Run {\fontfamily{qcr}\selectfont checkMesh} command to check generated mesh
\item Run {\fontfamily{qcr}\selectfont icoTempFoam} to solve the tutorial case.
\item Post-process the results in the {\fontfamily{qcr}\selectfont ParaView} using appropriate command.
\end{itemize}
The terminal output for solution with {\fontfamily{qcr}\selectfont icoTempFoam} is as given below.
\begin{verbatim}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time
Create mesh for time = 0
PISO: Operating solver in PISO mode
Reading transportProperties
Reading field p
Reading field U
Reading field T
Reading/calculating face flux field phi
Starting time loop
Time = 0.005
Courant Number mean: 0 max: 0
smoothSolver: Solving for Ux, Initial residual = 1, Final residual = 8.90511e-06, No Iterations 19
smoothSolver: Solving for Uy, Initial residual = 0, Final residual = 0, No Iterations 0
DICPCG: Solving for p, Initial residual = 1, Final residual = 0.0492854, No Iterations 12
time step continuity errors : sum local = 0.000466513, global = -1.79995e-19,
cumulative = -1.79995e-19
DICPCG: Solving for p, Initial residual = 0.590864, Final residual = 2.65225e-07, No Iterations 35
time step continuity errors : sum local = 2.74685e-09, global = -2.6445e-19,
cumulative = -4.44444e-19
smoothSolver: Solving for T, Initial residual = 1, Final residual = 4.36458e-08,
No Iterations 13
ExecutionTime = 0.01 s ClockTime = 0 s
Time = 0.01
Courant Number mean: 0.0976825 max: 0.585607
smoothSolver: Solving for Ux, Initial residual = 0.160686, Final residual = 6.83031e-06,
No Iterations 19
smoothSolver: Solving for Uy, Initial residual = 0.260828, Final residual = 9.65939e-06,
No Iterations 18
DICPCG: Solving for p, Initial residual = 0.428925, Final residual = 0.0103739, No Iterations 22
time step continuity errors : sum local = 0.000110788, global = 3.77194e-19,
cumulative = -6.72498e-20
DICPCG: Solving for p, Initial residual = 0.30209, Final residual = 5.26569e-07, No Iterations 33
time step continuity errors : sum local = 6.61987e-09, global = -2.74872e-19,
cumulative = -3.42122e-19
smoothSolver: Solving for T, Initial residual = 0.182558, Final residual = 5.62204e-08,
No Iterations 12
ExecutionTime = 0.01 s ClockTime = 0 s
...................
...................
Time = 1
Courant Number mean: 0.222159 max: 0.852134
smoothSolver: Solving for Ux, Initial residual = 2.58804e-08, Final residual = 2.58804e-08,
No Iterations 0
smoothSolver: Solving for Uy, Initial residual = 6.1466e-08, Final residual = 6.1466e-08,
No Iterations 0
DICPCG: Solving for p, Initial residual = 8.23011e-07, Final residual = 8.23011e-07,
No Iterations 0
time step continuity errors : sum local = 8.23402e-09, global = -2.52952e-19,
cumulative = 7.67715e-18
DICPCG: Solving for p, Initial residual = 1.01439e-06, Final residual = 2.01785e-07,
No Iterations 1
time step continuity errors : sum local = 3.13812e-09, global = 7.74406e-19,
cumulative = 8.45155e-18
smoothSolver: Solving for T, Initial residual = 0.000534862, Final residual = 3.18847e-08,
No Iterations 8
ExecutionTime = 0.15 s ClockTime = 0 s
End
\end{verbatim}
\newpage
\section{Results of the tutorial case {\fontfamily{qcr}\selectfont cavityTemp} for the test run of {\fontfamily{qcr}\selectfont icoTempFoam} solver}
\subsection{The initial \& final pressure contours}
\begin{figure}[h]
\centering
\includegraphics[scale=0.275]{P_initial.png}{ \label{fig:}}
\caption{Initial Pressure contours}
\end{figure}
\begin{figure}[h]
\centering
\includegraphics[scale=0.275]{P_final.png}{ \label{fig:}}
\caption{Final Pressure contours}
\end{figure}
\newpage
\subsection{The initial \& final velocity contours}
\begin{figure}[h]
\centering
\includegraphics[scale=0.275]{U_initial.png}{ \label{fig:}}
\caption{Initial Pressure contours}
\end{figure}
\begin{figure}[h]
\centering
\includegraphics[scale=0.275]{U_final.png}{ \label{fig:}}
\caption{Final Pressure contours}
\end{figure}
\newpage
\subsection{The initial \& final temperature contours}
\begin{figure}[h]
\centering
\includegraphics[scale=0.275]{T_initial.png}{ \label{fig:}}
\caption{Initial Pressure contours}
\end{figure}
\begin{figure}[h]
\centering
\includegraphics[scale=0.275]{T_final.png}{ \label{fig:}}
\caption{Final Pressure contours}
\end{figure}
\subsection{Observations \& Conclusion}
\begin{enumerate}
\item The Pressure and Velocity contours are similar to the results of {\fontfamily{qcr}\selectfont icoFoam/cavity/cavity} tutorial case, as expected.
\item The temperature contours show the sign of convection and diffusion as the temperature is more convected on the downstream side of the {\fontfamily{qcr}\selectfont movingWall} with respect to the upstream side. Also the temperature is slightly diffused to the sides and bottom.
\item Thus the we have successfully added the temperature equation to the {\fontfamily{qcr}\selectfont icoFoam} solver and successfully tested it on the test case {\fontfamily{qcr}\selectfont cavityTemp}.
\end{enumerate}
\end{document}
The supporting images are as follows:
- Compilation-message.png

- UserAppBin.png

- P_initial.png

- P_final.png

- U_initial.png

- U_final.png

- T_initial.png

- T_final.png

Thus the temperature equation is successfully added to the existing icoFoam solver and modified it to the icoTempFoam solver. Also it has been successfully tested on the test tutorial case cavityTemp.