diff --git a/flow360/component/simulation/models/bet/bet_translator_interface.py b/flow360/component/simulation/models/bet/bet_translator_interface.py index ced654705..2f963a755 100644 --- a/flow360/component/simulation/models/bet/bet_translator_interface.py +++ b/flow360/component/simulation/models/bet/bet_translator_interface.py @@ -8,6 +8,7 @@ import flow360.component.simulation.units as u from flow360.exceptions import Flow360ValueError +from flow360.log import log def get_file_content(file_path: str): @@ -658,15 +659,19 @@ def check_num_values(values_list, line_num, numelts): Attributes ---------- values: list - numelts: int + numelts: int, list[int] return: None, raises an exception if the error condition is met """ + if isinstance(numelts, int): + numelts = [numelts] - if not len(values_list) == numelts: - raise Flow360ValueError( - f"wrong number of items for line #%i: {values_list}. We were expecting %i numbers and got %i" - % (line_num, len(values_list), numelts) - ) + for numelt in numelts: + if len(values_list) == numelt: + return + raise Flow360ValueError( + f"wrong number of items for line #{line_num}: {values_list}. " + + f"We were expecting {' or '.join([str(num) for num in numelts])} numbers and got {len(values_list)}" + ) # pylint: disable=too-many-statements @@ -922,7 +927,7 @@ def parse_xrotor_file(xrotor_file_content): lines = xrotor_file_content.split("\n") line_iter = iter(lines) - top_line = next(line_iter) + top_line: str = next(line_iter) line_num += 1 if top_line.find("DFDC") == 0: return read_dfdc_file(xrotor_file_content) @@ -932,6 +937,14 @@ def parse_xrotor_file(xrotor_file_content): "This input XROTOR file does not seem to be a valid XROTOR input file" ) + version = top_line.split(":")[1].strip() + + if (float(version) < 7.54) or (float(version) > 7.69): + log.warning( + "The XROTOR translator was prepared for file versions between 7.54 and 7.69," + + f" your version is {version}, errors may occur." + ) + xrotor_input_dict = {} next(line_iter) @@ -979,6 +992,9 @@ def parse_xrotor_file(xrotor_file_content): xrotor_input_dict["cdmin"] = [0] * n_aero_sections xrotor_input_dict["clcdmin"] = [0] * n_aero_sections xrotor_input_dict["dcddcl2"] = [0] * n_aero_sections + xrotor_input_dict["dcddcm2"] = [ + 0 + ] * n_aero_sections # currently unused by BET translator but we are recording it in case we need it in the future. for i in range(n_aero_sections): comment_line = next(line_iter).upper().split() @@ -1015,10 +1031,12 @@ def parse_xrotor_file(xrotor_file_content): check_comment(comment_line, line_num, 4) values = next(line_iter).split() line_num += 1 - check_num_values(values, line_num, 3) + check_num_values(values, line_num, [3, 4]) xrotor_input_dict["cdmin"][i] = float(values[0]) xrotor_input_dict["clcdmin"][i] = float(values[1]) xrotor_input_dict["dcddcl2"][i] = float(values[2]) + if len(values) == 4: + xrotor_input_dict["dcddcm2"][i] = float(values[3]) comment_line = next(line_iter).upper().split() line_num += 1