# Calculating the branch current

**URL:** <https://discourse.julialang.org/t/calculating-the-branch-current/57768>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [March 23, 2021, 5:09am UTC](https://discourse.julialang.org/t/calculating-the-branch-current/57768 "2021-03-23T05:09:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![priod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/priod/32/53099_2.png) [@priod](https://discourse.julialang.org/u/priod)\
**Post date:** [March 23, 2021, 5:09am UTC](https://discourse.julialang.org/t/calculating-the-branch-current/57768/1 "2021-03-23T05:09:06Z")

</div>

I need some help in calculating the branch current flows using the PowerModels package, and matpower casses.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [March 23, 2021, 5:10am UTC](https://discourse.julialang.org/t/calculating-the-branch-current/57768/2 "2021-03-23T05:10:53Z")

</div>

Please be more specific with your question and show us what you have tried so far with minimal example code.

---

<div class="post-metadata">

**Author:** ![priod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/priod/32/53099_2.png) [@priod](https://discourse.julialang.org/u/priod)\
**Post date:** [March 23, 2021, 5:17am UTC](https://discourse.julialang.org/t/calculating-the-branch-current/57768/3 "2021-03-23T05:17:46Z")

</div>

Hi) Thanks for replying, I am running an AC-OPF, with one additional constraint,

```julia
@NLconstraint(m, Il[i in Nodes, j in Nodes; abs(Y_bus[i,j])>0 && i!=j], (G[i,j]^2+B[i,j]^2)*(v[i]^2+v[j]^2 -4*(v[i]*v[j])) <= s[i,j]*(Y_busnew[i,j]^2 * v[i]^2)+k*(1-s[i,j]))

```

Here, s[i,j] is the variable between 0 and 1, here I am trying to relax the line, my goal is to get the line with the minimum value of “s”. And the factor “k”, I defined it as a bigger number. My problem is, I need to remove this `Y_busnew[i,j]^2 * v[i]^2` with the branch current derived from power flow equations may be.

---

<div class="post-metadata">

**Author:** ![ccoffrin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccoffrin/32/400_2.png) [@ccoffrin](https://discourse.julialang.org/u/ccoffrin)\
**Post date:** [March 23, 2021, 11:32am UTC](https://discourse.julialang.org/t/calculating-the-branch-current/57768/4 "2021-03-23T11:32:55Z")

</div>

Hi @priod, the first thing to clarify if you want to compute the branch current after the optimization is complete or if you want to change the model to optimize the current.

In the former case, the solution that is returned by `run_ac_opf` already has the branch power values in it, you just need to do a little computation to convert those into current values.

In the later case, you need to modify the AC-OPF optimization model that is being solved. The simplest solution there is start with one of these models from PowerModelsAnnex,

> **[PowerModelsAnnex.jl/src/model at master · lanl-ansi/PowerModelsAnnex.jl](https://github.com/lanl-ansi/PowerModelsAnnex.jl/tree/master/src/model)**
>
> master/src/model

and adapt it to your own needs.
