#. # On the evaluation of thermal expansion coefficients
#.
#. When solving thermal-mechanical problems it is customary to use
#. thermal expansion coefficients in order to take into account the mechanical
#. strains induced by changes in the material temperature with respect to
#. a reference temperature where the deformation is identically zero.
#. These coefficients $\alpha$ are defined as the partial derivative
#. of the strain $\epsilon$ with respect to temperature $T$ such that
#. differential relationships like
#.
#. $$
#. d\epsilon = \frac{\partial \epsilon}{\partial T} \, dT = \alpha \cdot dT
#. $$
#.
#. hold. This derivative $\alpha$ is called the _instantaneous_
#. thermal expansion coefficient.
#. For finite temperature increments, one would like to be able to write
#.
#. $$
#. \Delta \epsilon = \alpha \cdot \Delta T
#. $$
#.
#. But if the strain is not linear with respect to the temperature---which
#. is the most common case---then $\alpha$ depends on $T$.
#. Therefore, when dealing with finite temperature increments $\Delta T = T-T_0$
#. where the thermal expansion coefficient $\alpha(T)$ depends on the temperature
#. itself then _mean_ values for the thermal expansion ought to be used:
#.
#. $$
#. \Delta \epsilon = \int_{\epsilon_0}^{\epsilon} d\epsilon^{\prime} 
#. = \int_{T_0}^{T} \frac{\partial \epsilon}{\partial T^\prime} \, dT^\prime
#. = \int_{T_0}^{T} \alpha(T^\prime) \, dT^\prime
#. $$
#.
#. We can multiply and divide by $\Delta T$ to obtain
#.
#. $$
#. \int_{T_0}^{T} \alpha(T^\prime) \, dT^\prime \cdot \frac{\Delta T}{\Delta T}
#. = \bar{\alpha}(T) \cdot \Delta T
#. $$
#. 
#. where the mean expansion coefficient for the temperature range $[T_0,T]$ is 
#.
#. $$
#. \bar{\alpha}(T) = \frac{\displaystyle \int_{T_0}^{T} \alpha(T^\prime) \, dT^\prime}{T-T_0}
#. $$
#. 
#. This is of course the classical calculus result of the mean value of a
#. continuous one-dimensional function in a certain range.
#.
#. Let $\epsilon(T)$ be the linear thermal expansion of a given material in a
#. certain direction when heating a piece of such material from an initial
#. temperature $T_0$ up to $T$ so that $\epsilon(T_0)=0$.
#. 
#. ![Table TE2 of thermal expansion properties for Aluminum alloys from ASME II Part D (figure from [this report](https://www.ramsay-maunder.co.uk/knowledge-base/technical-notes/asmeansys-potential-issue-with-thermal-expansion-calculations/).](asme-expansion-table.png){#fig:table-asme-expansion}
#.
#. From our previous analysis, we can see that in @fig:table-asme-expansion:
#. 
#. $$
#. \begin{aligned}
#. A(T) &= \alpha(T)       = \frac{\partial \epsilon}{\partial T} \\
#. B(T) &= \bar{\alpha}(T) = \frac{\epsilon(T)}{T-T_0} = \frac{\displaystyle \int_{T_0}^{T} \alpha(T^\prime) \, dT^\prime}{T - T_0} \\
#. C(T) &= \epsilon(T)     = \int_{T_0}^T \alpha(T^\prime) \, dT^\prime
#. \end{aligned}
#. $$
#. 
#. Therefore,
#.
#.  i.   $A(T)$ can be computed out of $C(T)$
#.  ii.  $B(T)$ can be computed either out of $A(T)$ or $C(T)$
#.  iii. $C(T)$ can be computed out of $A(T)$
#. 
#$ $ cat asme-expansion-table.dat 
#$ # temp  A       B        C
#$ 20      21.7    21.7     0
#$ 50      23.3    22.6     0.7
#$ 75      23.9    23.1     1.3
#$ 100     24.3    23.4     1.9
#$ 125     24.7    23.7     2.5
#$ 150     25.2    23.9     3.1
#$ 175     25.7    24.2     3.7
#$ 200     26.4    24.4     4.4
#$ 225     27.0    24.7     5.1
#$ 250     27.5    25.0     5.7
#$ 275     27.7    25.2     6.4
#$ 300     27.6    25.5     7.1
#$ 325     27.1    25.6     7.8
#$ $ feenox asme-expansion.fee > asme-expansion-interpolation.dat
#$ $ pyxplot asme-expansion.ppl
#$ $
# just in case we wanted to interpolate with another method (linear, splines, etc.)
DEFAULT_ARGUMENT_VALUE 1 steffen

# read columns from data file and interpolate
# A is the instantaenous coefficient of thermal expansion x 10^-6 (mm/mm/ºC)
FUNCTION A(T) FILE asme-expansion-table.dat COLUMNS 1 2 INTERPOLATION $1
# B is the mean coefficient of thermal expansion x 10^-6 (mm/mm/ºC) in going
# from 20ºC to indicated temperature
FUNCTION B(T) FILE asme-expansion-table.dat COLUMNS 1 3 INTERPOLATION $1
# C is the linear thermal expansion (mm/m) in going from 20ºC
# to indicated temperature
FUNCTION C(T) FILE asme-expansion-table.dat COLUMNS 1 4 INTERPOLATION $1

VAR T'                   # dummy variable for integration
T0 = 20                  # reference temperature
T_min = vecmin(vec_A_T)  # smallest argument of function A(T)
T_max = vecmax(vec_A_T)  # largest argument of function A(T)

# compute one column from another one
A_fromC(T) := 1e3*derivative(C(T'), T', T)

B_fromA(T) := integral(A(T'), T', T0, T)/(T-T0)
B_fromC(T) := 1e3*C(T)/(T-T0)   # C is in mm/m, hence the 1e3

C_fromA(T) := 1e-3*integral(A(T'), T', T0, T)

# write interpolated results
PRINT_FUNCTION A A_fromC   B B_fromA B_fromC   C C_fromA MIN T_min+1 MAX T_max-1 STEP 1
#> ![Column $A(T)$ from $C(T)$](asme-expansion-A.svg){width=100%}
#> ![Column $B(T)$ from $A(T)$ and $C(T)$](asme-expansion-B.svg){width=100%}
#> ![Column $C(T)$ from $A(T)$](asme-expansion-C.svg){width=100%}
#>
#> The conclusion (see
#> [this](https://www.linkedin.com/pulse/accuracy-thermal-expansion-properties-asme-bpv-code-angus-ramsay/),
#> [this](https://www.seamplex.com/docs/SP-WA-17-TN-F38B-A.pdf) and
#> [this](https://www.linkedin.com/pulse/ansys-potential-issue-thermal-expansion-calculations-angus-ramsay/) reports)
#> is that values rounded to only one decimal value as presented in the ASME code
#> section II subsection D tables are not enough to satisfy the mathematical relationships
#> between the physical magnitudes related to thermal expansion properties of the materials listed.
#> Therefore, care has to be taken as which of the three columns is chosen when using the data
#> for actual thermo-mechanical numerical computations.
#> As an exercise, the reader is encouraged to try different interpolation algorithms to
#> see how the results change. _Spoiler alert_: they are also highly sensible to the interpolation method used
#> to “fill in” the gaps between the table values.
