{"id":2166,"date":"2024-05-05T01:07:16","date_gmt":"2024-05-05T08:07:16","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=2166"},"modified":"2024-05-05T01:08:17","modified_gmt":"2024-05-05T08:08:17","slug":"423-the-2d-diffusion-equation-applied-to-the-temperature-of-a-steel-circular-plate","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2024\/05\/423-the-2d-diffusion-equation-applied-to-the-temperature-of-a-steel-circular-plate\/","title":{"rendered":"#423 The 2D diffusion equation applied to the temperature of a steel plate"},"content":{"rendered":"<p><a href=\"https:\/\/gantovnik.com\/bio-tips\/2024\/05\/423-the-2d-diffusion-equation-applied-to-the-temperature-of-a-steel-circular-plate\/ex423\/\" rel=\"attachment wp-att-2167\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex423.png?resize=640%2C480&#038;ssl=1\" alt=\"\" width=\"640\" height=\"480\" class=\"alignnone size-full wp-image-2167\" srcset=\"https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex423.png 640w, https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex423-480x360.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 640px, 100vw\" \/><\/a><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\n\r\n# plate size, mm\r\nw = h = 10.\r\n# intervals in x-, y- directions, mm\r\ndx = dy = 0.1\r\n# Thermal diffusivity of steel, mm2.s-1\r\nD = 4.\r\n\r\nTcool, Thot = 300, 700\r\n\r\nnx, ny = int(w\/dx), int(h\/dy)\r\n\r\ndx2, dy2 = dx*dx, dy*dy\r\ndt = dx2 * dy2 \/ (2 * D * (dx2 + dy2))\r\n\r\nu0 = Tcool * np.ones((nx, ny))\r\nu = u0.copy()\r\n\r\n# Initial conditions - circle of radius r centred at (cx,cy) (mm)\r\nr, cx, cy = 2, 5, 5\r\nr2 = r**2\r\nfor i in range(nx):\r\n    for j in range(ny):\r\n        p2 = (i*dx-cx)**2 + (j*dy-cy)**2\r\n        if p2 &lt; r2:\r\n            u0&#x5B;i,j] = Thot\r\n\r\ndef do_timestep(u0, u):\r\n    # Propagate with forward-difference in time, central-difference in space\r\n    u&#x5B;1:-1, 1:-1] = u0&#x5B;1:-1, 1:-1] + D * dt * (\r\n          (u0&#x5B;2:, 1:-1] - 2*u0&#x5B;1:-1, 1:-1] + u0&#x5B;:-2, 1:-1])\/dx2\r\n          + (u0&#x5B;1:-1, 2:] - 2*u0&#x5B;1:-1, 1:-1] + u0&#x5B;1:-1, :-2])\/dy2 )\r\n\r\n    u0 = u.copy()\r\n    return u0, u\r\n\r\n# Number of timesteps\r\nnsteps = 101\r\n# Output 4 figures at these timesteps\r\nmfig = &#x5B;0, 10, 50, 100]\r\nfignum = 0\r\nfig = plt.figure()\r\nfor m in range(nsteps):\r\n    u0, u = do_timestep(u0, u)\r\n    if m in mfig:\r\n        fignum += 1\r\n        print(m, fignum)\r\n        ax = fig.add_subplot(220 + fignum)\r\n        im = ax.imshow(u.copy(), cmap=plt.get_cmap(&#039;hot&#039;), vmin=Tcool,vmax=Thot)\r\n        ax.set_axis_off()\r\n        ax.set_title(&#039;{:.1f} ms&#039;.format(m*dt*1000))\r\nfig.subplots_adjust(right=0.85)\r\ncbar_ax = fig.add_axes(&#x5B;0.9, 0.15, 0.03, 0.7])\r\ncbar_ax.set_xlabel(&#039;$T$ \/ K&#039;, labelpad=20)\r\nfig.colorbar(im, cax=cbar_ax)\r\nplt.savefig(&#039;ex423.png&#039;, dpi=100)\r\nplt.show()\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>import numpy as np import matplotlib.pyplot as plt # plate size, mm w = h = 10. # intervals in x-, y- directions, mm dx = dy = 0.1 # Thermal diffusivity of steel, mm2.s-1 D = 4. Tcool, Thot = 300, 700 nx, ny = int(w\/dx), int(h\/dy) dx2, dy2 = dx*dx, dy*dy dt = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_lmt_disableupdate":"yes","_lmt_disable":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[69,77,99,91],"tags":[],"class_list":["post-2166","post","type-post","status-publish","format-standard","hentry","category-matplotlib","category-numerical","category-numpy","category-plot"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-yW","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":200,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/heat-equation-1d\/","url_meta":{"origin":2166,"position":0},"title":"Heat equation (1D)","author":"gantovnik","date":"2019-01-10","format":false,"excerpt":"import os import numpy as np import matplotlib.pyplot as plt os.chdir(r'D:\\projects\\wordpress\\ex41') os.getcwd() N = 5 u0 = 1 u1 = 2 dx = 1.0 \/ (N + 1) A = (np.eye(N, k=-1) - 2 * np.eye(N) + np.eye(N, k=1)) \/ dx**2 print(A) d = -5 * np.ones(N) d[0] -= u0\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example41","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example41.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example41.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example41.png?resize=525%2C300 1.5x"},"classes":[]},{"id":926,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/06\/166-solution-of-a-differential-equation-using-bubnov-galerkin-method-with-sympy-package\/","url_meta":{"origin":2166,"position":1},"title":"#166 Solution of a differential equation using Bubnov-Galerkin method with Sympy package","author":"gantovnik","date":"2021-06-15","format":false,"excerpt":"#166 Solution of a differential equation using Bubnov-Galerkin method with Sympy package The problem and solution in this pdf file: ex166 [code language=\"python\"] import sympy from matplotlib import pyplot as plt import seaborn as sns import numpy as np from sympy.utilities.lambdify import lambdify from sympy import simplify from sympy import\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":151,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/direction-fields\/","url_meta":{"origin":2166,"position":2},"title":"Direction fields","author":"gantovnik","date":"2019-01-07","format":false,"excerpt":"[code language=\"python\"] import os import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl mpl.rcParams['text.usetex'] = True import sympy os.chdir(r'D:\\projects\\wordpress\\ex32') os.getcwd() def plot_direction_field(x, y_x, f_xy, x_lim=(-5, 5), y_lim=(-5, 5), ax=None): f_np = sympy.lambdify((x, y_x), f_xy, 'numpy') x_vec = np.linspace(x_lim[0], x_lim[1], 20) y_vec = np.linspace(y_lim[0], y_lim[1], 20) if ax\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example32","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example32.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example32.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example32.png?resize=525%2C300 1.5x"},"classes":[]},{"id":157,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/numerical-integration-of-odes-using-scipy\/","url_meta":{"origin":2166,"position":3},"title":"Numerical integration of ODEs using SciPy","author":"gantovnik","date":"2019-01-09","format":false,"excerpt":"import os import numpy as np import matplotlib.pyplot as plt from scipy import integrate import sympy os.chdir(r'D:\\projects\\wordpress\\ex35') os.getcwd() def plot_direction_field(x, y_x, f_xy, x_lim=(-5, 5), y_lim=(-5, 5), ax=None): f_np = sympy.lambdify((x, y_x), f_xy, 'numpy') x_vec = np.linspace(x_lim[0], x_lim[1], 20) y_vec = np.linspace(y_lim[0], y_lim[1], 20) if ax is None: _, ax =\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example35","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example35.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":154,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/inexact-solutions-to-odes\/","url_meta":{"origin":2166,"position":4},"title":"Inexact solutions to ODEs","author":"gantovnik","date":"2019-01-08","format":false,"excerpt":"\u00a0 import os import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl import sympy from IPython.display import display sympy.init_printing() mpl.rcParams['text.usetex'] = True import sympy os.chdir(r'D:\\projects\\wordpress\\ex33') os.getcwd() def plot_direction_field(x, y_x, f_xy, x_lim=(-5, 5), y_lim=(-5, 5), ax=None): f_np = sympy.lambdify((x, y_x), f_xy, 'numpy') x_vec = np.linspace(x_lim[0], x_lim[1], 20) y_vec\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example33","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example33.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example33.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example33.png?resize=525%2C300 1.5x"},"classes":[]},{"id":210,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/2nd-order-runge-kutta-type-a\/","url_meta":{"origin":2166,"position":5},"title":"#44 2nd-order Runge-Kutta type A using python","author":"gantovnik","date":"2019-01-12","format":false,"excerpt":"[code language=\"python\"] import os import numpy as np import matplotlib.pyplot as plt os.chdir(r'D:\\projects\\wordpress\\ex44') os.getcwd() #2nd-order Runge-Kutta methods with A=1\/2 (type A) # dy\/dx=exp(-2x)-2y # y(0)=0.1, interval x=[0,2], step size = h=0.2 def feval(funcName, *args): return eval(funcName)(*args) def RK2A(func, yinit, x_range, h): m = len(yinit) n = int((x_range[-1] - x_range[0])\/h) x\u2026","rel":"","context":"In &quot;numerical&quot;","block_context":{"text":"numerical","link":"https:\/\/gantovnik.com\/bio-tips\/category\/numerical\/"},"img":{"alt_text":"example44","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example44-1.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example44-1.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example44-1.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/2166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/comments?post=2166"}],"version-history":[{"count":3,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/2166\/revisions"}],"predecessor-version":[{"id":2170,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/2166\/revisions\/2170"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=2166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=2166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=2166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}