Git Product home page Git Product logo

12-steps-to-navier-stokes's Introduction

12 Steps to Navier-Stokes Equations

Challenge

Use computing capabilities of Python to solve the nonlinear coupled partial derivative equations that govern the dynamics of fluids, the Navier-Stokes equations:

Actions

  • creating implicit numerical schemes to solve ever increasing difficult components of the NS equations
  • linear convection:

  • nonlinear convection:
# Step6: 2D Nonlinear Convection
# the ecuations to be solved are: du/dt + u*du/dx +v*du/dy = 0
#                                 dv/dt + u*dv/dx +v*dv/dy = 0
# in this equation we have the acumulation and convection terms
# but this time the convection is nonlinear and the equations are coupled
# this time the problem is 2D and we want to solve for the velocities

# First we use the equations given in the IPython notebook
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import pylab as pl
pl.ion()

# Variable declaration
nx = 501 # initial value 101
ny = 501 # initial value 101
nt = 400 # initial value 80

dx = 2.0/(nx-1)
dy = 2.0/(ny-1)
sigma = 0.2
dt = sigma*dx

x = np.linspace(0.0,2.0,nx)
y = np.linspace(0.0,2.0,ny)
 
u = np.ones((ny,nx))
v = np.ones((ny,nx))
un = np.ones((ny,nx))
vn = np.ones((ny,nx))

# Initialize the solution
u[.5/dy:1/dy+1, .5/dx:1/dx+1] = 2
v[.5/dy:1/dy+1, .5/dx:1/dx+1] = 2

# Apply the scheme
for n in range(nt+1):
    un = u.copy()
    vn = v.copy()
    
    u[1:,1:] = un[1:,1:] - un[1:,1:] * dt/dx * (un[1:,1:]-un[0:-1,1:])\
    -vn[1:,1:] * dt/dy * (un[1:,1:]-un[1:,0:-1])
    v[1:,1:] = vn[1:,1:] - un[1:,1:] * dt/dx * (vn[1:,1:]-vn[0:-1,1:])\
    -vn[1:,1:] * dt/dy * (vn[1:,1:]-vn[1:,0:-1])
    
    u[0,:] = 1
    u[-1,:] = 1
    u[:,0] = 1
    u[:,-1] = 1
    
    v[0,:] = 1
    v[-1,:] = 1
    v[:,0] = 1
    v[:,-1] = 1

from pylab import cm # this will be used to create a colormap 3d plot
fig = pl.figure(figsize=(11,7), dpi=100)
ax = Axes3D(fig)
X,Y = np.meshgrid(x,y)
ax.plot_surface(X,Y,v,cmap=cm.coolwarm) # plot the u component of the velocity
pl.xlabel('X')
pl.ylabel('Y')
pl.title('2D Nonlinear Convection: Solution')
# to plot the v component just change u with v
# because the equations are symetrical, the plots are identical

  • diffusion:

  • Burgers' equation

  • cavity flow

  • channel flow

Results

The result of this exercise was package of numerical solutions to the difficult equations of fluid dynamics; the implementation is only in 2D and can solve any problem that can be formulated in a structured 2D mesh; the main equations take also into account turbulence and as seen in the results of teh cavity problem, turbulence is modelled implicitly in the solutions of this project.

For a complete overview of this project please visit its dedicated repository on github: https://github.com/FlorinGh/12-steps-to-navier-stokesโ€‹.

12-steps-to-navier-stokes's People

Contributors

floringh avatar

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.