Exemplo n.º 1
0
def write_outputs(y, outputs):
    """Write outputs to cpacs.

    Write the predicted output of the model to the CPACS file.

    Args:
        y (DataFrame): Contains the outputs, locations.
        outputs (np.array): Values of the outputs.

    Returns:
        None.

    """

    tixi = cpsf.open_tixi(cpacs_path)
    tigl = cpsf.open_tigl(tixi)
    aircraft = cpud.get_aircraft(tigl)
    wings = aircraft.get_wings()
    fuselage = aircraft.get_fuselages().get_fuselage(1)

    y.fillna('-', inplace=True)
    for i, name in enumerate(y.index):
        if y.loc[name, 'setcmd'] != '-':
            exec('{} = {}'.format(name, outputs[0][i]))
            eval(y.loc[name, 'setcmd'])
        elif y.loc[name, 'getcmd'] != '-':
            xpath = y.loc[name, 'getcmd']
            cpsf.create_branch(tixi, xpath)
            tixi.updateDoubleElement(xpath, outputs[0][i], '%g')

    tigl.close()
    cpsf.close_tixi(tixi, cpacs_path_out)
Exemplo n.º 2
0
def write_inouts(v, inout, tixi):
    """Write inputs or outputs to cpacs.

    Write the specified input or the predicted output of the model to the
    CPACS file.

    Args:
        v (DataFrame): Contains the inout, locations.
        inout (np.array): Values of the inout.

    Returns:
        None.

    """

    tigl = cpsf.open_tigl(tixi)
    aircraft = cpud.get_aircraft(tigl)
    wings = aircraft.get_wings()
    fuselage = aircraft.get_fuselages().get_fuselage(1)

    v.fillna('-', inplace=True)
    for i, name in enumerate(v.index):
        if v.loc[name, 'setcmd'] != '-':
            exec('{} = {}'.format(name, inout[0][i]))
            eval(v.loc[name, 'setcmd'])
        elif v.loc[name, 'getcmd'] != '-':
            xpath = v.loc[name, 'getcmd']
            cpsf.create_branch(tixi, xpath)
            tixi.updateDoubleElement(xpath, inout[0][i], '%g')

    tigl.close()
Exemplo n.º 3
0
def init_geom_var_dict(tixi):
    """Create design variable dictionary

    Return the dictionary of the design variables using the TIGL library.
    Add design variables and constrains relative to the aircraft fuselages to
    the dictionnary.

    Args:
        tixi (handle) : Handle of the CPACS file

    Returns:
        geom_var_dict (dict) : dictionary with the geometric parameters of
        the routine.

    """
    tigl = cpsf.open_tigl(tixi)
    aircraft = cpud.get_aircraft(tigl)

    fuse_nb = aircraft.get_fuselage_count()
    if fuse_nb:
        init_fuse_param(aircraft, fuse_nb)

    wing_nb = aircraft.get_wing_count()
    if wing_nb:
        init_wing_param(aircraft, wing_nb)

    return geom_var_dict
Exemplo n.º 4
0
def init_design_var_dict(tixi):
    """
    Return the dictionary of the design variables using the TIGL library.

    Parameters
    ----------
    tigl : tigl3_handler

    Returns
    -------
    design_var_dict : TYPE

    """
    tigl = cpsf.open_tigl(tixi)
    aircraft = cpud.get_aircraft(tigl)

    # fuse_nb = aircraft.get_fuselage_count()
    # if fuse_nb:
    #     init_fuse_param(aircraft, fuse_nb)

    wing_nb = aircraft.get_wing_count()
    if wing_nb:
        init_wing_param(aircraft, wing_nb)

    init_specials(tixi)

    return design_var_dict
Exemplo n.º 5
0
def aeromap_calculation(sm, tixi):
    """Make a prediction using only the aeromap entries.

    By using only the aeromap functions this module is way faster to execute. Only
    works  with the aeromap as the other values of the CPACs are not vectors and
    have to be evaluated with a different CPACS every time.

    Args:
        sm (Surrogate model object): Surrogate used to predict the function output.
        tixi (Tixi handle): Handle of the current CPACS.

    Returns:
        None.

    """

    tigl = cpsf.open_tigl(tixi)
    aircraft = cpud.get_aircraft(tigl)
    wings = aircraft.get_wings()
    fuselage = aircraft.get_fuselages().get_fuselage(1)

    aeromap_uid = apmf.get_current_aeromap_uid(tixi, 'SMUse')
    log.info('Using aeromap :'+aeromap_uid)
    Coef = apmf.get_aeromap(tixi, aeromap_uid)

    inputs = np.array([Coef.alt, Coef.mach, Coef.aoa, Coef.aos]).T

    outputs = sm.predict_values(inputs)

    # Re-initiates the values of the results to write the new ones
    Coef.cl = []
    Coef.cd = []
    Coef.cs = []
    Coef.cml = []
    Coef.cmd = []
    Coef.cms = []

    for i in range(outputs.shape[0]):
        Coef.add_coefficients(outputs[i, 0], outputs[i, 1], outputs[i, 2],
                              outputs[i, 3], outputs[i, 4], outputs[i, 5])
    Coef.print_coef_list()
    apmf.save_coefficients(tixi, aeromap_uid, Coef)

    tigl.close()
Exemplo n.º 6
0
def get_inputs(x):
    """Get input for the surrogate model.

    Retrieve the inputs from the cpacs and return them as a numpy array.

    Args:
        x (DataFrame): Contains the inputs locations.

    Returns:
        inputs (np.array): Array of floats.

    """

    tixi = cpsf.open_tixi(cpacs_path)
    tigl = cpsf.open_tigl(tixi)
    aircraft = cpud.get_aircraft(tigl)
    wings = aircraft.get_wings()
    fuselage = aircraft.get_fuselages().get_fuselage(1)

    inputs = []
    am_uid = apmf.get_current_aeromap_uid(tixi, 'SMUse')
    am_index = apmf.get_aeromap_index(tixi, am_uid)
    xpath = apmf.AEROPERFORMANCE_XPATH + '/aeroMap' + am_index + '/aeroPerformanceMap/'

    x.set_index('Name', inplace=True)
    for name in x.index:
        if x.loc[name, 'setcmd'] != '-':
            inputs.append(eval(x.loc[name, 'getcmd']))
        else:
            if name in apmf.COEF_LIST + apmf.XSTATES:
                x.loc[name, 'getcmd'] = xpath + name
            inputs.append(tixi.getDoubleElement(x.loc[name, 'getcmd']))

    tigl.close()
    cpsf.close_tixi(tixi, cpacs_path)

    inputs = np.array([inputs])
    return inputs