-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_energy_diff.jl
58 lines (44 loc) · 2.16 KB
/
get_energy_diff.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function get_conserv_ΔE(target_pixel, neighbor_pixel, model)::Float64
target_cell_A = model.Cells[target_pixel.cellid].area
neighbor_cell_A = model.Cells[neighbor_pixel.cellid].area
target_cell_P = model.Cells[target_pixel.cellid].perimeter # Current target perimeter
neighbor_cell_P = model.Cells[neighbor_pixel.cellid].perimeter # Current neighbor perimeter
ΔP_t, ΔP_n = get_perimeter_change(target_pixel, neighbor_pixel, model)
ΔEₜ_area = model.K_E * (2*(model.A₀ - target_cell_A) + 1)
ΔEₙ_area = model.K_E * (2*(neighbor_cell_A - model.A₀) + 1)
ΔEₜ_peri = model.K_P * (2*ΔP_t*(target_cell_P - model.P₀) + ΔP_t^2)
ΔEₙ_peri = model.K_P * (2*ΔP_n*(neighbor_cell_P - model.P₀) + ΔP_n^2)
return ΔEₜ_area + ΔEₙ_area + ΔEₜ_peri + ΔEₙ_peri
end
function get_adh_ΔE(target_pixel, neighbor_pixel, model)
N_old = 0
N_new = 0
@inbounds for nc in node_neighbors(target_pixel, model)
npx = model.agents[Agents.coord2vertex((nc[1],nc[2]), model)]
# for npx in pixel_neighbors(target_pixel, model)
if npx.cellid==target_pixel.cellid
N_new += 1
elseif npx.cellid==neighbor_pixel.cellid
N_old += 1
end
end
return model.J_CC*(N_new - N_old)
end
function get_persis_ΔE(target_pixel, neighbor_pixel, model)
target_cell = model.Cells[target_pixel.cellid]
neighbor_cell = model.Cells[neighbor_pixel.cellid]
Δr_target = (target_cell.centerPos .- target_pixel.pos) ./ (target_cell.area - 1)
Δr_target = Δr_target ./ norm(Δr_target)
Δr_neighbor = (neighbor_pixel.pos .- neighbor_cell.centerPos) ./ (neighbor_cell.area + 1)
Δr_neighbor = Δr_neighbor ./ norm(Δr_neighbor)
ΔE = dot(target_cell.polarity, Δr_target) / norm(target_cell.polarity) +
dot(neighbor_cell.polarity, Δr_neighbor) / norm(neighbor_cell.polarity)
return - model.S * ΔE
end
function get_total_ΔE(target_pixel, neighbor_pixel, model)
ΔE =
get_conserv_ΔE(target_pixel, neighbor_pixel, model) +
get_adh_ΔE(target_pixel, neighbor_pixel, model)
get_persis_ΔE(target_pixel, neighbor_pixel, model)
return ΔE
end