Documentation Home Page HYPERSIM Home Page
Pour la documentation en FRANÇAIS, utilisez l'outil de traduction de votre navigateur Chrome, Edge ou Safari. Voir un exemple.

UCM: Exercise #3 Voltage Source

Exercise 3

Voltage source

Instead of considering R and L as 2 separate branches, as in the example above, combine them as a combined RL single branch (there is no more internal node). Write down its equivalent equation using the trapezoidal integration rule and build a UCM to represent it. Compare results with those of the example above.

Description

Build a three-phase sine-wave voltage source. The parameter Amp controls the sine wave amplitude and the parameter freq controls its frequency. The voltage sources are connected in Y grounded and each phase has an inductor Ls at its output.
The control outputs I_a, I_b, I_c at the connector I send out the source currents and the control outputs Db1, Db2, Db3 at connector Db are used for debugging purposes.

Codes

%%vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
%% BEGIN GENERAL INFORMATION -- Enter or modify general information
UCM_NAME = VSrc
UCM_TYPE = NetworkElement
UCM_CATEGORY = User
UCM_VERSION = "1.0"
UCM_EXEC_TIME = 5.0e-6
UCM_DESCRIPTION = "Three-phase Voltage source with inductor at output"
%% END GENERAL INFORMATION
%%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
%%vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
%% BEGIN DOCUMENTATION -- Enter model’s documentation after this line...
Three-phase sine-wave voltage source with inductor at output
%% END DOCUMENTATION
%%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
%%vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
%% BEGIN TUNABLE PARAMETERS -- Enter parameters table after this line...
Amp "Amp" V double 1 1.0 0.0 10.0 - "Source Amplitude"
Ls "Ls" H double 3 [0.1 0.1 0.1] 0.0 1.0e12 - "Output inductor"
freq "freq" Hz double 1 60.0 1.0e-12 1.0e12 - "frequency"
%% END TUNABLE PARAMETERS
%%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
%%vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
%% BEGIN CONTROL IOS -- Enter control IOs table after this line...
I_a - double out auto I "Output current, phase a"
I_b - double out auto I "Output current, phase b"
I_c - double out auto I "Output current, phase c"
Db1 - double out auto Db "Debugging output 1"
Db2 - double out auto Db "Debugging output 2"
Db3 - double out auto Db "Debugging output 3"
%% END CONTROL IOS
%%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
%%vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
%% BEGIN NODES DEFINITIONS -- Enter nodes table after this line...
T 3 extern bottom no "Network Connection"
%% END NODES DEFINITIONS
%%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
%%vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
%% BEGIN CURRENT SOURCES -- Enter sources table after this line...
Isrc_a T_a ground
Isrc_b T_b ground
Isrc_c T_c ground
%% END CURRENT SOURCES
%%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
%%vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
%% BEGIN HISTORICAL CURRENTS -- Enter historical currents table after this...
Ihist_a T_a ground
Ihist_b T_b ground
Ihist_c T_c ground
%% END HISTORICAL CURRENTS
%%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
%%vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
%% BEGIN CALCULATED PARAMETERS -- Enter parameters table after this line...
Gs - double 3 "Equiv.Conductance"
omega - double 1 "omega"
period - double 1 "period"
%% END CALCULATED PARAMETERS
%%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
%%vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
%% BEGIN PREPARATION FUNCTION CODE -- Enter code after this line...
int i, j;
doubleGLo, Lo;
/* Calculate equivalent conductances of Inductances */
Gs[0] = ucmTimeStep / (2.0 * Ls[0]);
Gs[1] = ucmTimeStep / (2.0 * Ls[1]);
Gs[2] = ucmTimeStep / (2.0 * Ls[2]);
/* Initialize Yini and Yfill */
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
ucmYini(i,j) = 0.0;
ucmYfill(i,j) = 0;
}
}
/* Calculate Yini and determine Yfill */
ucmYini(T_a, T_a) = Gs[0];
ucmYini(T_b, T_b) = Gs[1];
ucmYini(T_c, T_c) = Gs[2];
ucmYfill(T_a, T_a) = 1;
ucmYfill(T_b, T_b) = 1;
ucmYfill(T_c, T_c) = 1;
/* Calculate other Simulation parameters */
period = 1.0 / freq;
omega = 2.0 * 3.141593 * freq;
%% END PREPARATION FUNCTION CODE
%%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
%%vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
%% BEGIN HISTORICAL VALUES -- Enter the table after this line...
time double 1 0.0 "time"
%% END HISTORICAL VALUES
%%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
%%vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
%% BEGIN SIMULATION GLOBAL CODE -- Enter code under the appropriate comment...
/* 9.3.1 -- User includes */
#include <math.h>
%%% END SIMULATION GLOBAL CODE
%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
%%vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
%% BEGIN BEFORE VOLTAGE CALCULATION CODE -- Enter code ->...
/* User code: calulate Yadd */
int i;
doubleVsrc_a, Vsrc_b, Vsrc_c;
doubleTwoPiOver3 = 2.094395333; /* 2.0 Pi / 3 */
/* Calculate source voltages */
Vsrc_a = Amp * sin (omega * time);
Vsrc_b = Amp * sin (omega * time - TwoPiOver3);
Vsrc_c = Amp * sin (omega * time + TwoPiOver3);
/* Calculate current sources */
Isrc_a = Vsrc_a * Gs[0];
Isrc_b = Vsrc_b * Gs[1];
Isrc_c = Vsrc_c * Gs[2];
%% END BEFORE VOLTAGE CALCULATION CODE
%%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
%%vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
%% BEGIN AFTER VOLTAGE CALCULATION -- Enter code ->...
double Vsrc_a, Vsrc_b, Vsrc_c;
Vsrc_a = Isrc_a / Gs[0];
Vsrc_b = Isrc_b / Gs[1];
Vsrc_c = Isrc_c / Gs[2];
/* Calculate output currents and historic currents */
I_a = (Vsrc_a - ucmVNode(T_a)) * Gs[0] + Ihist_a;
Ihist_a = I_a + (Vsrc_a - ucmVNode(T_a)) * Gs[0];
I_b = (Vsrc_b - ucmVNode(T_b)) * Gs[1] + Ihist_b;
Ihist_b = I_b + (Vsrc_b - ucmVNode(T_b)) * Gs[1];
I_c = (Vsrc_c - ucmVNode(T_c)) * Gs[2] + Ihist_c;
Ihist_c = I_c + (Vsrc_c - ucmVNode(T_c)) * Gs[2];
/* Other calculations */
time += ucmTimeStep;
if (time >= period) /* To avoid truncation error */
time -= period;
/* Debugging outputs */
Db1 = I_a;
Db2 = Ihist_a;
Db3 = time;
%% END AFTER VOLTAGE CALCULATION CODE
%%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

OPAL-RT TECHNOLOGIES, Inc. | 1751, rue Richardson, bureau 1060 | Montréal, Québec Canada H3K 1G6 | opal-rt.com | +1 514-935-2323
Follow OPAL-RT: LinkedIn | Facebook | YouTube | X/Twitter