Skip to content

Commit

Permalink
allow different objectives for multiphase
Browse files Browse the repository at this point in the history
  • Loading branch information
junzis committed Jul 12, 2022
1 parent be27c69 commit 392144a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 11 additions & 4 deletions openap/top/full.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from collections.abc import Iterable

import casadi as ca
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -359,16 +361,21 @@ def change_engine(self, engtype):

def trajectory(self, objective="fuel", **kwargs) -> pd.DataFrame:

if isinstance(objective, Iterable):
obj_cl, obj_cr, obj_de = objective
else:
obj_cl = obj_cr = obj_de = objective

if self.debug:
print("Finding the preliminary optimal cruise trajectory parameters...")

dfcr = self.curise.trajectory(objective, **kwargs)
dfcr = self.curise.trajectory(obj_cr, **kwargs)

# climb
if self.debug:
print("Finding optimal climb trajectory...")

dfcl = self.climb.trajectory(objective, dfcr, **kwargs)
dfcl = self.climb.trajectory(obj_cl, dfcr, **kwargs)

# cruise
if self.debug:
Expand All @@ -377,14 +384,14 @@ def trajectory(self, objective="fuel", **kwargs) -> pd.DataFrame:
self.curise.initial_mass = dfcl.mass.iloc[-1]
self.curise.lat1 = dfcl.lat.iloc[-1]
self.curise.lon1 = dfcl.lon.iloc[-1]
dfcr = self.curise.trajectory(objective, **kwargs)
dfcr = self.curise.trajectory(obj_cr, **kwargs)

# descent
if self.debug:
print("Finding optimal descent trajectory...")

self.descent.initial_mass = dfcr.mass.iloc[-1]
dfde = self.descent.trajectory(objective, dfcr, **kwargs)
dfde = self.descent.trajectory(obj_de, dfcr, **kwargs)

# find top of descent
dbrg = np.array(
Expand Down
2 changes: 2 additions & 0 deletions test/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
m0 = 0.85

optimizer = otop.CompleteFlight(actype, origin, destination, m0)
optimizer = otop.MultiPhase(actype, origin, destination, m0)
# optimizer = otop.Cruise(actype, origin, destination, m0)
# optimizer = otop.Climb(actype, origin, destination, m0)
# optimizer = otop.Descent(actype, origin, destination, m0)
Expand All @@ -21,6 +22,7 @@
# flight = optimizer.trajectory(objective="ci:30")
# flight = optimizer.trajectory(objective="gwp100")
# flight = optimizer.trajectory(objective="gtp100")
# flight = optimizer.trajectory(objective=("ci:90", "ci:10", "ci:20")) # Multiphase


print(flight)
Expand Down

0 comments on commit 392144a

Please sign in to comment.