{
if (U.length == 0) {
U[0] = {value: randomLattice == "all down" ? -1*calcEnergy():calcEnergy(), type: "energy", iter: 0, T: T, H: H};
M[0] = {value: calcMagnetization(), type: "magnetization", iter: 0, T: T, H: H, magnetization: externalField};
mutable stats.push(U[0]);
mutable stats.push(M[0]);
}
while (pause) {
const startTime = new Date();
const counter = U.length - 1;
U[counter + 1] = {
value: U[counter].value + isingNIter(nIter),
type: "energy",
iter: counter + 1,
T: T,
H: H
};
M[counter + 1] = {
value: calcMagnetization(),
type: "magnetization",
iter: counter + 1,
T: T,
H: H,
magnetization: externalField,
};
mutable stats.push(U[counter +1]);
mutable stats.push(M[counter +1]);
mutable stats = stats;
mutable statsTemps.push(U[counter +1])
mutable statsTemps.push(M[counter +1])
mutable statsTemps = statsTemps;
yield Promises.delay(5, stats)
}
}