Skip to content

Commit

Permalink
new implementation + SerDe
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Rol <nicolas.rol@rte-france.com>
  • Loading branch information
rolnico committed Dec 20, 2023
1 parent d12ae22 commit 7258c98
Show file tree
Hide file tree
Showing 16 changed files with 474 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@
/**
* @author Nicolas Rol {@literal <nicolas.rol at rte-france.com>}
*/
public interface Ground extends Identifiable<Ground> {

/**
* Get the parent voltage level.
* @return the parent voltage level
*/
VoltageLevel getVoltageLevel();
public interface Ground extends Injection<Ground> {

@Override
default IdentifiableType getType() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2023, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.iidm.network;

/**
* @author Nicolas Rol {@literal <nicolas.rol at rte-france.com>}
*/
public interface GroundAdder extends InjectionAdder<Ground, GroundAdder> {
@Override
Ground add();
}
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,6 @@ interface SwitchAdder extends IdentifiableAdder<Switch, SwitchAdder> {
Switch add();
}

interface GroundAdder extends IdentifiableAdder<Ground, GroundAdder> {
GroundAdder setNode(int node);

@Override
Ground add();
}

interface InternalConnectionAdder {

InternalConnectionAdder setNode1(int node1);
Expand Down Expand Up @@ -472,11 +465,6 @@ default int getMaximumNodeIndex() {
*/
SwitchAdder newSwitch();

/**
* Get a builder to create a new ground.
*/
GroundAdder newGround();

/**
* Get a builder to create a new switch.
*/
Expand Down Expand Up @@ -704,13 +692,6 @@ interface SwitchAdder extends IdentifiableAdder<Switch, SwitchAdder> {

}

interface GroundAdder extends IdentifiableAdder<Ground, GroundAdder> {
GroundAdder setBus(String bus);

@Override
Ground add();
}

/**
* Get buses.
* <p>
Expand Down Expand Up @@ -855,13 +836,6 @@ default Stream<Bus> getBusStreamFromBusViewBusId(String mergedBusId) {
*/
SwitchAdder newSwitch();

/**
* Get a builder to create a new ground.
*
* @throws com.powsybl.commons.PowsyblException if the topology kind is NODE_BREAKER
*/
GroundAdder newGround();

interface TopologyTraverser {
/**
* Called for each traversal step
Expand Down Expand Up @@ -1278,6 +1252,26 @@ default Stream<DanglingLine> getDanglingLineStream() {
*/
int getThreeWindingsTransformerCount();

/**
* Get a builder to create a new ground.
*/
GroundAdder newGround();

/**
* Get grounds.
*/
Iterable<Ground> getGrounds();

/**
* Get grounds.
*/
Stream<Ground> getGroundStream();

/**
* Get ground count.
*/
int getGroundCount();

/**
* Remove this voltage level from the network.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,26 @@ public Stream<ThreeWindingsTransformer> getThreeWindingsTransformerStream() {
return getConnectableStream(ThreeWindingsTransformer.class);
}

@Override
public GroundAdder newGround() {
return new GroundAdderImpl(this);
}

@Override
public Iterable<Ground> getGrounds() {
return getConnectables(Ground.class);
}

@Override
public Stream<Ground> getGroundStream() {
return getConnectableStream(Ground.class);
}

@Override
public int getGroundCount() {
return getConnectableCount(Ground.class);
}

@Override
protected String getTypeDescription() {
return "Voltage level";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,46 +107,6 @@ public Switch add() {

}

private final class GroundAdderImpl extends AbstractIdentifiableAdder<GroundAdderImpl> implements BusBreakerView.GroundAdder {
private String busId;

private GroundAdderImpl() {
}

@Override
protected NetworkImpl getNetwork() {
return BusBreakerVoltageLevel.this.getNetwork();
}

@Override
protected String getTypeDescription() {
return "Ground";
}

@Override
public BusBreakerView.GroundAdder setBus(String bus) {
this.busId = bus;
return this;
}

@Override
public Ground add() {
// Check the ID
String id = checkAndGetUniqueId();

// Check that the bus is defined
if (busId == null) {
throw new ValidationException(this, "bus is not set");
}

// Create the ground element
GroundImpl ground = new GroundImpl(BusBreakerVoltageLevel.this, id, getName());
getNetwork().getIndex().checkAndAdd(ground);
getNetwork().getListeners().notifyCreation(ground);
return ground;
}
}

private final UndirectedGraphImpl<ConfiguredBus, SwitchImpl> graph = new UndirectedGraphImpl<>(NODE_INDEX_LIMIT);

/* buses indexed by vertex number */
Expand Down Expand Up @@ -528,11 +488,6 @@ public SwitchAdder newSwitch() {
throw createNotSupportedBusBreakerTopologyException();
}

@Override
public GroundAdder newGround() {
throw createNotSupportedBusBreakerTopologyException();
}

@Override
public InternalConnectionAdder newInternalConnection() {
throw createNotSupportedBusBreakerTopologyException();
Expand Down Expand Up @@ -733,11 +688,6 @@ public BusBreakerView.SwitchAdder newSwitch() {
return new SwitchAdderImpl();
}

@Override
public BusBreakerView.GroundAdder newGround() {
return new GroundAdderImpl();
}

private com.powsybl.math.graph.Traverser adapt(TopologyTraverser t) {
return (vertex1, e, vertex2) -> t.traverse(graph.getVertexObject(vertex1), graph.getEdgeObject(e), graph.getVertexObject(vertex2));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2023, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.iidm.network.impl;

import com.powsybl.iidm.network.GroundAdder;
import com.powsybl.iidm.network.impl.util.Ref;

/**
* @author Nicolas Rol {@literal <nicolas.rol at rte-france.com>}
*/
class GroundAdderImpl extends AbstractInjectionAdder<GroundAdderImpl> implements GroundAdder {

private final VoltageLevelExt voltageLevel;

GroundAdderImpl(VoltageLevelExt voltageLevel) {
this.voltageLevel = voltageLevel;
}

@Override
protected NetworkImpl getNetwork() {
return voltageLevel.getNetwork();
}

@Override
protected String getTypeDescription() {
return "Ground";
}

@Override
protected Ref<? extends VariantManagerHolder> getVariantManagerHolder() {
return getNetworkRef();
}

private Ref<NetworkImpl> getNetworkRef() {
return voltageLevel.getNetworkRef();
}

@Override
public GroundImpl add() {
NetworkImpl network = getNetwork();
String id = checkAndGetUniqueId();
TerminalExt terminal = checkAndGetTerminal();
GroundImpl ground = new GroundImpl(getNetworkRef(), id, id);
ground.addTerminal(terminal);
voltageLevel.attach(terminal, false);
network.getIndex().checkAndAdd(ground);
network.getListeners().notifyCreation(ground);
return ground;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,26 @@

import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.Ground;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.impl.util.Ref;

/**
* @author Nicolas Rol {@literal <nicolas.rol at rte-france.com>}
*/
class GroundImpl extends AbstractIdentifiable<Ground> implements Ground {
class GroundImpl extends AbstractConnectable<Ground> implements Ground {

private final VoltageLevelExt voltageLevel;

GroundImpl(VoltageLevelExt voltageLevel, String id, String name) {
super(id, name, false);
this.voltageLevel = voltageLevel;
}

@Override
public void setFictitious(boolean fictitious) {
throw new PowsyblException("The ground cannot be fictitious.");
GroundImpl(Ref<NetworkImpl> networkRef,
String id, String name) {
super(networkRef, id, name, false);
}

@Override
public NetworkImpl getNetwork() {
return voltageLevel.getNetwork();
public TerminalExt getTerminal() {
return terminals.get(0);
}

@Override
public Network getParentNetwork() {
return voltageLevel.getParentNetwork();
}

@Override
public VoltageLevelExt getVoltageLevel() {
return voltageLevel;
public void setFictitious(boolean fictitious) {
throw new PowsyblException("The ground cannot be fictitious.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,47 +176,6 @@ public Switch add() {

}

private final class GroundAdderImpl extends AbstractIdentifiableAdder<GroundAdderImpl> implements NodeBreakerView.GroundAdder {
private Integer node;

private GroundAdderImpl() {
}

@Override
protected NetworkImpl getNetwork() {
return NodeBreakerVoltageLevel.this.getNetwork();
}

@Override
protected String getTypeDescription() {
return "Ground";
}

@Override
public NodeBreakerView.GroundAdder setNode(int node) {
this.node = node;
return this;
}

@Override
public Ground add() {
// Check the ID
String id = checkAndGetUniqueId();

// Check that the bus is defined
if (node == null) {
throw new ValidationException(this, "node is not set");
}

// Create the ground element
GroundImpl ground = new GroundImpl(NodeBreakerVoltageLevel.this, id, getName());
getNetwork().getIndex().checkAndAdd(ground);
getNetwork().getListeners().notifyCreation(ground);
return ground;
}

}

private final class InternalConnectionAdderImpl implements NodeBreakerView.InternalConnectionAdder {

private Integer node1;
Expand Down Expand Up @@ -519,6 +478,7 @@ public boolean isValid(UndirectedGraph<? extends TerminalExt, SwitchImpl> graph,
case BATTERY:
case SHUNT_COMPENSATOR:
case STATIC_VAR_COMPENSATOR:
case GROUND:
feederCount++;
break;

Expand Down Expand Up @@ -837,11 +797,6 @@ public SwitchAdder newSwitch() {
return new SwitchAdderImpl();
}

@Override
public GroundAdder newGround() {
return new GroundAdderImpl();
}

@Override
public InternalConnectionAdder newInternalConnection() {
return new InternalConnectionAdderImpl();
Expand Down Expand Up @@ -1131,11 +1086,6 @@ public BusBreakerView.SwitchAdder newSwitch() {
throw createNotSupportedNodeBreakerTopologyException();
}

@Override
public GroundAdder newGround() {
throw createNotSupportedNodeBreakerTopologyException();
}

@Override
public void traverse(Bus bus, TopologyTraverser traverser) {
throw createNotSupportedNodeBreakerTopologyException();
Expand Down
Loading

0 comments on commit 7258c98

Please sign in to comment.