]>
tutorial14
In this tutorial we introduce the external functions concept that can handle and execute
functions in external libraries. The daeScalarExternalFunction-derived external function
object is used to calculate the heat transferred and to interpolate a set of values
using the scipy.interpolate.interp1d object.
In this example we use the same model as in the tutorial 5 with few additional equations.
The simulation output should show the following messages at the end of simulation:
.. code-block:: none
...
scipy.interp1d statistics:
interp1d called 1703 times (cache value used 770 times)
The plot of the 'Heat_ext' variable:
.. image:: _static/tutorial14-results.png
:width: 500px
The plot of the 'Value_interp' variable:
.. image:: _static/tutorial14-results2.png
:width: 500px
$\mathit{tutorial14}$
m
Mass of the copper plate
$\mathit{m}$
1
$\mathit{kg}$
c_p
Specific heat capacity of the plate
${\mathit{c}}_{\mathit{p}}$
1
-1
-1
$\mathit{J}{\mathit{K}}^{-1}{\mathit{kg}}^{-1}$
α
Heat transfer coefficient
$\mathit{\alpha}$
-1
1
-2
$\mathit{W}{\mathit{K}}^{-1}{\mathit{m}}^{-2}$
A
Area of the plate
$\mathit{A}$
2
${\mathit{m}}^{2}$
T_surr
Temperature of the surroundings
${\mathit{T}}_{\mathit{surr}}$
1
$\mathit{K}$
Q_in
Power of the heater
${\mathit{Q}}_{\mathit{in}}$
power_t
T
Temperature of the plate
$\mathit{T}$
temperature_t
Heat
Heat transferred
$\mathit{Heat}$
power_t
Heat_ext
Heat transferred calculated using an external function
${\mathit{Heat}}_{\mathit{ext}}$
power_t
Value
Simple value
$\mathit{Value}$
time_t
Value_interp
Simple value calculated using an external function that wraps scipy.interp1d
${\mathit{Value}}_{\mathit{interp}}$
time_t
HeatBalance
Integral heat balance equation
$\mathit{HeatBalance}$
eImplicitODE
$${ \left( { \left( { \left( { { m } \cdot { c_p } } \right) \cdot \left( { { \partial { { \left( { T } \right) } } } \over { \partial { t } } } \right) } \right) - { Q_in } } \right) + \left( { \left( { { \alpha } \cdot { A } } \right) \cdot \left( { { T } - { T_surr } } \right) } \right) } = 0$$
Heat
$\mathit{Heat}$
eImplicitODE
$${ { Heat } - \left( { \left( { { m } \cdot { c_p } } \right) \cdot \left( { { \partial { { \left( { T } \right) } } } \over { \partial { t } } } \right) } \right) } = 0$$
Heat_ext
${\mathit{Heat}}_{\mathit{ext}}$
eAlgebraic
$${ { Heat_ext } - \left( { Heat \left( cp = { { c_p } } , dT = { { { \partial { { \left( { T } \right) } } } \over { \partial { t } } } } , m = { { m } } \right) } \right) } = 0$$
Value
$\mathit{Value}$
eAlgebraic
$${ { Value } - \left( { {2 {}} \cdot \left( { {\tau} } \right) } \right) } = 0$$
Value_interp
${\mathit{Value}}_{\mathit{interp}}$
eAlgebraic
$${ { Value_interp } - \left( { interp1d \left( t = { { {\tau} } } \right) } \right) } = 0$$
Regulator
$\mathit{Regulator}$
eSTN
Heating
$\mathit{Heating}$
Q_in
The heater is on
${\mathit{Q}}_{\mathit{in}}$
eAlgebraic
$${ { Q_in } - {1500 {{W}}}} = 0$$
OnConditionActions_0
${\mathit{OnConditionActions}}_{\mathit{0}}$
eGT
$\mathit{T}$
T
1
340
$\mathit{T}>340\mathit{K}$
0
actionChangeState_Cooling
${\mathit{actionChangeState}}_{\mathit{Cooling}}$
eChangeState
$\mathit{Regulator}$
Regulator
$\mathit{Regulator}.\mathit{Cooling}$
Regulator.Cooling
OnConditionActions_1
${\mathit{OnConditionActions}}_{\mathit{1}}$
eGT
time
1
350
$\mathit{\tau}>350\mathit{s}$
0
actionChangeState_HeaterOff
${\mathit{actionChangeState}}_{\mathit{HeaterOff}}$
eChangeState
$\mathit{Regulator}$
Regulator
$\mathit{Regulator}.\mathit{HeaterOff}$
Regulator.HeaterOff
$\mathit{Regulator}$
Regulator
Cooling
$\mathit{Cooling}$
Q_in
The heater is off
${\mathit{Q}}_{\mathit{in}}$
eAlgebraic
$${ Q_in } = 0$$
OnConditionActions_0
${\mathit{OnConditionActions}}_{\mathit{0}}$
eLT
$\mathit{T}$
T
1
320
$\mathit{T}<320\mathit{K}$
0
actionChangeState_Heating
${\mathit{actionChangeState}}_{\mathit{Heating}}$
eChangeState
$\mathit{Regulator}$
Regulator
$\mathit{Regulator}.\mathit{Heating}$
Regulator.Heating
OnConditionActions_1
${\mathit{OnConditionActions}}_{\mathit{1}}$
eGT
time
1
350
$\mathit{\tau}>350\mathit{s}$
0
actionChangeState_HeaterOff
${\mathit{actionChangeState}}_{\mathit{HeaterOff}}$
eChangeState
$\mathit{Regulator}$
Regulator
$\mathit{Regulator}.\mathit{HeaterOff}$
Regulator.HeaterOff
$\mathit{Regulator}$
Regulator
HeaterOff
$\mathit{HeaterOff}$
Q_in
The heater is off
${\mathit{Q}}_{\mathit{in}}$
eAlgebraic
$${ Q_in } = 0$$
$\mathit{Regulator}$
Regulator
NULL