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

Additional clarifications on power flow inputs (SSH) and state values (SV) #1963

Merged
merged 9 commits into from
Feb 8, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ private Conversion.Config config(Properties p) {
p,
CREATE_BUSBAR_SECTION_FOR_EVERY_CONNECTIVITY_NODE_PARAMETER,
defaultValueConfig))
.setProfileUsedForInitialStateValues(
ConversionParameters.readStringParameter(
.setReadShuntSectionsTapPositionsFromSVIfPresen(
miovd marked this conversation as resolved.
Show resolved Hide resolved
ConversionParameters.readBooleanParameter(
getFormat(),
p,
PROFILE_USED_FOR_INITIAL_STATE_VALUES_PARAMETER,
READ_SHUNT_SECTIONS_TAP_POSITIONS_FROM_SV_IF_PRESENT_PARAMETER,
defaultValueConfig))
.setStoreCgmesModelAsNetworkExtension(
ConversionParameters.readBooleanParameter(
Expand Down Expand Up @@ -248,7 +248,7 @@ private void copyStream(ReadOnlyDataSource from, DataSource to, String fromName,
public static final String IMPORT_CONTROL_AREAS = "iidm.import.cgmes.import-control-areas";
public static final String POST_PROCESSORS = "iidm.import.cgmes.post-processors";
public static final String POWSYBL_TRIPLESTORE = "iidm.import.cgmes.powsybl-triplestore";
public static final String PROFILE_USED_FOR_INITIAL_STATE_VALUES = "iidm.import.cgmes.profile-used-for-initial-state-values";
public static final String READ_SHUNT_SECTIONS_TAP_POSITIONS_FROM_SV_IF_PRESENT = "iidm.import.cgmes.read-shunt-sections-tap-positions-from-sv-if-present";
public static final String STORE_CGMES_MODEL_AS_NETWORK_EXTENSION = "iidm.import.cgmes.store-cgmes-model-as-network-extension";
public static final String STORE_CGMES_CONVERSION_CONTEXT_AS_NETWORK_EXTENSION = "iidm.import.cgmes.store-cgmes-conversion-context-as-network-extension";

Expand Down Expand Up @@ -306,11 +306,11 @@ private void copyStream(ReadOnlyDataSource from, DataSource to, String fromName,
"The triplestore used during the import",
TripleStoreFactory.defaultImplementation())
.addAdditionalNames("powsyblTripleStore");
private static final Parameter PROFILE_USED_FOR_INITIAL_STATE_VALUES_PARAMETER = new Parameter(
PROFILE_USED_FOR_INITIAL_STATE_VALUES,
ParameterType.STRING,
"Profile used for initial state values",
"SSH");
private static final Parameter READ_SHUNT_SECTIONS_TAP_POSITIONS_FROM_SV_IF_PRESENT_PARAMETER = new Parameter(
miovd marked this conversation as resolved.
Show resolved Hide resolved
READ_SHUNT_SECTIONS_TAP_POSITIONS_FROM_SV_IF_PRESENT,
ParameterType.BOOLEAN,
"Read shunt sections and tap positions from SV if it is present",
Boolean.FALSE);
private static final Parameter STORE_CGMES_CONVERSION_CONTEXT_AS_NETWORK_EXTENSION_PARAMETER = new Parameter(
STORE_CGMES_CONVERSION_CONTEXT_AS_NETWORK_EXTENSION,
ParameterType.BOOLEAN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
import java.util.function.Supplier;
import java.util.stream.Collectors;

import static com.powsybl.cgmes.conversion.Conversion.Config.StateProfile.SSH;

/**
* TwoWindingsTransformer Interpretation
* <p>
Expand Down Expand Up @@ -674,11 +672,6 @@ private void debugTopology(Context context) {

public static class Config {

public enum StateProfile {
SSH,
SV
}

public List<String> substationIdsExcludedFromMapping() {
return Collections.emptyList();
}
Expand Down Expand Up @@ -757,19 +750,12 @@ public Config setConvertSvInjections(boolean convertSvInjections) {
return this;
}

public StateProfile getProfileUsedForInitialStateValues() {
return profileUsedForInitialStateValues;
public boolean isReadShuntSectionsTapPositionsFromSVIfPresent() {
return readShuntSectionsTapPositionsFromSVIfPresent;
}

public Config setProfileUsedForInitialStateValues(String profileUsedForInitialFlowsValues) {
switch (Objects.requireNonNull(profileUsedForInitialFlowsValues)) {
case "SSH":
case "SV":
this.profileUsedForInitialStateValues = StateProfile.valueOf(profileUsedForInitialFlowsValues);
break;
default:
throw new CgmesModelException("Unexpected profile used for state hypothesis: " + profileUsedForInitialFlowsValues);
}
public Config setReadShuntSectionsTapPositionsFromSVIfPresen(boolean readShuntSectionsTapPositionsFromSVIfPresent) {
this.readShuntSectionsTapPositionsFromSVIfPresent = readShuntSectionsTapPositionsFromSVIfPresent;
return this;
}

Expand Down Expand Up @@ -865,7 +851,7 @@ public void setXfmr3StructuralRatio(Xfmr3StructuralRatioInterpretationAlternativ

private boolean createBusbarSectionForEveryConnectivityNode = false;
private boolean convertSvInjections = true;
private StateProfile profileUsedForInitialStateValues = SSH;
private boolean readShuntSectionsTapPositionsFromSVIfPresent = false;
private boolean storeCgmesModelAsNetworkExtension = true;
private boolean storeCgmesConversionContextAsNetworkExtension = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void convertInsideBoundary() {
// is to accumulate the power flows of connected terminals at boundary node
for (int k = 1; k <= numTerminals; k++) {
if (terminalConnected(k)) {
context.boundary().addPowerFlowAtNode(nodeId(k), powerFlow(k));
context.boundary().addPowerFlowAtNode(nodeId(k), powerFlowSV(k));
}
}
}
Expand Down Expand Up @@ -261,7 +261,7 @@ public void convertToDanglingLine(int boundarySide, double r, double x, double g
// do it and assign the result at the terminal of the dangling line
if (context.config().computeFlowsAtBoundaryDanglingLines()
&& terminalConnected(modelSide)
&& !powerFlow(modelSide).defined()
&& !powerFlowSV(modelSide).defined()
&& context.boundary().hasVoltage(boundaryNode)) {

if (isZ0(dl)) {
Expand Down Expand Up @@ -426,45 +426,11 @@ private PowerFlow steadyStateHypothesisPowerFlow() {
}

PowerFlow powerFlow() {
switch (context.config().getProfileUsedForInitialStateValues()) {
case SSH:
if (steadyStateHypothesisPowerFlow().defined()) {
return steadyStateHypothesisPowerFlow();
}
if (stateVariablesPowerFlow().defined()) {
return stateVariablesPowerFlow();
}
break;
case SV:
if (stateVariablesPowerFlow().defined()) {
return stateVariablesPowerFlow();
}
if (steadyStateHypothesisPowerFlow().defined()) {
return steadyStateHypothesisPowerFlow();
}
break;
if (steadyStateHypothesisPowerFlow().defined()) {
return steadyStateHypothesisPowerFlow();
}
return PowerFlow.UNDEFINED;
}

PowerFlow powerFlow(int n) {
switch (context.config().getProfileUsedForInitialStateValues()) {
case SSH:
if (steadyStateHypothesisPowerFlow().defined()) {
return steadyStateHypothesisPowerFlow();
}
if (stateVariablesPowerFlow(n).defined()) {
return stateVariablesPowerFlow(n);
}
break;
case SV:
if (stateVariablesPowerFlow(n).defined()) {
return stateVariablesPowerFlow(n);
}
if (steadyStateHypothesisPowerFlow().defined()) {
return steadyStateHypothesisPowerFlow();
}
break;
if (stateVariablesPowerFlow().defined()) {
return stateVariablesPowerFlow();
}
return PowerFlow.UNDEFINED;
}
Expand Down Expand Up @@ -688,7 +654,7 @@ protected BoundaryLine createBoundaryLine(String boundaryNode) {
if (context.nodeBreaker()) {
modelNode = iidmNode(modelEnd);
}
PowerFlow modelPowerFlow = powerFlow(modelEnd);
PowerFlow modelPowerFlow = powerFlowSV(modelEnd);
return new BoundaryLine(id, name, modelIidmVoltageLevelId, modelBus, modelTconnected, modelNode,
modelTerminalId, boundaryTerminalId, modelPowerFlow);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.powsybl.cgmes.conversion.Context;
import com.powsybl.cgmes.model.CgmesNames;
import com.powsybl.cgmes.model.PowerFlow;
import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.ShuntCompensator;
import com.powsybl.iidm.network.ShuntCompensatorAdder;
import com.powsybl.iidm.network.ShuntCompensatorNonLinearModelAdder;
Expand All @@ -31,14 +30,10 @@ public ShuntConversion(PropertyBag sh, Context context) {
}

private int getSections(PropertyBag p, int normalSections) {
switch (context.config().getProfileUsedForInitialStateValues()) {
case SSH:
return fromContinuous(p.asDouble("SSHsections", p.asDouble("SVsections", normalSections)));
case SV:
return fromContinuous(p.asDouble("SVsections", p.asDouble("SSHsections", normalSections)));
default:
throw new PowsyblException("Unexpected profile used for initial state values");
if (context.config().isReadShuntSectionsTapPositionsFromSVIfPresent()) {
return fromContinuous(p.asDouble("SVsections", p.asDouble("SSHsections", normalSections)));
}
return fromContinuous(p.asDouble("SSHsections", p.asDouble("SVsections", normalSections)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import com.powsybl.cgmes.conversion.Context;
import com.powsybl.cgmes.conversion.elements.AbstractObjectConversion;
import com.powsybl.cgmes.model.CgmesModelException;
import com.powsybl.cgmes.model.CgmesNames;
import com.powsybl.commons.PowsyblException;
import com.powsybl.triplestore.api.PropertyBag;
Expand Down Expand Up @@ -47,14 +46,10 @@ static CgmesPhaseTapChangerBuilder newPhaseTapChanger(PropertyBag phaseTapChange
}

protected int initialTapPosition(int defaultStep) {
switch (context.config().getProfileUsedForInitialStateValues()) {
case SSH:
return AbstractObjectConversion.fromContinuous(p.asDouble(CgmesNames.STEP, p.asDouble(CgmesNames.SV_TAP_STEP, defaultStep)));
case SV:
return AbstractObjectConversion.fromContinuous(p.asDouble(CgmesNames.SV_TAP_STEP, p.asDouble(CgmesNames.STEP, defaultStep)));
default:
throw new CgmesModelException("Unexpected profile used for initial flows values: " + context.config().getProfileUsedForInitialStateValues());
if (context.config().isReadShuntSectionsTapPositionsFromSVIfPresent()) {
return AbstractObjectConversion.fromContinuous(p.asDouble(CgmesNames.SV_TAP_STEP, p.asDouble(CgmesNames.STEP, defaultStep)));
}
return AbstractObjectConversion.fromContinuous(p.asDouble(CgmesNames.STEP, p.asDouble(CgmesNames.SV_TAP_STEP, defaultStep)));
}

protected TapChanger build() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ private Network networkModel(TestGridModel testGridModel, Conversion.Config conf
CgmesModel cgmes = CgmesModelFactory.create(ds, impl);

config.setConvertSvInjections(true);
config.setProfileUsedForInitialStateValues(Conversion.Config.StateProfile.SSH.name());
Conversion c = new Conversion(cgmes, config);
Network n = c.convert();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ private static Network networkModel(TestGridModel testGridModel, Conversion.Conf
CgmesModel cgmes = CgmesModelFactory.create(ds, impl);

config.setConvertSvInjections(true);
config.setProfileUsedForInitialStateValues(Conversion.Config.StateProfile.SSH.name());
Conversion c = new Conversion(cgmes, config);
Network n = c.convert();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ private Network networkModel(TestGridModel testGridModel, Conversion.Config conf
CgmesModel cgmes = CgmesModelFactory.create(ds, impl);

config.setConvertSvInjections(true);
config.setProfileUsedForInitialStateValues(Conversion.Config.StateProfile.SSH.name());
Conversion c = new Conversion(cgmes, config);
Network n = c.convert();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,6 @@ private Network networkModel(TestGridModel testGridModel, Conversion.Config conf
CgmesModel cgmes = CgmesModelFactory.create(ds, impl);

config.setConvertSvInjections(true);
config.setProfileUsedForInitialStateValues(Conversion.Config.StateProfile.SSH.name());
Conversion c = new Conversion(cgmes, config);
Network n = c.convert();

Expand All @@ -473,7 +472,6 @@ private Network networkModel(TestGridModel testGridModel, Conversion.Config conf
CgmesModel cgmes = CgmesModelFactory.create(ds, impl);

config.setConvertSvInjections(true);
config.setProfileUsedForInitialStateValues(Conversion.Config.StateProfile.SSH.name());
Conversion c = new Conversion(cgmes, config, postProcessors);
Network n = c.convert();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ private Network networkModel(TestGridModel testGridModel, Conversion.Config conf
CgmesModel cgmes = CgmesModelFactory.create(ds, impl);

config.setConvertSvInjections(true);
config.setProfileUsedForInitialStateValues(Conversion.Config.StateProfile.SSH.name());
Conversion c = new Conversion(cgmes, config);
return c.convert();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void microGridBaseCaseBEBusBalanceValidation() throws IOException {
// the interpretation of the location of tap changer
// relative to the transmission impedance is correct
Properties params = new Properties();
params.put(CgmesImport.PROFILE_USED_FOR_INITIAL_STATE_VALUES, "SV");
params.put(CgmesImport.READ_SHUNT_SECTIONS_TAP_POSITIONS_FROM_SV_IF_PRESENT, "true");
ConversionTester t = new ConversionTester(
params,
TripleStoreFactory.onlyDefaultImplementation(),
Expand Down Expand Up @@ -171,7 +171,7 @@ public void miniNodeBreakerBusBalanceValidation() throws IOException {
// that will be computed by IIDM from CGMES node-breaker ConnectivityNodes,
// have proper balances from SV values
Properties params = new Properties();
params.put(CgmesImport.PROFILE_USED_FOR_INITIAL_STATE_VALUES, "SV");
params.put(CgmesImport.READ_SHUNT_SECTIONS_TAP_POSITIONS_FROM_SV_IF_PRESENT, "true");
ConversionTester t = new ConversionTester(
params,
TripleStoreFactory.onlyDefaultImplementation(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ private static Network networkModel(TestGridModel testGridModel, Conversion.Conf
CgmesModel cgmes = CgmesModelFactory.create(ds, impl);

config.setConvertSvInjections(true);
config.setProfileUsedForInitialStateValues(Conversion.Config.StateProfile.SSH.name());
Conversion c = new Conversion(cgmes, config);
Network n = c.convert();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public void miniBusBranchWithSvInjectionExportQ() throws IOException, XMLStreamE

private static Network importNetwork(ReadOnlyDataSource ds) {
Properties properties = new Properties();
properties.put("iidm.import.cgmes.profile-used-for-initial-state-values", "SV");
properties.put("iidm.import.cgmes.create-cgmes-export-mapping", "true");
return new CgmesImport().importData(ds, NetworkFactory.findDefault(), properties);
}
Expand Down Expand Up @@ -185,7 +184,6 @@ private void test(ReadOnlyDataSource dataSource, int svVersion, boolean exportFl
private void test(ReadOnlyDataSource dataSource, int svVersion, boolean exportFlowsForSwitches, Consumer<Repackager> repackagerConsumer) throws XMLStreamException, IOException {
// Import original
Properties properties = new Properties();
properties.put("iidm.import.cgmes.profile-used-for-initial-state-values", "SV");
properties.put("iidm.import.cgmes.create-cgmes-export-mapping", "true");
Network expected0 = new CgmesImport().importData(dataSource, NetworkFactory.findDefault(), properties);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ private void test(ReadOnlyDataSource dataSource, int version, DifferenceEvaluato
private void test(ReadOnlyDataSource dataSource, int version, DifferenceEvaluator knownDiffsSsh, DifferenceEvaluator knownDiffsIidm) throws IOException, XMLStreamException {
// Import original
Properties properties = new Properties();
properties.put("iidm.import.cgmes.profile-used-for-initial-state-values", "SSH");
properties.put("iidm.import.cgmes.create-cgmes-export-mapping", "true");
Network expected = new CgmesImport().importData(dataSource, NetworkFactory.findDefault(), properties);

Expand Down