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
CFD Python или 12 шагов до уравнений Навье-Стокса — это практический модуль для изучения основ вычислительной гидродинамики (CFD) путем кодирования решений основных дифференциальных уравнений в частных производных, описывающих физику течения жидкости. Модуль был частью курса, который читал Prof. Lorena Barba с 2009 по 2013 год на факультете машиностроения Бостонского университета (с тех пор профессор Барба перешел в Университет Джорджа Вашингтона).
Модуль предполагает только базовые знания программирования (на любом языке) и некоторый опыт работы с дифференциальными уравнениями в частных производных и гидромеханикой. «Шаги» были вдохновлены идеями доктора Рио Йокоты, который до 2011 года был постдоком в лаборатории профессора Барбы, а уроки были усовершенствованы профессором Барбой и ее студентами в течение нескольких семестров, преподававших курс CFD. Мы написали этот набор блокнотов Jupyter в 2013 году для проведения интенсивного двухдневного курса в Мендосе, Аргентина.
Проводя учащихся по этим шагам (не пропуская ни одного!), они получают много ценных уроков. Постепенный характер упражнений означает, что они получают чувство достижения в конце каждого задания, и они чувствуют, что учатся с минимальными усилиями. По мере продвижения они, естественно, практикуют повторное использование кода и постепенно изучают методы программирования и построения графиков. Анализируя свои результаты, они узнают о числовой диффузии, точности и сходимости.
Как использовать этот модуль
На обычном университетском курсе студенты могут пройти уроки CFD Python за 4–5 недель. В качестве интенсивного учебного модуля модуль может быть пройден за два или три полных дня, в зависимости от предыдущего опыта учащегося. Во всех случаях учащиеся должны следовать рабочим примерам в каждом уроке, повторно набирая код в новом блокноте Jupyter, возможно, делая оригинальные заметки по мере того, как они пробуют что-то.
Lessons
Launch an interactive session with this module using the Binder service:
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:
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!