Friday, December 1, 2017

Rivers: Here Comes the Math

Early on in this River series, we found the total amount of water flowing through any given river hex.  We need to find the dimensions of the river and how fast it flows, to properly picture it within the game world.  The formula for this is deceptively simple:

total flow = cross-sectional area x flow velocity

Or, in the standard abbreviations used by people who know what they're doing:

Q = A x v

For simplicity's sake, I'm going to use a triangular cross-section for our rivers.  A trapezoid would be more accurate, but this is going to get hairy enough down the road without getting into the geometry of trapezoids.  So, a triangle's area is one half of the product of the base and the height, giving us:

Q = (b x h)/2 x v

Since we're talking about rivers, to be more clear, we'll substitute the term "base" with "width" and "height" with "depth".

Q = (w x d)/2 x v

Now we plug in Robert Manning's equation so we can figure out the velocity, with n being Manning's n, R being the hydraulic radius, and S being the slope of the riverbed:

Q = (w x d)/2 x (1.49/n) x R2/3 x S1/2

And just what is this hydraulic radius?  It's the cross-sectional area of the river divided by the "wetted perimeter", which is like a regular perimeter except we can ignore the river surface.  Only the parts touching the ground count for wetted perimeter.

R = cross-sectional area/wetted perimeter

Since we're using triangular cross sections, the numerator on this is the same as what we worked out above, one half width times depth.  If we take the Pythagorean theorem (a2 + b2 = c2, or c = (a2 + b2)1/2), we can find one side of the wetted perimeter, using half the width as "a" and the depth as "b".  Doubling that gives the full wetted perimeter.


R = ((w x d)/2)/2((1/2(w))2 + d2)1/2

Substituting this into our flow equation gives us:

Q =  (w x d)/2 x (1.49/n) x (((w x d)/2)/(2((1/2(w))2 + d2)1/2)2/3 x S1/2

Now we need to make this mess a little simpler.  We know the total flow, the Manning's n, and the slope for our river, so let's put all that on one side of the equation, with our unknown quantities on the other:

Qn/(1.49 x S1/2) =  (w x d)/2 x (((w x d)/2)/(2((1/2(w))2 + d2)1/2)2/3

We still have two unknowns, width and depth.  But, in the last post, we worked out a range of Width-to-Depth Ratios (WDR) for each river type, so we can reduce this to one unknown quantity and finally beat this monster into submission.  If the WDR is 1 (width equal to depth) we get:

Qn/(1.49 x S1/2) =  (d x d)/2 x (((d x d)/2)/(2(((1/2)d)2 + d2)1/2)2/3
Qn/(1.49 x S1/2) =  d2/2 x ((d2/2)/(2(((1/4)d2) + d2)1/2)2/3
Qn/(1.49 x S1/2) =  (d2)/2 x (((d2)/2)/(2((5/4)d2)1/2))2/3
 Qn/(1.49 x S1/2) =  (d2)/2 x (d2/(4((5/4)d2)1/2))2/3
 Qn/(1.49 x S1/2) =  (d2)/2 x (d2/(4(51/2/2)d))2/3
 Qn/(1.49 x S1/2) =  (d2)/2 x (d2/(2(51/2)d))2/3
 Qn/(1.49 x S1/2) =  (d2)/2 x (d/(2(51/2)))2/3
 Qn/(1.49 x S1/2) =  (d2)/2 x (d2/3/((4)1/3(51/3)))
Qn/(1.49 x S1/2) =  (d2)/2 x (d2/3/(201/3))
 Qn/(1.49 x S1/2) =  d8/3/(2(201/3))
(2Qn(201/3))/(1.49 x S1/2) =  d8/3
 ((2Qn(201/3))/(1.49 x S1/2))3/8 =  d

Pretty simple, right?  Plug in all our known values and we have the depth.  Now that we have the depth, we also have the width, since they're equal in this case.  And since we have that we can solve for the velocity, and our basic description of the river is complete.

Of course, this only works out if the WDR is 1.  If our WDR is 2 (width equal to twice depth) we get instead:

Qn/(1.49 x S1/2) =  (2d x d)/2 x (((2d x d)/2)/(2(((1/2)2d)2 + d2)1/2)2/3
Qn/(1.49 x S1/2) =  2d2/2 x ((2d2/2)/(2(d2 + d2)1/2)2/3
Qn/(1.49 x S1/2) =  d2 x (d2/(2(2d2)1/2)2/3
 Qn/(1.49 x S1/2) =  d2 x (d2/(2(21/2d))2/3
 Qn/(1.49 x S1/2) =  d2 x (d/(2(21/2))2/3
 Qn/(1.49 x S1/2) =  d2 x d2/3/(41/3(21/3))
 Qn/(1.49 x S1/2) =  d8/3/81/3
 Qn/(1.49 x S1/2) =  d8/3/2
 2Qn/(1.49 x S1/2) =  d8/3
 (2Qn/(1.49 x S1/2))3/8 =  d

We have to do this for every single possible WDR, and because it's really difficult to get all this math across in this format (even working it out so that square roots and division of complex chains of numbers show up in a less confusing manner), rather than post pages of confusing equations, I've already arbitrarily limited WDRs to whole number ratios (no 1.5, for example...it's either 1 or 2), and I've also worked out a spreadsheet so all you have to do is input your total flow, Manning's n, and slope, and then find the proper WDR in the output fields, and it will spit out depth, width, cross-sectional area, and velocity.  I also added a second page on the spreadsheet that will work out speeds in meters per second, for sci-fi games or for those people who insist on using metric measures in a fantasy game.

Here's the link:   https://drive.google.com/open?id=1n5AB6HtQNKCMnp8k2u4CRBBfY9iMu8t9