Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Handling imports
- """
- import os
- import sys
- sys.path.append(os.path.dirname(os.getcwd()))
- from computational import finite_difference
- import numpy as np
- import matplotlib.pyplot as plt
- from matplotlib import cm
- """
- Setting up the dimensions of the grid
- and the point distribution
- """
- dx = 0.2
- dy = 0.2
- Lx = 1
- Ly = 1
- num_x = int(Lx / dx)
- num_y = int(Ly / dy)
- """
- Creating new grid with defined size and number of points
- """
- grids = finite_difference()
- grids.cartesian((Lx, Ly, 1), (num_x, num_y, 1))
- grids.initialize()
- grids.transmissibility()
- """
- Setting the solver to use second order derivative for the equation
- """
- grids.central(order=2)
- """
- Integrating the boundary conditions
- (b0, b1, f)
- (1 , 0 , 0)
- """
- grids.implement_bc(b_xmin=(1, 0, 0),
- b_xmax=(1, 0, 0),
- b_ymin=(1, 0, 10),
- b_ymax=(1, 1, 5))
- """
- Calculating the right hand side
- """
- rhs = [r[0]**2 for r in grids.center]
- """
- Calculating the boundary conditions
- """
- grids.solve(rhs=rhs)
- """
- Plotting the results
- """
- X = grids.center[:, 0].reshape(num_x, num_y)
- Y = grids.center[:, 1].reshape(num_x, num_y)
- Z = grids.unknown.reshape(num_x, num_y)
- plt.contourf(X, Y, Z, range(0,11),
- alpha=1, cmap=cm.hot, vmin=0, vmax=10)
- plt.colorbar()
- plt.title('Figure 1, velocity distribution', fontsize=14)
- plt.xlabel('x-axis', fontsize=14)
- plt.ylabel('y-axis', fontsize=14)
- plt.xlim([0, 1])
- plt.ylim([0, 1])
- plt.show()
Add Comment
Please, Sign In to add comment