Skip to content

Commit

Permalink
Merge branch 'issue-113' into generatorPQ
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbdr authored Dec 5, 2022
2 parents a143cc7 + f16d02a commit c6f3e99
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.powsybl.dynawaltz.dsl.automatons.CurrentLimitAutomatonGroovyExtension;
import com.powsybl.dynawaltz.dsl.dynamicmodels.GeneratorModelGroovyExtension;
import com.powsybl.dynawaltz.dsl.dynamicmodels.LoadAlphaBetaGroovyExtension;
import com.powsybl.dynawaltz.dynamicmodels.BlackBoxModel;
import com.powsybl.dynawaltz.dynamicmodels.BlackBoxModelWithDynamicId;
import com.powsybl.dynawaltz.dynamicmodels.LoadOneTransformerGroovyExtension;
import com.powsybl.dynawaltz.dynamicmodels.automatons.CurrentLimitAutomaton;
import com.powsybl.dynawaltz.dynamicmodels.staticid.staticref.BlackBoxModelWithStaticRef;
Expand Down Expand Up @@ -192,8 +192,8 @@ private void validateExtension(DynamicModelGroovyExtension extension) {
private void validateModel(DynamicModel dynamicModel) {
if (dynamicModel instanceof BlackBoxModelWithStaticRef) {
validateBlackBoxModel((BlackBoxModelWithStaticRef) dynamicModel);
} else if (dynamicModel instanceof BlackBoxModel) {
BlackBoxModel blackBoxModel = (BlackBoxModel) dynamicModel;
} else if (dynamicModel instanceof BlackBoxModelWithDynamicId) {
BlackBoxModelWithDynamicId blackBoxModel = (BlackBoxModelWithDynamicId) dynamicModel;
if (blackBoxModel instanceof CurrentLimitAutomaton) {
Identifiable<?> identifiable = network.getIdentifiable(((CurrentLimitAutomaton) blackBoxModel).getLineStaticId());
assertEquals("BBM_" + identifiable.getId(), blackBoxModel.getDynamicModelId());
Expand Down
20 changes: 10 additions & 10 deletions dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class DynaWaltzContext {
private final Map<String, MacroStaticReference> macroStaticReferences = new LinkedHashMap<>();
private final Map<Pair<String, String>, MacroConnector> connectorsMap = new LinkedHashMap<>();
private final Map<Pair<String, String>, MacroConnector> eventConnectorsMap = new LinkedHashMap<>();
private final Map<BlackBoxModel, List<BlackBoxModel>> modelsConnections = new LinkedHashMap<>();
private final Map<BlackBoxModelWithDynamicId, List<BlackBoxModel>> modelsConnections = new LinkedHashMap<>();
private final Map<BlackBoxEventModel, List<BlackBoxModel>> eventModelsConnections = new LinkedHashMap<>();
private final NetworkModel networkModel = new NetworkModel();

Expand Down Expand Up @@ -92,7 +92,7 @@ public List<DynamicModel> getDynamicModels() {
return Collections.unmodifiableList(dynamicModels);
}

public List<BlackBoxModel> getBlackBoxModels() {
public List<BlackBoxModelWithDynamicId> getBlackBoxModels() {
return getBlackBoxModelStream().collect(Collectors.toList());
}

Expand Down Expand Up @@ -129,7 +129,7 @@ public Collection<MacroConnector> getMacroConnectors() {
return connectorsMap.values();
}

public MacroConnector getMacroConnector(BlackBoxModel bbm0, BlackBoxModel bbm1) {
public MacroConnector getMacroConnector(BlackBoxModelWithDynamicId bbm0, BlackBoxModel bbm1) {
initConnectorsMap();
return connectorsMap.get(Pair.of(bbm0.getLib(), bbm1.getLib()));
}
Expand All @@ -140,7 +140,7 @@ private void initConnectorsMap() {
}
}

private void computeMacroConnectors(BlackBoxModel bbm) {
private void computeMacroConnectors(BlackBoxModelWithDynamicId bbm) {
getModelsConnections().get(bbm).forEach(connectedBbm -> {
var key = Pair.of(bbm.getLib(), connectedBbm.getLib());
connectorsMap.computeIfAbsent(key, k -> createMacroConnector(bbm, connectedBbm));
Expand Down Expand Up @@ -170,11 +170,11 @@ private void computeEventMacroConnector(BlackBoxEventModel bbem) {
});
}

private MacroConnector createMacroConnector(BlackBoxModel bbm0, BlackBoxModel bbm1) {
private MacroConnector createMacroConnector(BlackBoxModelWithParameterId bbm0, BlackBoxModel bbm1) {
return new MacroConnector(bbm0.getLib(), bbm1.getLib(), bbm0.getVarsConnect(bbm1));
}

public Map<BlackBoxModel, List<BlackBoxModel>> getModelsConnections() {
public Map<BlackBoxModelWithDynamicId, List<BlackBoxModel>> getModelsConnections() {
if (modelsConnections.isEmpty()) {
getBlackBoxModelStream().forEach(bbm -> modelsConnections.put(bbm, bbm.getModelsConnectedTo(this)));
}
Expand All @@ -188,14 +188,14 @@ public Map<BlackBoxEventModel, List<BlackBoxModel>> getEventModelsConnections()
return eventModelsConnections;
}

private Stream<BlackBoxModel> getInputBlackBoxModelStream() {
private Stream<BlackBoxModelWithDynamicId> getInputBlackBoxModelStream() {
//Doesn't include the OmegaRef, it only concerns the DynamicModels provided by the user
return dynamicModels.stream()
.filter(BlackBoxModel.class::isInstance)
.map(BlackBoxModel.class::cast);
.filter(BlackBoxModelWithDynamicId.class::isInstance)
.map(BlackBoxModelWithDynamicId.class::cast);
}

public Stream<BlackBoxModel> getBlackBoxModelStream() {
public Stream<BlackBoxModelWithDynamicId> getBlackBoxModelStream() {
if (omegaRef.getGeneratorConnectedToOmegaRefModels().isEmpty()) {
return getInputBlackBoxModelStream();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

Expand All @@ -21,12 +20,12 @@
/**
* @author Luma Zamarreño <zamarrenolm at aia.es>
*/
public abstract class AbstractBlackBoxModel implements BlackBoxModel, DynamicModel {
public abstract class AbstractBlackBoxModelWithDynamicId implements BlackBoxModelWithDynamicId, DynamicModel {

private final String dynamicModelId;
private final String parameterSetId;

protected AbstractBlackBoxModel(String dynamicModelId, String parameterSetId) {
protected AbstractBlackBoxModelWithDynamicId(String dynamicModelId, String parameterSetId) {
this.dynamicModelId = Objects.requireNonNull(dynamicModelId);
this.parameterSetId = Objects.requireNonNull(parameterSetId);
}
Expand Down Expand Up @@ -54,22 +53,6 @@ public List<Pair<String, String>> getAttributesConnectTo() {
return List.of(Pair.of("id2", getDynamicModelId()));
}

@Override
public void write(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException {
// Default models not written in dyd
}

@Override
public List<Pair<String, String>> getVarsConnect(BlackBoxModel connectedBbm) {
return Collections.emptyList();
}

@Override
public List<BlackBoxModel> getModelsConnectedTo(DynaWaltzContext dynaWaltzContext) {
// Default models are only connected to
return Collections.emptyList();
}

protected void writeAutomatonBlackBoxModel(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException {
// Write the blackBoxModel object
writer.writeEmptyElement(DYN_URI, "blackBoxModel");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,13 @@
/**
* Copyright (c) 2022, 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/.
*/
package com.powsybl.dynawaltz.dynamicmodels;

import com.powsybl.dynawaltz.DynaWaltzContext;
import org.apache.commons.lang3.tuple.Pair;

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

/**
* @author Florian Dupuy <florian.dupuy at rte-france.com>
*/
public interface BlackBoxModel {
String getDynamicModelId();

String getParameterSetId();

String getLib();

void write(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException;

void writeParameters(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException;

void writeMacroConnect(XMLStreamWriter writer, DynaWaltzContext context, MacroConnector macroConnector, BlackBoxModel connected) throws XMLStreamException;

List<Pair<String, String>> getVarsConnect(BlackBoxModel connected);

List<BlackBoxModel> getModelsConnectedTo(DynaWaltzContext dynaWaltzContext);

List<Pair<String, String>> getAttributesConnectTo();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright (c) 2022, 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/.
*/
package com.powsybl.dynawaltz.dynamicmodels;

import com.powsybl.dynawaltz.DynaWaltzContext;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

/**
* @author Florian Dupuy <florian.dupuy at rte-france.com>
*/
public interface BlackBoxModelWithDynamicId extends BlackBoxModelWithParameterId {
String getDynamicModelId();

void writeParameters(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.powsybl.dynawaltz.dynamicmodels;

import com.powsybl.dynawaltz.DynaWaltzContext;
import org.apache.commons.lang3.tuple.Pair;

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

public interface BlackBoxModelWithParameterId extends BlackBoxModel {
String getParameterSetId();

void write(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException;

void writeMacroConnect(XMLStreamWriter writer, DynaWaltzContext context, MacroConnector macroConnector, BlackBoxModel connected) throws XMLStreamException;

List<Pair<String, String>> getVarsConnect(BlackBoxModel connected);

List<BlackBoxModel> getModelsConnectedTo(DynaWaltzContext dynaWaltzContext);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*
* @author Marcos de Miguel <demiguelm at aia.es>
*/
public class OmegaRef extends AbstractBlackBoxModel {
public class OmegaRef extends AbstractBlackBoxModelWithDynamicId {

public static final String OMEGA_REF_ID = "OMEGA_REF";
private static final String OMEGA_REF_PARAMETER_SET_ID = "OMEGA_REF";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* @author Marcos de Miguel <demiguelm at aia.es>
*/
public class CurrentLimitAutomaton extends AbstractBlackBoxModel {
public class CurrentLimitAutomaton extends AbstractBlackBoxModelWithDynamicId {

private final Branch.Side side;
private final String lineStaticId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ public String getParameterSetId() {
return parameterSetId;
}

@Override
public String getDynamicModelId() {
return null;
}

@Override
public void write(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException {
// Write the blackBoxModel object
Expand All @@ -58,11 +53,6 @@ public void write(XMLStreamWriter writer, DynaWaltzContext context) throws XMLSt
writer.writeAttribute("parId", getParameterSetId());
}

@Override
public void writeParameters(XMLStreamWriter writer, DynaWaltzContext context) {
// No parameters for events
}

@Override
public void writeMacroConnect(XMLStreamWriter writer, DynaWaltzContext context, MacroConnector macroConnector, BlackBoxModel connected) throws XMLStreamException {
macroConnector.writeMacroConnect(writer, getAttributesConnectFrom(), connected.getAttributesConnectTo());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
*/
package com.powsybl.dynawaltz.dynamicmodels.events;

import com.powsybl.dynawaltz.dynamicmodels.BlackBoxModel;
import com.powsybl.dynawaltz.dynamicmodels.BlackBoxModelWithParameterId;

/**
* @author Florian Dupuy <florian.dupuy at rte-france.com>
*/
public interface BlackBoxEventModel extends BlackBoxModel {
public interface BlackBoxEventModel extends BlackBoxModelWithParameterId {

String getEventModelId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ public EventQuadripoleDisconnection(String eventModelId, String staticId, String
this.lineStaticId = staticId;
}

@Override
public String getDynamicModelId() {
return null;
}

@Override
public String getLib() {
return "EventQuadripoleDisconnection";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.powsybl.dynawaltz.dynamicmodels.staticid;

import com.powsybl.dynawaltz.dynamicmodels.AbstractBlackBoxModel;
import com.powsybl.dynawaltz.dynamicmodels.AbstractBlackBoxModelWithDynamicId;

public abstract class AbstractBlackBoxModelWithStaticId extends AbstractBlackBoxModel implements BlackBoxModelWithStaticId {
public abstract class AbstractBlackBoxModelWithStaticId extends AbstractBlackBoxModelWithDynamicId implements BlackBoxModelWithStaticId {

private final String staticId;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package com.powsybl.dynawaltz.dynamicmodels.staticid.network;

import com.powsybl.dynawaltz.DynaWaltzContext;
import com.powsybl.dynawaltz.dynamicmodels.staticid.AbstractBlackBoxModelWithStaticId;
import com.powsybl.dynawaltz.dynamicmodels.BlackBoxModel;
import com.powsybl.dynawaltz.dynamicmodels.MacroConnector;
import com.powsybl.dynawaltz.dynamicmodels.staticid.BlackBoxModelWithStaticId;
import com.powsybl.dynawaltz.xml.DynaWaltzXmlConstants;
import org.apache.commons.lang3.tuple.Pair;

import javax.xml.stream.XMLStreamWriter;
import java.util.List;

public abstract class AbstractNetworkBlackBoxModel extends AbstractBlackBoxModelWithStaticId {
public abstract class AbstractNetworkBlackBoxModel implements BlackBoxModelWithStaticId {

private final String staticId;

protected AbstractNetworkBlackBoxModel(String staticId) {
super("", staticId, "");
this.staticId = staticId;
}

@Override
public void writeMacroConnect(XMLStreamWriter writer, DynaWaltzContext context, MacroConnector macroConnector, BlackBoxModel connected) {
// Default models not written in dyd
public String getStaticId() {
return this.staticId;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
*/
package com.powsybl.dynawaltz.dynamicmodels.staticid.network;

import com.powsybl.dynawaltz.dynamicmodels.BlackBoxModel;
import com.powsybl.iidm.network.Branch;

/**
* @author Florian Dupuy <florian.dupuy at rte-france.com>
*/
public interface LineModel {
public interface LineModel extends BlackBoxModel {
String getIVarName();

String getStateVarName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package com.powsybl.dynawaltz.dynamicmodels.staticid.staticref;

import com.powsybl.dynawaltz.dynamicmodels.BlackBoxModelWithDynamicId;
import com.powsybl.dynawaltz.dynamicmodels.staticid.BlackBoxModelWithStaticId;
import org.apache.commons.lang3.tuple.Pair;

Expand All @@ -14,7 +15,7 @@
/**
* @author Florian Dupuy <florian.dupuy at rte-france.com>
*/
public interface BlackBoxModelWithStaticRef extends BlackBoxModelWithStaticId {
public interface BlackBoxModelWithStaticRef extends BlackBoxModelWithDynamicId, BlackBoxModelWithStaticId {

List<Pair<String, String>> getStaticRef();
}
7 changes: 4 additions & 3 deletions dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/DydXml.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.powsybl.commons.exceptions.UncheckedXmlStreamException;
import com.powsybl.dynawaltz.DynaWaltzContext;
import com.powsybl.dynawaltz.dynamicmodels.BlackBoxModel;
import com.powsybl.dynawaltz.dynamicmodels.BlackBoxModelWithDynamicId;
import com.powsybl.dynawaltz.dynamicmodels.MacroConnector;
import com.powsybl.dynawaltz.dynamicmodels.events.BlackBoxEventModel;

Expand Down Expand Up @@ -47,7 +48,7 @@ private static void writeDynamicModels(XMLStreamWriter writer, DynaWaltzContext

try {
// loop over the values of the map indexed by dynamicIds to write only once objects with the same dynamicId
for (BlackBoxModel model : context.getBlackBoxModels()) {
for (BlackBoxModelWithDynamicId model : context.getBlackBoxModels()) {
model.write(writer, context);
}
for (MacroConnector macroConnector : context.getMacroConnectors()) {
Expand All @@ -56,8 +57,8 @@ private static void writeDynamicModels(XMLStreamWriter writer, DynaWaltzContext
for (MacroStaticReference macroStaticReference : context.getMacroStaticReferences()) {
macroStaticReference.write(writer);
}
for (Map.Entry<BlackBoxModel, List<BlackBoxModel>> bbmMapping : context.getModelsConnections().entrySet()) {
BlackBoxModel bbm = bbmMapping.getKey();
for (Map.Entry<BlackBoxModelWithDynamicId, List<BlackBoxModel>> bbmMapping : context.getModelsConnections().entrySet()) {
BlackBoxModelWithDynamicId bbm = bbmMapping.getKey();
for (BlackBoxModel connectedBbm : bbmMapping.getValue()) {
bbm.writeMacroConnect(writer, context, context.getMacroConnector(bbm, connectedBbm), connectedBbm);
}
Expand Down
Loading

0 comments on commit c6f3e99

Please sign in to comment.