"""Design the taper for a space-dock-style tower. Assume synthetic
diamond with reasonable material properties. No unobtainium."""

import units

density = 3500 * units.kg / units.m**3
# This is the actually achievable compressive strength of
# synthetic diamond.
compressiveStrength = 5.e9 * units.pascal
# To build conservatively with a large safety margin, let's
# assume a much lower compressive strength.
compressiveStrength = 0.1 * compressiveStrength

topMass = 1000 * units.metricTon
topAltitude = 100 * units.km

def gravity(altitude):
    # inverse square law, returns an acceleration
    R = units.earthRadius
    ratio = (R / (R + altitude)) ** 2
    return ratio * units.earthGravity

h = topAltitude
force = topMass * gravity(topAltitude)
dh = 0.1 * units.km
volume = 0. * units.m**3

# For each dh step in altitude, design a cylinder to hold up the
# weight above, then add its weight to the weight of the weight of
# the stuff above it. Start at the top of the tower and iterate
# down to the ground.

crossSections = [ ]

while h > -units.cm:
    # support the weight above this piece
    area = force / compressiveStrength
    crossSections.append((h, area))
    h = h - dh
    # how much weight does this piece add?
    stepVolume = dh * area
    volume = volume + stepVolume
    force = force + stepVolume * density * gravity(h)

print "All these quantities scale linearly with topMass"
print "topMass", topMass
print "Cross section at the top", crossSections[0]
print "Cross section at the bottom", crossSections[-1]
print "Load resting on the ground", force / units.earthGravity
print "Volume of synthetic diamond", volume
print "Mass of synthetic diamond", volume * density
