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 active power variation #218

Merged
merged 12 commits into from
May 19, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,29 @@ import java.util.function.Consumer
abstract class AbstractEquipmentGroovyExtension<T> {

protected static final String MODELS_CONFIG = "models.cfg"
protected static final String MODELS_PROPERTIES = "properties"

protected List<String> modelTags
protected final List<EquipmentConfig> equipmentConfigs

abstract protected ModelBuilder<T> createBuilder(Network network, String currentTag);
AbstractEquipmentGroovyExtension(String modelTag) {
ConfigSlurper config = new ConfigSlurper()
equipmentConfigs = config.parse(this.getClass().getClassLoader().getResource(MODELS_CONFIG)).get(modelTag).collect {
def lib = it.key
(it.value.containsKey(MODELS_PROPERTIES))
? new EquipmentConfig(lib, it.value.get(MODELS_PROPERTIES).collect{it.toUpperCase() as EnumEquipmentProperty})
: new EquipmentConfig(lib)
}
}

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

String getName() {
return DynaWaltzProvider.NAME
}

void load(Binding binding, Consumer<T> consumer) {
modelTags.forEach {
binding.setVariable(it, { Closure<Void> closure ->
equipmentConfigs.forEach {
binding.setVariable(it.lib, { Closure<Void> closure ->
def cloned = closure.clone()
ModelBuilder<T> builder = createBuilder(binding.getVariable("network") as Network, it)
cloned.delegate = builder
Expand Down
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.dsl

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

import java.util.function.Consumer

/**
* @author Laurent Issertial <laurent.issertial at rte-france.com>
*/
abstract class AbstractSimpleEquipmentGroovyExtension<T> {

protected String modelTag

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

String getName() {
return DynaWaltzProvider.NAME
}

void load(Binding binding, Consumer<T> consumer) {
binding.setVariable(modelTag, { Closure<Void> closure ->
def cloned = closure.clone()
ModelBuilder<T> builder = createBuilder(binding.getVariable("network") as Network)
cloned.delegate = builder
cloned()
consumer.accept(builder.build())
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.powsybl.dynawaltz.dsl

enum EnumEquipmentProperty {

CONTROLLABLE

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.powsybl.dynawaltz.dsl

class EquipmentConfig {

String lib
List<EnumEquipmentProperty> properties

EquipmentConfig(String lib) {
this.lib = lib
this.properties = []
}

EquipmentConfig(String lib, List<EnumEquipmentProperty> properties) {
this.lib = lib
this.properties = properties
}

boolean isControllable() {
return properties.contains(EnumEquipmentProperty.CONTROLLABLE)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* 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.EventActivePowerVariation
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 EventActivePowerVariationGroovyExtension extends AbstractPureDynamicGroovyExtension<EventModel> implements EventModelGroovyExtension {

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

EventActivePowerVariationGroovyExtension() {
modelTags = ["Step"]
}

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

static class EventAPVBuilder extends AbstractEventModelBuilder {

double deltaP
Identifiable<? extends Identifiable> identifiable

EventAPVBuilder(Network network) {
super(network)
}

void deltaP(double deltaP) {
this.deltaP = deltaP
}

void checkData() {
super.checkData()
identifiable = network.getIdentifiable(staticId)
if (identifiable == null) {
throw new DslException("Identifiable static id unknown: " + getStaticId())
}
if (!EventActivePowerVariation.isConnectable(identifiable.getType())) {
throw new DslException("Equipment ${getStaticId()} cannot be disconnected")
}
}

@Override
AbstractEventModel build() {
checkData()
new EventActivePowerVariation(identifiable, startTime, deltaP)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package com.powsybl.dynawaltz.dsl.models.buses
import com.google.auto.service.AutoService
import com.powsybl.dynamicsimulation.DynamicModel
import com.powsybl.dynamicsimulation.groovy.DynamicModelGroovyExtension
import com.powsybl.dynawaltz.dsl.AbstractEquipmentGroovyExtension
import com.powsybl.dynawaltz.dsl.AbstractSimpleEquipmentGroovyExtension
import com.powsybl.dynawaltz.models.buses.StandardBus
import com.powsybl.iidm.network.Network

Expand All @@ -20,14 +20,14 @@ import com.powsybl.iidm.network.Network
* @author Dimitri Baudrier <dimitri.baudrier at rte-france.com>
*/
@AutoService(DynamicModelGroovyExtension.class)
class BusGroovyExtension extends AbstractEquipmentGroovyExtension<DynamicModel> implements DynamicModelGroovyExtension {
class BusGroovyExtension extends AbstractSimpleEquipmentGroovyExtension<DynamicModel> implements DynamicModelGroovyExtension {

BusGroovyExtension() {
modelTags = ["Bus"]
modelTag = "Bus"
}

@Override
protected BusBuilder createBuilder(Network network, String currentTag) {
protected BusBuilder createBuilder(Network network) {
new BusBuilder(network)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.google.auto.service.AutoService
import com.powsybl.dynamicsimulation.DynamicModel
import com.powsybl.dynamicsimulation.groovy.DynamicModelGroovyExtension
import com.powsybl.dynawaltz.dsl.AbstractEquipmentGroovyExtension
import com.powsybl.dynawaltz.dsl.EquipmentConfig
import com.powsybl.dynawaltz.models.buses.InfiniteBus
import com.powsybl.iidm.network.Network

Expand All @@ -23,28 +24,27 @@ class InfiniteBusGroovyExtension extends AbstractEquipmentGroovyExtension<Dynami
protected static final String BUSES = "infiniteBuses"

InfiniteBusGroovyExtension() {
ConfigSlurper config = new ConfigSlurper()
modelTags = config.parse(this.getClass().getClassLoader().getResource(MODELS_CONFIG)).get(BUSES).keySet() as List
super(BUSES)
}

@Override
protected BusBuilder createBuilder(Network network, String currentTag) {
new BusBuilder(network, currentTag)
protected BusBuilder createBuilder(Network network, EquipmentConfig equipmentConfig) {
new BusBuilder(network, equipmentConfig)
}

static class BusBuilder extends AbstractBusBuilder {

String tag
EquipmentConfig equipmentConfig

BusBuilder(Network network, String tag) {
BusBuilder(Network network, EquipmentConfig equipmentConfig) {
super(network)
this.tag = tag
this.equipmentConfig = equipmentConfig
}

@Override
InfiniteBus build() {
checkData()
new InfiniteBus(dynamicModelId, bus, parameterSetId, tag)
new InfiniteBus(dynamicModelId, bus, parameterSetId, equipmentConfig.lib)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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.AbstractEquipmentGroovyExtension
import com.powsybl.dynawaltz.dsl.AbstractSimpleEquipmentGroovyExtension
import com.powsybl.dynawaltz.dsl.models.builders.AbstractDynamicModelBuilder
import com.powsybl.dynawaltz.models.generators.GeneratorFictitious
import com.powsybl.iidm.network.Generator
Expand All @@ -20,14 +20,14 @@ import com.powsybl.iidm.network.Network
* @author Dimitri Baudrier <dimitri.baudrier at rte-france.com>
*/
@AutoService(DynamicModelGroovyExtension.class)
class GeneratorFictitiousGroovyExtension extends AbstractEquipmentGroovyExtension<DynamicModel> implements DynamicModelGroovyExtension {
class GeneratorFictitiousGroovyExtension extends AbstractSimpleEquipmentGroovyExtension<DynamicModel> implements DynamicModelGroovyExtension {

GeneratorFictitiousGroovyExtension() {
modelTags = ["GeneratorFictitious"]
modelTag = "GeneratorFictitious"
}

@Override
protected GeneratorFictitiousBuilder createBuilder(Network network, String currentTag) {
protected GeneratorFictitiousBuilder createBuilder(Network network) {
new GeneratorFictitiousBuilder(network)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import com.powsybl.dsl.DslException
import com.powsybl.dynamicsimulation.DynamicModel
import com.powsybl.dynamicsimulation.groovy.DynamicModelGroovyExtension
import com.powsybl.dynawaltz.dsl.AbstractEquipmentGroovyExtension
import com.powsybl.dynawaltz.dsl.EquipmentConfig
import com.powsybl.dynawaltz.dsl.models.builders.AbstractDynamicModelBuilder
import com.powsybl.dynawaltz.models.generators.GeneratorSynchronous
import com.powsybl.dynawaltz.models.generators.GeneratorSynchronousControllable
import com.powsybl.iidm.network.Generator
import com.powsybl.iidm.network.Network

Expand All @@ -25,23 +27,22 @@ class GeneratorSynchronousGroovyExtension extends AbstractEquipmentGroovyExtensi
protected static final String SYNCHRONOUS_GENERATORS = "synchronousGenerators"

GeneratorSynchronousGroovyExtension() {
ConfigSlurper config = new ConfigSlurper()
modelTags = config.parse(this.getClass().getClassLoader().getResource(MODELS_CONFIG)).get(SYNCHRONOUS_GENERATORS).keySet() as List
super(SYNCHRONOUS_GENERATORS)
}

@Override
protected GeneratorSynchronousBuilder createBuilder(Network network, String currentTag) {
new GeneratorSynchronousBuilder(network, currentTag)
protected GeneratorSynchronousBuilder createBuilder(Network network, EquipmentConfig equipmentConfig) {
new GeneratorSynchronousBuilder(network, equipmentConfig)
}

static class GeneratorSynchronousBuilder extends AbstractDynamicModelBuilder {

Generator generator
String tag
EquipmentConfig equipmentConfig

GeneratorSynchronousBuilder(Network network, String tag) {
GeneratorSynchronousBuilder(Network network, EquipmentConfig equipmentConfig) {
super(network)
this.tag = tag
this.equipmentConfig = equipmentConfig
}

void checkData() {
Expand All @@ -55,7 +56,11 @@ class GeneratorSynchronousGroovyExtension extends AbstractEquipmentGroovyExtensi
@Override
GeneratorSynchronous build() {
checkData()
new GeneratorSynchronous(dynamicModelId, generator, parameterSetId, tag)
if (equipmentConfig.isControllable()) {
new GeneratorSynchronousControllable(dynamicModelId, generator, parameterSetId, equipmentConfig.lib)
} else {
new GeneratorSynchronous(dynamicModelId, generator, parameterSetId, equipmentConfig.lib)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/**
* Copyright (c) 2022, 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
Expand All @@ -12,8 +12,10 @@ import com.powsybl.dsl.DslException
import com.powsybl.dynamicsimulation.DynamicModel
import com.powsybl.dynamicsimulation.groovy.DynamicModelGroovyExtension
import com.powsybl.dynawaltz.dsl.AbstractEquipmentGroovyExtension
import com.powsybl.dynawaltz.dsl.EquipmentConfig
import com.powsybl.dynawaltz.dsl.models.builders.AbstractDynamicModelBuilder
import com.powsybl.dynawaltz.models.generators.OmegaRefGenerator
import com.powsybl.dynawaltz.models.generators.OmegaRefGeneratorControllable
import com.powsybl.iidm.network.Generator
import com.powsybl.iidm.network.Network

Expand All @@ -27,23 +29,22 @@ class OmegaRefGeneratorGroovyExtension extends AbstractEquipmentGroovyExtension<
private static final String OMEGA_REF_GENERATORS = "omegaRefGenerators"

OmegaRefGeneratorGroovyExtension() {
ConfigSlurper config = new ConfigSlurper()
modelTags = config.parse(this.getClass().getClassLoader().getResource(MODELS_CONFIG)).get(OMEGA_REF_GENERATORS).keySet() as List
super(OMEGA_REF_GENERATORS)
}

@Override
protected OmegaRefGeneratorBuilder createBuilder(Network network, String currentTag) {
new OmegaRefGeneratorBuilder(network, currentTag)
protected OmegaRefGeneratorBuilder createBuilder(Network network, EquipmentConfig equipmentConfig) {
new OmegaRefGeneratorBuilder(network, equipmentConfig)
}

static class OmegaRefGeneratorBuilder extends AbstractDynamicModelBuilder {

Generator generator
String tag
EquipmentConfig equipmentConfig

OmegaRefGeneratorBuilder(Network network, String tag) {
super(network)
this.tag = tag
OmegaRefGeneratorBuilder(Network network, EquipmentConfig equipmentConfig) {
super(network, )
this.equipmentConfig = equipmentConfig
}

void checkData() {
Expand All @@ -57,7 +58,11 @@ class OmegaRefGeneratorGroovyExtension extends AbstractEquipmentGroovyExtension<
@Override
OmegaRefGenerator build() {
checkData()
new OmegaRefGenerator(dynamicModelId, generator, parameterSetId, tag)
if (equipmentConfig.isControllable()) {
new OmegaRefGeneratorControllable(dynamicModelId, generator, parameterSetId, equipmentConfig.lib)
} else {
new OmegaRefGenerator(dynamicModelId, generator, parameterSetId, equipmentConfig.lib)
}
}
}
}
Loading