Skip to content

Commit

Permalink
Merge branch 'master' into mcla_update
Browse files Browse the repository at this point in the history
  • Loading branch information
CBiasuzzi committed May 7, 2018
2 parents 14a9317 + 121791f commit 2f376ba
Show file tree
Hide file tree
Showing 27 changed files with 1,816 additions and 116 deletions.
18 changes: 13 additions & 5 deletions EU2Mod_MB/src/main/java/itesla/converter/ModelicaModel.java
Expand Up @@ -549,9 +549,13 @@ public void Connection() {
connRight = model.nameModelica + "_" + Blocks[Link[i][1] - 1].GraphicalNumber.toString() + ".u" + Link[i][2].toString();
}
}
Blocks[Link[i][1] - 1].UsedInputPins.set(Link[i][2] - 1, true);
conn = conn + connLeft + ", " + connRight + ");";
outputConnection.add(conn);
if ((Link[i][2]) <= Blocks[Link[i][1] - 1].UsedInputPins.size()) {
Blocks[Link[i][1] - 1].UsedInputPins.set(Link[i][2] - 1, true);
conn = conn + connLeft + ", " + connRight + ");";
outputConnection.add(conn);
} else {
System.err.println("Connection - file: " + pathEu + ", id: " + Blocks[Link[i][1] - 1].idEu + ", inputPins: " + Blocks[Link[i][1] - 1].UsedInputPins + ", inputPins size: " + Blocks[Link[i][1] - 1].UsedInputPins.size() + ", but the index to-be set is: " + Link[i][2]);
}
}
}

Expand Down Expand Up @@ -601,8 +605,12 @@ public void InputConnection() {
}
}
conn = " connect(" + connLeft + ", " + connRight + ");";
Blocks[i].UsedInputPins.set(indConnRight - 1, true);
outputInputConnection.add(conn);
if (indConnRight <= Blocks[i].UsedInputPins.size()) {
Blocks[i].UsedInputPins.set(indConnRight - 1, true);
outputInputConnection.add(conn);
} else {
System.err.println("InputConnection - file: " + pathEu + ", id: " + Blocks[i].idEu + ", inputPins: " + Blocks[i].UsedInputPins + ", inputPins size: " + Blocks[i].UsedInputPins.size() + ", but the index to-be set is: " + (indConnRight - 1));
}
}
}
}
Expand Down
Expand Up @@ -11,6 +11,7 @@

import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.stream.StreamSupport;

Expand Down Expand Up @@ -183,4 +184,53 @@ public static boolean isInMainCc(Branch branch, boolean noswitch) {
return (ConnectedComponents.getCcNum(EchUtil.getBus(branch.getTerminal1(), noswitch)) == Component.MAIN_NUM)
&& (ConnectedComponents.getCcNum(EchUtil.getBus(branch.getTerminal2(), noswitch)) == Component.MAIN_NUM);
}

/**
* given an iIDM HVDC line , returns its DC voltage to be used with Eurostag
* Multiplying the line's nominalV by 2 corresponds to the fact that iIDM refers to the cable-ground voltage
* while Eurostag regulations to the cable-cable voltage
*/
public static float getHvdcLineDcVoltage(HvdcLine line) {
Objects.requireNonNull(line);
return line.getNominalV() * 2.0f;
}

public static boolean isPMode(HvdcConverterStation vscConv, HvdcLine hvdcLine) {
Objects.requireNonNull(vscConv);
Objects.requireNonNull(hvdcLine);
HvdcConverterStation side1Conv = hvdcLine.getConverterStation1();
HvdcConverterStation side2Conv = hvdcLine.getConverterStation2();
if ((hvdcLine.getConvertersMode().equals(HvdcLine.ConvertersMode.SIDE_1_RECTIFIER_SIDE_2_INVERTER))
&& (vscConv.getId().equals(side1Conv.getId()))) {
return true;
}
if ((hvdcLine.getConvertersMode().equals(HvdcLine.ConvertersMode.SIDE_1_INVERTER_SIDE_2_RECTIFIER))
&& (vscConv.getId().equals(side2Conv.getId()))) {
return true;
}
return false;
}

public static HvdcConverterStation getPStation(HvdcLine hvdcLine) {
Objects.requireNonNull(hvdcLine);
if (hvdcLine.getConvertersMode().equals(HvdcLine.ConvertersMode.SIDE_1_RECTIFIER_SIDE_2_INVERTER)) {
return hvdcLine.getConverterStation1();
}
if (hvdcLine.getConvertersMode().equals(HvdcLine.ConvertersMode.SIDE_1_INVERTER_SIDE_2_RECTIFIER)) {
return hvdcLine.getConverterStation2();
}
return null;
}

public static HvdcConverterStation getVStation(HvdcLine hvdcLine) {
Objects.requireNonNull(hvdcLine);
if (hvdcLine.getConvertersMode().equals(HvdcLine.ConvertersMode.SIDE_1_RECTIFIER_SIDE_2_INVERTER)) {
return hvdcLine.getConverterStation2();
}
if (hvdcLine.getConvertersMode().equals(HvdcLine.ConvertersMode.SIDE_1_INVERTER_SIDE_2_RECTIFIER)) {
return hvdcLine.getConverterStation1();
}
return null;
}

}
Expand Up @@ -13,6 +13,8 @@
import eu.itesla_project.eurostag.network.EsgBranchName;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.util.Identifiables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.BufferedWriter;
Expand All @@ -31,6 +33,8 @@
*/
public final class EurostagDictionary {

private static final Logger LOGGER = LoggerFactory.getLogger(EurostagDictionary.class);

private static final EurostagNamingStrategy NAMING_STRATEGY = new DicoEurostagNamingStrategyFactory().create();

private final BiMap<String, String> iidmId2esgId;
Expand All @@ -54,16 +58,19 @@ public static EurostagDictionary create(Network network, BranchParallelIndexes p
Set<String> generatorIds = Identifiables.sort(network.getGenerators()).stream().map(Generator::getId).collect(Collectors.toSet());
Set<String> shuntIds = Identifiables.sort(network.getShunts()).stream().map(ShuntCompensator::getId).collect(Collectors.toSet());
Set<String> svcIds = Identifiables.sort(network.getStaticVarCompensators()).stream().map(StaticVarCompensator::getId).collect(Collectors.toSet());
Set<String> converterStationsIds = Identifiables.sort(network.getVscConverterStations()).stream().map(VscConverterStation::getId).collect(Collectors.toSet());

NAMING_STRATEGY.fillDictionary(dictionary, EurostagNamingStrategy.NameType.NODE, busIds);
NAMING_STRATEGY.fillDictionary(dictionary, EurostagNamingStrategy.NameType.GENERATOR, generatorIds);
NAMING_STRATEGY.fillDictionary(dictionary, EurostagNamingStrategy.NameType.LOAD, loadIds);
NAMING_STRATEGY.fillDictionary(dictionary, EurostagNamingStrategy.NameType.BANK, shuntIds);
NAMING_STRATEGY.fillDictionary(dictionary, EurostagNamingStrategy.NameType.SVC, svcIds);
NAMING_STRATEGY.fillDictionary(dictionary, EurostagNamingStrategy.NameType.VSC, converterStationsIds);

for (DanglingLine dl : Identifiables.sort(network.getDanglingLines())) {
// skip if not in the main connected component
if (config.isExportMainCCOnly() && !EchUtil.isInMainCc(dl, config.isNoSwitch())) {
LOGGER.trace("dangling line not mapped, not in main component: {}", dl.getId());
continue;
}
ConnectionBus bus1 = ConnectionBus.fromTerminal(dl.getTerminal(), config, fakeNodes);
Expand All @@ -79,6 +86,7 @@ public static EurostagDictionary create(Network network, BranchParallelIndexes p
Bus bus2 = EchUtil.getBus2(vl, sw.getId(), config);
// skip switches not in the main connected component
if (config.isExportMainCCOnly() && (!EchUtil.isInMainCc(bus1) || !EchUtil.isInMainCc(bus2))) {
LOGGER.trace("switch not mapped, not in main component: {}", sw.getId());
continue;
}
dictionary.addIfNotExist(sw.getId(),
Expand All @@ -91,6 +99,7 @@ public static EurostagDictionary create(Network network, BranchParallelIndexes p
for (Line l : Identifiables.sort(network.getLines())) {
// skip lines not in the main connected component
if (config.isExportMainCCOnly() && !EchUtil.isInMainCc(l, config.isNoSwitch())) {
LOGGER.trace("line not mapped, not in main component: {}", l.getId());
continue;
}
ConnectionBus bus1 = ConnectionBus.fromTerminal(l.getTerminal1(), config, fakeNodes);
Expand All @@ -104,6 +113,7 @@ public static EurostagDictionary create(Network network, BranchParallelIndexes p
for (TwoWindingsTransformer twt : Identifiables.sort(network.getTwoWindingsTransformers())) {
// skip transformers not in the main connected component
if (config.isExportMainCCOnly() && !EchUtil.isInMainCc(twt, config.isNoSwitch())) {
LOGGER.trace("two windings transformer not mapped, not in main component: {}", twt.getId());
continue;
}
ConnectionBus bus1 = ConnectionBus.fromTerminal(twt.getTerminal1(), config, fakeNodes);
Expand All @@ -114,6 +124,7 @@ public static EurostagDictionary create(Network network, BranchParallelIndexes p
}

for (ThreeWindingsTransformer twt : Identifiables.sort(network.getThreeWindingsTransformers())) {
LOGGER.error("NOT YET IMPLEMENTED");
throw new AssertionError("TODO");
}

Expand All @@ -133,31 +144,39 @@ private EurostagDictionary(Map<String, String> iidmId2esgId, EurostagEchExportCo

public void add(String iidmId, String esgId) {
if (iidmId2esgId.containsKey(iidmId)) {
throw new RuntimeException("IIDM id '" + iidmId + "' already exists in the dictionary");
String errorMsg = "IIDM id '" + iidmId + "' already exists in the dictionary";
LOGGER.error(errorMsg);
throw new RuntimeException(errorMsg);
}
iidmId2esgId.put(iidmId, esgId);
}

public void addIfNotExist(String iidmId, String esgId) {
if (!iidmId2esgId.containsKey(iidmId)) {
if (iidmId2esgId.inverse().containsKey(esgId)) {
throw new RuntimeException("Esg id '" + esgId + "' is already associated to IIDM id '"
+ iidmId2esgId.inverse().get(esgId) + "' impossible to associate it to IIDM id '" + iidmId + "'");
String errorMsg = "Esg id '" + esgId + "' is already associated to IIDM id '"
+ iidmId2esgId.inverse().get(esgId) + "' impossible to associate it to IIDM id '" + iidmId + "'";
LOGGER.error(errorMsg);
throw new RuntimeException(errorMsg);
}
iidmId2esgId.put(iidmId, esgId);
}
}

public String getEsgId(String iidmId) {
if (!iidmId2esgId.containsKey(iidmId)) {
throw new RuntimeException("IIDM id '" + iidmId + "' + not found in the dictionary");
String errorMsg = "IIDM id '" + iidmId + "' + not found in the dictionary";
LOGGER.error(errorMsg);
throw new RuntimeException(errorMsg);
}
return iidmId2esgId.get(iidmId);
}

public String getIidmId(String esgId) {
if (!iidmId2esgId.containsValue(esgId)) {
throw new RuntimeException("ESG id '" + esgId + "' + not found in the dictionary");
String errorMsg = "ESG id '" + esgId + "' + not found in the dictionary";
LOGGER.error(errorMsg);
throw new RuntimeException(errorMsg);
}
return iidmId2esgId.inverse().get(esgId);
}
Expand Down Expand Up @@ -187,6 +206,7 @@ public void load(Path file) {
}
}
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
Expand All @@ -200,6 +220,7 @@ public void dump(Path file) {
}
}
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
Expand Down

0 comments on commit 2f376ba

Please sign in to comment.