"use strict"; const $ = (id) => document.getElementById(id); const MONTH_DAYS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; const MONTH_NAMES = ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"]; const HOUR_MONTH = new Uint8Array(8760); { let h = 0; MONTH_DAYS.forEach((days, m) => { HOUR_MONTH.fill(m, h, h + days * 24); h += days * 24; }); } // Remko LWM 110 datasheet, full load at W35: [outdoor °C, COP] const LWM110_W35 = [[-7, 3.42], [2, 4.04], [7, 5.02]]; // constant source temperature of ground and water heat pumps, and their Carnot efficiency const SOURCE = { brine: [0, 0.68], water: [10, 0.68], dx: [-2, 0.68] }; const K = 273.15; // Carnot COP between condensing (5 K above flow) and evaporating (6 K below source) temperature const carnot = (flow, source) => (flow + 5 + K) / (flow + 5 - (source - 6)); const COP_MAX = 6.5; const LWM110_ETA = LWM110_W35.map(([t, cop]) => [t, cop / carnot(35, t)]); function interp(points, x) { if (x <= points[0][0]) return points[0][1]; for (let i = 1; i < points.length; i++) { const [x0, y0] = points[i - 1], [x1, y1] = points[i]; if (x <= x1) return y0 + ((y1 - y0) * (x - x0)) / (x1 - x0); } return points[points.length - 1][1]; } // Backup heating fuels, energy content as lower heating value. `perPrice` is the energy in // kWh bought per price unit and `scale` converts the price to euros. const FUELS = { electric: { unit: "kWh", kwh: 1, price: 28, priceUnit: "ct/kWh", perPrice: 1, scale: 0.01, eff: 100 }, gas: { unit: "m³", kwh: 10, price: 11, priceUnit: "ct/kWh", perPrice: 1, scale: 0.01, eff: 95 }, lpg: { unit: "l", kwh: 6.6, price: 0.7, priceUnit: "€/l", perPrice: 6.6, scale: 1, eff: 95 }, oil: { unit: "l", kwh: 9.8, price: 1.0, priceUnit: "€/l", perPrice: 9.8, scale: 1, eff: 95 }, pellets: { unit: "kg", kwh: 4.8, price: 350, priceUnit: "€/t", perPrice: 4800, scale: 1, eff: 90 }, wood: { unit: "rm", kwh: 1700, price: 110, priceUnit: "€/rm", perPrice: 1700, scale: 1, eff: 80 }, }; const fmt = (v, digits = 0) => v.toLocaleString("de-DE", { minimumFractionDigits: digits, maximumFractionDigits: digits }); let meta, plzMap, stationById; const seriesCache = new Map(); let station = null; let tnEdited = false; let lastResult = null; let binView = "energy"; // ---------- data ---------- async function loadSeries(id) { if (!seriesCache.has(id)) { const res = await fetch(`data/t/${id}.bin`); const raw = new Int16Array(await res.arrayBuffer()); const years = new Map(); meta.years.forEach((year, i) => { const slice = raw.subarray(i * meta.hours, (i + 1) * meta.hours); if (slice[0] !== meta.missing) years.set(year, slice); }); seriesCache.set(id, years); } return seriesCache.get(id); } /** Heating degree hours below 15 °C, used to find the coldest and warmest year. */ function degreeHours(slice) { let sum = 0; for (let i = 0; i < slice.length; i++) sum += Math.max(0, 150 - slice[i]); return sum; } function scenarioYears(series, scenario) { const years = [...series.keys()]; if (scenario === "all") return years; if (scenario === "cold" || scenario === "warm") { const sorted = years.slice().sort((a, b) => degreeHours(series.get(b)) - degreeHours(series.get(a))); return [scenario === "cold" ? sorted[0] : sorted[sorted.length - 1]]; } return series.has(+scenario) ? [+scenario] : years; } /** Temperatures in °C as used by the chosen evaluation type. */ function temperatures(slice, resolution) { const t = new Float32Array(slice.length); for (let i = 0; i < slice.length; i++) t[i] = slice[i] / 10; if (resolution === "day") { for (let d = 0; d < t.length; d += 24) { let sum = 0; for (let h = 0; h < 24; h++) sum += t[d + h]; t.fill(sum / 24, d, d + 24); } } else if (resolution === "bin") { for (let i = 0; i < t.length; i++) t[i] = Math.round(t[i]); } return t; } // ---------- model ---------- /** * Hour-by-hour split of the heating load between heat pump and backup heater. * Load is linear from qn at tn to 0 at the heating limit thg. The heat pump is * sized so that its capacity equals the load at the bivalence point; its capacity * changes by `slope` (fraction per K) with the outdoor temperature. */ function model(p) { const tb = p.mode === "mono" ? p.tn : p.tbiv; const load = (t) => (t < p.thg ? (p.qn * (p.thg - t)) / (p.thg - p.tn) : 0); const pb = load(tb); const capacity = (t) => Math.max(0, pb * (1 + p.slope * (t - tb))); const heatPump = (t) => { if (p.mode === "alternative" && t < tb) return 0; if (p.mode === "parallel" && Number.isFinite(p.cutoff) && t < p.cutoff) return 0; return Math.min(load(t), capacity(t)); }; const flow = (t) => { if (!p.flowCurve) return p.flowN; const f = 20 + ((p.flowN - 20) * (20 - t)) / (20 - p.tn); return Math.min(p.flowN, Math.max(25, f)); }; const cop = (t) => { if (p.type === "air") return Math.min(COP_MAX, interp(LWM110_ETA, t) * carnot(flow(t), t)); const [source, eta] = SOURCE[p.type]; return Math.min(COP_MAX, eta * carnot(flow(t), source)); }; return { tb, pb, load, capacity, heatPump, flow, cop }; } function simulate(series, years, p) { const m = model(p); const n = years.length; const r = { years, n, tb: m.tb, pb: m.pb, model: m, params: p, q: 0, hp: 0, backup: 0, el: 0, heatingHours: 0, backupHours: 0, belowTn: 0, peak: 0, months: Array.from({ length: 12 }, () => ({ hp: 0, backup: 0 })), els: new Float32Array(n * 8760), bins: new Map(), loads: new Float32Array(n * 8760), hps: new Float32Array(n * 8760), temps: [], }; years.forEach((year, y) => { const t = temperatures(series.get(year), p.resolution); r.temps.push(t); for (let i = 0; i < t.length; i++) { const q = m.load(t[i]); const hp = m.heatPump(t[i]); const backup = q - hp; r.loads[y * 8760 + i] = q; r.hps[y * 8760 + i] = hp; if (q <= 0) continue; const el = hp > 0 ? hp / m.cop(t[i]) : 0; r.els[y * 8760 + i] = el; r.q += q; r.hp += hp; r.backup += backup; r.el += el; r.heatingHours++; if (backup > 1e-9) r.backupHours++; if (t[i] < p.tn) r.belowTn++; if (q > r.peak) r.peak = q; r.months[HOUR_MONTH[i]].hp += hp; r.months[HOUR_MONTH[i]].backup += backup; const key = Math.round(t[i]); const bin = r.bins.get(key) || { hours: 0, hp: 0, backup: 0, el: 0 }; bin.hours++; bin.hp += hp; bin.backup += backup; bin.el += el; r.bins.set(key, bin); } }); // per-year averages for (const k of ["q", "hp", "backup", "el", "heatingHours", "backupHours", "belowTn"]) r[k] /= n; for (const month of r.months) { month.hp /= n; month.backup /= n; } for (const bin of r.bins.values()) { bin.hours /= n; bin.hp /= n; bin.backup /= n; bin.el /= n; } r.jaz = r.el > 0 ? r.hp / r.el : 0; r.costHp = (r.el * p.priceEl) / 100; r.backupFuel = r.backup / p.effBackup; const fuel = FUELS[p.fuel]; r.backupAmount = r.backupFuel / fuel.kwh; r.costBackup = (r.backupFuel / fuel.perPrice) * p.priceBackup * fuel.scale; const loadTn = m.load(p.tn); r.powerShareTn = loadTn > 0 ? m.heatPump(p.tn) / loadTn : 0; return r; } // ---------- form ---------- function params() { const cutoff = $("cutoff").value.trim(); return { qn: +$("qn").value, tn: +$("tn").value, thg: +$("thg").value, mode: $("mode").value, tbiv: +$("tbiv").value, cutoff: cutoff === "" ? NaN : +cutoff, slope: +$("slope").value / 100, resolution: $("resolution").value, type: $("type").value, flowN: +$("flowN").value, flowCurve: $("flowCurve").checked, priceEl: +$("priceEl").value, fuel: $("fuel").value, priceBackup: +$("priceBackup").value, effBackup: +$("effBackup").value / 100, }; } function validate(p) { if (!(p.qn > 0)) return "Norm-Heizlast muss größer als 0 sein."; if (!(p.flowN >= 25 && p.flowN <= 65)) return "Vorlauftemperatur muss zwischen 25 und 65 °C liegen."; if (!(p.effBackup > 0)) return "Wirkungsgrad der Zusatzheizung muss größer als 0 sein."; if (!(p.tn < p.thg)) return "Norm-Außentemperatur muss unter der Heizgrenztemperatur liegen."; if (p.mode !== "mono" && !(p.tbiv < p.thg)) return "Bivalenzpunkt muss unter der Heizgrenztemperatur liegen."; if (p.mode !== "mono" && p.tbiv < p.tn) return "Bivalenzpunkt unter der Norm-Außentemperatur: dann ist die Anlage praktisch monovalent."; return null; } function showLocation() { const code = $("plz").value.trim(); const entry = plzMap[code]; if (!entry) { station = null; $("location").textContent = code.length === 5 ? "Postleitzahl nicht gefunden." : ""; return; } const [place, , , id, dist] = entry; station = stationById[id]; $("location").innerHTML = `${place} · Station ${station.name} (${station.elev} m ü. NN, ${fmt(dist, 1)} km entfernt, ${station.years.length} Jahre)` + (dist > 25 ? ` Nächste Station ist weit entfernt.` : ""); $("tnHint").textContent = station.tnorm != null ? `(${fmt(station.tnorm, 1)} °C)` : ""; if (!tnEdited && station.tnorm != null) $("tn").value = station.tnorm; fillScenarios(); } function fillScenarios() { const select = $("scenario"); const previous = select.value || "all"; const first = station.years[0], last = station.years[station.years.length - 1]; select.innerHTML = `` + `` + station.years.slice().reverse().map((y) => ``).join(""); select.value = [...select.options].some((o) => o.value === previous) ? previous : "all"; } function updateFieldVisibility() { const mode = $("mode").value; $("bivalentFields").hidden = mode === "mono"; $("cutoffField").hidden = mode !== "parallel"; $("cutoffField").nextElementSibling.hidden = mode !== "parallel"; } function onFuelChange(resetValues = true) { const fuel = FUELS[$("fuel").value]; if (resetValues) { $("priceBackup").value = fuel.price; $("effBackup").value = fuel.eff; } $("priceBackupUnit").textContent = fuel.priceUnit; $("fuelHint").textContent = fuel.unit === "kWh" ? "" : `Heizwert ${fmt(fuel.kwh, fuel.kwh < 100 ? 1 : 0)} kWh/${fuel.unit}, Wirkungsgrad bezogen auf den Heizwert.`; } function onTypeChange() { $("slope").value = $("type").value === "air" ? 3 : 0; } let runToken = 0; async function run() { updateFieldVisibility(); if (!station) { $("status").textContent = "Bitte eine gültige Postleitzahl eingeben."; return; } const p = params(); const error = validate(p); if (error) { $("status").textContent = error; return; } const token = ++runToken; const series = await loadSeries(station.id); if (token !== runToken) return; const years = scenarioYears(series, $("scenario").value); const r = simulate(series, years, p); lastResult = r; $("status").textContent = years.length > 1 ? `Mittelwerte über ${years.length} Jahre (${years[0]}–${years[years.length - 1]}), Station ${station.name}.` : `Wetterjahr ${years[0]}, Station ${station.name}.`; $("tbivHint").textContent = `WP-Heizleistung am Bivalenzpunkt: ${fmt(r.pb, 1)} kW`; renderKpis(r); renderDuration(r); renderBins(r); renderMonths(r); } // ---------- output ---------- function kpi(label, value, sub = "", cls = "") { return `