# Example 2: One-dimensional heat flow (exs2.py)  

This example is from the CALFEM manual.

**Purpose:**

Analysis of one-dimensional heat flow.

**Description:**

Consider a wall built up of concrete and thermal insulation. The outdoor
temperature is −17 ◦C and the temperature inside is 20 ◦C. At the inside of
the thermal insulation there is a heat source yielding $10 ~W/m^2$.



The wall is subdivided into five elements and the one-dimensional spring
(analogy) element `spring1e` is used. Equivalent spring stiffnesses are
$k_i = λ A/L$ for thermal conductivity and $k_i = A/R$ for thermal
surface resistance. Corresponding spring stiffnesses per $m^2$ of the wall
are:

\begin{align}
k_1 &= 1/0.04 = 25.0 ~W/K  \\
k_2 &= 1.7/0.070 = 24.3 ~W/K  \\
k_3 &= 0.040/0.100 = 0.4 ~W/K  \\
k_4 &= 1.7/0.100 = 17.0 ~W/K  \\
k_5 &= 1/0.13 = 7.7 ~W/K 
\end{align}

A global system matrix K and a heat flow vector f are defined. The heat source
inside the wall is considered by setting $f_4 = 10$. The element matrices
`Ke` are computed using `spring1e`, and the function `assem` assembles the
global stiffness matrix.

The system of equations is solved using `solveq` with considerations to the
boundary conditions in `bc` and `bcVal`. The prescribed temperatures are 
$T_1 = −17 ~^{\circ}C$ and $T_2 = 20~^{\circ}C$.

Necessary modules are first imported.


```python
import numpy as np
import calfem.core as cfc
```

Next, the element topology is defined


```python
Edof = np.array([
    [1,2],
    [2,3],
    [3,4],
    [4,5],
    [5,6]
])
```

Create stiffness matrix K and load vector f


```python
K = np.mat(np.zeros((6,6)))
f = np.mat(np.zeros((6,1)))
f[3] = 10.0
```

Define element properties (ep) and create element matrices for the different material layers.


```python
ep1 = 25.0
ep2 = 24.3
ep3 = 0.4
ep4 = 17.0
ep5 = 7.7
```

Element stiffness matrices


```python
Ke1 = cfc.spring1e(ep1)
Ke2 = cfc.spring1e(ep2)
Ke3 = cfc.spring1e(ep3)
Ke4 = cfc.spring1e(ep4)
Ke5 = cfc.spring1e(ep5)
```

Assemble all element matrices into the global stiffness matrix


```python
cfc.assem(Edof[0,:], K, Ke1)
cfc.assem(Edof[1,:], K, Ke2) 
cfc.assem(Edof[2,:], K, Ke3)
cfc.assem(Edof[3,:], K, Ke4)
cfc.assem(Edof[4,:], K, Ke5)

print("Stiffness matrix K:")
print(K)
```

    Stiffness matrix K:
    [[ 25.  -25.    0.    0.    0.    0. ]
     [-25.   49.3 -24.3   0.    0.    0. ]
     [  0.  -24.3  24.7  -0.4   0.    0. ]
     [  0.    0.   -0.4  17.4 -17.    0. ]
     [  0.    0.    0.  -17.   24.7  -7.7]
     [  0.    0.    0.    0.   -7.7   7.7]]


Define the boundary conditions and solve the system of equations


```python
bc = np.array([1,6])
bcVal = np.array([-17.0, 20.0])
a,r = cfc.solveq(K, f, bc, bcVal)

print("Displacements a:")
print(a)

print("Reaction forces r:")
print(r)
```

    Displacements a:
    [[-17.        ]
     [-16.43842455]
     [-15.86067203]
     [ 19.23779344]
     [ 19.47540439]
     [ 20.        ]]
    Reaction forces r:
    [[-1.40393862e+01]
     [ 0.00000000e+00]
     [ 0.00000000e+00]
     [ 0.00000000e+00]
     [ 5.68434189e-14]
     [ 4.03938619e+00]]




0fc6225c93867b95da28cc22b3461c73cce8efca
ipynb
Jupyter Notebook
examples/.ipynb_checkpoints/exs2-checkpoint.ipynb
Karl-Eriksson/calfem-python
e9a88a85d3a73877ec99f7fbd1a296a44c3c9b22
MIT
2016-04-11T19:12:13.000Z
2022-02-22T07:15:39.000Z
examples/.ipynb_checkpoints/exs2-checkpoint.ipynb
Karl-Eriksson/calfem-python
e9a88a85d3a73877ec99f7fbd1a296a44c3c9b22
MIT
2019-07-01T19:48:38.000Z
2022-02-11T12:50:02.000Z
examples/.ipynb_checkpoints/exs2-checkpoint.ipynb
Karl-Eriksson/calfem-python
e9a88a85d3a73877ec99f7fbd1a296a44c3c9b22
MIT
2017-08-01T10:29:09.000Z
2022-02-16T14:02:36.000Z
Qwen/Qwen-72B
1. YES
2. YES