Skip to content

Commit

Permalink
Merge branch 'main' into add_readthedocs
Browse files Browse the repository at this point in the history
  • Loading branch information
olperr1 authored Jun 25, 2024
2 parents b34249b + 62865d6 commit fd74e5e
Show file tree
Hide file tree
Showing 48 changed files with 1,159 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
public abstract class AbstractEquipmentModelBuilder<T extends Identifiable<?>, R extends AbstractEquipmentModelBuilder<T, R>> extends AbstractDynamicModelBuilder implements EquipmentModelBuilder<R> {
public abstract class AbstractEquipmentModelBuilder<T extends Identifiable<?>, R extends AbstractEquipmentModelBuilder<T, R>> extends AbstractDynamicModelBuilder implements EquipmentModelBuilder<T, R> {

protected String dynamicModelId;
protected String parameterSetId;
Expand All @@ -38,21 +38,25 @@ protected AbstractEquipmentModelBuilder(Network network, ModelConfig modelConfig
this.builderEquipment = new BuilderEquipment<>(equipmentType);
}

@Override
public R staticId(String staticId) {
builderEquipment.addEquipment(staticId, this::findEquipment);
return self();
}

@Override
public R equipment(T equipment) {
builderEquipment.addEquipment(equipment, this::checkEquipment);
return self();
}

@Override
public R dynamicModelId(String dynamicModelId) {
this.dynamicModelId = dynamicModelId;
return self();
}

@Override
public R parameterSetId(String parameterSetId) {
this.parameterSetId = parameterSetId;
return self();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ public interface ModelBuilderConstructor {
ModelBuilder<DynamicModel> createBuilder(Network network, String lib, ReportNode reportNode);
}

private final String category;
private final ModelBuilderConstructor builderConstructor;
private final Supplier<Collection<String>> libsSupplier;

public BuilderConfig(ModelBuilderConstructor builderConstructor, Supplier<Collection<String>> libsSupplier) {
public BuilderConfig(String category, ModelBuilderConstructor builderConstructor, Supplier<Collection<String>> libsSupplier) {
this.category = category;
this.builderConstructor = builderConstructor;
this.libsSupplier = libsSupplier;
}

public String getCategory() {
return category;
}

public ModelBuilderConstructor getBuilderConstructor() {
return builderConstructor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ public void addEquipments(String[] staticIds, Function<String, T> equipmentsSupp
}

public void addEquipments(Iterable<String> staticIds, Function<String, T> equipmentsSupplier) {
staticIds.forEach(id -> {
T equipment = equipmentsSupplier.apply(id);
if (equipment != null) {
equipments.add(equipment);
} else {
missingEquipmentIds.add(id);
}
});
staticIds.forEach(id -> addEquipment(id, equipmentsSupplier));
}

public void addEquipment(String staticId, Function<String, T> equipmentsSupplier) {
T equipment = equipmentsSupplier.apply(staticId);
if (equipment != null) {
equipments.add(equipment);
} else {
missingEquipmentIds.add(staticId);
}
}

public boolean checkEquipmentData(ReportNode reportNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public final class BuilderReports {
private BuilderReports() {
}

public static void reportBuilderNotFound(ReportNode reportNode, String lib) {
reportNode.newReportNode()
.withMessageTemplate("builderNotFound", "No builder found for ${lib}")
.withUntypedValue("lib", lib)
.withSeverity(TypedValue.INFO_SEVERITY)
.add();
}

public static void reportLibNotFound(ReportNode reportNode, String builderName, String lib) {
reportNode.newReportNode()
.withMessageTemplate("libNotFound", "Library ${lib} not found for ${builderName}")
Expand All @@ -40,7 +48,7 @@ public static void reportModelInstantiation(ReportNode reportNode, String dynami

public static void reportModelInstantiationFailure(ReportNode reportNode, String dynamicId) {
reportNode.newReportNode()
.withMessageTemplate("modelInstantiation", "Model ${dynamicId} cannot be instantiated")
.withMessageTemplate("modelInstantiationError", "Model ${dynamicId} cannot be instantiated")
.withUntypedValue("dynamicId", dynamicId)
.withSeverity(TypedValue.WARN_SEVERITY)
.add();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
package com.powsybl.dynawaltz.builders;

import com.powsybl.dynamicsimulation.DynamicModel;
import com.powsybl.iidm.network.Identifiable;

/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
*/
public interface EquipmentModelBuilder<R extends EquipmentModelBuilder<R>> extends ModelBuilder<DynamicModel> {
public interface EquipmentModelBuilder<T extends Identifiable<?>, R extends EquipmentModelBuilder<T, R>> extends ModelBuilder<DynamicModel> {

R staticId(String staticId);

R equipment(T equipment);

R dynamicModelId(String dynamicModelId);

R parameterSetId(String parameterSetId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,30 @@ public final class ModelConfigLoaderImpl implements ModelConfigLoader {
private static final String MODEL_CONFIG_FILENAME = "models.json";

private static final Stream<BuilderConfig> BUILDER_CONFIGS = Stream.of(
new BuilderConfig(DynamicOverloadManagementSystemBuilder::of, DynamicOverloadManagementSystemBuilder::getSupportedLibs),
new BuilderConfig(DynamicTwoLevelsOverloadManagementSystemBuilder::of, DynamicTwoLevelsOverloadManagementSystemBuilder::getSupportedLibs),
new BuilderConfig(TapChangerAutomationSystemBuilder::of, TapChangerAutomationSystemBuilder::getSupportedLibs),
new BuilderConfig(TapChangerBlockingAutomationSystemBuilder::of, TapChangerBlockingAutomationSystemBuilder::getSupportedLibs),
new BuilderConfig(UnderVoltageAutomationSystemBuilder::of, UnderVoltageAutomationSystemBuilder::getSupportedLibs),
new BuilderConfig(PhaseShifterPAutomationSystemBuilder::of, PhaseShifterPAutomationSystemBuilder::getSupportedLibs),
new BuilderConfig(PhaseShifterIAutomationSystemBuilder::of, PhaseShifterIAutomationSystemBuilder::getSupportedLibs),
new BuilderConfig(StandardBusBuilder::of, StandardBusBuilder::getSupportedLibs),
new BuilderConfig(InfiniteBusBuilder::of, InfiniteBusBuilder::getSupportedLibs),
new BuilderConfig(TransformerFixedRatioBuilder::of, TransformerFixedRatioBuilder::getSupportedLibs),
new BuilderConfig(LineBuilder::of, LineBuilder::getSupportedLibs),
new BuilderConfig(HvdcVscBuilder::of, HvdcVscBuilder::getSupportedLibs),
new BuilderConfig(HvdcPBuilder::of, HvdcPBuilder::getSupportedLibs),
new BuilderConfig(BaseLoadBuilder::of, BaseLoadBuilder::getSupportedLibs),
new BuilderConfig(LoadOneTransformerBuilder::of, LoadOneTransformerBuilder::getSupportedLibs),
new BuilderConfig(LoadOneTransformerTapChangerBuilder::of, LoadOneTransformerTapChangerBuilder::getSupportedLibs),
new BuilderConfig(LoadTwoTransformersBuilder::of, LoadTwoTransformersBuilder::getSupportedLibs),
new BuilderConfig(LoadTwoTransformersTapChangersBuilder::of, LoadTwoTransformersTapChangersBuilder::getSupportedLibs),
new BuilderConfig(BaseStaticVarCompensatorBuilder::of, BaseStaticVarCompensatorBuilder::getSupportedLibs),
new BuilderConfig(GeneratorFictitiousBuilder::of, GeneratorFictitiousBuilder::getSupportedLibs),
new BuilderConfig(SynchronizedGeneratorBuilder::of, SynchronizedGeneratorBuilder::getSupportedLibs),
new BuilderConfig(SynchronousGeneratorBuilder::of, SynchronousGeneratorBuilder::getSupportedLibs),
new BuilderConfig(WeccBuilder::of, WeccBuilder::getSupportedLibs),
new BuilderConfig(GridFormingConverterBuilder::of, GridFormingConverterBuilder::getSupportedLibs),
new BuilderConfig(GeneratorFictitiousBuilder::of, GeneratorFictitiousBuilder::getSupportedLibs));
new BuilderConfig(DynamicOverloadManagementSystemBuilder.CATEGORY, DynamicOverloadManagementSystemBuilder::of, DynamicOverloadManagementSystemBuilder::getSupportedLibs),
new BuilderConfig(DynamicTwoLevelsOverloadManagementSystemBuilder.CATEGORY, DynamicTwoLevelsOverloadManagementSystemBuilder::of, DynamicTwoLevelsOverloadManagementSystemBuilder::getSupportedLibs),
new BuilderConfig(TapChangerAutomationSystemBuilder.CATEGORY, TapChangerAutomationSystemBuilder::of, TapChangerAutomationSystemBuilder::getSupportedLibs),
new BuilderConfig(TapChangerBlockingAutomationSystemBuilder.CATEGORY, TapChangerBlockingAutomationSystemBuilder::of, TapChangerBlockingAutomationSystemBuilder::getSupportedLibs),
new BuilderConfig(UnderVoltageAutomationSystemBuilder.CATEGORY, UnderVoltageAutomationSystemBuilder::of, UnderVoltageAutomationSystemBuilder::getSupportedLibs),
new BuilderConfig(PhaseShifterPAutomationSystemBuilder.CATEGORY, PhaseShifterPAutomationSystemBuilder::of, PhaseShifterPAutomationSystemBuilder::getSupportedLibs),
new BuilderConfig(PhaseShifterIAutomationSystemBuilder.CATEGORY, PhaseShifterIAutomationSystemBuilder::of, PhaseShifterIAutomationSystemBuilder::getSupportedLibs),
new BuilderConfig(StandardBusBuilder.CATEGORY, StandardBusBuilder::of, StandardBusBuilder::getSupportedLibs),
new BuilderConfig(InfiniteBusBuilder.CATEGORY, InfiniteBusBuilder::of, InfiniteBusBuilder::getSupportedLibs),
new BuilderConfig(TransformerFixedRatioBuilder.CATEGORY, TransformerFixedRatioBuilder::of, TransformerFixedRatioBuilder::getSupportedLibs),
new BuilderConfig(LineBuilder.CATEGORY, LineBuilder::of, LineBuilder::getSupportedLibs),
new BuilderConfig(HvdcVscBuilder.CATEGORY, HvdcVscBuilder::of, HvdcVscBuilder::getSupportedLibs),
new BuilderConfig(HvdcPBuilder.CATEGORY, HvdcPBuilder::of, HvdcPBuilder::getSupportedLibs),
new BuilderConfig(BaseLoadBuilder.CATEGORY, BaseLoadBuilder::of, BaseLoadBuilder::getSupportedLibs),
new BuilderConfig(LoadOneTransformerBuilder.CATEGORY, LoadOneTransformerBuilder::of, LoadOneTransformerBuilder::getSupportedLibs),
new BuilderConfig(LoadOneTransformerTapChangerBuilder.CATEGORY, LoadOneTransformerTapChangerBuilder::of, LoadOneTransformerTapChangerBuilder::getSupportedLibs),
new BuilderConfig(LoadTwoTransformersBuilder.CATEGORY, LoadTwoTransformersBuilder::of, LoadTwoTransformersBuilder::getSupportedLibs),
new BuilderConfig(LoadTwoTransformersTapChangersBuilder.CATEGORY, LoadTwoTransformersTapChangersBuilder::of, LoadTwoTransformersTapChangersBuilder::getSupportedLibs),
new BuilderConfig(BaseStaticVarCompensatorBuilder.CATEGORY, BaseStaticVarCompensatorBuilder::of, BaseStaticVarCompensatorBuilder::getSupportedLibs),
new BuilderConfig(GeneratorFictitiousBuilder.CATEGORY, GeneratorFictitiousBuilder::of, GeneratorFictitiousBuilder::getSupportedLibs),
new BuilderConfig(SynchronizedGeneratorBuilder.CATEGORY, SynchronizedGeneratorBuilder::of, SynchronizedGeneratorBuilder::getSupportedLibs),
new BuilderConfig(SynchronousGeneratorBuilder.CATEGORY, SynchronousGeneratorBuilder::of, SynchronousGeneratorBuilder::getSupportedLibs),
new BuilderConfig(WeccBuilder.CATEGORY, WeccBuilder::of, WeccBuilder::getSupportedLibs),
new BuilderConfig(GridFormingConverterBuilder.CATEGORY, GridFormingConverterBuilder::of, GridFormingConverterBuilder::getSupportedLibs));

@Override
public String getModelConfigFileName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
package com.powsybl.dynawaltz.builders;

import com.google.common.collect.Lists;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.dynamicsimulation.DynamicModel;
import com.powsybl.dynamicsimulation.EventModel;
import com.powsybl.dynawaltz.models.events.EventActivePowerVariationBuilder;
import com.powsybl.dynawaltz.models.events.EventDisconnectionBuilder;
import com.powsybl.dynawaltz.models.events.NodeFaultEventBuilder;
import com.powsybl.iidm.network.Network;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.stream.Collectors;

/**
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>}
Expand All @@ -25,13 +30,17 @@ public final class ModelConfigsHandler {
private static final ModelConfigsHandler INSTANCE = new ModelConfigsHandler();

private final Map<String, ModelConfigs> modelConfigsCat = new HashMap<>();

private final List<BuilderConfig> builderConfigs;
private final Map<String, BuilderConfig.ModelBuilderConstructor> builderConstructorByName = new HashMap<>();

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 final Map<String, EventBuilderConfig.EventModelBuilderConstructor> eventBuilderConstructorByName =
eventBuilderConfigs.stream().collect(Collectors.toMap(EventBuilderConfig::getTag, EventBuilderConfig::getBuilderConstructor));

private ModelConfigsHandler() {
List<ModelConfigLoader> modelConfigLoaders = Lists.newArrayList(ServiceLoader.load(ModelConfigLoader.class));
modelConfigLoaders.forEach(l -> l.loadModelConfigs().forEach(
Expand All @@ -41,6 +50,8 @@ private ModelConfigsHandler() {
})
));
builderConfigs = modelConfigLoaders.stream().flatMap(ModelConfigLoader::loadBuilderConfigs).toList();
builderConfigs.forEach(bc -> modelConfigsCat.get(bc.getCategory()).getSupportedLibs()
.forEach(lib -> builderConstructorByName.put(lib, bc.getBuilderConstructor())));
}

public static ModelConfigsHandler getInstance() {
Expand All @@ -58,4 +69,22 @@ public List<BuilderConfig> getBuilderConfigs() {
public List<EventBuilderConfig> getEventBuilderConfigs() {
return eventBuilderConfigs;
}

public ModelBuilder<DynamicModel> getModelBuilder(Network network, String modelName, ReportNode reportNode) {
BuilderConfig.ModelBuilderConstructor constructor = builderConstructorByName.get(modelName);
if (constructor == null) {
BuilderReports.reportBuilderNotFound(reportNode, modelName);
return null;
}
return constructor.createBuilder(network, modelName, reportNode);
}

public ModelBuilder<EventModel> getEventModelBuilder(Network network, String modelName, ReportNode reportNode) {
EventBuilderConfig.EventModelBuilderConstructor constructor = eventBuilderConstructorByName.get(modelName);
if (constructor == null) {
BuilderReports.reportBuilderNotFound(reportNode, modelName);
return null;
}
return constructor.createBuilder(network, reportNode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
public class TapChangerAutomationSystemBuilder extends AbstractAutomationSystemModelBuilder<TapChangerAutomationSystemBuilder> {

private static final String CATEGORY = "tapChangers";
public static final String CATEGORY = "TAP_CHANGER";
private static final ModelConfigs MODEL_CONFIGS = ModelConfigsHandler.getInstance().getModelConfigs(CATEGORY);

protected final BuilderEquipment<Load> load;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
public class TapChangerBlockingAutomationSystemBuilder extends AbstractAutomationSystemModelBuilder<TapChangerBlockingAutomationSystemBuilder> {

private static final String CATEGORY = "tcbs";
public static final String CATEGORY = "TAP_CHANGER_BLOCKING";
private static final ModelConfigs MODEL_CONFIGS = ModelConfigsHandler.getInstance().getModelConfigs(CATEGORY);
private static final String TAP_CHANGER_TYPE = IdentifiableType.TWO_WINDINGS_TRANSFORMER + "/" + IdentifiableType.LOAD;
private static final String U_MEASUREMENTS_FIELD = "uMeasurements";
Expand Down Expand Up @@ -60,6 +60,11 @@ protected TapChangerBlockingAutomationSystemBuilder(Network network, ModelConfig
uMeasurementPoints = new BuilderIdListEquipmentList<>(MEASUREMENT_POINT_TYPE, U_MEASUREMENTS_FIELD);
}

public TapChangerBlockingAutomationSystemBuilder transformers(String staticId) {
tapChangerEquipments.addEquipment(staticId, id -> this.getTapChangerEquipment(network, id));
return self();
}

public TapChangerBlockingAutomationSystemBuilder transformers(String... staticIds) {
tapChangerEquipments.addEquipments(staticIds, id -> this.getTapChangerEquipment(network, id));
return self();
Expand All @@ -75,6 +80,11 @@ private Identifiable<?> getTapChangerEquipment(Network network, String staticId)
return tapChangerEquipment != null ? tapChangerEquipment : network.getLoad(staticId);
}

public TapChangerBlockingAutomationSystemBuilder uMeasurements(String staticId) {
uMeasurementPoints.addEquipment(staticId, id -> BuildersUtil.getActionConnectionPoint(network, id));
return self();
}

public TapChangerBlockingAutomationSystemBuilder uMeasurements(String... staticIds) {
uMeasurementPoints.addEquipments(staticIds, id -> BuildersUtil.getActionConnectionPoint(network, id));
return self();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
public class UnderVoltageAutomationSystemBuilder extends AbstractAutomationSystemModelBuilder<UnderVoltageAutomationSystemBuilder> {

private static final String CATEGORY = "underVoltages";
public static final String CATEGORY = "UNDER_VOLTAGE";
private static final ModelConfigs MODEL_CONFIGS = ModelConfigsHandler.getInstance().getModelConfigs(CATEGORY);

protected final BuilderEquipment<Generator> generator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
public class DynamicOverloadManagementSystemBuilder extends AbstractOverloadManagementSystemBuilder<DynamicOverloadManagementSystemBuilder> {

private static final String CATEGORY = "overloadManagements";
public static final String CATEGORY = "OVERLOAD_MANAGEMENT";
private static final ModelConfigs MODEL_CONFIGS = ModelConfigsHandler.getInstance().getModelConfigs(CATEGORY);

public static DynamicOverloadManagementSystemBuilder of(Network network) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
public class DynamicTwoLevelsOverloadManagementSystemBuilder extends AbstractOverloadManagementSystemBuilder<DynamicTwoLevelsOverloadManagementSystemBuilder> {

private static final String CATEGORY = "twoLevelsOverloadManagements";
public static final String CATEGORY = "TWO_LEVEL_OVERLOAD_MANAGEMENT";
private static final ModelConfigs MODEL_CONFIGS = ModelConfigsHandler.getInstance().getModelConfigs(CATEGORY);

protected final BuilderEquipment<Branch<?>> iMeasurement2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
public class PhaseShifterIAutomationSystemBuilder extends AbstractPhaseShifterModelBuilder<PhaseShifterIAutomationSystemBuilder> {

private static final String CATEGORY = "phaseShiftersI";
public static final String CATEGORY = "PHASE_SHIFTER_I";
private static final ModelConfigs MODEL_CONFIGS = ModelConfigsHandler.getInstance().getModelConfigs(CATEGORY);

public static PhaseShifterIAutomationSystemBuilder of(Network network) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
public class PhaseShifterPAutomationSystemBuilder extends AbstractPhaseShifterModelBuilder<PhaseShifterPAutomationSystemBuilder> {

private static final String CATEGORY = "phaseShiftersP";
public static final String CATEGORY = "PHASE_SHIFTER_P";
private static final ModelConfigs MODEL_CONFIGS = ModelConfigsHandler.getInstance().getModelConfigs(CATEGORY);

public static PhaseShifterPAutomationSystemBuilder of(Network network) {
Expand Down
Loading

0 comments on commit fd74e5e

Please sign in to comment.