首次提交

This commit is contained in:
2026-10-10 21:56:35 +08:00
commit 246d9b7870
96 changed files with 7109 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
本目录下文件为:
使用mkdocs生成wiki静态html页面的源md及相关配置文件。
+4
View File
@@ -0,0 +1,4 @@
site_name: Ruyang.wiki
site_url: https://wiki.ruyangthinks.com
theme:
name: material
+58
View File
@@ -0,0 +1,58 @@
site_name: MeshKernelPy 中文文档
site_url: https://wiki.ruyangthinks.com/meshkernelpy
theme:
name: material
language: zh
font: false
features:
- navigation.top
- content.code.copy
site_description: MeshKernelPy 8.3.0 完整中文 API 参考与示例教程
docs_dir: /data/md/docs/meshkernelpy #../doc/meshkernelpy
site_dir: /data/html/meshkernelpy #../../tem
use_directory_urls: false
plugins:
- search:
lang:
- zh
- en
markdown_extensions:
- admonition
- attr_list
- tables
- toc:
permalink: true
- pymdownx.highlight
- pymdownx.superfences
nav:
- 首页: index.md
- API 参考:
- 总览: api/modules.md
- 包顶层导出接口: api/meshkernel.md
- MeshKernel 核心接口: api/meshkernel.meshkernel.md
- Python 数据结构与枚举: api/meshkernel.py_structures.md
- C 数据结构与转换接口: api/meshkernel.c_structures.md
- 异常类型: api/meshkernel.errors.md
- 辅助函数: api/meshkernel.utils.md
- 版本信息: api/meshkernel.version.md
- 示例教程:
- 示例目录: examples/index.md
- 二维网格基础: examples/01_mesh2d_basics.md
- 一维网格基础: examples/02_mesh1d_basics.md
- 在给定几何区域内生成简单三角网格: examples/03_tri_mesh2d_pol.md
- 曲线网格基础: examples/04_curvilineargrid_basics.md
- 基于规则网格采样数据的二维网格加密: examples/05_mesh2d_refinement_gridded_samples.md
- 基于不同水深精度的 GEBCO 网格采样数据进行二维网格加密: examples/06_mesh2d_refinement_gridded_samples_gebco.md
- 在指定范围内生成曲线网格: examples/07_curvilineargrid_with_defined_extension.md
- 大型网格正交化: examples/08_mesh2d_orthogonalization.md
- 网格删除: examples/09_mesh2d_deletion.md
- 生成全球网格: examples/10_mesh2d_global_grid.md
- 基于网格采样数据的二维网格脊线加密: examples/11_mesh2d_refine_ridges_gridded_samples.md
- 基于含海岸线的网格采样数据进行二维网格加密: examples/12_mesh2d_refine_gridded_samples_coastlines.md
- 基于带步长数组的网格采样数据进行二维网格加密: examples/13_mesh2d_refine_gridded_samples_strided_arrays.md
- 生成一维与二维网格之间的连接: examples/14_contacts_generation.md
- 基于水深的二维网格 Casulli 加密: examples/15_mesh2d_refinement_casulli_based_on_depths.md
validation:
links:
anchors: warn
unrecognized_links: warn
+3
View File
@@ -0,0 +1,3 @@
# 导航页面
这是主导航页面。
@@ -0,0 +1,809 @@
# C 数据结构与转换接口
模块:`meshkernel.c_structures`。本页依据本地 MeshKernelPy `8.3.0` 源码生成,包含该模块定义的类、方法、函数和常量。签名及参数默认值以源码为准;原文未提供的说明会明确标记。
[返回 API 总览](modules.md)
## `CMesh2d` {#cmesh2d}
继承:`Structure`。
仅供内部使用的 C 数据结构。 表示 MeshKernel API 定义的 Mesh2D 结构体。
用于与 MeshKernel 动态链接库通信。
该类的 `_fields_` 属性包含以下字段:
- **`edge_faces`(`POINTER(c_int)`)**:每条边关联的网格面索引。
- **`edge_nodes`(`POINTER(c_int)`)**:组成每条二维网格边的节点。
- **`face_edges`(`POINTER(c_int)`)**:每个网格面的边索引。
- **`face_nodes`(`POINTER(c_int)`)**:组成每个二维网格面的节点。
- **`nodes_per_face`(`POINTER(c_int)`)**:组成每个二维网格面的节点。(原说明如此;实际字段表示每个面的节点数。)
- **`node_x`(`POINTER(c_double)`)**:节点的 x 坐标。
- **`node_y`(`POINTER(c_double)`)**:节点的 y 坐标。
- **`edge_x`(`POINTER(c_double)`)**:网格边中点的 x 坐标。
- **`edge_y`(`POINTER(c_double)`)**:网格边中点的 y 坐标。(原文误写为 x 坐标。)
- **`face_x`(`POINTER(c_double)`)**:网格面质心的 x 坐标。
- **`face_y`(`POINTER(c_double)`)**:网格面质心的 y 坐标。
- **`num_nodes`(`c_int`)**:网格节点数。
- **`num_valid_nodes`(`c_int`)**:有效一维节点数。
- **`num_edges`(`c_int`)**:边数。
- **`num_valid_edges`(`c_int`)**:有效边数。
- **`num_faces`(`c_int`)**:网格面数。
- **`num_face_nodes`(`c_int`)**:组成所有二维网格面的节点总数。
**C 结构体字段(按源码顺序)**
| 字段 | C 类型 |
| --- | --- |
| `edge_faces` | `POINTER(c_int)` |
| `edge_nodes` | `POINTER(c_int)` |
| `face_edges` | `POINTER(c_int)` |
| `face_nodes` | `POINTER(c_int)` |
| `nodes_per_face` | `POINTER(c_int)` |
| `node_x` | `POINTER(c_double)` |
| `node_y` | `POINTER(c_double)` |
| `edge_x` | `POINTER(c_double)` |
| `edge_y` | `POINTER(c_double)` |
| `face_x` | `POINTER(c_double)` |
| `face_y` | `POINTER(c_double)` |
| `num_nodes` | `c_int` |
| `num_valid_nodes` | `c_int` |
| `num_edges` | `c_int` |
| `num_valid_edges` | `c_int` |
| `num_faces` | `c_int` |
| `num_face_nodes` | `c_int` |
**方法索引**
- [`from_mesh2d`](#cmesh2d-from-mesh2d)
- [`allocate_memory`](#cmesh2d-allocate-memory)
### `CMesh2d.from_mesh2d` {#cmesh2d-from-mesh2d}
```python
from_mesh2d(mesh2d: Mesh2d) -> CMesh2d
```
修饰器:`staticmethod`。
根据给定的 Mesh2d 实例创建新的 CMesh 实例。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `mesh2d` | `Mesh2d` | `必填` | 持有状态的 NumPy 数组封装对象。 |
**返回值**
- **`CMesh2d`**:创建的 CMesh2d 实例。
### `CMesh2d.allocate_memory` {#cmesh2d-allocate-memory}
```python
allocate_memory(self) -> Mesh2d
```
根据名称以 `num_` 开头的参数分配数据内存。 随后将指针指向新分配的内存。 内存由此方法返回的 Mesh2d 实例持有。
**返回值**
- **`Mesh2d`**:持有已分配内存的对象。
## `CGeometryList` {#cgeometrylist}
继承:`Structure`。
仅供内部使用的 C 数据结构。 表示 MeshKernel API 定义的 GeometryList 结构体。
用于与 MeshKernel 动态链接库通信。
该类的 `_fields_` 属性包含以下字段:
- **`geometry_separator`(`c_double`)**:坐标数组中的几何分隔值。
- **`inner_outer_separator`(`c_double`)**:用于分隔多边形内边界和外边界的值。
- **`n_coordinates`(`c_int`)**:坐标值的数量。
- **`x_coordinates`(`POINTER(c_double)`)**:x 坐标。
- **`y_coordinates`(`POINTER(c_double)`)**:y 坐标。
- **`values`(`POINTER(c_double)`)**:二维网格上的数值。
**C 结构体字段(按源码顺序)**
| 字段 | C 类型 |
| --- | --- |
| `geometry_separator` | `c_double` |
| `inner_outer_separator` | `c_double` |
| `n_coordinates` | `c_int` |
| `x_coordinates` | `POINTER(c_double)` |
| `y_coordinates` | `POINTER(c_double)` |
| `values` | `POINTER(c_double)` |
**方法索引**
- [`from_geometrylist`](#cgeometrylist-from-geometrylist)
### `CGeometryList.from_geometrylist` {#cgeometrylist-from-geometrylist}
```python
from_geometrylist(geometry_list: GeometryList) -> CGeometryList
```
修饰器:`staticmethod`。
根据给定的 GeometryList 实例创建新的 `CGeometryList` 实例。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `geometry_list` | `GeometryList` | `必填` | 几何列表。 |
**返回值**
- **`CGeometryList`**:为给定 GeometryList 创建的 C 数据结构。
## `CInterpolationParameters` {#cinterpolationparameters}
继承:`Structure`。
仅供内部使用的 C 数据结构。 表示采样数据插值所用的参数。
用于与 MeshKernel 动态链接库通信。
该类的 `_fields_` 属性包含以下字段:
- **`interpolation_type`(`c_int`)**:默认使用采样数据平均插值。
- **`method`(`c_int`)**:使用的平均方法。
- **`absolute_search_radius`(`c_double`)**:绝对搜索半径。
- **`relative_search_radius`(`c_double`)**:相对搜索半径。
- **`use_closest_if_none_found`(`c_bool`)**:如果多边形内未找到采样点,则使用最近的点。
- **`minimum_number_of_samples`(`c_int`)**:某些平均方法所需的最少采样点数。
**C 结构体字段(按源码顺序)**
| 字段 | C 类型 |
| --- | --- |
| `interpolation_type` | `c_int` |
| `method` | `c_int` |
| `absolute_search_radius` | `c_double` |
| `relative_search_radius` | `c_double` |
| `use_closest_if_none_found` | `c_bool` |
| `minimum_number_of_samples` | `c_int` |
**方法索引**
- [`from_interpolationparameters`](#cinterpolationparameters-from-interpolationparameters)
### `CInterpolationParameters.from_interpolationparameters` {#cinterpolationparameters-from-interpolationparameters}
```python
from_interpolationparameters(interpolation_parameters: InterpolationParameters) -> CInterpolationParameters
```
修饰器:`staticmethod`。
根据给定的 InterpolationParameters 实例创建新的 `CInterpolationParameters` 实例。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `interpolation_parameters` | `InterpolationParameters` | `必填` | 插值参数。 |
**返回值**
- **`CInterpolationParameters`**:为给定 InterpolationParameters 创建的 C 数据结构。
## `COrthogonalizationParameters` {#corthogonalizationparameters}
继承:`Structure`。
仅供内部使用的 C 数据结构。 表示 MeshKernel API 定义的 OrthogonalizationParameters 结构体。
用于与 MeshKernel 动态链接库通信。
该类的 `_fields_` 属性包含以下字段:
- **`outer_iterations`(`c_int`)**:正交化的外层迭代次数。
- **`boundary_iterations`(`c_int`)**:网格正交化过程中 itatp 内的边界迭代次数。
- **`inner_iterations`(`c_int`)**:网格正交化过程中 itbnd 内的内部迭代次数。
- **`orthogonalization_to_smoothing_factor`(`c_double`)**:控制网格平滑(0)与网格正交化(1)之间权重的系数。
- **`orthogonalization_to_smoothing_factor_at_boundary`(`c_double`)**:边界上的最小 ATPF 值。
- **`areal_to_angle_smoothing_factor`(`c_double`)**:在平滑器(1.0)与面积均匀化(0.0)之间调节的系数。
**C 结构体字段(按源码顺序)**
| 字段 | C 类型 |
| --- | --- |
| `outer_iterations` | `c_int` |
| `boundary_iterations` | `c_int` |
| `inner_iterations` | `c_int` |
| `orthogonalization_to_smoothing_factor` | `c_double` |
| `orthogonalization_to_smoothing_factor_at_boundary` | `c_double` |
| `areal_to_angle_smoothing_factor` | `c_double` |
**方法索引**
- [`from_orthogonalizationparameters`](#corthogonalizationparameters-from-orthogonalizationparameters)
### `COrthogonalizationParameters.from_orthogonalizationparameters` {#corthogonalizationparameters-from-orthogonalizationparameters}
```python
from_orthogonalizationparameters(orthogonalization_parameters: OrthogonalizationParameters) -> COrthogonalizationParameters
```
修饰器:`staticmethod`。
根据给定的 OrthogonalizationParameters 实例创建新的 `COrthogonalizationParameters` 实例。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `orthogonalization_parameters` | `OrthogonalizationParameters` | `必填` | 正交化参数。 |
**返回值**
- **`COrthogonalizationParameters`**:为给定 OrthogonalizationParameters 创建的 C 数据结构。
## `CMeshRefinementParameters` {#cmeshrefinementparameters}
继承:`Structure`。
仅供内部使用的 C 数据结构。 表示 MeshKernel API 定义的 MeshRefinementParameters 结构体。
用于与 MeshKernel 动态链接库通信。
该类的 `_fields_` 属性包含以下字段:
- **`max_refinement_iterations`(`c_int`)**:最大加密迭代次数。
- **`refine_intersected`(`c_int`)**:是否处理与多边形相交的网格面(1 为是,0 为否)。
- **`use_mass_center_when_refining`(`c_int`)**:加密过程中划分网格面时是否使用质心(1 为是,0 为否)。
- **`min_edge_size`(`c_double`)**:最小网格单元尺寸。
- **`refinement_type`(`c_int`)**:加密判据类型。
- **`connect_hanging_nodes`(`c_int`)**:是否在迭代结束时连接悬挂节点。
- **`account_for_samples_outside`(`c_int`)**:是否考虑网格面外的采样数据。
**C 结构体字段(按源码顺序)**
| 字段 | C 类型 |
| --- | --- |
| `max_refinement_iterations` | `c_int` |
| `refine_intersected` | `c_int` |
| `use_mass_center_when_refining` | `c_int` |
| `min_edge_size` | `c_double` |
| `refinement_type` | `c_int` |
| `connect_hanging_nodes` | `c_int` |
| `account_for_samples_outside_face` | `c_int` |
| `smoothing_iterations` | `c_int` |
| `max_courant_time` | `c_double` |
| `directional_refinement` | `c_int` |
**方法索引**
- [`from_meshrefinementparameters`](#cmeshrefinementparameters-from-meshrefinementparameters)
### `CMeshRefinementParameters.from_meshrefinementparameters` {#cmeshrefinementparameters-from-meshrefinementparameters}
```python
from_meshrefinementparameters(mesh_refinement_parameters: MeshRefinementParameters) -> CMeshRefinementParameters
```
修饰器:`staticmethod`。
根据给定的 MeshRefinementParameters 实例创建新的 `CMeshRefinementParameters` 实例。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `mesh_refinement_parameters` | `MeshRefinementParameters` | `必填` | 网格加密参数。 |
**返回值**
- **`CMeshRefinementParameters`**:为给定 MeshRefinementParameters 创建的 C 数据结构。
## `CMakeGridParameters` {#cmakegridparameters}
继承:`Structure`。
仅供内部使用的 C 数据结构。 表示 MeshKernel API 定义的 MakeGridParameters 结构体。
用于与 MeshKernel 动态链接库通信。
该类的 `_fields_` 属性包含以下字段:
- **`num_columns`(`c_int`)**:x 方向的列数。
- **`num_rows`(`c_int`)**:y 方向的行数。(原文称为列数。)
- **`angle`(`c_double`)**:网格角度。
- **`origin_x`(`c_double`)**:左下角原点的 x 坐标。
- **`origin_y`(`c_double`)**:左下角原点的 y 坐标。
- **`block_size_x`(`c_double`)**:x 方向的网格块尺寸,仅用于方形网格。
- **`block_size_y`(`c_double`)**:y 方向的网格块尺寸,仅用于方形网格。
- **`upper_right_x`(`c_double`)**:右上角的 x 坐标。
- **`upper_right_y`(`c_double`)**:右上角的 y 坐标。
**C 结构体字段(按源码顺序)**
| 字段 | C 类型 |
| --- | --- |
| `num_columns` | `c_int` |
| `num_rows` | `c_int` |
| `angle` | `c_double` |
| `origin_x` | `c_double` |
| `origin_y` | `c_double` |
| `block_size_x` | `c_double` |
| `block_size_y` | `c_double` |
| `upper_right_x` | `c_double` |
| `upper_right_y` | `c_double` |
**方法索引**
- [`from_makegridparameters`](#cmakegridparameters-from-makegridparameters)
### `CMakeGridParameters.from_makegridparameters` {#cmakegridparameters-from-makegridparameters}
```python
from_makegridparameters(make_grid_parameters: MakeGridParameters) -> CMakeGridParameters
```
修饰器:`staticmethod`。
根据给定的 MeshRefinementParameters 实例创建新的 `CMeshRefinementParameters` 实例。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `make_grid_parameters` | `MakeGridParameters` | `必填` | 网格生成参数。 |
**返回值**
- **`CMakeGridParameters`**:为给定 MakeGridParameters 创建的 C 数据结构。
## `CMesh1d` {#cmesh1d}
继承:`Structure`。
仅供内部使用的 C 数据结构。 表示 MeshKernel API 定义的 Mesh1D 结构体。
用于与 MeshKernel 动态链接库通信。
该类的 `_fields_` 属性包含以下字段:
- **`edge_nodes`(`POINTER(c_int)`)**:组成每条一维网格边的节点。
- **`node_x`(`POINTER(c_double)`)**:节点的 x 坐标。
- **`node_y`(`POINTER(c_double)`)**:节点的 y 坐标。
- **`num_nodes`(`c_int`)**:节点数。
- **`num_valid_nodes`(`c_int`)**:有效网格节点数。
- **`num_edges`(`c_int`)**:边数。
- **`num_valid_edges`(`c_int`)**:有效边数。
**C 结构体字段(按源码顺序)**
| 字段 | C 类型 |
| --- | --- |
| `edge_nodes` | `POINTER(c_int)` |
| `node_x` | `POINTER(c_double)` |
| `node_y` | `POINTER(c_double)` |
| `num_nodes` | `c_int` |
| `num_valid_nodes` | `c_int` |
| `num_edges` | `c_int` |
| `num_valid_edges` | `c_int` |
**方法索引**
- [`from_mesh1d`](#cmesh1d-from-mesh1d)
- [`allocate_memory`](#cmesh1d-allocate-memory)
### `CMesh1d.from_mesh1d` {#cmesh1d-from-mesh1d}
```python
from_mesh1d(mesh1d: Mesh1d) -> CMesh1d
```
修饰器:`staticmethod`。
根据给定的 Mesh1d 实例创建新的 CMesh 实例。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `mesh1d` | `Mesh1d` | `必填` | 持有状态的 NumPy 数组封装对象。 |
**返回值**
- **`CMesh1d`**:创建的 CMesh1d 实例。
### `CMesh1d.allocate_memory` {#cmesh1d-allocate-memory}
```python
allocate_memory(self) -> Mesh1d
```
根据名称以 `num_` 开头的参数分配数据内存。 随后将指针指向新分配的内存。 内存由此方法返回的 Mesh1d 实例持有。
**返回值**
- **`Mesh1d`**:持有已分配内存的对象。
## `CContacts` {#ccontacts}
继承:`Structure`。
仅供内部使用的 C 数据结构。 表示 MeshKernel API 定义的 Contacts 结构体。
用于与 MeshKernel 动态链接库通信。
该类的 `_fields_` 属性包含以下字段:
- **`mesh1d_indices`(`POINTER(c_int)`)**:一维网格节点的索引。
- **`mesh2d_indices`(`POINTER(c_int)`)**:二维网格面的索引。
- **`num_contacts`(`c_int`)**:连接数。
**C 结构体字段(按源码顺序)**
| 字段 | C 类型 |
| --- | --- |
| `mesh1d_indices` | `POINTER(c_int)` |
| `mesh2d_indices` | `POINTER(c_int)` |
| `num_contacts` | `c_int` |
**方法索引**
- [`from_contacts`](#ccontacts-from-contacts)
- [`allocate_memory`](#ccontacts-allocate-memory)
### `CContacts.from_contacts` {#ccontacts-from-contacts}
```python
from_contacts(contacts: Contacts) -> CContacts
```
修饰器:`staticmethod`。
根据给定的 Contacts 实例创建新的 `CContacts` 实例。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `contacts` | `Contacts` | `必填` | 网格连接。 |
**返回值**
- **`CContacts`**:为给定 Contacts 创建的 C 数据结构。
### `CContacts.allocate_memory` {#ccontacts-allocate-memory}
```python
allocate_memory(self) -> Contacts
```
根据名称以 `num_` 开头的参数分配数据内存。 随后将指针指向新分配的内存。 内存由此方法返回的 Contacts 实例持有。
**返回值**
- **`Contacts`**:持有已分配内存的对象。
## `CCurvilinearGrid` {#ccurvilineargrid}
继承:`Structure`。
仅供内部使用的 C 数据结构。 表示 MeshKernel API 定义的 Curvilinear 结构体。
用于与 MeshKernel 动态链接库通信。
该类的 `_fields_` 属性包含以下字段:
- **`node_x`(`POINTER(c_double)`)**:节点的 x 坐标。
- **`node_y`(`POINTER(c_double)`)**:节点的 y 坐标。
- **`num_m`(`c_int`)**:沿 m 方向的曲线网格节点数。
- **`num_n`(`c_int`)**:沿 n 方向的曲线网格节点数。
**C 结构体字段(按源码顺序)**
| 字段 | C 类型 |
| --- | --- |
| `node_x` | `POINTER(c_double)` |
| `node_y` | `POINTER(c_double)` |
| `num_m` | `c_int` |
| `num_n` | `c_int` |
**方法索引**
- [`from_curvilinearGrid`](#ccurvilineargrid-from-curvilineargrid)
- [`allocate_memory`](#ccurvilineargrid-allocate-memory)
### `CCurvilinearGrid.from_curvilinearGrid` {#ccurvilineargrid-from-curvilineargrid}
```python
from_curvilinearGrid(curvilinear_grid: CurvilinearGrid) -> CCurvilinearGrid
```
修饰器:`staticmethod`。
根据给定的 CurvilinearGrid 实例创建新的 CMesh 实例。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `curvilinear_grid` | `CurvilinearGrid` | `必填` | 持有状态的 NumPy 数组封装对象。 |
**返回值**
- **`CCurvilinearGrid`**:创建的 CCurvilinearGrid 实例。
### `CCurvilinearGrid.allocate_memory` {#ccurvilineargrid-allocate-memory}
```python
allocate_memory(self) -> CurvilinearGrid
```
根据名称以 `num_` 开头的参数分配数据内存。 随后将指针指向新分配的内存。 内存由此方法返回的 CurvilinearGrid 实例持有。
**返回值**
- **`CurvilinearGrid`**:持有已分配内存的对象。
## `CCurvilinearParameters` {#ccurvilinearparameters}
继承:`Structure`。
仅供内部使用的 C 数据结构。 表示 MeshKernel API 定义的 CurvilinearParameters 结构体。
用于与 MeshKernel 动态链接库通信。
该类的 `_fields_` 属性包含以下字段:
- **`m_refinement`(`c_int`)**:生成规则网格时的 m 方向加密系数。
- **`n_refinement`(`c_int`)**:生成规则网格时的 n 方向加密系数。
- **`smoothing_iterations`(`c_int`)**:规则网格平滑的内部迭代次数。
- **`smoothing_parameter`(`c_double`)**:平滑参数。
- **`attraction_parameter`(`c_double`)**:吸引/排斥参数。
**C 结构体字段(按源码顺序)**
| 字段 | C 类型 |
| --- | --- |
| `m_refinement` | `c_int` |
| `n_refinement` | `c_int` |
| `smoothing_iterations` | `c_int` |
| `smoothing_parameter` | `c_double` |
| `attraction_parameter` | `c_double` |
**方法索引**
- [`from_curvilinearParameters`](#ccurvilinearparameters-from-curvilinearparameters)
### `CCurvilinearParameters.from_curvilinearParameters` {#ccurvilinearparameters-from-curvilinearparameters}
```python
from_curvilinearParameters(curvilinear_parameters: CurvilinearParameters) -> CCurvilinearParameters
```
修饰器:`staticmethod`。
根据给定的 CurvilinearParameters 实例创建新的 `CCurvilinearParameters` 实例。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `curvilinear_parameters` | `CurvilinearParameters` | `必填` | 曲线网格参数。 |
**返回值**
- **`CCurvilinearParameters`**:为给定 CurvilinearParameters 创建的 C 数据结构。
## `CSplinesToCurvilinearParameters` {#csplinestocurvilinearparameters}
继承:`Structure`。
仅供内部使用的 C 数据结构。 表示 MeshKernel API 定义的 SplinesToCurvilinearParameters 结构体。
用于与 MeshKernel 动态链接库通信。
该类的 `_fields_` 属性包含以下字段:
- **`aspect_ratio`(`c_double`)**:纵横比。
- **`aspect_ratio_grow_factor`(`c_double`)**:纵横比增长系数。
- **`average_width`(`c_double`)**:中心样条曲线上的平均网格宽度。
- **`curvature_adapted_grid_spacing`(`c_int`)**:随曲率调整的网格间距。
- **`grow_grid_outside`(`c_int`)**:是否在指定网格高度之外扩展网格。
- **`maximum_num_faces_in_uniform_part`(`c_int`)**:均匀部分的最大层数。
- **`nodes_on_top_of_each_other_tolerance`(`c_double`)**:节点重合判定容差。
- **`min_cosine_crossing_angles`(`c_double`)**:交叉角余弦绝对值允许的最小值。
- **`check_front_collisions`(`c_int`)**:是否检查与前沿其他部分的碰撞。
- **`remove_skinny_triangles`(`c_int`)**:是否检查与前沿其他部分的碰撞。(源说明与上一字段重复;字段名称表示移除细长三角形。)
**C 结构体字段(按源码顺序)**
| 字段 | C 类型 |
| --- | --- |
| `aspect_ratio` | `c_double` |
| `aspect_ratio_grow_factor` | `c_double` |
| `average_width` | `c_double` |
| `curvature_adapted_grid_spacing` | `c_int` |
| `grow_grid_outside` | `c_int` |
| `maximum_num_faces_in_uniform_part` | `c_int` |
| `nodes_on_top_of_each_other_tolerance` | `c_double` |
| `min_cosine_crossing_angles` | `c_double` |
| `check_front_collisions` | `c_int` |
| `remove_skinny_triangles` | `c_int` |
**方法索引**
- [`from_splinesToCurvilinearParameters`](#csplinestocurvilinearparameters-from-splinestocurvilinearparameters)
### `CSplinesToCurvilinearParameters.from_splinesToCurvilinearParameters` {#csplinestocurvilinearparameters-from-splinestocurvilinearparameters}
```python
from_splinesToCurvilinearParameters(splines_to_curvilinear_parameters: SplinesToCurvilinearParameters) -> CSplinesToCurvilinearParameters
```
修饰器:`staticmethod`。
根据给定的 OrthogonalizationParameters 实例创建新的 `COrthogonalizationParameters` 实例。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `splines_to_curvilinear_parameters` | `SplinesToCurvilinearParameters` | `必填` | 源码未单独提供参数说明。 |
原文还列出了以下参数说明(名称可能与当前签名不一致):
- **`orthogonalization_parameters`(`OrthogonalizationParameters`)**:正交化参数。
**返回值**
- **`COrthogonalizationParameters`**:为给定 OrthogonalizationParameters 创建的 C 数据结构。
## `CGriddedSamples` {#cgriddedsamples}
继承:`Structure`。
仅供内部使用的 C 数据结构。 表示 MeshKernel API 定义的 GriddedSamples 结构体。
用于与 MeshKernel 动态链接库通信。
该类的 `_fields_` 属性包含以下字段:
- **`num_x`(`c_int`)**:网格采样数据在 x 方向上的坐标数。
- **`num_y`(`c_int`)**:网格采样数据在 y 方向上的坐标数。
- **`x_origin`(`c_double`)**:采样网格原点的 x 坐标。
- **`y_origin`(`c_double`)**:采样网格原点的 y 坐标。
- **`cell_size`(`c_int`)**:固定的采样网格单元尺寸。
- **`x_coordinates`(`POINTER(c_double)`)**:若不为 nullptr,则指定 x 方向非均匀网格间距对应的坐标。
- **`y_coordinates`(`POINTER(c_double)`)**:若不为 nullptr,则指定 y 方向非均匀网格间距对应的坐标。
- **`values`(`POINTER(c_double)`)**:采样值。
**C 结构体字段(按源码顺序)**
| 字段 | C 类型 |
| --- | --- |
| `num_x` | `c_int` |
| `num_y` | `c_int` |
| `x_origin` | `c_double` |
| `y_origin` | `c_double` |
| `cell_size` | `c_double` |
| `x_coordinates` | `POINTER(c_double)` |
| `y_coordinates` | `POINTER(c_double)` |
| `values` | `c_void_p` |
| `value_type` | `c_int` |
**方法索引**
- [`from_griddedSamples`](#cgriddedsamples-from-griddedsamples)
### `CGriddedSamples.from_griddedSamples` {#cgriddedsamples-from-griddedsamples}
```python
from_griddedSamples(gridded_samples: GriddedSamples) -> CGriddedSamples
```
修饰器:`staticmethod`。
根据给定的 GriddedSamples 实例创建新的 `CGriddedSamples` 实例。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `gridded_samples` | `GriddedSamples` | `必填` | 网格采样数据。 |
**返回值**
- **`CGriddedSamples`**:为给定 CGriddedSamples 创建的 C 数据结构。
+91
View File
@@ -0,0 +1,91 @@
# 异常类型
模块:`meshkernel.errors`。本页依据本地 MeshKernelPy `8.3.0` 源码生成,包含该模块定义的类、方法、函数和常量。签名及参数默认值以源码为准;原文未提供的说明会明确标记。
[返回 API 总览](modules.md)
## `Error` {#error}
继承:`Exception`。
本模块中所有异常的基类。
## `InputError` {#inputerror}
继承:`Error`。
输入发生错误时抛出的异常。
## `MeshKernelError` {#meshkernelerror}
继承:`Error`。
MeshKernel 库发生错误时抛出的异常。
**方法索引**
- [`__init__`](#meshkernelerror---init--)
### `MeshKernelError.__init__` {#meshkernelerror---init--}
```python
__init__(self, category: str, message: str)
```
构造实例。源码没有单独编写此构造函数的文档字符串,参数及默认值如下。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `category` | `str` | `必填` | 源码未单独提供参数说明。 |
| `message` | `str` | `必填` | 源码未单独提供参数说明。 |
## `MeshGeometryError` {#meshgeometryerror}
继承:`MeshKernelError`。
MeshKernel 库发生网格几何错误时抛出的异常。
**方法索引**
- [`__init__`](#meshgeometryerror---init--)
- [`index`](#meshgeometryerror-index)
- [`location`](#meshgeometryerror-location)
### `MeshGeometryError.__init__` {#meshgeometryerror---init--}
```python
__init__(self, message: str, info: Tuple[int, mps.Mesh2dLocation])
```
构造实例。源码没有单独编写此构造函数的文档字符串,参数及默认值如下。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `message` | `str` | `必填` | 源码未单独提供参数说明。 |
| `info` | `Tuple[int, mps.Mesh2dLocation]` | `必填` | 源码未单独提供参数说明。 |
### `MeshGeometryError.index` {#meshgeometryerror-index}
```python
index(self) -> int
```
返回几何错误信息中的索引 `info[0]`。
**返回类型**:`int`。源码未单独说明返回值。
### `MeshGeometryError.location` {#meshgeometryerror-location}
```python
location(self) -> mps.Mesh2dLocation
```
返回几何错误信息中的位置类型 `info[1]`。
**返回类型**:`mps.Mesh2dLocation`。源码未单独说明返回值。
+33
View File
@@ -0,0 +1,33 @@
# meshkernel 包与导出接口
本页列出 `meshkernel/__init__.py` 显式导出的接口,可直接使用 `from meshkernel import 名称` 导入。未在包顶层导出的类或函数仍可在对应模块页面查阅。
| 导出名称 | 定义模块 |
| --- | --- |
| [`InputError`](meshkernel.errors.md#inputerror) | `meshkernel.errors` |
| [`MeshKernelError`](meshkernel.errors.md#meshkernelerror) | `meshkernel.errors` |
| [`MeshKernel`](meshkernel.meshkernel.md#meshkernel) | `meshkernel.meshkernel` |
| [`AveragingMethod`](meshkernel.py_structures.md#averagingmethod) | `meshkernel.py_structures` |
| [`Contacts`](meshkernel.py_structures.md#contacts) | `meshkernel.py_structures` |
| [`CurvilinearGrid`](meshkernel.py_structures.md#curvilineargrid) | `meshkernel.py_structures` |
| [`CurvilinearParameters`](meshkernel.py_structures.md#curvilinearparameters) | `meshkernel.py_structures` |
| [`DeleteMeshOption`](meshkernel.py_structures.md#deletemeshoption) | `meshkernel.py_structures` |
| [`GeometryList`](meshkernel.py_structures.md#geometrylist) | `meshkernel.py_structures` |
| [`GriddedSamples`](meshkernel.py_structures.md#griddedsamples) | `meshkernel.py_structures` |
| [`InterpolationParameters`](meshkernel.py_structures.md#interpolationparameters) | `meshkernel.py_structures` |
| [`InterpolationType`](meshkernel.py_structures.md#interpolationtype) | `meshkernel.py_structures` |
| [`InterpolationValues`](meshkernel.py_structures.md#interpolationvalues) | `meshkernel.py_structures` |
| [`MakeGridParameters`](meshkernel.py_structures.md#makegridparameters) | `meshkernel.py_structures` |
| [`Mesh1d`](meshkernel.py_structures.md#mesh1d) | `meshkernel.py_structures` |
| [`Mesh2d`](meshkernel.py_structures.md#mesh2d) | `meshkernel.py_structures` |
| [`Mesh2dLocation`](meshkernel.py_structures.md#mesh2dlocation) | `meshkernel.py_structures` |
| [`Mesh2dProperty`](meshkernel.py_structures.md#mesh2dproperty) | `meshkernel.py_structures` |
| [`MeshRefinementParameters`](meshkernel.py_structures.md#meshrefinementparameters) | `meshkernel.py_structures` |
| [`OrthogonalizationParameters`](meshkernel.py_structures.md#orthogonalizationparameters) | `meshkernel.py_structures` |
| [`ProjectionType`](meshkernel.py_structures.md#projectiontype) | `meshkernel.py_structures` |
| [`ProjectToLandBoundaryOption`](meshkernel.py_structures.md#projecttolandboundaryoption) | `meshkernel.py_structures` |
| [`RefinementType`](meshkernel.py_structures.md#refinementtype) | `meshkernel.py_structures` |
| [`SplinesToCurvilinearParameters`](meshkernel.py_structures.md#splinestocurvilinearparameters) | `meshkernel.py_structures` |
| [`__version__`](meshkernel.version.md#--version--) | `meshkernel.version` |
[返回 API 总览](modules.md)
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,879 @@
# Python 数据结构与枚举
模块:`meshkernel.py_structures`。本页依据本地 MeshKernelPy `8.3.0` 源码生成,包含该模块定义的类、方法、函数和常量。签名及参数默认值以源码为准;原文未提供的说明会明确标记。
[返回 API 总览](modules.md)
## `DeleteMeshOption` {#deletemeshoption}
继承:`IntEnum`。
删除多边形内部网格时使用的策略。
**枚举成员**
| 名称 | 值 | 中文说明 |
| --- | --- | --- |
| `INSIDE_NOT_INTERSECTED` | `0` | 删除位于多边形内部、未与边界相交的网格。 |
| `INSIDE_AND_INTERSECTED` | `1` | 删除位于多边形内部及与边界相交的网格。 |
| `FACES_WITH_INCLUDED_CIRCUMCENTERS` | `2` | 删除外心位于多边形内部的网格面。 |
## `ProjectToLandBoundaryOption` {#projecttolandboundaryoption}
继承:`IntEnum`。
投影到陆地边界的策略。
**枚举成员**
| 名称 | 值 | 中文说明 |
| --- | --- | --- |
| `DO_NOT_PROJECT_TO_LANDBOUNDARY` | `0` | 不投影到陆地边界。 |
| `TO_ORIGINAL_NETBOUNDARY` | `1` | 投影到原始网格边界。 |
| `OUTER_MESH_BOUNDARY_TO_LANDBOUNDARY` | `2` | 将网格外边界投影到陆地边界。 |
| `INNER_AND_OUTER_MESH_BOUNDARY_TO_LANDBOUNDARY` | `3` | 将网格内外边界投影到陆地边界。 |
| `WHOLE_MESH` | `4` | 处理整个网格。 |
## `RefinementType` {#refinementtype}
继承:`IntEnum`。
加密类型。
**枚举成员**
| 名称 | 值 | 中文说明 |
| --- | --- | --- |
| `WAVE_COURANT` | `1` | 根据采样水深加密,使库朗数判据不被超过。 |
| `REFINEMENT_LEVELS` | `2` | 递归加密指定的固定次数。 |
| `RIDGE_DETECTION` | `3` | 基于脊线检测进行加密。 |
## `Mesh2dLocation` {#mesh2dlocation}
继承:`IntEnum`。
二维网格位置类型。
**枚举成员**
| 名称 | 值 | 中文说明 |
| --- | --- | --- |
| `FACES` | `0` | 网格面。 |
| `NODES` | `1` | 节点。 |
| `EDGES` | `2` | 网格边。 |
## `Mesh2dProperty` {#mesh2dproperty}
继承:`IntEnum`。
二维网格上的不同属性。
**枚举成员**
| 名称 | 值 | 中文说明 |
| --- | --- | --- |
| `ORTHOGONALITY` | `0` | 正交性。 |
| `EDGE_LENGTHS` | `1` | 边长。 |
| `FACE_CIRCUMCENTER` | `2` | 网格面外心。 |
| `NETLINK_CONTOUR_POLYGON` | `3` | 网格连接的轮廓多边形。 |
| `FACE_BOUNDS` | `4` | 网格面边界。 |
| `SMOOTHNESS` | `5` | 平滑性。 |
## `AveragingMethod` {#averagingmethod}
继承:`IntEnum`。
平均方法。
**枚举成员**
| 名称 | 值 | 中文说明 |
| --- | --- | --- |
| `SIMPLE_AVERAGING` | `1` | 计算简单算术平均值。 |
| `CLOSEST_POINT` | `2` | 取距离插值位置最近的采样点的值。 |
| `MAX` | `3` | 取采样值的最大值。 |
| `MIN` | `4` | 取采样值的最小值。 |
| `INVERSE_WEIGHT_DISTANCE` | `5` | 计算反距离加权平均值。 |
| `MIN_ABS` | `6` | 取最小绝对值。 |
## `ProjectionType` {#projectiontype}
继承:`IntEnum`。
投影类型。
**枚举成员**
| 名称 | 值 | 中文说明 |
| --- | --- | --- |
| `CARTESIAN` | `0` | 笛卡尔坐标投影。 |
| `SPHERICAL` | `1` | 球面坐标投影。 |
| `SPHERICALACCURATE` | `2` | 高精度球面坐标投影。 |
## `InterpolationValues` {#interpolationvalues}
继承:`IntEnum`。
网格采样数据中待插值数值的可选类型。
**枚举成员**
| 名称 | 值 | 中文说明 |
| --- | --- | --- |
| `SHORT` | `0` | 短整数类型。 |
| `FLOAT` | `1` | 单精度浮点类型。 |
| `INT` | `2` | 整数类型。 |
| `DOUBLE` | `3` | 双精度浮点类型。 |
## `InterpolationType` {#interpolationtype}
继承:`IntEnum`。
点云插值类型。
**枚举成员**
| 名称 | 值 | 中文说明 |
| --- | --- | --- |
| `TRIANGULATION` | `0` | 三角剖分插值。 |
| `AVERAGING` | `1` | 平均插值。 |
## `Mesh2d` {#mesh2d}
继承:`object`。
此类用于获取和设置二维网格数据。
**属性说明**
- **`node_x`(`ndarray`)**:描述节点 x 坐标的一维双精度数组。
- **`node_y`(`ndarray`)**:描述节点 y 坐标的一维双精度数组。
- **`edge_nodes`(`ndarray, 可选`)**:描述每条二维网格边端点节点的一维整数数组。
- **`face_nodes`(`ndarray, 可选`)**:描述组成每个二维网格面的节点的一维整数数组。
- **`nodes_per_face`(`ndarray, 可选`)**:描述组成每个二维网格面的节点的一维整数数组。(原文如此;实际为每个面的节点数。)
- **`edge_x`(`ndarray, 可选`)**:描述网格边中点 x 坐标的一维双精度数组。
- **`edge_y`(`ndarray, 可选`)**:描述网格边中点 y 坐标的一维双精度数组。
- **`face_x`(`ndarray, 可选`)**:描述网格面质心 x 坐标的一维双精度数组。
- **`face_y`(`ndarray, 可选`)**:描述网格面质心 y 坐标的一维双精度数组。
- **`edge_faces`(`ndarray, 可选`)**:描述每条边关联的网格面索引的一维整数数组。
- **`face_edges`(`ndarray, 可选`)**:描述每个网格面关联的边索引的一维整数数组。
**方法索引**
- [`__init__`](#mesh2d---init--)
- [`remove_invalid_values`](#mesh2d-remove-invalid-values)
- [`__eq__`](#mesh2d---eq--)
- [`almost_equal`](#mesh2d-almost-equal)
- [`plot_edges`](#mesh2d-plot-edges)
- [`plot_faces`](#mesh2d-plot-faces)
### `Mesh2d.__init__` {#mesh2d---init--}
```python
__init__(self, node_x=np.empty(0, dtype=np.double), node_y=np.empty(0, dtype=np.double), edge_nodes=np.empty(0, dtype=np.int32), face_nodes=np.empty(0, dtype=np.int32), nodes_per_face=np.empty(0, dtype=np.int32), edge_x=np.empty(0, dtype=np.double), edge_y=np.empty(0, dtype=np.double), face_x=np.empty(0, dtype=np.double), face_y=np.empty(0, dtype=np.double), edge_faces=np.empty(0, dtype=np.int32), face_edges=np.empty(0, dtype=np.int32))
```
构造实例。源码没有单独编写此构造函数的文档字符串,参数及默认值如下。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `node_x` | `未标注` | `np.empty(0, dtype=np.double)` | 源码未单独提供参数说明。 |
| `node_y` | `未标注` | `np.empty(0, dtype=np.double)` | 源码未单独提供参数说明。 |
| `edge_nodes` | `未标注` | `np.empty(0, dtype=np.int32)` | 源码未单独提供参数说明。 |
| `face_nodes` | `未标注` | `np.empty(0, dtype=np.int32)` | 源码未单独提供参数说明。 |
| `nodes_per_face` | `未标注` | `np.empty(0, dtype=np.int32)` | 源码未单独提供参数说明。 |
| `edge_x` | `未标注` | `np.empty(0, dtype=np.double)` | 源码未单独提供参数说明。 |
| `edge_y` | `未标注` | `np.empty(0, dtype=np.double)` | 源码未单独提供参数说明。 |
| `face_x` | `未标注` | `np.empty(0, dtype=np.double)` | 源码未单独提供参数说明。 |
| `face_y` | `未标注` | `np.empty(0, dtype=np.double)` | 源码未单独提供参数说明。 |
| `edge_faces` | `未标注` | `np.empty(0, dtype=np.int32)` | 源码未单独提供参数说明。 |
| `face_edges` | `未标注` | `np.empty(0, dtype=np.int32)` | 源码未单独提供参数说明。 |
### `Mesh2d.remove_invalid_values` {#mesh2d-remove-invalid-values}
```python
remove_invalid_values(self, float_invalid_value: float)
```
移除数组中可能存在的无效值。 同时移除其他数组中对应的条目。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `float_invalid_value` | `float` | `必填` | 浮点无效值。 |
### `Mesh2d.__eq__` {#mesh2d---eq--}
```python
__eq__(self, other: Mesh2d)
```
此成员以内部名称定义,供理解实现及转换流程时参考。
检查此网格是否与另一个网格完全相等。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `other` | `Mesh2d` | `必填` | 用于比较的网格。 |
### `Mesh2d.almost_equal` {#mesh2d-almost-equal}
```python
almost_equal(self, other: Mesh2d, rtol: float=1e-05, atol: float=1e-08) -> bool
```
根据给定的相对容差和绝对容差,检查此网格是否与另一个网格近似相等。 容差只适用于浮点数组(node_x、node_y、face_x、face_y、edge_x 和 edge_y;原文将 face_y 写作 faces_y)。 每个浮点数组都必须满足以下条件: absolute(self.float_array - other.float_array) <= (atol + rtol * absolute(other.float_array)) 包含索引和计数的数组(face_edges、face_nodes、edge_faces、edge_nodes、nodes_per_face) 在两个网格中必须完全相等。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `other` | `Mesh2d` | `必填` | 用于比较的网格。 |
| `rtol` | `float` | `1e-05` | 相对容差,默认为 1.0e-5。 |
| `atol` | `float` | `1e-08` | 绝对容差,默认为 1.0e-8。 |
**返回类型**:`bool`。源码未单独说明返回值。
### `Mesh2d.plot_edges` {#mesh2d-plot-edges}
```python
plot_edges(self, ax, *args, **kwargs)
```
在指定坐标轴上绘制网格边。 `args` 和 `kwargs` 作为 matplotlib 的 `plot` 方法参数传入。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `ax` | `matplotlib.axes.Axes` | `必填` | 绘制网格边所用的坐标轴对象。 |
| `args` | `未标注` | `不适用` | 可变位置参数。源码未单独提供参数说明。 |
| `kwargs` | `未标注` | `不适用` | 可变关键字参数。源码未单独提供参数说明。 |
### `Mesh2d.plot_faces` {#mesh2d-plot-faces}
```python
plot_faces(self, ax, *args, **kwargs)
```
在指定坐标轴上绘制网格面。 `args` 和 `kwargs` 作为 matplotlib 的 `plot` 方法参数传入。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `ax` | `matplotlib.axes.Axes` | `必填` | 绘制网格面所用的坐标轴对象。 |
| `args` | `未标注` | `不适用` | 可变位置参数。源码未单独提供参数说明。 |
| `kwargs` | `未标注` | `不适用` | 可变关键字参数。源码未单独提供参数说明。 |
## `GeometryList` {#geometrylist}
继承:`object`。
用于描述几何对象列表的类。
**属性说明**
- **`x_coordinates`(`ndarray`)**:描述节点 x 坐标的一维双精度数组。
- **`y_coordinates`(`ndarray`)**:描述节点 y 坐标的一维双精度数组。
- **`values`(`ndarray, 可选`)**:描述节点数值的一维双精度数组。
- **`geometry_separator`(`float, 可选`)**:坐标中的几何分隔值,默认为 `-999.0`。
- **`inner_outer_separator`(`float, 可选`)**:用于分隔多边形内边界和外边界的 值,默认为 `-998.0`。
**方法索引**
- [`__init__`](#geometrylist---init--)
### `GeometryList.__init__` {#geometrylist---init--}
```python
__init__(self, x_coordinates=np.empty(0, dtype=np.double), y_coordinates=np.empty(0, dtype=np.double), values=np.empty(0, dtype=np.double), geometry_separator=-999.0, inner_outer_separator=-998.0)
```
构造实例。源码没有单独编写此构造函数的文档字符串,参数及默认值如下。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `x_coordinates` | `未标注` | `np.empty(0, dtype=np.double)` | 源码未单独提供参数说明。 |
| `y_coordinates` | `未标注` | `np.empty(0, dtype=np.double)` | 源码未单独提供参数说明。 |
| `values` | `未标注` | `np.empty(0, dtype=np.double)` | 源码未单独提供参数说明。 |
| `geometry_separator` | `未标注` | `-999.0` | 源码未单独提供参数说明。 |
| `inner_outer_separator` | `未标注` | `-998.0` | 源码未单独提供参数说明。 |
## `InterpolationParameters` {#interpolationparameters}
继承:`object`。
保存属性插值参数的类。
**属性说明**
- **`interpolation_type`(`int, 可选`)**:要使用的插值类型。
- **`method`(`int, 可选`)**:要使用的平均方法。
- **`absolute_search_radius`(`float, 可选`)**:绝对搜索半径。
- **`relative_search_radius`(`float, 可选`)**:相对搜索半径。
- **`use_closest_if_none_found`(`bool, 可选`)**:若多边形内未找到点,则使用最近的点。
- **`minimum_number_of_samples`(`int, 可选`)**:某些平均方法所需的最少采样点数。
**方法索引**
- [`__init__`](#interpolationparameters---init--)
### `InterpolationParameters.__init__` {#interpolationparameters---init--}
```python
__init__(self, interpolation_type=1, method=1, absolute_search_radius=100.0, relative_search_radius=1.0, use_closest_if_none_found=True, minimum_number_of_samples=10)
```
构造实例。源码没有单独编写此构造函数的文档字符串,参数及默认值如下。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `interpolation_type` | `未标注` | `1` | 源码未单独提供参数说明。 |
| `method` | `未标注` | `1` | 源码未单独提供参数说明。 |
| `absolute_search_radius` | `未标注` | `100.0` | 源码未单独提供参数说明。 |
| `relative_search_radius` | `未标注` | `1.0` | 源码未单独提供参数说明。 |
| `use_closest_if_none_found` | `未标注` | `True` | 源码未单独提供参数说明。 |
| `minimum_number_of_samples` | `未标注` | `10` | 源码未单独提供参数说明。 |
## `OrthogonalizationParameters` {#orthogonalizationparameters}
继承:`object`。
保存正交化参数的类。
**属性说明**
- **`outer_iterations`(`int, 可选`)**:正交化的外层迭代次数。对于复杂网格, 应增大此值。默认为 `2`。
- **`boundary_iterations`(`int, 可选`)**:网格正交化过程中 itatp 内的边界迭代次数。 默认为 `25`。
- **`inner_iterations`(`int, 可选`)**:网格正交化过程中 itbnd 内的内部迭代次数。 默认为 `25`。
- **`orthogonalization_to_smoothing_factor`(`float, 可选`)**:控制网格平滑(0)与网格正交化(1)之间 权重的系数,默认为 `0.975`。
- **`orthogonalization_to_smoothing_factor_at_boundary`(`float, 可选`)**:边界上的最小 ATPF 值。 默认为 `1.0`。
- **`areal_to_angle_smoothing_factor`(`float, 可选`)**:在平滑器(1.0)与面积均匀化(0.0)之间调节的系数。 默认为 `1.0`。
**方法索引**
- [`__init__`](#orthogonalizationparameters---init--)
### `OrthogonalizationParameters.__init__` {#orthogonalizationparameters---init--}
```python
__init__(self, outer_iterations=2, boundary_iterations=25, inner_iterations=25, orthogonalization_to_smoothing_factor=0.975, orthogonalization_to_smoothing_factor_at_boundary=1.0, areal_to_angle_smoothing_factor=1.0)
```
构造实例。源码没有单独编写此构造函数的文档字符串,参数及默认值如下。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `outer_iterations` | `未标注` | `2` | 源码未单独提供参数说明。 |
| `boundary_iterations` | `未标注` | `25` | 源码未单独提供参数说明。 |
| `inner_iterations` | `未标注` | `25` | 源码未单独提供参数说明。 |
| `orthogonalization_to_smoothing_factor` | `未标注` | `0.975` | 源码未单独提供参数说明。 |
| `orthogonalization_to_smoothing_factor_at_boundary` | `未标注` | `1.0` | 源码未单独提供参数说明。 |
| `areal_to_angle_smoothing_factor` | `未标注` | `1.0` | 源码未单独提供参数说明。 |
## `CurvilinearGrid` {#curvilineargrid}
继承:`object`。
此类用于获取和设置曲线网格数据。
**属性说明**
- **`node_x`(`ndarray`)**:描述节点 x 坐标的一维双精度数组。
- **`node_y`(`ndarray`)**:描述节点 y 坐标的一维双精度数组。
- **`num_m`(`int`)**:曲线网格沿 m 方向的节点数。
- **`num_n`(`int`)**:曲线网格沿 n 方向的节点数。
**方法索引**
- [`__init__`](#curvilineargrid---init--)
- [`plot_edges`](#curvilineargrid-plot-edges)
### `CurvilinearGrid.__init__` {#curvilineargrid---init--}
```python
__init__(self, node_x, node_y, num_m, num_n)
```
构造实例。源码没有单独编写此构造函数的文档字符串,参数及默认值如下。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `node_x` | `未标注` | `必填` | 源码未单独提供参数说明。 |
| `node_y` | `未标注` | `必填` | 源码未单独提供参数说明。 |
| `num_m` | `未标注` | `必填` | 源码未单独提供参数说明。 |
| `num_n` | `未标注` | `必填` | 源码未单独提供参数说明。 |
### `CurvilinearGrid.plot_edges` {#curvilineargrid-plot-edges}
```python
plot_edges(self, ax, *args, **kwargs)
```
在指定坐标轴上绘制网格边。 `args` 和 `kwargs` 作为 matplotlib 的 `plot` 方法参数传入。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `ax` | `matplotlib.axes.Axes` | `必填` | 绘制网格边所用的坐标轴对象。 |
| `args` | `未标注` | `不适用` | 可变位置参数。源码未单独提供参数说明。 |
| `kwargs` | `未标注` | `不适用` | 可变关键字参数。源码未单独提供参数说明。 |
## `CurvilinearParameters` {#curvilinearparameters}
继承:`object`。
保存从样条曲线生成曲线网格所需参数的类。
**属性说明**
- **`m_refinement`(`int, 可选`)**:生成规则网格时的 m 方向加密系数,默认为 `2000`。
- **`n_refinement`(`int, 可选`)**:生成规则网格时的 n 方向加密系数,默认为 `40`。
- **`smoothing_iterations`(`int, 可选`)**:规则网格平滑的内部迭代次数,默认为 `25`。
- **`smoothing_parameter`(`float, 可选`)**:平滑参数,默认为 `0.5`。
- **`attraction_parameter`(`float, 可选`)**:吸引/排斥参数,默认为 `0.0`。
**方法索引**
- [`__init__`](#curvilinearparameters---init--)
### `CurvilinearParameters.__init__` {#curvilinearparameters---init--}
```python
__init__(self, m_refinement=2000, n_refinement=40, smoothing_iterations=10, smoothing_parameter=0.5, attraction_parameter=0.0)
```
构造实例。源码没有单独编写此构造函数的文档字符串,参数及默认值如下。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `m_refinement` | `未标注` | `2000` | 源码未单独提供参数说明。 |
| `n_refinement` | `未标注` | `40` | 源码未单独提供参数说明。 |
| `smoothing_iterations` | `未标注` | `10` | 源码未单独提供参数说明。 |
| `smoothing_parameter` | `未标注` | `0.5` | 源码未单独提供参数说明。 |
| `attraction_parameter` | `未标注` | `0.0` | 源码未单独提供参数说明。 |
## `SplinesToCurvilinearParameters` {#splinestocurvilinearparameters}
继承:`object`。
保存使用推进前沿法从样条曲线生成曲线网格 所需附加参数的类。
**属性说明**
- **`aspect_ratio`(`float, 可选`)**:纵横比,默认为 `0.1`。
- **`aspect_ratio_grow_factor`(`float, 可选`)**:纵横比增长系数,默认为 `1.1`。
- **`average_width`(`float, 可选`)**:中心样条曲线上的平均网格宽度,默认为 `0.005`。
- **`curvature_adapted_grid_spacing`(`int, 可选`)**:随曲率调整网格间距的选项,默认为 `1`。
- **`grow_grid_outside`(`int, 可选`)**:是否在指定网格高度之外扩展网格,默认为 `0`。
- **`maximum_num_faces_in_uniform_part`(`int, 可选`)**:均匀部分的最大层数,默认为 `5`。
- **`nodes_on_top_of_each_other_tolerance`(`float, 可选`)**:节点重合判定容差,默认为 `0.0001`。
- **`min_cosine_crossing_angles`(`float, 可选`)**:交叉角余弦绝对值允许的最小值。 默认为 `0.95`。
- **`check_front_collisions`(`int, 可选`)**:是否检查与前沿其他部分的碰撞,默认为 `0`。
- **`remove_skinny_triangles`(`int, 可选`)**:是否检查与前沿其他部分的碰撞,默认为 `1`。(原说明与前一字段重复;字段名称表示移除细长三角形。)
**方法索引**
- [`__init__`](#splinestocurvilinearparameters---init--)
### `SplinesToCurvilinearParameters.__init__` {#splinestocurvilinearparameters---init--}
```python
__init__(self, aspect_ratio=0.1, aspect_ratio_grow_factor=1.1, average_width=500.0, curvature_adapted_grid_spacing=1, grow_grid_outside=False, maximum_num_faces_in_uniform_part=5, nodes_on_top_of_each_other_tolerance=0.0001, min_cosine_crossing_angles=0.95, check_front_collisions=False, remove_skinny_triangles=True)
```
构造实例。源码没有单独编写此构造函数的文档字符串,参数及默认值如下。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `aspect_ratio` | `未标注` | `0.1` | 源码未单独提供参数说明。 |
| `aspect_ratio_grow_factor` | `未标注` | `1.1` | 源码未单独提供参数说明。 |
| `average_width` | `未标注` | `500.0` | 源码未单独提供参数说明。 |
| `curvature_adapted_grid_spacing` | `未标注` | `1` | 源码未单独提供参数说明。 |
| `grow_grid_outside` | `未标注` | `False` | 源码未单独提供参数说明。 |
| `maximum_num_faces_in_uniform_part` | `未标注` | `5` | 源码未单独提供参数说明。 |
| `nodes_on_top_of_each_other_tolerance` | `未标注` | `0.0001` | 源码未单独提供参数说明。 |
| `min_cosine_crossing_angles` | `未标注` | `0.95` | 源码未单独提供参数说明。 |
| `check_front_collisions` | `未标注` | `False` | 源码未单独提供参数说明。 |
| `remove_skinny_triangles` | `未标注` | `True` | 源码未单独提供参数说明。 |
## `MeshRefinementParameters` {#meshrefinementparameters}
继承:`object`。
保存二维网格加密参数的类。
**属性说明**
- **`refine_intersected`(`bool`)**:是否处理与多边形相交的网格面,默认为 `False`。
- **`use_mass_center_when_refining`(`bool`)**:加密过程中划分网格面时, 是否使用质心,默认为 `True`。
- **`min_edge_size`(`float`)**:最小边长,默认为 `0.5`。
- **`refinement_type`(`RefinementType`)**:加密判据类型,默认为 `RefinementType.REFINEMENT_LEVELS`。
- **`connect_hanging_nodes`(`bool`)**:是否在迭代结束时连接悬挂节点,默认为 `True`。
- **`account_for_samples_outside`(`bool`)**:是否考虑网格面外的采样数据,默认为 `False`。
- **`max_refinement_iterations`(`int, 可选`)**:最大加密迭代次数,默认为 `10`。
- **`smoothing_iterations`(`int, 可选`)**:平滑迭代次数,默认为 `5`。
- **`max_courant_time`(`double, 可选`)**:最大库朗时间,单位为秒,默认为 `120`。
- **`directional_refinement`(`bool, 可选`)**:定向加密选项,当平滑迭代次数 大于 0 时不可使用,默认为 `False`。
**方法索引**
- [`__init__`](#meshrefinementparameters---init--)
### `MeshRefinementParameters.__init__` {#meshrefinementparameters---init--}
```python
__init__(self, refine_intersected=False, use_mass_center_when_refining=True, min_edge_size=0.5, refinement_type=RefinementType.REFINEMENT_LEVELS, connect_hanging_nodes=True, account_for_samples_outside_face=False, max_refinement_iterations=10, smoothing_iterations=5, max_courant_time=120.0, directional_refinement=False)
```
构造实例。源码没有单独编写此构造函数的文档字符串,参数及默认值如下。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `refine_intersected` | `未标注` | `False` | 源码未单独提供参数说明。 |
| `use_mass_center_when_refining` | `未标注` | `True` | 源码未单独提供参数说明。 |
| `min_edge_size` | `未标注` | `0.5` | 源码未单独提供参数说明。 |
| `refinement_type` | `未标注` | `RefinementType.REFINEMENT_LEVELS` | 源码未单独提供参数说明。 |
| `connect_hanging_nodes` | `未标注` | `True` | 源码未单独提供参数说明。 |
| `account_for_samples_outside_face` | `未标注` | `False` | 源码未单独提供参数说明。 |
| `max_refinement_iterations` | `未标注` | `10` | 源码未单独提供参数说明。 |
| `smoothing_iterations` | `未标注` | `5` | 源码未单独提供参数说明。 |
| `max_courant_time` | `未标注` | `120.0` | 源码未单独提供参数说明。 |
| `directional_refinement` | `未标注` | `False` | 源码未单独提供参数说明。 |
## `MakeGridParameters` {#makegridparameters}
继承:`object`。
保存以 C 兼容方式创建新曲线网格所需参数的类。
**属性说明**
- **`num_columns`(`int, 可选`)**:x 方向的列数,默认为 `3`。
- **`num_rows`(`int, 可选`)**:y 方向的行数,默认为 `3`。(原文称为列数。)
- **`angle`(`float, 可选`)**:网格角度,默认为 `0.0`。
- **`origin_x`(`float, 可选`)**:左下角原点的 x 坐标。 默认为 `0.0`。
- **`origin_y`(`float, 可选`)**:左下角原点的 y 坐标。 默认为 `0.0`。
- **`block_size_x`(`float, 可选`)**:x 方向的网格块尺寸,仅用于方形网格。 默认为 `10.0`。
- **`block_size_y`(`float, 可选`)**:y 方向的网格块尺寸,仅用于方形网格。 默认为 `10.0`。
- **`upper_right_x`(`float, 可选`)**:右上角的 x 坐标。 默认为 `0.0`。
- **`upper_right_y`(`float, 可选`)**:右上角的 y 坐标。 默认为 `0.0`。
**方法索引**
- [`__init__`](#makegridparameters---init--)
### `MakeGridParameters.__init__` {#makegridparameters---init--}
```python
__init__(self, num_columns=3, num_rows=3, angle=0.0, origin_x=0.0, origin_y=0.0, block_size_x=10.0, block_size_y=10.0, upper_right_x=0.0, upper_right_y=0.0)
```
构造实例。源码没有单独编写此构造函数的文档字符串,参数及默认值如下。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `num_columns` | `未标注` | `3` | 源码未单独提供参数说明。 |
| `num_rows` | `未标注` | `3` | 源码未单独提供参数说明。 |
| `angle` | `未标注` | `0.0` | 源码未单独提供参数说明。 |
| `origin_x` | `未标注` | `0.0` | 源码未单独提供参数说明。 |
| `origin_y` | `未标注` | `0.0` | 源码未单独提供参数说明。 |
| `block_size_x` | `未标注` | `10.0` | 源码未单独提供参数说明。 |
| `block_size_y` | `未标注` | `10.0` | 源码未单独提供参数说明。 |
| `upper_right_x` | `未标注` | `0.0` | 源码未单独提供参数说明。 |
| `upper_right_y` | `未标注` | `0.0` | 源码未单独提供参数说明。 |
## `Mesh1d` {#mesh1d}
继承:`object`。
此类用于获取和设置一维网格数据。
**属性说明**
- **`node_x`(`ndarray`)**:描述节点 x 坐标的一维双精度数组。
- **`node_y`(`ndarray`)**:描述节点 y 坐标的一维双精度数组。
- **`edge_nodes`(`ndarray, 可选`)**:描述每条网格边端点节点的一维整数数组。
**方法索引**
- [`__init__`](#mesh1d---init--)
- [`remove_invalid_values`](#mesh1d-remove-invalid-values)
- [`plot_edges`](#mesh1d-plot-edges)
### `Mesh1d.__init__` {#mesh1d---init--}
```python
__init__(self, node_x, node_y, edge_nodes)
```
构造实例。源码没有单独编写此构造函数的文档字符串,参数及默认值如下。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `node_x` | `未标注` | `必填` | 源码未单独提供参数说明。 |
| `node_y` | `未标注` | `必填` | 源码未单独提供参数说明。 |
| `edge_nodes` | `未标注` | `必填` | 源码未单独提供参数说明。 |
### `Mesh1d.remove_invalid_values` {#mesh1d-remove-invalid-values}
```python
remove_invalid_values(self, float_invalid_value: float)
```
移除数组中可能存在的无效值。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `float_invalid_value` | `float` | `必填` | 浮点无效值。 |
### `Mesh1d.plot_edges` {#mesh1d-plot-edges}
```python
plot_edges(self, ax, *args, **kwargs)
```
在指定坐标轴上绘制网格边。 `args` 和 `kwargs` 作为 matplotlib 的 `plot` 方法参数传入。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `ax` | `matplotlib.axes.Axes` | `必填` | 绘制网格边所用的坐标轴对象。 |
| `args` | `未标注` | `不适用` | 可变位置参数。源码未单独提供参数说明。 |
| `kwargs` | `未标注` | `不适用` | 可变关键字参数。源码未单独提供参数说明。 |
## `Contacts` {#contacts}
继承:`object`。
此类描述一维与二维网格之间的连接。
**属性说明**
- **`mesh1d_indices`(`ndarray`)**:描述一维网格节点索引的一维整数数组。
- **`mesh2d_indices`(`ndarray`)**:描述二维网格面索引的一维整数数组。
**方法索引**
- [`__init__`](#contacts---init--)
- [`remove_invalid_values`](#contacts-remove-invalid-values)
- [`plot_edges`](#contacts-plot-edges)
### `Contacts.__init__` {#contacts---init--}
```python
__init__(self, mesh1d_indices, mesh2d_indices)
```
构造实例。源码没有单独编写此构造函数的文档字符串,参数及默认值如下。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `mesh1d_indices` | `未标注` | `必填` | 源码未单独提供参数说明。 |
| `mesh2d_indices` | `未标注` | `必填` | 源码未单独提供参数说明。 |
### `Contacts.remove_invalid_values` {#contacts-remove-invalid-values}
```python
remove_invalid_values(self, int_invalid_value: int)
```
移除数组中可能存在的无效值。 同时移除其他数组中对应的条目。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `int_invalid_value` | `int` | `必填` | 整数无效值。 |
### `Contacts.plot_edges` {#contacts-plot-edges}
```python
plot_edges(self, ax, mesh1d, mesh2d, *args, **kwargs)
```
在指定坐标轴上绘制网格边。 `args` 和 `kwargs` 作为 matplotlib 的 `plot` 方法参数传入。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `ax` | `matplotlib.axes.Axes` | `必填` | 绘制网格边所用的坐标轴对象。 |
| `mesh1d` | `Mesh1d` | `必填` | 绘制连接所用的一维网格实例。 |
| `mesh2d` | `Mesh2d` | `必填` | 绘制连接所用的二维网格实例。 |
| `args` | `未标注` | `不适用` | 可变位置参数。源码未单独提供参数说明。 |
| `kwargs` | `未标注` | `不适用` | 可变关键字参数。源码未单独提供参数说明。 |
## `GriddedSamples` {#griddedsamples}
继承:`object`。
保存均匀或非均匀网格采样数据的类。
**属性说明**
- **`num_x`(`int, 可选`)**:x 方向的采样坐标数,采样网格点数为 num_x × num_y。 默认为 `0`。
- **`num_y`(`int, 可选`)**:y 方向的采样坐标数,采样网格点数为 num_x × num_y。 默认为 `0`。
- **`x_origin`(`float, 可选`)**:采样网格原点的 x 坐标,默认为 `0.0`。
- **`y_origin`(`float, 可选`)**:采样网格原点的 y 坐标,默认为 `0.0`。
- **`cell_size`(`float, 可选`)**:固定的采样网格边长,默认为 `0.0`。
- **`x_coordinates`(`ndarray, 可选`)**:x 方向非均匀网格间距对应的坐标。
- **`y_coordinates`(`ndarray, 可选`)**:y 方向非均匀网格间距对应的坐标。
- **`values`(`ndarray`)**:采样值。
**方法索引**
- [`__init__`](#griddedsamples---init--)
### `GriddedSamples.__init__` {#griddedsamples---init--}
```python
__init__(self, num_x=0, num_y=0, x_origin=0.0, y_origin=0.0, cell_size=0.0, x_coordinates=np.empty(0, dtype=np.double), y_coordinates=np.empty(0, dtype=np.double), values=np.empty(0, dtype=np.float32))
```
构造实例。源码没有单独编写此构造函数的文档字符串,参数及默认值如下。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `num_x` | `未标注` | `0` | 源码未单独提供参数说明。 |
| `num_y` | `未标注` | `0` | 源码未单独提供参数说明。 |
| `x_origin` | `未标注` | `0.0` | 源码未单独提供参数说明。 |
| `y_origin` | `未标注` | `0.0` | 源码未单独提供参数说明。 |
| `cell_size` | `未标注` | `0.0` | 源码未单独提供参数说明。 |
| `x_coordinates` | `未标注` | `np.empty(0, dtype=np.double)` | 源码未单独提供参数说明。 |
| `y_coordinates` | `未标注` | `np.empty(0, dtype=np.double)` | 源码未单独提供参数说明。 |
| `values` | `未标注` | `np.empty(0, dtype=np.float32)` | 源码未单独提供参数说明。 |
## `CurvilinearDirection` {#curvilineardirection}
继承:`IntEnum`。
曲线网格算法使用的方向。
**枚举成员**
| 名称 | 值 | 中文说明 |
| --- | --- | --- |
| `M` | `0` | 沿 m 方向。 |
| `N` | `1` | 沿 n 方向。 |
+56
View File
@@ -0,0 +1,56 @@
# 辅助函数
模块:`meshkernel.utils`。本页依据本地 MeshKernelPy `8.3.0` 源码生成,包含该模块定义的类、方法、函数和常量。签名及参数默认值以源码为准;原文未提供的说明会明确标记。
[返回 API 总览](modules.md)
## `to_contiguous_numpy_array` {#to-contiguous-numpy-array}
```python
to_contiguous_numpy_array(vec) -> np.ndarray
```
在将输入向量传给 MeshKernel C API 函数前,确保其内存连续, 适用于通过切片操作创建的向量。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `vec` | `np.ndarray` | `必填` | 输入向量。 |
**返回值**
内存连续的向量。
**异常**
- **`TypeError`**:`vec` 不是 NumPy 数组时抛出。
## `plot_edges` {#plot-edges}
```python
plot_edges(node_x, node_y, edge_nodes, ax, *args, **kwargs)
```
在指定坐标轴上绘制网格边。 `args` 和 `kwargs` 将作为 `plot` 方法的参数传入。
**参数**
| 名称 | 类型 | 默认值 | 中文说明 |
| --- | --- | --- | --- |
| `node_x` | `ndarray` | `必填` | 描述节点 x 坐标的一维双精度数组。 |
| `node_y` | `ndarray` | `必填` | 描述节点 y 坐标的一维双精度数组。 |
| `edge_nodes` | `ndarray` | `必填` | 描述每条二维网格边端点节点的一维整数数组。 |
| `ax` | `matplotlib.axes.Axes` | `必填` | 绘制网格边所用的坐标轴对象。 |
| `args` | `未标注` | `不适用` | 可变位置参数。源码未单独提供参数说明。 |
| `kwargs` | `未标注` | `不适用` | 可变关键字参数。源码未单独提供参数说明。 |
## `get_maximum_bounding_box_coordinates` {#get-maximum-bounding-box-coordinates}
```python
get_maximum_bounding_box_coordinates()
```
获取浮点坐标定义的边界框可用的最大坐标范围。
@@ -0,0 +1,21 @@
# 版本信息
模块:`meshkernel.version`。本页依据本地 MeshKernelPy `8.3.0` 源码生成,包含该模块定义的类、方法、函数和常量。签名及参数默认值以源码为准;原文未提供的说明会明确标记。
[返回 API 总览](modules.md)
## `__version__` {#--version--}
```python
__version__ = '8.3.0'
```
Python 封装库版本。
## `__backend_version__` {#--backend-version--}
```python
__backend_version__ = '8.3.0'
```
C++ 后端版本。
+13
View File
@@ -0,0 +1,13 @@
# MeshKernelPy API 总览
本 API 文档根据本地 MeshKernelPy **8.3.0** 源码编写,完整列出 6 个模块中的 **39 个类**与 **167 个方法/函数**,另含版本常量和包顶层导出表。内部辅助成员也单独列出并注明用途。所有源码文档字符串均已翻译;参数类型、默认值、继承关系、枚举值及 C 字段从源码提取。
源码未编写的成员说明不凭空补造;原文与签名不一致的内容保留并标注。旧 Sphinx 配置中的 `2.1.0` 与当前源码版本不一致,本页及所有 API 页面采用源码的 `8.3.0`。
- [包顶层导出接口](meshkernel.md)
- [MeshKernel 核心接口](meshkernel.meshkernel.md)
- [Python 数据结构与枚举](meshkernel.py_structures.md)
- [C 数据结构与转换接口](meshkernel.c_structures.md)
- [异常类型](meshkernel.errors.md)
- [辅助函数](meshkernel.utils.md)
- [版本信息](meshkernel.version.md)
@@ -0,0 +1,215 @@
# 二维网格基础
本教程介绍 `meshkernel` 库的基本用法。
`meshkernel` 可以创建和操作多种网格。
最常见的应用涉及二维非结构网格,因此本教程重点介绍这类网格。
[返回示例目录](index.md)
以下保留原笔记本的代码和已保存输出;转换过程中未重新执行代码。
首先导入所需的库。
```python
import matplotlib.pyplot as plt
import numpy as np
from meshkernel import GeometryList, MakeGridParameters, MeshKernel, ProjectionType
```
`meshkernel` 提供了一组便捷方法,用于创建常见网格。
这里使用 `curvilinear_compute_rectangular_grid` 方法创建一个简单的曲线网格。该方法的完整参数请参阅相应文档。
```python
mk = MeshKernel()
make_grid_parameters = MakeGridParameters()
make_grid_parameters.num_columns = 3
make_grid_parameters.num_rows = 2
make_grid_parameters.angle = 0.0
make_grid_parameters.origin_x = 0.0
make_grid_parameters.origin_y = 0.0
make_grid_parameters.block_size_x = 1.0
make_grid_parameters.block_size_y = 1.0
mk.curvilinear_compute_rectangular_grid(make_grid_parameters)
```
将曲线网格转换为非结构网格,并获取生成的 `mesh2d`。
```python
mk.curvilinear_convert_to_mesh2d()
```
```python
mesh2d_input = mk.mesh2d_get()
```
`Mesh2D` 有三个必需属性,仅凭它们就可以完整描述任意非结构网格。
前两个属性是 `node_x` 和 `node_y`,它们是一维 `double` 数组,用来描述节点的位置,如下图所示。
```python
fig, ax = plt.subplots()
# 绘制白色点,仅用于调整图的显示范围
ax.plot(mesh2d_input.node_x, mesh2d_input.node_y, "ow")
# 为节点编号
for i in range(mesh2d_input.node_x.size):
ax.annotate(
int(i),
xy=(mesh2d_input.node_x[i], mesh2d_input.node_y[i]),
ha="center",
va="center",
fontsize=12,
color="blue",
)
```
![单元格 9 的绘图输出](images/01_mesh2d_basics_9_0.png)
第三个必需属性是 `edge_nodes`,它描述组成各条边的节点索引。
每两个索引表示一条边。因此,在本例中,0–4、1–5、2–6 等索引对分别表示一条边。
```python
mesh2d_input.edge_nodes
```
```text
array([ 0, 4, 1, 5, 2, 6, 3, 7, 4, 8, 5, 9, 6, 10, 7, 11, 0,
1, 1, 2, 2, 3, 4, 5, 5, 6, 6, 7, 8, 9, 9, 10, 10, 11],
dtype=int32)
```
结合这三个参数即可绘制网格。
```python
fig, ax = plt.subplots()
mesh2d_input.plot_edges(ax, color="blue")
```
![单元格 13 的绘图输出](images/01_mesh2d_basics_13_0.png)
要与 `meshkernel` 库交互,首先创建一个 `MeshKernel` 类实例。
构造函数的 `projection` 参数用于指定网格采用笛卡尔坐标(`ProjectionType.CARTESIAN`)还是球面坐标(`ProjectionType.SPHERICAL`)。
```python
mk = MeshKernel(projection=ProjectionType.CARTESIAN)
```
每个实例都维护各自的状态,可以通过对应的获取和设置方法访问这些状态。
```python
mk.mesh2d_set(mesh2d_input)
```
```python
mesh2d_output_0 = mk.mesh2d_get()
```
刚才设置了 `mesh2d`,随后立即将它取出,期间没有要求 `meshkernel` 执行其他操作。
设置 `mesh2d` 后,`meshkernel` 已计算出网格面数据和边的坐标。
```python
fig, ax = plt.subplots()
mesh2d_output_0.plot_faces(ax)
# 在网格面中心标注面索引
for face_index, (face_x, face_y) in enumerate(
zip(mesh2d_output_0.face_x, mesh2d_output_0.face_y)
):
ax.text(face_x, face_y, face_index, ha="center", va="center", fontsize=22)
```
![单元格 20 的绘图输出](images/01_mesh2d_basics_20_0.png)
`meshkernel` 还会查找边的中点,并将其作为属性添加到 `Mesh2D` 类中。
```python
fig, ax = plt.subplots()
ax.plot(mesh2d_output_0.edge_x, mesh2d_output_0.edge_y, ".");
```
![单元格 22 的绘图输出](images/01_mesh2d_basics_22_0.png)
目前网格看起来仍然是结构化的。接下来添加几个节点,改变它的结构。
```python
node_index_0 = mk.mesh2d_insert_node(4.0, 1.5)
node_index_1 = mk.mesh2d_insert_node(4.0, 2.5)
```
还需要将新增节点连接起来,否则 `meshkernel` 会将未连接的节点清理掉。
```python
edge_index_0 = mk.mesh2d_insert_edge(7, node_index_0)
edge_index_1 = mk.mesh2d_insert_edge(node_index_0, node_index_1)
edge_index_3 = mk.mesh2d_insert_edge(node_index_1, 11)
```
获取更新后的状态。
```python
mesh2d_output_1 = mk.mesh2d_get()
```
绘制输出网格,可以看到 `meshkernel` 已立即识别出一个新的网格面。
```python
fig, ax = plt.subplots()
mesh2d_output_1.plot_faces(ax)
# 在网格面中心标注面索引
for face_index, (face_x, face_y) in enumerate(
zip(mesh2d_output_1.face_x, mesh2d_output_1.face_y)
):
ax.text(face_x, face_y, face_index, ha="center", va="center", fontsize=22)
```
![单元格 30 的绘图输出](images/01_mesh2d_basics_30_0.png)
也可以删除节点。
```python
mk.mesh2d_delete_node(node_index_1)
mesh2d_output_2 = mk.mesh2d_get()
```
网格重新变成六个面,但仍留有一条悬挂边。
```python
fig, ax = plt.subplots()
mesh2d_output_2.plot_edges(ax, color="blue")
```
![单元格 34 的绘图输出](images/01_mesh2d_basics_34_0.png)
悬挂边通常是不需要的,因此 `meshkernel` 提供了处理它们的方法。首先,可以统计悬挂边的数量。
```python
hanging_edges = mk.mesh2d_get_hanging_edges()
assert hanging_edges.size == 1
```
`meshkernel` 还可以查找并删除悬挂边。
```python
mk.mesh2d_delete_hanging_edges()
mesh2d_output_3 = mk.mesh2d_get()
```
删除悬挂边后,网格恢复到最初的状态。
```python
fig, ax = plt.subplots()
mesh2d_output_3.plot_edges(ax, color="blue")
```
![单元格 40 的绘图输出](images/01_mesh2d_basics_40_0.png)
@@ -0,0 +1,121 @@
# 一维网格基础
本教程介绍一维网格的处理方式,以及一维网格与二维网格之间的交互。
[返回示例目录](index.md)
以下保留原笔记本的代码和已保存输出;转换过程中未重新执行代码。
首先导入所需的库。
```python
import matplotlib.pyplot as plt
import numpy as np
from meshkernel import Mesh1d, GeometryList, MakeGridParameters, MeshKernel
```
首先,使用正弦函数上的八个点描述一维网格。原说明写为六个点,此处按下方 `np.linspace(..., 8)` 代码修正。
```python
node_x = np.linspace(0, 2 * np.pi, 8)
node_y = np.sin(node_x)
```
为了形成一条连续的折线,将每个点与下一个点相连。
```python
edge_nodes = np.zeros(node_x.size * 2, np.int32)
edge_index = 0
for node_index in range(node_x.size - 1):
edge_nodes[edge_index] = node_index
edge_index += 1
edge_nodes[edge_index] = node_index + 1
edge_index += 1
```
然后创建 `Mesh1d` 实例。
```python
mesh1d_input = Mesh1d(node_x, node_y, edge_nodes)
```
创建 `MeshKernel` 实例。
```python
mk = MeshKernel()
```
使用 `curvilinear_compute_rectangular_grid` 方法创建一个简单的曲线网格。该方法的完整参数请参阅相应文档。
```python
make_grid_parameters = MakeGridParameters()
make_grid_parameters.num_columns = 7
make_grid_parameters.num_rows = 3
make_grid_parameters.angle = 0.0
make_grid_parameters.origin_x = -0.1
make_grid_parameters.origin_y = -1.5
make_grid_parameters.block_size_x = 1.0
make_grid_parameters.block_size_y = 1.0
mk.curvilinear_compute_rectangular_grid(make_grid_parameters)
```
将曲线网格转换为非结构 `mesh2d`,并从 `MeshKernel` 中获取该网格。
```python
mk.curvilinear_convert_to_mesh2d()
mesh2d_input = mk.mesh2d_get()
```
设置 `mesh1d`。
```python
mk.mesh1d_set(mesh1d_input)
```
当前网格如下图所示:
```python
fig, ax = plt.subplots()
mesh1d_input.plot_edges(ax, color="blue")
mesh2d_input.plot_edges(ax, color="black")
```
![单元格 18 的绘图输出](images/02_mesh1d_basics_18_0.png)
同时使用一维和二维网格时,通常需要在它们之间建立连接(contacts)。
所有连接计算方法都需要节点掩码,用于确定哪些一维节点应参与连接。
本例考虑所有节点。
```python
node_mask = np.full(mesh1d_input.node_x.size, True)
```
调用 `contacts_compute_multiple` 方法建立连接。
```python
mk.contacts_compute_multiple(node_mask)
```
然后从 `MeshKernel` 实例中获取状态。
```python
mesh1d_output_0 = mk.mesh1d_get()
mesh2d_output_0 = mk.mesh2d_get()
contacts_output_0 = mk.contacts_get()
```
可以看到,一维节点与二维网格面之间已经建立了连接。
```python
fig, ax = plt.subplots()
mesh1d_output_0.plot_edges(ax, color="blue")
mesh2d_output_0.plot_edges(ax, color="black")
contacts_output_0.plot_edges(ax, mesh1d_output_0, mesh2d_output_0, color="red")
```
![单元格 26 的绘图输出](images/02_mesh1d_basics_26_0.png)
@@ -0,0 +1,71 @@
# 在给定几何区域内生成简单三角网格
本教程介绍如何在给定几何区域内生成二维网格。
首先导入所需的库。
[返回示例目录](index.md)
以下保留原笔记本的代码和已保存输出;转换过程中未重新执行代码。
```python
from pathlib import Path
import matplotlib.pyplot as plt
import numpy as np
from meshkernel import GeometryList, MeshKernel
```
首先,使用 NumPy 从 Deltares 自定义多边形文件 `test.pol` 中加载数据。
注意,需要忽略文件开头的若干行,以跳过 Deltares 特有的头部数据。
```python
polygon_file_path = Path().absolute() / "data_examples" / "test.pol"
polygon_np = np.loadtxt(polygon_file_path, comments="*", skiprows=8, dtype=np.double)
```
提取从文件中加载的数据,并按照 `MeshKernel` 的要求,将其存入 `GeometryList`。
```python
x_coordinates = np.array(polygon_np[:, 0], dtype=np.double)
y_coordinates = np.array(polygon_np[:, 1], dtype=np.double)
polygon = GeometryList(x_coordinates, y_coordinates)
```
导入的多边形如下图所示:
```python
fig, ax = plt.subplots()
ax.plot(x_coordinates, y_coordinates, ".-", color="green");
```
![单元格 7 的绘图输出](images/03_tri_mesh2d_pol_7_0.png)
接着创建一个 `MeshKernel` 实例。
```python
mk = MeshKernel()
```
现在可以调用 `MeshKernel` 的 `mesh2d_make_triangular_mesh_from_polygon` 方法,根据给定多边形生成三角网格。
```python
mk.mesh2d_make_triangular_mesh_from_polygon(polygon)
```
然后从 `MeshKernel` 实例中获取状态。
```python
mesh2d_output_0 = mk.mesh2d_get()
```
绘制生成的网格。
```python
fig, ax = plt.subplots()
mesh2d_output_0.plot_edges(ax, color="black")
```
![单元格 15 的绘图输出](images/03_tri_mesh2d_pol_15_0.png)
@@ -0,0 +1,585 @@
# 曲线网格基础
本教程介绍如何使用 `meshkernel` 库生成曲线网格。
[返回示例目录](index.md)
以下保留原笔记本的代码和已保存输出;转换过程中未重新执行代码。
首先导入所需的库。
```python
import matplotlib.pyplot as plt
import numpy as np
from meshkernel import (
CurvilinearParameters,
MakeGridParameters,
GeometryList,
MeshKernel,
SplinesToCurvilinearParameters,
OrthogonalizationParameters,
)
```
定义一个函数,使用 `curvilinear_compute_transfinite_from_splines` 生成曲线网格,并创建包含该网格的 `MeshKernel` 实例:
- 首先创建用于生成曲线网格的样条曲线,各条样条曲线用 `-999.0` 分隔。
- 在新的 `CurvilinearParameters` 实例中设置 m、n 方向的划分数。
- 创建一个新的 `MeshKernel` 实例。
- 使用超限插值算法生成曲线网格。
```python
def create_mk_instance_with_curvilinear_grid_from_transfinite_method():
r"""创建包含曲线网格的 MeshKernel 实例。"""
mk = MeshKernel()
separator = -999.0
splines_x = np.array(
[
2.0,
4.0,
7.0,
separator,
-1.0,
1.0,
5.0,
separator,
3.0,
-2.0,
separator,
7.0,
4.0,
],
dtype=np.double,
)
splines_y = np.array(
[
1.0,
3.0,
4.0,
separator,
4.0,
6.0,
7.0,
separator,
1.0,
6.0,
separator,
3.0,
8.0,
],
dtype=np.double,
)
splines = GeometryList(splines_x, splines_y)
curvilinear_parameters = CurvilinearParameters()
curvilinear_parameters.n_refinement = 10
curvilinear_parameters.m_refinement = 10
mk.curvilinear_compute_transfinite_from_splines(splines, curvilinear_parameters)
return mk
```
定义一个用于创建矩形曲线网格的函数。
```python
def create_mk_instance_with_a_rectangular_curvilinear_grid(num_columns=3, num_rows=3):
r"""创建包含矩形曲线网格的 MeshKernel 实例的局部函数。"""
mk = MeshKernel()
# 创建 MakeGridParameters 实例并设置参数值
make_grid_parameters = MakeGridParameters()
make_grid_parameters.num_columns = num_columns
make_grid_parameters.num_rows = num_rows
make_grid_parameters.angle = 0.0
make_grid_parameters.origin_x = 0.0
make_grid_parameters.origin_y = 0.0
make_grid_parameters.block_size_x = 10.0
make_grid_parameters.block_size_y = 10.0
mk.curvilinear_compute_rectangular_grid(make_grid_parameters)
return mk
```
## 使用超限插值法生成曲线网格
```python
curvilinear_grid_transfinite = (
create_mk_instance_with_curvilinear_grid_from_transfinite_method().curvilineargrid_get()
)
```
绘制结果。
```python
fig, ax = plt.subplots()
curvilinear_grid_transfinite.plot_edges(ax)
```
![单元格 10 的绘图输出](images/04_curvilineargrid_basics_10_0.png)
## 使用推进前沿法生成曲线网格
定义生成曲线网格的过程,使用 `curvilinear_compute_orthogonal_from_splines` 方法创建包含网格的 `MeshKernel` 实例:
- 首先创建用于生成曲线网格的样条曲线,各条样条曲线用 `-999.0` 分隔。
- 在新的 `CurvilinearParameters` 实例中设置 m、n 方向的划分数。
- 该算法还需要设置从样条曲线生成曲线网格所需的附加参数。
- 然后使用推进前沿算法生成曲线网格。
```python
mk = MeshKernel()
separator = -999.0
splines_x = np.array([-1.0, 2.0, 6.0, separator, 3.0, -2.0, separator], dtype=np.double)
splines_y = np.array([2.0, 5.0, 6.0, separator, 1.0, 6.0, separator], dtype=np.double)
splines_values = np.zeros_like(splines_x)
splines = GeometryList(splines_x, splines_y, splines_values)
curvilinearParameters = CurvilinearParameters()
curvilinearParameters.n_refinement = 10
curvilinearParameters.m_refinement = 10
splinesToCurvilinearParameters = SplinesToCurvilinearParameters()
splinesToCurvilinearParameters.aspect_ratio = 1.0
splinesToCurvilinearParameters.aspect_ratio_grow_factor = 1.0
splinesToCurvilinearParameters.average_width = 0.2
splinesToCurvilinearParameters.nodes_on_top_of_each_other_tolerance = 1e-4
splinesToCurvilinearParameters.min_cosine_crossing_angles = 0.95
splinesToCurvilinearParameters.check_front_collisions = 0
splinesToCurvilinearParameters.curvature_adapted_grid_spacing = 1
splinesToCurvilinearParameters.remove_skinny_triangles = 1
mk.curvilinear_compute_orthogonal_from_splines(
splines, curvilinearParameters, splinesToCurvilinearParameters
)
curvilinear_grid_orthogonal = mk.curvilineargrid_get()
```
绘制结果。
```python
fig, ax = plt.subplots()
curvilinear_grid_orthogonal.plot_edges(ax)
```
![单元格 15 的绘图输出](images/04_curvilineargrid_basics_15_0.png)
## 曲线网格加密与粗化
加密前的网格。
```python
mk = create_mk_instance_with_curvilinear_grid_from_transfinite_method()
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 18 的绘图输出](images/04_curvilineargrid_basics_18_0.png)
在两个选定点之间,为每一行添加两条水平网格线进行加密,并绘制结果。
```python
mk.curvilinear_refine(2.299, 4.612, 3.074, 3.684, 2)
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 20 的绘图输出](images/04_curvilineargrid_basics_20_0.png)
删除相同行中的网格线,进行粗化。
```python
mk.curvilinear_refine(2.299, 4.612, 3.074, 3.684, -2)
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 22 的绘图输出](images/04_curvilineargrid_basics_22_0.png)
## 创建矩形网格
```python
mk = create_mk_instance_with_a_rectangular_curvilinear_grid()
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 24 的绘图输出](images/04_curvilineargrid_basics_24_0.png)
也可以根据多边形生成矩形网格。多边形必须闭合。
```python
node_x = np.array([2.5, 5.5, 3.5, 0.5, 2.5], dtype=np.double)
node_y = np.array([0.5, 3.0, 5.0, 2.5, 0.5], dtype=np.double)
geometry_list = GeometryList(node_x, node_y)
```
```python
make_grid_parameters = MakeGridParameters()
make_grid_parameters.num_columns = 10
make_grid_parameters.num_rows = 10
make_grid_parameters.angle = 0.0
make_grid_parameters.origin_x = 0.0
make_grid_parameters.origin_y = 0.0
make_grid_parameters.block_size_x = 0.2
make_grid_parameters.block_size_y = 0.2
```
```python
mk.curvilinear_compute_rectangular_grid_from_polygon(
make_grid_parameters, geometry_list
)
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 28 的绘图输出](images/04_curvilineargrid_basics_28_0.png)
## 利用多边形边界上的节点生成曲线网格
定义多边形并生成曲线网格。
```python
node_x = np.array([2, 4, 6, 7, 8, 8, 8, 8, 7, 5, 3, 2, 2, 2, 2], dtype=np.double)
node_y = np.array([1, 1, 1, 1, 1, 1.2, 4, 6, 6, 6, 6, 6, 5, 3, 1], dtype=np.double)
geometry_list = GeometryList(node_x, node_y)
mk = MeshKernel()
mk.curvilinear_compute_transfinite_from_polygon(geometry_list, 0, 4, 7, False)
```
```python
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 32 的绘图输出](images/04_curvilineargrid_basics_32_0.png)
## 曲线网格正交化
移动一个节点,使网格不再正交,并绘制结果。
```python
mk = create_mk_instance_with_a_rectangular_curvilinear_grid()
mk.curvilinear_move_node(10.0, 20.0, 18.0, 12.0)
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 35 的绘图输出](images/04_curvilineargrid_basics_35_0.png)
执行正交化。
```python
# 在正交化前检查节点位置
orthogonalization_parameters = OrthogonalizationParameters()
orthogonalization_parameters.outer_iterations = 1
orthogonalization_parameters.boundary_iterations = 25
orthogonalization_parameters.inner_iterations = 25
orthogonalization_parameters.orthogonalization_to_smoothing_factor = 0.95
# 初始化曲线网格正交化算法
# 设置要正交化的网格块(本例指定网格的左下角和右上角)
mk.curvilinear_orthogonalize(orthogonalization_parameters, 0.0, 0.0, 30.0, 30.0)
```
绘制正交化后的结果。
```python
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 39 的绘图输出](images/04_curvilineargrid_basics_39_0.png)
## 固定一条网格线进行曲线网格正交化
```python
mk = create_mk_instance_with_a_rectangular_curvilinear_grid()
mk.curvilinear_move_node(10.0, 20.0, 18.0, 12.0)
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 41 的绘图输出](images/04_curvilineargrid_basics_41_0.png)
执行正交化,同时固定被移动节点所在的垂直网格线。
```python
# 在正交化前检查节点位置
orthogonalization_parameters = OrthogonalizationParameters()
orthogonalization_parameters.outer_iterations = 1
orthogonalization_parameters.boundary_iterations = 25
orthogonalization_parameters.inner_iterations = 25
orthogonalization_parameters.orthogonalization_to_smoothing_factor = 0.95
# 固定被移动节点所在的垂直网格线
mk.curvilinear_frozen_line_add(10.0, 0.0, 10.0, 30.0)
# 执行正交化
# 初始化曲线网格正交化算法
# 设置要正交化的网格块(本例指定网格的左下角和右上角)
mk.curvilinear_orthogonalize(orthogonalization_parameters, 0.0, 0.0, 30.0, 30.0)
```
绘制正交化后的结果。
```python
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 45 的绘图输出](images/04_curvilineargrid_basics_45_0.png)
## 曲线网格平滑
移动一个节点,使网格不再平滑,并绘制结果。
```python
mk = create_mk_instance_with_a_rectangular_curvilinear_grid()
mk.curvilinear_move_node(10.0, 20.0, 18.0, 12.0)
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 48 的绘图输出](images/04_curvilineargrid_basics_48_0.png)
执行平滑。
```python
mk.curvilinear_smoothing(10, 0.0, 0.0, 30.0, 30.0)
```
绘制平滑后的结果。
```python
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 52 的绘图输出](images/04_curvilineargrid_basics_52_0.png)
## 曲线网格定向平滑
移动一个节点,使网格不再平滑,并绘制结果。
```python
mk = create_mk_instance_with_a_rectangular_curvilinear_grid()
mk.curvilinear_move_node(10.0, 20.0, 18.0, 12.0)
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 55 的绘图输出](images/04_curvilineargrid_basics_55_0.png)
执行定向平滑。
```python
mk.curvilinear_smoothing_directional(
10, # 平滑迭代次数
10.0,
0.0,
10.0,
30.0, # 用于定义平滑方向的网格线坐标
0.0,
0.0,
30.0,
30.0,
) # 要平滑的网格块角点
```
绘制定向平滑后的结果。
```python
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 59 的绘图输出](images/04_curvilineargrid_basics_59_0.png)
## 曲线网格线平移
```python
mk = create_mk_instance_with_a_rectangular_curvilinear_grid(5, 5)
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 61 的绘图输出](images/04_curvilineargrid_basics_61_0.png)
初始化网格线平移操作,并设置要移动的网格线。
```python
mk.curvilinear_initialize_line_shift()
mk.curvilinear_set_line_line_shift(0.0, 0.0, 0.0, 50.0)
```
设置用于分配网格线位移的网格块。
```python
mk.curvilinear_set_block_line_shift(0.0, 0.0, 20.0, 50.0)
```
将曲线网格左侧的所有节点向左移动。
```python
mk.curvilinear_move_node_line_shift(0.0, 0.0, -50.0, 0.0)
mk.curvilinear_move_node_line_shift(0.0, 10.0, -50.0, 10.0)
mk.curvilinear_move_node_line_shift(0.0, 20.0, -50.0, 20.0)
mk.curvilinear_move_node_line_shift(0.0, 30.0, -50.0, 30.0)
mk.curvilinear_move_node_line_shift(0.0, 40.0, -50.0, 40.0)
mk.curvilinear_move_node_line_shift(0.0, 50.0, -50.0, 50.0)
```
执行网格线平移。前面指定网格块以外的节点不会移动。
```python
mk.curvilinear_line_shift()
```
```python
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 70 的绘图输出](images/04_curvilineargrid_basics_70_0.png)
## 在曲线网格中插入网格面
```python
mk = create_mk_instance_with_a_rectangular_curvilinear_grid(5, 5)
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 72 的绘图输出](images/04_curvilineargrid_basics_72_0.png)
插入两个网格面。
```python
mk.curvilinear_insert_face(-10.0, 5.0)
mk.curvilinear_insert_face(-5.0, 10.0)
```
```python
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 75 的绘图输出](images/04_curvilineargrid_basics_75_0.png)
## 删除曲线网格节点
```python
mk = create_mk_instance_with_a_rectangular_curvilinear_grid(5, 5)
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 77 的绘图输出](images/04_curvilineargrid_basics_77_0.png)
删除角点节点。
```python
mk.curvilinear_delete_node(0.0, 0.0)
```
```python
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 80 的绘图输出](images/04_curvilineargrid_basics_80_0.png)
## 曲线网格线吸引与排斥
将网格块内的节点向指定网格线吸引。
```python
mk = create_mk_instance_with_a_rectangular_curvilinear_grid(5, 5)
mk.curvilinear_line_attraction_repulsion(
1.0, # 正值表示排斥网格线,此处为列宽的 1 倍
30.0,
0.0,
30.0,
50.0, # 网格线坐标
10.0,
0.0,
50.0,
50.0,
) # 受影响的网格块
```
```python
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 84 的绘图输出](images/04_curvilineargrid_basics_84_0.png)
```python
mk = create_mk_instance_with_a_rectangular_curvilinear_grid(5, 5)
mk.curvilinear_line_attraction_repulsion(
-1.0, # 负值表示吸引网格线,此处为列宽的 0.5 倍
30.0,
0.0,
30.0,
50.0, # 网格线坐标
10.0,
0.0,
50.0,
50.0,
) # 受影响的网格块
```
```python
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 86 的绘图输出](images/04_curvilineargrid_basics_86_0.png)
## 曲线网格线镜像扩展
以两倍列宽对左侧网格线进行镜像扩展。
```python
mk = create_mk_instance_with_a_rectangular_curvilinear_grid(5, 5)
# 镜像系数、要镜像的网格线数量以及目标网格线
mk.curvilinear_line_mirror(2.0, 1, 0.0, 0.0, 0.0, 50.0)
```
```python
curvilinear_grid = mk.curvilineargrid_get()
fig, ax = plt.subplots()
curvilinear_grid.plot_edges(ax)
```
![单元格 90 的绘图输出](images/04_curvilineargrid_basics_90_0.png)
@@ -0,0 +1,140 @@
# 基于规则网格采样数据的二维网格加密
本教程简要介绍如何使用规则网格采样数据进行网格加密。加密时,通过双线性插值计算网格节点处的水深值。
[返回示例目录](index.md)
以下保留原笔记本的代码和已保存输出;转换过程中未重新执行代码。
首先导入所需的库。
```python
import matplotlib.pyplot as plt
import numpy as np
from meshkernel import (
GeometryList,
GriddedSamples,
MakeGridParameters,
MeshKernel,
MeshRefinementParameters,
RefinementType,
)
```
`meshkernel` 提供了一组便捷方法,用于创建常见网格。
这里使用 `curvilinear_compute_rectangular_grid` 方法创建一个简单的曲线网格。该方法的完整参数请参阅相应文档。
```python
mk = MeshKernel()
make_grid_parameters = MakeGridParameters()
make_grid_parameters.num_columns = 4
make_grid_parameters.num_rows = 5
make_grid_parameters.angle = 0.0
make_grid_parameters.origin_x = 0.0
make_grid_parameters.origin_y = 0.0
make_grid_parameters.block_size_x = 100.0
make_grid_parameters.block_size_y = 100.0
mk.curvilinear_compute_rectangular_grid(make_grid_parameters)
```
将曲线网格转换为非结构网格,并获取生成的 `mesh2d`。
```python
mk.curvilinear_convert_to_mesh2d()
mesh2d_input = mk.mesh2d_get()
```
生成的网格可以按如下方式可视化。
```python
fig, ax = plt.subplots()
mesh2d_input.plot_edges(ax, color="black")
```
![单元格 8 的绘图输出](images/05_mesh2d_refinement_gridded_samples_8_0.png)
定义均匀间距的网格采样数据。
```python
gridded_samples = GriddedSamples(
num_x=5,
num_y=6,
x_origin=-50.0,
y_origin=-50.0,
cell_size=100.0,
values=np.array([-0.05] * 42, dtype=np.float32),
)
```
设置网格加密算法的参数。
```python
refinement_params = MeshRefinementParameters(
refine_intersected=False,
use_mass_center_when_refining=False,
min_edge_size=2.0,
refinement_type=RefinementType.WAVE_COURANT,
connect_hanging_nodes=True,
account_for_samples_outside_face=False,
max_refinement_iterations=5,
)
```
现在可以执行加密。
```python
mk.mesh2d_refine_based_on_gridded_samples(gridded_samples, refinement_params, True)
```
绘制加密后的网格。
```python
mesh2d_output = mk.mesh2d_get()
fig, ax = plt.subplots()
mesh2d_output.plot_edges(ax, color="black")
```
![单元格 16 的绘图输出](images/05_mesh2d_refinement_gridded_samples_16_0.png)
如果采样网格间距不均匀,可以省略部分 `GriddedSamples` 参数,以另一种方式创建网格采样数据。
首先重新生成初始网格。
```python
mk.curvilinear_compute_rectangular_grid(make_grid_parameters)
mk.curvilinear_convert_to_mesh2d()
```
```python
fig, ax = plt.subplots()
mesh2d_input.plot_edges(ax, color="black")
```
![单元格 19 的绘图输出](images/05_mesh2d_refinement_gridded_samples_19_0.png)
当采样网格的 x 或 y 方向间距不均匀时,可以使用 `x_coordinates` 和 `y_coordinates` 参数指定非均匀间距。
```python
gridded_samples = GriddedSamples(
x_coordinates=np.array([-50.0, 50.0, 150.0, 250.0, 350.0, 450.0], dtype=np.double),
y_coordinates=np.array(
[-50.0, 50.0, 150.0, 250.0, 350.0, 450.0, 550.0], dtype=np.double
),
values=np.array([-0.05] * 42, dtype=np.float32),
)
```
```python
mk.mesh2d_refine_based_on_gridded_samples(gridded_samples, refinement_params, True)
```
```python
mesh2d_output = mk.mesh2d_get()
fig, ax = plt.subplots()
mesh2d_output.plot_edges(ax, color="black")
```
![单元格 23 的绘图输出](images/05_mesh2d_refinement_gridded_samples_23_0.png)
@@ -0,0 +1,247 @@
# 基于不同水深精度的 GEBCO 网格采样数据进行二维网格加密
本教程简要介绍如何使用 GEBCO 全球数据集中的网格采样数据进行网格加密。
同时演示以下操作:
1. 在指定范围内生成网格。
2. 将生成的网格保存为 UGrid 文件。
3. 从大型 NetCDF 文件中读取水深数据。
4. 根据均匀间距水深采样数据(较快)或非均匀间距水深采样数据(较慢)进行网格加密。
[返回示例目录](index.md)
以下保留原笔记本的代码和已保存输出;转换过程中未重新执行代码。
导入所需的库,并关闭所有图窗。
```python
import meshkernel
import numpy as np
import matplotlib.pyplot as plt
plt.close("all")
```
# 1. 在指定范围内生成网格
```python
# 通用设置
lon_min, lon_max = -1, -0.2
lat_min, lat_max = 49.1, 49.6
lon_res, lat_res = 0.1, 0.1
figsize = (10, 4)
crs = "EPSG:4326"
"""
Make a regular (potentially rotated) rectilinear grid. First generate a curvilinear grid than convert the curvilinear grid into unstructured grid. The steps are the following:
- curvilinear_compute_uniform_on_extension, see the following notebook: https://github.com/Deltares/MeshKernelPy/blob/AddCurvilinearGridSupport/docs/examples/04_curvilineargrid_basics.ipynb
- curvilinear_convert_to_mesh2d: https://github.com/Deltares/MeshKernelPy/blob/118cb4953c4e95d5b18ed283bb37f391134b2bb2/meshkernel/meshkernel.py#L1399
"""
# 创建 MakeGridParameters 实例并设置参数值
make_grid_parameters = meshkernel.MakeGridParameters()
make_grid_parameters.origin_x = lon_min
make_grid_parameters.origin_y = lat_min
make_grid_parameters.upper_right_x = lon_max
make_grid_parameters.upper_right_y = lat_max
make_grid_parameters.block_size_x = lon_res
make_grid_parameters.block_size_y = lat_res
mk2 = meshkernel.MeshKernel(projection=meshkernel.ProjectionType.SPHERICAL)
mk2.curvilinear_compute_rectangular_grid_on_extension(make_grid_parameters)
mk2.curvilinear_convert_to_mesh2d() # 转换为 UGrid/二维网格
mesh2d = mk2.mesh2d_get()
fig, ax = plt.subplots()
mesh2d.plot_edges(ax)
```
![单元格 4 的绘图输出](images/06_mesh2d_refinement_gridded_samples_gebco_4_0.png)
# 2. 将生成的网格保存为 UGrid 文件
可以使用以下代码将生成的网格保存为 UGrid 文件。执行这些代码前,需要安装 UGrid Python 包。
```python
ugrid_installed = False
if ugrid_installed:
from ugrid import UGrid, UGridMesh2D
mesh2d_ugrid = UGrid.from_meshkernel_mesh2d_to_ugrid_mesh2d(
mesh2d=mesh2d, name="mesh2d", is_spherical=True
)
attribute_dict = {
"name": "Unknown projected",
"epsg": np.array([4326], dtype=int),
"grid_mapping_name": "Unknown projected",
"longitude_of_prime_meridian": np.array([0.0], dtype=float),
"semi_major_axis": np.array([6378137.0], dtype=float),
"semi_minor_axis": np.array([6356752.314245], dtype=float),
"inverse_flattening": np.array([6356752.314245], dtype=float),
"EPSG_code": "EPSG:4326",
"value": "value is equal to EPSG code",
}
with UGrid("./gebco_mesh2d_net.nc", "w+") as ug:
# 1. 定义新的二维网格
topology_id = ug.mesh2d_define(mesh2d_ugrid)
# 3. 写入新的二维网格
ug.mesh2d_put(topology_id, mesh2d_ugrid)
# 3. 将坐标参考系统添加到文件
ug.variable_int_with_attributes_define("wgs84", attribute_dict)
# 4. 添加数据约定(全局属性)
conventions = {
"institution": "Deltares",
"references": "Unknown",
"source": "Unknown Unknown. Model: Unknown",
"history": "Created on 2017-11-27T18:05:09+0100, Unknown",
"Conventions": "CF-1.6 UGRID-1.0/Deltares-0.8",
}
ug.attribute_global_define(conventions)
```
# 3. 从大型 NetCDF 文件中读取水深数据
可以使用 `xarray` 从大型数据集中读取水深数据,它支持仅加载选定区域的数据。当按非均匀间距处理经纬度数组时,双线性插值的速度较慢。
```python
# 选择并绘制水深数据
uniform_grid_spacing = False
if not uniform_grid_spacing:
import xarray as xr
file_nc_bathy = r"p:\metocean-data\open\GEBCO\2021\GEBCO_2021.nc"
data_bathy = xr.open_dataset(file_nc_bathy)
data_bathy_sel = data_bathy.sel(
lon=slice(lon_min - 1 / 4, lon_max + 1 / 4),
lat=slice(lat_min - 1 / 4, lat_max + 1 / 4),
)
lon_np = data_bathy_sel.lon.to_numpy().flatten().astype("float")
lat_np = data_bathy_sel.lat.to_numpy().flatten().astype("float")
values_np = data_bathy_sel.elevation.to_numpy().flatten().astype("float32")
```
另一种方式是从 ASCII 文件读取数据,并假设采样间距均匀。
```python
def read_asc_file(file_path, dtype=np.float32):
"""读取 ASC 文件,返回文件头和 NumPy 数组形式的数据。
参数:
file_path (str):文件路径。
返回值:
header:ASCII 文件头。
data:以双精度 NumPy 数组表示的 ASCII 数据。
"""
header = {}
data = []
with open(file_path, "r") as file:
# 读取文件头信息
for _ in range(6):
line = file.readline().strip().split()
header[line[0]] = float(line[1])
# 读取数据值
for line in file:
data_row = [float(value) for value in line.strip().split()]
data.insert(0, data_row) # 将该行插入到开头
# 将数据展平
data = np.array(data).flatten().astype(dtype)
return header, data
```
# 4. 基于网格采样数据进行加密:水深类型为 np.float32 或 np.int16
将文件中的水深读取为 `np.float32`。
```python
header, values_np = read_asc_file("./data_examples/gebco.asc", dtype=np.float32)
```
将文件中的水深读取为 `np.int16`。
```python
header, values_np = read_asc_file("./data_examples/gebco.asc", dtype=np.int16)
```
采样网格属性。
```python
num_x = int(header["ncols"])
num_y = int(header["nrows"])
x_origin = header["xllcenter"]
y_origin = header["yllcenter"]
```
网格采样数据。
```python
gridded_samples = meshkernel.GriddedSamples(
num_x=num_x,
num_y=num_y,
x_origin=x_origin,
y_origin=y_origin,
cell_size=0.0041666666666,
values=values_np,
)
```
另一种方式是通过非均匀间距的 x、y 坐标数组生成网格采样数据。
```python
if not uniform_grid_spacing:
gridded_samples = meshkernel.GriddedSamples(
x_coordinates=lon_np,
y_coordinates=lat_np,
num_x=len(lon_np),
num_y=len(lat_np),
values=values_np,
)
```
定义网格加密参数。
```python
mesh_refinement_parameters = meshkernel.MeshRefinementParameters(
refine_intersected=False,
use_mass_center_when_refining=False,
min_edge_size=500,
refinement_type=meshkernel.RefinementType.WAVE_COURANT,
connect_hanging_nodes=True,
account_for_samples_outside_face=False,
max_refinement_iterations=3,
smoothing_iterations=5,
max_courant_time=120.0,
directional_refinement=0,
)
```
执行加密,此处使用双线性插值。
```python
mk2.mesh2d_refine_based_on_gridded_samples(
gridded_samples=gridded_samples,
mesh_refinement_params=mesh_refinement_parameters,
use_nodal_refinement=True,
)
```
绘制加密后的网格。
```python
# 放大绘图,以观察零散的海岸线
fig1 = plt.figure(figsize=(16, 12))
ax1 = fig1.add_subplot(111)
mesh2d_grid2 = mk2.mesh2d_get()
mesh2d_grid2.plot_edges(ax1, linewidth=1)
```
![单元格 29 的绘图输出](images/06_mesh2d_refinement_gridded_samples_gebco_29_0.png)
@@ -0,0 +1,97 @@
# 在指定范围内生成曲线网格
本教程简要介绍如何在指定范围内生成曲线网格。
[返回示例目录](index.md)
以下保留原笔记本的代码和已保存输出;转换过程中未重新执行代码。
首先导入所需的库。
```python
import matplotlib.pyplot as plt
import numpy as np
from meshkernel import (
GeometryList,
GriddedSamples,
MakeGridParameters,
MeshKernel,
MeshRefinementParameters,
ProjectionType,
RefinementType,
)
```
## 在球面坐标系中创建曲线网格
网格从原点延伸到右上角,自动计算行数和列数,并调整纬度,使实际距离上的纵横比接近 1。
```python
lon_min, lon_max = -1, -0.2
lat_min, lat_max = 49.1, 49.6
lon_res, lat_res = 0.1, 0.1
make_grid_parameters = MakeGridParameters()
make_grid_parameters.origin_x = lon_min
make_grid_parameters.origin_y = lat_min
make_grid_parameters.upper_right_x = lon_max
make_grid_parameters.upper_right_y = lat_max
make_grid_parameters.block_size_x = lon_res
make_grid_parameters.block_size_y = lat_res
mk = MeshKernel(projection=ProjectionType.SPHERICAL)
mk.curvilinear_compute_rectangular_grid_on_extension(make_grid_parameters)
```
将曲线网格转换为非结构网格。
```python
mk.curvilinear_convert_to_mesh2d()
```
绘制网格。
```python
mesh2d = mk.mesh2d_get()
fig, ax = plt.subplots()
mesh2d.plot_edges(ax, color="black")
```
![单元格 9 的绘图输出](images/07_curvilineargrid_with_defined_extension_9_0.png)
## 在笛卡尔坐标系中创建曲线网格
在笛卡尔坐标系中,无需调整 y 坐标。
```python
min_x, min_y = 0, 0
max_x, max_y = 10.0, 10.0
block_size_x, block_size_y = 1, 2
make_grid_parameters = MakeGridParameters()
make_grid_parameters.origin_x = min_x
make_grid_parameters.origin_y = min_y
make_grid_parameters.upper_right_x = max_x
make_grid_parameters.upper_right_y = max_y
make_grid_parameters.block_size_x = block_size_x
make_grid_parameters.block_size_y = block_size_y
mk = MeshKernel(projection=ProjectionType.CARTESIAN)
mk.curvilinear_compute_rectangular_grid_on_extension(make_grid_parameters)
```
将曲线网格转换为非结构网格。
```python
mk.curvilinear_convert_to_mesh2d()
```
绘制网格。
```python
mesh2d = mk.mesh2d_get()
fig, ax = plt.subplots()
mesh2d.plot_edges(ax, color="black")
```
![单元格 16 的绘图输出](images/07_curvilineargrid_with_defined_extension_16_0.png)
@@ -0,0 +1,124 @@
# 大型网格正交化
[返回示例目录](index.md)
以下保留原笔记本的代码和已保存输出;转换过程中未重新执行代码。
本示例演示如何加载大型二维网格并进行正交化。首先导入所需的库。这里还使用 UGrid 库正确加载二维网格。
```python
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from meshkernel import (
GeometryList,
MeshKernel,
OrthogonalizationParameters,
ProjectionType,
Mesh2d,
)
from ugrid import UGrid, UGridMesh2D
```
定义正交性阈值和文件名。
```python
orthogonality_criteria = 0.3
input_file = "./Michigan_Huron_ORTHO_mc025_mn5_net.nc"
output_file = "./Michigan_Huron_orthogonality_issues.xyz"
```
读取网格几何数据。
```python
with UGrid(input_file, "r") as ug:
num_mesh2d_topologies = ug.mesh2d_get_num_topologies()
mesh2d_ugrid = ug.mesh2d_get(num_mesh2d_topologies - 1)
```
根据节点和边创建 `meshkernel` 的二维网格。
```python
mesh2d_mk = Mesh2d()
mesh2d_mk.node_x = mesh2d_ugrid.node_x
mesh2d_mk.node_y = mesh2d_ugrid.node_y
mesh2d_mk.edge_nodes = mesh2d_ugrid.edge_nodes
```
创建 `MeshKernel` 实例。
```python
mk = MeshKernel(ProjectionType.SPHERICAL)
```
设置网格,此调用计算开销较大。
```python
mk.mesh2d_set(mesh2d_mk)
```
获取网格。
```python
mesh2d_output = mk.mesh2d_get()
```
```python
fig, ax = plt.subplots()
mesh2d_output.plot_edges(ax, color="black")
```
![单元格 15 的绘图输出](images/08_mesh2d_orthogonalization_15_0.png)
查询正交性,此调用计算开销较大。
```python
orthogonality = mk.mesh2d_get_orthogonality().values
```
提取正交性指标值高于 `orthogonality_criteria` 的边。
```python
criteria_indices = np.where(orthogonality > orthogonality_criteria)[0]
```
将提取的边保存到文件。
```python
xyz_df = pd.DataFrame([])
xyz_df["edge_x"] = mesh2d_output.edge_x[criteria_indices]
xyz_df["edge_y"] = mesh2d_output.edge_y[criteria_indices]
xyz_df["orthogonality"] = orthogonality[criteria_indices]
xyz_df.to_csv(output_file, index=False, header=False, sep=" ")
```
## 执行正交化
```python
selecting_polygon = GeometryList(
np.empty(0, dtype=np.double), np.empty(0, dtype=np.double)
)
land_boundaries = GeometryList(
np.empty(0, dtype=np.double), np.empty(0, dtype=np.double)
)
```
```python
mk.mesh2d_compute_orthogonalization(
project_to_land_boundary_option=0,
orthogonalization_parameters=OrthogonalizationParameters(outer_iterations=1),
selecting_polygon=selecting_polygon,
land_boundaries=land_boundaries,
)
```
```python
mesh2d_output = mk.mesh2d_get()
```
```python
fig, ax = plt.subplots()
mesh2d_output.plot_edges(ax, color="black")
```
![单元格 26 的绘图输出](images/08_mesh2d_orthogonalization_26_0.png)
@@ -0,0 +1,304 @@
# 网格删除
[返回示例目录](index.md)
以下保留原笔记本的代码和已保存输出;转换过程中未重新执行代码。
本教程演示球面坐标下的网格删除操作。首先导入所需的库。
```python
import meshkernel
import matplotlib.pyplot as plt
import numpy as np
from pathlib import Path
import datetime as dt
```
## 删除简单网格
创建矩形网格。
```python
lon_min, lon_max = -2.5, -1.3
lat_min, lat_max = 48.4, 49.0
lon_res, lat_res = 0.01, 0.01
make_grid_parameters = meshkernel.MakeGridParameters()
make_grid_parameters.origin_x = lon_min
make_grid_parameters.origin_y = lat_min
make_grid_parameters.upper_right_x = lon_max
make_grid_parameters.upper_right_y = lat_max
make_grid_parameters.block_size_x = lon_res
make_grid_parameters.block_size_y = lat_res
mk2 = meshkernel.MeshKernel(projection=meshkernel.ProjectionType.SPHERICAL)
mk2.get_projection()
mk2.curvilinear_compute_rectangular_grid_on_extension(make_grid_parameters)
mk2.curvilinear_convert_to_mesh2d()
mesh2d_orig = mk2.mesh2d_get()
```
创建用于删除操作的多边形。
```python
pol_x = np.array(
[
-2.554972,
-2.475056,
-2.488361,
-2.4375,
-2.418417,
-2.319139,
-2.313333,
-2.28625,
-2.336694,
-2.314167,
-2.246722,
-2.213361,
-2.195028,
-2.182472,
-2.157944,
-2.175444,
-2.152528,
-2.125889,
-2.152528,
-2.04925,
-2.057944,
-2.032111,
-2.034639,
-1.997083,
-2.015472,
-1.975028,
-1.962972,
-1.989667,
-1.957139,
-2.015056,
-2.004583,
-2.033,
-1.98925,
-1.992556,
-1.941667,
-1.962972,
-1.935056,
-1.905028,
-1.843389,
-1.837111,
-1.872111,
-1.842528,
-1.771667,
-1.635028,
-1.592528,
-1.511722,
-1.51,
-1.470056,
-1.43,
-1.3575,
-1.412889,
-1.389222,
-1.447583,
-1.453361,
-1.505028,
-1.530056,
-1.570444,
-1.576278,
-1.615444,
-1.580417,
-1.2,
-1.2,
-2.6,
-2.554972,
]
)
pol_y = np.array(
[
48.599583,
48.622889,
48.64625,
48.653722,
48.634556,
48.690389,
48.672083,
48.667444,
48.620389,
48.612111,
48.645444,
48.57375,
48.611222,
48.577889,
48.587472,
48.597472,
48.618722,
48.604528,
48.633694,
48.639583,
48.625833,
48.624972,
48.604944,
48.578306,
48.571667,
48.536222,
48.549944,
48.583333,
48.578306,
48.598722,
48.614111,
48.650806,
48.668722,
48.684583,
48.684583,
48.689972,
48.702917,
48.690417,
48.712083,
48.679972,
48.645806,
48.616222,
48.603722,
48.617889,
48.639611,
48.621222,
48.632056,
48.625417,
48.643722,
48.63375,
48.659139,
48.67625,
48.655389,
48.672083,
48.687056,
48.73125,
48.744167,
48.821639,
48.835806,
48.856639,
48.9,
48.3,
48.3,
48.599583,
]
)
```
执行网格删除。由于网格较大,可能需要约一分钟。
```python
delete_pol_geom = meshkernel.GeometryList(x_coordinates=pol_x, y_coordinates=pol_y)
print("Deleting grid with coastlines: ", end="")
dtstart = dt.datetime.now()
mk2.mesh2d_delete(
geometry_list=delete_pol_geom,
delete_option=meshkernel.DeleteMeshOption.INSIDE_NOT_INTERSECTED,
invert_deletion=False,
)
print(f"{(dt.datetime.now()-dtstart).total_seconds():.2f} sec")
```
```text
Deleting grid with coastlines: 0.02 sec
```
绘制删除后的结果。
```python
plt.close("all")
figsize = (8, 4)
mesh2d = mk2.mesh2d_get()
fig, ax = plt.subplots(figsize=figsize)
mesh2d_orig.plot_edges(ax, color="grey")
mesh2d.plot_edges(ax, color="k")
ax.plot(pol_x, pol_y, "r", linewidth=1)
ax.set_ylim(lat_min - 0.11, lat_max)
```
```text
(48.29, 49.0)
```
![单元格 11 的绘图输出](images/09_mesh2d_deletion_11_1.png)
## 使用全球多边形删除网格
创建矩形网格。
```python
lon_min, lon_max = -6, 2
lat_min, lat_max = 48.5, 51.2
lon_res, lat_res = 0.2, 0.2
make_grid_parameters = meshkernel.MakeGridParameters()
make_grid_parameters.origin_x = lon_min
make_grid_parameters.origin_y = lat_min
make_grid_parameters.upper_right_x = lon_max
make_grid_parameters.upper_right_y = lat_max
make_grid_parameters.block_size_x = lon_res
make_grid_parameters.block_size_y = lat_res
mk = meshkernel.MeshKernel(projection=meshkernel.ProjectionType.SPHERICAL)
mk.curvilinear_compute_rectangular_grid_on_extension(make_grid_parameters)
mk.curvilinear_convert_to_mesh2d()
mesh2d = mk.mesh2d_get()
mesh2d_orig = mk.mesh2d_get()
num_faces_before = len(mesh2d.face_x)
num_columns = int((lat_max - lat_min) / 0.2)
num_rows = int((lon_max - lon_min) / 0.2)
print("num_faces_before ", num_faces_before)
print("num_columns ", num_columns)
print("num_rows ", num_rows)
```
```text
num_faces_before 1120
num_columns 13
num_rows 40
```
导入全球海岸线,约包含 130,000 条线段。
```python
polygon_file_path = Path().absolute() / "data_examples" / "global_coastline.pol"
polygon_np = np.loadtxt(polygon_file_path, comments="*", skiprows=2, dtype=np.double)
pol_x = np.array(polygon_np[:, 0], dtype=np.double)
pol_y = np.array(polygon_np[:, 1], dtype=np.double)
```
```python
print(">> deleting grid with coastlines: ", end="")
dtstart = dt.datetime.now()
delete_pol_geom = meshkernel.GeometryList(x_coordinates=pol_x, y_coordinates=pol_y)
mk.mesh2d_delete(
geometry_list=delete_pol_geom,
delete_option=meshkernel.DeleteMeshOption.INSIDE_NOT_INTERSECTED,
invert_deletion=False,
)
print(f"{(dt.datetime.now()-dtstart).total_seconds():.2f} sec")
```
```text
>> deleting grid with coastlines: 1.36 sec
```
```python
plt.close("all")
figsize = (8, 4)
mesh2d = mk.mesh2d_get()
fig, ax = plt.subplots(figsize=figsize)
mesh2d_orig.plot_edges(ax, color="grey")
mesh2d.plot_edges(ax, color="k")
ax.plot(pol_x, pol_y, "r", linewidth=1)
ax.set_xlim(lon_min, lon_max)
ax.set_ylim(lat_min, lat_max)
num_faces_after = len(mesh2d.face_x)
print("num_faces_after ", num_faces_before)
print("deleted faces ", num_faces_before - num_faces_after)
```
```text
num_faces_after 1120
deleted faces 213
```
![单元格 18 的绘图输出](images/09_mesh2d_deletion_18_1.png)
@@ -0,0 +1,30 @@
# 生成全球网格
[返回示例目录](index.md)
以下保留原笔记本的代码和已保存输出;转换过程中未重新执行代码。
本教程演示如何在球面坐标系中生成全球网格。
```python
import meshkernel
import matplotlib.pyplot as plt
```
```python
mk = meshkernel.MeshKernel(projection=meshkernel.ProjectionType.SPHERICAL)
mk.mesh2d_make_global(num_longitude_nodes=192, num_latitude_nodes=100)
mesh2d = mk.mesh2d_get()
```
绘制结果。
```python
plt.close("all")
figsize = (20, 10)
mesh2d = mk.mesh2d_get()
fig, ax = plt.subplots(figsize=figsize)
mesh2d.plot_edges(ax, color="k")
```
![单元格 5 的绘图输出](images/10_mesh2d_global_grid_5_0.png)
@@ -0,0 +1,161 @@
# 基于网格采样数据的二维网格脊线加密
[返回示例目录](index.md)
以下保留原笔记本的代码和已保存输出;转换过程中未重新执行代码。
首先导入所需的库。
```python
import matplotlib.pyplot as plt
import numpy as np
from meshkernel import (
GeometryList,
GriddedSamples,
MakeGridParameters,
MeshKernel,
MeshRefinementParameters,
RefinementType,
GriddedSamples,
)
```
`meshkernel` 提供了一组便捷方法,用于创建常见网格。
这里使用 `curvilinear_compute_rectangular_grid` 方法创建一个简单的曲线网格。该方法的完整参数请参阅相应文档。
```python
mk = MeshKernel()
num_rows = 21
num_columns = 41
make_grid_parameters = MakeGridParameters()
make_grid_parameters.num_columns = num_columns
make_grid_parameters.num_rows = num_rows
make_grid_parameters.angle = 0.0
make_grid_parameters.origin_x = 0.0
make_grid_parameters.origin_y = 0.0
make_grid_parameters.block_size_x = 10.0
make_grid_parameters.block_size_y = 10.0
mk.curvilinear_compute_rectangular_grid(make_grid_parameters)
```
将曲线网格转换为非结构网格,并获取生成的 `mesh2d`。
```python
mk.curvilinear_convert_to_mesh2d()
mesh2d_input = mk.mesh2d_get()
```
生成的网格可以按如下方式可视化。
```python
fig, ax = plt.subplots()
mesh2d_input.plot_edges(ax, color="black")
```
![单元格 8 的绘图输出](images/11_mesh2d_refine_ridges_gridded_samples_8_0.png)
定义均匀间距的网格采样数据。
```python
def read_asc_file(file_path, dtype=np.float32):
"""读取 ASC 文件,返回文件头和 NumPy 数组形式的数据。
参数:
file_path (str):文件路径。
返回值:
header:ASCII 文件头。
data:以双精度 NumPy 数组表示的 ASCII 数据。
"""
header = {}
data = []
with open(file_path, "r") as file:
# 读取文件头信息
for _ in range(6):
line = file.readline().strip().split()
header[line[0]] = float(line[1])
# 读取数据值
for line in file:
data_row = [float(value) for value in line.strip().split()]
data.insert(0, data_row) # 将该行插入到开头
# 将数据展平
data = np.array(data).flatten().astype(dtype)
return header, data
```
```python
header, values_np = read_asc_file("./data_examples/gaussian_bump.asc", dtype=np.float32)
```
绘制从 ASC 文件读取的数据。
```python
values_np_matrix = np.reshape(values_np, (int(header["nrows"]), int(header["ncols"])))
plt.imshow(values_np_matrix, cmap="viridis", interpolation="nearest")
plt.title("gaussian bump")
plt.show()
```
![单元格 13 的绘图输出](images/11_mesh2d_refine_ridges_gridded_samples_13_0.png)
假设间距均匀,将 ASCII 数据存入 `GriddedSamples` 实例。
```python
num_sample_x_coordinates = (num_columns - 1) * 2 + 1
num_sample_y_coordinates = (num_rows - 1) * 2 + 1
gridded_samples = GriddedSamples(
num_x=num_sample_x_coordinates,
num_y=num_sample_y_coordinates,
x_origin=0.0,
y_origin=-0.0,
cell_size=5.0,
values=values_np,
)
```
设置网格加密算法的参数。注意,必须正确设置脊线加密类型。
```python
refinement_params = MeshRefinementParameters(
refine_intersected=False,
use_mass_center_when_refining=False,
min_edge_size=2.0,
refinement_type=RefinementType.RIDGE_DETECTION,
connect_hanging_nodes=True,
account_for_samples_outside_face=False,
max_refinement_iterations=1,
)
```
现在可以执行加密。
```python
relative_search_radius = 1.01
minimum_num_samples = 1
number_of_smoothing_iterations = 0
mk.mesh2d_refine_ridges_based_on_gridded_samples(
gridded_samples=gridded_samples,
relative_search_radius=relative_search_radius,
minimum_num_samples=minimum_num_samples,
number_of_smoothing_iterations=number_of_smoothing_iterations,
mesh_refinement_params=refinement_params,
)
```
绘制加密后的网格。
```python
mesh2d_output = mk.mesh2d_get()
fig, ax = plt.subplots()
mesh2d_output.plot_edges(ax, color="black")
```
![单元格 21 的绘图输出](images/11_mesh2d_refine_ridges_gridded_samples_21_0.png)
@@ -0,0 +1,125 @@
# 基于含海岸线的网格采样数据进行二维网格加密
[返回示例目录](index.md)
以下保留原笔记本的代码和已保存输出;转换过程中未重新执行代码。
```python
import matplotlib.pyplot as plt
plt.close("all")
import xarray as xr
import numpy as np
import meshkernel
import contextily as ctx
from meshkernel import (
MakeGridParameters,
MeshKernel,
GriddedSamples,
ProjectionType,
MeshRefinementParameters,
RefinementType,
)
mk_version = meshkernel.__version__
```
### 水深采样数据
```python
# GEBCO 水深采样数据
lon_np = np.array(
[
-68.54791667,
-68.46458333,
-68.38125,
-68.29791667,
-68.21458333,
-68.13125,
-68.04791667,
-67.96458333,
]
)
lat_np = np.array(
[
11.80208333,
11.88541667,
11.96875,
12.05208333,
12.13541667,
12.21875,
12.30208333,
12.38541667,
12.46875,
12.55208333,
]
)
values_np_2d = np.array(
[
[-1700, -1769, -1688, -1641, -1526, -1291, -1121, -1537],
[-1561, -1674, -1354, -757, -837, -838, -1080, -1466],
[-1630, -1390, -710, -562, -479, -753, -1246, -1703],
[-1553, -1446, -1147, -248, -175, -712, -1621, -1920],
[-1503, -1380, -1080, -305, 18, -543, -1563, -2241],
[-1477, -1571, -3, 100, 11, -891, -1521, -2446],
[-1892, -1808, 16, -3102, -2015, -1302, -1484, -2581],
[-2516, -2091, -1957, -2647, -1422, -1486, -2340, -2702],
[-2689, -2353, -2614, -3612, -3058, -3017, -3181, -2848],
[-3110, -3025, -3861, -3927, -3818, -4162, -4386, -4504],
]
)
values_np = values_np_2d.flatten().astype(np.float32)
```
### 生成规则网格
```python
lon_min, lon_max, lat_min, lat_max = -68.55, -67.9, 11.8, 12.6
dx = dy = 0.05
make_grid_parameters = MakeGridParameters(
angle=0,
origin_x=lon_min,
origin_y=lat_min,
upper_right_x=lon_max,
upper_right_y=lat_max,
block_size_x=dx,
block_size_y=dy,
)
mk = MeshKernel(projection=ProjectionType(1))
mk.curvilinear_compute_rectangular_grid_on_extension(make_grid_parameters)
mk.curvilinear_convert_to_mesh2d() # 转换为 UGrid/二维网格
```
### 执行加密
```python
gridded_samples = GriddedSamples(
x_coordinates=lon_np, y_coordinates=lat_np, values=values_np
)
```
```python
mesh_refinement_parameters = MeshRefinementParameters(
min_edge_size=300, # 单位始终为米
refinement_type=RefinementType(1), # 波动库朗数加密类型,枚举值为 1
connect_hanging_nodes=True, # 设为 False 可分多步加密,例如分别处理多个区域
smoothing_iterations=2,
max_courant_time=120,
)
```
```python
mk.mesh2d_refine_based_on_gridded_samples(
gridded_samples=gridded_samples,
mesh_refinement_params=mesh_refinement_parameters,
use_nodal_refinement=True,
)
```
```python
fig, ax = plt.subplots()
mk.mesh2d_get().plot_edges(ax=ax, linewidth=1)
```
![单元格 10 的绘图输出](images/12_mesh2d_refine_gridded_samples_coastlines_10_0.png)
@@ -0,0 +1,82 @@
# 基于带步长数组的网格采样数据进行二维网格加密
[返回示例目录](index.md)
以下保留原笔记本的代码和已保存输出;转换过程中未重新执行代码。
```python
import matplotlib.pyplot as plt
plt.close("all")
import numpy as np
from meshkernel import (
MeshKernel,
ProjectionType,
MakeGridParameters,
GriddedSamples,
MeshRefinementParameters,
RefinementType,
)
import xarray as xr
```
### 导入水深采样数据并生成内存不连续的数组
```python
lon_min, lon_max, lat_min, lat_max = 142, 150, -42, -39
dxy = 0.5
file_nc_bathy = r"p:\metocean-data\open\GEBCO\2021\GEBCO_2021.nc"
data_bathy = xr.open_dataset(file_nc_bathy)
data_bathy_sel = data_bathy.sel(
lon=slice(lon_min, lon_max, 10), lat=slice(lat_min, lat_max, 10)
).elevation
```
### 生成矩形网格
```python
# 创建基础网格
make_grid_parameters = MakeGridParameters(
angle=0,
origin_x=lon_min,
origin_y=lat_min,
upper_right_x=lon_max,
upper_right_y=lat_max,
block_size_x=dxy,
block_size_y=dxy,
)
mk = MeshKernel(projection=ProjectionType(1))
mk.curvilinear_compute_rectangular_grid_on_extension(make_grid_parameters)
mk.curvilinear_convert_to_mesh2d()
```
### 加密网格
```python
lon_np = data_bathy_sel.lon.to_numpy()
lat_np = data_bathy_sel.lat.to_numpy()
values_np = data_bathy_sel.to_numpy().flatten().astype(np.float32)
gridded_samples = GriddedSamples(
x_coordinates=lon_np, y_coordinates=lat_np, values=values_np
)
# 网格加密
mesh_refinement_parameters = MeshRefinementParameters(
min_edge_size=1000, refinement_type=RefinementType.WAVE_COURANT
)
mk.mesh2d_refine_based_on_gridded_samples(
gridded_samples=gridded_samples, mesh_refinement_params=mesh_refinement_parameters
)
```
### 绘制加密后的网格
```python
fig, ax = plt.subplots()
mk.mesh2d_get().plot_edges(ax=ax, linewidth=1)
```
![单元格 9 的绘图输出](images/13_mesh2d_refine_gridded_samples_strided_arrays_9_0.png)
@@ -0,0 +1,137 @@
# 生成一维与二维网格之间的连接
本教程介绍使用 `meshkernel` 生成网格连接的基本方法。
[返回示例目录](index.md)
以下保留原笔记本的代码和已保存输出;转换过程中未重新执行代码。
```python
from meshkernel import MakeGridParameters, Mesh1d, Mesh2d, MeshKernel, GeometryList
from meshkernel.version import __version__
__version__
```
```text
'7.0.4'
```
导入其他所需的库。
```python
import numpy as np
from pathlib import Path
import matplotlib.pyplot as plt
```
```python
def plot_mesh_and_contacts(mesh1d_output_0, mesh2d_output_0, contacts_output_0=None):
fig, ax = plt.subplots()
mesh1d_output_0.plot_edges(ax, color="blue")
mesh2d_output_0.plot_edges(ax, color="black")
if contacts_output_0:
contacts_output_0.plot_edges(ax, mesh1d_output_0, mesh2d_output_0, color="red")
ax.plot(
mesh1d_output_0.node_x, mesh1d_output_0.node_y, "o", color="blue", markersize=5
)
plt.show()
```
# 设置二维网格和一维网格
```python
# 创建基础网格
mk = MeshKernel()
make_grid_parameters = MakeGridParameters(
angle=0,
origin_x=0.0,
origin_y=0.0,
upper_right_x=100.0,
upper_right_y=100.0,
block_size_x=10.0,
block_size_y=10.0,
)
mk.curvilinear_compute_rectangular_grid_on_extension(make_grid_parameters)
mk.curvilinear_convert_to_mesh2d()
mesh1d_node_x = [0.0, 50.0, 100.0]
mesh1d_node_y = [20.0, 20.0, 20.0]
mesh1d_edge_nodes = [0, 1, 1, 2]
mesh1d = Mesh1d(
node_x=mesh1d_node_x, node_y=mesh1d_node_y, edge_nodes=mesh1d_edge_nodes
)
mk.mesh1d_set(mesh1d)
```
```python
mesh1d_output_0 = mk.mesh1d_get()
mesh2d_output_0 = mk.mesh2d_get()
contacts_output_0 = mk.contacts_get()
plot_mesh_and_contacts(mesh1d_output_0, mesh2d_output_0, contacts_output_0)
```
![单元格 7 的绘图输出](images/14_contacts_generation_7_0.png)
## 计算连接
```python
node_mask = np.full(mesh1d.node_x.size, True)
```
#### 计算多重连接
```python
mk.contacts_compute_multiple(node_mask)
mesh1d_output_0 = mk.mesh1d_get()
mesh2d_output_0 = mk.mesh2d_get()
contacts_output_0 = mk.contacts_get()
plot_mesh_and_contacts(mesh1d_output_0, mesh2d_output_0, contacts_output_0)
```
![单元格 11 的绘图输出](images/14_contacts_generation_11_0.png)
#### 计算单一连接
```python
x_coordinates = np.array([0.0, 100.0, 100.0, 0.0, 0.0], dtype=np.double)
y_coordinates = np.array([0.0, 0.0, 100.0, 100.0, 0.0], dtype=np.double)
area_selection = GeometryList(x_coordinates, y_coordinates)
mk.contacts_compute_single(node_mask, area_selection, projection_factor=0.0)
mesh1d_output_0 = mk.mesh1d_get()
mesh2d_output_0 = mk.mesh2d_get()
contacts_output_0 = mk.contacts_get()
plot_mesh_and_contacts(mesh1d_output_0, mesh2d_output_0, contacts_output_0)
```
![单元格 13 的绘图输出](images/14_contacts_generation_13_0.png)
#### 根据指定点计算连接
```python
x_coordinates = np.array([10.000001], dtype=np.double)
y_coordinates = np.array([5.0], dtype=np.double)
point_cloud = GeometryList(x_coordinates, y_coordinates)
mk.contacts_compute_with_points(node_mask, point_cloud)
mesh1d_output_0 = mk.mesh1d_get()
mesh2d_output_0 = mk.mesh2d_get()
contacts_output_0 = mk.contacts_get()
plot_mesh_and_contacts(mesh1d_output_0, mesh2d_output_0, contacts_output_0)
```
![单元格 15 的绘图输出](images/14_contacts_generation_15_0.png)
### 计算边界连接
```python
mk.contacts_compute_boundary(node_mask, search_radius=50.0)
mesh1d_output_0 = mk.mesh1d_get()
mesh2d_output_0 = mk.mesh2d_get()
contacts_output_0 = mk.contacts_get()
plot_mesh_and_contacts(mesh1d_output_0, mesh2d_output_0, contacts_output_0)
```
![单元格 17 的绘图输出](images/14_contacts_generation_17_0.png)
@@ -0,0 +1,255 @@
# 基于水深的二维网格 Casulli 加密
!!! note "接口版本差异"
原示例代码使用旧名称 `mkernel_set_property` 和 `mkernel_mesh2d_casulli_refinement_based_on_depths`。当前 8.3.0 源码中的对应接口为 `mesh2d_set_property` 和 `mesh2d_casulli_refinement_based_on_depths`;实际运行时请依据 [完整 API 参考](../api/meshkernel.meshkernel.md) 调整。以下保留原示例代码。
[返回示例目录](index.md)
以下保留原笔记本的代码和已保存输出;转换过程中未重新执行代码。
```python
import matplotlib.pyplot as plt
from pathlib import Path
plt.close("all")
import xarray as xr
import numpy as np
import meshkernel
from meshkernel import (
MakeGridParameters,
MeshKernel,
GeometryList,
GriddedSamples,
ProjectionType,
MeshRefinementParameters,
RefinementType,
InterpolationType,
InterpolationParameters,
)
mk_version = meshkernel.__version__
```
# 示例 1:加密笛卡尔坐标网格
```python
mk = MeshKernel(ProjectionType.CARTESIAN)
x_start, x_end = 0, 10000
y_min, y_max = 0, 10000
num_samples = 100
makeGridParameters = MakeGridParameters()
makeGridParameters.origin_x = x_start
makeGridParameters.origin_y = y_min
makeGridParameters.upper_right_x = x_end
makeGridParameters.upper_right_y = y_max
makeGridParameters.block_size_x = 1000
makeGridParameters.block_size_y = 1000
mk.mesh2d_make_rectangular_mesh_on_extension(makeGridParameters)
```
### 绘制初始笛卡尔坐标网格
```python
mesh2d_not_refined = mk.mesh2d_get()
fig, ax = plt.subplots()
mesh2d_not_refined.plot_edges(ax)
```
![单元格 5 的绘图输出](images/15_mesh2d_refinement_casulli_based_on_depths_5_0.png)
```python
x_grid, y_grid = np.meshgrid(
np.linspace(x_start, x_end, num_samples), np.linspace(y_min, y_max, num_samples)
)
values = np.array(np.interp(x_grid, [x_start, x_end], [-10.0, 5.0]), dtype=np.double)
```
### 绘制采样数据集
```python
plt.figure(figsize=(8, 6))
plt.contourf(x_grid, y_grid, values, levels=50)
```
```text
<matplotlib.contour.QuadContourSet at 0x1f054cec790>
```
![单元格 8 的绘图输出](images/15_mesh2d_refinement_casulli_based_on_depths_8_1.png)
```python
samples = GeometryList(
x_coordinates=np.array(x_grid.flatten(), dtype=np.double),
y_coordinates=np.array(y_grid.flatten(), dtype=np.double),
values=np.array(values.flatten(), dtype=np.double),
)
interpolation_parameters = InterpolationParameters()
interpolation_parameters.interpolation_type = InterpolationType.AVERAGING
property_id = mk.mkernel_set_property(interpolation_parameters, samples)
x_coordinates_pol = np.empty(0, dtype=np.double)
y_coordinates_pol = np.empty(0, dtype=np.double)
polygons = GeometryList(
x_coordinates=x_coordinates_pol, y_coordinates=y_coordinates_pol
)
meshRefinementParameters = MeshRefinementParameters()
minimumRefinementDepth = 0.0
mk.mkernel_mesh2d_casulli_refinement_based_on_depths(
polygons, property_id, meshRefinementParameters, minimumRefinementDepth
)
```
### 绘制加密后的网格(应能看到变化)
```python
mesh2d_refined = mk.mesh2d_get()
fig, ax = plt.subplots()
mesh2d_refined.plot_edges(ax)
```
![单元格 11 的绘图输出](images/15_mesh2d_refinement_casulli_based_on_depths_11_0.png)
# 示例 2:使用较小区域的真实水深数据进一步细化分析
## 读取采样数据的辅助函数
```python
def read_and_filter_samples(file_path, lower_left, upper_right):
"""
读取包含采样数据(纬度、经度、水深)的文本文件,筛选边界框内的采样点,
返回三个双精度 NumPy 数组(纬度、经度、水深)。
:param file_path: 包含数据的文本文件路径。
:param lower_left: 边界框左下角的(纬度、经度)元组。
:param upper_right: 边界框右上角的(纬度、经度)元组。
:return: 包含纬度、经度、水深三个 NumPy 数组的元组。
"""
latitudes = []
longitudes = []
depths = []
# 解包边界框角点坐标
ll_lat, ll_long = lower_left
ur_lat, ur_long = upper_right
try:
with open(file_path, "r") as file:
for line in file:
# 将该行解析为纬度、经度和水深
parts = line.strip().split("\t")
if len(parts) != 3:
continue
try:
lat, long, depth = map(float, parts)
except ValueError:
continue
# 检查采样点是否位于边界框内
if ll_lat <= lat <= ur_lat and ll_long <= long <= ur_long:
latitudes.append(lat)
longitudes.append(long)
depths.append(depth)
except FileNotFoundError:
print(f"Error: File {file_path} not found.")
return (
np.array([], dtype=np.double),
np.array([], dtype=np.double),
np.array([], dtype=np.double),
)
except Exception as e:
print(f"An error occurred: {e}")
return (
np.array([], dtype=np.double),
np.array([], dtype=np.double),
np.array([], dtype=np.double),
)
# 将列表转换为 double 类型的 NumPy 数组
return (
np.array(latitudes, dtype=np.double),
np.array(longitudes, dtype=np.double),
np.array(depths, dtype=np.double),
)
```
```python
input_file = "stpete.xyz"
input_file_path = Path().absolute() / "data_examples" / input_file
lower_left_corner = (-82.79428, 28.00218)
upper_right_corner = (-82.76323, 28.02404)
# 读取并筛选采样数据
x_coordinates, y_coordinates, values = read_and_filter_samples(
input_file_path, lower_left_corner, upper_right_corner
)
```
### 生成规则网格
```python
lon_min, lon_max, lat_min, lat_max = -82.79428, -82.76323, 28.00218, 28.02404
dx = (lon_max - lon_min) / 10.0
dy = (lat_max - lat_min) / 10.0
makeGridParameters = MakeGridParameters(
angle=0,
origin_x=lon_min,
origin_y=lat_min,
upper_right_x=lon_max,
upper_right_y=lat_max,
block_size_x=dx,
block_size_y=dy,
)
mk = MeshKernel(projection=ProjectionType.SPHERICAL)
mk.mesh2d_make_rectangular_mesh(makeGridParameters)
```
```python
mesh2d_not_refined = mk.mesh2d_get()
fig, ax = plt.subplots()
mesh2d_not_refined.plot_edges(ax)
```
![单元格 18 的绘图输出](images/15_mesh2d_refinement_casulli_based_on_depths_18_0.png)
```python
samples = GeometryList(
x_coordinates=x_coordinates, y_coordinates=y_coordinates, values=values
)
```
```python
interpolation_parameters = InterpolationParameters()
interpolation_parameters.interpolation_type = InterpolationType.AVERAGING
property_id = mk.mkernel_set_property(interpolation_parameters, samples)
x_coordinates_pol = np.empty(0, dtype=np.double)
y_coordinates_pol = np.empty(0, dtype=np.double)
polygons = GeometryList(
x_coordinates=x_coordinates_pol, y_coordinates=y_coordinates_pol
)
meshRefinementParameters = MeshRefinementParameters()
minimumRefinementDepth = 0.0
mk.mkernel_mesh2d_casulli_refinement_based_on_depths(
polygons, property_id, meshRefinementParameters, minimumRefinementDepth
)
```
```python
mesh2d_refined = mk.mesh2d_get()
fig, ax = plt.subplots()
mesh2d_refined.plot_edges(ax)
```
![单元格 21 的绘图输出](images/15_mesh2d_refinement_casulli_based_on_depths_21_0.png)
Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

+21
View File
@@ -0,0 +1,21 @@
# 中文示例教程
以下 15 个教程按原 Jupyter 笔记本顺序译为中文网页,保留示例代码、代码注释与原笔记本已保存的计算结果和绘图。生成文档时未执行示例代码。
若要实际运行示例,可从 [上游示例目录](https://github.com/Deltares/MeshKernelPy/tree/main/docs/examples) 获取笔记本及 `data_examples` 数据。部分示例还依赖 UGrid、xarray、contextily 或外部网格/GEBCO 数据,需要按本机环境调整路径。
- [二维网格基础](01_mesh2d_basics.md)
- [一维网格基础](02_mesh1d_basics.md)
- [在给定几何区域内生成简单三角网格](03_tri_mesh2d_pol.md)
- [曲线网格基础](04_curvilineargrid_basics.md)
- [基于规则网格采样数据的二维网格加密](05_mesh2d_refinement_gridded_samples.md)
- [基于不同水深精度的 GEBCO 网格采样数据进行二维网格加密](06_mesh2d_refinement_gridded_samples_gebco.md)
- [在指定范围内生成曲线网格](07_curvilineargrid_with_defined_extension.md)
- [大型网格正交化](08_mesh2d_orthogonalization.md)
- [网格删除](09_mesh2d_deletion.md)
- [生成全球网格](10_mesh2d_global_grid.md)
- [基于网格采样数据的二维网格脊线加密](11_mesh2d_refine_ridges_gridded_samples.md)
- [基于含海岸线的网格采样数据进行二维网格加密](12_mesh2d_refine_gridded_samples_coastlines.md)
- [基于带步长数组的网格采样数据进行二维网格加密](13_mesh2d_refine_gridded_samples_strided_arrays.md)
- [生成一维与二维网格之间的连接](14_contacts_generation.md)
- [基于水深的二维网格 Casulli 加密](15_mesh2d_refinement_casulli_based_on_depths.md)
Binary file not shown.

After

Width:  |  Height:  |  Size: 230 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 KiB

+116
View File
@@ -0,0 +1,116 @@
# MeshKernelPy 中文文档
[![质量门禁状态](https://sonarcloud.io/api/project_badges/measure?project=Deltares_MeshKernelPy&metric=alert_status)](https://sonarcloud.io/dashboard?id=Deltares_MeshKernelPy)
[![PyPI 版本](https://badge.fury.io/py/meshkernel.svg)](https://badge.fury.io/py/meshkernel)
`MeshKernelPy` 是用于创建和编辑网格的 Python 库,支持一维和二维非结构网格。其底层 C++ 库为 [MeshKernel](https://github.com/Deltares/MeshKernel)。
## 文档导航
- [示例教程:全部 15 个中文网页](examples/index.md)
- [完整 API 参考:类、方法、参数与枚举](api/modules.md)
本中文文档的示例译自本地 `MeshKernelPy-main/docs`,API 说明依据对应 `meshkernel` 源码完整整理,源码版本为 **8.3.0**。示例代码和命令按源文件保留;页面图片使用本地资源,绘图来自原笔记本已保存的输出。
## 安装
执行以下命令,从 [PyPI](https://pypi.org/project/meshkernel/) 安装:
```bash
pip install meshkernel
```
在 Windows 上,如果通过 pip 安装 wheel 后导入库时出现问题,可能需要安装 [Visual Studio 2019 的 Visual C++ 可再发行组件](https://docs.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170)。
## 功能示例
### 在多边形内部创建三角网格
本示例按期望的边长离散多边形边界,从而创建网格。
![在多边形内部生成的三角网格](images/TriangularMeshInPolygon.jpg)
### 网格正交化
采用交错布置的有限体积流动求解器要求网格尽可能正交。MeshKernel 提供网格调整算法,使网格正交性与平滑性达到良好的平衡。
![网格正交化效果](images/MeshOrthogonalization.jpg)
### 网格加密
可以根据采样数据或选定的多边形区域,对网格进行局部加密。
![网格局部加密效果](images/GridRefinement.jpg)
## 参与开发
要在本地安装 `MeshKernelPy`,请在虚拟环境中执行:
```bash
pip install -e ".[tests, lint, docs]"
```
然后将编译好的 `MeshKernelApi.dll` 放入 `src` 文件夹。
请将编辑器配置为使用 [black](https://black.readthedocs.io/en/stable/) 和 [isort](https://pycqa.github.io/isort/) 格式化代码。修改 Jupyter 笔记本时,可以使用 [jupyterlab-code-formatter](https://jupyterlab-code-formatter.readthedocs.io/en/latest/installation.html)。
## 构建并安装 wheel
### 按平台构建 {#platform-build}
项目提供了用于构建 wheel 的安装脚本,已知可在 Windows、Linux 和 macOS 上使用。
安装依赖:
```powershell
python -m pip install --upgrade pip
python -m pip install wheel numpy matplotlib pytest
```
构建 wheel 前,必须设置环境变量 `BACK_END_BRANCH`,以指定生成 wheel 时要构建的 [MeshKernel](https://github.com/Deltares/MeshKernel) 分支。按照源文档约定,若 MeshKernelPy 位于 `main` 分支,应将其设为 `master`;若位于发布分支,应设为 `release`。MeshKernel 发布分支的版本号硬编码在 `meshkernel/version.py` 中。
在项目根目录执行以下命令,构建 wheel:
```powershell
python setup.py build_ext
python setup.py sdist bdist_wheel
```
安装生成的 wheel:
```powershell
python -m pip install <meshkernel_wheel_name>
```
其中,`<meshkernel_wheel_name>` 为生成的 wheel 文件名。运行 `pytest` 即可进行测试。
### Manylinux Docker 镜像
为了向 PyPI 发布 Linux wheel,项目提供了基于 `manylinux_2_28_x86_64` 的 Docker 镜像。该镜像包含编译 C++ 原生 MeshKernel 库所需的 CMake 和 Boost。
使用以下命令构建 Docker 镜像:
```powershell
chmod +x scripts/compile_deps.sh
chmod +x scripts/build_deps.sh
docker build --progress=plain ./scripts -t build_linux_library
```
镜像构建完成后,使用以下命令构建 Linux wheel:
```powershell
docker run -e BACK_END_BRANCH=<meshkernel_back_end_branch_name> -v $(pwd):/root --rm build_linux_library
```
其中,`<meshkernel_back_end_branch_name>` 为 `master` 或 `release`,具体参见[按平台构建](#platform-build)。
可发布的 Linux wheel 位于 `dist/wheelhouse` 目录。
## 许可证
`MeshKernelPy` 使用 MIT 许可证,但 PyPI 上发布的 wheel 捆绑了采用 LGPL 许可证的 [MeshKernel](https://github.com/Deltares/MeshKernel)。使用前请确认这些许可证满足你的需求。
## 文档入口
- [中文示例教程](examples/index.md)
- [中文 API 参考](api/modules.md)