code wiki / (root) / nx_emulsion.nx

nx_emulsion.nx source

↩ module page · 90 lines · 3455 B

1// nx_emulsion.nx -- FOOD-SCIENCE SUITE / COLLOID & EMULSION rung. Designs 2// emulsions with the HLB (hydrophilic-lipophilic balance) system: match an 3// emulsifier (or a blend) to the REQUIRED HLB of an oil, predict the 4// emulsion TYPE (oil-in-water vs water-in-oil, Griffin/Bancroft), and rank 5// creaming STABILITY by Stokes' law -- versus trial-and-error. 6// 7// All INTEGER: HLB values x10 (one decimal, HLB 15.0 = 150); weights in 8// parts; creaming index in relative units. Stokes: creaming rate rises 9// with density difference and droplet-diameter squared, falls with 10// continuous-phase viscosity (smaller droplets + thicker phase = stabler). 11// 12// THE exceed: emulsifier selection becomes a MATCH against the oil's 13// required HLB (with a blend to hit any target), the type is PREDICTED, and 14// stability is RANKED from physics -- not guessed from a recipe. 15// 16// grounded: griffin_hlb_system + bancroft_rule + stokes_law_creaming 17// genealogy_id: emulsion_colloid_science + nishi_food_science_suite 18 19import "nx_syscalls.nx" 20const EM_MAGIC_1000000: i64 = 1000000 21 22const EM_TYPE_SPLIT_HLB: i64 = 70 // HLB 7.0: below -> W/O, at/above -> O/W 23 24// ===== Sealed enums =============================================== 25 26const EM_WO: i64 = 0 // water-in-oil 27const EM_OW: i64 = 1 // oil-in-water 28 29const EM_SPAN80: i64 = 0 // HLB 4.3 30const EM_TWEEN80: i64 = 1 // HLB 15.0 31const EM_LECITHIN: i64 = 2 // HLB ~4.0 32const EM_MONOGLYCERIDE: i64 = 3 // HLB ~3.7 33const EM_SSL: i64 = 4 // sodium stearoyl lactylate, HLB ~8.3 34 35const EM_OIL_OLIVE: i64 = 0 // required HLB ~7.0 36const EM_OIL_MINERAL: i64 = 1 // required HLB ~10.5 37 38// ===== HLB lookups ================================================ 39 40func em_emulsifier_hlb(id: i64) -> i64 { 41 if id == EM_SPAN80 { return 43 } 42 if id == EM_TWEEN80 { return 150 } 43 if id == EM_LECITHIN { return 40 } 44 if id == EM_MONOGLYCERIDE { return 37 } 45 if id == EM_SSL { return 83 } 46 return 0 47} 48 49// Required HLB of an oil to be emulsified oil-in-water. 50func em_required_hlb(oil_id: i64) -> i64 { 51 if oil_id == EM_OIL_OLIVE { return 70 } 52 if oil_id == EM_OIL_MINERAL { return 105 } 53 return 100 54} 55 56// Blend HLB = weighted mean of two emulsifiers (weights in parts). 57func em_blend_hlb(hlb_a: i64, w_a: i64, hlb_b: i64, w_b: i64) -> i64 { 58 let tot: i64 = w_a + w_b 59 if tot <= 0 { return 0 } 60 return (hlb_a * w_a + hlb_b * w_b) / tot 61} 62 63// Predicted emulsion type from the emulsifier/blend HLB. 64func em_emulsion_type(hlb: i64) -> i64 { 65 if hlb < EM_TYPE_SPLIT_HLB { return EM_WO } 66 return EM_OW 67} 68 69// Does an emulsifier/blend HLB match an oil's required HLB within tol? 70func em_match(required_hlb: i64, actual_hlb: i64, tol: i64) -> i64 { 71 var d: i64 = required_hlb - actual_hlb 72 if d < 0 { d = 0 - d } 73 if d <= tol { return 1 } 74 return 0 75} 76 77// ===== Stokes creaming stability ================================== 78 79// Relative creaming rate: density_diff (g/L) x diameter^2 (um^2) / viscosity 80// (mPa.s), scaled. Higher = creams faster = LESS stable. 81func em_creaming_index(density_diff_gpl: i64, diam_um: i64, visc_mpas: i64) -> i64 { 82 if visc_mpas <= 0 { return EM_MAGIC_1000000 } 83 return density_diff_gpl * diam_um * diam_um * 1000 / visc_mpas 84} 85 86// 1 iff emulsion A is more stable (lower creaming index) than B. 87func em_more_stable(index_a: i64, index_b: i64) -> i64 { 88 if index_a < index_b { return 1 } 89 return 0 90}