Skip to content
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

Illegal call to zeros with negative argument #49

Open
maltelenz opened this issue Oct 4, 2022 · 2 comments
Open

Illegal call to zeros with negative argument #49

maltelenz opened this issue Oct 4, 2022 · 2 comments

Comments

@maltelenz
Copy link

The call to zeros(n_q - 1) here:

(zr_q, zx_q) := z_matrix(n_q, x_q, xsig_s, r_s, zeros(n_q-1), xsig_rq, r_rq);

seems to come down to zeros(-1), if we resolve n_q:
final parameter Integer n_q=size(xsig_rq,1);

parameter SIpu.Reactance[:] xsig_rq=fill(0,0)

giving the expression zeros(size(fill(0, 0), 1) - 1) ==> zeros(-1), which is illegal (all arguments to zeros need to be >=0), or am I missing something?

@rfranke
Copy link
Collaborator

rfranke commented Mar 21, 2023

Just checked with OpenModelica. It generates code with zeros(0), i.e. silently corrects this during model translation. The called function doesn't use the array for n < 2.

function z_fromEqCirc "Calculates impedance matrix z from equivalent circuit"
  extends Modelica.Icons.Function;
  input Integer n "transient order";
...
  input SIpu.Reactance[n-1] xm2_n(each unit="1") "coupling reactance";
...
  output SIpu.Reactance[n+1,n+1] zx(each unit="1")  "impedance matrix reactive";

algorithm 
...
    for k in 2:n loop
      zx[1:k,1:k] := zx[1:k,1:k] + fill(xm2_n[k-1], k, k);
    end for;
...
end z_fromEqCirc;

@maltelenz
Copy link
Author

It is explicitly illegal: https://specification.modelica.org/maint/3.6/arrays.html#modelica:zeros

Wolfram System Modeler will reject models with such illegal uses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants