ansys / pydpf-core

Data Processing Framework - Python Core
http://dpf.docs.pyansys.com/
MIT License
67 stars 24 forks source link

Field.append() with np.array view does not hold data #1489

Open PProfizi opened 5 months ago

PProfizi commented 5 months ago

Before submitting the issue

Description of the bug

Appending data to a Field using an array slice does not hold onto the data for GrpcCLayer and InProcess. This results in the Field reporting unassigned values. Using sliced_data.copy() does not solve the issue despite it reporting sliced_data.flags["OWNDATA"]==True and sliced_data.base!=None. Basically the field does not hold the data when added this way. The question is whether there is something we can actually do about it, as it seems there is no way to know where the data comes from.

Steps To Reproduce

result_field = dpf.field.Field(location=dpf.locations.elemental_nodal, nature=dpf.natures.scalar)
assert result_field.component_count == 1

input_data = np.array([[1,2],[3,4]])
sliced_data = input_data[:,0]

result_field.append(sliced_data, 1)
assert result_field.elementary_data_count == 2
print(result_field)
assert np.allclose(result_field.get_entity_data_by_id(1), sliced_data)

prints:

Location: ElementalNodal
  Unit: 
  1 entities 
  Data: 1 components and 2 elementary data

  IDs                   data
  ------------          ----------
  1                     4.243992e-314  
                        8.487983e-314 

Which Operating System causes the issue?

Windows

Which DPF/Ansys version are you using?

DPF Server 2024.2.pre0

Which Python version causes the issue?

3.11

Installed packages

NA

PProfizi commented 5 months ago

@janvonrickenbach FYI