Project 3- Adding a temperature dictionary to the incompressible icoFoam case to solve the energy equation
Project 3: To solve the incompressible flow equations for mass and momentum by adding a temperature dictionary to the icoFoam solver.
-- The following Latex code is the report of the Project_3. And Latex pdf file is also attached in the following link.
Latex Code:-
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\title{Adding a temperature dictionary to the incompressible icoFoam case to solve the energy equation}
\author{Pavan Kumar}
\date{}
\begin{document}
\maketitle
\newpage
\section{AIM}
To solve the incompressible flow equations for mass and momentum by adding a temperature dictionary to the icoFoam solver.
\section{Objectives }
\begin{enumerate}
\item Create a new solver based on icoFoam called icoTempFoam
\item Create a IOobject for temperature T to solve the TEqn by compiling the soler
\begin{enumerate}
\item equation for temperature as
\begin{equation}
\frac{\partial\mathbf{T}}{\partial\mathbf{t}}+(\cdot\mathbf{U}\nabla)\mathbf{T}=\kappa\nabla^2\mathbf{T}
\end{equation}
\end{enumerate}
\item Copy the TUTORIALS/incompressible/icoFoam/cavity/cavity tutorial and rename it to cavityTemp
\item Make changes in the 0 folder by adding the T file and add kappa term to the transport properties file
\item Then, Make necessary changes inside the fvSchemes and fvSolutions to run the solver
\item Then, plot the Results of Temperature T.
\end{enumerate}
\section{Introduction}
\subsection{icoFoam}
Icofoam is a transient solver for incompressible, laminar flow of Newtonian fluids. The solver uses the PISO algorithm to solve the continuity equation:
\begin{equation}
\nabla\cdot\mathbf{U} = 0
\end{equation}
\begin{equation}
\frac{\partial\mathbf{U}}{\partial\mathbf{t}}+\nabla\cdot\mathbf{U.U}= -\nabla\cdot\mathbf{p}+\nabla\cdot\mathbf{\upsilon\nabla\mathbf{U}}+g
\end{equation}
$$$$
\section{Procedure}
\begin{enumerate}
\item First, copy the icoFoam solver into the user run folder and rename it as icoTempFoam.
\item And also rename the inside files like icoFoam.C into icoTempFoam.C
\item Change the files in Make folder to change the target directory to User APPBIN.
\subsection{Make/files}
\begin{verbatim}
icoTempFoam.C
EXE = $(FOAM_USER_APPBIN)/icoTempFoam
\end{verbatim}
\item Now, included a dictionary reader for kappa in the createFields.H and also added a field read and write IOObject for temperature T
\subsection{createFields.H}
\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 T\n" << endl;
volScalarField T
(
IOobject
(
"T",
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
);
#include "createPhi.H"
label pRefCell = 0;
scalar pRefValue = 0.0;
setRefCell(p, mesh.solutionDict().subDict("PISO"), pRefCell, pRefValue);
mesh.setFluxRequired(p.name());
\end{verbatim}
\item Here, I added a fvScalarMatrix in the icoTempFoam.C file that stores the scalar matrix value of TEqn and to the solve the Temperature equation. And the file code is as follows.
\subsection{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(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)
);
solve(TEqn);
runTime.write();
runTime.printExecutionTime(Info);
}
Info<< "End\n" << endl;
return 0;
}
// ************************************************************************* //
\end{verbatim}
\item Now, compile the solver by using the command "wmake".
\begin{figure}
\centering
\includegraphics[width=1\linewidth]{wmake.png}
\caption{wmake}
\end{figure}
\item Here, the solver is working fine and no errors are found. So now copy the text case file from TUTORIALS/incompressible/icoFoam/cavity/cavity and remane it as cavityTemp
\item And, inside the transport properties Add a dictionary entry for kappa as kappa [ 0 2 -1 0 0 0 0 ] 0.001;
\subsection{constant/transport properties}
\begin{verbatim}
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2306 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object transportProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
nu 0.01;
kappa [0 2 -1 0 0 0 0] 0.001;
// ************************************************************************* //
\end{verbatim}
\item Then, added a file in the 0 folder for temperature T and setted the boundaryFields of moving walls of a fixed value 300, and assigned uniform value of internalFields as 300.
\subsection{0/ T}
\begin{verbatim}
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2306 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
object T;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 0 0 0 0 0 0];
internalField uniform 300;
boundaryField
{
movingWall
{
type fixedValue;
value uniform 400;
}
fixedWalls
{
type zeroGradient;
}
frontAndBack
{
type empty;
}
}
// ************************************************************************* //
\end{verbatim}
\item After that, added a div(phi,T) in divSchemes and laplacian(kappa,T) in laplacianSchemes as follows,
\subsection{system/fvSchemes}
\begin{verbatim}
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2306 |
| \\ / 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;
}
laplacianSchemes
{
default Gauss linear orthogonal;
}
interpolationSchemes
{
default linear;
}
snGradSchemes
{
default orthogonal;
}
// ************************************************************************* //
\end{verbatim}
\item And also added a smoothSolver linear solver for temperature in fvSolution of tolerance of 1e-07 and a relTol of 0.
\subsection{system/fvSolutions}
\begin{verbatim}
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2306 |
| \\ / 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
{
solver smoothSolver;
smoother symGaussSeidel;
tolerance 1e-07;
relTol 0;
}
}
PISO
{
nCorrectors 2;
nNonOrthogonalCorrectors 0;
pRefCell 0;
pRefValue 0;
}
// ************************************************************************* //
\end{verbatim}
\end{enumerate}
\section{Results}
Now, to get the results, run the case file by using the following commands:
\begin{enumerate}
\item blockMesh
\item icoTempFoam
\item paraFoam
\end{enumerate}
\begin{figure}
\centering
\includegraphics[width=0.5\linewidth]{pressure.png}
\caption{visual results of Pressure field}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=0.5\linewidth]{velocity.png}
\caption{visual results of U field}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=0.5\linewidth]{Temperature.png}
\caption{visual results of Temperature field}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=0.5\linewidth]{graphical plot.png}
\caption{Graphical plot}
\end{figure}
\section{Conclusion}
Hence, in this report, the icoTempFoam is the solver solves the incompressible flow equations for mass and momentum and also temperature equation of the cavityTemp case file and plotted the results as shown in the above report.
\end{document}
-- The below link is the pdf file format of the Latex code:https://drive.google.com/file/d/1lAHSEyZUaNDLB193CPuXvHZoyv1HH2qE/view?usp=sharing