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

Persisting modification after redeclaration

Persisting modification after redeclaration

In http://book.xogeny.com/components/archi … placeable/ , in the subsection "Modifications", it is said that if I want modifications to a component not to persist in subsequent redeclarations, I need to put the modifications behind the variable name. This is my test package:

--

within ;

package testpackage
    model firstOrder "simple decay with fixed half-life"
            parameter Real initial_x= 1.0;
            Real x;
        initial equation
            x= initial_x;
        equation
            der(x) = -x;
    end firstOrder;
   
    model firstOrder_hl "decay with half-life parameter"
            parameter Real hl= 2;
            parameter Real initial_x= 1.0;
            Real a;
            Real x;
   
        initial equation
            x= initial_x;
        equation
            Modelica.Constants.e ^ (-a * hl) = 0.5;
            der(x)= -a*x;
    end firstOrder_hl;
   
    model myModel "package with a replaceable model"
        replaceable firstOrder_hl subModel(hl=3, initial_x=2);
    end myModel;
   
    model myModel_2 "derived model in which submodel is redeclared" // <-- PROBLEM HERE
        extends myModel(redeclare firstOrder subModel(initial_x=2));
    end myModel_2;

end testpackage;

--

Why can I simulate myModel without errors but NOT myModel_2? I see this error:

[1] 20:10:09 Translation Error
[testpackage: 27:3-27:56]: Variable subModel: In modifier (hl = 3), class or component hl not found in <testpackage.firstOrder$subModel>.

To my understanding, this could mean that the modification did in fact persist although I did not want this.
Am I doing something wrong here?

Edited by: dafred - Dec-23-18 21:54:29
There are 0 guests and 0 other users also viewing this topic
You are here: