Tutorial for Channel Flow by LES using Open Source CFD Máté Márton Lohász February 2011 i
CONTENTS ii Contents 1 Overview 1 2 Set up your environment 1 3 Very short intro to OpenFOAM 1 3.1 Simulation set-up............................ 1 3.1.1 Timestep directories...................... 2 3.1.2 constant directory........................ 2 4 Meshing 2 5 Physical parameters 2 6 Inlet condition 2 7 Model parameters 2 8 Numerical settings 3 9 Time step 3 10 Simulation of the temporal transition 3 11 Time averaging 4 12 Validation 6 13 Using the cluster 7 14 Content of the LESchannel package 9
NOMENCLATURE 1 1 Overview 2 Set up your environment Login to our small cluster. ssh 152.66.21.39 If you login first time, you have to answer some (3) questions by ENTER. Login to a compute node using an interactive job. qlogin -P LEScourse OF17 Set up the OpenFOAM environmental variables Create your working directory: mkdir -p $FOAM_RUN run pwd cd.. Go to your working (run) directory: Check the path of your directory! Download the prepared case data. wget http://www.ara.bme.hu/~lohasz/lescourse/package_post.tar.gz Extract the package. tar -Pxvf package_post.tar.gz 3 Very short intro to OpenFOAM A much better intro can be found on the webpage of the code: http://www.openfoam. org. A course is given every autumn at Chalmers University: http://www.tfd. chalmers.se/~hani/teaching.html. OpenFOAM is a open-source environment for solving PDE s by finite volume techniques. In many aspects is very similar to ANSYS-Fluent. The biggest difference is that is only available for Linux, it is free to use, but it has no GUI. It is written in C++ (Fluent is written in C), so it is object oriented. In some cases the source code can be consider as easy to read. 3.1 Simulation set-up The simulation settings are not saved in some files as in Fluent but in a directory structure.
4 MESHING 2 3.1.1 Timestep directories The 0 directory contains the initial and the boundary conditions. The results of the simulations are also saved in directories named after the actual time. For our case the boundary conditions will be always the same there no further explanation is given. 3.1.2 constant directory This directory contains important settings 4 Meshing run cd LESchannel Modify the mesh if needed: vi constant/polymesh/blockmeshdict Create the mesh blockmesh 5 Physical parameters Check the transport properties vi constant/transportproperties 6 Inlet condition Create the "turbulent" initial condition perturbu 7 Model parameters Edit the LES properties vi constant/lesproperties Check the SGS model //LESModel Smagorinsky; LESModel dynamicsmagorinsky; The first (Smagorinsky) is commented above. Check the evaluation of the filter width: delta dummy; Since the use of dummy you will have an error message, where you will see the available options for delta. This can be used everywhere in OF. Set it to cuberootvol.
8 NUMERICAL SETTINGS 3 8 Numerical settings Set the numerical parameters. Edit (check) the fvschemes file. Time advancement (similar to the second order of Fluent) ddtschemes { default } backward; Momentum convection scheme (corresponds to second order central scheme): divschemes { div(phi,u) } Gauss linear; The solution of the linearised equation system is set in fvsolution, also the parameters of the pressure-velocity coupling (PISO in our case) are defined here. 9 Time step The timestep can be set in the controldict file vi system/controldict deltat 0.2; 10 Simulation of the temporal transition When simulating the temporal laminar-turbulent transition prior to a turbulent LES simulation some quantities needs to be selected to be plotted during the simulation to determine the required simulation time. Since the turbulent kinetic energy (TKE) has specific temporal character during transition it is useful to plot it. But generally TKE is difficult to plot since we are not in the position of the average velocities, i.e. the fluctuations can not be determined. For the channel flow the average velocity in the span-wise and in the wall-normal component is zero, i.e. the corresponding fluctuations can be computed easily. Set the endtime of your simulation for the time you expect transition. During this time there will be no time averaging. Set 500 for the present setting vi system/controldict endtime 500; Run the simulation (in this case interactively) LMchannelFoam >> log & Check the "tail" of the log file to see the progress of the simulation.
11 TIME AVERAGING 4 tail -n20 log Check if transition is finished. For this purpose post-process the log file. foamlog log cd logs gnuplot plot "volavuy2_0", "volavuz2_0" exit cd.. Normally you should see 1 the peak in the two "components" of TKE and than the fluctuation around a value. If this is not the case continue the simulation as required. The plotting (saving the figures in png format) can be done using the provided script: gnuplot trans.gnuplot 11 Time averaging After the temporal transition you should carry out temporal simulation to determine the statistical averages of the flow. In this case the streamwise velocity profile and the profiles of Reynolds stress tensor. Modify the controdict to switch on the averaging. functions { fieldaverage1 { type fieldaverage; functionobjectlibs ( "libfieldfunctionobjects.so" ); enabled false; } } Insert some probes to see the temporal convergence of velocities and the Reynolds stress tensor. The following function should be embedded to the functions section, inside the curly brackets. probes { type probes; functionobjectlibs ("libsampling.so"); 1 If you are not in a graphical session you can not plot obviously, download the files and plot it on your local machine
11 TIME AVERAGING 5 enabled true; outputcontrol timestep; outputinterval 1; probelocations ( ( 1 1 1 ) ( 2 1 1 ) ( 1 0.1 1 ) ); fields ( U UPrime2Mean UMean } ); Modify the endtime variable (in controldict) to a higher value, i.e. 2000. Continue the simulation LMchannelFoam >>log & Plot the convergence of your simulation cd probes/aaaa gnuplot Here AAAA stand for the last time-step of your directory. You can list them by typing ls Use the following commands in gnuplot! First plot the time signal of the wall normal velocity at the three different points. plot "< tr ( < U" using 1:3, "< tr ( < U" \ using 1:6, "< tr ( < U" using 1:9 You can see which signal is at different y position, i.e. wall distance, since the fluctuation close to the wall is higher. Now plot the time average (always until the actual plotted time instance) of these velocities. plot "< tr ( < UMean" using 1:3, "< tr ( \ < UMean" using 1:6, "< tr ( < UMean" using 1:9 It is also very important to plot the Reynolds stress components. The streamwise fluctuation square in the first probe location, (1 1 1) in our example is plotted as follows: plot "< tr ( < UPrime2Mean" using 1:2 The other locations can plotted by adding 6 to the last number:
12 VALIDATION 6 plot "< tr ( < UPrime2Mean" using 1:2, "< tr ( \ < UPrime2Mean" using 1:8 If you plot also the third location, you will more clearly the importance of your variation. plot "< tr ( < UPrime2Mean" using 1:2, "< tr ( \ > < UPrime2Mean" using 1:8, "< tr ( < \ UPrime2Mean" using 1:14 The plotting (saving the figures in png format) can be done using the provided script (you should edit the script if needed): gnuplot conv.gnuplot We should see in any case some type of convergence to an unknown (or known) value. In some cases this value is known to be zero, which facilitates the judgement. If you decide that your simulation is not converged enough, continue it! 12 Validation The results can be validated by comparing them to know profiles. Before doing this a spatial averaging can be carried out to improve the confidence of the statistical convergence. Carry out the spatial averaging and the extraction of the profiles. postchannel -latesttime Enter the latest time-step directory cd AAAA gnuplot Plot the Reynolds stress normal components. plot "u.xy", "v.xy", "w.xy" Plot the logarithmic velocity profile. plot "Uf.xy" set log x plot "Uf.xy" unset log x The plotting (saving the figures in png format) can be done using the provided script (you should edit the script if needed): gnuplot valid.gnuplot
13 USING THE CLUSTER 7 13 Using the cluster For running a long simulation you have to divide your simulation in multiple parts. The cluster management (queuing system) only allows a maximum 24 hours long simulation time. Your simulation is dived into at least two parts, first the simulation of the transition. We estimate the length of the transition to be 1000 sec, and we hope that it will be possible to simulate it in a shorter time than 24 hours. During this part of the simulation nighters the averaging nor the probes are enabled. The second part of the simulation is the time averaging. We can not be sure that this simulation is shorter than 24 hours, so we divide our simulation into some hours (e.g. 3600 sec) of simulation, which will follow each-other, in this case we don not specify the endtime of the simulation explicitly but save our date after e.g. 3600 sec of simulation time. The two steps described before can be efficiently carried out when we comment out the setting for the not used simulation in the controldict file as shown below. application startfrom starttime 0; LMchannelFoam; latesttime; //stopat endtime; stopat nextwrite; endtime 1000; deltat 0.2; //writecontrol timestep; writecontrol clocktime; //writeinterval 200; writeinterval 3600; purgewrite 3; writeformat writeprecision 6; binary; writecompression compressed; timeformat timeprecision 6; general; runtimemodifiable yes; The actual setting corresponds to the averaging.
13 USING THE CLUSTER 8 You can do the simulation by typing the following command (you should be at the simulation directory): qsub LES.run LES.run is is script file, which looks like: #!/bin/bash #$ -cwd #$ -S /bin/bash #$ -m aes #$ -M hbamba@gmail.com #$ -j y #$ -P LEScourse #$ -V. /share/apps/usr/openfoam/openfoam-1.7.1/etc/bashrc LMchannelFoam >> log This file specifies that you want to run the command LMchannelFoam» log. It set up a email address where information will be sent. The previous line set up the environmental variables needed by the code. In the case you are running the averaging, you have to submit more jobs which follow each-other after the previous one finished execution. This can be done easily: [lohasz@kovasznayl LESchannel_DMS]$ qsub LES.run Your job 1492 ("LES.run") has been submitted [lohasz@kovasznayl LESchannel_DMS]$ qsub -hold_jid 1492 LES.run Your job 1493 ("LES.run") has been submitted [lohasz@kovasznayl LESchannel_DMS]$ qsub -hold_jid 1493 LES.run Your job 1498 ("LES.run") has been submitted In this case you specify the previous job by the -hold_jid AAA flag, where AAA is job id of your previous job. So if your job finished the next one will start immediately. You have to specify so many consecutive jobs, that you averaging time is enough, you can also increase the length of the jobs by changing writeinterval 3600; to a higher value below 82800.
14 CONTENT OF THE LESCHANNEL PACKAGE 9 14 Content of the LESchannel package ~/.foamlog.db $FOAM_RUN/LESchannel/ $FOAM_RUN/../src/