Skip to content

Commit

Permalink
Debug type inference (#76)
Browse files Browse the repository at this point in the history
* Start debugging type instability

* Reduce type instability

* Attempt to update ghost floes

* Fix ghost bug

* Work on removing deepcopy

* Remove output type instabilities

* Remove direct floe modifications

* Fix floe util

* Update intersect coords

* Remove stuct array i index call

* Update comments

* Finish tests
  • Loading branch information
skygering authored Jul 18, 2023
1 parent c457cb6 commit 3402de7
Show file tree
Hide file tree
Showing 14 changed files with 632 additions and 418 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.1.0"
[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
Cthulhu = "f68482b8-f384-11e8-15f7-abe071a5a75f"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
GR = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71"
Expand All @@ -14,14 +15,15 @@ Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
LibGEOS = "a90b1aa1-3769-5649-ba7e-abc5a9d163eb"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Measures = "442fdcdd-2543-5da2-b0f3-8c86c306513e"
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
NetCDF = "30363a11-5582-574a-97bb-aa9a979735b9"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
PolygonInbounds = "e4521ec6-8c1d-418e-9da2-b3bc4ae105d6"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
ProfileView = "c46f51b8-102a-5cf2-8d2c-8597cb0e0da7"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SplitApplyCombine = "03a91e81-4c3e-53e1-a0a4-9c0c8f19dd66"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Expand Down
6 changes: 4 additions & 2 deletions examples/shear_flow.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using JLD2, Random, Statistics, StructArrays, Subzero
using JLD2, Random, Statistics, StructArrays, Subzero, ProfileView
import LibGEOS as LG

# User Inputs
Expand Down Expand Up @@ -71,13 +71,15 @@ simulation = Simulation(
model = model,
consts = consts,
Δt = Δt,
nΔt = 2000,
nΔt = 1000,
verbose = true,
writers = writers,
rng = Xoshiro(1),
coupling_settings = coupling_settings,
)
run_time!(simulation)

#ProfileView.@profview run!(simulation)

Subzero.create_sim_gif("output/shear_flow/floes.jld2",
"output/shear_flow/initial_state.jld2",
Expand Down
5 changes: 3 additions & 2 deletions examples/simple_strait.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using JLD2, Random, SplitApplyCombine, Statistics, StructArrays, Subzero
using JLD2, Random, SplitApplyCombine, Statistics, StructArrays, Subzero, ProfileView
import LibGEOS as LG

# User Inputs
const FT = Float64
const Lx = 1e5
const Ly = 1e5
const Δgrid = 1e4
const Δgrid = 2e3
const hmean = 0.25
const Δh = 0.0
const Δt = 20
Expand Down Expand Up @@ -90,6 +90,7 @@ simulation = Simulation(

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

Subzero.create_sim_gif("output/simple_strait/floes.jld2",
"output/simple_strait/initial_state.jld2",
Expand Down
106 changes: 37 additions & 69 deletions examples/test_run.jl
Original file line number Diff line number Diff line change
@@ -1,80 +1,48 @@
using JLD2, Random, Statistics, Subzero, BenchmarkTools, StructArrays
import LibGEOS as LG

frac_stress = [-29955.396 -3428.008; -3428.008 -1942.0464]
frac_deform_floe = Floe(
[[
[-50548.186, -49995.968],
[-50550.745, -37790.078],
[-20856.010, -32518.566],
[-20929.577, -49989.757],
[-50548.186, -49995.968],
]],
0.25,
0.0,
u = 0.1,
v = -0.2,
ξ = 0.05,
Δt = 10
max_overlap = 0.75
Lx = 1e5
Ly = Lx
hmean = 0.25
Δh = 0.0
grid = RegRectilinearGrid(
(-Lx, Lx),
(-Ly, Ly),
1e4,
1e4,
)
frac_floe = deepcopy(frac_deform_floe) # Without interactions, won't deform
no_frac_floe = Floe( # This floe is colliding with frac_deform_floe
[[
[1467.795, -25319.563],
[1664.270, -25640.216],
[-1105.179, -33458.936],
[-17529.019, -50035.583],
[-21193.828, -50088.777],
[-21370.170, -32618.322],
[-21247.656, -31077.536],
[-12818.593, -27031.048],
[1467.795, -25319.563],
]],
0.25,
0.0,
nboundary = PeriodicBoundary(North, grid)
sboundary = PeriodicBoundary(South, grid)
eboundary = CollisionBoundary(East, grid)
wboundary = OpenBoundary(West, grid)
topo_elem = TopographyElement(
[[[1e4, 0.0], [0.0, 1e4], [1e4, 2e4], [2e4, 1e4], [1e4, 0.0]]],
)
domain = Domain(
nboundary,
sboundary,
eboundary,
wboundary,
StructArray([topo_elem]),
)
no_frac_small = Floe( # This floe is too small to fracture or deform
# Diagonal floe barely overlaping with eastern collision boundary
efloe_small = Floe(
[[
[1e3, 1e3],
[1e3, 1.5e3],
[1.5e3, 1.5e3],
[1.5e3, 1e3],
[1e3, 1e3],
[9.5e4, 0.0],
[9e4, 0.5e4],
[10e4, 2.5e4],
[10.05e4, 2e4],
[9.5e4, 0.0],
]],
0.25,
0.0,
)
frac_deform_floe.stress = frac_stress
frac_deform_floe.interactions = collect([
3,
-279441968.984,
-54223517.438,
-21091.0918258529,
-40358.0042297616,
-148920620521.112,
6795329.38154967,
]')
frac_deform_floe.p_dudt = 0.11
frac_floe.stress = frac_stress
no_frac_small.stress = frac_stress

floes = StructArray([
frac_deform_floe, frac_floe, no_frac_floe, no_frac_small
])
floes.id .= collect(1:4)
frac_settings = FractureSettings(
fractures_on = true,
criteria = HiblerYieldCurve(floes),
Δt = 75,
deform_on = true,
hmean,
Δh,
)
new_floes = Subzero.split_floe(
floes[1],
Xoshiro(3),
frac_settings,
CouplingSettings(),
Constants(),
10,
)
efloe_small.u = 0.5
efloe_small.v = 0.25
consts = Constants()
Subzero.floe_domain_interaction!(efloe_small, domain, consts, Δt, max_overlap)

# User Inputs
const FT = Float64
Expand Down
Loading

0 comments on commit 3402de7

Please sign in to comment.