You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

OpenModelica中ClosedVolume与SweptVolume仿真报错及质量设置求助

问题描述

我正在学习OpenModelica软件,尝试搭建一个由ClosedVolume、StaticPipe、SweptVolume及平动质量组件组成的简单模型,但运行仿真时出现错误,进程崩溃。错误信息显示:solveOneNonlinearEquation函数调用中u_min和u_max未包围非线性方程的根,fa与fb符号未相反。同时希望了解如何为ClosedVolume设置指定质量,特附上模型代码及错误信息如下:

模型代码

Modelica.Fluid.Machines.SweptVolume sweptVolume(redeclare package Medium = Modelica.Media.Air.SimpleAir, clearance = 0.0001, nPorts = 1, pistonCrossArea = 0.001) annotation(
    Placement(visible = true, transformation(origin = {18, 0}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Fluid.Vessels.ClosedVolume volume(redeclare package Medium = Modelica.Media.Air.SimpleAir, V = 6e-4, nPorts = 1, use_portsData = false) annotation(
    Placement(visible = true, transformation(origin = {-66, 20}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  inner Modelica.Fluid.System system annotation(
    Placement(visible = true, transformation(origin = {-82, 80}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Fluid.Pipes.StaticPipe pipe(redeclare package Medium = Modelica.Media.Air.SimpleAir, diameter = 0.8, length = 1, nParallel = 1) annotation(
    Placement(visible = true, transformation(origin = {-28, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Mechanics.Translational.Components.Mass mass(m = 0.1) annotation(
    Placement(visible = true, transformation(origin = {54, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
  connect(volume.ports[1], pipe.port_a) annotation(
    Line(points = {{-66, 10}, {-66, 0}, {-38, 0}}, color = {0, 127, 255}));
  connect(pipe.port_b, sweptVolume.ports[1]) annotation(
    Line(points = {{-18, 0}, {8, 0}}, color = {0, 127, 255}));
  connect(sweptVolume.flange, mass.flange_a) annotation(
    Line(points = {{28, 0}, {44, 0}}, color = {0, 127, 0}));
  annotation(
end ClosedSwept; 

错误信息

The arguments u_min and u_max provided in the function call     solveOneNonlinearEquation(f,u_min,u_max) do not bracket the root of the single non-linear equation 0=f(u):   u_min  = 200   u_max  = 6000   fa = f(u_min) = 212529   fb = f(u_max) = 7.66508e+06 fa and fb must have opposite sign which is not the case
Process crashed Simulation process failed. Exited with code 0xffffffffc0000005.
仿真崩溃问题解决

这个错误源于求解器无法找到非线性方程的根,核心原因是模型初始条件或参数设置不合理,可按以下步骤调整:

  • 修正组件初始条件
    • 给ClosedVolume手动设置合理的初始压力和温度,比如标准大气压和室温:
      Modelica.Fluid.Vessels.ClosedVolume volume(
        redeclare package Medium = Modelica.Media.Air.SimpleAir,
        V = 6e-4,
        nPorts = 1,
        use_portsData = false,
        p_start=101325,
        T_start=293.15
      );
      
    • 给SweptVolume设置合理的初始活塞位置,避免初始体积与clearance冲突:
      Modelica.Fluid.Machines.SweptVolume sweptVolume(
        redeclare package Medium = Modelica.Media.Air.SimpleAir,
        clearance = 0.0001,
        nPorts = 1,
        pistonCrossArea = 0.001,
        x_start=0.1
      );
      
  • 调整管道参数
    当前StaticPipe直径0.8米,和其他组件(ClosedVolume体积6e-4 m³、活塞面积0.001 m²)尺寸差距过大,会导致流体状态异常。建议缩小管道直径,比如改成0.01米:
    Modelica.Fluid.Pipes.StaticPipe pipe(
      redeclare package Medium = Modelica.Media.Air.SimpleAir,
      diameter = 0.01,
      length = 1,
      nParallel = 1
    );
    
  • 可选:调整求解器设置
    如果上述调整后仍有问题,可在仿真设置中切换非线性求解器(比如从默认的Newton法改为Broyden法),或增大迭代次数,但优先调整模型参数和初始条件。
ClosedVolume指定质量设置方法

ClosedVolume默认通过体积、初始压力/温度间接确定质量,要直接指定质量,有两种可行方式:

方式1:利用portsData初始化

设置use_portsData=true,结合理想气体状态方程反推初始压力/温度,来得到目标质量。示例:
假设目标质量为0.0007kg(标准状态下6e-4 m³空气的质量),修改ClosedVolume参数:

Modelica.Fluid.Vessels.ClosedVolume volume(
  redeclare package Medium = Modelica.Media.Air.SimpleAir,
  V = 6e-4,
  nPorts = 1,
  use_portsData = true,
  portsData = {Modelica.Fluid.Types.PortData(m_flow_start=0, p_start=101325, T_start=293.15)}
);

如果需要其他目标质量,可通过公式m = (p*V)/(R*T)(R为空气气体常数,取287 J/(kg·K))反推对应的p或T值。

方式2:添加初始方程约束

在模型的initial equation部分直接指定ClosedVolume的介质质量,需确保参数兼容:

initial equation
  volume.medium.m = 0.0007; // 替换为你的目标质量值

注意:这种方式可能需要同时约束压力或温度,避免状态变量冲突,比如同时添加volume.medium.p = 101325;。

内容的提问来源于stack exchange,提问作者Emma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 22:59:56