Comments (6)
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
from externalmedia.
Hi,
I'm having a similar problem. Basically, calling a time derivative of a variable that is connected to setState_xx seem to be unsolvable cause of the DAE index reduction (in my example, the variable in question is "DER") . I've read that you should be able to provide the derivative by including the "derivative" annotation to the problematic function, but I haven't managed to accomplish that.
here is the model, it uses R290 from external media
model Compressor_test_small
replaceable package Medium_ref = R290;
//Medium_ref.ThermodynamicState State_in;
Modelica.Units.SI.SpecificEnthalpy h_inlet;
Modelica.Units.SI.SpecificEnthalpy h_ideal;
Modelica.Units.SI.SpecificEnthalpy h_real;
Modelica.Units.SI.AbsolutePressure p1;
Modelica.Units.SI.AbsolutePressure p2;
Real DER;
Modelica.Units.SI.SpecificEntropy S;
equation
DER=der(h_ideal);
// h_inlet = 400000;
h_inlet = 400000+100*time;
// p1 = 500000+100*time;
p1 = 500000;
p2 = 1500000;
h_real = h_ideal * 1.2;
//h_ideal = 600000;
S = Medium_ref.specificEntropy_ph(p1,h_inlet);
h_ideal = Medium_ref.specificEnthalpy_ps(p2,S);
// h_ideal=Medium_ref.isentropicEnthalpy(p2,State_in);
//State_in = Medium_ref.setState_ph(p1, h_inlet);
end Compressor_test_small;
since the function "specificEnthalpy" uses "setState_ps" I get an error
Failed to differentiate the equation
h_ideal = TESTY.R290.specificEnthalpy_ps_state_Unique7(
1500000.0,
S,
TESTY.R290.setState_ps_Unique9(1500000.0, S, 0));
in order to reduce the DAE index.
Cannot find differentiation function:
TESTY.R290.setState_ps_Unique9(1500000.0, S, 0)
with respect to time
Failed to reduce the DAE index.
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
Pavel
from externalmedia.
Dymola and probably other tools can not calculate the derivatives of functions that use records as input or output.
So this will fail to be differentiated: density(setState_pT(101325, 300))
but this will work to get the time derivative: density_pT(101325, 300)
from externalmedia.
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:
h := specificEnthalpy_ps_state(p=p, s=s, state=setState_ps(p=p, s=s, phase=phase));
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
when sample(2,1) then x = h_in; t = time; approx_der = (x1-x2) / (t-pre(t)); x1=x; x2=pre(x); Flag=1; end when;
but this creates issues with model stability and simulation time due to the sampling.
Thanks in advance for any answer,
Pavel
from externalmedia.
Quick link to the code in question for specificEnthalpy_ps function:
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??).
Also read this SO question&answer: https://stackoverflow.com/q/55019892/874701
from externalmedia.
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:
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.
from externalmedia.
Related Issues (20)
- Incompressible package runs in OpenModelica but not Dymola
- Model fails to execute when using two different fluids
- Model fails to run when using Modelica.Fluid.Sensors.Temperature
- Call ExternalMedia from OMPython HOT 1
- Questions about function calls
- Communication protocol error. Expected 'DONE', received 'calc_transport has the value of 1 HOT 3
- Use CoolProp 6.4.4 as soon as it is released, instead of nightly build HOT 1
- support for older gcc versions HOT 4
- Compilation errors in OpenModelica HOT 7
- Selection of different state variables (ph, pt, dT) for a CoolProp 2-phase medium HOT 1
- Cannot compute arbitrary partial derivatives with function `partialDeriv_state` HOT 2
- Wrong version of cmake required to compile the library HOT 1
- Restructuring of the repository HOT 4
- build error using cmake on windows HOT 1
- Compressible mixture support? HOT 2
- Custom fluid property support
- Incompressible CoolProp tests do not compile HOT 3
- Remove experiment annotation from partial models
- how to use fliudprop in external Media?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from externalmedia.