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

Refactor disconnection events #197

Merged
merged 16 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from 12 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
Expand Up @@ -9,6 +9,7 @@
package com.powsybl.dynawaltz.dsl

import com.powsybl.dynawaltz.DynaWaltzProvider
import com.powsybl.iidm.network.Network

import java.util.function.Consumer

Expand All @@ -19,7 +20,7 @@ abstract class AbstractPureDynamicGroovyExtension<T> {

protected List<String> modelTags

abstract protected ModelBuilder<T> createBuilder();
abstract protected ModelBuilder<T> createBuilder(Network network);

String getName() {
return DynaWaltzProvider.NAME
Expand All @@ -29,7 +30,7 @@ abstract class AbstractPureDynamicGroovyExtension<T> {
modelTags.forEach {
binding.setVariable(it, { Closure<Void> closure ->
def cloned = closure.clone()
ModelBuilder<T> builder = createBuilder()
ModelBuilder<T> builder = createBuilder(binding.getVariable("network") as Network)
cloned.delegate = builder
cloned()
consumer.accept(builder.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ package com.powsybl.dynawaltz.dsl.events
import com.powsybl.dsl.DslException
import com.powsybl.dynamicsimulation.EventModel
import com.powsybl.dynawaltz.dsl.ModelBuilder
import com.powsybl.iidm.network.Network

/**
* @author Laurent Issertial <laurent.issertial at rte-france.com>
*/
abstract class AbstractEventModelBuilder implements ModelBuilder<EventModel> {

String eventModelId
Network network
String staticId
double startTime

void eventModelId(String eventModelId) {
this.eventModelId = eventModelId
AbstractEventModelBuilder(Network network) {
this.network = network
}

void staticId(String staticId) {
Expand All @@ -40,9 +41,6 @@ abstract class AbstractEventModelBuilder implements ModelBuilder<EventModel> {
if (!startTime) {
throw new DslException("'startTime' field is not set")
}
if (!eventModelId) {
eventModelId = staticId
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* 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.events

import com.google.auto.service.AutoService
import com.powsybl.dsl.DslException
import com.powsybl.dynamicsimulation.EventModel
import com.powsybl.dynamicsimulation.groovy.EventModelGroovyExtension
import com.powsybl.dynawaltz.dsl.AbstractPureDynamicGroovyExtension
import com.powsybl.dynawaltz.models.events.AbstractEventModel
import com.powsybl.dynawaltz.models.events.EventQuadripoleDisconnection
import com.powsybl.dynawaltz.models.events.EventSetPointBoolean
import com.powsybl.iidm.network.Branch
import com.powsybl.iidm.network.Identifiable
import com.powsybl.iidm.network.IdentifiableType
import com.powsybl.iidm.network.Network

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

private static final EnumSet<IdentifiableType> connectableEquipments = EnumSet.of(IdentifiableType.GENERATOR, IdentifiableType.LOAD)

private static final EnumSet<IdentifiableType> connectableQuadripoleEquipments = EnumSet.of(IdentifiableType.LINE, IdentifiableType.TWO_WINDINGS_TRANSFORMER)

EventDisconnectionGroovyExtension() {
modelTags = ["Disconnect"]
}

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

static class EventQuadripoleDisconnectionBuilder extends AbstractEventModelBuilder {

boolean disconnectSide = false
boolean isEquipment = false
boolean isQuadripoleEquipment = false

boolean disconnectOrigin = true
boolean disconnectExtremity = true
Identifiable<? extends Identifiable> identifiable

EventQuadripoleDisconnectionBuilder(Network network) {
super(network)
}

void disconnectOnly(Branch.Side side) {
disconnectSide = true
switch(side) {
case Branch.Side.ONE :
disconnectOrigin = true
disconnectExtremity = false
break
case Branch.Side.TWO :
disconnectOrigin = false
disconnectExtremity = true
break
}
}

void checkData() {
super.checkData()
identifiable = network.getIdentifiable(staticId)
if (identifiable == null) {
throw new DslException("Identifiable static id unknown: " + getStaticId())
}
isEquipment = connectableEquipments.contains(identifiable.getType())
isQuadripoleEquipment = connectableQuadripoleEquipments.contains(identifiable.getType())
if (!isEquipment && !isQuadripoleEquipment) {
throw new DslException("Equipment " + getStaticId() + " cannot be disconnected")
} else if(isEquipment && disconnectSide) {
throw new DslException("Equipment " + getStaticId() + " is not a quadripole")
Lisrte marked this conversation as resolved.
Show resolved Hide resolved
}
}

@Override
AbstractEventModel build() {
checkData()
if(isEquipment)
new EventSetPointBoolean(identifiable, startTime)
else if (isQuadripoleEquipment)
new EventQuadripoleDisconnection(identifiable, startTime, disconnectOrigin, disconnectExtremity)
}
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.powsybl.dynawaltz.models.Side
import com.powsybl.dynawaltz.models.automatons.CurrentLimitAutomaton
import com.powsybl.dynawaltz.models.utils.SideConverter
import com.powsybl.iidm.network.Branch
import com.powsybl.iidm.network.Network

/**
* An implementation of {@link DynamicModelGroovyExtension} that adds the <pre>CurrentLimitAutomaton</pre> keyword to the DSL
Expand All @@ -31,7 +32,7 @@ class CurrentLimitAutomatonGroovyExtension extends AbstractPureDynamicGroovyExte
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class EventModelsSupplierTest extends AbstractModelSupplierTest {

@Test
void testGroovyExtensionCount() {
assertEquals(2, EXTENSIONS.size());
assertEquals(1, EXTENSIONS.size());
}

@ParameterizedTest(name = "{0}")
Expand All @@ -52,16 +52,16 @@ void testEventModels(String groovyScriptName, Class<? extends AbstractEventModel

void assertEventModel(AbstractEventModel em, String dynamicId, String equipmentStaticId, String lib, double startTime) {
assertEquals(dynamicId, em.getDynamicModelId());
assertEquals(equipmentStaticId, em.getEquipmentStaticId());
assertEquals(equipmentStaticId, em.getEquipment().getId());
assertEquals(dynamicId, em.getParameterSetId());
assertEquals(lib, em.getLib());
assertEquals(startTime, em.getStartTime());
}

private static Stream<Arguments> provideEventModelData() {
return Stream.of(
Arguments.of("quadripoleDisconnection", EventQuadripoleDisconnection.class, EurostagTutorialExample1Factory.create(), "NHV1_NHV2_1", "EM_NHV1_NHV2_1", "EventQuadripoleDisconnection", 4),
Arguments.of("setPointBoolean", EventSetPointBoolean.class, EurostagTutorialExample1Factory.create(), "GEN", "EM_GEN", "EventSetPointBoolean", 1)
Arguments.of("quadripoleDisconnection", EventQuadripoleDisconnection.class, EurostagTutorialExample1Factory.create(), "NHV1_NHV2_1", "Disconnect_NHV1_NHV2_1", "EventQuadripoleDisconnection", 4),
Arguments.of("equipmentDisconnection", EventSetPointBoolean.class, EurostagTutorialExample1Factory.create(), "GEN", "Disconnect_GEN", null, 1)
);
}

Expand Down
8 changes: 3 additions & 5 deletions dynawaltz-dsl/src/test/resources/eventModels.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
*/

import com.powsybl.iidm.network.Line

import com.powsybl.iidm.network.Branch

for (Line line : network.lines) {
EventQuadripoleDisconnection {
Disconnect {
staticId line.id
eventModelId "EM_" + line.id
startTime 4
disconnectOrigin false
disconnectExtremity true
disconnectOnly Branch.Side.TWO
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

package eventModels

EventSetPointBoolean {
Disconnect {
staticId "GEN"
eventModelId "EM_GEN"
startTime 1
stateEvent true
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

package eventModels

EventQuadripoleDisconnection {
import com.powsybl.iidm.network.Branch

Disconnect {
staticId "NHV1_NHV2_1"
eventModelId "EM_NHV1_NHV2_1"
startTime 4
disconnectOrigin false
disconnectExtremity true
disconnectOnly Branch.Side.ONE
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
<reference name="generator_U0Pu" origData="IIDM" origName="v_pu" type="DOUBLE"/>
<reference name="generator_UPhase0" origData="IIDM" origName="angle_pu" type="DOUBLE"/>
</set>
<set id="EQD">
<set id="Disconnect__BUS____1-BUS____5-1_AC">
<par type="DOUBLE" name="event_tEvent" value="5"/>
<par type="BOOL" name="event_disconnectOrigin" value="false"/>
<par type="BOOL" name="event_disconnectExtremity" value="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<dyn:par type="DOUBLE" name="weight_gen_4" value="687.0"/>
<dyn:par type="INT" name="nbGen" value="5"/>
</dyn:set>
<dyn:set id="DISCONNECT_LINE">
<dyn:set id="Disconnect__BUS____1-BUS____5-1_AC">
<dyn:par type="DOUBLE" name="event_tEvent" value="5.0"/>
<dyn:par type="BOOL" name="event_disconnectOrigin" value="false"/>
<dyn:par type="BOOL" name="event_disconnectExtremity" value="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
<reference name="generator_U0Pu" origData="IIDM" origName="v_pu" type="DOUBLE"/>
<reference name="generator_UPhase0" origData="IIDM" origName="angle_pu" type="DOUBLE"/>
</set>
<set id="EQD">
<set id="Disconnect__BUS____1-BUS____5-1_AC">
<par type="DOUBLE" name="event_tEvent" value="5"/>
<par type="BOOL" name="event_disconnectOrigin" value="false"/>
<par type="BOOL" name="event_disconnectExtremity" value="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<dyn:blackBoxModel id="CLA_2_4" lib="CurrentLimitAutomaton" parFile="models.par" parId="CLA_2_4"/>
<dyn:blackBoxModel id="CLA_2_5" lib="CurrentLimitAutomaton" parFile="models.par" parId="CLA_2_5"/>
<dyn:blackBoxModel id="OMEGA_REF" lib="DYNModelOmegaRef" parFile="ieee14bus.par" parId="OMEGA_REF"/>
<dyn:blackBoxModel id="DISCONNECT_LINE" lib="EventQuadripoleDisconnection" parFile="ieee14bus.par" parId="DISCONNECT_LINE"/>
<dyn:blackBoxModel id="Disconnect__BUS____1-BUS____5-1_AC" lib="EventQuadripoleDisconnection" parFile="ieee14bus.par" parId="Disconnect__BUS____1-BUS____5-1_AC"/>
<dyn:macroConnector id="MC_LoadAlphaBeta-NetworkBus">
<dyn:connect var1="load_terminal" var2="@NAME@_ACPIN"/>
<dyn:connect var1="load_switchOffSignal1" var2="@NAME@_switchOff"/>
Expand Down Expand Up @@ -128,5 +128,5 @@
<dyn:macroConnect connector="MC_DYNModelOmegaRef-NetworkBus" id1="OMEGA_REF" index1="3" id2="NETWORK" name2="_BUS____6_TN"/>
<dyn:macroConnect connector="MC_DYNModelOmegaRef-GeneratorSynchronousThreeWindingsProportionalRegulations" id1="OMEGA_REF" index1="4" id2="_GEN____8_SM"/>
<dyn:macroConnect connector="MC_DYNModelOmegaRef-NetworkBus" id1="OMEGA_REF" index1="4" id2="NETWORK" name2="_BUS____8_TN"/>
<dyn:macroConnect connector="MC_EventQuadripoleDisconnection-NetworkLine" id1="DISCONNECT_LINE" id2="NETWORK" name2="_BUS____1-BUS____5-1_AC"/>
<dyn:macroConnect connector="MC_EventQuadripoleDisconnection-NetworkLine" id1="Disconnect__BUS____1-BUS____5-1_AC" id2="NETWORK" name2="_BUS____1-BUS____5-1_AC"/>
</dyn:dynamicModelsArchitecture>
Loading