Project 2- Creating a custom IOObject in Visual Studio Code
The latex code of the documentation and code used for total pressure , and the p_total plot is added in the latex below
\documentclass[12pt]{report}
\usepackage{graphicx}
\usepackage{caption}
\author{Sai Krishnakanth}
\title{Creating a custom IOObject in VsCode}
\maketitle
\begin{document}
\section{Introduction}
This is my first report of latex in the course Openfoam development,
In this challenge a total pressure object is created which stores the value of pressure for each time step and
calculate the total pressure for each value of pressure at every time strp.
To achieve this firsly we have used a cavity solver from the tutorials , and by using our custom made
solver scalarFoam .
\section{Description}
In the generation of this object which calculates the total pressure , we first create a an object
in an .cpp file and compile it, for compiling it we use a Make folder which has two files , named
files and options, in files we need to chanfe the location where it compiles from , we point it to FOAM USER LIBBIN
instead of FOAM LIBBIN this is the location where the shared objects are created when make command is executed.
This object created calculates the total pressure which is given by the eqaution below
\begin{equation}
P_{total} = P +1/2 U^2;
\end{equation}
the velocity U is calculated for every time step , that is the file must read U for every time step.
Firstly a cpp file named Ptotal is created which has the above code for calculation of the total pressure
and this file is compiled using make command .The code is written as follows
\begin{verbatim}
#include "fvCFD.H"
using namespace std;
int main(int argc, char *argv[])
{
Foam::argList::noBanner();
timeSelector::addOptions();
#include "addTimeOptions.H"
#include "setRootCase.H"
#include "createTime.H"
#include "createMesh.H"
instantList Times = timeSelector::select0(runTime,args);
forAll(Times,i)
{
runTime.setTime(Times[i],i);
Info<<"Time: "<<runTime.timeName()<<endl;
volVectorField U
(
IOobject
(
"U",
runTime.timeName(),
mesh,
IOobject::MUST_READ
),
mesh
);
volScalarField p
(
IOobject
(
"p",
runTime.timeName(),
mesh,
IOobject::MUST_READ
),
mesh
);
volScalarField p_total
(
IOobject
(
"p_total",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
::mag(p+0.5*pow(mag(U),2))
);
p_total.write();
}
return 0;
}
\end{verbatim}
This code is compiled in the make directory by using the following commands in the files
\begin{verbatim}
p_total.cpp
EXE = p_total
\end{verbatim}
And in the options file the code is given as following
\begin{verbatim}
EXE_INC = \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-g
EXE_LIBS = \
-lfiniteVolume
\end{verbatim}
when make command is created , it creates a binary file, the output of the binary file when when
executed gives the following output, which calculates for each time step
\begin{verbatim}
Create time
Create mesh for time = 0
Time: 0
Time: 0.1
Time: 0.2
Time: 0.3
Time: 0.4
Time: 0.5
\end{verbatim}
The case used in this assignment is from tutorials named cavity, the solver used here is the scalarFoam
which is a custom made solver , the remaining files are the same. This has to be updated in the the controlDict file in the
system folder
The ptotal entry is created for each time step the variation of ptotal across the length is as follows
\begin{figure}
\includegraphics{Ptotalvsx.png}
\caption{Variation of total pressure across the top layer}
\end{figure}
\end{document}
