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

Ampl exporter : add versionning #2597

Merged
merged 33 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9379bef
add constructor with list instead of varargs
Jun 2, 2023
dbf18e0
WIP add ampl export version
Jun 2, 2023
4143d1a
refactor all writing to BasicAmplExporter
Jun 2, 2023
84987ea
match setVersion to return this
Jun 2, 2023
54fa975
AmplExportVersion is now an interface
Jun 2, 2023
8be12fe
missing author and licence
Jun 2, 2023
595b20b
typo in writeThreeWindingsTranformersMiddleBusesColumnsToFormatter
Jun 5, 2023
57cd659
integrating #2596 into this PR
Jun 5, 2023
73884d9
fix function accepting only implementation and not interface
Jun 7, 2023
8c67231
Accept version in parameters of AmplExport service
Jun 7, 2023
fc3adf0
add header file indicating version
Jun 12, 2023
38eba0a
fix test because of new version parameter
Jun 12, 2023
639bbd5
Merge remote-tracking branch 'origin/main' into ampl/export-slack
Jun 13, 2023
a0160f3
fix BasicAmplExporter according to b7f9c3df
Jun 13, 2023
261c0e0
clean
Jun 13, 2023
b96f2a9
Merge branch 'main' into ampl/export-slack
annetill Aug 31, 2023
0f27df1
Merge branch 'main' into ampl/export-slack
olperr1 Nov 2, 2023
43dabbb
formatting
pjeanmarie Nov 6, 2023
51a9598
SPDX clause missing
pjeanmarie Nov 6, 2023
20bc489
escape email to avoid javadoc warnings
pjeanmarie Nov 6, 2023
54cdc68
Add missing Override
pjeanmarie Nov 6, 2023
4db1b94
Improve switch case
pjeanmarie Nov 6, 2023
fa3aa31
To be consistent
pjeanmarie Nov 6, 2023
9a08421
Distinct columns headers from suffix
Nov 7, 2023
759507d
If we want to use valueOf which exist on enum, than there is not usag…
Nov 7, 2023
2331afe
Fix comment
Nov 10, 2023
5454e50
Light refacto
Nov 10, 2023
8f60ac3
Actual version of Ampl is 1.0 so use that instead of V1_LEGACY
Nov 10, 2023
c8dd384
Merge branch 'main' into ampl/export-slack
Nov 10, 2023
6d32105
Use exporter id instead of AmplExportVersion enum name in properties …
Nov 14, 2023
aa351b4
Merge branch 'main' into ampl/export-slack
annetill Nov 15, 2023
1c16e45
Merge branch 'main' into ampl/export-slack
olperr1 Nov 23, 2023
d13ac2c
Merge branch 'main' into ampl/export-slack
olperr1 Nov 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,39 @@
import java.util.Locale;

/**
*
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public final class AmplConstants {

private AmplConstants() {
}

public static final String XNODE_COUNTRY_NAME = "XNODE";
public static final String FAULT = "fault";
public static final String DESCRIPTION = "description";
public static final String SUBSTATION = "substation";
public static final String TARGET_V = "targetV (pu)";
public static final String TARGET_Q = "targetQ (MVar)";
public static final String CON_BUS = "con. bus";
public static final String MINP = "minP (MW)";
public static final String MAXP = "maxP (MW)";
public static final String V_REGUL = "v regul.";
public static final String ACTIVE_POWER = "P (MW)";
public static final String REACTIVE_POWER = "Q (MVar)";
public static final String MIN_Q_MAX_P = "minQmaxP (MVar)";
public static final String MIN_Q0 = "minQ0 (MVar)";
public static final String MIN_Q_MIN_P = "minQminP (MVar)";
public static final String MAX_Q_MAX_P = "maxQmaxP (MVar)";
public static final String MAX_Q0 = "maxQ0 (MVar)";
public static final String MAX_Q_MIN_P = "maxQminP (MVar)";
public static final String NUM = "num";
public static final String BUS = "bus";
public static final String P0 = "p0 (MW)";
public static final String Q0 = "q0 (MW)";
public static final String ID = "id";
public static final String RATIO_TABLE = "_ratio_table";
public static final String PHASE_TABLE = "_phase_table";
pjeanmarie marked this conversation as resolved.
Show resolved Hide resolved

public static final float INVALID_FLOAT_VALUE = -99999f;

public static final Locale LOCALE = Locale.US;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
*/
package com.powsybl.ampl.converter;

import com.powsybl.ampl.converter.version.AmplExportVersion;
import com.powsybl.ampl.converter.version.AmplExportVersionImpl;

import java.util.Objects;

/**
Expand Down Expand Up @@ -38,6 +41,8 @@ public String getLabel() {

private ExportScope exportScope;

private AmplExportVersion version;

private boolean exportXNodes;

private ExportActionType actionType;
Expand All @@ -47,15 +52,24 @@ public String getLabel() {
private boolean twtSplitShuntAdmittance;

public AmplExportConfig(ExportScope exportScope, boolean exportXNodes, ExportActionType actionType) {
this(exportScope, exportXNodes, actionType, false, false);
this(exportScope, exportXNodes, actionType, false, false, AmplExportVersionImpl.V1_LEGACY);
}

public AmplExportConfig(ExportScope exportScope, boolean exportXNodes, ExportActionType actionType, boolean exportRatioTapChangerVoltageTarget, boolean twtSplitShuntAdmittance) {
public AmplExportConfig(ExportScope exportScope, boolean exportXNodes, ExportActionType actionType,
boolean exportRatioTapChangerVoltageTarget, boolean twtSplitShuntAdmittance) {
this(exportScope, exportXNodes, actionType, exportRatioTapChangerVoltageTarget, twtSplitShuntAdmittance,
AmplExportVersionImpl.V1_LEGACY);
}

public AmplExportConfig(ExportScope exportScope, boolean exportXNodes, ExportActionType actionType,
boolean exportRatioTapChangerVoltageTarget, boolean twtSplitShuntAdmittance,
AmplExportVersion version) {
this.exportScope = Objects.requireNonNull(exportScope);
this.exportXNodes = exportXNodes;
this.actionType = Objects.requireNonNull(actionType);
this.exportRatioTapChangerVoltageTarget = exportRatioTapChangerVoltageTarget;
this.twtSplitShuntAdmittance = twtSplitShuntAdmittance;
this.version = Objects.requireNonNull(version);
}

public ExportScope getExportScope() {
Expand Down Expand Up @@ -103,4 +117,13 @@ public AmplExportConfig setTwtSplitShuntAdmittance(boolean twtSplitShuntAdmittan
return this;
}

public AmplExportVersion getVersion() {
return version;
}

public AmplExportConfig setVersion(AmplExportVersion version) {
this.version = Objects.requireNonNull(version);
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
package com.powsybl.ampl.converter;

import com.google.auto.service.AutoService;
import com.powsybl.ampl.converter.version.AmplExportVersion;
import com.powsybl.ampl.converter.version.AmplExportVersionImpl;
import com.powsybl.commons.config.PlatformConfig;
import com.powsybl.commons.datasource.DataSource;
import com.powsybl.iidm.network.Exporter;
import com.powsybl.iidm.network.Network;
import com.powsybl.commons.parameters.Parameter;
import com.powsybl.commons.parameters.ParameterDefaultValueConfig;
import com.powsybl.commons.parameters.ParameterType;
import com.powsybl.iidm.network.Exporter;
import com.powsybl.iidm.network.Network;

import java.io.IOException;
import java.io.UncheckedIOException;
Expand All @@ -36,22 +38,33 @@ public class AmplExporter implements Exporter {
public static final String EXPORT_ACTION_TYPE = "iidm.export.ampl.action-type";
public static final String EXPORT_RATIOTAPCHANGER_VT = "iidm.export.ampl.export-ratio-tap-changer-voltage-target";
public static final String TWT_SPLIT_SHUNT_ADMITTANCE = "iidm.export.ampl.twt-split-shunt-admittance";
public static final String EXPORT_VERSION = "iidm.export.ampl.export-version";

private static final Parameter EXPORT_SCOPE_PARAMETER = new Parameter(EXPORT_SCOPE, ParameterType.STRING, "Export scope",
AmplExportConfig.ExportScope.ALL.name(),
Arrays.stream(AmplExportConfig.ExportScope.values()).map(Enum::name).collect(Collectors.toList()));
private static final Parameter EXPORT_XNODES_PARAMETER = new Parameter(EXPORT_XNODES, ParameterType.BOOLEAN, "Export Xnodes of tie-lines", Boolean.FALSE);
private static final Parameter EXPORT_ACTION_TYPE_PARAMETER = new Parameter(EXPORT_ACTION_TYPE, ParameterType.STRING, "Type of the remedial actions (preventive or curative)",
AmplExportConfig.ExportActionType.CURATIVE.name(),
Arrays.stream(AmplExportConfig.ExportActionType.values()).map(Enum::name).collect(Collectors.toList()));
private static final Parameter EXPORT_RATIOTAPCHANGER_VT_PARAMETER = new Parameter(EXPORT_RATIOTAPCHANGER_VT, ParameterType.BOOLEAN, "Export ratio tap changer voltage target", Boolean.FALSE)
.addAdditionalNames("iidm.export.ampl.exportRatioTapChangerVoltageTarget");
private static final Parameter TWT_SPLIT_SHUNT_ADMITTANCE_PARAMETER = new Parameter(TWT_SPLIT_SHUNT_ADMITTANCE, ParameterType.BOOLEAN, "Export twt split shunt admittance", Boolean.FALSE)
Arrays.stream(AmplExportConfig.ExportScope.values()).map(Enum::name).collect(Collectors.toList()));
private static final Parameter EXPORT_XNODES_PARAMETER = new Parameter(EXPORT_XNODES, ParameterType.BOOLEAN,
"Export Xnodes of tie-lines", Boolean.FALSE);
private static final Parameter EXPORT_ACTION_TYPE_PARAMETER = new Parameter(EXPORT_ACTION_TYPE,
ParameterType.STRING, "Type of the remedial actions (preventive or curative)",
AmplExportConfig.ExportActionType.CURATIVE.name(),
Arrays.stream(AmplExportConfig.ExportActionType.values()).map(Enum::name).collect(Collectors.toList()));
private static final Parameter EXPORT_RATIOTAPCHANGER_VT_PARAMETER = new Parameter(EXPORT_RATIOTAPCHANGER_VT,
ParameterType.BOOLEAN, "Export ratio tap changer voltage target", Boolean.FALSE)
.addAdditionalNames("iidm.export.ampl.exportRatioTapChangerVoltageTarget");
private static final Parameter TWT_SPLIT_SHUNT_ADMITTANCE_PARAMETER = new Parameter(TWT_SPLIT_SHUNT_ADMITTANCE,
ParameterType.BOOLEAN, "Export twt split shunt admittance", Boolean.FALSE)
.addAdditionalNames("iidm.export.ampl.specific-compatibility")
.addAdditionalNames("iidm.export.ampl.specificCompatibility");

private static final List<Parameter> STATIC_PARAMETERS = List.of(EXPORT_SCOPE_PARAMETER, EXPORT_XNODES_PARAMETER, EXPORT_ACTION_TYPE_PARAMETER,
EXPORT_RATIOTAPCHANGER_VT_PARAMETER, TWT_SPLIT_SHUNT_ADMITTANCE_PARAMETER);
private static final Parameter EXPORT_VERSION_PARAMETER = new Parameter(EXPORT_VERSION, ParameterType.STRING,
"The version of the export.",
AmplExportVersionImpl.V1_LEGACY.name(),
Arrays.stream(AmplExportVersionImpl.values()).map(Enum::name).collect(Collectors.toList()));

private static final List<Parameter> STATIC_PARAMETERS = List.of(EXPORT_SCOPE_PARAMETER, EXPORT_XNODES_PARAMETER,
EXPORT_ACTION_TYPE_PARAMETER,
EXPORT_RATIOTAPCHANGER_VT_PARAMETER, TWT_SPLIT_SHUNT_ADMITTANCE_PARAMETER, EXPORT_VERSION_PARAMETER);
pjeanmarie marked this conversation as resolved.
Show resolved Hide resolved

private final ParameterDefaultValueConfig defaultValueConfig;

Expand Down Expand Up @@ -82,9 +95,13 @@ public void export(Network network, Properties parameters, DataSource dataSource
boolean exportXnodes = Parameter.readBoolean(getFormat(), parameters, EXPORT_XNODES_PARAMETER, defaultValueConfig);
AmplExportConfig.ExportActionType actionType = AmplExportConfig.ExportActionType.valueOf(Parameter.readString(getFormat(), parameters, EXPORT_ACTION_TYPE_PARAMETER, defaultValueConfig));
boolean exportRatioTapChangerVoltageTarget = Parameter.readBoolean(getFormat(), parameters, EXPORT_RATIOTAPCHANGER_VT_PARAMETER, defaultValueConfig);
boolean twtSplitShuntAdmittance = Parameter.readBoolean(getFormat(), parameters, TWT_SPLIT_SHUNT_ADMITTANCE_PARAMETER, defaultValueConfig);
boolean twtSplitShuntAdmittance = Parameter.readBoolean(getFormat(), parameters,
TWT_SPLIT_SHUNT_ADMITTANCE_PARAMETER, defaultValueConfig);
AmplExportVersion exportVersion = AmplExportVersionImpl.valueOf(
Parameter.readString(getFormat(), parameters, EXPORT_VERSION_PARAMETER, defaultValueConfig));

AmplExportConfig config = new AmplExportConfig(scope, exportXnodes, actionType, exportRatioTapChangerVoltageTarget, twtSplitShuntAdmittance);
AmplExportConfig config = new AmplExportConfig(scope, exportXnodes, actionType,
exportRatioTapChangerVoltageTarget, twtSplitShuntAdmittance, exportVersion);

new AmplNetworkWriter(network, dataSource, config).write();
} catch (IOException e) {
Expand Down
Loading