Пример #1
0
def create_files():
    """ Create/update test data files. """
    prob = set_as_top(SellarMDF())
    #prob.name = "top"
    prob.recorders = [
        JSONCaseRecorder('sellar_json.new'),
        BSONCaseRecorder('sellar_bson.new'),
    ]
    prob.run()
    def test_bsonrecorder(self):
        # Verify bson output can be read and that it matches json.
        bson_out = StringIO()
        json_out = StringIO()
        self.top.recorders = [
            BSONCaseRecorder(bson_out),
            JSONCaseRecorder(json_out)
        ]
        self.top.run()

        json_run = json.loads(json_out.getvalue())

        inp = StringIO(bson_out.getvalue())
        reclen = unpack('<L', inp.read(4))[0]
        data = inp.read(reclen)
        obj = bson.loads(data)  # simulation_info
        keys = sorted(obj.keys())
        self.assertEqual(keys, sorted(json_run['simulation_info'].keys()))
        for key in keys:
            # graph sometimes serializes with nodes in differant order
            # between json and bson. The graphs are still equivalent, but the
            # assertion below will fail
            if key not in (
                    'uuid',
                    'graph',
            ):
                self.assertEqual(obj[key], json_run['simulation_info'][key])

        driver_count = 1
        case_count = 1
        data = inp.read(4)
        while data:
            reclen = unpack('<L', data)[0]
            data = inp.read(reclen)
            obj = bson.loads(data)  # driver_info or iteration_case
            keys = sorted(obj.keys())

            if '_driver_id' in obj:  # iteration_case
                case = 'iteration_case_%s' % case_count
                self.assertEqual(keys, sorted(json_run[case].keys()))
                for key in keys:
                    if key not in ('_driver_id', '_id', '_parent_id',
                                   'timestamp'):
                        self.assertEqual(obj[key], json_run[case][key])
                case_count += 1
            else:  # driver_info
                driver = 'driver_info_%s' % driver_count
                self.assertEqual(keys, sorted(json_run[driver].keys()))
                for key in keys:
                    if key not in ('_id', ):
                        self.assertEqual(obj[key], json_run[driver][key])
                driver_count += 1

            data = inp.read(4)
Пример #3
0
    def configure(self):
        self.add('paraboloid', Paraboloid())

        self.add('driver', DOEdriver())
        # There are a number of different kinds of DOE available in openmdao.lib.doegenerators
        # self.driver.DOEgenerator = FullFactorial(10) #Full Factorial DOE with 10 levels for each variable
        self.driver.DOEgenerator = Uniform(1000)

        # DOEdriver will automatically record the values of any parameters for each case
        self.driver.add_parameter('paraboloid.x', low=-50, high=50)
        self.driver.add_parameter('paraboloid.y', low=-50, high=50)
        # tell the DOEdriver to also record any other variables you want to know for each case
        self.driver.add_response('paraboloid.f_xy')

        self.recorders = [
            JSONCaseRecorder('doe.json'),
            BSONCaseRecorder('doe.bson')
        ]
Пример #4
0
                result["arg"] += self.J[1] * arg["lon"]

    def apply_derivT(self, arg, result):
        if "alt" in arg:
            if "lat" in result:
                result["lat"] += self.J[0] * arg["alt"]
            if "lon" in result:
                result["lon"] += self.J[1] * arg["alt"]

print "setting up"
top = CADRE_Optimization(n=1500, m=300)
top.add("Elevation", Elevation())
top.driver.workflow.add("Elevation")
for i in xrange(6):
    top.connect("Elevation.alt", "pt%s.alt" % str(i))
lons = ["pt" + str(i) + ".lon" for i in xrange(6)] + ["Elevation.lon"]
lats = ["pt" + str(i) + ".lat" for i in xrange(6)] + ["Elevation.lat"]
top.driver.add_parameter(lons, low=-180, high=180)
top.driver.add_parameter(lats, low=-90, high=90)

top.recorders = [BSONCaseRecorder('CADRE_gs.bson')]
includes = [ 'pt' + str(i) + '.Data' for i in range(6)]
includes.extend( [ "_pseudo_" + str(i) for i in range(30) ] )
includes.append( "Elevation.alt")
includes.extend( [ 'pt' + str(i) + '.lat' for i in range(6)] )
includes.extend( [ 'pt' + str(i) + '.lon' for i in range(6)] )
top.includes = includes

print "running"
top.run()
Пример #5
0
    # Calculate velocity from the Mach we have specified.
    model.SysSpeed.v_specified = False

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

    # Recording the results - This records just the parameters, objective,
    # and constraints to mission_history_cp_#.bson
    filename = os.path.join('plotting','weight_sweep_data','mission_history_weight_%d.bson' % k)
    model.recorders = [BSONCaseRecorder(filename)]
    model.recorders.save_problem_formulation = True
    # model.recording_options.includes = model.driver.list_param_targets()
    # model.recording_options.includes.extend(model.driver.list_constraint_targets())
    # model.recording_options.includes.append('SysFuelObj.fuelburn')

    # Flag for making sure we run serial if we do an mpirun
    model.driver.system_type = 'serial'
    model.coupled_solver.system_type = 'serial'

    # Debugging some stuff
    #model.run()
    #print model.driver.workflow.calc_gradient()
    #model.run()
    #model.driver.workflow.check_gradient()
    #model.h_pt = np.array((7.0, 5.1, 13.3))
Пример #6
0
M_init = np.ones(num_cp)*0.78
M_init[:2] = np.linspace(0.5, 0.78, 2)
M_init[95:] = np.linspace(0.78, 0.5, 5)

h_init = (35000 / 3.28) * np.ones(num_cp) / 1e3
h_init[:2] = np.linspace(0, 35000/3.28, 2) / 1e3
h_init[95:] = np.linspace(35000/3.28, 0, 5) / 1e3

model = MissionSegment(num_elem, num_cp, x_init)
model.h_pt = h_init
model.M_pt = M_init

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

model.S = 124.58/1e2
model.ac_w = 57719.3*9.81/1e6
model.thrust_sl = 2*121436/1e6
model.SFCSL = (2*0.00001076/1e-6)*9.81
model.AR = 8.93
model.oswald = 0.8

filename = 'mission_history_737.bson'
model.recorders = [BSONCaseRecorder(os.path.join('plotting','737_data',filename))]
model.recorders.save_problem_formulation = True

start = time.time()
model.run()

print 'OPTIMIZATION TIME:', time.time() - start
Пример #7
0
        opt.add_constraint(
            '(level.lift/9.81 - (wing_weight.M_tot + fuse_weight.M_tot))/2500 = 0 '
        )
        opt.add_constraint(
            '(turning.lift/9.81 - (turning.load_factor * (wing_weight.M_tot + fuse_weight.M_tot)))/1200 = 0'
        )

        sweep = self.add('driver', CaseIteratorDriver())
        sweep.workflow.add('opt')
        sweep.add_parameter('fuse_weight.N_pilot')


if __name__ == "__main__":

    ma = SweepOpt()

    # ma.fuse_weight.N_pilot = 3
    # ma.fuse_weight.N_propellor = 1

    ma.driver.case_inputs.fuse_weight.N_pilot = [1, 2, 3, 4]
    data_file = os.path.join('dw_day3', 'pilot_study.bson')
    ma.recorders = [BSONCaseRecorder(data_file)]

    #initial guesses
    ma.wing_weight.cbar = .5
    ma.level.alpha = 3
    ma.wing_weight.b = 30
    ma.wing_weight.y_pod = 10

    ma.run()