Skip to content

Commit

Permalink
Eurostag's A17: fixes, defaults configs (sets observationDuration fro…
Browse files Browse the repository at this point in the history
…m SimulationParameters, if not declared explicitly) and tests
  • Loading branch information
CBiasuzzi committed Nov 29, 2018
1 parent bb2fe55 commit df0a89c
Show file tree
Hide file tree
Showing 16 changed files with 272 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ public void run(CommandLine line, ToolRunningContext context) throws Exception {
dictionary.dump(outputDir.resolve("dict.csv"));
context.getOutputStream().println("exporting dta...");

SimulationParameters simulationParameters = SimulationParameters.load();

// export .dta
ddbClient.dumpDtaFile(outputDir, "sim.dta", network, parallelIndexes.toMap(), EurostagUtil.VERSION, dictionary.toMap());
ddbClient.dumpDtaFile(outputDir, "sim.dta", network, parallelIndexes.toMap(), EurostagUtil.VERSION, dictionary.toMap(), simulationParameters);

context.getOutputStream().println("exporting seq...");

// export .seq
EurostagScenario scenario = new EurostagScenario(SimulationParameters.load(), eurostagConfig);
EurostagScenario scenario = new EurostagScenario(simulationParameters, eurostagConfig);
try (BufferedWriter writer = Files.newBufferedWriter(outputDir.resolve(PRE_FAULT_SEQ_FILE_NAME), StandardCharsets.UTF_8)) {
scenario.writePreFaultSeq(writer, PRE_FAULT_SAC_FILE_NAME);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private void writeDtaAndControls(Domain domain, OutputStream ddbOs, OutputStream
GenericArchive archive = domain.getArchiveFactory().create(GenericArchive.class);
try (FileSystem fileSystem = ShrinkWrapFileSystems.newFileSystem(archive)) {
Path rootDir = fileSystem.getPath("/");
ddbClient.dumpDtaFile(rootDir, DTA_FILE_NAME, network, parallelIndexes.toMap(), EurostagUtil.VERSION, dictionary.toMap());
ddbClient.dumpDtaFile(rootDir, DTA_FILE_NAME, network, parallelIndexes.toMap(), EurostagUtil.VERSION, dictionary.toMap(), parameters);
}
archive.as(ZipExporter.class).exportTo(ddbOs);
//put just the generators dict csv file (extracted from the ddb files) in the common files set, to be used by wp43 transient stability index
Expand Down
4 changes: 4 additions & 0 deletions iidm-ddb/iidm-ddb-eurostag-import-export/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
<groupId>com.powsybl</groupId>
<artifactId>powsybl-iidm-api</artifactId>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-simulation-api</artifactId>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-tools</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
public class DdExportConfig {

private static final String MODULE_NAME = "ddImportExport";
public static final String MODULE_NAME = "ddImportExport";

private static final boolean DEFAULT_AUTOMATON_A11 = false;
private static final boolean DEFAULT_AUTOMATON_A12 = false;
Expand All @@ -37,7 +37,7 @@ public class DdExportConfig {
private static final String DEFAULT_AUTOMATON_A17_REFERENCE_GENERATOR = null;
private static final double DEFAULT_AUTOMATON_A17_MINIMUM_PHASE_DIFFERENCE_THRESHOLD = -240.0;
private static final double DEFAULT_AUTOMATON_A17_MAXIMUM_PHASE_DIFFERENCE_THRESHOLD = 240.0;
private static final double DEFAULT_AUTOMATON_A17_OBSERVATION_DURATION = 15.0;
private static final double DEFAULT_AUTOMATON_A17_OBSERVATION_DURATION = -1;

private boolean automatonA11;
private boolean automatonA12;
Expand All @@ -61,7 +61,7 @@ public class DdExportConfig {
private double automatonA17MaximumPhaseDifferenceThreshold;
private double automatonA17ObservationDuration;

public static DdExportConfig load() {
public static DdExportConfig load(PlatformConfig platformConfig) {
boolean automatonA11 = DEFAULT_AUTOMATON_A11;
boolean automatonA12 = DEFAULT_AUTOMATON_A12;
boolean automatonA14 = DEFAULT_AUTOMATON_A14;
Expand All @@ -85,8 +85,8 @@ public static DdExportConfig load() {
double automatonA17ObservationDuration = DEFAULT_AUTOMATON_A17_OBSERVATION_DURATION;


if (PlatformConfig.defaultConfig().moduleExists(MODULE_NAME)) {
ModuleConfig config = PlatformConfig.defaultConfig().getModuleConfig(MODULE_NAME);
if (platformConfig.moduleExists(MODULE_NAME)) {
ModuleConfig config = platformConfig.getModuleConfig(MODULE_NAME);
automatonA11 = config.getBooleanProperty("automatonA11", DEFAULT_AUTOMATON_A11);
automatonA12 = config.getBooleanProperty("automatonA12", DEFAULT_AUTOMATON_A12);
automatonA14 = config.getBooleanProperty("automatonA14", DEFAULT_AUTOMATON_A14);
Expand All @@ -108,8 +108,8 @@ public static DdExportConfig load() {
gensPQfilter = config.getBooleanProperty("gensPQfilter", DEFAULT_GENPQFILTER);
}

if (PlatformConfig.defaultConfig().moduleExists("eurostag-ech-export")) {
ModuleConfig config = PlatformConfig.defaultConfig().getModuleConfig("eurostag-ech-export");
if (platformConfig.moduleExists("eurostag-ech-export")) {
ModuleConfig config = platformConfig.getModuleConfig("eurostag-ech-export");
exportMainCCOnly = config.getBooleanProperty("exportMainCCOnly", DEFAULT_EXPORT_MAIN_CC_ONLY);
noSwitch = config.getBooleanProperty("noSwitch", DEFAULT_NOSWITCH);
}
Expand All @@ -119,6 +119,10 @@ public static DdExportConfig load() {
acmcRegul, rstPilotGenerators, loadPatternAlpha, loadPatternBeta, gensPQfilter, exportMainCCOnly, noSwitch);
}

public static DdExportConfig load() {
return load(PlatformConfig.defaultConfig());
}

public DdExportConfig() {
this(DEFAULT_AUTOMATON_A11, DEFAULT_AUTOMATON_A12, DEFAULT_AUTOMATON_A14, DEFAULT_AUTOMATON_A17, DEFAULT_AUTOMATON_A17_REFERENCE_GENERATOR, DEFAULT_AUTOMATON_A17_MINIMUM_PHASE_DIFFERENCE_THRESHOLD, DEFAULT_AUTOMATON_A17_MAXIMUM_PHASE_DIFFERENCE_THRESHOLD, DEFAULT_AUTOMATON_A17_OBSERVATION_DURATION,
DEFAULT_RST, DEFAULT_ACMC, DEFAULT_LV_LOAD_MODELING, DEFAULT_RST_REGUL_INJECTOR, DEFAULT_RST_REGUL_GENERATOR, DEFAULT_RST_REGUL_GENERATOR_DELETE,
Expand Down Expand Up @@ -319,4 +323,8 @@ public boolean isExportMainCCOnly() {
public boolean isNoSwitch() {
return noSwitch;
}

public boolean isAutomatonA17ObservationDurationSet() {
return automatonA17ObservationDuration >= 0.0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.util.ConnectedComponents;
import com.powsybl.iidm.network.util.Identifiables;
import com.powsybl.simulation.SimulationParameters;
import eu.itesla_project.iidm.ddb.eurostag_imp_exp.utils.Utils;
import eu.itesla_project.iidm.ddb.model.*;
import eu.itesla_project.iidm.ddb.service.DDBManager;
Expand Down Expand Up @@ -958,10 +959,10 @@ public Map<String, String> readWithCsvMapReader(Path dicoFile) throws Exception
@Override
public void dumpDtaFile(Path workingDir, String fileName,
Network network, Map<String, Character> parallelIndexes, String eurostagVersion,
Map<String, String> iidm2eurostagId) {
Map<String, String> iidm2eurostagId, SimulationParameters simulationParameters) {
try (EjbClientCtx cx = newEjbClientEcx()) {
DDBManager ddbmanager = cx.connectEjb(DDBMANAGERJNDINAME);
dumpDtaFile(workingDir, fileName, network, parallelIndexes, eurostagVersion, iidm2eurostagId, ddbmanager);
dumpDtaFile(workingDir, fileName, network, parallelIndexes, eurostagVersion, iidm2eurostagId, simulationParameters, ddbmanager);

} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -1006,7 +1007,7 @@ public boolean isInMainCc(Injection injection, boolean noswitch) {
*/
public void dumpDtaFile(Path workingDir, String fileName,
Network network, Map<String, Character> parallelIndexes, String eurostagVersion,
Map<String, String> iidm2eurostagId, DDBManager ddbmanager) {
Map<String, String> iidm2eurostagId, SimulationParameters simulationParameters, DDBManager ddbmanager) {


if (workingDir == null) {
Expand Down Expand Up @@ -1135,7 +1136,7 @@ public void dumpDtaFile(Path workingDir, String fileName,

dumpDataLoadPatternAndBehaviour(cimIds, eurostagSim, ddbmanager, dtaOutStream);

dumpDataAutomatons(eurostagSim, ddbmanager, dtaOutStream, iidm2eurostagId);
dumpDataAutomatons(eurostagSim, ddbmanager, dtaOutStream, iidm2eurostagId, simulationParameters);

dumpDataACMC(eurostagSim, ddbmanager, dtaOutStream, iidm2eurostagId, workingDir);

Expand Down Expand Up @@ -1828,7 +1829,7 @@ private boolean isMacroblockIncluded(VscConverterStation cvStation, HashMap<Stri

// Dump data without DDB parameters
public void dumpDataAutomatons(SimulatorInst eurostagSim, DDBManager ddbmanager,
PrintStream dtaOutStream, Map<String, String> iidm2eurostagId) throws ParseException, IOException {
PrintStream dtaOutStream, Map<String, String> iidm2eurostagId, SimulationParameters simulationParameters) throws ParseException, IOException {

if (configExport.getAutomatonA11()) {
// A11
Expand Down Expand Up @@ -1894,46 +1895,62 @@ public void dumpDataAutomatons(SimulatorInst eurostagSim, DDBManager ddbmanager,
}
DtaParser.dumpAutomatonHeader("A14", true, dtaOutStream);
}
if (configExport.getAutomatonA17()) {
//A17
dumpDataAutomatonA17(dtaOutStream, iidm2eurostagId);
}

DdbDtaImpExp.dumpDataAutomatonA17(network, dtaOutStream, iidm2eurostagId, simulationParameters, configExport);
}

public void dumpDataAutomatonA17(PrintStream out, Map<String, String> iidm2eurostagId) throws IOException {
String refGenId = configExport.getAutomatonA17AngularReferenceGenerator();

public static EurostagRecord createA17Record(String refGenEurostagId, DdExportConfig configExport, SimulationParameters simulationParameters) {
String automatonId = "A17";
if (refGenId == null) {
log.warn("Dump automaton {}: an angular reference generator id must be declared (attribute automatonA17AngularReferenceGenerator)", automatonId);
} else {
Generator refGen = network.getGenerator(refGenId);
if (refGen == null) {
log.warn("Dump automaton {}: skipping generator {}: no generators with this ID exist", automatonId, refGenId);
HashMap<String, Object> zm = new HashMap<String, Object>();
zm.put("RESEARCH_CRITERION", "1");
zm.put("AUTO_DEVICE_FUNCTIONING_MODE", "1");
zm.put("machine.name", refGenEurostagId);
zm.put("SAMIN", configExport.getAutomatonA17MinimumPhaseDifferenceThreshold());
zm.put("SAMAX", configExport.getAutomatonA17MaximumPhaseDifferenceThreshold());
double observationDuration = configExport.getAutomatonA17ObservationDuration();
if (!configExport.isAutomatonA17ObservationDurationSet()) {
if (simulationParameters == null) {
throw new RuntimeException("simulation parameters must be not null");
}
observationDuration = simulationParameters.getPostFaultSimulationStopInstant() - simulationParameters.getFaultEventInstant();
log.warn("Dump automaton {}: parameter observationDuration is not declared; set to (postFaultSimulationStopInstant - faultEventInstant) = {}", automatonId, observationDuration);
}
zm.put("DOBSA", observationDuration);
zm.put("TYPE_REFERENCE", " ");
zm.put("SVMIN", "0.");
zm.put("SVMAX", "0.");
zm.put("DELAIV", "0.");
zm.put("DOBSV", "0.");
EurostagRecord eRecord = new EurostagRecord(automatonId, zm);
return eRecord;
}

public static void dumpDataAutomatonA17(Network network, PrintStream out, Map<String, String> iidm2eurostagId, SimulationParameters simulationParameters, DdExportConfig configExport) throws IOException {
if (configExport.getAutomatonA17()) {
String refGenId = configExport.getAutomatonA17AngularReferenceGenerator();
String automatonId = "A17";
if (refGenId == null) {
log.warn("Dump automaton {}: an angular reference generator id must be declared (attribute automatonA17AngularReferenceGenerator)", automatonId);
} else {
if (!iidm2eurostagId.containsKey(refGenId)) {
log.warn("Dump automaton {}: skipping generator {}: no mapped eurostag id exists, for it", automatonId, refGenId);
Generator refGen = network.getGenerator(refGenId);
if (refGen == null) {
log.warn("Dump automaton {}: skipping generator {}: no generators with this ID exist", automatonId, refGenId);

} else {
String refGenEurostagId = iidm2eurostagId.get(refGenId);
log.debug("Dump automaton {}: generator id: {} mapped to eurostag id: {}", automatonId, refGenId, refGenEurostagId);
try {
DtaParser.dumpAutomatonHeader(automatonId, false, out);
HashMap<String, Object> zm = new HashMap<String, Object>();
zm.put("RESEARCH_CRITERION", "1");
zm.put("AUTO_DEVICE_FUNCTIONING_MODE", "1");
zm.put("machine.name", refGenEurostagId);
zm.put("SAMIN", configExport.getAutomatonA17MinimumPhaseDifferenceThreshold());
zm.put("SAMAX", configExport.getAutomatonA17MaximumPhaseDifferenceThreshold());
zm.put("DOBSA", configExport.getAutomatonA17ObservationDuration());
zm.put("TYPE_REFERENCE", " ");
zm.put("SVMIN", "0.");
zm.put("SVMAX", "0.");
zm.put("DELAIV", "0.");
zm.put("DOBSV", "0.");
EurostagRecord eRecord = new EurostagRecord(automatonId, zm);
DtaParser.dumpZone(eRecord, out);
DtaParser.dumpAutomatonHeader(automatonId, true, out);
} catch (ParseException e) {
log.error(e.getMessage(), e);
if (!iidm2eurostagId.containsKey(refGenId)) {
log.warn("Dump automaton {}: skipping generator {}: no mapped eurostag id exists, for it", automatonId, refGenId);
} else {
String refGenEurostagId = iidm2eurostagId.get(refGenId);
log.debug("Dump automaton {}: generator id: {} mapped to eurostag id: {}", automatonId, refGenId, refGenEurostagId);
try {
DtaParser.dumpAutomatonHeader(automatonId, false, out);
EurostagRecord eRecord = createA17Record(refGenEurostagId, configExport, simulationParameters);
DtaParser.dumpZone(eRecord, out);
DtaParser.dumpAutomatonHeader(automatonId, true, out);
} catch (ParseException e) {
log.error(e.getMessage(), e);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ private DtaParser(final String name) {
});

componentsVariablesNames.put("A17", new String[]{
"RESEARCH_CRITERION", "AUTO_DEVICE_FUNCTIONING_MODE",
"machine.name", "SAMIN", "SAMAX", "DOBSA",
"TYPE_REFERENCE", "SVMIN", "SVMAX", "DELAIV", "DOBSV"
"RESEARCH_CRITERION,AUTO_DEVICE_FUNCTIONING_MODE",
"machine.name,SAMIN,SAMAX,DOBSA",
"TYPE_REFERENCE,SVMIN,SVMAX,DELAIV,DOBSV",
""
});

componentsVariablesNames.put("A33_ACMC", new String[]{
Expand Down Expand Up @@ -249,7 +250,8 @@ private DtaParser(final String name) {
componentsDescriptors.put("A17", new String[]{
"(A1, 1X, A1)",
"(A8, 1X, F8, 1X, F8, 10X, F8)",
"(A1, 8X, F8, 1X, F8, 1X, F8, 1X, F8)"
"(A1, 8X, F8, 1X, F8, 1X, F8, 1X, F8)",
"()"
});

componentsDescriptors.put("A33_ACMC", new String[]{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.util.Identifiables;
import com.powsybl.simulation.SimulationParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -70,7 +71,7 @@ private List<Generator> filterGenerators(Network network, boolean isFiltered) {


@Override
public void dumpDtaFile(Path workingDir, String fileName, Network network, Map<String, Character> parallelIndexes, String eurostagVersion, Map<String, String> iidm2eurostagId) {
public void dumpDtaFile(Path workingDir, String fileName, Network network, Map<String, Character> parallelIndexes, String eurostagVersion, Map<String, String> iidm2eurostagId, SimulationParameters simulationParameters) {
boolean isFiltered = DdExportConfig.load().getGensPQfilter();

CacheManager.CacheEntry cacheEntry = PlatformConfig.defaultCacheManager().newCacheEntry("ddb")
Expand All @@ -92,7 +93,7 @@ public void dumpDtaFile(Path workingDir, String fileName, Network network, Map<S
cacheEntry.create();

// generate data in the cache
delegate.dumpDtaFile(cacheEntry.toPath(), fileName, network, parallelIndexes, eurostagVersion, iidm2eurostagId);
delegate.dumpDtaFile(cacheEntry.toPath(), fileName, network, parallelIndexes, eurostagVersion, iidm2eurostagId, simulationParameters);
}
} finally {
cacheEntry.unlock();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* Copyright (c) 2017, RTE (http://www.rte-france.com)
* Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium)
* 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
Expand All @@ -8,6 +9,7 @@

import com.powsybl.iidm.network.Network;
import com.powsybl.commons.Versionable;
import com.powsybl.simulation.SimulationParameters;

import java.nio.file.Path;
import java.util.Map;
Expand All @@ -19,6 +21,6 @@
public interface DynamicDatabaseClient extends Versionable {

void dumpDtaFile(Path workingDir, String fileName, Network network, Map<String, Character> parallelIndexes,
String eurostagVersion, Map<String, String> iidm2eurostagId);
String eurostagVersion, Map<String, String> iidm2eurostagId, SimulationParameters simulationParameters);

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.powsybl.iidm.network.Bus;
import com.powsybl.iidm.network.Generator;
import com.powsybl.iidm.network.Network;
import com.powsybl.simulation.SimulationParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -30,7 +31,7 @@ class DynamicDatabaseMock implements DynamicDatabaseClient {
private static final Logger LOGGER = LoggerFactory.getLogger(DynamicDatabaseMock.class);

@Override
public void dumpDtaFile(Path workingDir, String fileName, Network network, Map<String, Character> parallelIndexes, String eurostagVersion, Map<String, String> iidm2eurostagId) {
public void dumpDtaFile(Path workingDir, String fileName, Network network, Map<String, Character> parallelIndexes, String eurostagVersion, Map<String, String> iidm2eurostagId, SimulationParameters simulationParameters) {
Objects.requireNonNull(workingDir);
Objects.requireNonNull(fileName);
Objects.requireNonNull(network);
Expand Down

0 comments on commit df0a89c

Please sign in to comment.