Challenge

Project 2- Creating a custom IOObject in Visual Studio Code

The LaTex code for the report is given as

\documentclass[12pt]{report}
\usepackage{parskip}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{amsmath,amssymb,amsthm}
\usepackage[utf8]{inputenc}
\usepackage[a4paper, total={6.5in, 9.8in}]{geometry}
\title{Creating a custom IOobject in VScode}
\author{Kawal Thakur}
\usepackage{sectsty}
\sectionfont{\fontsize{16}{16}\selectfont}
\subsectionfont{\fontsize{14}{14}\selectfont}
\begin{document} 
\maketitle
\section*{Aim}
The total pressure $p_{total}$ is a contribution of static pressure $p_{static}$ and dynamic pressure $p_{dynamic} = \frac{1}{2}{U}^{2}.$ Aim of this project is to create a custom IOobject to calculate total pressure.
\section*{Objectives}
Write a coded function object to
\begin{itemize}
\item{reads in the fields p and U}
\item{creates a field \verb!p_total! using IOobject }
\item{computes the expression $p_{total}= p + \frac{1}{2}{U}^{2}$ }
\item{writes the file \verb!p_total! to the disk}
\end{itemize}
Place this in the controlDict file of the \verb!pitzDaily! tutorial and plot the results
\section*{Procedure}
\subsection*{Copying the tutorial case from OpenFoam tutorial directory}
We have to copy the tutorial case from the tutorial directory of OpenFoam to the user run directory. To do this we need to follow the following commands. 
\\\\
\verb!>> tut !
\\\\
\verb!>> cd incompressible/pimpleFoam/RAS!
\\\\
\verb!>> cp pitzDaily $FOAM_RUN/pitzDaily-PIMPLE!
\subsection*{Adding the function Object in the controlDict file}
We have to add a function object which in this case is a coded function object in the controlDict file. To do this we navigate to the system directory of the case and make the following changes.
\\\\
\verb!>> cd $FOAM_RUN/pitzDaily-PIMPLE/!
\\\\
\verb!>> cd system/!
\\\\
\verb!>> code controlDict!
\\\\
Here we add the function named \verb!p_total! and specify the type as coded, we further specify the writeInterval and execution Interval as we want. In the codeWrite we specify the dynamic code for the operation.
\\
In that we read the value of Velocity \verb!U! as a Vector Field and Pressure \verb!p! as a Scalar Field. After that we define \verb!p_total! as a IOobject of Scalar Field, here we also calculate the magnitude of the total pressure as 
\\\\
\centerline{$p_{total} = p + \frac{1}{2}U^{2}$}
\\\\
We further write the \verb!p_total! value to the case directory 
The following code is given as 
\begin{verbatim}
functions
{
    p_total
    {
        type            coded;
        libs            (utilityFunctionObjects);
        // Name of the IOobject to be created as Total Pressure 
        name            p_total;
        executeControl  timeStep;
        executeInterval 100;
        writeControl    timeStep;
        writeInterval   100;
        codeWrite
        #{
            const volVectorField& U = mesh().lookupObject("U");
            const volScalarField& p = mesh().lookupObject("p");
            Info << "Creating a p_total IOobject\n";
            volScalarField p_total
            (
                IOobject
                (
                    "p_total",
                    mesh().time().timeName(),
                    mesh(),
                    IOobject::MUST_READ,
                    IOobject::AUTO_WRITE
                ),
                p + 0.5*magSqr(U)
            );
            Info << "Writing the p_total to the timeName\n";
            p_total().write();
        #};

    }

}
\end{verbatim}
\subsection*{Running the case}
After making all the necessary changes in the controlDict File we can run the case.
\\ 
To run the case we can execute the commands below in the case directory 
\\\\
\verb!>> blockMesh!
\\\\
\verb!>> pimpleFoam!
\subsection*{Visualising the results}
We can visualise our results in ParaView by 
\\\\
\verb!>> paraFoam!
\\\\
This will open ParaView where we can further manipulate our results.

\section*{Results}
\begin{figure}[!htb]
\centering
\includegraphics[scale=0.4]{p_total-contour.png}
\caption{Total Pressure at time = 0.017 sec}
\end{figure}
\section*{Conclusion}
We have successfully created a IOobject of total pressure by adding a coded function in the controlDict file and have visualised the results for the same.
\end{document}

The code for the following is present on github as a repository

https://github.com/kawalthakur/openfoam-cases/tree/main/pitzDaily-PIMPLE

The Report PDF is provided in the attachment below

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.