# Synthetic turbulence generation

**URL:** <https://pyfr.discourse.group/t/synthetic-turbulence-generation/513>\
**Category:** General\
**Created:** [14 December 2021 15:58 UTC](https://pyfr.discourse.group/t/synthetic-turbulence-generation/513 "2021-12-14T15:58:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giorgio\_Giangaspero](https://avatars.discourse-cdn.com/v4/letter/g/ce73a5/32.png) [@Giorgio\_Giangaspero](https://pyfr.discourse.group/u/Giorgio_Giangaspero)\
**Post date:** [14 December 2021 15:58 UTC](https://pyfr.discourse.group/t/synthetic-turbulence-generation/513/1 "2021-12-14T15:58:14Z")

</div>

Our paper on Synthetic turbulence generation with PyFR has been recently published in the AIAA Journal, see [here](https://arc.aiaa.org/doi/10.2514/1.J061046). The paper describes in details the extended Synthetic Eddy Method that was introduced previously in one of our seminars [here](https://doi.org/10.52843/cassyni.249z01), where you can find also some additional results.

The main features of the method are the following:

- source term formulation, which allows synthetic turbulence to be injected anywhere in the domain
- full anisotropy of the length scales (with a limitation on the minimum length scale ratio for a given direction, see eq.(16) in the paper or slide 13 of the seminar)
- works with the compressible and with the incompressible solver

The main limitations, which can be lifted with a bit of development, are the following:

- homogeneous turbulence in the z direction, which is assumed to be the spanwise direction
- the x-direction is assumed to be the streamwise direction

In the electronic supplemental material associated to the paper one can find the source files, mesh files and input files.

---

<div class="post-metadata">

**Author:** ![Giorgio\_Giangaspero](https://avatars.discourse-cdn.com/v4/letter/g/ce73a5/32.png) [@Giorgio\_Giangaspero](https://pyfr.discourse.group/u/Giorgio_Giangaspero)\
**Post date:** [14 December 2021 16:01 UTC](https://pyfr.discourse.group/t/synthetic-turbulence-generation/513/2 "2021-12-14T16:01:32Z")

</div>

A more recent version of the source can be obtained by checking out [this github branch](https://github.com/GiorgioGiangaspero/PyFR/tree/turb_injection_SEM_localLTurb_prepPR). In particular, this has been updated up to v1.12.2. Regarding the turbulence generator, there are a few implementation details that have been changed compared to the version published with the paper. For instance, the eddies’ data is stored directly in the solution file, rather than in a separate .csv files. Also, the turbulence generator loops over only the 5 eddies closest to a given element (rather than looping over all eddies), which are determined using a kd-tree. A consequence of this latter implementation strategy is that the overhead of the turbulence generator is almost independent of the total number of eddies (at least for N \<150) and also that the custom load-balancing strategy might not be necessary anymore. Preliminary tests gave a slowdown of less than 10% with standard mesh partitioning.

Here is an example of the relevant section that should be in the .ini file:

```auto
[soln-plugin-turbulencegenerator]
; how often to update the location of eddies
nsteps = 1
; reynolds stress components. can be function of xyz
r00 = 0.2
r11 = 0.05
r22 = 0.1
r01 = 0.001
; length scales, can be function of xyz
l00 = 0.3
l01 = 0.2
l02 = 0.2
l10 = 0.2
l11 = 0.1
l12 = 0.1
l20 = 0.1
l21 = 0.1
l22 = 0.1
; reference lengths, see eq. (14) in the paper
lturbref = [0.3 0.2, 0.1]
; Bulk velocity
Ubulk = 1.0
; bulk velocity direction 0=x, 1=y, 2=z. (x recommended)
Ubulk-dir = 0
; center of the turbulence generating plane
center = [-1.0, 0.0, 0.1]
; dimensions of the turbulence generation plane.
; if x is streamwise, these two represent the dimension of the plane in y and z
plane-dimensions = [1.0, 0.2]
; mean density and mean mach number. Only needed for a compressible solver.
rhomean = rho0
Mmean = Ma

```

Finally, for those interested in profiling and optimisation, with the help of @WillT I have created a standalone version of the relevant kernel, see [this file](https://www.dropbox.com/s/7ohl4cvvz9mdw5c/single.cu?dl=0) and [this file](https://www.dropbox.com/s/eqpvaatbeudm9lr/negdivconf.cu?dl=0).  
They can be compiled with:  
`nvcc -pg -lineinfo -O3 --gpu-code=compute_70 --gpu-architecture=compute_70 --std=c++17 --use_fast_math --fassociative-math single.cu negdivconf.cu -o go`  
and profiled with nvidia nsight.
