【问题标题】:Save start / initial guess values in OpenModelica & implement initial values from file在 OpenModelica 中保存开始/初始猜测值并从文件中实现初始值
【发布时间】:2019-12-09 10:56:10
【问题描述】:

Dymola 中有一个选项“在模型中保存起始值”,它允许重复使用这些参数来调整模拟。

我在 OpenModelica 中寻找类似的可能性,但到目前为止我无法弄清楚。特别是,我正在使用 ThermoSysPro 构建模型,它对初始值的变化相当敏感。我的模型有几个垂直管道(上游、下游),所以很容易失败。

1.是否可以在 OpenModelica 中保存初始/开始/猜测值?

2。在模型中实现/采用这些值的方法是什么? (假设我有密度 - ρ,焓 - h,温度 - T 等等。只是为了简化 Modelica 新手)

-----更新------

就我而言,我有两种方法来启动/初始值: (ThermoSysPro - TSP)

方法 1 - 通过引入所需的边界条件或接近成功运行的边界条件,在不更改 TSP 中给出的默认起始值​​的情况下运行模拟 1 秒。

收集生成的初始值并将它们添加为起始值(当一个组件有很多时很耗时)。

对于诸如 “volume” 之类的组件或任何其他未离散化的组件,只需在组件的 “Initialization” 部分或“文本视图” 窗口,例如Q(start = 0.3); P(start = xxx)

但对于离散化组件,例如 “管道”,它必须通过 “文本视图” 使用运算符 each 来完成,例如Q(each start = 0.3)。但是,当通过“图表视图”更改组件的任何参数时,运算符“each”会消失,因此必须给出如下:

•   Q(start = {0.3 for i in 1:componentName.Ns+1}) 
•   Q(start = fill(0.3, componentName.Ns+1))
•   Q(start = {x1, x2, x3, x4, … xi})

Ns + 1 - 用于水力节点/Ns - 用于热力节点

问题

P.1.1 - 通常应该写:

Q(start = fill(0.3, Ns+1), fixed = fill(true/false, Ns+1)) 

但这与操作符each 的情况相同,通过“图表视图”更改组件的任何参数后,属性fixed 会自动更改为fixed=false,尽管需要数组。我尝试创建一个布尔参数并使用数组理解,但我总是得到相同的结果。 有什么建议或解决方法吗?

P.1.2 – 在调整生成的起始值而不是使用默认值之后,我看不到模拟的任何改进(加速/更好的结果/或其他)。此外,在调整了太多之后,我开始遇到初始化问题——这应该与我的理解相反。所以,我不确定我应该如何正确使用/声明起始值?也许问题是我没有明确添加fixed = true/false

方法 2 – 使用 Modelica 函数根据边界条件计算起始值。所以首先,我计算多个参数的起始值(通常我计算压力和焓)。例如

parameter Modelica.SIunits.Enthalpy init_enthalpy[Ns+1] = {Modelica.Media.Water.WaterIF97_base.specificEnthalpy_pT(P[i], T) for i in 1:Ns+1}

然后将其添加到特定组件为:

h(start = init_enthalpy)

问题:

P2.1 对于 ThermoPower 库,这种方法非常有效,但是对于 ThermoSysPro,我遇到了困难,因为有很多可以为初始化给出的参数。通常应该给出多少参数,或者如何找到最重要的参数?

P2.2initial equation 部分中声明开始/初始值 和将其计算为parameter(如上)之间有区别吗?

P2.3 指出起始值是fixed=true / false 是不是意味着你在使用所谓的“逆问题”

【问题讨论】:

    标签: modelica openmodelica


    【解决方案1】:

    我不知道是否可以使用自动保存初始值的选项,但通常您可以使用初始方程设置变量的初始值,也可以更改变量的开始属性。如果它是一个状态,则必须将 fixed 属性设置为 true,以便将其考虑进行初始化。

    model test
      Real a(start=10, fixed=true);
      Real b;
    initial equation
      b = 20;
    equation
      der(a) = cos(time);
      der(b) = sin(time);
    end test;
    

    非线性系统的非线性迭代变量和离散变量也需要有起始值。

    【讨论】:

    • 您能解释一下状态变量是什么意思吗? 据我了解,这些变量是由求解器在展平和其他程序之后选择的。如何选择,哪些变量将是状态变量?例如,在动态管道中,哪些(P、T、h、m、ρ ...)可以/应该是状态变量?
    • 井状态是系统中出现差异的变量,例如der(x) 出现在系统中,因此 x 是一个状态。如果您制定约束方程,例如a=b,其中ab 都出现了差异,编译器必须选择哪些状态将被选为状态,哪些被撤销为常规代数变量。这整个过程称为“索引缩减”。但正如我所提到的,只有当你制定这样的约束方程并因此制定一个具有更高微分指数的系统时,这才是必要的。
    • 在大多数情况下,如果不深入了解系统,很难知道它是否包含约束方程。为每个出现差异的变量提供一个起始值是一种很好的做法。在模拟之前,您可以设置模拟标志。在 Simulation -> Simulation Setup -> Translation Flags 中,您会找到 Additional Translation Flags 的字段。将-d=backenddaeinfo 放在那里将输出您系统的简短摘要,-d=backenddaeinfo,stateselection 将另外输出所选状态。那些需要有固定的起始值。
    • openmodelica.org/doc/OpenModelicaUsersGuide/latest/… 在这里您可以找到可以与-d= 一起使用的所有调试标志。如果您不熟悉 DAE 理论,它们中的大多数很难阅读,我会坚持使用 -d=backenddaeinfo 以及该输出中提到的所有标志。
    【解决方案2】:

    P1.1 关于缺少的each 运算符,不幸的是,这是我们正在尝试修复的已知错误。相关票证:

    trac.openmodelica - #5737

    我也交叉链接了这个问题。

    P1.2 起始值并不能真正加速模拟,只是(稍微)初始化。如果您不提供任何内容,编译器只会将它们设置为零并从那里开始。这可能会导致多个问题:

    • 你实际上并没有模拟你认为你会的系统
    • 非线性系统的迭代求解器(牛顿)在初始化期间收敛到错误的解或根本不收敛
    • 意外除以零
    • 不可解析的下约束初始系统

    如果您提供许多初始值,您可能会导致别名冲突或过度约束系统。如果您有一个公式为a=b 并为两者提供起始值,则它们必须相等。您提供的起始值将始终隐藏原始模型中的起始值,但不会导致别名冲突。如果您有冲突,编译器会在选项之间任意选择(一些非常基本的启发式)。

    方法 2 不幸的是,我不是工程师,所以我不知道这是否是正确的方法,但总的来说这似乎没问题。

    P2.1 库中的默认初始值在大多数情况下都很好,如果你想做一些不同的事情,你只需要专门设置它们。例如。锅炉以更高的温度或类似的温度启动。

    如果您想获得完整的信息,请使用:Simulation -> Simulation Setup -> Translation Flags 字段Additional Translation Flags。放:-d=backenddaeinfo,stateselection,discreteinfo,iterationVars

    我为Modelica.Electrical.Analog.Examples.Rectifier 做了这个,这是输出:

    [1] 11:25:25 Symbolic Notification
    Model statistics after passing the front-end and creating the data structures used by the back-end:
     * Number of equations: 128
     * Number of variables: 128
    
    [2] 11:25:25 Translation Notification
    List of all iteration variables (DAE kind: initialization)
    Iteration variables of torn nonlinear equation system:
      IdealDiode6.s:VARIABLE(start = 0.0 unit = "1" protected = true )  "Auxiliary variable for actual position on the ideal diode characteristic" type: Real
      IdealDiode3.s:VARIABLE(start = 0.0 unit = "1" protected = true )  "Auxiliary variable for actual position on the ideal diode characteristic" type: Real
    Iteration variables of torn nonlinear equation system:
      IdealDiode5.s:VARIABLE(start = 0.0 unit = "1" protected = true )  "Auxiliary variable for actual position on the ideal diode characteristic" type: Real
      IdealDiode2.s:VARIABLE(start = 0.0 unit = "1" protected = true )  "Auxiliary variable for actual position on the ideal diode characteristic" type: Real
    Iteration variables of torn nonlinear equation system:
      IdealDiode1.s:VARIABLE(start = 0.0 unit = "1" protected = true )  "Auxiliary variable for actual position on the ideal diode characteristic" type: Real
      IdealDiode4.s:VARIABLE(start = 0.0 unit = "1" protected = true )  "Auxiliary variable for actual position on the ideal diode characteristic" type: Real
    Iteration variables of torn linear equation system:
      SineVoltage1.n.v:VARIABLE(flow=false unit = "V" )  "Potential at the pin" type: Real
    
    [3] 11:25:25 Symbolic Notification
    Model statistics after passing the back-end for initialization:
     * Number of independent subsystems: 2
     * Number of states: 0 ()
     * Number of discrete variables: 6 (IdealDiode1.off,IdealDiode2.off,IdealDiode3.off,IdealDiode4.off,IdealDiode5.off,IdealDiode6.off)
     * Number of discrete states: 0 ()
     * Top-level inputs: 0
    
    [4] 11:25:25 Symbolic Notification
    Strong component statistics for initialization (33):
     * Single equations (assignments): 29
     * Array equations: 0
     * Algorithm blocks: 0
     * Record equations: 0
     * When equations: 0
     * If-equations: 0
     * Equation systems (linear and non-linear blocks): 0
     * Torn equation systems: 4
     * Mixed (continuous/discrete) equation systems: 0
    
    [5] 11:25:25 Symbolic Notification
    Model statistics after passing the back-end for simulation:
     * Number of independent subsystems: 1
     * Number of states: 4 (Inductor2.i,Inductor3.i,Capacitor1.v,Capacitor2.v)
     * Number of discrete variables: 6 (IdealDiode1.off,IdealDiode2.off,IdealDiode3.off,IdealDiode4.off,IdealDiode5.off,IdealDiode6.off)
     * Number of discrete states: 0 ()
     * Top-level inputs: 0
    
    [6] 11:25:25 Symbolic Notification
    Strong component statistics for simulation (28):
     * Single equations (assignments): 24
     * Array equations: 0
     * Algorithm blocks: 0
     * Record equations: 0
     * When equations: 0
     * If-equations: 0
     * Equation systems (linear and non-linear blocks): 0
     * Torn equation systems: 4
     * Mixed (continuous/discrete) equation systems: 0
    
    [7] 11:25:25 Symbolic Notification
    Torn system details for strict tearing set:
     * Linear torn systems: 1 {(1,100.0%) 9}
     * Non-linear torn systems: 3 {2 7,2 7,2 7}
    
    [8] 11:25:25 Translation Notification
    List of all iteration variables (DAE kind: simulation)
    Iteration variables of torn nonlinear equation system:
      IdealDiode2.s:VARIABLE(start = 0.0 unit = "1" protected = true )  "Auxiliary variable for actual position on the ideal diode characteristic" type: Real
      IdealDiode5.s:VARIABLE(start = 0.0 unit = "1" protected = true )  "Auxiliary variable for actual position on the ideal diode characteristic" type: Real
    Iteration variables of torn nonlinear equation system:
      IdealDiode6.s:VARIABLE(start = 0.0 unit = "1" protected = true )  "Auxiliary variable for actual position on the ideal diode characteristic" type: Real
      IdealDiode3.s:VARIABLE(start = 0.0 unit = "1" protected = true )  "Auxiliary variable for actual position on the ideal diode characteristic" type: Real
    Iteration variables of torn nonlinear equation system:
      IdealDiode1.s:VARIABLE(start = 0.0 unit = "1" protected = true )  "Auxiliary variable for actual position on the ideal diode characteristic" type: Real
      IdealDiode4.s:VARIABLE(start = 0.0 unit = "1" protected = true )  "Auxiliary variable for actual position on the ideal diode characteristic" type: Real
    Iteration variables of torn linear equation system:
      SineVoltage1.n.v:VARIABLE(flow=false unit = "V" )  "Potential at the pin" type: Real
    

    在 [2] 下,您可以看到需要具有起始值的迭代变量。在 [3] 中,您可以看到需要具有起始值或在系统中明确定义的离散变量(例如,如果您使用 when 条件切换它们,它们需要具有起始值。布尔默认值:false)。在 [5] 中,您可以看到选择的状态,它们需要起始值并且需要固定(您也可以为它们的导数提供初始方程,例如稳态初始化)。

    P2.2 起始值可用作迭代变量的初始值(牛顿求解器所必需的)。对于状态,除非您设置 fixed=true,否则它们不会一直使用,fixed=false 是默认值。初始方程始终是初始系统的一部分。对于计算参数,无论您使用该参数作为起始值还是在初始方程中,都适用相同的规则。

    P2.3 不幸的是,我不太清楚您所说的逆问题是什么意思。正如我所提到的,您可以为状态导数而不是状态提供初始方程,这也可以工作(也许这就是您在这里暗示的意思?)。 fixed=false 是默认值,声明此选项的选项是撤销在较低级别或已使用库中做出的fixed=true 决策。

    对不起,这太冗长了,我希望我能帮上忙!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多