@Override public String getName(VoltageLevel voltageLevel, TIntArrayList nodes) { AtomicInteger i; lock.lock(); try { i = counter.computeIfAbsent(voltageLevel, k -> new AtomicInteger()); } finally { lock.unlock(); } return voltageLevel.getId() + "_" + i.getAndIncrement(); }
private String getEsgIdAndIncCounter(VoltageLevel vl) { String ret = fakeNodesMap.get(vl.getId()); countUsesMap.getAndIncrement(ret); return ret; } }
public static HistoDbNetworkAttributeId createVoltageAttributeId(VoltageLevel vl) { return new HistoDbNetworkAttributeId(vl.getId(), HistoDbAttr.V); }
/** * Keep this voltage level if the IDs list contains the ID of this voltage level. * @param voltageLevel The voltage level to test * @return true if the IDs list contains the ID of this voltage level, false otherwise */ @Override public boolean test(VoltageLevel voltageLevel) { Objects.requireNonNull(voltageLevel); return ids.contains(voltageLevel.getId()) || ids.contains(voltageLevel.getSubstation().getId()); } }
public static String getVoltageLevelId(LimitViolation limitViolation, Network network, boolean name) { VoltageLevel voltageLevel = getVoltageLevel(limitViolation, network); return name ? voltageLevel.getName() : voltageLevel.getId(); }
/** * Throw a {@link com.powsybl.commons.PowsyblException} if this voltage level contains at least one {@link Branch} or * one {@link ThreeWindingsTransformer} or one {@link HvdcConverterStation}. */ static void checkRemovability(VoltageLevel voltageLevel) { Network network = voltageLevel.getSubstation().getNetwork(); for (Connectable connectable : voltageLevel.getConnectables()) { ConnectableType type = connectable.getType(); if (MULTIPLE_TERMINALS_CONNECTABLE_TYPES.contains(type)) { // Reject lines, 2WT and 3WT throw new AssertionError("The voltage level '" + voltageLevel.getId() + "' cannot be removed because of a remaining " + type); } else if ((type == ConnectableType.HVDC_CONVERTER_STATION) && (network.getHvdcLine((HvdcConverterStation) connectable) != null)) { // Reject all converter stations connected to a HVDC line throw new AssertionError("The voltage level '" + voltageLevel.getId() + "' cannot be removed because of a remaining HVDC line"); } } } }
private static void addBranchSideData(LinkedHashMap<String, Double> branchesData, String branchId, Terminal terminal, double currentLimit) { branchesData.put(getAttributeKey(branchId, terminal.getVoltageLevel().getId(), HistoDbAttr.I.name()), terminal.getI()); branchesData.put(getAttributeKey(branchId, terminal.getVoltageLevel().getId(), HistoDbAttr.P.name()), terminal.getP()); branchesData.put(getAttributeKey(branchId, terminal.getVoltageLevel().getId(), "IMAX"), currentLimit); }
@Override public void checkVoltage(Bus bus, double value, Consumer<LimitViolation> consumer) { VoltageLevel vl = bus.getVoltageLevel(); if (!Double.isNaN(vl.getLowVoltageLimit()) && value <= vl.getLowVoltageLimit()) { consumer.accept(new LimitViolation(vl.getId(), vl.getName(), LimitViolationType.LOW_VOLTAGE, vl.getLowVoltageLimit(), limitReduction, value)); } if (!Double.isNaN(vl.getHighVoltageLimit()) && value >= vl.getHighVoltageLimit()) { consumer.accept(new LimitViolation(vl.getId(), vl.getName(), LimitViolationType.HIGH_VOLTAGE, vl.getHighVoltageLimit(), limitReduction, value)); } }
public static Set<Zone> getZone(ActionsContingencies actionContingencies, Network network) { Set<Zone> zones = new HashSet<Zone>(); Zones xmlZones = actionContingencies.getZones(); Iterable<VoltageLevel> voltageLevels = network.getVoltageLevels(); for (VoltageLevel vl: voltageLevels) { String networkVoltagelevelId = vl.getId(); for (Zone z :xmlZones.getZone()) { if (z.getVoltageLevels() != null) { for (eu.itesla_project.iidm.actions_contingencies.xml.mapping.VoltageLevel zvl : z.getVoltageLevels().getVoltageLevel()) { if (networkVoltagelevelId.equals(zvl.getID())) { zones.add(z); break; } } } } } return zones; }
valueMap.put(new HistoDbNetworkAttributeId(twt.getId(), t.getVoltageLevel().getId(), HistoDbAttr.V), context.v); valueMap.put(new HistoDbNetworkAttributeId(twt.getId(), t.getVoltageLevel().getId(), HistoDbAttr.I), context.i); valueMap.put(new HistoDbNetworkAttributeId(twt.getId(), t.getVoltageLevel().getId(), HistoDbAttr.P), context.p); valueMap.put(new HistoDbNetworkAttributeId(twt.getId(), t.getVoltageLevel().getId(), HistoDbAttr.Q), context.q);
private static double checkP(Terminal terminal) { if (!terminal.isConnected()) { return 0.0; } if (Double.isNaN(terminal.getP())) { String connectableId = terminal.getConnectable().getId(); String voltageLevelId = terminal.getVoltageLevel().getId(); throw new PowsyblException("The active power of '" + connectableId + "' (" + voltageLevelId + ") is not set. Do you forget to compute the flows?"); } return terminal.getP(); }
private static double checkQ(Terminal terminal) { if (!terminal.isConnected()) { return 0.0; } if (Double.isNaN(terminal.getQ())) { String connectableId = terminal.getConnectable().getId(); String voltageLevelId = terminal.getVoltageLevel().getId(); throw new PowsyblException("The reactive power of '" + connectableId + "' (" + voltageLevelId + ") is not set. Do you forget to compute the flows?"); } return terminal.getQ(); } }
public void build(Network network) { // build a unique topology for each of the substation reflecting history Map<String, UniqueTopology> uniqueTopos = build(); // remove from the reference network equipments not in the history, i.e always disconnected in the history cleanNetwork(network, uniqueTopos); // apply unique topology to the network for (VoltageLevel vl : network.getVoltageLevels()) { UniqueTopology uniqueTopo = uniqueTopos.get(vl.getId()); // uniqueTopo.print(System.out); uniqueTopo.apply(network); } Networks.printBalanceSummary("unique topo", network, LOGGER); new UniqueTopologyChecker(network, topoHisto, uniqueTopos, dict).check(); }
private void setNewLowVoltageLimit(String stateId, LimitViolation violation, float margin, boolean applyToBaseCase) { VoltageLevel voltageLevel = network.getVoltageLevel(violation.getSubjectId()); if (voltageLevel != null) { if (violation.getValue() < voltageLevel.getLowVoltageLimit()) { // it could already have been fixed double newLimit = getNewLowerLimit(violation, margin); LOGGER.debug("State {}: changing low voltage limit of voltage level {}: {} -> {}", stateId, voltageLevel.getId(), violation.getLimit(), newLimit); voltageLevel.setLowVoltageLimit(newLimit); if (applyToBaseCase && !StateManagerConstants.INITIAL_STATE_ID.equals(stateId)) { // change the limit also to basecase network.getStateManager().setWorkingState(StateManagerConstants.INITIAL_STATE_ID); voltageLevel = network.getVoltageLevel(violation.getSubjectId()); LOGGER.debug("State {}: changing low voltage limit of voltage level {}: {} -> {}", StateManagerConstants.INITIAL_STATE_ID, voltageLevel.getId(), violation.getLimit(), newLimit); voltageLevel.setLowVoltageLimit(newLimit); } } } else { LOGGER.warn("State {}: cannot change low voltage limit of voltage level {}: no voltage level with this id in the network", stateId, violation.getSubjectId()); } }
private void setNewHighVoltageLimit(String stateId, LimitViolation violation, float margin, boolean applyToBaseCase) { VoltageLevel voltageLevel = network.getVoltageLevel(violation.getSubjectId()); if (voltageLevel != null) { if (violation.getValue() > voltageLevel.getHighVoltageLimit()) { // it could already have been fixed double newLimit = getNewUpperLimit(violation, margin); LOGGER.debug("State {}: changing high voltage limit of voltage level {}: {} -> {}", stateId, voltageLevel.getId(), violation.getLimit(), newLimit); voltageLevel.setHighVoltageLimit(newLimit); if (applyToBaseCase && !StateManagerConstants.INITIAL_STATE_ID.equals(stateId)) { // change the limit also to basecase network.getStateManager().setWorkingState(StateManagerConstants.INITIAL_STATE_ID); voltageLevel = network.getVoltageLevel(violation.getSubjectId()); LOGGER.debug("State {}: changing high voltage limit of voltage level {}: {} -> {}", StateManagerConstants.INITIAL_STATE_ID, voltageLevel.getId(), violation.getLimit(), newLimit); voltageLevel.setHighVoltageLimit(newLimit); network.getStateManager().setWorkingState(stateId); } } } else { LOGGER.warn("State {}: cannot change high voltage limit of voltage level {}: no voltage level with this id in the network", stateId, violation.getSubjectId()); } }
private void createSwitch(VoltageLevel vl, cim1.model.Switch sw) { cim1.model.Terminal t1 = sw.getTerminals().get(0); cim1.model.Terminal t2 = sw.getTerminals().get(1); cim1.model.TopologicalNode tn1 = t1.getTopologicalNode(); cim1.model.TopologicalNode tn2 = t2.getTopologicalNode(); cim1.model.VoltageLevel vl1 = (cim1.model.VoltageLevel) tn1.getConnectivityNodeContainer(); cim1.model.VoltageLevel vl2 = (cim1.model.VoltageLevel) tn2.getConnectivityNodeContainer(); if (!vl1.getId().equals(vl.getId()) || !vl2.getId().equals(vl.getId())) { lowImpedanceLines.add(sw); } else { vl.getBusBreakerView().newSwitch() .setId(namingStrategy.getId(sw)) .setName(namingStrategy.getName(sw)) .setEnsureIdUnicity(false) .setBus1(namingStrategy.getId(tn1)) .setBus2(namingStrategy.getId(tn2)) .setOpen(!t1.isConnected() || !t2.isConnected()) .add(); } }
public static void fillMapper(StringToIntMapper<AmplSubset> mapper, Network network) { // Voltage levels network.getVoltageLevelStream().forEach(vl -> mapper.newInt(AmplSubset.VOLTAGE_LEVEL, vl.getId())); // Buses getBuses(network).forEach(b -> mapper.newInt(AmplSubset.BUS, b.getId())); // Lines fillLines(mapper, network); // Two windings transformers fillTwoWindingsTransformers(mapper, network); // Three windings transformers fillThreeWindingsTransformers(mapper, network); // Dangling lines fillDanglingLines(mapper, network); // loads network.getLoadStream().forEach(l -> mapper.newInt(AmplSubset.LOAD, l.getId())); // shunts network.getShuntCompensatorStream().forEach(sc -> mapper.newInt(AmplSubset.SHUNT, sc.getId())); // generators network.getGeneratorStream().forEach(g -> mapper.newInt(AmplSubset.GENERATOR, g.getId())); // static var compensators network.getStaticVarCompensatorStream().forEach(svc -> mapper.newInt(AmplSubset.STATIC_VAR_COMPENSATOR, svc.getId())); // HVDC lines network.getHvdcLineStream().forEach(hvdc -> mapper.newInt(AmplSubset.HVDC_LINE, hvdc.getId())); // HvdcConverterStations network.getHvdcConverterStations().forEach(conv -> mapper.newInt(conv.getHvdcType().equals(HvdcType.VSC) ? AmplSubset.VSC_CONVERTER_STATION : AmplSubset.LCC_CONVERTER_STATION, conv.getId())); }
throw new RuntimeException("Slack bus not found"); LOGGER.debug("Slack bus: {} ({})", sb, sb.getVoltageLevel().getId()); for (Bus b : Identifiables.sort(EchUtil.getBuses(network, config))) {
protected static void writeNodeOrBus(Integer index, Terminal t, NetworkXmlWriterContext context) throws XMLStreamException { TopologyLevel topologyLevel = TopologyLevel.min(t.getVoltageLevel().getTopologyKind(), context.getOptions().getTopologyLevel()); switch (topologyLevel) { case NODE_BREAKER: writeNode(index, t, context); break; case BUS_BREAKER: writeBus(index, t.getBusBreakerView().getBus(), t.getBusBreakerView().getConnectableBus(), context); break; case BUS_BRANCH: writeBus(index, t.getBusView().getBus(), t.getBusView().getConnectableBus(), context); break; default: throw new AssertionError("Unexpected TopologyLevel value: " + topologyLevel); } if (index != null) { context.getWriter().writeAttribute("voltageLevelId" + index, context.getAnonymizer().anonymizeString(t.getVoltageLevel().getId())); } }
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); } } }