Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions py-powsybl/Demo1.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def dumpLinesFlow(network):
computationManager = gateway.jvm.LocalComputationManager()
loadflowfactory=defaultConfig.newFactoryImpl(ReflectionUtil.classForName("com.powsybl.loadflow.LoadFlowFactory"))

lf_para = gateway.jvm.com.powsybl.loadflow.LoadFlowParameters.load()

#create a demo network
network = gateway.jvm.com.powsybl.iidm.network.test.FictitiousSwitchFactory.create()

Expand All @@ -52,7 +54,7 @@ def dumpLinesFlow(network):
dumpLinesFlow(network)

#run a LF on the network and dump its results metrics
loadflowResult = loadFlow.run()
loadflowResult = loadFlow.run(network.getStateManager().getWorkingStateId(), lf_para).get()
print("\nLF result: " + str(loadflowResult.isOk()) + "; metrics: " + str(loadflowResult.getMetrics()))

#dump network's lines flow
Expand All @@ -63,7 +65,7 @@ def dumpLinesFlow(network):
network.getSwitch("BD").setOpen(True)

#re-run a LF on the network and dump its results metrics
loadflowResult = loadFlow.run()
loadflowResult = loadFlow.run(network.getStateManager().getWorkingStateId(), lf_para).get()
print("\nLF result: " + str(loadflowResult.isOk()) + "; metrics: " + str(loadflowResult.getMetrics()))

#dump network's lines flow
Expand Down
40 changes: 40 additions & 0 deletions py-powsybl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,46 @@ Start the py-powsybl 'server' in a console.
Demo1.py demostrates what can be done (it executes a loadflow on a network, opens a switch, exports a network to a file in xiidm format)

python Demo1.py

Another example using pypowsybl module

```
from pypowsybl import *

# simple dump network flows function
def dump_lines_flow(network):
print(len(network.get_lines()))
for l in network.get_lines():
print(l.get_id() + ";" + str(l.get_terminal_1().get_i()) + ";" + str(l.get_terminal_2().get_i()))
print(l.get_current_limits_1().get_permanent_limit())
print(str(l.check_permanent_limit_1()) + ";" + str(l.check_permanent_limit_2()))
print(str(l.check_permanent_limit_1(0.1)) + ";" + str(l.check_permanent_limit_2(0.1)))
print(str(l.is_overloaded()) + ";" + str(l.is_overloaded(0.1)))

if __name__ == '__main__':
port = 3338
launch("config2", port)
Comment thread
yichen88 marked this conversation as resolved.
Outdated
if connect(port):
n1 = load("/path/to/case-file/example.xiidm")
Comment thread
yichen88 marked this conversation as resolved.
Outdated
dump_lines_flow(n1)

lf = run_load_flow(n1)
print("\nLF result: " + str(lf.is_ok()) + "; metrics: " + str(lf.get_metrics()))
dump_lines_flow(n1)

# re-run load flow alternatively
lf = n1.run_load_flow()
print("\nLF result: " + str(lf.is_ok()) + "; metrics: " + str(lf.get_metrics()))

n1.save("/path/to/output/example.xiidm")
# or save(n1, "/path/to/output/example.xiidm")

# don't forget to shundown jvm
shundown_pypowsybl()
Comment thread
yichen88 marked this conversation as resolved.
Outdated
else:
print("can not connect to jvm")

```

### Stop py-powsybl
To stop the py-powsybl 'server', CTRL+C in the itools console.
Comment thread
yichen88 marked this conversation as resolved.
Expand Down
Loading