def find_boundary(mesh,vals,threshold=0.5):
""" Find boundary points on the phase diagram where the switching probability = threshold """
boundary_points = []
durs = mesh.points[:,0]
volts = mesh.points[:,1]
indices, indptr = mesh.vertex_neighbor_vertices
for k in range(len(vals)):
for k_nb in indptr[indices[k]:indices[k+1]]:
if (vals[k]-threshold)*(vals[k_nb]-threshold)<0:
x0 = find_cross([durs[k],vals[k]],[durs[k_nb],vals[k_nb]],cut=threshold)
y0 = find_cross([volts[k],vals[k]],[volts[k_nb],vals[k_nb]],cut=threshold)
boundary_points.append([x0,y0])
boundary_points = np.array(boundary_points)
if len(boundary_points) > 0:
b = np.ascontiguousarray(boundary_points).view(np.dtype((np.void,
boundary_points.dtype.itemsize * boundary_points.shape[1])))
_, idx = np.unique(b, return_index=True)
boundary_points = boundary_points[idx]
# Sort the boundary_points by x-axis
boundary_points = sorted(boundary_points, key=itemgetter(0))
return np.array(boundary_points)
评论列表
文章目录