Exemplo n.º 1
0
def driver_setup(prob):
    """Change settings of the driver

    Here the type of the driver has to be selected, wether it will be an
    optimisation driver or a DoE driver. In both cases there are multiple
    options to choose from to tune the driver.
    Two recorders are then attached to the driver for results and N2 plotting.

    Args:
        prob (om.Problem object) : Instance of the Problem class that is used
        to define the current routine.

    """

    if Rt.type == 'Optim':
        # TBD : Genetic algorithm
        # if len(Rt.objective) > 1 and False:
        #     log.info("""More than 1 objective function, the driver will
        #              automatically be set to NSGA2""")
        #     prob.driver = om.pyOptSparseDriver() # multifunc driver : NSGA2
        #     prob.driver.options['optimizer'] = 'NSGA2'
        #     prob.driver.opt_settings['PopSize'] = 7
        #     prob.driver.opt_settings['maxGen'] = Rt.max_iter
        # else:
        prob.driver = om.ScipyOptimizeDriver()
        prob.driver.options['optimizer'] = Rt.driver
        prob.driver.options['maxiter'] = Rt.max_iter
        prob.driver.options['tol'] = Rt.tol
        prob.driver.options['disp'] = True
    elif Rt.type == 'DoE':
        if Rt.doedriver == 'Uniform':
            driver_type = om.UniformGenerator(num_samples=Rt.samplesnb)
        elif Rt.doedriver == 'LatinHypercube':
            driver_type = om.LatinHypercubeGenerator(samples=Rt.samplesnb)
        elif Rt.doedriver == 'FullFactorial':
            driver_type = om.FullFactorialGenerator(levels=Rt.samplesnb)
        elif Rt.doedriver == 'CSVGenerated':
            file = opf.gen_doe_csv(Rt.user_config)
            driver_type = om.CSVGenerator(file)
        prob.driver = om.DOEDriver(driver_type)
        prob.driver.options['run_parallel'] = True
        prob.driver.options['procs_per_model'] = 1
    else:
        log.error('Type of optimisation not recognize!!!')

    ## Attaching a recorder and a diagramm visualizer ##
    prob.driver.recording_options['record_inputs'] = True
    prob.driver.add_recorder(
        om.SqliteRecorder(optim_dir_path + '/circuit.sqlite'))
    prob.driver.add_recorder(
        om.SqliteRecorder(optim_dir_path + '/Driver_recorder.sql'))
Exemplo n.º 2
0
model.add_design_var('length', lower=0.0, upper=0.254)
model.add_design_var('eff', lower=0.25, upper=0.325)
model.add_design_var('eps', lower=0.02, upper=0.8)
model.add_design_var('R_m', lower=1., upper=250.0)
model.add_design_var('R_p', lower=1., upper=250.0)
model.add_design_var('R_s', lower=1., upper=250.0)

if case == 'cold':
    model.add_design_var('r_bat', lower=0.0, upper=1.0)

model.add_objective('tBat')
model.add_objective('tProp')
model.add_objective('tBPanel')
model.add_objective('tDPanel')

prob.driver = om.DOEDriver(om.CSVGenerator(input_file))
prob.driver.add_recorder(om.SqliteRecorder("cases.sql"))

prob.setup(check=True)
prob.run_driver()
prob.cleanup()

cr = om.CaseReader("cases.sql")
cases = cr.list_cases('driver')

values = []

if case == 'cold':
    for nt in cases:
        outputs = cr.get_case(nt).outputs
        values.append((outputs['eps'], outputs['length'], outputs['eff'],
Exemplo n.º 3
0
model.add_design_var('length', lower=0.0, upper=0.254)
model.add_design_var('eff', lower=0.25, upper=0.32)
model.add_design_var('P_un', lower=0.0, upper=1.0)
model.add_design_var('eps', lower=0.02, upper=0.8)
model.add_design_var('alp', lower=0.23, upper=0.48)
model.add_design_var('GlMain', lower=0.004, upper=1.0)
model.add_design_var('GlProp', lower=0.004, upper=1.0)
model.add_design_var('GlTether', lower=0.004, upper=1.0)
model.add_design_var('GlPanel', lower=0.004, upper=1.0)
model.add_objective('tBat')
model.add_objective('tProp')

prob.setup(check=True)

prob.driver = om.DOEDriver(om.CSVGenerator('morris_sample.csv'))
prob.driver.add_recorder(om.SqliteRecorder("cases.sql"))

prob.run_driver()
prob.cleanup()

cr = om.CaseReader("cases.sql")
cases = cr.list_cases('driver')

values = []
for case in cases:
    outputs = cr.get_case(case).outputs
    values.append((outputs['tBat'], outputs['tProp']))

data = np.reshape(values, (len(cases), 2))