/** * Constructor to buses that come from the IIDM network. * @param bus */ public BusRecord(Bus bus) { this.bus = bus; this.busId = bus.getId(); if (!Double.isNaN(this.bus.getV())) { this.busVoltage = bus.getV() / bus.getVoltageLevel().getNominalV(); this.busAngle = this.bus.getAngle(); addParameter(StaticData.V_0, this.busVoltage); addParameter(StaticData.ANGLE_0, this.busAngle); } else { this.busVoltage = Float.NaN; } }
/** * This implementation takes the voltage value to be checked from the Network. */ @Override public void checkVoltage(Bus bus, Consumer<LimitViolation> consumer) { checkVoltage(bus, bus.getV(), consumer); }
/** * Create a Dummy Bus (corresponding to a dangling line) * @param writerMo * @param modContext * @param modelicaModelsList * @param modelicaSim * @throws IOException */ private void exportDanglingBuses(Writer writerMo, ModExportContext modContext, List<String> modelicaModelsList, SimulatorInst modelicaSim) throws IOException { if ((dangLinesList.size() != 0) && (!dangLinesList.isEmpty())) { for (DanglingLine dl : dangLinesList) { Bus knownBus = dl.getTerminal().getBusBreakerView().getBus(); SV sv = new SV(0, 0, knownBus.getV(), knownBus.getAngle()); SV svDangling = sv.otherSide(dl); double voltage = svDangling.getU() / knownBus.getVoltageLevel().getNominalV(); double angle = svDangling.getA(); String name = "ext_" + dl.getId(); BusRecord busRecord = ModelConverter.getModelicaRecord(name, voltage, angle, modContext, _ddbManager, modelicaSim); this.danglingBuses.add(busRecord); this.addRecord(busRecord, writerMo, modContext, _ddbManager, modelicaSim); } } }
private static double getV(Terminal t) { Bus b = t.getBusBreakerView().getBus(); return b != null ? b.getV() : Double.NaN; }
/** * Create a Dummy Load (corresponding to a dangling line) * @param writerMo * @param modContext * @param modelicaModelsList * @param modelicaSim * @throws IOException */ private void exportDanglingLoads(Writer writerMo, ModExportContext modContext, List<String> modelicaModelsList, SimulatorInst modelicaSim) throws IOException { if ((dangLinesList.size() != 0) && (!dangLinesList.isEmpty())) { for (DanglingLine dl : dangLinesList) { Bus knownBus = dl.getTerminal().getBusBreakerView().getBus(); SV sv = new SV(0, 0, knownBus.getV(), knownBus.getAngle()); SV svDangling = sv.otherSide(dl); double busVoltage = svDangling.getU() / knownBus.getVoltageLevel().getNominalV(); double busAngle = svDangling.getA(); double p0 = dl.getP0(); double q0 = dl.getQ0(); String loadId = "ext_" + dl.getId(); LoadRecord loadRecord = ModelConverter.getModelicaRecord(loadId, p0, q0, busVoltage, busAngle, modContext, _ddbManager, modelicaSim, SNREF, this._sourceEngine); this.danglingLoads.add(loadRecord); this.addRecord(loadRecord, writerMo, modContext, _ddbManager, modelicaSim); } } }
private static void connectGenerator(Generator g) { Terminal t = g.getTerminal(); t.connect(); if (g.isVoltageRegulatorOn()) { Bus bus = t.getBusView().getBus(); if (bus != null) { // set voltage setpoint to the same as other generators connected to the bus double targetV = bus.getGeneratorStream().findFirst().map(Generator::getTargetV).orElse(Double.NaN); // if no other generator connected to the bus, set voltage setpoint to network voltage if (Double.isNaN(targetV) && !Double.isNaN(bus.getV())) { g.setTargetV(bus.getV()); } } } LOGGER.info("Connecting {}", g.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); } } }
private void visitInjection(Injection inj, TerminalContext context) { Terminal t = inj.getTerminal(); context.update(t); if (config.isReplaceMissingValues()) { if (Double.isNaN(context.p)) { context.p = 0f; } if (Double.isNaN(context.q)) { context.q = 0f; } if (Double.isNaN(context.v)) { // use connectable bus voltage, better than nothing... context.v = t.getBusBreakerView().getConnectableBus().getV(); } if (Double.isNaN(context.v)) { context.v = 0f; // TODO is there a better value? } if (Double.isNaN(context.i)) { context.i = 0f; } } valueMap.put(new HistoDbNetworkAttributeId(inj.getId(), HistoDbAttr.P), context.p); valueMap.put(new HistoDbNetworkAttributeId(inj.getId(), HistoDbAttr.Q), context.q); valueMap.put(new HistoDbNetworkAttributeId(inj.getId(), HistoDbAttr.V), context.v); valueMap.put(new HistoDbNetworkAttributeId(inj.getId(), HistoDbAttr.I), context.i); }
/** * Export IIDM coupling devices connect to Modelica coupling devices connect * @param writerMo * @param modContext * @param modelicaModelsList * @param modelicaSim * @throws IOException */ private void exportConnectCouplingDevices(Writer writerMo, ModExportContext modContext, List<String> modelicaModelsList, SimulatorInst modelicaSim) throws IOException { if ((connectCouplingList.size() != 0) && (!connectCouplingList.isEmpty())) { LOGGER.info("EXPORTING CONNECT COUPLING DEVICES " + connectCouplingList.size()); this.addRecord(writerMo, null); this.addRecord(writerMo, "// COUPLING DEVICES"); for (VoltageLevel voltageLevel : connectCouplingList) { for (Switch sw : voltageLevel.getBusBreakerView().getSwitches()) { LOGGER.info("\t Exporting coupling device connect " + sw.getId()); Bus bus1 = voltageLevel.getBusBreakerView().getBus1(sw.getId()); Bus bus2 = voltageLevel.getBusBreakerView().getBus2(sw.getId()); if (!Double.isNaN(bus1.getV()) && !Double.isNaN(bus2.getV())) { ConnectCouplingDevicesRecord couplingDeviceRecord = ModelConverter.getModelicaRecord(sw, bus1, bus2, modContext, _ddbManager, modelicaSim); this.addRecord(couplingDeviceRecord, writerMo, modContext, _ddbManager, modelicaSim); } } } } }
/** * Export IIDM Generators to Modelica Generators-OmegaRef connect */ private void exportConnectGlobalVar(Writer writerMo, ModExportContext modContext, List<Injection> identList, GlobalVariable globalVar, SimulatorInst modelicaSim) throws IOException { if ((identList.size() != 0) && (!identList.isEmpty())) { this.addRecord(writerMo, null); for (Injection injection : identList) { ConnectBusInfo busInfo = findBus(injection.getTerminal(), injection.getId()); if (!Double.isNaN(busInfo.getBus().getV()) && busInfo.isConnected()) { ConnectGlobalVarRecord record = ModelConverter.getModelicaRecord(injection, globalVar, modContext, _ddbManager, modelicaSim); if (record != null) { this.addRecord(record, writerMo, modContext, _ddbManager, modelicaSim); } } } } }
/** * Export IIDM shunts connect to Modelica capacitors connect */ private void exportConnectCapacitors(Writer writerMo, ModExportContext modContext, List<String> modelicaModelsList, SimulatorInst modelicaSim) throws IOException { if ((connectCapacitorsList.size() != 0) && (!connectCapacitorsList.isEmpty())) { LOGGER.info("EXPORTING CONNECT CAPACITORS"); this.addRecord(writerMo, null); this.addRecord(writerMo, "// Connecting Capacitors"); for (ShuntCompensator capacitor : connectCapacitorsList) { LOGGER.info("\t Exporting capacitor connect " + capacitor.getId()); ConnectBusInfo busInfo = findBus(capacitor.getTerminal(), capacitor.getId()); if (!Double.isNaN(busInfo.getBus().getV())) { if (busInfo.isConnected()) { ConnectRecord capacitorConnect = ModelConverter.getModelicaRecord(busInfo, capacitor, modContext, _ddbManager, modelicaSim); this.addRecord(capacitorConnect, writerMo, modContext, _ddbManager, modelicaSim); } } } } }
@Override protected void writeRootElementAttributes(Bus b, VoltageLevel vl, NetworkXmlWriterContext context) throws XMLStreamException { XmlUtil.writeDouble("v", b.getV(), context.getWriter()); XmlUtil.writeDouble("angle", b.getAngle(), context.getWriter()); }
/** * Export IIDM loads connect to Modelica loads connect * @param writerMo * @param modContext * @param modelicaModelsList * @param modelicaSim * @throws IOException */ private void exportConnectLoads(Writer writerMo, ModExportContext modContext, List<String> modelicaModelsList, SimulatorInst modelicaSim) throws IOException { if ((connectLoadsList.size() != 0) && (!connectLoadsList.isEmpty())) { LOGGER.info("EXPORTING CONNECT LOADS"); this.addRecord(writerMo, null); this.addRecord(writerMo, "// Connecting LOADS"); for (Load load : connectLoadsList) { LOGGER.info("\t Exporting load connect " + load.getId()); ConnectBusInfo busInfo = findBus(load.getTerminal(), load.getId()); if (!Double.isNaN(busInfo.getBus().getV())) { if (busInfo.isConnected()) { ConnectRecord loadConnect = ModelConverter.getModelicaRecord(busInfo, load, modContext, _ddbManager, modelicaSim); this.addRecord(loadConnect, writerMo, modContext, _ddbManager, modelicaSim); } } } } }
private static double getV(LegBase<?> leg) { return leg.getTerminal().isConnected() ? leg.getTerminal().getBusView().getBus().getV() : Double.NaN; }
private static void fillGeneratorState(Generator g, StateVariable sv) { Terminal t = g.getTerminal(); Bus b = t.getBusBreakerView().getBus(); if (Double.isNaN(t.getP())) { sv.p = 0; } else { sv.p = t.getP(); } if (Double.isNaN(t.getQ())) { sv.q = 0; } else { sv.q = t.getQ(); } if (b != null && !Double.isNaN(b.getV()) && !Double.isNaN(b.getAngle())) { // generator is connected sv.u = b.getV(); sv.theta = b.getAngle(); } else { sv.u = t.getVoltageLevel().getNominalV(); sv.theta = 0; } if (!sv.isValid()) { throw new RuntimeException("Invalid sv " + g.getId() + ": " + sv); } }
public static void printGeneratorsSetpointDiff(Network network, Logger logger) { for (Generator g : network.getGenerators()) { double dp = Math.abs(g.getTerminal().getP() + g.getTargetP()); double dq = Math.abs(g.getTerminal().getQ() + g.getTargetQ()); double dv = Math.abs(g.getTerminal().getBusBreakerView().getConnectableBus().getV() - g.getTargetV()); if (dp > 1 || dq > 5 || dv > 0.1) { logger.warn("Generator {}: ({}, {}, {}) ({}, {}, {}) -> ({}, {}, {})", g.getId(), dp, dq, dv, -g.getTargetP(), -g.getTargetQ(), g.getTargetV(), g.getTerminal().getP(), g.getTerminal().getQ(), g.getTerminal().getBusBreakerView().getConnectableBus().getV()); } } }
private void update(Terminal t) { if (t.getBusView().getBus() != null) { p = t.getP(); q = t.getQ(); v = t.getBusView().getBus().getV(); i = t.getI(); } }
public LoadRecord(Load load, ConnectBusInfo busInfo, double snref, SourceEngine sourceEngine) { this.load = load; this.busInfo = busInfo; this.loadId = load.getId(); this.busConnected = busInfo.isConnected(); this.p0 = this.load.getP0(); this.q0 = this.load.getQ0(); this.busVoltage = Double.NaN; this.busAngle = Double.NaN; this.sourceEngine = sourceEngine; if (this.busConnected) { if (load.getTerminal().getBusView().getBus() != null) { if (!Double.isNaN(load.getTerminal().getBusView().getBus().getV())) { busVoltage = load.getTerminal().getBusView().getBus().getV() / load.getTerminal().getVoltageLevel().getNominalV(); } if (!Double.isNaN(load.getTerminal().getBusView().getBus().getAngle())) { busAngle = load.getTerminal().getBusView().getBus().getAngle(); } } addLfParameters(); } else { LOGGER.warn("Load " + this.getModelicaName() + " disconnected."); this.addValue(StaticData.COMMENT + " Load " + this.getModelicaName() + " disconnected."); } if (this.busVoltage == 0) { LOGGER.info("Voltage 0"); } }
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); } } }