EurostagStepUpTransformerInserter { public static InsertionStatus insert(Generator hvGen, TG tg, IdDictionary auxDict, EurostagStepUpTransformerConfig config, StateBefore stateBefore) { Terminal hvT = hvGen.getTerminal(); VoltageLevel hvVl = hvT.getVoltageLevel(); Substation s = hvVl.getSubstation(); Network n = s.getNetwork(); double hvNomV = hvVl.getNominalV(); Bus hvGenBus = hvT.getBusView().getBus(); Bus hvGenConnectableBus = hvT.getBusBreakerView().getConnectableBus(); if (hvGenConnectableBus == null) { throw new RuntimeException("Generator " + hvGen.getId() + " is not connectable"); } if (hvNomV < 25) { LOGGER.warn("skipping generator '{}' ('{}') connected to low level voltage '{}': its nominal voltage {} is lower than 25.0 so it is guessed that it is the low-voltage end of a step-up transformer", hvGen.getId(), tg.fileName, hvVl.getId(), hvNomV); return InsertionStatus.ALREADY_DONE; } float vbase1 = tg.f1.vbase; float vbase2 = tg.f2.vbase; float vbaseHvBdd = Math.max(vbase1, vbase2); float vbaseLvBdd = Math.min(vbase1, vbase2); if (hvNomV != vbaseHvBdd) { LOGGER.warn("Hight nominal voltage ({}) of step up transformer is inconsistent with the one ({}) of its generator '{}'", vbaseHvBdd, hvNomV, hvGen.getId()); return InsertionStatus.DYNAMIC_DATA_ERROR; } LOGGER.trace("Adding step up transformer to generator '{}' ('{}')", hvGen.getId(), tg.fileName); VoltageLevel lvVl = s.newVoltageLevel() .setId(hvGen.getId() + "_VL") .setNominalV(vbaseLvBdd) .setTopologyKind(TopologyKind.BUS_BREAKER) .add(); LOGGER.trace("Creating voltage level '{}' in substation '{}'", lvVl.getId(), s.getId()); String lvBusId = vbase1 > vbase2 ? tg.t4x.name2 : tg.t4x.name1; if (lvBusId.equals(tg.fileName)) { lvBusId = lvBusId + "_bus"; } Bus lvBus = lvVl.getBusBreakerView().newBus() .setId(lvBusId) .add(); LOGGER.trace("Creating bus '{}' in voltage level '{}'", lvBusId, lvVl.getId()); TwoWindingsTransformer twt = createTransformer(tg, hvGen, lvVl, lvBus, vbaseHvBdd, vbaseLvBdd, config); TransformerModel transformerModel = new TransformerModel(SV.getR(twt), SV.getX(twt), SV.getG(twt), SV.getB(twt), SV.getRatio(twt)); PowerFlow lvAuxPf = new PowerFlow(0, 0); PowerFlow hvAuxPf = new PowerFlow(0, 0); createAux(tg, auxDict, n, lvVl, lvBusId, hvVl, hvGen, hvGenConnectableBus, lvAuxPf, hvAuxPf, transformerModel, config); LOGGER.trace("Moving generator '{}' from '{}' to '{}'", hvGen.getId(), hvVl.getId(), lvVl.getId()); Function<StateVariable, StateVariable> fct = sv -> toLvGenPf(transformerModel, sv, hvAuxPf, lvAuxPf); StateVariable hvGenSv = new StateVariable(); moveGenerator(hvGen, hvGenSv, lvVl, lvBus, hvGenBus != null, fct, config, twt); stateBefore.injections.put(twt.getId(), new PowerFlow((float) (hvGenSv.p + hvAuxPf.p), (float) (hvGenSv.q + hvAuxPf.q))); return InsertionStatus.OK; } private  EurostagStepUpTransformerInserter(); static InsertionStatus insert(Generator hvGen, TG tg, IdDictionary auxDict, EurostagStepUpTransformerConfig config,
                                         StateBefore stateBefore); static InsertionStatus insert(Generator g, Path ddbFile, IdDictionary auxDict, EurostagStepUpTransformerConfig config, StateBefore stateBefore); static InsertionStatus insert(Generator g, EurostagDDB ddb, IdDictionary genDict, IdDictionary auxDict, EurostagStepUpTransformerConfig config, StateBefore stateBefore); static void insert(Network n, LoadFlowFactory loadFlowFactory, ComputationManager computationManager, List<Path> ddbDirs,
                              IdDictionary genDict, IdDictionary auxDict, List<String> statorVoltageLevels, EurostagStepUpTransformerConfig config); static void insert(Network n, LoadFlowFactory loadFlowFactory, ComputationManager computationManager, List<Path> ddbDirs, IdDictionary genDict, IdDictionary auxDict, List<String> statorVoltageLevels); static void insert(Network n, LoadFlowFactory loadFlowFactory, ComputationManager computationManager, Path ddbDir, Path genDictFile, Path auxDictFile, EurostagStepUpTransformerConfig config); static List<String> readStatorVoltageLevels(Path statorVoltageLevelsFile); static void insert(Network n, LoadFlowFactory loadFlowFactory, ComputationManager computationManager, Path ddbDir, Path genDictFile, Path auxDictFile, Path statorVoltageLevelsFile, EurostagStepUpTransformerConfig config); static void insert(Network n, LoadFlowFactory loadFlowFactory, ComputationManager computationManager, Path ddbDir, Path genDictFile, Path auxDictFile); static void insert(Network n, LoadFlowFactory loadFlowFactory, ComputationManager computationManager, Path ddbDir, Path genDictFile, Path auxDictFile, Path statorVoltageLevelsFile);  }
@Test @Ignore public void test() { Generator g400 = n.getGenerator(GEN_400_ID); EurostagStepUpTransformerInserter.InsertionStatus status = EurostagStepUpTransformerInserter.insert(g400, tg, dict, new EurostagStepUpTransformerConfig(), new EurostagStepUpTransformerInserter.StateBefore()); Assert.assertTrue(status == EurostagStepUpTransformerInserter.InsertionStatus.OK); Generator g24 = n.getGenerator(GEN_400_ID); Assert.assertTrue(g400.getMinP() == g24.getMinP()); Assert.assertTrue(g400.getMaxP() == g24.getMaxP()); Assert.assertTrue(g400.getTargetP() == g24.getTargetP()); Assert.assertTrue(g24.getTargetV() == 23.223017f); Assert.assertTrue(g24.getTargetQ() == 195.01202f); Assert.assertTrue(g24.getReactiveLimits().getMinQ(220f) == -475.13937f); Assert.assertTrue(g24.getReactiveLimits().getMaxQ(220f) == 318.96487f); Assert.assertTrue(g24.getReactiveLimits().getMinQ(910f) == -433.98605f); Assert.assertTrue(g24.getReactiveLimits().getMaxQ(910f) == 427.53082f); }