nx_vessel_geometry.nx source
↩ module page · 73 lines · 3269 B
1// nx_vessel_geometry.nx -- C0 of the VESSEL-DESIGN ladder: PARAMETRIC
2// GEOMETRY that derives the thermal-twin parameters from the PHYSICAL
3// shape and materials. Until now the twin's heat capacity and insulation
4// conductance were hand-set; here they fall out of geometry + physics:
5//
6// contents heat capacity C = V * rho * c_p [J/K]
7// insulation conductance U = k * A / d (Fourier) [W/K]
8//
9// So "a 4 L vessel with 5 mm of cork" becomes a fully-specified thermal
10// twin you can certify (H3 / nx_vessel_twin) -- the geometry-to-thermal
11// design loop, closed in software. Change the insulation thickness and
12// re-certify; no prototype required.
13//
14// Cylinder, aspect set by a chosen radius: h = V / (pi r^2). Integer
15// units: volume ml, lengths mm, area mm^2, k in milli-(W/m.K).
16//
17// genealogy_id: lumped_thermal_from_geometry + fourier_conduction_1822
18
19import "nx_syscalls.nx"
20import "nx_vessel_thermal.nx"
21const NX_MAGIC_1000000: i64 = 1000000
22
23const NX_VG_PI_MILLI: i64 = 3142 // pi x1000
24const NX_VG_WATER_CP_X1K: i64 = 4186 // water specific heat x1000: 4.186 J/(g.K); rho=1 g/ml
25
26struct NxVesselGeom {
27 volume_ml: i64,
28 radius_mm: i64,
29 height_mm: i64,
30 wall_thickness_mm: i64,
31 insul_thickness_mm:i64,
32 insul_k_milli: i64, // insulation conductivity, milli-(W/m.K) (cork ~ 43)
33 area_mm2: i64, // outer surface area (sides + 2 caps)
34}
35
36// Design a cylindrical vessel for a target volume at a chosen radius;
37// compute the height and outer surface area.
38func nx_vessel_geom_design(volume_ml: i64, radius_mm: i64, wall_thickness_mm: i64,
39 insul_thickness_mm: i64, insul_k_milli: i64) -> *NxVesselGeom {
40 let g: *NxVesselGeom = (sys_mmap(56)) as *NxVesselGeom
41 g.volume_ml = volume_ml
42 g.radius_mm = radius_mm
43 g.wall_thickness_mm = wall_thickness_mm
44 g.insul_thickness_mm = insul_thickness_mm
45 g.insul_k_milli = insul_k_milli
46 // h = V / (pi r^2); V_mm3 = volume_ml * 1000; pi r^2 = PI_MILLI*r^2/1000
47 // => h = volume_ml * 1e6 / (PI_MILLI * r^2)
48 let r2: i64 = radius_mm * radius_mm
49 g.height_mm = volume_ml * NX_MAGIC_1000000 / (NX_VG_PI_MILLI * r2)
50 // A = 2*pi*r*(r+h) = 2*PI_MILLI*r*(r+h)/1000
51 g.area_mm2 = 2 * NX_VG_PI_MILLI * radius_mm * (radius_mm + g.height_mm) / 1000
52 return g
53}
54
55// Contents heat capacity (J/K): C = V * rho * c_p (water-like contents).
56func nx_vessel_geom_heat_capacity_jk(g: *NxVesselGeom) -> i64 {
57 return g.volume_ml * NX_VG_WATER_CP_X1K / 1000
58}
59
60// Insulation conductance to ambient (milli-W/K): U = k*A/d.
61// U_W = (k_milli/1000) * (A_mm2/1e6) / (d_mm/1000)
62// U_mwk = U_W*1000 = k_milli * A_mm2 / (1000 * d_mm)
63func nx_vessel_geom_insulation_mwk(g: *NxVesselGeom) -> i64 {
64 return g.insul_k_milli * g.area_mm2 / (1000 * g.insul_thickness_mm)
65}
66
67// Materialise the H0 thermal twin from geometry + a heater + ambient.
68func nx_vessel_geom_to_twin(g: *NxVesselGeom, heater_power_mw: i64,
69 ambient_mc: i64) -> *NxVesselThermal {
70 let c_jk: i64 = nx_vessel_geom_heat_capacity_jk(g)
71 let u_mwk: i64 = nx_vessel_geom_insulation_mwk(g)
72 return nx_vessel_thermal_new(c_jk, heater_power_mw, u_mwk, ambient_mc)
73}