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

Add phase shifter automatons #205

Merged
merged 4 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -0,0 +1,35 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com/)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/

package com.powsybl.dynawaltz.dsl.automatons

import com.powsybl.dsl.DslException
import com.powsybl.dynawaltz.dsl.models.builders.AbstractPureDynamicModelBuilder
import com.powsybl.iidm.network.Network
import com.powsybl.iidm.network.TwoWindingsTransformer

/**
* @author Laurent Issertial <laurent.issertial at rte-france.com>
*/
abstract class AbstractPhaseShifterModelBuilder extends AbstractPureDynamicModelBuilder {

Network network
TwoWindingsTransformer transformer

AbstractPhaseShifterModelBuilder(Network network) {
this.network = network
}

void transformer(String staticId) {
this.transformer = network.getTwoWindingsTransformer(staticId)
if (transformer == null) {
throw new DslException("Transformer static id unknown: " + staticId)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com/)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.dynawaltz.dsl.automatons

import com.google.auto.service.AutoService
import com.powsybl.dynamicsimulation.DynamicModel
import com.powsybl.dynamicsimulation.groovy.DynamicModelGroovyExtension
import com.powsybl.dynawaltz.dsl.AbstractPureDynamicGroovyExtension
import com.powsybl.dynawaltz.models.automatons.phaseshifters.PhaseShifterIAutomaton
import com.powsybl.iidm.network.Network

/**
* @author Laurent Issertial <laurent.issertial at rte-france.com>
*/
@AutoService(DynamicModelGroovyExtension.class)
class PhaseShifterIAutomatonGroovyExtension extends AbstractPureDynamicGroovyExtension<DynamicModel> implements DynamicModelGroovyExtension {

PhaseShifterIAutomatonGroovyExtension() {
modelTags = ["PhaseShifterI"]
}

@Override
protected PhaseShifterPAutomatonBuilder createBuilder(Network network) {
new PhaseShifterPAutomatonBuilder(network)
}

static class PhaseShifterPAutomatonBuilder extends AbstractPhaseShifterModelBuilder {

PhaseShifterPAutomatonBuilder(Network network) {
super(network)
}

@Override
PhaseShifterIAutomaton build() {
checkData()
new PhaseShifterIAutomaton(dynamicModelId, transformer, parameterSetId)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com/)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.dynawaltz.dsl.automatons

import com.google.auto.service.AutoService
import com.powsybl.dynamicsimulation.DynamicModel
import com.powsybl.dynamicsimulation.groovy.DynamicModelGroovyExtension
import com.powsybl.dynawaltz.dsl.AbstractPureDynamicGroovyExtension
import com.powsybl.dynawaltz.models.automatons.phaseshifters.PhaseShifterPAutomaton
import com.powsybl.iidm.network.Network

/**
* @author Laurent Issertial <laurent.issertial at rte-france.com>
*/
@AutoService(DynamicModelGroovyExtension.class)
class PhaseShifterPAutomatonGroovyExtension extends AbstractPureDynamicGroovyExtension<DynamicModel> implements DynamicModelGroovyExtension {

PhaseShifterPAutomatonGroovyExtension() {
modelTags = ["PhaseShifterP"]
}

@Override
protected PhaseShifterPAutomatonBuilder createBuilder(Network network) {
new PhaseShifterPAutomatonBuilder(network)
}

static class PhaseShifterPAutomatonBuilder extends AbstractPhaseShifterModelBuilder {

PhaseShifterPAutomatonBuilder(Network network) {
super(network)
}

@Override
PhaseShifterPAutomaton build() {
checkData()
new PhaseShifterPAutomaton(dynamicModelId, transformer, parameterSetId)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
import com.powsybl.dynamicsimulation.groovy.GroovyDynamicModelsSupplier;
import com.powsybl.dynamicsimulation.groovy.GroovyExtension;
import com.powsybl.dynawaltz.DynaWaltzProvider;
import com.powsybl.dynawaltz.models.BlackBoxModel;
import com.powsybl.dynawaltz.models.EquipmentBlackBoxModelModel;
import com.powsybl.dynawaltz.models.automatons.CurrentLimitAutomaton;
import com.powsybl.dynawaltz.models.automatons.TapChangerAutomaton;
import com.powsybl.dynawaltz.models.automatons.TapChangerBlockingAutomaton;
import com.powsybl.dynawaltz.models.automatons.phaseshifters.PhaseShifterIAutomaton;
import com.powsybl.dynawaltz.models.automatons.phaseshifters.PhaseShifterPAutomaton;
import com.powsybl.dynawaltz.models.buses.StandardBus;
import com.powsybl.dynawaltz.models.generators.GeneratorFictitious;
import com.powsybl.dynawaltz.models.generators.GeneratorSynchronous;
Expand Down Expand Up @@ -59,29 +62,14 @@ void testEquipmentDynamicModels(String groovyScriptName, Class<? extends Equipme
assertEquipmentBlackBoxModel(modelClass.cast(dynamicModels.get(0)), dynamicId, staticId, parameterId, lib);
}

@Test
void testCurrentLimitAutomaton() {
DynamicModelsSupplier supplier = new GroovyDynamicModelsSupplier(getResourceAsStream("currentLimit"), EXTENSIONS);
List<DynamicModel> dynamicModels = supplier.get(EurostagTutorialExample1Factory.create());
assertEquals(1, dynamicModels.size());
assertTrue(dynamicModels.get(0) instanceof CurrentLimitAutomaton);
CurrentLimitAutomaton bbm = (CurrentLimitAutomaton) dynamicModels.get(0);
assertEquals("AM_NHV1_NHV2_1", bbm.getDynamicModelId());
assertEquals("CLA", bbm.getParameterSetId());
assertEquals("CurrentLimitAutomaton", bbm.getLib());
assertEquals("NHV1_NHV2_1", bbm.getLineStaticId());
}

@Test
void testTapChangerAutomaton() {
DynamicModelsSupplier supplier = new GroovyDynamicModelsSupplier(getResourceAsStream("tapChanger"), EXTENSIONS);
List<DynamicModel> dynamicModels = supplier.get(EurostagTutorialExample1Factory.create());
@ParameterizedTest(name = "{0}")
@MethodSource("provideAutomatonModelData")
void testAutomatonDynamicModels(String groovyScriptName, Class<? extends BlackBoxModel> modelClass, Network network, String dynamicId, String parameterId, String lib) {
DynamicModelsSupplier supplier = new GroovyDynamicModelsSupplier(getResourceAsStream(groovyScriptName), EXTENSIONS);
List<DynamicModel> dynamicModels = supplier.get(network);
assertEquals(1, dynamicModels.size());
assertTrue(dynamicModels.get(0) instanceof TapChangerAutomaton);
TapChangerAutomaton bbm = (TapChangerAutomaton) dynamicModels.get(0);
assertEquals("TC", bbm.getDynamicModelId());
assertEquals("tc", bbm.getParameterSetId());
assertEquals("TapChangerAutomaton", bbm.getLib());
assertTrue(modelClass.isInstance(dynamicModels.get(0)));
assertPureDynamicBlackBoxModel(modelClass.cast(dynamicModels.get(0)), dynamicId, parameterId, lib);
}

@Test
Expand Down Expand Up @@ -111,6 +99,12 @@ void assertEquipmentBlackBoxModel(EquipmentBlackBoxModelModel bbm, String dynami
assertEquals(lib, bbm.getLib());
}

void assertPureDynamicBlackBoxModel(BlackBoxModel bbm, String dynamicId, String parameterId, String lib) {
assertEquals(dynamicId, bbm.getDynamicModelId());
assertEquals(parameterId, bbm.getParameterSetId());
assertEquals(lib, bbm.getLib());
}

private static Stream<Arguments> provideEquipmentModelData() {
return Stream.of(
Arguments.of("bus", StandardBus.class, EurostagTutorialExample1Factory.create(), "NGEN", "BBM_NGEN", "SB", "Bus"),
Expand All @@ -129,8 +123,18 @@ private static Stream<Arguments> provideEquipmentModelData() {
);
}

private static Stream<Arguments> provideAutomatonModelData() {
return Stream.of(
Arguments.of("currentLimit", CurrentLimitAutomaton.class, EurostagTutorialExample1Factory.create(), "AM_NHV1_NHV2_1", "CLA", "CurrentLimitAutomaton"),
Arguments.of("tapChanger", TapChangerAutomaton.class, EurostagTutorialExample1Factory.create(), "TC", "tc", "TapChangerAutomaton"),
Arguments.of("phaseShifterI", PhaseShifterIAutomaton.class, EurostagTutorialExample1Factory.create(), "PS_NGEN_NHV1", "ps", "PhaseShifterI"),
Arguments.of("phaseShifterP", PhaseShifterPAutomaton.class, EurostagTutorialExample1Factory.create(), "PS_NGEN_NHV1", "ps", "PhaseShifterP")
);
}

private static Stream<Arguments> provideExceptionsModel() {
return Stream.of(
Arguments.of("phaseShifterTransformerException", EurostagTutorialExample1Factory.create(), "Transformer static id unknown: NGEN"),
Arguments.of("tapChangerBusException", EurostagTutorialExample1Factory.create(), "Bus static id unknown: LOAD"),
Arguments.of("tapChangerCompatibleException", EurostagTutorialExample1Factory.create(), "GENERATOR GEN is not compatible")
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com/)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/

package dynamicModels


PhaseShifterI {
dynamicModelId "PS_NGEN_NHV1"
parameterSetId "ps"
transformer "NGEN_NHV1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com/)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/

package dynamicModels


PhaseShifterP {
dynamicModelId "PS_NGEN_NHV1"
parameterSetId "ps"
transformer "NGEN_NHV1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com/)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/

package dynamicModels


PhaseShifterI {
dynamicModelId "PS_NGEN_NHV1"
parameterSetId "ps"
transformer "NGEN"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com/)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.dynawaltz.models.automatons.phaseshifters;

import com.powsybl.dynawaltz.DynaWaltzContext;
import com.powsybl.dynawaltz.models.AbstractPureDynamicBlackBoxModel;
import com.powsybl.dynawaltz.models.VarConnection;
import com.powsybl.dynawaltz.models.transformers.TransformerModel;
import com.powsybl.iidm.network.TwoWindingsTransformer;

import java.util.List;
import java.util.Objects;

/**
* @author Laurent Issertial <laurent.issertial at rte-france.com>
*/
public abstract class AbstractPhaseShifterAutomaton extends AbstractPureDynamicBlackBoxModel {

protected final TwoWindingsTransformer transformer;

protected AbstractPhaseShifterAutomaton(String dynamicModelId, TwoWindingsTransformer transformer, String parameterSetId) {
super(dynamicModelId, parameterSetId);
this.transformer = Objects.requireNonNull(transformer);
}

@Override
public void createMacroConnections(DynaWaltzContext context) {
createMacroConnections(transformer, TransformerModel.class, this::getVarConnectionsWithTransformer, context);
}

protected abstract List<VarConnection> getVarConnectionsWithTransformer(TransformerModel connected);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com/)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.dynawaltz.models.automatons.phaseshifters;

import com.powsybl.dynawaltz.models.VarConnection;
import com.powsybl.dynawaltz.models.transformers.TransformerModel;
import com.powsybl.iidm.network.TwoWindingsTransformer;

import java.util.Arrays;
import java.util.List;

/**
* @author Laurent Issertial <laurent.issertial at rte-france.com>
*/
public class PhaseShifterIAutomaton extends AbstractPhaseShifterAutomaton {

public PhaseShifterIAutomaton(String dynamicModelId, TwoWindingsTransformer transformer, String parameterSetId) {
super(dynamicModelId, transformer, parameterSetId);
}

@Override
public String getLib() {
return "PhaseShifterI";
}

protected List<VarConnection> getVarConnectionsWithTransformer(TransformerModel connected) {
return Arrays.asList(
new VarConnection("phaseShifter_tap", connected.getStepVarName()),
new VarConnection("phaseShifter_iMonitored", connected.getIMonitoredVarName()),
new VarConnection("phaseShifter_P", connected.getPMonitoredVarName()),
new VarConnection("phaseShifter_AutomatonExists", connected.getDisableInternalTapChangerVarName())
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com/)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.dynawaltz.models.automatons.phaseshifters;

import com.powsybl.dynawaltz.models.VarConnection;
import com.powsybl.dynawaltz.models.transformers.TransformerModel;
import com.powsybl.iidm.network.TwoWindingsTransformer;

import java.util.Arrays;
import java.util.List;

/**
* @author Laurent Issertial <laurent.issertial at rte-france.com>
*/
public class PhaseShifterPAutomaton extends AbstractPhaseShifterAutomaton {

public PhaseShifterPAutomaton(String dynamicModelId, TwoWindingsTransformer transformer, String parameterSetId) {
super(dynamicModelId, transformer, parameterSetId);
}

@Override
public String getLib() {
return "PhaseShifterP";
}

protected List<VarConnection> getVarConnectionsWithTransformer(TransformerModel connected) {
return Arrays.asList(
new VarConnection("phaseShifter_tap", connected.getStepVarName()),
new VarConnection("phaseShifter_PMonitored", connected.getPMonitoredVarName()),
new VarConnection("phaseShifter_AutomatonExists", connected.getDisableInternalTapChangerVarName())
);
}
}
Loading