科研 Skill
ANSYS Fluent CFD仿真自动化
ansys-simulation
Automates ANSYS Fluent CFD setup, meshing, and batch runs via Python scripting, journal files, and the PyAnsys ecosystem. Use when a user wants to script or automate an ANSYS Fluent simulation.
SKILL.md
ANSYS Simulation Integration
Comprehensive guide for automating ANSYS Fluent CFD (Computational Fluid Dynamics) simulations using Python scripting, journal files, and the PyAnsys ecosystem.
Overview
ANSYS Fluent is a leading commercial CFD solver used for simulating fluid flow, heat transfer, and related phenomena in complex geometries. This skill covers automation approaches for:
- ANSYS Workbench: Unified platform for CAD integration, meshing, and workflow management
- ANSYS Fluent: Advanced CFD solver with extensive physics models
- PyAnsys: Python API ecosystem for programmatic control
- Journal Files: Text-based scripting for batch operations
ANSYS Workbench and Fluent Architecture
ANSYS Workbench
- Project-based workflow environment
- Integrates multiple ANSYS tools (Fluent, CFX, Mechanical, etc.)
- Supports parametric studies and design optimization
- Provides geometry and meshing tools (DesignModeler, SpaceClaim, Meshing)
ANSYS Fluent
- Finite volume-based CFD solver
- Extensive turbulence models (k-epsilon, k-omega SST, LES, DES)
- Multiphase flow capabilities
- Heat transfer and combustion modeling
- User-defined functions (UDFs) in C
- Text User Interface (TUI) for scripting
Licensing Requirements
Commercial Licensing
ANSYS products require commercial licenses managed through the ANSYS License Manager:
-
Fluent License Types:
- HPC licenses for parallel computing
- Solver licenses (increment-based)
- PrepPost licenses for pre/post-processing
-
License Server Setup:
# Set license server environment variable export ANSYSLMD_LICENSE_FILE=1055@license-server.company.com # Or in Windows set ANSYSLMD_LICENSE_FILE=1055@license-server.company.com -
License Checkout: Licenses are checked out when starting Fluent and returned on exit
-
HPC Licensing: Additional licenses required for parallel runs (typically cores/4)
Academic Licensing
- Student/teaching licenses available with limitations
- Typically limited mesh size and solver capabilities
- Separate license file required
Important Notes
- Always verify license availability before batch runs
- Consider license usage in automated workflows
- Use
-tflag to specify number of processors for HPC licensing
PyAnsys - Python API Introduction
PyAnsys provides a Pythonic interface to ANSYS products, enabling:
- Remote or local session management
- Programmatic control of simulation setup
- Data extraction and post-processing
- Integration with Python data science stack
Installation
# Install PyFluent (for Fluent automation)
pip install ansys-fluent-core
# Install other PyAnsys packages as needed
pip install ansys-mapdl-core # For Mechanical
pip install ansys-dpf-core # For post-processing
pip install ansys-geometry # For geometry operations
Basic PyFluent Usage
from ansys.fluent.core import launch_fluent
# Launch Fluent session
session = launch_fluent(precision='double', processor_count=4, mode='solver')
# Access TUI commands
session.tui.file.read_case('case_file.cas')
# Execute commands
session.tui.solve.iterate(100)
# Clean exit
session.exit()
Key PyAnsys Components
- ansys-fluent-core: Main Fluent automation package
- ansys-fluent-visualization: Post-processing and visualization
- ansys-geometry: CAD operations and geometry manipulation
- ansys-meshing: Automated meshing workflows
Journal File Scripting
Journal files are text-based scripts containing TUI commands executed sequentially by Fluent.
Journal File Format
; Comments start with semicolon
; Commands follow TUI menu structure
/file/read-case case_file.cas
/solve/initialize/initialize-flow
/solve/iterate 1000
/file/write-data result.dat
/exit yes
Running Journal Files
# Run Fluent in batch mode with journal file
fluent 3ddp -g -i journal.jou > fluent.log
# Flags:
# 3ddp: 3D double precision
# -g: Run without GUI
# -i: Input journal file
# -t4: Use 4 processors
Journal File Best Practices
- Use absolute paths for file I/O
- Include error checking where possible
- Add comments for maintainability
- Test interactively before batch execution
- Redirect output to log files for debugging
Common Workflow
1. Geometry Import
Via PyFluent:
from ansys.fluent.core import launch_fluent
solver = launch_fluent(precision='double', processor_count=4)
# Import geometry
solver.tui.file.import_.cad_geometry(
'geometry.scdoc',
'yes' # Confirm import
)
Via Journal File:
/file/import/cad-geometry geometry.step yes
2. Meshing Setup
Mesh Generation Strategy:
- Surface mesh extraction from CAD
- Volume mesh generation (tetrahedral, hex, poly)
- Boundary layer refinement for wall-bounded flows
- Mesh quality checks
PyFluent Meshing:
from ansys.fluent.core import launch_fluent
meshing = launch_fluent(precision='double', processor_count=4, mode='meshing')
# Import geometry
meshing.workflow.InitializeWorkflow(WorkflowType='Watertight Geometry')
# Set meshing parameters
meshing.meshing.GlobalSettings.set_state({
'MaxSize': 0.1,
'MinSize': 0.001,
'GrowthRate': 1.2
})
# Generate mesh
meshing.meshing.GenerateMesh()
# Switch to solver
solver = meshing.switch_to_solver()
Journal File Meshing:
/mesh/scale 0.001 0.001 0.001
/mesh/check
/mesh/repair-improve/repair
3. Physics Setup
Turbulence Models:
- k-epsilon: General purpose, wall functions
- k-omega SST: Better for adverse pressure gradients, boundary layers
- LES/DES: Large eddy simulation for transient, high-fidelity
Material Properties:
- Fluid properties (density, viscosity, thermal conductivity)
- Solid properties for conjugate heat transfer
PyFluent Physics Setup:
# Enable energy equation
solver.tui.define.models.energy('yes')
# Set turbulence model (k-omega SST)
solver.tui.define.models.viscous.kw_sst('yes')
# Define material properties
solver.tui.define.materials.change_create(
'water-liquid',
'water',
'yes',
'constant',
998.2, # Density
'yes',
'constant',
0.001003 # Viscosity
)
# Assign material to cell zone
solver.tui.define.boundary_conditions.fluid(
'fluid-zone',
'yes',
'water',
'no',
'no',
'no',
'no',
0,
'no',
0,
'no',
0,
'no',
'no'
)
Journal File Physics:
/define/models/energy yes no no no no
/define/models/viscous kw-sst yes
/define/materials/change-create air air yes constant 1.225 yes constant 1.7894e-05
4. Boundary Conditions
Common BC Types:
- Velocity inlet
- Pressure outlet
- Wall (stationary, moving, rotating)
- Symmetry
- Periodic
PyFluent BC Setup:
# Velocity inlet
solver.tui.define.boundary_conditions.velocity_inlet(
'inlet',
'yes',
'no',
'yes',
'yes',
'no',
10, # Velocity magnitude (m/s)
'no',
0,
'no',
0,
'no',
300, # Temperature
'no'
)
# Pressure outlet
solver.tui.define.boundary_conditions.pressure_outlet(
'outlet',
'yes',
'no',
0, # Gauge pressure
'no',
300,
'no',
'yes'
)
# Wall with no-slip
solver.tui.define.boundary_conditions.wall(
'wall',
'yes',
'no',
'no',
0,
'no',
0,
'no',
'yes',
'no',
0
)
5. Solver Settings
Solution Methods:
- Pressure-velocity coupling (SIMPLE, SIMPLEC, PISO, Coupled)
- Discretization schemes (first-order, second-order upwind, QUICK)
- Gradient evaluation (least squares, Green-Gauss)
PyFluent Solver Configuration:
# Set pressure-velocity coupling
solver.tui.solve.set.p_v_coupling(24) # 24 = Coupled
# Set discretization schemes
solver.tui.solve.set.discretization_scheme.pressure(12) # Second order
solver.tui.solve.set.discretization_scheme.mom(1) # Second order upwind
solver.tui.solve.set.discretization_scheme.k(1)
solver.tui.solve.set.discretization_scheme.omega(1)
# Set under-relaxation factors
solver.tui.solve.set.under_relaxation.pressure(0.3)
solver.tui.solve.set.under_relaxation.mom(0.7)
# Initialize flow field
solver.tui.solve.initialize.initialize_flow()
# Run iterations
solver.tui.solve.iterate(1000)
Convergence Criteria:
# Set residual convergence criteria
solver.tui.solve.monitors.residual.convergence_criteria(
'1e-6', # continuity
'1e-6', # x-velocity
'1e-6', # y-velocity
'1e-6', # z-velocity
'1e-6', # energy
'1e-6', # k
'1e-6' # omega
)
6. Post-Processing
Data Extraction:
# Create surface for reporting
solver.tui.surface.iso_surface(
'pressure',
'iso-surface-1',
'fluid-zone',
'()',
101325
)
# Export data
solver.tui.file.export.ascii(
'surface-data.csv',
'iso-surface-1',
'()',
'yes',
'pressure',
'velocity-magnitude',
'()'
)
# Calculate force on wall
solver.tui.report.forces.wall_forces(
'yes',
'wall-zone',
'()',
'yes',
'no',
'yes'
)
Visualization:
# Generate contour plot (requires GUI mode or visualization package)
solver.tui.display.set.contours.filled_contours('yes')
solver.tui.display.contour(
'pressure',
'pressure',
0,
0,
'surface-1',
'()'
)
# Save image
solver.tui.display.save_picture('pressure_contour.png')
Batch Mode Execution
Linux/Unix Batch Execution
#!/bin/bash
# batch_fluent.sh
# Set license server
export ANSYSLMD_LICENSE_FILE=1055@license-server.com
# Set number of processors
NPROCS=8
# Run Fluent in batch mode
fluent 3ddp -g -t${NPROCS} -i simulation.jou > fluent_${NPROCS}cores.log 2>&1
# Check exit status
if [ $? -eq 0 ]; then
echo "Simulation completed successfully"
else
echo "Simulation failed - check log file"
exit 1
fi
Windows Batch Execution
@echo off
REM batch_fluent.bat
set ANSYSLMD_LICENSE_FILE=1055@license-server.com
set NPROCS=8
"C:\Program Files\ANSYS Inc\v241\fluent\ntbin\win64\fluent.exe" 3ddp -g -t%NPROCS% -i simulation.jou > fluent.log 2>&1
if %ERRORLEVEL% EQU 0 (
echo Simulation completed successfully
) else (
echo Simulation failed - check log file
exit /b 1
)
Python-Based Batch Execution
import subprocess
import os
from pathlib import Path
def run_fluent_batch(journal_file, num_procs=4, log_file='fluent.log'):
"""
Run Fluent in batch mode with journal file.
Args:
journal_file: Path to journal file
num_procs: Number of processors
log_file: Output log file name
Returns:
bool: True if successful, False otherwise
"""
# Set license server
os.environ['ANSYSLMD_LICENSE_FILE'] = '1055@license-server.com'
# Build command
cmd = [
'fluent',
'3ddp', # 3D double precision
'-g', # No GUI
f'-t{num_procs}', # Number of processors
'-i', journal_file
]
# Run simulation
with open(log_file, 'w') as log:
result = subprocess.run(
cmd,
stdout=log,
stderr=subprocess.STDOUT,
text=True
)
return result.returncode == 0
# Example usage
if __name__ == '__main__':
success = run_fluent_batch(
journal_file='simulation.jou',
num_procs=8,
log_file='fluent_run.log'
)
if success:
print("Simulation completed successfully")
else:
print("Simulation failed - check log file")
Parametric Studies
import numpy as np
from ansys.fluent.core import launch_fluent
def parametric_study(velocities, case_file):
"""
Run parametric study varying inlet velocity.
Args:
velocities: List of inlet velocities to test
case_file: Base case file
"""
results = {}
for velocity in velocities:
print(f"Running simulation with velocity = {velocity} m/s")
# Launch Fluent
solver = launch_fluent(precision='double', processor_count=4)
# Read base case
solver.tui.file.read_case(case_file)
# Modify inlet velocity
solver.tui.define.boundary_conditions.velocity_inlet(
'inlet',
'yes', 'no', 'yes', 'yes', 'no',
velocity,
'no', 0, 'no', 0, 'no', 300, 'no'
)
# Initialize and solve
solver.tui.solve.initialize.initialize_flow()
solver.tui.solve.iterate(500)
# Extract results
# (Add result extraction here)
# Save case and data
output_file = f'result_v{velocity}.cas.h5'
solver.tui.file.write_case_data(output_file)
solver.exit()
results[velocity] = output_file
return results
# Run parametric study
velocities = np.linspace(5, 25, 5) # 5 to 25 m/s
results = parametric_study(velocities, 'base_case.cas.h5')
Best Practices
- License Management: Always check license availability before long batch runs
- Mesh Quality: Verify mesh quality before solving (skewness, aspect ratio)
- Convergence Monitoring: Set appropriate convergence criteria and monitor residuals
- File Management: Use clear naming conventions for parametric studies
- Error Handling: Implement robust error checking in automation scripts
- Documentation: Comment journal files and Python scripts thoroughly
- Version Control: Track journal files and scripts in version control
- Testing: Test automation workflows on small cases before production runs
- Resource Management: Monitor memory and disk usage for large simulations
- Reproducibility: Document all settings for reproducible results
Troubleshooting
Common Issues
- License checkout failures: Check license server connectivity and availability
- Mesh issues: Review mesh quality metrics and refine problematic regions
- Convergence problems: Adjust under-relaxation factors, check BC consistency
- Memory errors: Reduce mesh size or use more nodes in parallel
- File I/O errors: Verify file paths and permissions
Debugging Tips
- Run interactively first to validate workflow
- Check transcript files for TUI command syntax
- Use
-printflag in journal files for debugging - Monitor residual plots for convergence behavior
- Review warning and error messages in log files
Additional Resources
- ANSYS Documentation: Help system within ANSYS products
- PyAnsys Documentation: https://docs.pyansys.com
- ANSYS Learning Hub: Online training and tutorials
- ANSYS Community: User forums and knowledge base
- Fluent User's Guide: Comprehensive theory and usage manual
- Fluent TUI Reference: Complete TUI command listing
示例提示词
帮我写ANSYS Fluent的journal文件,自动跑这个叶轮的CFD仿真。
所属插件
安装该插件会一并获得同领域的 36 个 Skill / MCP。
同插件的其他科研 Skill
- Cantera燃烧仿真Runs Cantera combustion simulations: flame temperature, ignition delay, laminar flame speed, PSR. Use for mechanism-based combustion analysis tasks.
- 离心泵气蚀风险评估Calculates NPSHa and NPSHr and assesses cavitation risk for centrifugal pumps, with prevention and detection guidance. Use when sizing suction piping or diagnosing pump cavitation.
- 气蚀评估物性数据库Looks up vapor pressure, NPSHr data, and correlations for cavitation risk assessment in pumps. Use when cavitation-analysis needs reference property or NPSHr data.
- 离心泵设计计算Designs centrifugal pumps from first principles using Euler equations, velocity triangles, and specific speed. Use for impeller sizing or new centrifugal pump design.
- COMSOL多物理场耦合仿真Sets up coupled fluid-structure interaction simulations in COMSOL Multiphysics, focused on pump vibration analysis. Use when a user wants to script or automate a COMSOL FSI model.
- CoolProp流体物性查询Queries thermodynamic and transport properties for 100+ pure and pseudo-pure fluids via the CoolProp library. Use when a calculation needs fluid density, viscosity, or enthalpy data.
- 工程计算环境初始化Sets up a Python session with engineering constants, Pint units, and plotting defaults. Use at the start of a calculation session.
- 流体计算数值错误校验Handles common numerical errors in fluid calculations, such as division by zero and out-of-range physical values, with validation checks. Use when fluid code fails or returns unphysical results.
- 流体力学分析工作流Guides a systematic fluid dynamics analysis from problem setup and domain definition through model selection to validation. Use when planning a CFD or analytical fluid mechanics study end to end.
- 经验公式流体物性速算Computes quick fluid property estimates (density, viscosity, vapor pressure) from empirical correlations without needing a database. Use for fast order-of-magnitude property checks.
- 管道流动与泵选型计算Computes pipe flow, pump sizing, friction factor, and compressible flow results with the fluids Python package. Use for quick, code-based fluid mechanics calculations.
- 工程工具与数据库清点Enumerates installed Python packages, databases, and simulation tools available in the current environment. Use at the start of a session to avoid recommending unavailable tools.
- 管路元件损失系数查询Looks up loss coefficients (K-values) and equivalent lengths for pipes, valves, and fittings in pump and piping systems. Use when computing system head loss.
- 流体与材料物性查询Looks up temperature-dependent fluid viscosities, densities, and other material properties for pump and heat-transfer calculations. Use when a calculation needs property data at a given temperature.
- 泵性能曲线绘制Creates professional engineering plots such as pump performance curves, CFD velocity contours, and publication-quality figures with matplotlib. Use when a result needs a plotted figure.
- NASA大气与航空流体数据Accesses atmospheric property profiles and standard-atmosphere models from NASA Earthdata for high-altitude and aerospace fluid analysis. Use when a task needs altitude-dependent atmospheric data.
- 管网图论建模Models hydraulic piping networks and multi-pump systems as graphs using NetworkX flow algorithms. Use for analyzing flow distribution across a branched or looped piping network.
- REFPROP高精度物性查询Queries high-accuracy thermodynamic and transport properties from the commercial NIST REFPROP database. Use when a calculation needs reference-quality fluid property data and REFPROP is licensed.
- 数值数组计算Performs numerical array operations with NumPy: velocity field processing, pump curve interpolation, linear systems, and matrix methods. Use for general numerical computation in engineering code.
- OpenFOAM仿真与后处理Runs and post-processes OpenFOAM CFD simulations with PyFoam, pyvista, and vtk for mesh setup, solver control, and visualization. Use for scripted OpenFOAM workflows outside ParaView.
- 泵性能曲线与相似定律Generates and interprets pump H-Q/efficiency/power/NPSH curves, applies affinity laws, and predicts off-design performance. Use for pump curve analysis.
- 工程单位换算与量纲分析Handles engineering units with automatic conversion and dimensional-consistency checking using the Pint library. Use whenever a calculation mixes units or needs unit safety.
- 容积式泵设计分析Designs and analyzes gear, piston, and screw positive-displacement pumps, including volumetric efficiency and slip. Use when the pump is positive-displacement rather than centrifugal.
- 泵效率优化Maximizes pump efficiency through hydraulic design changes and operational strategies such as trimming, VFD control, and system matching. Use when a pump is running inefficiently.
常见问题
ANSYS Fluent CFD仿真自动化能做什么?
Automates ANSYS Fluent CFD setup, meshing, and batch runs via Python scripting, journal files, and the PyAnsys ecosystem. Use when a user wants to script or automate an ANSYS Fluent simulation。
如何安装ANSYS Fluent CFD仿真自动化?
在科搭 Codar 左侧点击「插件」,在「组件」页签搜索「ANSYS Fluent CFD仿真自动化」并安装;在 Claude Code 或 Codex 中可以发送本页的安装提示词,或下载 Skill 包后解压到 ~/.claude/skills 或 ~/.codex/skills。
ANSYS Fluent CFD仿真自动化需要哪些权限?
该科研 Skill没有声明额外权限;执行具体操作时仍由 Agent 按自身规则请求确认。
ANSYS Fluent CFD仿真自动化经过官方审核吗?
是。SpeedSkills 收录的每个版本都会记录内容摘要与权限声明,当前版本已通过安全审核。