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 under voltage automaton #204

Merged
merged 5 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,58 @@
/**
* 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.dsl.DslException
import com.powsybl.dynamicsimulation.DynamicModel
import com.powsybl.dynamicsimulation.groovy.DynamicModelGroovyExtension
import com.powsybl.dynawaltz.dsl.AbstractPureDynamicGroovyExtension
import com.powsybl.dynawaltz.dsl.models.builders.AbstractPureDynamicModelBuilder
import com.powsybl.dynawaltz.models.automatons.UnderVoltageAutomaton
import com.powsybl.iidm.network.Generator
import com.powsybl.iidm.network.Network

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

UnderVoltageAutomatonGroovyExtension() {
modelTags = ["UnderVoltage"]
}

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

static class UnderVoltageAutomatonBuilder extends AbstractPureDynamicModelBuilder {

Network network

Generator generator

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

void generator(String staticId) {
this.generator = network.getGenerator(staticId)
if (generator == null) {
throw new DslException("Generator static id unknown: " + staticId)
}
}

@Override
UnderVoltageAutomaton build() {
checkData()
new UnderVoltageAutomaton(dynamicModelId, parameterSetId, generator)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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.UnderVoltageAutomaton;
import com.powsybl.dynawaltz.models.automatons.phaseshifters.PhaseShifterIAutomaton;
import com.powsybl.dynawaltz.models.automatons.phaseshifters.PhaseShifterPAutomaton;
import com.powsybl.dynawaltz.models.buses.StandardBus;
Expand All @@ -34,7 +35,6 @@
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.iidm.network.test.HvdcTestNetwork;
import com.powsybl.iidm.network.test.SvcTestCaseFactory;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand Down Expand Up @@ -72,18 +72,6 @@ void testAutomatonDynamicModels(String groovyScriptName, Class<? extends BlackBo
assertPureDynamicBlackBoxModel(modelClass.cast(dynamicModels.get(0)), dynamicId, parameterId, lib);
}

@Test
void testTapChangerBlockingAutomaton() {
DynamicModelsSupplier supplier = new GroovyDynamicModelsSupplier(getResourceAsStream("tapChangerBlocking"), EXTENSIONS);
List<DynamicModel> dynamicModels = supplier.get(EurostagTutorialExample1Factory.create());
assertEquals(1, dynamicModels.size());
assertTrue(dynamicModels.get(0) instanceof TapChangerBlockingAutomaton);
TapChangerBlockingAutomaton bbm = (TapChangerBlockingAutomaton) dynamicModels.get(0);
assertEquals("ZAB", bbm.getDynamicModelId());
assertEquals("ZAB", bbm.getParameterSetId());
assertEquals("TapChangerBlockingAutomaton1", bbm.getLib());
}

@ParameterizedTest(name = "{0}")
@MethodSource("provideExceptionsModel")
void testDslExceptions(String groovyScriptName, Network network, String exceptionMessage) {
Expand Down Expand Up @@ -127,16 +115,19 @@ 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("tapChangerBlocking", TapChangerBlockingAutomaton.class, EurostagTutorialExample1Factory.create(), "ZAB", "ZAB", "TapChangerBlockingAutomaton1"),
Arguments.of("phaseShifterI", PhaseShifterIAutomaton.class, EurostagTutorialExample1Factory.create(), "PS_NGEN_NHV1", "ps", "PhaseShifterI"),
Arguments.of("phaseShifterP", PhaseShifterPAutomaton.class, EurostagTutorialExample1Factory.create(), "PS_NGEN_NHV1", "ps", "PhaseShifterP")
Arguments.of("phaseShifterP", PhaseShifterPAutomaton.class, EurostagTutorialExample1Factory.create(), "PS_NGEN_NHV1", "ps", "PhaseShifterP"),
Arguments.of("underVoltage", UnderVoltageAutomaton.class, EurostagTutorialExample1Factory.create(), "UV_GEN", "uv", "UnderVoltageAutomaton")
);
}

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")
Arguments.of("tapChangerCompatibleException", EurostagTutorialExample1Factory.create(), "GENERATOR GEN is not compatible"),
Arguments.of("underVoltageGeneratorException", EurostagTutorialExample1Factory.create(), "Generator static id unknown: NGEN")
);
}

Expand Down
16 changes: 16 additions & 0 deletions dynawaltz-dsl/src/test/resources/dynamicModels/underVoltage.groovy
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


UnderVoltage {
dynamicModelId "UV_GEN"
parameterSetId "uv"
generator "GEN"
}
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


UnderVoltage {
dynamicModelId "UV_GEN"
parameterSetId "uv"
generator "NGEN"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* 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;

import com.powsybl.dynawaltz.DynaWaltzContext;
import com.powsybl.dynawaltz.models.AbstractPureDynamicBlackBoxModel;
import com.powsybl.dynawaltz.models.VarConnection;
import com.powsybl.dynawaltz.models.generators.GeneratorModel;
import com.powsybl.iidm.network.Generator;

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

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

protected final Generator generator;

public UnderVoltageAutomaton(String dynamicModelId, String parameterSetId, Generator generator) {
super(dynamicModelId, parameterSetId);
this.generator = Objects.requireNonNull(generator);
}

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

@Override
public void createMacroConnections(DynaWaltzContext context) {
createMacroConnections(generator, GeneratorModel.class, this::getVarConnectionsWithGenerator, context);
}

protected List<VarConnection> getVarConnectionsWithGenerator(GeneratorModel connected) {
return Arrays.asList(
new VarConnection("underVoltageAutomaton_UMonitoredPu", connected.getUPuVarName()),
new VarConnection("underVoltageAutomaton_switchOffSignal", connected.getSwitchOffSignalAutomatonVarName())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public String getQStatorPuVarName() {
return "generator_QStatorPu";
}

@Override
public String getUPuVarName() {
return "generator_UPu";
}

@Override
public String getDisconnectableVarName() {
return getSwitchOffSignalEventVarName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ public String getRunningVarName() {
public String getQStatorPuVarName() {
return "@NAME@_QStatorPu";
}

public String getUPuVarName() {
return "@NAME@_UPu";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ public interface GeneratorModel extends Model {
String getRunningVarName();

String getQStatorPuVarName();

String getUPuVarName();
}
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.xml;

import com.powsybl.dynawaltz.models.automatons.UnderVoltageAutomaton;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXException;

import javax.xml.stream.XMLStreamException;
import java.io.IOException;

/**
* @author Laurent Issertial <laurent.issertial at rte-france.com>
*/
class UnderVoltageAutomatonXmlTest extends AbstractDynamicModelXmlTest {

@Override
protected void setupNetwork() {
network = EurostagTutorialExample1Factory.create();
}

@Override
protected void addDynamicModels() {
dynamicModels.add(new UnderVoltageAutomaton("BBM_under_voltage", "uv", network.getGenerator("GEN")));
}

@Test
void writeModel() throws SAXException, IOException, XMLStreamException {
DydXml.write(tmpDir, context);
ParametersXml.write(tmpDir, context);
validate("dyd.xsd", "under_voltage_dyd.xml", tmpDir.resolve(DynaWaltzConstants.DYD_FILENAME));
}
}
9 changes: 9 additions & 0 deletions dynawaltz/src/test/resources/under_voltage_dyd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<dyn:dynamicModelsArchitecture xmlns:dyn="http://www.rte-france.com/dynawo">
<dyn:blackBoxModel id="BBM_under_voltage" lib="UnderVoltageAutomaton" parFile="models.par" parId="uv"/>
<dyn:macroConnector id="MC_UnderVoltageAutomaton-NetworkGenerator">
<dyn:connect var1="underVoltageAutomaton_UMonitoredPu" var2="@NAME@_UPu"/>
<dyn:connect var1="underVoltageAutomaton_switchOffSignal" var2="@NAME@_switchOffSignal3"/>
</dyn:macroConnector>
<dyn:macroConnect connector="MC_UnderVoltageAutomaton-NetworkGenerator" id1="BBM_under_voltage" id2="NETWORK" name2="GEN"/>
</dyn:dynamicModelsArchitecture>