Skip to content

Commit

Permalink
新增CFD笔记
Browse files Browse the repository at this point in the history
  • Loading branch information
2693742095 committed Mar 4, 2023
1 parent c10909e commit c741ee0
Show file tree
Hide file tree
Showing 7 changed files with 353 additions and 0 deletions.
49 changes: 49 additions & 0 deletions CFD/CFD专业名词含义解释.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
## CFD

CFD是计算流体动力学(Computational Fluid Dynamics)的英文缩写,其利用计算机求解流体流动过程中的质量传递、能量传递、动量传递以及化学反应问题。CFD是一种方法或者工具,解决对象是流体力学问题,利用手段是数值计算。



## CFD应用场合

只要存在流体流动的场合均可应用CFD。随着计算机技术及计算机计算能力的发展,CFD以及广泛应用于航空航天、造船、汽车、食品、能源、石油化工、生物医学等领域,而且还在不断的向其他行业扩展。



## CFD如何应用于工程

要将CFD应用于工程,需要做很多的工作,一般来讲,CFD工程应用都可以分为三个阶段:前处理、计算求解以及后处理。

### 前处理

**定义流动计算域**:建立流体流动区域。告诉计算机流体流动发生的场合。

**计算域离散**:将流动计算区域离散成网格单元,网格实现了将一个大问题化解为多个小问题,将连续的问题化解为离散的问题,将微分方程转化为代数方程

**指定计算控制方程**:告诉计算机所要解决的流体流动遵循的物理规则。

**定义边界流动条件**:特定流动问题有特定的流动边界条件。

**定义初始时刻流动条件**:告诉计算机,零时刻计算域处于何种状态。

**求解参数定义**: 如指定串行或并行计算、计算过程监测、离散算法指定等。

**输出参数定义**:定义计算过程中一些计算参数输出。

### 计算求解

计算求解通常由计算机自动完成,一般不需要人工干预。在前处理指定完毕后,求解器读取所有的求解参数进行自动求解计算,直至求解完成。

### 计算后处理

通过计算后处理将计算求解得到的数据以直观的方式展示出来,便于解读和工程应用。数据展现的方式包括:

**数据表**:每一个网格节点上的物理量数据,通常为压力、速度等原始变量。

**曲线图**:反映物理量变化规律

**云图**:反映物理量空间分布

**矢量图**:反映矢量空间分布

**动画**:以动画形式反应物理量随时间变化
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions CFD/CFD网格类型.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 网格存储类型

## 结构化网格

结构化网格的特性: **已知网格内某个点, 其相邻的点都可以通过这个点的坐标计算得出**

- 网格区域内所有的内部点都具有相同的毗邻单元, 二维为四边形, 三维为六面体
- 在拓扑结构上矩形区域内的均匀网格,其节点定义在每一层的网格线上,且每一层上节点数都相等
- 可以生成贴体网格, 但复杂外形的贴体网格生产很困难, 例如圆形网格。

![image-20230302201425945](CFD网格类型.assets/image-20230302201425945.png)



优点:

- 在结构化网格中,每一个节点及控制容积的几何信息必须加以存储,但该节点的邻点关系则是可以依据网格编号的规律而自动得出的,因此数据结构简单,不必专门存储这类信息;
- 网格生成的速度快, 网格生成的质量好;
- 对曲面或空间的拟合大多数采用参数化或样条插值的方法得到,区域光滑,与实际的模型更容易接近。它可以很容易地实现区域的边界拟合,适于流体和表面应力集中等方面的计算。

缺点

- 适用的范围比较窄,只适用于形状规则的图形, 画起来复杂



## 非结构化网格

非结构化网格是指网格区域内的内部点不具有相同的毗邻单元,可以是多种形状,四面体(也就三角的形状),六面体,棱形,也可以是六面体。与网格剖分区域内的不同内点相连的网格数目不同。

由点描绘边, 由边描绘面, 由面描述体. 原则上可以是各种图形, 但在描述复杂图形时候也可能存在离散误差, 例如用三角形组成一个多边形去描述一个圆。

![image-20230303142158244](CFD网格类型.assets/image-20230303142158244.png)

优点

非结构画网格没有规则的拓扑结构,也没有层的概念。网格节点的分布是随意的,因此具有灵活性,用于复杂图形的描述

缺点:

计算时需要较大的内存, 在查找和存储相邻化网格时比较复杂, 除了点迭代以外, 结构化网格的算法基本都不适用。



## 分块结构化网格

将复杂的图形拆分成多个块, 然后在不同的块里面使用结构化网格. 这这种块与块之间的关系就叫做网格的拓扑结构.

- 这种网格也是非结构化网格, 每个块之间的拓扑结构也需要描述
- 针对类似的图形, 分块情况可以继承, 达到网格可重用

优点: 继承了结构化网格的算法, 而且计算速度快

缺点: 分块基本都是是手动完成, 比较麻烦.

14 changes: 14 additions & 0 deletions CFD/CFD软件体系.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# CFD软件体系

## 简介

常见的CFD软件流程体系,计算流体力学、计算传热学理论研究和学习主要是针对前处理和求解器:

1. **三维CAD建模**:Solidworks、UG、Catia
2. **网格生成软件**:ICEM、Hypermesh
3. **前处理**:设置物理模型(即使用的求解方程,例如湍流还是层流、可压还是不可压)和边界条件(入口与出口)
4. **求解器**:Fluent、CFX、StarCD、OpenFoam等,根据前处理的条件生成离散代数方程组,迭代求解
5. **后处理器**:Tecplot等,图形化显示计算结果,计算总参数和平均参数



235 changes: 235 additions & 0 deletions CFD/CGNS库函数.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
# CGNS库函数

c语言相关函数返回值基本都是ier(int)错误状态,用之后的错误处理函数处理。



## 文件操作



### 打开和关闭文件

- `cg_open` - Open a CGNS file
- `cg_version `- Get CGNS file version
- `cg_precision` - Get CGNS file precision
- `cg_close` - Close a CGNS file
- `cg_is_cgns` - Check for a valid CGNS file
- `cg_save_as` - Save the open CGNS file
- `cg_set_file_type` - Set default file type
- `cg_get_file_type` - Get file type for open CGNS file

#### 函数

```c
ier = cg_open(char *filename, int mode, int *fn);
ier = cg_version(int fn, float *version);
ier = cg_precision(int fn, int *precision);
ier = cg_close(int fn);
ier = cg_is_cgns(const char *filename, int *file_type);
ier = cg_save_as(int fn, const char *filename, int file_type, int follow_links);
ier = cg_set_file_type(int file_type);
ier = cg_get_file_type(int fn, int *file_type);
```

#### 参数说明

| 变量名 | 功能 |
| ------------ | ------------------------------------------------------------ |
| filename | CGNS 文件的名称,必要时包括路径名。这个字符变量的长度没有限制。 |
| mode | 用于打开文件的模式。当前支持的模式是`CG_MODE_READ`(只读)、 `CG_MODE_WRITE`(只写)和`CG_MODE_MODIFY`(读写)。 |
| fn | CGNS 文件索引号。 |
| version | CGNS 版本号。 |
| precision | 指明CGNS 文件的精度。返回值将是 32(32 位)、64(64 位)之一,如果未知则为 0。 |
| file_type | CGNS 文件的类型。这通常是`CG_FILE_ADF``CG_FILE_HDF5`,具体取决于基础文件格式。但是,当以 32 位构建时,还有一个选项可以通过将文件类型设置为 `CG_FILE_ADF2`来创建2.5版本的CGNS 文件。 |
| follow_links | 此标志确定在保存 CGNS 文件时链接是否保持不变。如果非零,则链接将被删除,与链接文件相关的数据将复制到新文件。 |
| ier | 错误码。 |

#### 注意事项

- 函数`cg_open`必须始终是第一个被调用的。它打开一个 CGNS 文件进行读取和/或写入,并返回一个索引号`fn`。索引号用于在后续函数调用中标识 CGNS 文件。可以同时打开多个 CGNS 文件。当前一次打开的文件数限制取决于平台。在 SGI 工作站上,此限制设置为 100( *stdio.h*中的参数`FOPEN_MAX`)。
- 对于现有文件,函数`cg_is_cgns`可用于确定文件是否为 CGNS 文件,以及文件类型(`CG_FILE_ADF``CG_FILE_HDF5`)。如果文件是 CGNS 文件, 则 `cg_is_cgns`返回`CG_OK`,否则 返回`CG_ERROR`并将`file_type`设置为`CG_FILE_NONE`
- 打开文件时,如果未找到`CGNSLibraryVersion_t`节点,则假定 CGNS 版本号的默认值为 1.05。这对应于 CGNS 标准的旧版本,不包括当前标准支持的许多数据结构。
- 函数`cg_close`必须始终是最后调用的函数。它关闭由索引号`fn`指定的 CGNS 文件并释放保存 CGNS 数据的内存。当打开文件进行写入时,`cg_close`在关闭文件之前将内存中的所有 CGNS 数据写入磁盘。因此,如果省略,则 CGNS 文件不会被正确写入。
- 为了减少内存占用和提高执行速度,网格坐标或流解等大型数组实际上并不存储在内存中,只保留有关节点的基本信息,而数据的读写直接在应用程序的内存中进行。还尝试对非结构化网格元素数据执行相同的操作。
- 当使用`CG_MODE_WRITE` 创建新 CGNS 文件时,所使用的默认数据类型在编译时确定。如果 CGNS 库是使用 HDF5 版本 1.8 或更高版本支持构建的,文件类型将为`CG_FILE_HDF5`,否则使用`CG_FILE_ADF`。这可以通过将环境变量 `CGNS_FILETYPE`设置为`adf``hdf5``adf2` 之一,或者通过在调用 cg_open 之前调用例程`cg_set_file_type`来更改。 使用参数`CG_FILE_NONE`调用`cg_set_file_type`将重置库以使用默认文件类型。注意:如果设置了环境变量 `CGNS_FILETYPE`,则优先生效。
-`fn` 标识的 CGNS 文件可以使用`cg_save_as`保存为不同的文件名和类型。为了另存为 HDF5 文件,库必须已构建为支持 HDF5。始终构建 ADF 支持。函数`cg_set_file_type`为新创建的 CGNS 文件设置默认文件类型。函数 `cg_get_file_type`返回由`fn`标识的 CGNS 文件的文件类型。如果 CGNS 库构建为 32 位,则附加文件类型`CG_FILE_ADF2`可用。这允许创建一个 2.5 兼容的 CGNS 文件。



### 配置cgns文件结构

- `**cg_configure**` - Configure CGNS internals
- `**cg_error_handler**` - Set CGNS error handler
- `**cg_set_compress**` - Set CGNS compression mode
- `**cg_get_compress**` - Get CGNS compression mode
- `**cg_set_path**` - Set the CGNS link search path
- `**cg_add_path**` - Add to the CGNS link search path

#### 函数

```c
ier = cg_configure(int option, void *value);
ier = cg_error_handler(void (*)(int, char *));
ier = cg_set_compress(int compress);
ier = cg_get_compress(int *compress);
ier = cg_set_path(const char *path);
ier = cg_add_path(const char *path);
```

#### 参数说明

| 变量名 | 作用 |
| ---------- | ------------------------------------------------------------ |
| `option` | The option to configure, currently one of `CG_CONFIG_ERROR`, `CG_CONFIG_COMPRESS`, `CG_CONFIG_SET_PATH`, `CG_CONFIG_ADD_PATH`, `CG_CONFIG_FILE_TYPE`, `CG_CONFIG_RIND_INDEX`, `CG_CONFIG_HDF5_DISKLESS`, `CG_CONFIG_HDF5_DISKLESS_INCR`, `CG_CONFIG_HDF5_DISKLESS_WRITE`, `CG_CONFIG_HDF5_COMPRESS`, or `CG_CONFIG_HDF5_MPI_COMM` as defined in *cgnslib.h*. |
| `value` | The value to set, type cast as `void *`. In Fortran the type is `TYPE(C_PTR)`. |
| `compress` | CGNS compress (rewrite) setting. |
| `path` | Pathname to search for linked to files when opening a file with external links. |

#### 注意事项

- 要使用cg_error_handle,需要先用cg_configure定义遇CG_CONFIG_ERROR,相当于注册回调函数。
- 函数cg_error_handler如果`flag` 不为零,那么当遇到错误时,库将打印错误消息并以代码 1 退出。将`flag`设置为零(默认值)可以防止这种情况,并将错误返回给用户代码。





## 文件跳转

### Accessing a Node

- `**cg_goto**` - Access a node via label/name, index pairs
- `**cg_gorel**` - Access a node via relative path
- `**cg_gopath**` - Access a node via pathname
- `**cg_golist**` - Access a node via arrays of labels and indices
- `**cg_where**` - Get path to current node

### Deleting a Node

- `**cg_delete_node**` - Delete a node



## 错误处理

```c
//获取错误信息
error_message = const char *cg_get_error();

//错误退出(一般不用)
void cg_error_exit();

//直接打印错误信息
void cg_error_print();
```



## Node结构

### CGNS Base Information

- `cg_base_write` - Create and/or write to a CGNS base node
- `cg_nbases` - Get number of CGNS base nodes in file
- `cg_base_read` - Read CGNS base information
- `cg_cell_dim` - Get the cell dimension for the CGNS base

#### 函数

```c
ier = cg_base_write(int fn, char *basename, int cell_dim, int phys_dim, int *B);
ier = cg_nbases(int fn, int *nbases);
ier = cg_base_read(int fn, int B, char *basename, int *cell_dim,int *phys_dim);
ier = cg_cell_dim(int fn, int B, int *cell_dim);
```

#### 参数说明

| 变量名 | 功能 |
| ---------- | ------------------------------------------------------------ |
| `fn` | CGNS file index number. |
| `B` | Base index number, where 1 ≤ `B``nbases`. |
| `nbases` | Number of bases present in the CGNS file `fn`. |
| `basename` | Name of the base. |
| `cell_dim` | Dimension of the cells; 3 for volume cells, 2 for surface cells and 1 for line cells. |
| `phys_dim` | Number of coordinates required to define a vector in the field. |

### Zone Information

- `cg_zone_write` - Create and/or write to a zone node
- `cg_nzones` - Get number of zones in base
- `cg_zone_read` - Read zone information
- `cg_zone_type` - Get type of zone (structured or unstructured)aa·`cg_index_dim` - Get the index dimension for the CGNS zone

#### 函数

```c
ier = cg_zone_write(int fn, int B, char *zonename, cgsize_t *size,ZoneType_t zonetype, int *Z);
ier = cg_nzones(int fn, int B, int *nzones);
ier = cg_zone_read(int fn, int B, int Z, char *zonename, cgsize_t *size);
ier = cg_zone_type(int fn, int B, int Z, ZoneType_t *zonetype);
ier = cg_index_dim(int fn, int B, int Z, int *index_dim);
```

#### 参数说明

| 变量名 | 功能 |
| -------- | ------------------------------------------------------------ |
| fn | CGNS 文件索引号。 |
| B | 基本索引号,其中 1 ≤ `B``nbases`|
| Z | 区域索引号,其中 1 ≤ `Z``nzones`|
| nzones | base`B`中存在的区域数。 |
| zonename | 区域的名称。 |
| size | 每个 索引--维度 中的顶点、单元格和边界顶点的数量。对于结构化网格,维度在数组中具有单位跨度(例如`[NVertexI, NVertexJ, NVertexK, NCellI, NCellJ, NCellK, NBoundVertexI, NBoundVertexJ, NBoundVertexK]`)。 |

* 请注意,对于非结构化网格,单元格的数量是最高阶元素的数量。因此,在三个维度中,它是 3-D 单元的数量,在二维中,它是 2-D 单元的数量。同样对于非结构化网格,如果节点在内部节点和边界节点之间排序,则可选参数 `NBoundVertex`必须设置为等于边界节点的数量。默认情况下,`NBoundVertex`等于零,这意味着节点未排序。`请注意, NBoundVertex` 的非零值仅适用于非结构化网格。对于结构化网格,`NBoundVertex`参数在所有方向上始终等于 0。

### Simulation Type

- `**cg_simulation_type_write**` - Write simulation type
- `**cg_simulation_type_read**` - Read simulation type



## 网格操作



### zone网格坐标

- `cg_grid_write` - Create a `GridCoordinates_t` node
- `cg_ngrids` - Get number of `GridCoordinates_t` nodes
- `cg_grid_read` - Get name of a `GridCoordinates_t` node
- `cg_grid_bounding_box_read` - Get bounding box associated to a `GridCoordinates_t` node
- `cg_grid_bounding_box_write` - Write bounding box associated to a `GridCoordinates_t` node
- `cg_coord_write` - Write grid coordinates
- `cg_coord_partial_write` - Write subset of grid coordinates
- `cg_coord_general_write` - Write shaped array to a subset of grid coordinates
- `cg_ncoords`- Get number of coordinate arrays
- `cg_coord_info` - Get info about a coordinate array
- `cg_coord_read` - Read grid coordinates
- `cg_coord_general_read` - Read subset of grid coordinates to a shaped array

#### 函数

```c
ier = cg_grid_write(int fn, int B, int Z, char *GridCoordName, int *G);
ier = cg_ngrids(int fn, int B, int Z, int *ngrids);
ier = cg_grid_read(int fn, int B, int Z, int G, char *GridCoordName);
ier = cg_grid_bounding_box_write(int fn, int B, int Z, int G, DataType_t datatype, void *bbox_array);
ier = cg_grid_bounding_box_read(int fn, int B, int Z, int G, DataType_t datatype, void *bbox_array);
```

#### 参数说明

| 变量名 | 功能 |
| ------------------ | ------------------------------------------------------------ |
| fn | CGNS文件索引号 |
| B | 基本索引号,其中 1 ≤ `B``nbases`|
| Z | 区域索引号,其中 1 ≤ `Z``nzones`|
| `G` | 网格索引号,其中 1 ≤ `G``ngrids`|
| ngrids | 区域`Z``GridCoordinates_t`节点数。 |
| GridCoordinateName | `GridCoordinates_t`节点的名称。请注意,名称“ `GridCoordinates` ”是为原始网格保留的,并且必须是要定义的第一个`GridCoordinates_t` 节点。 |
| datatype | 写入文件或读取的边界框数组的数据类型。坐标边界框可接受的数据类型是`RealSingle``RealDouble`|
| `bbox_array` | 具有边界框值的数据数组。 |

0 comments on commit c741ee0

Please sign in to comment.