-
Notifications
You must be signed in to change notification settings - Fork 43
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
Changes from all commits
70bccec
487490e
5c7cdc4
4dae10f
c1888c3
e4af5e4
d8f3cba
0d05b0e
39277ce
e255c01
d47d3a4
a1a30e9
2a042ce
b91b911
868dc4f
f00b2cd
b73f59b
db7c287
e358010
e241306
04db632
16d41d3
6f6ffe2
11f1175
2d0bfdf
f1234c4
17f3381
3b34c79
2bdabca
a6f7b6d
0336c6f
825c764
2bf7181
82e16c0
b3e0e2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,22 +51,23 @@ public class CgmesExportContext { | |
private static final String REGION_NAME = "regionName"; | ||
private static final String DEFAULT_REGION = "default region"; | ||
public static final String SUB_REGION_ID = "subRegionId"; | ||
private static final String BOUNDARY_EQ_ID_PROPERTY = Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + "EQ_BD_ID"; | ||
private static final String BOUNDARY_TP_ID_PROPERTY = Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + "TP_BD_ID"; | ||
|
||
private CgmesNamespace.Cim cim = CgmesNamespace.CIM_16; | ||
private CgmesTopologyKind topologyKind = CgmesTopologyKind.BUS_BRANCH; | ||
private ZonedDateTime scenarioTime = ZonedDateTime.now(); | ||
private ReportNode reportNode = ReportNode.NO_OP; | ||
private String boundaryEqId; // may be null | ||
private String boundaryTpId; // may be null | ||
private String businessProcess = DEFAULT_BUSINESS_PROCESS; | ||
|
||
private final CgmesMetadataModel exportedEQModel = new CgmesMetadataModelImpl(CgmesSubset.EQUIPMENT, DEFAULT_MODELING_AUTHORITY_SET_VALUE); | ||
private final CgmesMetadataModel exportedTPModel = new CgmesMetadataModelImpl(CgmesSubset.TOPOLOGY, DEFAULT_MODELING_AUTHORITY_SET_VALUE); | ||
private final CgmesMetadataModel exportedSVModel = new CgmesMetadataModelImpl(CgmesSubset.STATE_VARIABLES, DEFAULT_MODELING_AUTHORITY_SET_VALUE); | ||
private final CgmesMetadataModel exportedSSHModel = new CgmesMetadataModelImpl(CgmesSubset.STEADY_STATE_HYPOTHESIS, DEFAULT_MODELING_AUTHORITY_SET_VALUE); | ||
|
||
private NamingStrategy namingStrategy = new NamingStrategy.Identity(); | ||
|
||
private String modelingAuthoritySet = null; | ||
private String modelDescription = null; | ||
private String modelVersion = null; | ||
private String boundaryEqId = null; | ||
private String boundaryTpId = null; | ||
private List<String> profiles = null; | ||
private String baseName = null; | ||
public static final boolean CGM_EXPORT_VALUE = false; | ||
public static final boolean EXPORT_BOUNDARY_POWER_FLOWS_DEFAULT_VALUE = true; | ||
public static final boolean EXPORT_POWER_FLOWS_FOR_SWITCHES_DEFAULT_VALUE = true; | ||
public static final boolean EXPORT_TRANSFORMERS_WITH_HIGHEST_VOLTAGE_AT_END1_DEFAULT_VALUE = false; | ||
|
@@ -99,59 +100,6 @@ public class CgmesExportContext { | |
private final Map<String, String> fictitiousContainers = new HashMap<>(); | ||
private final Map<String, Bus> topologicalNodes = new HashMap<>(); | ||
private final ReferenceDataProvider referenceDataProvider; | ||
private final EnumMap<CgmesSubset, List<String>> legacyIdsForSvDependencies = new EnumMap<>(CgmesSubset.class); | ||
|
||
/** | ||
* Update dependencies in a way that: | ||
* SV depends on TP and SSH | ||
* TP depends on EQ | ||
* SSH depends on EQ | ||
* If the boundaries subset have been defined: | ||
* EQ depends on EQ_BD | ||
* SV depends on TP_BD | ||
*/ | ||
public void updateDependencies() { | ||
if (!updateDependencies) { | ||
return; | ||
} | ||
String eqModelId = getExportedEQModel().getId(); | ||
if (eqModelId == null || eqModelId.isEmpty()) { | ||
return; | ||
} | ||
|
||
getExportedTPModel() | ||
.clearDependencies() | ||
.addDependentOn(eqModelId); | ||
|
||
getExportedSSHModel() | ||
.clearDependencies() | ||
.addDependentOn(eqModelId); | ||
|
||
getExportedSVModel().clearDependencies(); | ||
List<String> tpIds = legacyIdsForSvDependencies.get(CgmesSubset.TOPOLOGY); | ||
if (tpIds != null) { | ||
// If the list of SV dependencies from TP files has been set, even if it is empty, | ||
// use it and ignore the exported TP model | ||
getExportedSVModel().addDependentOn(tpIds); | ||
} else { | ||
getExportedSVModel().addDependentOn(getExportedTPModel().getId()); | ||
} | ||
List<String> sshIds = legacyIdsForSvDependencies.get(CgmesSubset.STEADY_STATE_HYPOTHESIS); | ||
if (sshIds != null) { | ||
// If the list of SV dependencies from SSH files has been set, even if it is empty, | ||
// use it and ignore the exported SSH model | ||
getExportedSVModel().addDependentOn(sshIds); | ||
} else { | ||
getExportedSVModel().addDependentOn(getExportedSSHModel().getId()); | ||
} | ||
|
||
if (boundaryEqId != null) { | ||
getExportedEQModel().addDependentOn(boundaryEqId); | ||
} | ||
if (boundaryTpId != null) { | ||
getExportedSVModel().addDependentOn(boundaryTpId); | ||
} | ||
} | ||
|
||
public String getFictitiousContainerFor(Identifiable<?> id) { | ||
return fictitiousContainers.get(id.getId()); | ||
|
@@ -162,7 +110,6 @@ public void setFictitiousContainerFor(Identifiable<?> id, String containerId) { | |
} | ||
|
||
public CgmesExportContext() { | ||
initializeExportedModelProfiles(this.cim); | ||
referenceDataProvider = null; | ||
} | ||
|
||
|
@@ -183,7 +130,6 @@ public CgmesExportContext(Network network, ReferenceDataProvider referenceDataPr | |
} | ||
|
||
public CgmesExportContext(Network network, ReferenceDataProvider referenceDataProvider, NamingStrategy namingStrategy) { | ||
initializeExportedModelProfiles(this.cim); | ||
this.referenceDataProvider = referenceDataProvider; | ||
this.namingStrategy = namingStrategy; | ||
CimCharacteristics cimCharacteristics = network.getExtension(CimCharacteristics.class); | ||
|
@@ -194,41 +140,14 @@ public CgmesExportContext(Network network, ReferenceDataProvider referenceDataPr | |
topologyKind = networkTopologyKind(network); | ||
} | ||
scenarioTime = network.getCaseDate(); | ||
CgmesMetadataModels models = network.getExtension(CgmesMetadataModels.class); | ||
if (models != null) { | ||
models.getModelForSubset(CgmesSubset.EQUIPMENT).ifPresent(eq -> prepareExportedModelFrom(exportedEQModel, eq)); | ||
models.getModelForSubset(CgmesSubset.STEADY_STATE_HYPOTHESIS).ifPresent(ssh -> prepareExportedModelFrom(exportedSSHModel, ssh)); | ||
models.getModelForSubset(CgmesSubset.TOPOLOGY).ifPresent(tp -> prepareExportedModelFrom(exportedTPModel, tp)); | ||
models.getModelForSubset(CgmesSubset.STATE_VARIABLES).ifPresent(sv -> prepareExportedModelFrom(exportedSVModel, sv)); | ||
} | ||
addIidmMappings(network); | ||
} | ||
|
||
/** | ||
* Set for each exported model the profile relative to the cim version. | ||
* @param cim The cim version from which depends the models profiles uri. | ||
*/ | ||
private void initializeExportedModelProfiles(CgmesNamespace.Cim cim) { | ||
if (cim.hasProfiles()) { | ||
exportedEQModel.setProfile(cim.getProfileUri("EQ")); | ||
exportedTPModel.setProfile(cim.getProfileUri("TP")); | ||
exportedSVModel.setProfile(cim.getProfileUri("SV")); | ||
exportedSSHModel.setProfile(cim.getProfileUri("SSH")); | ||
if (network.hasProperty(BOUNDARY_EQ_ID_PROPERTY)) { | ||
setBoundaryEqId(network.getProperty(BOUNDARY_EQ_ID_PROPERTY)); | ||
} | ||
if (network.hasProperty(BOUNDARY_TP_ID_PROPERTY)) { | ||
setBoundaryTpId(network.getProperty(BOUNDARY_TP_ID_PROPERTY)); | ||
} | ||
} | ||
|
||
/** | ||
* Update the model used for the export according to the network model. | ||
* All the metadata information will be duplicated, except for the version that will be incremented. | ||
* @param exportedModel The {@link CgmesMetadataModel} used for the export. | ||
* @param fromModel The {@link CgmesMetadataModel} attached to the network. | ||
*/ | ||
private void prepareExportedModelFrom(CgmesMetadataModel exportedModel, CgmesMetadataModel fromModel) { | ||
exportedModel.setDescription(fromModel.getDescription()); | ||
exportedModel.setVersion(fromModel.getVersion() + 1); | ||
exportedModel.addSupersedes(fromModel.getId()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The md:Model.Supersedes is no longer exported in the SSH and SV file when they are generated separately There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above. Please review the added unit test. The supersedes information must also be obtained from the output file. |
||
exportedModel.addDependentOn(fromModel.getDependentOn()); | ||
exportedModel.setModelingAuthoritySet(fromModel.getModelingAuthoritySet()); | ||
} | ||
|
||
private CgmesTopologyKind networkTopologyKind(Network network) { | ||
|
@@ -367,16 +286,6 @@ public boolean isExportedEquipment(Identifiable<?> c) { | |
return !ignored; | ||
} | ||
|
||
public CgmesExportContext setBoundaryEqId(String boundaryEqId) { | ||
this.boundaryEqId = boundaryEqId; | ||
return this; | ||
} | ||
|
||
public CgmesExportContext setBoundaryTpId(String boundaryTpId) { | ||
this.boundaryTpId = boundaryTpId; | ||
return this; | ||
} | ||
|
||
private void addIidmMappingsSwitchTerminals(Network network) { | ||
for (Switch sw : network.getSwitches()) { | ||
String terminal1Id = sw.getAliasFromType(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + CgmesNames.TERMINAL + "1").orElse(null); | ||
|
@@ -637,7 +546,6 @@ public int getCimVersion() { | |
|
||
public CgmesExportContext setCimVersion(int cimVersion) { | ||
cim = CgmesNamespace.getCim(cimVersion); | ||
initializeExportedModelProfiles(cim); | ||
return this; | ||
} | ||
|
||
|
@@ -659,22 +567,6 @@ public CgmesExportContext setScenarioTime(ZonedDateTime scenarioTime) { | |
return this; | ||
} | ||
|
||
public CgmesMetadataModel getExportedEQModel() { | ||
return exportedEQModel; | ||
} | ||
|
||
public CgmesMetadataModel getExportedTPModel() { | ||
return exportedTPModel; | ||
} | ||
|
||
public CgmesMetadataModel getExportedSVModel() { | ||
return exportedSVModel; | ||
} | ||
|
||
public CgmesMetadataModel getExportedSSHModel() { | ||
return exportedSSHModel; | ||
} | ||
|
||
public boolean exportBoundaryPowerFlows() { | ||
return exportBoundaryPowerFlows; | ||
} | ||
|
@@ -823,13 +715,76 @@ public CgmesExportContext setBusinessProcess(String businessProcess) { | |
return this; | ||
} | ||
|
||
public void setLegacyIdsForSvDependencies(CgmesSubset subset, List<String> ids) { | ||
legacyIdsForSvDependencies.put(subset, ids); | ||
public String getModelingAuthoritySet() { | ||
return modelingAuthoritySet; | ||
} | ||
|
||
public CgmesExportContext setModelingAuthoritySet(String modelingAuthoritySet) { | ||
this.modelingAuthoritySet = modelingAuthoritySet; | ||
return this; | ||
} | ||
|
||
public String getModelDescription() { | ||
return modelDescription; | ||
} | ||
|
||
public CgmesExportContext setModelDescription(String modelDescription) { | ||
this.modelDescription = modelDescription; | ||
return this; | ||
} | ||
|
||
public String getModelVersion() { | ||
return modelVersion; | ||
} | ||
|
||
public CgmesExportContext setModelVersion(String modelVersion) { | ||
this.modelVersion = modelVersion; | ||
return this; | ||
} | ||
|
||
public String getBoundaryEqId() { | ||
return boundaryEqId; | ||
} | ||
|
||
public CgmesExportContext setBoundaryEqId(String boundaryEqId) { | ||
this.boundaryEqId = boundaryEqId; | ||
return this; | ||
} | ||
|
||
public String getBoundaryTpId() { | ||
return boundaryTpId; | ||
} | ||
|
||
public CgmesExportContext setBoundaryTpId(String boundaryTpId) { | ||
this.boundaryTpId = boundaryTpId; | ||
return this; | ||
} | ||
|
||
public List<String> getProfiles() { | ||
return profiles; | ||
} | ||
|
||
public CgmesExportContext setProfiles(List<String> profiles) { | ||
this.profiles = profiles; | ||
return this; | ||
} | ||
|
||
public String getBaseName() { | ||
return baseName; | ||
} | ||
|
||
public CgmesExportContext setBaseName(String baseName) { | ||
this.baseName = baseName; | ||
return this; | ||
} | ||
|
||
public CgmesExportContext setUpdateDependencies(boolean updateDependencies) { | ||
this.updateDependencies = updateDependencies; | ||
return this; | ||
} | ||
|
||
public boolean updateDependencies() { | ||
return updateDependencies; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exported model does no longer increment the version for SSH and SV when they are generated separately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The metadata models in the Network are never updated after export (this is by design). To obtain the version of the exported files one must read the contents of the output.
I've prepared a unit test that I think demonstrates and clarifies how this CGM export can be used. It is inside
CommonGridModelExportTest::testFaraoUseCase
.