Skip to content

Commit 4447aec

Browse files
[Python] Add unstructured grid example and fix array casting
Introduced an unstructured grid example in example.py and updated several method calls to use the .cast() method for array arguments to ensure correct type handling. Also made minor updates in fesapi.ipynb for array casting and kernel metadata. See #367
1 parent d7e1603 commit 4447aec

4 files changed

Lines changed: 52 additions & 15 deletions

File tree

.github/workflows/github-actions.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,10 @@ jobs:
7171
fail-fast: false # 'false' means Don't stop matrix workflows even if some matrix failed.
7272
matrix:
7373
include: [
74-
{ xcc_name: 'gcc 9', xcc_pkg: gcc-9, cc: gcc-9, cxx: g++-9 },
7574
{ xcc_name: 'gcc 10', xcc_pkg: gcc-10, cc: gcc-10, cxx: g++-10 },
76-
{ xcc_name: 'clang 11', xcc_pkg: clang-11, cc: clang-11, cxx: clang++-11 },
77-
{ xcc_name: 'clang 12', xcc_pkg: clang-12, cc: clang-12, cxx: clang++-12 },
75+
{ xcc_name: 'gcc 12', xcc_pkg: gcc-12, cc: gcc-12, cxx: g++-12 },
7876
{ xcc_name: 'clang 13', xcc_pkg: clang-13, cc: clang-13, cxx: clang++-13 },
77+
{ xcc_name: 'clang 15', xcc_pkg: clang-15, cc: clang-15, cxx: clang++-15 },
7978
]
8079
env:
8180
XCC: ${{ matrix.xcc_name }}

example/example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ void serializeGrid(COMMON_NS::DataObjectRepository * repo, EML2_NS::AbstractHdfP
12291229
// The cumulative count of points per face i.e. first face contains 3 points, second face contains 6-3=3 points, third face contains 9-6=3 points etc...
12301230
uint64_t nodeIndicesCumulativeCountPerFace[8] = { 3, // shared face
12311231
6, 9, 12, // faces for tetra
1232-
16, 20, 24, 27 // faces for wedge
1232+
16, 20, 24, 27 // faces for wedge
12331233
};
12341234
// The face indices of each cell.
12351235
uint64_t faceIndicesPerCell[9] = { 0, 1, 2, 3, // tetra

python/example/example.py

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def serialize_grid(repo: fesapi.DataObjectRepository):
2020
resqml_points.setitem(i, value)
2121
single_cell_ijk_grid.setGeometryAsCoordinateLineNodes(
2222
fesapi.resqml20__PillarShape_vertical, fesapi.resqml20__KDirection_down, False,
23-
resqml_points)
23+
resqml_points.cast())
2424

2525
# ONE CONTINUOUS PROPERTY ON A PARTIAL 3 cells I=1 J=1 K=3 GRID
2626
partial_ijk_grid = repo.createPartialIjkGridRepresentation("bc92a216-aa17-4a1f-9253-8b3ab094bf84", "partial grid")
@@ -33,7 +33,48 @@ def serialize_grid(repo: fesapi.DataObjectRepository):
3333
stats = fesapi.FloatArrayStatistics()
3434
stats.setMaximum(3.3)
3535
stats.setMinimum(1.1)
36-
continuous_prop.pushBackFloatArray3dOfValuesPlusStatistics(resqml_values, 1, 1, 3, stats)
36+
continuous_prop.pushBackFloatArray3dOfValuesPlusStatistics(resqml_values.cast(), 1, 1, 3, stats)
37+
38+
# unstructured grid example
39+
unstructured_grid = repo.createUnstructuredGridRepresentation(
40+
"9283cd33-5e52-4110-b7b1-616abde2b303",
41+
"One tetrahedron + prism grid",
42+
2
43+
)
44+
python_points = [0, 0, 300, 375, 0, 300, 0, 150, 300, # points for shared face between tetra and wedge
45+
0, 0, 500, # point for tetra
46+
0, 0, 0, 375, 0, 0, 0, 150, 0]
47+
resqml_points = fesapi.DoubleArray(21)
48+
for i, value in enumerate(python_points):
49+
resqml_points.setitem(i, value)
50+
python_node_indices_per_face = [0, 1, 2, # shared face
51+
1, 2, 3, 0, 1, 3, 0, 2, 3, # faces for tetra
52+
0, 2, 6, 4, 2, 1, 5, 6, 0, 1, 5, 4, 4, 5, 6] # faces for wedge
53+
resqml_node_indices_per_face = fesapi.UInt64Array(27)
54+
for i, value in enumerate(python_node_indices_per_face):
55+
resqml_node_indices_per_face.setitem(i, value)
56+
python_node_indices_cumulative_count_per_face = [3, # shared face
57+
6, 9, 12, # faces for tetra
58+
16, 20, 24, 27] # faces for wedge
59+
resqml_node_indices_cumulative_count_per_face = fesapi.UInt64Array(8)
60+
for i, value in enumerate(python_node_indices_cumulative_count_per_face):
61+
resqml_node_indices_cumulative_count_per_face.setitem(i, value)
62+
python_face_indices_per_cell = [0, 1, 2, 3, # tetra
63+
0, 4, 5, 6, 7] # wedge
64+
resqml_face_indices_per_cell = fesapi.UInt64Array(9)
65+
for i, value in enumerate(python_face_indices_per_cell):
66+
resqml_face_indices_per_cell.setitem(i, value)
67+
python_face_indices_cumulative_count_per_cell = [ 4, 9 ];
68+
resqml_face_indices_cumulative_count_per_cell = fesapi.UInt64Array(2)
69+
for i, value in enumerate(python_face_indices_cumulative_count_per_cell):
70+
resqml_face_indices_cumulative_count_per_cell.setitem(i, value)
71+
python_face_right_handness = [ 1, 0, 0, 1, 0, 0, 0, 1, 1 ];
72+
resqml_face_right_handness = fesapi.UInt8Array(9)
73+
for i, value in enumerate(python_face_right_handness):
74+
resqml_face_right_handness.setitem(i, value)
75+
unstructured_grid.setGeometry(resqml_face_right_handness.cast(), resqml_points.cast(), 7, None, resqml_face_indices_per_cell.cast(), resqml_face_indices_cumulative_count_per_cell.cast(), 8,
76+
resqml_node_indices_per_face.cast(), resqml_node_indices_cumulative_count_per_face.cast(), fesapi.resqml20__CellShape_prism);
77+
3778

3879
def serialize(file_name: str):
3980
"""
@@ -122,15 +163,15 @@ def show_ijk_grid(ijk_grid: fesapi.Resqml2_AbstractIjkGridRepresentation):
122163
for patch_index in range(patch_count):
123164
nb_xyz_points_in_patch = ijk_grid.getXyzPointCountOfPatch(patch_index)
124165
xyz_points_in_patch = fesapi.DoubleArray(nb_xyz_points_in_patch * 3)
125-
ijk_grid.getXyzPointsOfPatch(patch_index, xyz_points_in_patch)
166+
ijk_grid.getXyzPointsOfPatch(patch_index, xyz_points_in_patch.cast())
126167
for vertex_index in range(nb_xyz_points_in_patch):
127168
x = xyz_points_in_patch.getitem(vertex_index * 3)
128169
y = xyz_points_in_patch.getitem(vertex_index * 3 + 1)
129170
z = xyz_points_in_patch.getitem(vertex_index * 3 + 2)
130171
print("Vertex ", vertex_index, " : ", x, " ", y, " ", z)
131172

132173
xyz_points = fesapi.DoubleArray(nb_xyz_points * 3)
133-
ijk_grid.getXyzPointsOfAllPatches(xyz_points)
174+
ijk_grid.getXyzPointsOfAllPatches(xyz_points.cast())
134175

135176
ijk_grid.loadSplitInformation()
136177
for cell_corner in range(8):

python/example/fesapi.ipynb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
"resqml_points = fesapi.DoubleArray(24)\n",
117117
"for i in range(6):\n",
118118
" resqml_points.setitem(i, i*100)\n",
119-
"horizon_grid_2d_representation.setGeometryAsArray2dOfExplicitZ(resqml_points, 2, 3, hdf_proxy,\n",
119+
"horizon_grid_2d_representation.setGeometryAsArray2dOfExplicitZ(resqml_points.cast(), 2, 3, hdf_proxy,\n",
120120
" 0.0, 0.0, 0.0,\n",
121121
" 1.0, 0.0, 0.0, 25.0,\n",
122122
" 0.0, 1.0, 0.0, 50.0)"
@@ -132,15 +132,12 @@
132132
},
133133
{
134134
"cell_type": "code",
135-
"execution_count": 6,
136135
"id": "b5d289e6-c699-4d88-a870-3dae2baf14ee",
137136
"metadata": {},
138-
"outputs": [],
139137
"source": [
140138
"# Create an EPC Document in the current folder nad named TestingFesapiWithPython.epc\n",
141139
"epc_file = fesapi.EpcDocument(file_name_without_extension + \".epc\")\n",
142-
"epc_file.serializeFrom(repo)\n",
143-
"epc_file.close()"
140+
"epc_file.serializeFrom(repo)"
144141
]
145142
},
146143
{
@@ -164,7 +161,7 @@
164161
],
165162
"metadata": {
166163
"kernelspec": {
167-
"display_name": "Python 3 (ipykernel)",
164+
"display_name": ".venv (3.11.9)",
168165
"language": "python",
169166
"name": "python3"
170167
},
@@ -178,7 +175,7 @@
178175
"name": "python",
179176
"nbconvert_exporter": "python",
180177
"pygments_lexer": "ipython3",
181-
"version": "3.11.5"
178+
"version": "3.11.9"
182179
}
183180
},
184181
"nbformat": 4,

0 commit comments

Comments
 (0)