示例#1
0
def test_sweep_serial():

    # set-up trial options
    options = awe.Options(True)  # True refers to internal access switch
    options['user_options']['system_model']['architecture'] = {1: 0}
    options['user_options']['system_model']['kite_dof'] = 3
    options['user_options']['kite_standard'] = awe.ampyx_data.data_dict()
    options['user_options']['tether_drag_model'] = 'split'
    options['user_options']['trajectory']['lift_mode']['windings'] = 1
    options['user_options']['induction_model'] = 'not_in_use'
    options['nlp']['n_k'] = 2
    options['solver']['max_iter'] = 0

    # set-up sweep options
    sweep_opts = [(['nlp', 'discretization'],
                   ['direct_collocation', 'multiple_shooting'])]  # trial sweep
    sweep_opts = [(['user_options', 'wind',
                    'u_ref'], [5., 5.5])]  # parametric sweep

    # build, run and save sweep
    sweep = awe.Sweep(name='serial_test', options=options, seed=sweep_opts)
    sweep.build()
    sweep.run(final_homotopy_step='initial')
    sweep.save('dict')

    # load and test sweep
    file_pi = open('serial_test.dict', 'rb')
    dict_test = pickle.load(file_pi)
    sweep_test = awe.Sweep(dict_test)
    file_pi.close()
    os.remove("serial_test.dict")

    sweep_test.plot(['all', 'comp_all'])
示例#2
0
def test_animation():

    options = awe.Options(True)

    # basic options
    options['user_options']['system_model']['architecture'] = {1: 0}
    options['user_options']['trajectory']['lift_mode']['windings'] = 1
    options['user_options']['kite_standard'] = awe.ampyx_data.data_dict()
    options['user_options']['trajectory']['type'] = 'lift_mode'
    options['user_options']['system_model']['kite_dof'] = 3
    options['user_options']['induction_model'] = 'not_in_use'
    options['user_options']['tether_drag_model'] = 'trivial'
    options['nlp']['n_k'] = 2
    options['solver']['max_iter'] = 0

    options['visualization']['cosmetics']['trajectory']['kite_bodies'] = True
    options['visualization']['cosmetics']['interpolation']['N'] = 2

    # build trial and optimize
    trial = awe.Trial(options, 'trial1')
    trial.build()
    trial.optimize(final_homotopy_step='initial')

    trial.plot('animation')
    os.remove('trial1.mp4')
示例#3
0
def test_visualization():

    options = awe.Options(True)

    # basic options
    options['user_options']['system_model']['architecture'] = {1: 0}
    options['user_options']['trajectory']['lift_mode']['windings'] = 1
    options['user_options']['kite_standard'] = awe.ampyx_data.data_dict()
    options['user_options']['trajectory']['type'] = 'lift_mode'
    options['user_options']['system_model']['kite_dof'] = 3
    options['user_options']['induction_model'] = 'not_in_use'
    options['user_options']['tether_drag_model'] = 'trivial'
    options['nlp']['n_k'] = 2
    options['solver']['max_iter'] = 0

    # build trial and optimize
    trial = awe.Trial(options, 'trial1')
    trial.build()
    trial.optimize(final_homotopy_step='initial', debug_flags='all')

    # set flags and plot
    trial_flags = ['all']
    trial.plot(trial_flags)

    # build sweep and run
    sweep_opts = [(['user_options', 'wind', 'u_ref'], [5., 5.5])]
    sweep = awe.Sweep(name='sweep_viz_test', options=options, seed=sweep_opts)
    sweep.run(final_homotopy_step='initial', debug_flags='all')

    # set flags and plot
    sweep_flags = [
        'all', 'comp_all', 'outputs:tether_length',
        'comp_outputs:tether_length'
    ]
    sweep.plot(sweep_flags)
def test_initial_guess_generation():
    # ===========================================
    # SET-UP DUMMY PROBLEM
    # ===========================================

    # make default options object
    options = awe.Options(True)  # True refers to internal access switch

    # choose simplest model
    options['user_options']['system_model']['architecture'] = {
        1: 0,
        2: 1,
        3: 1,
        4: 1,
        5: 4,
        6: 4
    }
    options['user_options']['system_model']['kite_dof'] = 3
    options['user_options']['tether_drag_model'] = 'split'
    options['user_options']['trajectory']['lift_mode']['phase_fix'] = True
    options['user_options']['induction_model'] = 'not_in_use'
    options['user_options']['kite_standard'] = ampyx_data.data_dict()
    options['solver']['initialization']['initialization_type'] = 'modular'
    options['model']['tether']['control_var'] = 'dddl_t'

    # make trial, build and run
    trial = awe.Trial(name='test', seed=options)
    trial.build()
    trial.optimize(final_homotopy_step='initial_guess')
    architecture = trial.model.architecture
    number_of_nodes = architecture.number_of_nodes
    parent_map = architecture.parent_map
    for node in range(1, number_of_nodes):
        parent = parent_map[node]
        c_avg = np.average(
            abs(
                np.array(
                    trial.optimization.output_vals[0]['coll_outputs', :, :,
                                                      'tether_length',
                                                      'c' + str(node) +
                                                      str(parent)])))
        dc_avg = np.average(
            abs(
                np.array(
                    trial.optimization.output_vals[0]['coll_outputs', :, :,
                                                      'tether_length',
                                                      'dc' + str(node) +
                                                      str(parent)])))
        ddc_avg = np.average(
            abs(
                np.array(
                    trial.optimization.output_vals[0]['coll_outputs', :, :,
                                                      'tether_length',
                                                      'ddc' + str(node) +
                                                      str(parent)])))
        assert (c_avg < 1e-8)
        assert (dc_avg < 1e-8)
        assert (ddc_avg < 1)
示例#5
0
def test_trial_serial():

    # set-up trial options
    options = awe.Options(True)  # True refers to internal access switch
    options['user_options']['system_model']['architecture'] = {1: 0}
    options['user_options']['system_model']['kite_dof'] = 3
    options['user_options']['kite_standard'] = awe.ampyx_data.data_dict()
    options['user_options']['tether_drag_model'] = 'split'
    options['user_options']['trajectory']['lift_mode']['windings'] = 1
    options['user_options']['induction_model'] = 'not_in_use'
    options['nlp']['n_k'] = 2
    options['solver']['max_iter'] = 0

    # build collocation trial
    trial = awe.Trial(name='serial_test', seed=options)
    trial.build()
    trial.optimize(final_homotopy_step='initial')
    trial.save('dict')

    # load and test collocation trial
    file_pi = open('serial_test.dict', 'rb')
    dict_test = pickle.load(file_pi)
    trial_test = awe.Trial(dict_test)
    file_pi.close()
    os.remove("serial_test.dict")

    trial_test.plot('all')

    # set-up ms trial options
    options['nlp']['discretization'] = 'multiple_shooting'
    options['nlp']['n_k'] = 10

    # build multiple shooting trial
    trialMS = awe.Trial(name='serial_test_MS', seed=options)
    trialMS.build()
    trialMS.optimize(final_homotopy_step='initial')
    trialMS.save('dict')

    # load and test multiple shooting trial
    file_pi_serial = open('serial_test_MS.dict', 'rb')
    dict_testMS = pickle.load(file_pi_serial)
    trial_testMS = awe.Trial(dict_testMS)

    file_pi_serial.close()
    os.remove("serial_test_MS.dict")

    trial_testMS.plot('all')
示例#6
0
def generate_kite_model_and_orbit(N):

    import point_mass_model

    # make default options object
    options = awe.Options(True)

    # single kite with point-mass model
    options['user_options']['system_model']['architecture'] = {1: 0}
    options['user_options']['system_model']['kite_dof'] = 3
    options['user_options']['kite_standard'] = point_mass_model.data_dict()

    # trajectory should be a single pumping cycle with initial number of five windings
    options['user_options']['trajectory']['type'] = 'power_cycle'
    options['user_options']['trajectory']['system_type'] = 'drag_mode'
    options['user_options']['trajectory']['lift_mode']['windings'] = 1

    # don't include induction effects, use simple tether drag
    options['user_options']['induction_model'] = 'not_in_use'
    options['user_options']['tether_drag_model'] = 'trivial'
    options['nlp']['n_k'] = N

    # get point mass model data
    options = point_mass_model.set_options(options)

    # initialize and optimize trial
    trial = awe.Trial(options, 'single_kite_drag_mode')
    trial.build()
    trial.optimize(final_homotopy_step='final')
    # trial.plot(['states','controls', 'constraints'])
    # plt.show()

    # extract model data
    sol = {}
    sol['model'] = trial.generate_optimal_model()
    sol['l_t'] = trial.optimization.V_opt['xd', 0, 'l_t']

    # initial guess
    w_init = []
    for k in range(N):
        w_init.append(trial.optimization.V_opt['xd', k][:-3])
        w_init.append(trial.optimization.V_opt['u', k][3:6])
    sol['w0'] = ca.vertcat(*w_init)

    return sol
示例#7
0


wind_ref = [2,3,4,5,6,7]

n_k = 30
wd =1
tim = 3e4

for w in wind_ref:


    name = 'veela_double_125_kw_gen_265_mm_gear_u_ref_' + str(w) + '_log_wind' + '_nk_' + str(n_k) + '_wd_' + str(wd) + 'invest'

        # make default options object
    options = awe.Options(True)

        # single kite with point-mass model
    options['user_options']['system_model']['architecture'] = {1:0,2:1,3:1}
    options['user_options']['system_model']['kite_dof'] = 6
    options['user_options']['kite_standard'] = awe.ampyx_data.data_dict()
    options['user_options']['generator'] = awe.pmsm_125_kw_gen.data_dict()
    options['user_options']['generator']['gear_train']['used'] = True
    #options['user_options']['generator']['gear_train']['optimize'] = True
    #options['user_options']['generator']['dv_sd'] = False
    #options['user_options']['generator']['control_var'] = 'dddl_t'
    #options['model']['tether']['control_var'] = 'dddl_t'
    #options['user_options']['generator']['type'] = None
    #options['user_options']['generator']['ground_station']['in_lag_dyn'] = True

#    options['model']['ground_station']['ddl_t_max'] = 3
示例#8
0
        for n, line in enumerate(f):
            n_neu = n+1
            line_lst += [line]
    with open(filename, 'w') as f:
        string = ''
        for l in line_lst:
            if l != '\n':
                string += l + '\n'
        string += '\n' + name + ' : ' + quality_print_results
        f.write(string)


zus = 'lag: mein winch'

    # make default options object
options = awe.Options(internal_access = True)

    # single kite with point-mass model
options['user_options']['system_model']['architecture'] = {1:0}
options['user_options']['system_model']['kite_dof'] = 6
options['user_options']['kite_standard'] = awe.ampyx_data.data_dict()
options['user_options']['generator'] = awe.pmsm_125_kw_gen.data_dict()
#options['user_options']['generator']['gear_train']['used'] = True
#options['user_options']['generator']['gear_train']['optimize'] = True
options['user_options']['generator']['dv_sd'] = False
#options['user_options']['generator']['control_var'] = 'ddl_t'
#options['model']['tether']['control_var'] = 'ddl_t'
#options['user_options']['generator']['type'] = None

    # trajectory should be a single pumping cycle with initial number of five windings
options['user_options']['trajectory']['system_type'] = 'lift_mode'
示例#9
0
#!/usr/bin/python3

import awebox as awe
import matplotlib.pyplot as plt
import numpy as np

from awebox.logger.logger import Logger as awelogger
awelogger.logger.setLevel(10)

########################
# SET-UP TRIAL OPTIONS #
########################

# make default options object
options = awe.Options()

# single kite with point-mass model
options['user_options']['system_model']['architecture'] = {1:0, 2:1, 3:1}
options['user_options']['system_model']['kite_dof'] = 3
options['user_options']['kite_standard'] = awe.ampyx_data.data_dict()
# trajectory should be a single pumping cycle with initial number of three windings
options['user_options']['trajectory']['type'] = 'power_cycle'
options['user_options']['trajectory']['system_type'] = 'lift_mode'
options['user_options']['trajectory']['lift_mode']['windings'] = 2

# don't include induction effects, use simple tether drag
options['user_options']['wind']['u_ref'] = 5.0 # m/s
options['user_options']['induction_model'] = 'not_in_use'
options['user_options']['tether_drag_model'] = 'split'

trial = awe.Trial(seed = options, name = 'opt_design')
#!/usr/bin/python3

import awebox as awe
import matplotlib.pyplot as plt
import copy

##########################
# GENERATE TRIAL OPTIONS #
##########################

## PUMPING TRIAL

# make pumping options object
pumping_options = awe.Options(True)

# dual kite with  point-mass model
pumping_options['user_options']['system_model']['architecture'] = {
    1: 0,
    2: 1,
    3: 1
}
pumping_options['user_options']['system_model']['kite_dof'] = 3
pumping_options['user_options']['kite_standard'] = awe.ampyx_data.data_dict()

# trajectory should be a single pumping cycle with initial number of five windings
pumping_options['user_options']['trajectory']['type'] = 'power_cycle'
pumping_options['user_options']['trajectory']['system_type'] = 'lift_mode'
pumping_options['user_options']['trajectory']['lift_mode']['windings'] = 5

# don't include induction effects, use simple tether drag
pumping_options['user_options']['induction_model'] = 'not_in_use'
#!/usr/bin/python3

import awebox as awe
import copy
import matplotlib.pyplot as plt

# ================
# SET-UP AND SOLVE
# ================

# SET INTEGRATOR TO BE TESTED
integrator = 'rk4root'
final_step = 'final'

# make default options object
options = awe.Options(True)  # True refers to internal access switch
options['user_options']['system_model']['architecture'] = {1: 0}
options['user_options']['system_model']['kite_dof'] = 3
options['user_options']['kite_standard'] = awe.ampyx_data.data_dict()

options['user_options']['tether_drag_model'] = 'split'
options['user_options']['trajectory']['lift_mode']['windings'] = 1
options['user_options']['induction_model'] = 'not_in_use'

# direct collocation options
options['nlp']['n_k'] = 40
options['nlp']['collocation']['d'] = 4
options['nlp']['discretization'] = 'direct_collocation'
options['nlp']['parallelization']['overwrite'] = True
options['nlp']['cost']['output_quadrature'] = False
示例#12
0
def test_integrators():

    # ===========================================
    # SET-UP DIRECT COLLOCATION PROBLEM AND SOLVE
    # ===========================================

    # make default options object
    base_options = awe.Options(True) # True refers to internal access switch

    # choose simplest model
    base_options['user_options']['system_model']['architecture'] = {1:0}
    base_options['user_options']['system_model']['kite_dof'] = 3
    base_options['user_options']['kite_standard'] = awe.ampyx_data.data_dict()
    base_options['user_options']['tether_drag_model'] = 'split'
    base_options['user_options']['induction_model'] = 'not_in_use'
    
    # specify direct collocation options
    base_options['nlp']['n_k'] = 40
    base_options['nlp']['discretization'] = 'direct_collocation'
    base_options['nlp']['collocation']['u_param'] = 'zoh'
    base_options['nlp']['collocation']['scheme'] = 'radau'
    base_options['nlp']['collocation']['d'] = 4

    base_options['model']['tether']['control_var'] = 'dddl_t'

     # homotopy tuning
    base_options['solver']['mu_hippo'] = 1e-4
    base_options['solver']['tol_hippo'] = 1e-4

    # make trial, build and run
    trial = awe.Trial(name = 'test', seed = base_options)
    trial.build()
    trial.optimize()

    # extract solution data
    V_final = trial.optimization.V_opt
    P       = trial.optimization.p_fix_num
    Int_outputs = trial.optimization.integral_output_vals[1]
    model   = trial.model
    dae     = model.get_dae()

    # build dae variables for t = 0 within first shooting interval
    variables0 = struct_op.get_variables_at_time(base_options['nlp'], V_final, None, model.variables, 0)
    parameters = model.parameters(vertcat(P['theta0'], V_final['phi']))
    x0, z0, p  = dae.fill_in_dae_variables(variables0, parameters)

    # ===================================
    # TEST COLLOCATION INTEGRATOR
    # ===================================

    # set discretization to multiple shooting
    base_options['nlp']['discretization'] = 'multiple_shooting'
    base_options['nlp']['integrator']['type'] = 'collocation'
    base_options['nlp']['integrator']['collocation_scheme'] = base_options['nlp']['collocation']['scheme']
    base_options['nlp']['integrator']['interpolation_order'] = base_options['nlp']['collocation']['d']
    base_options['nlp']['integrator']['num_steps'] = 1

    # switch off expand to allow for use of integrator in NLP
    base_options['solver']['expand_overwrite'] = False

    # build MS trial
    trialColl = awe.Trial(name = 'testColl', seed = base_options)
    trialColl.build()

    # multiple shooting dae integrator
    F = trialColl.nlp.Multiple_shooting.F

    # integrate over one interval
    Ff = F(x0 = x0, z0 = z0, p = p)
    xf = Ff['xf']
    zf = Ff['zf']
    qf = Ff['qf']

    # evaluate integration error
    err_coll_x = np.max(np.abs(np.divide((xf - V_final['xd',1]), V_final['xd',1]).full()))
    xa = dae.z(zf)['xa']
    err_coll_z = np.max(np.abs(np.divide(dae.z(zf)['xa'] - V_final['coll_var',0, -1, 'xa'], V_final['coll_var',0, -1, 'xa']).full()))
    err_coll_q = np.max(np.abs(np.divide((qf - Int_outputs['int_out',1]), Int_outputs['int_out',1]).full()))

    tolerance = 1e-8

    # values should match up to nlp solver accuracy
    assert(err_coll_x < tolerance)
    assert(err_coll_z < tolerance)
    assert(err_coll_q < tolerance)

    # ===================================
    # TEST RK4-ROOT INTEGRATOR
    # ===================================

    # set discretization to multiple shooting
    base_options['nlp']['integrator']['type'] = 'rk4root'
    base_options['nlp']['integrator']['num_steps'] = 20

    # build MS trial
    trialRK = awe.Trial(name = 'testRK', seed = base_options)
    trialRK.build()

    # multiple shooting dae integrator
    F = trialRK.nlp.Multiple_shooting.F

    # integrate over one interval
    Ff = F(x0 = x0, z0 = z0, p = p)
    xf = Ff['xf']
    zf = Ff['zf']
    qf = Ff['qf']

    # evaluate 
    err_rk_x = np.max(np.abs(np.divide((xf - V_final['xd',1]), V_final['xd',1]).full()))
    xa = dae.z(zf)['xa']
    err_rk_z = np.max(np.abs(np.divide(dae.z(zf)['xa'] - V_final['coll_var',0, -1, 'xa'], V_final['coll_var',0, -1, 'xa']).full()))
    err_rk_q = np.max(np.abs(np.divide((qf - Int_outputs['int_out',1]), Int_outputs['int_out',1]).full()))

    # error should be below 1%
    assert(err_rk_x < 1e-2)
    assert(err_rk_z < 1e-2)
    assert(err_rk_q < 2e-2)