Skip to content

Feihei/windAroundBuildings-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fast Wind Around Buildings Simulation Template

建筑室外风模拟快速模板

中文说明 / Chinese Version

Project Overview

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.

System Requirements

Software

  • OpenFOAM: Version 12 or higher
  • Python: Version 3.10 or higher
  • Operating System: Windows (blueCFD-Core recommended), Linux, or macOS

Hardware

  • Memory: Minimum 8GB RAM (16GB or higher recommended)
  • Storage: At least 5GB free space
  • Processor: Multi-core processor (4 cores or more recommended)

Installation & Setup

Windows Users (blueCFD-Core)

  1. Install blueCFD-Core 2024
  2. Ensure OpenFOAM 12 is properly installed
  3. Clone or download this project to a local directory recognized by the OpenFOAM terminal, e.g., \blueCFD-install-dir\ofuser-of12\

Linux/macOS Users

  1. Install OpenFOAM 12:

    # Refer to the official documentation for OpenFOAM installation
    # https://develop.openfoam.com/Development/openfoam/wiki/
  2. Clone the project:

    git clone <repository-url>
    cd windAroundBuildings-py

Usage

1. Prepare Building Model

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
}

2. Configure Simulation Parameters

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.

3. Run Configuration Script

In a terminal with OpenFOAM and Python environments configured (blueCFD-Core Terminal on Windows), navigate to the case directory and run:

python configure.py

4. Run Simulation

Continue 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
foamRun

Or run all at once (no error output):

Allrun

5. Post-Processing

Use ParaView or other OpenFOAM-compatible post-processing tools to view results:

# Launch ParaView
paraFoam

6. Clean Case

Full cleanup, restoring the case to its initial state:

Allclean

To clean only the results while keeping the mesh: delete all numerically-named folders (OpenFOAM time steps) except the 0/ directory.

Project Structure

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

Custom Functions

This project includes the following custom functions:

  • get_model_bounding_box(): Reads an STL file and calculates the bounding box
  • calculate_background_mesh(): Computes the background mesh based on the model bounding box
  • calculate_cells(): Calculates the number of mesh cells in each direction
  • calculate_refinement_box(): Computes the refinement region
  • calculate_velocity_components(): Calculates wind speed components
  • get_boundary_faces(): Retrieves boundary face indices
  • get_emesh_name(): Generates the eMesh filename
  • get_all_parameters(): Collects all replacement parameters
  • copy_template_file(): Copies files from templates
  • replace_placeholders(): Replaces placeholders in files

FAQ

Q: What if the simulation does not converge?

A: Try the following:

  • Lower relaxation factors
  • Reduce the time step
  • Increase maximum iterations
  • Check mesh quality

Q: What if mesh generation fails?

A: Possible causes and solutions:

  • Check the STL model for errors (use the surfaceCheck tool)
  • Adjust refinement levels
  • Increase background mesh resolution
  • Verify the model is inside the computational domain

Q: How to improve simulation accuracy?

A: Try the following:

  • Increase mesh resolution
  • Use a higher-order turbulence model
  • Extend the simulation time
  • Use a tighter convergence tolerance

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Issue reports and improvement suggestions are welcome. If you wish to contribute code, please follow these steps:

  1. Fork this repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Contact

For questions or suggestions, please reach out via:

Acknowledgments

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 核或更多)

安装与设置

Windows 用户 (使用 blueCFD-Core)

  1. 安装 blueCFD-Core 2024
  2. 确保 OpenFOAM 12 已正确安装
  3. 克隆或下载此项目到 openFoam终端能识别到的本地目录\blueCFD安装目录\ofuser-of12\

Linux/macOS 用户

  1. 安装 OpenFOAM 12:

    # 参考官方文档安装 OpenFOAM
    # https://develop.openfoam.com/Development/openfoam/wiki/
  2. 克隆项目:

    git clone <repository-url>
    cd windAroundBuildings-py

使用方法

1. 准备建筑模型

将建筑模型保存为 ASCII编码 的 STL 格式,并放置在项目 constant/geometry/ 目录下。在 configure.py 中更新模型名称(无需加上路径,系统自动添加):

CONFIG = {
    "model": {
        "path": "your_building.stl",  # 更新为你的模型文件
    },
    # ... 其他配置
}

2. 配置模拟参数

编辑 configure.py 文件,根据需要调整以下参数:

  • 背景网格参数: 计算域大小和网格密度
  • 边界条件: 入口风速、风向、湍流参数等
  • 细化参数: 网格细化级别和区域
  • 求解器参数: 计算时间、步长、收敛条件等

3. 运行配置脚本

在配置好openFoam以及python环境的终端(Windows下的 blueCFD-Core Terminal),进入本算例文件夹后,执行配置脚本生成 OpenFOAM 参数字典文件:

python configure.py

4. 运行模拟

终端中继续按照配置脚本输出的提示执行以下命令:

# 1. 提取表面特征
surfaceFeatures

# 2. 生成运算域网格
blockMesh

# 3. 生成细化网格
snappyHexMesh -overwrite

# 4. 运行求解器
foamRun

或者直接运行以上命令(无错误提示):

Allrun

5. 后处理

终端中使用 ParaView 或其他 OpenFOAM 兼容的后处理工具查看结果:

# 启动 ParaView
paraFoam

6. 清理算例

全部清理,回到算例最初始状态:

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(): 替换文件中的占位符

常见问题

Q: 模拟不收敛怎么办?

A: 可以尝试以下方法:

  • 降低松弛因子
  • 减小时间步长
  • 增加最大迭代次数
  • 检查网格质量

Q: 网格生成失败怎么办?

A: 可能的原因和解决方案:

  • 检查STL模型是否有错误(使用 surfaceCheck 工具)
  • 调整细化级别
  • 增加背景网格分辨率
  • 检查模型是否在计算域内

Q: 如何提高模拟精度?

A: 可以尝试:

  • 增加网格分辨率
  • 使用更高级的湍流模型
  • 增加计算时间
  • 使用更小的收敛容差

许可证

本项目采用 MIT 许可证。详见 LICENSE 文件。

贡献

欢迎提交问题报告和改进建议。如果您想贡献代码,请遵循以下步骤:

  1. Fork 本仓库
  2. 创建您的特性分支 (git checkout -b feature/AmazingFeature)
  3. 提交您的更改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 打开一个 Pull Request

联系方式

如有问题或建议,请通过以下方式联系:

致谢

感谢 OpenFOAM 社区和 blueCFD-Core 项目提供的优秀工具和支持。

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors