Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Neph adapted this from Momo
- # https://repl.it/repls/WellwornBowedDemos
- # Import packages
- import numpy as np
- # Multi-stage deltaV calculator. All arguments must be lists of the same length except the int 'payload'
- def getdV(isp, wet, dry, payload):
- dV = 0
- wet.append(0)
- for i in range(len(isp)):
- dV += isp[i] * np.log((sum(wet[i:])+payload) / (dry[i]+sum(wet[i+1:])+payload))
- return dV * 9.8
- # Payload calculator
- def getPayload(isp, wet, dry, dV2leo):
- dV = getdV(isp, wet, dry, 0)
- if dV < dV2leo:
- # oof
- return -1
- else:
- # Payload mass
- payload = 0
- # Iteration variables
- i = 1
- lastSign = 1
- # Iterate until the dV equation is solved
- while np.abs(dV-dV2leo) > 1:
- # This helps us close in on a solution
- sign = np.sign(dV-dV2leo)
- if sign != lastSign: i *= 2
- # Change payload mass
- payload += sign*100/i
- # Recalculate
- dV = getdV(isp, wet, dry, payload)
- # Iterate
- lastSign = sign
- # Solution!
- return payload
- # Run the thing
- while True:
- try:
- # Set up parameter lists
- isp = []
- wet = []
- dry = []
- # Get stages
- moreStages = True
- stage = 1
- while True:
- # Get first-stage boosters
- if stage == 1:
- print("Are there boosters? (If so, they must have the same engines as the first stage for this calculator to work) [Y/n]: ")
- if input() != 'n':
- print("Input first stage/booster engine isp (seconds):")
- ISP = float(input())
- print("Input engine fuel consumption rate (tons/sec):")
- rate = float(input())
- print("Input number of first stage engines:")
- enginesFirst = float(input())
- print("Input first stage total mass (tons):")
- wetFirst = float(input())
- print("Input first stage fuel mass (tons):")
- fuelFirst = float(input())
- dryFirst = wetFirst - fuelFirst
- print("Input number of booster engines:")
- enginesBoosters = float(input())
- print("Input booster total mass (tons):")
- wetBoosters = float(input())
- print("Input booster fuel mass (tons):")
- dryBoosters = wetBoosters - float(input())
- # Calculate how long it takes for boosters to burn dry
- t = (wetBoosters - dryBoosters)/rate/enginesBoosters
- firstFuelConsumedWithBoosters = rate*t*enginesFirst
- if firstFuelConsumedWithBoosters > fuelFirst:
- raise Exception("Your boosters finish after your first stage does. This calculator cannot handle that lift vehicle architecture.")
- # Calculate the booster+first stage "stage"
- isp.append(ISP)
- wet.append(wetBoosters + firstFuelConsumedWithBoosters)
- dry.append(dryBoosters)
- # Caculate the remainder of the first stage "stage"
- isp.append(ISP)
- wet.append(wetFirst - firstFuelConsumedWithBoosters)
- dry.append(dryFirst)
- # More stages?
- print("Are there more stages? [y/N]")
- if input() == 'y':
- stage += 1
- else:
- break
- # Get stage parameters
- print(f"Input stage {stage} engine isp (seconds): ")
- isp.append(float(input()))
- print(f"Input stage {stage} total mass (tons): ")
- wet.append(float(input()))
- print(f"Input stage {stage} fuel mass (tons): ")
- dry.append(wet[-1] - float(input()))
- # More stages?
- print("Are there more stages? [y/N]")
- if input() == 'y':
- stage += 1
- else:
- break
- # Okay, let's get a move on
- print("Without payload, you have", str(int(getdV(isp, wet, dry, 0))), "m/s of delta V.")
- # Will we go to space?
- payload = getPayload(isp, wet, dry, 2300.0)
- if payload == -1:
- # oof
- print("You will not go to space today. :(")
- else:
- # yay
- print("With a very high t/w ratio, perfect piloting and no drag, you can lift", str(int(payload)), "tons to LEO.\nDon't abuse the drag bug!")
- # What would a realistic payload be?
- realistic = getPayload(isp, wet, dry, 3000.0)
- if realistic == -1:
- print("Realistically, you'll probably have a hard time getting anything to orbit.")
- else:
- print("Realistically, you'll probably be able to get", str(int(realistic)), "tons to orbit.")
- # Move it along now
- print("\nPress Enter to continue.")
- input()
- except ValueError:
- print("Please give me numbers.")
- except Exception as error:
- print(error)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement