Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

project #16

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Amiya Project/Final Version/images/Set-up.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions Amiya Project/Final Version/laplace_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import numpy
from matplotlib import pyplot, cm
from mpl_toolkits.mplot3d import Axes3D

def L2_rel_error(p, pn):
''' Compute the relative L2 norm of the difference
Parameters:
----------
p : array of float
array 1
pn: array of float
array 2
Returns:
-------
Relative L2 norm of the difference
'''
return numpy.sqrt(numpy.sum((p - pn)**2)/numpy.sum(pn**2))

def plot_3D(x, y, p, elev=30, azi=45):
'''Creates 3D projection plot with appropriate limits and viewing angle

Parameters:
----------
x: array of float
nodal coordinates in x
y: array of float
nodal coordinates in y
p: 2D array of float
calculated potential field

'''
fig = pyplot.figure(figsize=(11,7), dpi=100)
ax = fig.gca(projection='3d')
X,Y = numpy.meshgrid(x,y)
surf = ax.plot_surface(X,Y,p[:], rstride=1, cstride=1, cmap=cm.viridis,
linewidth=0, antialiased=False)

ax.set_xlabel('$x$')
ax.set_ylabel('$y$')
ax.set_zlabel('$z$')
ax.view_init(elev,azi)

def p_analytical(x, y):
'''Returns the analytical solution for the given Laplace Problem on a grid
with coordinates x and y

Parameters:
----------
xL array of float
Nodal coordinates in x
y: array of float
Nodal coordinates in y

Returns:
-------
pxy: 2D array of float
Potential distribution analytical solution

'''
X, Y = numpy.meshgrid(x,y)
pxy = numpy.sinh(1.5*numpy.pi*Y / x[-1]) /\
(numpy.sinh(1.5*numpy.pi*y[-1]/x[-1]))*numpy.sin(1.5*numpy.pi*X/x[-1])

return pxy
108 changes: 108 additions & 0 deletions Amiya Project/Final Version/multigrid_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import numpy
from numba import autojit

@autojit(nopython=True)
def poisson1d_GS_SingleItr(nx, dx, p, b):
'''
Gauss-Seidel method for 1D Poisson eq. with Dirichlet BCs at both
ends. Only a single iteration is executed. **blitz** is used.

Parameters:
----------
nx: int, number of grid points in x direction
dx: float, grid spacing in x
p: 1D array of float, approximated soln. in last iteration
b: 1D array of float, 0th-order derivative term in Poisson eq.

Returns:
-------
p: 1D array of float, approximated soln. in current iteration
'''

for i in range(1,len(p)-1):
p[i] = 0.5 * (p[i+1] + p[i-1] - dx**2 * b[i])

return p



def RMS(p):
'''
Return the root mean square of p.

Parameters:
----------
p: array

Returns:
-------
Root mean square of p
'''
return numpy.sqrt(numpy.sum(p**2) / p.size)



def residual(dx, pn, b, r):
'''
Calculate the residual for the 1D Poisson equation.

Parameters:
----------
pn: 1D array, approximated solution at a certain iteration n
b: 1D array, the b(x) in the Poisson eq.

Return:
----------
The residual r
'''

# r[0] = 0
r[1:-1] = b[1:-1] - (pn[:-2] - 2 * pn[1:-1] + pn[2:]) / dx**2
# r[-1] = 0

return r



def full_weighting_1d(vF, vC):
'''
Transfer a vector on a fine grid to a coarse grid with full weighting
. The number of elements (not points) of the coarse grid is
half of that of the fine grid.

Parameters:
----------
vF: 1D numpy array, the vector on the fine grid
vC: 1D numpy array, the vector on the coarse grid,
size(vC) = (size(vF) + 1) / 2

Output: vC
'''

vC[0] = vF[0]
vC[1:-1] = 0.25 * (vF[1:-3:2] + 2. * vF[2:-2:2] + vF[3:-1:2])
vC[-1] = vF[-1]

return vC



def interpolation_1d(vC, vF):
'''
Transfer a vector on a coarse grid to a fine grid by linear
interpolation. The number of elements (not points) of the coarse
grid is a half of that of the fine grid.

Parameters:
----------
vC: 1D numpy array, the vector on the coarse grid,
vF: 1D numpy array, the vector on the fine grid
size(vF) = size(vC) * 2 - 1

Output: vF
'''

vF[::2] = vC[:];
vF[1:-1:2] = 0.5 * (vC[:-1] + vC[1:])

return vF
296 changes: 296 additions & 0 deletions Amiya Project/Rayleigh Benard Convection - 2.ipynb

Large diffs are not rendered by default.

326 changes: 326 additions & 0 deletions Amiya Project/Rayleigh Benard Convection - 3.ipynb

Large diffs are not rendered by default.

Loading