I have made a python script for running steady k-omega SST flow on an aircraft geometry, varying vertical and horizontal velocity components to simulate different angles of attack, trying to obtain lift and drag coefficients. The steady script works perfectly for what I need it to do. I now need the same script but for transient mode, and looked online for examples and such and made all changes that I thought I needed to, but keep getting errors saying that my .cas.h5 file is not in transient mode, and so transient-related commands will not work. I have 2 .cas.h5 files, one in steady and one in transient, and I ran both in the Fluent app just to make sure that they were both in their correct mode, and exported the .cas.h5 files from the app. So what changes need to be made from my steady script that works in order to run transient?
```# aoa_sweep_steady.py
import shutil
from pathlib import Path
from ansys.fluent.core import launch_fluent
import math
PARAMETERS
V = 15.0 # Freestream velocity [m/s]
nsteps = 250 # Number of iterations per AoA
aoa_start = 0 # Start angle of attack [deg]
aoa_end = 25 # End angle of attack [deg]
processors = 4 # Number of CPU cores for Fluent
reports = ["report-def-0-rfile.out", "report-def-1-rfile.out"] # Report files to copy
script_dir = Path(file).resolve().parent
project_root = script_dir
raw_data_base = project_root / "Raw Data"
raw_data_base.mkdir(parents=True, exist_ok=True)
LAUNCH FLUENT
session = launch_fluent(
mode="solver",
precision="single",
processor_count=processors,
)
LOAD BASE CASE
session.tui.file.read_case("base_aircraft_steady.cas.h5")
RUN COUNTER
run_id = 1
AOA SWEEP LOOP
for aoa in range(aoa_start, aoa_end + 1):
aoa_rad = math.radians(aoa)
Vy = V * math.sin(aoa_rad)
Vz = V * math.cos(aoa_rad)
# Set velocity inlet
session.settings.setup.boundary_conditions.velocity_inlet["farfield"] = {
"momentum": {
"velocity_specification_method": "Components",
"velocity": [0.0, Vy, Vz],
"reference_frame": "Absolute",
}
}
# Initialize only once
if aoa == 0:
session.settings.solution.initialization.initialization_type = "hybrid"
session.settings.solution.initialization.hybrid_initialize()
# Run steady solver
session.settings.solution.run_calculation.iterate(iter_count=nsteps)
# Save case & data
session.tui.file.write_case_data(f"aoa_{aoa}.cas.h5")
# Create numbered folder & copy reports
aoa_folder = raw_data_base / str(run_id)
aoa_folder.mkdir(parents=True, exist_ok=True)
for report in reports:
src = Path(report)
if src.exists():
shutil.copy2(src, aoa_folder / report)
else:
print(f"Warning: {report} not found")
run_id += 1
EXIT FLUENT
session.exit()```
```# aoa_sweep_transient.py
import shutil
from pathlib import Path
from ansys.fluent.core import launch_fluent
import math
PARAMETERS
V = 15.0 # Freestream velocity [m/s]
dt = 0.0002 # Time step size [s]
nsteps = 300 # Number of time steps per AoA
aoa_start = 0 # Start AoA [deg]
aoa_end = 25 # End AoA [deg]
processors = 4 # Fluent cores
reports = ["report-def-0-rfile.out", "report-def-1-rfile.out"]
PROJECT ROOT
script_dir = Path(file).resolve().parent
project_root = script_dir
raw_data_base = project_root / "Raw Data"
raw_data_base.mkdir(parents=True, exist_ok=True)
LAUNCH FLUENT
session = launch_fluent(
mode="solver",
precision="single",
processor_count=processors
)
LOAD BASE TRANSIENT CASE
session.tui.file.read_case("base_aircraft_transient.cas.h5")
RUN COUNTER
run_id = 1
AOA SWEEP LOOP
for aoa in range(aoa_start, aoa_end + 1):
aoa_rad = math.radians(aoa)
Vy = V * math.sin(aoa_rad)
Vz = V * math.cos(aoa_rad)
# Set velocity inlet
session.settings.setup.boundary_conditions.velocity_inlet["farfield"] = {
"momentum": {
"velocity_specification_method": "Components",
"velocity": [0.0, Vy, Vz],
"reference_frame": "Absolute",
}
}
# Initialize at first AoA
if aoa == 0:
session.settings.solution.initialization.initialization_type = "hybrid"
session.settings.solution.initialization.hybrid_initialize()
tc = session.settings.solution.run_calculation.transient_controls
tc.specified_time_step = dt
tc.max_iter_per_time_step = 20
tc.max_number_of_time_steps = nsteps
elif aoa > 0:
tc = session.settings.solution.run_calculation.transient_controls
tc.specified_time_step = dt
tc.max_iter_per_time_step = 20
tc.max_number_of_time_steps = nsteps
session.settings.solution.run_calculation.run()
# Save case & data
case_filename = f"aoa_{aoa}.cas.h5"
session.tui.file.write_case_data(case_filename)
print(f"Saved case/data: {case_filename}")
# Create numbered folder & copy reports
aoa_folder = raw_data_base / str(run_id)
aoa_folder.mkdir(parents=True, exist_ok=True)
for report in reports:
src = Path(report)
if src.exists():
shutil.copy2(src, aoa_folder / report)
print(f"Copied {report} -> {aoa_folder}")
else:
print(f"Warning: {report} not found")
run_id += 1
Exit Fluent
session.exit()```