-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Modified SSTO problem to be a single component rather than a group * Updated problem to use wildcard for derivative declaration * Removed anayltical derivatives. Removed cb as an option and replaced it with options for rho_ref and h_scale. Removed targets and units where not longer necessary * fixed test_upgrade_guide problem to match changes to LaunchVehicleODE * added tolerance to coloring * Modified scaling on problem * updated some docs for kaushiks SSTO case * formatting fix for pep8 Co-authored-by: Kaushik Ponnapalli <kaushik.s.ponnapalli@nasa.gov> Co-authored-by: Rob Falck <rfalck@nasa.gov>
- Loading branch information
1 parent
9ee496b
commit 41c23c5
Showing
8 changed files
with
146 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,121 @@ | ||
import openmdao.api as om | ||
import numpy as np | ||
|
||
from .log_atmosphere_comp import LogAtmosphereComp | ||
from .launch_vehicle_2d_eom_comp import LaunchVehicle2DEOM | ||
|
||
|
||
class LaunchVehicleODE(om.Group): | ||
class LaunchVehicleODE(om.ExplicitComponent): | ||
|
||
def initialize(self): | ||
self.options.declare('num_nodes', types=int, | ||
desc='Number of nodes to be evaluated in the RHS') | ||
|
||
self.options.declare('central_body', values=['earth', 'moon'], default='earth', | ||
desc='The central gravitational body for the launch vehicle.') | ||
self.options.declare('g', types=float, default=9.80665, | ||
desc='Gravitational acceleration, m/s**2') | ||
|
||
self.options.declare('rho_ref', types=float, default=1.225, | ||
desc='Reference atmospheric density, kg/m**3') | ||
|
||
self.options.declare('h_scale', types=float, default=8.44E3, | ||
desc='Reference altitude, m') | ||
|
||
self.options.declare('CD', types=float, default=0.5, | ||
desc='coefficient of drag') | ||
|
||
self.options.declare('S', types=float, default=7.069, | ||
desc='aerodynamic reference area (m**2)') | ||
|
||
def setup(self): | ||
nn = self.options['num_nodes'] | ||
cb = self.options['central_body'] | ||
|
||
if cb == 'earth': | ||
rho_ref = 1.225 | ||
h_scale = 8.44E3 | ||
elif cb == 'moon': | ||
rho_ref = 0.0 | ||
h_scale = 1.0 | ||
else: | ||
raise RuntimeError('Unrecognized value for central_body: {0}'.format(cb)) | ||
self.add_input('y', | ||
val=np.zeros(nn), | ||
desc='altitude', | ||
units='m') | ||
|
||
self.add_input('vx', | ||
val=np.zeros(nn), | ||
desc='x velocity', | ||
units='m/s') | ||
|
||
self.add_input('vy', | ||
val=np.zeros(nn), | ||
desc='y velocity', | ||
units='m/s') | ||
|
||
self.add_input('m', | ||
val=np.zeros(nn), | ||
desc='mass', | ||
units='kg') | ||
|
||
self.add_input('theta', | ||
val=np.zeros(nn), | ||
desc='pitch angle', | ||
units='rad') | ||
|
||
self.add_input('thrust', | ||
val=2100000 * np.ones(nn), | ||
desc='thrust', | ||
units='N') | ||
|
||
self.add_input('Isp', | ||
val=265.2 * np.ones(nn), | ||
desc='specific impulse', | ||
units='s') | ||
# Outputs | ||
self.add_output('xdot', | ||
val=np.zeros(nn), | ||
desc='velocity component in x', | ||
units='m/s') | ||
|
||
self.add_output('ydot', | ||
val=np.zeros(nn), | ||
desc='velocity component in y', | ||
units='m/s') | ||
|
||
self.add_output('vxdot', | ||
val=np.zeros(nn), | ||
desc='x acceleration magnitude', | ||
units='m/s**2') | ||
|
||
self.add_output('vydot', | ||
val=np.zeros(nn), | ||
desc='y acceleration magnitude', | ||
units='m/s**2') | ||
|
||
self.add_output('mdot', | ||
val=np.zeros(nn), | ||
desc='mass rate of change', | ||
units='kg/s') | ||
|
||
self.add_output('rho', | ||
val=np.zeros(nn), | ||
desc='density', | ||
units='kg/m**3') | ||
|
||
# Setup partials | ||
# Complex-step derivatives | ||
self.declare_coloring(wrt='*', method='cs', show_sparsity=True) | ||
|
||
def compute(self, inputs, outputs): | ||
|
||
theta = inputs['theta'] | ||
cos_theta = np.cos(theta) | ||
sin_theta = np.sin(theta) | ||
vx = inputs['vx'] | ||
vy = inputs['vy'] | ||
m = inputs['m'] | ||
F_T = inputs['thrust'] | ||
Isp = inputs['Isp'] | ||
y = inputs['y'] | ||
|
||
self.add_subsystem('atmos', | ||
LogAtmosphereComp(num_nodes=nn, rho_ref=rho_ref, h_scale=h_scale)) | ||
g = self.options['g'] | ||
rho_ref = self.options['rho_ref'] | ||
h_scale = self.options['h_scale'] | ||
|
||
self.add_subsystem('eom', LaunchVehicle2DEOM(num_nodes=nn, central_body=cb)) | ||
CDA = self.options['CD'] * self.options['S'] | ||
|
||
self.connect('atmos.rho', 'eom.rho') | ||
outputs['rho'] = rho_ref * np.exp(-y / h_scale) | ||
outputs['xdot'] = vx | ||
outputs['ydot'] = vy | ||
outputs['vxdot'] = (F_T * cos_theta - 0.5 * CDA * outputs['rho'] * vx**2) / m | ||
outputs['vydot'] = (F_T * sin_theta - 0.5 * CDA * outputs['rho'] * vy**2) / m - g | ||
outputs['mdot'] = -F_T / (g * Isp) |
Oops, something went wrong.