You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

191 lines
1.7 KiB

  1. ```python
  2. #1 Loading functions and modules
  3. from fenics import *
  4. import matplotlib.pyplot as plt
  5. T = 2.0
  6. num_steps = 20
  7. dt = T/num_steps
  8. rho = 7500
  9. Cp = 500
  10. k = 50
  11. alpha = k/(rho*Cp)
  12. ```
  13. ```python
  14. #2 Create mesh and define function space
  15. nx = 0.008
  16. ny = 0.003
  17. mesh = RectangleMesh(Point(0,0),Point(nx,ny),30, 30,'left')
  18. V = FunctionSpace(mesh, 'Lagrange', 1) #Lagrange are triangular elements
  19. plot(mesh)
  20. plt.show()
  21. ```
  22. ![png](output_1_0.png)
  23. ```python
  24. # Boundary conditions
  25. u0 = Constant(100)
  26. def boundary(x, on_boundary):
  27. return on_boundary
  28. bc = DirichletBC(V,u0, boundary)
  29. ```
  30. ```python
  31. u_n = project(1, V)
  32. u = TrialFunction(V)
  33. v = TestFunction(V)
  34. f = Constant(0.0)
  35. F = u*v*dx + alpha*dt*dot(grad(u), grad(v))*dx-u_n*v*dx
  36. a, L = lhs(F), rhs(F)
  37. ```
  38. Calling FFC just-in-time (JIT) compiler, this may take some time.
  39. ```python
  40. u = Function(V)
  41. t = 0
  42. for n in range(num_steps):
  43. t += dt
  44. #u0.t = t
  45. solve(a == L, u, bc)
  46. c = plot(u,)
  47. plt.colorbar(c)
  48. plt.show()
  49. u_n.assign(u)
  50. ```
  51. Calling FFC just-in-time (JIT) compiler, this may take some time.
  52. ![png](output_4_1.png)
  53. ![png](output_4_2.png)
  54. ![png](output_4_3.png)
  55. ![png](output_4_4.png)
  56. ![png](output_4_5.png)
  57. ![png](output_4_6.png)
  58. ![png](output_4_7.png)
  59. ![png](output_4_8.png)
  60. ![png](output_4_9.png)
  61. ![png](output_4_10.png)
  62. ![png](output_4_11.png)
  63. ![png](output_4_12.png)
  64. ![png](output_4_13.png)
  65. ![png](output_4_14.png)
  66. ![png](output_4_15.png)
  67. ![png](output_4_16.png)
  68. ![png](output_4_17.png)
  69. ![png](output_4_18.png)
  70. ![png](output_4_19.png)
  71. ![png](output_4_20.png)
  72. ```python
  73. 1E-7
  74. ```
  75. 1e-07
  76. ```python
  77. 1e2
  78. ```
  79. 100.0
  80. ```python
  81. 1E-7+1e2
  82. ```
  83. 100.0000001
  84. ```python
  85. ```