Skip to content

Commit

Permalink
Remove iidm-converter-api (merged with iidm-api) (#2350)
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffroy Jamgotchian <[email protected]>
  • Loading branch information
geofjamg authored Nov 3, 2022
1 parent 7012399 commit b8476d7
Show file tree
Hide file tree
Showing 111 changed files with 882 additions and 1,009 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
import com.powsybl.commons.datasource.DataSource;
import com.powsybl.commons.datasource.DataSourceUtil;
import com.powsybl.contingency.Contingency;
import com.powsybl.iidm.export.Exporters;
import com.powsybl.iidm.export.ExportersLoader;
import com.powsybl.iidm.export.ExportersServiceLoader;
import com.powsybl.iidm.network.ExportersLoader;
import com.powsybl.iidm.network.ExportersServiceLoader;
import com.powsybl.security.LimitViolation;

import java.nio.file.Path;
Expand Down Expand Up @@ -68,7 +67,7 @@ public void loadFlowConverged(RunningContext runningContext, List<LimitViolation

private void exportNetwork(RunningContext context) {
DataSource dataSource = DataSourceUtil.createDataSource(outputCaseFolder, getBasename(context.getContingency(), context.getRound()), compressionFormat, null);
Exporters.export(loader, outputCaseFormat, context.getNetwork(), new Properties(), dataSource);
context.getNetwork().write(loader, outputCaseFormat, new Properties(), dataSource);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
import com.powsybl.commons.io.table.TableFormatterConfig;
import com.powsybl.computation.Partition;
import com.powsybl.contingency.Contingency;
import com.powsybl.iidm.export.Exporter;
import com.powsybl.iidm.import_.ImportConfig;
import com.powsybl.iidm.import_.Importers;
import com.powsybl.iidm.network.Exporter;
import com.powsybl.iidm.network.ImportConfig;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.tools.ConversionToolUtils;
import com.powsybl.iidm.network.tools.ConversionToolUtils;
import com.powsybl.security.Security;
import com.powsybl.security.SecurityAnalysisResult;
import com.powsybl.security.converter.SecurityAnalysisResultExporters;
Expand Down Expand Up @@ -51,9 +50,9 @@
import java.util.stream.Collectors;

import static com.powsybl.action.simulator.tools.ActionSimulatorToolConstants.*;
import static com.powsybl.iidm.tools.ConversionToolUtils.createImportParameterOption;
import static com.powsybl.iidm.tools.ConversionToolUtils.createImportParametersFileOption;
import static com.powsybl.iidm.tools.ConversionToolUtils.readProperties;
import static com.powsybl.iidm.network.tools.ConversionToolUtils.createImportParameterOption;
import static com.powsybl.iidm.network.tools.ConversionToolUtils.createImportParametersFileOption;
import static com.powsybl.iidm.network.tools.ConversionToolUtils.readProperties;
import static com.powsybl.tools.ToolConstants.TASK;
import static com.powsybl.tools.ToolConstants.TASK_COUNT;

Expand Down Expand Up @@ -256,7 +255,7 @@ public void run(CommandLine line, ToolRunningContext context) throws Exception {
// load network
context.getOutputStream().println("Loading network '" + caseFile + "'");
Properties inputParams = readProperties(line, ConversionToolUtils.OptionType.IMPORT, context);
Network network = Importers.loadNetwork(caseFile, context.getShortTimeExecutionComputationManager(), ImportConfig.load(), inputParams);
Network network = Network.read(caseFile, context.getShortTimeExecutionComputationManager(), ImportConfig.load(), inputParams);

try {
// load actions from Groovy DSL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import com.google.common.jimfs.Jimfs;
import com.powsybl.commons.datasource.CompressionFormat;
import com.powsybl.contingency.Contingency;
import com.powsybl.iidm.export.ExportersLoader;
import com.powsybl.iidm.export.ExportersLoaderList;
import com.powsybl.iidm.network.ExportersLoader;
import com.powsybl.iidm.network.ExportersLoaderList;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.xml.XMLExporter;
import org.junit.After;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/
package com.powsybl.action.simulator.tools;

import com.powsybl.iidm.export.Exporter;
import com.powsybl.iidm.export.ExportersLoaderList;
import com.powsybl.iidm.network.Exporter;
import com.powsybl.iidm.network.ExportersLoaderList;
import com.powsybl.tools.AbstractToolTest;
import com.powsybl.tools.Command;
import com.powsybl.tools.Tool;
Expand Down
2 changes: 1 addition & 1 deletion ampl-converter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-iidm-converter-api</artifactId>
<artifactId>powsybl-iidm-api</artifactId>
<version>${project.version}</version>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.google.auto.service.AutoService;
import com.powsybl.commons.config.PlatformConfig;
import com.powsybl.commons.datasource.DataSource;
import com.powsybl.iidm.export.Exporter;
import com.powsybl.iidm.network.Exporter;
import com.powsybl.iidm.network.Network;
import com.powsybl.commons.parameters.Parameter;
import com.powsybl.commons.parameters.ParameterDefaultValueConfig;
Expand Down
5 changes: 0 additions & 5 deletions cgmes/cgmes-conversion/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@
<artifactId>powsybl-iidm-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-iidm-converter-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-iidm-xml-converter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.reporter.TypedValue;
import com.powsybl.commons.xml.XmlUtil;
import com.powsybl.iidm.export.Exporter;
import com.powsybl.iidm.network.Exporter;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.TopologyKind;
import com.powsybl.iidm.network.VoltageLevel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.powsybl.commons.parameters.ParameterScope;
import com.powsybl.commons.parameters.ParameterType;
import com.powsybl.commons.util.ServiceLoaderCache;
import com.powsybl.iidm.import_.Importer;
import com.powsybl.iidm.network.Importer;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.NetworkFactory;
import com.powsybl.triplestore.api.TripleStoreFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.powsybl.cgmes.model.test.TestGridModel;
import com.powsybl.commons.reporter.ReporterModel;
import com.powsybl.commons.reporter.TypedValue;
import com.powsybl.iidm.import_.Importers;
import com.powsybl.iidm.network.Importers;
import org.junit.Test;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import com.powsybl.cgmes.conformity.CgmesConformity1Catalog;
import com.powsybl.cgmes.conversion.CgmesImport;
import com.powsybl.iidm.import_.Importers;
import com.powsybl.iidm.network.Importers;
import com.powsybl.iidm.network.Network;
import com.powsybl.triplestore.api.TripleStore;
import com.powsybl.triplestore.api.TripleStoreFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.powsybl.cgmes.conversion.test.network.compare.ComparisonConfig;
import com.powsybl.cgmes.model.CgmesModel;
import com.powsybl.cgmes.model.test.cim14.Cim14SmallCasesCatalog;
import com.powsybl.iidm.import_.Importers;
import com.powsybl.iidm.network.Importers;
import com.powsybl.iidm.network.Network;
import com.powsybl.triplestore.api.TripleStoreFactory;
import org.junit.BeforeClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.powsybl.cgmes.conformity.Cgmes3Catalog;
import com.powsybl.cgmes.conformity.Cgmes3ModifiedCatalog;
import com.powsybl.cgmes.conversion.CgmesModelExtension;
import com.powsybl.iidm.import_.Importers;
import com.powsybl.iidm.network.Importers;
import com.powsybl.iidm.network.Network;
import org.junit.After;
import org.junit.Before;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.config.InMemoryPlatformConfig;
import com.powsybl.commons.datasource.ReadOnlyDataSource;
import com.powsybl.iidm.import_.Importers;
import com.powsybl.iidm.network.Importers;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.extensions.GeneratorEntsoeCategory;
import com.powsybl.iidm.network.extensions.LoadDetail;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import com.powsybl.cgmes.model.test.cim14.Cim14SmallCasesCatalog;
import com.powsybl.commons.datasource.GenericReadOnlyDataSource;
import com.powsybl.commons.datasource.ReadOnlyDataSource;
import com.powsybl.iidm.export.Exporters;
import com.powsybl.iidm.import_.Importers;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.test.FictitiousSwitchFactory;
import com.powsybl.iidm.network.util.Networks;
Expand Down Expand Up @@ -91,8 +89,8 @@ public void testFromIidm() throws IOException {

try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) {
Path tmpDir = Files.createDirectory(fs.getPath("/cgmes"));
Exporters.export("CGMES", network, null, tmpDir.resolve("tmp"));
Network n2 = Importers.loadNetwork(new GenericReadOnlyDataSource(tmpDir, "tmp"));
network.write("CGMES", null, tmpDir.resolve("tmp"));
Network n2 = Network.read(new GenericReadOnlyDataSource(tmpDir, "tmp"));
VoltageLevel c = n2.getVoltageLevel("C");
assertNull(Networks.getEquivalentTerminal(c, c.getNodeBreakerView().getNode2("TEST_SW")));
assertNull(n2.getVscConverterStation("C2").getTerminal().getBusView().getBus());
Expand All @@ -108,15 +106,15 @@ public void testSynchronousMachinesWithSameGeneratingUnit() throws IOException {
try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) {
Path tmpDir = Files.createDirectory(fs.getPath(exportFolder));
// Export to CGMES and add boundary EQ for reimport
Exporters.export("CGMES", n, null, tmpDir.resolve(baseName));
n.write("CGMES", null, tmpDir.resolve(baseName));
String eqbd = ds.listNames(".*EQ_BD.*").stream().findFirst().orElse(null);
if (eqbd != null) {
try (InputStream is = ds.newInputStream(eqbd)) {
Files.copy(is, tmpDir.resolve(baseName + "_EQ_BD.xml"));
}
}

Network n2 = Importers.loadNetwork(new GenericReadOnlyDataSource(tmpDir, baseName), null);
Network n2 = Network.read(new GenericReadOnlyDataSource(tmpDir, baseName), null);
Generator g1 = n2.getGenerator("3a3b27be-b18b-4385-b557-6735d733baf0");
Generator g2 = n2.getGenerator("550ebe0d-f2b2-48c1-991f-cebea43a21aa");
String gu1 = g1.getProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + "GeneratingUnit");
Expand All @@ -139,14 +137,14 @@ public void testPhaseTapChangerFixedTapNotExported() throws IOException, XMLStre

// With original regulating mode the regulating control should be written in the EQ output
String baseNameWithRc = baseName + "-with-rc";
Exporters.export("CGMES", n, null, tmpDir.resolve(baseNameWithRc));
n.write("CGMES", null, tmpDir.resolve(baseNameWithRc));
assertTrue(cgmesFileContainsRegulatingControl(regulatingControlId, tmpDir, baseNameWithRc, "EQ"));
assertTrue(cgmesFileContainsRegulatingControl(regulatingControlId, tmpDir, baseNameWithRc, "SSH"));

transformer.getPhaseTapChanger().setRegulating(false);
transformer.getPhaseTapChanger().setRegulationMode(PhaseTapChanger.RegulationMode.FIXED_TAP);
String baseNameNoRc = baseName + "-no-rc";
Exporters.export("CGMES", n, null, tmpDir.resolve(baseNameNoRc));
n.write("CGMES", null, tmpDir.resolve(baseNameNoRc));
assertFalse(cgmesFileContainsRegulatingControl(regulatingControlId, tmpDir, baseNameNoRc, "EQ"));
assertFalse(cgmesFileContainsRegulatingControl(regulatingControlId, tmpDir, baseNameNoRc, "SSH"));
}
Expand Down Expand Up @@ -216,14 +214,14 @@ private static void testPhaseTapChangerType(ReadOnlyDataSource ds, String transf
Properties paramsOnlySsh = new Properties();
paramsOnlySsh.put(CgmesExport.PROFILES, List.of("SSH"));
paramsOnlySsh.put(CgmesExport.CIM_VERSION, "" + cimVersion);
Exporters.export("CGMES", network, paramsOnlySsh, tmpDir.resolve(baseName));
network.write("CGMES", paramsOnlySsh, tmpDir.resolve(baseName));
String typeOnlySsh = CgmesExportUtil.cgmesTapChangerType(transformer, phaseTapChangerId).orElseThrow(RuntimeException::new);
assertEquals(typeOriginal, typeOnlySsh);

// If we export EQ and SSH (or all instance fiels), type of tap changer should be changed to tabular
Properties paramsEqAndSsh = new Properties();
paramsEqAndSsh.put(CgmesExport.CIM_VERSION, "" + cimVersion);
Exporters.export("CGMES", network, paramsEqAndSsh, tmpDir.resolve(baseName));
network.write("CGMES", paramsEqAndSsh, tmpDir.resolve(baseName));
String typeEqAndSsh = CgmesExportUtil.cgmesTapChangerType(transformer, phaseTapChangerId).orElseThrow(RuntimeException::new);
assertEquals(CgmesNames.PHASE_TAP_CHANGER_TABULAR, typeEqAndSsh);
}
Expand Down Expand Up @@ -259,7 +257,7 @@ public void testDoNotExportFictitiousSwitchesCreatedForDisconnectedTerminals() t
assertFalse(cgmes.terminal(disconnectedTerminalId).connected());

// Verify that the fictitious switch is created again when we re-import the exported CGMES data
Network networkReimported = Importers.loadNetwork(exportedCgmes, null);
Network networkReimported = Network.read(exportedCgmes, null);
Switch fictitiousSwitchReimported = networkReimported.getSwitch(fictitiousSwitchId);
assertNotNull(fictitiousSwitchReimported);
assertTrue(fictitiousSwitchReimported.isFictitious());
Expand All @@ -275,14 +273,14 @@ public void testDoNotExportFictitiousSwitchesCreatedForDisconnectedTerminals() t
assertTrue(cgmes1.isNodeBreaker());
assertFalse(cgmes1.switches().stream().anyMatch(sw -> sw.getId("Switch").equals(fictitiousSwitchId)));
assertTrue(cgmes1.terminal(disconnectedTerminalId).connected());
Network networkReimported1 = Importers.loadNetwork(exportedCgmes1, null);
Network networkReimported1 = Network.read(exportedCgmes1, null);
Switch fictitiousSwitchReimported1 = networkReimported1.getSwitch(fictitiousSwitchId);
assertNull(fictitiousSwitchReimported1);
}
}

private static ReadOnlyDataSource exportAndAddBoundaries(Network network, Path tmpDir, String baseName, ReadOnlyDataSource originalDataSource) throws IOException {
Exporters.export("CGMES", network, null, tmpDir.resolve(baseName));
network.write("CGMES", null, tmpDir.resolve(baseName));
String eqbd = originalDataSource.listNames(".*EQ_BD.*").stream().findFirst().orElse(null);
if (eqbd != null) {
try (InputStream is = originalDataSource.newInputStream(eqbd)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import com.powsybl.cgmes.model.CgmesNames;
import com.powsybl.commons.AbstractConverterTest;
import com.powsybl.commons.datasource.*;
import com.powsybl.iidm.export.Exporters;
import com.powsybl.iidm.import_.Importers;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.extensions.SlackTerminal;
import com.powsybl.iidm.xml.NetworkXml;
Expand Down Expand Up @@ -83,7 +81,7 @@ public void testExportUsingCgmesNamingStrategy(String namingStrategy, Network ne
exportParams.put(CgmesExport.NAMING_STRATEGY, namingStrategy);
String outputFolder = "exportedCgmes" + baseName;
DataSource exportedCgmes = tmpDataSource(outputFolder, baseName);
Exporters.export("CGMES", network, exportParams, exportedCgmes);
network.write("CGMES", exportParams, exportedCgmes);
if (originalDataSource != null) {
copyBoundary(outputFolder, baseName, originalDataSource);
}
Expand Down Expand Up @@ -123,7 +121,7 @@ public void testExportUsingCgmesNamingStrategy(String namingStrategy, Network ne
Properties reExportParams = exportParams;
String reOutputFolder = "reExportedCgmes" + baseName;
DataSource reExportedCgmes = tmpDataSource(reOutputFolder, baseName);
Exporters.export("CGMES", networkActual, reExportParams, reExportedCgmes);
networkActual.write("CGMES", reExportParams, reExportedCgmes);
if (originalDataSource != null) {
copyBoundary(reOutputFolder, baseName, originalDataSource);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import com.powsybl.commons.datasource.ResourceSet;
import com.powsybl.commons.xml.XmlUtil;
import com.powsybl.computation.local.LocalComputationManager;
import com.powsybl.iidm.import_.ImportConfig;
import com.powsybl.iidm.import_.Importers;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.xml.ExportOptions;
import com.powsybl.iidm.xml.NetworkXml;
Expand Down Expand Up @@ -452,7 +450,7 @@ private Network exportImport(Network expected, ReadOnlyDataSource dataSource, bo
// There is no need to create the IIDM-CGMES mappings
// We are reading only an EQ, we won't have TP data in the input
// And to compare the expected and actual networks we are dropping all IIDM-CGMES mapping context information
return Importers.loadNetwork(repackaged, LocalComputationManager.getDefault(), ImportConfig.load(), null);
return Network.read(repackaged, LocalComputationManager.getDefault(), ImportConfig.load(), null);
}

private Path exportToCgmesEQ(Network network) throws IOException, XMLStreamException {
Expand Down Expand Up @@ -496,7 +494,7 @@ private void compareNetworksEQdata(Network expected, Network actual) throws IOEx
ExportXmlCompare::numericDifferenceEvaluator,
ExportXmlCompare::ignoringNonEQ));

compareTemporaryLimits(Importers.loadNetwork(tmpDir.resolve("expected.xml")), Importers.loadNetwork(tmpDir.resolve("actual.xml")));
compareTemporaryLimits(Network.read(tmpDir.resolve("expected.xml")), Network.read(tmpDir.resolve("actual.xml")));
}

private void compareTemporaryLimits(Network expected, Network actual) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
import com.powsybl.commons.reporter.Report;
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.reporter.ReporterModel;
import com.powsybl.iidm.export.Exporters;
import com.powsybl.iidm.export.ExportersServiceLoader;
import com.powsybl.iidm.import_.Importers;
import com.powsybl.iidm.network.ExportersServiceLoader;
import com.powsybl.iidm.network.Importers;
import com.powsybl.iidm.network.Network;
import org.junit.Test;

Expand Down Expand Up @@ -60,6 +59,6 @@ private Network importNetwork(ReadOnlyDataSource dataSource) {
private void exportProfiles(List<String> profiles, Network network, Reporter reporter) {
Properties params = new Properties();
params.put(CgmesExport.PROFILES, profiles);
Exporters.export(new ExportersServiceLoader(), "CGMES", network, params, tmpDir.resolve("exported"), reporter);
network.write(new ExportersServiceLoader(), "CGMES", params, tmpDir.resolve("exported"), reporter);
}
}
Loading

0 comments on commit b8476d7

Please sign in to comment.