#version 2
/*
Compiling the attached program generates an error:
[gst2d.diderot:32.22-32] Error: "stabilize" statment outside of initially/update method
The stabilize is inside an update, but its the global update not the strand update.
Being able to stabilize all strands from the global update, as a consequence of some
computation done in the global update, is a natural way to express the convergence of
particle systems. Also, this was part of Lamont's branch, and it was used in Fig 2 of
the Vis'15 paper, so I hope that the merge will include this important capability.
*/
/*const*/ int N = 10;
real target = 0.0;
strand S (int i) {
output real e = i;
int iter = 0;
update {
iter += 1;
real delta = (target - e)/2 + iter;
print (i, "(", iter, "): e = ", e, ", delta = ", delta, "\n");
// if (target > 10) { stabilize; } // works, but ugly
if (|delta| < 0.001) {
stabilize;
} else {
e += delta;
}
}
}
start {
target = mean { p.e | p in S.all };
print("initially: target = ", target, "\n");
}
update {
target = sum { p.e | p in S.all } / N;
print("update: target = ", target, "\n");
if (target > 10) { stabilize; }
print("update done\n");
}
create_collection { S(i) | i in 1..N }