Skip to content
This repository has been archived by the owner on Feb 20, 2019. It is now read-only.

Commit

Permalink
initial commit of laplace
Browse files Browse the repository at this point in the history
  • Loading branch information
gforsyth committed Feb 13, 2013
0 parents commit a28e31b
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions 2d_laplace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
##2D Laplace
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import matplotlib.pyplot as plt
import numpy as np
import os

##variable declarations
nx = 31
ny = 31
nt = 100
c = 1
dx = 2.0/(nx-1)
dy = 2.0/(ny-1)
sigma = .2
dt = sigma*dx*dy


##initial conditions
p = np.zeros((ny,nx)) ##create a XxY vector of 0's
pn = np.zeros((ny,nx)) ##create a XxY vector of 0's



##plotting aids
x = np.linspace(0,2,nx)
y = np.linspace(0,2,ny)


##time loop
for n in nt:
pn[:] = p[:]
p[1:-1,1:-1] = (dy**2*(pn[2:,1:-1]+pn[0:-2,1:-1])+dx**2(pn[1:-1,2:]+pn[1:-1,0:-2]))/(2*(dx**2+dy**2))
p[0,0] = (dy**2*(pn[1,0]+pn[-1,0])+dx**2(pn[0,1]+pn[0,-1]))/(2*(dx**2+dy**2))
p[-1,-1] = (dy**2*(pn[0,-1]+pn[-2,-1])+dx**2(pn[-1,0]+pn[-1,-2]))/(2*(dx**2+dy**2))

p[:,0] = 0
p[:,-1] = y


0 comments on commit a28e31b

Please sign in to comment.