package hydrogen import "math" // PressureMassKg converts pressure (MPa), temperature (C) and total water volume (L) // using the existing real-gas compressibility equation. func PressureMassKg(pressureMPa, temperatureC, capacityLiter float64) (float64, bool) { temperatureK := temperatureC + 273.15 if pressureMPa < 0 || pressureMPa > 70 || temperatureK < 220 || temperatureK > 1000 || capacityLiter <= 0 || capacityLiter > 10000 { return 0, false } a := [...]float64{0.05888460, -0.06136111, -0.002650473, 0.002731125, 0.001802374, -0.001150707, 0.00009588528, -0.0000001109040, 0.0000000001264403} b := [...]float64{1.325, 1.87, 2.5, 2.8, 2.938, 3.14, 3.37, 3.75, 4.0} c := [...]float64{1, 1, 2, 2, 2.42, 2.63, 3, 4, 5} z := 1.0 for index := range a { z += a[index] * math.Pow(100/temperatureK, b[index]) * math.Pow(pressureMPa, c[index]) } if z <= 0 { return 0, false } density := pressureMPa * 1000 / (8.314472 * temperatureK * z) * 0.00201588 * 1000 mass := density * capacityLiter / 1000 return mass, !math.IsNaN(mass) && !math.IsInf(mass, 0) && mass >= 0 && mass <= 500 }