OpenFOAM WorkshopCopy the tutorial directory •Load OpenFOAM software on the login node (only small...
Transcript of OpenFOAM WorkshopCopy the tutorial directory •Load OpenFOAM software on the login node (only small...
OpenFOAM WorkshopComputational Fluid Dynamics – Special Interest Group
Giulio Vita, Bruño Fraga
University of Birmingham, 26th Feb 2020
Outline• Definition of problem
• Working with a new Solver
• BlueBEAR and CFD solvers
• Numerical Simulation with OpenFOAM• Domain definition
• Domain discretisation
• Equation discretisation (numerical method)
• Fluid Properties
• Initial Conditions
• Boundary Conditions
• Solution
• Results Analysis with OpenFOAM and ParaView
• Q&A and Feedback: How can we help? The CFD-SIG of UoB
Definition of Problem• Backward facing step
• Inflow velocity: 12 m/s
• Incompressible, viscous fluid, nu = 1.5e-5 (air)
• Buoyancy neglected: no need to specify gravity
• Single phase flow
• Steady simulation (for the moment)
Inlet Velocity
Outlet Pressure
Wall
Wall
2D geometry
Working with a new solver• 2 main sources for failure
• Solver Choice: Code not capable to do what we need to do!
• User Capability: We do not know how to do it with the solver of choice!
• Benchmarking• Previous problem solved having similar geometry, physics, conditions
• Validation & Training• Benchmark to validate solver of choice (is it able to solve my problem?)
• Benchmark to train the user to implement the solver
BlueBEAR and CFD solvers• Massive use of resources due to CFD simulations: CARE & PATIENCE
• Preparation of (multiple) scripts: instructions to be run by the HPC
• Work in serial or parallel
• Commenting commands – log & error files
BlueBEAR and CFD solvers• Hands-on: writing a script for the OpenFOAM workshop
• 20 processors
• over 1 Haswell node
• using 120GB of RAM
• bbshort job queue (for inexpensive jobs and debugging-testing)
• for the maximum allowed time 0:10:0 for this queue
• Specify to send email when job starts, fails or ends
• Specify to write error message in separate file
• Settings requested by OpenFOAM (set of computation directory etc etc)
• Load the software
• All the commands you want to execute
• DO NOT RUN JOBS IN THE LOGIN NODES!
OpenFOAM software
• 3 versions of the software• OpenFOAM – www.openfoam.org – currently patch released v.7 (Sep 2019)
• OpenFOAMplus – www.openfoam.com – currently released v1912 (Dec 2019)
• OpenFOAMextended - https://sourceforge.net/projects/foam-extend/
• Versions installed in bluebear• https://bear-apps.bham.ac.uk/
• https://bear-apps.bham.ac.uk/applications/OpenFOAM/
Getting Started: Ancillary softwares
• Putty• SSH client to navigate the blueBEAR linux environment
• Set Putty correctly
• Enable X11 forwarding (to open GUI softwares from blueBEAR)
• WinSCP• FTP software to input data from windows into blueBEAR
• Also good as GUI to visualise and edit text files
• Exceed• To operate any GUI software from blueBEAR
Numerical Simulation with OpenFOAM
• Domain definition (geometry from CAD software)
• Domain discretisation (either in OpenFOAM or from MESH software)
• Equation discretisation (numerical method)
• Fluid Properties
• Initial Conditions
• Boundary Conditions
• Solution
• Each step corresponds to a text file in the OpenFOAM directory
• Hands on: let’s create our directory!
OpenFOAM Directory• /yourHomePageDirectory/case
• 0/
• U
• p
• k
• epsilon
• constant/
• polyMesh/
• boundary
• …
• transportProperties
• turbulenceProperties
• system/
• controlDict
• fvSchemes
• fvSolution
• decomposeParDict
OpenFOAM Directory• /yourHomePageDirectory/case
• 0/
• U
• p
• k
• epsilon
• constant/
• polyMesh/
• boundary
• …
• transportProperties
• turbulenceProperties
• system/
• controlDict
• fvSchemes
• fvSolution
• decomposeParDict
0/ directory - initial and boundary conditions for every variablein this case U p k and epsilon
constant/ directorymesh, physical and turbulence model properties
system/ directoryfinite volume algorithm – simulation controls – parallel solution
• Further directories may be created by OpenFOAM depending on solution, results etc
Copy the tutorial directory
• Load OpenFOAM software on the login node (only small commands)> module load bluebear
> module load bear-apps/2019b
> module load OpenFOAM/v1912-foss-2019b
> source ${FOAM_BASH}
• View and navigate $FOAM_TUTORIALS directory to choose tutorial> ls $FOAM_TUTORIALS
• Copy tutorial into case directory (simpleFoam solver for RANS)> cp –r $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily .
• Rename tutorial into case directory> ls
> mv pitzDaily/ case/
The 0/ directory
• Go into 0/ directory (only small commands)> cd 0/
> ls
epsilon f k nut nuTilda omega p U v2
• Edit epsilon k p U with text editor> gedit epsilon (if exceed is running)
> nano epsilon (pre-built text editor in Linux)
> open case directory on winSCP (FTP client for windows – if preinstalled)
OpenFOAM dictionaries
• Dictionary: text file with instructions composed by
• header/*--------------------------------*- C++ -*----------------------------------*\| ========= | || \\ / F ield | OpenFOAM: The Open Source CFD Toolbox || \\ / O peration | Version: v1912 || \\ / A nd | Website: www.openfoam.com || \\/ M anipulation | |\*---------------------------------------------------------------------------*/
• descriptionFoamFile{
version 2.0;format ascii;class volScalarField;location "0";object epsilon;
}// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
OpenFOAM dictionaries• Instructionsdimensions [0 2 -3 0 0 0 0];
internalField uniform 14.855;
boundaryField
{
inlet
{
type fixedValue;
value uniform 14.855;
}
outlet
{
type zeroGradient;
}
upperWall
{
type epsilonWallFunction;
value uniform 14.855;
}
lowerWall
{
type epsilonWallFunction;
value uniform 14.855;
}
frontAndBack
{
type empty;
}
}
[ M L T K etc..]
Initial conditions for volume field
Boundary and Initial conditions for surfaces
Leibniz boundary condition for outlet velocity
Wall function
2D geometry
The constant/ directory
• Go into constant/ directory> cd ../constant/
> ls
transportProperties turbulenceProperties
• transportProperties defines fluid properties• Newtonian fluid kinematic viscosity (OpenFOAM incompressible)
• turbulenceProperties defines turbulence model properties• K-epsilon – k-omega SST – model constants are all specified here
• Mesh is stored in the polyMesh/ directory> cd polyMesh/
No polyMesh directory means mesh has not been generated yet
Mesh Generation (blockMesh)• Mesh generation can be done in several ways
• blockMesh utility provided in OpenFOAM (as in this case, simple geometry)> cd ../system
> ls
blockMeshDict controlDict fvSchemes fvSolution streamlines
• snappyHexMesh utility also provided in OpenFOAM (more complex geometries)
• Generate the mesh externally (Fluent etc) and then import it into OpenFOAM, e.g.:> fluentMeshToFoam
• Mesh generation using the blockMesh utility
• View blockMesh Dictionary> gedit blockMeshDict
• Generate mesh inputting utility> blockMesh
> blockMesh > log.block (better option)
• Check Mesh Quality> checkMesh > log.check
Mesh visualisation
• OpenFOAM utility to run Paraview (if exceed is running…)> paraFoam
• Or export the mesh into another format e.g. Fluent or Ensight> foamMeshToFluent > log.fluent
> foamToEnsight –constant > log.ensight (alternatively)
The system/ directory
• Go into system/ directory> cd ../system/
> ls
blockMeshDict controlDict fvSchemes fvSolution streamlines
• Manage all numerical aspects of your simulation
• controlDict controls all solver settings• iterations/time steps, libraries, sampling etc…
• fvSchemes controls the Finite Volume schemes• gradient, laplacian, divergence etc – central difference, upwind etc
• fvSolution controls the solution algorithms for the linear system• CholeskyGauss, DILU triangulation – simple algorithm settings
• streamlines is a specific instruction for additional utilities• In this case generation of streamlines – sampling – probing – etc…
The banana method• Tricky to know and keep in mind all possible settings
• Editing fvSchemes and fvSolution dictionaries> gedit fvSchemes
• Substitute any entry with the keyword (the instruction) banana> cd ../
> simpleFoam > log.simple (very small case -> never the case, use a script to debug!)
> gedit log.simple
--> FOAM FATAL IO ERROR:
Unknown convection type banana
Valid convection types :
2(Gauss bounded)
• Use OpenFOAM errors to navigate the software options and…
… never question the banana method!
Set your solver for simulation
• Fix back the fvSchemes dictionary and open fvSolution> gedit fvSolution
• Solution algorithms for U p k epsilon
• Settings for the solver (simple algorithm in this case)SIMPLE
{
nNonOrthogonalCorrectors 0;
consistent yes;
residualControl
{
p 1e-2;
U 1e-3;
"(k|epsilon|omega|f|v2)" 1e-3;
}
• nNonOrthogonalCorrectors helps convergence for (really) bad meshes • residualControl sets the residual limit to be reached after the software reaches numerical convergence
Set your solver for simulation• Open controlDictapplication 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
{
#includeFunc streamlines
}
• Algorithm to be used (not necessary, from an old version of OpenFOAM)
• Where solver starts – from initial time or resume calculations from previous timestep?
• Entry needed only if startTime is specified for startFrom
• When solver stops – if convergence is reached set in fvSolution solver stops before
• in this case time is not a physical time, but is the number of iterations
• 1 for steady simulations – any number for transient simulations
• Instructions to write results
• How many writeControl intervals are results written?
• How many results file to keep (last 10 files)
• Alternatively binary – keep ascii if you want to read dictionaries with a text editor
• Entries can be modified while the software is running (more complex simulations)
• Functions are extra commands executed while solving
• In this case streamlines dictionary (alternatively streamlines content can be copied here)
Submit your job in bluebear with a script• Create new script file in case/ directory
> gedit runCase (easy name preferrably)
• Set scheduler and queue (qos) to submit your job to (bbshort or bbdefault)#!/bin/bash#SBATCH --qos bbshort
• Set up the node usage (usually 50000-10000 cells per processor) Different possibilities in BlueBEAR
• Sandybridge nodes (2015)> #SBATCH --constraint sandybridge> #SBATCH --ntasks 16> #SBATCH --nodes 1> #SBATCH –mem-per-cpu 1850
• Broadwell nodes (2017)> #SBATCH --constraint haswell> #SBATCH --ntasks 20> #SBATCH --nodes 1> #SBATCH --mem 120G
• CascadeLake nodes (2019)> #SBATCH --constraint cascadelake> #SBATCH --ntasks 40> #SBATCH --nodes 1> #SBATCH --mem 180G
• Name your simulation for reference> #SBATCH --job-name OpenFOAMcase
• Give your simulation a time limit> #SBATCH --time 0:10:0 (10 mins max time for bbshort – 10 days max time for bbdefault)
• Additional settings for this training> #SBATCH --reservation=OpenFOAM
> #SBATCH --account=ghumraak-bluebear-training
Submit your job in bluebear with a script
• Tell OpenFOAM what to do• Load blueBEAR environment
> module purge
> module load bluebear
> module load bear-apps/2019b
• Load OpenFOAM> module load OpenFOAM/v1912-foss-2019b
> source ${FOAM_BASH}
• List OpenFOAM commands to run within a script> blockMesh > log.block
> checkMesh > log.check
> simpleFoam > log.simple (serial simulation)> foamToEnsight > log.ensight
• Convergence history> foamLog log.simple > log.log
Ansys interoperability
• The University of Birmingham has a Campus licence for Ansys
• OpenFOAM works quite well combined with ansys• Meshing with IcemCFD or Fluent or Ansys Meshing
> fluentMeshToFoam mesh.msh > log.mesh
• Post-processing with Fluent or CFX> foamMeshToFluent > log.meshfluent
> foamDataToFluent > log.fluent (requires a foamDataToFluentDict)
• Best option is Ensight (not available as standard, but available on request, difficult to use)> foamToEnsight > log.ensight
• Alternatively many formats are available (Tecplot, vtk, etc)> foamToTecplot360 > log.tecplot
> foamToVtk > log.vtk
• ParaView is the OpenFOAM built-in option (difficult to use)> paraFoam (if exceed is running)
Aspects not covered by this presentation
• Parallel Computing• decomposeParDict dictionary in system/ directory• mpirun utility to run your simulation (instead of simpleFoam utility)
• Meshing with blockMesh (more details in https://cfd.direct/openfoam/user-guide/v6-blockmesh/)
• Meshing with snappyHexMesh (more details in https://cfd.direct/openfoam/user-guide/v6-snappyhexmesh/)
• Post-processing within OpenFOAM using paraView (can be installed on personal pc https://mysoftware.bham.ac.uk/default.aspx more info on https://cfd.direct/openfoam/user-guide/v6-paraview/)
• For ansys interoperability: map your home BEAR folder in Windows https://intranet.birmingham.ac.uk/it/teams/infrastructure/research/bear/HowTo/HowToRDS.aspx
How are you getting on?
• The CFD-SIG is here to help
• Any questions about the OpenFOAM training?
• Any questions about your simulations?
• Would advanced OpenFOAM training be useful?
Thanks for participating!