Skip to content

Commit

Permalink
Reworked two windings transformers tests using a small network instea…
Browse files Browse the repository at this point in the history
…d of a CGMES conformity one

Signed-off-by: Romain Courtier <[email protected]>
  • Loading branch information
rcourtier committed Nov 12, 2024
1 parent be08524 commit 54a0363
Show file tree
Hide file tree
Showing 5 changed files with 469 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,165 +46,134 @@ class TransformerConversionTest {
private static final String DIR = "/issues/transformers/";

@Test
void microGridBaseCaseBExfmr2ShuntDefault() {
Conversion.Config config = new Conversion.Config();
Network n = networkModel(CgmesConformity1Catalog.microGridBaseCaseBE(), config);
boolean ok = t2xCompareFlow(n, "e482b89a-fa84-4ea9-8e70-a83d44790957", -93.855301, -15.285520, 94.158074, 20.388478);
assertTrue(ok);
void t2wDefaultConfigTest() {
// Load network model with default config
Network n = networkModel(twoWindingTransformers());

// TRA is a transformer with a RatioTapChanger, PST is a phase shifter with PhaseTapChanger
assertTrue(t2xCompareFlow(n, "TRA", -93.855301, -15.285520, 94.158074, 20.388478));
assertTrue(t2xCompareFlow(n, "PST", 927.034612, -339.274880, -911.542354, 422.345850));
}

@Test
void microGridBaseCaseBExfmr2ShuntEnd1() {
void t2wShuntEnd1Test() {
// All shunt admittances to ground (g, b) at end1 (before transmission impedance)
Conversion.Config config = new Conversion.Config();
config.setXfmr2Shunt(Xfmr2ShuntInterpretationAlternative.END1);
Network n = networkModel(CgmesConformity1Catalog.microGridBaseCaseBE(), config);
boolean ok = t2xCompareFlow(n, "e482b89a-fa84-4ea9-8e70-a83d44790957", -93.855301, -15.285520, 94.158074, 20.388478);
assertTrue(ok);
Network n = networkModel(twoWindingTransformers(), config);

assertTrue(t2xCompareFlow(n, "TRA", -93.855301, -15.285520, 94.158074, 20.388478));
}

@Test
void microGridBaseCaseBExfmr2ShuntEnd2() {
void t2wShuntEnd2Test() {
// All shunt admittances to ground (g, b) at end2 (after transmission impedance)
Conversion.Config config = new Conversion.Config();
config.setXfmr2Shunt(Xfmr2ShuntInterpretationAlternative.END2);
// Same result as End1, IIDM model and LoadFlowParameters does not allow this configuration
Network n = networkModel(CgmesConformity1Catalog.microGridBaseCaseBE(), config);
boolean ok = t2xCompareFlow(n, "e482b89a-fa84-4ea9-8e70-a83d44790957", -93.855301, -15.285520, 94.158074, 20.388478);
assertTrue(ok);
Network n = networkModel(twoWindingTransformers(), config);

// Same result as end1, IIDM model and LoadFlowParameters does not allow this configuration
assertTrue(t2xCompareFlow(n, "TRA", -93.855301, -15.285520, 94.158074, 20.388478));
}

@Test
void microGridBaseCaseBExfmr2ShuntEnd1End2() {
void t2wShuntEnd1End2Test() {
// Shunt admittances to ground (g, b) at the end where they are defined in Cgmes model
Conversion.Config config = new Conversion.Config();
config.setXfmr2Shunt(Xfmr2ShuntInterpretationAlternative.END1_END2);
// Same result as End1, IIDM model and LoadFlowParameters does not allow this configuration
Network n = networkModel(CgmesConformity1Catalog.microGridBaseCaseBE(), config);
boolean ok = t2xCompareFlow(n, "e482b89a-fa84-4ea9-8e70-a83d44790957", -93.855301, -15.285520, 94.158074, 20.388478);
assertTrue(ok);
Network n = networkModel(twoWindingTransformers(), config);

// Same result as end1, IIDM model and LoadFlowParameters does not allow this configuration
assertTrue(t2xCompareFlow(n, "TRA", -93.855301, -15.285520, 94.158074, 20.388478));
}

@Test
void microGridBaseCaseBExfmr2ShuntSplit() {
void t2wShuntSplitTest() {
// Split shunt admittances to ground (g, b) between end1 and end2.
Conversion.Config config = new Conversion.Config();
config.setXfmr2Shunt(Xfmr2ShuntInterpretationAlternative.SPLIT);
config.setXfmr3Shunt(Xfmr3ShuntInterpretationAlternative.SPLIT);
Network n = networkModel(CgmesConformity1Catalog.microGridBaseCaseBE(), config);
boolean ok = t2xCompareFlow(n, "e482b89a-fa84-4ea9-8e70-a83d44790957", -93.970891, -15.839366, 94.275697, 20.952066);
assertTrue(ok);
}
Network n = networkModel(twoWindingTransformers(), config);

@Test
void microGridBaseCaseBExfmr2RatioPhaseDefault() {
Conversion.Config config = new Conversion.Config();
Network n = networkModel(CgmesConformity1Catalog.microGridBaseCaseBE(), config);
// RatioTapChanger
boolean ok = t2xCompareFlow(n, "e482b89a-fa84-4ea9-8e70-a83d44790957", -93.855301, -15.285520, 94.158074, 20.388478);
assertTrue(ok);
// PhaseTapChanger
ok = t2xCompareFlow(n, "a708c3bc-465d-4fe7-b6ef-6fa6408a62b0", 927.034612, -339.274880, -911.542354, 422.345850);
assertTrue(ok);
assertTrue(t2xCompareFlow(n, "TRA", -93.970891, -15.839366, 94.275697, 20.952066));
}

@Test
void microGridBaseCaseBExfmr2RatioPhaseEnd1() {
void t2wRatioPhaseEnd1Test() {
// All tapChangers (ratioTapChanger and phaseTapChanger) are considered at end1 (before transmission impedance)
Conversion.Config config = new Conversion.Config();
config.setXfmr2RatioPhase(Xfmr2RatioPhaseInterpretationAlternative.END1);
Network n = networkModel(CgmesConformity1Catalog.microGridBaseCaseBE(), config);
// RatioTapChanger
boolean ok = t2xCompareFlow(n, "e482b89a-fa84-4ea9-8e70-a83d44790957", -91.807775, 98.389959, 92.184500, -89.747219);
assertTrue(ok);
// PhaseTapChanger
ok = t2xCompareFlow(n, "a708c3bc-465d-4fe7-b6ef-6fa6408a62b0", 927.034612, -339.274880, -911.542354, 422.345850);
assertTrue(ok);
Network n = networkModel(twoWindingTransformers(), config);

assertTrue(t2xCompareFlow(n, "TRA", -91.807775, 98.389959, 92.184500, -89.747219));
assertTrue(t2xCompareFlow(n, "PST", 927.034612, -339.274880, -911.542354, 422.345850));
}

@Test
void microGridBaseCaseBExfmr2RatioPhaseEnd2() {
void t2wRatioPhaseEnd2Test() {
// All tapChangers (ratioTapChanger and phaseTapChanger) are considered at end2 (after transmission impedance)
Conversion.Config config = new Conversion.Config();
config.setXfmr2RatioPhase(Xfmr2RatioPhaseInterpretationAlternative.END2);
Network n = networkModel(CgmesConformity1Catalog.microGridBaseCaseBE(), config);
// RatioTapChanger
boolean ok = t2xCompareFlow(n, "e482b89a-fa84-4ea9-8e70-a83d44790957", -93.855301, -15.285520, 94.158074, 20.388478);
assertTrue(ok);
// PhaseTapChanger
ok = t2xCompareFlow(n, "a708c3bc-465d-4fe7-b6ef-6fa6408a62b0", 58.877292, -201.626411, -58.176878, 205.382102);
assertTrue(ok);
Network n = networkModel(twoWindingTransformers(), config);

assertTrue(t2xCompareFlow(n, "TRA", -93.855301, -15.285520, 94.158074, 20.388478));
assertTrue(t2xCompareFlow(n, "PST", 58.877292, -201.626411, -58.176878, 205.382102));
}

@Test
void microGridBaseCaseBExfmr2RatioPhaseEnd1End2() {
void t2wRatioPhaseEnd1End2Test() {
// TapChangers (ratioTapChanger and phaseTapChanger) are considered at the end where they are defined in CGMES
Conversion.Config config = new Conversion.Config();
config.setXfmr2RatioPhase(Xfmr2RatioPhaseInterpretationAlternative.END1_END2);
Network n = networkModel(CgmesConformity1Catalog.microGridBaseCaseBE(), config);
// RatioTapChanger
boolean ok = t2xCompareFlow(n, "e482b89a-fa84-4ea9-8e70-a83d44790957", -93.855301, -15.285520, 94.158074, 20.388478);
assertTrue(ok);
// PhaseTapChanger
ok = t2xCompareFlow(n, "a708c3bc-465d-4fe7-b6ef-6fa6408a62b0", 927.034612, -339.274880, -911.542354, 422.345850);
assertTrue(ok);
Network n = networkModel(twoWindingTransformers(), config);

assertTrue(t2xCompareFlow(n, "TRA", -93.855301, -15.285520, 94.158074, 20.388478));
assertTrue(t2xCompareFlow(n, "PST", 927.034612, -339.274880, -911.542354, 422.345850));
}

@Test
void microGridBaseCaseBExfmr2RatioPhaseX() {
void t2wRatioPhaseXTest() {
// If x1 == 0 all tapChangers (ratioTapChanger and phaseTapChanger) are considered at the end1
// otherwise they are considered at end2
Conversion.Config config = new Conversion.Config();
config.setXfmr2RatioPhase(Xfmr2RatioPhaseInterpretationAlternative.X);
Network n = networkModel(CgmesConformity1Catalog.microGridBaseCaseBE(), config);
// RatioTapChanger
boolean ok = t2xCompareFlow(n, "e482b89a-fa84-4ea9-8e70-a83d44790957", -93.855301, -15.285520, 94.158074, 20.388478);
assertTrue(ok);
// PhaseTapChanger
ok = t2xCompareFlow(n, "a708c3bc-465d-4fe7-b6ef-6fa6408a62b0", 58.877292, -201.626411, -58.176878, 205.382102);
assertTrue(ok);
}
Network n = networkModel(twoWindingTransformers(), config);

@Test
void microGridBaseCaseBExfmr2Ratio0Default() {
Conversion.Config config = new Conversion.Config();
Network n = networkModel(CgmesConformity1Catalog.microGridBaseCaseBE(), config);
// RatioTapChanger
boolean ok = t2xCompareFlow(n, "e482b89a-fa84-4ea9-8e70-a83d44790957", -93.855301, -15.285520, 94.158074, 20.388478);
assertTrue(ok);
// PhaseTapChanger
ok = t2xCompareFlow(n, "a708c3bc-465d-4fe7-b6ef-6fa6408a62b0", 927.034612, -339.274880, -911.542354, 422.345850);
assertTrue(ok);
assertTrue(t2xCompareFlow(n, "TRA", -93.855301, -15.285520, 94.158074, 20.388478));
assertTrue(t2xCompareFlow(n, "PST", 58.877292, -201.626411, -58.176878, 205.382102));
}

@Test
void microGridBaseCaseBExfmr2Ratio0End1() {
void t2wRatio0End1Test() {
// Structural ratio always at end1 (before transmission impedance)
Conversion.Config config = new Conversion.Config();
config.setXfmr2StructuralRatio(Xfmr2StructuralRatioInterpretationAlternative.END1);
Network n = networkModel(CgmesConformity1Catalog.microGridBaseCaseBE(), config);
// RatioTapChanger
boolean ok = t2xCompareFlow(n, "e482b89a-fa84-4ea9-8e70-a83d44790957", -0.849849, -0.138409, 0.852591, 0.184615);
assertTrue(ok);
// PhaseTapChanger
ok = t2xCompareFlow(n, "a708c3bc-465d-4fe7-b6ef-6fa6408a62b0", 70.106993, -25.657663, -68.935391, 31.939905);
assertTrue(ok);
Network n = networkModel(twoWindingTransformers(), config);

assertTrue(t2xCompareFlow(n, "TRA", -0.849849, -0.138409, 0.852591, 0.184615));
assertTrue(t2xCompareFlow(n, "PST", 70.106993, -25.657663, -68.935391, 31.939905));
}

@Test
void microGridBaseCaseBExfmr2Ratio0End2() {
void t2wRatio0End2Test() {
// Structural ratio always at end2 (after transmission impedance)
Conversion.Config config = new Conversion.Config();
config.setXfmr2StructuralRatio(Xfmr2StructuralRatioInterpretationAlternative.END2);
Network n = networkModel(CgmesConformity1Catalog.microGridBaseCaseBE(), config);
// RatioTapChanger
boolean ok = t2xCompareFlow(n, "e482b89a-fa84-4ea9-8e70-a83d44790957", -93.855301, -15.285520, 94.158074, 20.388478);
assertTrue(ok);
// PhaseTapChanger
ok = t2xCompareFlow(n, "a708c3bc-465d-4fe7-b6ef-6fa6408a62b0", 927.034612, -339.274880, -911.542354, 422.345850);
assertTrue(ok);
Network n = networkModel(twoWindingTransformers(), config);

assertTrue(t2xCompareFlow(n, "TRA", -93.855301, -15.285520, 94.158074, 20.388478));
assertTrue(t2xCompareFlow(n, "PST", 927.034612, -339.274880, -911.542354, 422.345850));
}

@Test
void microGridBaseCaseBExfmr2Ratio0X() {
void t2wRatio0XTest() {
// If x1 == 0 structural ratio at end1, otherwise at end2
Conversion.Config config = new Conversion.Config();
config.setXfmr2StructuralRatio(Xfmr2StructuralRatioInterpretationAlternative.X);
Network n = networkModel(CgmesConformity1Catalog.microGridBaseCaseBE(), config);
// RatioTapChanger
boolean ok = t2xCompareFlow(n, "e482b89a-fa84-4ea9-8e70-a83d44790957", -93.855301, -15.285520, 94.158074, 20.388478);
assertTrue(ok);
// PhaseTapChanger
ok = t2xCompareFlow(n, "a708c3bc-465d-4fe7-b6ef-6fa6408a62b0", 927.034612, -339.274880, -911.542354, 422.345850);
assertTrue(ok);
Network n = networkModel(twoWindingTransformers(), config);

assertTrue(t2xCompareFlow(n, "TRA", -93.855301, -15.285520, 94.158074, 20.388478));
assertTrue(t2xCompareFlow(n, "PST", 927.034612, -339.274880, -911.542354, 422.345850));
}

/**
Expand Down Expand Up @@ -339,7 +308,7 @@ void microGridBaseCaseBExfmr3Ratio0End3() {
@Test
void phaseAngleClockTest() {
// A 2w- and a 3w-transformer with non-null phase angle clock value on respectively 2nd and 3rd winding
Network n = networkModelWithPhaseAngleClock(phaseAngleClock("PhaseAngleClock_EQ.xml"));
Network n = networkModel(phaseAngleClock("PhaseAngleClock_EQ.xml"), new PhaseAngleClock());

// Phase angle clock values have been correctly read
assertEquals(5, n.getTwoWindingsTransformer("T2W").getExtension(TwoWindingsTransformerPhaseAngleClock.class).getPhaseAngleClock());
Expand All @@ -354,7 +323,7 @@ void phaseAngleClockTest() {
@Test
void phaseAngleClockAllZeroTest() {
// The same 2w- and a 3w-transformer as in phaseAngleClockTest() but with all phase angle clock equal to 0
Network n = networkModelWithPhaseAngleClock(phaseAngleClock("PhaseAngleClock_EQ_AllZero.xml"));
Network n = networkModel(phaseAngleClock("PhaseAngleClock_EQ_AllZero.xml"), new PhaseAngleClock());

// No phase angle clock extension has been created since all values are equal to 0
assertNull(n.getTwoWindingsTransformer("T2W").getExtension(TwoWindingsTransformerPhaseAngleClock.class));
Expand All @@ -368,7 +337,7 @@ void phaseAngleClockAllZeroTest() {
@Test
void phaseAngleClockAllNonZeroTest() {
// The same 2w- and a 3w-transformer as in phaseAngleClockTest() but with non-null phase angle clock value on all windings
Network n = networkModelWithPhaseAngleClock(phaseAngleClock("PhaseAngleClock_EQ_AllNonZero.xml"));
Network n = networkModel(phaseAngleClock("PhaseAngleClock_EQ_AllNonZero.xml"), new PhaseAngleClock());

// Non-null phase angle clock values on 1st winding are discarded, the other ones are correctly read
assertEquals(5, n.getTwoWindingsTransformer("T2W").getExtension(TwoWindingsTransformerPhaseAngleClock.class).getPhaseAngleClock());
Expand Down Expand Up @@ -436,20 +405,24 @@ private boolean t3xCompareFlow(Network n, String id, double p1, double q1, doubl
return ok;
}

private Network networkModelWithPhaseAngleClock(GridModelReference gridModelReference) {
private Network networkModel(GridModelReference gridModelReference) {
return networkModel(gridModelReference, new Conversion.Config(), Collections.emptyList());
}

private Network networkModel(GridModelReference gridModelReference, CgmesImportPostProcessor postProcessor) {
List<CgmesImportPostProcessor> postProcessors = new ArrayList<>();
postProcessors.add(new PhaseAngleClock());
postProcessors.add(postProcessor);

return networkModel(gridModelReference, new Conversion.Config(), postProcessors);
}

private Network networkModel(GridModelReference testGridModel, Conversion.Config config) {
return networkModel(testGridModel, config, Collections.emptyList());
private Network networkModel(GridModelReference gridModelReference, Conversion.Config config) {
return networkModel(gridModelReference, config, Collections.emptyList());
}

private Network networkModel(GridModelReference testGridModel, Conversion.Config config, List<CgmesImportPostProcessor> postProcessors) {
private Network networkModel(GridModelReference gridModelReference, Conversion.Config config, List<CgmesImportPostProcessor> postProcessors) {
config.setConvertSvInjections(true);
Network n = ConversionUtil.networkModel(testGridModel, config, postProcessors);
Network n = ConversionUtil.networkModel(gridModelReference, config, postProcessors);

double threshold = 0.01;
ValidationConfig vconfig = loadFlowValidationConfig(threshold);
Expand All @@ -459,6 +432,17 @@ private Network networkModel(GridModelReference testGridModel, Conversion.Config
return n;
}

private GridModelReferenceResources twoWindingTransformers() {
return new GridModelReferenceResources(
"TwoWindingsTransformers",
null,
new ResourceSet(DIR,
"TwoWindingsTransformers_EQ.xml",
"TwoWindingsTransformers_SSH.xml",
"TwoWindingsTransformers_SV.xml",
"TwoWindingsTransformers_TP.xml"));
}

private GridModelReferenceResources phaseAngleClock(String phaseAngleClockEQ) {
return new GridModelReferenceResources(
"PhaseAngleClock",
Expand Down
Loading

0 comments on commit 54a0363

Please sign in to comment.