Skip to content

Commit 0bc8199

Browse files
authored
Merge pull request #240 from precice/python-bindings-v3.2.1
Release v3.2.1
2 parents c28df2b + 8665ba9 commit 0bc8199

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## 3.2.1
6+
7+
* Modify docstrings to highlight flexibility of the API in terms of its ability to handle multidimensional input data structures https://github.com/precice/python-bindings/pull/239
8+
* Fix bug in `map_and_read_data` https://github.com/precice/python-bindings/pull/237
9+
510
## 3.2.0
611

712
* Update `requirements.txt` of the solver dummy https://github.com/precice/python-bindings/pull/233

cyprecice/cyprecice.pyx

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ cdef class Participant:
401401
positions : array_like
402402
The coordinates of the vertices in a numpy array [N x D] where
403403
N = number of vertices and D = dimensions of geometry.
404+
A list of the same shape is also accepted.
404405
405406
Returns
406407
-------
@@ -435,6 +436,16 @@ cdef class Participant:
435436
>>> vertex_ids = participant.set_mesh_vertices(mesh_name, positions)
436437
>>> vertex_ids.shape
437438
(5,)
439+
440+
Set mesh vertices for a 3D problem with 5 mesh vertices, where the positions are a list of tuples.
441+
442+
>>> positions = [(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5)]
443+
>>> positions.shape
444+
(5, 3)
445+
>>> mesh_name = "MeshOne"
446+
>>> vertex_ids = participant.set_mesh_vertices(mesh_name, positions)
447+
>>> vertex_ids.shape
448+
(5,)
438449
"""
439450
check_array_like(positions, "positions", "set_mesh_vertices")
440451

@@ -496,6 +507,7 @@ cdef class Participant:
496507
vertices : array_like
497508
The IDs of the vertices in a numpy array [N x 2] where
498509
N = number of edges and D = dimensions of geometry.
510+
A list of the same shape is also accepted.
499511
500512
Examples
501513
--------
@@ -557,6 +569,7 @@ cdef class Participant:
557569
vertices : array_like
558570
The IDs of the vertices in a numpy array [N x 3] where
559571
N = number of triangles and D = dimensions of geometry.
572+
A list of the same shape is also accepted.
560573
561574
Examples
562575
--------
@@ -621,6 +634,7 @@ cdef class Participant:
621634
vertices : array_like
622635
The IDs of the vertices in a numpy array [N x 4] where
623636
N = number of quads and D = dimensions of geometry.
637+
A list of the same shape is also accepted.
624638
625639
Examples
626640
--------
@@ -685,6 +699,7 @@ cdef class Participant:
685699
vertices : array_like
686700
The IDs of the vertices in a numpy array [N x 4] where
687701
N = number of quads and D = dimensions of geometry.
702+
A list of the same shape is also accepted.
688703
689704
Examples
690705
--------
@@ -794,6 +809,13 @@ cdef class Participant:
794809
>>> vertex_ids = [1, 2, 3, 4, 5]
795810
>>> values = np.array([[v1_x, v1_y, v1_z], [v2_x, v2_y, v2_z], [v3_x, v3_y, v3_z], [v4_x, v4_y, v4_z], [v5_x, v5_y, v5_z]])
796811
>>> participant.write_data(mesh_name, data_name, vertex_ids, values)
812+
813+
Write vector data for a 3D (D=3) problem with 5 (N=5) vertices, where the values are provided as a list of tuples:
814+
>>> mesh_name = "MeshOne"
815+
>>> data_name = "DataOne"
816+
>>> vertex_ids = [1, 2, 3, 4, 5]
817+
>>> values = [(v1_x, v1_y, v1_z), (v2_x, v2_y, v2_z), (v3_x, v3_y, v3_z), (v4_x, v4_y, v4_z), (v5_x, v5_y, v5_z)]
818+
>>> participant.write_data(mesh_name, data_name, vertex_ids, values)
797819
"""
798820
check_array_like(vertex_ids, "vertex_ids", "write_data")
799821
check_array_like(values, "values", "write_data")
@@ -934,8 +956,14 @@ cdef class Participant:
934956
>>> coordinates = np.array([[c1_x, c1_y], [c2_x, c2_y], [c3_x, c3_y], [c4_x, c4_y], [c5_x, c5_y]])
935957
>>> values = np.array([v1, v2, v3, v4, v5])
936958
>>> participant.write_and_map_data(mesh_name, data_name, coordinates, values)
937-
"""
938959
960+
Write scalar data for a 2D problem with 5 vertices, where the coordinates are provided as a list of tuples, and the values are provided as a list of scalars:
961+
>>> mesh_name = "MeshOne"
962+
>>> data_name = "DataOne"
963+
>>> coordinates = [(c1_x, c1_y), (c2_x, c2_y), (c3_x, c3_y), (c4_x, c4_y), (c5_x, c5_y)]
964+
>>> values = [v1, v2, v3, v4, v5]
965+
>>> participant.write_and_map_data(mesh_name, data_name, coordinates, values)
966+
"""
939967
check_array_like(coordinates, "coordinates", "write_and_map_data")
940968
check_array_like(values, "values", "write_and_map_data")
941969

@@ -982,13 +1010,21 @@ cdef class Participant:
9821010
Read scalar data for a 2D problem with 2 vertices:
9831011
>>> mesh_name = "MeshOne"
9841012
>>> data_name = "DataOne"
1013+
>>> coordinates = np.array([[1.0, 1.0], [2.0, 2.0]])
1014+
>>> dt = 1.0
1015+
>>> values = map_and_read_data(mesh_name, data_name, coordinates, dt)
1016+
>>> values.shape
1017+
>>> (2, )
1018+
1019+
Read scalar data for a 2D problem with 2 vertices, where the coordinates are provided as a list of tuples:
1020+
>>> mesh_name = "MeshOne"
1021+
>>> data_name = "DataOne"
9851022
>>> coordinates = [(1.0, 1.0), (2.0, 2.0)]
9861023
>>> dt = 1.0
9871024
>>> values = map_and_read_data(mesh_name, data_name, coordinates, dt)
9881025
>>> values.shape
9891026
>>> (2, )
9901027
"""
991-
9921028
check_array_like(coordinates, "coordinates", "map_and_read_data")
9931029

9941030
if not isinstance(coordinates, np.ndarray):
@@ -997,7 +1033,7 @@ cdef class Participant:
9971033
size = coordinates.shape[0]
9981034
dimensions = self.get_data_dimensions(mesh_name, data_name)
9991035

1000-
cdef vector[double] cpp_coordinates = coordinates
1036+
cdef vector[double] cpp_coordinates = coordinates.flatten()
10011037
cdef vector[double] cpp_values = [-1 for _ in range(size * dimensions)]
10021038

10031039
self.thisptr.mapAndReadData (convert(mesh_name), convert(data_name), cpp_coordinates, relative_read_time, cpp_values)
@@ -1045,6 +1081,13 @@ cdef class Participant:
10451081
>>> gradients = np.array([[v1x_dx, v1y_dx, v1x_dy, v1y_dy], [v2x_dx, v2y_dx, v2x_dy, v2y_dy]])
10461082
>>> participant.write_gradient_data(mesh_name, data_name, vertex_ids, gradients)
10471083
1084+
Write gradient vector data for a 2D problem with 2 vertices, where the gradients are provided as a list of tuples:
1085+
>>> mesh_name = "MeshOne"
1086+
>>> data_name = "DataOne"
1087+
>>> vertex_ids = [1, 2]
1088+
>>> gradients = [(v1x_dx, v1y_dx, v1x_dy, v1y_dy), (v2x_dx, v2y_dx, v2x_dy, v2y_dy)]
1089+
>>> participant.write_gradient_data(mesh_name, data_name, vertex_ids, gradients)
1090+
10481091
Write vector data for a 3D problem with 2 vertices:
10491092
>>> mesh_name = "MeshOne"
10501093
>>> data_name = "DataOne"
@@ -1072,7 +1115,6 @@ cdef class Participant:
10721115

10731116
self.thisptr.writeGradientData (convert(mesh_name), convert(data_name), cpp_vertex_ids, cpp_gradients)
10741117

1075-
10761118
def requires_gradient_data_for(self, mesh_name, data_name):
10771119
"""
10781120
Checks if the given data set requires gradient data. We check if the data object has been intialized with the gradient flag.
@@ -1096,11 +1138,9 @@ cdef class Participant:
10961138
>>> data_name = "DataOne"
10971139
>>> participant.is_gradient_data_required(mesh_name, data_name)
10981140
"""
1099-
11001141
return self.thisptr.requiresGradientDataFor(convert(mesh_name), convert(data_name))
11011142

1102-
1103-
def set_mesh_access_region (self, mesh_name, bounding_box):
1143+
def set_mesh_access_region(self, mesh_name, bounding_box):
11041144
"""
11051145
This function is required if you don't want to use the mapping schemes in preCICE, but rather
11061146
want to use your own solver for data mapping. As opposed to the usual preCICE mapping, only a
@@ -1156,8 +1196,7 @@ cdef class Participant:
11561196

11571197
self.thisptr.setMeshAccessRegion(convert(mesh_name), cpp_bounding_box)
11581198

1159-
1160-
def get_mesh_vertex_ids_and_coordinates (self, mesh_name):
1199+
def get_mesh_vertex_ids_and_coordinates(self, mesh_name):
11611200
"""
11621201
Iterating over the region of interest defined by bounding boxes and reading the corresponding
11631202
coordinates omitting the mapping. This function is still experimental.

0 commit comments

Comments
 (0)