Closed WinfriedL closed 5 years ago
I think the problem is (not surprisingly) in https://github.com/e2nIEE/pandapower/blob/67823ae7a60af529b7fae9ad863c5e57cb079fba/pandapower/pd2ppc.py#L198-L221
The new_gen_positions
still contains all generators from the ppc, even isolated ones, but eg_end
and gen_end
only count in_service ones. That means the indices in the generated lookup are shifted.
I have added a testcase in https://github.com/WinfriedL/pandapower/commit/ec594088bde5d94c0bda12b42299596bace20f4c and a temporary (ugly) fix in https://github.com/WinfriedL/pandapower/commit/94838e4adf4984e8ea805f531c63e0356053ffbd
In your fix, can you please alter net[element][net[element]['in_service']].index.values in net[element].index.values[net[element]['in_service'].values] and np.sum(net['gen']['in_service']) in np.sum(net['gen']['in_service'].values) for performance reasons and open a pull request ?
Yes of course, I will do that (later). I was not sure if that fix is the right way to fix the problem, it was more meant as a proof of concept.
I have opened the pull request. It is only tested for explicit generators so far. I expect the same issue exists at least for xwards as well.
I completely refactored how generators are added. There was a lot of copy pasted code in build_gen.py between powerflow and OPF that I replaced with one consistent function that works for OPF as well as PF. I also refactored the way the pd2ppc lookups for generators are created.
With regards to isolated generators: the assumption for creating the lookup was, that all generators are in service (because out of service generators wouldn't be added to the gen matrix in the first place). When the connectivity check set some generators out of service, the mapping of the generators was messed up. I solved this by moving the _build_gen function after the connectivity check in pd2ppc:
So now the connectivity check is performed first and disconnected generators are marked as out of service before the gen matrix is initialized. Disconnected generators are then treated the same as out of service generators, in that they aren't added to the gen matrix in the ppc in the first place. This solves the mapping issues described here without any workarounds. I also added a test with isolated xwards in test_scenario, and everything seems to work fine.
The following net has an issue with the generator lookup:
The result of the (not isolated) generator is -1 kw instead of -2 kw. From the ppc it seems like the lookup is wrong.