function pwr_con

% PWR_CON Show the help for the functions in this toolbox.

% This file is automatically generated.  Matthew Simoneau, 09-04-98
% Copyright (c) 1984-98 by The MathWorks, Inc. All Rights Reserved
% $Revision: 1.3 $ $Date: 1998/10/16 23:19:36 $

helpwin('pwr_con/Contents');

function Contents
%MATLAB Tour Partial Function Help:  pwr_con
%
%Double click on any function for more information
%
%  Power System Blockset
%  Version 1.1 (R11) 10-Aug-1998
% 
%  Network analyser.
%    power2sys         - Network analyser.
%    powergui          - Network analyser graphical user interface (GUI).
%    circ2ss           - Compute State space representation of electrical circuit.
%    powerinit         - Set initial states of an electric circuit.
%    powerflow         - Solve load flow in multimachine power system.
%    psbflowsolv       - MDL file used by powerflow.
% 
%  Blockset libraries.
%    powerlib          - Power System Blockset library.
%    powerlib_extras   - extra library of powerlib.
%    powerlib_models   - Non linear models library for powerlib non-linear blocks.
% 
%  Graphical user interface windows.
%    powergui_loadflow - Graphical user interface for the Machine Load Flow.
%    powergui_state    - Graphical user interface for initial states setting.
%    powergui_steady   - Graphical user interface for steady-state informations.
% 
%  HTML help file.
%    psbhelp.m        - Points Web browser to the HTML help file.
%-------------------------------------------
%
%  Power System Blockset Demos.
% 
%  General Demos library.
%    psbfilter       - Demo1  Steady-state operation of linear circuit filter.
%    psbtransient    - Demo2  Transient analysis of a linear circuit.
%    psbtransfo      - Demo3  Three-winding distribution transformer.
%    psbtransfosat   - Demo4  Energization of a three-phase Saturable Transformer.
%    psbsurgnetwork  - Demo5  AC network Surge Arrester.
%    psbrectifier    - Demo6  Three-phase diode rectifier.
%    psbconverter    - Demo7  Thyristor Converter.
%    psbswitching    - Demo8  Ideal Switch in switching circuit.
%    psbmosconv      - Demo9  Mosfet converter.
%    psbbuckconv     - Demo10 Gto Thyristor in buck converter topology.
%    psbloadshed     - Demo11 Load shedding on a simplified alternator.
%    psbturbine      - Demo12 Synchronous generator powered by hydraulic turbine.
%    psbpwm          - Demo13 Asynchronous machine fed by PWM inverter.
%    psbpmmotor      - Demo14 PM synchronous motor fed by PWM inverter.
% 
%  Utility function for demos.
%    psbfilterbode   - Used by Demo1.
%    psbturbinit     - Initialization of demo 12.
%    psbturbdata     - Initial conditions for demo 12.
% 
%  Case studies demonstration files.
%    psbcompensated  - Case study 1 Series compensated network.
%    psbdcdrive      - Case study 2 Chopper fed DC motor drive.
%    psbregulator    - Case study 3 Synchronous machine and regulator.
%    psbfrequency    - Case study 4 Variable frequency induction motor drive.
%    psbhvdc         - Case study 5 HVDC transmission system.
% 
%  Utility functions for Case study 3
%    psbregulinit    - Initialization function.
%    psbregulset     - Initialization function.  
%    psbreguldelta   - Initialization function.  
%    psbregulzero    - Initialization function.     
%    psbreguldata    - Data for fast steady-state initialization. 
%   
%  Distributed parameter Line demos (powerlib_extras).
%    psbmonophaseline - Switching of a single phase line.
%    psbtriphaseline  - Single phase energization of a three-phase line.
% 
%  Demo examples used in the reference documentation.
%    power2sys example.
%    psbnetsim1       - power2sys example 1.
%    psbnetsim2       - power2sys example 2.
% 
%    Linear blocks.
%    psbbusbar        - Bus Bar. 
%    psbneutral       - Neutral. 
%    psbground        - Ground. 
%    psbpiline        - Line Pi. 
%    psbmutual        - Mutual inductance. 
%    psbseriesbranch  - Series RLC Branch. 
%    psbseriesload    - Series RLC Load. 
%    psbparalbranch   - Parallel RLC Branch. 
%    psbparalload     - Parallel RLC Load. 
%    psbcurrmeasure   - Current measurement. 
%    psbvoltmeasure   - Voltage measurement. 
%    psbaccurrent     - AC current source. 
%    psbdcvoltage     - DC voltage source.
%    psbcontrolcurr   - Controlled current source. 
%    psbcontrolvolt   - Controlled voltage source. 
%    psbacvoltage     - AC voltage source. 
%    psbtransformer   - Linear transformer. 
% 
%    Power network non-linear blocks.
%    psbarrester      - Surge Arrester. 
%    psbbreaker       - breaker. 
%    psbxfosaturable  - Saturable transformer. 
%    psbswitch        - Ideal Switch.
% 
%    Machines.
%    psbsimplealt     - Simplified alternator.
%    psbsyncmachine   - Synchronous machine. 
% 
%    Power electronics.
%    psbdiode         - Diode.
%    psbthyristor     - Thyristor.
%

function power2sys
%MATLAB Tour Partial Function Help:  pwr_con
%
% POWER2SYS Simulink graphical interface analyser for Electrical Toolbox
% 	[A,B,C,D,X0,STATE_VAR,SOURCES,OUTPUTS,USS,XSS,YSS,RLC,SOURCE,SWITCH, ...
% 	NB_TRUE_SENSOR,NB_MODELS,MODELS,Y_TYPE,YOUT]=POWER2SYS(SIMUWIN,OPTION);
% 
%  	PURPOSE
% 
%  	Analyse electrical network built with powerlib library 
% 
%  	SYNOPSIS
% 
%  	POWER2SYS;
%  	[A,B,C,D,X0,STATE_VAR,SOURCES,OUTPUTS,USS,XSS,YSS,FREQYSS,HLIN]= ...
% 							POWER2SYS(SIMWIN)
%  	[A,B,C,D,X0,STATE_VAR,SOURCES,OUTPUTS,USS,XSS,YSS,FREQYSS,HLIN]]= ...
% 	                                                POWER2SYS(SIMWIN,OPTIONS)
% 
%  	DESCRIPTION
% 
%  	POWER2SYS is used to compute the equivalent State-Space model of an
% 	electrical network built with `Electrical blockset' blocks library. 
% Power2sys extracts the linear part of the simuwin system and build the 
% 	corresponding state-space model.Non-linear elements are simulated by 
% 	current sources (state-space model input) driven by the voltage across 
% 	the non-linear element. After POWER2SYS has been called, the internal 
% 	structure of the system becomes functional, and the simulation of the
% 	electrical network can be made normally by using the 'Simulation/Start'
% 	menu command.
% 
%  	[ A,B,C,D,X0,STATE_VAR,SOURCES,OUTPUTS,USS,XSS,YSS,FREQYSS,Hlin ] =
% 	 POWER2SYS(SIMWIN) 
%  	computes the equivalent state-space model of the SIMULINK window named
% 	SIMUWIN. A,B,C,D are the standard matrices of the state-space system
%  	described by the equations x'=Ax+Bu and y=Cx+Du. X0 is a vector
%  	containing the initial conditions of the state-space variables listed
%  	in STATE_VAR.
%  
%  	STATE_VAR is the list of the names of the state-space
%  	variables (vector x). Each line of STATE_VAR begins with a prefix,
%  	`Uc_' for capacitor voltages or`Il_' for inductance currents, followed
%  	by the name of the block in which the element (C or L) is found.
% 	Inductance currents senses and capacitor voltages are defined as taken 
% 	from the input of the block to the output of the block. 
% 	A suffix is added to the line for blocks made of more than 2 inductances
% 	or capacitors: for example, the `Linear transformer' block will produce 
% 	STATE_VAR lines for its leakage inductances with the suffix `coil:x' 
% 	where x is the winding number of the transformer. 
% 
%  	INPUTS is the names list of the names of the inputs of the system 
% 	(vector u). Each line of INPUTS begins with a prefix, `U_' for
%  	voltage sources or `I_' for current sources, followed by the name of the
%  	source block. Currents sources are defined as taken from the input of 
% 	the block to the output of the block while voltages are defined as taken
% 	from the output of the block to the input of the block. A suffix may end
% 	a line of INPUTS for multi-source block like, for example, the 
% 	`Simplified alternator' block that produce two inputs.
% 
%  	OUTPUTS is the list of the outputs of the state-space system (vector y).
% 	Each line of OUTPUTS begins with a prefix, `U_' for voltage outputs or 
% 	`I_' for current outputs , followed by the name of the block which 
% 	produce the output.
% 
% 	USS contains the steady-state complex values of the sources of 
% 	the system. 
% 
% 	XSS contains the steady-state complex values of the state-space
% 	variables of the system.
% 
% 	YSS contains the steady-state complex values of the outputs of 
% 	the system. 
% 
% 	FREQYSS is the column vector containing the sources (inputs) frequencies
% 	ordered by increasing values.
% 
% 	HLIN is the complex transfer impedance matrix of the linear system 
% 	corresponding to the first non-zero frequency of the FREQYSS vector.
% 
% 	power2sys(simwin,options) will run power2sys with special functional flags. 
% 	The string variable options may contains one or many of the following 
% 	flag characters in any order:
% 	`w':	power2sys pop-up warning conditions if any.
% 	`o':	power2sys produce a .net file containing processing information.
% 	`s':	enable auto-save of Simulink window simwin after analysis.
%  	The `s' flag is used to automatically save the state-space system
%  	constructed by power2sys in the Simulink window.

function powergui
%MATLAB Tour Partial Function Help:  pwr_con
%
% POWERGUI  Graphical user interface for the Power System Blockset.
%  
%    POWERGUI opens a visual tool for the power2sys.m function
% 
%    

function circ2ss
%MATLAB Tour Partial Function Help:  pwr_con
%
% 
%  CIRC2SS produces the continuous state-space representation of a linear 
%          electrical circuit. The state variables are inductor currents and
%          capacitor voltages.
%  
%          CIRC2SS can be called in two different ways:
% 
%      1)  CIRC2SS is called automatically by the POWER2SYS function producing
%          the topology and state-space representation of an electrical circuit
%          previously drawn in  a SIMULINK window
%          from the blocks of the ELECTRICAL LIBRARY.
%      2)  Directly from the Matlab window
%      
%   Input arguments
%   ===============
%        The number of arguments may be 7, 12, 13, 14 or 16.
%        The first 7 arguments must be specified. Arguments 8 to 16 are optional.
% 
%        rlc : Branch matrix (nbr,6) or (nbr,7) specifying the network topology
%              and R L C values; see format below
%   switches : switch matrix (nsw,7) ; see format  below
%     source : source matrix (nsrc,5) or (nsrc,6) or nsrc(7) ; see format  below
%   line_dist: distributed parameter line matrix (nline,7) ; see format  below
%       yout : string matrix (nb_output,ncar) of output expressions
%              see format below
%     y_type : vector indicating output types
%              (0=voltage output ; 1=current output)
%       unit : units used to specify R L and C values in the rlc matrix 'rlc
%              unit= 'OHM' R L C values specified in ohms at fundamental frequency
%                     specified by freq_sys.
%              unit= 'OMU' R L C values specified in ohms millihenries (mH) and 
%                     microfarads(uF)
% 
%        The following  9 arguments are optional:
% 
%             Specify empty variables [] for the next 3 arguments 
%             if CIRC2SS is not called by POWER2SYS :
%      blocs : string matrix containing  names of blocks  
%     srcstr : string matrix containing names of source blocks
%              starting with  I_ ou V_ prefix
%  BrancheREF: Integer matrix= cross reference list between POWER2SYS topology 
%              and rlc matrix
% 
% power2sys_flag: Integer =0: CIRC2SS is called by ETAT or from the Matlab window.
%                          Informations on circuit (topology, modes, outputs ...)
%                          are displayed during execution.
%                       1: if CIRC2SS is called by POWER2SYS
%                          Only version number, number of states, inputs
%                          and outputs are displayed.
%                       2: Silent mode. 
% 
% fid_outfile: File identifier of output file containing detailed messages 
% 
%   freq_sys : Fundamental frequency (Hz) considered for specification of
%              L and C reactances if unit = 'OHM';  default value = 60 Hz
% 
%     option : Integer vector specifying options (5);default values= [0 0 0 0 0]
%                 option(1)= reference node number used for pi transmission lines
%                           -1 Node is not specified (The user will be prompted to
%                            specify a node number).
%                 option(2)= used to specify normalization of A B C D matrices
%                            in order to use the per-unit system.
%                            This option is not available from POWER2SYS
%                            0 : no normalization ;
%                            1 : Use per-unit system ;
%                                (Base voltage and base power are specified
%                                by option(3) and opotion(4))
%                           -1 : The user will be prompted to specify 
%                                a base voltage and a base power.
%                 option(3)= base voltage (kVrms Phase-Phase)
%                 option(4)= base power (MVA 3 phase)
%                 option(5)= 0 used only for debugging; (normal value=0)
%                            1 allows to display detailed calculation of A B C D
%                             used only for debugging purposes. 
% 
%  vary_name : String matrix (nvary,n) containing the variable names 
%              used in output expressions          
%   vary_val : Vector containing the values of the variable names specified
%              in vary_name.      
% 
%   Output arguments
%   ================
%    A,B,C,D :  State-space matrices of the linear circuit with all switches open
%               A(nstates,nstates) B(nstates,ninput)
%               C(noutput,nstates) D(noutput,ninput)
%     states :  String matrix (n,nstates) containing the names of the
%               state variables. Each string has the following format:
%                    Inductor  currents: Il_bxx_nzz1_zz2 
%                    Capacitor voltages: Uc_bxx_nzz2_zz2 
%                    where : xx = branch number 
%                            zz1= 1st node number of the branch
%                            zz2= 2nd node number of the branch
%         x0 :  Column vector of initial values of state variables
%               considering the status (open or closed) of switches
%       x0sw :  Vector of initial values of switch currents
%       rlsw :  Matrix (nsw,2) containing the R and L values of series switch
%               impedances in Ohm and Henry,
%      u,x,y :  Matrices  u(ninput,nfreq) x(nstates,nfreq) y(noutput,nfreq)
%               containing the steady-state complex values of inputs, states
%               and outputs. Each column correspond to a different source
%               frequency as specified by the next argument (freq).
%       freq :  Column vector containing the (nfreq) source frequencies 
%               ordered by increasing frequencies.
%     Asw,Bsw : State-space matrices of the circuit including the closed switches
%     Csw,Dsw   (one extra state per closed switch)
%        Hlin : Complex transfer impedance matrix (noutput,ninput) of the linear
%               system corresponding to the first non-zero frequency
%               of the FREQ vector.
%                    
% 
%  Format of the RLC input matrix
%  ==============================
%          Two formats are allowed:
%          6 columns :  No branch numbering; 
%                       Branch numbers correspond to the RLC line numbers(1-nbr)
%          7 columns :  Branch numbering is imposed by the user
% 
%          Each line of the RLC matrix must be specified according to the
%          following format:
% 
%                  (1)   (2)  (3)  (4)  (5)  (6)   [7]
%                node1 node2  TYPE  R    Xl  Xc   [Nobr] for a RLC or line branch
%           or   node1 node2  TYPE  R    L   C    [Nobr]
%                node1 node2  TYPE  R    Xl  U    [Nobr] for a transformer branch
%           or   node1 node2  TYPE  R    L   U    [Nobr]
% 
%                node1 : Node number 1 of the branch
%                node2 : Node number 2 of the branch
%                        Note:
%                        Node numbers must be positive or zero.
%                        Decimal node numbers are allowed.                       
%                 TYPE : Code indicating the type of connection of R L C elements
%                        (0-3) or the transmission line length (negative value).
%                        0 : series R L C
%                        1 : parallel R L C
%                        2 : transformer winding
%                        3 : coupled (mutual) winding
%                            For a mutual or a transformer having N windings,
%                            N+1 consecutive lines must be specified:
%                           -N lines TYPE=2 or TYPE=3; (one line per winding)
%                            Each line specifies R/L/U or R/Xl/Xc
%                            where : R/L R/Xl = winding resistance and leakage
%                                 reactance or winding resist. and self reactance
%                                    U = Nominal voltage of transformer winding 
%                                        (specify 0 for TYPE 3)
%                           - one line TYPE=1 for the magnetizing branch of a
%                             transformer (parallel R/L or R/XLl)
%                             or one line TYPE=0 for a mutual impedance
%                             (series R/L or R/XL)
%  
%                        Negative value:  transmission line length (km)
%                        ---------------
%                         For a transmission line, the R,L,C or R/Xl/Xc values
%                         must be specified in (ohm/km) or (ohm,mH,uF /km)
% 
%                 R    : Branch resistance (ohms or pu)
%                 Xl   : Branch inductive reactance  (ohms or pu at FREQ_SYS)
%                        or transformer winding leakage reactance (ohms)
%                  L   : Branch inductance (mH)
%                 Xc   : Branch capacitive reactance (ohms or pu at FREQ_SYS)
%                        (The negative sign of Xc is optional)
%                  C   : Capacitance (uF)
%                  U   : Nominal voltage of transformer winding
%                        Same units Volts or kV must be used for each winding.
%                        For a mutual (TYPE=3), this value must be set to zero.
% 
%                        Zero values
%                        ----------- 
%                        For R, L or Xl, C or Xc, in a series or parallel branch
%                        indicates that the corresponding element does not exist.
% 
%                        Restrictions for transformers and mutuals
%                        -----------------------------------------
%                      - Null values are not allowed for winding resistances
%                        of transformers and mutuals. Specify a very low value
%                       (e.g. 1e-6 pu based on rated voltage and power)
%                        to simulate a quasi ideal transformer.
%                        The leakage reactances can be set to zero.
%                      - The resistive part of the magnetizing branch of a   
%                        transformer must have a finite value. Specify a very
%                        high value (low losses, e.g 1e4 pu or 0.01% based on 
%                        rating) to simulate a quasi ideal transformer.
%                        The inductive part of the magnetizing branch can be 
%                        set to infinite (No reactive losses; specify Xm=0)
%                      - A null value is not allowed for the mutual inductance 
%                        of coupled windings. The resistive part of 
%                        series mutual branch can set to zero. 
% 
%     Format of the SOURCE input matrix
%     =================================
%          Three formats are allowed:
%          5 columns :  All sources are generating the same frequency specified
%                       by FREQ_SYS
%          6 columns : The frequency of each source is specified in col. 6
%          7 columns : This column is used to specify the type
%                      of non linear element modelled by the current source
% 
%          Each line of the SOURCE matrix must be specified according to the
%          following format:
% 
%                  (1)   (2)  (3)    (4)   (5)    [6]    [7]
%                node1 node2  TYPE  AMP   PHASE  [FREQ]  [MODEL]
% 
%          node1,node2 :Node numbers corresponding to the source terminals
%                       Polarity conventions:
%                         Voltage source : Node 1 is the positive terminal.
%                         Current source : Current is flowing out of node 1. 
%                 TYPE : Code indicating type of source
%                        0= voltage source
%                        1= current source
%                  AMP : amplitude of the AC or DC voltage or current (V,A or pu)
%                PHASE : phase of the AC voltage or current (degrees)
%                 FREQ : Frequency (Hz) of the generated voltage or current.
%                        For a DC voltage or current source specify
%                        PHASE=0 and FREQ=0. AMP can be set to a negative value. 
%                        Generated signal:
%                                           AMP*sin(2*pi*FREQ*t+PHASE) for AC
%                                           AMP for DC
%                MODEL : integer specifying the type of non linear element
%                        modelled by the current source (saturable inductance,
%                        thyristor, switch...);  Used by POWER2SYS only.
% 
%  
%     Format of the SWITCHES input matrix
%     =================================
%     Switches are non linear elements simulating mechanical or electronic
%     devices such as circuit breakers diodes or thyristors. As other non linear
%     elements, they are simulated by current sources driven by the voltage
%     appearing across their terminals. Therefore, they cannot have a perfectly
%     zero impedance. They are simulated as ideal switches in series with a
%     series R-L circuit.
%     The switch parameters must be specified  in a line of the SWITCHES matrix 
%     in 7 different columns according to the following format:
% 
%                  (1)   (2)  (3)    (4)   (5)     (6)     (7)
%               node1  node2 STATUS   R    L/Xl    No_I    No_U
% 
%         node1, node2 : Node numbers corresponding to the switch terminals
%               STATUS : Code indicating the initial status of the switch at t=0
%                        0= open
%                        1= closed
%                   R  : Resistance of the switch when closed (ohms or pu)
%                 L/Xl : Inductance of the switch when closed (mH)
%                        or inductive reactance (ohms or pu at FREQ_SYS)
%                        Note: For these last two fields, the same units as
%                              specified for the RLC matrix (UNIT) must be used.
%                              Null inductance values are not allowed. However,
%                              the resistance value can be set to zero.
% 
%                        The next two fields specify the current input number
%                        and the voltage output number to be used for 
%                        interconnecting the switch model to state-space block
% 
%                 no_I : Current input number coming from the output of
%                        the switch model.
%                 no_U : Voltage output number driving the input of the 
%                        switch model.
% 
%     Format of the LINE_DIST matrix
%     ==============================
%            Each row of the LINE_DIST matrix is used to specify
%            a distributed parameter transmission line.
%            The number of columns of LINE_DIST depends on the number of phases
%            of the transmission line.
%            For a NPHASE line, the first (4+3*NPHASE+NPHASE^2) columns are used.
%            For example, for a three-phase line, 22 columns are used.
% 
%                  (1)   (2)   (3)   (4)  (5...                 ...)
%               NPHASE  No_I  No_U  LONG  L/Xl   Zc  Rm   SPEED Ti
% 
%            NPHASE = Number of phases of the transmission line
%             No_I  = Input number in the SOURCE matrix corresponding to the
%                     first current source Is_1 of the line model.
%                     Each line model uses 2*NPHASE current sources specified
%                     in the SOURCE matrix as follows:
%                     Is_1 Is_2 ...Is_nphase for the sending end followed by
%                     Ir_1 Ir_2 ...Ir_nphase for the receiving end.
%             No_U  = Output number of the state-space corresponding to the
%                     first voltage output Vs_1 feeding the line model.
%                     Each line model uses 2*NPHASE voltage outputs
%                     in the SOURCE matrix as follows:
%                     Vs_1 Vs_2 ...Vs_NPHASE for the sending end followed by
%                     Vr_1 Vr_2 ...Vr_NPHASE for the sending end followed by
%            LONG   = Length of the line (km)
%              Zc   = Vector of the NPHASE modal characteristic impedances (ohms)
%              Rm   = Vector of the NPHASE modal series linear resistances
%                     (ohms/km)
%            SPEED  = Vector of the NPHASE modal propagation speeds (km/s)
%              Ti   = Transformation matrix from  mode to phase currents
%                     such that Iphase=Ti.Imode
%                     The  NPHASE*NPHASE matrix is given in vector format
%                     [col_1,col_2, ... col_NPHASE]
% 
%  Format of the YOUT matrix
%  =========================
%    The desired outputs are specified by a string matrix (YOUT). Each line of
%    the YOUT matrix must be an algebraic expression containing any linear
%    combination of states and state derivatives specified according to the
%    following format:
%                  
%                     Uc_bn  : Capacitor voltage of branch #n
%                     Il_bn  : Inductor current of branch #n
%           dUc_bn,  dIl_bn  : Derivative of Uc_bn or Il_bn
%                    Un, In  : Source voltage or current specified by line #n
%                              of the SOURCE matrix
%                  U_nx1_x2  : Voltage between node x1 and node x2
%                      I_bn  : Current in branch #n
%                              For a parallel RLC branch, I_bn corresponds
%                               to the total current IR+IL+IC
%                   I_bn_nx  : Current flowing into node x of a transmission 
%                              line specified by line #n of the RLC matrix.
%                              (This current includes the series inductive branch
%                               current and the capacitive shunt current).
% 
%    Each output expression is built from the above voltage and current variable
%    names, constants, variable names, parenthesis and  operators (+-*/^) in
%    order to form a valid MATLAB expression.  
% 
%                   Example :  YOUT=[ '10*I_b1 + Uc_b3 -L2*dIl_b2',
%                                     'U_n10_20                  '];
% 
%    If variable names are used (ex. L2 in the above example), their names and
%    values must be specified by the two input arguments VARY_NAME and VARY_VAL.
% 
%         Sign conventions for voltages and currents
%         ------------------------------------------
%    I_bn Il_bn, In = Branch current, inductor current of branch
%                     or current of source #n 
%                     is oriented from node1 to node2.
%         I_bn_nx   = Current at one end (node x) of a transmission line  
%                     If x= node1, the current is entering the line
%                     If x= node2, the current is going out of the line
%         Uc_bn, Un = Voltage across capacitor or voltage source
%                     = Unode1 - Unode2
%         U_nx1_x2  = Voltage between nodes x1 and x2 = Ux1 - Ux2
% 
% 
%    

function powerinit
%MATLAB Tour Partial Function Help:  pwr_con
%
%  POWERINIT Set or reset x0 state-space initial values for an existing model
% 
%     powerinit(system,'look')   : display current values of states variables,
%     powerinit(system,'reset')  : reset to zero x0 vector of system model,
%     powerinit(system,'steady') : set x0 vector for steady-state simulation,
%     powerinit(system,'set',P)  : set x0 vector equal to P vector, 
%     powerinit(system,'setb',StateVariableName,Value) 
% 	                           : set StateVariableName to Value.
% 
%     

function powerflow
%MATLAB Tour Partial Function Help:  pwr_con
%
%  FLOWMAC is a utility function used to solve a load flow in a three-phase
%  multi-machine power system built with the Power System Blockset.
%  FLOWMAC also initializes the SIMULINK model so that the simulation starts
%  in steady state.
% 
%     Syntax:  [machines]=powerflow(system,source,inputs,outputs)
%              [machines]=powerflow(system,[],[],[],machines)
%              [machines]=powerflow(system,[],[],[],machines,init)
%              [machines]=powerflow(system,[],[],[],machines,init,freq)
% 
%  Input arguments
%  ===============
%        system : String = Name of the SIMULINK system containing the circuit
%        source : Source matrix (nb_input,7) containing:
%                 col. 1, 2 Node numbers col. 1,2
%                 Col. 3    Source type (0=voltage 1=current) 
%                 Col. 4 5  Magnitude (V or A)  and phase (Degrees)
%                 Col. 6    Frequency (Hz) 
%                 Col. 7    Model type represented by the source type
%                           Two current sources are used for each
%                           machine three- phase winding
%                           stator and rotor
%                           31=Simplified synchronous machine stator
%                           32=Synchronous machine stator
%                           33=Asynchronous machine stator
%                           34=Asynchronous machine rotor
%                           35=Permanent MAgnet stator
%        inputs : String matrix (nb_input,n) of voltage and current  source names
%       outputs : String matrix (nb_output,n) of output names
%      machines : (1,nb_mac) structure array of machine load flow parameters     
%                            See description below.
%          init : flag (0 or 1)  default value=0
%                 init=0 : FLOWMAC will compute its own initial values
%                          for machine currents and motor slip guesses
%                          This option should be used for the first load flow
%                 init=1 : FLOWMAC will use initial conditions 
%                          corresponding to the last load flow
%                          This option may help load flow convergence.
%          freq : System frequency (Hz) used to solve the load flow
%                 Default value freq=60 Hz;
% 
%  The MACHINES structure array is used to specify the reference power P
%  and voltage VT for synchronous machines and reference mechanical power PMEC
%  for asynchronous motors. The same  structure is used as an output argument
%  to return updated values of power (P),  terminal voltage (VT), % mechanical
%  power (PMEC), synchronous machine field Voltage (EF) and motor SLIP.
% 
%      machines : (1,nb_mac) structure array with the following fields:
%         .name : String matrix containing the names of the nb_mac machines
%         .type : Integer specifying type of machine.
%                 31 Simplified alternator;
%                 32 Synchronous machines
%                 33 Asynchronous motor
%                 35 Permanent magnet motor
%      .bustype : Integer specifying machine bus type 
%                 BUSTYPE=1 : PV bus ; Voltage(MACHINES.VT )
%                             and active power (MACHINES.P) are specified
%                 BUSTYPE=2 : Swing bus ; Voltage (MACHINES.VT) and angle
%                             (MACHINES.PHASE) are specified.
%                             The power will be adjusted to balance the 
%                             power generated or absorbed by other machines
%                             and sources plus loads and losses.
%                 If the circuit contains at least one voltage source
%                 No swing is needed. All machine buses are declared type 1.
%                 If the circuit contains no voltage source, one machine
%                 must be specified as a swing bus (BUSTYPE=2).
%                         
%        .input : Integer =index to the line of the INPUTS string matrix
%                 corresponding to the machines I_A current source 
%       .output : Integer =index to the line of the OUTPUTS string matrix
%                 corresponding to the machines U_AB output
%            .P : Three-phase active powers (watts)
%                 For the swing bus, the specified power is the initial guess.
%            .Q : Three-phase reactive powers (watts)
%                 Sign conventions: For synchronous machines: P,Q>0 indicate
%                 power going out of  the machine (generator mode).
%                 For asynchronous machines P, Q >0 indicate power entering
%                 the machine (motor mode).
%           .Vt : Machine terminal A-B voltage (volts rms);
%         .Phase: Phase angle of the A-Neutral terminal voltage (degrees)
%                 for the synchronous machine declared as swing bus (BUSTYPE=2)
%           .Ef : Field voltage of synchronous machines (pu)
%          .Pmec: Mechanical power (pu) .P>0 for synch. machines in generator
%                 mode and for asynchronous machines in motor mode.
%          .slip: slip of asynchronous machines (pu)
%        .torque: mechanical torque (N.m)
% 
%  Output argument
%  ===============
%      machines : (1,nb_mac) machine structure array
% 
%                -If number of input argument = 4  the MACHINES structure is
%                 returned with  initialized fields  NAME TYPE INPUT and OUTPUT.
%                 P, Q U Vt Phase Ef Pmec are set to zero. BUSTYPE is set to 1;
% 
%                -If number of input argument = 5 or 6 the MACHINES structure is
%                 used as an input argument to specify the desired power flow
%                 and as an output argument to return the load flow solution.
%                 FLOWMAC returns an updated MACHINES structure with
%                 new values of P Q VT PHASE EF PMEC and SLIP according to the
%                 load flow solution;
% 
%                -For synchronous machines declared with MACHINES.BUSTYPE=1,
%                 specify the desired active power and voltage in MACHINES.P and
%                 MACHINES.VT.
%                 The obtained active and reactive powers are returned in
%                 MACHINES.P and MACHINES.Q. The required mechanical power is
%                 returned in MACHINES.PMEC.
% 
%                -For the machine declared with MACHINES.BUSTYPE=2, specify
%                 voltage and phase angle in MACHINES.VT and MACHINES.PHASE. 
%                 The obtained active and reactive powers are returned in
%                 MACHINES.P and MACHINES.Q. The required mechanical power is
%                 returned in MACHINES.PMEC.
% 
%                -For asynchronous machines (MACHINES.BUSTYPE=3), specify
%                 the desired mechanical power in MACHINE.PMEC. 
%                 The obtained active and reactive powers are returned in
%                 MACHINES.P and MACHINES.Q and the obtained mechanical power
%                 is returned in MACHINES.PMEC. Slip is returned in MACHINES.SLIP.
%               
%    G. Sybille (IREQ)  June 1997,September 1997,Last revision: 08-07-98.
%    Copyright (c) 1997-1998 by TEQSIM International, Inc., under sublicense 
%    from Hydro-Quebec, and The MathWorks, Inc.  All Rights Reserved.
%    $Revision: 1.3 $

function psbflowsolv
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbflowsolv is a Simulink model

function powerlib
%MATLAB Tour Partial Function Help:  pwr_con
%
%powerlib is a Simulink model

function powerlib_extras
%MATLAB Tour Partial Function Help:  pwr_con
%
%powerlib_extras is a Simulink model

function powerlib_models
%MATLAB Tour Partial Function Help:  pwr_con
%
%powerlib_models is a Simulink model

function powergui_loadflow
%MATLAB Tour Partial Function Help:  pwr_con
%
%  POWERGUI_LOADFLOW  Graphical user interface for the Machine Load Flow.
% 
%     POWERGUI_LOADFLOW opens a visual tool to compute load flow for 
%     circuits that contains machines.
% 
%     

function powergui_state
%MATLAB Tour Partial Function Help:  pwr_con
%
%  POWERGUI_STATE  Graphical user interface for initial states setting.
% 
%     POWERGUI_STATE opens a visual tool to set initial states of an electrical
%     model build with the Power System Blockset.
% 
%     

function powergui_steady
%MATLAB Tour Partial Function Help:  pwr_con
%
%  POWERGUI_STEADY   Graphical user interface for steady-state informations.
% 
%     POWERGUI_STEADY  opens a visual tool that displays steady-state
%     informations for an electrical model build with the Power System Blockset.
% 
%     

function psbhelp
%MATLAB Tour Partial Function Help:  pwr_con
%
%  PSBHELP Points Web browser to the HTML help file
%          corresponding to this Power System Blockset block.

function psbfilter
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbfilter is a Simulink model

function psbtransient
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbtransient is a Simulink model

function psbtransfo
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbtransfo is a Simulink model

function psbtransfosat
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbtransfosat is a Simulink model

function psbsurgnetwork
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbsurgnetwork is a Simulink model

function psbrectifier
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbrectifier is a Simulink model

function psbconverter
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbconverter is a Simulink model

function psbswitching
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbswitching is a Simulink model

function psbmosconv
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbmosconv is a Simulink model

function psbbuckconv
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbbuckconv is a Simulink model

function psbloadshed
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbloadshed is a Simulink model

function psbturbine
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbturbine is a Simulink model

function psbpwm
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbpwm is a Simulink model

function psbpmmotor
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbpmmotor is a Simulink model

function psbfilterbode
%MATLAB Tour Partial Function Help:  pwr_con
%
%  PSBFILTERBODE plots the impedance versus frequency characteristic of psbfilter demo.

function psbturbinit
%MATLAB Tour Partial Function Help:  pwr_con
%
%    Copyright (c) 1997-1998 by TEQSIM International, Inc., under sublicense 
%    from Hydro-Quebec, and The MathWorks, Inc.  All Rights Reserved.
%    $Revision: 1.3 $

function psbcompensated
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbcompensated is a Simulink model

function psbdcdrive
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbdcdrive is a Simulink model

function psbregulator
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbregulator is a Simulink model

function psbfrequency
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbfrequency is a Simulink model

function psbhvdc
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbhvdc is a Simulink model

function psbregulinit
%MATLAB Tour Partial Function Help:  pwr_con
%
%    Copyright (c) 1997-1998 by TEQSIM International, Inc., under sublicense 
%    from Hydro-Quebec, and The MathWorks, Inc.  All Rights Reserved.
%    $Revision: 1.3 $

function psbregulset
%MATLAB Tour Partial Function Help:  pwr_con
%
%  synchronous machine parameters (p.u)

function psbreguldelta
%MATLAB Tour Partial Function Help:  pwr_con
%
%  Computing the final (steady) states of the generator
% 
%  Parameters of the generator and network, and coefficients of the 
%  model; at the end delta and omega in steady state.
%  Parameters of the generator and network: from parms7i2.m (Francis);
%  coefficiets of the model: paper Conf IEEE CANADA, May 1996.
% 
%  Parameters of the generator

function psbregulzero
%MATLAB Tour Partial Function Help:  pwr_con
%
%  Prerequisite for computing the steady states of the generator
%  Data: the coefficients of the plant A, c, a, g11,g31, and wf = 1 (speed
%  in st. st.) and df = given (delta in st. st.), all in datagen.m
%  Output: the permanent excitation voltage vFf (vfd in steady
%  state, having a "f" at the end from "final"), essential for 
%  computing the other steady states, in stestagen.m.
%  Method: from the first 3 eqs one find the currents as a function
%  of vFf; using also the eq of vt one finds vFf by the matlab
%  function: fzero('equilgen', 0.01).
% 

function psbmonophaseline
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbmonophaseline is a Simulink model

function psbtriphaseline
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbtriphaseline is a Simulink model

function psbnetsim1
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbnetsim1 is a Simulink model

function psbnetsim2
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbnetsim2 is a Simulink model

function psbbusbar
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbbusbar is a Simulink model

function psbneutral
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbneutral is a Simulink model

function psbground
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbground is a Simulink model

function psbpiline
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbpiline is a Simulink model

function psbmutual
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbmutual is a Simulink model

function psbseriesbranch
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbseriesbranch is a Simulink model

function psbseriesload
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbseriesload is a Simulink model

function psbparalbranch
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbparalbranch is a Simulink model

function psbparalload
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbparalload is a Simulink model

function psbcurrmeasure
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbcurrmeasure is a Simulink model

function psbvoltmeasure
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbvoltmeasure is a Simulink model

function psbaccurrent
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbaccurrent is a Simulink model

function psbdcvoltage
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbdcvoltage is a Simulink model

function psbcontrolcurr
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbcontrolcurr is a Simulink model

function psbcontrolvolt
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbcontrolvolt is a Simulink model

function psbacvoltage
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbacvoltage is a Simulink model

function psbtransformer
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbtransformer is a Simulink model

function psbarrester
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbarrester is a Simulink model

function psbbreaker
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbbreaker is a Simulink model

function psbxfosaturable
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbxfosaturable is a Simulink model

function psbswitch
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbswitch is a Simulink model

function psbsimplealt
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbsimplealt is a Simulink model

function psbsyncmachine
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbsyncmachine is a Simulink model

function psbdiode
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbdiode is a Simulink model

function psbthyristor
%MATLAB Tour Partial Function Help:  pwr_con
%
%psbthyristor is a Simulink model

