Skip to content

Commit

Permalink
Convert slices to list before appending to dpf field (#443)
Browse files Browse the repository at this point in the history
* Convert slice to list with numpy.tolist
  • Loading branch information
janvonrickenbach authored Apr 4, 2024
1 parent 4b66159 commit d74db57
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion examples/006_filter_composite_data_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@
)

value = stress_data[selected_indices][:, component]
local_result_field.append(value, element_id)
# value needs to be passed as list because dpf does not support numpy
# slices in the append call.
local_result_field.append(value.tolist(), element_id)

composite_model.get_mesh().plot(result_field)

Expand Down
4 changes: 2 additions & 2 deletions tests/filter_layered_data_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def get_result_field(
# Conversion to a list is a temporary workaround
# because the append method does currently not work
# reliably for slices of numpy arrays
local_result_field.append(list(values), element_id)
local_result_field.append(values.tolist(), element_id)
else:
local_result_field.append(strain_data[selected_indices, component], element_id)
return result_field
Expand Down Expand Up @@ -166,7 +166,7 @@ def test_filter_by_global_ply(dpf_server):
component = 0
value = strain_data[selected_indices][:, component]

local_result_field.append(value, element_id)
local_result_field.append(value.tolist(), element_id)

# Ply is only present in element 1 and 2
assert list(result_field.scoping.ids) == [1, 2]
Expand Down

0 comments on commit d74db57

Please sign in to comment.