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
TwoPhase_setState fails on Openmodelica 1.18 #48
Comments
I suspect that it shouldn't really have worked before my change either, it looks like we generate code that's using uninitialized variables so the behaviour is undefined. The actual issue looks to be that OM drops the modifiers on record R
Real x;
Real y;
end R;
function f
input Real x;
output Real y = r.x;
protected
R r(x = x);
end f;
model M
Real x = f(time);
end M; I get: function R "Automatically generated record constructor for R"
input Real x;
input Real y;
output R res;
end R;
function f
input Real x;
output Real y = r.x;
protected R r;
end f;
class M
Real x = f(time);
end M; As you can see the modifiers on function f
input Real x;
output Real y = x;
protected R r = R(x, <EMPTY(scope: <global scope>, name: y, ty: Real)>);
end f; I.e. it generates a record constructor call to initialise The old frontend doesn't work at all with HelmholtzMedia so I can't check if it simulates with it, but it seems very likely that this is the issue. So l'll try to implement something similar for our new frontend and see if that fixes it. |
After wasting some time implementing my proposal I realized it wasn't actually needed and we already do handle the modifiers, and the issue is actually my previous changes like you said. The issue is that |
- Take the modifiers on local record instances into account too when computing the dependencies between local function variables. Fixes thorade/HelmholtzMedia#48
The issue should be fixed once my PR has been merged, the model now simulates successfully at least. |
- Take the modifiers on local record instances into account too when computing the dependencies between local function variables. Fixes thorade/HelmholtzMedia#48
Thanks @bilderbuchi and @perost for the analysis. If any changes in the library are needed afterwards, I am also happy to try that. I think I tried to change this part before, and then it started to fail in another tool, but I can try again if needed. |
The report looks good, a few more models simulate and nothing broke (just some unstable models). The remaining models that don't simulate all fail with similar errors to this issue, so there might still be some issue with how we initialise variables. All the models that broke due to my earlier commit all work now though. |
Thanks! I think this can be closed now. |
Very nice, thank you! |
Sorry to disappoint, but I iiuc the earlier commit (or at least one in that changeset) broke HelmholtzMedia.Examples.ConvergenceTest.SinglePhase_setState_psine_Tramp and HelmholtzMedia.Examples.ConvergenceTest.TwoPhase_setState which are still failing. |
They show up as working for me, but I had to manually refresh the page with F5 for some reason. Maybe you're having the same issue. There should be 5 models still failing during simulation. |
exactly, and those two are 2 of these 5 from what I see (after even Ctrl-F5). They dropped from simulate->compile in the earlier commit. I'm confused now? |
The ones I see that are still failing are:
The simulation log for SinglePhase_setState_psine_Tramp shows some limits being violated (though it seems to just be due to floating point precision issues) but the simulation is successful in the end. TwoPhase_setState on the other hand simulates without any warnings. |
|
We've encountered a bug that is also present in HelmholtzMedia.Examples.ConvergenceTest.TwoPhase_setState. See also #39, but I didn't want to pollute that one with details.
TwoPhase_setState fails in Openmodelica 1.18 (NF) on Windows 10 using either current HelmHoltzMedia master (18ff552) and MSL 3.2.3 or current msl4update (20bd884) and MSL 4.0.0
The error also happens on the OM 1.18 test server (also currently on the OM master):
The test regressed at this point (also cited by @thorade in #39), and I suspect that this OM commit by @perost could be connected/the cause (old trac issue related to that).
The Modelica Specification issue modelica/ModelicaSpecification#2757 is probably connected but does not seem close to resolution.
Now, why all this exposition?
The error seems to occur, as far as we can tell, in
HelmholtzMedia.Interfaces.PartialHelmholtzMedium.setState_pd
, becausef.delta
is NaN, withdelta
becoming NaN here during record constructions because it seems to see ad_crit
of 0.d_crit
maybe ends up being 0 a little above whenMM
is 0 here.I'm not sure if those 0s occur because something is off in the ordering of binding equations when the function is evaluated, so a default/uninitialized value of 0.0 is used (hence the suspicion of OpenModelica/OpenModelica@14d191b423 above), or because something wonky happens when looking up
fluidConstants[1].molarMass
.In any case, the minimal workaround that makes this test (and our internal model) work is to delay the assignment of
f.delta
:This strengthens my suspicion that the ordering of operations could be off in OM.
Questions/remarks:
The text was updated successfully, but these errors were encountered: