carbonfly.wsl module

WSL runners for executing OpenFOAM commands from Windows.

This module provides helpers to launch OpenFOAM utilities inside WSL from a Windows Python environment (typically Rhino/Grasshopper on Windows). It opens a real Windows console window, invokes wsl.exe to run a command in bash, and optionally mirrors live output to a log file inside the case folder.

Note

This module is intended for Windows environments with WSL installed. On non-Windows platforms it may not be functional.

carbonfly.wsl.run_blockmesh_console(case_root: str | Path, *, foam_bashrc: str | None = '/opt/openfoam10/etc/bashrc', distro: str | None = None, timeout: int | None = None, log_rel: str = 'system/blockMesh.run.log') int[source]

Open a console and run blockMesh -case . inside the provided case folder, with progressive output mirrored to both the console and a log file.

Parameters:
  • case_root (str | Path) – Windows path to the OpenFOAM case directory.

  • foam_bashrc (str | None) – OpenFOAM bashrc to source in WSL.

  • distro (str | None) – WSL distro/profile name (e.g., Ubuntu-22.04).

  • timeout (int | None) – Optional timeout (seconds) for the launcher process.

  • log_rel (str) – Relative log path (under the case folder in WSL).

Returns:

Return code of the launcher process.

Return type:

int

carbonfly.wsl.run_check_mesh_console(case_root: str | Path, *, foam_bashrc: str | None = '/opt/openfoam10/etc/bashrc', distro: str | None = None, timeout: int | None = None, log_rel: str = 'system/checkMesh.run.log') int[source]

Open a console and run checkMesh inside the given case folder.

Parameters:
  • case_root (str | Path) – Windows path to the OpenFOAM case directory.

  • foam_bashrc (str | None) – OpenFOAM bashrc to source in WSL.

  • distro (str | None) – WSL distro/profile name (e.g., Ubuntu-22.04).

  • timeout (int | None) – Optional timeout (seconds) for the launcher process.

  • log_rel (str) – Relative log path (under the case folder in WSL).

Returns:

Return code of the launcher process.

Return type:

int

carbonfly.wsl.run_foam_console(case_root: str | Path, *, foam_bashrc: str | None = '/opt/openfoam10/etc/bashrc', distro: str | None = None, timeout: int | None = None, log_rel: str = 'buoyantReactingFoam.run.log') int[source]

Open a console and run buoyantReactingFoam inside the given case folder.

Parameters:
  • case_root (str | Path) – Windows path to the OpenFOAM case directory.

  • foam_bashrc (str | None) – OpenFOAM bashrc to source in WSL.

  • distro (str | None) – WSL distro/profile name (e.g., Ubuntu-22.04).

  • timeout (int | None) – Optional timeout (seconds) for the launcher process.

  • log_rel (str) – Relative log path (under the case folder in WSL).

Returns:

Return code of the launcher process.

Return type:

int

carbonfly.wsl.run_foam_monitor_console(case_root: str | Path, *, foam_bashrc: str | None = '/opt/openfoam10/etc/bashrc', distro: str | None = None, timeout: int | None = None, log_rel: str = 'foamMonitor.run.log', start_time: float | None = 0) int[source]

Open a console and run foamMonitor inside the given case folder.

This uses the residuals file produced by the OpenFOAM residuals function object, e.g.: postProcessing/residuals/<start_time>/residuals.dat.

Parameters:
  • case_root (str | Path) – Windows path to the OpenFOAM case directory.

  • foam_bashrc (str | None) – OpenFOAM bashrc to source in WSL.

  • distro (str | None) – WSL distro/profile name (e.g., Ubuntu-22.04).

  • timeout (int | None) – Optional timeout (seconds) for the launcher process.

  • log_rel (str) – Relative log path (under the case folder in WSL).

  • start_time (float | None) – Start time folder name used under postProcessing/residuals/. Default is 0.

Returns:

Return code of the launcher process.

Return type:

int

carbonfly.wsl.run_snappy_console(case_root: str | Path, *, foam_bashrc: str | None = '/opt/openfoam10/etc/bashrc', distro: str | None = None, timeout: int | None = None, log_rel: str = 'system/snappyHexMesh.run.log') int[source]

Open a console and run snappyHexMesh -overwrite inside the given case folder.

Parameters:
  • case_root (str | Path) – Windows path to the OpenFOAM case directory.

  • foam_bashrc (str | None) – OpenFOAM bashrc to source in WSL.

  • distro (str | None) – WSL distro/profile name (e.g., Ubuntu-22.04).

  • timeout (int | None) – Optional timeout (seconds) for the launcher process.

  • log_rel (str) – Relative log path (under the case folder in WSL).

Returns:

Return code of the launcher process.

Return type:

int

carbonfly.wsl.run_surface_features_console(case_root: str | Path, *, foam_bashrc: str | None = '/opt/openfoam10/etc/bashrc', distro: str | None = None, timeout: int | None = None, log_rel: str = 'system/surfaceFeatures.run.log') int[source]

Open a console and run surfaceFeatures inside the given case folder.

Parameters:
  • case_root (str | Path) – Windows path to the OpenFOAM case directory.

  • foam_bashrc (str | None) – OpenFOAM bashrc to source in WSL.

  • distro (str | None) – WSL distro/profile name (e.g., Ubuntu-22.04).

  • timeout (int | None) – Optional timeout (seconds) for the launcher process.

  • log_rel (str) – Relative log path (under the case folder in WSL).

Returns:

Return code of the launcher process.

Return type:

int

carbonfly.wsl.run_wsl_console(command: str, *, cwd_wsl: str | None = None, foam_bashrc: str | None = '/opt/openfoam10/etc/bashrc', distro: str | None = None, log_rel: str | None = None, timeout: int | None = None, keep_open: bool = True) int[source]

Launch command inside WSL in a Windows console, with live output.

Parameters:
  • command (str) – Command to run (e.g., blockMesh -case .).

  • cwd_wsl (str | None) – Working directory in WSL (e.g., /mnt/c/…/case). If None, no cd is performed.

  • foam_bashrc (str | None) – OpenFOAM bashrc to source before running the command. If None, no sourcing is done.

  • distro (str | None) – WSL distro name (e.g., Ubuntu-22.04). If None, default distro is used.

  • log_rel (str | None) – Relative log path (under cwd_wsl) for logging (e.g., system/blockMesh.run.log). If None, no log file is created.

  • timeout (int | None) – Optional timeout in seconds for the launcher process. Note: this does not control the lifetime of the spawned console.

  • keep_open (bool) – If True, keep the console open after the command ends (in that console) by prompting for a key press.

Returns:

Return code of the launcher process

Return type:

int

carbonfly.wsl.win_to_wsl_path(p: str) str[source]

Convert a Windows path (e.g., C:casesdemo) into a WSL path (/mnt/c/cases/demo).

Parameters:

p (str) – Windows path.

Returns:

WSL-style path.

Return type:

str

carbonfly.wsl.wsl_to_win_path(p: str) str[source]

Convert a WSL path (/mnt/c/…) to a Windows path when possible.

Only handles /mnt/<drive>/…; other forms are returned unchanged.

Parameters:

p (str) – WSL path.

Returns:

Windows path if convertible, otherwise the original input.

Return type:

str