URI: 
       fix(python): NumPy 2.0 compatibility in sphere module - sphere - GPU-based 3D discrete element method algorithm with optional fluid coupling
  HTML git clone git://src.adamsgaard.dk/sphere
   DIR Log
   DIR Files
   DIR Refs
   DIR LICENSE
       ---
   DIR commit 0ab896ddc297bde8ea2d314bcae35e2dec81a85b
   DIR parent 07cbc0187d7275aa422010407afa0f346d005309
  HTML Author: Anders Damsgaard <anders@adamsgaard.dk>
       Date:   Sat,  4 Jul 2026 23:46:51 +0200
       
       fix(python): NumPy 2.0 compatibility in sphere module
       
       Diffstat:
         M python/sphere.py                    |      67 ++++++++++++++++---------------
       
       1 file changed, 34 insertions(+), 33 deletions(-)
       ---
   DIR diff --git a/python/sphere.py b/python/sphere.py
       @@ -281,10 +281,10 @@ class sim:
                self.nb0 = 0
        
                # Bond tensile strength [Pa]
       -        self.sigma_b = numpy.ones(1, dtype=numpy.float64) * numpy.infty
       +        self.sigma_b = numpy.ones(1, dtype=numpy.float64) * numpy.inf
        
                # Bond shear strength [Pa]
       -        self.tau_b = numpy.ones(1, dtype=numpy.float64) * numpy.infty
       +        self.tau_b = numpy.ones(1, dtype=numpy.float64) * numpy.inf
        
                # Bond pairs
                self.bonds = numpy.zeros((self.nb0, 2), dtype=numpy.uint32)
       @@ -629,19 +629,19 @@ class sim:
                elif self.tau_b != other.tau_b:
                    print('tau_b')
                    return False
       -        elif self.bonds != other.bonds:
       +        elif (self.bonds != other.bonds).any():
                    print('bonds')
                    return False
       -        elif self.bonds_delta_n != other.bonds_delta_n:
       +        elif (self.bonds_delta_n != other.bonds_delta_n).any():
                    print('bonds_delta_n')
                    return False
       -        elif self.bonds_delta_t != other.bonds_delta_t:
       +        elif (self.bonds_delta_t != other.bonds_delta_t).any():
                    print('bonds_delta_t')
                    return False
       -        elif self.bonds_omega_n != other.bonds_omega_n:
       +        elif (self.bonds_omega_n != other.bonds_omega_n).any():
                    print('bonds_omega_n')
                    return False
       -        elif self.bonds_omega_t != other.bonds_omega_t:
       +        elif (self.bonds_omega_t != other.bonds_omega_t).any():
                    print('bonds_omega_t')
                    return False
                elif self.fluid != other.fluid:
       @@ -978,8 +978,8 @@ class sim:
                    self.version = numpy.fromfile(fh, dtype=numpy.float64, count=1)
        
                    # Read the number of dimensions and particles
       -            self.nd = int(numpy.fromfile(fh, dtype=numpy.int32, count=1))
       -            self.np = int(numpy.fromfile(fh, dtype=numpy.uint32, count=1))
       +            self.nd = int(numpy.fromfile(fh, dtype=numpy.int32, count=1)[0])
       +            self.np = int(numpy.fromfile(fh, dtype=numpy.uint32, count=1)[0])
        
                    # Read the time variables
                    self.time_dt = numpy.fromfile(fh, dtype=numpy.float64, count=1)
       @@ -1016,7 +1016,7 @@ class sim:
                        self.x[i, :] =\
                                numpy.fromfile(fh, dtype=numpy.float64, count=self.nd)
                        self.radius[i] =\
       -                        numpy.fromfile(fh, dtype=numpy.float64, count=1)
       +                        numpy.fromfile(fh, dtype=numpy.float64, count=1)[0]
        
                    if self.version >= 1.03:
                        self.xyzsum = numpy.fromfile(fh, dtype=numpy.float64,\
       @@ -1027,7 +1027,7 @@ class sim:
        
                    for i in numpy.arange(self.np):
                        self.vel[i, :] = numpy.fromfile(fh, dtype=numpy.float64, count=self.nd)
       -                self.fixvel[i] = numpy.fromfile(fh, dtype=numpy.float64, count=1)
       +                self.fixvel[i] = numpy.fromfile(fh, dtype=numpy.float64, count=1)[0]
        
                    self.force = numpy.fromfile(fh, dtype=numpy.float64,\
                                             count=self.np*self.nd)\
       @@ -1079,7 +1079,7 @@ class sim:
                    self.V_b = numpy.fromfile(fh, dtype=numpy.float64, count=1)
        
                    # Wall data
       -            self.nw = int(numpy.fromfile(fh, dtype=numpy.uint32, count=1))
       +            self.nw = int(numpy.fromfile(fh, dtype=numpy.uint32, count=1)[0])
                    self.wmode = numpy.empty(self.nw, dtype=numpy.int32)
                    self.w_n = numpy.empty(self.nw*self.nd, dtype=numpy.float64)\
                               .reshape(self.nw, self.nd)
       @@ -1093,12 +1093,12 @@ class sim:
                    for i in numpy.arange(self.nw):
                        self.w_n[i, :] =\
                                numpy.fromfile(fh, dtype=numpy.float64, count=self.nd)
       -                self.w_x[i] = numpy.fromfile(fh, dtype=numpy.float64, count=1)
       +                self.w_x[i] = numpy.fromfile(fh, dtype=numpy.float64, count=1)[0]
                    for i in numpy.arange(self.nw):
       -                self.w_m[i] = numpy.fromfile(fh, dtype=numpy.float64, count=1)
       -                self.w_vel[i] = numpy.fromfile(fh, dtype=numpy.float64, count=1)
       -                self.w_force[i] = numpy.fromfile(fh, dtype=numpy.float64, count=1)
       -                self.w_sigma0[i] = numpy.fromfile(fh, dtype=numpy.float64, count=1)
       +                self.w_m[i] = numpy.fromfile(fh, dtype=numpy.float64, count=1)[0]
       +                self.w_vel[i] = numpy.fromfile(fh, dtype=numpy.float64, count=1)[0]
       +                self.w_force[i] = numpy.fromfile(fh, dtype=numpy.float64, count=1)[0]
       +                self.w_sigma0[i] = numpy.fromfile(fh, dtype=numpy.float64, count=1)[0]
                    if sigma0mod:
                        self.w_sigma0_A = numpy.fromfile(fh, dtype=numpy.float64, count=1)
                        self.w_sigma0_f = numpy.fromfile(fh, dtype=numpy.float64, count=1)
       @@ -1110,13 +1110,13 @@ class sim:
                    if bonds:
                        # Inter-particle bonds
                        self.lambda_bar = numpy.fromfile(fh, dtype=numpy.float64, count=1)
       -                self.nb0 = int(numpy.fromfile(fh, dtype=numpy.uint32, count=1))
       +                self.nb0 = int(numpy.fromfile(fh, dtype=numpy.uint32, count=1)[0])
                        self.sigma_b = numpy.fromfile(fh, dtype=numpy.float64, count=1)
                        self.tau_b = numpy.fromfile(fh, dtype=numpy.float64, count=1)
                        self.bonds = numpy.empty((self.nb0, 2), dtype=numpy.uint32)
                        for i in numpy.arange(self.nb0):
       -                    self.bonds[i, 0] = numpy.fromfile(fh, dtype=numpy.uint32, count=1)
       -                    self.bonds[i, 1] = numpy.fromfile(fh, dtype=numpy.uint32, count=1)
       +                    self.bonds[i, 0] = numpy.fromfile(fh, dtype=numpy.uint32, count=1)[0]
       +                    self.bonds[i, 1] = numpy.fromfile(fh, dtype=numpy.uint32, count=1)[0]
                        self.bonds_delta_n = numpy.fromfile(fh, dtype=numpy.float64,
                                                            count=self.nb0)
                        self.bonds_delta_t = numpy.fromfile(fh, dtype=numpy.float64,
       @@ -1158,23 +1158,24 @@ class sim:
                                for x in numpy.arange(self.num[0]):
                                    self.v_f[x, y, z, 0] = numpy.fromfile(fh,
                                                                          dtype=numpy.float64,
       -                                                                  count=1)
       +                                                                  count=1)[0]
                                    self.v_f[x, y, z, 1] = numpy.fromfile(fh,
                                                                          dtype=numpy.float64,
       -                                                                  count=1)
       +                                                                  count=1)[0]
                                    self.v_f[x, y, z, 2] = numpy.fromfile(fh,
                                                                          dtype=numpy.float64,
       -                                                                  count=1)
       +                                                                  count=1)[0]
                                    self.p_f[x, y, z] = numpy.fromfile(fh,
                                                                       dtype=numpy.float64,
       -                                                               count=1)
       +                                                               count=1)[0]
                                    self.phi[x, y, z] = numpy.fromfile(fh,
                                                                       dtype=numpy.float64,
       -                                                               count=1)
       +                                                               count=1)[0]
                                    self.dphi[x, y, z] = numpy.fromfile(fh,
                                                                        dtype=numpy.float64,
       -                                                                count=1)\
       -                                                 /(self.time_dt*self.ndem)
       +                                                                count=1)[0]\
       +                                                 /(self.time_dt[0]
       +                                                   *self.ndem.item())
        
                        if self.version >= 0.36:
                            self.rho_f = numpy.fromfile(fh, dtype=numpy.float64,
       @@ -1224,7 +1225,7 @@ class sim:
                                        for x in numpy.arange(self.num[0]):
                                            self.p_f_constant[x, y, z] = \
                                                numpy.fromfile(fh, dtype=numpy.int32,
       -                                                       count=1)
       +                                                       count=1)[0]
                            else:
                                self.p_f_constant = numpy.zeros((self.num[0],
                                                                 self.num[1],
       @@ -2988,9 +2989,9 @@ class sim:
        
                # Initialize upper wall
                if idx == 0 or idx == 1 or idx == 3:
       -            self.w_x[idx] = numpy.array([xmax])
       +            self.w_x[idx] = xmax
                else:
       -            self.w_x[idx] = numpy.array([xmin])
       +            self.w_x[idx] = xmin
                self.w_m[idx] = self.totalMass()
        
            def consolidate(self, normal_stress=10e3):
       @@ -3311,7 +3312,7 @@ class sim:
                elif self.np > 0:
        
                    r_min = numpy.min(self.radius)
       -            m_min = self.rho * 4.0/3.0*numpy.pi*r_min**3
       +            m_min = self.rho[0] * 4.0/3.0*numpy.pi*r_min**3
        
                    if self.E > 0.001:
                        k_max = numpy.max(numpy.pi/2.0*self.E*self.radius)
       @@ -3825,7 +3826,7 @@ class sim:
                    self.V_b[0] = 0.0     # Zero liquid volume at bond
        
                # Debonding distance
       -        self.db[0] = (1.0 + theta/2.0) * self.V_b**(1.0/3.0)
       +        self.db[0] = (1.0 + theta/2.0) * self.V_b[0]**(1.0/3.0)
        
            def setStiffnessNormal(self, k_n):
                '''
       @@ -4764,7 +4765,7 @@ class sim:
                particle). Requires a previous call to :func:`findOverlaps()`. Values
                are stored in ``self.coordinationnumber``.
                '''
       -        self.coordinationnumber = numpy.zeros(self.np, dtype=numpy.int)
       +        self.coordinationnumber = numpy.zeros(self.np, dtype=int)
                for i in numpy.arange(self.overlaps.size):
                    self.coordinationnumber[self.pairs[0, i]] += 1
                    self.coordinationnumber[self.pairs[1, i]] += 1