diff --git a/src/ansys/fluent/core/launcher/launcher.py b/src/ansys/fluent/core/launcher/launcher.py index 13856fcb25d7..bd2b87db5a26 100644 --- a/src/ansys/fluent/core/launcher/launcher.py +++ b/src/ansys/fluent/core/launcher/launcher.py @@ -12,7 +12,7 @@ import subprocess import tempfile import time -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, List, Optional, Union from ansys.fluent.core.fluent_connection import FluentConnection from ansys.fluent.core.launcher.fluent_container import ( @@ -426,13 +426,11 @@ def _generate_launch_string( return launch_string -def scm_to_py(topy): +def scm_to_py(topy, journal_filepaths): """Convert journal filenames to Python filename.""" - if not isinstance(topy, (str, list)): - raise TypeError("Journal name should be of str or list type.") + fluent_jou_arg = "".join([f'-i "{journal}" ' for journal in journal_filepaths]) if isinstance(topy, str): - topy = [topy] - fluent_jou_arg = "".join([f'-i "{journal}" ' for journal in topy]) + return f" {fluent_jou_arg} -topy={topy}" return f" {fluent_jou_arg} -topy" @@ -451,7 +449,7 @@ def launch_fluent( version: Optional[str] = None, precision: Optional[str] = None, processor_count: Optional[int] = None, - journal_filepath: Optional[str] = None, + journal_filepaths: Optional[List[str]] = None, start_timeout: int = 60, additional_arguments: Optional[str] = None, env: Optional[Dict[str, Any]] = None, @@ -492,8 +490,9 @@ def launch_fluent( Number of processors. The default is ``None``, in which case ``1`` processor is used. In job scheduler environments the total number of allocated cores is clamped to value of ``processor_count``. - journal_filepath : str, optional - Name of the journal file to read. The default is ``None``. + journal_filepaths : str, optional + The string path to a Fluent journal file, or a list of such paths. Fluent will execute the + journal(s). The default is ``None``. start_timeout : int, optional Maximum allowable time in seconds for connecting to the Fluent server. The default is ``60``. @@ -550,9 +549,9 @@ def launch_fluent( If True, Fluent will start with GPU Solver. cwd : str, Optional Working directory for the Fluent client. - topy : str or list, optional - The string path to a Fluent journal file, or a list of such paths. Fluent will execute the - journal(s) and write the equivalent Python journal(s). + topy : bool or str, optional + A boolean flag to write the equivalent Python journal(s) from the journal(s) passed. + Can optionally take the file name of the new python journal file. start_watchdog : bool, optional When ``cleanup_on_exit`` is True, ``start_watchdog`` defaults to True, which means an independent watchdog process is run to ensure @@ -640,7 +639,7 @@ def launch_fluent( "topy", "case_filepath", "lightweight_mode", - "journal_filepath", + "journal_filepaths", "case_data_filepath", ] invalid_arg_names = list( @@ -677,8 +676,17 @@ def launch_fluent( kwargs = _get_subprocess_kwargs_for_fluent(env) if cwd: kwargs.update(cwd=cwd) + if journal_filepaths: + if not isinstance(journal_filepaths, (str, list)): + raise TypeError("Journal name should be a list of strings.") + if isinstance(journal_filepaths, str): + journal_filepaths = [journal_filepaths] if topy: - launch_string += scm_to_py(topy) + if not journal_filepaths: + raise RuntimeError( + "Please provide the journal files to be converted as 'journal_filepaths' argument." + ) + launch_string += scm_to_py(topy, journal_filepaths) if _is_windows(): # Using 'start.exe' is better, otherwise Fluent is more susceptible to bad termination attempts @@ -726,11 +734,11 @@ def launch_fluent( session.tui.file.read_case(case_filepath) else: session.read_case(case_filepath, lightweight_mode) - if journal_filepath: + if journal_filepaths: if meshing_mode: - session.tui.file.read_journal(journal_filepath) + session.tui.file.read_journal(*journal_filepaths) else: - session.file.read_journal(file_name_list=[str(journal_filepath)]) + session.file.read_journal(file_name_list=journal_filepaths) if case_data_filepath: if not meshing_mode: session.file.read(