Skip to content

Commit

Permalink
Fixes in CGMES export (#2574)
Browse files Browse the repository at this point in the history
Signed-off-by: Coline PILOQUET <coline.piloquet@rte-france.com>
Signed-off-by: Luma <zamarrenolm@aia.es>
Signed-off-by: Anne Tilloy <anne.tilloy@rte-france.com>
  • Loading branch information
colinepiloquet authored May 31, 2023
1 parent b7f9c3d commit 3ac1b87
Show file tree
Hide file tree
Showing 19 changed files with 232 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public void export(Network network, Properties params, DataSource ds, Reporter r
.setBoundaryEqId(getBoundaryId("EQ", network, params, BOUNDARY_EQ_ID_PARAMETER))
.setBoundaryTpId(getBoundaryId("TP", network, params, BOUNDARY_TP_ID_PARAMETER))
.setReporter(reporter);
context.getEqModelDescription().setModelingAuthoritySet(Parameter.readString(getFormat(), params, MODELING_AUTHORITY_SET_PARAMETER, defaultValueConfig));
context.getTpModelDescription().setModelingAuthoritySet(Parameter.readString(getFormat(), params, MODELING_AUTHORITY_SET_PARAMETER, defaultValueConfig));
context.getSshModelDescription().setModelingAuthoritySet(Parameter.readString(getFormat(), params, MODELING_AUTHORITY_SET_PARAMETER, defaultValueConfig));
context.getSvModelDescription().setModelingAuthoritySet(Parameter.readString(getFormat(), params, MODELING_AUTHORITY_SET_PARAMETER, defaultValueConfig));
String cimVersionParam = Parameter.readString(getFormat(), params, CIM_VERSION_PARAMETER, defaultValueConfig);
if (cimVersionParam != null) {
context.setCimVersion(Integer.parseInt(cimVersionParam));
Expand Down Expand Up @@ -177,6 +181,7 @@ 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 MODELING_AUTHORITY_SET = "iidm.export.cgmes.modeling-authority-set";

private static final Parameter BASE_NAME_PARAMETER = new Parameter(
BASE_NAME,
Expand All @@ -193,17 +198,17 @@ public String getFormat() {
ENCODE_IDS,
ParameterType.BOOLEAN,
"Encode IDs as valid URI",
Boolean.TRUE);
CgmesExportContext.ENCODE_IDS_DEFAULT_VALUE);
private static final Parameter EXPORT_BOUNDARY_POWER_FLOWS_PARAMETER = new Parameter(
EXPORT_BOUNDARY_POWER_FLOWS,
ParameterType.BOOLEAN,
"Export boundaries' power flows",
Boolean.TRUE);
CgmesExportContext.EXPORT_BOUNDARY_POWER_FLOWS_DEFAULT_VALUE);
private static final Parameter EXPORT_POWER_FLOWS_FOR_SWITCHES_PARAMETER = new Parameter(
EXPORT_POWER_FLOWS_FOR_SWITCHES,
ParameterType.BOOLEAN,
"Export power flows for switches",
Boolean.FALSE);
CgmesExportContext.EXPORT_POWER_FLOWS_FOR_SWITCHES_DEFAULT_VALUE);
private static final Parameter NAMING_STRATEGY_PARAMETER = new Parameter(
NAMING_STRATEGY,
ParameterType.STRING,
Expand All @@ -227,6 +232,12 @@ public String getFormat() {
"Boundary TP model identifier",
null);

private static final Parameter MODELING_AUTHORITY_SET_PARAMETER = new Parameter(
MODELING_AUTHORITY_SET,
ParameterType.STRING,
"Modeling authority set",
"powsybl.org");

private static final List<Parameter> STATIC_PARAMETERS = List.of(
BASE_NAME_PARAMETER,
CIM_VERSION_PARAMETER,
Expand All @@ -235,7 +246,8 @@ public String getFormat() {
NAMING_STRATEGY_PARAMETER,
PROFILES_PARAMETER,
BOUNDARY_EQ_ID_PARAMETER,
BOUNDARY_TP_ID_PARAMETER);
BOUNDARY_TP_ID_PARAMETER,
MODELING_AUTHORITY_SET_PARAMETER);

private static final Logger LOG = LoggerFactory.getLogger(CgmesExport.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,15 @@ public class CgmesExportContext {

private NamingStrategy namingStrategy = new NamingStrategy.Identity();

private boolean exportBoundaryPowerFlows = true;
private boolean exportFlowsForSwitches = 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 ENCODE_IDS_DEFAULT_VALUE = true;
public static final double MAXIMUM_DOUBLE_DEFAULT_VALUE = Double.MAX_VALUE;

private boolean exportBoundaryPowerFlows = EXPORT_BOUNDARY_POWER_FLOWS_DEFAULT_VALUE;
private boolean exportFlowsForSwitches = EXPORT_POWER_FLOWS_FOR_SWITCHES_DEFAULT_VALUE;
private boolean exportEquipment = false;
private boolean encodeIds = true;
private boolean encodeIds = ENCODE_IDS_DEFAULT_VALUE;

private final Map<Double, BaseVoltageMapping.BaseVoltageSource> baseVoltageByNominalVoltageMapping = new HashMap<>();

Expand All @@ -69,7 +74,7 @@ public class CgmesExportContext {

// Update dependencies in a way that:
// [EQ.dependentOn EQ_BD]
// SV.dependentOn TP, SSH
// SV.dependentOn TP, SSH[, TP_BD]
// TP.dependentOn EQ[, EQ_BD][, TP_BD]
// SSH.dependentOn EQ
public void updateDependencies() {
Expand All @@ -89,14 +94,14 @@ public void updateDependencies() {
Set<String> sshModelIds = getSshModelDescription().getIds();
if (!sshModelIds.isEmpty()) {
getSvModelDescription().addDependencies(sshModelIds);
getSvModelDescription().addDependencies(sshModelIds);
}
if (boundaryEqId != null) {
getEqModelDescription().addDependency(boundaryEqId);
getTpModelDescription().addDependency(boundaryEqId);
}
if (boundaryTpId != null) {
getTpModelDescription().addDependency(boundaryTpId);
getSvModelDescription().addDependency(boundaryTpId);
}
}
}
Expand Down Expand Up @@ -339,6 +344,13 @@ public boolean isExportedEquipment(Identifiable<?> c) {
boolean ignored = c.isFictitious() &&
(c instanceof Load
|| c instanceof Switch && "true".equals(c.getProperty(Conversion.PROPERTY_IS_CREATED_FOR_DISCONNECTED_TERMINAL)));
if (c instanceof Switch) {
Switch ss = (Switch) c;
VoltageLevel.BusBreakerView view = ss.getVoltageLevel().getBusBreakerView();
if (ss.isRetained() && view.getBus1(ss.getId()).equals(view.getBus2(ss.getId()))) {
ignored = true;
}
}
return !ignored;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,20 @@ private CgmesExportUtil() {
private static final Pattern ENTSOE_BD_EXCEPTIONS_PATTERN1 = Pattern.compile("(?i)[a-f\\d]{8}-[a-f\\d]{4}-[a-f\\d]{4}-[a-f\\d]{4}-[a-f\\d]{7}");
private static final Pattern ENTSOE_BD_EXCEPTIONS_PATTERN2 = Pattern.compile("(?i)[a-f\\d]{8}[a-f\\d]{4}[a-f\\d]{4}[a-f\\d]{4}[a-f\\d]{12}");

private static double fixValue(double value) {
return Double.isNaN(value) ? 0.0 : value; // disconnected equipment in general, a bit dangerous.
}

public static String format(double value) {
return DOUBLE_FORMAT.format(Double.isNaN(value) ? 0.0 : value);
// Always use scientific format for extreme values
if (value == Double.MAX_VALUE || value == -Double.MAX_VALUE) {
return scientificFormat(value);
}
return DOUBLE_FORMAT.format(fixValue(value));
}

public static String scientificFormat(double value) {
return SCIENTIFIC_FORMAT.format(Double.isNaN(value) ? 0.0 : value);
return SCIENTIFIC_FORMAT.format(fixValue(value));
}

public static String format(int value) {
Expand Down Expand Up @@ -182,10 +190,10 @@ public static String loadClassName(LoadDetail loadDetail) {
if (loadDetail.getFixedActivePower() == 0 && loadDetail.getFixedReactivePower() == 0
&& (loadDetail.getVariableActivePower() != 0 || loadDetail.getVariableReactivePower() != 0)) {
return CgmesNames.CONFORM_LOAD;
}
// NonConform load if fixed part is non-zero and variable part is all zero
if (loadDetail.getVariableActivePower() == 0 && loadDetail.getVariableReactivePower() == 0
&& (loadDetail.getFixedActivePower() != 0 || loadDetail.getFixedReactivePower() != 0)) {
} else if (loadDetail.getVariableActivePower() == 0 && loadDetail.getVariableReactivePower() == 0
&& (loadDetail.getFixedActivePower() != 0 || loadDetail.getFixedReactivePower() != 0)) { // NonConform load if fixed part is non-zero and variable part is all zero
return CgmesNames.NONCONFORM_LOAD;
} else {
return CgmesNames.NONCONFORM_LOAD;
}
}
Expand Down
Loading

0 comments on commit 3ac1b87

Please sign in to comment.