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.

295 lines
82 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {},
  7. "outputs": [],
  8. "source": [
  9. "#1 Loading functions and modules\n",
  10. "from fenics import *\n",
  11. "import matplotlib.pyplot as plt\n",
  12. "T = 0.1\n",
  13. "num_steps = 20\n",
  14. "dt = T/num_steps\n",
  15. "rho = 7500\n",
  16. "Cp = 500\n",
  17. "k = 50\n",
  18. "alpha = k/(rho*Cp)"
  19. ]
  20. },
  21. {
  22. "cell_type": "code",
  23. "execution_count": 2,
  24. "metadata": {},
  25. "outputs": [
  26. {
  27. "data": {
  28. "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAACgCAYAAAAM9xtHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzsvXl0G9eZJX6LWEiCG0CCxMJ9AcEFZIE7JWs1rcWyLMmSZcuSvMiRJVmy40WxezoTZ+vjOHEnnenTm9uJx2c880t34nYcJUrS09NuO9pFiiLADaRIivtOgAAXECBB1u8P6j1XAQWJluUlCb5zdI4AfgCqLh7qvfru9+5lOI5DKEIRilCEIhRhX/QBhCIUoQhFKL4cEZoQQhGKUIQiFABCE0IoQhGKUITiRoQmhFCEIhShCAWA0IQQilCEIhShuBGhCSEUoQhFKEIBIDQhhCIUoQhFKG5EaEIIRShCEYpQAAhNCKEIRShCEYobIf2iD+CThFqt5jIyMr7owwhFKEIRij+aqK+vn+A4LnEluX9UE0JGRgauXLnyRR9GKEIRilD80QTDML0rzV1RyYhhmK0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6OwsJCXL16FRkZGXj88ccBLJelCDZjY2OQSCTIy8tDR0cHZDIZvva1r1FsWltbYbFY0N/fT7FxOp0YHx/H17/+dchkMvh8PgE2HMchLS0NMpkMXV1dOHbsGDQaDZaWlnD9+nU6ERNsdDodLBYL9u7di4KCAnAch4GBAVgsFjQ3N2N+fh5KpRKFhYU4f/48ampqsGbNGgD
  29. "text/plain": [
  30. "<Figure size 432x288 with 1 Axes>"
  31. ]
  32. },
  33. "metadata": {
  34. "needs_background": "light"
  35. },
  36. "output_type": "display_data"
  37. }
  38. ],
  39. "source": [
  40. "#2 Create mesh and define function space\n",
  41. "nx = 0.008\n",
  42. "ny = 0.003\n",
  43. "mesh = RectangleMesh(Point(0,0),Point(nx,ny),30, 30,'left')\n",
  44. "V = FunctionSpace(mesh, 'Lagrange', 1) #Lagrange are triangular elements\n",
  45. "plot(mesh)\n",
  46. "plt.show()\n"
  47. ]
  48. },
  49. {
  50. "cell_type": "code",
  51. "execution_count": 3,
  52. "metadata": {},
  53. "outputs": [],
  54. "source": [
  55. "# Boundary conditions\n",
  56. "u0 = Constant(100)\n",
  57. "def boundary(x, on_boundary):\n",
  58. " return on_boundary\n",
  59. "\n",
  60. "bc = DirichletBC(V,u0, boundary)"
  61. ]
  62. },
  63. {
  64. "cell_type": "code",
  65. "execution_count": 4,
  66. "metadata": {},
  67. "outputs": [],
  68. "source": [
  69. "u_n = project(1, V)\n",
  70. "u = TrialFunction(V)\n",
  71. "v = TestFunction(V)\n",
  72. "f = Constant(0.0)\n",
  73. "F = u*v*dx + alpha*dt*dot(grad(u), grad(v))*dx-u_n*v*dx\n",
  74. "a, L = lhs(F), rhs(F)"
  75. ]
  76. },
  77. {
  78. "cell_type": "code",
  79. "execution_count": 5,
  80. "metadata": {},
  81. "outputs": [],
  82. "source": [
  83. "vtkfile = File('solution/solution.pvd')\n",
  84. "u = Function(V)\n",
  85. "t = 0\n",
  86. "for n in range(num_steps):\n",
  87. " t += dt\n",
  88. " #u0.t = t\n",
  89. " solve(a == L, u, bc)\n",
  90. " #c = plot(u,)\n",
  91. " #plt.colorbar(c)\n",
  92. " #plt.show()\n",
  93. " ####\n",
  94. " vtkfile << (u, t)\n",
  95. " u_n.assign(u)"
  96. ]
  97. },
  98. {
  99. "cell_type": "code",
  100. "execution_count": 6,
  101. "metadata": {},
  102. "outputs": [
  103. {
  104. "data": {
  105. "text/plain": [
  106. "1e-13"
  107. ]
  108. },
  109. "execution_count": 6,
  110. "metadata": {},
  111. "output_type": "execute_result"
  112. }
  113. ],
  114. "source": [
  115. "1E-13"
  116. ]
  117. },
  118. {
  119. "cell_type": "code",
  120. "execution_count": 7,
  121. "metadata": {},
  122. "outputs": [
  123. {
  124. "data": {
  125. "text/plain": [
  126. "100.0"
  127. ]
  128. },
  129. "execution_count": 7,
  130. "metadata": {},
  131. "output_type": "execute_result"
  132. }
  133. ],
  134. "source": [
  135. "1e2"
  136. ]
  137. },
  138. {
  139. "cell_type": "code",
  140. "execution_count": 8,
  141. "metadata": {},
  142. "outputs": [
  143. {
  144. "data": {
  145. "text/plain": [
  146. "100.0000000000001"
  147. ]
  148. },
  149. "execution_count": 8,
  150. "metadata": {},
  151. "output_type": "execute_result"
  152. }
  153. ],
  154. "source": [
  155. "1E-13+1e2"
  156. ]
  157. },
  158. {
  159. "cell_type": "markdown",
  160. "metadata": {},
  161. "source": [
  162. "# Boundary conditions"
  163. ]
  164. },
  165. {
  166. "cell_type": "code",
  167. "execution_count": 17,
  168. "metadata": {},
  169. "outputs": [],
  170. "source": [
  171. "#1 Loading functions and modules\n",
  172. "from fenics import *\n",
  173. "import matplotlib.pyplot as plt\n",
  174. "T = 4\n",
  175. "num_steps = 200\n",
  176. "dt = T/num_steps\n",
  177. "rho = 7500\n",
  178. "Cp = 500\n",
  179. "k = 50\n",
  180. "alpha = k/(rho*Cp)"
  181. ]
  182. },
  183. {
  184. "cell_type": "code",
  185. "execution_count": 22,
  186. "metadata": {},
  187. "outputs": [
  188. {
  189. "data": {
  190. "image/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ebPPvnnz5rnSSwn8uc6cOcONGzf67Js7d64rvZTA38Tx7NmzVhO7ULxeryu9lMDfxPH8+fNW88ZQ/v7v/35I7xNKqeNa6/kRHfugDwgdHR388Ic/7LPdzZa7XV1d/e4bM2aMaxNMksseozGXUsq1NtijMRe4917RO9cLL7wwpL8pOwPCA6+M4uPjiYmJISUlhfT0dOrq6ujq6iItLc1SN25dDfzoRz8iJiaG/Px8amtr6ezstNSNG1VKQX7yk5/Q3t5OSUkJ1dXV+Hy+HurGrfbcP/vZz7h58yZlZWVUV1fT0dHRQ9241Z578+bN1NfXM3fuXKqqqmhvb++hbtxqz/2rX/2K8+fP8+ijj1JZWcn9+/etjrVuVCkF2bJlC7W1tSxcuJDKykru3r1LYmKipW7cas/99ttvU1FRweLFi6moqODOnTuuVikF2bZtG6ZpOnKB8cAPCPBJbfCKFSu4d+8eJ0+exDAMdu7caU3keL1exyeYghNya9assaqUDMPoUaXk8XgoLi52VN2MGTOG4uJi/uzP/syqUjIMIyqqlIqKili7di3PPvssNTU1mKZpVSnl5eXh9Xpdac9dUFDA5z73OVatWkVtbS2maUZFldK0adNYvXp11FUpZWZm9qhSMgyDw4cPc+jQIbKzs61qIKeV0uTJk1mxYgXLli3j7NmzGIbB0aNHXa9Scurv5qEYEEIZN24cjz76KI8++iiNjY2YpklFRQV1dXWu1ywHq5RCJ5hOnz4tVUphiI+Pt650o61Kqay
  191. "text/plain": [
  192. "<Figure size 432x288 with 1 Axes>"
  193. ]
  194. },
  195. "metadata": {
  196. "needs_background": "light"
  197. },
  198. "output_type": "display_data"
  199. }
  200. ],
  201. "source": [
  202. "#2 Create mesh and define function space\n",
  203. "nx = 0.008\n",
  204. "ny = 0.003\n",
  205. "mesh = RectangleMesh(Point(0,0),Point(nx,ny),8, 8,'left')\n",
  206. "V = FunctionSpace(mesh, 'Lagrange', 1) #Lagrange are triangular elements\n",
  207. "plot(mesh)\n",
  208. "plt.show()\n",
  209. "\n"
  210. ]
  211. },
  212. {
  213. "cell_type": "code",
  214. "execution_count": 23,
  215. "metadata": {},
  216. "outputs": [],
  217. "source": [
  218. "#Boundary Conditions\n",
  219. "tol = 1E-14\n",
  220. "\n",
  221. "def BC1(x, on_boundary):\n",
  222. " return on_boundary and abs(x[0]-nx) < tol\n",
  223. "\n",
  224. "def BC2(x, on_boundary):\n",
  225. " return on_boundary and abs(x[0]-0) < tol\n",
  226. "\n",
  227. "bc1=DirichletBC(V,Constant(25),BC1)\n",
  228. "bc2=DirichletBC(V,Constant(800),BC2)\n",
  229. "bc=(bc1,bc2)"
  230. ]
  231. },
  232. {
  233. "cell_type": "code",
  234. "execution_count": 24,
  235. "metadata": {},
  236. "outputs": [],
  237. "source": [
  238. "u_n = project(25, V)\n",
  239. "u = TrialFunction(V)\n",
  240. "v = TestFunction(V)\n",
  241. "f = Constant(0.0)\n",
  242. "F = u*v*dx + alpha*dt*dot(grad(u), grad(v))*dx-u_n*v*dx\n",
  243. "a, L = lhs(F), rhs(F)"
  244. ]
  245. },
  246. {
  247. "cell_type": "code",
  248. "execution_count": 25,
  249. "metadata": {},
  250. "outputs": [],
  251. "source": [
  252. "vtkfile = File('solution/solution2.pvd')\n",
  253. "u = Function(V)\n",
  254. "t = 0\n",
  255. "for n in range(num_steps):\n",
  256. " t += dt\n",
  257. " #u0.t = t\n",
  258. " solve(a == L, u, bc)\n",
  259. " vtkfile << (u, t)\n",
  260. " #c = plot(u,)\n",
  261. " #plt.colorbar(c)\n",
  262. " #plt.show()\n",
  263. " u_n.assign(u)"
  264. ]
  265. },
  266. {
  267. "cell_type": "code",
  268. "execution_count": null,
  269. "metadata": {},
  270. "outputs": [],
  271. "source": []
  272. }
  273. ],
  274. "metadata": {
  275. "kernelspec": {
  276. "display_name": "Python 3",
  277. "language": "python",
  278. "name": "python3"
  279. },
  280. "language_info": {
  281. "codemirror_mode": {
  282. "name": "ipython",
  283. "version": 3
  284. },
  285. "file_extension": ".py",
  286. "mimetype": "text/x-python",
  287. "name": "python",
  288. "nbconvert_exporter": "python",
  289. "pygments_lexer": "ipython3",
  290. "version": "3.6.7"
  291. }
  292. },
  293. "nbformat": 4,
  294. "nbformat_minor": 2
  295. }