2015-12-02 81 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;