Skip to content

Commit

Permalink
juice added to the gym
Browse files Browse the repository at this point in the history
  • Loading branch information
darioizzo committed Jul 19, 2019
1 parent 6a1e613 commit bb852a4
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 11 deletions.
8 changes: 0 additions & 8 deletions .travis.yml
Expand Up @@ -22,14 +22,6 @@ matrix:
sudo: required
services:
- docker
- env: PYKEP_BUILD="manylinux64Py27" DOCKER_IMAGE="pagmo2/manylinux1_x86_64_with_deps"
sudo: required
services:
- docker
#- env: PYKEP_BUILD="manylinux64Py27mu" DOCKER_IMAGE="pagmo2/manylinux1_x86_64_with_deps"
# sudo: required
# services:
# - docker
install:
- docker pull $DOCKER_IMAGE
script:
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Expand Up @@ -11,7 +11,7 @@ environment:
#- BUILD_TYPE: "Release"
- BUILD_TYPE: "Python36-x64"
- BUILD_TYPE: "Python37-x64"
- BUILD_TYPE: "Python27-x64"


install:
- if [%BUILD_TYPE%]==[MSVC_64_Python36] set PATH=C:\Miniconda36-x64\Scripts;%PATH%
Expand Down
15 changes: 14 additions & 1 deletion pykep/test.py
Expand Up @@ -168,7 +168,20 @@ def run_tandem_test(self):
4.21911761e-01, 3.38579352e+02, -1.68143357e+00, 1.10121434e+00,
6.39679220e-01, 1.17925136e+03, -2.02838607e+00, 1.05000000e+00,
2.31554532e-01, 1.80000707e+03]
self.assertAlmostEqual(udp.fitness(x)[0], -7.355990585895818)
self.assertAlmostEqual(udp.fitness(x)[0], -7.302117213470749)

def run_juice_test(self):
from .trajopt import gym
udp = gym.tandem(prob_id = 6, constrained=False)
x = [ 8.16283083e+03, 6.41922787e-01, 6.51202691e-01, 2.51009414e+03,
2.97841478e-01, 3.81541370e+02, 9.58572190e-01, 1.53007674e+00,
3.06125365e-01, 1.49264351e+02, 4.10103546e+00, 2.39297670e+00,
4.34424957e-01, 3.16066418e+02, 4.33225338e+00, 1.30946367e+00,
4.52048883e-01, 1.63208108e+02, 5.93850330e-01, 1.34871269e+00,
2.03288502e-01, 6.52494606e+02, -1.37902374e+00, 1.55482534e+00,
1.96917559e-01, 1.08471126e+03]
self.assertAlmostEqual(udp.fitness(x)[0], -7.987614956531155)



def run_test_suite(level=0):
Expand Down
64 changes: 64 additions & 0 deletions pykep/trajopt/_juice.py
Expand Up @@ -34,3 +34,67 @@ def __init__(self):
eta_ub=0.99,
rp_ub=10
)

def fitness(self, x):
T, Vinfx, Vinfy, Vinfz = self._decode_times_and_vinf(x)
# We transform it (only the needed component) to an equatorial system rotating along x
# (this is an approximation, assuming vernal equinox is roughly x and the ecliptic plane is roughly xy)
earth_axis_inclination = 0.409072975
# This is different from the GTOP tanmEM problem, I think it was bugged there as the rotation was in the wrong direction.
Vinfz = - Vinfy * sin(earth_axis_inclination) + Vinfz * cos(earth_axis_inclination)
# And we find the vinf declination (in degrees)
sindelta = Vinfz / x[3]
declination = asin(sindelta) / np.pi * 180.
# We now have the initial mass of the spacecraft
m_initial = launchers.ariane5(x[3] / 1000., declination)
# And we can evaluate the final mass via Tsiolkowsky
Isp = 312.
g0 = 9.80665
DV = super(_juice_udp, self).fitness(x)[0]
DV = DV + 275. # losses for 5 swingbys + insertion
m_final = m_initial * exp(-DV / Isp / g0)
# Numerical guard for the exponential
if m_final == 0:
m_final = 1e-320
return [-log(m_final), ]

def get_name(self):
return "JUICE"

def get_extra_info(self):
retval = "\t Sequence: " + \
[pl.name for pl in self._seq].__repr__()
return retval

def pretty(self, x):
"""
prob.plot(x)
- x: encoded trajectory
Prints human readable information on the trajectory represented by the decision vector x
Example::
print(prob.pretty(x))
"""
super(_juice_udp, self).pretty(x)
T, Vinfx, Vinfy, Vinfz = self._decode_times_and_vinf(x)
# We transform it (only the needed component) to an equatorial system rotating along x
# (this is an approximation, assuming vernal equinox is roughly x and the ecliptic plane is roughly xy)
earth_axis_inclination = 0.409072975
# This is different from the GTOP tanmEM problem, I think it was bugged there as the rotation was in the wrong direction.
Vinfz = - Vinfy * sin(earth_axis_inclination) + Vinfz * cos(earth_axis_inclination)
# And we find the vinf declination (in degrees)
sindelta = Vinfz / x[3]
declination = asin(sindelta) / np.pi * 180.
m_initial = launchers.ariane5(x[3] / 1000., declination)
# And we can evaluate the final mass via Tsiolkowsky
Isp = 312.
g0 = 9.80665
DV = super(_juice_udp, self).fitness(x)[0]
DV = DV + 275. # losses for 5 swgbys + insertion
m_final = m_initial * exp(-DV / Isp / g0)
print("\nInitial mass:", m_initial)
print("Final mass:", m_final)
print("Declination:", declination)
47 changes: 47 additions & 0 deletions pykep/trajopt/_launchers.py
Expand Up @@ -40,6 +40,37 @@
[1e-3, 1e-3, 1e-3, 1e-3, 1e-3, 1e-3]
]

# Ariane 5: data provided to ESOC by Arianespace when they were still considering Ariane launch for ExoMars.
# Negative mass values have been substituted with exp(m/1000) to avoid problems.
# Declination has been extended up to 90 degrees.
_vinfs_Ariane5 = [0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5, 5. , 5.5, 6. ]
_decls_Ariane5 = [-90, -50, -45, -40, -35, -30, -25, -20, -15, -10, -5, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 90]
_data_Ariane5 = [
[4.97870684e-02, 3.01973834e-02, 1.83156389e-02, 1.11089965e-02, 6.73794700e-03, 2.47875218e-03, 9.11881966e-04, 3.35462628e-04, 1.23409804e-04, 4.53999298e-05, 1.67017008e-05, 6.14421235e-06],
[4.97870684e-02, 3.01973834e-02, 1.83156389e-02, 1.11089965e-02, 6.73794700e-03, 2.47875218e-03, 9.11881966e-04, 3.35462628e-04, 1.23409804e-04, 4.53999298e-05, 1.67017008e-05, 6.14421235e-06],
[8.20849986e-02, 4.97870684e-02, 3.01973834e-02, 1.83156389e-02, 1.11089965e-02, 6.73794700e-03, 2.47875218e-03, 9.11881966e-04, 3.35462628e-04, 1.23409804e-04, 4.53999298e-05, 1.67017008e-05],
[1.35335283e-01, 8.20849986e-02, 4.97870684e-02, 2.55785799e-02, 1.83156389e-02, 1.11089965e-02, 6.73794700e-03, 2.47875218e-03, 9.11881966e-04, 3.35462628e-04, 1.23409804e-04, 4.53999298e-05],
[2.23130160e-01, 1.35335283e-01, 1.35335283e-01, 8.20849986e-02, 4.97870684e-02, 1.83156389e-02, 1.11089965e-02, 4.08677144e-03, 2.47875218e-03, 9.11881966e-04, 3.35462628e-04, 1.23409804e-04],
[3.67879441e-01, 2.63685018e-01, 2.23130160e-01, 1.89001562e-01, 1.35335283e-01, 4.97870684e-02, 1.83156389e-02, 6.73794700e-03, 4.08677144e-03, 2.47875218e-03, 9.11881966e-04, 3.35462628e-04],
[6.06530660e-01, 5.13759511e-01, 3.67879441e-01, 2.63685018e-01, 1.89001562e-01, 1.35335283e-01, 4.97870684e-02, 1.83156389e-02, 6.73794700e-03, 4.08677144e-03, 2.47875218e-03, 9.11881966e-04],
[5.00600000e+03, 4.66700000e+03, 6.06530660e-01, 3.67879441e-01, 2.63685018e-01, 1.89001562e-01, 1.35335283e-01, 4.97870684e-02, 1.83156389e-02, 1.11089965e-02, 6.73794700e-03, 2.47875218e-03],
[5.47400000e+03, 5.19500000e+03, 4.80500000e+03, 4.31600000e+03, 7.16770194e-01, 5.13759511e-01, 3.67879441e-01, 1.35335283e-01, 4.97870684e-02, 1.83156389e-02, 1.11089965e-02, 6.73794700e-03],
[5.83500000e+03, 5.61500000e+03, 5.29100000e+03, 4.87000000e+03, 4.35900000e+03, 3.77400000e+03, 3.13600000e+03, 3.67879441e-01, 1.35335283e-01, 4.97870684e-02, 1.83156389e-02, 1.83156389e-02],
[6.07800000e+03, 5.91000000e+03, 5.64800000e+03, 5.29500000e+03, 4.85600000e+03, 4.34000000e+03, 3.76300000e+03, 3.14100000e+03, 3.67879441e-01, 2.23130160e-01, 1.35335283e-01, 4.97870684e-02],
[6.19100000e+03, 6.05900000e+03, 5.84400000e+03, 5.54900000e+03, 5.18000000e+03, 4.74400000e+03, 4.25100000e+03, 3.71400000e+03, 3.15500000e+03, 6.06530660e-01, 3.67879441e-01, 1.35335283e-01],
[6.07300000e+03, 5.95300000e+03, 5.74900000e+03, 5.47000000e+03, 5.12700000e+03, 4.72900000e+03, 4.28600000e+03, 3.80800000e+03, 3.30400000e+03, 2.78500000e+03, 2.26000000e+03, 3.67879441e-01],
[3.67879441e-01, 3.32871084e-01, 3.01194212e-01, 2.72531793e-01, 2.46596964e-01, 2.23130160e-01, 2.01896518e-01, 1.82683524e-01, 1.65298888e-01, 1.49568619e-01, 1.35335283e-01, 1.22456428e-01],
[1.35335283e-01, 1.22456428e-01, 1.10803158e-01, 1.00258844e-01, 9.07179533e-02, 8.20849986e-02, 7.42735782e-02, 6.72055127e-02, 6.08100626e-02, 5.50232201e-02, 4.97870684e-02, 4.50492024e-02],
[2.23130160e-01, 2.63685018e-01, 3.67879441e-01, 4.72366553e-01, 6.06530660e-01, 7.78800783e-01, 4.08100000e+03, 3.50900000e+03, 2.89100000e+03, 2.24400000e+03, 3.67879441e-01, 1.35335283e-01],
[3.67879441e-01, 4.72366553e-01, 6.06530660e-01, 7.78800783e-01, 4.87400000e+03, 4.39100000e+03, 3.83600000e+03, 3.22000000e+03, 2.55900000e+03, 3.67879441e-01, 1.35335283e-01, 4.97870684e-02],
[6.06530660e-01, 7.78800783e-01, 5.48400000e+03, 5.13400000e+03, 4.69300000e+03, 4.16700000e+03, 3.56300000e+03, 2.89700000e+03, 2.19000000e+03, 2.23130160e-01, 4.97870684e-02, 1.83156389e-02],
[5.77300000e+03, 5.58900000e+03, 5.30600000e+03, 4.92400000e+03, 4.44300000e+03, 3.86800000e+03, 3.21000000e+03, 3.67879441e-01, 1.35335283e-01, 4.97870684e-02, 1.83156389e-02, 6.73794700e-03],
[5.65000000e+03, 5.44100000e+03, 5.12400000e+03, 4.69700000e+03, 4.16100000e+03, 3.52200000e+03, 3.67879441e-01, 1.35335283e-01, 4.97870684e-02, 1.83156389e-02, 6.73794700e-03, 2.47875218e-03],
[5.47700000e+03, 5.23900000e+03, 4.88200000e+03, 4.40100000e+03, 3.79500000e+03, 3.67879441e-01, 1.35335283e-01, 4.97870684e-02, 1.83156389e-02, 6.73794700e-03, 2.47875218e-03, 9.11881966e-04],
[5.30200000e+03, 5.02100000e+03, 4.60400000e+03, 4.04400000e+03, 3.67879441e-01, 1.35335283e-01, 4.97870684e-02, 1.83156389e-02, 6.73794700e-03, 2.47875218e-03, 9.11881966e-04, 3.35462628e-04],
[5.30200000e+03, 5.02100000e+03, 4.60400000e+03, 4.04400000e+03, 3.67879441e-01, 1.35335283e-01, 4.97870684e-02, 1.83156389e-02, 6.73794700e-03, 2.47875218e-03, 9.11881966e-04, 3.35462628e-04]
]

class _launchers:
"""
This class contains a few functions that return the mass launchers can deliver
Expand All @@ -59,6 +90,7 @@ class _launchers:
def __init__(self):
self._atlas501 = interp2d(_vinfs_A5, _decls_A5, _data_A5, kind='linear', fill_value=0.1, copy=False)
self._soyuzf = interp2d(_vinfs_SF, _decls_SF, _data_SF, kind='linear', fill_value=1e-3, copy=False)
self._ariane5 = interp2d(_vinfs_Ariane5, _decls_Ariane5, _data_Ariane5, kind='linear', fill_value=1e-3, copy=False)
def atlas501(self, vinfs, decls):
"""atlas501(vinfs, decls)
Expand Down Expand Up @@ -88,3 +120,18 @@ def soyuzf(self, vinfs, decls):
Numpy array containg the mass delivered to escape with said declinations and magnitudes.
"""
return self._soyuzf(vinfs, decls)
def ariane5(self, vinfs, decls):
"""ariane5(vinfs, decls)
Computes the mass that the Ariane5 launcher can deliver to a certain vinf and declination, assuming
a launch from Kourou. Data provided to ESOC by Arianespace when Ariane launch for ExoMars was an option.
If the inputs are arrays, then a mesh is considered and the mass is returned on points of the mesh.
Args:
- vinfs (``float`` or array-like): the hyperbolic escape velocity in km/s
- decls (``float`` or array-like): the declination in degrees
Returns:
Numpy array containg the mass delivered to escape with said declinations and magnitudes.
"""
return self._ariane5(vinfs, decls)
2 changes: 1 addition & 1 deletion pykep/trajopt/_tandem.py
Expand Up @@ -95,7 +95,7 @@ def fitness(self, x):
Isp = 312.
g0 = 9.80665
DV = super(_tandem_udp, self).fitness(x)[0]
DV = DV + 0.165 # losses for 3 swgbys + insertion
DV = DV + 165. # losses for 3 swgbys + insertion
m_final = m_initial * exp(-DV / Isp / g0)
# Numerical guard for the exponential
if m_final == 0:
Expand Down

0 comments on commit bb852a4

Please sign in to comment.