OpenModelica / OMMatlab

Matlab scripting OpenModelica interface
12 stars 4 forks source link

Linearization Bug #10

Closed crazy734 closed 3 years ago

crazy734 commented 3 years ago

Hey,

There's a minor issue in the linearization function that I may have noticed in line 757. The isempty function does not work if the fields of the struct are empty, i.e. even if it is a 1X1 struct with no fieldnames as well, the ~isempty(matrix_name) returns a 1.

if(~isempty(matrix_name)) fields=fieldnames(matrix_name);

I also found the solution by changing it to

if(~isempty(fieldnames(matrix_name))) fields=fieldnames(matrix_name);

kabdelhak commented 3 years ago

What file are you referring to with line 757? And can you provide an example that currently does not work?

arun3688 commented 3 years ago

@kabdelhak i think this is not related to openmodelica code generation for linearization, it is related to OMMatlab.m stand alone linearization API

crazy734 commented 3 years ago

Thank you @arun3688 . It is an OMMatlab.m linearization API within the file itself @kabdelhak . It needs to changed as I mentioned above. However, since you asked for an example of it not working, I'll give you one below.

image

This only happens because matrix_name in the second iteration of the loop is empty and the isempty function directly does not work on empty struct. On the second iteration, fieldnames of the struct are empty and not the struct itself. Therefore this edit is required.

arun3688 commented 3 years ago

@crazy734 , can you make a PR with the changes you made ?, i can push it

casella commented 3 years ago

As a side note, shouldn't we avoid to have code to do this in two different places? Or do I miss something?

arun3688 commented 3 years ago

@casella this is a stand alone package, the current code generation has nothing to do with this

casella commented 3 years ago

OK, so I guess we just need to be careful to keep them in synch

arun3688 commented 3 years ago

this is fixed with https://github.com/OpenModelica/OMMatlab/commit/c9b6fff88efc7c1a6b4652ab978fc1c32636078d