Skip to content

Commit

Permalink
Move weakref finalize to core.
Browse files Browse the repository at this point in the history
  • Loading branch information
NikoOinonen committed Dec 13, 2024
1 parent 87f5e32 commit 4e88e33
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 0 additions & 5 deletions ppafm/HighLevel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/python

import sys
import weakref

import numpy as np

Expand Down Expand Up @@ -211,11 +210,9 @@ def prepareArrays(FF, Vpot, parameters):
gridN = np.shape(FF)
parameters.gridN = gridN
core.setFF_Fpointer(FF)
weakref.finalize(FF, core.deleteFF_Fpointer) # Set array pointer to NULL when garbage collector runs.
if Vpot:
V = np.zeros((gridN[2], gridN[1], gridN[0]))
core.setFF_Epointer(V)
weakref.finalize(V, core.deleteFF_Epointer)
else:
V = None
return FF, V
Expand Down Expand Up @@ -462,5 +459,3 @@ def subtractCoreDensities(
print("sum(RHO), Nelec: ", rho.sum(), rho.sum() * dV) # check sum
if bSaveDebugDens:
io.saveXSF("rho_subCoreChg.xsf", rho, lvec, head=head)

core.deleteFF_Epointer()
3 changes: 3 additions & 0 deletions ppafm/core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/python

import weakref
from ctypes import POINTER, Structure, c_double, c_int

import numpy as np
Expand Down Expand Up @@ -76,6 +77,7 @@ def setFF_shape(n_, cell, parameters=None):

def setFF_Fpointer(gridF):
lib.setFF_Fpointer(gridF)
weakref.finalize(gridF, deleteFF_Fpointer) # Set array pointer to NULL when garbage collector runs.


# void setFF_pointer( double * gridF, double * gridE )
Expand All @@ -85,6 +87,7 @@ def setFF_Fpointer(gridF):

def setFF_Epointer(gridE):
lib.setFF_Epointer(gridE)
weakref.finalize(gridE, deleteFF_Epointer) # Set array pointer to NULL when garbage collector runs.


# void deleteFF_Fpointer()
Expand Down

0 comments on commit 4e88e33

Please sign in to comment.