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.
This commit is contained in:
2022-12-29 22:02:15 -04:00
parent 62ae84382c
commit e65a0993ec
+21
View File
@@ -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) {