Skip to content

Commit

Permalink
Fix TODO
Browse files Browse the repository at this point in the history
Signed-off-by: lisrte <[email protected]>
  • Loading branch information
Lisrte committed Jan 16, 2024
1 parent 6f10f80 commit 1260896
Show file tree
Hide file tree
Showing 18 changed files with 135 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import com.powsybl.commons.reporter.Reporter
import com.powsybl.dynamicsimulation.EventModel
import com.powsybl.dynamicsimulation.groovy.EventModelGroovyExtension
import com.powsybl.dynawaltz.DynaWaltzProvider
import com.powsybl.dynawaltz.builders.EventModelsBuilderUtils
import com.powsybl.dynawaltz.builders.EventModelCategory
import com.powsybl.dynawaltz.builders.EventBuilderConfig
import com.powsybl.dynawaltz.builders.ModelBuilder
import com.powsybl.dynawaltz.builders.ModelConfigsSingleton
import com.powsybl.iidm.network.Network

import java.util.function.Consumer
Expand All @@ -24,10 +24,10 @@ import java.util.function.Consumer
@AutoService(EventModelGroovyExtension.class)
class DynaWaltzEventModelGroovyExtension implements EventModelGroovyExtension {

private final List<EventModelCategory> modelConstructors
private final List<EventBuilderConfig> builderConfigs

DynaWaltzEventModelGroovyExtension() {
modelConstructors = EventModelsBuilderUtils.eventModelCategories
builderConfigs = ModelConfigsSingleton.getInstance().getEventBuilderConfigs()
}

@Override
Expand All @@ -36,12 +36,12 @@ class DynaWaltzEventModelGroovyExtension implements EventModelGroovyExtension {
}

List<String> getModelNames() {
modelConstructors.collect {it.tag}
builderConfigs.collect {it.tag}
}

@Override
void load(Binding binding, Consumer<EventModel> consumer, Reporter reporter) {
modelConstructors.forEach {
builderConfigs.forEach {
binding.setVariable(it.tag, { Closure<Void> closure ->
def cloned = closure.clone()
ModelBuilder<EventModel> builder = it.builderConstructor.createBuilder(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Copyright (c) 2024, 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.builders;

import com.powsybl.commons.reporter.Reporter;
Expand All @@ -7,6 +14,9 @@
import java.util.Collection;
import java.util.function.Supplier;

/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
public class BuilderConfig {

@FunctionalInterface
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (c) 2024, 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.builders;

import com.powsybl.commons.reporter.Reporter;
import com.powsybl.dynamicsimulation.EventModel;
import com.powsybl.iidm.network.Network;

/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
public class EventBuilderConfig {

@FunctionalInterface
public interface EventModelBuilderConstructor {
ModelBuilder<EventModel> createBuilder(Network network, Reporter reporter);
}

private final EventModelBuilderConstructor builderConstructor;
private final String tag;

public EventBuilderConfig(EventModelBuilderConstructor builderConstructor, String tag) {
this.builderConstructor = builderConstructor;
this.tag = tag;
}

public EventModelBuilderConstructor getBuilderConstructor() {
return builderConstructor;
}

public String getTag() {
return tag;
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
package com.powsybl.dynawaltz.builders;

import com.google.common.collect.Lists;
import com.powsybl.dynawaltz.models.events.EventActivePowerVariationBuilder;
import com.powsybl.dynawaltz.models.events.EventDisconnectionBuilder;
import com.powsybl.dynawaltz.models.events.NodeFaultEventBuilder;

import java.util.HashMap;
import java.util.List;
Expand All @@ -24,6 +27,10 @@ public final class ModelConfigsSingleton {
private final List<ModelConfigLoader> modelConfigLoaders;
private final Map<String, Map<String, ModelConfig>> modelConfigs = new HashMap<>();
private final List<BuilderConfig> builderConfigs;
private final List<EventBuilderConfig> eventBuilderConfigs = List.of(
new EventBuilderConfig(EventActivePowerVariationBuilder::of, EventActivePowerVariationBuilder.TAG),
new EventBuilderConfig(EventDisconnectionBuilder::of, EventDisconnectionBuilder.TAG),
new EventBuilderConfig(NodeFaultEventBuilder::of, NodeFaultEventBuilder.TAG));

private ModelConfigsSingleton() {
modelConfigLoaders = Lists.newArrayList(ServiceLoader.load(ModelConfigLoader.class));
Expand All @@ -47,4 +54,8 @@ public Map<String, ModelConfig> getModelConfigs(String categoryName) {
public List<BuilderConfig> getBuilderConfigs() {
return builderConfigs;
}

public List<EventBuilderConfig> getEventBuilderConfigs() {
return eventBuilderConfigs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ public class EventActivePowerVariationBuilder extends AbstractEventModelBuilder<

protected Double deltaP;

public EventActivePowerVariationBuilder(Network network, Reporter reporter) {
public static EventActivePowerVariationBuilder of(Network network) {
return of(network, Reporter.NO_OP);
}

public static EventActivePowerVariationBuilder of(Network network, Reporter reporter) {
return new EventActivePowerVariationBuilder(network, reporter);
}

EventActivePowerVariationBuilder(Network network, Reporter reporter) {
super(network, new BuilderEquipment<>("GENERATOR/LOAD"), TAG, reporter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ private enum DisconnectionType {
protected boolean disconnectOrigin = true;
protected boolean disconnectExtremity = true;

public EventDisconnectionBuilder(Network network, Reporter reporter) {
public static EventDisconnectionBuilder of(Network network) {
return of(network, Reporter.NO_OP);
}

public static EventDisconnectionBuilder of(Network network, Reporter reporter) {
return new EventDisconnectionBuilder(network, reporter);
}

EventDisconnectionBuilder(Network network, Reporter reporter) {
super(network, new BuilderEquipment<>("Disconnectable equipment"), TAG, reporter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ public class NodeFaultEventBuilder extends AbstractEventModelBuilder<Bus, NodeFa
protected double rPu;
protected double xPu;

public NodeFaultEventBuilder(Network network, Reporter reporter) {
public static NodeFaultEventBuilder of(Network network) {
return of(network, Reporter.NO_OP);
}

public static NodeFaultEventBuilder of(Network network, Reporter reporter) {
return new NodeFaultEventBuilder(network, reporter);
}

NodeFaultEventBuilder(Network network, Reporter reporter) {
super(network, new BuilderEquipment<>(IdentifiableType.BUS), TAG, reporter);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Copyright (c) 2024, 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.builders;

import com.fasterxml.jackson.core.type.TypeReference;
Expand All @@ -11,6 +18,9 @@
import java.util.List;
import java.util.Map;

/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
public class ModelConfigLoaderTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
package com.powsybl.dynawaltz.xml;

import com.powsybl.dynawaltz.builders.EventModelsBuilderUtils;
import com.powsybl.dynawaltz.models.events.EventActivePowerVariationBuilder;
import com.powsybl.dynawaltz.models.loads.BaseLoadBuilder;
import com.powsybl.dynawaltz.models.generators.SynchronizedGeneratorBuilder;
import com.powsybl.dynawaltz.models.generators.SynchronousGeneratorBuilder;
Expand Down Expand Up @@ -44,27 +44,27 @@ protected void addDynamicModels() {
.staticId("LOAD2")
.parameterSetId("load")
.build());
eventModels.add(EventModelsBuilderUtils.newEventActivePowerVariationBuilder(network)
eventModels.add(EventActivePowerVariationBuilder.of(network)
.staticId("GEN")
.startTime(1)
.deltaP(1.1)
.build());
eventModels.add(EventModelsBuilderUtils.newEventActivePowerVariationBuilder(network)
eventModels.add(EventActivePowerVariationBuilder.of(network)
.staticId("GEN2")
.startTime(1)
.deltaP(1.2)
.build());
eventModels.add(EventModelsBuilderUtils.newEventActivePowerVariationBuilder(network)
eventModels.add(EventActivePowerVariationBuilder.of(network)
.staticId("GEN3")
.startTime(1)
.deltaP(1.3)
.build());
eventModels.add(EventModelsBuilderUtils.newEventActivePowerVariationBuilder(network)
eventModels.add(EventActivePowerVariationBuilder.of(network)
.staticId("LOAD")
.startTime(10)
.deltaP(1.2)
.build());
eventModels.add(EventModelsBuilderUtils.newEventActivePowerVariationBuilder(network)
eventModels.add(EventActivePowerVariationBuilder.of(network)
.staticId("LOAD2")
.startTime(10)
.deltaP(1.3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
package com.powsybl.dynawaltz.xml;

import com.powsybl.dynawaltz.builders.EventModelsBuilderUtils;
import com.powsybl.dynawaltz.models.events.EventDisconnectionBuilder;
import com.powsybl.dynawaltz.models.generators.GeneratorFictitiousBuilder;
import com.powsybl.iidm.network.Bus;
import com.powsybl.iidm.network.VoltageLevel;
Expand Down Expand Up @@ -46,19 +46,19 @@ protected void addDynamicModels() {
.staticId("G1")
.parameterSetId("GF")
.build());
eventModels.add(EventModelsBuilderUtils.newEventDisconnectionBuilder(network)
eventModels.add(EventDisconnectionBuilder.of(network)
.staticId("G1")
.startTime(1)
.build());
eventModels.add(EventModelsBuilderUtils.newEventDisconnectionBuilder(network)
eventModels.add(EventDisconnectionBuilder.of(network)
.staticId("L2")
.startTime(1)
.build());
eventModels.add(EventModelsBuilderUtils.newEventDisconnectionBuilder(network)
eventModels.add(EventDisconnectionBuilder.of(network)
.staticId("SVC2")
.startTime(1)
.build());
eventModels.add(EventModelsBuilderUtils.newEventDisconnectionBuilder(network)
eventModels.add(EventDisconnectionBuilder.of(network)
.staticId("SH1")
.startTime(1)
.build());
Expand Down
Loading

0 comments on commit 1260896

Please sign in to comment.