Project 2- Creating a custom IOObject in Visual Studio Code
Aim:To calculate the total pressure pTotal which is the contribution of the static pressure and the dynamic pressure by using a coded function object called totalPressure which:
- reads in the fields p and U
- creates a field pTotal (using IOobject)
- computes the expression
`p"Total" = p + frac{U^2}{2}` - writes the file pTotal to the disk.
The coded function has to be included in the controlDict file of the case here simpleFoam/pitzDaily tutorial case has been used.
The pitzDaily/system/controlDict file has been modified and the case has been simulated.The results are obtained and plotted.
The report of the same has been written usin LATEX and the respective code is as follows:
\documentclass[a4paper]{article}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{geometry}
\usepackage{subfigure}
\geometry{verbose,a4paper,tmargin=15mm,bmargin=30mm,lmargin=30mm,rmargin=20mm}
\begin{document}
\title{Report On Coded Function Objects using Customised IOobject in OpenFOAM}
\author{Kavendra Ashokrao Thakare}
\maketitle
\section{Introduction}
In this project, The original tutorial case \textit{pitzDaily} based on \textit{simpleFoam} solver is used. \\
The \textit{pitzDaily/system/controlDict} file is modified by addition of a coded Function Object which will be compiled on the fly which will be responsible for the calculation of total pressure.\\
The Steps to write a coded Function Object to calculate the total pressure are as follows:
\begin{itemize}
\item Write a function block named \textit{totalPressure} with the details as\\
type \textit{coded}, \\
libs \textit{libutilityFunctionObjects.so} \\
name \textit{pTotal} and \\
other necessary details like\\
\textit{writeControl} and \textit{writeInterval}.
\item After the details the function code is written with \textit{codeWrite} block with\\
\\
\#\{......\\
\\
function code\\
\\
......\#\}
\\
\item Inside the function code the fields U and p are read.
\item Then volscalarField \textit{pToal} with the Customised IOobject is written which will make the custom variable the total pressure parameter (\textit{pTotal}).
\item The \textit{pTotal} will be Calculated using the equation
\begin{equation}
pTotal = p + (U^2/2)
\end{equation}
\item Then the \textit{pTotal} file will be written to the disk at each timestep,
\end{itemize}
\section{File \textit{pitzDaily/system/controlDict} with coded Function Object}
\begin{verbatim}
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2012 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application simpleFoam;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 2000;
deltaT 1;
writeControl timeStep;
writeInterval 50;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
functions
{
#includeFunc streamlines
totalPressure
{
//Mandatory entries
type coded;
libs ("libutilityFunctionObjects.so");
name pTotal;
enabled true;
executeControl timeStep;
executeInterval 50;
WriteControl timeStep;
writeInterval 50;
codeWrite
#{
const volVectorField& U = mesh().lookupObject<volVectorField>("U");
const volScalarField& p = mesh().lookupObject<volScalarField>("p");
Info << "Creating pTotal Field" << nl << endl;
volScalarField pTotal
(
IOobject
(
"pTotal",
mesh().time().timeName(),
mesh(),
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
p + 0.5*magSqr(U)
);
pTotal.write();
#};
};
};
\end{verbatim}
\section{List of Commands used to simulate the \textit{pitzDaily} case with the respective outputs }
Rest of tutorial case files are kept as it is and the case is simulated with following commands.
\begin{enumerate}
\item \textit{blockMesh} - To generate mesh. Results are as follows:
\begin{verbatim}
/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2012 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
Build : _7bdb509494-20201222 OPENFOAM=2012
Arch : "LSB;label=32;scalar=64"
Exec : blockMesh
Date : Jun 04 2022
Time : 18:05:44
Host : LAPTOP-40IM2VAG
PID : 1122
I/O : uncollated
Case : /home/kaven19/OpenFOAM/kaven19-v2012/run/pitzDaily
nProcs : 1
trapFpe: Floating point exception trapping enabled (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using
timeStampMaster (fileModificationSkew 5, maxFileModificationPolls 20)
allowSystemOperations : Allowing user-supplied system call operations
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time
Creating block mesh from "system/blockMeshDict"
Creating block edges
No non-planar block faces defined
Creating topology blocks
Creating topology patches
Creating block mesh topology
Check topology
Basic statistics
Number of internal faces : 5
Number of boundary faces : 20
Number of defined boundary faces : 20
Number of undefined boundary faces : 0
Checking patch -> block consistency
Creating block offsets
Creating merge list (topological search)...
Deleting polyMesh directory "constant/polyMesh"
Creating polyMesh from blockMesh
Creating patches
Creating cells
Creating points with scale 0.001
Block 0 cell size :
i : 0.00158284 .. 0.000791418
j : 0.000318841 .. 0.000420268
k : 0.001 .. 0.001
Block 1 cell size :
i : 0.000528387 .. 0.00211355
j : 0.00112889 .. 0.000360188
k : 0.001 .. 0.001
Block 2 cell size :
i : 0.000528387 .. 0.00211355
j : 0.000318841 .. 0.000420268
k : 0.001 .. 0.001
Block 3 cell size :
i : 0.0020578 .. 0.00514451
j : 0.000940741 .. 0.000940741
k : 0.001 .. 0.001
Block 4 cell size :
i : 0.0020466 .. 0.00511651
j : 0.00112889 .. 0.000257962
k : 0.001 .. 0.001
There are no merge patch pairs
Writing polyMesh with 0 cellZones
----------------
Mesh Information
----------------
boundingBox: (-0.0206 -0.0254 -0.0005) (0.29 0.0254 0.0005)
nPoints: 25012
nCells: 12225
nFaces: 49180
nInternalFaces: 24170
----------------
Patches
----------------
patch 0 (start: 24170 size: 30) name: inlet
patch 1 (start: 24200 size: 57) name: outlet
patch 2 (start: 24257 size: 223) name: upperWall
patch 3 (start: 24480 size: 250) name: lowerWall
patch 4 (start: 24730 size: 24450) name: frontAndBack
End
\end{verbatim}
\item \textit{checkMesh} - To check the mesh.The Results are as follows:
\begin{verbatim}
/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2012 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
Build : _7bdb509494-20201222 OPENFOAM=2012
Arch : "LSB;label=32;scalar=64"
Exec : checkMesh
Date : Jun 04 2022
Time : 18:08:34
Host : LAPTOP-40IM2VAG
PID : 1174
I/O : uncollated
Case : /home/kaven19/OpenFOAM/kaven19-v2012/run/pitzDaily
nProcs : 1
trapFpe: Floating point exception trapping enabled (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using
timeStampMaster (fileModificationSkew 5, maxFileModificationPolls 20)
allowSystemOperations : Allowing user-supplied system call operations
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time
Create mesh for time = 0
Time = 0
Mesh stats
points: 25012
internal points: 0
faces: 49180
internal faces: 24170
cells: 12225
faces per cell: 6
boundary patches: 5
point zones: 0
face zones: 0
cell zones: 0
Overall number of cells of each type:
hexahedra: 12225
prisms: 0
wedges: 0
pyramids: 0
tet wedges: 0
tetrahedra: 0
polyhedra: 0
Checking topology...
Boundary definition OK.
Cell to face addressing OK.
Point usage OK.
Upper triangular ordering OK.
Face vertices OK.
Number of regions: 1 (OK).
Checking patch topology for multiply connected surfaces...
Patch Faces Points Surface topology
inlet 30 62 ok (non-closed singly connected)
outlet 57 116 ok (non-closed singly connected)
upperWall 223 448 ok (non-closed singly connected)
lowerWall 250 502 ok (non-closed singly connected)
frontAndBack 24450 25012 ok (non-closed singly connected)
Checking faceZone topology for multiply connected surfaces...
No faceZones found.
Checking basic cellZone addressing...
No cellZones found.
Checking geometry...
Overall domain bounding box (-0.0206 -0.0254 -0.0005) (0.29 0.0254 0.0005)
Mesh has 2 geometric (non-empty/wedge) directions (1 1 0)
Mesh has 2 solution (non-empty) directions (1 1 0)
All edges aligned with or perpendicular to non-empty directions.
Boundary openness (-1.74458e-19 3.10465e-18 2.11178e-15) OK.
Max cell openness = 2.21044e-16 OK.
Max aspect ratio = 8.1407 OK.
Minimum face area = 1.68589e-07. Maximum face area = 5.14451e-06.
Face area magnitudes OK.
Min volume = 1.6902e-10. Max volume = 3.83579e-09.
Total volume = 1.4516e-05. Cell volumes OK.
Mesh non-orthogonality Max: 5.95045 average: 1.63034
Non-orthogonality check OK.
Face pyramids OK.
Max skewness = 0.260575 OK.
Coupled point location match (average 0) OK.
Mesh OK.
End
\end{verbatim}
\item \textit{simpleFoam} - To solve the case
\begin{verbatim}
/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2012 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
Build : _7bdb509494-20201222 OPENFOAM=2012
Arch : "LSB;label=32;scalar=64"
Exec : simpleFoam
Date : Jun 04 2022
Time : 18:17:26
Host : LAPTOP-40IM2VAG
PID : 1341
I/O : uncollated
Case : /home/kaven19/OpenFOAM/kaven19-v2012/run/pitzDaily
nProcs : 1
trapFpe: Floating point exception trapping enabled (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using
timeStampMaster (fileModificationSkew 5, maxFileModificationPolls 20)
allowSystemOperations : Allowing user-supplied system call operations
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time
Create mesh for time = 0
SIMPLE: convergence criteria
field p tolerance 0.01
field U tolerance 0.001
field "(k|epsilon|omega|f|v2)" tolerance 0.001
Reading field p
Reading field U
Reading/calculating face flux field phi
Selecting incompressible transport model Newtonian
Selecting turbulence model type RAS
Selecting RAS turbulence model kEpsilon
RAS
{
RASModel kEpsilon;
turbulence on;
printCoeffs on;
Cmu 0.09;
C1 1.44;
C2 1.92;
C3 0;
sigmak 1;
sigmaEps 1.3;
}
No MRF models present
No finite volume options present
Starting time loop
streamLine streamlines:
Employing velocity field U
automatic track length specified through number of sub cycles : 5
Using dynamicCode for functionObject totalPressure at line 55 in
"/home/kaven19/OpenFOAM/kaven19-v2012/run/pitzDaily/system
/controlDict.functions.totalPressure"
Could not load "/home/kaven19/OpenFOAM/kaven19-v2012/run/pitzDaily/
dynamicCode/platforms/linux64Gcc63DPInt32Opt/lib/
libpTotal_755b71d57c5a9b51961618d7463564f3b7322da9.so"
/home/kaven19/OpenFOAM/kaven19-v2012/run/pitzDaily/dynamicCode/platforms
/linux64Gcc63DPInt32Opt/lib/libpTotal_755b71d57c5a9b51961618d7463564f3b7322da9.so
: cannot open shared object file: No such file or directory
Creating new library in "dynamicCode/pTotal/platforms/linux64Gcc63DPInt32Opt/lib/
libpTotal_755b71d57c5a9b51961618d7463564f3b7322da9.so"
Invoking wmake libso /home/kaven19/OpenFOAM/kaven19-v2012/run/pitzDaily/
dynamicCode/pTotal
wmake libso /home/kaven19/OpenFOAM/kaven19-v2012/run/pitzDaily/dynamicCode/pTotal
ln: ./lnInclude
dep: functionObjectTemplate.C
Ctoo: functionObjectTemplate.C
ld: /home/kaven19/OpenFOAM/kaven19-v2012/run/pitzDaily/dynamicCode/pTotal/
../platforms/linux64Gcc63DPInt32Opt/lib/
libpTotal_755b71d57c5a9b51961618d7463564f3b7322da9.so
Time = 1
smoothSolver: Solving for Ux, Initial residual = 1, Final residual = 0.0538101,
No Iterations 1
smoothSolver: Solving for Uy, Initial residual = 1, Final residual = 0.030925,
No Iterations 2
GAMG: Solving for p, Initial residual = 1, Final residual = 0.068427,
No Iterations 17
time step continuity errors : sum local = 1.19733, global = 0.179883,
cumulative = 0.179883
smoothSolver: Solving for epsilon, Initial residual = 0.199984,
Final residual = 0.0100282, No Iterations 3
bounding epsilon, min: -1.98669 max: 1080.25 average: 47.5305
smoothSolver: Solving for k, Initial residual = 1,
Final residual = 0.0439204, No Iterations 3
ExecutionTime = 0.3 s ClockTime = 9 s
Creating pTotal Field
Time = 2
........
........
Time = 281
smoothSolver: Solving for Ux, Initial residual = 0.00012297,
Final residual = 1.19576e-05, No Iterations 5
smoothSolver: Solving for Uy, Initial residual = 0.00100116,
Final residual = 6.98274e-05, No Iterations 6
GAMG: Solving for p, Initial residual = 0.000792438,
Final residual = 7.0396e-05, No Iterations 5
time step continuity errors : sum local = 0.00336158, global = -0.000238994,
cumulative = 1.03076
smoothSolver: Solving for epsilon, Initial residual = 0.000122041,
Final residual = 6.91595e-06, No Iterations 3
smoothSolver: Solving for k, Initial residual = 0.000224151,
Final residual = 1.40606e-05, No Iterations 4
ExecutionTime = 8.33 s ClockTime = 17 s
Creating pTotal Field
Time = 282
smoothSolver: Solving for Ux, Initial residual = 0.000118356,
Final residual = 1.15546e-05, No Iterations 5
smoothSolver: Solving for Uy, Initial residual = 0.000975505,
Final residual = 6.74704e-05, No Iterations 6
GAMG: Solving for p, Initial residual = 0.000787109,
Final residual = 6.59467e-05, No Iterations 5
time step continuity errors : sum local = 0.00314713, global = -0.000234334,
cumulative = 1.03052
smoothSolver: Solving for epsilon, Initial residual = 0.00011874,
Final residual = 6.88843e-06, No Iterations 3
smoothSolver: Solving for k, Initial residual = 0.000218376,
Final residual = 1.36587e-05, No Iterations 4
ExecutionTime = 8.35 s ClockTime = 17 s
SIMPLE solution converged in 282 iterations
streamLine streamlines write:
seeded 10 particles
Tracks:10
Total samples:10885
Writing data to "/home/kaven19/OpenFOAM/kaven19-v2012/run/pitzDaily/
postProcessing/sets/streamlines/282"
Creating pTotal Field
End
\end{verbatim}
\end{enumerate}
\section{Coded Function on the fly compilation message}
\begin{verbatim}
Using dynamicCode for functionObject totalPressure at line 55 in
"/home/kaven19/OpenFOAM/kaven19-v2012/run/pitzDaily/system
/controlDict.functions.totalPressure"
Could not load "/home/kaven19/OpenFOAM/kaven19-v2012/run/pitzDaily/dynamicCode
/platforms/linux64Gcc63DPInt32Opt/lib/
libpTotal_755b71d57c5a9b51961618d7463564f3b7322da9.so"
/home/kaven19/OpenFOAM/kaven19-v2012/run/pitzDaily/dynamicCode/platforms
/linux64Gcc63DPInt32Opt/lib/libpTotal_755b71d57c5a9b51961618d7463564f3b7322da9.so:
cannot open shared object file: No such file or directory
Creating new library in "dynamicCode/pTotal/platforms/linux64Gcc63DPInt32Opt/lib
/libpTotal_755b71d57c5a9b51961618d7463564f3b7322da9.so"
Invoking wmake libso /home/kaven19/OpenFOAM/kaven19-v2012/run/pitzDaily
/dynamicCode/pTotal
wmake libso /home/kaven19/OpenFOAM/kaven19-v2012/run/pitzDaily/dynamicCode/pTotal
ln: ./lnInclude
dep: functionObjectTemplate.C
Ctoo: functionObjectTemplate.C
ld: /home/kaven19/OpenFOAM/kaven19-v2012/run/pitzDaily/dynamicCode/pTotal/
../platforms/linux64Gcc63DPInt32Opt/lib/
libpTotal_755b71d57c5a9b51961618d7463564f3b7322da9.so
\end{verbatim}
\newpage
\section{Contours of Total Pressure}
The contours of \textit{pTotal} are as follows:
\begin{figure}[h]
\centering
\includegraphics[scale=0.225]{pTotal-Initial.png}{ \label{fig:1}}
\caption{Initial \textit{pTotal} contours}
\end{figure}
\begin{figure}[h]
\centering
\includegraphics[scale=0.225]{ptotal-intermediate.png}{ \label{fig:2}}
\caption{Intermediate \textit{pTotal} contours}
\end{figure}
\begin{figure}[h!]
\centering
\includegraphics[scale=0.225]{pToal-Steadystate.png}{ \label{fig:3}}
\caption{Steady state \textit{pTotal} contours}
\end{figure}
\newpage
\section{Conclusion}
Thus the coded Function Object with customised IOobject is successfully implemented into the case to calculate and write the customised parameter.
\end{document}
The required images of the contours have been added to the same folder where the above code has been saved. The respective image files and output pdf file have been attached herewith.