2015-12-02 40 views
3

我想在模型中设置默认变量名称T(= xx) - 将该模型拖入新模型并定义变量xx。 我收到错误消息:使用未声明的变量xx。Modelica传播/默认变量名称

这是子模型

model test 
    parameter Real T = xx; 
    Real f; 
equation 
    f = T + time; 
end test; 

这是整个模型

model fullmodel 
    parameter Real xx = 12; 
    Test Test1; 
end fullmodel; 

我的问题:你会怎么做,在Modelica的?我需要我的模型100的相同模型,我想设置一些参数(diamter,lenghts等)默认为一个变量名,然后定义这个变量。我知道我可以传播变量 - 但它会很好,如果我只需拖动模型,然后定义参数。感谢您的帮助!

回答

2

或者你可以做到这一点使用内/外:

model Test 
    outer parameter Real xx; 
    parameter Real T = xx; 
    Real f; 
equation 
    f = T + time; 
end Test; 

model fullmodel 
    inner parameter Real xx = 12; 
    Test test1; 
end fullmodel; 
+0

通过这种方式,您不需要在测试中更改任何内容,或者在fullmodel中使用它时添加修饰符, –

+0

我尽可能避免使用“内部”和“外部”关键字。是的,当您拥有多个组件时,您可能觉得不得不将信息传播到层次结构中非常乏味。但根据我的经验,这种基于'inner'和'outer'的方法很快就会退化。问题在于层次结构中的关系是隐含的而非明确的。你的模型会很快退化成一个脆弱的,单一的混乱。关于像这样的唯一合法用例涉及基本假设,您需要级联到所有组件。 –

+0

是的,内/外可能是很好的避免。我猜如果你有100个模型拖放它,使用一些脚本语言自动生成这个大模型可能会更好,然后你可以自动包含修改器。 –

3

你应该能够做一些事情,如:

model test 
    parameter Real T; 
    Real f; 
equation 
    f = T + time; 
end test; 

model fullmodel 
    parameter Real xx = 12; 
    Test Test1(T = xx); 
end fullmodel; 
+0

嘿嘿,谢谢您的回复:如果我那样做,我拖例如100“测试”模式在“fullmodel”中,那么我必须在每个“测试”(T = xx)中定义对吗? – Kenni

+0

不幸的是,是的。 –

2

另一种可能性,如果你有相同的模型和你的多个实例不想重复的修改是这样做的:

model test 
    parameter Real T; 
    parameter Real S=1; 
    Real f; 
equation 
    f = S*(T + time); 
end test; 

model fullmodel 
    parameter Real xx = 12; 
    // Create an "alias" model using a short class definition that 
    // includes a modification (for all instances of PreConfig). 
    model PreConfig = Test1(T=xx); 
    // Now create instances (potentially with their own unique values 
    // for some parameters 
    PreConfig pc1(S=1), pc2(S=2), pc3(S=3); 
end fullmodel; 

作为我在评论中提及上面的fullmodel另一种实现使用数组是这样的:

model fullmodel 
    parameter Integer n = 100; 
    parameter Real xx = 12; 
    // Create 100 instances of Test1. Each on has the same 
    // value for T, but they each have different values for 
    // S 
    Test1 tarray[n](each T=xx, S=linspace(0, 1, n)); 
end fullmodel;