Media properties and component encapsulation in MTK

Hi,

Modelica has a Media library that captures the properties of various materials. It implements the equations given in IF97 (a version of was apparently implemented in Julia). It provides e.g. calculation of the Cp, Cv from temperature and pressure.

What’s the best practice to implement something similar in MTK (e.g. as part of a ThermalFluid library)?

In particular:

  • How do you define the “type” of a component? i.e. I’d like to have a Mediumabstract type” with properties Cp, Cv, ‘ρ’ etc. with “concrete” components such as Water and Oil implementing it (sure, I can document what a “Medium” is required to provide, but I’d like MTK to enforce these interfaces)
  • IF97 is rather complex, with dozens of parameters, which are of little interest to most using it. We could implement IF97 fully as part of MTK, but using that model would import all those parameters and equations to the system using it. I think it makes sense for sub-systems to be (optionally) “black-boxes”, without all of their “internals” exposed.

DD

1 Like

Hi,

I use CoolProp (low level interace) with MTK.
It requires some interfacing and it has some limitations (it is not thread safe).
I had to map functions with their derivatives and declare them to work with ForwardDiff.
I hope that Clapeyron will be able to replace CoolProp sooner or later. I think it would require less interfacing.

The components of the fluid (and the thermodynamic model) are declared when the MTK component are instantiated.

About your second point, the macro ModelingToolkit.@register allows to keep functions as black-boxes in the equation system.

1 Like