Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CGMES export. Handle CGM export dependencies #2927

Merged
merged 35 commits into from
Jun 19, 2024

Conversation

zamarrenolm
Copy link
Member

@zamarrenolm zamarrenolm commented Mar 12, 2024

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Does this PR already have an issue describing the problem?

What kind of change does this PR introduce?

Feature.

What is the current behavior?

CGMES export only considers IGM (Individual Grid Model) dependencies when exporting.

What is the new behavior (if this is a feature change)?
CGMES export will consider the dependencies required for CGM (Common Grid Model) export.

A Merging Agent using PowSyBl will export first an updated SSH for each IGM,
that should contain a Supersedes reference to the IGM’s original SSH CIMXML file.

Then, the Merging Agent should export a single SV for the whole CGM. This SV file must contain a DependentOn reference to each IGM’s updated SSH. The power flow of a CGM is calculated without topology processing. No new TP CIMXML files are created. This means that the CGM SV file must contain a DependentOn reference to each IGM’s original TP.

Does this PR introduce a breaking change or deprecate an API?

  • Yes
  • No

If yes, please check if the following requirements are fulfilled

  • The Breaking Change or Deprecated label has been added
  • The migration steps are described in the following section

What changes might users need to make in their application due to this PR? (migration steps)

Other information:

This change is based on #2898

@annetill annetill changed the base branch from main to cgmes_metadata_models March 14, 2024 14:30
@zamarrenolm
Copy link
Member Author

When exporting a CGM, we need a Network with Subnetworks, and we expect the "profiles" to be exported to be "SSH,SV".

We have to export an updated SSH for every Subnetwork (for every IGM) and a single SV for the main Network (that represents the CGM).

We could have the parameter explicit, defined as the rest of configuration values in the CgmesImport, or just assume that it will be true if the network that is being exported has more than one Subnetwork and the profiles requested are "SSH,SV". We could save in the context if we are exporting a CGM solution:

context.isExportCommongGridModelSolution = network.getSubnetworks().size() > 1
                && parts.contains("SSH")
                && parts.contains("SV");

It would be nice to refactor the current contents of the CgmesExport::export function, splitting the code in separate methods to:

  • Determine basename for exported files.
  • Determine reference data (boundaries that will be used for exported data).
  • Create the Context (the object that will store relevant data for export).
  • Determine the modeling authority.
  • Prepare the metadata Models for the exported instance files.
  • Export instance files.

Then, when exporting the SSH instance files, we should consider whether we are exporting a CGM solution:

if (context.isExportCommongGridModelSolution) {
    for (Network sn : network.getSubnetworks()) {
        exportUpdatedSSHForIGM(sn, ds, context, baseName, parts, masUri);
    }
} else {
    exportSSH(network, ds, context, baseName, parts);
}

The method that outputs the updated SSH for an IGM should look like the following:

void exportUpdatedSSHForIGM(Subnetwork subnetwork, ...) {
  CgmesMetadataModel updatedSSHModel = new CgmesMetadataModel(CgmesSubset.STEADY_STATE_HYPOTHESIS, modelingAuthoritySet);
  subnetwork
      .getExtension(CgmesMetadataModels.class)
      .getModelForPart(CgmesSubset.STEADY_STATE_HYPOTHESIS)
      .ifPresent(ssh -> context.prepareExportedModelFrom(updatedSSHModel, ssh));
  SteadyStateHypothesisExport.write(subnetwork, writer, context, updatedSSHModel);
  context.igmUpdatedSshModels.add(updatedSSHModel.getId());
}

The non-null check for result of subnetwork.getExtension is omitted in this pseudo-code.
Also, a call to context.addIidmMappingsControlArea(subnetwork) before SteadyStateHypothesis.write will be required to initialise data related to control areas required in the export.

@rcourtier rcourtier force-pushed the cgmes_cgm_export_dependencies branch from d7b9d82 to a902a87 Compare March 22, 2024 15:29
@rcourtier rcourtier mentioned this pull request Mar 26, 2024
7 tasks
Base automatically changed from cgmes_metadata_models to main March 26, 2024 15:23
zamarrenolm and others added 4 commits March 28, 2024 10:41
Signed-off-by: Luma <zamarrenolm@aia.es>
Signed-off-by: Luma <zamarrenolm@aia.es>
Signed-off-by: Romain Courtier <romain.courtier@rte-france.com>
Signed-off-by: Romain Courtier <romain.courtier@rte-france.com>
@rcourtier rcourtier force-pushed the cgmes_cgm_export_dependencies branch from c81b1d8 to 4dae10f Compare March 28, 2024 10:14
Signed-off-by: Romain Courtier <romain.courtier@rte-france.com>
Signed-off-by: Romain Courtier <romain.courtier@rte-france.com>
@rcourtier rcourtier changed the title [WIP] CGMES export. Handle CGM export dependencies CGMES export. Handle CGM export dependencies Apr 12, 2024
@rcourtier rcourtier marked this pull request as ready for review April 12, 2024 21:25
@rcourtier rcourtier requested a review from annetill April 12, 2024 21:27
@zamarrenolm
Copy link
Member Author

To build the filename template for exported SSH we should look into QoCDC rule FilenameMD. We should use a sourcing actor reference that is composed of <sourcingRSC>-<cgmRegion>-<sourcingTSO> (the merging agent, the region for the CGM and each TSO sourcing actor identifier). Currently, we are using only the country id.

* @return A model with all necessary metadata information for the export.
*/
public static CgmesMetadataModel initializeModelForExport(
Network network, CgmesSubset subset, CgmesExportContext context, Boolean mainNetwork, Boolean modelUpdate) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use primitive boolean's here? the conditions below will be more concise and readable

*/
private void updateDependenciesCGM(Collection<IgmModelsForCgm> igmModels, CgmesMetadataModel updatedCgmSvModel) {
// Each updated SSH model supersedes the original one
igmModels.forEach(m -> m.updatedSsh.clearDependencies());
Copy link
Member Author

@zamarrenolm zamarrenolm Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we must keep the dependencies of the original SSH. If we clear the dependencies, we lose the SSH dependent on the EQ. This dependency has been correctly prepared in the method initializeModelForExport, but is removed if we clear the dependencies here.

Signed-off-by: Luma <zamarrenolm@aia.es>
Signed-off-by: Luma <zamarrenolm@aia.es>
Signed-off-by: Luma <zamarrenolm@aia.es>
Signed-off-by: Luma <zamarrenolm@aia.es>
Signed-off-by: Luma <zamarrenolm@aia.es>
Signed-off-by: Luma <zamarrenolm@aia.es>
Signed-off-by: Luma <zamarrenolm@aia.es>
@zamarrenolm
Copy link
Member Author

When exporting a CGM, we need a Network with Subnetworks, and we expect the "profiles" to be exported to be "SSH,SV".
We have to export an updated SSH for every Subnetwork (for every IGM) and a single SV for the main Network (that represents the CGM).
We could have the parameter explicit, defined as the rest of configuration values in the CgmesImport, or just assume that it will be true if the network that is being exported has more than one Subnetwork and the profiles requested are "SSH,SV". We could save in the context if we are exporting a CGM solution:

context.isExportCommongGridModelSolution = network.getSubnetworks().size() > 1
                && parts.contains("SSH")
                && parts.contains("SV");

It would be nice to refactor the current contents of the CgmesExport::export function, splitting the code in separate methods to:

  • Determine basename for exported files.
  • Determine reference data (boundaries that will be used for exported data).
  • Create the Context (the object that will store relevant data for export).
  • Determine the modeling authority.
  • Prepare the metadata Models for the exported instance files.
  • Export instance files.

Then, when exporting the SSH instance files, we should consider whether we are exporting a CGM solution:

if (context.isExportCommongGridModelSolution) {
    for (Network sn : network.getSubnetworks()) {
        exportUpdatedSSHForIGM(sn, ds, context, baseName, parts, masUri);
    }
} else {
    exportSSH(network, ds, context, baseName, parts);
}

The method that outputs the updated SSH for an IGM should look like the following:

void exportUpdatedSSHForIGM(Subnetwork subnetwork, ...) {
  CgmesMetadataModel updatedSSHModel = new CgmesMetadataModel(CgmesSubset.STEADY_STATE_HYPOTHESIS, modelingAuthoritySet);
  subnetwork
      .getExtension(CgmesMetadataModels.class)
      .getModelForPart(CgmesSubset.STEADY_STATE_HYPOTHESIS)
      .ifPresent(ssh -> context.prepareExportedModelFrom(updatedSSHModel, ssh));
  SteadyStateHypothesisExport.write(subnetwork, writer, context, updatedSSHModel);
  context.igmUpdatedSshModels.add(updatedSSHModel.getId());
}

The non-null check for result of subnetwork.getExtension is omitted in this pseudo-code. Also, a call to context.addIidmMappingsControlArea(subnetwork) before SteadyStateHypothesis.write will be required to initialise data related to control areas required in the export.

Can you transfer a part of this to the documentation (readthedocs now). We have now an "exported.md" in CGMES to explain how to export CGM. Thanks !

Done. I added documentation for the new parameters and a brief explanation of the two main use-cases for export: IGM and CGM.

Signed-off-by: Luma <zamarrenolm@aia.es>
Signed-off-by: Luma <zamarrenolm@aia.es>
@@ -261,6 +519,8 @@ public String getFormat() {
public static final String EXPORT_POWER_FLOWS_FOR_SWITCHES = "iidm.export.cgmes.export-power-flows-for-switches";
public static final String NAMING_STRATEGY = "iidm.export.cgmes.naming-strategy";
public static final String PROFILES = "iidm.export.cgmes.profiles";
public static final String CGM_EXPORT = "iidm.export.cgmes.cgm_export";
public static final String MODEL_UPDATE = "iidm.export.cgmes.model_update";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parameter key is not used anymore (unless in some unit tests).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the obsolete parameter name and its uses in unit tests

level of the PowSyBl network.

## CGM (Common Grid Model) export

When exporting a CGM, we need an IIDM network (CGM) that contains multiple subnetworks (one for each IGM).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with this part: if we want to export a CGM with EQ and TP files, we can do it too. We have 2 methods to export CGM, a quick one that you are describing and a more complex one manipulating extensions and exporting profile by profile. Both must be explained and illustrated here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added documentation for the two ways of exporting CGM: quick and manual. Included code to illustrate both ways of generating the required files. Also added a unit test for the "manual" option, showing how metadata can be defined by the user by setting information in the related extension.

Signed-off-by: Luma <zamarrenolm@aia.es>
Signed-off-by: Luma <zamarrenolm@aia.es>
Signed-off-by: Luma <zamarrenolm@aia.es>
Signed-off-by: Luma <zamarrenolm@aia.es>
Signed-off-by: Luma <zamarrenolm@aia.es>
Signed-off-by: Luma <zamarrenolm@aia.es>
Copy link
Member

@annetill annetill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small changes in doc.

docs/grid_exchange_formats/cgmes/export.md Outdated Show resolved Hide resolved
Network cgmNetwork = Network.read(CgmesConformity1Catalog.microGridBaseCaseAssembled().dataSource());

Properties exportParams = new Properties();
exportParams.put(CgmesExport.PROFILES, List.of("SV", "SSH"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens here if I put "EQ", "TP", "SSH" and "SV" ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, after a small test, changing this list does not change anything. We always export SV and SSH, even if I only put SV.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clarified the documentation to explicitly state that CGM quick export ignores the profiles parameter and always exports SSH IGMs and CGM SV. Removed the parameter from the code example in the docs and from the main unit test showing its use.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you pushed?

exportParams.put(CgmesExport.NAMING_STRATEGY, "cgmes");
// We do not want a quick CGM export
exportParams.put(CgmesExport.CGM_EXPORT, false);
exportParams.put(CgmesExport.UPDATE_DEPENDENCIES, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure update dependencies parameter is used for CGM export?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the update dependencies parameter is considered for both for CGM quick export and in manual network export. For CGM quick export dependencies are updated in CgmesExport::updateDependenciesCGM. For manual network export they are handled in CgmesExport::updateDependenciesIGM.

zamarrenolm and others added 3 commits June 18, 2024 14:35
Signed-off-by: Luma <zamarrenolm@aia.es>
Signed-off-by: Anne Tilloy <anne.tilloy@rte-france.com>
…H, SV

Signed-off-by: Luma <zamarrenolm@aia.es>
Copy link
Member

@annetill annetill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, looks good!

Copy link

@annetill annetill merged commit e0deb3e into main Jun 19, 2024
7 checks passed
@annetill annetill deleted the cgmes_cgm_export_dependencies branch June 19, 2024 11:12
geofjamg pushed a commit that referenced this pull request Sep 18, 2024
Signed-off-by: Luma <zamarrenolm@aia.es>
Co-authored-by: Romain Courtier <romain.courtier@rte-france.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants