Skip to content
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

Remove DynaWaltzContext event model connector list #195

Merged
merged 2 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<dyn:blackBoxModel id="CLA_2_4" lib="CurrentLimitAutomaton" parFile="models.par" parId="CLA_2_4"/>
<dyn:blackBoxModel id="CLA_2_5" lib="CurrentLimitAutomaton" parFile="models.par" parId="CLA_2_5"/>
<dyn:blackBoxModel id="OMEGA_REF" lib="DYNModelOmegaRef" parFile="ieee14bus.par" parId="OMEGA_REF"/>
<dyn:blackBoxModel id="DISCONNECT_LINE" lib="EventQuadripoleDisconnection" parFile="ieee14bus.par" parId="DISCONNECT_LINE"/>
<dyn:macroConnector id="MC_LoadAlphaBeta-NetworkBus">
<dyn:connect var1="load_terminal" var2="@NAME@_ACPIN"/>
<dyn:connect var1="load_switchOffSignal1" var2="@NAME@_switchOff"/>
Expand Down Expand Up @@ -81,6 +82,9 @@
<dyn:connect var1="omegaRef_grp_@INDEX@" var2="generator_omegaRefPu"/>
<dyn:connect var1="running_grp_@INDEX@" var2="generator_running"/>
</dyn:macroConnector>
<dyn:macroConnector id="MC_EventQuadripoleDisconnection-NetworkLine">
<dyn:connect var1="event_state1_value" var2="@NAME@_state_value"/>
</dyn:macroConnector>
<dyn:macroStaticReference id="MSR_LoadAlphaBeta">
<dyn:staticRef var="load_PPu" staticVar="p"/>
<dyn:staticRef var="load_QPu" staticVar="q"/>
Expand Down Expand Up @@ -124,9 +128,5 @@
<dyn:macroConnect connector="MC_DYNModelOmegaRef-NetworkBus" id1="OMEGA_REF" index1="3" id2="NETWORK" name2="_BUS____6_TN"/>
<dyn:macroConnect connector="MC_DYNModelOmegaRef-GeneratorSynchronousThreeWindingsProportionalRegulations" id1="OMEGA_REF" index1="4" id2="_GEN____8_SM"/>
<dyn:macroConnect connector="MC_DYNModelOmegaRef-NetworkBus" id1="OMEGA_REF" index1="4" id2="NETWORK" name2="_BUS____8_TN"/>
<dyn:blackBoxModel id="DISCONNECT_LINE" lib="EventQuadripoleDisconnection" parFile="ieee14bus.par" parId="DISCONNECT_LINE"/>
<dyn:macroConnector id="MC_EventQuadripoleDisconnection-NetworkLine">
<dyn:connect var1="event_state1_value" var2="@NAME@_state_value"/>
</dyn:macroConnector>
<dyn:macroConnect connector="MC_EventQuadripoleDisconnection-NetworkLine" id1="DISCONNECT_LINE" id2="NETWORK" name2="_BUS____1-BUS____5-1_AC"/>
</dyn:dynamicModelsArchitecture>
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<dyn:macroStaticRef id="MSR_GeneratorSynchronousThreeWindingsProportionalRegulations"/>
</dyn:blackBoxModel>
<dyn:blackBoxModel id="OMEGA_REF" lib="DYNModelOmegaRef" parFile="ieee14bus.par" parId="OMEGA_REF"/>
<dyn:blackBoxModel id="DISCONNECT_LINE" lib="EventQuadripoleDisconnection" parFile="ieee14bus.par" parId="DISCONNECT_LINE"/>
<dyn:macroConnector id="MC_LoadAlphaBeta-NetworkBus">
<dyn:connect var1="load_terminal" var2="@NAME@_ACPIN"/>
<dyn:connect var1="load_switchOffSignal1" var2="@NAME@_switchOff"/>
Expand All @@ -74,6 +75,9 @@
<dyn:connect var1="omegaRef_grp_@INDEX@" var2="generator_omegaRefPu"/>
<dyn:connect var1="running_grp_@INDEX@" var2="generator_running"/>
</dyn:macroConnector>
<dyn:macroConnector id="MC_EventQuadripoleDisconnection-NetworkLine">
<dyn:connect var1="event_state1_value" var2="@NAME@_state_value"/>
</dyn:macroConnector>
<dyn:macroStaticReference id="MSR_LoadAlphaBeta">
<dyn:staticRef var="load_PPu" staticVar="p"/>
<dyn:staticRef var="load_QPu" staticVar="q"/>
Expand Down Expand Up @@ -115,9 +119,5 @@
<dyn:macroConnect connector="MC_DYNModelOmegaRef-NetworkBus" id1="OMEGA_REF" index1="3" id2="NETWORK" name2="_BUS____6_TN"/>
<dyn:macroConnect connector="MC_DYNModelOmegaRef-GeneratorSynchronousThreeWindingsProportionalRegulations" id1="OMEGA_REF" index1="4" id2="_GEN____8_SM"/>
<dyn:macroConnect connector="MC_DYNModelOmegaRef-NetworkBus" id1="OMEGA_REF" index1="4" id2="NETWORK" name2="_BUS____8_TN"/>
<dyn:blackBoxModel id="DISCONNECT_LINE" lib="EventQuadripoleDisconnection" parFile="ieee14bus.par" parId="DISCONNECT_LINE"/>
<dyn:macroConnector id="MC_EventQuadripoleDisconnection-NetworkLine">
<dyn:connect var1="event_state1_value" var2="@NAME@_state_value"/>
</dyn:macroConnector>
<dyn:macroConnect connector="MC_EventQuadripoleDisconnection-NetworkLine" id1="DISCONNECT_LINE" id2="NETWORK" name2="_BUS____1-BUS____5-1_AC"/>
</dyn:dynamicModelsArchitecture>
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<dyn:macroStaticRef id="MSR_GeneratorSynchronousFourWindingsProportionalRegulations"/>
</dyn:blackBoxModel>
<dyn:blackBoxModel id="OMEGA_REF" lib="DYNModelOmegaRef" parFile="ieee57bus.par" parId="OMEGA_REF"/>
<dyn:blackBoxModel id="DisconnectGenerator" lib="EventSetPointBoolean" parFile="ieee57bus.par" parId="DisconnectGenerator"/>
<dyn:macroConnector id="MC_GeneratorSynchronousFourWindingsProportionalRegulations-NetworkBus">
<dyn:connect var1="generator_terminal" var2="@NAME@_ACPIN"/>
<dyn:connect var1="generator_switchOffSignal1" var2="@NAME@_switchOff"/>
Expand All @@ -34,6 +35,9 @@
<dyn:macroConnector id="MC_DYNModelOmegaRef-NetworkBus">
<dyn:connect var1="numcc_node_@INDEX@" var2="@NAME@_numcc"/>
</dyn:macroConnector>
<dyn:macroConnector id="MC_EventSetPointBoolean-GeneratorSynchronousFourWindingsProportionalRegulations">
<dyn:connect var1="event_state1" var2="generator_switchOffSignal2"/>
</dyn:macroConnector>
<dyn:macroStaticReference id="MSR_GeneratorSynchronousFourWindingsProportionalRegulations">
<dyn:staticRef var="generator_PGenPu" staticVar="p"/>
<dyn:staticRef var="generator_QGenPu" staticVar="q"/>
Expand All @@ -60,9 +64,5 @@
<dyn:macroConnect connector="MC_DYNModelOmegaRef-NetworkBus" id1="OMEGA_REF" index1="5" id2="NETWORK" name2="_SALT___9_TN"/>
<dyn:macroConnect connector="MC_DYNModelOmegaRef-GeneratorSynchronousFourWindingsProportionalRegulations" id1="OMEGA_REF" index1="6" id2="_GEN____2_SM"/>
<dyn:macroConnect connector="MC_DYNModelOmegaRef-NetworkBus" id1="OMEGA_REF" index1="6" id2="NETWORK" name2="_TURN___2_TN"/>
<dyn:blackBoxModel id="DisconnectGenerator" lib="EventSetPointBoolean" parFile="ieee57bus.par" parId="DisconnectGenerator"/>
<dyn:macroConnector id="MC_EventSetPointBoolean-GeneratorSynchronousFourWindingsProportionalRegulations">
<dyn:connect var1="event_state1" var2="generator_switchOffSignal2"/>
</dyn:macroConnector>
<dyn:macroConnect connector="MC_EventSetPointBoolean-GeneratorSynchronousFourWindingsProportionalRegulations" id1="DisconnectGenerator" id2="_GEN___12_SM"/>
</dyn:dynamicModelsArchitecture>
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public class DynaWaltzContext {
private final Map<String, MacroStaticReference> macroStaticReferences = new LinkedHashMap<>();
private final List<MacroConnect> macroConnectList = new ArrayList<>();
private final Map<String, MacroConnector> macroConnectorsMap = new LinkedHashMap<>();
private final List<MacroConnect> eventMacroConnectList = new ArrayList<>();
private final Map<String, MacroConnector> eventMacroConnectorsMap = new LinkedHashMap<>();
private final NetworkModel networkModel = new NetworkModel();

private final OmegaRef omegaRef;
Expand Down Expand Up @@ -176,24 +174,6 @@ public Collection<MacroConnector> getMacroConnectors() {
return macroConnectorsMap.values();
}

public void addEventMacroConnect(String macroConnectorId, List<MacroConnectAttribute> attributesFrom, List<MacroConnectAttribute> attributesTo) {
eventMacroConnectList.add(new MacroConnect(macroConnectorId, attributesFrom, attributesTo));
}

public List<MacroConnect> getEventMacroConnectList() {
return eventMacroConnectList;
}

public String addEventMacroConnector(String name1, String name2, List<VarConnection> varConnections) {
String macroConnectorId = MacroConnector.createMacroConnectorId(name1, name2);
eventMacroConnectorsMap.computeIfAbsent(macroConnectorId, k -> new MacroConnector(macroConnectorId, varConnections));
return macroConnectorId;
}

public Collection<MacroConnector> getEventMacroConnectors() {
return eventMacroConnectorsMap.values();
}

public boolean isWithoutBlackBoxDynamicModel(String staticId) {
return !staticIdBlackBoxModelMap.containsKey(staticId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@
import com.powsybl.dynamicsimulation.EventModel;
import com.powsybl.dynawaltz.DynaWaltzContext;
import com.powsybl.dynawaltz.models.AbstractPureDynamicBlackBoxModel;
import com.powsybl.dynawaltz.models.Model;
import com.powsybl.dynawaltz.models.VarConnection;
import com.powsybl.dynawaltz.xml.ParametersXml;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import java.util.List;
import java.util.function.Function;

import static com.powsybl.dynawaltz.DynaWaltzParametersDatabase.ParameterType.DOUBLE;
import static com.powsybl.dynawaltz.xml.DynaWaltzXmlConstants.DYN_URI;
Expand Down Expand Up @@ -61,11 +57,4 @@ public void writeParameters(XMLStreamWriter writer, DynaWaltzContext context) th
}

protected abstract void writeEventSpecificParameters(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException;

@Override
protected final <T extends Model> void createMacroConnections(String modelStaticId, Class<T> modelClass, Function<T, List<VarConnection>> varConnectionsSupplier, DynaWaltzContext context) {
T connectedModel = context.getDynamicModel(modelStaticId, modelClass);
String macroConnectorId = context.addEventMacroConnector(getName(), connectedModel.getName(), varConnectionsSupplier.apply(connectedModel));
context.addEventMacroConnect(macroConnectorId, getMacroConnectFromAttributes(), connectedModel.getMacroConnectToAttributes());
}
}
20 changes: 3 additions & 17 deletions dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/DydXml.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ public static void write(Path workingDir, DynaWaltzContext context) throws IOExc
}

private static void write(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException {
writeDynamicModels(writer, context);
writeEvents(writer, context);
}

private static void writeDynamicModels(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException {
// loop over the values of the map indexed by dynamicIds to write only once objects with the same dynamicId
for (BlackBoxModel model : context.getBlackBoxDynamicModels()) {
model.write(writer, context);
}
for (BlackBoxModel model : context.getBlackBoxEventModels()) {
model.write(writer, context);
}
for (MacroConnector macroConnector : context.getMacroConnectors()) {
macroConnector.write(writer);
}
Expand All @@ -55,16 +53,4 @@ private static void writeDynamicModels(XMLStreamWriter writer, DynaWaltzContext
macroConnect.write(writer);
}
}

private static void writeEvents(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException {
for (BlackBoxModel model : context.getBlackBoxEventModels()) {
model.write(writer, context);
}
for (MacroConnector macroConnector : context.getEventMacroConnectors()) {
macroConnector.write(writer);
}
for (MacroConnect macroConnect : context.getEventMacroConnectList()) {
macroConnect.write(writer);
}
}
}
18 changes: 9 additions & 9 deletions dynawaltz/src/test/resources/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<dyn:macroStaticRef id="MSR_GeneratorSynchronousFourWindingsProportionalRegulations"/>
</dyn:blackBoxModel>
<dyn:blackBoxModel id="OMEGA_REF" lib="DYNModelOmegaRef" parFile="sim1.par" parId="OMEGA_REF"/>
<dyn:blackBoxModel id="EM_NHV1_NHV2_1" lib="EventQuadripoleDisconnection" parFile="sim1.par" parId="EM_NHV1_NHV2_1"/>
<dyn:blackBoxModel id="EM_NHV1_NHV2_2" lib="EventQuadripoleDisconnection" parFile="sim1.par" parId="EM_NHV1_NHV2_2"/>
<dyn:blackBoxModel id="EM_GEN2" lib="EventSetPointBoolean" parFile="sim1.par" parId="EM_GEN2"/>
<dyn:macroConnector id="MC_GeneratorSynchronousFourWindingsProportionalRegulations-NetworkBus">
<dyn:connect var1="generator_terminal" var2="@NAME@_ACPIN"/>
<dyn:connect var1="generator_switchOffSignal1" var2="@NAME@_switchOff"/>
Expand All @@ -16,6 +19,12 @@
<dyn:macroConnector id="MC_DYNModelOmegaRef-NetworkBus">
<dyn:connect var1="numcc_node_@INDEX@" var2="@NAME@_numcc"/>
</dyn:macroConnector>
<dyn:macroConnector id="MC_EventQuadripoleDisconnection-NetworkLine">
<dyn:connect var1="event_state1_value" var2="@NAME@_state_value"/>
</dyn:macroConnector>
<dyn:macroConnector id="MC_EventSetPointBoolean-GeneratorSynchronousFourWindingsProportionalRegulations">
<dyn:connect var1="event_state1" var2="generator_switchOffSignal2"/>
</dyn:macroConnector>
<dyn:macroStaticReference id="MSR_GeneratorSynchronousFourWindingsProportionalRegulations">
<dyn:staticRef var="generator_PGenPu" staticVar="p"/>
<dyn:staticRef var="generator_QGenPu" staticVar="q"/>
Expand All @@ -24,15 +33,6 @@
<dyn:macroConnect connector="MC_GeneratorSynchronousFourWindingsProportionalRegulations-NetworkBus" id1="BBM_GEN2" id2="NETWORK" name2="NGEN"/>
<dyn:macroConnect connector="MC_DYNModelOmegaRef-GeneratorSynchronousFourWindingsProportionalRegulations" id1="OMEGA_REF" index1="0" id2="BBM_GEN2"/>
<dyn:macroConnect connector="MC_DYNModelOmegaRef-NetworkBus" id1="OMEGA_REF" index1="0" id2="NETWORK" name2="NGEN"/>
<dyn:blackBoxModel id="EM_NHV1_NHV2_1" lib="EventQuadripoleDisconnection" parFile="sim1.par" parId="EM_NHV1_NHV2_1"/>
<dyn:blackBoxModel id="EM_NHV1_NHV2_2" lib="EventQuadripoleDisconnection" parFile="sim1.par" parId="EM_NHV1_NHV2_2"/>
<dyn:blackBoxModel id="EM_GEN2" lib="EventSetPointBoolean" parFile="sim1.par" parId="EM_GEN2"/>
<dyn:macroConnector id="MC_EventQuadripoleDisconnection-NetworkLine">
<dyn:connect var1="event_state1_value" var2="@NAME@_state_value"/>
</dyn:macroConnector>
<dyn:macroConnector id="MC_EventSetPointBoolean-GeneratorSynchronousFourWindingsProportionalRegulations">
<dyn:connect var1="event_state1" var2="generator_switchOffSignal2"/>
</dyn:macroConnector>
<dyn:macroConnect connector="MC_EventQuadripoleDisconnection-NetworkLine" id1="EM_NHV1_NHV2_1" id2="NETWORK" name2="NHV1_NHV2_1"/>
<dyn:macroConnect connector="MC_EventQuadripoleDisconnection-NetworkLine" id1="EM_NHV1_NHV2_2" id2="NETWORK" name2="NHV1_NHV2_2"/>
<dyn:macroConnect connector="MC_EventSetPointBoolean-GeneratorSynchronousFourWindingsProportionalRegulations" id1="EM_GEN2" id2="BBM_GEN2"/>
Expand Down