Repository navigation
Expand file tree
/
Copy pathcalc-hvacsystems.js
More file actions
2975 lines (2840 loc) · 256 KB
/
Copy pathcalc-hvacsystems.js
File metadata and controls
2975 lines (2840 loc) · 256 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Group C: building-systems HVAC engineering bench (spec-v16 first-principles batch).
//
// spec-v81 cap-relief split: the cohesive spec-v16 "Group C expansion" batch --
// seven first-principles HVAC engineering tiles (chiller-tons, hx-lmtd-ntu,
// air-changes-hour, boiler-pipe-sizing, compressor-short-cycle,
// humidifier-capacity, filter-pressure-drop) -- was extracted verbatim from
// calc-hvac.js (which sat at 94.9% of its size cap, the tightest remaining
// calculator module) into this module. The seven share a theme distinct from
// the residential split-system core that stays in calc-hvac.js (Manual J loads,
// duct sizing, refrigerant charging and superheat/subcool service): they are
// engineered building-systems calcs -- central-plant chiller tonnage and
// heat-exchanger LMTD/effectiveness-NTU, hydronic boiler-distribution pipe
// sizing, compressor short-cycle protection, humidifier capacity, filter
// pressure-drop / fan-energy penalty, and air changes per hour. Each KEEPS
// group "C" -- a tile's group letter is independent of the module that holds it
// (the v28/v30/v36/v39/v42/v70..v80 precedent). Their ids, citations, worked
// examples, dimensional annotations, and behavior are byte-for-byte unchanged.
// The seven compute functions use the per-module _finiteGuard, copied verbatim
// below (non-exported, so it adds no v14 derivation-corpus row), exactly as the
// v72/v73/v76/v77/v78/v80 benches did. The block carries its own module-local
// helpers (_v16h_readNum, _v16h_HX_FLUIDS, _v16h_pipeVelocityFps,
// _v16h_humidityRatioFromRH), which travel with it unchanged. Lazy-loaded on
// first open of one of its tiles, so it is not in the home-view first-paint
// payload.
import {
DEBOUNCE_MS, debounce, makeNumber, makeSelect,
makeOutputLine, attachExampleButton, fmt,
} from "./ui-fields.js";
import { hazenWilliamsFrictionLoss } from "./pure-math.js";
// v18 §7 contract guard: reject a non-finite numeric input. A renderer
// coerces an empty number field to 0 (Number("") === 0), so a NaN or
// Infinity reaching a solver is genuinely unusable (a pasted 1e999, a
// degenerate computed slot); per the spec-v18 §2 output contract the
// solver returns {error} rather than leaking a non-finite output field.
// Generic over the input object, so it needs no per-tile slot list, and
// it inspects only own numeric values (strings/arrays/null pass through).
// Non-exported, so it adds no v14 derivation-corpus row.
const _finiteGuard = (o) => {
if (o && typeof o === "object" && !Array.isArray(o)) {
for (const v of Object.values(o)) {
if (typeof v === "number" && !Number.isFinite(v)) {
return { error: "All numeric inputs must be finite numbers." };
}
}
}
return null;
};
// spec-v9 psychrometric helpers shared by the humidifier-capacity tile. Copied
// verbatim from calc-hvac.js (which still uses them for its v9 outdoor-air /
// wet-bulb tiles), so the split leaves no cross-module import. Non-exported, so
// they add no v14 derivation-corpus row.
function _v9_satPressure_kPa(T_C) {
// Magnus form: e_s = 0.61094 * exp(17.625 * T / (T + 243.04)).
return 0.61094 * Math.exp((17.625 * T_C) / (T_C + 243.04));
}
function _v9_pressureAtAltitude_kPa(z_ft) {
const z_m = z_ft * 0.3048;
return 101.325 * Math.pow(1 - 2.25577e-5 * z_m, 5.2559);
}
// Compact renderer factory, copied verbatim from calc-arborist.js (same
// ui-fields imports) per the new-module convention; only the inner render
// function's name differs, so the schema-coverage gates read it unchanged.
function _simpleRenderer(spec) {
const _hsRender = function (inputRegion, outputRegion, citationEl) {
citationEl.textContent = spec.citation;
attachExampleButton(inputRegion, () => fillExample(spec.example));
const fields = {};
for (const f of spec.fields) {
let field;
if (f.kind === "select") field = makeSelect(f.label, f.id || f.key, f.options);
else field = makeNumber(f.label, f.id || f.key, f.attrs || { step: "any", min: "0" });
fields[f.key] = field;
if (f.default !== undefined) {
if (f.kind === "select") field.select.value = f.default;
else field.input.value = String(f.default);
}
inputRegion.appendChild(field.wrap);
}
const outs = {};
for (const o of spec.outputs) outs[o.key] = makeOutputLine(outputRegion, o.label, o.id);
function fillExample(v) {
for (const f of spec.fields) {
if (v[f.key] === undefined) continue;
if (f.kind === "select") fields[f.key].select.value = v[f.key];
else fields[f.key].input.value = v[f.key];
}
update();
}
const update = debounce(() => {
const params = {};
for (const f of spec.fields) {
if (f.kind === "select") params[f.key] = fields[f.key].select.value;
// A field marked `required` passes null when blank, so the compute can
// ask for it. Blank must not become 0 where 0 is a real value (0 F).
else params[f.key] = f.required && fields[f.key].input.value === "" ? null : Number(fields[f.key].input.value) || 0;
}
const r = spec.compute(params);
if (r.error) { for (const k of Object.keys(outs)) outs[k].textContent = "-"; outs[spec.outputs[0].key].textContent = r.error; return; }
for (const o of spec.outputs) outs[o.key].textContent = o.value(r);
}, DEBOUNCE_MS);
for (const f of spec.fields) {
const el = f.kind === "select" ? fields[f.key].select : fields[f.key].input;
el.addEventListener(f.kind === "select" ? "change" : "input", update);
}
};
_hsRender.schema = {
inputs: (spec.fields || []).map((f) => ({ key: f.key, label: f.label, kind: f.kind ?? "number", options: f.options ?? null, default: f.default ?? null, attrs: f.attrs ?? (f.kind && f.kind !== "number" ? null : { step: "any", min: "0" }) })),
outputs: (spec.outputs || []).map((o) => ({ key: o.key, label: o.label, unit: o.unit ?? null, format: o.value })),
citation: spec.citation ?? null,
scope: spec.scope ?? null,
};
return _hsRender;
}
export const HVACSYSTEMS_RENDERERS = {};
// =====================================================================
// spec-v16 Group C expansion (HVAC). The first-principles batch lands
// here per spec-v16 §3 / §Z.2: C.3 chiller tonnage from delta-T and GPM,
// C.5 heat-exchanger LMTD and effectiveness-NTU, and C.9 air changes per
// hour. C.4 (cooling-tower range/approach) is substantially covered by
// the existing `cooling-tower` tile and C.1 (duct fitting equivalent
// length) by the existing `equivalent-length` tile -- see the spec-v16
// status header for the audit findings. Render functions are module-
// local; only the pure compute functions enter the v14 corpus.
// =====================================================================
const _v16h_readNum = (input) => {
if (!input || input.value === "") return null;
const n = Number(input.value);
return Number.isFinite(n) ? n : null;
};
// --- C.3 Chiller tonnage from delta-T and GPM ------------------------
// Fluid energy-balance factor: Q (BTU/hr) = gpm * factor * delta_T,
// where factor = 60 min/hr * density (lb/gal) * specific heat
// (BTU/lb-F). Water is the textbook 500. Propylene-glycol factors are
// property-derived at a typical 40-50 F chilled-water mean per ASHRAE
// Fundamentals 2021 Chapter 31 (secondary coolants); the manufacturer's
// fluid table governs final selection.
export const CHILLER_FLUID_FACTORS = {
water: 500,
glycol_30: 475, // 30% propylene glycol: ~8.6 lb/gal * 0.92 cp * 60
glycol_50: 449, // 50% propylene glycol: ~8.8 lb/gal * 0.85 cp * 60
};
// dims: in { gpm: L^3 T^-1, ewt_F: T, lwt_F: T, fluid: dimensionless, nameplate_tons: M L^2 T^-3 } out: { delta_T_F: T, q_btu_hr: M L^2 T^-3, tons: M L^2 T^-3, required_gpm: L^3 T^-1 }
export function computeChillerTons({
gpm = 0,
ewt_F = 54,
lwt_F = 44,
fluid = "water",
nameplate_tons = null,
} = {}) {
const _g = _finiteGuard(arguments[0]); if (_g) return _g;
const flow = Number(gpm) || 0;
const Te = Number(ewt_F);
const Tl = Number(lwt_F);
const factor = CHILLER_FLUID_FACTORS[fluid] ?? CHILLER_FLUID_FACTORS.water;
if (!(flow > 0)) return { error: "Enter a positive chilled-water flow (GPM)." };
if (!Number.isFinite(Te) || !Number.isFinite(Tl)) return { error: "Enter entering and leaving water temperatures." };
const delta_T_F = Te - Tl;
if (!(delta_T_F > 0)) return { error: "Entering water temperature must exceed leaving water temperature." };
const q_btu_hr = flow * factor * delta_T_F;
const tons = q_btu_hr / 12000;
const kw = q_btu_hr / 3412;
// Required flow to carry the chiller's nameplate tons at this delta-T.
const np = nameplate_tons != null && Number.isFinite(Number(nameplate_tons)) ? Number(nameplate_tons) : null;
const required_gpm = np != null && np > 0 ? (np * 12000) / (factor * delta_T_F) : null;
const warnings = [];
if (delta_T_F < 5 || delta_T_F > 20) warnings.push("Delta-T outside the 5-20 F screening band (typical 10-14 F); confirm the entering and leaving temperatures.");
if (fluid !== "water") warnings.push("Glycol factor is property-derived at a typical chilled-water mean; the manufacturer's fluid correction table governs.");
return {
delta_T_F,
factor,
q_btu_hr,
tons,
kw,
fluid,
nameplate_tons: np,
required_gpm,
warnings,
};
}
export const chillerTonsExample = {
// 240 GPM water, 54 F EWT -> 44 F LWT (10 F delta-T):
// Q = 240 * 500 * 10 = 1,200,000 BTU/hr = 100 tons exactly.
inputs: { gpm: 240, ewt_F: 54, lwt_F: 44, fluid: "water" },
};
// dims: in { dom: dimensionless } out: { dom_side_effect: dimensionless }
function _v16h_renderChillerTons(inputRegion, outputRegion, citationEl) {
citationEl.textContent = "Citation: Q (BTU/hr) = GPM x factor x delta-T; tons = Q / 12000. The water factor 500 = 60 min/hr x 8.33 lb/gal x 1 BTU/lb-F (first-principles fluid energy balance). Glycol factors per ASHRAE Fundamentals 2021 Ch. 31 (secondary coolants). Free at ashrae.org for the TOC.";
const gpm = makeNumber("Chilled-water flow (GPM)", "ct3-gpm", { step: "any", min: "0" });
const ewt = makeNumber("Entering water temp (°F)", "ct3-ewt", { step: "any" });
const lwt = makeNumber("Leaving water temp (°F)", "ct3-lwt", { step: "any" });
const fluid = makeSelect("Fluid", "ct3-fluid", [
{ value: "water", label: "Water (500)", selected: true },
{ value: "glycol_30", label: "30% propylene glycol" },
{ value: "glycol_50", label: "50% propylene glycol" },
]);
const np = makeNumber("Nameplate tons (optional)", "ct3-np", { step: "any", min: "0" });
for (const f of [gpm, ewt, lwt, fluid, np]) inputRegion.appendChild(f.wrap);
attachExampleButton(inputRegion, () => {
gpm.input.value = "240"; ewt.input.value = "54"; lwt.input.value = "44";
fluid.select.value = "water"; np.input.value = ""; update();
});
const oDt = makeOutputLine(outputRegion, "Delta-T", "ct3-out-dt");
const oTons = makeOutputLine(outputRegion, "Cooling capacity", "ct3-out-tons");
const oReq = makeOutputLine(outputRegion, "Required flow at nameplate", "ct3-out-req");
const oNote = makeOutputLine(outputRegion, "Notes", "ct3-out-note");
const update = debounce(() => {
const r = computeChillerTons({
gpm: _v16h_readNum(gpm.input),
ewt_F: _v16h_readNum(ewt.input),
lwt_F: _v16h_readNum(lwt.input),
fluid: fluid.select.value,
nameplate_tons: _v16h_readNum(np.input),
});
if (r.error) { oDt.textContent = r.error; oTons.textContent = "-"; oReq.textContent = "-"; oNote.textContent = ""; return; }
oDt.textContent = fmt(r.delta_T_F, 1) + " F (factor " + r.factor + ")";
oTons.textContent = fmt(r.tons, 1) + " tons (" + fmt(r.q_btu_hr, 0) + " BTU/hr, " + fmt(r.kw, 1) + " kW)";
oReq.textContent = r.required_gpm != null ? fmt(r.required_gpm, 1) + " GPM for " + fmt(r.nameplate_tons, 1) + " tons" : "-";
oNote.textContent = r.warnings.length ? r.warnings.join(" ") : "Within the 5-20 F screening band (typical 10-14 F).";
}, DEBOUNCE_MS);
for (const el of [gpm.input, ewt.input, lwt.input, np.input]) el.addEventListener("input", update);
fluid.select.addEventListener("change", update);
}
HVACSYSTEMS_RENDERERS["chiller-tons"] = _v16h_renderChillerTons;
// --- C.5 Heat exchanger LMTD and effectiveness-NTU -------------------
// Capacity-rate factor per fluid (BTU/hr-F per GPM) = same fluid energy
// balance as the chiller tile. C = GPM * factor.
export const HX_FLUID_FACTORS = CHILLER_FLUID_FACTORS;
// dims: in { config: dimensionless, th_in_F: T, th_out_F: T, tc_in_F: T, tc_out_F: T, hot_gpm: L^3 T^-1, cold_gpm: L^3 T^-1, hot_fluid: dimensionless, cold_fluid: dimensionless } out: { lmtd_F: T, q_btu_hr: M L^2 T^-3, ua_btu_hr_F: M L^2 T^-3, effectiveness: dimensionless, ntu: dimensionless }
export function computeHxLmtdNtu({
config = "counterflow",
th_in_F = 0,
th_out_F = 0,
tc_in_F = 0,
tc_out_F = 0,
hot_gpm = 0,
cold_gpm = 0,
hot_fluid = "water",
cold_fluid = "water",
} = {}) {
const _g = _finiteGuard(arguments[0]); if (_g) return _g;
const Thi = Number(th_in_F), Tho = Number(th_out_F);
const Tci = Number(tc_in_F), Tco = Number(tc_out_F);
const gh = Number(hot_gpm) || 0, gc = Number(cold_gpm) || 0;
if ([Thi, Tho, Tci, Tco].some((v) => !Number.isFinite(v))) return { error: "Enter all four inlet/outlet temperatures." };
if (!(Thi > Tho)) return { error: "Hot fluid must cool down (hot inlet above hot outlet)." };
if (!(Tco > Tci)) return { error: "Cold fluid must warm up (cold outlet above cold inlet)." };
if (Tco > Thi) return { error: "Cold outlet cannot exceed hot inlet (thermodynamic limit)." };
let dT1, dT2;
if (config === "parallel") {
dT1 = Thi - Tci;
dT2 = Tho - Tco;
if (!(dT2 > 0)) return { error: "Parallel-flow outlets cross (hot outlet below cold outlet is impossible)." };
} else {
// counter-flow (and a reasonable approximation entry for cross-flow)
dT1 = Thi - Tco;
dT2 = Tho - Tci;
if (!(dT1 > 0) || !(dT2 > 0)) return { error: "Temperature difference at an end is non-positive; check the temperatures." };
}
// LMTD; the limit as dT1 -> dT2 is the common difference.
const lmtd_F = Math.abs(dT1 - dT2) < 1e-9 ? dT1 : (dT1 - dT2) / Math.log(dT1 / dT2);
const fh = HX_FLUID_FACTORS[hot_fluid] ?? 500;
const fc = HX_FLUID_FACTORS[cold_fluid] ?? 500;
const Ch = gh > 0 ? gh * fh : null; // BTU/hr-F
const Cc = gc > 0 ? gc * fc : null;
// Heat duty from the hot side if its flow is known, else the cold side.
let q_btu_hr = null;
if (Ch != null) q_btu_hr = Ch * (Thi - Tho);
else if (Cc != null) q_btu_hr = Cc * (Tco - Tci);
const ua_btu_hr_F = q_btu_hr != null && lmtd_F > 0 ? q_btu_hr / lmtd_F : null;
let effectiveness = null, ntu = null, cr = null, c_min = null;
if (Ch != null && Cc != null) {
c_min = Math.min(Ch, Cc);
const c_max = Math.max(Ch, Cc);
cr = c_min / c_max;
const q_max = c_min * (Thi - Tci);
effectiveness = q_max > 1e-9 ? q_btu_hr / q_max : null;
ntu = ua_btu_hr_F != null ? ua_btu_hr_F / c_min : null;
}
const warnings = [];
if (config === "parallel" && effectiveness != null && effectiveness > 0.75) warnings.push("Parallel-flow effectiveness above ~0.75 is unusual; a counter-flow arrangement reaches higher effectiveness for the same area.");
if (Ch == null && Cc == null) warnings.push("Enter at least one side's flow (GPM) to compute heat duty, UA, effectiveness, and NTU.");
return {
config,
dT1,
dT2,
lmtd_F,
c_hot: Ch,
c_cold: Cc,
c_ratio: cr,
q_btu_hr,
ua_btu_hr_F,
effectiveness,
ntu,
warnings,
};
}
export const hxLmtdNtuExample = {
// Counter-flow water/water: hot 200->100 F at 50 GPM (C_h = 25,000),
// cold 60->140 F at 62.5 GPM (C_c = 31,250). LMTD = (60-40)/ln(60/40)
// = 49.33 F; Q = 2,500,000 BTU/hr; UA = 50,683; C_min = 25,000;
// effectiveness = 2.5e6/3.5e6 = 0.7143; NTU = 2.027.
inputs: {
config: "counterflow",
th_in_F: 200, th_out_F: 100, tc_in_F: 60, tc_out_F: 140,
hot_gpm: 50, cold_gpm: 62.5,
},
};
const _v16h_HX_FLUIDS = [
{ value: "water", label: "Water" },
{ value: "glycol_30", label: "30% propylene glycol" },
{ value: "glycol_50", label: "50% propylene glycol" },
];
// dims: in { dom: dimensionless } out: { dom_side_effect: dimensionless }
function _v16h_renderHxLmtdNtu(inputRegion, outputRegion, citationEl) {
citationEl.textContent = "Citation: LMTD = (dT1 - dT2) / ln(dT1/dT2); Q = C x delta-T with C = GPM x fluid factor; UA = Q / LMTD; effectiveness = Q / (C_min x (Th_in - Tc_in)); NTU = UA / C_min. Per the TEMA standards and standard heat-transfer texts (Incropera, Cengel). Free at tema.org for the standards TOC.";
const config = makeSelect("Flow configuration", "hx-config", [
{ value: "counterflow", label: "Counter-flow", selected: true },
{ value: "parallel", label: "Parallel-flow" },
]);
const thi = makeNumber("Hot inlet (°F)", "hx-thi", { step: "any" });
const tho = makeNumber("Hot outlet (°F)", "hx-tho", { step: "any" });
const tci = makeNumber("Cold inlet (°F)", "hx-tci", { step: "any" });
const tco = makeNumber("Cold outlet (°F)", "hx-tco", { step: "any" });
const hg = makeNumber("Hot flow (GPM)", "hx-hg", { step: "any", min: "0" });
const cg = makeNumber("Cold flow (GPM)", "hx-cg", { step: "any", min: "0" });
const hf = makeSelect("Hot fluid", "hx-hf", _v16h_HX_FLUIDS.map((o) => ({ ...o })));
const cf = makeSelect("Cold fluid", "hx-cf", _v16h_HX_FLUIDS.map((o) => ({ ...o })));
for (const f of [config, thi, tho, tci, tco, hg, cg, hf, cf]) inputRegion.appendChild(f.wrap);
attachExampleButton(inputRegion, () => {
config.select.value = "counterflow";
thi.input.value = "200"; tho.input.value = "100"; tci.input.value = "60"; tco.input.value = "140";
hg.input.value = "50"; cg.input.value = "62.5"; hf.select.value = "water"; cf.select.value = "water"; update();
});
const oLmtd = makeOutputLine(outputRegion, "LMTD", "hx-out-lmtd");
const oQ = makeOutputLine(outputRegion, "Heat duty", "hx-out-q");
const oUa = makeOutputLine(outputRegion, "Required UA", "hx-out-ua");
const oEff = makeOutputLine(outputRegion, "Effectiveness / NTU", "hx-out-eff");
const oNote = makeOutputLine(outputRegion, "Notes", "hx-out-note");
const update = debounce(() => {
const r = computeHxLmtdNtu({
config: config.select.value,
th_in_F: _v16h_readNum(thi.input), th_out_F: _v16h_readNum(tho.input),
tc_in_F: _v16h_readNum(tci.input), tc_out_F: _v16h_readNum(tco.input),
hot_gpm: _v16h_readNum(hg.input), cold_gpm: _v16h_readNum(cg.input),
hot_fluid: hf.select.value, cold_fluid: cf.select.value,
});
if (r.error) { oLmtd.textContent = r.error; oQ.textContent = "-"; oUa.textContent = "-"; oEff.textContent = "-"; oNote.textContent = ""; return; }
oLmtd.textContent = fmt(r.lmtd_F, 2) + " F";
oQ.textContent = r.q_btu_hr != null ? fmt(r.q_btu_hr, 0) + " BTU/hr" : "enter a flow";
oUa.textContent = r.ua_btu_hr_F != null ? fmt(r.ua_btu_hr_F, 0) + " BTU/hr-F" : "-";
oEff.textContent = r.effectiveness != null ? fmt(r.effectiveness, 3) + " / NTU " + fmt(r.ntu, 2) + " (Cr " + fmt(r.c_ratio, 2) + ")" : "enter both flows";
oNote.textContent = r.warnings.length ? r.warnings.join(" ") : "Sized from the four temperatures and the entered flows.";
}, DEBOUNCE_MS);
for (const el of [thi.input, tho.input, tci.input, tco.input, hg.input, cg.input]) el.addEventListener("input", update);
for (const s of [config.select, hf.select, cf.select]) s.addEventListener("change", update);
}
HVACSYSTEMS_RENDERERS["hx-lmtd-ntu"] = _v16h_renderHxLmtdNtu;
// --- C.9 Air changes per hour from CFM and room volume ---------------
// Typical ACH design targets by occupancy (ASHRAE 62.1-2022 ventilation
// and ASHRAE 170-2021 healthcare). Most are comparison bands; the patient-room and OR entries are ASHRAE 170 Table 7-1
// minimums with no ceiling. None is the code minimum for a specific project; the AHJ and the governing
// standard's full procedure govern.
export const ACH_TARGET_BANDS = {
residential: { lo: 0.35, hi: 1, label: "Residential whole-house ventilation (the older ASHRAE 62-1989 0.35 ACH figure; 62.2 sets a cfm rate instead)" },
office: { lo: 4, hi: 10, label: "Office / commercial" },
classroom: { lo: 4, hi: 6, label: "Classroom (ASHRAE 62.1)" },
lab: { lo: 6, hi: 12, label: "Laboratory" },
// ASHRAE 170 Table 7-1 sets MINIMUM total air changes with no ceiling: patient room 4 (6 for a
// single-bed room with Group D diffusers, note y), operating room 20. Until 2026-09-25 these
// were 6-6 and 20-25, which failed a compliant 4-6 ACH patient room and a 30 ACH OR.
patient_room: { lo: 4, hi: Infinity, label: "Hospital patient room (ASHRAE 170 minimum; 6 with Group D diffusers)" },
operating_room: { lo: 20, hi: Infinity, label: "Operating room (ASHRAE 170 minimum)" },
};
// dims: in { volume_ft3: L^3, supply_cfm: L^3 T^-1, return_cfm: L^3 T^-1, occupancy: dimensionless } out: { ach: T^-1, net_ach: T^-1, pressurization_cfm: L^3 T^-1 }
export function computeAirChangesPerHour({
volume_ft3 = 0,
supply_cfm = 0,
return_cfm = null,
occupancy = "classroom",
} = {}) {
const _g = _finiteGuard(arguments[0]); if (_g) return _g;
const vol = Number(volume_ft3) || 0;
const supply = Number(supply_cfm) || 0;
const ret = return_cfm != null && Number.isFinite(Number(return_cfm)) ? Number(return_cfm) : supply;
if (!(vol > 0)) return { error: "Enter a positive room volume (ft^3)." };
if (!(supply > 0)) return { error: "Enter a positive supply CFM." };
const ach = (supply * 60) / vol;
// Net delivered air change is governed by the smaller of supply and
// return; the difference is the pressurization (exfiltration) airflow.
const net_cfm = Math.min(supply, ret);
const net_ach = (net_cfm * 60) / vol;
const pressurization_cfm = supply - ret;
const band = ACH_TARGET_BANDS[occupancy] ?? ACH_TARGET_BANDS.classroom;
let comparison;
if (band.hi === Infinity) comparison = (ach < band.lo ? "below the " : "meets the ") + band.lo + " ACH minimum (" + band.label + ")";
else if (ach < band.lo) comparison = "below the " + band.lo + "-" + band.hi + " ACH target (" + band.label + ")";
else if (ach > band.hi) comparison = "above the " + band.lo + "-" + band.hi + " ACH target (" + band.label + ")";
else comparison = "within the " + band.lo + "-" + band.hi + " ACH target (" + band.label + ")";
let pressure_state;
if (pressurization_cfm > 1e-9) pressure_state = "positively pressurized (" + fmt(pressurization_cfm, 0) + " CFM exfiltration)";
else if (pressurization_cfm < -1e-9) pressure_state = "negatively pressurized (" + fmt(-pressurization_cfm, 0) + " CFM infiltration)";
else pressure_state = "balanced (supply = return)";
const warnings = [];
if (vol < 100) warnings.push("Room volume below 100 ft^3 is outside the typical range; confirm the dimensions.");
if (ach > 50) warnings.push("ACH above 50 is outside the typical HVAC range; confirm the CFM and volume.");
return {
volume_ft3: vol,
supply_cfm: supply,
return_cfm: ret,
ach,
net_ach,
pressurization_cfm,
pressure_state,
band: band.label,
comparison,
warnings,
};
}
export const airChangesPerHourExample = {
// 10,000 ft^3 classroom, 1,000 CFM supply, balanced return:
// ACH = 1000 * 60 / 10000 = 6.0, within the 4-6 classroom target.
inputs: { volume_ft3: 10000, supply_cfm: 1000, occupancy: "classroom" },
};
// dims: in { dom: dimensionless } out: { dom_side_effect: dimensionless }
function _v16h_renderAirChangesPerHour(inputRegion, outputRegion, citationEl) {
citationEl.textContent = "Citation: ACH = supply CFM x 60 / room volume (ft^3). Net delivered ACH uses the smaller of supply and return; their difference is the pressurization airflow. Target bands per ASHRAE 62.1-2022 (ventilation) and ASHRAE 170-2021 (healthcare). AHJ and the governing standard's full procedure govern. Free at ashrae.org for the TOCs.";
const vol = makeNumber("Room volume (ft³)", "ach-vol", { step: "any", min: "0" });
const supply = makeNumber("Supply CFM", "ach-supply", { step: "any", min: "0" });
const ret = makeNumber("Return CFM (blank = supply)", "ach-return", { step: "any", min: "0" });
const occ = makeSelect("Occupancy (comparison band)", "ach-occ", [
{ value: "residential", label: "Residential (0.35-1)" },
{ value: "office", label: "Office (4-10)" },
{ value: "classroom", label: "Classroom (4-6)", selected: true },
{ value: "lab", label: "Laboratory (6-12)" },
{ value: "patient_room", label: "Patient room (4 minimum; 6 with Group D diffusers)" },
{ value: "operating_room", label: "Operating room (20 minimum)" },
]);
for (const f of [vol, supply, ret, occ]) inputRegion.appendChild(f.wrap);
attachExampleButton(inputRegion, () => {
vol.input.value = "10000"; supply.input.value = "1000"; ret.input.value = "";
occ.select.value = "classroom"; update();
});
const oAch = makeOutputLine(outputRegion, "Air changes per hour", "ach-out-ach");
const oNet = makeOutputLine(outputRegion, "Net / pressurization", "ach-out-net");
const oBand = makeOutputLine(outputRegion, "Comparison", "ach-out-band");
const oNote = makeOutputLine(outputRegion, "Notes", "ach-out-note");
const update = debounce(() => {
const r = computeAirChangesPerHour({
volume_ft3: _v16h_readNum(vol.input),
supply_cfm: _v16h_readNum(supply.input),
return_cfm: _v16h_readNum(ret.input),
occupancy: occ.select.value,
});
if (r.error) { oAch.textContent = r.error; oNet.textContent = "-"; oBand.textContent = "-"; oNote.textContent = ""; return; }
oAch.textContent = fmt(r.ach, 2) + " ACH";
oNet.textContent = fmt(r.net_ach, 2) + " net ACH; " + r.pressure_state;
oBand.textContent = r.comparison;
oNote.textContent = r.warnings.length ? r.warnings.join(" ") : "ACH compared against the selected occupancy target.";
}, DEBOUNCE_MS);
for (const el of [vol.input, supply.input, ret.input]) el.addEventListener("input", update);
occ.select.addEventListener("change", update);
}
HVACSYSTEMS_RENDERERS["air-changes-hour"] = _v16h_renderAirChangesPerHour;
// --- C.6 Hot water boiler distribution pipe sizing -------------------
// Standard inner diameters (in) by material and nominal trade size.
// Copper Type L (ASTM B88) and Steel Schedule 40 (ASTM A53) are
// published dimensional standards; PEX is ASTM F876 SDR-9 nominal. The
// Hazen-Williams roughness coefficient C is the water-flow value for
// each material (copper/PEX smooth ~150; black steel ~130).
export const BOILER_PIPE_TABLE = {
copper: {
label: "Copper Type L",
c: 150,
sizes: [
{ size: "1/2", id_in: 0.545 }, { size: "3/4", id_in: 0.785 },
{ size: "1", id_in: 1.025 }, { size: "1-1/4", id_in: 1.265 },
{ size: "1-1/2", id_in: 1.505 }, { size: "2", id_in: 1.985 },
{ size: "2-1/2", id_in: 2.465 }, { size: "3", id_in: 2.945 },
],
},
steel: {
label: "Steel Schedule 40",
c: 130,
sizes: [
{ size: "1/2", id_in: 0.622 }, { size: "3/4", id_in: 0.824 },
{ size: "1", id_in: 1.049 }, { size: "1-1/4", id_in: 1.380 },
{ size: "1-1/2", id_in: 1.610 }, { size: "2", id_in: 2.067 },
{ size: "2-1/2", id_in: 2.469 }, { size: "3", id_in: 3.068 },
],
},
pex: {
label: "PEX (SDR-9)",
c: 150,
sizes: [
{ size: "1/2", id_in: 0.475 }, { size: "3/4", id_in: 0.671 },
{ size: "1", id_in: 0.863 }, { size: "1-1/4", id_in: 1.053 },
{ size: "1-1/2", id_in: 1.243 }, { size: "2", id_in: 1.629 },
],
},
};
// Default quiet-operation velocity ceiling (ft/sec) by material.
export const BOILER_PIPE_VMAX = { copper: 4, steel: 6, pex: 3 };
// Velocity (ft/sec) of `gpm` through a pipe of inner diameter `id_in`.
// v = gpm / (2.44778 * d^2): A(ft^2) * 448.831 gal/(ft^3·min) inverted.
function _v16h_pipeVelocityFps(gpm, id_in) {
return id_in > 0 ? gpm / (2.44778 * id_in * id_in) : Infinity;
}
// dims: in { boiler_btu_hr: M L^2 T^-3, delta_T_F: T, material: dimensionless, max_velocity_fps: L T^-1, length_ft: L } out: { gpm: L^3 T^-1, velocity_fps: L T^-1, friction_ft_per_100ft: dimensionless, head_ft: L }
export function computeBoilerPipeSizing({
boiler_btu_hr = 0,
delta_T_F = 20,
material = "copper",
max_velocity_fps = null,
length_ft = 100,
} = {}) {
const _g = _finiteGuard(arguments[0]); if (_g) return _g;
const Q = Number(boiler_btu_hr) || 0;
const dT = Number(delta_T_F) || 0;
const tbl = BOILER_PIPE_TABLE[material] ?? BOILER_PIPE_TABLE.copper;
const vmax = max_velocity_fps != null && Number.isFinite(Number(max_velocity_fps)) && Number(max_velocity_fps) > 0
? Number(max_velocity_fps)
: (BOILER_PIPE_VMAX[material] ?? 4);
const len = Number(length_ft);
if (!(Q > 0)) return { error: "Enter a positive boiler output (BTU/hr)." };
if (!(dT > 0)) return { error: "Enter a positive supply-return delta-T (F)." };
// Hydronic energy balance: GPM = Q / (500 * delta-T) for water.
const gpm = Q / (500 * dT);
// Smallest table size whose velocity is at or below the ceiling.
let pick = null;
for (const s of tbl.sizes) {
if (_v16h_pipeVelocityFps(gpm, s.id_in) <= vmax) { pick = s; break; }
}
const oversize = pick == null;
if (oversize) pick = tbl.sizes[tbl.sizes.length - 1];
const velocity_fps = _v16h_pipeVelocityFps(gpm, pick.id_in);
// Hazen-Williams head loss (ft) per 100 ft at the recommended size.
const friction_ft_per_100ft = hazenWilliamsFrictionLoss({
flow_gpm: gpm, internal_diameter_in: pick.id_in, length_ft: 100, C: tbl.c,
});
const runLen = Number.isFinite(len) && len > 0 ? len : 0;
const head_ft = friction_ft_per_100ft * (runLen / 100);
const warnings = [];
if (dT < 10 || dT > 40) warnings.push("Delta-T outside the typical 10-40 F hydronic range; high-delta-T commercial systems exist but are non-default.");
if (oversize) warnings.push("Flow exceeds the largest tabulated " + tbl.label + " size (" + pick.size + " in) at the velocity ceiling; parallel mains or a larger main are required.");
return {
gpm,
material,
material_label: tbl.label,
max_velocity_fps: vmax,
recommended_size: pick.size,
recommended_id_in: pick.id_in,
velocity_fps,
friction_ft_per_100ft,
length_ft: runLen,
head_ft,
oversize,
warnings,
};
}
export const boilerPipeSizingExample = {
// 200,000 BTU/hr boiler, 20 F delta-T -> 20 GPM. Copper Type L at a
// 4 ft/s quiet-operation ceiling: 1-1/4 in (ID 1.265) runs 5.11 ft/s
// (over), so the tile steps up to 1-1/2 in (ID 1.505) at 3.61 ft/s.
// Hazen-Williams (C=150): 3.42 ft head (1.48 psi) per 100 ft; 100 ft run -> 3.42 ft.
inputs: { boiler_btu_hr: 200000, delta_T_F: 20, material: "copper", max_velocity_fps: 4, length_ft: 100 },
};
// dims: in { dom: dimensionless } out: { dom_side_effect: dimensionless }
function _v16h_renderBoilerPipeSizing(inputRegion, outputRegion, citationEl) {
citationEl.textContent = "Citation: GPM = Q / (500 x delta-T) (hydronic water energy balance); velocity = GPM / (2.448 x d^2); the smallest standard size at or below the velocity ceiling is recommended; head loss per Hazen-Williams (public domain, 1905). Per ASHRAE Systems and Equipment 2020 Ch. 13 (hydronic heating) with Bell & Gossett / Taco velocity limits. Free at ashrae.org for the TOC.";
const q = makeNumber("Boiler output (BTU/hr)", "bp6-q", { step: "any", min: "0", value: "200000" });
const dt = makeNumber("Supply-return delta-T (°F)", "bp6-dt", { step: "any", min: "0", value: "20" });
const mat = makeSelect("Pipe material", "bp6-mat", [
{ value: "copper", label: "Copper Type L (4 ft/s)", selected: true },
{ value: "steel", label: "Steel Schedule 40 (6 ft/s)" },
{ value: "pex", label: "PEX SDR-9 (3 ft/s)" },
]);
const vmax = makeNumber("Max velocity (ft/s, blank = material default)", "bp6-vmax", { step: "any", min: "0" });
const len = makeNumber("Run length one-way (ft)", "bp6-len", { step: "any", min: "0", value: "100" });
for (const f of [q, dt, mat, vmax, len]) inputRegion.appendChild(f.wrap);
attachExampleButton(inputRegion, () => {
q.input.value = "200000"; dt.input.value = "20"; mat.select.value = "copper";
vmax.input.value = "4"; len.input.value = "100"; update();
});
const oGpm = makeOutputLine(outputRegion, "Required flow", "bp6-out-gpm");
const oSize = makeOutputLine(outputRegion, "Recommended size", "bp6-out-size");
const oVel = makeOutputLine(outputRegion, "Velocity", "bp6-out-vel");
const oFric = makeOutputLine(outputRegion, "Friction / pump head", "bp6-out-fric");
const oNote = makeOutputLine(outputRegion, "Notes", "bp6-out-note");
const update = debounce(() => {
const r = computeBoilerPipeSizing({
boiler_btu_hr: _v16h_readNum(q.input),
delta_T_F: _v16h_readNum(dt.input),
material: mat.select.value,
max_velocity_fps: _v16h_readNum(vmax.input),
length_ft: _v16h_readNum(len.input),
});
if (r.error) { oGpm.textContent = r.error; oSize.textContent = "-"; oVel.textContent = "-"; oFric.textContent = "-"; oNote.textContent = ""; return; }
oGpm.textContent = fmt(r.gpm, 1) + " GPM";
oSize.textContent = r.recommended_size + " in " + r.material_label + " (ID " + fmt(r.recommended_id_in, 3) + " in)";
oVel.textContent = fmt(r.velocity_fps, 2) + " ft/s (ceiling " + fmt(r.max_velocity_fps, 0) + " ft/s)";
oFric.textContent = fmt(r.friction_ft_per_100ft, 2) + " ft/100 ft; pump head " + fmt(r.head_ft, 2) + " ft at " + fmt(r.length_ft, 0) + " ft";
oNote.textContent = r.warnings.length ? r.warnings.join(" ") : "Sized at or below the velocity ceiling; add fitting equivalent length for the final pump head.";
}, DEBOUNCE_MS);
for (const el of [q.input, dt.input, vmax.input, len.input]) el.addEventListener("input", update);
mat.select.addEventListener("change", update);
}
HVACSYSTEMS_RENDERERS["boiler-pipe-sizing"] = _v16h_renderBoilerPipeSizing;
// --- C.8 Compressor short-cycle protection minimum runtime -----------
// Protection thresholds by system type. min_on (oil return / latent
// removal), min_off (high/low pressure equalization), and the
// maximum cycles per hour the cycling-rate parabola peaks at. Inverter
// systems modulate capacity and do not cycle the compressor the same
// way; their limits are per-manufacturer. Copeland Application
// Engineering Bulletin 17-1226 and ASHRAE Fundamentals 2021.
export const COMPRESSOR_CYCLE_LIMITS = {
single: { label: "Single-stage", min_on_min: 10, min_off_min: 5, max_cph: 6 },
two_stage: { label: "Two-stage", min_on_min: 8, min_off_min: 5, max_cph: 8 },
inverter: { label: "VRF / inverter", min_on_min: 4, min_off_min: 3, max_cph: null },
};
// dims: in { system_type: dimensionless, load_fraction_pct: dimensionless, observed_cph: T^-1 } out: { cph_estimated: T^-1, on_time_min: T, off_time_min: T }
export function computeCompressorShortCycle({
system_type = "single",
load_fraction_pct = 50,
observed_cph = null,
} = {}) {
const lim = COMPRESSOR_CYCLE_LIMITS[system_type] ?? COMPRESSOR_CYCLE_LIMITS.single;
const lf = Number(load_fraction_pct);
if (!Number.isFinite(lf) || lf <= 0 || lf >= 100) return { error: "Enter a load fraction between 0 and 100 percent (the part-load operating point)." };
const x = lf / 100;
// Cycling-rate parabola (ASHRAE/AHRI part-load model): the cycle rate
// peaks at the 50% runtime fraction and falls to zero at 0% and 100%.
// N(x) = N_max * 4 * x * (1 - x). Inverter systems modulate instead of
// cycling, so the parabola does not apply.
let cph_estimated = null, on_time_min = null, off_time_min = null;
if (lim.max_cph != null) {
cph_estimated = lim.max_cph * 4 * x * (1 - x);
if (cph_estimated > 1e-9) {
on_time_min = (x * 60) / cph_estimated;
off_time_min = ((1 - x) * 60) / cph_estimated;
}
}
const obs = observed_cph != null && Number.isFinite(Number(observed_cph)) && Number(observed_cph) > 0 ? Number(observed_cph) : null;
const flags = [];
let short_cycling = false;
if (lim.max_cph == null) {
flags.push("Inverter / VRF systems modulate capacity rather than cycle; minimum on-time " + lim.min_on_min + " min per the manufacturer, no fixed cycles-per-hour ceiling.");
} else {
if (on_time_min != null && on_time_min < lim.min_on_min) {
short_cycling = true;
flags.push("Estimated on-time " + on_time_min.toFixed(1) + " min is below the " + lim.min_on_min + "-min oil-return / dehumidification runtime; the unit is oversized for this load and will short-cycle.");
}
if (off_time_min != null && off_time_min < lim.min_off_min) {
flags.push("Estimated off-time below the " + lim.min_off_min + "-min pressure-equalization delay; a hard-start anti-short-cycle timer is indicated.");
}
if (obs != null && obs > lim.max_cph) {
short_cycling = true;
flags.push("Observed " + obs + " cycles/hr exceeds the " + lim.max_cph + " cph ceiling; check the thermostat differential and refrigerant charge.");
}
}
return {
system_type,
system_label: lim.label,
load_fraction_pct: lf,
min_runtime_min: lim.min_on_min,
min_off_min: lim.min_off_min,
max_cph: lim.max_cph,
cph_estimated,
on_time_min,
off_time_min,
observed_cph: obs,
short_cycling,
flags,
};
}
export const compressorShortCycleExample = {
// Single-stage at 50% load: the cycling parabola peaks at the 6 cph
// ceiling, on-time = 0.5 * 60 / 6 = 5 min, below the 10-min oil-return
// runtime -> short-cycling flagged (the classic oversized-unit case).
inputs: { system_type: "single", load_fraction_pct: 50 },
};
// dims: in { dom: dimensionless } out: { dom_side_effect: dimensionless }
function _v16h_renderCompressorShortCycle(inputRegion, outputRegion, citationEl) {
citationEl.textContent = "Citation: cycle rate N = N_max x 4 x X x (1 - X) where X is the runtime (load) fraction (the ASHRAE/AHRI part-load cycling model, peaking at 50% load); on-time = X x 60 / N. Minimum runtime and pressure-equalization delays per the Copeland Application Engineering Bulletin 17-1226 and ASHRAE Fundamentals 2021. Per-manufacturer guidance governs inverter systems. Free at copeland.com/literature.";
const sys = makeSelect("System type", "cc8-sys", [
{ value: "single", label: "Single-stage", selected: true },
{ value: "two_stage", label: "Two-stage" },
{ value: "inverter", label: "VRF / inverter" },
]);
const lf = makeNumber("Load fraction (% of design)", "cc8-lf", { step: "any", min: "0", max: "100" });
const obs = makeNumber("Observed cycles/hr (optional)", "cc8-obs", { step: "any", min: "0" });
for (const f of [sys, lf, obs]) inputRegion.appendChild(f.wrap);
attachExampleButton(inputRegion, () => {
sys.select.value = "single"; lf.input.value = "50"; obs.input.value = ""; update();
});
const oCph = makeOutputLine(outputRegion, "Estimated cycles/hr", "cc8-out-cph");
const oOn = makeOutputLine(outputRegion, "On / off time", "cc8-out-on");
const oMin = makeOutputLine(outputRegion, "Minimum runtime", "cc8-out-min");
const oNote = makeOutputLine(outputRegion, "Notes", "cc8-out-note");
const update = debounce(() => {
const r = computeCompressorShortCycle({
system_type: sys.select.value,
load_fraction_pct: _v16h_readNum(lf.input),
observed_cph: _v16h_readNum(obs.input),
});
if (r.error) { oCph.textContent = r.error; oOn.textContent = "-"; oMin.textContent = "-"; oNote.textContent = ""; return; }
oCph.textContent = r.cph_estimated != null ? fmt(r.cph_estimated, 2) + " cph (ceiling " + r.max_cph + ")" : "modulates (no fixed ceiling)";
oOn.textContent = r.on_time_min != null ? fmt(r.on_time_min, 1) + " min on / " + fmt(r.off_time_min, 1) + " min off" : "-";
oMin.textContent = fmt(r.min_runtime_min, 0) + " min on (oil return), " + fmt(r.min_off_min, 0) + " min off (equalization)";
oNote.textContent = r.flags.length ? r.flags.join(" ") : "On-time meets the minimum runtime at this load fraction.";
}, DEBOUNCE_MS);
for (const el of [lf.input, obs.input]) el.addEventListener("input", update);
sys.select.addEventListener("change", update);
}
HVACSYSTEMS_RENDERERS["compressor-short-cycle"] = _v16h_renderCompressorShortCycle;
// --- C.10 Humidifier capacity (lb/hr from RH target) -----------------
// Humidity ratio (lb water / lb dry air) from dry-bulb (F) and relative
// humidity (%) at total pressure P (kPa). W = 0.621945 * Pw / (P - Pw),
// Pw = RH * Pws(T). ASHRAE Fundamentals 2021 Ch. 1.
function _v16h_humidityRatioFromRH({ T_db_F, rh_pct, P_kPa }) {
const T_C = (T_db_F - 32) * 5 / 9;
const Pws = _v9_satPressure_kPa(T_C);
const Pw = (rh_pct / 100) * Pws;
if (Pw >= P_kPa) return null;
return 0.621945 * Pw / (P_kPa - Pw);
}
// Latent heat of vaporization of water near room temperature (BTU/lb).
const _V16H_HFG_BTU_LB = 1061;
// dims: in { cfm: L^3 T^-1, supply_db_F: T, entering_rh_pct: dimensionless, target_rh_pct: dimensionless, altitude_ft: L } out: { addition_lb_hr: M T^-1, gpd: L^3 T^-1, latent_btu_hr: M L^2 T^-3 }
export function computeHumidifierCapacity({
cfm = 0,
supply_db_F = 70,
entering_rh_pct = 20,
target_rh_pct = 40,
altitude_ft = 0,
} = {}) {
const _g = _finiteGuard(arguments[0]); if (_g) return _g;
const CFM = Number(cfm) || 0;
const Tdb = Number(supply_db_F);
const rhIn = Number(entering_rh_pct);
const rhTgt = Number(target_rh_pct);
const z = Number(altitude_ft) || 0;
if (!(CFM > 0)) return { error: "Enter a positive supply airflow (CFM)." };
if (!Number.isFinite(Tdb)) return { error: "Enter the supply-air dry-bulb temperature (F)." };
if (!Number.isFinite(rhIn) || !Number.isFinite(rhTgt) || rhIn < 0 || rhTgt <= 0) return { error: "Enter entering and target relative humidity (percent)." };
if (rhTgt <= rhIn) return { error: "Target RH must exceed entering RH (a humidifier adds moisture)." };
const P_kPa = _v9_pressureAtAltitude_kPa(z);
const W_in = _v16h_humidityRatioFromRH({ T_db_F: Tdb, rh_pct: rhIn, P_kPa });
const W_tgt = _v16h_humidityRatioFromRH({ T_db_F: Tdb, rh_pct: rhTgt, P_kPa });
if (W_in == null || W_tgt == null) return { error: "Saturation reached at this temperature and pressure; check the inputs." };
const dW = W_tgt - W_in;
// Dry-air density (lb/ft^3) at the altitude pressure and dry-bulb temp.
const T_K = (Tdb - 32) * 5 / 9 + 273.15;
const rho_kg_m3 = (P_kPa * 1000) / (287.055 * T_K);
const rho_lb_ft3 = rho_kg_m3 * (0.3048 * 0.3048 * 0.3048 / 0.45359237);
const m_dot_air_lb_hr = 60 * CFM * rho_lb_ft3;
const addition_lb_hr = m_dot_air_lb_hr * dW;
const gpd = (addition_lb_hr * 24) / 8.34;
const latent_btu_hr = addition_lb_hr * _V16H_HFG_BTU_LB;
const warnings = [];
if (rhTgt > 60) warnings.push("Target RH above 60% risks condensation on cold surfaces and windows; confirm the building envelope.");
if (z < 0 || z > 12000) warnings.push("Altitude " + z + " ft is outside the standard-atmosphere correction's typical range (0-12,000 ft).");
return {
cfm: CFM,
supply_db_F: Tdb,
altitude_ft: z,
pressure_kPa: P_kPa,
W_entering: W_in,
W_target: W_tgt,
delta_W: dW,
air_density_lb_ft3: rho_lb_ft3,
addition_lb_hr,
gpd,
latent_btu_hr,
warnings,
};
}
export const humidifierCapacityExample = {
// 1,000 CFM, 70 F supply, 20% -> 40% RH at sea level. W rises from
// ~0.00308 to ~0.00620 lb/lb; dry-air density ~0.0749 lb/ft^3;
// m_dot = 60*1000*0.0749 = 4,493 lb/hr; addition ~13.99 lb/hr ~ 40 gpd;
// latent ~14,850 BTU/hr.
inputs: { cfm: 1000, supply_db_F: 70, entering_rh_pct: 20, target_rh_pct: 40, altitude_ft: 0 },
};
// dims: in { dom: dimensionless } out: { dom_side_effect: dimensionless }
function _v16h_renderHumidifierCapacity(inputRegion, outputRegion, citationEl) {
citationEl.textContent = "Citation: addition (lb/hr) = 60 x CFM x rho x (W_target - W_entering), with W from dry-bulb and RH at the altitude-corrected pressure; latent load = addition x 1061 BTU/lb. Per ASHRAE Fundamentals 2021 Ch. 1 (psychrometrics). AHJ and the manufacturer's published humidifier capacity govern actual delivery. Free at ashrae.org for the TOC.";
const cfm = makeNumber("Supply airflow (CFM)", "hc10-cfm", { step: "any", min: "0" });
const db = makeNumber("Supply dry-bulb (°F)", "hc10-db", { step: "any" });
const rin = makeNumber("Entering RH (%)", "hc10-rin", { step: "any", min: "0", max: "100" });
const rtg = makeNumber("Target RH (%)", "hc10-rtg", { step: "any", min: "0", max: "100" });
const alt = makeNumber("Altitude (ft)", "hc10-alt", { step: "any" });
for (const f of [cfm, db, rin, rtg, alt]) inputRegion.appendChild(f.wrap);
attachExampleButton(inputRegion, () => {
cfm.input.value = "1000"; db.input.value = "70"; rin.input.value = "20"; rtg.input.value = "40"; alt.input.value = "0"; update();
});
const oAdd = makeOutputLine(outputRegion, "Moisture addition", "hc10-out-add");
const oGpd = makeOutputLine(outputRegion, "Daily water", "hc10-out-gpd");
const oLat = makeOutputLine(outputRegion, "Latent load added", "hc10-out-lat");
const oNote = makeOutputLine(outputRegion, "Notes", "hc10-out-note");
const update = debounce(() => {
const r = computeHumidifierCapacity({
cfm: _v16h_readNum(cfm.input),
supply_db_F: _v16h_readNum(db.input),
entering_rh_pct: _v16h_readNum(rin.input),
target_rh_pct: _v16h_readNum(rtg.input),
altitude_ft: _v16h_readNum(alt.input),
});
if (r.error) { oAdd.textContent = r.error; oGpd.textContent = "-"; oLat.textContent = "-"; oNote.textContent = ""; return; }
oAdd.textContent = fmt(r.addition_lb_hr, 1) + " lb/hr (delta-W " + fmt(r.delta_W * 7000, 1) + " gr/lb)";
oGpd.textContent = fmt(r.gpd, 1) + " gal/day";
oLat.textContent = fmt(r.latent_btu_hr, 0) + " BTU/hr";
oNote.textContent = r.warnings.length ? r.warnings.join(" ") : "Required steam or evaporative output; the manufacturer's capacity governs delivery.";
}, DEBOUNCE_MS);
for (const el of [cfm.input, db.input, rin.input, rtg.input, alt.input]) el.addEventListener("input", update);
}
HVACSYSTEMS_RENDERERS["humidifier-capacity"] = _v16h_renderHumidifierCapacity;
// --- C.7 Filter pressure-drop schedule and fan-energy penalty --------
// Representative clean and change-out (final) pressure drops (in. WC) by
// filter class at a 300 fpm reference face velocity, from typical
// manufacturer cut sheets for 2-4 in pleated media (the MERV rating
// itself is defined by ASHRAE 52.2; the cut sheet, not the test method,
// publishes the pressure drop). These are user-overridable defaults, not
// a fixed reference table; the actual filter's cut sheet governs.
export const FILTER_DP_TABLE = {
merv8: { label: "MERV 8", clean_dp: 0.20, final_dp: 0.50 },
merv11: { label: "MERV 11", clean_dp: 0.28, final_dp: 0.60 },
merv13: { label: "MERV 13", clean_dp: 0.35, final_dp: 0.70 },
merv16: { label: "MERV 16", clean_dp: 0.55, final_dp: 1.00 },
hepa: { label: "HEPA", clean_dp: 1.00, final_dp: 2.00 },
};
// Reference face velocity (fpm) the bundled clean/final drops are quoted
// at. Pressure drop through fibrous media scales ~linearly with face
// velocity in the operating range (Darcy regime), so dp(V) = dp_ref *
// V / V_ref is the first-order correction the tile applies.
const _V16H_FILTER_REF_FPM = 300;
// Air horsepower constant: AHP = CFM * dp(in. WC) / 6356.
const _V16H_AHP_CONST = 6356;
// dims: in { filter_type: dimensionless, face_area_ft2: L^2, face_velocity_fpm: L T^-1, clean_dp_override: M L^-1 T^-2, final_dp_override: M L^-1 T^-2, fan_total_efficiency: dimensionless, runtime_hr_per_year: T, energy_cost_per_kwh: dimensionless } out: { airflow_cfm: L^3 T^-1, clean_dp_in_wc: M L^-1 T^-2, final_dp_in_wc: M L^-1 T^-2, clean_fan_kw: M L^2 T^-3 }
export function computeFilterPressureDrop({
filter_type = "merv13",
face_area_ft2 = 0,
face_velocity_fpm = 300,
clean_dp_override = null,
final_dp_override = null,
fan_total_efficiency = 0.6,
runtime_hr_per_year = 4000,
energy_cost_per_kwh = null,
} = {}) {
const _g = _finiteGuard(arguments[0]); if (_g) return _g;
const t = FILTER_DP_TABLE[filter_type] ?? FILTER_DP_TABLE.merv13;
const area = Number(face_area_ft2) || 0;
const vel = Number(face_velocity_fpm) || 0;
const eta = Number(fan_total_efficiency) || 0;
const runtime = Number(runtime_hr_per_year);
if (!(area > 0)) return { error: "Enter a positive filter face area (ft^2)." };
if (!(vel > 0)) return { error: "Enter a positive face velocity (fpm)." };
if (!(eta > 0 && eta <= 1)) return { error: "Fan total efficiency must be between 0 and 1." };
const airflow_cfm = area * vel;
// Velocity-scaled clean / final drops (unless the user overrides with a
// cut-sheet value, which is taken at the actual operating point as-is).
const velScale = vel / _V16H_FILTER_REF_FPM;
const clean_dp_in_wc = clean_dp_override != null && Number.isFinite(Number(clean_dp_override)) && Number(clean_dp_override) > 0
? Number(clean_dp_override)
: t.clean_dp * velScale;
const final_dp_in_wc = final_dp_override != null && Number.isFinite(Number(final_dp_override)) && Number(final_dp_override) > 0
? Number(final_dp_override)
: t.final_dp * velScale;
// Average drop across a roughly linear loading cycle.
const avg_dp_in_wc = (clean_dp_in_wc + final_dp_in_wc) / 2;
// Fan power (kW) attributable to the filter at a given pressure drop:
// brake HP = (CFM * dp / 6356) / efficiency; kW = HP * 0.7457.
const fanKw = (dp) => ((airflow_cfm * dp) / _V16H_AHP_CONST / eta) * (550 * 0.3048 * 4.4482216152605 / 1000);
const clean_fan_kw = fanKw(clean_dp_in_wc);
const final_fan_kw = fanKw(final_dp_in_wc);
const avg_fan_kw = fanKw(avg_dp_in_wc);
// Annual fan energy attributable to the filter (averaged over the
// loading cycle) and the penalty over a clean filter.
const rt = Number.isFinite(runtime) && runtime > 0 ? runtime : 0;
const annual_fan_kwh = avg_fan_kw * rt;
const annual_penalty_kwh = (avg_fan_kw - clean_fan_kw) * rt;
const cost = energy_cost_per_kwh != null && Number.isFinite(Number(energy_cost_per_kwh)) && Number(energy_cost_per_kwh) >= 0 ? Number(energy_cost_per_kwh) : null;
const annual_fan_cost = cost != null ? annual_fan_kwh * cost : null;
const warnings = [];
if (vel > 500) warnings.push("Face velocity above 500 fpm is outside the typical commercial range; pressure drop and filter loading rise steeply and HEPA stages may need a pre-filter.");
if (final_dp_in_wc <= clean_dp_in_wc) warnings.push("Change-out pressure drop is at or below the clean drop; enter a higher final (loaded) value.");
return {
filter_type,
filter_label: t.label,
airflow_cfm,
face_velocity_fpm: vel,
clean_dp_in_wc,
final_dp_in_wc,
avg_dp_in_wc,
clean_fan_kw,
final_fan_kw,
avg_fan_kw,
runtime_hr_per_year: rt,
annual_fan_kwh,
annual_penalty_kwh,
annual_fan_cost,
warnings,
};
}
export const filterPressureDropExample = {
// MERV 13, 4 ft^2 face at the 300 fpm reference velocity -> 1,200 CFM.
// Clean 0.35 in WC, change-out 0.70 in WC. Clean fan power =