Heat transfer through a wall

This problem demonstrates a combination of prescribed temperature on the left and prescribed flux on the right side.

Using

Theory

We shall consider a stationary heat transfer problem within a wall. The inner surface of the wall, \(x=0~m\), is heated to \(200~K\), the outer surface of the wall, \(x=10~m\), to \(300~K\).

The thermal equation for the uni-directional problem can be expressed as

\[\Delta T = \frac{\partial^2 T}{\partial r^2} = 0\]

where \(\Delta\) is the Laplace operator.

The analytic solution follows as

\[T(x) = T_i + q_n \: x\]

This solution will be compared against the finite element solution in the last figure.

import matplotlib.pyplot as plt

import math
import sys
import numpy as np

from femedu.examples.Example import *

from femedu.domain import *
from femedu.mesher import PatchMesher
from femedu.elements.diffusion import Triangle
from femedu.materials import Thermal


class ExampleThermal01(Example):

    def problem(self):
        # ========== setting mesh parameters ==============

        Nx = 5  # number of elements through the wall
        Ny = 1  # number of elements parallel to the wall
        Lx = 10.00  # wall thickness in m
        Ly =  1.00  # wall thickness in m

        # ========== setting material parameters ==============

        params = dict(
            E=20000.,  # Young's modulus
            nu=0.250,  # Poisson's ratio
            t=1.00     # thickness of the plate
        )

        # ========== setting load parameters ==============

        qn = 1.00  # uniform flux normal to x=const

        # ========== setting analysis parameters ==============

        target_load_level = 1.00  # reference load
        max_steps = 2  # number of load steps: 2 -> [0.0, 1.0]

        # define a list of target load levels
        load_levels = np.linspace(0, target_load_level, max_steps)

        #
        # ==== Build the system model ====
        #

        model = System()

        # create nodes

        #  2 -------- 3
        #  |          |
        #  |          |
        #  |          |          |
        #  0 -------- 1

        pts = (
            ( 0,  0),  # 0
            (Lx,  0),  # 1
            ( 0, Ly),  # 2
            (Lx, Ly),  # 3
        )

        mesher = PatchMesher(model, pts[0], pts[1], pts[3], pts[2])
        nodes, elements = mesher.triangleMesh(Nx, Ny, Triangle, Thermal(params))

        model.plot(factor=0.0,
                   title='Uni-directional diffusion',
                   show_reactions=0, show_bc=0, show_loads=0)

        model.report()

        # boundary condition(s)

        ## find nodes at y==0 and x==0

        for node in nodes:
            X = node.getPos()
            if math.isclose(X[0], 0.0):
                node.fixDOF('T')    # prescribed temperature at x=0.0
            # if math.isclose(X[0], Lx):
            #     node.fixDOF('T')  # prescribed temperature at x=Lx

        # ==== complete the reference load ====

        Xo = np.array([Lx, 0.0])
        No = np.array([1.0, 0.0])

        for node in nodes:
            X = node.getPos()
            if math.isclose(X[0], Lx):
                print(node)
                for elem in node.elements:
                    print('+', elem)
                    for face in elem.faces:
                        for x, area in zip(face.pos, face.area):
                            if np.abs((x - Xo) @ No) < 1.0e-2 and No @ area / np.linalg.norm(area) > 1.0e-2:
                                face.setFlux(qn)

        # perform the analysis
        model.setLoadFactor(1.0)
        model.solve()

        model.report()

        model.valuePlot('T', show_mesh=True)

        # creating a path plot

        R_list = []
        T_list = []

        for node in nodes:
            X = node.getPos()
            T = node.getDisp('T')
            R_list.append(X[0])
            T_list.append(T)

        # the analytic solution for comparison
        x = np.linspace(0, Lx, 21)
        T = 0.0 * (1 - x/Lx) + qn * x

        fig, axs = plt.subplots()
        axs.plot(x,T,'-b',label="analytic solution")
        axs.plot(R_list,T_list,'ro',label="FEM")
        axs.set_title('Nodal Temperature for ALL Nodes')
        axs.set_xlabel("X distance")
        axs.set_ylabel('T')
        axs.legend()
        axs.grid(True)
        plt.show()

Run the example by creating an instance of the problem and executing it by calling Example.run()

if __name__ == "__main__":
    ex = ExampleThermal01()
    ex.run()
  • Uni-directional diffusion
  • Contours of 'T'
  • Nodal Temperature for ALL Nodes
System Analysis Report
=======================

Nodes:
---------------------
  Node_219:
      x:    [0. 0.]
      u:    [0.]
  Node_220:
      x:    [2. 0.]
      u:    [0.]
  Node_221:
      x:    [4. 0.]
      u:    [0.]
  Node_222:
      x:    [6. 0.]
      u:    [0.]
  Node_223:
      x:    [8. 0.]
      u:    [0.]
  Node_224:
      x:    [10.  0.]
      u:    [0.]
  Node_225:
      x:    [0. 1.]
      u:    [0.]
  Node_226:
      x:    [2. 1.]
      u:    [0.]
  Node_227:
      x:    [4. 1.]
      u:    [0.]
  Node_228:
      x:    [6. 1.]
      u:    [0.]
  Node_229:
      x:    [8. 1.]
      u:    [0.]
  Node_230:
      x:    [10.  1.]
      u:    [0.]

Elements:
---------------------
  Triangle_337: nodes ( Node_219 Node_220 Node_225 )
      material: Thermal
      grad phi: x=0.000e+00 y=0.000e+00
      flux:     x=0.000e+00 y=0.000e+00
  Triangle_338: nodes ( Node_226 Node_225 Node_220 )
      material: Thermal
      grad phi: x=0.000e+00 y=0.000e+00
      flux:     x=0.000e+00 y=0.000e+00
  Triangle_339: nodes ( Node_220 Node_221 Node_226 )
      material: Thermal
      grad phi: x=0.000e+00 y=0.000e+00
      flux:     x=0.000e+00 y=0.000e+00
  Triangle_340: nodes ( Node_227 Node_226 Node_221 )
      material: Thermal
      grad phi: x=0.000e+00 y=0.000e+00
      flux:     x=0.000e+00 y=0.000e+00
  Triangle_341: nodes ( Node_221 Node_222 Node_227 )
      material: Thermal
      grad phi: x=0.000e+00 y=0.000e+00
      flux:     x=0.000e+00 y=0.000e+00
  Triangle_342: nodes ( Node_228 Node_227 Node_222 )
      material: Thermal
      grad phi: x=0.000e+00 y=0.000e+00
      flux:     x=0.000e+00 y=0.000e+00
  Triangle_343: nodes ( Node_222 Node_223 Node_228 )
      material: Thermal
      grad phi: x=0.000e+00 y=0.000e+00
      flux:     x=0.000e+00 y=0.000e+00
  Triangle_344: nodes ( Node_229 Node_228 Node_223 )
      material: Thermal
      grad phi: x=0.000e+00 y=0.000e+00
      flux:     x=0.000e+00 y=0.000e+00
  Triangle_345: nodes ( Node_223 Node_224 Node_229 )
      material: Thermal
      grad phi: x=0.000e+00 y=0.000e+00
      flux:     x=0.000e+00 y=0.000e+00
  Triangle_346: nodes ( Node_230 Node_229 Node_224 )
      material: Thermal
      grad phi: x=0.000e+00 y=0.000e+00
      flux:     x=0.000e+00 y=0.000e+00

Node_224:
    x:    [10.  0.]
    u:    [0.]
+ Triangle_345: nodes ( Node_223 Node_224 Node_229 )
    material: Thermal
    grad phi: x=0.000e+00 y=0.000e+00
    flux:     x=0.000e+00 y=0.000e+00
+ Triangle_346: nodes ( Node_230 Node_229 Node_224 )
    material: Thermal
    grad phi: x=0.000e+00 y=0.000e+00
    flux:     x=0.000e+00 y=0.000e+00
Node_230:
    x:    [10.  1.]
    u:    [0.]
+ Triangle_346: nodes ( Node_230 Node_229 Node_224 )
    material: Thermal
    grad phi: x=0.000e+00 y=0.000e+00
    flux:     x=0.000e+00 y=0.000e+00

System Analysis Report
=======================

Nodes:
---------------------
  Node_219:
      x:    [0. 0.]
      fix:  ['T']
      u:    [0.]
  Node_220:
      x:    [2. 0.]
      u:    [2.]
  Node_221:
      x:    [4. 0.]
      u:    [4.]
  Node_222:
      x:    [6. 0.]
      u:    [6.]
  Node_223:
      x:    [8. 0.]
      u:    [8.]
  Node_224:
      x:    [10.  0.]
      u:    [10.]
  Node_225:
      x:    [0. 1.]
      fix:  ['T']
      u:    [0.]
  Node_226:
      x:    [2. 1.]
      u:    [2.]
  Node_227:
      x:    [4. 1.]
      u:    [4.]
  Node_228:
      x:    [6. 1.]
      u:    [6.]
  Node_229:
      x:    [8. 1.]
      u:    [8.]
  Node_230:
      x:    [10.  1.]
      u:    [10.]

Elements:
---------------------
  Triangle_337: nodes ( Node_219 Node_220 Node_225 )
      material: Thermal
      grad phi: x=1.000e+00 y=0.000e+00
      flux:     x=-1.000e+00 y=-0.000e+00
  Triangle_338: nodes ( Node_226 Node_225 Node_220 )
      material: Thermal
      grad phi: x=1.000e+00 y=0.000e+00
      flux:     x=-1.000e+00 y=-0.000e+00
  Triangle_339: nodes ( Node_220 Node_221 Node_226 )
      material: Thermal
      grad phi: x=1.000e+00 y=0.000e+00
      flux:     x=-1.000e+00 y=-0.000e+00
  Triangle_340: nodes ( Node_227 Node_226 Node_221 )
      material: Thermal
      grad phi: x=1.000e+00 y=0.000e+00
      flux:     x=-1.000e+00 y=-0.000e+00
  Triangle_341: nodes ( Node_221 Node_222 Node_227 )
      material: Thermal
      grad phi: x=1.000e+00 y=0.000e+00
      flux:     x=-1.000e+00 y=-0.000e+00
  Triangle_342: nodes ( Node_228 Node_227 Node_222 )
      material: Thermal
      grad phi: x=1.000e+00 y=0.000e+00
      flux:     x=-1.000e+00 y=-0.000e+00
  Triangle_343: nodes ( Node_222 Node_223 Node_228 )
      material: Thermal
      grad phi: x=1.000e+00 y=0.000e+00
      flux:     x=-1.000e+00 y=-0.000e+00
  Triangle_344: nodes ( Node_229 Node_228 Node_223 )
      material: Thermal
      grad phi: x=1.000e+00 y=-8.882e-16
      flux:     x=-1.000e+00 y=8.882e-16
  Triangle_345: nodes ( Node_223 Node_224 Node_229 )
      material: Thermal
      grad phi: x=1.000e+00 y=-8.882e-16
      flux:     x=-1.000e+00 y=8.882e-16
  Triangle_346: nodes ( Node_230 Node_229 Node_224 )
      material: Thermal
      grad phi: x=1.000e+00 y=-1.776e-15
      flux:     x=-1.000e+00 y=1.776e-15

Total running time of the script: (0 minutes 0.552 seconds)

Gallery generated by Sphinx-Gallery