Aykhann

AFMM Poisson 2D

May 31st, 2021 (edited)
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. """
  2. Handling imports
  3. """
  4. import os
  5. import sys
  6.  
  7. sys.path.append(os.path.dirname(os.getcwd()))
  8.  
  9. from computational import finite_difference
  10. import numpy as np
  11. import matplotlib.pyplot as plt
  12. from matplotlib import cm
  13.  
  14. """
  15. Setting up the dimensions of the grid
  16. and the point distribution
  17. """
  18. dx = 0.2
  19. dy = 0.2
  20. Lx = 1
  21. Ly = 1
  22.  
  23. num_x = int(Lx / dx)
  24. num_y = int(Ly / dy)
  25.  
  26. """
  27. Creating new grid with defined size and number of points
  28. """
  29.  
  30. grids = finite_difference()
  31.  
  32. grids.cartesian((Lx, Ly, 1), (num_x, num_y, 1))
  33.  
  34. grids.initialize()
  35.  
  36. grids.transmissibility()
  37.  
  38. """
  39. Setting the solver to use second order derivative for the equation
  40. """
  41. grids.central(order=2)
  42.  
  43. """
  44. Integrating the boundary conditions
  45. (b0, b1, f)  
  46. (1 , 0 , 0)
  47. """
  48. grids.implement_bc(b_xmin=(1, 0, 0),
  49.                    b_xmax=(1, 0, 0),
  50.                    b_ymin=(1, 0, 10),
  51.                    b_ymax=(1, 1, 5))
  52.  
  53. """
  54. Calculating the right hand side
  55. """
  56. rhs = [r[0]**2 for r in grids.center]
  57.  
  58. """
  59. Calculating the boundary conditions
  60. """
  61. grids.solve(rhs=rhs)
  62.  
  63.  
  64. """
  65. Plotting the results
  66. """
  67.  
  68. X = grids.center[:, 0].reshape(num_x, num_y)
  69. Y = grids.center[:, 1].reshape(num_x, num_y)
  70.  
  71. Z = grids.unknown.reshape(num_x, num_y)
  72.  
  73. plt.contourf(X, Y, Z, range(0,11),
  74.              alpha=1, cmap=cm.hot, vmin=0, vmax=10)
  75. plt.colorbar()
  76.  
  77. plt.title('Figure 1, velocity distribution', fontsize=14)
  78. plt.xlabel('x-axis', fontsize=14)
  79. plt.ylabel('y-axis', fontsize=14)
  80.  
  81. plt.xlim([0, 1])
  82. plt.ylim([0, 1])
  83.  
  84. plt.show()
  85.  
Add Comment
Please, Sign In to add comment