From 819306379df5b0df5fc95840e5bf2bbda777738b Mon Sep 17 00:00:00 2001 From: aidanjungo Date: Fri, 9 Dec 2022 16:38:09 +0100 Subject: [PATCH 1/3] adapt to newer version of CEASIOMpy --- ceasiompy/CPACSUpdater/cpacsupdater.py | 61 +++++++++++++++++--------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/ceasiompy/CPACSUpdater/cpacsupdater.py b/ceasiompy/CPACSUpdater/cpacsupdater.py index 5bee0e3ce..a1087fd1b 100644 --- a/ceasiompy/CPACSUpdater/cpacsupdater.py +++ b/ceasiompy/CPACSUpdater/cpacsupdater.py @@ -16,24 +16,33 @@ """ -# ============================================================================== +# ================================================================================================= # IMPORTS -# ============================================================================== +# ================================================================================================= +from pathlib import Path +from cpacspy.cpacspy import CPACS from ceasiompy.utils.ceasiomlogger import get_logger -from cpacspy.cpacsfunctions import get_tigl_configuration, open_tigl, open_tixi + +from ceasiompy.utils.moduleinterfaces import ( + check_cpacs_input_requirements, + get_toolinput_file_path, +) log = get_logger() +MODULE_DIR = Path(__file__).parent +MODULE_NAME = MODULE_DIR.name + -# ============================================================================== +# ================================================================================================= # CLASSES -# ============================================================================== +# ================================================================================================= -# ============================================================================== +# ================================================================================================= # FUNCTIONS -# ============================================================================== +# ================================================================================================= def update_cpacs_file(cpacs_path, cpacs_out_path, optim_var_dict): @@ -53,16 +62,12 @@ def update_cpacs_file(cpacs_path, cpacs_out_path, optim_var_dict): """ - log.info("----- Start of CPACSUpdater -----") + cpacs = CPACS(cpacs_path) log.info(f"{cpacs_path} will be updated.") - tixi = open_tixi(cpacs_path) - tigl = open_tigl(tixi) - # Object seems to be unused, but are use in "eval" function - aircraft = get_tigl_configuration(tigl) - wings = aircraft.get_wings() - fuselage = aircraft.get_fuselages().get_fuselage(1) + wings = cpacs.aircraft.get_wings() + fuselage = cpacs.aircraft.get_fuselages().get_fuselage(1) # Perform update of all the variable contained in 'optim_var_dict' for name, variables in optim_var_dict.items(): @@ -88,23 +93,37 @@ def update_cpacs_file(cpacs_path, cpacs_out_path, optim_var_dict): # Update value directly in the CPACS file xpath = getcommand - tixi.updateTextElement(xpath, str(listval[-1])) + cpacs.tixi.updateTextElement(xpath, str(listval[-1])) - aircraft.write_cpacs(aircraft.get_uid()) - tigl.close() - tixi.save(str(cpacs_out_path)) + # aircraft.write_cpacs(aircraft.get_uid()) + cpacs.save_cpacs(str(cpacs_out_path)) log.info(f"{cpacs_out_path} has been saved.") log.info("----- Start of CPACSUpdater -----") -# ============================================================================== +# ================================================================================================= # MAIN -# ============================================================================== +# ================================================================================================= + + +def main(cpacs_path, cpacs_out_path): + + log.info("----- Start of " + MODULE_NAME + " -----") + + check_cpacs_input_requirements(cpacs_path) + update_cpacs_file(cpacs_path, cpacs_out_path, variable_to_update) + + log.info("----- End of " + MODULE_NAME + " -----") + if __name__ == "__main__": - print("Nothing to execute!") + cpacs_path = get_toolinput_file_path(MODULE_NAME) + cpacs_out_path = get_tooloutput_file_path(MODULE_NAME) + + main(cpacs_path, cpacs_out_path) + # Other functions which could be useful # help(aircraft) From fba902f5241661ac4ac379b6106a517f88fcebe1 Mon Sep 17 00:00:00 2001 From: aidanjungo Date: Thu, 15 Dec 2022 15:38:02 +0100 Subject: [PATCH 2/3] Rename variable and update comments --- ceasiompy/CPACSUpdater/cpacsupdater.py | 43 ++++++++++++-------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/ceasiompy/CPACSUpdater/cpacsupdater.py b/ceasiompy/CPACSUpdater/cpacsupdater.py index a1087fd1b..b0ef4a4ed 100644 --- a/ceasiompy/CPACSUpdater/cpacsupdater.py +++ b/ceasiompy/CPACSUpdater/cpacsupdater.py @@ -12,7 +12,7 @@ TODO: - * This module is still a bit tricky to use, it will be simplified in the future + * """ @@ -27,6 +27,7 @@ from ceasiompy.utils.moduleinterfaces import ( check_cpacs_input_requirements, get_toolinput_file_path, + get_tooloutput_file_path, ) log = get_logger() @@ -65,42 +66,38 @@ def update_cpacs_file(cpacs_path, cpacs_out_path, optim_var_dict): cpacs = CPACS(cpacs_path) log.info(f"{cpacs_path} will be updated.") - # Object seems to be unused, but are use in "eval" function + # DO NOT REMOVE, those variables are used in "eval" function wings = cpacs.aircraft.get_wings() fuselage = cpacs.aircraft.get_fuselages().get_fuselage(1) - # Perform update of all the variable contained in 'optim_var_dict' for name, variables in optim_var_dict.items(): - # Unpack the variables - val_type, listval, _, _, getcommand, setcommand = variables + val_type, list_val, _, _, get_command, set_command = variables - if val_type == "des" and listval[0] not in ["-", "True", "False"]: + if val_type == "des" and list_val[0] not in ["-", "True", "False"]: - if setcommand not in ["-", ""]: + if set_command in ["-", ""]: + + # Update value directly in the CPACS file + xpath = get_command + cpacs.tixi.updateTextElement(xpath, str(list_val[-1])) + + else: # Define variable (var1,var2,..) - locals()[str(name)] = listval[-1] + locals()[str(name)] = list_val[-1] - # Update value by using tigl configuration - if ";" in setcommand: # if more than one command on the line - command_split = setcommand.split(";") - for setcommand in command_split: - eval(setcommand) + if ";" in set_command: # if more than one command on the line + commands = set_command.split(";") else: - eval(setcommand) - else: + commands = [set_command] - # Update value directly in the CPACS file - xpath = getcommand - cpacs.tixi.updateTextElement(xpath, str(listval[-1])) + # Update value by using tigl configuration + for command in commands: + eval(command) - # aircraft.write_cpacs(aircraft.get_uid()) cpacs.save_cpacs(str(cpacs_out_path)) - log.info(f"{cpacs_out_path} has been saved.") - log.info("----- Start of CPACSUpdater -----") - # ================================================================================================= # MAIN @@ -112,7 +109,7 @@ def main(cpacs_path, cpacs_out_path): log.info("----- Start of " + MODULE_NAME + " -----") check_cpacs_input_requirements(cpacs_path) - update_cpacs_file(cpacs_path, cpacs_out_path, variable_to_update) + update_cpacs_file(cpacs_path, cpacs_out_path) log.info("----- End of " + MODULE_NAME + " -----") From 32a7d82728553ad1b8211f57b9d720dd59ce2276 Mon Sep 17 00:00:00 2001 From: aidanjungo Date: Thu, 15 Dec 2022 16:36:50 +0100 Subject: [PATCH 3/3] fix get wing and fuselage from configuration --- ceasiompy/CPACSUpdater/cpacsupdater.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ceasiompy/CPACSUpdater/cpacsupdater.py b/ceasiompy/CPACSUpdater/cpacsupdater.py index b0ef4a4ed..0188ea2b2 100644 --- a/ceasiompy/CPACSUpdater/cpacsupdater.py +++ b/ceasiompy/CPACSUpdater/cpacsupdater.py @@ -67,8 +67,8 @@ def update_cpacs_file(cpacs_path, cpacs_out_path, optim_var_dict): log.info(f"{cpacs_path} will be updated.") # DO NOT REMOVE, those variables are used in "eval" function - wings = cpacs.aircraft.get_wings() - fuselage = cpacs.aircraft.get_fuselages().get_fuselage(1) + wings = cpacs.aircraft.configuration.get_wings() + fuselage = cpacs.aircraft.configuration.get_fuselages().get_fuselage(1) for name, variables in optim_var_dict.items():