Skip to content

Commit

Permalink
Simplify synchronous generator models declaration (#146)
Browse files Browse the repository at this point in the history
* Synchronous generators were redundant.
* dynawaltz-dsl : dynamic allocation of synchronous generators

Signed-off-by: BAUDRIER Dimitri <dimitri.baudrier@rte-france.com>
  • Loading branch information
dimbdr authored Jan 4, 2023
1 parent 2885554 commit 00d9e7c
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 371 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package com.powsybl.dynawaltz.dsl.models.generators

import com.powsybl.dynawaltz.models.generators.GeneratorSynchronous

import java.util.function.Consumer

import com.google.auto.service.AutoService
Expand All @@ -18,7 +20,11 @@ import com.powsybl.dynawaltz.DynaWaltzProvider
/**
* @author Marcos de Miguel <demiguelm at aia.es>
*/
abstract class GeneratorModelGroovyExtension implements DynamicModelGroovyExtension {
@AutoService(DynamicModelGroovyExtension.class)
class GeneratorModelGroovyExtension implements DynamicModelGroovyExtension {

private static final String GENERATORS_CONFIG = "synchronous_generators.cfg";
private static final String SYNCHRONOUS_GENERATORS_LIBS = "synchronousGeneratorsLibs";

static class GeneratorModelSpec {
String dynamicModelId
Expand All @@ -41,5 +47,35 @@ abstract class GeneratorModelGroovyExtension implements DynamicModelGroovyExtens
String getName() {
return DynaWaltzProvider.NAME
}


void load(Binding binding, Consumer<DynamicModel> consumer) {
ConfigSlurper config = new ConfigSlurper()
def cfg = config.parse(this.getClass().getClassLoader().getResource(GENERATORS_CONFIG)).get(SYNCHRONOUS_GENERATORS_LIBS)
for (String gen : cfg.keySet()) {
binding.setVariable(gen, generatorClosure(consumer, gen))
}
}

def generatorClosure = {
Consumer<DynamicModel> consumer, String generator ->
{
Closure<Void> closure -> {
def cloned = closure.clone()
GeneratorModelSpec generatorModelSpec = new GeneratorModelSpec()

cloned.delegate = generatorModelSpec
cloned()

if (!generatorModelSpec.staticId) {SYNCHRONOUS_GENERATORS_LIBS
throw new DslException("'staticId' field is not set")
}
if (!generatorModelSpec.parameterSetId) {
throw new DslException("'parameterSetId' field is not set")
}

String dynamicModelId = generatorModelSpec.dynamicModelId ? generatorModelSpec.dynamicModelId : generatorModelSpec.staticId
consumer.accept(new GeneratorSynchronous(dynamicModelId, generatorModelSpec.staticId, generatorModelSpec.parameterSetId, generator))
}
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

7 changes: 7 additions & 0 deletions dynawaltz-dsl/src/main/resources/synchronous_generators.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
synchronousGeneratorsLibs {
GeneratorSynchronousFourWindings
GeneratorSynchronousFourWindingsProportionalRegulations
GeneratorSynchronousFourWindingsProportionalRegulationsStepPm
GeneratorSynchronousThreeWindings
GeneratorSynchronousThreeWindingsProportionalRegulations
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void tearDown() throws IOException {
public void test() {

List<DynamicModelGroovyExtension> extensions = GroovyExtension.find(DynamicModelGroovyExtension.class, DynaWaltzProvider.NAME);
assertEquals(10, extensions.size());
assertEquals(6, extensions.size());
extensions.forEach(this::validateExtension);

DynamicModelsSupplier supplier = new GroovyDynamicModelsSupplier(fileSystem.getPath("/dynamicModels.groovy"), extensions);
Expand Down Expand Up @@ -181,30 +181,8 @@ private void validateModel(DynamicModel dynamicModel) {
assertEquals(identifiable.getId(), blackBoxModel.getDynamicModelId());
assertEquals("LOT", blackBoxModel.getParameterSetId());
assertTrue(identifiable instanceof Load);
} else if (blackBoxModel instanceof GeneratorSynchronousThreeWindingsProportionalRegulations) {
Identifiable<?> identifiable = network.getIdentifiable(blackBoxModel.getStaticId().orElse(null));
assertEquals("BBM_" + identifiable.getId(), blackBoxModel.getDynamicModelId());
assertEquals("GSTWPR", blackBoxModel.getParameterSetId());
assertTrue(identifiable instanceof Generator);
} else if (blackBoxModel instanceof GeneratorSynchronousFourWindingsProportionalRegulations) {
Identifiable<?> identifiable = network.getIdentifiable(blackBoxModel.getStaticId().orElse(null));
assertEquals("BBM_" + identifiable.getId(), blackBoxModel.getDynamicModelId());
assertEquals("GSFWPR", blackBoxModel.getParameterSetId());
assertTrue(identifiable instanceof Generator);
} else if (blackBoxModel instanceof GeneratorSynchronousFourWindingsProportionalRegulationsStepPm) {
Identifiable<?> identifiable = network.getIdentifiable(blackBoxModel.getStaticId().orElse(null));
assertEquals("BBM_" + identifiable.getId(), blackBoxModel.getDynamicModelId());
assertEquals("GSFWPRSP", blackBoxModel.getParameterSetId());
assertTrue(identifiable instanceof Generator);
} else if (blackBoxModel instanceof GeneratorSynchronousThreeWindings) {
Identifiable<?> identifiable = network.getIdentifiable(blackBoxModel.getStaticId().orElse(null));
assertEquals("BBM_" + identifiable.getId(), blackBoxModel.getDynamicModelId());
assertEquals("GSTW", blackBoxModel.getParameterSetId());
} else if (blackBoxModel instanceof GeneratorSynchronousFourWindings) {
Identifiable<?> identifiable = network.getIdentifiable(blackBoxModel.getStaticId().orElse(null));
assertEquals("BBM_" + identifiable.getId(), blackBoxModel.getDynamicModelId());
assertEquals("GSFW", blackBoxModel.getParameterSetId());
assertTrue(identifiable instanceof Generator);
} else if (blackBoxModel instanceof GeneratorSynchronous) {
validateGeneratorSynchronous((GeneratorSynchronous) blackBoxModel);
} else if (blackBoxModel instanceof GeneratorFictitious) {
Identifiable<?> identifiable = network.getIdentifiable(blackBoxModel.getStaticId().orElse(null));
assertEquals("BBM_" + identifiable.getId(), blackBoxModel.getDynamicModelId());
Expand All @@ -222,4 +200,32 @@ private void validateModel(DynamicModel dynamicModel) {
assertTrue(identifiable instanceof Bus);
}
}

private void validateGeneratorSynchronous(GeneratorSynchronous generatorSynchronous) {
if (generatorSynchronous.getLib().equals("GeneratorSynchronousThreeWindingsProportionalRegulations")) {
Identifiable<?> identifiable = network.getIdentifiable(generatorSynchronous.getStaticId().orElse(null));
assertEquals("BBM_" + identifiable.getId(), generatorSynchronous.getDynamicModelId());
assertEquals("GSTWPR", generatorSynchronous.getParameterSetId());
assertTrue(identifiable instanceof Generator);
} else if (generatorSynchronous.getLib().equals("GeneratorSynchronousFourWindingsProportionalRegulations")) {
Identifiable<?> identifiable = network.getIdentifiable(generatorSynchronous.getStaticId().orElse(null));
assertEquals("BBM_" + identifiable.getId(), generatorSynchronous.getDynamicModelId());
assertEquals("GSFWPR", generatorSynchronous.getParameterSetId());
assertTrue(identifiable instanceof Generator);
} else if (generatorSynchronous.getLib().equals("GeneratorSynchronousFourWindingsProportionalRegulationsStepPm")) {
Identifiable<?> identifiable = network.getIdentifiable(generatorSynchronous.getStaticId().orElse(null));
assertEquals("BBM_" + identifiable.getId(), generatorSynchronous.getDynamicModelId());
assertEquals("GSFWPRSP", generatorSynchronous.getParameterSetId());
assertTrue(identifiable instanceof Generator);
} else if (generatorSynchronous.getLib().equals("GeneratorSynchronousThreeWindings")) {
Identifiable<?> identifiable = network.getIdentifiable(generatorSynchronous.getStaticId().orElse(null));
assertEquals("BBM_" + identifiable.getId(), generatorSynchronous.getDynamicModelId());
assertEquals("GSTW", generatorSynchronous.getParameterSetId());
} else if (generatorSynchronous.getLib().equals("GeneratorSynchronousFourWindings")) {
Identifiable<?> identifiable = network.getIdentifiable(generatorSynchronous.getStaticId().orElse(null));
assertEquals("BBM_" + identifiable.getId(), generatorSynchronous.getDynamicModelId());
assertEquals("GSFW", generatorSynchronous.getParameterSetId());
assertTrue(identifiable instanceof Generator);
}
}
}
Loading

0 comments on commit 00d9e7c

Please sign in to comment.