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

Inheritance with data value redefinition [fritz,p.65]

Inheritance with data value redefinition [fritz,p.65]

I found some strange case in Fritz tutorial, page 65:

slide: Inheriting definitions

Code:

record ColorData

    parameter Real red = 0.2;
    parameter Real blue = 0.6;
    Real green;
end ColorData;

class ErrorColor
    extends ColorData;
    parameter Real blue = 0.6;
    parameter Real red = 0.3;   // this line strangly marked as error due to _value_ redefenition
equation
    red + blue + green = 1;
end ErrorColor;

Isn't inheritance must garantee this case as inherited class behavior extension ?

Re: Inheritance with data value redefinition [fritz,p.65]

For example I use some basic nozzle model with some parameter R with typical value 0.1,
but extends it with new model of same nozzle with new value R=0.05

Re: Inheritance with data value redefinition [fritz,p.65]

If you have multiple elements with the same name that come from the local scope and the extends scope the have to be *identical* which is not the case in this particular example. The correct way to deal with changes is via modifications on the extends clause:

Code:


record ColorData
    parameter Real red = 0.2;
    parameter Real blue = 0.6;
    Real green;
end ColorData;

class ErrorColor
    extends ColorData(red=0.3, blue = 0.12);
equation
    red + blue + green = 1;
end ErrorColor;

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