Added site distances to stats dictionary, and second near neighbor functionality

This commit is contained in:
Kenneth Jao 2022-03-25 17:10:55 -04:00
parent 87be8908e3
commit 0551faf085
5 changed files with 1077 additions and 817 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -164,7 +164,9 @@ class Simulation:
sim, frames = Simulation.load(path)
for frame in frames:
sim.frames.append(sim.energy.mode(*frame["domain"], frame["arr"]))
sim.frames[-1].stats = frame["stats"]
for k, v in frame["stats"].items():
if k not in sim.frames[-1].stats:
sim.frames[-1].stats[k] = v
return sim

File diff suppressed because it is too large Load Diff

View File

@ -650,6 +650,7 @@ cdef class VoronoiContainer:
edge_cache = np.asarray(self.edge_cache)
self.stats["edge_lengths"] = edge_cache[caches, self.edge_cache_map.ila_mag]
self.stats["site_distances"] = edge_cache[caches, self.edge_cache_map.iya_mag]
@property
def site_arr(self):
@ -704,3 +705,43 @@ cdef class VoronoiContainer:
site_verts.append(verts)
return sites, site_verts
def second_near_neighbor(self):
cdef VoronoiInfo info = _VoronoiInfo(self.sites, self.edges, self.points,
self.vertices, self.site_cache, self.edge_cache, self.edge_cache_map)
cdef INT_T i, j, k
cdef Site xi, xj, xk
cdef HalfEdge e, f
cdef Vector2D v
snn = []
for i in range(self.n):
xi = _Site(i, &info)
e = xi.edge(&xi)
first_neighbors = np.empty((xi.edge_num(&xi),), dtype=INT)
for j in range(xi.edge_num(&xi)):
f = e.twin(&e)
xj = f.face(&f)
first_neighbors[j] = xj.index(&xj) % self.n
e = e.next(&e)
second_neighbors = set()
for j in range(len(first_neighbors)):
xj = _Site(first_neighbors[j], &info)
e = xj.edge(&xj)
for k in range(xj.edge_num(&xj)):
f = e.twin(&e)
xk = f.face(&f)
second_neighbors.add(xk.index(&xk) % self.n)
e = e.next(&e)
for j in range(len(first_neighbors)):
second_neighbors.remove(first_neighbors[j])
second_neighbors.remove(i)
snn.append(list(second_neighbors))
return snn