Search code examples
modelicaopenmodelica

How can I access multiphase connectors in modelica? (FFT model)


I managed to make a FFT model to analyze the frequency of a single phase sine wave voltage source. Now I'm trying to apply my FFT model to the 3-phase domain to analyze the frequencies of a 3-phase voltage source. This looks like the following:

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;

When I hit "check model" I don't get any errors but when I try to simulate, it gives me the error

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.

and warnings like:

[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])

This is the model of my 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;

As I sad my single phase example works (with some warnings). I guess I'm doing something wrong with the connection between the voltage source and my FFT model, but I can't figure out what it is. Can someone may explain to me what I'm doing wrong and how to fix it?

I'm really new to Modelica/OpenModelica so please excuse if it is a silly question.

Many thanks in advance!


Solution

  • Some things I observed (using Dymola) that could cause some troubles:

    1. The block FFTmultiphase has a Multiphase Interface, which is usually not done in Modelica. Blocks only have causal in-/outputs. I've changed the class from a block to a model. You could as well use a Real input to the model using a sensor to measure the voltage.
    2. Your initial set of equations seem to be over-determined due to the fixed=true in Real y[3](start = fill(0, 3), each fixed = true, each unit = "V");. I would try to remove each fixed = true.

    The second seems likelier to cause the problems you describe.

    The result seems reasonable then giving A_i = {0,0,4.87,0,0,0} (although I guess it should be 5 for the 3rd entry).