Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update generated code for DPF 252_memleak2 on master #2135

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ansys/dpf/core/collection_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ def _set_integral_entries(self, input):
def get_integral_entries(self):
"""Get integral entries."""
try:
vec = dpf_vector.DPFVectorInt(client=self._server.client)
vec = dpf_vector.DPFVectorInt(owner=self)
self._api.collection_get_data_as_int_for_dpf_vector(
self, vec, vec.internal_data, vec.internal_size
)
Expand Down Expand Up @@ -715,7 +715,7 @@ def _set_integral_entries(self, input):
def get_integral_entries(self):
"""Get integral entries."""
try:
vec = dpf_vector.DPFVectorDouble(client=self._server.client)
vec = dpf_vector.DPFVectorDouble(owner=self)
self._api.collection_get_data_as_double_for_dpf_vector(
self, vec, vec.internal_data, vec.internal_size
)
Expand Down
8 changes: 4 additions & 4 deletions src/ansys/dpf/core/custom_type_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@

"""
try:
vec = dpf_vector.DPFVectorCustomType(self._type, client=self._server.client)
vec = dpf_vector.DPFVectorCustomType(self._type, owner=self)

Check warning on line 329 in src/ansys/dpf/core/custom_type_field.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/custom_type_field.py#L329

Added line #L329 was not covered by tests
self._api.cscustom_type_field_get_entity_data_for_dpf_vector(
self, vec, vec.internal_data, vec.internal_size, index
)
Expand Down Expand Up @@ -366,7 +366,7 @@

"""
try:
vec = dpf_vector.DPFVectorCustomType(self._type, client=self._server.client)
vec = dpf_vector.DPFVectorCustomType(self._type, owner=self)

Check warning on line 369 in src/ansys/dpf/core/custom_type_field.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/custom_type_field.py#L369

Added line #L369 was not covered by tests
self._api.cscustom_type_field_get_entity_data_by_id_for_dpf_vector(
self, vec, vec.internal_data, vec.internal_size, id
)
Expand All @@ -390,7 +390,7 @@

def _get_data_pointer(self):
try:
vec = dpf_vector.DPFVectorInt(client=self._server.client)
vec = dpf_vector.DPFVectorInt(owner=self)

Check warning on line 393 in src/ansys/dpf/core/custom_type_field.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/custom_type_field.py#L393

Added line #L393 was not covered by tests
self._api.cscustom_type_field_get_data_pointer_for_dpf_vector(
self, vec, vec.internal_data, vec.internal_size
)
Expand All @@ -404,7 +404,7 @@

def _get_data(self, np_array=True):
try:
vec = dpf_vector.DPFVectorCustomType(self._type, client=self._server.client)
vec = dpf_vector.DPFVectorCustomType(self._type, owner=self)
self._api.cscustom_type_field_get_data_for_dpf_vector(
self, vec, vec.internal_data, vec.internal_size
)
Expand Down
8 changes: 4 additions & 4 deletions src/ansys/dpf/core/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def shell_layers(self, value):
def get_entity_data(self, index: int) -> dpf_array.DPFArray:
"""Retrieve entity data by index."""
try:
vec = dpf_vector.DPFVectorDouble(client=self._server.client)
vec = dpf_vector.DPFVectorDouble(owner=self)
self._api.csfield_get_entity_data_for_dpf_vector(
self, vec, vec.internal_data, vec.internal_size, index
)
Expand All @@ -425,7 +425,7 @@ def get_entity_data(self, index: int) -> dpf_array.DPFArray:
def get_entity_data_by_id(self, id: int) -> dpf_array.DPFArray:
"""Retrieve entity data by id."""
try:
vec = dpf_vector.DPFVectorDouble(client=self._server.client)
vec = dpf_vector.DPFVectorDouble(owner=self)
self._api.csfield_get_entity_data_by_id_for_dpf_vector(
self, vec, vec.internal_data, vec.internal_size, id
)
Expand All @@ -450,7 +450,7 @@ def append(self, data, scopingid):

def _get_data_pointer(self):
try:
vec = dpf_vector.DPFVectorInt(client=self._server.client)
vec = dpf_vector.DPFVectorInt(owner=self)
self._api.csfield_get_data_pointer_for_dpf_vector(
self, vec, vec.internal_data, vec.internal_size
)
Expand All @@ -464,7 +464,7 @@ def _set_data_pointer(self, data):

def _get_data(self, np_array=True):
try:
vec = dpf_vector.DPFVectorDouble(client=self._server.client)
vec = dpf_vector.DPFVectorDouble(owner=self)
self._api.csfield_get_data_for_dpf_vector(
self, vec, vec.internal_data, vec.internal_size
)
Expand Down
8 changes: 4 additions & 4 deletions src/ansys/dpf/core/property_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def _get_scoping(self):
def get_entity_data(self, index):
"""Return the data associated with the entity by index."""
try:
vec = dpf_vector.DPFVectorInt(client=self._server.client)
vec = dpf_vector.DPFVectorInt(owner=self)
self._api.csproperty_field_get_entity_data_for_dpf_vector(
self, vec, vec.internal_data, vec.internal_size, index
)
Expand All @@ -239,7 +239,7 @@ def get_entity_data(self, index):
def get_entity_data_by_id(self, id):
"""Return the data associated with entity by id."""
try:
vec = dpf_vector.DPFVectorInt(client=self._server.client)
vec = dpf_vector.DPFVectorInt(owner=self)
self._api.csproperty_field_get_entity_data_by_id_for_dpf_vector(
self, vec, vec.internal_data, vec.internal_size, id
)
Expand All @@ -264,7 +264,7 @@ def append(self, data, scopingid):

def _get_data_pointer(self):
try:
vec = dpf_vector.DPFVectorInt(client=self._server.client)
vec = dpf_vector.DPFVectorInt(owner=self)
self._api.csproperty_field_get_data_pointer_for_dpf_vector(
self, vec, vec.internal_data, vec.internal_size
)
Expand All @@ -278,7 +278,7 @@ def _set_data_pointer(self, data):

def _get_data(self, np_array=True):
try:
vec = dpf_vector.DPFVectorInt(client=self._server.client)
vec = dpf_vector.DPFVectorInt(owner=self)
self._api.csproperty_field_get_data_for_dpf_vector(
self, vec, vec.internal_data, vec.internal_size
)
Expand Down
8 changes: 1 addition & 7 deletions src/ansys/dpf/core/scoping.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,7 @@ def _get_ids(self, np_array=None):

np_array = settings.get_runtime_client_config(self._server).return_arrays
try:
vec = dpf_vector.DPFVectorInt(
client=self._server.client,
api=self._server.get_api_for_type(
capi=dpf_vector_capi.DpfVectorCAPI,
grpcapi=dpf_vector_abstract_api.DpfVectorAbstractAPI,
),
)
vec = dpf_vector.DPFVectorInt(owner=self)
self._api.scoping_get_ids_for_dpf_vector(
self, vec, vec.internal_data, vec.internal_size
)
Expand Down
6 changes: 3 additions & 3 deletions src/ansys/dpf/core/string_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def _get_scoping(self):
def get_entity_data(self, index):
"""Return entity data."""
try:
vec = dpf_vector.DPFVectorString(client=self._server.client)
vec = dpf_vector.DPFVectorString(owner=self)
self._api.csstring_field_get_entity_data_for_dpf_vector(
self, vec, vec.internal_data, vec.internal_size, index
)
Expand All @@ -213,7 +213,7 @@ def get_entity_data(self, index):
def get_entity_data_by_id(self, id):
"""Return entity data corresponding to the provided id."""
try:
vec = dpf_vector.DPFVectorString(client=self._server.client)
vec = dpf_vector.DPFVectorString(owner=self)
self._api.csstring_field_get_entity_data_by_id_for_dpf_vector(
self, vec, vec.internal_data, vec.internal_size, id
)
Expand All @@ -236,7 +236,7 @@ def append(self, data: List[str], scopingid: int):

def _get_data(self, np_array=True):
try:
vec = dpf_vector.DPFVectorString(client=self._server.client)
vec = dpf_vector.DPFVectorString(owner=self)
self._api.csstring_field_get_data_for_dpf_vector(
self, vec, vec.internal_data, vec.internal_size
)
Expand Down
60 changes: 32 additions & 28 deletions src/ansys/dpf/gate/dpf_vector.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import copy
import ctypes
import numpy as np

from ansys.dpf.core.check_version import server_meet_version
from ansys.dpf.gate.generated import dpf_vector_capi
from ansys.dpf.gate.integral_types import MutableListInt32, MutableInt32, MutableListDouble, \
MutableListString, MutableListChar
Expand All @@ -23,23 +25,22 @@ class DPFVectorBase:

Parameters
----------
client: object having _internal_obj attribute and a shared CLayer Client instance, optional
owner: object having _internal_obj attribute and a shared CLayer Client instance, optional
Enables DPFClientAPI to choose the right API to use.

api: DpfVectorAbstractAPI, optional
"""

def __init__(self, client, api):
def __init__(self, owner, api):
self.dpf_vector_api = api
self._modified = False
self._check_changes = True
try:
if not client:
self._internal_obj = self.dpf_vector_api.dpf_vector_new()
self._internal_obj = self.dpf_vector_api.dpf_vector_new_for_object(owner)
if not server_meet_version("4.1",
owner._server) and owner._server.client is None: # BUG in 22.2: DpfVector is not holding the data owner and not call to data owner should be done at delete
self._check_changes = False
else:
self._internal_obj = self.dpf_vector_api.dpf_vector_new_for_object(client)
except AttributeError:
except ctypes.ArgumentError:
raise NotImplementedError

@property
Expand Down Expand Up @@ -81,7 +82,6 @@ def has_changed(self):
self._modified = True
return self._modified


@property
def np_array(self) -> np.ndarray:
"""
Expand All @@ -94,7 +94,7 @@ def np_array(self) -> np.ndarray:
--------
Memory of the DPFVector is not managed in this object. Use a ```DPFArray``` instead.
"""
if not self._array.pointer or self.size==0:
if not self._array.pointer or self.size == 0:
return np.empty((0,), dtype=self._array.np_type)
return np.ctypeslib.as_array(self._array.pointer, shape=(self.size,))

Expand Down Expand Up @@ -140,8 +140,8 @@ def __del__(self):


class DPFVectorInt(DPFVectorBase):
def __init__(self, client=None, api=dpf_vector_capi.DpfVectorCAPI):
super().__init__(client, api)
def __init__(self, owner=None, api=dpf_vector_capi.DpfVectorCAPI):
super().__init__(owner, api)
self._array = MutableListInt32()

@property
Expand All @@ -164,15 +164,16 @@ def commit(self) -> None:
def __del__(self):
try:
if self._array:
self.dpf_vector_api.dpf_vector_int_free(self, self.internal_data, self.internal_size, self.has_changed())
self.dpf_vector_api.dpf_vector_int_free(self, self.internal_data, self.internal_size,
self.has_changed())
except:
pass
super().__del__()


class DPFVectorDouble(DPFVectorBase):
def __init__(self, client=None, api=dpf_vector_capi.DpfVectorCAPI):
super().__init__(client, api)
def __init__(self, owner=None, api=dpf_vector_capi.DpfVectorCAPI):
super().__init__(owner, api)
self._array = MutableListDouble()

@property
Expand All @@ -195,16 +196,17 @@ def commit(self) -> None:
def __del__(self):
try:
if self._array:
self.dpf_vector_api.dpf_vector_double_free(self, self.internal_data, self.internal_size, self.has_changed())
self.dpf_vector_api.dpf_vector_double_free(self, self.internal_data, self.internal_size,
self.has_changed())
except:
pass
super().__del__()


class DPFVectorCustomType(DPFVectorBase):
def __init__(self, unitary_type, client=None, api=dpf_vector_capi.DpfVectorCAPI):
def __init__(self, unitary_type, owner=None, api=dpf_vector_capi.DpfVectorCAPI):
self.type = unitary_type
super().__init__(client, api)
super().__init__(owner, api)
self._array = MutableListChar()

@property
Expand All @@ -222,7 +224,8 @@ def commit(self) -> None:
if self._check_changes is set to True, compares the initial data computed in
```start_checking_modification``` (which should have been called beforehand) to the current one.
"""
self.dpf_vector_api.dpf_vector_char_commit(self, self.internal_data, self.size*self.type.itemsize, self.has_changed())
self.dpf_vector_api.dpf_vector_char_commit(self, self.internal_data, self.size * self.type.itemsize,
self.has_changed())

@property
def size(self) -> int:
Expand All @@ -241,7 +244,7 @@ def np_array(self) -> np.ndarray:
--------
Memory of the DPFVector is not managed in this object. Use a ```DPFArray``` instead.
"""
if not self._array.pointer or self.size==0:
if not self._array.pointer or self.size == 0:
return np.empty((0,), dtype=self._array.np_type)
return np.ctypeslib.as_array(
ctypes.cast(self._array.pointer, ctypes.POINTER(np.ctypeslib.as_ctypes_type(self.type))),
Expand All @@ -251,15 +254,16 @@ def np_array(self) -> np.ndarray:
def __del__(self):
try:
if self._array:
self.dpf_vector_api.dpf_vector_char_free(self, self.internal_data, self.size*self.type.itemsize, self.has_changed())
self.dpf_vector_api.dpf_vector_char_free(self, self.internal_data, self.size * self.type.itemsize,
self.has_changed())
except:
pass
super().__del__()


class DPFVectorString(DPFVectorBase):
def __init__(self, client=None, api=dpf_vector_capi.DpfVectorCAPI):
super().__init__(client, api)
def __init__(self, owner=None, api=dpf_vector_capi.DpfVectorCAPI):
super().__init__(owner, api)
self._array = MutableListString()

@property
Expand All @@ -275,7 +279,8 @@ def internal_data(self) -> MutableListString:
def __del__(self):
try:
if self._array:
self.dpf_vector_api.dpf_vector_char_ptr_free(self, self.internal_data, self.internal_size, self.has_changed())
self.dpf_vector_api.dpf_vector_char_ptr_free(self, self.internal_data, self.internal_size,
self.has_changed())
except:
pass
super().__del__()
Expand All @@ -293,7 +298,7 @@ def __iter__(self):
def __next__(self):
if self.n < len(self):
self.n += 1
return self.__getitem__(self.n-1)
return self.__getitem__(self.n - 1)
else:
raise StopIteration

Expand All @@ -310,12 +315,11 @@ def __ne__(self, other):

def __str__(self):
out = f"DPFVectorString["
for i in range(min(5, len(self)-1)):
for i in range(min(5, len(self) - 1)):
out += f"'{self[i]}', "
if len(self)>2:
if len(self) > 2:
out += "..., "
if len(self) >= 2:
out += f"'{self[len(self)-1]}'"
out += f"'{self[len(self) - 1]}'"
out += "]"
return out

Binary file modified src/ansys/dpf/gatebin/Ans.Dpf.GrpcClient.dll
Binary file not shown.
Binary file modified src/ansys/dpf/gatebin/DPFClientAPI.dll
Binary file not shown.
Binary file modified src/ansys/dpf/gatebin/libAns.Dpf.GrpcClient.so
Binary file not shown.
Binary file modified src/ansys/dpf/gatebin/libDPFClientAPI.so
Binary file not shown.
Loading