Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)

Forgot password? | Forgot username? | Register

Type mismatch error when using "cat" function

Type mismatch error when using "cat" function


I'm getting an Type mismatch error in OpenModelica 1.8.0 (r10230) when I try to set an array parameter of a partial model from another array parameter of an extending model created with cat function.

Although there might be simpler codes producing the same error, I've keep some parts of the code in order to show up some peculiarities. The code is:

type MyType = enumeration(divisionType1,divisionType2);

partial model myPartialModel
  parameter Integer n (min = 1) = 2;
  parameter MyType myDivision = MyType.divisionType1;
  parameter Modelica.SIunits.Length[n] x;
  parameter Modelica.SIunits.Length[n] y;
  Modelica.SIunits.Area[n] z;
  for i in 1:n loop
    z[i] = x[i] * y[i];
  end for;
end myPartialModel;

model myExtendingModel
  parameter Modelica.SIunits.Length a;
  parameter Modelica.SIunits.Length b;

  final parameter Modelica.SIunits.Length[n] aDivisions = if n == 1 then {a} else fill(a/n, n);
  final parameter Modelica.SIunits.Length[n] bDivisions = if n == 1 then {b}
                                                                                                       elseif myDivision == divisionType1 then
                                                                                                                  cat(1, {b/(n-1)/2}, fill(b/(n-1), n-2), {b/(n-1)/2})
                                                                                                       else fill(b/n, n);
  extends myPartialModel(final x = aDivisions,
                         final y = bDivisions);

end myExtendingModel;

The error I get when checking the model is the following:

[/home/.../] Error: Type mismatch in modifier of component y, declared type .Modelica.SIunits.Length[n], got modifier bDivisions of type #NOTYPE#
Error: Error occured while flattening model myExtendingModel

I think the error is related with the cat function because the aDimensions doesn't through any errors.
The same code works if I only use the fill function.
The if statement works properly.

I've also programmed a myConcatenate function with its input and output declared as Modelica.SIunits.Length and used it instead of the cat function, but I get the same error. The function is the following:

function myConcatenate
    input SI.Length[:,:] array;
    output SI.Length[arrayLength] newArray;
    Integer arrayLength := sum(size(lengthsArray,2));
    Integer aux := 1;
    for i in 1:size(array,1) loop
      for j in 1:size(array(i),1) loop
        newArray[aux] := array(i,j);
        aux := aux +1;
      end for;
    end for;
  end myConcatenate;

It seems to me that the type is lost when using both cat and myConcatenate functions, but it is kept when using fill, so I don't think this is the desired behavior of OM.

Any help would be very appreciated.

Thank you in advance,


Re: Type mismatch error when using "cat" function

Hi Javier,

I have fixed the issues with the cat operator in revision 10258, so your model works now with some slight modifications. The usage of divisionType1 in the modifier of bDivisions is illegal, you need to prefix it with the enumeration type name, i.e. MyType.divisionType1. Besides this it should work fine.

There are still some issues left though, since the compiler seems to give the same error if it fails on anything when evaluating the binding of aDivisions or bDivisions (such as not finding divisionType1). This will only give the wrong error message though, and correct code should still work.

Re: Type mismatch error when using "cat" function

Hi perost,

Thank you for fixing that. Regarding the MyType prefix, it was a copy&Paste error, it was correct in my real code.

However, I'm afraid there is still a problem related with the #NOTYPE# message, perhaps is related to what you're saying in your last paragraph, but I thing it is again a (different?) bug, not only the message itself.

This code is not working and I think it should:
type MyType = enumeration(divisionType1 , divisionType2 );

partial model myPartialModel
  parameter Integer m(min = 1) = 2;
  input Modelica.SIunits.Volume[n] v;
end myPartialModel;

partial model mySecondPartialModel
  parameter Integer n(min = 1) = 3;
  parameter MyType myDivision = MyType.divisionType1;
  extends myPartialModel(final m = n - 1, final v = z);
  parameter Modelica.SIunits.Length[n] x;
  parameter Modelica.SIunits.Area[n] y;
  parameter Modelica.SIunits.Volume[n] z;
end mySecondPartialModel;

model myExtendingModel
  parameter Modelica.SIunits.Length a = 1;
  parameter Modelica.SIunits.Length b = 1;
  final parameter Modelica.SIunits.Length c = a * a;
  final parameter Modelica.SIunits.Area[n] areas = fill(c / n, n);
  final parameter Modelica.SIunits.Length[n] lengths = if n == 1 then {b} elseif myDivision == MyType.divisionType1 then cat(1, {b / (n - 1) / 2}, fill(b / (n - 1), n - 2), {b / (n - 1) / 2}) else fill(b / n, n);
  final parameter Modelica.SIunits.Volume[n] volumes = array(areas[i] * lengths[i] for i in 1:n);
  extends mySecondPartialModel(final x = lengths, final y = areas, final z = volumes);
end myExtendingModel;
Now, the "cat" is working (I've left the previous code regarding it), but I get the following message when I check the model:

Check of myExtendingModel completed successfully.

[/home/.../] Error: Type mismatch in modifier of component z, declared type .Modelica.SIunits.Volume[n], got modifier volumes of type #NOTYPE#

Class myExtendingModel has 0 equation(s) and 0 variable(s).
0 of these are trivial equation(s).
class myExtendingModel
  parameter Integer n(min = 1) = 3;
  parameter enumeration(divisionType1, divisionType2) myDivision = MyType.divisionType1;
  parameter Integer m(min = 1) = n + -1;
  input Real v[1](quantity = "Volume", unit = "m3") = z[1];
  input Real v[2](quantity = "Volume", unit = "m3") = z[2];
  input Real v[3](quantity = "Volume", unit = "m3") = z[3];
  parameter Real x[1](quantity = "Length", unit = "m") = lengths[1];
  parameter Real x[2](quantity = "Length", unit = "m") = lengths[2];
  parameter Real x[3](quantity = "Length", unit = "m") = lengths[3];
  parameter Real y[1](quantity = "Area", unit = "m2") = areas[1];
  parameter Real y[2](quantity = "Area", unit = "m2") = areas[2];
  parameter Real y[3](quantity = "Area", unit = "m2") = areas[3];
  parameter Real z[1](quantity = "Volume", unit = "m3") = volumes[1];
  parameter Real z[2](quantity = "Volume", unit = "m3") = volumes[2];
  parameter Real z[3](quantity = "Volume", unit = "m3") = volumes[3];
  parameter Real a(quantity = "Length", unit = "m") = 1.0;
  parameter Real b(quantity = "Length", unit = "m") = 1.0;
  final parameter Real lengths[1](quantity = "Length", unit = "m") = if myDivision == MyType.divisionType1 then b / (Real(n + -1) * 2.0) else b / Real(n);
  final parameter Real lengths[2](quantity = "Length", unit = "m") = if myDivision == MyType.divisionType1 then b / Real(n + -1) else b / Real(n);
  final parameter Real lengths[3](quantity = "Length", unit = "m") = if myDivision == MyType.divisionType1 then b / (Real(n + -1) * 2.0) else b / Real(n);
  final parameter Real c(quantity = "Length", unit = "m") = a ^ 2.0;
  final parameter Real areas[1](quantity = "Area", unit = "m2") = c / Real(n);
  final parameter Real areas[2](quantity = "Area", unit = "m2") = c / Real(n);
  final parameter Real areas[3](quantity = "Area", unit = "m2") = c / Real(n);
  final parameter Real volumes[1](quantity = "Volume", unit = "m3") = areas[1] * lengths[1];
  final parameter Real volumes[2](quantity = "Volume", unit = "m3") = areas[2] * lengths[2];
  final parameter Real volumes[3](quantity = "Volume", unit = "m3") = areas[3] * lengths[3];
end myExtendingModel;
[/home/.../] Error: Type mismatch in modifier of component z, declared type .Modelica.SIunits.Volume[n], got modifier volumes of type #NOTYPE#
Warning: Parameter z has neither value nor start value, and is fixed during initialization (fixed=true)
I would be grateful if you could check it and tell me if it's another "bug" or the error is related to something illegal in my code.

Thank you very much for your time,


Re: Type mismatch error when using "cat" function

Hi Javier,

I looked at your model, and I think that you can safely ignore that error message. The model still seems to instantiate properly, and you can even compile and simulate it. I have not investigated it much yet, but what is probably happening is that the compiler fails somewhere and instead tries something else that succeeds. In that case it should not print out an error message, but in this case it does so anyway. I will investigate this further and see if I can get rid of this issue.

Re: Type mismatch error when using "cat" function

I fixed the issue with that model in revision 10291, so when you update your OMC you should not get any errors or warnings for that model anymore.

Re: Type mismatch error when using "cat" function

Thank you, perost!

I've checked it with the last versions and works fine!

Best regards,

There are 0 guests and 0 other users also viewing this topic
You are here: