Example #1
0
def gen_df_from_am(tixi):
    """Create the dataframe to be saved in the Tool object.

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

    Returns:
        df (DataFrame): The dataframe containing the aeromap data.

    """

    x = pd.DataFrame()
    y = pd.DataFrame()
    am_uid = apmf.get_current_aeromap_uid(tixi, 'SMTrain')
    am_index = apmf.get_aeromap_index(tixi, am_uid)

    outputs = COEF_LIST
    inputs = ['altitude', 'machNumber', 'angleOfAttack', 'angleOfSideslip']

    x['Name'] = inputs
    y['Name'] = outputs
    x['type'] = 'des'
    y['type'] = 'obj'

    df = x.append(y, ignore_index=True)
    df['getcmd'] = '-'
    df['setcmd'] = '-'
    df['initial value'] = '-'

    xpath = apmf.AEROPERFORMANCE_XPATH + '/aeroMap' + am_index + '/aeroPerformanceMap/'
    for index, name in enumerate(df['Name']):
        df.loc[index, 'getcmd'] = xpath + name
        df.loc[index, 'initial value'] = tixi.getDoubleElement(xpath + name)

    return df
Example #2
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()
Example #3
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