private int getBusNum(Bus bus) { return bus == null ? -1 : mapper.getInt(AmplSubset.BUS, bus.getId()); }
public static int getConnectableBusNum(StringToIntMapper<AmplSubset> mapper, Terminal t) { Bus bus = getConnectableBus(t); return bus == null ? -1 : mapper.getInt(AmplSubset.BUS, bus.getId()); }
public static int getBusNum(StringToIntMapper<AmplSubset> mapper, Terminal t) { Bus bus = getBus(t); return bus == null ? -1 : mapper.getInt(AmplSubset.BUS, bus.getId()); }
public static void writeActions(Collection<String> actionIds, DataSource dataSource, StringToIntMapper<AmplSubset> mapper, String title, AmplSubset amplSubset) { Objects.requireNonNull(actionIds); Objects.requireNonNull(dataSource); Objects.requireNonNull(mapper); Objects.requireNonNull(title); Objects.requireNonNull(amplSubset); try (Writer writer = new OutputStreamWriter(dataSource.newOutputStream(WCAConstants.ACTIONS_FILE_SUFFIX, WCAConstants.TXT_EXT, false), StandardCharsets.UTF_8); TableFormatter formatter = new AmplDatTableFormatter( writer, title, AmplConstants.INVALID_FLOAT_VALUE, true, AmplConstants.LOCALE, new Column("num"), new Column("id"))) { for (String actionId : actionIds) { int actionNum = mapper.getInt(amplSubset, actionId); formatter.writeCell(actionNum) .writeCell(actionId); } } catch (IOException e) { throw new RuntimeException(e); } }
public static void writeContingencies(Collection<Contingency> contingencies, DataSource dataSource, StringToIntMapper<AmplSubset> mapper) { Objects.requireNonNull(contingencies); Objects.requireNonNull(dataSource); Objects.requireNonNull(mapper); try (Writer writer = new OutputStreamWriter(dataSource.newOutputStream(WCAConstants.FAULTS_FILE_SUFFIX, WCAConstants.TXT_EXT, false), StandardCharsets.UTF_8); TableFormatter formatter = new AmplDatTableFormatter( writer, "Contingencies", AmplConstants.INVALID_FLOAT_VALUE, true, AmplConstants.LOCALE, new Column("num"), new Column("id"))) { for (Contingency contingency : contingencies) { int contingencyNum = mapper.getInt(AmplSubset.FAULT, contingency.getId()); formatter.writeCell(contingencyNum) .writeCell(contingency.getId()); } } catch (IOException e) { throw new RuntimeException(e); } }
private void writeTemporaryCurrentLimits(CurrentLimits limits, TableFormatter formatter, String branchId, boolean side1, String sideId) throws IOException { int branchNum = mapper.getInt(AmplSubset.BRANCH, branchId); for (TemporaryLimit tl : limits.getTemporaryLimits()) { String limitId = branchId + "_" + sideId + "_" + tl.getAcceptableDuration(); int limitNum = mapper.getInt(AmplSubset.TEMPORARY_CURRENT_LIMIT, limitId); formatter.writeCell(variantIndex) .writeCell(limitNum) .writeCell(branchNum) .writeCell(side1 ? 1 : 2) .writeCell(tl.getValue()) .writeCell(tl.getAcceptableDuration()) .writeCell(faultNum) .writeCell(actionNum); } }
String id = e.getKey(); Range<Float> range = e.getValue(); int num = mapper.getInt(AmplSubset.LOAD, id); formatter.writeCell(num) .writeCell(range.lowerEndpoint()) String id = e.getKey(); Range<Float> range = e.getValue(); int num = mapper.getInt(AmplSubset.LOAD, id); formatter.writeCell(num) .writeCell(range.lowerEndpoint()) String id = e.getKey(); Range<Float> range = e.getValue(); int num = mapper.getInt(AmplSubset.GENERATOR, id); formatter.writeCell(num) .writeCell(range.lowerEndpoint())
private void writeThreeWindingsTransformerMiddleBuses(AmplExportContext context, TableFormatter formatter) throws IOException { for (ThreeWindingsTransformer twt : network.getThreeWindingsTransformers()) { int middleCcNum = getThreeWindingsTransformerMiddleBusComponentNum(context, twt); if (connectedComponentToExport(middleCcNum)) { String middleBusId = getThreeWindingsTransformerMiddleBusId(twt); String middleVlId = getThreeWindingsTransformerMiddleVoltageLevelId(twt); context.busIdsToExport.add(middleBusId); int middleBusNum = mapper.getInt(AmplSubset.BUS, middleBusId); int middleVlNum = mapper.getInt(AmplSubset.VOLTAGE_LEVEL, middleVlId); formatter.writeCell(variantIndex) .writeCell(middleBusNum) .writeCell(middleVlNum) .writeCell(middleCcNum) .writeCell(Float.NaN) .writeCell(Double.NaN) .writeCell(0.0) .writeCell(0.0) .writeCell(faultNum) .writeCell(actionNum) .writeCell(middleBusId); } } }
private void writeRatioTapChanger(TableFormatter formatter, String rtcId, RatioTapChanger rtc, String tcsId) throws IOException { int rtcNum = mapper.getInt(AmplSubset.RATIO_TAP_CHANGER, rtcId); int tcsNum = mapper.getInt(AmplSubset.TAP_CHANGER_TABLE, tcsId); formatter.writeCell(variantIndex) .writeCell(rtcNum) .writeCell(rtc.getTapPosition() - rtc.getLowTapPosition() + 1) .writeCell(tcsNum) .writeCell(rtc.hasLoadTapChangingCapabilities() && rtc.isRegulating()); if (config.isExportRatioTapChangerVoltageTarget()) { formatter.writeCell(rtc.getTargetV()); } formatter.writeCell(faultNum) .writeCell(actionNum) .writeCell(rtcId); }
private void writePhaseTapChanger(TableFormatter formatter, String id, double zb2, double reactance, PhaseTapChanger ptc) throws IOException { int num = mapper.getInt(AmplSubset.TAP_CHANGER_TABLE, id); for (int position = ptc.getLowTapPosition(); position <= ptc.getHighTapPosition(); position++) { PhaseTapChangerStep step = ptc.getStep(position); double x = reactance * (1 + step.getX() / 100) / zb2; formatter.writeCell(variantIndex) .writeCell(num) .writeCell(position - ptc.getLowTapPosition() + 1) .writeCell(step.getRho()) .writeCell(x) .writeCell(Math.toRadians(step.getAlpha())) .writeCell(faultNum) .writeCell(actionNum); } }
private void writeTieLineMiddleBuses(AmplExportContext context, TableFormatter formatter) throws IOException { for (Line l : network.getLines()) { if (!l.isTieLine()) { continue; } TieLine tieLine = (TieLine) l; int xNodeCcNum = getTieLineMiddleBusComponentNum(context, tieLine); if (connectedComponentToExport(xNodeCcNum)) { String xNodeBusId = AmplUtil.getXnodeBusId(tieLine); int xNodeBusNum = mapper.getInt(AmplSubset.BUS, xNodeBusId); int xNodeVlNum = mapper.getInt(AmplSubset.VOLTAGE_LEVEL, AmplUtil.getXnodeVoltageLevelId(tieLine)); formatter.writeCell(variantIndex) .writeCell(xNodeBusNum) .writeCell(xNodeVlNum) .writeCell(xNodeCcNum) .writeCell(Float.NaN) .writeCell(Double.NaN) .writeCell(0.0) .writeCell(0.0) .writeCell(faultNum) .writeCell(actionNum) .writeCell(xNodeBusId); } } }
private void writeBuses(AmplExportContext context, TableFormatter formatter) throws IOException { for (Bus b : AmplUtil.getBuses(network)) { int ccNum = ConnectedComponents.getCcNum(b); if (connectedComponentToExport(ccNum)) { String id = b.getId(); VoltageLevel vl = b.getVoltageLevel(); context.busIdsToExport.add(id); int num = mapper.getInt(AmplSubset.BUS, id); int vlNum = mapper.getInt(AmplSubset.VOLTAGE_LEVEL, vl.getId()); double nomV = vl.getNominalV(); double v = b.getV() / nomV; double theta = Math.toRadians(b.getAngle()); formatter.writeCell(variantIndex) .writeCell(num) .writeCell(vlNum) .writeCell(ccNum) .writeCell(v) .writeCell(theta) .writeCell(b.getP()) .writeCell(b.getQ()) .writeCell(faultNum) .writeCell(actionNum) .writeCell(id); addExtensions(num, b); } } }
private void writeDanglingLineMiddleBuses(AmplExportContext context, TableFormatter formatter) throws IOException { for (DanglingLine dl : network.getDanglingLines()) { Terminal t = dl.getTerminal(); Bus b = AmplUtil.getBus(dl.getTerminal()); int middleCcNum = getDanglingLineMiddleBusComponentNum(context, dl); if (connectedComponentToExport(middleCcNum)) { String middleBusId = getDanglingLineMiddleBusId(dl); String middleVlId = getDanglingLineMiddleVoltageLevelId(dl); context.busIdsToExport.add(middleBusId); int middleBusNum = mapper.getInt(AmplSubset.BUS, middleBusId); int middleVlNum = mapper.getInt(AmplSubset.VOLTAGE_LEVEL, middleVlId); SV sv = new SV(t.getP(), t.getQ(), b != null ? b.getV() : Double.NaN, b != null ? b.getAngle() : Double.NaN).otherSide(dl); double nomV = t.getVoltageLevel().getNominalV(); double v = sv.getU() / nomV; double theta = Math.toRadians(sv.getA()); formatter.writeCell(variantIndex) .writeCell(middleBusNum) .writeCell(middleVlNum) .writeCell(middleCcNum) .writeCell(v) .writeCell(theta) .writeCell(0.0) // 0 MW injected at dangling line internal bus .writeCell(0.0) // 0 MVar injected at dangling line internal bus .writeCell(faultNum) .writeCell(actionNum) .writeCell(middleBusId); } } }
private void writeRatioTapChanger(TableFormatter formatter, String id, double zb2, double reactance, RatioTapChanger rtc) throws IOException { int num = mapper.getInt(AmplSubset.TAP_CHANGER_TABLE, id); for (int position = rtc.getLowTapPosition(); position <= rtc.getHighTapPosition(); position++) { RatioTapChangerStep step = rtc.getStep(position); double x = reactance * (1 + step.getX() / 100) / zb2; formatter.writeCell(variantIndex) .writeCell(num) .writeCell(position - rtc.getLowTapPosition() + 1) .writeCell(step.getRho()) .writeCell(x) .writeCell(0.0) .writeCell(faultNum) .writeCell(actionNum); } }
mapper.getInt(TestSubset.TYPE, value); fail(); } catch (IllegalStateException ignored) { assertEquals(1, num); assertEquals(value, mapper.getId(TestSubset.TYPE, 1)); assertEquals(1, mapper.getInt(TestSubset.TYPE, value)); assertEquals(2, num); assertEquals(value, mapper.getId(TestSubset.TYPE, 2)); assertEquals(2, mapper.getInt(TestSubset.TYPE, value)); mapper.getInt(null, value); fail(); } catch (IllegalArgumentException ignored) { mapper.getInt(TestSubset.TYPE, null); fail(); } catch (IllegalArgumentException ignored) {
for (HvdcLine hvdcLine : network.getHvdcLines()) { String id = hvdcLine.getId(); int num = mapper.getInt(AmplSubset.HVDC_LINE, id); HvdcType type = hvdcLine.getConverterStation1().getHvdcType(); AmplSubset subset = type.equals(HvdcType.VSC) ? AmplSubset.VSC_CONVERTER_STATION : AmplSubset.LCC_CONVERTER_STATION; .writeCell(num) .writeCell(type.equals(HvdcType.VSC) ? 1 : 2) .writeCell(mapper.getInt(subset, hvdcLine.getConverterStation1().getId())) .writeCell(mapper.getInt(subset, hvdcLine.getConverterStation2().getId())) .writeCell(hvdcLine.getR()) .writeCell(hvdcLine.getNominalV())