Exemplo n.º 1
0
def test_check_cpacs_input_requirements():
    """
    Test "check_cpacs_input_requirements()" function
    """

    os.chdir(os.path.dirname(__file__))

    cpacs_inout = m.CPACSInOut()
    cpacs_file = 'ToolInput/D150_AGILE_Hangar_v3.xml'

    cpacs_inout.add_input(
        var_name='cruise_alt',
        default_value=12000,
        unit='m',
        descr='Aircraft cruise altitude',
        xpath=m.CEASIOM_XPATH + '/ranges/cruiseAltitude',
    )

    assert m.check_cpacs_input_requirements(cpacs_file,
                                            cpacs_inout=cpacs_inout) is None

    cpacs_inout.add_input(
        var_name='something',
        default_value=None,
        unit='m',
        descr='Some description',
        xpath='/a/non-existent/path',
    )

    with pytest.raises(m.CPACSRequirementError):
        m.check_cpacs_input_requirements(cpacs_file, cpacs_inout=cpacs_inout)
def test_check_cpacs_input_requirements():
    """
    Test "check_cpacs_input_requirements()" function
    """

    os.chdir(os.path.dirname(__file__))

    cpacs_inout = mi.CPACSInOut()
    cpacs_file = "ToolInput/D150_AGILE_Hangar_v3.xml"

    cpacs_inout.add_input(
        var_name="cruise_alt",
        default_value=12000,
        unit="m",
        descr="Aircraft cruise altitude",
        xpath=RANGE_XPATH + "/cruiseAltitude",
    )

    assert mi.check_cpacs_input_requirements(cpacs_file,
                                             cpacs_inout=cpacs_inout) is None

    cpacs_inout.add_input(
        var_name="something",
        default_value=None,
        unit="m",
        descr="Some description",
        xpath="/a/non-existent/path",
    )

    with pytest.raises(mi.CPACSRequirementError):
        mi.check_cpacs_input_requirements(cpacs_file, cpacs_inout=cpacs_inout)
Exemplo n.º 3
0
def main(cpacs_path, cpacs_out_path):

    log.info("----- Start of " + os.path.basename(__file__) + " -----")

    mi.check_cpacs_input_requirements(cpacs_path)
    get_balance_estimations(cpacs_path, cpacs_out_path)

    log.info("----- End of " + os.path.basename(__file__) + " -----")
Exemplo n.º 4
0
def main(cpacs_path, cpacs_out_path):

    log.info("----- Start of " + MODULE_NAME + " -----")

    mi.check_cpacs_input_requirements(cpacs_path)

    get_weight_unc_estimations(cpacs_path, cpacs_out_path)

    log.info("----- End of " + MODULE_NAME + " -----")
Exemplo n.º 5
0
def main(cpacs_path, cpacs_out_path):

    log.info("----- Start of " + os.path.basename(__file__) + " -----")

    mi.check_cpacs_input_requirements(cpacs_path)

    add_skin_friction(cpacs_path, cpacs_out_path)

    log.info("----- End of " + os.path.basename(__file__) + " -----")
Exemplo n.º 6
0
def main(cpacs_path, cpacs_out_path):

    log.info("----- Start of " + MODULE_NAME + " -----")

    # Call the function which check if imputs are well define
    mi.check_cpacs_input_requirements(cpacs_path)

    export_aeromaps(cpacs_path, cpacs_out_path)

    log.info("----- End of " + MODULE_NAME + " -----")
Exemplo n.º 7
0
def main():
    log.info("Running PyTornado...")

    # ===== CPACS inout and output paths =====
    cpacs_in_path = DIR_MODULE + '/ToolInput/ToolInput.xml'
    cpacs_out_path = DIR_MODULE + '/ToolOutput/ToolOutput.xml'

    # ===== Delete old working directories =====
    settings_from_CPACS = get_pytornado_settings_from_CPACS(cpacs_in_path)
    if settings_from_CPACS is not None:
        if settings_from_CPACS.get('deleteOldWKDIRs', False):
            wkdirs = glob(os.path.join(DIR_MODULE, 'wkdir_*'))
            for wkdir in wkdirs:
                shutil.rmtree(wkdir, ignore_errors=True)

    # ===== Paths =====
    dir_pyt_wkdir = os.path.join(
        DIR_MODULE,
        f"wkdir_{datetime.strftime(datetime.now(), '%F_%H%M%S')}_{randint(1000, 9999)}"
    )
    dir_pyt_aircraft = os.path.join(dir_pyt_wkdir, 'aircraft')
    dir_pyt_settings = os.path.join(dir_pyt_wkdir, 'settings')
    file_pyt_aircraft = os.path.join(dir_pyt_aircraft, 'ToolInput.xml')
    file_pyt_settings = os.path.join(dir_pyt_settings, 'cpacs_run.json')

    # ===== Make directories =====
    Path(dir_pyt_wkdir).mkdir(parents=True, exist_ok=True)
    Path(dir_pyt_aircraft).mkdir(parents=True, exist_ok=True)
    Path(dir_pyt_settings).mkdir(parents=True, exist_ok=True)

    # ===== Setup =====
    shutil.copy(src=cpacs_in_path, dst=file_pyt_aircraft)
    check_cpacs_input_requirements(cpacs_in_path)

    # ===== Get PyTornado settings =====
    cpacs_settings = get_pytornado_settings(cpacs_in_path)
    with open(file_pyt_settings, "w") as fp:
        dump_pretty_json(cpacs_settings, fp)

    # ===== PyTornado analysis =====
    pytornado = import_pytornado('pytornado.stdfun.run')
    pytornado.standard_run(
        args=pytornado.StdRunArgs(run=file_pyt_settings, verbose=True))

    # ===== Clean up =====
    shutil.copy(src=file_pyt_aircraft, dst=cpacs_out_path)
    log.info("PyTornado analysis completed")
Exemplo n.º 8
0
    cpsf.close_tixi(tixi, cpacs_out_path)


#==============================================================================
#    MAIN
#==============================================================================

if __name__ == '__main__':

    log.info('----- Start of ' + os.path.basename(__file__) + ' -----')

    MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
    cpacs_path = os.path.join(MODULE_DIR, 'ToolInput', 'ToolInput.xml')
    cpacs_out_path = os.path.join(MODULE_DIR, 'ToolOutput', 'ToolOutput.xml')

    mi.check_cpacs_input_requirements(cpacs_path)

    add_skin_friction(cpacs_path, cpacs_out_path)

    log.info('----- End of ' + os.path.basename(__file__) + ' -----')

# Old function !!!
# TODO: Adapt the code deal with fixed CL mode case, then this function could be deleted completly

# def add_skin_friction(cpacs_path,cpacs_out_path):
#     cruise_alt_xpath = range_xpath + '/cruiseAltitude'
#     tixi, cruise_alt = cpsf.get_value_or_default(tixi,cruise_alt_xpath,12000)
#
#     cruise_mach_xpath = range_xpath + '/cruiseMach'
#     tixi, cruise_mach = cpsf.get_value_or_default(tixi,cruise_mach_xpath,0.78)
#
Exemplo n.º 9
0
    cd0 = estimate_skin_friction_coef(wetted_area,wing_area,wing_span, \
                                      cruise_mach,cruise_alt)

    # Save Cd0 in the CPACS file
    cd0_xpath = '/cpacs/toolspecific/CEASIOMpy/aerodynamics/skinFriction/cd0'
    tixi = create_branch(tixi, cd0_xpath)
    tixi.updateDoubleElement(cd0_xpath, cd0, '%g')
    log.info('Skin friction drag coeffienct (cd0) has been saved in the \
              CPACS file')

    close_tixi(tixi, cpacs_out_path)


#==============================================================================
#    MAIN
#==============================================================================

if __name__ == '__main__':

    log.info('----- Start of ' + os.path.basename(__file__) + ' -----')

    MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
    cpacs_path = MODULE_DIR + '/ToolInput/ToolInput.xml'
    cpacs_out_path = MODULE_DIR + '/ToolOutput/ToolOutput.xml'

    check_cpacs_input_requirements(cpacs_path, cpacs_inout, __file__)

    add_skin_friction(cpacs_path, cpacs_out_path)

    log.info('----- End of ' + os.path.basename(__file__) + ' -----')
Exemplo n.º 10
0
def main(cpacs_in_path, cpacs_out_path):

    log.info("Running PyTornado...")

    # ===== Delete old working directories =====
    settings_from_CPACS = get_pytornado_settings_from_CPACS(cpacs_in_path)
    if settings_from_CPACS is not None:
        if settings_from_CPACS.get("deleteOldWKDIRs", False):
            wkdirs = glob(os.path.join(DIR_MODULE, "wkdir_*"))
            for wkdir in wkdirs:
                shutil.rmtree(wkdir, ignore_errors=True)

    # ===== Paths =====
    dir_pyt_wkdir = os.path.join(DIR_MODULE, "wkdir_temp")

    dir_pyt_aircraft = os.path.join(dir_pyt_wkdir, "aircraft")
    dir_pyt_settings = os.path.join(dir_pyt_wkdir, "settings")
    dir_pyt_results = os.path.join(dir_pyt_wkdir, "_results")
    file_pyt_aircraft = os.path.join(dir_pyt_aircraft, "ToolInput.xml")
    file_pyt_settings = os.path.join(dir_pyt_settings, "cpacs_run.json")

    # ===== Make directories =====
    Path(dir_pyt_wkdir).mkdir(parents=True, exist_ok=True)
    Path(dir_pyt_aircraft).mkdir(parents=True, exist_ok=True)
    Path(dir_pyt_settings).mkdir(parents=True, exist_ok=True)
    Path(dir_pyt_results).mkdir(parents=True, exist_ok=True)

    # ===== Setup =====
    shutil.copy(src=cpacs_in_path, dst=file_pyt_aircraft)
    mi.check_cpacs_input_requirements(cpacs_in_path)

    # ===== Get PyTornado settings =====
    cpacs_settings = get_pytornado_settings(cpacs_in_path)
    with open(file_pyt_settings, "w") as fp:
        dump_pretty_json(cpacs_settings, fp)

    # ===== PyTornado analysis =====
    pytornado = import_pytornado("pytornado.stdfun.run")
    # pytornado.standard_run(args=pytornado.StdRunArgs(run=file_pyt_settings, verbose=True))
    results = pytornado.standard_run(
        args=pytornado.StdRunArgs(run=file_pyt_settings, verbose=True))

    # ===== Extract load =====
    tixi = open_tixi(cpacs_in_path)
    extract_loads_xpath = "/cpacs/toolspecific/pytornado/save_results/extractLoads"
    extract_loads = get_value_or_default(tixi, extract_loads_xpath, False)

    if extract_loads:
        _get_load_fields(results, dir_pyt_results)

    # ===== Clean up =====
    shutil.copy(src=file_pyt_aircraft, dst=cpacs_out_path)

    # ===== Copy files in the wkflow results directory =====
    # TODO: use dirs_exist_ok=True option when  python >=3.8 and remove "tmp"
    dst_pyt_wkdir = Path(get_results_directory("PyTornado"), "tmp")
    if os.path.isdir(dst_pyt_wkdir):
        shutil.rmtree(dst_pyt_wkdir)
    shutil.copytree(src=dir_pyt_wkdir, dst=dst_pyt_wkdir)
    shutil.rmtree(dir_pyt_wkdir, ignore_errors=True)

    log.info("PyTornado analysis completed")
Exemplo n.º 11
0
def main():

    log.info("Running PyTornado...")

    # ===== CPACS inout and output paths =====
    MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
    cpacs_in_path = mi.get_toolinput_file_path(MODULE_NAME)
    cpacs_out_path = mi.get_tooloutput_file_path(MODULE_NAME)

    # ===== Delete old working directories =====
    settings_from_CPACS = get_pytornado_settings_from_CPACS(cpacs_in_path)
    if settings_from_CPACS is not None:
        if settings_from_CPACS.get('deleteOldWKDIRs', False):
            wkdirs = glob(os.path.join(DIR_MODULE, 'wkdir_*'))
            for wkdir in wkdirs:
                shutil.rmtree(wkdir, ignore_errors=True)

    # ===== Paths =====
    dir_pyt_wkdir = os.path.join(DIR_MODULE, 'wkdir_temp')

    dir_pyt_aircraft = os.path.join(dir_pyt_wkdir, 'aircraft')
    dir_pyt_settings = os.path.join(dir_pyt_wkdir, 'settings')
    dir_pyt_results = os.path.join(dir_pyt_wkdir, '_results')
    file_pyt_aircraft = os.path.join(dir_pyt_aircraft, 'ToolInput.xml')
    file_pyt_settings = os.path.join(dir_pyt_settings, 'cpacs_run.json')

    # ===== Make directories =====
    Path(dir_pyt_wkdir).mkdir(parents=True, exist_ok=True)
    Path(dir_pyt_aircraft).mkdir(parents=True, exist_ok=True)
    Path(dir_pyt_settings).mkdir(parents=True, exist_ok=True)
    Path(dir_pyt_results).mkdir(parents=True, exist_ok=True)

    # ===== Setup =====
    shutil.copy(src=cpacs_in_path, dst=file_pyt_aircraft)
    mi.check_cpacs_input_requirements(cpacs_in_path)

    # ===== Get PyTornado settings =====
    cpacs_settings = get_pytornado_settings(cpacs_in_path)
    with open(file_pyt_settings, "w") as fp:
        dump_pretty_json(cpacs_settings, fp)

    # ===== PyTornado analysis =====
    pytornado = import_pytornado('pytornado.stdfun.run')
    #pytornado.standard_run(args=pytornado.StdRunArgs(run=file_pyt_settings, verbose=True))
    results = pytornado.standard_run(
        args=pytornado.StdRunArgs(run=file_pyt_settings, verbose=True))

    # ===== Extract load =====
    tixi = cpsf.open_tixi(cpacs_in_path)
    extract_loads_xpath = '/cpacs/toolspecific/pytornado/save_results/extractLoads'
    extract_loads = cpsf.get_value_or_default(tixi, extract_loads_xpath, False)

    if extract_loads:
        _get_load_fields(results, dir_pyt_results)

    # ===== Clean up =====
    shutil.copy(src=file_pyt_aircraft, dst=cpacs_out_path)

    wkdir = ceaf.get_wkdir_or_create_new(tixi)
    dst_pyt_wkdir = os.path.join(
        wkdir, 'CFD', 'PyTornado',
        f"wkdir_{datetime.strftime(datetime.now(), '%F_%H%M%S')}")
    shutil.copytree(src=dir_pyt_wkdir, dst=dst_pyt_wkdir)
    shutil.rmtree(dir_pyt_wkdir, ignore_errors=True)

    log.info("PyTornado analysis completed")