File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,12 @@ function Base.iterate(iter::LayoutIterator{<:SFDP}, state)
101
101
((locs[j] .- locs[i]) / norm (locs[j] .- locs[i])))
102
102
end
103
103
end
104
+ if any (isnan, force)
105
+ # if two points are at the exact same location
106
+ # use random force in any direction
107
+ rng = MersenneTwister (algo. seed + i)
108
+ force = randn (rng, Ftype)
109
+ end
104
110
mask = (! ). (pin[i]) # where pin=true mask will multiply with 0
105
111
locs[i] = locs[i] .+ (step .* (force ./ norm (force))) .* mask
106
112
energy = energy + norm (force)^ 2
Original file line number Diff line number Diff line change @@ -104,7 +104,15 @@ function Base.iterate(iter::LayoutIterator{<:Spring}, state)
104
104
# / | cos θ = d_x/d = fx/F
105
105
# /--- -> fx = F*d_x/d
106
106
# dx fx
107
- force_vec += Ftype (F_d .* (locs[j] .- locs[i]))
107
+ if ! iszero (d)
108
+ force_vec += Ftype (F_d .* (locs[j] .- locs[i]))
109
+ else
110
+ # if two points are at the exact same location
111
+ # use random force in any direction
112
+ rng = MersenneTwister (algo. seed + i)
113
+ force_vec += randn (rng, Ftype)
114
+ end
115
+
108
116
end
109
117
force[i] = force_vec
110
118
end
You can’t perform that action at this time.
0 commit comments