commit 246d9b78702dafd9f5dbf6fd38dabbfa91beff77 Author: Zijun Liu <1843720320@qq.com> Date: Sat Oct 10 21:56:35 2026 +0800 首次提交 diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..20c09cd --- /dev/null +++ b/Readme.md @@ -0,0 +1,2 @@ +本目录下文件为: +使用mkdocs生成wiki静态html页面的源md及相关配置文件。 diff --git a/config/main.yml b/config/main.yml new file mode 100644 index 0000000..c632523 --- /dev/null +++ b/config/main.yml @@ -0,0 +1,4 @@ +site_name: Ruyang.wiki +site_url: https://wiki.ruyangthinks.com +theme: + name: material \ No newline at end of file diff --git a/config/meshkernelpy.yml b/config/meshkernelpy.yml new file mode 100644 index 0000000..5224a46 --- /dev/null +++ b/config/meshkernelpy.yml @@ -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 diff --git a/doc/main/index.md b/doc/main/index.md new file mode 100644 index 0000000..e4e02df --- /dev/null +++ b/doc/main/index.md @@ -0,0 +1,3 @@ +# 导航页面 + +这是主导航页面。 diff --git a/doc/meshkernelpy/api/meshkernel.c_structures.md b/doc/meshkernelpy/api/meshkernel.c_structures.md new file mode 100644 index 0000000..d0ae5ef --- /dev/null +++ b/doc/meshkernelpy/api/meshkernel.c_structures.md @@ -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 数据结构。 diff --git a/doc/meshkernelpy/api/meshkernel.errors.md b/doc/meshkernelpy/api/meshkernel.errors.md new file mode 100644 index 0000000..bffb167 --- /dev/null +++ b/doc/meshkernelpy/api/meshkernel.errors.md @@ -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`。源码未单独说明返回值。 diff --git a/doc/meshkernelpy/api/meshkernel.md b/doc/meshkernelpy/api/meshkernel.md new file mode 100644 index 0000000..67932f9 --- /dev/null +++ b/doc/meshkernelpy/api/meshkernel.md @@ -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) diff --git a/doc/meshkernelpy/api/meshkernel.meshkernel.md b/doc/meshkernelpy/api/meshkernel.meshkernel.md new file mode 100644 index 0000000..8c47b7c --- /dev/null +++ b/doc/meshkernelpy/api/meshkernel.meshkernel.md @@ -0,0 +1,2309 @@ +# MeshKernel 核心接口 + +模块:`meshkernel.meshkernel`。本页依据本地 MeshKernelPy `8.3.0` 源码生成,包含该模块定义的类、方法、函数和常量。签名及参数默认值以源码为准;原文未提供的说明会明确标记。 + +[返回 API 总览](modules.md) + +## `MeshKernel` {#meshkernel} + +继承:`object`。 + +该类是与 MeshKernel 库交互的入口。 + +**方法索引** + +- [`__init__`](#meshkernel---init--) +- [`__del__`](#meshkernel---del--) +- [`__get_exit_codes`](#meshkernel---get-exit-codes) +- [`_allocate_state`](#meshkernel--allocate-state) +- [`_set_undo_size`](#meshkernel--set-undo-size) +- [`_deallocate_state`](#meshkernel--deallocate-state) +- [`mesh2d_set`](#meshkernel-mesh2d-set) +- [`mesh2d_add`](#meshkernel-mesh2d-add) +- [`mesh2d_get`](#meshkernel-mesh2d-get) +- [`_mesh2d_get_dimensions`](#meshkernel--mesh2d-get-dimensions) +- [`mesh2d_delete`](#meshkernel-mesh2d-delete) +- [`mesh2d_get_mesh_inner_boundaries_as_polygons`](#meshkernel-mesh2d-get-mesh-inner-boundaries-as-polygons) +- [`mesh2d_delete_faces_in_polygons`](#meshkernel-mesh2d-delete-faces-in-polygons) +- [`mesh2d_insert_edge`](#meshkernel-mesh2d-insert-edge) +- [`mesh2d_insert_node`](#meshkernel-mesh2d-insert-node) +- [`mesh2d_delete_node`](#meshkernel-mesh2d-delete-node) +- [`mesh2d_move_node`](#meshkernel-mesh2d-move-node) +- [`mesh2d_delete_edge`](#meshkernel-mesh2d-delete-edge) +- [`mesh2d_get_edge`](#meshkernel-mesh2d-get-edge) +- [`mesh2d_get_face_polygons`](#meshkernel-mesh2d-get-face-polygons) +- [`mesh2d_get_filtered_face_polygons`](#meshkernel-mesh2d-get-filtered-face-polygons) +- [`mesh2d_get_node_index`](#meshkernel-mesh2d-get-node-index) +- [`mesh2d_get_hanging_edges`](#meshkernel-mesh2d-get-hanging-edges) +- [`_mesh2d_count_hanging_edges`](#meshkernel--mesh2d-count-hanging-edges) +- [`mesh2d_delete_hanging_edges`](#meshkernel-mesh2d-delete-hanging-edges) +- [`mesh2d_make_global`](#meshkernel-mesh2d-make-global) +- [`mesh2d_make_triangular_mesh_from_polygon`](#meshkernel-mesh2d-make-triangular-mesh-from-polygon) +- [`mesh2d_make_triangular_mesh_from_samples`](#meshkernel-mesh2d-make-triangular-mesh-from-samples) +- [`mesh2d_make_rectangular_mesh`](#meshkernel-mesh2d-make-rectangular-mesh) +- [`mesh2d_make_rectangular_mesh_from_polygon`](#meshkernel-mesh2d-make-rectangular-mesh-from-polygon) +- [`mesh2d_make_rectangular_mesh_on_extension`](#meshkernel-mesh2d-make-rectangular-mesh-on-extension) +- [`polygon_refine`](#meshkernel-polygon-refine) +- [`mesh2d_refine_based_on_samples`](#meshkernel-mesh2d-refine-based-on-samples) +- [`mesh2d_refine_ridges_based_on_gridded_samples`](#meshkernel-mesh2d-refine-ridges-based-on-gridded-samples) +- [`mesh2d_refine_based_on_gridded_samples`](#meshkernel-mesh2d-refine-based-on-gridded-samples) +- [`mesh2d_refine_based_on_polygon`](#meshkernel-mesh2d-refine-based-on-polygon) +- [`mesh2d_remove_disconnected_regions`](#meshkernel-mesh2d-remove-disconnected-regions) +- [`mesh2d_rotate`](#meshkernel-mesh2d-rotate) +- [`mesh2d_translate`](#meshkernel-mesh2d-translate) +- [`polygon_get_included_points`](#meshkernel-polygon-get-included-points) +- [`mesh2d_flip_edges`](#meshkernel-mesh2d-flip-edges) +- [`_mesh2d_count_obtuse_triangles`](#meshkernel--mesh2d-count-obtuse-triangles) +- [`mesh2d_get_obtuse_triangles_mass_centers`](#meshkernel-mesh2d-get-obtuse-triangles-mass-centers) +- [`_mesh2d_count_small_flow_edge_centers`](#meshkernel--mesh2d-count-small-flow-edge-centers) +- [`mesh2d_get_small_flow_edge_centers`](#meshkernel-mesh2d-get-small-flow-edge-centers) +- [`mesh2d_delete_small_flow_edges_and_small_triangles`](#meshkernel-mesh2d-delete-small-flow-edges-and-small-triangles) +- [`get_splines`](#meshkernel-get-splines) +- [`mesh2d_get_mesh_boundaries_as_polygons`](#meshkernel-mesh2d-get-mesh-boundaries-as-polygons) +- [`_mesh2d_count_mesh_boundaries_as_polygons`](#meshkernel--mesh2d-count-mesh-boundaries-as-polygons) +- [`mesh2d_merge_nodes`](#meshkernel-mesh2d-merge-nodes) +- [`mesh2d_merge_nodes_with_merging_distance`](#meshkernel-mesh2d-merge-nodes-with-merging-distance) +- [`mesh2d_merge_two_nodes`](#meshkernel-mesh2d-merge-two-nodes) +- [`mesh2d_get_nodes_in_polygons`](#meshkernel-mesh2d-get-nodes-in-polygons) +- [`_mesh2d_count_nodes_in_polygons`](#meshkernel--mesh2d-count-nodes-in-polygons) +- [`mesh1d_set`](#meshkernel-mesh1d-set) +- [`mesh1d_add`](#meshkernel-mesh1d-add) +- [`mesh1d_get`](#meshkernel-mesh1d-get) +- [`_mesh1d_get_dimensions`](#meshkernel--mesh1d-get-dimensions) +- [`contacts_set`](#meshkernel-contacts-set) +- [`_contacts_get_dimensions`](#meshkernel--contacts-get-dimensions) +- [`contacts_get`](#meshkernel-contacts-get) +- [`contacts_compute_single`](#meshkernel-contacts-compute-single) +- [`contacts_compute_multiple`](#meshkernel-contacts-compute-multiple) +- [`contacts_compute_with_polygons`](#meshkernel-contacts-compute-with-polygons) +- [`contacts_compute_with_points`](#meshkernel-contacts-compute-with-points) +- [`contacts_compute_boundary`](#meshkernel-contacts-compute-boundary) +- [`mesh2d_casulli_derefinement`](#meshkernel-mesh2d-casulli-derefinement) +- [`mesh2d_casulli_derefinement_on_polygon`](#meshkernel-mesh2d-casulli-derefinement-on-polygon) +- [`mesh2d_delete_property`](#meshkernel-mesh2d-delete-property) +- [`mesh2d_set_property`](#meshkernel-mesh2d-set-property) +- [`mesh2d_casulli_refinement_based_on_depths`](#meshkernel-mesh2d-casulli-refinement-based-on-depths) +- [`mesh2d_casulli_refinement`](#meshkernel-mesh2d-casulli-refinement) +- [`mesh2d_casulli_refinement_on_polygon`](#meshkernel-mesh2d-casulli-refinement-on-polygon) +- [`mesh2d_compute_orthogonalization`](#meshkernel-mesh2d-compute-orthogonalization) +- [`mesh2d_get_orthogonality`](#meshkernel-mesh2d-get-orthogonality) +- [`mesh2d_get_property`](#meshkernel-mesh2d-get-property) +- [`mesh2d_get_smoothness`](#meshkernel-mesh2d-get-smoothness) +- [`mesh2d_connect_meshes`](#meshkernel-mesh2d-connect-meshes) +- [`_get_error`](#meshkernel--get-error) +- [`_get_geometry_error`](#meshkernel--get-geometry-error) +- [`mesh2d_triangulation_interpolation`](#meshkernel-mesh2d-triangulation-interpolation) +- [`mesh2d_averaging_interpolation`](#meshkernel-mesh2d-averaging-interpolation) +- [`mesh2d_convert_projection`](#meshkernel-mesh2d-convert-projection) +- [`get_projection`](#meshkernel-get-projection) +- [`get_meshkernel_version`](#meshkernel-get-meshkernel-version) +- [`get_meshkernelpy_version`](#meshkernel-get-meshkernelpy-version) +- [`mkernel_get_separator`](#meshkernel-mkernel-get-separator) +- [`mkernel_get_inner_outer_separator`](#meshkernel-mkernel-get-inner-outer-separator) +- [`_execute_function`](#meshkernel--execute-function) +- [`_curvilineargrid_get_dimensions`](#meshkernel--curvilineargrid-get-dimensions) +- [`curvilineargrid_get`](#meshkernel-curvilineargrid-get) +- [`curvilinear_compute_transfinite_from_splines`](#meshkernel-curvilinear-compute-transfinite-from-splines) +- [`curvilinear_compute_orthogonal_from_splines`](#meshkernel-curvilinear-compute-orthogonal-from-splines) +- [`curvilinear_compute_curvature`](#meshkernel-curvilinear-compute-curvature) +- [`curvilinear_compute_smoothness`](#meshkernel-curvilinear-compute-smoothness) +- [`curvilinear_convert_to_mesh2d`](#meshkernel-curvilinear-convert-to-mesh2d) +- [`curvilinear_compute_rectangular_grid`](#meshkernel-curvilinear-compute-rectangular-grid) +- [`curvilinear_compute_rectangular_grid_from_polygon`](#meshkernel-curvilinear-compute-rectangular-grid-from-polygon) +- [`curvilinear_compute_rectangular_grid_on_extension`](#meshkernel-curvilinear-compute-rectangular-grid-on-extension) +- [`curvilinear_refine`](#meshkernel-curvilinear-refine) +- [`curvilinear_compute_transfinite_from_polygon`](#meshkernel-curvilinear-compute-transfinite-from-polygon) +- [`curvilinear_compute_transfinite_from_triangle`](#meshkernel-curvilinear-compute-transfinite-from-triangle) +- [`curvilinear_orthogonalize`](#meshkernel-curvilinear-orthogonalize) +- [`curvilinear_frozen_line_is_valid`](#meshkernel-curvilinear-frozen-line-is-valid) +- [`curvilinear_frozen_line_delete`](#meshkernel-curvilinear-frozen-line-delete) +- [`curvilinear_frozen_line_add`](#meshkernel-curvilinear-frozen-line-add) +- [`curvilinear_frozen_line_get`](#meshkernel-curvilinear-frozen-line-get) +- [`curvilinear_frozen_lines_get_ids`](#meshkernel-curvilinear-frozen-lines-get-ids) +- [`curvilinear_smoothing`](#meshkernel-curvilinear-smoothing) +- [`curvilinear_smoothing_directional`](#meshkernel-curvilinear-smoothing-directional) +- [`curvilinear_initialize_line_shift`](#meshkernel-curvilinear-initialize-line-shift) +- [`curvilinear_set_line_line_shift`](#meshkernel-curvilinear-set-line-line-shift) +- [`curvilinear_set_block_line_shift`](#meshkernel-curvilinear-set-block-line-shift) +- [`curvilinear_move_node_line_shift`](#meshkernel-curvilinear-move-node-line-shift) +- [`curvilinear_line_shift`](#meshkernel-curvilinear-line-shift) +- [`curvilinear_move_node`](#meshkernel-curvilinear-move-node) +- [`curvilinear_insert_face`](#meshkernel-curvilinear-insert-face) +- [`curvilinear_line_attraction_repulsion`](#meshkernel-curvilinear-line-attraction-repulsion) +- [`curvilinear_line_mirror`](#meshkernel-curvilinear-line-mirror) +- [`curvilinear_delete_node`](#meshkernel-curvilinear-delete-node) +- [`_get_num_coordinates`](#meshkernel--get-num-coordinates) +- [`__map_to_valid_values`](#meshkernel---map-to-valid-values) + +### `MeshKernel.__init__` {#meshkernel---init--} + +```python +__init__(self, projection: ProjectionType=ProjectionType.CARTESIAN) +``` + +MeshKernel 的构造函数。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `projection` | `ProjectionType` | `ProjectionType.CARTESIAN` | 投影类型,默认为 `ProjectionType.CARTESIAN`。 | + + +**异常** + +- **`OSError`**:在不支持的操作系统上使用 MeshKernel 时抛出。 + +### `MeshKernel.__del__` {#meshkernel---del--} + +```python +__del__(self) +``` + +析构方法,用于释放实例持有的状态。 + +### `MeshKernel.__get_exit_codes` {#meshkernel---get-exit-codes} + +```python +__get_exit_codes(self) +``` + +此成员以内部名称定义,供理解实现及转换流程时参考。 + +保存后端退出码。 + +**返回值** + +名为 exit_code 的整数枚举,包含后端退出码。 + +### `MeshKernel._allocate_state` {#meshkernel--allocate-state} + +```python +_allocate_state(self, projection: ProjectionType) -> None +``` + +此成员以内部名称定义,供理解实现及转换流程时参考。 + +创建一个新的空网格。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `projection` | `ProjectionType` | `必填` | 投影类型。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel._set_undo_size` {#meshkernel--set-undo-size} + +```python +_set_undo_size(self, undo_stack_size: int) -> None +``` + +此成员以内部名称定义,供理解实现及转换流程时参考。 + +设置撤销栈的最大容量。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `undo_stack_size` | `int` | `必填` | 撤销栈的最大容量。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel._deallocate_state` {#meshkernel--deallocate-state} + +```python +_deallocate_state(self) -> None +``` + +此成员以内部名称定义,供理解实现及转换流程时参考。 + +释放网格状态。 + +此方法由析构函数调用, 不应手动调用。 + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_set` {#meshkernel-mesh2d-set} + +```python +mesh2d_set(self, mesh2d: Mesh2d) -> None +``` + +设置 MeshKernel 的二维网格状态。 + +注意,此操作会复制数据。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `mesh2d` | `Mesh2d` | `必填` | 用于设置状态的输入数据。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_add` {#meshkernel-mesh2d-add} + +```python +mesh2d_add(self, mesh2d: Mesh2d) -> None +``` + +添加二维网格。 + +注意,此操作会复制数据。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `mesh2d` | `Mesh2d` | `必填` | 用于设置状态的输入数据。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_get` {#meshkernel-mesh2d-get} + +```python +mesh2d_get(self) -> Mesh2d +``` + +从 MeshKernel 获取二维网格状态。 + +注意,此操作会复制数据。 + +**返回值** + +- **`Mesh2d`**:二维网格状态的副本。 + +### `MeshKernel._mesh2d_get_dimensions` {#meshkernel--mesh2d-get-dimensions} + +```python +_mesh2d_get_dimensions(self) -> CMesh2d +``` + +此成员以内部名称定义,供理解实现及转换流程时参考。 + +仅供内部使用。 + +获取 Mesh2d 的维度信息。 将 Mesh2D 结构体中的整数参数设置为对应维度。 传入 `mesh2d_get` 前,必须让结构体指针指向大小正确的内存。 + +**返回值** + +- **`Mesh2d`**:Mesh2d 的维度信息。 + +### `MeshKernel.mesh2d_delete` {#meshkernel-mesh2d-delete} + +```python +mesh2d_delete(self, geometry_list: GeometryList, delete_option: DeleteMeshOption, invert_deletion: bool) -> None +``` + +按指定策略删除多边形内部的部分网格。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `geometry_list` | `GeometryList` | `必填` | 描述操作区域多边形的 GeometryList。 | +| `delete_option` | `DeleteMeshOption` | `必填` | 指定网格删除策略的选项。 | +| `invert_deletion` | `bool` | `必填` | 是否反转删除区域。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_get_mesh_inner_boundaries_as_polygons` {#meshkernel-mesh2d-get-mesh-inner-boundaries-as-polygons} + +```python +mesh2d_get_mesh_inner_boundaries_as_polygons(self) -> GeometryList +``` + +从 MeshKernel 获取内边界多边形。 + +**返回值** + +- **`GeometryList`**:描述网格内边界多边形的点序列。 + +### `MeshKernel.mesh2d_delete_faces_in_polygons` {#meshkernel-mesh2d-delete-faces-in-polygons} + +```python +mesh2d_delete_faces_in_polygons(self, geometry_list: GeometryList) -> None +``` + +删除位于一个或多个多边形内部的网格面。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `geometry_list` | `GeometryList` | `必填` | 描述删除区域多边形的 GeometryList。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_insert_edge` {#meshkernel-mesh2d-insert-edge} + +```python +mesh2d_insert_edge(self, start_node: int, end_node: int) -> int +``` + +插入一条连接两个指定节点的二维网格边。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `start_node` | `int` | `必填` | 第一个节点的索引。 | +| `end_node` | `int` | `必填` | 第二个节点的索引。 | + + +**返回值** + +- **`int`**:新边的索引。 + +### `MeshKernel.mesh2d_insert_node` {#meshkernel-mesh2d-insert-node} + +```python +mesh2d_insert_node(self, x: float, y: float) -> int +``` + +在指定坐标处插入新节点。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `x` | `float` | `必填` | 新节点的 x 坐标。 | +| `y` | `float` | `必填` | 新节点的 y 坐标。 | + + +**返回值** + +- **`int`**:新节点的索引。 + +### `MeshKernel.mesh2d_delete_node` {#meshkernel-mesh2d-delete-node} + +```python +mesh2d_delete_node(self, node_index: int) -> None +``` + +删除给定索引 `index` 对应的 Mesh2d 节点。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `node_index` | `int` | `必填` | 待删除节点的索引。 | + + +**异常** + +- **`InputError`**:`node_index` 小于 0 时抛出。 + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_move_node` {#meshkernel-mesh2d-move-node} + +```python +mesh2d_move_node(self, x: float, y: float, node_index: int) -> None +``` + +将给定索引 `index` 对应的 Mesh2d 节点移动到指定位置。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `x` | `float` | `必填` | 节点新位置的 x 坐标。 | +| `y` | `float` | `必填` | 节点新位置的 y 坐标。 | +| `node_index` | `int` | `必填` | 待移动节点的索引。 | + + +**异常** + +- **`InputError`**:`node_index` 小于 0 时抛出。 + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_delete_edge` {#meshkernel-mesh2d-delete-edge} + +```python +mesh2d_delete_edge(self, x_coordinate: float, y_coordinate: float) -> None +``` + +删除距离指定点最近的二维网格边。 使用边中点的坐标计算边到该点的距离。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `x_coordinate` | `float` | `必填` | 源码未单独提供参数说明。 | +| `y_coordinate` | `float` | `必填` | 源码未单独提供参数说明。 | + +原文还列出了以下参数说明(名称可能与当前签名不一致): + +- **`x`(`float`)**:指定点的 x 坐标。 + +- **`y`(`float`)**:指定点的 y 坐标。 + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_get_edge` {#meshkernel-mesh2d-get-edge} + +```python +mesh2d_get_edge(self, x: float, y: float) -> int +``` + +获取距离指定点最近的二维网格边。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `x` | `float` | `必填` | 指定点的 x 坐标。 | +| `y` | `float` | `必填` | 指定点的 y 坐标。 | + + +**返回值** + +- **`int`**:边的索引,使用无空缺数组索引。 + +### `MeshKernel.mesh2d_get_face_polygons` {#meshkernel-mesh2d-get-face-polygons} + +```python +mesh2d_get_face_polygons(self, num_edges: int) -> GeometryList +``` + +获取边数等于 num_edges 的网格面多边形。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `num_edges` | `int` | `必填` | 边数。 | + + +**返回值** + +- **`GeometryList`**:生成的网格面多边形。 + +### `MeshKernel.mesh2d_get_filtered_face_polygons` {#meshkernel-mesh2d-get-filtered-face-polygons} + +```python +mesh2d_get_filtered_face_polygons(self, property: Mesh2dProperty, min_value: float, max_value: float) -> GeometryList +``` + +获取指标值位于最小值和最大值之间的多边形。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `property` | `Mesh2dProperty` | `必填` | 用于筛选位置的属性。 | +| `min_value` | `float` | `必填` | 指标的最小值。 | +| `max_value` | `float` | `必填` | 指标的最大值。 | + + +**返回值** + +- **`GeometryList`**:生成的网格面多边形。 + +### `MeshKernel.mesh2d_get_node_index` {#meshkernel-mesh2d-get-node-index} + +```python +mesh2d_get_node_index(self, x: float, y: float, search_radius: float) -> int +``` + +在给定搜索半径内查找距离指定点最近的节点。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `x` | `float` | `必填` | 指定点的 x 坐标。 | +| `y` | `float` | `必填` | 指定点的 y 坐标。 | +| `search_radius` | `float` | `必填` | 搜索半径。 | + + +**返回值** + +- **`int`**:节点索引,使用无空缺数组索引。 + +### `MeshKernel.mesh2d_get_hanging_edges` {#meshkernel-mesh2d-get-hanging-edges} + +```python +mesh2d_get_hanging_edges(self) -> ndarray +``` + +获取悬挂边的索引。悬挂边是指两个端点中有一个未连接到其他边的边。 + +**返回值** + +- **`ndarray`**:包含悬挂边索引的整数数组。 + +### `MeshKernel._mesh2d_count_hanging_edges` {#meshkernel--mesh2d-count-hanging-edges} + +```python +_mesh2d_count_hanging_edges(self) -> int +``` + +此成员以内部名称定义,供理解实现及转换流程时参考。 + +仅供内部使用。 + +统计二维网格中的悬挂边数。 悬挂边是指两个端点中有一个未连接到其他边的边。 + +**返回值** + +- **`int`**:悬挂边数。 + +### `MeshKernel.mesh2d_delete_hanging_edges` {#meshkernel-mesh2d-delete-hanging-edges} + +```python +mesh2d_delete_hanging_edges(self) -> None +``` + +删除 Mesh2d 中的悬挂边。 悬挂边是指两个端点中有一个未连接到其他边的边。 + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_make_global` {#meshkernel-mesh2d-make-global} + +```python +mesh2d_make_global(self, num_longitude_nodes: int, num_latitude_nodes: int) -> None +``` + +按经度和纬度方向上给定的点数计算全球网格。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `num_longitude_nodes` | `int` | `必填` | 经度方向的点数。 | +| `num_latitude_nodes` | `int` | `必填` | 纬度方向的点数(半球)。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_make_triangular_mesh_from_polygon` {#meshkernel-mesh2d-make-triangular-mesh-from-polygon} + +```python +mesh2d_make_triangular_mesh_from_polygon(self, polygon: GeometryList, scale_factor: float=float(-999.0)) -> None +``` + +在多边形内部生成二维三角网格。三角形尺寸由 多边形边长确定。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `polygon` | `GeometryList` | `必填` | 多边形。 | +| `scale_factor` | `float` | `float(-999.0)` | 三角剖分的缩放系数;若为负值,则使用默认值。 默认缩放系数取决于多边形。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_make_triangular_mesh_from_samples` {#meshkernel-mesh2d-make-triangular-mesh-from-samples} + +```python +mesh2d_make_triangular_mesh_from_samples(self, sample_points: GeometryList) -> None +``` + +对采样点进行三角剖分,从采样点集合生成三角网格。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `sample_points` | `GeometryList` | `必填` | 采样点。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_make_rectangular_mesh` {#meshkernel-mesh2d-make-rectangular-mesh} + +```python +mesh2d_make_rectangular_mesh(self, make_grid_parameters: MakeGridParameters) -> None +``` + +生成二维矩形网格。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `make_grid_parameters` | `MakeGridParameters` | `必填` | 生成均匀网格所用的参数。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_make_rectangular_mesh_from_polygon` {#meshkernel-mesh2d-make-rectangular-mesh-from-polygon} + +```python +mesh2d_make_rectangular_mesh_from_polygon(self, make_grid_parameters: MakeGridParameters, polygon: GeometryList) -> None +``` + +在多边形内部生成二维矩形网格。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `make_grid_parameters` | `MakeGridParameters` | `必填` | 生成均匀网格所用的参数。 | +| `polygon` | `GeometryList` | `必填` | 源码未单独提供参数说明。 | + +原文还列出了以下参数说明(名称可能与当前签名不一致): + +- **`geometry_list`(`GeometryList`)**:生成网格的区域多边形。 + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_make_rectangular_mesh_on_extension` {#meshkernel-mesh2d-make-rectangular-mesh-on-extension} + +```python +mesh2d_make_rectangular_mesh_on_extension(self, make_grid_parameters: MakeGridParameters) -> None +``` + +生成二维矩形网格。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `make_grid_parameters` | `MakeGridParameters` | `必填` | 生成均匀网格所用的参数。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.polygon_refine` {#meshkernel-polygon-refine} + +```python +polygon_refine(self, polygon: GeometryList, first_node: int, second_node: int, target_edge_length: float) -> GeometryList +``` + +加密多边形边界上两个节点之间的区间,使其达到目标边长。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `polygon` | `GeometryList` | `必填` | 待加密的输入多边形。 | +| `first_node` | `int` | `必填` | 加密区间的第一个节点索引。 | +| `second_node` | `int` | `必填` | 加密区间的第二个节点索引。 | +| `target_edge_length` | `float` | `必填` | 该区间的目标边长。 | + + +**返回值** + +- **`GeometryList`**:加密后的多边形。 + +### `MeshKernel.mesh2d_refine_based_on_samples` {#meshkernel-mesh2d-refine-based-on-samples} + +```python +mesh2d_refine_based_on_samples(self, samples: GeometryList, relative_search_radius: float, minimum_num_samples: int, mesh_refinement_params: MeshRefinementParameters, polygon: GeometryList=GeometryList()) -> None +``` + +基于采样数据加密二维网格,通过连续划分网格面的边实现加密。 连续划分次数由采样值指定。 例如: + +- 值为 0 表示不划分,也不加密; + +- 值为 1 表示划分一次,一个四边形面生成 4 个面; + +- 值为 2 表示划分两次,一个四边形面生成 16 个面。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `samples` | `GeometryList` | `必填` | 采样数据。 | +| `relative_search_radius` | `float` | `必填` | 相对于网格面尺寸的相对搜索半径, 用于某些插值算法。 | +| `minimum_num_samples` | `int` | `必填` | 某些平均算法使用的最少采样点数。 | +| `mesh_refinement_params` | `MeshRefinementParameters` | `必填` | 网格加密参数。 | +| `polygon` | `GeometryList` | `GeometryList()` | 加密区域;若多边形为空,则考虑整个网格。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_refine_ridges_based_on_gridded_samples` {#meshkernel-mesh2d-refine-ridges-based-on-gridded-samples} + +```python +mesh2d_refine_ridges_based_on_gridded_samples(self, gridded_samples: GriddedSamples, relative_search_radius: float, minimum_num_samples: int, number_of_smoothing_iterations: int, mesh_refinement_params: MeshRefinementParameters, polygon: GeometryList=GeometryList()) -> None +``` + +基于采样数据进行脊线加密,自动检测采样数据集中的脊线。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `gridded_samples` | `GriddedSamples` | `必填` | 网格采样数据。 | +| `relative_search_radius` | `float` | `必填` | 相对于网格面尺寸的相对搜索半径, 用于某些插值算法。 | +| `minimum_num_samples` | `int` | `必填` | 某些平均算法使用的最少采样点数。 | +| `number_of_smoothing_iterations` | `int` | `必填` | 对输入采样数据集执行的平滑迭代次数。 | +| `mesh_refinement_params` | `MeshRefinementParameters` | `必填` | 网格加密参数。 | +| `polygon` | `GeometryList` | `GeometryList()` | 加密区域;若多边形为空,则考虑整个网格。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_refine_based_on_gridded_samples` {#meshkernel-mesh2d-refine-based-on-gridded-samples} + +```python +mesh2d_refine_based_on_gridded_samples(self, gridded_samples: GriddedSamples, mesh_refinement_params: MeshRefinementParameters, use_nodal_refinement: bool=True, polygon: GeometryList=GeometryList()) -> None +``` + +基于网格采样数据和双线性插值计算网格加密。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `gridded_samples` | `GriddedSamples` | `必填` | 网格采样数据。 | +| `mesh_refinement_params` | `MeshRefinementParameters` | `必填` | 网格加密参数。 | +| `use_nodal_refinement` | `bool` | `True` | 是否使用节点处的水深值进行加密,默认为 True。 | +| `polygon` | `GeometryList` | `GeometryList()` | 加密区域;若多边形为空,则考虑整个网格。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_refine_based_on_polygon` {#meshkernel-mesh2d-refine-based-on-polygon} + +```python +mesh2d_refine_based_on_polygon(self, polygon: GeometryList, mesh_refinement_params: MeshRefinementParameters) -> None +``` + +在多边形内部加密二维网格,将多边形内的边 一分为二。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `polygon` | `GeometryList` | `必填` | 源码未单独提供参数说明。 | +| `mesh_refinement_params` | `MeshRefinementParameters` | `必填` | 网格加密参数。 | + +原文还列出了以下参数说明(名称可能与当前签名不一致): + +- **`samples`(`GeometryList`)**:闭合多边形。 + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_remove_disconnected_regions` {#meshkernel-mesh2d-remove-disconnected-regions} + +```python +mesh2d_remove_disconnected_regions(self) -> None +``` + +移除二维网格中所有不连通的区域,仅保留占主导的区域。 + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_rotate` {#meshkernel-mesh2d-rotate} + +```python +mesh2d_rotate(self, centre_x: float, centre_y: float, angle: float) -> None +``` + +绕旋转中心旋转二维网格。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `centre_x` | `float` | `必填` | 旋转中心的 x 坐标。 | +| `centre_y` | `float` | `必填` | 旋转中心的 y 坐标。 | +| `angle` | `float` | `必填` | 旋转角度,单位为度。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_translate` {#meshkernel-mesh2d-translate} + +```python +mesh2d_translate(self, translation_x: float, translation_y: float) -> None +``` + +平移二维网格。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `translation_x` | `float` | `必填` | 平移向量的 x 分量。 | +| `translation_y` | `float` | `必填` | 平移向量的 y 分量。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.polygon_get_included_points` {#meshkernel-polygon-get-included-points} + +```python +polygon_get_included_points(self, selecting_polygon: GeometryList, selected_polygon: GeometryList) -> GeometryList +``` + +选择位于另一个多边形内部的多边形节点。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `selecting_polygon` | `GeometryList` | `必填` | 用于选择区域的多边形。 | +| `selected_polygon` | `GeometryList` | `必填` | 待筛选节点所属的多边形。 | + + +**返回值** + +- **`GeometryList`**:选择结果。选中情况保存在返回的 GeometryList 的 values 数组中, 0.0 表示未选中,1.0 表示选中。 + +### `MeshKernel.mesh2d_flip_edges` {#meshkernel-mesh2d-flip-edges} + +```python +mesh2d_flip_edges(self, triangulation_required: bool, project_to_land_boundary_required: bool, selecting_polygon: GeometryList, land_boundaries: GeometryList) +``` + +通过翻转二维网格边优化网格平滑性。 连接到超过六个其他节点的节点,通常被形状高度不均匀、 面积差异很大的网格面包围。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `triangulation_required` | `bool` | `必填` | 是否对非三角形单元进行三角剖分。 | +| `project_to_land_boundary_required` | `bool` | `必填` | 是否需要投影到陆地边界。 | +| `selecting_polygon` | `GeometryList` | `必填` | 执行边翻转操作的区域多边形。 | +| `land_boundaries` | `GeometryList` | `必填` | 翻转边时需要考虑的陆地边界。 | + + +### `MeshKernel._mesh2d_count_obtuse_triangles` {#meshkernel--mesh2d-count-obtuse-triangles} + +```python +_mesh2d_count_obtuse_triangles(self) -> int +``` + +此成员以内部名称定义,供理解实现及转换流程时参考。 + +仅供内部使用。 + +获取二维网格中钝角三角形的数量。 钝角三角形指有一个内角大于 90° 的三角形。 + +**返回值** + +- **`int`**:钝角三角形的数量。 + +### `MeshKernel.mesh2d_get_obtuse_triangles_mass_centers` {#meshkernel-mesh2d-get-obtuse-triangles-mass-centers} + +```python +mesh2d_get_obtuse_triangles_mass_centers(self) -> GeometryList +``` + +获取二维网格中钝角三角形的质心。 钝角三角形指有一个内角大于 90° 的三角形。 + +**返回值** + +- **`GeometryList`**:包含质心坐标的几何列表。 + +### `MeshKernel._mesh2d_count_small_flow_edge_centers` {#meshkernel--mesh2d-count-small-flow-edge-centers} + +```python +_mesh2d_count_small_flow_edge_centers(self, small_flow_edges_length_threshold: float) -> int +``` + +此成员以内部名称定义,供理解实现及转换流程时参考。 + +仅供内部使用。 + +统计二维网格中短流动边的数量。 流动边是连接网格面外心的边。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `small_flow_edges_length_threshold` | `float` | `必填` | 用于识别短流动边的长度阈值。 | + + +**返回值** + +- **`int`**:短流动边的数量。 + +### `MeshKernel.mesh2d_get_small_flow_edge_centers` {#meshkernel-mesh2d-get-small-flow-edge-centers} + +```python +mesh2d_get_small_flow_edge_centers(self, small_flow_edges_length_threshold: float) -> GeometryList +``` + +获取二维网格中短流动边的中心。 流动边是连接网格面外心的边。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `small_flow_edges_length_threshold` | `float` | `必填` | 用于识别短流动边的长度阈值。 | + + +**返回值** + +- **`int`**:包含短流动边中心坐标的几何列表。(原文将返回类型标为 int,实际返回 GeometryList。) + +### `MeshKernel.mesh2d_delete_small_flow_edges_and_small_triangles` {#meshkernel-mesh2d-delete-small-flow-edges-and-small-triangles} + +```python +mesh2d_delete_small_flow_edges_and_small_triangles(self, small_flow_edges_length_threshold: float, min_fractional_area_triangles: float) -> None +``` + +删除二维网格中所有短流动边和小三角形。 流动边是连接网格面外心的边。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `small_flow_edges_length_threshold` | `float` | `必填` | 用于识别短流动边的长度阈值。 | +| `min_fractional_area_triangles` | `float` | `必填` | 网格面面积与相邻非三角形网格面平均面积之比, 此参数用于判断 三角形网格面是否过小。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.get_splines` {#meshkernel-get-splines} + +```python +get_splines(self, geometry_list: GeometryList, number_of_points_between_nodes: int) -> GeometryList +``` + +获取两个拐点节点之间计算得到的样条曲线点。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `geometry_list` | `GeometryList` | `必填` | 样条曲线的输入拐点节点。 | +| `number_of_points_between_nodes` | `int` | `必填` | 两个拐点节点之间生成的样条曲线点数。 | + + +**返回值** + +- **`GeometryList`**:输出样条曲线。 + +### `MeshKernel.mesh2d_get_mesh_boundaries_as_polygons` {#meshkernel-mesh2d-get-mesh-boundaries-as-polygons} + +```python +mesh2d_get_mesh_boundaries_as_polygons(self, geometry_list: GeometryList=GeometryList()) -> GeometryList +``` + +将选择多边形内的网格边界提取为一系列相互分隔的多边形。 若多边形为空,则获取全部网格边界。 + +例如,若网格中有一个孔洞,则生成两个多边形, 分别表示内边界和外边界。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `geometry_list` | `GeometryList` | `GeometryList()` | 选择多边形。 | + + +**返回值** + +- **`GeometryList`**:输出网格边界多边形。 + +### `MeshKernel._mesh2d_count_mesh_boundaries_as_polygons` {#meshkernel--mesh2d-count-mesh-boundaries-as-polygons} + +```python +_mesh2d_count_mesh_boundaries_as_polygons(self, geometry_list: GeometryList) -> int +``` + +此成员以内部名称定义,供理解实现及转换流程时参考。 + +仅供内部使用。获取选择多边形内部的网格边界数量。 若多边形为空,则考虑全部网格边界。 + +统计网格边界多边形包含的多边形节点数, 这些边界多边形由 mesh2d_get_mesh_boundaries_as_polygons 计算得到。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `geometry_list` | `GeometryList` | `必填` | 选择多边形。 | + + +**返回值** + +- **`int`**:多边形节点数。 + +### `MeshKernel.mesh2d_merge_nodes` {#meshkernel-mesh2d-merge-nodes} + +```python +mesh2d_merge_nodes(self, geometry_list: GeometryList) -> None +``` + +合并二维网格节点,从而移除短边。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `geometry_list` | `GeometryList` | `必填` | 定义操作区域的多边形。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_merge_nodes_with_merging_distance` {#meshkernel-mesh2d-merge-nodes-with-merging-distance} + +```python +mesh2d_merge_nodes_with_merging_distance(self, geometry_list: GeometryList, merging_distance: float) -> None +``` + +合并二维网格节点,从而移除短边。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `geometry_list` | `GeometryList` | `必填` | 定义操作区域的多边形。 | +| `merging_distance` | `float` | `必填` | 两个节点之间的距离小于此值时进行合并。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_merge_two_nodes` {#meshkernel-mesh2d-merge-two-nodes} + +```python +mesh2d_merge_two_nodes(self, first_node: int, second_node: int) -> None +``` + +将 `first_node` 合并到 `second_node`。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `first_node` | `int` | `必填` | 第一个待合并节点的索引。 | +| `second_node` | `int` | `必填` | 第二个待合并节点的索引。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_get_nodes_in_polygons` {#meshkernel-mesh2d-get-nodes-in-polygons} + +```python +mesh2d_get_nodes_in_polygons(self, geometry_list: GeometryList, inside: bool) -> ndarray +``` + +获取通过多边形选中的二维网格节点索引。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `geometry_list` | `GeometryList` | `必填` | 输入多边形。 | +| `inside` | `bool` | `必填` | 选择多边形内部的节点(True)或外部的节点(False)。 | + + +**返回值** + +- **`ndarray`**:包含选中节点索引的整数数组。 + +### `MeshKernel._mesh2d_count_nodes_in_polygons` {#meshkernel--mesh2d-count-nodes-in-polygons} + +```python +_mesh2d_count_nodes_in_polygons(self, geometry_list: GeometryList, inside: bool) -> int +``` + +此成员以内部名称定义,供理解实现及转换流程时参考。 + +仅供内部使用。 + +统计选中的网格节点索引数量。 调用方应在 `mesh2d_get_nodes_in_polygons` 前调用此函数, 以分配保存选择结果的整数数组。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `geometry_list` | `GeometryList` | `必填` | 源码未单独提供参数说明。 | +| `inside` | `bool` | `必填` | 源码未单独提供参数说明。 | + + +**返回值** + +- **`int`**:选中的节点数。 + +### `MeshKernel.mesh1d_set` {#meshkernel-mesh1d-set} + +```python +mesh1d_set(self, mesh1d: Mesh1d) -> None +``` + +设置 MeshKernel 的一维网格状态。 + +注意,此操作会复制数据。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `mesh1d` | `Mesh1d` | `必填` | 用于设置状态的输入数据。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh1d_add` {#meshkernel-mesh1d-add} + +```python +mesh1d_add(self, mesh1d: Mesh1d) -> None +``` + +添加一维网格。 + +注意,此操作会复制数据。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `mesh1d` | `Mesh1d` | `必填` | 用于设置状态的输入数据。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh1d_get` {#meshkernel-mesh1d-get} + +```python +mesh1d_get(self) -> Mesh1d +``` + +从 MeshKernel 获取一维网格状态。 + +注意,此操作会复制数据。 + +**返回值** + +- **`Mesh1d`**:一维网格状态的副本。(原文误写为二维。) + +### `MeshKernel._mesh1d_get_dimensions` {#meshkernel--mesh1d-get-dimensions} + +```python +_mesh1d_get_dimensions(self) -> CMesh1d +``` + +此成员以内部名称定义,供理解实现及转换流程时参考。 + +仅供内部使用。 + +获取 Mesh1d 的维度信息。 将 Mesh1D 结构体中的整数参数设置为对应维度。 传入 `mesh1d_get` 前,必须让结构体指针指向大小正确的内存。 + +**返回值** + +- **`CMesh1d`**:已设置维度信息的 CMesh1d。 + +### `MeshKernel.contacts_set` {#meshkernel-contacts-set} + +```python +contacts_set(self, contacts: Contacts) -> None +``` + +设置网格连接。 + +注意,此操作会复制数据。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `contacts` | `Contacts` | `必填` | 用于设置网格连接的输入数据。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel._contacts_get_dimensions` {#meshkernel--contacts-get-dimensions} + +```python +_contacts_get_dimensions(self) -> CContacts +``` + +此成员以内部名称定义,供理解实现及转换流程时参考。 + +仅供内部使用。 + +获取 Contacts 的维度信息。 将 Contacts 结构体中的整数参数设置为对应维度。 传入 `contacts_get` 前,必须让结构体指针指向大小正确的内存。 + +**返回值** + +- **`CContacts`**:已设置维度信息的 Contacts。 + +### `MeshKernel.contacts_get` {#meshkernel-contacts-get} + +```python +contacts_get(self) -> Contacts +``` + +从 MeshKernel 获取 Mesh1d 和 Mesh2d 之间的连接。 + +注意,此操作会复制数据。 + +**返回值** + +- **`Contacts`**:网格连接。 + +### `MeshKernel.contacts_compute_single` {#meshkernel-contacts-compute-single} + +```python +contacts_compute_single(self, node_mask: ndarray, polygons: GeometryList, projection_factor: float) -> None +``` + +计算一维与二维网格的连接,使每个一维节点连接到一个二维网格面的外心。 一维网格的边界节点(仅关联一条一维边的节点)不会连接到任何二维网格面。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `node_mask` | `ndarray` | `必填` | 布尔数组,用于指定一维节点是否 参与连接。 | +| `polygons` | `GeometryList` | `必填` | 用于选择连接生成区域的多边形。 | +| `projection_factor` | `float` | `必填` | 当一维节点位于二维网格外部时,生成连接所用的 投影系数。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.contacts_compute_multiple` {#meshkernel-contacts-compute-multiple} + +```python +contacts_compute_multiple(self, node_mask: ndarray) -> None +``` + +计算一维与二维网格的连接,使一个一维节点连接到 多个二维网格面的外心。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `node_mask` | `ndarray` | `必填` | 布尔数组,用于指定一维节点是否 参与连接。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.contacts_compute_with_polygons` {#meshkernel-contacts-compute-with-polygons} + +```python +contacts_compute_with_polygons(self, node_mask: ndarray, polygons: GeometryList) -> None +``` + +计算一维与二维网格的连接,将每个多边形内的一个二维网格面连接到最近的一维节点。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `node_mask` | `ndarray` | `必填` | 布尔数组,用于指定一维节点是否 参与连接。 | +| `polygons` | `GeometryList` | `必填` | 在这些多边形中,将距离一维节点最近的二维网格面与之连接。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.contacts_compute_with_points` {#meshkernel-contacts-compute-with-points} + +```python +contacts_compute_with_points(self, node_mask: ndarray, polygons: GeometryList=GeometryList()) -> None +``` + +计算一维与二维网格的连接,将一维节点连接到包含 输入点的二维网格面的质心。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `node_mask` | `ndarray` | `必填` | 布尔数组,用于指定一维节点是否 参与连接。 | +| `polygons` | `GeometryList` | `GeometryList()` | 用于选择待连接二维网格面的多边形。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.contacts_compute_boundary` {#meshkernel-contacts-compute-boundary} + +```python +contacts_compute_boundary(self, node_mask: ndarray, search_radius: float, polygons: GeometryList=GeometryList()) -> None +``` + +计算一维与二维网格的连接,将一维节点连接到边界处最近的二维网格面。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `node_mask` | `ndarray` | `必填` | 布尔数组,用于指定一维节点是否 参与连接(1 表示生成连接,0 表示不生成连接)。 | +| `search_radius` | `float` | `必填` | 搜索相邻二维网格面的半径,笛卡尔投影下以米为单位, 球面投影下以度为单位。若等于双精度缺失值, 则在内部计算搜索半径。 | +| `polygons` | `GeometryList` | `GeometryList()` | 用于选择待连接二维网格面的多边形。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_casulli_derefinement` {#meshkernel-mesh2d-casulli-derefinement} + +```python +mesh2d_casulli_derefinement(self) -> None +``` + +使用 Casulli 算法粗化整个网格。 + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_casulli_derefinement_on_polygon` {#meshkernel-mesh2d-casulli-derefinement-on-polygon} + +```python +mesh2d_casulli_derefinement_on_polygon(self, polygon: GeometryList) -> None +``` + +使用 Casulli 算法粗化指定网格区域。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `polygon` | `GeometryList` | `必填` | 输入多边形。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_delete_property` {#meshkernel-mesh2d-delete-property} + +```python +mesh2d_delete_property(self, property_id: int) +``` + +删除属性及其计算器。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `property_id` | `int` | `必填` | 属性标识符。 | + + +### `MeshKernel.mesh2d_set_property` {#meshkernel-mesh2d-set-property} + +```python +mesh2d_set_property(self, interpolation_parameters: InterpolationParameters, sample_data: GeometryList) -> int +``` + +设置网格属性数据,采样数据点无需与二维网格节点重合。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `interpolation_parameters` | `InterpolationParameters` | `必填` | 插值所需的参数。 | +| `sample_data` | `GeometryList` | `必填` | 采样数据及对应的采样点。 | + + +**返回值** + +- **`int`**:属性标识符。 + +### `MeshKernel.mesh2d_casulli_refinement_based_on_depths` {#meshkernel-mesh2d-casulli-refinement-based-on-depths} + +```python +mesh2d_casulli_refinement_based_on_depths(self, polygons: GeometryList, property_id: int, meshRefinementParameters: MeshRefinementParameters, minimumRefinementDepth: float) -> None +``` + +根据水深值使用 Casulli 加密算法加密网格。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `polygons` | `GeometryList` | `必填` | 计算加密的区域多边形。 | +| `property_id` | `int` | `必填` | 要使用的插值器标识符。 | +| `meshRefinementParameters` | `MeshRefinementParameters` | `必填` | 指定网格加密方式的参数。 | +| `minimumRefinementDepth` | `float` | `必填` | 水深值小于此阈值的节点不会被标记为需要加密。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_casulli_refinement` {#meshkernel-mesh2d-casulli-refinement} + +```python +mesh2d_casulli_refinement(self) -> None +``` + +使用 Casulli 算法加密整个网格。 + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_casulli_refinement_on_polygon` {#meshkernel-mesh2d-casulli-refinement-on-polygon} + +```python +mesh2d_casulli_refinement_on_polygon(self, polygon: GeometryList) -> None +``` + +使用 Casulli 算法加密指定网格区域。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `polygon` | `GeometryList` | `必填` | 输入多边形。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_compute_orthogonalization` {#meshkernel-mesh2d-compute-orthogonalization} + +```python +mesh2d_compute_orthogonalization(self, project_to_land_boundary_option: ProjectToLandBoundaryOption, orthogonalization_parameters: OrthogonalizationParameters, land_boundaries: GeometryList, selecting_polygon: GeometryList=GeometryList()) -> None +``` + +对二维网格进行正交化。 该函数修改网格,使网格边与 连接网格面外心的线段之间尽量正交。 正交程度与网格平滑程度之间需要权衡;此处平滑性体现为网格面面积的均匀程度。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `project_to_land_boundary_option` | `ProjectToLandBoundaryOption` | `必填` | 用于确定如何贴合 陆地边界的选项。 | +| `orthogonalization_parameters` | `OrthogonalizationParameters` | `必填` | 正交化参数。 | +| `land_boundaries` | `GeometryList` | `必填` | 正交化过程中需要考虑的陆地边界。 | +| `selecting_polygon` | `GeometryList` | `GeometryList()` | 执行正交化的区域多边形。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.mesh2d_get_orthogonality` {#meshkernel-mesh2d-get-orthogonality} + +```python +mesh2d_get_orthogonality(self) -> GeometryList +``` + +获取网格正交性,以网格边与 连接网格面外心的线段之间的比值表示。 + +**返回值** + +- **`GeometryList`**:包含每条边正交性数值的几何列表。 + +### `MeshKernel.mesh2d_get_property` {#meshkernel-mesh2d-get-property} + +```python +mesh2d_get_property(self, mesh2d_location: Mesh2dLocation, property: Mesh2dProperty) -> GeometryList +``` + +获取指标值位于最小值和最大值之间的多边形。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `mesh2d_location` | `Mesh2dLocation` | `必填` | 属性所在的网格位置。 | +| `property` | `Mesh2dProperty` | `必填` | 要获取的属性。 | + + +**返回值** + +- **`GeometryList`**:包含属性值的结果几何列表。 + +### `MeshKernel.mesh2d_get_smoothness` {#meshkernel-mesh2d-get-smoothness} + +```python +mesh2d_get_smoothness(self) +``` + +获取平滑性,以两个相邻网格面面积的比值表示。 + +**返回值** + +- **`GeometryList`**:包含每条边平滑性数值的几何列表。 + +### `MeshKernel.mesh2d_connect_meshes` {#meshkernel-mesh2d-connect-meshes} + +```python +mesh2d_connect_meshes(self, mesh2d: Mesh2d, connect: bool, polygon: GeometryList=GeometryList(), search_fraction: float=float(0.4)) -> None +``` + +将网格连接到现有网格。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `mesh2d` | `Mesh2d` | `必填` | 要连接到现有网格的网格。 | +| `connect` | `bool` | `必填` | 是否通过添加额外的边来连接网格。 | +| `polygon` | `GeometryList` | `GeometryList()` | 连接网格时考虑的区域;若为空,表示考虑整个 计算域。 | +| `search_fraction` | `float` | `float(0.4)` | 用于判断两条边是否足够接近、可以连接, 其值为最短边长的一个比例。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel._get_error` {#meshkernel--get-error} + +```python +_get_error(self) -> str +``` + +此成员以内部名称定义,供理解实现及转换流程时参考。 + +源码未为此成员编写文档字符串;下面保留完整签名和参数信息。 + +**返回类型**:`str`。源码未单独说明返回值。 + +### `MeshKernel._get_geometry_error` {#meshkernel--get-geometry-error} + +```python +_get_geometry_error(self) -> Tuple[int, Mesh2dLocation] +``` + +此成员以内部名称定义,供理解实现及转换流程时参考。 + +获取几何错误信息。 + +**返回值** + +- **`index`(`int`)**:索引。 + +- **`location`(`int`)**:位置。 + +### `MeshKernel.mesh2d_triangulation_interpolation` {#meshkernel-mesh2d-triangulation-interpolation} + +```python +mesh2d_triangulation_interpolation(self, samples: GeometryList, location_type: Mesh2dLocation) -> GeometryList +``` + +对采样数据进行三角剖分插值。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `samples` | `GeometryList` | `必填` | 待插值的采样数据。 | +| `location_type` | `Mesh2dLocation` | `必填` | 插值目标的网格位置类型。 | + + +**返回值** + +- **`GeometryList`**:插值后的采样数据。 + +### `MeshKernel.mesh2d_averaging_interpolation` {#meshkernel-mesh2d-averaging-interpolation} + +```python +mesh2d_averaging_interpolation(self, samples: GeometryList, location_type: Mesh2dLocation, averaging_method: AveragingMethod, relative_search_size: float, min_samples: int) -> GeometryList +``` + +对采样数据进行平均插值。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `samples` | `GeometryList` | `必填` | 待插值的采样数据。 | +| `location_type` | `Mesh2dLocation` | `必填` | 插值目标的网格位置类型。 | +| `averaging_method` | `AveragingMethod` | `必填` | 平均方法。 | +| `relative_search_size` | `float` | `必填` | 相对搜索范围。 | +| `min_samples` | `int` | `必填` | 某些插值算法执行有效插值 所需的最少采样点数。 | + + +**返回值** + +- **`GeometryList`**:插值后的采样数据。 + +### `MeshKernel.mesh2d_convert_projection` {#meshkernel-mesh2d-convert-projection} + +```python +mesh2d_convert_projection(self, projection: ProjectionType, zone: str) -> None +``` + +转换二维网格的投影。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `projection` | `ProjectionType` | `必填` | 新的网格投影。 | +| `zone` | `str` | `必填` | UTM 分区及相关信息字符串。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.get_projection` {#meshkernel-get-projection} + +```python +get_projection(self) -> ProjectionType +``` + +获取 MeshKernel 状态的投影类型。 + +**返回值** + +- **`ProjectionType`**:投影类型。 + +### `MeshKernel.get_meshkernel_version` {#meshkernel-get-meshkernel-version} + +```python +get_meshkernel_version(self) -> str +``` + +获取底层 C++ MeshKernel 库的版本。 + +**返回值** + +- **`str`**:版本字符串。 + +### `MeshKernel.get_meshkernelpy_version` {#meshkernel-get-meshkernelpy-version} + +```python +get_meshkernelpy_version(self) -> str +``` + +获取此 Python 封装库的版本。 + +**返回值** + +- **`str`**:版本字符串。 + +### `MeshKernel.mkernel_get_separator` {#meshkernel-mkernel-get-separator} + +```python +mkernel_get_separator(self) -> float +``` + +获取 MeshKernel 使用的分隔值。 + +**返回值** + +- **`float`**:分隔值。 + +### `MeshKernel.mkernel_get_inner_outer_separator` {#meshkernel-mkernel-get-inner-outer-separator} + +```python +mkernel_get_inner_outer_separator(self) -> float +``` + +获取 MeshKernel 用于分隔多边形外边界与内边界的分隔值。 + +**返回值** + +- **`float`**:多边形内/外边界分隔值。 + +### `MeshKernel._execute_function` {#meshkernel--execute-function} + +```python +_execute_function(self, function, *args) +``` + +此成员以内部名称定义,供理解实现及转换流程时参考。 + +执行 MeshKernel C 函数并检查其状态的辅助函数。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `function` | `Callable` | `必填` | 要调用的函数。 | +| `args` | `未标注` | `不适用` | 可变位置参数。传递给 `function` 的参数。 | + + +**异常** + +- **`MeshKernelError`**:当 MeshKernel 库 报告错误时抛出此异常。 + +### `MeshKernel._curvilineargrid_get_dimensions` {#meshkernel--curvilineargrid-get-dimensions} + +```python +_curvilineargrid_get_dimensions(self) -> CCurvilinearGrid +``` + +此成员以内部名称定义,供理解实现及转换流程时参考。 + +仅供内部使用。 + +获取曲线网格的维度信息。 将曲线网格结构体中的整数参数设置为对应维度。 传入 `curvilineargrid_get` 前,必须让结构体指针指向大小正确的内存。 + +**返回值** + +- **`CMesh1d`**:已设置维度信息的 CCurvilinearGrid。(原文返回类型标签为 CMesh1d。) + +### `MeshKernel.curvilineargrid_get` {#meshkernel-curvilineargrid-get} + +```python +curvilineargrid_get(self) -> CurvilinearGrid +``` + +从 MeshKernel 获取曲线网格状态。 + +注意,此操作会复制数据。 + +**返回值** + +- **`CurvilinearGrid`**:曲线网格状态的副本。 + +### `MeshKernel.curvilinear_compute_transfinite_from_splines` {#meshkernel-curvilinear-compute-transfinite-from-splines} + +```python +curvilinear_compute_transfinite_from_splines(self, splines: GeometryList, curvilinear_parameters: CurvilinearParameters) -> None +``` + +通过超限插值从样条曲线生成曲线网格。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `splines` | `GeometryList` | `必填` | 生成曲线网格所用的样条曲线。 | +| `curvilinear_parameters` | `CurvilinearParameters` | `必填` | 曲线网格参数。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.curvilinear_compute_orthogonal_from_splines` {#meshkernel-curvilinear-compute-orthogonal-from-splines} + +```python +curvilinear_compute_orthogonal_from_splines(self, splines: GeometryList, curvilinear_parameters: CurvilinearParameters, splines_to_curvilinear_parameters: SplinesToCurvilinearParameters) -> None +``` + +通过推进前沿法从样条曲线生成曲线网格。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `splines` | `GeometryList` | `必填` | 生成曲线网格所用的样条曲线。 | +| `curvilinear_parameters` | `CurvilinearParameters` | `必填` | 曲线网格参数。 | +| `splines_to_curvilinear_parameters` | `SplinesToCurvilinearParameters` | `必填` | 算法所需的 附加参数。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.curvilinear_compute_curvature` {#meshkernel-curvilinear-compute-curvature} + +```python +curvilinear_compute_curvature(self, direction: CurvilinearDirection) -> ndarray +``` + +计算曲线网格的曲率。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `direction` | `CurvilinearDirection` | `必填` | 计算平滑性的方向。(此说明也出现在曲率方法中,按原文保留。) | + + +**返回类型**:`ndarray`。源码未单独说明返回值。 + +### `MeshKernel.curvilinear_compute_smoothness` {#meshkernel-curvilinear-compute-smoothness} + +```python +curvilinear_compute_smoothness(self, direction: CurvilinearDirection) -> ndarray +``` + +计算曲线网格的平滑性。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `direction` | `CurvilinearDirection` | `必填` | 计算平滑性的方向。(此说明也出现在曲率方法中,按原文保留。) | + + +**返回类型**:`ndarray`。源码未单独说明返回值。 + +### `MeshKernel.curvilinear_convert_to_mesh2d` {#meshkernel-curvilinear-convert-to-mesh2d} + +```python +curvilinear_convert_to_mesh2d(self) -> None +``` + +将曲线网格转换为非结构网格。 + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.curvilinear_compute_rectangular_grid` {#meshkernel-curvilinear-compute-rectangular-grid} + +```python +curvilinear_compute_rectangular_grid(self, make_grid_parameters: MakeGridParameters) -> None +``` + +生成矩形网格。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `make_grid_parameters` | `MakeGridParameters` | `必填` | 生成均匀网格所用的参数。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.curvilinear_compute_rectangular_grid_from_polygon` {#meshkernel-curvilinear-compute-rectangular-grid-from-polygon} + +```python +curvilinear_compute_rectangular_grid_from_polygon(self, make_grid_parameters: MakeGridParameters, geometry_list: GeometryList) -> None +``` + +根据多边形生成矩形网格。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `make_grid_parameters` | `MakeGridParameters` | `必填` | 生成均匀网格所用的参数。 | +| `geometry_list` | `GeometryList` | `必填` | 生成网格的区域多边形。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.curvilinear_compute_rectangular_grid_on_extension` {#meshkernel-curvilinear-compute-rectangular-grid-on-extension} + +```python +curvilinear_compute_rectangular_grid_on_extension(self, make_grid_parameters: MakeGridParameters) -> None +``` + +在指定范围内生成矩形网格。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `make_grid_parameters` | `MakeGridParameters` | `必填` | 生成均匀网格所用的参数。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.curvilinear_refine` {#meshkernel-curvilinear-refine} + +```python +curvilinear_refine(self, x_lower_left_corner: float, y_lower_left_corner: float, x_upper_right_corner: float, y_upper_right_corner: float, refinement: int) -> None +``` + +曲线网格定向加密。 沿垂直于 lower_left_corner 和 upper_right_corner 所定义线段的方向添加网格线。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `x_lower_left_corner` | `float` | `必填` | 待加密网格块左下角的 x 坐标。 | +| `y_lower_left_corner` | `float` | `必填` | 待加密网格块左下角的 y 坐标。 | +| `x_upper_right_corner` | `float` | `必填` | 待加密网格块右上角的 x 坐标。 | +| `y_upper_right_corner` | `float` | `必填` | 待加密网格块右上角的 y 坐标。 | +| `refinement` | `int` | `必填` | 在左下角与右上角之间添加的网格线数量。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.curvilinear_compute_transfinite_from_polygon` {#meshkernel-curvilinear-compute-transfinite-from-polygon} + +```python +curvilinear_compute_transfinite_from_polygon(self, geometry_list: GeometryList, first_node: int, second_node: int, third_node: int, use_fourth_side: bool) -> None +``` + +在多边形内部计算曲线网格,需要选取三个不同的多边形节点。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `geometry_list` | `GeometryList` | `必填` | 输入多边形。 | +| `first_node` | `int` | `必填` | 第一个选中的节点。 | +| `second_node` | `int` | `必填` | 第二个选中的节点。 | +| `third_node` | `int` | `必填` | 第三个选中的节点。 | +| `use_fourth_side` | `bool` | `必填` | 是否使用多边形的第四条边计算曲线网格。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.curvilinear_compute_transfinite_from_triangle` {#meshkernel-curvilinear-compute-transfinite-from-triangle} + +```python +curvilinear_compute_transfinite_from_triangle(self, geometry_list: GeometryList, first_node: int, second_node: int, third_node: int) -> None +``` + +在三角形内部计算曲线网格,需要选取三个不同的多边形节点。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `geometry_list` | `GeometryList` | `必填` | 输入多边形。 | +| `first_node` | `int` | `必填` | 第一个选中的节点。 | +| `second_node` | `int` | `必填` | 第二个选中的节点。 | +| `third_node` | `int` | `必填` | 第三个选中的节点。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.curvilinear_orthogonalize` {#meshkernel-curvilinear-orthogonalize} + +```python +curvilinear_orthogonalize(self, orthogonalization_parameters: OrthogonalizationParameters, x_lower_left_corner: float, y_lower_left_corner: float, x_upper_right_corner: float, y_upper_right_corner: float) -> None +``` + +对曲线网格内指定网格块进行正交化。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `orthogonalization_parameters` | `OrthogonalizationParameters` | `必填` | 源码未单独提供参数说明。 | +| `x_lower_left_corner` | `float` | `必填` | 网格块左下角的 x 坐标。 | +| `y_lower_left_corner` | `float` | `必填` | 网格块左下角的 y 坐标。 | +| `x_upper_right_corner` | `float` | `必填` | 网格块右上角的 x 坐标。 | +| `y_upper_right_corner` | `float` | `必填` | 网格块右上角的 y 坐标。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.curvilinear_frozen_line_is_valid` {#meshkernel-curvilinear-frozen-line-is-valid} + +```python +curvilinear_frozen_line_is_valid(self, frozen_line_id: int) -> bool +``` + +检查固定网格线标识符是否有效。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `frozen_line_id` | `int` | `必填` | 待验证的固定网格线标识符。 | + + +**返回值** + +- **`bool`**:若 MeshKernel 状态中存在该固定网格线,则为 True,否则为 False。 + +### `MeshKernel.curvilinear_frozen_line_delete` {#meshkernel-curvilinear-frozen-line-delete} + +```python +curvilinear_frozen_line_delete(self, frozen_line_id: int) +``` + +删除曲线网格中的固定网格线。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `frozen_line_id` | `int` | `必填` | 待删除的固定网格线标识符。 | + + +### `MeshKernel.curvilinear_frozen_line_add` {#meshkernel-curvilinear-frozen-line-add} + +```python +curvilinear_frozen_line_add(self, x_first_grid_line_node: float, y_first_grid_line_node: float, x_second_grid_line_node: float, y_second_grid_line_node: float) -> int +``` + +向 MeshKernel 状态添加固定网格线。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `x_first_grid_line_node` | `float` | `必填` | 第一个网格线节点的 x 坐标。 | +| `y_first_grid_line_node` | `float` | `必填` | 第一个网格线节点的 y 坐标。 | +| `x_second_grid_line_node` | `float` | `必填` | 第二个网格线节点的 x 坐标。 | +| `y_second_grid_line_node` | `float` | `必填` | 第二个网格线节点的 y 坐标。 | + + +**返回值** + +MeshKernel 状态中新添加的固定网格线标识符。 + +### `MeshKernel.curvilinear_frozen_line_get` {#meshkernel-curvilinear-frozen-line-get} + +```python +curvilinear_frozen_line_get(self, frozen_line_id: int) -> tuple[float, float, float, float] +``` + +获取曲线网格中固定网格线的坐标。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `frozen_line_id` | `int` | `必填` | 待获取的固定网格线标识符。若找不到该标识符, 则返回包含无效坐标的元组。 | + + +**返回值** + +- **`tuple`**:包含以下内容的元组: + +- **`x_first_frozen_line_coordinate`(`float`)**:第一个固定网格线节点的 x 坐标。 + +- **`y_first_frozen_line_coordinate`(`float`)**:第一个固定网格线节点的 y 坐标。 + +- **`x_second_frozen_line_coordinate`(`float`)**:第二个固定网格线节点的 x 坐标。 + +- **`y_second_frozen_line_coordinate`(`float`)**:第二个固定网格线节点的 y 坐标。 + +### `MeshKernel.curvilinear_frozen_lines_get_ids` {#meshkernel-curvilinear-frozen-lines-get-ids} + +```python +curvilinear_frozen_lines_get_ids(self) -> np.ndarray +``` + +获取曲线网格中所有有效固定网格线的标识符。 + +**返回值** + +包含固定网格线标识符的 NumPy 数组。 + +### `MeshKernel.curvilinear_smoothing` {#meshkernel-curvilinear-smoothing} + +```python +curvilinear_smoothing(self, smoothing_iterations: int, x_lower_left_corner: float, y_lower_left_corner: float, x_upper_right_corner: float, y_upper_right_corner: float) -> None +``` + +平滑曲线网格。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `smoothing_iterations` | `int` | `必填` | 要执行的平滑迭代次数。 | +| `x_lower_left_corner` | `float` | `必填` | 待加密网格块左下角的 x 坐标。 | +| `y_lower_left_corner` | `float` | `必填` | 待加密网格块左下角的 y 坐标。 | +| `x_upper_right_corner` | `float` | `必填` | 待加密网格块右上角的 x 坐标。 | +| `y_upper_right_corner` | `float` | `必填` | 待加密网格块右上角的 y 坐标。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.curvilinear_smoothing_directional` {#meshkernel-curvilinear-smoothing-directional} + +```python +curvilinear_smoothing_directional(self, smoothing_iterations: int, x_first_grid_line_node: float, y_first_grid_line_node: float, x_second_grid_line_node: float, y_second_grid_line_node: float, x_lower_left_corner: float, y_lower_left_corner: float, x_upper_right_corner: float, y_upper_right_corner: float) -> None +``` + +沿指定线段方向平滑曲线网格。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `smoothing_iterations` | `int` | `必填` | 要执行的平滑迭代次数。 | +| `x_first_grid_line_node` | `float` | `必填` | 第一个曲线网格节点的 x 坐标。 | +| `y_first_grid_line_node` | `float` | `必填` | 第一个曲线网格节点的 y 坐标。 | +| `x_second_grid_line_node` | `float` | `必填` | 第二个曲线网格节点的 x 坐标。 | +| `y_second_grid_line_node` | `float` | `必填` | 第二个曲线网格节点的 y 坐标。 | +| `x_lower_left_corner` | `float` | `必填` | 待加密网格块左下角的 x 坐标。 | +| `y_lower_left_corner` | `float` | `必填` | 待加密网格块左下角的 y 坐标。 | +| `x_upper_right_corner` | `float` | `必填` | 待加密网格块右上角的 x 坐标。 | +| `y_upper_right_corner` | `float` | `必填` | 待加密网格块右上角的 y 坐标。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.curvilinear_initialize_line_shift` {#meshkernel-curvilinear-initialize-line-shift} + +```python +curvilinear_initialize_line_shift(self) -> None +``` + +初始化曲线网格线平移算法。 + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.curvilinear_set_line_line_shift` {#meshkernel-curvilinear-set-line-line-shift} + +```python +curvilinear_set_line_line_shift(self, x_first_grid_line_node: float, y_first_grid_line_node: float, x_second_grid_line_node: float, y_second_grid_line_node: float) -> None +``` + +设置待平移网格线的起点和终点节点。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `x_first_grid_line_node` | `float` | `必填` | 待平移网格线第一个节点的 x 坐标。 | +| `y_first_grid_line_node` | `float` | `必填` | 待平移网格线第一个节点的 y 坐标。 | +| `x_second_grid_line_node` | `float` | `必填` | 待平移网格线第二个节点的 x 坐标。 | +| `y_second_grid_line_node` | `float` | `必填` | 待平移网格线第二个节点的 y 坐标。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.curvilinear_set_block_line_shift` {#meshkernel-curvilinear-set-block-line-shift} + +```python +curvilinear_set_block_line_shift(self, x_lower_left_corner: float, y_lower_left_corner: float, x_upper_right_corner: float, y_upper_right_corner: float) -> None +``` + +定义曲线网格上的网格块,用于分配网格线平移量。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `x_lower_left_corner` | `float` | `必填` | 网格块左下角的 x 坐标。 | +| `y_lower_left_corner` | `float` | `必填` | 网格块左下角的 y 坐标。 | +| `x_upper_right_corner` | `float` | `必填` | 网格块右上角的 x 坐标。 | +| `y_upper_right_corner` | `float` | `必填` | 网格块右上角的 y 坐标。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.curvilinear_move_node_line_shift` {#meshkernel-curvilinear-move-node-line-shift} + +```python +curvilinear_move_node_line_shift(self, x_from_coordinate: float, y_from_coordinate: float, x_to_coordinate: float, y_to_coordinate: float) -> None +``` + +移动待平移网格线的一个节点。可以多次执行此操作。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `x_from_coordinate` | `float` | `必填` | 待移动节点的 x 坐标。 | +| `y_from_coordinate` | `float` | `必填` | 待移动节点的 y 坐标。 | +| `x_to_coordinate` | `float` | `必填` | 节点新位置的 x 坐标。 | +| `y_to_coordinate` | `float` | `必填` | 节点新位置的 y 坐标。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.curvilinear_line_shift` {#meshkernel-curvilinear-line-shift} + +```python +curvilinear_line_shift(self) +``` + +执行曲线网格线平移,并结束算法。 + +### `MeshKernel.curvilinear_move_node` {#meshkernel-curvilinear-move-node} + +```python +curvilinear_move_node(self, x_from_point: float, y_from_point: float, x_to_point: float, y_to_point: float) -> None +``` + +将曲线网格中的一个点从原位置移到新位置。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `x_from_point` | `float` | `必填` | 待移动点的 x 坐标。 | +| `y_from_point` | `float` | `必填` | 待移动点的 y 坐标。 | +| `x_to_point` | `float` | `必填` | 点的新 x 坐标。 | +| `y_to_point` | `float` | `必填` | 点的新 y 坐标。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.curvilinear_insert_face` {#meshkernel-curvilinear-insert-face} + +```python +curvilinear_insert_face(self, x_coordinate: float, y_coordinate: float) -> None +``` + +在曲线网格中插入新网格面。 通过线性外推在距离指定位置最近的边外侧插入新网格面。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `x_coordinate` | `float` | `必填` | 用于查找最近网格面的点的 x 坐标。 | +| `y_coordinate` | `float` | `必填` | 用于查找最近网格面的点的 y 坐标。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.curvilinear_line_attraction_repulsion` {#meshkernel-curvilinear-line-attraction-repulsion} + +```python +curvilinear_line_attraction_repulsion(self, repulsion_parameter: float, x_first_grid_line_node: float, y_first_grid_line_node: float, x_second_grid_line_node: float, y_second_grid_line_node: float, x_lower_left_corner: float, y_lower_left_corner: float, x_upper_right_corner: float, y_upper_right_corner: float) +``` + +将网格块内的网格线向另一条指定网格线吸引或排斥。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `repulsion_parameter` | `float` | `必填` | 排斥参数。 | +| `x_first_grid_line_node` | `float` | `必填` | 第一个节点的 x 坐标。 | +| `y_first_grid_line_node` | `float` | `必填` | 第一个节点的 y 坐标。 | +| `x_second_grid_line_node` | `float` | `必填` | 第二个节点的 x 坐标。 | +| `y_second_grid_line_node` | `float` | `必填` | 第二个节点的 y 坐标。 | +| `x_lower_left_corner` | `float` | `必填` | 网格块左下角的 x 坐标。 | +| `y_lower_left_corner` | `float` | `必填` | 网格块左下角的 y 坐标。 | +| `x_upper_right_corner` | `float` | `必填` | 网格块右上角的 x 坐标。 | +| `y_upper_right_corner` | `float` | `必填` | 网格块右上角的 y 坐标。 | + + +### `MeshKernel.curvilinear_line_mirror` {#meshkernel-curvilinear-line-mirror} + +```python +curvilinear_line_mirror(self, mirroring_factor: float, num_lines_to_mirror: int, x_first_grid_line_node: float, y_first_grid_line_node: float, x_second_grid_line_node: float, y_second_grid_line_node: float) -> None +``` + +将边界网格线向外镜像扩展。边界网格线由起点和终点定义。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `mirroring_factor` | `float` | `必填` | 镜像系数。 | +| `num_lines_to_mirror` | `int` | `必填` | 要镜像的网格线数量。 | +| `x_first_grid_line_node` | `float` | `必填` | 第一个节点的 x 坐标。 | +| `y_first_grid_line_node` | `float` | `必填` | 第一个节点的 y 坐标。 | +| `x_second_grid_line_node` | `float` | `必填` | 第二个节点的 x 坐标。 | +| `y_second_grid_line_node` | `float` | `必填` | 第二个节点的 y 坐标。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel.curvilinear_delete_node` {#meshkernel-curvilinear-delete-node} + +```python +curvilinear_delete_node(self, x_coordinate: float, y_coordinate: float) -> None +``` + +删除距离指定点最近的节点。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `x_coordinate` | `float` | `必填` | 指定点的 x 坐标。 | +| `y_coordinate` | `float` | `必填` | 指定点的 y 坐标。 | + + +**返回类型**:`None`。源码未单独说明返回值。 + +### `MeshKernel._get_num_coordinates` {#meshkernel--get-num-coordinates} + +```python +_get_num_coordinates(self, location_type) +``` + +此成员以内部名称定义,供理解实现及转换流程时参考。 + +获取指定位置类型的网格坐标数量。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `location_type` | `Mesh2dLocation` | `必填` | 位置类型。 | + + +**异常** + +- **`Exception`**:使用无效位置类型时抛出此异常。 + +### `MeshKernel.__map_to_valid_values` {#meshkernel---map-to-valid-values} + +```python +__map_to_valid_values(self, geometry_list: GeometryList, location_type: Mesh2dLocation) +``` + +此成员以内部名称定义,供理解实现及转换流程时参考。 + +从 geometry_list 中移除无效值。 + +**参数** + +| 名称 | 类型 | 默认值 | 中文说明 | +| --- | --- | --- | --- | +| `geometry_list` | `GeometryList` | `必填` | 输入几何列表。 | +| `location_type` | `Mesh2dLocation` | `必填` | 位置类型。 | + + +**异常** + +- **`Exception`**:使用无效位置类型时抛出此异常。 diff --git a/doc/meshkernelpy/api/meshkernel.py_structures.md b/doc/meshkernelpy/api/meshkernel.py_structures.md new file mode 100644 index 0000000..0320dfa --- /dev/null +++ b/doc/meshkernelpy/api/meshkernel.py_structures.md @@ -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 方向。 | diff --git a/doc/meshkernelpy/api/meshkernel.utils.md b/doc/meshkernelpy/api/meshkernel.utils.md new file mode 100644 index 0000000..b9fe3a4 --- /dev/null +++ b/doc/meshkernelpy/api/meshkernel.utils.md @@ -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() +``` + +获取浮点坐标定义的边界框可用的最大坐标范围。 diff --git a/doc/meshkernelpy/api/meshkernel.version.md b/doc/meshkernelpy/api/meshkernel.version.md new file mode 100644 index 0000000..d237c28 --- /dev/null +++ b/doc/meshkernelpy/api/meshkernel.version.md @@ -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++ 后端版本。 diff --git a/doc/meshkernelpy/api/modules.md b/doc/meshkernelpy/api/modules.md new file mode 100644 index 0000000..4cde242 --- /dev/null +++ b/doc/meshkernelpy/api/modules.md @@ -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) diff --git a/doc/meshkernelpy/examples/01_mesh2d_basics.md b/doc/meshkernelpy/examples/01_mesh2d_basics.md new file mode 100644 index 0000000..5958acb --- /dev/null +++ b/doc/meshkernelpy/examples/01_mesh2d_basics.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) diff --git a/doc/meshkernelpy/examples/02_mesh1d_basics.md b/doc/meshkernelpy/examples/02_mesh1d_basics.md new file mode 100644 index 0000000..a82746c --- /dev/null +++ b/doc/meshkernelpy/examples/02_mesh1d_basics.md @@ -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) diff --git a/doc/meshkernelpy/examples/03_tri_mesh2d_pol.md b/doc/meshkernelpy/examples/03_tri_mesh2d_pol.md new file mode 100644 index 0000000..8d2acbe --- /dev/null +++ b/doc/meshkernelpy/examples/03_tri_mesh2d_pol.md @@ -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) diff --git a/doc/meshkernelpy/examples/04_curvilineargrid_basics.md b/doc/meshkernelpy/examples/04_curvilineargrid_basics.md new file mode 100644 index 0000000..2ee5ccf --- /dev/null +++ b/doc/meshkernelpy/examples/04_curvilineargrid_basics.md @@ -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) diff --git a/doc/meshkernelpy/examples/05_mesh2d_refinement_gridded_samples.md b/doc/meshkernelpy/examples/05_mesh2d_refinement_gridded_samples.md new file mode 100644 index 0000000..c7449e4 --- /dev/null +++ b/doc/meshkernelpy/examples/05_mesh2d_refinement_gridded_samples.md @@ -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) diff --git a/doc/meshkernelpy/examples/06_mesh2d_refinement_gridded_samples_gebco.md b/doc/meshkernelpy/examples/06_mesh2d_refinement_gridded_samples_gebco.md new file mode 100644 index 0000000..4bf6893 --- /dev/null +++ b/doc/meshkernelpy/examples/06_mesh2d_refinement_gridded_samples_gebco.md @@ -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) diff --git a/doc/meshkernelpy/examples/07_curvilineargrid_with_defined_extension.md b/doc/meshkernelpy/examples/07_curvilineargrid_with_defined_extension.md new file mode 100644 index 0000000..844ccdf --- /dev/null +++ b/doc/meshkernelpy/examples/07_curvilineargrid_with_defined_extension.md @@ -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) diff --git a/doc/meshkernelpy/examples/08_mesh2d_orthogonalization.md b/doc/meshkernelpy/examples/08_mesh2d_orthogonalization.md new file mode 100644 index 0000000..074e1cf --- /dev/null +++ b/doc/meshkernelpy/examples/08_mesh2d_orthogonalization.md @@ -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) diff --git a/doc/meshkernelpy/examples/09_mesh2d_deletion.md b/doc/meshkernelpy/examples/09_mesh2d_deletion.md new file mode 100644 index 0000000..e3690ed --- /dev/null +++ b/doc/meshkernelpy/examples/09_mesh2d_deletion.md @@ -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) diff --git a/doc/meshkernelpy/examples/10_mesh2d_global_grid.md b/doc/meshkernelpy/examples/10_mesh2d_global_grid.md new file mode 100644 index 0000000..fabcfad --- /dev/null +++ b/doc/meshkernelpy/examples/10_mesh2d_global_grid.md @@ -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) diff --git a/doc/meshkernelpy/examples/11_mesh2d_refine_ridges_gridded_samples.md b/doc/meshkernelpy/examples/11_mesh2d_refine_ridges_gridded_samples.md new file mode 100644 index 0000000..dbfbda7 --- /dev/null +++ b/doc/meshkernelpy/examples/11_mesh2d_refine_ridges_gridded_samples.md @@ -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) diff --git a/doc/meshkernelpy/examples/12_mesh2d_refine_gridded_samples_coastlines.md b/doc/meshkernelpy/examples/12_mesh2d_refine_gridded_samples_coastlines.md new file mode 100644 index 0000000..49aada3 --- /dev/null +++ b/doc/meshkernelpy/examples/12_mesh2d_refine_gridded_samples_coastlines.md @@ -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) diff --git a/doc/meshkernelpy/examples/13_mesh2d_refine_gridded_samples_strided_arrays.md b/doc/meshkernelpy/examples/13_mesh2d_refine_gridded_samples_strided_arrays.md new file mode 100644 index 0000000..6f983cb --- /dev/null +++ b/doc/meshkernelpy/examples/13_mesh2d_refine_gridded_samples_strided_arrays.md @@ -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) diff --git a/doc/meshkernelpy/examples/14_contacts_generation.md b/doc/meshkernelpy/examples/14_contacts_generation.md new file mode 100644 index 0000000..e0e1ee4 --- /dev/null +++ b/doc/meshkernelpy/examples/14_contacts_generation.md @@ -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) diff --git a/doc/meshkernelpy/examples/15_mesh2d_refinement_casulli_based_on_depths.md b/doc/meshkernelpy/examples/15_mesh2d_refinement_casulli_based_on_depths.md new file mode 100644 index 0000000..4d5729f --- /dev/null +++ b/doc/meshkernelpy/examples/15_mesh2d_refinement_casulli_based_on_depths.md @@ -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 + +``` + +![单元格 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) diff --git a/doc/meshkernelpy/examples/images/01_mesh2d_basics_13_0.png b/doc/meshkernelpy/examples/images/01_mesh2d_basics_13_0.png new file mode 100644 index 0000000..cb5911c Binary files /dev/null and b/doc/meshkernelpy/examples/images/01_mesh2d_basics_13_0.png differ diff --git a/doc/meshkernelpy/examples/images/01_mesh2d_basics_20_0.png b/doc/meshkernelpy/examples/images/01_mesh2d_basics_20_0.png new file mode 100644 index 0000000..33c2542 Binary files /dev/null and b/doc/meshkernelpy/examples/images/01_mesh2d_basics_20_0.png differ diff --git a/doc/meshkernelpy/examples/images/01_mesh2d_basics_22_0.png b/doc/meshkernelpy/examples/images/01_mesh2d_basics_22_0.png new file mode 100644 index 0000000..3edf1c8 Binary files /dev/null and b/doc/meshkernelpy/examples/images/01_mesh2d_basics_22_0.png differ diff --git a/doc/meshkernelpy/examples/images/01_mesh2d_basics_30_0.png b/doc/meshkernelpy/examples/images/01_mesh2d_basics_30_0.png new file mode 100644 index 0000000..f4d94bd Binary files /dev/null and b/doc/meshkernelpy/examples/images/01_mesh2d_basics_30_0.png differ diff --git a/doc/meshkernelpy/examples/images/01_mesh2d_basics_34_0.png b/doc/meshkernelpy/examples/images/01_mesh2d_basics_34_0.png new file mode 100644 index 0000000..d5362c2 Binary files /dev/null and b/doc/meshkernelpy/examples/images/01_mesh2d_basics_34_0.png differ diff --git a/doc/meshkernelpy/examples/images/01_mesh2d_basics_40_0.png b/doc/meshkernelpy/examples/images/01_mesh2d_basics_40_0.png new file mode 100644 index 0000000..cb5911c Binary files /dev/null and b/doc/meshkernelpy/examples/images/01_mesh2d_basics_40_0.png differ diff --git a/doc/meshkernelpy/examples/images/01_mesh2d_basics_9_0.png b/doc/meshkernelpy/examples/images/01_mesh2d_basics_9_0.png new file mode 100644 index 0000000..7c4b3d9 Binary files /dev/null and b/doc/meshkernelpy/examples/images/01_mesh2d_basics_9_0.png differ diff --git a/doc/meshkernelpy/examples/images/02_mesh1d_basics_18_0.png b/doc/meshkernelpy/examples/images/02_mesh1d_basics_18_0.png new file mode 100644 index 0000000..6966d86 Binary files /dev/null and b/doc/meshkernelpy/examples/images/02_mesh1d_basics_18_0.png differ diff --git a/doc/meshkernelpy/examples/images/02_mesh1d_basics_26_0.png b/doc/meshkernelpy/examples/images/02_mesh1d_basics_26_0.png new file mode 100644 index 0000000..8fb7a41 Binary files /dev/null and b/doc/meshkernelpy/examples/images/02_mesh1d_basics_26_0.png differ diff --git a/doc/meshkernelpy/examples/images/03_tri_mesh2d_pol_15_0.png b/doc/meshkernelpy/examples/images/03_tri_mesh2d_pol_15_0.png new file mode 100644 index 0000000..8dd5d64 Binary files /dev/null and b/doc/meshkernelpy/examples/images/03_tri_mesh2d_pol_15_0.png differ diff --git a/doc/meshkernelpy/examples/images/03_tri_mesh2d_pol_7_0.png b/doc/meshkernelpy/examples/images/03_tri_mesh2d_pol_7_0.png new file mode 100644 index 0000000..925f99f Binary files /dev/null and b/doc/meshkernelpy/examples/images/03_tri_mesh2d_pol_7_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_10_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_10_0.png new file mode 100644 index 0000000..fe82bbe Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_10_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_15_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_15_0.png new file mode 100644 index 0000000..5b6164b Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_15_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_18_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_18_0.png new file mode 100644 index 0000000..fe82bbe Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_18_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_20_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_20_0.png new file mode 100644 index 0000000..ff110b0 Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_20_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_22_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_22_0.png new file mode 100644 index 0000000..fe82bbe Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_22_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_24_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_24_0.png new file mode 100644 index 0000000..cefa96e Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_24_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_28_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_28_0.png new file mode 100644 index 0000000..40702db Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_28_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_32_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_32_0.png new file mode 100644 index 0000000..043eb91 Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_32_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_35_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_35_0.png new file mode 100644 index 0000000..ff5b6cc Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_35_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_39_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_39_0.png new file mode 100644 index 0000000..4bdf7c3 Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_39_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_41_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_41_0.png new file mode 100644 index 0000000..ff5b6cc Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_41_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_45_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_45_0.png new file mode 100644 index 0000000..9e3d5c7 Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_45_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_48_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_48_0.png new file mode 100644 index 0000000..ff5b6cc Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_48_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_52_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_52_0.png new file mode 100644 index 0000000..e86b92d Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_52_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_55_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_55_0.png new file mode 100644 index 0000000..ff5b6cc Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_55_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_59_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_59_0.png new file mode 100644 index 0000000..067d027 Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_59_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_61_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_61_0.png new file mode 100644 index 0000000..ef69223 Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_61_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_70_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_70_0.png new file mode 100644 index 0000000..998fb4f Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_70_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_72_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_72_0.png new file mode 100644 index 0000000..ef69223 Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_72_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_75_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_75_0.png new file mode 100644 index 0000000..90fa1dd Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_75_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_77_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_77_0.png new file mode 100644 index 0000000..ef69223 Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_77_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_80_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_80_0.png new file mode 100644 index 0000000..e33a30b Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_80_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_84_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_84_0.png new file mode 100644 index 0000000..2115c3e Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_84_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_86_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_86_0.png new file mode 100644 index 0000000..b024a3d Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_86_0.png differ diff --git a/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_90_0.png b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_90_0.png new file mode 100644 index 0000000..0cd2f0b Binary files /dev/null and b/doc/meshkernelpy/examples/images/04_curvilineargrid_basics_90_0.png differ diff --git a/doc/meshkernelpy/examples/images/05_mesh2d_refinement_gridded_samples_16_0.png b/doc/meshkernelpy/examples/images/05_mesh2d_refinement_gridded_samples_16_0.png new file mode 100644 index 0000000..4862dc5 Binary files /dev/null and b/doc/meshkernelpy/examples/images/05_mesh2d_refinement_gridded_samples_16_0.png differ diff --git a/doc/meshkernelpy/examples/images/05_mesh2d_refinement_gridded_samples_19_0.png b/doc/meshkernelpy/examples/images/05_mesh2d_refinement_gridded_samples_19_0.png new file mode 100644 index 0000000..749a9cc Binary files /dev/null and b/doc/meshkernelpy/examples/images/05_mesh2d_refinement_gridded_samples_19_0.png differ diff --git a/doc/meshkernelpy/examples/images/05_mesh2d_refinement_gridded_samples_23_0.png b/doc/meshkernelpy/examples/images/05_mesh2d_refinement_gridded_samples_23_0.png new file mode 100644 index 0000000..fcb3777 Binary files /dev/null and b/doc/meshkernelpy/examples/images/05_mesh2d_refinement_gridded_samples_23_0.png differ diff --git a/doc/meshkernelpy/examples/images/05_mesh2d_refinement_gridded_samples_8_0.png b/doc/meshkernelpy/examples/images/05_mesh2d_refinement_gridded_samples_8_0.png new file mode 100644 index 0000000..749a9cc Binary files /dev/null and b/doc/meshkernelpy/examples/images/05_mesh2d_refinement_gridded_samples_8_0.png differ diff --git a/doc/meshkernelpy/examples/images/06_mesh2d_refinement_gridded_samples_gebco_29_0.png b/doc/meshkernelpy/examples/images/06_mesh2d_refinement_gridded_samples_gebco_29_0.png new file mode 100644 index 0000000..97fdcce Binary files /dev/null and b/doc/meshkernelpy/examples/images/06_mesh2d_refinement_gridded_samples_gebco_29_0.png differ diff --git a/doc/meshkernelpy/examples/images/06_mesh2d_refinement_gridded_samples_gebco_4_0.png b/doc/meshkernelpy/examples/images/06_mesh2d_refinement_gridded_samples_gebco_4_0.png new file mode 100644 index 0000000..781cc7d Binary files /dev/null and b/doc/meshkernelpy/examples/images/06_mesh2d_refinement_gridded_samples_gebco_4_0.png differ diff --git a/doc/meshkernelpy/examples/images/07_curvilineargrid_with_defined_extension_16_0.png b/doc/meshkernelpy/examples/images/07_curvilineargrid_with_defined_extension_16_0.png new file mode 100644 index 0000000..3e5c260 Binary files /dev/null and b/doc/meshkernelpy/examples/images/07_curvilineargrid_with_defined_extension_16_0.png differ diff --git a/doc/meshkernelpy/examples/images/07_curvilineargrid_with_defined_extension_9_0.png b/doc/meshkernelpy/examples/images/07_curvilineargrid_with_defined_extension_9_0.png new file mode 100644 index 0000000..386d44d Binary files /dev/null and b/doc/meshkernelpy/examples/images/07_curvilineargrid_with_defined_extension_9_0.png differ diff --git a/doc/meshkernelpy/examples/images/08_mesh2d_orthogonalization_15_0.png b/doc/meshkernelpy/examples/images/08_mesh2d_orthogonalization_15_0.png new file mode 100644 index 0000000..3f44df8 Binary files /dev/null and b/doc/meshkernelpy/examples/images/08_mesh2d_orthogonalization_15_0.png differ diff --git a/doc/meshkernelpy/examples/images/08_mesh2d_orthogonalization_26_0.png b/doc/meshkernelpy/examples/images/08_mesh2d_orthogonalization_26_0.png new file mode 100644 index 0000000..2ba44c1 Binary files /dev/null and b/doc/meshkernelpy/examples/images/08_mesh2d_orthogonalization_26_0.png differ diff --git a/doc/meshkernelpy/examples/images/09_mesh2d_deletion_11_1.png b/doc/meshkernelpy/examples/images/09_mesh2d_deletion_11_1.png new file mode 100644 index 0000000..2863774 Binary files /dev/null and b/doc/meshkernelpy/examples/images/09_mesh2d_deletion_11_1.png differ diff --git a/doc/meshkernelpy/examples/images/09_mesh2d_deletion_18_1.png b/doc/meshkernelpy/examples/images/09_mesh2d_deletion_18_1.png new file mode 100644 index 0000000..39f4191 Binary files /dev/null and b/doc/meshkernelpy/examples/images/09_mesh2d_deletion_18_1.png differ diff --git a/doc/meshkernelpy/examples/images/10_mesh2d_global_grid_5_0.png b/doc/meshkernelpy/examples/images/10_mesh2d_global_grid_5_0.png new file mode 100644 index 0000000..684e905 Binary files /dev/null and b/doc/meshkernelpy/examples/images/10_mesh2d_global_grid_5_0.png differ diff --git a/doc/meshkernelpy/examples/images/11_mesh2d_refine_ridges_gridded_samples_13_0.png b/doc/meshkernelpy/examples/images/11_mesh2d_refine_ridges_gridded_samples_13_0.png new file mode 100644 index 0000000..42b239e Binary files /dev/null and b/doc/meshkernelpy/examples/images/11_mesh2d_refine_ridges_gridded_samples_13_0.png differ diff --git a/doc/meshkernelpy/examples/images/11_mesh2d_refine_ridges_gridded_samples_21_0.png b/doc/meshkernelpy/examples/images/11_mesh2d_refine_ridges_gridded_samples_21_0.png new file mode 100644 index 0000000..16b0b57 Binary files /dev/null and b/doc/meshkernelpy/examples/images/11_mesh2d_refine_ridges_gridded_samples_21_0.png differ diff --git a/doc/meshkernelpy/examples/images/11_mesh2d_refine_ridges_gridded_samples_8_0.png b/doc/meshkernelpy/examples/images/11_mesh2d_refine_ridges_gridded_samples_8_0.png new file mode 100644 index 0000000..1e9e2d9 Binary files /dev/null and b/doc/meshkernelpy/examples/images/11_mesh2d_refine_ridges_gridded_samples_8_0.png differ diff --git a/doc/meshkernelpy/examples/images/12_mesh2d_refine_gridded_samples_coastlines_10_0.png b/doc/meshkernelpy/examples/images/12_mesh2d_refine_gridded_samples_coastlines_10_0.png new file mode 100644 index 0000000..7b5fbe4 Binary files /dev/null and b/doc/meshkernelpy/examples/images/12_mesh2d_refine_gridded_samples_coastlines_10_0.png differ diff --git a/doc/meshkernelpy/examples/images/13_mesh2d_refine_gridded_samples_strided_arrays_9_0.png b/doc/meshkernelpy/examples/images/13_mesh2d_refine_gridded_samples_strided_arrays_9_0.png new file mode 100644 index 0000000..49967f6 Binary files /dev/null and b/doc/meshkernelpy/examples/images/13_mesh2d_refine_gridded_samples_strided_arrays_9_0.png differ diff --git a/doc/meshkernelpy/examples/images/14_contacts_generation_11_0.png b/doc/meshkernelpy/examples/images/14_contacts_generation_11_0.png new file mode 100644 index 0000000..cc421ff Binary files /dev/null and b/doc/meshkernelpy/examples/images/14_contacts_generation_11_0.png differ diff --git a/doc/meshkernelpy/examples/images/14_contacts_generation_13_0.png b/doc/meshkernelpy/examples/images/14_contacts_generation_13_0.png new file mode 100644 index 0000000..158f1b8 Binary files /dev/null and b/doc/meshkernelpy/examples/images/14_contacts_generation_13_0.png differ diff --git a/doc/meshkernelpy/examples/images/14_contacts_generation_15_0.png b/doc/meshkernelpy/examples/images/14_contacts_generation_15_0.png new file mode 100644 index 0000000..3f1a936 Binary files /dev/null and b/doc/meshkernelpy/examples/images/14_contacts_generation_15_0.png differ diff --git a/doc/meshkernelpy/examples/images/14_contacts_generation_17_0.png b/doc/meshkernelpy/examples/images/14_contacts_generation_17_0.png new file mode 100644 index 0000000..ee22908 Binary files /dev/null and b/doc/meshkernelpy/examples/images/14_contacts_generation_17_0.png differ diff --git a/doc/meshkernelpy/examples/images/14_contacts_generation_7_0.png b/doc/meshkernelpy/examples/images/14_contacts_generation_7_0.png new file mode 100644 index 0000000..45157de Binary files /dev/null and b/doc/meshkernelpy/examples/images/14_contacts_generation_7_0.png differ diff --git a/doc/meshkernelpy/examples/images/15_mesh2d_refinement_casulli_based_on_depths_11_0.png b/doc/meshkernelpy/examples/images/15_mesh2d_refinement_casulli_based_on_depths_11_0.png new file mode 100644 index 0000000..a36155f Binary files /dev/null and b/doc/meshkernelpy/examples/images/15_mesh2d_refinement_casulli_based_on_depths_11_0.png differ diff --git a/doc/meshkernelpy/examples/images/15_mesh2d_refinement_casulli_based_on_depths_18_0.png b/doc/meshkernelpy/examples/images/15_mesh2d_refinement_casulli_based_on_depths_18_0.png new file mode 100644 index 0000000..87e3607 Binary files /dev/null and b/doc/meshkernelpy/examples/images/15_mesh2d_refinement_casulli_based_on_depths_18_0.png differ diff --git a/doc/meshkernelpy/examples/images/15_mesh2d_refinement_casulli_based_on_depths_21_0.png b/doc/meshkernelpy/examples/images/15_mesh2d_refinement_casulli_based_on_depths_21_0.png new file mode 100644 index 0000000..284461b Binary files /dev/null and b/doc/meshkernelpy/examples/images/15_mesh2d_refinement_casulli_based_on_depths_21_0.png differ diff --git a/doc/meshkernelpy/examples/images/15_mesh2d_refinement_casulli_based_on_depths_5_0.png b/doc/meshkernelpy/examples/images/15_mesh2d_refinement_casulli_based_on_depths_5_0.png new file mode 100644 index 0000000..02d4b3d Binary files /dev/null and b/doc/meshkernelpy/examples/images/15_mesh2d_refinement_casulli_based_on_depths_5_0.png differ diff --git a/doc/meshkernelpy/examples/images/15_mesh2d_refinement_casulli_based_on_depths_8_1.png b/doc/meshkernelpy/examples/images/15_mesh2d_refinement_casulli_based_on_depths_8_1.png new file mode 100644 index 0000000..b78974c Binary files /dev/null and b/doc/meshkernelpy/examples/images/15_mesh2d_refinement_casulli_based_on_depths_8_1.png differ diff --git a/doc/meshkernelpy/examples/index.md b/doc/meshkernelpy/examples/index.md new file mode 100644 index 0000000..2144a16 --- /dev/null +++ b/doc/meshkernelpy/examples/index.md @@ -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) diff --git a/doc/meshkernelpy/images/GridRefinement.jpg b/doc/meshkernelpy/images/GridRefinement.jpg new file mode 100644 index 0000000..123085d Binary files /dev/null and b/doc/meshkernelpy/images/GridRefinement.jpg differ diff --git a/doc/meshkernelpy/images/MeshOrthogonalization.jpg b/doc/meshkernelpy/images/MeshOrthogonalization.jpg new file mode 100644 index 0000000..eab05ef Binary files /dev/null and b/doc/meshkernelpy/images/MeshOrthogonalization.jpg differ diff --git a/doc/meshkernelpy/images/TriangularMeshInPolygon.jpg b/doc/meshkernelpy/images/TriangularMeshInPolygon.jpg new file mode 100644 index 0000000..23ed9f6 Binary files /dev/null and b/doc/meshkernelpy/images/TriangularMeshInPolygon.jpg differ diff --git a/doc/meshkernelpy/index.md b/doc/meshkernelpy/index.md new file mode 100644 index 0000000..663fc50 --- /dev/null +++ b/doc/meshkernelpy/index.md @@ -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 +``` + +其中,`` 为生成的 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= -v $(pwd):/root --rm build_linux_library +``` + +其中,`` 为 `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)