Skip to content

Commit

Permalink
Reduce interactions memory (#80)
Browse files Browse the repository at this point in the history
* Start removing vcat

* Working version with num_inters

* Reduce torque allocations

* Update stress calculations to reduce allocations

* Update strain calculations to reduce allocations

* Finish small memory updates and tests

* Debug collision interactions

* Re-add threading
  • Loading branch information
skygering authored Sep 11, 2023
1 parent 3f952fa commit efd0f61
Show file tree
Hide file tree
Showing 18 changed files with 241 additions and 149 deletions.
12 changes: 7 additions & 5 deletions examples/converge_diverge_flow.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using JLD2, Random, SplitApplyCombine, Statistics, StructArrays, Subzero
import LibGEOS as LG
using JLD2, Random, Statistics, Subzero

# User Inputs
const FT = Float64
Expand Down Expand Up @@ -72,6 +71,9 @@ simulation = Simulation(
# Run simulation
run!(simulation)

Subzero.create_sim_gif("output/converge_diverge/floes.jld2",
"output/converge_diverge/initial_state.jld2",
"output/converge_diverge/converge_diverge.gif")
plot_sim(
"output/converge_diverge/floes.jld2",
"output/converge_diverge/initial_state.jld2",
20,
"output/converge_diverge/converge_diverge.mp4",
)
14 changes: 7 additions & 7 deletions examples/shear_flow.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using JLD2, Random, Statistics, StructArrays, Subzero
import LibGEOS as LG
using JLD2, Random, Statistics, Subzero

# User Inputs
const FT = Float64
Expand Down Expand Up @@ -79,8 +78,9 @@ simulation = Simulation(
)
run_time!(simulation)

#ProfileView.@profview run!(simulation)

Subzero.create_sim_gif("output/shear_flow/floes.jld2",
"output/shear_flow/initial_state.jld2",
"output/shear_flow/shear_flow.gif")
plot_sim(
"output/shear_flow/floes.jld2",
"output/shear_flow/initial_state.jld2",
20,
"output/shear_flow/shear_flow.mp4",
)
19 changes: 5 additions & 14 deletions examples/simple_strait.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
using JLD2, Random, SplitApplyCombine, Statistics, StructArrays, Subzero
import LibGEOS as LG
using JLD2, Random, Statistics, Subzero


Subzero.plot_sim(
"output/simple_strait/floes.jld2",
"output/simple_strait/initial_state.jld2",
20,
"output/simple_strait/simple_strait.mp4",
)
# User Inputs
const FT = Float64
const Lx = 1e5
Expand Down Expand Up @@ -52,7 +44,7 @@ coupling_settings = CouplingSettings(
# Floe creation
floe_arr = initialize_floe_field(
FT,
200,
75,
[0.7],
domain,
hmean,
Expand All @@ -72,7 +64,7 @@ fracture_settings = FractureSettings(
criteria = HiblerYieldCurve(floe_arr),
Δt = 75,
npieces = 3,
nhistory = 1000,
nhistory = 100,
deform_on = false,
)

Expand All @@ -88,7 +80,7 @@ simulation = Simulation(
model = model,
consts = consts,
Δt = Δt,
nΔt = 20000,
nΔt = 5000,
verbose = true,
coupling_settings = coupling_settings,
fracture_settings = fracture_settings,
Expand All @@ -97,9 +89,8 @@ simulation = Simulation(

# Run simulation
run_time!(simulation)
#ProfileView.@profview run!(simulation)

Subzero.plot_sim(
plot_sim(
"output/simple_strait/floes.jld2",
"output/simple_strait/initial_state.jld2",
Δt,
Expand Down
65 changes: 64 additions & 1 deletion examples/test_run.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,69 @@
using JLD2, Random, Statistics, Subzero, BenchmarkTools, StructArrays
using JLD2, Random, Statistics, Subzero, BenchmarkTools, StructArrays, SplitApplyCombine
import LibGEOS as LG


Δt = 10
Lx = 1e5
Ly = 1e5
collision_settings = CollisionSettings()
grid = RegRectilinearGrid(
(-Lx, Lx),
(-Lx, Lx),
1e4,
1e4,
)
double_periodic_domain = Domain(
PeriodicBoundary(North, grid),
PeriodicBoundary(South, grid),
PeriodicBoundary(East, grid),
PeriodicBoundary(West, grid),
)
# Parent-parent collison (parents are touching)
coords1 = splitdims(vcat([5*Lx/8 5*Lx/8 3*Lx/4 3*Lx/4].+1000, [3*Ly/4 5*Ly/4 5*Ly/4 3*Ly/4]))
coords2 = splitdims(vcat(-[5*Lx/4 5*Lx/4 3*Lx/4-1000 3*Lx/4-1000], -[7*Lx/8 3*Lx/4-1000 3*Lx/4-1000 7*Lx/8]))

floe_arr = StructArray(Floe([c], 0.5, 0.0) for c in [coords1, coords2])
for i in eachindex(floe_arr)
floe_arr.id[i] = Float64(i)
end
trans_arr = StructArray([
Floe(
Subzero.translate([coords1],
0.0, -2Ly),
0.5,
0.0,
),
Floe(
Subzero.translate([coords2], 2Lx, 0.0),
0.5,
0.0,
),
])
for i in eachindex(trans_arr)
trans_arr.id[i] = i
end
spinlock = Threads.SpinLock()
Subzero.timestep_collisions!(
trans_arr,
2,
double_periodic_domain,
Subzero.Constants(),
Δt,
collision_settings,
spinlock,
)
add_ghosts!(floe_arr, double_periodic_domain)
Subzero.timestep_collisions!(
floe_arr,
2,
double_periodic_domain,
Subzero.Constants(),
Δt,
collision_settings,
spinlock,
)


# User Inputs
const FT = Float64
const Lx = 1e5
Expand Down
11 changes: 7 additions & 4 deletions examples/uniform_flow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ simulation = Simulation(
coupling_settings = CouplingSettings(two_way_coupling_on = true),
)
run_time!(simulation)

Subzero.create_sim_gif("output/uniform_flow/floes.jld2",
"output/uniform_flow/initial_state.jld2",
"output/uniform_flow/uniform_flow.gif")

Subzero.plot_sim(
"output/uniform_flow/floes.jld2",
"output/uniform_flow/initial_state.jld2",
20,
"output/uniform_flow/uniform_flow.mp4",
)
5 changes: 3 additions & 2 deletions src/Subzero.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ export
IceStressCell,
CellFloes,
MonteCarloPointsGenerator,
SubGridPointsGenerator
SubGridPointsGenerator,
plot_sim

import Base.@kwdef # this is being exported as of version 1.9
import LibGEOS as LG
using DataStructures, Dates, GeometryBasics, Interpolations, JLD2,
using CairoMakie, DataStructures, Dates, GeometryBasics, Interpolations, JLD2,
LinearAlgebra, Logging, Makie, Measures, NCDatasets, NetCDF,
PolygonInbounds, Printf, Random, SplitApplyCombine, StaticArrays,
Statistics, StructArrays, VoronoiCells
Expand Down
Loading

0 comments on commit efd0f61

Please sign in to comment.