galaxy_of_nuclides
galaxy_of_nuclides copied to clipboard
Chaining decay methods on Nucleus sometimes creates duplicate nucleons
To reproduce:
var carbon9 = new Nucleus(matter.elements[6].nuclides[3]).appendTo(d3.select("svg"));
carbon9.alphaDecay().betaDecay();
Chaining alpha and beta decays together on a Carbon-9 nucleus should result in a Lithium-5 (three protons, two neutrons) and about half the time this is what happens. However, about half the time, what remains is a nucleus with four protons and two neutrons (technically a Beryllium-5). Inspecting the elements makes it clear that the daughter neutron from the beta decay is not present and one of the neutrons is duplicated. That is, the nucleus group in the SVG has two child proton groups with the same ID.
The fact that this happens intermittently could point to a race condition. Either way it's unclear how one proton would be generated twice in the SVG and the daughter neutron not at all, despite the Nucleus.particles
object/array looking correct 100% of the time.
As a stopgap, the method Nucleus.prototype.restart()
currently has a line that removes all child elements from the nucleon selector before redefining the child nodes:
nucleus.nucleons_selector.selectAll("g.nucleon").remove();
This is not a clean solution. It fails to reuse SVG elements efficiently and, especially for larger nuclides, can result in a momentary but visible instance of the entire nuclide disappearing in order to be redrawn.