Implement A Passive Scalar Transport Solver: Håkan Nilsson 1
Implement A Passive Scalar Transport Solver: Håkan Nilsson 1
Prerequisites
• You are familiar with the directory structure of OpenFOAM applications.
• You are familiar with user compilation procedures of applications.
• You are familiar with the fundamental high-level components of application codes, and how
new classes can be introduced to an application.
Learning outcomes
• You will practice high-level coding and modification of solvers.
• You will adapt case set-ups according to the new solver.
• You will improve your understanding of classes and object orientation, from a high-level
perspective.
Note that you will be asked to pack up your final cleaned-up directories and submit them for
assessment of completion:
passiveScalarPimpleFoam
passiveScalarPitzDaily
(not the icoFoam/cavity alternative)
Copy the icoFoam solver, rename it, and test that it still compiles
• We copy the icoFoam solver and put it in our $WM_PROJECT_USER_DIR with the same file
structure as in the OpenFOAM installation:
foam
cp -r --parents applications/solvers/incompressible/icoFoam $WM_PROJECT_USER_DIR
cd $WM_PROJECT_USER_DIR/applications/solvers/incompressible
mv icoFoam passiveScalarIcoFoam
cd passiveScalarIcoFoam
wclean
mv icoFoam.C passiveScalarIcoFoam.C
Make sure that you understand what this command does, and why it is done!
Make sure that you understand why those modifications are made, and why the pieces of code
are put at those exact locations! Why don’t we have to do more modifications?
− Copy the 0/p file to 0/s and modify p to s in that file. Choose approprate dimensions
for the scalar field (not important now).
− In fvSchemes, add (if you don’t, it will complain):
div(phi,s) Gauss linearUpwind grad(U);
− In fvSolution, copy the solution settings from U (since the equations for velocity
and s are similar), and just change U to s. (if you use PCG, as for p, it will complain
- try it yourself!)
Make sure that you understand why those modifications are made! Why don’t we have to do
more modifications?
− Set defaultFieldValues:
volScalarFieldValue s 0
− Modify the bounding box to:
box (0.03 0.03 -1) (0.06 0.06 1);
− Set fieldValues:
volScalarFieldValue s 1
• You can see that although there is no diffusion term in the equation, there is massive diffu-
sion in the results. This is due to mesh resolution, numerical scheme etc. The interfoam
solver has a special treatment to reduce this kind of diffusion.