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

Dynawaltz builders #323

Merged
merged 19 commits into from
Jan 29, 2024
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

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* 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.google.auto.service.AutoService
import com.powsybl.commons.reporter.Reporter
import com.powsybl.dynamicsimulation.DynamicModel
import com.powsybl.dynamicsimulation.groovy.DynamicModelGroovyExtension
import com.powsybl.dynawaltz.DynaWaltzProvider
import com.powsybl.dynawaltz.builders.BuilderConfig
import com.powsybl.dynawaltz.builders.ModelBuilder
import com.powsybl.dynawaltz.builders.ModelConfigs
import com.powsybl.iidm.network.Network

import java.util.function.Consumer
/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
@AutoService(DynamicModelGroovyExtension.class)
class DynaWaltzDynamicModelGroovyExtension implements DynamicModelGroovyExtension {

private final List<BuilderConfig> builderConfigs

DynaWaltzDynamicModelGroovyExtension() {
builderConfigs = ModelConfigs.getInstance().getBuilderConfigs()
}

@Override
String getName() {
DynaWaltzProvider.NAME
}

@Override
List<String> getModelNames() {
builderConfigs.stream().flatMap { it -> it.libs}.toList() as List<String>
}

@Override
void load(Binding binding, Consumer<DynamicModel> consumer, Reporter reporter) {
builderConfigs.forEach {conf ->
conf.libs.forEach {lib ->
binding.setVariable(lib , { Closure<Void> closure ->
def cloned = closure.clone()
ModelBuilder<DynamicModel> builder = conf.builderConstructor
.createBuilder(binding.getVariable("network") as Network, lib, Reporters.createModelBuilderReporter(reporter, lib))
cloned.delegate = builder
cloned()
builder.build()?.tap {
consumer.accept(it)
}
})
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,46 @@
*/
package com.powsybl.dynawaltz.dsl

import com.google.auto.service.AutoService
import com.powsybl.commons.reporter.Reporter
import com.powsybl.dynamicsimulation.groovy.GroovyExtension
import com.powsybl.dynamicsimulation.EventModel
import com.powsybl.dynamicsimulation.groovy.EventModelGroovyExtension
import com.powsybl.dynawaltz.DynaWaltzProvider
import com.powsybl.dynawaltz.builders.EventBuilderConfig
import com.powsybl.dynawaltz.builders.ModelBuilder
import com.powsybl.dynawaltz.builders.ModelConfigs
import com.powsybl.iidm.network.Network

import java.util.function.Consumer

/**
* Superclass for automaton and event groovy extensions
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
abstract class AbstractPureDynamicGroovyExtension<T> implements GroovyExtension<T> {
@AutoService(EventModelGroovyExtension.class)
class DynaWaltzEventModelGroovyExtension implements EventModelGroovyExtension {

protected List<String> modelTags
private final List<EventBuilderConfig> builderConfigs

abstract protected ModelBuilder<T> createBuilder(Network network, Reporter reporter)
DynaWaltzEventModelGroovyExtension() {
builderConfigs = ModelConfigs.getInstance().getEventBuilderConfigs()
}

@Override
String getName() {
DynaWaltzProvider.NAME
}

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

@Override
void load(Binding binding, Consumer<T> consumer, Reporter reporter) {
modelTags.forEach {
binding.setVariable(it, { Closure<Void> closure ->
void load(Binding binding, Consumer<EventModel> consumer, Reporter reporter) {
builderConfigs.forEach {
binding.setVariable(it.tag, { Closure<Void> closure ->
def cloned = closure.clone()
ModelBuilder<T> builder = createBuilder(binding.getVariable("network") as Network,
Reporters.createModelBuilderReporter(reporter, it))
ModelBuilder<EventModel> builder = it.builderConstructor.createBuilder(
binding.getVariable("network") as Network,
Reporters.createModelBuilderReporter(reporter, it.tag))
cloned.delegate = builder
cloned()
builder.build()?.tap {
Expand All @@ -48,5 +55,4 @@ abstract class AbstractPureDynamicGroovyExtension<T> implements GroovyExtension<
})
}
}

}
Loading
Loading