diff --git a/TrimSPlib.js b/TrimSPlib.js index 1e52dd2..4b1679d 100644 --- a/TrimSPlib.js +++ b/TrimSPlib.js @@ -581,6 +581,27 @@ function rho_fun() "":"" } document.getElementById(rhoLi).value = rhos[chem]; + + // suggest a material density based on composition (when it's undefined) + if (!isFinite(document.getElementById(rhoLi).value)) { + let layer_formula = parse_formula(chem); + + // determine the stoichiometry sum (for normalization) + let stoichiometry_sum = 0; + for (key of Object.keys(layer_formula)) { + stoichiometry_sum = stoichiometry_sum + layer_formula[key]; + } + + // determine the density using on a weighted average of the elemental densities + let density_estimate = 0; + for (key of Object.keys(layer_formula)) { + if (layer_formula[key] != null) { + density_estimate = density_estimate + (layer_formula[key] / stoichiometry_sum) * rhos[key]; + } + } + + document.getElementById(rhoLi).value = density_estimate; + } } function openTab(event, tabName) {