# Adding Flexibility/Storage to Matpower case files in PowerModel

**URL:** <https://discourse.julialang.org/t/adding-flexibility-storage-to-matpower-case-files-in-powermodel/92067>\
**Category:** Optimization (Mathematical)\
**Created:** [December 23, 2022, 10:51pm UTC](https://discourse.julialang.org/t/adding-flexibility-storage-to-matpower-case-files-in-powermodel/92067 "2022-12-23T22:51:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wahee01](https://avatars.discourse-cdn.com/v4/letter/w/aca169/32.png) [@Wahee01](https://discourse.julialang.org/u/Wahee01)\
**Post date:** [December 23, 2022, 10:51pm UTC](https://discourse.julialang.org/t/adding-flexibility-storage-to-matpower-case-files-in-powermodel/92067/1 "2022-12-23T22:51:56Z")

</div>

Hello, I’m attempting to add flexibility/battery to several nodes in the Matpower IEEE9 bus case file. With this method “% hours  
mpc.time\_elapsed = 1.0  
%% storage data  
% storage\_bus ps qs energy energy\_rating charge\_rating discharge\_rating charge\_efficiency discharge\_efficiency thermal\_rating qmin qmax r x p\_loss p\_loss status  
mpc.storage = [  
5 0.0 0.0 20.0 100.0 50.0 70.0 0.8 0.9 100.0 -50.0 70.0 0.1 0.0 0.0 0.0 1;  
7 0.0 0.0 30.0 100.0 50.0 70.0 0.9 0.8 100.0 -50.0 70.0 0.1 0.0 0.0 0.0 1;  
];”, I introduced storage.

As a result, whenever I attempted to execute the OPF of the case file, the error "

 ![Screenshot 2022-12-23 at 5.44.11 PM](https://global.discourse-cdn.com/julialang/original/3X/b/5/b55644325e7160b58dacca7f5d37e806774f80c0.png)  
" appeared. This is my code:  
using PowerModel, Ipopt  
network\_data = PowerModels.parse\_file(“case9bb.m”)  
result=solve\_opf(network\_data, ACPPowerModel, Ipopt.Optimizer)  
PowerModels.print\_summary(result[“solution”])

---

<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:** [December 24, 2022, 5:55pm UTC](https://discourse.julialang.org/t/adding-flexibility-storage-to-matpower-case-files-in-powermodel/92067/2 "2022-12-24T17:55:12Z")

</div>

Have a look at this paper, [[2004.14768] A Flexible Storage Model for Power Network Optimization](https://arxiv.org/abs/2004.14768)

and this example repo, [GitHub - lanl-ansi/energy-storage-example: An example of energy storage optimization using PowerModels](https://github.com/lanl-ansi/energy-storage-example)

The short answer to the error you are seeing here is that `solve_opf` does not support storage components. Most likely you want to use `solve_mn_opf_strg` that solves a multi-period OPF with storage components. There is not great documentation for this but the example repo should be a reasonable guide.

---

<div class="post-metadata">

**Author:** ![Wahee01](https://avatars.discourse-cdn.com/v4/letter/w/aca169/32.png) [@Wahee01](https://discourse.julialang.org/u/Wahee01)\
**Post date:** [December 24, 2022, 7:42pm UTC](https://discourse.julialang.org/t/adding-flexibility-storage-to-matpower-case-files-in-powermodel/92067/3 "2022-12-24T19:42:08Z")

</div>

Thank you very much for your answer and suggestion. I attempted to replicate the example in the linked link, but I kept receiving the error "

 ![Screenshot 2022-12-24 at 2.38.59 PM](https://global.discourse-cdn.com/julialang/original/3X/6/f/6fe9a8997e1d787b40a75aca1e4f26e42afaeb3f.png)  
"

---

<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:** [December 24, 2022, 9:48pm UTC](https://discourse.julialang.org/t/adding-flexibility-storage-to-matpower-case-files-in-powermodel/92067/4 "2022-12-24T21:48:13Z")

</div>

Focus your attention on `comp-model.jl` (not `comp-phase.jl`) unless you would like to model distribution systems. This example requires Guorbi to run, but even if you cannot run it, should provide a guide for how to use this feature.
