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

Refactor model builders #401

Merged
merged 2 commits into from
Nov 6, 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
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public interface EventModelBuilderConstructor {
}

private final EventModelBuilderConstructor builderConstructor;
private final EventModelInfo eventModelInfo;
private final ModelInfo eventModelInfo;

public EventBuilderConfig(EventModelBuilderConstructor builderConstructor, EventModelInfo eventModelInfo) {
public EventBuilderConfig(EventModelBuilderConstructor builderConstructor, ModelInfo eventModelInfo) {
this.builderConstructor = builderConstructor;
this.eventModelInfo = eventModelInfo;
}
Expand All @@ -33,7 +33,7 @@ public EventModelBuilderConstructor getBuilderConstructor() {
return builderConstructor;
}

public EventModelInfo getEventModelInfo() {
public ModelInfo getEventModelInfo() {
return eventModelInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,30 @@

/**
* @param name Model name
* @param info Definition of the event model
* @param doc Definition of the event model
* @param version Dynawo version range where the model can be used
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
public record EventModelInfo(String name, String info, VersionInterval version) {
public record EventModelInfo(String name, String doc, VersionInterval version) implements ModelInfo {

public EventModelInfo(String name, String info) {
this(name, info, VersionInterval.createDefaultVersion());
}

@Override
public String lib() {
return name;
}

@Override
public String alias() {
return null;
}

/**
* Concatenation of name, doc and version bound
*/
public String formattedInfo() {
return String.format("%s: %s (%s)", name, info, version);
return String.format("%s: %s (%s)", name, doc, version);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public final class ModelConfigLoaderImpl implements ModelConfigLoader {
new BuilderConfig(SignalNGeneratorBuilder.CATEGORY, SignalNGeneratorBuilder::of, SignalNGeneratorBuilder::getSupportedModelInfos));

private static final Stream<EventBuilderConfig> EVENT_BUILDER_CONFIGS = Stream.of(
new EventBuilderConfig(EventActivePowerVariationBuilder::of, EventActivePowerVariationBuilder.getEventModelInfo()),
new EventBuilderConfig(EventDisconnectionBuilder::of, EventDisconnectionBuilder.getEventModelInfo()),
new EventBuilderConfig(NodeFaultEventBuilder::of, NodeFaultEventBuilder.getEventModelInfo()));
new EventBuilderConfig(EventActivePowerVariationBuilder::of, EventActivePowerVariationBuilder.getModelInfo()),
new EventBuilderConfig(EventDisconnectionBuilder::of, EventDisconnectionBuilder.getModelInfo()),
new EventBuilderConfig(NodeFaultEventBuilder::of, NodeFaultEventBuilder.getModelInfo()));

@Override
public String getModelConfigFileName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public static TapChangerAutomationSystemBuilder of(Network network, String model
return new TapChangerAutomationSystemBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public static TapChangerBlockingAutomationSystemBuilder of(Network network, Stri
return new TapChangerBlockingAutomationSystemBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public static UnderVoltageAutomationSystemBuilder of(Network network, String mod
return new UnderVoltageAutomationSystemBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public static DynamicOverloadManagementSystemBuilder of(Network network, String
return new DynamicOverloadManagementSystemBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public static DynamicTwoLevelsOverloadManagementSystemBuilder of(Network network
return new DynamicTwoLevelsOverloadManagementSystemBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public static PhaseShifterBlockingIAutomationSystemBuilder of(Network network, S
return new PhaseShifterBlockingIAutomationSystemBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public static PhaseShifterIAutomationSystemBuilder of(Network network, String mo
return new PhaseShifterIAutomationSystemBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public static PhaseShifterPAutomationSystemBuilder of(Network network, String mo
return new PhaseShifterPAutomationSystemBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public static InfiniteBusBuilder of(Network network, String modelName, ReportNod
return new InfiniteBusBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public static StandardBusBuilder of(Network network, String modelName, ReportNod
return new StandardBusBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.powsybl.dynawo.builders.BuilderEquipment;
import com.powsybl.dynawo.builders.BuilderReports;
import com.powsybl.dynawo.builders.EventModelInfo;
import com.powsybl.dynawo.builders.ModelInfo;
import com.powsybl.dynawo.commons.DynawoVersion;
import com.powsybl.iidm.network.Injection;
import com.powsybl.iidm.network.Network;
Expand All @@ -32,14 +33,14 @@ public static EventActivePowerVariationBuilder of(Network network, ReportNode re
return new EventActivePowerVariationBuilder(network, reportNode);
}

public static EventModelInfo getEventModelInfo() {
public static ModelInfo getModelInfo() {
return MODEL_INFO;
}

/**
* Returns the model info if usable with the given {@link DynawoVersion}
*/
public static EventModelInfo getEventModelInfo(DynawoVersion dynawoVersion) {
public static ModelInfo getModelInfo(DynawoVersion dynawoVersion) {
return MODEL_INFO.version().includes(dynawoVersion) ? MODEL_INFO : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.powsybl.dynawo.builders.BuilderEquipment;
import com.powsybl.dynawo.builders.BuilderReports;
import com.powsybl.dynawo.builders.EventModelInfo;
import com.powsybl.dynawo.builders.ModelInfo;
import com.powsybl.dynawo.commons.DynawoVersion;
import com.powsybl.iidm.network.*;

Expand Down Expand Up @@ -43,14 +44,14 @@ public static EventDisconnectionBuilder of(Network network, ReportNode reportNod
return new EventDisconnectionBuilder(network, reportNode);
}

public static EventModelInfo getEventModelInfo() {
public static ModelInfo getModelInfo() {
return MODEL_INFO;
}

/**
* Returns the model info if usable with the given {@link DynawoVersion}
*/
public static EventModelInfo getEventModelInfo(DynawoVersion dynawoVersion) {
public static ModelInfo getModelInfo(DynawoVersion dynawoVersion) {
return MODEL_INFO.version().includes(dynawoVersion) ? MODEL_INFO : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.powsybl.dynawo.builders.BuilderEquipment;
import com.powsybl.dynawo.builders.BuilderReports;
import com.powsybl.dynawo.builders.EventModelInfo;
import com.powsybl.dynawo.builders.ModelInfo;
import com.powsybl.dynawo.commons.DynawoVersion;
import com.powsybl.iidm.network.Bus;
import com.powsybl.iidm.network.IdentifiableType;
Expand All @@ -35,14 +36,14 @@ public static NodeFaultEventBuilder of(Network network, ReportNode reportNode) {
return new NodeFaultEventBuilder(network, reportNode);
}

public static EventModelInfo getEventModelInfo() {
public static ModelInfo getModelInfo() {
return MODEL_INFO;
}

/**
* Returns the model info if usable with the given {@link DynawoVersion}
*/
public static EventModelInfo getEventModelInfo(DynawoVersion dynawoVersion) {
public static ModelInfo getModelInfo(DynawoVersion dynawoVersion) {
return MODEL_INFO.version().includes(dynawoVersion) ? MODEL_INFO : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public static BaseGeneratorBuilder of(Network network, String modelName, ReportN
return new BaseGeneratorBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public static GridFormingConverterBuilder of(Network network, String modelName,
return new GridFormingConverterBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public static SignalNGeneratorBuilder of(Network network, String modelName, Repo
return new SignalNGeneratorBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public static SynchronizedGeneratorBuilder of(Network network, String modelName,
return new SynchronizedGeneratorBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public static SynchronousGeneratorBuilder of(Network network, String modelName,
return new SynchronousGeneratorBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public static WeccBuilder of(Network network, String modelName, ReportNode repor
return new WeccBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public static HvdcPBuilder of(Network network, String modelName, ReportNode repo
return new HvdcPBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public static HvdcVscBuilder of(Network network, String modelName, ReportNode re
return new HvdcVscBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public static LineBuilder of(Network network, String modelName, ReportNode repor
return new LineBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public static BaseLoadBuilder of(Network network, String modelName, ReportNode r
return new BaseLoadBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public static LoadOneTransformerBuilder of(Network network, String modelName, Re
return new LoadOneTransformerBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public static LoadOneTransformerTapChangerBuilder of(Network network, String mod
return new LoadOneTransformerTapChangerBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public static LoadTwoTransformersBuilder of(Network network, String modelName, R
return new LoadTwoTransformersBuilder(network, modelConfig, reportNode);
}

public static ModelInfo getDefaultModelInfo() {
return MODEL_CONFIGS.getDefaultModelConfig();
}

public static Collection<ModelInfo> getSupportedModelInfos() {
return MODEL_CONFIGS.getModelInfos();
}
Expand Down
Loading
Loading