Created
February 20, 2026 19:25
-
-
Save Suave101/dc2d95896e8191b9794c4e21933facfd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ansys.fluent.core as pyfluent | |
| import pandas as pd | |
| # 1. Read your Excel file | |
| # Assuming columns: 'Mach', 'T_total', 'P_total', 'k', 'omega', 'viscosity' | |
| df = pd.read_excel('Ansys - 10k Rocket.xlsx') | |
| # 2. Launch Fluent | |
| # Because this runs inside SLURM, PyFluent automatically grabs the 32 cores you requested | |
| solver = pyfluent.launch_fluent(precision="double", dimension=3, mode="solver") | |
| # 3. Read Mesh | |
| solver.file.read(file_name="rocket_mesh.msh") | |
| # 4. Global Solver Setup (Your specific GUI settings) | |
| solver.setup.models.solver.type = "density-based" | |
| solver.setup.models.energy.enable = True | |
| solver.setup.models.viscous.model = "k-omega" | |
| solver.setup.models.viscous.k_omega_model = "sst" | |
| # Set Air to Ideal Gas and Sutherland viscosity | |
| solver.setup.materials.fluid['air'].density.option = "ideal-gas" | |
| solver.setup.materials.fluid['air'].viscosity.option = "sutherland" | |
| # 5. Loop over your Excel data | |
| for index, row in df.iterrows(): | |
| print(f"--- Running Simulation for Mach {row['Mach']} ---") | |
| # Apply Excel boundary conditions to the inlet | |
| solver.setup.boundary_conditions.pressure_inlet['inlet'] = { | |
| "momentum": { | |
| "gauge_total_pressure": {"value": row['P_total']}, | |
| "turbulent_kinetic_energy": {"value": row['k']}, | |
| "specific_dissipation_rate": {"value": row['omega']} | |
| }, | |
| "thermal": { | |
| "t0": {"value": row['T_total']} | |
| } | |
| } | |
| # Initialize and run 1000 iterations | |
| solver.solution.initialization.standard_initialize() | |
| solver.solution.run_calculation.iterate(iter_count=1000) | |
| # Extract the C_D value directly into Python | |
| cd_value = solver.solution.report_definitions.drag["drag_report"].get_value() | |
| print(f"Completed Mach {row['Mach']} | C_D = {cd_value}") | |
| # Save the data file for this specific Mach number | |
| solver.file.write_case_data(file_name=f"rocket_results_mach_{row['Mach']}.cas.h5") | |
| # Exit Fluent when the loop is done | |
| solver.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment