Modelica Tutorial with PowerSystems: A tutorial for Modelica simulation

Post on 23-Feb-2017

558 views 17 download

transcript

West Lab

Modelica Tutorial

1

West Lab

OpenModelica• OS

- Linux- Windows- Mac

ØPartly supportedØInstall

• Homebrew• Macport

- Virtual Machine (ubuntu)Ø https://openmodelica.org/download/virtual-

machineØ Installation

1. Install virtualbox2. Download box file, and vmdk file in same

directory3. Double click the box file

Ø Bug: cannot login• Change GUI manager

2

West Lab3

1. Modelica introduction2. Thermal simulation using Modelica3. Exercise1: RL Circuit4. Exercise2: Transmission Loss5. Exercise3: Power World

West Lab

What is Modelica?

4

TUTORIAL – COURSE

Introduction to Object-Oriented Modeling and Simulation with Modelica

Using OpenModelica

Peter Fritzson

Copyright (c) Open Source Modelica Consortium Version 2012

https://www.modelica.org/libraries

A language for modeling of complex physical system.

Primary designed for simulation.

West Lab

What is Modelica?

5

TUTORIAL – COURSE

Introduction to Object-Oriented Modeling and Simulation with Modelica

Using OpenModelica

Peter Fritzson

Copyright (c) Open Source Modelica Consortium Version 2012

https://www.modelica.org/libraries

A language for modeling of complex physical system.

Combine multi-domain modeling

West Lab

What is Modelica?

6

Declarative languageEquations and mathematical functions allow acausal modeling, high level specification, increased correctness

Multi-domain modelingCombine electrical, mechanical, thermodynamic, hydraulic, biological, control, event, real-time, etc…

Everything is a classStrongly typed object-oriented language with a general class concept, Java & MATLAB-like syntax

Visual component programmingHierarchical system architecture capabilities

Efficient, non-proprietaryEfficiency comparable to C; advanced equation compilation,e.g. 300 000 equations, ~ 150 000 lines on standard PC

West Lab

Free/Commercial tools• Simulator

- CommercialØDymolaØCyModelicaØWoflramØSimulationX

- FreeØOpenModelicaØJModelica.orgØModelicac

• Editor- Modelica mode for emacs- UltraEdit- Modelica Plugin (for Eclipse)- Modelica Sublime Text Package- OMEditor

7

• Developer site- https://modelica.org/tools

West Lab

Modelica Free/Commercial Libraries

8

• Modelica Library- Modelica- Power system- Vehicle- Mathematics- Chemical- Building

https://www.modelica.org/libraries

West Lab

Modelica Tutorial

9

• Exercise 1- RL Circuit model

• Exercise 2- Transmission Loss model

• Exercise 3- Power World

West Lab

Exercise 1: RL Circuit

10

• Goal- Making a basic RL circuit model using Modelica language- Executing a simulation and plotting the result- Understanding the relationship between electrical-thermal energy

• Library- Modelica library

West Lab

Exercise 1: RLC Circuit Modeling

11

OpentheOMEdit

West Lab12

1. MakeanewPackage“RLCircuit”2. MakeanewModel“Resistor”3. Addaextendsmodel4. Addaparameter“R”5. Addaequation

West Lab13

extendsModelica.Electrical.Analog.Interfaces.OnePort;parameterModelica.SIunits.Resistance R(start=1);equationv=R*i;

West Lab14

West Lab15

“partial”meansthismodelisincomplete

West Lab16

SI=>Modelica.SIunitsimportSI=Modelica.SIunits;

West Lab17

modelResistorequationv=p.v - nv;0=p.i - n.i;i =p.i;v=R*i;endResistor

West Lab18

Youcancheckyourcodehere

West Lab19

1. Makeanewmodel“RLCircuit”inRLCircuit package2. Add Inductor,Ground, andsinVoltage from

Modelica.Electrical.Analog,andResistor3. Connecteachother

West Lab20

1. Changethestoptime2. simulatethemodel

West Lab

Exercise 1: Simulation result

21

Choosetheresistor1.v

West Lab22

1. RightclicktheRLCircuit2. Clickthe“Duplicate”3. ChooseRLCircuit packageasthe“Path”4. Choosethenewmodel

West Lab23

1. Rightclicktheresistance2. Deletetheblock3. Replacetheresistanceto

Modelica.Electrical.Analog.Basic.Resistor

West Lab24

1. AddFixedTemperature fromModelica.Thermal.HeatTransfer.Sources.FixedTemperature

2. Connecttothereplacedresistor

West Lab25

West Lab26

Simulation results1. ClicktheLossPower andvinRLCircuit22. Comparetheresult

West Lab27

Newplotwindow

West Lab

Exercise 2: Transmission Loss

28

• Goal- Making a simple model representing transmission loss

using PowerSystems library- Using the icon setting- Understanding the outer/inner variables

• Library- PowerSystems

West Lab29

1. OpenFile->SystemLibraries->PowerSystems2. Makeanewmodel

West Lab30

extendsPowerSystems.Basic.Icons.Block;

Icon setting

West Lab31

Clicktheiconview

Icon setting

West Lab32

Icon setting

West Lab33

1. ExtendPartialTwoTerminal2. Add threevariables

YoucansearchthePartialTwoTerminal here

Parameter of the line model

West Lab34

West Lab35

Replaceablepackageinheritsallfunctions/variables/settingsfromPowerSystems libraryEverymodelinPowerSystems inheritsthisPhaseSystem• DCorAC• Phasenumber• Frequency

West Lab36

1. AddequationPhaseSystem.m:NumberofreferenceangleDC:m=0AC:m>0

Equation of the line model

West Lab37

ifPhaseSystem.m >0thenomegaRef =der(PhaseSystem.thetaRef(terminal_p.theta));elseomegaRef =0;endif;v=R*i +omegaRef *L*j(i);zeros(PhaseSystem.n)=terminal_p.i +terminal_n.i;ifPhaseSystem.m >0thenterminal_p.theta =terminal_n.theta;endif

Equation of the line model

West Lab38

Simulation of the line model

West Lab39

1. Set1.FixedVoltageSource, 2.FixedCurrennt,and3.SystemfromPowersystem.Generic

2. OpentheparameterwindowoftheFixedCurrent bydoubleclickandchangetheparameter

Simulation of the line model

West Lab40

1. Set1.FixedVoltageSource, 2.FixedCurrennt,and3.SystemfromPowersystem.Generic

2. OpentheparameterwindowoftheFixedCurrent bydoubleclickandchangetheparameter

Simulation of the line model

West Lab41

1. Confirmyourcodeiscorrect

Simulation of the line model

West Lab42

System:aninterfaceofPhaseSystem setting”inner”worksasaglobalvariable• Omega,theta,andfrequency• DC/AC/AC(3phase)• Initialvalue

Simulation of the line model

West Lab43

System:aninterfaceofPhaseSystem setting”inner”worksasaglobalvariable• Omega,theta,andfrequency• DC/AC/AC(3phase)• Initialvalue

innerPowerSystems.Systemsystem(…

Simulation of the line model

West Lab44

*ModelicaAdvancedTutorial:DevelopingModelingLibrary,MartinOtter,HildingElmqvist

West Lab45

Byclickingtheinformation button,youcanseethedetailedinformation ofthe“System”.

Simulation of the line model

West Lab46

Theresultisconstantvalue

Simulation of the line model

West Lab

Exercise 3: Power World

47

• Goal- Simulating the simplified power grid including

ØVoltageØCurrentØFrequency

- Considering transmission loss, and voltage conversion- Using dynamic wind and electricity consumption data

• Library- PowerSystems

* The Power World uses Generic components with the quasi-static ThreePhase_dq because fast electrical transients and asymmetries are neglected. For more precise simulation of power grid, you can use the SPOT from PowerSystems supporting AC 3 phase.

West Lab

Exercise 3: Power World

48

• Goal- Simulating the simplified power grid including

ØVoltageØCurrentØFrequency

- Considering transmission loss, and voltage conversion- Using dynamic wind and electricity consumption data

• Library- PowerSystems

* The Power World uses Generic components with the quasi-static ThreePhase_dq because fast electrical transients and asymmetries are neglected. For more precise simulation of power grid, you can use the SPOT from PowerSystems supporting AC 3 phase.

West Lab49

Exercise 3: Power World

1. AddSystemfromPowerSystems2. AddPowerPlant,HydroPlant,WindFarm,andCity

fromPowerSystems.Examples.Components

West Lab50

Youcancheckthecontentby1. Rightclicktheblock2. Choose“OpenClass"

Exercise 3: Power World

West Lab51

Exercise 3: Power World

West Lab52

1. Clickthe“TextView”2. ChangetheWindFarm setting

Exercise 3: Power World

West Lab53

windFarm1(redeclare packagePhaseSystem =PowerSystems.PhaseSystems.DirectCurrent)

Exercise 3: Power World

West Lab54

1. AddVoltageConverter,Inverterandline

2. DoubleclickandchangetheparameterofVoltageConverter to380/50

3. DoubleclickandchangethePotentialReference ofInvertertofalse

Exercise 3: Power World

West Lab55

1. AddVoltageConverter,Inverterandline

2. DoubleclickandchangetheparameterofVoltageConverter to380/10

Exercise 3: Power World

West Lab56

1. AddLoadDispatcher fromPowerSystems.Example.PowerWorld.Components

2. AddRealExpression fromModelica.Blocks.Sources

Exercise 3: Power World

West Lab57

1. DoubleclicktheRealExpression2. Settheoutput“y”as“system.omega/2/pi”

Exercise 3: Power World

West Lab58

“pi”isdefined inModelica.Constants1. Click“TextView”2. Add”importModelica.Constants.pi;”

Exercise 3: Power World

West Lab59

1. Justclick“OK”whenyouconnecttheLoadDispatcher andPlants

Exercise 3: Power World

West Lab60

Exercise 3: Power World

1. Doubleclickthe”system”2. Changeini to“tr”(double quotation isrequired)3. Changeftype_par tofalse

West Lab61

Exercise 3: Power World

1. Changethestoptime to8640060(sec)*60*24=86400

West Lab62

Simulation result: Electricity demand and supply

West Lab63

Simulation result: Wind

West Lab64

Simulation result: Frequency

West Lab65

Simulation result: Frequency

Inthesystem,simulation isterminatedwhenthefrequencyexceedthelimitation.

West Lab66

Two Windfarm model

West Lab67

Two Windfarm model

West Lab

SPOT: more precise power-system simulation

68

* The Power World uses Generic components with the quasi-static ThreePhase_dq because fast electrical transients and asymmetries are neglected. For more precise simulation of power grid, you can use the SPOT from PowerSystems supporting AC 3 phase.

West Lab69

Thankyouforyourattention

West Lab70

Converter(DC/AC)

EnergyConsumer

FrequencyData

PowerPlant

West Lab71

HydroDispatch:HydroDispatch[1] = hydroBaseHydroDispatch[2] = hydroDailyHydroDispatch[3] = controlHydro

plantDispatch:plantDispatch[1] = plantScheduleplantDispatch[2] = secondaryControlplantDispatch[3] = primaryControl

𝜃 = 𝜔 $ 2𝜋

LoadDispatcher

West Lab72

PowerPlant

plantDispatch:plantDispatch[1] = plantSchedule = fuel.u1plantDispatch[2] = secondaryControl = add.u1plantDispatch[3] = primaryControl

West Lab73

HydroPlant

HydroDispatch:HydroDispatch[1] = hydroBase = riverControl.uHydroDispatch[2] = hydroDaily = add.u2HydroDispatch[3] = controlHydro

West Lab74

WindFarm

Wind Data

West Lab75

City

West Lab

Open Modelica Library

76

• Simulation Result

city

windFarmhydroPlant

powerPlant

West Lab

IPSL

77