Can ModelingToolkit be used for simulating fluid flow including fluid properties?

Hi all,

I am huge fan of Julia, and I used it for my Master’s thesis where I made a large dynamic model of a two-stage heat pump, including all of the fluid properties (via CoolProp.jl), such as: Temperature, pressure, enthalpy, density and so on. I did these simulations using DifferentialEquations.jl. I made a large function to get all of the derivatives, and for all the components of the heat pump I made subfunctions within the main function. It worked OK, but there was a natural limit to how coupled the system could be with this ‘line-by-line’ kind of coding.

At some point I tried to see if I could make ModelingToolkit do what I wanted in fluid flow with fluid properties, but I was unsuccessful at this. I attempted to write reusable functions for the heat pump components. I struggled with making the connectivity work. When compared to electric circuits (the tutorial from Chris Rackauckas) fluid flow is more complex, since it always has at least 3 properties at each point: A mass flow rate, and two independent properties (such as temperature and pressure). It can even be more complex if we are talking about a mixture of chemical species, where the concentration of each species would also need their own equations.

Is there anyway to use ModelingToolkit for these kind of simulations? Help is highly appreciated, since I would love to start using the acausal feature of this package. :slight_smile:

Juliahub has an HVAC Library for MTK, you find a tutorial available here


Thank you for your answer and for the link! :slight_smile:

From the video I cannot see how they built the internals of their component models.
That was my original question: How to set up connectivity for 3 or more ‘flow properties’.
So this video does not really answer my challenge.
Other than that, I always had the impression that JuliaHub will be paid software, since on their webpage it says ‘pricing’.
While I would probably be able to afford buying this kind of software, I was hoping that somebody would be able/willing to share such ideas with me, so that I would be able to construct models using ModelingToolkit.jl, and was not forced to obtain a license for proprietary software built on top of Julia itself.
Afterall, one of the things I like about Julia is that it is open.

I hope that somebody are able/willing to help me make these kinds of models using ModelingToolkit. :slight_smile:

You are correct, the HVAC.jl library is proprietary, but it’s available license free for academic users. JuliaHub, which is developing both ModelingToolkit and the HVAC library for ModelingToolkit (together with MERL), specializes in building model libraries that are highly nontrivial to implement, require domain expertise and include patented technology. Simpler model components and libraries that are completely free and open source are also contributed by JuliaHub to ModelingToolkitStandardLibrary.jl.

Proprietary products are not for everybody and that is fine, but these particular proprietary products are part of what is funding the development of ModelingToolkit, which itself is an enormous effort.

If you want to build an HVAC library yourself I do not want to discourage you, in that case you may take HVAC.jl simply as a proof of a positive answer to your question

1 Like

Thank you for making me aware of ModelingToolkitStandardLibrary.jl, I think this package can be a great help for me. :slight_smile: I will try to see if I can make more progress on my own.
I appreciate the work being put into these packages. :slight_smile:

I have been looking around in ModelingToolkitStandardLibrary.jl and I have to say that I’m sorry for my ‘harsh’ words above. I can see that you guys are contributing a huge amount of work/code and I’m really grateful for this.

That said, the company I currently work at is a potential customer at JuliaSim in the future. We are eagerly awaiting your progress. At my company we have experts in Modelica who like to build and extend their own models. If we should choose to convert our models to ModelingToolkit/JuliaSim I think it is important that we can still build and extend our own models, along with the existing ones. I hope that this will be possible?

1 Like

No worries, certainly no offense taken :slight_smile:

ModelingToolkit and the standard library are and will always continue to be fully open and extensible by any and all users. Being able to implement your own component and model libraries are key features, both to the ModelingToolkit effort and the JuliaSim that builds on top of it.

An HVAC library in particular happens to be a rather “advanced” model library, in particular if you intend to model fluids that change phases and flows that contain two phases mixed etc. This is part of why JuliaHub is developing a commercial library in this domain, but this does not preclude any user from implementing a similar library themselves :slight_smile: