Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/nro/make_network_copy_use_binari…
Browse files Browse the repository at this point in the history
…es' into nro/make_network_copy_use_binaries
  • Loading branch information
rolnico committed Sep 24, 2024
2 parents e89019b + fdb3846 commit ec0bed4
Show file tree
Hide file tree
Showing 216 changed files with 4,517 additions and 1,349 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ By participating, you are expected to uphold this code. Please report unacceptab

This document describes how to build the code of PowSyBl Core. If you just want to run PowSyBl demos, please visit
https://www.powsybl.org/ where downloads will be available soon. If you want guidance on how to start building your own
application based on PowSyBl, please visit the [tutorials](https://www.powsybl.org/pages/documentation/developer/tutorials/) page.
application based on PowSyBl, please visit the [tutorials](https://powsybl.readthedocs.io/projects/powsybl-tutorials/) page.

The PowSyBl Core project is not a standalone project. Read on to learn how to modify the core code, be it for fun, for
diagnosing bugs, for improving your understanding of the framework, or for preparing pull requests to suggest improvements!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,24 @@ public void export(Network network, Properties parameters, DataSource dataSource
private void exportCGM(Network network, DataSource dataSource, CgmesExportContext context) {
checkCgmConsistency(network, context);

// Initialize models for export. The original IGM TP and SSH don't get exported,
// Initialize models for export. The original IGM EQ, SSH, TP and TP_BD don't get exported,
// but we need to init their models to retrieve their IDs when building the dependencies.
Map<Network, IgmModelsForCgm> igmModels = new HashMap<>();
for (Network subnetwork : network.getSubnetworks()) {
IgmModelsForCgm igmModelsForCgm = new IgmModelsForCgm(
initializeModelForExport(subnetwork, CgmesSubset.STEADY_STATE_HYPOTHESIS, context, false, false),
initializeModelForExport(subnetwork, CgmesSubset.STEADY_STATE_HYPOTHESIS, context, false, true),
initializeModelForExport(subnetwork, CgmesSubset.TOPOLOGY, context, false, false)
initializeModelForExport(subnetwork, CgmesSubset.EQUIPMENT, context, false, false),
initializeModelForExport(subnetwork, CgmesSubset.STEADY_STATE_HYPOTHESIS, context, false, false),
initializeModelForExport(subnetwork, CgmesSubset.TOPOLOGY, context, false, false),
initializeModelForExport(subnetwork, CgmesSubset.TOPOLOGY_BOUNDARY, context, false, false)
);
igmModels.put(subnetwork, igmModelsForCgm);
}
CgmesMetadataModel updatedCgmSvModel = initializeModelForExport(network, CgmesSubset.STATE_VARIABLES, context, true, true);

// Update dependencies
if (context.updateDependencies()) {
updateDependenciesCGM(igmModels.values(), updatedCgmSvModel);
updateDependenciesCGM(igmModels.values(), updatedCgmSvModel, context.getBoundaryTpId());
}

// Export the SSH for the IGMs and the SV for the CGM
Expand Down Expand Up @@ -227,22 +229,29 @@ public static CgmesMetadataModel initializeModelForExport(
}

/**
* Update cross dependencies between the subset models through the dependentOn relationship.
* The IGMs updated SSH supersede the original ones.
* The CGM updated SV depends on the IGMs updated SSH and on the IGMs original TP.
* @param igmModels For each IGM: the original SSH model, the updated SSH model and the original TP model.
* Update cross dependencies between the subset models (including boundaries) through the dependentOn relationship.
* The IGMs updated SSH supersede the original ones and depend on the original EQ. Other dependencies are kept.
* The CGM updated SV depends on the IGMs updated SSH and on the IGMs original TP and TP_BD.
* @param igmModels For each IGM: the updated SSH model and the original SSH, TP and TP_BD models.
* @param updatedCgmSvModel The SV model for the CGM.
* @param boundaryTpId The model id for the TP_BD subset.
*/
private void updateDependenciesCGM(Collection<IgmModelsForCgm> igmModels, CgmesMetadataModel updatedCgmSvModel) {
private void updateDependenciesCGM(Collection<IgmModelsForCgm> igmModels, CgmesMetadataModel updatedCgmSvModel, String boundaryTpId) {
// Each updated SSH model depends on the original EQ model
igmModels.forEach(m -> m.updatedSsh.addDependentOn(m.originalEq.getId()));

// Each updated SSH model supersedes the original one
// Clear previous dependencies
igmModels.forEach(m -> m.updatedSsh.clearDependencies());
igmModels.forEach(m -> m.updatedSsh.clearSupersedes());
igmModels.forEach(m -> m.updatedSsh.addSupersedes(m.originalSsh.getId()));

// Updated SV model depends on updated SSH models and original TP models
// Updated SV model depends on updated SSH models and original TP and TP_BD models
updatedCgmSvModel.addDependentOn(igmModels.stream().map(m -> m.updatedSsh.getId()).collect(Collectors.toSet()));
updatedCgmSvModel.addDependentOn(igmModels.stream().map(m -> m.originalTp.getId()).collect(Collectors.toSet()));
if (boundaryTpId != null) {
updatedCgmSvModel.addDependentOn(boundaryTpId);
} else {
updatedCgmSvModel.addDependentOn(igmModels.stream().map(m -> m.originalTpBd.getId()).collect(Collectors.toSet()));
}
}

/**
Expand Down Expand Up @@ -492,14 +501,19 @@ private String getBaseName(CgmesExportContext context, DataSource dataSource, Ne
* when setting the relationships (dependOn, supersedes) between them in a CGM export.
*/
private static class IgmModelsForCgm {
CgmesMetadataModel originalSsh;
CgmesMetadataModel updatedSsh;
CgmesMetadataModel originalEq;
CgmesMetadataModel originalSsh;
CgmesMetadataModel originalTp;
CgmesMetadataModel originalTpBd;

public IgmModelsForCgm(CgmesMetadataModel originalSsh, CgmesMetadataModel updatedSsh, CgmesMetadataModel originalTp) {
this.originalSsh = originalSsh;
public IgmModelsForCgm(CgmesMetadataModel updatedSsh, CgmesMetadataModel originalEq, CgmesMetadataModel originalSsh,
CgmesMetadataModel originalTp, CgmesMetadataModel originalTpBd) {
this.updatedSsh = updatedSsh;
this.originalEq = originalEq;
this.originalSsh = originalSsh;
this.originalTp = originalTp;
this.originalTpBd = originalTpBd;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ public String getFormat() {
return FORMAT;
}

@Override
public List<String> getSupportedExtensions() {
return List.of("xml");
}

@Override
public Network importData(ReadOnlyDataSource ds, NetworkFactory networkFactory, Properties p, ReportNode reportNode) {
Objects.requireNonNull(ds);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright (c) 2024, 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/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.cgmes.conversion.test;

import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import com.powsybl.cgmes.conversion.CgmesImport;
import com.powsybl.commons.config.InMemoryPlatformConfig;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
*/
class CgmesImporterMetaInfoTest {

@Test
void test() throws IOException {
try (var fs = Jimfs.newFileSystem(Configuration.unix())) {
var importer = new CgmesImport(new InMemoryPlatformConfig(fs));
assertEquals("CGMES", importer.getFormat());
assertEquals("ENTSO-E CGMES version 2.4.15", importer.getComment());
assertEquals(List.of("xml"), importer.getSupportedExtensions());
}
}
}
Loading

0 comments on commit ec0bed4

Please sign in to comment.