This project provides a general-purpose OpenFOAM case template for building outdoor wind environment simulation, suitable for:
- Wind environment assessment around buildings
- Building wind load analysis
- Urban microclimate research
- Building ventilation effectiveness evaluation
All parameters are centralized in a Python script, which generates OpenFOAM dictionary files from templates, simplifying input parameters. Parameter calculations are automated (e.g., simulation domain size is automatically determined from model dimensions), improving ease of use and lowering the entry barrier.
- OpenFOAM: Version 12 or higher
- Python: Version 3.10 or higher
- Operating System: Windows (blueCFD-Core recommended), Linux, or macOS
- Memory: Minimum 8GB RAM (16GB or higher recommended)
- Storage: At least 5GB free space
- Processor: Multi-core processor (4 cores or more recommended)
- Install blueCFD-Core 2024
- Ensure OpenFOAM 12 is properly installed
- Clone or download this project to a local directory recognized by the OpenFOAM terminal, e.g.,
\blueCFD-install-dir\ofuser-of12\
-
Install OpenFOAM 12:
# Refer to the official documentation for OpenFOAM installation # https://develop.openfoam.com/Development/openfoam/wiki/
-
Clone the project:
git clone <repository-url> cd windAroundBuildings-py
Save your building model as an ASCII-encoded STL file and place it in the constant/geometry/ directory. Update the model name in configure.py (no path needed; it is added automatically):
CONFIG = {
"model": {
"path": "your_building.stl", # Update to your model file
},
# ... other configurations
}Edit configure.py and adjust the following parameters as needed:
- Background mesh parameters: Domain size and mesh density
- Boundary conditions: Inlet wind speed, direction, turbulence parameters, etc.
- Refinement parameters: Mesh refinement levels and regions
- Solver parameters: Simulation time, time step, convergence criteria, etc.
In a terminal with OpenFOAM and Python environments configured (blueCFD-Core Terminal on Windows), navigate to the case directory and run:
python configure.pyContinue in the terminal, following the prompts from the configuration script:
# 1. Extract surface features
blockMesh
# 2. Generate background mesh
blockMesh
# 3. Generate refined mesh
snappyHexMesh -overwrite
# 4. Run solver
foamRunOr run all at once (no error output):
AllrunUse ParaView or other OpenFOAM-compatible post-processing tools to view results:
# Launch ParaView
paraFoamFull cleanup, restoring the case to its initial state:
AllcleanTo clean only the results while keeping the mesh: delete all numerically-named folders (OpenFOAM time steps) except the 0/ directory.
windAroundBuildings-py/
├── 0/ # Initial conditions
├── system/ # Solver and numerical scheme settings
├── constant/ # Mesh and physical properties
├── templates/ # Configuration file templates
├── configure.py # Main configuration script
└── README.md # This file
This project includes the following custom functions:
get_model_bounding_box(): Reads an STL file and calculates the bounding boxcalculate_background_mesh(): Computes the background mesh based on the model bounding boxcalculate_cells(): Calculates the number of mesh cells in each directioncalculate_refinement_box(): Computes the refinement regioncalculate_velocity_components(): Calculates wind speed componentsget_boundary_faces(): Retrieves boundary face indicesget_emesh_name(): Generates the eMesh filenameget_all_parameters(): Collects all replacement parameterscopy_template_file(): Copies files from templatesreplace_placeholders(): Replaces placeholders in files
A: Try the following:
- Lower relaxation factors
- Reduce the time step
- Increase maximum iterations
- Check mesh quality
A: Possible causes and solutions:
- Check the STL model for errors (use the
surfaceChecktool) - Adjust refinement levels
- Increase background mesh resolution
- Verify the model is inside the computational domain
A: Try the following:
- Increase mesh resolution
- Use a higher-order turbulence model
- Extend the simulation time
- Use a tighter convergence tolerance
This project is licensed under the MIT License. See the LICENSE file for details.
Issue reports and improvement suggestions are welcome. If you wish to contribute code, please follow these steps:
- Fork this repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
For questions or suggestions, please reach out via:
- Submit an Issue
- Email: [zh_k_j@163.com]
Thanks to the OpenFOAM community and the blueCFD-Core project for their excellent tools and support.
本项目旨在建立一个通用的建筑室外风环境模拟的 OpenFOAM 算例,可用于:
- 建筑物周围风环境评估
- 建筑物风荷载分析
- 城市微气候研究
- 建筑物通风效果评估
将参数集中于python脚本中,通过python从模板创建openFoam字典文件,简化输入条件参数,参数计算自动化(如模拟区域尺寸根据模型大小创建),以提高算例的易用性,降低使用门槛
- OpenFOAM: 版本 12 或更高
- Python: 版本 3.10 或更高
- 操作系统: Windows (推荐使用 blueCFD-Core)、Linux 或 macOS
- 内存: 最少 8GB RAM(推荐 16GB 或更高)
- 存储: 至少 5GB 可用空间
- 处理器: 多核处理器(推荐 4 核或更多)
- 安装 blueCFD-Core 2024
- 确保 OpenFOAM 12 已正确安装
- 克隆或下载此项目到 openFoam终端能识别到的本地目录 如
\blueCFD安装目录\ofuser-of12\
-
安装 OpenFOAM 12:
# 参考官方文档安装 OpenFOAM # https://develop.openfoam.com/Development/openfoam/wiki/
-
克隆项目:
git clone <repository-url> cd windAroundBuildings-py
将建筑模型保存为 ASCII编码 的 STL 格式,并放置在项目 constant/geometry/ 目录下。在 configure.py 中更新模型名称(无需加上路径,系统自动添加):
CONFIG = {
"model": {
"path": "your_building.stl", # 更新为你的模型文件
},
# ... 其他配置
}编辑 configure.py 文件,根据需要调整以下参数:
- 背景网格参数: 计算域大小和网格密度
- 边界条件: 入口风速、风向、湍流参数等
- 细化参数: 网格细化级别和区域
- 求解器参数: 计算时间、步长、收敛条件等
在配置好openFoam以及python环境的终端(Windows下的 blueCFD-Core Terminal),进入本算例文件夹后,执行配置脚本生成 OpenFOAM 参数字典文件:
python configure.py终端中继续按照配置脚本输出的提示执行以下命令:
# 1. 提取表面特征
surfaceFeatures
# 2. 生成运算域网格
blockMesh
# 3. 生成细化网格
snappyHexMesh -overwrite
# 4. 运行求解器
foamRun或者直接运行以上命令(无错误提示):
Allrun终端中使用 ParaView 或其他 OpenFOAM 兼容的后处理工具查看结果:
# 启动 ParaView
paraFoam全部清理,回到算例最初始状态:
Allclean仅清理计算结果,保留网格:删除除0以外所有数字命名的文件夹(openFoam计算写入的时间步)即可
windAroundBuildings-py/
├── 0/ # 初始条件目录
├── system/ # 求解器和数值方案设置
├── constant/ # 网格和物理属性
├── templates/ # 配置文件模板
├── configure.py # 主配置脚本
└── README.md # 本文件
本项目包含以下自定义函数:
get_model_bounding_box(): 读取STL文件并计算边界框calculate_background_mesh(): 根据模型边界框计算背景网格calculate_cells(): 计算各方向的网格单元数量calculate_refinement_box(): 计算细化区域calculate_velocity_components(): 计算风速分量get_boundary_faces(): 获取边界面索引get_emesh_name(): 生成eMesh文件名get_all_parameters(): 获取所有替换参数copy_template_file(): 从模板复制文件replace_placeholders(): 替换文件中的占位符
A: 可以尝试以下方法:
- 降低松弛因子
- 减小时间步长
- 增加最大迭代次数
- 检查网格质量
A: 可能的原因和解决方案:
- 检查STL模型是否有错误(使用 surfaceCheck 工具)
- 调整细化级别
- 增加背景网格分辨率
- 检查模型是否在计算域内
A: 可以尝试:
- 增加网格分辨率
- 使用更高级的湍流模型
- 增加计算时间
- 使用更小的收敛容差
本项目采用 MIT 许可证。详见 LICENSE 文件。
欢迎提交问题报告和改进建议。如果您想贡献代码,请遵循以下步骤:
- Fork 本仓库
- 创建您的特性分支 (
git checkout -b feature/AmazingFeature) - 提交您的更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 打开一个 Pull Request
如有问题或建议,请通过以下方式联系:
- 提交 Issue
- 发送邮件至 [zh_k_j@163.com]
感谢 OpenFOAM 社区和 blueCFD-Core 项目提供的优秀工具和支持。