Skip to content

Commit

Permalink
Merge commit '8b3e26cc48a05fa81a15bb0bd075b4a2eee80887' as '2-finite-…
Browse files Browse the repository at this point in the history
…difference-method'
  • Loading branch information
mbarzegary committed May 30, 2021
2 parents 17fbf47 + 8b3e26c commit 334b750
Show file tree
Hide file tree
Showing 134 changed files with 49,191 additions and 0 deletions.
4 changes: 4 additions & 0 deletions 2-finite-difference-method/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.ipynb_checkpoints
*.pyc
.env
__pycache__
55 changes: 55 additions & 0 deletions 2-finite-difference-method/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Instructional Material

All instructional material is made available under the Creative
Commons Attribution license. You are free:

* to Share---to copy, distribute and transmit the work
* to Remix---to adapt the work

Under the following conditions:

* Attribution---You must attribute the work using "Copyright (c)
Barbagroup" (but not in any way that suggests that we
endorse you or your use of the work). Where practical, you must
also include a hyperlink to https://github.com/numerical-mooc/numerical-mooc.

With the understanding that:

* Waiver---Any of the above conditions can be waived if you get
permission from the copyright holder.
* Other Rights---In no way are any of the following rights
affected by the license:
* Your fair dealing or fair use rights;
* The author's moral rights;
* Rights other persons may have either in the work itself or in
how the work is used, such as publicity or privacy rights. *
* Notice---For any reuse or distribution, you must make clear to
others the license terms of this work. The best way to do this is
with a link to http://creativecommons.org/licenses/by/3.0/.

For the full legal text of this license, please see:
http://creativecommons.org/licenses/by/3.0/legalcode

Software

The MIT License (MIT)

Copyright (c) 2014 Barba group

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
55 changes: 55 additions & 0 deletions 2-finite-difference-method/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Practical Numerical Methods with Python

This project started in 2014 as a multi-campus, connected course (plus MOOC) on numerical methods for science and engineering.

In Fall 2015 and 2016, second and third run of the connected courses, we had these instructors participating (using the materials as part of their syllabus):
- [Lorena A. Barba](http://lorenabarba.com), George Washington University, USA
- [Ian Hawke](http://www.southampton.ac.uk/maths/about/staff/ih3.page), Southampton University, UK
- [Bernard Knaepen](http://depphys.ulb.ac.be/bknaepen/), Université Libre de Bruxelles, Belgium


[**"Practical Numerical Methods with Python"**](https://openedx.seas.gwu.edu/courses/course-v1:MAE+MAE6286+2017/about) is an open, online course hosted on an independent installation of the [Open edX](http://code.edx.org) software platform for MOOCs.
The MOOC (massive open online course) was run in 2014 for the first time by Prof. Barba at the George Washington University. At the same time, two other participating instructors ran a local course, for credit at their institution.

### The MOOC

You can register for the MOOC at any time in the [GW Online Open edX](http://openedx.seas.gwu.edu/) platform to experience the complete course (including quizzes, examples and discussion board).

All content is open —really open, i.e., you can use, share, mod, remix— and most is available outside the course platform also (on GitHub and YouTube).

#### Find the list of IPython Notebooks, with links to nbviewer, in the [Wiki](https://github.com/numerical-mooc/numerical-mooc/wiki).

## Getting Started

1. Introduction to the command line: [OS X version](https://github.com/numerical-mooc/numerical-mooc/blob/master/lessons/00_getting_started/00_01_Intro_to_the_command_line_osx.md); [RedHat version](https://github.com/numerical-mooc/numerical-mooc/blob/master/lessons/00_getting_started/00_01_Intro_to_the_command_line_redhat.md)
2. [Installing Jupyter](https://github.com/numerical-mooc/numerical-mooc/blob/master/lessons/00_getting_started/00_02_Installing_Jupyter.md)
3. [Introduction to Jupyter notebooks](https://github.com/numerical-mooc/numerical-mooc/blob/master/lessons/00_getting_started/00_03_Intro_to_Jupyter_notebook.md)
4. [Introduction to git](https://github.com/numerical-mooc/numerical-mooc/blob/master/lessons/00_getting_started/00_04_Intro_to_git.md)

## Course Modules

1. [**The phugoid model of glider flight.**](https://github.com/numerical-mooc/numerical-mooc/tree/master/lessons/01_phugoid)
Described by a set of two nonlinear ordinary differential equations, the phugoid model motivates numerical time integration methods, and we build it up starting from one simple equation, so that the unit can include 3 or 4 lessons on initial value problems. This includes: a) Euler's method, 2nd-order RK, and leapfrog; b) consistency, convergence testing; c) stability
Computational techniques: array operations with NumPy; symbolic computing with SymPy; ODE integrators and libraries; writing and using functions.
2. [**Space and Time—Introduction to finite-difference solutions of PDEs.**](https://github.com/numerical-mooc/numerical-mooc/tree/master/lessons/02_spacetime)
Starting with the simplest model represented by a partial differential equation (PDE)—the linear convection equation in one dimension—, this module builds the foundation of using finite differencing in PDEs. (The module is based on the “CFD Python” collection, steps 1 through 4.) It also motivates CFL condition, numerical diffusion, accuracy of finite-difference approximations via Taylor series, consistency and stability, and the physical idea of conservation laws.
Computational techniques: more array operations with NumPy and symbolic computing with SymPy; getting better performance with NumPy array operations.
3. [**Riding the wave: convection problems.**](https://github.com/numerical-mooc/numerical-mooc/tree/master/lessons/03_wave)
Starting with an overview of the concept of conservation laws, this module uses the traffic-flow model to study different solutions methods for problems with shocks: upwind, Lax-Friedrichs, Lax-Wendroff, MacCormack, then MUSCL (discussing limiters). Reinforces concepts of numerical diffusion and stability, in the context of solutions with shocks. It will motivate spectral analysis of schemes, dispersion errors, Gibbs phenomenon, conservative schemes.
4. [**Spreading out: diffusion problems.**](https://github.com/numerical-mooc/numerical-mooc/tree/master/lessons/04_spreadout)
This module deals with solutions to parabolic PDEs, exemplified by the diffusion (heat) equation. Starting with the 1D heat equation, we learn the details of implementing boundary conditions and are introduced to implicit schemes for the first time. Another first in this module is the solution of a two-dimensional problem. The 2D heat equation is solved with both explicit and implict schemes, each time taking special care with boundary conditions. The final lesson builds solutions with a Crank-Nicolson scheme.
5. [**Relax and hold steady: elliptic problems.**](https://github.com/numerical-mooc/numerical-mooc/tree/master/lessons/05_relax)
Laplace and Poisson equations (steps 9 and 10 of “CFD Python”), seen as systems relaxing under the influence of the boundary conditions and the Laplace operator. Iterative methods for algebraic equations resulting from discretizign PDEx: Jacobi method, Gauss-Seidel and successive over-relaxation methods. Conjugate gradient methods.


Planned modules:
- **Perform like a pro: making your codes run faster**
Getting performance out of your numerical Python codes with just-in-time compilation, targeting GPUs with Numba and PyCUDA.
- **Boundaries take over: the boundary element method (BEM).**
Weak and boundary integral formulation of elliptic partial differential equations; the free space Green's function. Boundary discretization: basis functions; collocation and Galerkin systems. The BEM stiffness matrix: dense versus sparse; matrix conditioning. Solving the BEM system: singular and near-singular integrals; Gauss quadrature integration.

## Sponsors

The initial deployment of the GW SEAS Open edX instance and the creation of the first course in the platform (Fall 2014) were funded with a seed grant from the GW VP for Online Education and Academic Innovation, TA support from the GW School of Engineering and Applied Sciences, and additional support from Nvidia Corp. Academic Programs and Amazon AWS (donated cloud credits for the first year).


Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Intro to the command line

Welcome! The command line can be one of the most powerful ways to interact with
a variety of computer systems, but it can also be a little confusing at first
glance. This mini-crash-course should help familiarize you with the basics of
command line usage and navigation.

## Open a terminal!

Hit `⌘ + Space` to bring up spotlight, then type the first few letters of
`Terminal` and select `Terminal`.


## Who am I?

Time to get started! You likely know your username since you've just logged in,
but sometimes you may have multiple accounts with slight variations on a
username.

You can always ask the terminal who you are by entering

```console
whoami
```

and hitting \<Enter\>. (From now on, after typing in a command, just hit
\<Enter\> unless we tell you otherwise.)

![whoami](./images/1.whoami.gif)

**Note**: These gifs were made on a Red Hat linux machine, so they'll look a
little bit different than what you see. Don't worry about it.

## Where am I?

We know who we are, time to find out *where* we are. You can always find out
what folder you're in by using the "print working directory" command, or `pwd`.
Try it out!

```console
pwd
```

![pwd](./images/2.pwd.gif)

We're in our home directory. This is the base directory for a regular user in
Linux or OSX. In the SEAS Mac Labs, the home directory is always
`/Users/<username>`. If you're using your own Linux machine, the home directory
is probably `/home/<username>`.

## What's in here?

We know who we are and where we are, now it's time to figure out what's in here.
We use the "list" command, `ls`, to view any files or directories that are in
the current folder.

```console
ls
```

![ls](./images/3.ls.gif)

The items you see above in the gif are all folders. They're the usual folders
created by default in Red Hat Linux. Your home folder is actually the same
folder as your Titan network drive on Windows, so you may have other files and
folders in your home directory.

## How do I go there?

To navigate to a new folder, we use the change directory command, `cd`, followed
by the name of the folder. While you *can* type out the full folder name, it's
usually nicer to use what's called Tab-completion.

Let's change to the `Pictures` directory. Type `cd Pi` and then hit the TAB key
to complete the directory name. Then hit \<Enter\>

Now you're in the `Pictures` directory. It's probably empty, but you can check
with `ls`.

To go back to your home directory, type `cd ..`

The `..` is a command-line shortcut to move "up" one folder in a directory tree.
Try `cd`-ing into a few other folders and then returning back to your home
directory to get the hang of moving around.

![cd](./images/4.cd.gif)

### Multiple tab-completions

If there are multiple possible completions for a partial directory name, you can
ask the terminal to display them by hitting TAB twice. Try entering

```console
cd Do
```

and then hit TAB twice to see the list of matching directories. Then you can add
a `c` and Tab-complete `Documents`.

![cdtabtab](./images/5.cdtabtab.gif)

## Quick config step

Now that we have a handle on basic terminal navigation, we are going to make a
few tweaks to this setup to make it friendlier. Copy the two lines below by
selecting them and hitting `⌘+c` and then paste them into the terminal using
`⌘+v` and hit \<Enter\>.

```console
echo "export PATH=/Applications/anaconda/bin:\$PATH" >> .bash_profile
```

(If you are following along and aren't at GW, don't do this, it only applies to
the GW Mac Labs)

Now, to activate the options we just selected, type the following line in the
terminal and hit \<Enter\>

```console
source .bash_profile
```

It should look a little something like this:

![image](./images/6.bashrc.gif)

## Make sure Anaconda is on your PATH

```console
python --version
```

That command should return a version number >= `3.5` and it should also say Anaconda.
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# Intro to the command line

Welcome! The command line can be one of the most powerful ways to interact with
a variety of computer systems, but it can also be a little confusing at first
glance. This mini-crash-course should help familiarize you with the basics of
command line usage and navigation.


## Who am I?

Time to get started! You likely know your username since you've just logged in,
but sometimes you may have multiple accounts with slight variations on a
username.

First, please open up a terminal using the menu in the upper-left corner (on Red
Hat) and selecting

> Applications -> System Tools -> Terminal
You can always ask the terminal who you are by entering

```Bash
whoami
```

and hitting \<Enter\>. (From now on, after typing in a command, just hit
\<Enter\> unless we tell you otherwise.)

![whoami](./images/1.whoami.gif)

## Where am I?

We know who we are, time to find out *where* we are. You can always find out
what folder you're in by using the "print working directory" command, or `pwd`.
Try it out!

```Bash
pwd
```

![pwd](./images/2.pwd.gif)

We're in our home directory. This is the base directory for a regular user in
Linux. In the SEAS labs, the home directory is always `/home/seas/<username>`.
If you're using your own Linux machine, the home directory is probably
`/home/<username>`. If you're on a Mac, the home directory is
`/Users/<username>` (they like to be different).

## What's in here?

We know who we are and where we are, now it's time to figure out what's in here.
We use the "list" command, `ls`, to view any files or directories that are in
the current folder.

```Bash
ls
```

![ls](./images/3.ls.gif)

The items you see above in the gif are all folders. They're the usual folders
created by default in Red Hat Linux. Your home folder is actually the same
folder as your Titan network drive on Windows, so you may have other files and
folders in your home directory.

## How do I go there?

To navigate to a new folder, we use the change directory command, `cd`, followed
by the name of the folder. While you *can* type out the full folder name, it's
usually nicer to use what's called Tab-completion.

Let's change to the `Pictures` directory. Type `cd Pi` and then hit the TAB key
to complete the directory name. Then hit \<Enter\>

Now you're in the `Pictures` directory. It's probably empty, but you can check
with `ls`.

To go back to your home directory, type `cd ..`

The `..` is a command-line shortcut to move "up" one folder in a directory tree.
Try `cd`-ing into a few other folders and then returning back to your home
directory to get the hang of moving around.

![cd](./images/4.cd.gif)

### Multiple tab-completions

If there are multiple possible completions for a partial directory name, you can
ask the terminal to display them by hitting TAB twice. Try entering

```Bash
cd Do
```

and then hit TAB twice to see the list of matching directories. Then you can add
a `c` and Tab-complete `Documents`.

![cdtabtab](./images/5.cdtabtab.gif)

## Quick config step

Now that we have a handle on basic terminal navigation, we are going to make a
few tweaks to this setup to make it friendlier. Copy the two lines below by
selecting them and hitting Ctrl+c and then paste them into the terminal using
Ctrl+Shift+v and hit \<Enter\>. **Note** that Ctrl+v doesn't work, you need to
add Shift.

```Bash
echo "export PATH=/opt/anaconda/bin:\$PATH" >> .bashrc
echo "export PS1=\"\u \w \"" >> .bashrc
```

(If you are following along and aren't at GW, don't copy the first line, that
only applies to the GW Linux labs)

Now, to activate the options we just selected, type the following line in the
terminal and hit \<Enter\>

```Bash
source .bashrc
```

It should look a little something like this:

![image](./images/6.bashrc.gif)

## Fire up a jupyter notebook!

It's time to get started! If you're at GW then everything is already installed,
just run

```Bash
jupyter notebook
```

in a terminal and it will launch a notebook server in your browser. If you
*aren't* at GW, then see the next module in Getting Started on installing Python
and Jupyter.
Loading

0 comments on commit 334b750

Please sign in to comment.