-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
State functions do not seem to work properly #93
Comments
Hi, here is the model, it uses R290 from external media
since the function "specificEnthalpy" uses "setState_ps" I get an error
defining the input variables h_inlet and p1 as constants leads to no problems, but is unlikely to happen in my simulations. Thanks in advance for any answer |
Dymola and probably other tools can not calculate the derivatives of functions that use records as input or output. |
This approach is what I am using - the problem is (for me) in the internals of the function - in my example, I do not use the setState_ps function - but the function "specificEnthalpy_ps" (and "isentropicEnthalpy") does use it:
It's not like I am calling the derivative of the record - I am calling the derivative of just the enthalpy function basically ("Medium_ref.specificEnthalpy_ps") - but the solver itself calls the derivative of the state record I have partially solved this issue with using a numerical kind of derivative for the enthalpy
but this creates issues with model stability and simulation time due to the sampling. Thanks in advance for any answer, |
Quick link to the code in question for specificEnthalpy_ps function: ExternalMedia/Modelica/ExternalMedia/Media/BaseClasses/ExternalTwoPhaseMedium.mo Lines 771 to 784 in 8f5df11
You want to achieve two things for good speed: derivatives and caching, and you have the annotations Inline or LateInline and derivative to do it. The caching is achieved by collecting all setState_ps function calls with identical input (you need inlining to move it to equation section). The trick that is missing currently: specificEnthalpy_ps should not use Inline, it should use LateInline instead, and you need the derivative annotation. That should tell the tool to first find and use the derivative, and then afterwards do the inlining to get caching and good speed. The above is at least true for Dymola and pure Modelica code, it might be different with OpenModelica and external code (maybe CoolPRop does some kind of caching??). |
There are variants to achieve the same, and looking at density_ph, it seem that ExternalMedia is using a different approach than what I descriebed: ExternalMedia/Modelica/ExternalMedia/Media/BaseClasses/ExternalTwoPhaseMedium.mo Lines 392 to 430 in 8f5df11
It is quite some effort to test whether caching works as expected, probably need to generate flat Modelica output, and also do some benchmarking. After that, the same approach can be used on all functions. |
I created a simple model using a derivative of the result of the density_ph and it seems that it works fine. So basically, I create a function "specificEnthalpy_ps_der" calculating the total derivative (using partialDeriv_state probably?) and add the derivative annotation to the "xxx_state" function(s). Thanks for your answers truly, I'm a newbie in this part of Modelica. Pavel |
Hi,
I am quite new with Modelica, but when I am trying to simulate the CoolProp models, Dymola gives an error about not being able to find a function.
This is the error message I get when trying the run the standard example ExternalMedia.Test.CoolProp.Pentane.Pentane_hs, delivered with the ExternalMedia package.
The other example ExternalMedia.Test.CoolProp.Pentane.Pentane_hs_state does work however.
I get a similar error when making use of media described in Coolprop in another model (heat exchanger), such as ExternalMedia.Examples.CO2CoolProp or any other media described for that matter.
I suppose that Dymola is looking for this function that is nowhere defined (with the addition Unique35 or Unique25 that is).
The text was updated successfully, but these errors were encountered: