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 Current limit two levels automaton #209

Merged
merged 40 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
618f668
Replace Event disconnection in DSL with Disconnect and DisconnectQuad…
Lisrte Apr 4, 2023
02849d6
Add default model and quadripole disconnection for Transformer
Lisrte Apr 4, 2023
6d38349
Fix quadripole disconnection
Lisrte Apr 4, 2023
d837b66
Handle default & dynamic model disconnection
Lisrte Apr 4, 2023
f2a0c41
Add default model generator
Lisrte Apr 5, 2023
30aef8a
Merge equipment and quadripole equipment disconnection event in DSL
Lisrte Apr 5, 2023
4fc95eb
Fix after branch update
Lisrte Apr 5, 2023
9d0dc6e
Add test coverage
Lisrte Apr 5, 2023
b333430
Review fix
Lisrte Apr 5, 2023
d76813c
Refactor event constructor
Lisrte Apr 5, 2023
89e185d
Add Load with tap changer
Lisrte Apr 7, 2023
8ac8af6
Refactor Load with tap changer
Lisrte Apr 11, 2023
9c6dc3d
Add TapChangerAutomaton
Lisrte Apr 12, 2023
d81be5e
Add TapChangerBlockingAutomaton to TapChangerAutomaton connection
Lisrte Apr 12, 2023
a11c80f
Add TapChangerBlockingAutomaton libs
Lisrte Apr 13, 2023
8df0020
Add phase shifter automatons
Lisrte Apr 17, 2023
941ab22
Fix copyrights & UT
Lisrte Apr 18, 2023
3995d5b
Connect quadripole to Current limit automaton
Lisrte Apr 19, 2023
eaf818d
Add transformer to quadripole interface
Lisrte Apr 20, 2023
94e5519
Remove QuadripoleDisconnectableEquipment and use QuadripoleModel instead
Lisrte Apr 20, 2023
88708eb
Use Branch instead of Identifiable
Lisrte Apr 20, 2023
36fec45
Add CurrentLimitTwoLevelsAutomaton
Lisrte Apr 20, 2023
1c2c223
Use Branch instead of Identifiable
Lisrte Apr 20, 2023
07787a2
Separate measured and controlled quadripoles in CLA
Lisrte May 4, 2023
4b19aef
Merge branch 'connect_cla_to_quadripole' into add_cla_two_levels
Lisrte May 4, 2023
5ad56e2
Separate measured and controlled quadripoles in CLA two levels
Lisrte May 4, 2023
c6eeb77
Merge branch 'main' into connect_cla_to_quadripole
Lisrte May 9, 2023
8d03390
Fix post rebase
Lisrte May 9, 2023
37c14ed
Fix coverage
Lisrte May 9, 2023
df9ea75
Merge branch 'main' into connect_cla_to_quadripole
flo-dup May 22, 2023
a1f3eaf
Review fix
Lisrte May 23, 2023
fd3d605
Add dynamic lib for CLA
Lisrte May 24, 2023
eb496af
Merge branch 'connect_cla_to_quadripole' into add_cla_two_levels
Lisrte May 24, 2023
825db5b
Add dynamic lib for CLA two levels
Lisrte May 24, 2023
bf2cbe5
use method instead of field
Lisrte May 24, 2023
eb492fd
Merge branch 'main' into add_cla_two_levels
Lisrte May 25, 2023
3b2a5f0
Revert formatting changes
flo-dup May 26, 2023
2a2d330
ControlledQuadripole argument mandatory for CLAs
flo-dup May 26, 2023
8eab8f5
Update unit tests
flo-dup May 26, 2023
eda49dc
Merge branch 'main' into add_cla_two_levels
flo-dup May 26, 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 @@ -80,16 +80,15 @@ class CurrentLimitAutomatonGroovyExtension extends AbstractPureDynamicGroovyExte
if (!side) {
throw new DslException("'iMeasurementSide' field is not set")
}
if (!controlledEquipment) {
throw new DslException("'controlledEquipment' field is not set")
}
}

@Override
CurrentLimitAutomaton build() {
checkData()
if (!controlledEquipment) {
new CurrentLimitAutomaton(dynamicModelId, parameterSetId, equipment, side, lib)
} else {
new CurrentLimitAutomaton(dynamicModelId, parameterSetId, equipment, side, controlledEquipment, lib)
}
new CurrentLimitAutomaton(dynamicModelId, parameterSetId, equipment, side, controlledEquipment, lib)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* 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.models.Side
import com.powsybl.dynawaltz.models.automatons.CurrentLimitTwoLevelsAutomaton
import com.powsybl.dynawaltz.models.utils.SideConverter
import com.powsybl.iidm.network.Branch
import com.powsybl.iidm.network.Network

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

CurrentLimitTwoLevelsAutomatonGroovyExtension() {
modelTags = [getLib()]
}

protected String getLib() {
return "CurrentLimitAutomatonTwoLevels"
}

@Override
protected CurrentLimitAutomatonTwoLevelBuilder createBuilder(Network network) {
new CurrentLimitAutomatonTwoLevelBuilder(network, getLib())
}

static class CurrentLimitAutomatonTwoLevelBuilder extends CurrentLimitAutomatonGroovyExtension.CurrentLimitAutomatonBuilder {

Branch<? extends Branch> equipment2
Side side2

CurrentLimitAutomatonTwoLevelBuilder(Network network, String lib) {
super(network, lib)
}

void iMeasurement1(String staticId) {
iMeasurement(staticId)
}

void iMeasurement1Side(Branch.Side side) {
iMeasurementSide(side)
}

void iMeasurement2(String staticId) {
equipment2 = network.getBranch(staticId)
if (!equipment2) {
throw new DslException("Equipment ${staticId} is not a quadripole")
}
}

void iMeasurement2Side(Branch.Side side) {
this.side2 = SideConverter.convert(side)
}

@Override
void checkData() {
super.checkData()
if (!equipment2) {
throw new DslException("'iMeasurement2' field is not set")
}
if (!side2) {
throw new DslException("'iMeasurement2Side' field is not set")
}
}

@Override
CurrentLimitTwoLevelsAutomaton build() {
checkData()
new CurrentLimitTwoLevelsAutomaton(dynamicModelId, parameterSetId, equipment, side, equipment2, side2, controlledEquipment, lib)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
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.UnderVoltageAutomaton;
import com.powsybl.dynawaltz.models.automatons.*;
import com.powsybl.dynawaltz.models.automatons.phaseshifters.PhaseShifterIAutomaton;
import com.powsybl.dynawaltz.models.automatons.phaseshifters.PhaseShifterPAutomaton;
import com.powsybl.dynawaltz.models.buses.InfiniteBus;
Expand Down Expand Up @@ -116,9 +113,10 @@ private static Stream<Arguments> provideEquipmentModelData() {
);
}

private static Stream<Arguments> provideAutomatonModelData() {
private static Stream<Arguments> provideAutomatonModelData() {
return Stream.of(
Arguments.of("currentLimit", CurrentLimitAutomaton.class, EurostagTutorialExample1Factory.create(), "AM_NHV1_NHV2_1", "CLA", "CurrentLimitAutomaton"),
Arguments.of("currentLimitTwoLevels", CurrentLimitTwoLevelsAutomaton.class, EurostagTutorialExample1Factory.create(), "AM_NHV1_NHV2_1", "CLA", "CurrentLimitAutomatonTwoLevels"),
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"),
Expand All @@ -129,6 +127,8 @@ private static Stream<Arguments> provideAutomatonModelData() {

private static Stream<Arguments> provideExceptionsModel() {
return Stream.of(
Arguments.of("currentLimitQuadripoleException", EurostagTutorialExample1Factory.create(), "Equipment NGEN is not a quadripole"),
Arguments.of("currentLimitMissingControlledException", EurostagTutorialExample1Factory.create(), "'controlledEquipment' field is not set"),
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,18 @@
/**
* 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

import com.powsybl.iidm.network.Branch

CurrentLimitAutomaton {
dynamicModelId "CLA_NGEN"
parameterSetId "CLA"
iMeasurement "NHV1_NHV2_1"
iMeasurementSide Branch.Side.TWO
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.powsybl.iidm.network.Branch
CurrentLimitAutomaton {
dynamicModelId "CLA_NGEN"
parameterSetId "CLA"
controlledQuadripole "NHV1_NHV2_2"
iMeasurement "NGEN"
iMeasurementSide Branch.Side.TWO
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* 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

import com.powsybl.iidm.network.Branch

CurrentLimitAutomatonTwoLevels {
dynamicModelId "AM_NHV1_NHV2_1"
parameterSetId "CLA"
controlledQuadripole "NHV1_NHV2_2"
iMeasurement1 "NHV1_NHV2_1"
iMeasurement1Side Branch.Side.TWO
iMeasurement2 "NGEN_NHV1"
iMeasurement2Side Branch.Side.ONE
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ for (Generator gen : network.generators) {
CurrentLimitAutomaton {
dynamicModelId "CLA_2_4"
parameterSetId "CLA_2_4"
controlledQuadripole "_BUS____2-BUS____4-1_AC"
iMeasurement "_BUS____2-BUS____4-1_AC"
iMeasurementSide Branch.Side.TWO
}

CurrentLimitAutomaton {
dynamicModelId "CLA_2_5"
parameterSetId "CLA_2_5"
controlledQuadripole "_BUS____2-BUS____5-1_AC"
iMeasurement "_BUS____2-BUS____5-1_AC"
iMeasurementSide Branch.Side.TWO
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
*/
public class CurrentLimitAutomaton extends AbstractPureDynamicBlackBoxModel {

private static final String MEASURE_SUFFIX = "Measure";
private static final String CONTROL_SUFFIX = "Control";
protected static final String MEASURE_SUFFIX = "Measure";
protected static final String CONTROL_SUFFIX = "Control";

private final Branch<?> measuredQuadripole;
private final Side measuredSide;
private final Branch<?> controlledQuadripole;
private final String lib;
protected final Branch<?> measuredQuadripole;
protected final Side measuredSide;
protected final Branch<?> controlledQuadripole;
protected final String lib;

public CurrentLimitAutomaton(String dynamicModelId, String parameterSetId, Branch<?> measuredQuadripole, Side measuredSide, Branch<?> controlledQuadripole, String lib) {
super(dynamicModelId, parameterSetId);
Expand All @@ -53,14 +53,14 @@ public void createMacroConnections(DynaWaltzContext context) {
createMacroConnections(controlledQuadripole, QuadripoleModel.class, this::getVarConnectionsWithControlledQuadripole, context, CONTROL_SUFFIX);
}

private List<VarConnection> getVarConnectionsWithMeasuredQuadripole(QuadripoleModel connected) {
protected List<VarConnection> getVarConnectionsWithMeasuredQuadripole(QuadripoleModel connected) {
return Arrays.asList(
new VarConnection("currentLimitAutomaton_IMonitored", connected.getIVarName(measuredSide)),
new VarConnection("currentLimitAutomaton_AutomatonExists", connected.getDeactivateCurrentLimitsVarName())
);
}

private List<VarConnection> getVarConnectionsWithControlledQuadripole(QuadripoleModel connected) {
protected List<VarConnection> getVarConnectionsWithControlledQuadripole(QuadripoleModel connected) {
return List.of(new VarConnection("currentLimitAutomaton_order", connected.getStateVarName()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* 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.Side;
import com.powsybl.dynawaltz.models.VarConnection;
import com.powsybl.iidm.network.Branch;

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

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

protected static final String FIRST_MEASURE_SUFFIX = MEASURE_SUFFIX + "1";
protected static final String SECOND_MEASURE_SUFFIX = MEASURE_SUFFIX + "2";

private final Branch<?> secondMeasuredQuadripole;
private final Side secondMeasuredSide;

public CurrentLimitTwoLevelsAutomaton(String dynamicModelId, String parameterSetId, Branch<?> measuredQuadripole, Side measuredSide, Branch<?> secondMeasuredQuadripole, Side secondMeasuredSide, Branch<?> controlledQuadripole, String lib) {
super(dynamicModelId, parameterSetId, measuredQuadripole, measuredSide, controlledQuadripole, lib);
this.secondMeasuredQuadripole = Objects.requireNonNull(secondMeasuredQuadripole);
this.secondMeasuredSide = Objects.requireNonNull(secondMeasuredSide);
}

@Override
public void createMacroConnections(DynaWaltzContext context) {
createMacroConnections(measuredQuadripole, QuadripoleModel.class, this::getVarConnectionsWithMeasuredQuadripole, context, FIRST_MEASURE_SUFFIX + measuredSide.getSideSuffix());
createMacroConnections(secondMeasuredQuadripole, QuadripoleModel.class, this::getVarConnectionsWithSecondMeasuredQuadripole, context, SECOND_MEASURE_SUFFIX + secondMeasuredSide.getSideSuffix());
createMacroConnections(controlledQuadripole, QuadripoleModel.class, this::getVarConnectionsWithControlledQuadripole, context, CONTROL_SUFFIX);
}

@Override
protected List<VarConnection> getVarConnectionsWithMeasuredQuadripole(QuadripoleModel connected) {
return Arrays.asList(
new VarConnection("currentLimitAutomaton_IMonitored1", connected.getIVarName(measuredSide)),
new VarConnection("currentLimitAutomaton_AutomatonExists", connected.getDeactivateCurrentLimitsVarName())
);
}

private List<VarConnection> getVarConnectionsWithSecondMeasuredQuadripole(QuadripoleModel connected) {
return List.of(new VarConnection("currentLimitAutomaton_IMonitored2", connected.getIVarName(secondMeasuredSide)));
}
}
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.Side;
import com.powsybl.dynawaltz.models.automatons.CurrentLimitTwoLevelsAutomaton;
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 CurrentLimitTwoLevelsModelXmlTest extends AbstractDynamicModelXmlTest {

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

@Override
protected void addDynamicModels() {
dynamicModels.add(new CurrentLimitTwoLevelsAutomaton("BBM_CLA_TWO_LEVELS", "cla", network.getLine("NHV1_NHV2_1"), Side.TWO, network.getLine("NHV1_NHV2_2"), Side.ONE, network.getTwoWindingsTransformer("NGEN_NHV1"), "CurrentLimitAutomatonTwoLevels"));
}

@Test
void writeModel() throws SAXException, IOException, XMLStreamException {
DydXml.write(tmpDir, context);
validate("dyd.xsd", "cla_tl_dyd.xml", tmpDir.resolve(DynaWaltzConstants.DYD_FILENAME));
}
}
17 changes: 17 additions & 0 deletions dynawaltz/src/test/resources/cla_tl_dyd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<dyn:dynamicModelsArchitecture xmlns:dyn="http://www.rte-france.com/dynawo">
<dyn:blackBoxModel id="BBM_CLA_TWO_LEVELS" lib="CurrentLimitAutomatonTwoLevels" parFile="models.par" parId="cla"/>
<dyn:macroConnector id="MC_CurrentLimitAutomatonTwoLevelsMeasure1Side2-NetworkLine">
<dyn:connect var1="currentLimitAutomaton_IMonitored1" var2="@NAME@_iSide2"/>
<dyn:connect var1="currentLimitAutomaton_AutomatonExists" var2="@NAME@_desactivate_currentLimits"/>
</dyn:macroConnector>
<dyn:macroConnector id="MC_CurrentLimitAutomatonTwoLevelsMeasure2Side1-NetworkLine">
<dyn:connect var1="currentLimitAutomaton_IMonitored2" var2="@NAME@_iSide1"/>
</dyn:macroConnector>
<dyn:macroConnector id="MC_CurrentLimitAutomatonTwoLevelsControl-NetworkTransformer">
<dyn:connect var1="currentLimitAutomaton_order" var2="@NAME@_state"/>
</dyn:macroConnector>
<dyn:macroConnect connector="MC_CurrentLimitAutomatonTwoLevelsMeasure1Side2-NetworkLine" id1="BBM_CLA_TWO_LEVELS" id2="NETWORK" name2="NHV1_NHV2_1"/>
<dyn:macroConnect connector="MC_CurrentLimitAutomatonTwoLevelsMeasure2Side1-NetworkLine" id1="BBM_CLA_TWO_LEVELS" id2="NETWORK" name2="NHV1_NHV2_2"/>
<dyn:macroConnect connector="MC_CurrentLimitAutomatonTwoLevelsControl-NetworkTransformer" id1="BBM_CLA_TWO_LEVELS" id2="NETWORK" name2="NGEN_NHV1"/>
</dyn:dynamicModelsArchitecture>