# PowerModelsProtection

Fault study for PowerModels and PowerModelsDistribution

In the future this will also include optimal protection coordation formulations and possibly also protection coordination constraints for optimal switching problems

## Modeling Assumptions

- Generators are modeled as voltage sources behind an impedance. For synchronous generation, this is the subtransient reactance $X_d''$. For inverters, this is currently a virtual resistance. A more accurate model for inverters will take into account their current limits
- Loads are neglected
- Faults are modeled as an admittance matrix

## Usage Example (Balanced Case)

```
using PowerModels, PowerModelsProtection, Ipopt
net = PowerModels.parse_file("case5.raw", import_all=true)
solver = JuMP.with_optimizer(Ipopt.Optimizer)
net["fault"] = Dict()
net["fault"]["1"] = Dict("bus"=>2, "r"=>0.0001)
results = PowerModelsProtection.run_fault_study(net, solver )
print(results)
```

## TODO

*TODO section has moved to issues*

## LLG Fault Model

## Inverter Fault Models

### Grid-Following Inverter

#### Balanced

`k*p = vr*cr - vi*ci`

`k*q = vr*ci + vi*cr`

where `k`

is a decision variable ranging from 0 to 1

### Unbalanced

An inverter under unbalanced conditions will operate
at a fixed power factor *averaged across all phases*
while injecting only positive-sequence current.
This sounds ugly, but the constraints don't appear
to be too bad.

Given

`a = ar + ai = exp(j*2*pi/3) = -1/2 + j*sqrt(3/2`

`a^2 = a2r + j*a2i = exp(j*4*pi/3) = -1/2 - j*sqrt(3/2`

Positive-sequence current constraints:

`car = c1r`

`cai = c1i`

`cbr = a2r*c1r + a2i*c1i`

`cbi = a2r*c1i + a2i*c2r`

`ccr = ar*c1r + ai*c1i`

`cci = ar*c1i + ai*c1i`

Constant power factor constraints:

`k*p = var*car + vbr*cbr + vcr*ccr - vai*cai - vbi*cbi - vci*cci`

`k*q = var*cai + vbr*cbi + vcr*cci + vai*car + vbi*cbr + vci*ccr`

### Grid-Forming Inverter

#### Virtual Resistance Model

`vr`

, `vi`

set from inverter node voltage base power flow
`rs = 0.8 pu`

, gives `1.3 pu`

current into a short
`xs = 0 pu`

#### Current Limiting Model

This model assumes that
`vm`

, `va`

set from inverter node voltage from base power flow

```
vr[c] = kg[c]*vm[c]*cos(va[c])
vi[c] = kg[c]*vm[c]*sin(va[c])
-cmax <= crg[c] <= cmax for c in cnds
-cmax <= cig[c] <= cmax for c in cnds
```

Objective is `sum( sum((vr[c] - vm[c]*cos(va[c]))^2 + (vi[c] - vm[c]*sin(va[c]))^2 for c in cnd) for g in inverter_gens)`

#### Current Limiting Model with Droop

Constraints

```
Vg0 = V0 + zg*Ig0
V = kg*Vg0 - Z*Ig
|Ig| <= Igmax
```

Objective is `sum( (vg - vg0)^2 for g in inverter_gens)`

This code is provided under a BSD license as part of the Multi-Infrastructure Control and Optimization Toolkit (MICOT) project, LA-CC-13-108.