Fortran 读写 CGNS 网格

CGNS 网格 Fortran 读写方法

Resource

CGNS 官网 中点击 Under Construction New CGNS Website 可以进入正在建设的新网站,相关内容有所更新,特别是在历次版本更新中删改了部分文件代码 CGNS Release Documents

当前官网上已是最新版文档,旧文档入口 (https://cgns.github.io/cgns-archives/CGNS_docs_current/index.html)

MLL Remarke

MLL (Mid-Level Library) 基本内容

  • 基本文件操作,包括文件打开关闭和配置选项
  • CGNS 数据库访问节点
  • 错误处理
  • 数据库节点数据的读写和修改

基本语法

  • CGNS MLL 通过C语言编写,函数名以 cg 开头,Fortran函数添加 _g 后缀
  • 数据结构名和标签都限制 32 个字符,CGNS 文件名或描述符文本长度不限
  • CGNS-3.3.0开始,库中添加了一个 cgns.mod 文件,可以直接被 Fortran 调用
  • Fortran 函数会返回一个 ier 错误参数,如果不为0表示读取出错

CGNS 文件 Base 节点顶层结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
CGNSBase_t :=
{
List( Descriptor_t Descriptor1 ... DescriptorN ) ; (o)

int CellDimension ; (r)
int PhysicalDimension ; (r)

BaseIterativeData_t BaseIterativeData ; (o)

List( Zone_t<CellDimension, PhysicalDimension> Zone1 ... ZoneN ) ; (o)

ReferenceState_t ReferenceState ; (o)

Axisymmetry_t Axisymmetry ; (o)

RotatingCoordinates_t RotatingCoordinates ; (o)

Gravity_t Gravity ; (o)

SimulationType_t SimulationType ; (o)

DataClass_t DataClass ; (o)

DimensionalUnits_t DimensionalUnits ; (o)

FlowEquationSet_t<CellDimension> FlowEquationSet ; (o)

ConvergenceHistory_t GlobalConvergenceHistory ; (o)

List( IntegralData_t IntegralData1... IntegralDataN ) ; (o)

List( Family_t Family1... FamilyN ) ; (o)

List( UserDefinedData_t UserDefinedData1 ... UserDefinedDataN ) ; (o)
} ;

CGNS File Mapping Figures

Detailed CGNS Node Descriptions
CGNS File Mapping Figures

CGNS基础结构如下,关键物理数据保存在 zone 中,基本上网格包含几个 region 或 block,对应有多少个 zone

flowchart LR
  A1[Root Node]
    B1[CGNSLibraryVersion]
    B2[CGNSBase1]
      C1[ReferenceState]
      C2[SimulationType]
      C3[BaseIterativeData]
      C4[Axisymmetry]
      C5[RotatingCoordinates]
      C6[Gravity]
      C7[IntegralData]
      C8[ConvergenceHistory]
      C9[Family]
      C10[FlowEquationSet]
      C11[DataClass]
      C12[DimensionalUnits]
      C13[Descriptor]
      C14[UserDefinedData]
      D1[Zone1]
      D2[Zone2]
      D3[Zone...]
    B3[CGNSBase2]
    B4[CGNSBase...]

  subgraph Structural-Nodes; C2; D1; D2; D3; end;
  subgraph Descriptor; C13; end;
  subgraph Physical-Data; C11; C12; end;
  subgraph Auxiliary; C1; C6; C7; C8; C14; end;
  subgraph Time-Dependent; C3; end;
  subgraph Grid-Specification; C4; C5; end;
  subgraph Family; C9; end;
  subgraph Equation-Specification; C10; end;

  A1 --> B1 & B2 & B3 & B4
  B2 --> Structural-Nodes
  B2 --> Descriptor
  B2 --> Physical-Data
  B2 --> Auxiliary
  B2 --> Time-Dependent
  B2 --> Grid-Specification
  B2 --> Auxiliary
  B2 --> Family
  B2 --> Equation-Specification

zone 中的物理数据包括

flowchart LR
  A1[Zone]
    B1[GridCoordinates]
    B2[FlowSolution]
    B3[DiscreteData]
    B4[ZoneType]
    B5[Ordinal]
    B6[Elements]
    B7[ZoneGridConnectivity]
    B8[ZoneBC]
    B9[ZoneIterativeData]
    B10[ArbitraryGridMotion]
    B11[RigidGridMotion]
    B12[FamilyName]
    B13[AdditionalFamilyName]
    B14[ZoneSubRegion]

    subgraph Grid; B1; B6; B7; end;
    subgraph Solution; B2; B3; B9; end;
    subgraph BC; B8; B12; B13; end;
    subgraph Special-Grid; B10; B11; end;
    subgraph Sub-Region; B14; end;
    subgraph Information; B4; B5; end;

  A1 --> Grid
  A1 --> Solution
  A1 --> BC
  A1 --> Special-Grid
  A1 --> Sub-Region
  A1 --> Information

Multi-block strutural mesh

参考 CGNS UserGuide 和案例给出结构网格读写方法

  • Single-Zone Structured Grid
    • write_grid_str.f read_grid_str.f
  • Multi-Zone Structured Grid with 1-to-1 Connectivity
    • write_grid2zn_str.f read_grid2zn_str.f

Code basic structure

  • 读取文件
    • 打开文件 cg_open_f
    • 获取 zone 数量 cg_nzones_f
    • 获取 zone 大小 cg_zone_read_f
    • 读取 zone 网格坐标 cg_coord_read_f
    • 关闭文件 cg_close_f
  • 写入文件
    • 打开文件 cg_open_f
    • 创建 base cg_base_write_f
    • 创建 zone cg_zone_write_f
    • 写入 zone 网格坐标 cg_coord_write_f
    • 关闭文件 cg_close_f

需要注意节点读写顺序

Unstructural mesh

参考 CGNS UserGuide 和案例给出结构网格读写方法

  • Single-Zone Unstructured Grid
    • write_grid_unst.f read_grid_unst.f

Code basic structure

  • 读取文件
    • 打开文件 cg_open_f
    • 获取 zone 大小 cg_zone_read_f
    • 读取 zone 网格坐标 cg_coord_read_f
    • 获取 sections 数量 cg_nsections_f
    • 读取网格单元连接 cg_section_read_f cg_elements_read_f
    • 关闭文件 cg_close_f
  • 写入文件
    • 打开文件 cg_open_f
    • 创建 base cg_base_write_f
    • 创建 zone cg_zone_write_f
    • 写入 zone 网格坐标 cg_coord_write_f
    • 写入网格连接信息 cg_section_write_f
    • 关闭文件 cg_close_f
0%