# Dendritic Crystal Growth

Dendrites are the multi-branched fractal like patterns that can grow in crystals or metals. Snowflakes are also a good example dendritic growth.

After seeing this post on r/Simulations that linked to the paper Numerical Simulation of Dendritic crystal growth using phase field method and investigating the effects of different physical parameter on the growth of the dendrite (great name) which includes some Matlab code I was able to add Dendritic Crystal Growth as a new mode in Visions of Chaos.

Also see the original paper referenced which is Ryo Kobayashi’s “Modeling and numerical simulations of dendritic crystal growth“.

Results

Here are some results from the new mode. I have also added an option to give the growths a 3D embossed look.

Here is a sample movie

Bug fix for code

At first my translation of the Matlab code in the paper did not result in anything but boring smooth edged blobs. I don’t own a copy of Matlab to verify the code, but I assumed (as any programmer does when their code doesn’t work) that it must be something I am doing wrong. But after some time checking and double-checking I did find some problems with the code in the paper.

Firstly this line near the end

``````
tnew(i,j) =t(i,j) + lap _t(i,j)*dt + k*(phi(i,j) -phiold);
```
```

needs to be changed to

``````
tnew(i,j) =t(i,j) + lap _t(i,j)*dt + k*(phinew(i,j) -phiold);
```
```

otherwise the phi-phiold cancels out and k is multiplied by zero.

Secondly the calculations for grad_epsilon_x and grad_epsilon_y

``````
grad_epsilon2_x = (epsilon(ip,j)^2 -epsilon(im,j)^2)/dx;
grad_epsilon2_y = (epsilon(i,jp)^2 -epsilon(i,jm)^2)/dy;
```
```

should be moved to the second loop before the term1 calculation.

With those two simple fixes my code was generating the correct dendritic structures and created the images in this post.

Availability

Dendritic Crystal Growth and two Snowflake modes are now included under the new Dendritic Growth mode menu in Visions of Chaos.

Jason.

# Pandemic Simulations

Due to COVID-19 I have seen some infection simulations going around the Internet. Most popular (or what I have seen linked to the most) seems to be this simulation from the Washington Post.

I have been wanting to experiment with virus infection simulations for a while now, so now is the time.

Before going further I want to make it clear that this is in no way specific to COVID-19 and I have no professional training in viruses or infections. This is Softology, not Virology.

Simulation Version 1

This version is a blatant ripoff the Washington Post simulation but allows more settings to be tweaked and larger population sizes to be experimented with. People (shown as circles) move around in random directions bouncing off each other.

The simulation starts with all the people healthy (not infected) and a single person set as infected in the middle of the world. These are the settings for the simulation that can be tweaked.

The above default parameters result in the following run. The virus spreads quickly to the entire population. The 50% recovery probability results in roughly half the population dying with the other half recovering from infection.

Now let’s take a look at modifying some parameters.

The next run had increased population density so people are much closer together. The virus now spreads much faster and ends the same as the previous run with a 50/50 dead/recovered ratio.

Now with the density lowered so people are not as packed together. This time the virus does not infect all healthy people. This is a good example of “social distancing” helping.

Lowering the speed at which people move. If infected and healthy people move slower then the virus has less chances to spread. In the end about a third of al people never get infected and another third recover from infection.

Lowering the probability that people will move each step of the simulation to 10%. This could represent the majority of the population staying home and people only going out for essentials. With this change the virus dies out and the impact on the population is minimal.

If the probability of movement is 0 then the initial virus cannot spread and it dies out.

Simulation Version 2

This time I used an even simpler model. People live on a square grid and only move randomly in a north, south, east or west direction.

Here are the default settings this time

Using those parameters gives the following result

Again a higher density population allows the virus to spread much faster

Social distancing can be simulated by lowering the population density to 10%. People are still freely moving around but keeping their distance from each other due to lower density. The virus spreads much more slowly and not all people get infected.

The original settings are run again, but this time there is only a 5% chance people move around each step of the simulation. This models people who are isolating themselves at home. The fewer people who do move around can be thought of as the people who have to go out for food or medicine. This results in the virus barely spreads at all before dying out.

Conclusion

Both of these very simplistic models show clearly that the best way to stop or severely limit a virus spreading is social distancing and self isolation.

If you want to play with these simulations yourself and try tweaking other parameters they are now included in Visions of Chaos.

Another Example

Grant Sanderson aka 3Blue1Brown made the following video about his simulation tests. Much more detailed than my simple tests and as with all his videos highly recommended.

Jason.

# Ant Colony Simulations

Introduction

This is a simple example of an agent-based model that tries to emulate behavior of ants as they forage for food.

The basic principals of the simulation are;
1. Ants leave the nest moving randomly.
2. If an ant finds some food it picks it up and takes it back to the nest.
3. Ants carrying food leave a pheromone trail on their way back to the nest.
4. Ants looking for food will follow pheromone trails to have a better chance at finding food.

Once an ant finds food, it turns around 180 degrees and then heads towards the nest (with some random turns thrown in so their paths are not always straight lines). In reality ants seem to be able to use the sun position and landmarks to find their way back to the nest.

Using those very simple principals shows how a colony of ants with no other means of communication can coordinate to locate and retrieve food in the surrounding areas.

Programming the ants

For these simulations each ant has some simple properties that control its behavior like position, direction, maximum angle it can turn, move speed, sense angle and sense direction.

Position is the X,Y coordinates of the ant. Direction is the angle the ant is facing. Maximum angle determines how far an ant can turn left or right each step of the simulation. Move speed is how far the ant moves forward each simulation step.

For the process of how an ant looks for pheromones I based this on a similar way to how the Physarum Simulation particles work. An ant looks a certain distance and angle to the left, front and right ahead of itself and senses how many pheromones are in these three locations. The ant then turns towards the spot with the highest pheromone count. If an ant is moving randomly and gets near a pheromone trail it will turn towards the trail and hopefully follow the trail to find food.

The pheromones can be slightly blurred out each frame to simulate diffusion.

If an ant hits the edge of the world it turns 90 degrees and keeps moving.

I had an early attempt at ants simulation for many years that kept the ants on a fixed integer coordinate 2D grid. The change here to using floating point values for ant positions and angles really helped give more natural looking movement as shown in the animated gifs in this post.

Obstacles

Obstacles turned out to be a problem. If there is an obstacle between the food and nest and ant who finds the food will then head towards the nest and get stuck on the obstacle wall. They do eventually bump along the edge of the obstacle and make it around, but they should be smarter and follow a known “good trail”.

If an ant hit an obstacle I got it to only move randomly for the next 100 simulation steps and not leave any pheromones (as we don’t want a trail heading to an obstacle). Still doesn’t really help. Ants still get stuck at the obstacle. More thought and testing required.

Then I got a twitter reply from @psychobiotic suggesting having a foraging pheromone trail left by ants as they look for food. When an ant finds food it can then use the foraging trail to get back to the nest.

That works much better than my previous method above.

Results

This new version of the ant simulation is now available in Visions of Chaos.

Jason.

# A New Kind of Science

A New Kind of Science

A New Kind of Science (referred to as ANKOS from now on) is an immense tome written by Stephen Wolfram in virtual isolation over a ten year period.

Like most cellular automata enthusiasts I was interested in seeing the book once I first heard about it and I grabbed a copy when it was first available in the local book shop. When I first purchased ANKOS I was hoping to get some ideas for new cellular automata from the book to add to Visions of Chaos. What really happened is that after skimming through it a few times it went on the bookshelf and was never referred to again.

For many more detailed reviews of the book you can refer to the Amazon reviews and this collection. I am not qualified to judge if there is a “new kind of science” contained within the many pages, but the general consensus seems to be that the book does not contain a new kind of science and that someone should never ever write a book of that size without an editor and without peer review. If anything, ANKOS is a good lesson on how not to write about something you have done or discovered.

The other day I took the book off the shelf again and cracked it open, still in pristine condition other than the layer of dust that had gathered over the past 18 years. This time I am looking specifically for ideas that I can program and add to Visions of Chaos. ANKOS is a high quality book in terms of physical production value but some of the diagrams and font sizes (especially in the notes section) can be a strain for my not so perfect eyes. Luckily Wolfram provides the entire book online so I can read (and zoom) that version much more easily. Having the book online is appreciated as I can easily link to specific sections of the book directly. Physical ANKOS went back on the shelf again. Maybe forever this time.

Over the past three days I implemented the following nine cellular automata types from ANKOS that I had not previously included with Visions of Chaos.

1D Cellular Automata

2D Cellular Automata

846 pages later I am done.

See my ANKOS album on Flickr for more images from ANKOS.

Final Summary

I had a bunch of other complaints about the book here that I deleted. Everything I wanted to say has been covered in other reviews. Besides that I do try and keep to the “if you don’t have anything nice to say, then don’t say anything at all” adage in this blog.

Was I glad I went back and opened ANKOS again? Yes, overall I did find some interesting new cellular automata to play with. I have experimented with cellular automata of many types over the years and while I do find them very interesting I doubt that they will be the answer to everything, but hey, what do I know?

I do know that if anyone shows any interest in my copy of the physical book it will be thrust into their eager hands with my insistence that they take it as a gift and not a loan.

Following on from this (a year and a bit later) there was an ad hoc book giveaway in my building. You know how a few books appear, then more, and everyone sort of exchanges the books they do not want over a few days. Everything from novels to cook books to unwanted coffee table books. So I plopped ANKOS on the pile thinking someone else can have it. Over the next week the other books rotated around and new ones came and went, but ANKOS sat there like a deformed puppy at the pound that nobody wanted to adopt. Eventually it went in the bin destined for landfill. I tried to find it a home.

Jason.