User Code Model (UCM) is a HYPERSIM® utility that allows users to build their custom models that cannot otherwise be built using existing models. As its name implies, a UCM is coded by users, using C language, according to HYPERSIM® rules.

The UCM makes it possible to build models composed of power and control parts. The advantage of using the UCM is that its power part is solved simultaneously with other power components. The UCM’s admittance is added to the admittance of the whole substation and all node voltages are solved together in the same step. This gives greater numerical stability than if the user’s model power part is represented as controlled sources which imply one-step delay.

Because the UCM’s power part is solved together with other power elements, users must follow the same procedure used in HYPERSIM® algorithm to solve node voltages. The control part is simply a relationship between inputs and outputs and is simpler to model.**This document is intended as both a UCM user manual and tutorial. It contains the following sections:**

**Solution method in HYPERSIM®:**description of the way HYPERSIM® models power elements, handles non-linearity, solves node equations, organizes parallel tasks. This helps to understand the procedure to build an UCM.**User Code Model:**description of the UCM and the procedure to build and use UCMs.**Progressive practice with UCM:**series of examples to instruct users on and provide practice with UCMs.

The HYPERSIM® solution method is based on the traditional EMTP technique. Using the trapezoidal rule for integration, the EMTP converts most power system lump components into resistors and current sources and, finally, solves for node voltages.

HYPERSIM® takes advantage of transmission lines to separate the whole power system into parallel tasks and simulate them in parallel computers. This chapter will first describe the line model and show that events that happen at one end of the

line will affect the other end only after a transmission delay. Different types of branches will be analyzed to show that they can be represented as resistor-source equivalents.

The simulation of a network is therefore summarized to the modeling of lines and the solution of node equations formed by resistors and current sources to find the node voltages. Non-linear elements and switches will affect the model behavior during the simulation and require HYPERSIM® to recalculate them during the simulation.

HYPERSIM® also simulates control systems that are simply represented as relationships of outputs to inputs.

In terms of software, HYPERSIM® is composed of an interface and a simulation program. The interface is not simply a graphical interface but it also analyses the network, calculates models and generates codes necessary for the simulation. Most of simulation preparation is done in the interface to optimize the simulation speed. The simulation program can run either in real-time on parallel computers or in non real-time on workstations.

**Line Model****Conversion from 3 coupled phases into 3 decoupled modes**

In a three-phase line, each phase is mutually coupled with other phases. To facilitate the line simulation, the EMTP uses a technique to convert a mutually coupled three-phase line into 3 decoupled, single-phase lines representing 3 decoupled modes.

In HYPERSIM®, lines are modeled as follows:

Get three phase node voltages at each terminal K and M,

Convert three phase voltages into three-mode voltages:

**Model of single-phase line**

Each mode (0, 1, 2) can then be represented as shown in . The current sources in this figure are

given as

**Equivalent circuit of one mode on a transmission line**

Each half (left and right) of the line equivalents will be converted from mode to phase form and incorporated into the corresponding substation equation to be solved with other elements.

**Substation modeling**

In each substation, there are passive components interpreted as RLC elements which can be linear or non-linear, circuit-breakers, different kinds of generation interpreted as voltage and current sources equipped with control systems. Machines and motors are considered as sources with control systems.

Beside control systems, other equipments are power elements working at the power system level voltages and currents. Power elements of a substation are interconnected together via nodes. Power elements are not simulated sequentially one by one but rather simultaneously all together in a single equation call the node equation:

**YV=I**

where Y is the substation admittance matrix, V is vector of node voltages and I is vector of node currents (currents injected to nodes).

Control systems are modeled using the bloc diagram principle, either under graphic form (HYPERSIM ® bloc diagram and Simulink bloc diagram) or coded in C/C++. Their inputs can be node voltages and currents while their outputs can be used to control sources and switches.

**RLC element****Trapezoidal integration**

HYPERSIM®, as EMTP, uses the trapezoidal integration technique, it means that:

The C branch is also equivalent to a resistor given by the equation above, in parallel with a historic current source as shown . Here again, for a fixed capacitor, is constant. The historic current

is recalculated at each time step using voltages and current from the previous time step.**Branch of RLC combination**

For branches of different combinations of RLC elements, one can always write down the voltage current relationship, replace integrals by eq. “” on page 489, derivative by eq. “” on page 489, and get more or less complex forms of a equivalent resistor and a historic current.**Current and voltage sources**

A current source i flowing from node k to node m has the effect of removing a current i from node k and adding a current i to node m.

Voltage sources with output impedances are converted into current sources in parallel with the same impedance using Thevenin-Norton conversion.**Non-linear elements**

Non-linear elements are treated as RLC elements, and are also equivalent to a resistor in parallel with a historic current (if it is not a pure resistor).

Non-linearity is represented normally as a characteristic curve approximated by successive linear segments. Due to the non-linearity, is no longer constant and needs to be recalculated for each time step. Theoretically, this must be done based on the conditions of the actual time step, but HYPERSIM® does it based on conditions obtained at the last time step because the current results are not yet available. The change from one segment to the next can be one time-step delayed.

It is therefore a good practice to define the non linearity characteristic with a smooth changing (more points where there are more changes and vice versa) to avoid searching. An example of a non-linear resistance is shown below:

HYPERSIM® works rather with the conductance and splits it as follows:

**<<Gordon bottom of page 7>>**