\documentclass[12pt]{report}
\usepackage{parskip}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{amsmath,amssymb,amsthm}
%\usepackage{physics}
\usepackage[utf8]{inputenc}
\usepackage[a4paper, total={6.5in, 9.8in}]{geometry}
\title{Adding a temperature dictionary to the incompressible icoFoam case to solve the energy equation}
\author{Kawal Thakur}
\usepackage{sectsty}
\sectionfont{\fontsize{15}{15}\selectfont}
\subsectionfont{\fontsize{14}{14}\selectfont}
\begin{document}
\maketitle
\section*{Aim}
To add the functionality to solve for the equation of temperature in an icoFoam solver which otherwise solves for the mass and momentum equation given by
\\
\begin{center}
$\nabla\cdot\boldsymbol{U} = 0$
\[\frac{\partial \boldsymbol{U}}{\partial t} + \nabla\cdot\boldsymbol{UU} = -\nabla p + \nabla\cdot(\nu\nabla\boldsymbol{U})+g\]
\end{center}
We need to add the equation for temperature \verb!T! as
\begin{center}
\[\frac{\partial T}{\partial t} + (\boldsymbol{U}\cdot\nabla)T = \kappa\nabla^{2}T\]
\end{center}
where $\kappa$ is the heat diffusion coefficient.
\section*{Objectives}
\begin{itemize}
\item{Creating an IOobject for temperature \verb!T! as a \verb!volScalarField! }
\item{Creating a dimenioned Scalar $\kappa$ as an IOobject and creating an entry for it in the dictionary}
\item{Adding the equations for calculating temperature in the solver .C file}
\item{Running the solver}
\end{itemize}
\section*{Procedure}
\subsection*{Copying tutorial case from incompressible/icoFoam/cavity/cavity}
Here we use the tutorial case from the incompressible/icoFoam/cavity/cavity where we change the necessary files to run our case. For this we follow the commands below
\\\\
\verb!>> tut!
\\\\
\verb!>> cp incompressible/icoFoam/cavity/cavity $FOAM_RUN/openfoam-cases/cavity!
\subsection*{Copying the source-code of icoFoam solver to application folder in user directory}
Since we need to modify the source code of the icoFoam solver it is recommended to make changes with the source code copied in the user directory
\\\\
\verb!>> sol!
\\\\
\verb!>> cp incompressible/icoFoam $FOAM_RUN/../applications/openfoam-apps/icoTempFoam!
\\\\
\verb!!
\subsection*{Adding a dimensionedScalar object and an IOobject in the createFields.H File in the solver}
The \verb!createFields.H! file in the solver directory creates all the IOobjects required to run in the case.
\\
We intend to add \verb!dimensionedScalar! object and a \verb!volScalarField! as our IOobject in the file.
\\\\
\verb!>> cd $FOAM_RUN/../applications/openfoam-apps/icoTempFoam/!
\\\\
\verb!>> code createFields.H!
\\\\
The \verb!dimensionedScalar! object for $\kappa$ is coded as
\begin{verbatim}
//Adding the kappa as Dimensioned scalar
dimensionedScalar kappa
(
"kappa",
dimensionSet(0,2,-1,0,0,0,0),
transportProperties
);
\end{verbatim}
The \verb!volScalarField! IOobject for T is coded as
\begin{verbatim}
//Adding Temperature as a IOobject to be read
Info<< "Reading field T\n" << endl;
volScalarField T
(
IOobject
(
"T",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);
\end{verbatim}
\subsection*{Adding entry of $\kappa$ in the transportProperties dict file present in the case folder's constant directory}
We have already created kappa as a \verb!dimensionedScalar! object in the \verb!createFields.H! file that reads the value from the dictionary file \verb!transportProperties! present in the constant folder of the case directory.
\\\\
\verb!>> run!
\\\\
\verb!>> cd openfoam-cases/cavityTemp/constant!
\\\\
\verb!>> code transportProperties!
\\
We create a entry of \verb!kappa! with the dimension set of the heat diffusion coefficient which is the unit of it $(m^{2}/s)$ and the value being 0.001
\\
\begin{verbatim}
kappa [0 2 -1 0 0 0 0] 0.001;
\end{verbatim}
\subsection*{Adding the Initial and Boundary conditions for temperature field T in the 0 folder in the case directory}
For any case the \verb!0! folder holds the initial and boundary conditions for the fields like velocity U, pressure p, other turbulence paramters and since we have to calculate for the temperature we also need to specify the initial and boundary conditions for temperature field T.\\
As per our objective the initial and boundary conditions for temperature are,
\begin{itemize}
\item{The \verb!internalField! is set to 300K.}
\item{The \verb!movingWall! patch is set to 400K.}
\item{The rest \verb!fixedWall! patches are set to 300K.}
\end{itemize}
First we need to create a \verb!T! file in the \verb!0! folder
\\\\
\verb!>> run!
\\\\
\verb!>> cd openfoam-cases/cavityTemp/0!
\\\\
\verb!>> code T!
\\\\
The code includes the file-header specifying the type of file, object its location, etc
next it includes the dimensionSet of the Field, in our case its K(Kelvin) for temperature, next it contains the initial internal-field, we specify it as uniform and value as 300K. Further we have the boundary conditions, since its a cavity problem which is a simple block having a moving wall with a certain velocity along x-axis
\pagebreak
\\
The code for the following is given as
\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}
\subsection*{Adding the equation of temperature in the solver .C file}
Here in the solver .C file we create a fvScalarMatrix object since we intend to solve the temperature equation implicitly. Here \verb!fvm! namespace indicates we are doing implicit descretization. We need to solve the fvScalarMatrix object in the runTime while loop so that it solves for every time-step.
\\
The code that needs to be added in the runtime loop is given as
\begin{verbatim}
Info << "Solving the Equation for Temperature \n" ;
fvScalarMatrix temperatureEquation
(
fvm::ddt(T)+fvm::div(phi,T)-fvm::laplacian(kappa,T)
);
temperatureEquation.solve();
\end{verbatim}
\subsection*{Compiling the updated solver}
Now since we have made changes in the icoFoam solver we need to compile this updated solver in the \verb!$FOAM_USER_APPBIN! directory. We intend to store the executable in the user's appbin directory.
\\
For this we need to make the changes in the Make/files in the solver directory \\ We also change the name of the .C file from \verb!icoFoam.C! to \verb!\icoTempFoam.C! \\\\
\verb!>> cd $FOAM_RUN/../applications/openfoam-apps/icoFoam!
\\\\
\verb!>> mv icoFoam.C icoTempFoam.C!
\\\\
The changes in the Make/files are as follows
\begin{verbatim}
icoTempFoam.C
EXE = $(FOAM_USER_APPBIN)/icoTempFoam
\end{verbatim}
We have changed the name of the executable and also the location of the executable is set to \verb!FOAM_USER_APPBIN! in the user directory.\\ While executing the solver openfoam will select the executable present in the user-app-bin.
\\\\
Finally after changing all the essential things we can compile our application, this is done by
\\\\
\verb!>> cd $FOAM_RUN/../applications/openfoam-apps/icoFoam!
\\\\
\verb!>> wmake!
\subsection*{Specifying the solver settings for the temperature field in fvSolution and fvScheme file present in the system folder of case directory}
In OpenFoam case we have a file fvSolution and fvSchemes which stores important parameters associated with the solution. Here we can change the type of scheme that is used in the discretisation, also in the fvSolution we can specify the tolerance of the fields.
Here we have to specify \\\\
The tolerance to be \verb!1e-07! \\\\ The relative tolerance to be \verb!0! \\\\The code to add in fvSolution is given as
\begin{verbatim}
T
{
solver smoothSolver;
smoother symGaussSeidel;
tolerance 1e-7;
relTol 0;
}
\end{verbatim}
\pagebreak
Further we also need to specify which schemes are we using to discretise for \verb!fvm::ddt(T)!,
\verb!fvm::div(phi,T)!,\verb!laplacian(kappa,T)! The code for fvSchemes is as follows
\begin{verbatim}
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;
}
laplacianSchemes
{
default Gauss linear orthogonal;
//laplacian(kappa,T) Gauss linear orthogonal;
}
interpolationSchemes
{
default linear;
}
snGradSchemes
{
default orthogonal;
}
\end{verbatim}
\pagebreak
\subsection*{Running the case using the updated solver icoTempFoam}
After making the appropriate changes in the solver and case we are ready to run our case,
Here we can also make changes in the \verb!controlDict! File for the startTime, endTime and the timeStep.\\\\
Here we specify our startTime as 0 and endTime as 0.5 sec with the timeStep of 0.005 sec. We set the writeInterval to be 20 (writing after 20 timeSteps)\\\\
Also we change the application name from \verb!icoFoam! to \verb!icoTempFoam!
\\\\
In the \verb!controlDict! File we update the following entries.
\begin{verbatim}
application icoTempFoam;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 0.5;
deltaT 0.005;
writeControl timeStep;
writeInterval 20;
\end{verbatim}
Before running we need to initialise the blockmesh by executing the following command in the case directory \\\\
\verb!>> blockMesh!
\\\\
After we have a \verb!polyMesh! folder in the \verb!constant! folder we can run our application
\\\\
\verb!>> icoTempFoam!
\\\\
After the successful execution our case is finally ready with all the timeSteps present as directories. We can further visualise the results in ParaView.
\pagebreak
\section*{Results}
To visualise the results we need to execute the following command \\\\
\verb!>> paraFoam!
\\\\
in the case directory, this will create a temporary .foam file to be viewed in ParaView.
\begin{figure}[!htb]
\centering
\includegraphics[scale=0.4]{0.1.png}
\caption{Temperature Contour at time = 0.1 sec}
\end{figure}
\begin{figure}[!htb]
\centering
\includegraphics[scale=0.4]{0.3.png}
\caption{Temperature Contour at time = 0.3sec}
\end{figure}
\pagebreak
\begin{figure}[!htb]
\centering
\includegraphics[scale=0.4]{0.5.png}
\caption{Temperature Contour at time = 0.5 sec}
\end{figure}
\section*{Conclusion}
Thus we have demonstrated the flexibility of OpenFoam by incorporating a new equation for solving Temperature in a existing solver.
\section*{References}
github : \href{https://github.com/kawalthakur/openfoam-cases/tree/main/cavityTemp}{Click Here}
\\google drive project-3 link : \href{https://drive.google.com/drive/folders/1jGktgx0l1rh9ip6qhsTl2MuGesmeDyid?usp=share_link}{Click Here}
\end{document}