You are on page 1of 83

Disclaimer

This offering is not approved or


endorsed by OpenCFD Limited, the
producer of the OpenFOAM software
and owner of the OPENFOAM and
OpenCFD trade marks.

Introductory OpenFOAM Course


From 14th to 18th July, 2014

University of Genoa, DICCA


Dipartimento di Ingegneria Civile, Chimica e Ambientale

Your Lecturer

Joel GUERRERO

joel.guerrero@unige.it



guerrero@wolfdynamics.com

Todays lecture

1. How to implement a new boundary condition


in OpenFOAM
2. How to implement my own application in
OpenFOAM
3. How to add temperature to icoFoam

This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM and OpenCFD trade marks.

Todays lecture

1. How to implement a new boundary condition


in OpenFOAM
2. How to implement my own application in
OpenFOAM
3. How to add temperature to icoFoam

This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM and OpenCFD trade marks.

How to implement a new boundary condition in OpenFOAM


Remember, all components in OpenFOAM are implemented in library
form for easy re-use. So, in order to implement a new boundary
condition, we should follow these basic steps:
The implementations of the boundary conditions are located in the
directory $FOAM_SRC/finiteVolume/fields/fvPatchFields/

To add a new boundary condition, start by finding one that does


almost what you want to do. Then, copy that boundary condition
implementation to $WM_PROJECT_USER_DIR and modify it according
to your needs.

How to implement a new boundary condition in OpenFOAM


Remember, all components in OpenFOAM are implemented in library
form for easy re-use. So, in order to implement a new boundary
condition, we should follow these basic steps:
Rename all the copied .C and .H files, for instance you can change
their names to myFvPatchField.*. In the new files, search for all
text occurrences with originalFvPatchField (the original name of
the .C and .H files) and replace them with myFvPatchField.

Modify the boundary condition to suit your needs. After you finish
modifying it, compile it and use it as a dynamic library.

How to implement a new boundary condition in OpenFOAM

Parabolic inlet boundary condition

How to implement a new boundary condition in OpenFOAM


Parabolic inlet boundary condition
We will add a new parabolic inlet profile boundary condition.
In the directory $ptofc/programming/src/finiteVolume/
fields/fvPatchFields/derived/parabolicVelocity you will
find the new boundary condition. Notice that we kept the same directory
structure as in $FOAM_SRC.
From the terminal type:
cd $ptofc/programming/src/finiteVolume/fields/
fvPatchFields/derived/parabolicVelocity
wmake libso
Starting from OpenFOAM version 2.2.1, the argument libso is not
required anymore.

How to implement a new boundary condition in OpenFOAM


Parabolic inlet boundary condition
If you did not get any error, the new boundary condition is ready to use. wmake
will compile the new boundary condition and will place the new library in the
directory $WM_PROJECT_USER_DIR /platforms/linux64GccDPOpt/lib
(environment variable $FOAM_USER_LIBBIN).
Remember to modify the files located in the Make directory, so they
reflect the location of the new library and its name.
By the way, take a look at the files.

How to implement a new boundary condition in OpenFOAM


Parabolic inlet boundary condition
Let us now setup a new case using the new boundary condition. From the
terminal:
cd $ptofc/mycases1/elbow2d_1/elbow_parabolic_inlet_0

Before running the solver we need to:


Add the new boundary condition parabolicVelocity in 0/U.
velocity-inlet-5
{
type parabolicVelocity;
maxValue 2.0;
n
(1 0 0);
y
(0 1 0);
value
(0 0 0); //dummy value
}

How to implement a new boundary condition in OpenFOAM


Parabolic inlet boundary condition
Let us now setup a new case using the new boundary condition.
Before running the solver we need to:
Then add the line:
libs (parabolicvelocityBC.so)
to the case controlDict dictionary in the system directory.

How to implement a new boundary condition in OpenFOAM


Parabolic inlet boundary condition
Remember to always add the newly created boundary condition to your control
dictionary controlDict. If you do not do this OpenFOAM will complain.
Now we are ready to run the case. From the terminal type:
cd $ptofc/mycases1/elbow2d_1/elbow_parabolic_inlet_0
fluentMeshToFoam ../../../meshes/elbow2d_1/ascii.msh
checkMesh
icoFoam
paraFoam

How to implement a new boundary condition in OpenFOAM


Parabolic inlet boundary condition
By following the instructions, you should get something like this

Mesh

How to implement a new boundary condition in OpenFOAM


Parabolic inlet boundary condition
By following the instructions, you should get something like this

Parabolic inlet profile

Uniform inlet profile

How to implement a new boundary condition in OpenFOAM


Parabolic inlet boundary condition
By following the instructions, you should get something like this

Inlet profiles

How to implement a new boundary condition in OpenFOAM


A closer look to the parabolic inlet boundary condition
The parabolicVelocityFvPatchVectorField boundary condition
consists of two files:
parabolicVelocityFvPatchVectorField.C
parabolicVelocityFvPatchVectorField.H
The .H file is the header file, and it is included in the header of the .C file.
We can see that in the .H file we create a sub class to the
fixedValueFvPatchVectorField:
class parabolicVelocityFvPatchVectorField: public fixedValueFvPatchVectorField

i.e. this is for Dirichlet boundary conditions for a vector field.

How to implement a new boundary condition in OpenFOAM


A closer look to the parabolic inlet boundary condition
The class has private data and takes in the following data
//- Peak velocity magnitude
scalar maxValue_;
//- Flow direction
vector n_;
//- Direction of the y-coordinate
vector y_;

The TypeName("parabolicVelocity"), used when specifying the


boundary condition, is defined.
There are some public constructors and member functions that are defined
in detail in the .C file.
We used the third constructor when we tested the boundary condition, i.e.
we read the member data from a dictionary.

How to implement a new boundary condition in OpenFOAM


A closer look to the parabolic inlet boundary condition
The actual implementation of the boundary condition can be found in the
updateCoeffs() member function:
boundBox bb(patch().patch().localPoints(), true);
vector ctr = 0.5*(bb.max() + bb.min());
const vectorField& c = patch().Cf();
scalarField coord = 2*((c - ctr) & y_)/((bb.max() - bb.min()) & y_);
vectorField::operator=(n_*maxValue_*(1.0 - sqr(coord)));

The member function write defines how to write out the boundary values in
the time directory. The final line, writeEntry("value", os); writes out
all the values, which is only needed for post-processing.

How to implement a new boundary condition in OpenFOAM


A closer look to the parabolic inlet boundary condition
Find out more about all the variables by including the following lines at the end
of the updateCoeffs member function:
Info
Info
Info
Info
Info
Info
Info
Info
Info

<<
<<
<<
<<
<<
<<
<<
<<
<<

c << c << endl;


ctr << ctr << endl;
y_ << y_ << endl;
bb.max() << bb.max() <<
bb.min() << bb.min() <<
(c - ctr) << c - ctr <<
((c - ctr) & y_) << ((c
((bb.max() - bb.min()) &
coord << coord << endl;

endl;
endl;
endl;
- ctr) & y_) << endl;
y_) << ((bb.max() - bb.min()) & y_) << end;

How to implement a new boundary condition in OpenFOAM


Wait, what if I do not want to program my boundary
condition?
You can save the pain of programming the boundary conditions in
OpenFOAM if you use swak4foam.
swak4foam offers the possibility of implementing new boundary conditions
without the need of programming.
If you go to the directory $ptofc/mycases1/elbow2d_1/
elbow_parabolic_inlet_1, you will find a case where we use
swak4foam to implement a parabolic profile inlet.
Do not worry, I will show how to use swak4foam and how to run this case.

How to implement a new boundary condition in OpenFOAM


Wait, what if I do not want to program my boundary
condition?
I highly advise you to spend some time and try to learn how to use
swak4foam as it will save you a lot of time.
I have been able to program really complex boundary conditions using
swak4foam. It works most of the times.
For more information about swak4foam you can visit the following site
http://openfoamwiki.net/index.php/Contrib/swak4Foam.
Let us go to the directory $ptofc/mycases1/elbow2d_1/
elbow_parabolic_inlet_1, from now on follow me.

How to implement a new boundary condition in OpenFOAM

Paraboloid inlet boundary condition

How to implement a new boundary condition in OpenFOAM


Paraboloid inlet boundary condition
Starting from the parabolic inlet profile boundary condition, let us now create a
new boundary condition to model a paraboloid inlet profile.
In the directory $ptofc/programming/src/finiteVolume/fields/
fvPatchFields/derived/p3d you will find the new boundary condition.
Notice that we kept the same directory structure as in $FOAM_SRC.
Notice that we also kept the same naming convention for the files and
classes as for the parabolic inlet profile boundary condition, that is, we simply
cloned the directory. This is to show you how the code can be reused.
Starting from this point, we can modify the files to fit our needs.

How to implement a new boundary condition in OpenFOAM


Paraboloid inlet boundary condition
Starting from the parabolic inlet profile boundary condition, let us now create a
new boundary condition to model a paraboloid inlet profile.
As we simply cloned the directory parabolicVelocity, the name of the
paraboloid inlet boundary condition is the same as the one used in the
parabolicVelocity boundary condition and the implementation consists
of two files:
parabolicVelocityFvPatchVectorField.C
parabolicVelocityFvPatchVectorField.H

By the way, take a look at the files and identify all the modifications.

How to implement a new boundary condition in OpenFOAM


Paraboloid inlet boundary condition
Starting from the parabolic inlet profile boundary condition, let us now create a
new boundary condition to model a paraboloid inlet profile.
While this approach will work, I highly recommend you to change the names
of the files and classes. For instance, if you use the library
parabolicvelocityBC.so and p3d.so in the same case, you will have
a conflict between the libraries as both of them use the same symbols.
In the directory $ptofc/programming/src/finiteVolume/fields/
fvPatchFields/derived/paraboloid you will find the paraboloid
inlet boundary condition. For your convenience, in this implementation I
already replaced all instances of parabolicVelocity by paraboloid
(names of files, classes and functions).

How to implement a new boundary condition in OpenFOAM


Paraboloid inlet boundary condition
Starting from the parabolic inlet profile boundary condition, let us now create a
new boundary condition to model a paraboloid inlet profile.
By the way, take a look at the files in the directory $ptofc/programming/
src/finiteVolume/fields/fvPatchFields/derived/paraboloid
and identify all the modifications (in naming convention and implementation).
To compile:
cd $ptofc/programming/src/finiteVolume/fields/
fvPatchFields/derived/paraboloid
wmake libso
Starting from OpenFOAM version 2.2.1, the argument libso is not
required anymore

How to implement a new boundary condition in OpenFOAM


Paraboloid inlet boundary condition
If you did not get any error, the new boundary condition is ready to use. wmake
will compile the new boundary condition and will place the new library in the
directory $WM_PROJECT_USER_DIR /platforms/linux64GccDPOpt/lib
(environment variable $FOAM_USER_LIBBIN).
Remember to modify the files located in the Make directory, so they
reflect the location of the new library and its name.
By the way, take a look at the files.

How to implement a new boundary condition in OpenFOAM


Paraboloid inlet boundary condition
Let us now setup a new case using the new boundary condition. From the
terminal:
cd $ptofc/mycases1/elbow3d/elbow_paraboloid
Before running the solver we need to:
Add the new boundary condition parabolicVelocity in 0/U.
inlet1
{
type
paraboloid;
maxValue
0.4;
n
(1 0 0);
y
(0 1 0);
y1
(0 0 1);
radius
1.0;
value
uniform (0 0 0); //dummy value
}

How to implement a new boundary condition in OpenFOAM


Paraboloid inlet boundary condition
Let us now setup a new case using the new boundary condition.
Before running the solver we need to:
Then add the line:
libs (paraboloid.so)
to the case controlDict dictionary in the system directory.

How to implement a new boundary condition in OpenFOAM


Paraboloid inlet boundary condition
Remember to always add the newly created boundary condition to your control
dictionary controlDict. If you do not do this OpenFOAM will complain.
Now we are ready to run the case. From the terminal type:
cd $ptofc/mycases1/elbow3d/elbow_paraboloid
blockMesh
surfaceFeatureExtract
snappyHexMesh -overwrite
checkMesh
icoFoam
paraFoam
Note: you will need to modify the boundary file in the directory constant/polyMesh. If you do not know how
to modify the file boundary, take a look at the README.FIRST file for instructions.

How to implement a new boundary condition in OpenFOAM


Paraboloid inlet boundary condition
By following the instructions, you should get something like this

Geometry

How to implement a new boundary condition in OpenFOAM


Paraboloid inlet boundary condition
By following the instructions, you should get something like this

Mesh

How to implement a new boundary condition in OpenFOAM


Paraboloid inlet boundary condition
By following the instructions, you should get something like this

Paraboloid profile

How to implement a new boundary condition in OpenFOAM


Paraboloid inlet boundary condition
By following the instructions, you should get something like this

Velocity magnitude contours in a cut plane

How to implement a new boundary condition in OpenFOAM

Atmospheric boundary layer

How to implement a new boundary condition in OpenFOAM


Atmospheric boundary layer
Starting from the parabolic inlet profile boundary condition, let us now created a new
boundary condition to model the atmospheric boundary layer.
In the directory $ptofc/programming/src/finiteVolume/fields/
fvPatchFields/derived/ablVelocity you will find the new boundary condition.
Take a look at the new boundary condition and identify the changes we have done.
Also, try to figure out what kind of law we used to model the atmospheric boundary layer
inlet profile. In the terminal type:

cd $ptofc/programming/src/finiteVolume/fields/
fvPatchFields/derived/ablVelocity

wmake libso

Starting from OpenFOAM version 2.2.1, the argument libso is not


required anymore

How to implement a new boundary condition in OpenFOAM


Atmospheric boundary layer
If you did not get any error, the new boundary condition is ready to use. wmake
will compile the new boundary condition and will place the new library in the
directory $WM_PROJECT_USER_DIR /platforms/linux64GccDPOpt/lib
(environment variable $FOAM_USER_LIBBIN).
Remember to modify the files located in the Make directory, so they
reflect the location of the new library and its name.
By the way, take a look at the files.

How to implement a new boundary condition in OpenFOAM


Atmospheric boundary layer
Let us now setup a new case using the new boundary condition. From the
terminal:
cd $ptofc/mycases4/building/c0
Before running the solver we need to:
Add the new boundary condition ablVelocity in 0/U.
inflow
{
type
ablVelocity;
n
(1 0 0);
y
(0 1 0);
maxValue 12.3;
value
(0 0 0);
//dummy value
}

How to implement a new boundary condition in OpenFOAM


Atmospheric boundary layer
Let us now setup a new case using the new boundary condition.
Before running the solver we need to:
Then add the line:
libs (ablvelocityBC)
to the case controlDict dictionary in the system directory.

How to implement a new boundary condition in OpenFOAM


Atmospheric boundary layer
Remember to always add the newly created boundary condition to your control
dictionary controlDict. If you do not do this OpenFOAM will complain.
Now we are ready to run the case. From the terminal type:
cd $ptofc/mycases4/building/c0
fluent3DMeshToFoam ../../../meshes/building/
ascii1.msh
checkMesh
simpleFoam
paraFoam
By the way, this case is expensive so you better run in parallel.

How to implement a new boundary condition in OpenFOAM


Atmospheric boundary layer
To run this case, you can use as initial conditions the solution obtained using
potentialFoam. From the terminal type:
cd $ptofc/mycases4/building/potential
rm ./0/*
cp 0org/U 0/U
cp 0org/p 0/p
fluent3DMeshToFoam ../../../meshes/building/
ascii1.msh
checkMesh
potentialFoam writep -noFunctionObjects

How to implement a new boundary condition in OpenFOAM


Atmospheric boundary layer
To run this case, you can use as initial conditions the solution obtained using
potentialFoam. From the terminal type:
cd $ptofc/mycases4/building/c0
rm ./0/*
cp ./0rg/* ./0
cp ../potential/0/U 0/
cp ../potential/0/p 0/
fluent3DMeshToFoam ../../../meshes/building/
ascii1.msh
checkMesh
simpleFoam

How to implement a new boundary condition in OpenFOAM


Atmospheric boundary layer
By following the instructions, you should get something like this

Mesh

How to implement a new boundary condition in OpenFOAM


Atmospheric boundary layer
By following the instructions, you should get something like this

Pressure and velocity contours

How to implement a new boundary condition in OpenFOAM


Atmospheric boundary layer
By following the instructions, you should get something like this

Pressure and velocity contours

How to implement a new boundary condition in OpenFOAM


Atmospheric boundary layer
By following the instructions, you should get something like this

Pressure and velocity contours

How to implement a new boundary condition in OpenFOAM


Atmospheric boundary layer
By following the instructions, you should get something like this

Inlet profile

Todays lecture

1. How to implement a new boundary condition


in OpenFOAM
2. How to implement my own application in
OpenFOAM
3. How to add temperature to icoFoam

This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM and OpenCFD trade marks.

How to implement my own application in OpenFOAM


Remember, all components in OpenFOAM are implemented in library
form for easy re-use. So, in order to implement a new application, we
should follow these basic steps:
The applications implementations are located in $WM_PROJECT_DIR/
applications
To add a new application, start by finding one that does almost what
you want to do. Then, copy that application implementation to
$WM_PROJECT_USER_DIR and modify it according to your needs.
You can also write a solver from scratch. Remember to keep the
prototype body of a solver or utility.
After you finish modifying or writing your own application, compile it
and use it as you normally do.

How to implement my own application in OpenFOAM

Laplace equation solver

How to implement my own application in OpenFOAM


Laplace equation solver
Let us write a solver for the Laplace equation:
In the directory $ptofc/programming/applications/solvers/
my_laplace/ you will find the new application.

From the terminal type:


cd $ptofc/programming/applications/solvers/
my_laplace/
wmake

How to implement my own application in OpenFOAM


Laplace equation solver
If you did not get any error, the new boundary condition is ready to use. wmake
will compile the new boundary condition and will place the new library in the
directory $WM_PROJECT_USER_DIR /platforms/linux64GccDPOpt/bin
(environment variable $FOAM_USER_APPBIN).
Remember to modify the files located in the Make directory, so they
reflect the location of the new library and its name.
By the way, take a look at the files.

How to implement my own application in OpenFOAM


Laplace equation solver
So, what changes did we introduce in my_laplace directory:
We created volumeScalarField T in createFields.H
We created the dimensionedScalar DT in createFields.H
We added the Laplace equation in my_lapace.C
solve
(
fvm::ddt(T) - fvm::laplacian(DT, T)
);

@T
@t

r ( rT )

How to implement my own application in OpenFOAM


Laplace equation solver
So, what changes did we introduce in my_laplace directory:
Additionally we added in my_laplace.C the line:
#include "write.H
This line of code writes out volScalarField gradTx,
volScalarField gradTx and volScalarField gradTx
(the T gradient)

How to implement my own application in OpenFOAM


Laplace equation solver
Let us now setup a new case using my_laplace. From the terminal:
cd $ptofc/mycases0/mylaplace_1
Before running the solver we need to:
Add the new field variable file T to 0 directory.
In fvSchemes, add the following line:
laplacian(DT,T)

Gauss linearUpwind grad(T);

In fvSolution, add the solutions settings for T.

How to implement my own application in OpenFOAM


Laplace equation solver
Remember to always add the new entries to the case dictionaries in the
directory system. Also, you will need to initialize all the fields you use in your
solver. If you do not do this OpenFOAM will complain.
Let us now setup a new case using my_laplace. From the terminal:
blockMesh
my_laplace
Sample latestTime
paraFoam
gnuplot gnuplot_script
evince T_sampling.ps

How to implement my own application in OpenFOAM


Laplace equation solver
By following the instructions, you should get something like this

Mesh (5 cells)

How to implement my own application in OpenFOAM


Laplace equation solver
By following the instructions, you should get something like this
260

260

Analytical solution
Numerical solution

240

240

220

220

200

200

180

180

160

160

140

140

120

120

100

Analytical solution
Numerical solution

100
0

0.005

0.01

5 cells

0.015

0.02

0.005

0.01

100 cells

Comparison analytical solution versus numerical solution

0.015

0.02

Todays lecture

1. How to implement a new boundary condition


in OpenFOAM
2. How to implement my own application in
OpenFOAM
3. How to add temperature to icoFoam

This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM and OpenCFD trade marks.

How to add temperature to icoFoam


Hereafter we will modify an existing solver (icoFoam).
The modification will consist in adding temperature to the solver.
We will need to copy the original solver into the directory
$WM_PROJECT_USER_DIR. Remember to use the exact directory structure.
After creating the new applications directory, various small changes are
necessary to introduce in the solver files.
Finally, the new field (temperature), needs to be added to the initial and
boundary conditions. Also, we need to tell to OpenFOAM how to discretize
the new terms, this is done in the fvSchemes dictionary. In the
fvSolution dictionary, we need to set the solver that we want to use to
solve the field temperature.

How to add temperature to icoFoam


In the folder $ptofc/programming/applications/solvers/
icoFoam/, you will find a copy of the original icoFoam solver. Let us copy
the content of this folder to the folder my_icoFoam. From the terminal:
cp -r $ptofc/programming/applications/solvers/
icoFoam/ $ptofc/programming/applications/solvers/
my_icoFoam/
Now rename the file icoFoam.C to my_icoFoam.C.

mv icoFoam.C my_icoFoam.C

Remember, the directory and the file must have the same name.

How to add temperature to icoFoam


Now go to the Make sub-directory, and open the file files with your favorite
editor and add the following changes:
my_icoFoam.C
EXE = $(FOAM_USER_APPBIN)/my_icoFoam
No changes are necessary for the file options.
Now go back to the my_icoFoam directory and compile the application. In
the terminal,
cd ..

How to add temperature to icoFoam


Before compiling the new application, make sure that you do not have old
binaries, old object files or old dependencies files in your application
directory. In the terminal:
wclean
This will clean the directory.
Now we are ready to compile the new application. In the terminal:
wmake
If everything went fine, your new solver binary should be in the
$FOAM_USER_APPBIN directory. Check this with:
ls $FOAM_USER_APPBIN
You should see the new solver my_icoFoam in this directory.

How to add temperature to icoFoam

So far we only compiled the application with a new name.


Let us now add the necessary changes in order to solve the temperature
field.

How to add temperature to icoFoam


First, we need to create the new temperature field. Open the
createFields.H file using your favorite editor.
The first thing we can notice in createFields.H is that OpenFOAM loads
the kinematic viscosity from the transportProperties dictionary file. Let
us add a new transport property related to the thermal diffusion which we will
denote as DT. Make the following changes:
dimensionedScalar nu
(
//Look for these lines
transportProperties.lookup("nu"));
//Starting from here add this line
dimensionedScalar DT
(
transportProperties.lookup("DT")
);
//Done adding new lines

How to add temperature to icoFoam


If you keep reading the file, you will see that the scalar field p
(volScalarField) and the velocity field U (volVectorField) are
created. We need to add the new field for temperature T
(volScalarField).
After the creation of the field U and before the line #include
createPhi.H, add the following lines:
Info<< "Reading field T\n" <<endl;
volScalarField T
(
IOobject
(
"T",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);

How to add temperature to icoFoam


Save the modifications in createFields.H. At this point we have created
the new field T and the new transport property DT.
Let us now add the new equation to solve. Recalling that we want to add the
transport equation for the scalar T (temperature) to the current solver

T
+ (T )
t

( T ) = 0

Using OpenFOAM equation mimicking syntax, we can write this equation


as
fvScalarMatrix TEqn
(
fvm::ddt(T)
+
fvm::div(phi,T)
fvm::laplacian(nu,T)
);
Teqn.solve( );

How to add temperature to icoFoam


Now, we need to add the new equation to the file my_icoFoam.C. Using
your favorite editor add the following modifications.
Because the temperature transport depends on the velocity field, we will add
the equation after the momentum equation is solved (after the PISO loop),
but before the time step is written. Edit your file so it looks like this:
U -= rAU*fvc::grad(p);
U.correctBoundaryConditions( );
}
//Starting from here add these lines
fvScalarMatrix TEqn
(
fvm::ddt(T)
+
fvm::div(phi,T)
fvm::laplacian(nu,T)
);
Teqn.solve( );
//End adding lines
runTime.write();

How to add temperature to icoFoam


Save the modifications and compile the new solver. From the terminal
wclean
wmake
If everything went fine, your new solver binary should be in the
$FOAM_USER_APPBIN directory. Check this with:
ls $FOAM_USER_APPBIN
You should see the new solver my_icoFoam in this directory.

How to add temperature to icoFoam


The next step is to test the new solver.
Go to the directory $ptofc/mycases1/elbow2d_1/
elbow_plus_temperature. In the terminal:
cd $ptofc/mycases1/elbow2d_1/elbow_plus_temperature
In this directory you will find the case setup files for a case using
my_icoFoam solver.

How to add temperature to icoFoam


Notice that we need to create the field file for T in the 0 directory (initial and
boundary conditions).
We also need to add the new transport property to the
transportProperty dictionary in the constant directory.
We need to tell to OpenFOAM how to discretize the new equations. This
is done in the fvSchemes dictionary in the system directory.
Finally, you will need to tell to OpenFOAM how to solve the field T. This is
done in the fvSolution dictionary in the system directory.
Take a look at these files (T, transportProperties, fvSchemes and
fvSolution) and identify all the additions and changes made.
Always remember, OpenFOAM is fully dimensional so your
dimensions must be consistent.

How to add temperature to icoFoam


We will now use the new solver. From now on follow me.
cd $ptofc/mycases1/elbow2d_1/
elbow_plus_temperature
fluentMeshToFoam ../../../meshes/elbow2d_1/
ascii.msh
checkMesh
my_icoFoam
paraFoam

How to implement my own application in OpenFOAM


By following the instructions, you should get something like this

Mesh

How to implement my own application in OpenFOAM


By following the instructions, you should get something like this

Contours of velocity magnitude and temperature

How to implement my own application in OpenFOAM


By following the instructions, you should get something like this

Contours of pressure

How to add temperature to icoFoam

In the directory $ptofc/mycases1/elbow2d_1/, you will find various


setup for the same geometry. For instance you could use the solver
my_icoFoam with the parabolic inlet boundary condition we previously
created (elbow_parabolic_inlet_plus_temperature).
Try to run all cases and identify the changes in the dictionaries.

How to add temperature to icoFoam


Remember, all components in OpenFOAM are implemented in library form for
easy re-use. So, in order to implement a new application, we should follow
these basic steps:
The applications implementations are located in $WM_PROJECT_DIR/
applications
To create a new application, start by finding one that does almost what you
want to do. Then, copy that application implementation to your user directory
$WM_PROJECT_USER_DIR and modify it according to your needs.
You can also write a solver from scratch. Remember to keep the prototype
body of a solver.
After you finish modifying or writing your application, compile it and use it as
you normally do.

How to add temperature to icoFoam

At this point you should be able


to modify OpenFOAM solvers
and utilities, and create your own
applications and boundary
conditions.

Mesh generation using open source tools

Additional tutorials
In the folders $ptofc/programming/applications and
$ptofc/programming/src you will find many tutorials, try to go through each one to
understand how to program in OpenFOAM.

Thank you for your attention

Hands-on session

In the courses directory ($ptofc) you will find many tutorials (which are different from
those that come with the OpenFOAM installation), let us try to go through each one to
understand and get functional using OpenFOAM.
If you have a case of your own, let me know and I will try to do my best to help you to
setup your case. But remember, the physics is yours.
This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM and OpenCFD trade marks.

These lectures notes are licensed under the Creative Commons


Attribution-ShareAlike 4.0 International License.
To view a copy of this license, visit
http://creativecommons.org/licenses/by-sa/4.0/

You might also like