I'm trying to get the convergence of my calculations, but isn't working. I'm iterating the function through the for loop, and I want break the loop when I get the tolerance. So, the function gives me an array D[nr, nz]
, I iterate him in the for loop, and each time I want to compare the last iteration with the new iteration, to know if that difference is lower than the tolerance. But the difference between the arrays, before and after calling the function Ddif
, is returning a vector of zeros. I think I am not passing the values correctly, and making the difference between the same values, but I don't know why.
nr = 8
nz = 10
def calculo(E):
# my calcs
#return an array D[nr,nz]
return
ncolmns3 = (nr * nz)
cont_i = 0
Ddif = []
for a in range(0, 10000, 1):
#before calling the function
DOld2 = D
#turning the array in an array of one row, and (nr * nz) columns
DOld3 = numpy.reshape(DOld2, ncolmns3)
D = calculo(D)
#after calling the function
DNew2 = D
#turning the array in an array of one row, and (nr * nz) columns
DNew3 = numpy.reshape(DNew2, ncolmns3)
# Difference between before and after calling the function
for i in range(0, ncolmns3, 1):
Ddif.append(math.fabs(DOld3[i] - DNew3[i]))
MaxDif = numpy.max(Ddif)
#tolerance
Tol = 0.01
cont_i += 1
if (MaxDif <= Tol) is True:
break
print(cont_i)