示例#1
0
def test_join_paths():
    """
    Test function to join file paths
    """

    path_joined = join_paths(PATH1, PATH2)
    assert str(path_joined) == f"{PATH1}/{PATH2}"

    with raises(TypeError):
        join_paths('only_one_path')
示例#2
0
def write_airfoil_files(settings, tixi):
    """
    Extract airfoil data from CPACS and write airfoil files

    Args:
        :settings: Settings object
        :tixi: Tixi handle
    """

    logger.debug("Extracting airfoil data...")
    num_airfoils = tixi.getNumberOfChilds(XPATHS.AIRFOILS)
    for i in range(1, num_airfoils + 1):
        node_airfoil = XPATHS.AIRFOILS + f"/wingAirfoil[{i}]"
        node_data = node_airfoil + "/pointList"

        try:
            name_airfoil = parse_str(
                tixi.getTextElement(node_airfoil + '/name'))
        except tixiwrapper.TixiException:
            name_airfoil = f'AIRFOIL{i:02d}'

        file_airfoil = join_paths(settings.paths('root'),
                                  PATHS.FILES.AIRFOIL(name_airfoil))

        # Convert string to numpy array
        coords_x = np.fromstring(tixi.getTextElement(node_data + '/x'),
                                 sep=';')
        coords_z = np.fromstring(tixi.getTextElement(node_data + '/z'),
                                 sep=';')
        coords = np.transpose([coords_x, coords_z])

        logger.info(f"Copying airfoil {name_airfoil} to file...")
        np.savetxt(file_airfoil,
                   coords,
                   header=f"{name_airfoil}",
                   fmt=COORD_FORMAT)
示例#3
0
def get_aircraft_airfoils(aircraft, settings, tigl, wing_uid, segment_uid,
                          idx_wing, idx_segment):
    """
    Extract the aircraft airfoils

    Args:
        :aircraft: Aircraft model
        :settings: Settings object
        :tigl: Tigl handle
        :segment_uid: Name of the segment
        :idx_wing: Index of the wing
        :idx_segment: Index of the segment
    """

    for position in ['inner', 'outer']:
        if position == 'inner':
            tigl_func = tigl.wingGetInnerSectionAndElementIndex
        else:
            tigl_func = tigl.wingGetOuterSectionAndElementIndex

        idx_section, idx_elem = tigl_func(idx_wing, idx_segment)
        name_airfoil = parse_str(
            tigl.wingGetProfileName(idx_wing, idx_section, idx_elem))
        if not name_airfoil:
            err_msg = f"""
            CPACS error: Could not extract {position} airfoil name
            * Wing: {idx_wing}
            * Segment: {idx_section}
            * Element: {idx_elem}
            """
            raise ValueError(err_msg)

        file_airfoil = join_paths(settings.paths('root'),
                                  PATHS.FILES.AIRFOIL(name_airfoil))
        aircraft.wings[wing_uid].segments[segment_uid].airfoils[
            position] = str(file_airfoil)