• Stars
    star
    3,380
  • Rank 13,158 (Top 0.3 %)
  • Language
    Jupyter Notebook
  • License
    Other
  • Created over 10 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A sequence of Jupyter notebooks featuring the "12 Steps to Navier-Stokes" http://lorenabarba.com/

CFD Python

Please cite as: Barba, Lorena A., and Forsyth, Gilbert F. (2018). CFD Python: the 12 steps to Navier-Stokes equations. Journal of Open Source Education, 1(9), 21, https://doi.org/10.21105/jose.00021

DOI

CFD Python, a.k.a. the 12 steps to Navier-Stokes, is a practical module for learning the foundations of Computational Fluid Dynamics (CFD) by coding solutions to the basic partial differential equations that describe the physics of fluid flow. The module was part of a course taught by Prof. Lorena Barba between 2009 and 2013 in the Mechanical Engineering department at Boston University (Prof. Barba since moved to the George Washington University).

The module assumes only basic programming knowledge (in any language) and some background in partial differential equations and fluid mechanics. The "steps" were inspired by ideas of Dr. Rio Yokota, who was a post-doc in Prof. Barba's lab until 2011, and the lessons were refined by Prof. Barba and her students over several semesters teaching the CFD course. We wrote this set of Jupyter notebooks in 2013 to teach an intensive two-day course in Mendoza, Argentina.

Guiding students through these steps (without skipping any!), they learn many valuable lessons. The incremental nature of the exercises means they get a sense of achievement at the end of each assignment, and they feel they are learning with low effort. As they progress, they naturally practice code re-use and they incrementally learn programming and plotting techniques. As they analyze their results, they learn about numerical diffusion, accuracy and convergence. In about four weeks of a regularly scheduled course, they become moderately proficient programmers and are motivated to start discussing more theoretical matters.

How to use this module

In a regular-session university course, students can complete the CFD Python lessons in 4 to 5 weeks. As an intensive tutorial, the module can be completed in two or three full days, depending on the learner's prior experience. The lessons can also be used for self study. In all cases, learners should follow along the worked examples in each lesson by re-typing the code in a fresh Jupyter notebook, maybe taking original notes as they try things out.

Lessons

Launch an interactive session with this module using the Binder service: Binder

Steps 1–4 are in one spatial dimension. Steps 5–10 are in two dimensions (2D). Steps 11–12 solve the Navier-Stokes equation in 2D. Three "bonus" notebooks cover the CFL condition for numerical stability, array operations with NumPy, and defining functions in Python.

  • Quick Python Intro —For Python novices, this lesson introduces the numerical libraries (NumPy and Matplotlib), Python variables, use of whitespace, and slicing arrays.
  • Step 1 —Linear convection with a step-function initial condition (IC) and appropriate boundary conditions (BCs).
  • Step 2 —With the same IC/BCs, nonlinear convection.
  • CFL Condition —Exploring numerical stability and the Courant-Friedrichs-Lewy (CFL) condition.
  • Step 3 —With the same IC/BCs, diffusion only.
  • Step 4 —Burgers’ equation, with a saw-tooth IC and periodic BCs (with an introduction to Sympy).
  • Array Operations with NumPy
  • Step 5 —Linear convection in 2D with a square-function IC and appropriate BCs.
  • Step 6 —With the same IC/BCs, nonlinear convection in 2D.
  • Step 7 —With the same IC/BCs, diffusion in 2D.
  • Step 8 —Burgers’ equation in 2D
  • Defining Functions in Python
  • Step 9 —Laplace equation with zero IC and both Neumann and Dirichlet BCs.
  • Step 10 —Poisson equation in 2D.
  • Step 11 —Solves the Navier-Stokes equation for 2D cavity flow.
  • Step 12 —Solves the Navier-Stokes equation for 2D channel flow.

Dependencies

To use these lessons, you need Python 3, and the standard stack of scientific Python: NumPy, Matplotlib, SciPy, Sympy. And of course, you need Jupyter—an interactive computational environment that runs on a web browser.

This mini-course is built as a set of Jupyter notebooks containing the written materials and worked-out solutions on Python code. To work with the material, we recommend that you start each lesson with a fresh new notebook, and follow along, typing each line of code (don't copy-and-paste!), and exploring by changing parameters and seeing what happens.

Installing via Anaconda
We *highly* recommend that you install the [Anaconda Python Distribution](http://docs.continuum.io/anaconda/install). It will make your life so much easier. You can download and install Anaconda on Windows, OSX and Linux.

After installing, to ensure that your packages are up to date, run the following commands in a terminal:

conda update conda
conda update jupyter numpy sympy scipy matplotlib

If you prefer Miniconda (a mini version of Anaconda that saves you disk space), install all the necessary libraries to follow this course by running the following commands in a terminal:

conda update conda
conda install jupyter
conda install numpy scipy sympy matplotlib
Without Anaconda
If you already have Python installed on your machine, you can install Jupyter using pip:
pip install jupyter

Please also make sure that you have the necessary libraries installed by running

pip install numpy scipy sympy matplotlib

How to contribute to CFD Python

We accept contributions via pull request—in fact, several users have already submitted pull requests making corrections or small improvements. You can also open an issue if you find a bug, or have a suggestion.

Copyright and License

(c) 2017 Lorena A. Barba, Gilbert F. Forsyth. All content is under Creative Commons Attribution CC-BY 4.0, and all code is under BSD-3 clause (previously under MIT, and changed on March 8, 2018).

We are happy if you re-use the content in any way!

License License: CC BY 4.0

More Repositories

1

AeroPython

Classical Aerodynamics of potential flow using Python and Jupyter Notebooks
Jupyter Notebook
907
star
2

numba_tutorial_scipy2016

Numba tutorial materials for Scipy 2016
Jupyter Notebook
140
star
3

PetIBM

PetIBM - toolbox and applications of the immersed-boundary method on distributed-memory architectures
C++
103
star
4

cuIBM

cuIBM: a GPU-based immersed boundary method code.
Cuda
88
star
5

FMM_tutorial

A step-by-step introduction to treecode.
Jupyter Notebook
55
star
6

AmgXWrapper

AmgXWrapper: An interface between PETSc and the NVIDIA AmgX library
C++
42
star
7

essential_skills_RRC

Essential skills for reproducible research computing
Jupyter Notebook
39
star
8

snake-repro

An article reporting the travails of reproducibility in unsteady CFD studies
Jupyter Notebook
26
star
9

jupyter-tutorial

"The world of Jupyter"—a tutorial
Jupyter Notebook
21
star
10

teaching-materials

Jupyter Notebook
21
star
11

petrbf

Automatically exported from code.google.com/p/petrbf
Makefile
21
star
12

pyrbf

Automatically exported from code.google.com/p/pyrbf
C
10
star
13

fmm-bem-relaxed

Source code for the paper on inexact Krylov iterations with FMM BEM
C++
10
star
14

pyfmm

Automatically exported from code.google.com/p/pyfmm
Python
9
star
15

AeroPython-studentprojects2015

Student projects for the Spring 2015 MAE 6226 class at GW
Jupyter Notebook
9
star
16

gemsfmm

Automatically exported from code.google.com/p/gemsfmm
Cuda
9
star
17

MG_tutorial

Multigrid Tutorial (based on W.L. Briggs, V.E. Henson and S.F. McCormick, A Multigrid Tutorial, 2nd. ed., SIAM, Philadelphia, 2000)
Python
9
star
18

cloud-repro

Reproducible workflow on a public cloud for computational fluid dynamics
Jupyter Notebook
9
star
19

jcs_paper_pinn

PINN paper that will be submitted to Journal of Computational Science
TeX
8
star
20

pipe_verification

OpenFoam example of pipe flow and result comparison with analytical solution of Hagen-Poiseuille flow
Jupyter Notebook
8
star
21

inexact-gmres

Paper: inexact GMRES with fast multipole method and low-p relaxation
TeX
8
star
22

JITcode-MechE

Online learning modules to learn computing in a problem-based context within Mechanical Engineering
Jupyter Notebook
7
star
23

geoclaw-landspill

An oil land-spill and overland flow simulator for pipeline rupture events
Fortran
7
star
24

bibtex

TeX
6
star
25

bempp_exafmm_paper

Manuscript repository for our research paper, including reproducibility packages for all results, and latex source files.
Jupyter Notebook
6
star
26

AeroPython-studentprojects2017

Jupyter Notebook
5
star
27

petibm-rollingpitching

3D rolling and pitching flat plate with PetIBM
Python
3
star
28

land-spill

TeX
3
star
29

geoclaw-azure-launcher

Helpers for launching GeoClaw land-spill simulations on Azure.
Python
3
star
30

AeroPython-studentprojects2018

Jupyter Notebook
3
star
31

pygbe_lspr_paper

GLSL
3
star
32

legate-evaluation

Legate evaluation reports
2
star
33

pygbe_lspr

GLSL
2
star
34

DirectForcingMethod

Python
2
star
35

petibm-examples

Collection of the PetIBM examples
Python
2
star
36

chuang-dissertation-repro-pack

Python
2
star
37

snake-lips-2d

2d cfd study (PetIBM on Azure) on the lateral lips of a gliding snake
Python
1
star
38

snake-lips

Numerical study of the effect of the lips on the aerodynamics of the gliding snake
Python
1
star
39

petibm-recipes

Collection of Dockerfiles and Singularity recipes for PetIBM
Dockerfile
1
star
40

JITcode-MechE-Workbook

CSS
1
star
41

geoclaw-landspill-paper

Python
1
star
42

pygbe_lspr_proposal

Porposal on using PyGBe to develop LSPR (Localized Surface Plasmon Resonance) applications.
1
star
43

pygbe_validation_paper

Paper on Validation for PyGBe and replication studies.
Jupyter Notebook
1
star
44

conferences

TeX
1
star
45

scipy-2022-repro-pack

Reproducibility package for SciPy 2022
Python
1
star
46

rescience-rollingpitching

Manuscript for ReScience C about the replication study on the pitching and rolling wing
TeX
1
star
47

PASI2013

Lessons based on a Pan-American Advanced Studies Institute "The science of predicting and understanding tsunamis, storm surges and tidal phenomena"
CSS
1
star
48

Caminos

"Data Science for a Better World"—A tutorial for the GW Caminos al Futuro Summer program
Jupyter Notebook
1
star