From e65a0993ecc1500ad85e2d6fb2ee33e7c76bcf67 Mon Sep 17 00:00:00 2001 From: "Ryan M. L. McFadden" Date: Thu, 29 Dec 2022 22:02:15 -0400 Subject: [PATCH] improve handeling of layer densities - when a layer's composition isn't found in the (internal) dictionary of compounds, estimate its density using a weighted average of elemental densities. - this fixes the annoying behaviour of having an "undefined" density passed to the generated input file when the user forgets to update the density manually. --- TrimSPlib.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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) {