Improve fallback density estimate

This commit is contained in:
2026-04-14 17:05:15 +02:00
parent 04272a0fc5
commit 11dd8896fc
+12 -8
View File
@@ -3093,24 +3093,28 @@ function rho_fun()
}
}
// determine the density using a weighted average of the elemental densities
let density_estimate = 0;
// estimate the density from additive elemental molar volumes:
// rho ~= total molar mass / total molar volume
let total_molar_mass = 0;
let total_molar_volume = 0;
for (const key of Object.keys(layer_formula)) {
const amount = Number(layer_formula[key]);
if (!isFinite(amount) || amount <= 0) {
continue;
}
if (!elemPars[key] || !isFinite(elemPars[key].rho)) {
if (!elemPars[key] || !isFinite(elemPars[key].rho) || !isFinite(elemPars[key].A) || elemPars[key].rho <= 0) {
continue;
}
if (stoichiometry_sum > 0) {
density_estimate += (amount / stoichiometry_sum) * elemPars[key].rho;
}
total_molar_mass += amount * elemPars[key].A;
total_molar_volume += amount * (elemPars[key].A / elemPars[key].rho);
}
rho = density_estimate;
rho = 0;
if (total_molar_volume > 0) {
rho = total_molar_mass / total_molar_volume;
}
if (rho > 0) {
alert("Warning: Estimated density from elemental constituents; please verify manually.");
alert("Warning: Estimated density from additive elemental molar volumes; please verify manually.");
}
}
}