如何访问Modelica中的多相连接器? (FFT模型)

时间:2019-07-12 12:04:05

标签: modelica openmodelica

我设法建立了一个FFT模型来分析单相正弦波电压源的频率。 现在,我正在尝试将FFT模型应用于三相域,以分析三相电压源的频率。如下所示:

within MasterarbeitPWM.FrequenzAnalysator;

model FFTmultiphaseTest
  MasterarbeitPWM.FrequenzAnalysator.FFTmultiphase fFTmultiphase1 annotation(
    Placement(visible = true, transformation(origin = {188, 110}, extent = {{-38, -38}, {38, 38}}, rotation = 0)));
  Modelica.Electrical.MultiPhase.Sources.SineVoltage sineVoltage1(V = fill(5, 3), freqHz = fill(2, 3), m = 3)  annotation(
    Placement(visible = true, transformation(origin = {121, 22}, extent = {{-24, -27}, {24, 27}}, rotation = -90)));
  Modelica.Electrical.Analog.Basic.Ground ground1 annotation(
    Placement(visible = true, transformation(origin = {121, -71}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
  Modelica.Electrical.MultiPhase.Basic.Star star1 annotation(
    Placement(visible = true, transformation(origin = {120, -32}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
equation
  connect(sineVoltage1.plug_p, fFTmultiphase1.positivePlug1) annotation(
    Line(points = {{122, 46}, {120, 46}, {120, 110}, {146, 110}, {146, 110}}, color = {0, 0, 255}));
  connect(star1.plug_p, sineVoltage1.plug_n) annotation(
    Line(points = {{120, -22}, {123, -22}, {123, -18}, {120, -18}, {120, 2.98024e-07}, {122, 2.98024e-07}, {122, -4}, {124, -4}, {124, -2}, {122, -2}}, color = {0, 0, 255}));
  connect(ground1.p, star1.pin_n) annotation(
    Line(points = {{121, -52}, {119, -52}, {119, -42}, {119, -42}}, color = {0, 0, 255}));
  annotation(
    Diagram(coordinateSystem(extent = {{-300, -200}, {300, 200}})),
    Icon(coordinateSystem(extent = {{-300, -200}, {300, 200}})),
    __OpenModelica_commandLineOptions = "");end FFTmultiphaseTest;

当我点击“检查模型”时,我没有得到任何错误,但是当我尝试进行仿真时,它给了我错误

The initialization problem is inconsistent due to the following equation: 0 != 4.33013 = $START.fFTmultiphase1.y[2] - fFTmultiphase1.y[2]
Error in initialization. Storing results and exiting.<br>
Use -lv=LOG_INIT -w for more information.
Simulation process failed. Exited with code -1.

和警告,例如:

[1] 13:55:08 Translation Warning
It was not possible to determine if the initialization problem is consistent, because of not evaluable parameters/start values during compile time: fFTmultiphase1.y[1] = $START.fFTmultiphase1.y[1] (sineVoltage1.sineVoltage[1].signalSource.offset + (if time < sineVoltage1.sineVoltage[1].signalSource.startTime then 0.0 else sineVoltage1.sineVoltage[1].signalSource.amplitude * sin(6.283185307179586 * sineVoltage1.sineVoltage[1].signalSource.freqHz * (time - sineVoltage1.sineVoltage[1].signalSource.startTime) + sineVoltage1.sineVoltage[1].signalSource.phase)) = $START.fFTmultiphase1.y[1])

这是我的FFT的模型:

within MasterarbeitPWM.FrequenzAnalysator;

block FFTmultiphase
  import Modelica.Constants.{pi};
  import Modelica.Math.FastFourierTransform.*;
  import Modelica.SIunits.*;
  parameter Frequency f_max = 5 "Maximum frequency of interest";
  parameter Frequency f_res = 1 "Frequency resolution";
  final parameter Integer ns = realFFTsamplePoints(f_max, f_res, f_max_factor = 5) "Number of samples";
  final parameter Integer nf = div(ns, 2) + 1 "Number of frequency points";
  final parameter Integer nfi = max(1, min(integer(ceil(f_max / f_res)) + 1, nf));
  final parameter Frequency f_i[nfi](each fixed = false) "FFT frequencies of interested frequency points";
  parameter Time samplePeriod = 1 / (2 * f_res * div(ns, 2));
  output Integer info(start = 0, fixed = true) "Information flag from FFT computation";
  Integer iTick(start = 0, fixed = true);
  discrete Real Buf[ns](start = zeros(ns), each fixed = true) "Input buffer";
  Real A_i[nfi](start = zeros(nfi), each fixed = true) "FFT amplitudes";
  Real Phi_i[nfi](start = zeros(nfi), each fixed = true) "FFT phases";
  Real y[3](start = fill(0, 3), each fixed = true, each unit = "V");
  // "Signal from which FFT is computed";
  Modelica.Electrical.MultiPhase.Interfaces.PositivePlug positivePlug1 annotation(
    Placement(visible = true, transformation(origin = {-114, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-110, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
initial equation
  for i in 1:nfi loop
    f_i[i] = (i - 1) * f_res;
  end for;
equation
  y = positivePlug1.pin.v;
  positivePlug1.pin[1].i = 0.0;
  positivePlug1.pin[2].i = 0.0;
  positivePlug1.pin[3].i = 0.0;
algorithm
  when sample(0, samplePeriod) then
    iTick := iTick + 1;
    if iTick <= ns then
      Buf[iTick] := y[1];
    end if;
    if iTick == ns then
      (info, A_i, Phi_i) := realFFT(Buf, nfi);
    end if;
  end when;
  annotation(
    Icon(graphics = {Text(origin = {-42, 62}, extent = {{110, -78}, {-30, 18}}, textString = "FFT"), Rectangle(origin = {0, -79}, fillPattern = FillPattern.Solid, extent = {{-80, -1}, {80, 1}}), Rectangle(origin = {-79, -49}, fillPattern = FillPattern.Solid, extent = {{-1, -29}, {1, 29}}), Polygon(origin = {-79, -15}, fillPattern = FillPattern.Solid, points = {{0, -5}, {-6, -5}, {0, 5}, {6, -5}, {6, -5}, {0, -5}}), Polygon(origin = {85, -79}, rotation = -90, fillPattern = FillPattern.Solid, points = {{0, -5}, {-6, -5}, {0, 5}, {6, -5}, {6, -5}, {0, -5}}), Rectangle(origin = {-59, -65}, fillPattern = FillPattern.Solid, extent = {{-1, 23}, {1, -15}}), Ellipse(origin = {-59, -39}, fillPattern = FillPattern.Solid, extent = {{-3, 3}, {3, -3}}, endAngle = 360), Ellipse(origin = {-49, -61}, fillPattern = FillPattern.Solid, extent = {{-3, 3}, {3, -3}}, endAngle = 360), Ellipse(origin = {-19, -53}, fillPattern = FillPattern.Solid, extent = {{-3, 3}, {3, -3}}, endAngle = 360), Ellipse(origin = {25, -67}, fillPattern = FillPattern.Solid, extent = {{-3, 3}, {3, -3}}, endAngle = 360), Ellipse(origin = {31, -49}, fillPattern = FillPattern.Solid, extent = {{-3, 3}, {3, -3}}, endAngle = 360), Rectangle(origin = {-49, -65}, fillPattern = FillPattern.Solid, extent = {{-1, 1}, {1, -15}}), Rectangle(origin = {31, -65}, fillPattern = FillPattern.Solid, extent = {{-1, 15}, {1, -15}}), Rectangle(origin = {-19, -63}, fillPattern = FillPattern.Solid, extent = {{-1, 7}, {1, -15}}), Rectangle(origin = {25, -63}, fillPattern = FillPattern.Solid, extent = {{-1, -5}, {1, -15}}), Ellipse(origin = {-67, -61}, fillPattern = FillPattern.Solid, extent = {{-3, 3}, {3, -3}}, endAngle = 360), Rectangle(origin = {-67, -63}, fillPattern = FillPattern.Solid, extent = {{-1, 1}, {1, -15}}), Rectangle(origin = {37, -63}, fillPattern = FillPattern.Solid, extent = {{-1, -5}, {1, -15}}), Ellipse(origin = {37, -67}, fillPattern = FillPattern.Solid, extent = {{-3, 3}, {3, -3}}, endAngle = 360), Line(points = {{-100, 100}, {100, 100}, {100, -100}, {-100, -100}, {-100, 100}, {-100, 100}}, thickness = 0.5)}),
    Diagram,
    __OpenModelica_commandLineOptions = "");
end FFTmultiphase;

令我难过的是我的单阶段示例有效(带有一些警告)。 我猜我在电压源和FFT模型之间的连接上做错了什么,但我不知道它是什么。 有人可以向我解释我在做什么错以及如何解决吗?

我对Modelica / OpenModelica真的很陌生,所以如果这是一个愚蠢的问题,请原谅。

非常感谢!

1 个答案:

答案 0 :(得分:2)

我观察到的某些事情(使用Dymola)可能会引起一些麻烦:

  1. block FFTmultiphase具有一个多相接口,通常在Modelica中无法做到。块仅具有因果输入/输出。我已经将类从块更改为模型。您也可以通过传感器将Real输入到模型中以测量电压。
  2. 由于fixed=true中的Real y[3](start = fill(0, 3), each fixed = true, each unit = "V");,您的初始方程组似乎过高。我会尝试删除each fixed = true

第二个似乎更可能引起您描述的问题。

然后给出A_i = {0,0,4.87,0,0,0}(尽管我猜第3个条目应该为5),结果似乎是合理的。