Sunday, February 5, 2017

Plate Tectonics - 11

Well, never mind then.  I understand where the problems I'm running into with non-power-of-two dimensions comes from.  It comes from the multitude of bit-wise operations that depend upon the width or height of the map being a power of two.  One less than a power of two results in a "mask" with all the bits below the bit for that power being set to one.  That is, if the value is 8, the binary is 1000, but if the value is 7, the binary is 0111.  So a bit-wise AND operation of a coordinate and the length of a side of the map would result in a value that was always within the range of the map side's length - but only if the side (width or height) is a power of two.  If the dimension was seven, the binary would be 0111, but  binary for one less would be 0110.  That screws things up.

The code is riddled with statements like

if (area[i].lft == ((lft + 1) & (map_width-1)))

and

size_t k = (y & (map_height - 1)) * map_width + (x & (map_width - 1));

They are short, terse, and computationally inexpensive, but they fail to work properly when the map_width and map_height values are not powers-of-two.  I started to rewrite code to address it, and was making a little progress. Unfortunately the end product is several extra lines of code for each such instance, and involves more computationally expensive (costly) operations than a simple bit-wise AND and a subtraction operation. After 90 minutes of work, it was almost right in one function, as shown below.

512x384 map of the plates.  Almost right, but still seeing red, which indicates plate is missing.
768x384 and 768x768 show similar problems.  512x256, 512x512, 512x1024, and 1024x256 maps do NOT.  

But not quite right.  And that was in only one function among several, and many of those functions made far heavier use of those AND operations.  So I made up my mind.  Rather then go through the many hundreds of lines of code that use such statements, and rewrite them into more computationally expensive (costly) operations and adding many news lines of and taking perhaps another dozen hours, I shall give up on non-power-of-two dimensions for this release.  Maybe someday in the future.  So no 1024x768 or 640x480 or 512x384 output for now, but 1024x1024, 1024x512, etc. should work just fine.  I'll make some comments in the code, remove the non-power-of-two dimensions from the GUI, and move on.

Integration of parameters from the GUI into the simulation will likely be my last thing to accomplish before I release this, unless I uncover additional problems.

Plate Tectonics - 10

It is well after midnight.  My first approach at getting the erosion situation ("caterpillars" vs. worn-down mountains) resolved did not work nearly so well as I had hoped.  Careful tuning was not enough.  Either it was ineffective or it eroded land down to shoals.

Not cutting it

So I decided upon a new approach. The erosion algorithm has been split into two.  One is the "wave erosion" for coastal and island erosion. That's my very crude but rather effective method. The other part is the rain drop algorithm implemented by the original PlaTec developer, Lauri Viitanen.  Wave erosion runs more frequently than the regular erosion.  This is a fairly effective approach, although different parameters can yield different results.

Decent mountains, island chains, few "caterpillars"

I'm still not quite happy with this outcome. Some of the simulation parameters are still hard-coded constants.  I have another few hours to go integrating all the parameters shown in the GUI as true parameters that can be passed into the main simulation class.  The restart and aggregation overlap settings can really improve the compactness of the continental masses that form.  Likewise, having the fractal parameters driven from the UI (or later, a settings file) will be quite nice - as it is, I currently have to make changes to hard coded constants.  Ugh.
Parameters organized

I was testing non-power-of-two dimensions for the map and discovered a problems.  I can use whatever aspect ratio I want, but if any dimension is not an exact power of two (two raised to an integral positive power), problems ensue.  I am currently debugging this, which yielded the colorful image below.  Each of the grayscale rectangles represents the bounding box of a plate, while the red represents areas that plates have moved away from.  Those lines?  They represent an indicator that I have problems. So, either a bit more work, or forget about non-power-of-two dimensions for now.


Seeing red

Friday, February 3, 2017

Plate Tectonics - 9

As I mentioned in my last post on this topic, I believe the erosion algorithm for the Plate Tectonics simulator needs to be tweaked.  I've been analyzing the current erosion code and discovered that unlike the original version of PlaTec I worked with that basically used a smoothing algorithm, the version I'm working with now looks to be using the water drop erosion algorithm, akin to what is described as hydraulic erosion in Musgrave's work. In addition to the erosion proper, the function that implements the erosion also introduces some random noise (variations in elevation) every time the erosion function is called. The difference is "splotchy" without random variation vs. "grainy" with random variation, as seen in the image below.  Have I discovered the need for yet another parameter?




The current set of parameters is already pretty large. I'm still working all of these parameters into the code base. A lot of them are currently constants. Now they need to go into/come out of the parameters window and get passed to the simulation code.

Parameter chaos.  Perhaps grouping them into labelled groups and changing some into sliders will improve things?
In many case, many times just leaving the values as-is works great.  But not always.  It depends on your goal.
And I still need to back and fix the problem that I posted about previously, the "caterpillars" and over-eroded mountains.  That's why I started looking at the erosion code in the first place.  I basically want the land bordering on ocean to erode faster than the mountains.  The "caterpillar" islands form from too little erosion of islands in the oceans formed by plate movement.  Attempting to prevent the "caterpillars" by increasing the frequency with which erosion is applied causes the mountains to erode too quickly instead.

Conceptually, I think it is as simple as a scalar factor for the amount of material to move when the erosion algorithm moves material from a "high" cell to neighboring "low" cell(s).  My first approach would be that the scalar could equal the sum the number of neighbor cells that are below sea level, divide by four (von Neumann neighborhoold, not Moore), plus 0.5.  Hence a "high" cell that was inland would erode at half the nominal rate, a single-cell island would erode at 1.5 times the nominal rate, and cells belonging to larger islands or on the coast would erode at an intermediate rate. This actually makes some sense within the context of the simulation, as well, as wave action and rainfall would result in more erosion than rainfall alone. We'll see what it takes to implement that once I fully understand the existing implementation of the erosion algorithm, then how well it works in practice.

An Interesting Character: Lew Wallace

Lew Wallace was an interesting character.  He was an author, soldier, lawyer, diplomat, politician, investigator, and inventor. He wrote the best-selling American novel of the 19th century, Ben-Hur, beating out Harriet Beecher Stowe's Uncle Tom's Cabin, and has remained in print ever since.

He served in the Mexican-American War and the Civil War.  Commanding the vastly outnumbered Union forces at the Battle of Monocacy, he was defeated on the battlefield, but delayed the Confederates by a day, allowing Union reinforcements to arrive at Washington, D.C. before the Confederates.  At 71 years of age, he attempted to enlist for the Spanish-American War.

At different times in his life he was a Whig, a Free Soil man, a Democrat, and a Republican.  He was involved in a Free Soil newspaper for a time.  He was the appointed governor of the New Mexico Territory, in which position he had dealings with a notorious criminal known as Billy the Kid.  He then served as minister (ambassador) to the Ottoman Empire (i.e. Turkey) for several years.

Frankly, Lew Wallace had a long and varied career.  When the country was at war, he served it in a military capacity.  When it was at peace, a variety of private pursuits and public service occupied him for almost eighty years.  He was an outstanding American with an interesting life that seems vaguely improbable - until one considers even larger-than-life figures such as Theodore Roosevelt and Winston Churchill.  In comparison, Lew Wallace almost seems prosaic - but only almost.

Thursday, February 2, 2017

Boredom

I am bored.  Why am I bored?  Because I'm performing final integration testing on some rather boring but important code, prior to releasing it for UAT (User Acceptance Testing).  I am on my nth iteration of testing the code, various minor problems having cropped up that weren't apparent during development and unit testing.  This is why integration test, afterall.

Alas, since the code being tested is for certain timeout functionality, I have to allow for at least a little bit of time to allow the multitude of components involved to start up and start working before the timeout is applied.  This gives me a very few minutes of dead time during each test cycle.  It is not enough time to do anything particularly useful, however.  Hence this blog post.  I caught up on work emails on the first couple cycles, checked the tech news after, and then caught up on the blogs that aren't NSFW.  So now... this blog post.

Wednesday, February 1, 2017

Plate Tectonics - 8

So close, yet so far.  That's the best description of the current state of the Plate Tectonics code.  I've got a decent feel for the parameters now, and will be exposing them through the UI so different effects can be achieved.  However, there's two different artifacts caused by the erosion period parameter.  Run erosion too frequently, and the mountains erode down from something like the Rockies, Alps, and Himalayas, to something more like the lesser portions of the Appalachians or Catskills.  Run it too infrequently, and you get long "fuzzy" islands or island chains that remind me of caterpillars. Hours of running simulations show it is almost impossible to find a "happy medium" by simply adjusting the erosion period. I think the erosion algorithm needs to be tweaked to increase the level of erosion for sea-exposed cells and/or decrease it for land-bound cells.  Perhaps a scaling factor calculated from the percentage of neighbor cells that are below sea level?

An example terrain mapped onto a globe

Examples of "caterpillar" islands arising from too little erosion

Examples of heavily eroded mountains, from too much erosion

Book Review: Loose Ends

Loose Ends is the third and latest volume in John Van Stry's Hammer Commission series.  Earlier this week I read it in one long sitting. Loose Ends continues the tale of Mark Levin, Army veteran, werecougar, and agent for the Vatican's Hammer Commission. The agents of the Hammer Commission handle demons, devils, and other dark forces in the world.  This volume finds him still on loan to FBI, and dealing with some loose ends from a previous mission.

The book was a great read. It wasn't a particularly light story, given the dark elements involved, but neither does it wallow in the dark. As dark as humanity can be at times, nothing in the novel implies it is universal or inevitable.

You don't need to have read the previous two volumes to understand what's going on, though a few points here and there will definitely reward those who've read the earlier novels. Typographical errors were wonderfully rare.  The language was not oversimplified but was not overly complex, either, making it a moderately easy read.

I would definitely recommend this book and the others in the series.  It was quite engrossing - I read it in essentially one sitting, stopping only to use the restroom a couple times.  I hope anybody who chooses to follow this recommendation and check out this novel will be as entertained as I was.