Skip to content

Added support for newer versions of the xrotor file #1042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down