Switched reluctance motor drive simulation using open-source software
Abstract
PSSOH 2024 paper and presentation on open-source software application for motor drive simulation. The lecture was recorded and the video of the presentation held by Assist. Prof. Bogdan Brković, together with the Q&A session in Serbian language is available at YouTube: https://youtu.be/p_xD-VDllfE.
Full text
PSSOH 2024, DOI: https://doi.org/10.5281/zenodo.13892004 SWITCHED RELUCTANCE MOTOR DRIVE SIMULATION USING OPEN-SOURCE SOFTWARE Bogdan Brković1, Milovan Majstorović1, Mateja Ivanović1, Mladen Terzić1 1: University of Belgrade, School of Electrical Engineering, 11000 Belgrade, Serbia e-mails: [email protected],[email protected],[email protected], [email protected] Abstract The switched reluctance motor is a viable magnet-free option for low and medium power applications. Current challenges limiting widespread application are the inherent noise and vibration issues. Mitigation of these problems while retaining the required performance can be achieved by improving the motor design and control. The research presented in this paper is aimed at developing a detailed simulation model of the switched reluctance motor drive system. This process includes: motor parameter identification based on finite-element analysis, composition of the joined model of the motor and dedicated power converter, automatic simulation running, output data logging, and processing. The entire procedure is conducted using open-source software platforms. The developed modelling and simulation approach enables the determination of motor and converter performance indicators, including a detailed calculation of semiconductor losses and temperature rise. Furthermore, this provides a foundation for applying design and control optimization algorithms to achieve enhanced performance characteristics. Keywords: switched reluctance motor, power converter, drive, modelling, simulation. 1 Introduction The switched reluctance motor (SRM) is recognized as a topology of interest in low and medium power applications such as home appliances and small electric vehicles [1–4]. Compared to its main counterpart, the permanent magnet synchronous machine (PMSM), the SRM has a distinct advantage of being a magnet-free device. This feature makes the SRM more cost-effective and eco-friendly, considering the volatility of the permanent magnet market and the devastating procedure of rare-earth material extraction. The major drawbacks of the SRM are noise and vibration inherently related to the double-salient structure [5]. To overcome these challenges, improved motor and converter design and control approaches are required. The SRM design procedure is based on analytical calculations or finite element analysis (FEA). The two approaches can be combined to take advantage of the FEA accuracy and the time-efficiency of the analytical approach. This is commonly done by using FEA to obtain flux and torque lookup tables which are then used to compose the SRM dynamic model. This model can then be used to simulate SRM operation under various conditions using any software package equipped with standard nonlinear differential equation solvers. 1
The SRM can be supplied exclusively from a dedicated power converter. Multiple topologies have been proposed over the years [6,7]. The most commonly employed topology is the Asymmetric HalfBridge Converter (AHBC), due to its relatively low cost, control flexibility, and simplicity. A simulation of the SRM drive is required in the development stage to assess the drive performance under various operating modes. Both the motor and converter need to be simulated in sufficient detail within a reasonable time frame. As previously stated, the motor can be simulated in great detail using FEA software, however such simulations are by no means time-efficient. On the other hand, there is a wide array of circuit simulation software packages. Notably, LTspice is a powerful open-source simulation tool incorporating actual device models [8]. This allows an accurate prediction of converter performance, most notably calculation of losses and dynamic behaviour. There is only the matter of interfacing the converter model to the SRM model. In this paper, a detailed SRM model based on flux and torque lookup tables is developed and implemented in the LTspice circuit simulation tool. The lookup tables are generated using the FEA software platform FEMM 4.2 [9] in combination with GNU Octave [10]. To the best of our knowledge, no previous implementations of an SRM model in a circuit analysis sofware such as LTspice have been reported. Finally, the complete drive model is assembled in LTspice. Interaction with the LTspice model (starting and stopping the model execution, output data recording and processing) is conducted entirely using a dedicated Python script. The paper is composed as follows. Following the Introduction, fundamental information regarding the applied SRM and AHBC are given in section 2. Details regarding the development and implementation of the SRM drive model using open-source software platforms are given in section 3. The model results are displayed in section 4 and the conclusions and plans for future work are presented in section 5. 2 SRM drive overview The SRM under investigation has six stator poles and ten rotor poles. Such a machine is aptly referred to as a 6/10 SRM. The machine cross-section is displayed in Figure 1. The operating principle is relatively simple - when a given phase is energized a magnetic field established in the corresponding stator poles attracts the nearest rotor poles. By applying excitation in an appropriate order and with suitable timing, high average torque with minimal oscillations is obtained. Typical SRM waveforms are illustrated in Figure 2. The diagrams display the phase inductance, excitation voltage and current, and electromagnetic torque developed by a single phase. The variation of quantities is shown with respect to the rotor angle. Characteristic positions of the rotor with corresponding qualitative flux line distributions are also displayed. Two characteristic rotor positions are identified: the unaligned position, when the stator pole is between two rotor poles and the inductance value is minimal, and the aligned position, when the axes of stator and rotor poles are aligned and the inductance value is maximal. The inductance variation between these two positions is approximately linear, disregarding magnetic saturation. The phase is usually energized before the overlap between the stator and rotor poles begins and the current is quickly increased. Prior to reaching full alignment, the voltage polarity is reversed and the current is reduced back to zero, after which the voltage is maintained at zero value until the next cycle. The obtained electromagnetic torque is mostly positive, however a slight negative pulse cannot be avoided practically, due to the finite current decrease rate. Positive torque is generated when the inductance is increasing and vice versa. No torque is generated when the inductance is constant. Without diving to deep into the SRM model itself, only the basic 2
Figure 1: SRM cross-section equations are given as follows [5]: uξ=Rξiξ+dψξ dt=Rξiξ+Lξ(iξ, θ)diξ dt+∂Lξ(iξ, θ) ∂θ iξ,(1) Teξ =1 2i2 ξ ∂Lξ(iξ, θ) ∂θ ,(2) θ=∫Ωdt. (3) The variables and parameters in the previous expressions are defined as: •ξdenotes the observed phase (A, B, or C), •uξ,iξ, and ψξare the voltage, current, and flux linkage of the observed phase, •θis the rotor position with respect to phase A, •Ωis the rotor angular speed, •Teξ is the electromagnetic torque generated by the observed phase, and •Rξand Lξare the resistance and inductance of the observed phase. It should be emphasized that the inductances are dependent on current values due to magnetic saturation, which makes the SRM model highly non-linear. This non-linearity will be accounted for by modelling the SRM using flux and torque lookup tables obtained from FEM simulations, as elaborated in section 3. The motion equation is excluded from the model, as the rotor speed is considered constant in all upcoming analyses. The SRM supply voltage obviously needs to be varied frequently which can only be accomplished by means of a power converter. Considering the required voltage values (+VDC,−VDC , and 0), a two-level converter such as an H-bridge would be suitable. However, considering the fact that the 3
10 20 30 40 50 60 70 0 Lmax Angle (degrees) Inductance (H) ∙×∙×∙× 010 20 30 40 50 60 70 VDC Voltage (V) −VDC Angle (degrees) Current (A) Lmin Imax 010 20 30 40 50 60 70 Torque (Nm) Angle (degrees) Figure 2: Example of SRM waveforms for a typical operating mode SRM current is unidirectional, it is very common in practice to apply the asymmetric half-bridge converter (AHBC). The AHBC topology and its connections to respective SRM phases is schematically displayed in Figure 3. The AHBC structurally resembles a standard H-bridge module, except that it only employs two switches (most commonly MOSFET or IGBT) and two diodes for each phase. As previously stated, this is due to the fact that the current is unidirectional, which even eliminates the need for reverse diodes in parallel with the switches (even though these are inherently present in most cases). Reducing the number of power switches reduces the total component cost, which makes the AHBC a preferred option for SRM supply. Moreover, the control algorithm is simpler, as only two switches per phase are controlled, and the switching losses tend to be lower. The only drawback is that the converter is composed of discrete components which may increase manufacturing cost and complexity. The control approach will now be briefly explained for a typical operating mode. Example voltage and current waveforms along with corresponding AHBC switching states are shown in Figure 4. Hysteresis current control is commonly applied in the following manner: • positive DC link voltage VDC is applied by turning on the power switches when the turn-on angle (θon) is exceeded, which causes the current to increase; 4
LALBLC VDC QA+ QADA+ DAQB+ DB+ QB-DBQC+ DCQCDC+ Figure 3: Schematic display of SRM phases supplied from an AHBC • when the current exceeds the value Iref + ∆I(Iref is the reference and ∆Ithe hysteresis band), the lower switch is turned off and approximately zero voltage is applied to the phase winding, causing the current to gradually decrease; • when the current drops to Iref −∆I, the lower switch is again turned on and the current increases due to positive DC link voltage; • the previous two steps are repeated until the turn-off angle (θoff ) is reached, after which both switches are turned off and negative voltage −VDC is applied through the diodes; • the negative voltage reduces the current to zero. It should be noted that either of the two switches can be manipulated to achieve hysteresis control, and normally both are used alternately to achieve an even loss distribution. The selection of turn-on and turn-off angles is crucial for maximizing the average torque and minimizing the torque ripple. Different values of θon and θoff should be applied for various speeds and loads to achieve optimal operating conditions. 3 Model synthesis and implementation The flowchart depicting the model development and execution procedure is shown in Figure 5. The applied software tools are indicated and the key outputs are highlighted. The entire procedure can be divided into three four steps: (i) FEM model composition, (ii) FEM model execution by means of Octave code, (iii) LTspice model assembly, and (iv) LTspice model execution by means Python code. After completing steps (i) and (ii), flux and torque lookup tables are generated. Based on these lookup tables, the LTspice model is composed in step (iii). Finally, a Python script for automationg the LTspice simulation execution and output data logging is developed in step (iv). The obtained outputs are the SRM drive performance indicators, such as currents, voltages, power switch losses, etc. Each of the listed steps is analysed in detail in the following subsections. Subsection 3.1 describes steps (i) and (ii), whereas subsection 3.2 is concerned with steps (iii) and (iv). 5
QA+ QADA+ DAvA VDC QA+ QADA+ DAiA vA VDC QA+ QADA+ DAiA vA VDC iA 1 2 3 (a) AHBC switching states θ 1 31 22121 ΔI iA uA θ VDC -VDC Iref θon θoff (b) SRM voltage and current waveforms Figure 4: Illustration of SRM current control using AHBC 3.1 Flux and torque lookup table generation (FEMM & Octave) The FEM model is developed based on the construction data of the 6/10 SRM displayed in Figure 1. The open-source software platform FEMM 4.2 for finite element-based electromagnetic calculations is used. The SRM geometry is plotted and appropriate materials are assigned to different areas. After this is completed, the machine geometry is divided into a great number of small (finite) triangular elements. The obtained finite element mesh is displayed in Figure 6a. When the mesh of appropriate density is formed, the calculation is conducted and the field distribution within the analysed domain (machine) is obtained. An example flux density distribution is displayed in Figure 6b. Manual model execution is generally inconvenient, as many input parameters need to be set prior to each calculation. This becomes very cumbersome and time-consuming when a wide range of operating modes needs to be analysed. In this paper, the FEM model was used for obtaining flux and torque lookup tables (LUTs) with respect to winding currents and rotor angular position. As the accuracy of the resulting SRM model is directly dependent on the resolution of these LUTs, over 2000 simulations for various current and rotor angle combinations are required. This process is therefore automated by interfacing FEMM with GNU Octave by means of the OctaveFEMM toolbox [11]. This toolbox allows Octave to modify the model, run the simulation, and access the output values. The process of generating flux and torque LUTs is depicted in the flowchart of Figure 7a. Note that 6
V1 36 D1 RBQ30NS45B R1 0.2 V2 V=IF(V(theta)<18,5,0) D3 RBQ30NS45B BSC019N06NS_L0 M1 M2 BSC019N06NS_L0 L 1 MechTorque 0.5 Jm 0.002 Torque 1 w MechTorque 57.325 C1 1 MOD IN OUT X1 thetaBuff 1 w1 187500 C2 1 Flux 1 StatorWind 1000 V4 V=IF(((V(theta)<18) & (V(Sch)>0.1)),5,0) I1 24000 Torque2DLookup X YZ X2 Phi2DLookup X YZ X3 R2 0.1 R3 0.1 Struja1 L 1 Vt={Vt} Vh={Vh} A1 R4 15k R5 15k thetaBuff1 0.5 Struja2 L 1 R6 10 R7 10 C3 1n C4 1n B1 L 1 B2 V=IF(TIME<1us,V(Struja),ABS(V(Struja))) B3 V=sgn(V(Struja))*V(Phi_abs) C5 1e-11 R8 0.5e9 G1 A AG1 B L1 C theta_0 theta_0 theta struja_0 theta Tem Tem Phi L1 G1_1 G1_1 sta1 Sch theta Phi_abs Struja Phi Struja_abs M1H .lib irfh5004pbf.spi .tran 0 0.005s 1us 1e-6 uic .lib SiR180DP_PS.LIB .lib OptiMOS_60V_PSpice.lib .param N=100 .ic V(theta_0)=0 .ic V(struja_0)=0 .param Ns=116 .options abstol=1e-10 .options reltol=0.001 .param Vt=12 Vh=0.2 Biblioteke: RESULTS FEMM 4.2 FLUX AND TORQUE LOOKUP TABLES Figure 5: Flowchart of the model synthesis, implementation, and execution procedure M330-35A M330-35A Copper [I1:-58] Copper [I1:58] Copper [I2:58] Copper [I2:-58] Copper [I3:-58] Copper [I3:58] Copper [I1:58] Copper [I1:-58] Copper [I2:-58] Copper [I2:58] Copper [I3:58] Copper [I3:-58] Air Air Air Air Air Air Air Air Air (a) Density Plot: |B|, Tesla 1.284e+000 : >1.352e+000 1.216e+000 : 1.284e+000 1.149e+000 : 1.216e+000 1.081e+000 : 1.149e+000 1.014e+000 : 1.081e+000 9.461e-001 : 1.014e+000 8.785e-001 : 9.461e-001 8.110e-001 : 8.785e-001 7.434e-001 : 8.110e-001 6.758e-001 : 7.434e-001 6.082e-001 : 6.758e-001 5.407e-001 : 6.082e-001 4.731e-001 : 5.407e-001 4.055e-001 : 4.731e-001 3.379e-001 : 4.055e-001 2.704e-001 : 3.379e-001 2.028e-001 : 2.704e-001 1.352e-001 : 2.028e-001 6.763e-002 : 1.352e-001 <5.607e-005 : 6.763e-002 (b) Figure 6: SRM cross-section in FEMM 4.2 environment: (a) finite element mesh, (b) flux density distribution obtained after calculation 7
the software tools applied in each stage of the procedure are indicated by appropriate icons. The model is generated using only FEMM, although this step can also be carried out using Octave. After the model is formed, input values are provided to Octave, specifically the set of currents and rotor angles for LUT formation. A loop is then initiated, wherein FEMM calculations are conducted for all current and angle combinations. This part of the process is automated: Octave invokes the model, sets the current and angle to the required values, runs the model, and obtains the flux and torque values. Upon exiting the loop, two-dimensional flux and torque LUTs are formed and exported to text files for further use in forming the SRM numerical model. With a 1◦angle resolution and 1A current resolution, the LUT contains a total of 2263 entries. This rule of thumb ensures high modelling accuracy while maintaining the number of executed FEM simulations and total LUT generation time within reasonable limits. Additionally, increasing the number of data points in the LUT eventually reduces the simulation efficiency without significantly improving the accuracy. The graphical representation of the flux and torque LUTs in the form of surface diagrams is given in Figure 7b. SRM geometry Create the FEMM model Vectors of current values and rotor angles Set the current and rotor position Run the FEMM model Flux and torque LUTs Winding fluxes and electromagnetic torque YES NO All simulations completed? (a) (b) Figure 7: (a) Flux and torque LUT calculation flowchart, (b) flux and torque LUTs represented by 3D diagrams 8
3.2 SRM drive model assembly and execution (LTspice & Python) As indicated in Figure 5, the flux and torque LUTs are used to form an SRM model in the LTspice environment. While the converter model is implemented in a straightforward manner, the SRM model includes electrical, magnetic, and mechanical quantities. Therefore, appropriate electrical equivalents need to be employed. Moreover, LUT implementation in LTspice is quite involved. Software tools that enable a simpler SRM model formulation are available, but none of them provides accurate modelling of power switching device dynamics and losses. As the power converter is an integral and most sensitive part of the SRM drive, a high-fidelity model is crucial for proper performance prediction. The complete SRM drive model implemented in LTspice is displayed in Figure 8. The model can be divided into several functional entities as designated in the figure: 1. The main part of the model – converter circuit connected to the phase winding terminals. The phase winding is modelled as resistor connected in series with a dependent voltage source corresponding to the winding electromotive force (EMF). When the EMF is calculated, the current is obtained simply as: iA=uA−eA RA ,(4) where uAis the terminal voltage, eAis the EMF, and RAis the phase winding resistance. 2. The EMF calculation circuit based on differentiating the winding flux. For this purpose, the flux value is assigned to a voltage controlled current source connected in series with an inductor. The current value corresponds to the flux and the inductance corresponds to the number of turns per phase, thereby essentially obtaining the EMF value as: eA=Ns dΦA(iA, θ) dt,(5) where Nsis the number of turns per phase (“inductance”), and ΦAis the flux per pole (“current”). Note that a series RC snubber is added in parallel to avoid numerical issues due to connecting a current source in series with an inductor. The RC element filters out the high-frequency noise caused by the switching actions. The flux value is obtained from the LUT as a function of winding current iAand rotor angle θ. ② ①⑥ ⑤ ③ ④ V1 36 D1 RBQ30NS45B R1 0.2 V=IF(V(theta)<18,5,0) V2 D3 RBQ30NS45B BSC019N06NS_L0 M1 M2 BSC019N06NS_L0 L 1 MechTorque 0.5 Jm 0.002 Torque 1 w MechTorque 57.325 C1 1 MOD IN OUT X1 thetaBuff 1 w1 187500 C2 1 Flux 1 StatorWind 1000 V=IF(((V(theta)<18) & (V(Sch)>0.1)),5,0) V4 I1 108000 Torque2DLookup X YZ X2 Phi2DLookup X YZ X3 R2 0.1 R3 0.1 Struja1 L 1 Vt={Vt} Vh={Vh} A1 R4 15k R5 15k thetaBuff1 0.5 Struja2 L 1 R6 10 R7 10 C3 1n C4 1n B1 L 1 B2 V=IF(TIME<1us,V(Struja),ABS(V(Struja))) B3 V=sgn(V(Struja))*V(Phi_abs) 1e-10 C5 R8 1e9 C6 1e-12 GU A AGU B L1 C theta_0 theta_0 theta struja_0 theta Tem Tem Phi L1 GL GL sta1 Sch theta Phi_abs Struja Phi Struja_abs M1H VTem .lib irfh5004pbf.spi .tran 0 0.005s 1us 1e-6 uic .lib SiR180DP_PS.LIB .lib OptiMOS_60V_PSpice.lib .param N=100 .ic V(theta_0)=0 .ic V(struja_0)=0 .param Ns=116 .options abstol=1e-10 .options reltol=0.001 .param Vt=12 Vh=0.2 Biblioteke: Figure 8: LTspice model of the SRM drive: 1 – converter circuit, 2 – SRM phase winding model, 3 – flux and torque calculation from LUTs, 4 – rotor angle calculation, 5 – control circuits, 6 – model inputs (parameters, libraries, initial conditions) and simulation settings 9
get-up-and-running-with-ltspice.html. Accessed: 2024-30-8. [9] D. Meeker. Finite element method magnetics version 4.2 user’s manual, May 2020. Available at http://www. femm.info/Archives/doc/manual.pdf. [10] Gnu octave 9.2.0 manual, 2024. Available at https://docs.octave.org/interpreter/. [11] D. Meeker. Finite element method magnetics: Octavefemm version 1.2 user’s manual, Mar 2018. Available at http://www.femm.info/Archives/doc/octavefemm.pdf. [12] Pyltspice 5.3.2 documentation, 2024. Available at https://pyltspice.readthedocs.io/en/latest/ modules/modules.html. Appendix The Python code used to manipulate the LTspice model of the SRM drive is given below. Parts of the code not specific to the Python–LTspice interface are omitted and replace by vertical dots. User defined functions read_data and calcVals dedicated to reading, processing, and plotting output data, are given after the main program. Main program 1# Import PyLTSpice modules 2from PyLTSpice import SimRunner 3from PyLTSpice import SpiceEditor 4from PyLTSpice import LTSpiceLogReader 5from PyLTSpice import RawRead , Trace , RawWrite 6. 7. 8. 9# Import user defined functions 10 from functions import * 11 . 12 . 13 . 14 # Define vectors of rotating speeds and currents 15 nmeh_vec = [2000, 4000, 8000, 12000, 18000] # rotating speeds (rpm) 16 Iref_vec = [2, 4, 6, 8, 10, 12, 14] # reference currents (A) 17 18 # Run the simulations for all speed and ref. current values 19 for Iref in Iref_vec: 20 for nmeh in nmeh_vec: 21 22 # Select Spice model and generate netlist 23 LTC = SimRunner(output_folder='./temp'+str(nmeh), timeout=6000.0) 24 LTC.create_netlist('AHB.asc') 25 netlist = SpiceEditor('AHB.net') 26 27 # Calculate speed in (deg/s) and define the angular period 28 ndegs = nmeh*360.0/60.0 # speed (deg/s) 29 theta_per = 36.0 # angle corresponding to one electrical period (deg) 30 tsim = 2.0*theta_per/(nmeh*360.0/60.0) # simulation length = two periods 31 # netlist.set_parameters(res=0, cap=100e-6) 32 33 # Set the values of operating speed , reference current , and hysteresis band 34 netlist.set_component_value('I1',str(ndegs)) 35 netlist.set_parameter('Vt', Iref) 36 netlist.set_parameter('Vh', 0.2) 37 38 # Simulation settings 39 netlist.add_instructions( 40 "; Simulation settings", 41 ";.param run = 0", 42 ".tran 0 " +str(tsim) + " 0.1us 1e-6 uic" # makes a transient simulation 43 ) 44 netlist.set_parameter('run', 0) 45 46 # Run the simulation 47 print("simulating test") 48 LTC.run(netlist ,timeout=60.0) 49 netlist.reset_netlist() 50 51 # Sim Statistics 52 print('Successful/Total Simulations: ' +str(LTC.okSim) + '/' +str(LTC.runno)) 53 16
54 # Read data from the output (*.raw) file 55 read_data("temp"+str(nmeh)+"/AHB_1.raw") 56 57 # Calculate the average losses of switching devices 58 gubici = calcVals("temp"+str(nmeh)+"/AHB_1.raw") 59 print(gubici) Functions 1########################################################################## 2# read_data --> reads and plots the voltage , current , and torque waveforms 3def read_data(filename): 4 5# Import the RawRead module for reading output traces 6from PyLTSpice import RawRead 7from matplotlib import pyplot as plt 8 9# Read the output traces 10 LTR = RawRead(filename) 11 IR1 = LTR.get_trace("I(R1)")# Current 12 Torque = LTR.get_trace("V(VTem)")# Torque 13 VSRM = LTR.get_trace("V(L1)")# Voltage 14 15 x = LTR.get_trace('time')# Gets the time axis 16 steps = LTR.get_steps() 17 18 # Plot the waveforms 19 for step in range(len(steps)): 20 # print(steps[step]) 21 plt.figure() 22 plt.plot(x.get_wave(step), -IR1.get_wave(step), label=steps[step]) 23 plt.grid() 24 25 plt.figure() 26 plt.plot(x.get_wave(step), Torque.get_wave(step), label=steps[step]) 27 plt.grid() 28 29 plt.figure() 30 plt.plot(x.get_wave(step), VSRM.get_wave(step), label=steps[step]) 31 plt.grid() 32 33 plt.show() 34 35 #################################################################################### 36 # calcVals --> reads and plots switching device losses and calculates average losses 37 def calcVals(filename): 38 39 # Import the RawRead module for reading output traces 40 from PyLTSpice import RawRead 41 from matplotlib import pyplot as plt 42 43 # Read the output traces 44 LTR = RawRead(filename) 45 IM1 = LTR.get_trace("Ix(M1:DRAIN)") 46 IM2 = LTR.get_trace("Ix(M2:DRAIN)") 47 VM1H = LTR.get_trace("V(M1H)") 48 VM1L = LTR.get_trace("V(A)") 49 VM2 = LTR.get_trace("V(A)") 50 51 x = LTR.get_trace('time')# Gets the time axis 52 steps = LTR.get_steps() 53 54 # MOSFET losses 55 # Array initialization 56 PgM1 = [] 57 PgM2 = [] 58 59 # Loss calculation and data plotting 60 for step in range(len(steps)): 61 # Calculate losses at the current time step and add to array 62 PgM1.append ((VM1H.get_wave(step)-VM1L.get_wave(step)) * IM1.get_wave(step)) 63 PgM2.append (VM2.get_wave(step) * IM2.get_wave(step)) 64 65 # Plot the data 66 plt.figure() 67 plt.plot(x.get_wave(step), PgM1[step], label='Pg1') 17
68 plt.plot(x.get_wave(step), PgM2[step], label='Pg2') 69 plt.legend() # order a legend 70 plt.grid() 71 plt.show() 72 73 # Calculate the average losses over the simulation interval 74 PgM1_avg = sum(PgM1[0])/len(PgM1[0]) 75 PgM2_avg = sum(PgM2[0])/len(PgM2[0]) 76 77 # Return the average values of losses 78 return [PgM1_avg , PgM2_avg] 18