commit fdcbb84010a27836443ff76524129e0dfa956f48
parent 81fe44ecb8d02e99a8f6e7e1a0002ad960ff01ac
Author: Anders Damsgaard <andersd@riseup.net>
Date: Mon, 1 May 2017 14:39:18 -0400
gather contact check functionality in single function
Diffstat:
M | src/contact_search.jl | | | 79 | ++++++++++++++++++++++++++++++++++++------------------------------------------- |
1 file changed, 36 insertions(+), 43 deletions(-)
diff --git a/src/contact_search.jl b/src/contact_search.jl
@@ -58,26 +58,7 @@ function findContactsAllToAll!(simulation::Simulation)
# Check contacts with other grains
for j = 1:length(simulation.ice_floes)
- if i < j
-
- if (simulation.ice_floes[i].fixed &&
- simulation.ice_floes[j].fixed) ||
- !simulation.ice_floes[i].enabled ||
- !simulation.ice_floes[j].enabled
- continue
- end
-
- # Inter-grain position vector and grain overlap
- position_ij = interIceFloePositionVector(simulation, i, j)
- overlap_ij = findOverlap(simulation, i, j, position_ij)
-
- # Check if grains overlap (overlap when negative)
- if overlap_ij < 0.0
- push!(simulation.contact_pairs, [i, j])
- push!(simulation.overlaps,
- overlap_ij*position_ij/norm(position_ij))
- end
- end
+ checkAndAddContact!(simulation, i, j)
end
end
end
@@ -105,31 +86,43 @@ function findContactsOceanGrid!(simulation::Simulation)
end
for idx_j in simulation.ocean.ice_floe_list[i, j]
-
- if idx_i < idx_j
-
- if (simulation.ice_floes[idx_i].fixed &&
- simulation.ice_floes[idx_j].fixed) ||
- !simulation.ice_floes[idx_i].enabled ||
- !simulation.ice_floes[idx_j].enabled
- continue
- end
-
- # Inter-grain position vector and grain overlap
- position_ij = interIceFloePositionVector(simulation,
- idx_i, idx_j)
- overlap_ij = findOverlap(simulation, idx_i, idx_j,
- position_ij)
-
- # Check if grains overlap (overlap when negative)
- if overlap_ij < 0.0
- push!(simulation.contact_pairs, [idx_i, idx_j])
- push!(simulation.overlaps,
- overlap_ij*position_ij/norm(position_ij))
- end
- end
+ checkAndAddContact!(simulation, idx_i, idx_j)
end
end
end
end
end
+
+export addContact!
+"""
+checkAndAddContact!(simulation, i, j)
+
+Check for contact between two ice floes and register the interaction.
+
+# Arguments
+* `simulation::Simulation`: the simulation object containing the ice floes
+* `i::Int`: index of the first ice floe
+* `j::Int`: index of the second ice floe
+"""
+function checkAndAddContact!(simulation::Simulation, i::Int, j::Int)
+ if i < j
+
+ if (simulation.ice_floes[i].fixed &&
+ simulation.ice_floes[j].fixed) ||
+ !simulation.ice_floes[i].enabled ||
+ !simulation.ice_floes[j].enabled
+ return
+ end
+
+ # Inter-grain position vector and grain overlap
+ position_ij = interIceFloePositionVector(simulation, i, j)
+ overlap_ij = findOverlap(simulation, i, j, position_ij)
+
+ # Check if grains overlap (overlap when negative)
+ if overlap_ij < 0.0
+ push!(simulation.contact_pairs, [i, j])
+ push!(simulation.overlaps, overlap_ij*position_ij/norm(position_ij))
+ #push!(simulation.contact_parallel_displacement, zeros(2))
+ end
+ end
+end