Jump to content

Transfer Stage Design Helper v1.2


RadHazard

Recommended Posts

This is a simple Java program I threw together for myself to help me design interplanetary transfer stages. After some people showed interest, I decided to share it. It takes three design parameters and outputs the number of engines and amount of fuel you'd need in order to meet that design.

lHNucHL.png

Instructions

The Java Runtime Environment is required to run the program. You can download it at java.com/en/download/

The program takes three inputs:

Minimum TWR: This is the minimum TWR you want your ship to have. This can be as low as you have patience for. Lower TWR results in higher fuel efficiency, especially when using the LV-N.

Minimum dV: This is the minimum amount of dV that your ship will have. There are many dV charts available to help you plan your mission. Increasing this will reduce your ship's payload fraction.

Payload Mass: This is how much your payload weighs. In this context, "payload" is defined as everything that's not an engine or a fuel tank, including RCS, landers, and upper stages. You can design multi-stage craft with this program by designing the final stage, then using the total weight of that stage as the payload of the next stage, and so on.

The program outputs a table of all the stock LFO engines, Ion Engine, and an optional custom engine you can enter values for, along with various number related to each:

Name: The name of the engine

Engines Required: This is the number of engines required to meet your design specifications for your given payload weight. When designing the stage, add this many engines and ensure they all have equal amounts of fuel (or that they all draw from the same fuel tank)

Total Fuel Mass: This is how much fuel, in tons, that you need to add to your ship if you use the specified engine. You will either need to round up or down to the nearest small fuel tank or you will need to use the procedural fuel tanks mod in order to get exactly this amount. The ability to accommodate non-infinitely-divisible fuel tanks is coming in a future version.

Total Ship Mass: This is the total mass of your ship, assuming you meet the design parameters exactly. This will help you design a mass-efficient ship.

Payload Fraction: This is the fraction of your ship that is payload, as opposed to engines and fuel.

If any of the rows are empty, that means that specific engine cannot meet your design requirements. You will need to reduce either the minimum dV or the minimum TWR. This is independent of payload mass because carrying a payload twice as large simply requires twice the engines and twice the fuel.

When choosing the engine to use, note that the best engine for the job depends on your preferences. Lower mass results in a smaller launch vehicle, whereas lower part count reduces lag. A smaller Engines Required makes your ship somewhat lighter and drastically reduces part count, while lower fuel mass drastically reduces weight, with a less drastic reduction in part count. I hope to include part count (not including your payload, of course) as part of the readout in a future implementation.

Custom Engine

Version 1.2 supports custom engines. Simply enter the mass, thrust, and vacuum ISP of your desired engine, along with the type of fuel it uses (only LFO and Xenon are supported right now). The chart will update the custom engine automatically.

How it works

The program works in four steps

1) Figure out how much mass each engine can lift while still maintaining the given T/W ratio. This depends only on engine thrust, engine mass, and target T/W.

2) Use the inverted rocket equation to figure out how much mass each engine can carry as payload while still meeting the dV requirement (that is, the payload fraction). This changes depending on the above max load and the given dV.

3) Divide the payload mass by the payload mass/engine to figure out how many engines are required to lift your given payload. This uses the previously calculated payload fraction and the given payload mass.

4) Again using the inverted rocket equation, calculate the exact amount of fuel needed to achieve the desired dV, given the number of engines attached.

This approach is analytic, so it should be perfectly correct (barring any rounding errors). If you build your ship with the given instructions, it should meet or exceed both the given TWR and dV you provided. Also note that this program is meant for designing interplanetary stages only. The difference in engine ISP in-atmosphere means that your ship will have less dV than what my program predicts, so if you try to design a launcher with it you'll need to pack extra dV.

Changelog


v1.2
- Modified fuel weight calculation to better adhere to payload mass. It will no longer overshoot the total fuel required. In most cases the difference was minor, but in certain edge cases (e.g. a 1-ton probe with a Mainsail) it would pile on a ridiculous amount of fuel.
- Added Ion support (3 different modes: Gigantor, 9 OX-4, or No solar panels)
- Added custom engine support

v1.1
- Removed the Max Load, Max dV, and Max Payload columns. They weren't really useful to designing your ship and they cluttered the interface.
- You can now sort columns by clicking the column header
- If an engine cannot meet the requirements, it now displays a dash rather than nonsensical negative numbers

v1.0
- Now has a GUI!
- Fixed a bug in calculations resulting in incorrect numbers

v0.5
- First public release.

Download

Download Here

Source Here

Liscense

Copyright © 2013, Ryan Schneider

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Edited by RadHazard
Version 1.2
Link to comment
Share on other sites

  • 4 weeks later...

Finally put up a new version, with a proper GUI. You no longer need the console to use it. I also found a bug in the calculations that resulted in the wrong numbers (I had accidentally had a multiplication instead of division in one place). If the numbers are still very far off from what MechJeb/Kerbal Engineer report, let me know.

Edit: Oops, it was still broken. NOW the calculation bug should be fixed.

Edited by RadHazard
Link to comment
Share on other sites

This... This is mathematical genius stored neatly in one program. You sir are amazing.

Thanks, I'm glad you like it.

New Version Released: v1.1

I polished up the interface a lot. It's nicer now, and it has a column for total mass and payload fraction as well. I removed the Max Load, Max dV, and Max Payload columns, as those were only really useful for debugging. I added some needed code for Ion-Engine support, although it's not functional yet.

Link to comment
Share on other sites

New Version Released: v1.2

- Ion engine support added. Correctly calculates the ion engine using the mass ratio of the larger xenon tank. The engine shows up three different times on the chart, one for using a single Gigantor to power the engine, one for using 9 OX-4 panels (same power as 1 Gigantor but less weight), and one without solar panes (assumes your ship has some other form of power generation included in the payload).

- You can also add a custom engine using the boxes at the bottom, in case you want to calculate with a mod-added engine. However, only engines that use LFO or Xenon are currently supported.

- Finally, I changed the way fuel is calculated so it no longer overshoots the amount of fuel to add. Previously, the calculator would find the minimum number of engines needed, and then added as much fuel as possible. This produced close-to-optimal fuel levels in most cases. However, in extreme situations, such as where a single engine was overkill (A one-ton space probe with a mainsail, for example), it would gleefully keep piling on fuel until it reached the TWR you specified, resulting in a 1-ton probe with 800 tons of fuel attached to it. It now adds the minimum amount of fuel necessary to meet your dV requirement, choosing mass-efficiency over extra dV.

I'm attempting to add proper fuel-tank count for the next version. However, this is proving more difficult than simply modifying my analytic approach, as adding non-infinitely-divisible fuel tanks with differing mass ratios results in a non-linear optimization problem.

Edited by RadHazard
Link to comment
Share on other sites

Mixed-integer nonlinear optimization problem to be specific, at least if you want to allow for mixing multiple engine types. If you stick to single engine types, you can use a table-driven approach where you pre-calculate a discrete list of possibly-optimal fuel tank combinations. Start by enumerating all integer combinations of FL-T100, Oscar-B, and Round-8. Due to their worse mass ratios, you'll never need more than about 10 Oscar-B's or Round-8's. Then sort the fuel tank combinations by total mass (propellant + dry), and prune any configuration that has lower fuel mass than some lighter-total-mass combination.

For mixing engine types, you'll need some extremely sophisticated branch-and-bound mixed-integer optimization. Have a look at the osil file I made here: http://forum.kerbalspaceprogram.com/threads/45155-Mass-optimal-engine-type-vs-delta-V-payload-and-min-TWR/page3, it wouldn't be too tough to programmatically modify the appropriate data in the osil file, call the OSSolverService executable, and read the result back into your Java gui.

Edited by tavert
Link to comment
Share on other sites

Thanks for the help. I'd rather not restrain my code to shortcuts based on the properties of stock parts as I'd like to add mod support at some point, but that solver looks like it might be really helpful.

I've actually managed to reduce the problem of single engine types to a mixed-integer linear optimization. Unfortunately, mixed-integer linear programming is still NP-hard, so that doesn't help much. I'm guessing that at this point I'm probably going to have to use some kind of solver in order to make any progress.

Link to comment
Share on other sites

How'd you get it to be linear? The delta-V constraint depends on the log of the mass ratio. Full mass and empty mass are linear functions of the number of tanks and engines.

There are plenty of good MILP solvers. I think CBC is the Coin-OR MILP solver, there's also SCIP (http://scip.zib.de/). Most of the specialized MILP modeling languages are kind of archaic, OSiL is pretty nice and reasonably human-readable as long as you understand how to represent a compressed row (or compressed column) sparse matrix. The generality of extending to nonlinear problems is also hard to match.

Link to comment
Share on other sites

It required some trickery. It actually happened somewhat accidentally. In my code I had created a variable that I used multiple times when calculating the inverted rocket equation. I had solved the rocket equation for the wet/dry mass ratio, which is equal to e^(dV / (g0 * ISP)). I also noticed that the dV of a rocket is dependant only on the ratio of these masses, assuming ISP is constant. If a rocket had a greater wet/dry mass ratio, it would always exceed the dV requirement.

wetMass
------- >= DMR (desired mass ratio)
dryMass

After looking at this for a bit, I realized I could multiply both sides by the dry mass without disturbing the greater-than operator as I knew that dry mass would always be positive and non-zero. I then subtracted that from both sides, leaving me with

wetMass - DMR*dryMass >= 0

which when expanded becomes

m[SUB]p[/SUB] + m[SUB]e[/SUB]x[SUB]e[/SUB] + (wm[SUB]1[/SUB]x[SUB]1[/SUB] + ... + wm[SUB]n[/SUB]x[SUB]n[/SUB]) - DMR * (p + m[SUB]e[/SUB]x[SUB]e[/SUB] + dm[SUB]1[/SUB]x[SUB]1[/SUB] + ... dm[SUB]n[/SUB]x[SUB]n[/SUB]) >= 0

where

mp is the mass of the payload

me is the mass of each engine

wmi is the wet mass of the ith fuel tank

dmi is the dry mass of the ith fuel tank

xe is the number of engines

xi is the number of the ith fuel tanks

Te is the thrust of each engine.

I rearranged it and got

(m[SUB]p[/SUB] - DMR * m[SUB]p[/SUB]) + (m[SUB]e[/SUB] - DMR * m[SUB]e[/SUB])x[SUB]e[/SUB] + (wm[SUB]1[/SUB] - DMR * dm[SUB]1[/SUB])x[SUB]1[/SUB] + ... + (wm[SUB]n[/SUB] - DMR * dm[SUB]n[/SUB])x[SUB]n[/SUB] >= 0

Looking at, it makes sense to me. (wm - DMR * dm), the constant portion, is basically a measure of how much each part contributes to the DMR, and therefore the dV constraint.

I did a similar thing for the TWR constraint, which gave me

T[SUB]e[/SUB]x[SUB]e[/SUB] - (TWR * m[SUB]p[/SUB]) - (TWR * m[SUB]e[/SUB])x[SUB]e[/SUB] - (TWR * m[SUB]1[/SUB])x[SUB]1[/SUB] - ... - (TWR * m[SUB]n[/SUB])x[SUB]n[/SUB] >= 0

Again, (TWR * m) ends up being a measure of how much each part subtracts from the desired TWR.

Edited by RadHazard
Oh dear, grammar.
Link to comment
Share on other sites

Ah, okay, if you consider Isp constant and only look at a single engine type at a time (or I suppose you could combine different engine types as long as the Isp's are equal), then the delta-V constraint is equivalent to a mass-ratio constraint which you can reformulate as a linear inequality. I was still thinking of Isp as being a variable equal to thrust / (g0*mdot), where thrust and mdot are linear functions of the numbers of different types of engines.

Good idea, solving one or two dozen tiny MILP's (one per engine type) is probably faster than solving one bigger MINLP (hard to say for sure until you try though). Especially since I'd have to introduce a binary indicator variable for each engine type if I wanted to restrict the MINLP version to a single engine type.

Edited by tavert
Link to comment
Share on other sites

CBC does the trick in a quick test. Try out https://dl.dropboxusercontent.com/u/8244638/single_engine_type.osil (or https://dl.dropboxusercontent.com/u/8244638/single_engine_type_commented.osil, though this one's much simpler to read even without comments). I ran my test example as follows (assuming you're in an environment where sed is available, otherwise use your text-replacing tool of choice):

sed -e 's/MIN_ACCELERATION/9.81/g' -e 's/PAYLOAD_MASS/10/g' -e 's/ENGINE_MASS/2.25/g' -e 's/ENGINE_THRUST/60/g' -e 's/MAX_NUM_ENGINES/16/g' -e 's/ONE_MINUS_RECIPROCAL_DMR/0.399003/g' single_engine_type.osil > lvn_twr1_payload10_dv4000.osil

OSSolverService osil lvn_twr1_payload10_dv4000.osil

It's 3 linear constraints and 5 variables for stock fuel tank types: total mass, number of specified type of engine, number of FL-T100's, number of Round-8's, and number of Oscar-B's. One equality for total mass, one inequality for min TWR (total thrust >= MIN_ACCELERATION*total_mass, where MIN_ACCELERATION = 9.81*MIN_TWR for Kerbin-relative weight), and one inequality for min delta-V: dry_mass <= total_mass / DMR, expanded out to ONE_MINUS_RECIPROCAL_DMR*total_mass - fuel_mass <= 0.

In my thread I had been using g0 = 9.81 for Isp for consistency with MechJeb/KER, but the 0.399003 number above was calculated using the correct g0 = 9.82 so I get a tiny bit lighter answer here of 9 LV-N's, 43 FL-T100 tanks, and 4 Round-8 tanks. Keep an eye out for rounding on the integer variables output from CBC, it seems to be displaying them with either .99... or .0...01 for whatever reason.

Small MILP is about 2 orders of magnitude faster than the MINLP I previously had, takes tens of milliseconds versus a couple of seconds for the MINLP.

If you're in Linux or Mac or Cygwin and have the bc calculator available, you can save a little bit of hassle by replacing that last expression 's/ONE_MINUS_RECIPROCAL_DMR/0.399003/g' with "s/ONE_MINUS_RECIPROCAL_DMR/`echo "1-e(-4000/(9.82*800))" | bc -l`/g", though you can do this programmatically in whatever other language you feel like.

Edited by tavert
Link to comment
Share on other sites

I was bored/procrastinating and you've been gone for a few days, so I went and made an interactive version using Mathematica to solve the MILP's, you can check it out at http://dl.dropboxusercontent.com/u/8244638/KSP%20Design%20Optimizer%20v01.html

You'll need the Wolfram CDF Player plugin to use this, hopefully it should tell you so if you don't have it installed but if not, see http://www.wolfram.com/cdf-player/

I put in the bigger tanks and a part-count constraint too, for fun. I suppose I could throw in the ion engine + solar panel combinations like you have them. Your changelog and posts say you're using 8 OX-4's as one of the combinations (which is consistent with my numbers for how many panels you'd need for one ion engine, though I think their effectiveness drops further from the sun?), but your code appears to be using 9. You aren't using the fuel tank stats yet in your current version, but note that FL-T100's have 45 units of liquid and 55 units of oxidizer, so 100 total not 90.

Link to comment
Share on other sites

Thanks for all the help, tavert.

I've been busy with college work for the past week or so, so I haven't had much time to work on this. I've been hoping to find a native java MILP solver to avoid platform-specific binaries, but it looks like there aren't any of those around. I'm not exactly up to the task of writing a solver myself, so I think I'll end up using the one you linked.

I looked at my code, and I remembered that I used 9 OX-4's because it's equal to the output of exactly one gigantor, which is what is generally recommenced for Ion engines, as far as I've seen. Perhaps at some point I'll end up adding in a second calculator to find the ideal number of solar panels to power an electrical engine with a given power draw. As for the FL-T100 bug, thanks for that. I must have spaced out when putting in values from the wiki and added wrong. The name of the tank certainly makes more sense now :)

Link to comment
Share on other sites

This problem's simple and small enough that you could write a branch-and-bound solver yourself without too much trouble. The continuous relaxation can be solved greedily by using the best mass-ratio fuel tanks first, up to the maximum imposed by integer-branching constraints. It'll be faster in both coding time and running time to just use an existing general-purpose solver though, at the cost of having binary dependencies users will have to download.

Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...

I'm back. I've been caught up with college work for the past month, but I figured I'd finally take a crack at some mixed integer linear programming. I'm planning on using Apache Commons Math for the matrix operations and implementing a simple cutting-plane algorithm. I'm hoping performance won't be too much of an issue since the number of variables I'm working with should be small.

I'd like modify the solver to account for solar panels/RTGs at some point as well, but I think I'll try and get the basic fuel-tank solver working first before I try anything too crazy.

Link to comment
Share on other sites

  • 2 weeks later...

An update on what I've been up to:

I've got a cutting plane algorithm written that uses Gomory's Cuts. Unfortunately, I'm having trouble getting performance to reasonable levels, which is mostly due to (I'm assuming) my poor heuristic for choosing the cutting plane, leading to a large number of barely useful cuts. I'll continue to hammer this out, and with luck I should have a usable version available Soontm.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...