Challenge

Project 2- Creating a custom IOObject in Visual Studio Code

Report is written in the LaTeX language here is the code and the link to the PDF file:
Link: https://drive.google.com/file/d/1UrUmNiQjkvAGCXleuF8C1_V_OnYL0aRe/view?usp=drive_link

\documentclass[a4paper]{report}
\usepackage{graphicx} % Required for inserting images

\title{\textbf{Creating  a Custom IOObject in OpenFOAM}}
\author{Altamash Siddiqui}
\date{September 2023}

\begin{document}

\maketitle

\section{\textbf{Introduction}} In this project, the aim is to create a \underline{coded function object} to calculate the \textbf{Total Pressure} for the 'pitzDaily' tutorial and writing that total pressure value. Also the report has to be written in \LaTeX.

\section{\textbf{Objective}}
To write a coded function named \textbf{totalPressure} for calculating the total pressure, the algorithm for the totalPressure FO is given as:
\begin{itemize}

    \item Read the value of \textbf{p}(static pressure) and \textbf{U}(for dynamic pressure) from each time-step.

    \item Creates a field \textbf{\underline{pTotal}} using IOObject.

    \item Compute the given expression: \(pTotal = p + 0.5*(U^2)\)\\
    where \textbf{p} is the computed field and is \textit{Static Pressure}\\ and \textbf{U} is the computed velocity and is \textit{Dynamic Pressure} that is given as \(0.5*(U^2)\)

    \item In last the computed pTotal should be written on the disk.
\end{itemize}
This is the objective of the coded function object \underline{totalPressure}.

\section{\textbf{Theory}}
\subsection{\textbf{IOObject:}}
In OpenFOAM, an IOObject is a fundamental class used for input and output operations. It is part of the core infrastructure that enables OpenFOAM to handle various types of data, such as meshes, fields, and dictionaries.\par
Here are some key aspects of IOObject:
\begin{enumerate}
    \item \textbf{Data Handling}: IOObject is responsible for handling data read from or written to various sources. This data can include mesh files, solution fields, and configuration settings.

    \item \textbf{Hierarchy}: IOObject is part of a class hierarchy in OpenFOAM. It serves as the base class for other more specialized classes, such as IOdictionary (for handling dictionaries), IOfield (for handling field data), and IOstream (for handling stream-based input/output).

    \item \textbf{File Handling}: One of the primary functions of IOObject is to manage file operations. It can open, close, and perform other file-related operations, making it essential for reading and writing data files in OpenFOAM. 

    \item \textbf{Reading Input Files}: IOObject is essential for reading configuration settings, boundary conditions, initial conditions, and other data from input files like dictionaries. It allows you to specify what data to read and how to handle it.

    \item \textbf{Writing Output Data}: When writing simulation results, including field data, time step information, and post-processing results, you should use IOObject to ensure proper file output. This helps in generating output files in the correct format and location.\par
\end{enumerate}
In creating of fields, dictionaries the IOObject are used for the input/output as well as the writing and reading operations, that is also seen in the present Project. For the purpose of writing the \textit{pTotal} field for every time-step or for some certain time-steps IOObject is utilized for that purpose.

\section{\textbf{Procedure}:}
\begin{enumerate}
    \item Copy the simpleFoam/pitzDaily tutorial from the OpenFOAM directory to you run directory.

    \item As we know, any function objects are either created in a separate file or are directly added in the controlDict of the case file. 

    \item So now we will add our Function Object \textbf{totalPressure} in the controlDict of the pitzDaily case file as shown below:\\
    \begin{verbatim}
        /*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2212                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

application     simpleFoam;

startFrom       startTime;

startTime       0;

stopAt          endTime;

endTime         2000;

deltaT          1;

writeControl    timeStep;

writeInterval   100;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;


functions
{
    totalPressure
{
    // Mandatory entries
    type            coded;
    libs            (utilityFunctionObjects);
    name            pTotal;
    enabled         true;
    writeControl    timeStep;
    writeInterval   20;




   codeWrite
   #{
       const volVectorField& U = mesh().lookupObject("U");
       const volScalarField& p = mesh().lookupObject("p");

       Info << "Creating pTotal field" << nl includegraphics[width=\textwidth]{image/Screenshot includegraphics[width=\textwidth]{image/Screenshot includegraphics[width=\textwidth]{image/Screenshot includegraphics[width=\textwidth]{image/U.png} includegraphics[width=\textwidth]{image/p.png} includegraphics[width=\textwidth]{image/pTO_20.png} includegraphics[width=\textwidth]{image/pTO_100.png}>
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.