Giter VIP home page Giter VIP logo

2d-turbulence-python's Introduction

Decaying Turbulence in Python (OOP)

Build Status

Coverage Status

DOI

Pseudo-spectral collocation code for two-dimensional turbulence simulations written in object-oriented python.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

To run the code provided in this repository, you will need standard python packages, such as numpy and matplotlib. These should already be installed on most machines.

To use the master branch of this code (the fast one!), you will need to have pyFFTW installed. Installation instructions can be found here.

Alternatively, you can create a new conda environment using the environment.yml file provided. First, got in the '2D-Turbulence-Python' cloned repository and creat the new environment

$ conda env create -f environment.yml

This will create a new conda environment called 2D-Turbulence-Python. Then activate it

$ conda activate 2D-Turbulence-Python

This will install all the required packages and allows you to use this repo.

This repository contains three (as of today) branches, the master branch that includes the pseudo-spectral code running with the pyFFTW library, the CDS branch that contains the high-order (up to 6th) compact difference scheme version and the numpy branch that contains a numpy-only version of the code. When the repository has been cloned/downloaded, you can switch between branches using

git checkout numpy (or CDS)

to switch to the desired branch. The solver is implemented such that functions calls perform the same tasks on each branch.

Running The Tests

Once you are happy with the version you are going to use, check that everything works by running the validation script

python valid.py

This runs a simulation of the Taylor-Green Vortex for which we have an analytical solution. The output should look similar to this

Starting integration on field.

Iteration    100, time   0.020, time remaining   0.079. TKE: 0.180  ENS: 23580.54
Iteration    200, time   0.041, time remaining   0.058. TKE: 0.129  ENS: 16934.10
Iteration    300, time   0.061, time remaining   0.038. TKE: 0.092  ENS: 12157.35
Iteration    400, time   0.082, time remaining   0.017. TKE: 0.066  ENS: 8725.782

Execution time for 484 iterations is 2.737 seconds.
The L2-norm of the Error in the Taylor-Green vortex on a 128x128 grid is 1.362e-10.
The Linf-norm of the Error in the Taylor-Green vortex on a 128x128 grid is 2.725e-10.

You should get errors in both norms close to the values displayed above.

This repo also contains some more basic test, that can be run using pytest

$ pytest

Using the code

Simulations are initialized by defining a grid, and specifying the Reynolds number of the flow

flow = Fluid(nx=64, ny=64, Re=1)
flow.init_solver()
flow.init_field(TaylorGreen)

Here we have initialized the Taylor-Green vortex. The solver initiation generates all the working arrays and transforms the initial conditions. Simulations can also be initialized using results from previous runs (these need to have been saved with flow.write(folder='', 1))

from src.field import FromDat
flow.init_field(FromDat, name="vort_000001.dat")

here we reset the flow timer using the time value saved in the vort_ID.dat file. The finish time of the simulation must be adjusted accordingly, as well as the ID if the field is saved. This allows user-generated field to be used, within the limitations of the method (periodic boundary conditions). The main loop of the solver is called as

# loop to solve
while(flow.time<=finish):
    flow.update()
    if(flow.it % 1000 == 0):
        print("Iteration \t %d, time \t %f, time remaining \t %f. TKE: %f, ENS: %f" %(flow.it,
              flow.time, finish-flow.time, flow.tke(), flow.enstrophy()))
        flow.write(file="fluid")

Small simulations can also be run live, which can also be handy for de-bugging

flow.run_live(finish, every=100)

Additional Content

For a description of the theory behind this code, or to run other cases, such as a double shear layer, or decaying isotropic turbulence, look at this.

Authors

  • Marin Lauber - Initial work - github

License

This project is licensed under the MIT License - see the LICENSE file for details

2d-turbulence-python's People

Contributors

marinlauber avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

2d-turbulence-python's Issues

about energy spectrum

still have another question about the reference energy spectrum line(k^-4)
I looked up in some books but did not find any 2D HIT that presents a reference energy spectrum line of k^-4, but I did find out in a published paper that also uses the reference line of k^-4(but did not leave any reference).
Could you please tell me where to find about why 2D decaying turbulence has the cascade of k^-4

Thank you in advance!

Instabilities at high Re

Hi Marin,

I have been attempting to reproduce the results you show for the evolution of a McWilliam's initial field with 512x512 grid points at Re=2000. Unfortunately, after around half a second of simulation time, I consistently encounter numerical instabilities. I have attempted to fix the time step size to a constant value much lower than calculated through the CFL criterion and also tried reducing the Reynold's number to ~500, to no avail so far. Could you tell me how you set the parameters to produce a stable solution for Re=2000?

Thanks in advance!

about post.py

Hello! Your code is very helpful!
Since I'm trying to get the velocity field of the decaying turbulence, there seems to be a type error in post.py
it is the function get_velocity

def get_velocity(psih, kx, kk):
uh = 1jky[:,np.newaxis]psih
vh = -1j
kk
psih
return np.fft.irfft2(uh, axes=(-2,-1)), np.fft.irfft2(vh, axes=(-2,-1))

where the "ky" is an obvious error. I was wondering whether it is :
uh = 1jkx[:,np.newaxis]psih
vh = -1j
kk
psih

or it is:
uh = 1jkk[:,np.newaxis]psih
vh = -1j
kx
psih

Not sure if you are still active in Github, but thanks in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.