0

我已经用Modelica对非线性电感器进行了建模,但是梯形积分无法解决电路,不胜感激有人可以帮我解决电路。

model NonlinearInductor
  import Modelica.SIunits.MagneticFlux;
  extends Modelica.Electrical.Analog.Interfaces.OnePort;

  parameter Real T[:,2]=[-1.0015,-1200;-0.0015,-200;0,0;0.0015,200;1.0015,1200]
                                                                               "piecewiselinear current versus flux relation";
  Integer nbPoints = size(T,1) "Number of interpolation points";
  Real L;  //Slop of line flux-Current; inductance
  MagneticFlux flux( start=0);

equation
  v =  der(flux);     // Faraday's Low

algorithm
                // Definition of Piecewise nonlinear inductance


if  i < T[2,1] then
   L     := ((T[1,2] - T[2,2]) / (T[1,1] - T[2,1]));
   flux  :=  L  *  (i-T[1,1]) +  T[1,2];

  elseif i >= T[nbPoints-1,1] then
   L     := (( T[nbPoints-1,2] - T[nbPoints,2]) / (T[nbPoints-1,1] - T[nbPoints,1]));
   flux  := L * (i-T[nbPoints-1,1]) +  T[nbPoints-1,2];

  else
      for iter in 2:(nbPoints-2) loop
         if i >= T[iter,1] and i <T[iter+1,1] then
            L      := (( T[iter,2] - T[iter+1,2]) / (T[iter,1] - T[iter+1,1]));
            flux   := L * (i-T[iter,1]) +  T[iter,2];
         end if;
      end for;
 end if;
end NonlinearInductor;

我准备了如下示例:

model NonlinearInductorTest
  Modelica.Electrical.Analog.Sources.CosineVoltage cosineVoltage1(V = 25e3 * sqrt(2), freqHz = 50,
    phase=1.5707963267949)                                                                                          annotation (
    Placement(visible = true, transformation(origin = {-80, 20}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Electrical.Analog.Basic.Resistor resistor1(R = 1000e6)  annotation (
    Placement(visible = true, transformation(origin = {-14, 20}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Electrical.Analog.Basic.Ground ground1 annotation (
    Placement(visible = true, transformation(origin = {-80, -12}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Capacitor capacitor1(C=0.4e-9)    annotation (
    Placement(visible = true, transformation(origin = {-50, 42}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  NonlinearInductor L annotation(
    Placement(visible = true, transformation(origin = {28, 20}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
equation
  connect(L.n, ground1.p) annotation(
    Line(points = {{28, 10}, {28, 10}, {28, -2}, {-80, -2}, {-80, -2}}, color = {0, 0, 255}));
  connect(L.p, capacitor1.n) annotation(
    Line(points = {{28, 30}, {28, 30}, {28, 42}, {-40, 42}, {-40, 42}}, color = {0, 0, 255}));
  connect(capacitor1.p, cosineVoltage1.p) annotation(
    Line(points = {{-60, 42}, {-80, 42}, {-80, 30}}, color = {0, 0, 255}));
  connect(capacitor1.n, resistor1.p) annotation(
    Line(points = {{-40, 42}, {-14, 42}, {-14, 30}}, color = {0, 0, 255}));
  connect(resistor1.n, ground1.p) annotation(
    Line(points = {{-14, 10}, {-14, -2}, {-80, -2}}, color = {0, 0, 255}));
  connect(ground1.p, cosineVoltage1.n) annotation(
    Line(points = {{-80, -2}, {-80, 10}}, color = {0, 0, 255}));
  annotation (
    uses(Modelica(version="3.2.2")),
    experiment(StartTime = 0, StopTime = 0.1, Tolerance = 1e-6, Interval = 2e-05));
end NonlinearInductorTest;

请通过求解器梯形运行示例,StopTime = 0.1,Interval = 2e-05

4

1 回答 1

0

使用 MSL 的插值功能可以大大简化您的模型。据我了解,您的代码与此函数的作用相同:在定义的区间内使用线性插值,在外部使用线性外插。

这是更新的代码:

model NonlinearInductor2
  extends Modelica.Electrical.Analog.Interfaces.OnePort;

  parameter Real T[:,2]=[-1.0015,-1200;
                         -0.0015,-200;
                               0,0;
                          0.0015,200;
                          1.0015,1200] "piecewiselinear current versus flux relation";

  Modelica.SIunits.MagneticFlux flux( start=0);

protected 
  final parameter Real[:] i_vec = T[:, 1];
  final parameter Real[:] flux_vec = T[:, 2];

equation 
  v = der(flux);     // Faraday's Law
  flux = Modelica.Math.Vectors.interpolate(i_vec,flux_vec,i);
end NonlinearInductor2;

除了使您的模型更易于理解之外,使用 interpolate 函数还带来了以下好处:

  • 该函数smoothOrder定义了注释,它允许 Modelica 翻译器flux分析区分您的变量。
    (使用注释smoothsmoothOrder您可以定义导数连续的顺序)
  • 除了算法部分,我们可以使用单个方程部分。
    (您应该避免使用算法部分来描述物理行为,因为它限制了 Modelica 翻译器在操作您的方程以创建可解系统时。使用算法部分,您可以强制按照您编写的方式对代码进行评估,这违反了a-因果物理建模)

不幸的是,OpenModelica 在使用您的模拟设置(梯形规则,容差 = 1e-6)模拟新模型时仍然存在一些问题。通过将容差降低到 1e-4,模拟完成,但仍显示警告

重启 Kinsol:将线性求解器更改为 KINDense。

很多很多次。也许 OpenModelica 专家可以提供帮助。

顺便说一句,无论选择何种求解器,Dymola 对新代码都没有任何问题。

于 2019-11-11T11:47:15.710 回答