示例#1
0
    def test_MissionSegment(self):

        #num_elem = 100
        #num_cp = 30
        x_range = 9000.0

        num_elem = 6
        num_cp = 3

        altitude = np.zeros(num_elem + 1)
        altitude = 10 * np.sin(np.pi * np.linspace(0, 1, num_elem + 1))

        x_range *= 1.852
        x_init = x_range * 1e3 * (
            1 - np.cos(np.linspace(0, 1, num_cp) * np.pi)) / 2 / 1e6
        M_init = np.ones(num_cp) * 0.8
        h_init = 10 * np.sin(np.pi * x_init / (x_range / 1e3))

        model = set_as_top(
            MissionSegment(num_elem=num_elem,
                           num_cp=num_cp,
                           x_pts=x_init,
                           surr_file='../crm_surr'))

        model.h_pt = h_init
        model.M_pt = M_init
        model.set_init_h_pt(altitude)

        # Initial parameters
        model.S = 427.8 / 1e2
        model.ac_w = 210000 * 9.81 / 1e6
        model.thrust_sl = 1020000.0 / 1e6
        model.SFCSL = 8.951 * 9.81
        model.AR = 8.68
        model.oswald = 0.8

        # Add param/obj/constr to make sure they set up.
        #gamma_lb = np.tan(-10.0 * (np.pi/180.0))/1e-1
        #gamma_ub = np.tan(10.0 * (np.pi/180.0))/1e-1
        #model.replace('driver', SimpleDriver())
        #model.driver.add_parameter('h_pt', low=0.0, high=20.0)
        #model.driver.add_objective('SysFuelObj.fuelburn')
        #model.driver.add_constraint('SysHi.h_i = 0.0')
        #model.driver.add_constraint('SysHf.h_f = 0.0')
        #model.driver.add_constraint('SysTmin.Tmin < 0.0')
        #model.driver.add_constraint('SysTmax.Tmax < 0.0')
        #model.driver.add_constraint('%.15f < SysGammaBspline.Gamma < %.15f' %
        #(gamma_lb, gamma_ub), linear=True)

        # Linear GS doesn't work yet
        #model.driver.gradient_options.lin_solver = 'petsc_ksp'

        model.run()
示例#2
0
    def test_MissionSegment(self):

        num_elem = 100
        num_cp = 30
        x_range = 150.0

        x_init = x_range * 1e3 * (1-np.cos(np.linspace(0, 1, num_cp)*np.pi))/2/1e6
        v_init = np.ones(num_cp)*2.3
        h_init = 1 * np.sin(np.pi * x_init / (x_range/1e3))

        model = set_as_top(MissionSegment(num_elem, num_cp, x_init))

        model.h_pt = h_init
        model.v_pt = v_init

        # Pull velocity from BSpline instead of calculating it.
        model.SysSpeed.v_specified = True

        # Initial parameters
        model.S = 427.8/1e2
        model.ac_w = 210000*9.81/1e6
        model.thrust_sl = 1020000.0/1e6/3
        model.SFCSL = 8.951
        model.AR = 8.68
        model.oswald = 0.8

        model.run()

        # Load in original data from pickle
        dirname = os.path.abspath(os.path.dirname(__file__))
        filename = os.path.join(dirname, 'analysis.p')
        old_data = pickle.load(open(filename, 'rb'))

        # Some names changed
        old_data['Gamma'] = old_data['gamma']
        old_data['temp'] = old_data['Temp']

        # Don't compare the extra constraint/objective stuff, because we
        # don't create comps for them.
        old_keys = old_data.keys()
        old_keys.remove('gamma')
        old_keys.remove('gamma_max')
        old_keys.remove('gamma_min')
        #old_keys.remove('Tmin')
        #old_keys.remove('Tmax')
        #old_keys.remove('h_i')
        #old_keys.remove('h_f')
        #old_keys.remove('wf_obj')
        old_keys.remove('CL_tar')
        old_keys.remove('thrust_sl')
        old_keys.remove('e')
        old_keys.remove('Temp')
        old_keys.remove('M_pt')


        # Find data in model
        new_data = {}
        comps = [comp for comp in model.list_components() if comp not in ['coupled_solver', 'drag_solver']]
        for name in comps:
            comp = model.get(name)
            for key in old_keys:
                if key in comp.list_vars():
                    new_data[key] = comp.get(key)
                    old_keys.remove(key)

        self.assertEqual(len(old_keys), 0)

        for key in new_data.keys():
            old = old_data[key]
            new = new_data[key]

            #diff = np.nan_to_num(abs(new - old) / old)
            diff = new-old
            #print key
            #print old
            #print new
            assert_rel_error(self, diff.max(), 0.0, 1e-12)
示例#3
0
altitude = np.zeros(num_elem + 1)
altitude = 10 * np.sin(np.pi * np.linspace(0, 1, num_elem + 1))

start = time.time()
num_cp = num_cp_init
while num_cp <= num_cp_max:

    x_range *= 1.852
    x_init = x_range * 1e3 * (
        1 - np.cos(np.linspace(0, 1, num_cp) * np.pi)) / 2 / 1e6
    M_init = np.ones(num_cp) * 0.82
    h_init = 10 * np.sin(np.pi * x_init / (x_range / 1e3))

    model = set_as_top(
        MissionSegment(num_elem=num_elem,
                       num_cp=num_cp,
                       x_pts=x_init,
                       surr_file='crm_surr'))

    model.replace('driver', pyOptSparseDriver())
    #model.replace('driver', SimpleDriver())
    model.driver.optimizer = 'SNOPT'
    model.driver.options = {'Iterations limit': 5000000}

    # Add parameters, objectives, constraints
    model.driver.add_parameter('h_pt', low=0.0, high=14.1)
    model.driver.add_objective('SysFuelObj.fuelburn')
    model.driver.add_constraint('SysHBspline.h[0] = 0.0')
    model.driver.add_constraint('SysHBspline.h[-1] = 0.0')
    model.driver.add_constraint('SysTmin.Tmin < 0.0')
    model.driver.add_constraint('SysTmax.Tmax < 0.0')
    model.driver.add_constraint('%.15f < SysGammaBspline.Gamma < %.15f' % \
示例#4
0
    def test_MissionSegment(self):

        num_elem = 100
        num_cp = 30
        x_range = 9000.0

        altitude = np.zeros(num_elem + 1)
        altitude = 10 * np.sin(np.pi * np.linspace(0, 1, num_elem + 1))

        x_range *= 1.852
        x_init = x_range * 1e3 * (
            1 - np.cos(np.linspace(0, 1, num_cp) * np.pi)) / 2 / 1e6
        M_init = np.ones(num_cp) * 0.8
        h_init = 10 * np.sin(np.pi * x_init / (x_range / 1e3))

        model = set_as_top(
            MissionSegment(num_elem=num_elem,
                           num_cp=num_cp,
                           x_pts=x_init,
                           surr_file='../crm_surr'))

        model.h_pt = h_init
        model.M_pt = M_init
        model.set_init_h_pt(altitude)

        # Initial parameters
        model.S = 427.8 / 1e2
        model.ac_w = 210000 * 9.81 / 1e6
        model.thrust_sl = 1020000.0 / 1e6
        model.SFCSL = 8.951 * 9.81
        model.AR = 8.68
        model.oswald = 0.8

        # Some adjustments to match the case ran for the pickle
        #model.SysFuelWeight.fuel_scale = 1e6
        #model.SysTau.thrust_scale = 0.072

        model.run()

        # Load in original data from pickle
        dirname = os.path.abspath(os.path.dirname(__file__))
        filename = os.path.join(dirname, 'analysis2.p')
        old_data = pickle.load(open(filename, 'rb'))

        # Some names changed
        old_data['Gamma'] = old_data['gamma']
        old_data['temp'] = old_data['Temp']

        # Don't compare the extra constraint/objective stuff, because we
        # don't create comps for them.
        old_keys = old_data.keys()
        old_keys.remove('gamma')
        old_keys.remove('CL_tar')
        old_keys.remove('Temp')
        old_keys.remove('M_i')
        old_keys.remove('M_f')
        old_keys.remove('h_i')
        old_keys.remove('h_f')
        old_keys.remove('M_spline')
        old_keys.remove('jason')
        old_keys.remove('time')

        # Find data in model
        new_data = {}
        comps = [
            comp for comp in model.list_components()
            if comp not in ['coupled_solver']
        ]
        for name in comps:
            comp = model.get(name)
            s1 = set(comp.list_vars())
            s2 = set(old_keys)
            s_int = s1.intersection(s2)
            for key in s_int:
                new_data[key] = comp.get(key)
                old_keys.remove(key)

        print old_keys
        self.assertEqual(len(old_keys), 0)

        for key in new_data.keys():
            old = old_data[key]
            new = new_data[key]

            #diff = np.nan_to_num(abs(new - old) / old)
            diff = new - old
            print key
            print old
            print new
            assert_rel_error(self, diff.max(), 0.0, 1e-3)
示例#5
0
    def test_MissionSegment(self):

        # define bounds for the flight path angle
        gamma_lb = np.tan(-10.0 * (np.pi / 180.0)) / 1e-1
        gamma_ub = np.tan(10.0 * (np.pi / 180.0)) / 1e-1

        num_elem = 100
        num_cp = 30
        x_range = 9000.0

        altitude = np.zeros(num_elem + 1)
        altitude = 10 * np.sin(np.pi * np.linspace(0, 1, num_elem + 1))

        x_range *= 1.852
        x_init = x_range * 1e3 * (
            1 - np.cos(np.linspace(0, 1, num_cp) * np.pi)) / 2 / 1e6
        M_init = np.ones(num_cp) * 0.8
        h_init = 10 * np.sin(np.pi * x_init / (x_range / 1e3))

        model = set_as_top(
            MissionSegment(num_elem=num_elem,
                           num_cp=num_cp,
                           x_pts=x_init,
                           surr_file='../crm_surr'))
        model.replace('driver', SimpleDriver())

        model.h_pt = h_init
        model.M_pt = M_init
        model.set_init_h_pt(altitude)

        # Initial parameters
        model.S = 427.8 / 1e2
        model.ac_w = 210000 * 9.81 / 1e6
        model.thrust_sl = 1020000.0 / 1e6
        model.SFCSL = 8.951 * 9.81
        model.AR = 8.68
        model.oswald = 0.8

        model.driver.add_parameter('h_pt', low=0.0, high=20.0)
        model.driver.add_objective('SysFuelObj.fuelburn')
        model.driver.add_constraint('SysHi.h_i = 0.0')
        model.driver.add_constraint('SysHf.h_f = 0.0')
        model.driver.add_constraint('SysTmin.Tmin < 0.0')
        model.driver.add_constraint('SysTmax.Tmax < 0.0')
        model.driver.add_constraint('%.15f < SysGammaBspline.Gamma < %.15f' %
                                    (gamma_lb, gamma_ub),
                                    linear=True)

        model.run()

        new_derivs = model.driver.calc_gradient(return_format='dict')

        # Load in original data from pickle
        dirname = os.path.abspath(os.path.dirname(__file__))
        filename = os.path.join(dirname, 'derivs2.p')
        old_derivs_dict = pickle.load(open(filename, 'rb'))

        translate_dict = {
            'fuelburn': '_pseudo_2.out0',
            'h_i': '_pseudo_3.out0',
            'h_f': '_pseudo_4.out0',
            'Tmin': '_pseudo_5.out0',
            'Tmax': '_pseudo_6.out0'
        }
        #'gamma':    '_pseudo_12.out0'}

        for j, key in enumerate(translate_dict.keys()):

            old = old_derivs_dict[key]['h_pt']
            print 'h_pt', key

            openmdao_key = translate_dict[key]
            new = new_derivs[openmdao_key]['h_pt']

            diff = new - old
            print 'old', old
            print 'new', new
            assert_rel_error(self, diff.max(), 0.0, 2e-5)

        for i in xrange(0, num_elem):
            old = old_derivs_dict['gamma'][i]['h_pt']
            #print 'h_pt', 'gamma'+str(i)

            new = new_derivs['_pseudo_7.out0']['h_pt'][i, :]

            diff = new - old
            #print 'old', old
            #print 'new', new
            assert_rel_error(self, diff.max(), 0.0, 2e-5)
示例#6
0
# define bounds for the flight path angle
gamma_lb = np.tan(-35.0 * (np.pi/180.0))/1e-1
gamma_ub = np.tan(35.0 * (np.pi/180.0))/1e-1
takeoff_speed = 83.3
landing_speed = 72.2

altitude = 10 * np.sin(np.pi * np.linspace(0,1,num_elem+1))

start = time.time()

x_range *= 1.852
x_init = x_range * 1e3 * (1-np.cos(np.linspace(0, 1, num_cp)*np.pi))/2/1e6
M_init = np.ones(num_cp)*0.82
h_init = 10 * np.sin(np.pi * x_init / (x_range/1e3))

model.add('seg1', MissionSegment(num_elem=num_elem, num_cp=num_cp,
                                 x_pts=x_init, surr_file='crm_surr'))

# Initial value of the parameter
model.seg1.h_pt = h_init
model.seg1.M_pt = M_init
model.seg1.set_init_h_pt(altitude)

# Calculate velocity from the Mach we have specified.
model.seg1.SysSpeed.v_specified = False

# Initial design parameters
model.seg1.S = 427.8/1e2
model.seg1.ac_w = 210000*9.81/1e6
model.seg1.thrust_sl = 1020000.0/1e6
model.seg1.SFCSL = 8.951*9.81
model.seg1.AR = 8.68
示例#7
0
altitude = np.zeros(num_elem+1)
altitude = 10 * np.sin(np.pi * np.linspace(0,1,num_elem+1))

start = time.time()
num_cp = num_cp_init
while num_cp <= num_cp_max:

    x_range *= 1.852
    x_init = x_range * 1e3 * (1-np.cos(np.linspace(0, 1, num_cp)*np.pi))/2/1e6
    #v_init = np.ones(num_cp)*2.5
    M_init = np.ones(num_cp)*0.8
    #M_init = np.ones(num_cp)*0.82
    h_init = 10 * np.sin(np.pi * x_init / (x_range/1e3))

    model = set_as_top(MissionSegment(num_elem=num_elem, num_cp=num_cp,
                                      x_pts=x_init, surr_file=os.path.join('..','src','pyMission','crm_surr')))

    model.replace('driver', pyOptSparseDriver())
    #model.replace('driver', SimpleDriver())
    model.driver.optimizer = 'SNOPT'
    model.driver.options = {'Iterations limit': 5000000, 
                            'Print file': os.path.join('plotting','weight_sweep_data','SNOPT_%d_print.out' % k)
                            }

    # Add parameters, objectives, constraints
    model.driver.add_parameter('h_pt', low=0.0, high=14.1)
    model.driver.add_objective('SysFuelObj.fuelburn')
    model.driver.add_constraint('SysHi.h_i = 0.0')
    model.driver.add_constraint('SysHf.h_f = 0.0')
    model.driver.add_constraint('SysTmin.Tmin < 0.0')
    model.driver.add_constraint('SysTmax.Tmax < 0.0')
示例#8
0
    def test_MissionSegment(self):

        # define bounds for the flight path angle
        gamma_lb = np.tan(-10.0 * (np.pi / 180.0)) / 1e-1
        gamma_ub = np.tan(10.0 * (np.pi / 180.0)) / 1e-1

        num_elem = 10
        num_cp = 5
        x_range = 150.0

        x_init = x_range * 1e3 * (
            1 - np.cos(np.linspace(0, 1, num_cp) * np.pi)) / 2 / 1e6
        v_init = np.ones(num_cp) * 2.3
        h_init = 1 * np.sin(np.pi * x_init / (x_range / 1e3))

        model = set_as_top(MissionSegment(num_elem, num_cp, x_init))
        model.replace('driver', SimpleDriver())

        model.h_pt = h_init
        model.v_pt = v_init

        # Pull velocity from BSpline instead of calculating it.
        model.SysSpeed.v_specified = True

        # Initial parameters
        model.S = 427.8 / 1e2
        model.ac_w = 210000 * 9.81 / 1e6
        model.thrust_sl = 1020000.0 / 1e6 / 3
        model.SFCSL = 8.951
        model.AR = 8.68
        model.oswald = 0.8

        model.driver.add_parameter('h_pt', low=0.0, high=20.0)
        model.driver.add_objective('SysFuelObj.wf_obj')
        model.driver.add_constraint('SysHi.h_i = 0.0')
        model.driver.add_constraint('SysHf.h_f = 0.0')
        model.driver.add_constraint('SysTmin.Tmin < 0.0')
        model.driver.add_constraint('SysTmax.Tmax < 0.0')
        model.driver.add_constraint('%.15f < SysGammaBspline.Gamma < %.15f' % \
                                    (gamma_lb, gamma_ub), linear=True)

        model.run()

        new_derivs = model.driver.workflow.calc_gradient()

        # Load in original data from pickle
        dirname = os.path.abspath(os.path.dirname(__file__))
        filename = os.path.join(dirname, 'derivs.p')
        old_derivs_dict = pickle.load(open(filename, 'rb'))

        for i in range(0, 4):

            old_derivs = old_derivs_dict['h_pt' + str(i)]
            print 'h_pt' + str(i)

            for j, key in enumerate(['wf_obj', 'h_i', 'h_f', 'Tmin', 'Tmax']):
                old = old_derivs[key]
                new = new_derivs[j, i]

                #diff = np.nan_to_num(abs(new - old) / old)
                diff = new - old
                print key
                print old
                print new
                assert_rel_error(self, diff.max(), 0.0, 1e-5)
示例#9
0
x_range = 15000.0

# define bounds for the flight path angle
gamma_lb = np.tan(-10.0 * (np.pi / 180.0)) / 1e-1
gamma_ub = np.tan(10.0 * (np.pi / 180.0)) / 1e-1

start = time.time()
num_cp = num_cp_init
while num_cp <= num_cp_max:

    x_init = x_range * 1e3 * (
        1 - np.cos(np.linspace(0, 1, num_cp) * np.pi)) / 2 / 1e6
    v_init = np.ones(num_cp) * 2.3
    h_init = 1 * np.sin(np.pi * x_init / (x_range / 1e3))

    model = set_as_top(MissionSegment(num_elem, num_cp, x_init))
    model.replace('driver', pyOptSparseDriver())
    model.driver.optimizer = 'SNOPT'
    #opt_dict = {'Iterations limit': 1000000,
    #            'Major iterations limit': 1000000,
    #            'Minor iterations limit': 1000000 }
    #model.driver.options = opt_dict

    # Add parameters, objectives, constraints
    model.driver.add_parameter('h_pt', low=0.0, high=20.0)
    model.driver.add_objective('SysFuelObj.wf_obj')
    model.driver.add_constraint('SysHi.h_i = 0.0')
    model.driver.add_constraint('SysHf.h_f = 0.0')
    model.driver.add_constraint('SysTmin.Tmin < 0.0')
    model.driver.add_constraint('SysTmax.Tmax < 0.0')
    model.driver.add_constraint('%.15f < SysGammaBspline.Gamma < %.15f' % \
示例#10
0
# define bounds for the flight path angle
gamma_lb = np.tan(-35.0 * (np.pi/180.0))/1e-1
gamma_ub = np.tan(35.0 * (np.pi/180.0))/1e-1
takeoff_speed = 83.3
landing_speed = 72.2
takeoff_M = takeoff_speed / np.sqrt(1.4*287*288)
landing_M = landing_speed / np.sqrt(1.4*287*288)

# Convert from NMi to km
x_range *= 1.852

x_init = x_range * 1e3 * (1-np.cos(np.linspace(0, 1, num_cp)*np.pi))/2/1e6
M_init = 0.5 * np.sin(np.pi * x_init / (x_range/1e3)) + 0.3
h_init = 10 * np.sin(np.pi * x_init / (x_range/1e3))

model = set_as_top(MissionSegment(num_elem=num_elem, num_cp=num_cp,
                                  x_pts=x_init, surr_file='../crm_surr'))

model.replace('driver', pyOptSparseDriver())
#model.replace('driver', SimpleDriver())
model.driver.optimizer = 'SNOPT'

# Initial design parameters
model.S = 427.8/1e2
model.ac_w = 210000*9.81/1e6
model.thrust_sl = 1020000.0/1e6
model.SFCSL = 8.951*9.81
model.AR = 8.68
model.oswald = 0.8

# Needs to use the old propulsion model
model.SysTau.thrust_scale = 0.072