Conversation
Math.Nonlinear.quadratureNewtonCotes (new in 4.2) evaluates its function
argument in an array constructor with an iterator:
y:={f(x[k]) for k in 1:n + 1};
OpenModelica 1.27.1 generates C code that does not compile for this
(undeclared metatype_array), so neither the example
Math.Nonlinear.Examples.MovingIntegral nor any other model using the
function builds. Evaluate the integrand in a for-loop instead.
With this change, MovingIntegral simulates in OpenModelica and all six
quadrature orders agree with the analytical flux linkage. OCT (Modelon
Impact) gives identical results for both forms.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UmNZkRw6HV9CeBvNk36AzT
|
@hubertus65 I'd recommend to validate results you got from an AI manually with Natural Intelligence. |
|
Same argument again. The question is what we want to achieve with the Standard Library: make it work for as many tools as possible, or make it a gate by using as many features of the Modelica language as possible. FWIW: I also filed a bug report for Modelon Impact. That doesn't mean that a rewrite that works on more tools is isn't useful. I also have made similar changes that make models work in OpenModelica. And regarding speed: there is no measurable difference. The real industry value of Modelica is the cross- tool compatibility of the libraries. Without it, the Dyad language and tool would be just as good. In Modelica we need to do the best to make use of that advantage. |
|
@hubertus65 You didn't even read my comment. Furthermore: |
On the other hand, there is also the argument that Modelica must keep developing, and focusing on the common denominator of all tools (in MSL) is likely to stop that and also progress down-stream to other libraries As far as I know the strategy we have used so far:
|
|
@HansOlsson, I agree with your principles we have applied, and did this exactly in accordance with that. I agree to those principles. FWIW: I have always tested these PR's with released versions OpenModelica, Dymola and Modelon Impact, (with the exception of Dymola lately because my normal laptop is away for repairs) |
|
Thinking more, to me the main benefit of (You can, of course, use implicit loop-indices, but we generally don't use that in MSL - and some might argue that it is too magic.) |
There was a problem hiding this comment.
Thinking more, to me the main benefit of y:={f(x[k]) for k in 1:n + 1}; isn't performance, but readability.
I agree with that. @AHaumer an iterator is an iterator, one never knows what kind of tricks the backend can apply behind the scene. In fact, I think the generated code could eventually be exactly the same with both formulations.
As in the previous case, I think it's best if OpenModelica is improved to also handle this case, which is perfectly legal Modelica. Please open a ticket about that on the OpenModelica issue tracker.
|
@casella I checked with Dymola, OpenModelica and Wolfram System Modeler. |
Modelica.Math.Nonlinear.quadratureNewtonCotes, new in MSL 4.2, evaluates its function argument in an array constructor with an iterator:OpenModelica 1.27.1 generates C code for this that does not compile:
As a result, no model that uses the function builds in OpenModelica. That includes the MSL's own example
Modelica.Math.Nonlinear.Examples.MovingIntegral.This PR evaluates the integrand in a for-loop instead:
Verification
Math.Nonlinear.Examples.MovingIntegralpsi1…psi6= 0.65450 agree with the analyticalpsi0(Boole's rulepsi4within 2e-5)Math.TestQuadrature(all degreesd = 1…6, exact for polynomials)3u² + sin(u),d = 1and4The OCT rows used local copies of the function, because Impact ships MSL 4.1.0, which does not contain it yet.
🤖 Generated with Claude Code
https://claude.ai/code/session_01UmNZkRw6HV9CeBvNk36AzT