Skip to content

Commit

Permalink
Refactor Generator Inheritance (#378)
Browse files Browse the repository at this point in the history
* Replace AbstractGenerator with BaseGenerator
* Remove GeneratorFictitious and replace it with BaseGenerator
* Change SynchronousGenerator extension with BaseGenerator

Signed-off-by: lisrte <[email protected]>
  • Loading branch information
Lisrte authored Sep 11, 2024
1 parent a4cea8d commit 9666e7f
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private static Stream<Arguments> provideEquipmentModelData() {
Arguments.of("/dynamicModels/loadTwoTransformersTapChangers.groovy", LoadTwoTransformersTapChangers.class, EurostagTutorialExample1Factory.create(), "LOAD", "LOAD", "LTT", "LoadTwoTransformersTapChangers"),
Arguments.of("/dynamicModels/infiniteBus.groovy", InfiniteBus.class, HvdcTestNetwork.createVsc(), "B1", "BBM_BUS", "b", "InfiniteBusWithVariations"),
Arguments.of("/dynamicModels/line.groovy", StandardLine.class, EurostagTutorialExample1Factory.create(), "NHV1_NHV2_1", "BBM_NHV1_NHV2_1", "LINE", "Line"),
Arguments.of("/dynamicModels/genFictitious.groovy", GeneratorFictitious.class, EurostagTutorialExample1Factory.create(), "GEN", "BBM_GEN", "GF", "GeneratorFictitious"),
Arguments.of("/dynamicModels/genFictitious.groovy", BaseGenerator.class, EurostagTutorialExample1Factory.create(), "GEN", "BBM_GEN", "GF", "GeneratorFictitious"),
Arguments.of("/dynamicModels/gen.groovy", SynchronousGenerator.class, EurostagTutorialExample1Factory.create(), "GEN", "BBM_GEN", "GSFWPR", "GeneratorSynchronousThreeWindings"),
Arguments.of("/dynamicModels/genControllable.groovy", SynchronousGeneratorControllable.class, EurostagTutorialExample1Factory.create(), "GEN", "BBM_GEN", "GSFWPR", "GeneratorSynchronousFourWindingsProportionalRegulations"),
Arguments.of("/dynamicModels/omegaGen.groovy", SynchronizedGenerator.class, EurostagTutorialExample1Factory.create(), "GEN", "BBM_GEN", "GPQ", "GeneratorPQ"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ default double getWeightGen(DynawoSimulationParameters dynawoSimulationParameter
return 0;
}

String getOmegaRefPuVarName();
default String getOmegaRefPuVarName() {
return "generator_omegaRefPu";
}

String getRunningVarName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
* @author Marcos de Miguel {@literal <demiguelm at aia.es>}
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
public abstract class AbstractGenerator extends AbstractEquipmentBlackBoxModel<Generator> implements GeneratorModel {
public class BaseGenerator extends AbstractEquipmentBlackBoxModel<Generator> implements GeneratorModel {

protected static final List<VarMapping> VAR_MAPPING = Arrays.asList(
new VarMapping("generator_PGenPu", "p"),
new VarMapping("generator_QGenPu", "q"),
new VarMapping("generator_state", "state"));

protected AbstractGenerator(String dynamicModelId, Generator generator, String parameterSetId, String lib) {
protected BaseGenerator(String dynamicModelId, Generator generator, String parameterSetId, String lib) {
super(dynamicModelId, parameterSetId, generator, lib);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ protected GeneratorFictitiousBuilder(Network network, ModelConfig modelConfig, R
}

@Override
public GeneratorFictitious build() {
return isInstantiable() ? new GeneratorFictitious(dynamicModelId, getEquipment(), parameterSetId, modelConfig.lib()) : null;
public BaseGenerator build() {
return isInstantiable() ? new BaseGenerator(dynamicModelId, getEquipment(), parameterSetId, modelConfig.lib()) : null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
public class SignalNGenerator extends AbstractGenerator implements SignalNModel {
public class SignalNGenerator extends BaseGenerator implements SignalNModel {

protected SignalNGenerator(String dynamicModelId, Generator generator, String parameterSetId, String lib) {
super(dynamicModelId, generator, parameterSetId, lib);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @author Dimitri Baudrier {@literal <dimitri.baudrier at rte-france.com>}
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
public class SynchronizedGenerator extends AbstractGenerator implements FrequencySynchronizedModel {
public class SynchronizedGenerator extends BaseGenerator implements FrequencySynchronizedModel {

protected SynchronizedGenerator(String dynamicModelId, Generator generator, String parameterSetId, String generatorLib) {
super(dynamicModelId, generator, parameterSetId, generatorLib);
Expand All @@ -33,18 +33,6 @@ public List<VarConnection> getOmegaRefVarConnections() {
);
}

@Override
public List<VarConnection> getSetPointVarConnections() {
return List.of(
new VarConnection("setPoint_setPoint", getOmegaRefPuVarName())
);
}

@Override
public String getOmegaRefPuVarName() {
return "generator_omegaRefPu";
}

@Override
public Bus getConnectableBus() {
return BusUtils.getConnectableBus(equipment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import com.powsybl.dynawo.DynawoSimulationParameters;
import com.powsybl.dynawo.models.VarConnection;
import com.powsybl.dynawo.models.frequencysynchronizers.FrequencySynchronizedModel;
import com.powsybl.dynawo.models.utils.BusUtils;
import com.powsybl.iidm.network.Bus;
import com.powsybl.iidm.network.Generator;

import java.util.Arrays;
Expand All @@ -17,7 +20,9 @@
/**
* @author Florian Dupuy {@literal <florian.dupuy at rte-france.com>}
*/
public class SynchronousGenerator extends SynchronizedGenerator {
public class SynchronousGenerator extends BaseGenerator implements FrequencySynchronizedModel {

private static final String OMEGA_PU_VAR_NAME = "generator_omegaPu";

private final EnumGeneratorComponent generatorComponent;

Expand All @@ -31,14 +36,10 @@ public String getTerminalVarName() {
return generatorComponent.getTerminalVarName();
}

public String getOmegaPuVarName() {
return "generator_omegaPu";
}

@Override
public List<VarConnection> getOmegaRefVarConnections() {
return Arrays.asList(
new VarConnection("omega_grp_@INDEX@", getOmegaPuVarName()),
new VarConnection("omega_grp_@INDEX@", OMEGA_PU_VAR_NAME),
new VarConnection("omegaRef_grp_@INDEX@", getOmegaRefPuVarName()),
new VarConnection("running_grp_@INDEX@", getRunningVarName())
);
Expand All @@ -50,4 +51,9 @@ public double getWeightGen(DynawoSimulationParameters dynawoSimulationParameters
double sNom = dynawoSimulationParameters.getModelParameters(getParameterSetId()).getDouble("generator_SNom");
return h * sNom;
}

@Override
public Bus getConnectableBus() {
return BusUtils.getConnectableBus(equipment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.google.common.collect.Lists;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.dynamicsimulation.DynamicSimulationParameters;
import com.powsybl.dynawo.models.generators.AbstractGenerator;
import com.powsybl.dynawo.models.generators.BaseGenerator;
import com.powsybl.dynawo.models.generators.GeneratorFictitiousBuilder;
import com.powsybl.dynawo.models.loads.BaseLoadBuilder;
import com.powsybl.dynawo.models.transformers.TransformerFixedRatioBuilder;
Expand Down Expand Up @@ -85,7 +85,7 @@ public static class ModelsSimplifierSubstitution implements ModelsSubstitutionSi
@Override
public Function<BlackBoxModel, BlackBoxModel> getModelSubstitutionFunction(Network network, DynawoSimulationParameters dynawoSimulationParameters, ReportNode reportNode) {
return m -> {
if ("BBM_GEN".equalsIgnoreCase(m.getDynamicModelId()) && m instanceof AbstractGenerator gen) {
if ("BBM_GEN".equalsIgnoreCase(m.getDynamicModelId()) && m instanceof BaseGenerator gen) {
return GeneratorFictitiousBuilder.of(network)
.dynamicModelId("newModel")
.staticId(gen.getStaticId())
Expand Down

0 comments on commit 9666e7f

Please sign in to comment.