.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/thermal/thermal_conduction_2d.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_thermal_thermal_conduction_2d.py: Transient heat conduction in a 2D square ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Transient heat conduction in a unit square with :class:`fedoo.weakform.HeatEquation` and :class:`fedoo.constitutivelaw.ThermalProperties`, solved on a :class:`fedoo.problem.NonLinear` problem with a first-order backward Euler time integrator. The temperatures of the left and right edges are ramped from 0 to :math:`T = 100` and :math:`T = 50`; the other edges are insulated. .. GENERATED FROM PYTHON SOURCE LINES 11-16 .. code-block:: Python import os import fedoo as fd .. GENERATED FROM PYTHON SOURCE LINES 17-22 Mesh and thermal law -------------------- Units: W, m, kg, s, K. The values are illustrative: the conductivity is the one of a steel, but the specific heat is about 1000 times smaller than that of steel, which shortens the diffusion time to a few tens of seconds. .. GENERATED FROM PYTHON SOURCE LINES 22-40 .. code-block:: Python fd.ModelingSpace("2Dplane") L = 1 meshname = "Domain" fd.mesh.rectangle_mesh( nx=21, ny=21, x_min=0, x_max=L, y_min=0, y_max=L, elm_type="quad4", name=meshname ) mesh = fd.Mesh[meshname] K = 18 # thermal conductivity, W/(m.K) c = 0.500 # specific heat, J/(kg.K) (illustrative value) rho = 7800 # density, kg/m3 (unit thickness in 2Dplane) material = fd.constitutivelaw.ThermalProperties(K, c, rho, name="ThermalLaw") wf = fd.weakform.HeatEquation(material) assemb = fd.Assembly.create(wf, meshname, name="Assembling") .. GENERATED FROM PYTHON SOURCE LINES 41-47 Problem, time integrator and boundary conditions ------------------------------------------------ The ``"Displacement"`` criterion is the generic norm of the dof increment; here it applies to the temperature. The prescribed temperatures start from 0 (``start_value=0``) and follow the default linear time function, so they reach their final value only at :math:`t_{max}`. .. GENERATED FROM PYTHON SOURCE LINES 47-65 .. code-block:: Python left = mesh.find_nodes("X", 0) right = mesh.find_nodes("X", L) pb = fd.problem.NonLinear("Assembling") pb.set_time_integrator(fd.time.FIRST_ORDER, fd.time.BackwardEuler()) pb.set_nr_criterion("Displacement", tol=1e-2, max_subiter=5, err0=100) if not (os.path.isdir("results")): os.mkdir("results") res = pb.add_output( "results/thermal2D", "Assembling", ["Temp"], output_type="Node", file_format="vtk" ) tmax = 200 pb.bc.add("Dirichlet", left, "Temp", 100, start_value=0) pb.bc.add("Dirichlet", right, "Temp", 50, start_value=0) .. rst-class:: sphx-glr-script-out .. code-block:: none Dirichlet boundary condition: var = 'Temp' n_nodes = 21 value = 50 .. GENERATED FROM PYTHON SOURCE LINES 66-77 Solve and plot the final temperature field ------------------------------------------ With the diffusivity :math:`\alpha = K / (\rho c) \approx 4.6 \times 10^{-3}`, the slowest transient mode decays with the time constant :math:`\tau_1 = L^2 / (\pi^2 \alpha) \approx 22`, much shorter than :math:`t_{max} = 200`: the initial transient has vanished at the end. The final field is nevertheless not yet the linear steady profile, because the boundary temperatures are still rising at :math:`t_{max}`. For such a ramp the interior lags behind the boundary values by about 10 K at the center (about 13 % of the steady value of 75 K), and the backward Euler scheme with :math:`\Delta t = 20` adds a further lag. .. GENERATED FROM PYTHON SOURCE LINES 77-81 .. code-block:: Python pb.nlsolve(dt=tmax / 10, tmax=tmax, update_dt=True) res.plot("Temp") .. image-sg:: /examples/thermal/images/sphx_glr_thermal_conduction_2d_001.png :alt: thermal conduction 2d :srcset: /examples/thermal/images/sphx_glr_thermal_conduction_2d_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Iter 1 - Time: 20.00000 - dt 20.00000 - NR iter: 2 - Err: 0.00158 Iter 2 - Time: 40.00000 - dt 20.00000 - NR iter: 2 - Err: 0.00081 Iter 3 - Time: 60.00000 - dt 20.00000 - NR iter: 2 - Err: 0.00043 Iter 4 - Time: 80.00000 - dt 20.00000 - NR iter: 2 - Err: 0.00022 Iter 5 - Time: 100.00000 - dt 20.00000 - NR iter: 2 - Err: 0.00012 Iter 6 - Time: 120.00000 - dt 20.00000 - NR iter: 2 - Err: 0.00006 Iter 7 - Time: 140.00000 - dt 20.00000 - NR iter: 2 - Err: 0.00003 Iter 8 - Time: 160.00000 - dt 20.00000 - NR iter: 2 - Err: 0.00002 Iter 9 - Time: 180.00000 - dt 20.00000 - NR iter: 2 - Err: 0.00001 Iter 10 - Time: 200.00000 - dt 20.00000 - NR iter: 2 - Err: 0.00000 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.338 seconds) .. _sphx_glr_download_examples_thermal_thermal_conduction_2d.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: thermal_conduction_2d.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: thermal_conduction_2d.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: thermal_conduction_2d.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_