Skip to content

Commit

Permalink
Add dynamic model ID to instantiation logs
Browse files Browse the repository at this point in the history
Signed-off-by: lisrte <[email protected]>
  • Loading branch information
Lisrte authored and flo-dup committed Nov 23, 2023
1 parent b55a090 commit aac0ec7
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,20 @@ final class Reporters {
"lib", lib)
}

static void reportModelInstantiation(Reporter reporter) {
static void reportModelInstantiation(Reporter reporter, String dynamicId) {
reporter.report(Report.builder()
.withKey("modelInstantiation")
.withDefaultMessage('Instantiation successful')
.withDefaultMessage('Model ${dynamicId} instantiation successful')
.withValue("dynamicId", dynamicId)
.withSeverity(TypedValue.TRACE_SEVERITY)
.build())
}

static void reportModelInstantiationFailure(Reporter reporter) {
static void reportModelInstantiationFailure(Reporter reporter, String dynamicId) {
reporter.report(Report.builder()
.withKey("modelInstantiation")
.withDefaultMessage('Model cannot be instantiated')
.withDefaultMessage('Model ${dynamicId} cannot be instantiated')
.withValue("dynamicId", dynamicId)
.withSeverity(TypedValue.WARN_SEVERITY)
.build())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ abstract class AbstractDynamicModelBuilder {

protected final boolean isInstantiable() {
checkData()
isInstantiable ? Reporters.reportModelInstantiation(reporter) : Reporters.reportModelInstantiationFailure(reporter)
isInstantiable ? Reporters.reportModelInstantiation(reporter, getModelId()) : Reporters.reportModelInstantiationFailure(reporter, getModelId())
isInstantiable
}

abstract protected String getModelId()
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ abstract class AbstractEquipmentModelBuilder<T extends Identifiable> extends Abs
dslEquipment.equipment
}

@Override
String getModelId() {
dynamicModelId ?: "unknownDynamicId"
}

@Override
abstract DynamicModel build()
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.powsybl.dynamicsimulation.EventModel
import com.powsybl.dynawaltz.dsl.DslEquipment
import com.powsybl.dynawaltz.dsl.ModelBuilder
import com.powsybl.dynawaltz.dsl.Reporters
import com.powsybl.dynawaltz.models.events.AbstractEvent
import com.powsybl.iidm.network.Identifiable
import com.powsybl.iidm.network.Network

Expand Down Expand Up @@ -51,6 +52,11 @@ abstract class AbstractEventModelBuilder<T extends Identifiable> extends Abstrac

abstract protected Identifiable findEquipment(String staticId)

@Override
String getModelId() {
AbstractEvent.generateEventId(tag + "_", dslEquipment.staticId ?: "unknownStaticId")
}

@Override
abstract EventModel build()
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ abstract class AbstractPureDynamicModelBuilder extends AbstractDynamicModelBuild
}
}

@Override
String getModelId() {
dynamicModelId ?: "unknownDynamicId"
}

@Override
abstract DynamicModel build()
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private static Stream<Arguments> provideWarningsModel() {
+ DSL model builder for LoadAlphaBeta
'staticId' field is not set
'dynamicModelId' field is not set, staticId (unknown staticId) will be used instead
Model cannot be instantiated
Model unknownDynamicId cannot be instantiated
"""),
Arguments.of("/warnings/missingParameterId.groovy", EurostagTutorialExample1Factory.create(),
"""
Expand All @@ -163,7 +163,7 @@ private static Stream<Arguments> provideWarningsModel() {
+ DSL model builder for LoadAlphaBeta
'parameterSetId' field is not set
'dynamicModelId' field is not set, staticId LOAD will be used instead
Model cannot be instantiated
Model LOAD cannot be instantiated
"""),
Arguments.of("/warnings/missingEquipment.groovy", EurostagTutorialExample1Factory.create(),
"""
Expand All @@ -172,79 +172,79 @@ private static Stream<Arguments> provideWarningsModel() {
+ DSL model builder for LoadAlphaBeta
'staticId' field value 'GEN' not found for equipment type(s) LOAD
'dynamicModelId' field is not set, staticId GEN will be used instead
Model cannot be instantiated
Model GEN cannot be instantiated
"""),
Arguments.of("/warnings/missingDangling.groovy", HvdcTestNetwork.createVsc(),
"""
+ DSL tests
+ Groovy Dynamic Models Supplier
+ DSL model builder for HvdcPVDangling
'dangling' field is not set
Model cannot be instantiated
Model BBM_HVDC_L cannot be instantiated
"""),
Arguments.of("/warnings/missingDanglingProperty.groovy", HvdcTestNetwork.createVsc(),
"""
+ DSL tests
+ Groovy Dynamic Models Supplier
+ DSL model builder for HvdcPV
'dangling' field is set but HvdcPV does not possess this option
Model cannot be instantiated
Model BBM_HVDC_L cannot be instantiated
"""),
Arguments.of("/warnings/underVoltageMissingGenerator.groovy", EurostagTutorialExample1Factory.create(),
"""
+ DSL tests
+ Groovy Dynamic Models Supplier
+ DSL model builder for UnderVoltage
'generator' field value 'NGEN' not found for equipment type(s) GENERATOR
Model cannot be instantiated
Model UV_GEN cannot be instantiated
"""),
Arguments.of("/warnings/phaseShifterMissingTransformer.groovy", EurostagTutorialExample1Factory.create(),
"""
+ DSL tests
+ Groovy Dynamic Models Supplier
+ DSL model builder for PhaseShifterI
'transformer' field value 'NGEN' not found for equipment type(s) TWO_WINDINGS_TRANSFORMER
Model cannot be instantiated
Model PS_NGEN_NHV1 cannot be instantiated
"""),
Arguments.of("/warnings/claMissingMeasurement.groovy", EurostagTutorialExample1Factory.create(),
"""
+ DSL tests
+ Groovy Dynamic Models Supplier
+ DSL model builder for CurrentLimitAutomaton
'iMeasurement' field value 'NGEN' not found for equipment type(s) Quadripole
Model cannot be instantiated
Model CLA_NGEN cannot be instantiated
"""),
Arguments.of("/warnings/claMissingMeasurementSide.groovy", EurostagTutorialExample1Factory.create(),
"""
+ DSL tests
+ Groovy Dynamic Models Supplier
+ DSL model builder for CurrentLimitAutomaton
'iMeasurementSide' field is not set
Model cannot be instantiated
Model CLA_NGEN cannot be instantiated
"""),
Arguments.of("/warnings/claMissingControlled.groovy", EurostagTutorialExample1Factory.create(),
"""
+ DSL tests
+ Groovy Dynamic Models Supplier
+ DSL model builder for CurrentLimitAutomaton
'controlledQuadripole' field value 'GEN' not found for equipment type(s) Quadripole
Model cannot be instantiated
Model CLA_NGEN cannot be instantiated
"""),
Arguments.of("/warnings/cla2MissingMeasurement2.groovy", EurostagTutorialExample1Factory.create(),
"""
+ DSL tests
+ Groovy Dynamic Models Supplier
+ DSL model builder for CurrentLimitAutomatonTwoLevels
'iMeasurement2' field value 'NGEN' not found for equipment type(s) Quadripole
Model cannot be instantiated
Model CLA_NGEN cannot be instantiated
"""),
Arguments.of("/warnings/cla2MissingMeasurementSide2.groovy", EurostagTutorialExample1Factory.create(),
"""
+ DSL tests
+ Groovy Dynamic Models Supplier
+ DSL model builder for CurrentLimitAutomatonTwoLevels
'iMeasurement2Side' field is not set
Model cannot be instantiated
Model CLA_NGEN cannot be instantiated
"""),
Arguments.of("/warnings/tapChangerMissingBus.groovy", EurostagTutorialExample1Factory.create(),
"""
Expand All @@ -253,7 +253,7 @@ private static Stream<Arguments> provideWarningsModel() {
+ DSL model builder for TapChangerBlockingAutomaton
'uMeasurements' field value 'LOAD' not found for equipment type(s) BUS
'uMeasurements' list is empty
Model cannot be instantiated
Model ZAB cannot be instantiated
"""),
Arguments.of("/warnings/tapChangerCompatible.groovy", EurostagTutorialExample1Factory.create(),
"""
Expand All @@ -262,7 +262,7 @@ private static Stream<Arguments> provideWarningsModel() {
+ DSL model builder for TapChangerBlockingAutomaton
'uMeasurements' field value 'GEN' not found for equipment type(s) LOAD/TWO_WINDINGS_TRANSFORMER
'transformers' list is empty
Model cannot be instantiated
Model ZAB cannot be instantiated
""")
);
}
Expand All @@ -274,14 +274,14 @@ private static Stream<Arguments> provideGenerator() {
+ DSL tests
+ Groovy Dynamic Models Supplier
+ DSL model builder for GeneratorSynchronousThreeWindings
Instantiation successful
Model BBM_GEN instantiation successful
"""),
Arguments.of("/dynamicModels/genTfo.groovy", SynchronousGenerator.class, EurostagTutorialExample1Factory.create(), "transformer_terminal1",
"""
+ DSL tests
+ Groovy Dynamic Models Supplier
+ DSL model builder for GeneratorSynchronousThreeWindingsPmConstVRNordicTfo
Instantiation successful
Model BBM_GEN instantiation successful
""")
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,23 @@ private static Stream<Arguments> provideWarningsModel() {
+ Groovy Event Models Supplier
+ DSL model builder for NodeFault
'staticId' field value 'GEN' not found for equipment type(s) BUS
Model cannot be instantiated
Model NodeFault_GEN cannot be instantiated
"""),
Arguments.of("/eventWarnings/missingStartTime.groovy", EurostagTutorialExample1Factory.create(),
"""
+ DSL tests
+ Groovy Event Models Supplier
+ DSL model builder for NodeFault
'startTime' field is not set
Model cannot be instantiated
Model NodeFault_NGEN cannot be instantiated
"""),
Arguments.of("/eventWarnings/missingNodeFaultParameters.groovy", EurostagTutorialExample1Factory.create(),
"""
+ DSL tests
+ Groovy Event Models Supplier
+ DSL model builder for NodeFault
faultTime should be strictly positive (0.0)
Model cannot be instantiated
Model NodeFault_NGEN cannot be instantiated
"""),
Arguments.of("/eventWarnings/missingAPVParameters.groovy", SvcTestCaseFactory.create(),
"""
Expand All @@ -109,23 +109,23 @@ faultTime should be strictly positive (0.0)
+ DSL model builder for Step
'staticId' field value 'SVC2' not found for equipment type(s) GENERATOR/LOAD
'deltaP' field is not set
Model cannot be instantiated
Model Step_SVC2 cannot be instantiated
"""),
Arguments.of("/eventWarnings/missingDisconnectionEquipment.groovy", EurostagTutorialExample1Factory.create(),
"""
+ DSL tests
+ Groovy Event Models Supplier
+ DSL model builder for Disconnect
'staticId' field value 'NGEN' not found for equipment type(s) Disconnectable equipment
Model cannot be instantiated
Model Disconnect_NGEN cannot be instantiated
"""),
Arguments.of("/eventWarnings/missingDisconnectionSide.groovy", EurostagTutorialExample1Factory.create(),
"""
+ DSL tests
+ Groovy Event Models Supplier
+ DSL model builder for Disconnect
'disconnectSide' field is set but GENERATOR GEN does not possess this option
Model cannot be instantiated
Model Disconnect_GEN cannot be instantiated
""")
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public abstract class AbstractEvent extends AbstractPureDynamicBlackBoxModel imp
private final double startTime;

protected AbstractEvent(Identifiable<?> equipment, double startTime, String eventPrefix) {
super(generateEventId(equipment.getId(), eventPrefix));
super(generateEventId(eventPrefix, equipment.getId()));
this.equipment = equipment;
this.startTime = startTime;
}

private static String generateEventId(String equipmentStaticId, String eventPrefix) {
public static String generateEventId(String eventPrefix, String equipmentStaticId) {
return eventPrefix + equipmentStaticId;
}

Expand Down

0 comments on commit aac0ec7

Please sign in to comment.