0

I am coding to simulate the growth of a sphere in a solution environment. I am doing in this way.

  1. Create of space and put a cell in the center as a seed.

    pSpace = new char[nXRange * nYRange * nZRange];
    for (int i = 0; i < nZRange; i++)
    for (int j = 0; j < nYRange; j++)
    for (int k = 0; k < nXRange; k++)
      pSpace[i * nXRange * nYRange + j * nXRange + k] = 0;
    pSpace[nXRange * nYRange * nZRange / 2 + nXRange * nYRange / 2 + nXRange/2] = 1;
    
  2. Create a cell in the solution. The position of the cell is created by a random number.

    int nXPostion = (int)(((float)rand()/RAND_MAX) * (nXRange - 1));
    int nYPostion = (int)(((float)rand()/RAND_MAX) * (nYRange - 1));
    int nZPostion = (int)(((float)rand()/RAND_MAX) * (nZRange - 1));
    
  3. Calculate the change of the potential for creation of the cell.Six neighbors of the new cell are checked as left (L), Right (R), Front (F), Behind(B), Top (T), and Bottom (B*). If the neighbors of the new cell is an old cell as L in the figure, the change of the potential is PA2A, else, if it is not an old cell but solution, as R, F, B, T, and B * in the figure, it is PA2S. The creation of the new cell change the potential with PCREATE. So, the change of the potential is

    fPotential = PCREATE + P(Left) + p(Right) + p(Front) + p(Behind) + p(Top) + p(Bottom);
    
  4. Use a random number to compare the change of the potential as following. If the random number is larger than the exponential of change of the potential, than create a new cell, else cancel.

Theoretically, a sphere will growth around the seed. However, in my experiment, the shape of the cluster is irregular. The attached image is a cluster of 50000 cells. Could anyone give me some comments. Is it related with the generation of the random number? Thanks.

a cluster created around a seed with random number

XY plane of cluster

XZ plane of cluster

Interplate in process 3

HXGuo
  • 45
  • 1
  • 1
  • 6
  • That might be a stupid question, but why do you think the shape you posted is "irregular" ? I seems the center of your cell colony is 260,260,260 and the cell colony roughly spreads around 230..290 in x/y/z direction. That pretty much is a sphere ? – Ingo Blackman Jan 27 '14 at 13:31
  • You are right. The range of the cluster looks correct. But, the shape of the envelope of the cluster is not a circle. You can see from the xy and xz plane of the cluster. The surface of the cluster is not smooth. I have created 50000 cells. – HXGuo Jan 27 '14 at 13:58
  • Do you have a reason not to be using a multi-dimensional array? e.g. `a[x][y][z]`. It would improve the readability of your code and reduce the potential to making mistakes with our indices. – Richard Jan 27 '14 at 14:02
  • Also: can you explain Step 3 better? How does this potential work? – Richard Jan 27 '14 at 14:03
  • @Richard, Thank you for your comments. It might be a bad habit, but I prefer to a one-dimensional array. It is a kind of easy for debugging. I have upload my source file. If you are interested with it. you can download from [http://hxguo.sakura.ne.jp/single.cpp ] and [http://hxguo.sakura.ne.jp/single.h ] – HXGuo Jan 27 '14 at 14:09
  • @HXGuo, looking at sources is usually not a good way to get insight into a well-asked question and raises a barrier for others to benefit. :-) – Richard Jan 27 '14 at 14:11
  • (I took a peek at the code. Note that one reason why I, and others, might prefer not looking at someone's code is the use of odd indexing conventions, as discussed previously, and other idiosyncrasies, coupled with a lack of extensive clarifying comments. In scientific code like this you _need_ comments to convey the ideas behind an algorithm. You cannot expected people to believe your code is correct otherwise, or to help you with it. The code does not explain itself.) – Richard Jan 27 '14 at 14:24
  • Did you try with 10 or 100 times more cells ? Maybe then you'll get closer to a sphere. – Jabberwocky Jan 27 '14 at 14:33
  • @Richard, Thanks for your help. Actually, your comments about the different growth rate alone x-, y-, z-axis and diagonal axis is very good. In my opinion, it is just the key point. I will try to improve the source even it is difficult. – HXGuo Jan 27 '14 at 15:10
  • @MichaelWalz, I have tried 10 times more cells. But, it was same shape. – HXGuo Jan 27 '14 at 15:11
  • @HXGuo, this almost looks like a cellular automata, but if your program has a global awareness of the shape, maybe using [random spherical coordinates](http://mathworld.wolfram.com/SpherePointPicking.html) would help? Again, I encourage you to develop a statistical test of what the shape should look like, unless you have a good reasons to believe that the current result is bad. – Richard Jan 27 '14 at 17:42

1 Answers1

2

I have two thoughts regarding this.

First: the rectilinear grid you are using presents a difficulty. That is, without looking too deeply at your code, growth along an x-, y-, or z-axis is likely proceed at a different rate than growth along a diagonal axis.

This problem is difficult to work around. If you allow d-26 connectivity (central cell connects to the cube of all cells around it), then how do you account for the (slightly) longer distance to diagonal cells? If you only allow growth along x-, y-, and z-axes, how do you account for the fact that cell in a diagonal direction now takes longer to get to than it should?

This may account for some of the fuzziness.

Second: Right now we are using the metric of "it looks irregular". But is it really? What we need is a good statistical test of how irregular it is versus how irregular we would expect it to be. Certainly it is the case that you wouldn't expect the edge of your blob to be completely spherical, since this is, after all, a random process.

Richard
  • 56,349
  • 34
  • 180
  • 251