-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect invalid element overrides #203
Conversation
50566fd
to
de70b4f
Compare
Hello, I'm not sure of the problem you are trying to solve. If we look at the example linked in #186, and if we run the following code: import roseau.load_flow as lf
bus = lf.Bus("bus1", phases="an")
load1 = lf.PowerLoad("load1", bus, powers=[1000])
load2 = lf.PowerLoad("load1", bus, powers=[1000]) # <- oops, forgot to change the ID
en = lf.ElectricalNetwork.from_element(bus) We get the right error message:
However the problem could arise if we connect the load later on (I had to add a few elements): import roseau.load_flow as lf
bus = lf.Bus("bus1", phases="an")
vs = lf.VoltageSource("source", bus, voltages=[10])
pref = lf.PotentialRef("pref", bus)
load1 = lf.PowerLoad("load1", bus, powers=[1000])
en = lf.ElectricalNetwork.from_element(bus)
load2 = lf.PowerLoad("load1", bus, powers=[1000]) # <- oops, forgot to change the ID In that case no error message is currently raised, but it should be easy to add in the elif isinstance(element, AbstractLoad):
if element.id in self.loads:
raise RoseauLoadFlowException("Duplicate ID...", code=error_code)
self.loads[element.id] = element This seems simpler than modifying every elements |
Yes, this is the main problem we are trying to solve.
You are right, and that's why the PR is still a draft 😉. |
Fixes #186