Skip to content

Commit aecb9c1

Browse files
authored
Sg/fix nares issues (#133)
* Update sim startup for ease of use * Re-add messages per timestep keyword * Debugging statment * Fix debugging statement * Remove debug printing * Add in try catch * Add in try/catch and info output when voronoi fails
1 parent 6491677 commit aecb9c1

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/simulation_components/simulation.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,19 @@ function timestep_sim!(sim, tstep, start_tstep = 0)
219219
end
220220

221221
# Required actions to setup simulation. Right now, this only entails setting up the simulation's logger.
222-
function _startup_sim(sim, logger)
222+
function startup_sim(sim, logger = nothing; messages_per_tstep = 1)
223+
# Set up logger if needed
224+
if isnothing(logger)
225+
logger = SubzeroLogger(; sim, messages_per_tstep)
226+
end
223227
global_logger(logger)
224228
# Start sim notice
225229
sim.verbose && println(sim.name * " is running!")
226230
return
227231
end
228232

229233
# Required actions to tear down simulation. Right now, this just involves flushing the simulation's logger and closing the stream.
230-
function _teardown_sim(sim)
234+
function teardown_sim(sim)
231235
# Finish logging
232236
logger = current_logger()
233237
if hasfield(typeof(logger), :stream)
@@ -258,18 +262,14 @@ Simulation calculations will be done with Floats of type FT (Float64 of Float32)
258262
- None. The simulation will be run and outputs will be saved in the output folder.
259263
"""
260264
function run!(sim; logger = nothing, messages_per_tstep = 1, start_tstep = 0)
261-
# Set up logger if needed
262-
if isnothing(logger)
263-
logger = SubzeroLogger(; sim, messages_per_tstep)
264-
end
265-
_startup_sim(sim, logger)
265+
startup_sim(sim, logger; messages_per_tstep)
266266
tstep = start_tstep
267267
while tstep <= (start_tstep + sim.nΔt)
268268
# Timestep the simulation forward
269269
timestep_sim!(sim, tstep, start_tstep)
270270
tstep+=1
271271
end
272-
_teardown_sim(sim)
272+
teardown_sim(sim)
273273
return
274274
end
275275

src/tools/geom_utils.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,12 @@ function _generate_voronoi_coords(::Type{FT}, desired_points::Int, Δx, Δy, xmi
247247
clip_points = GO.tuples(((xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax)), FT)
248248
clip_vertices = (1, 2, 3, 4, 1)
249249
clip_polygon = (clip_points, clip_vertices)
250-
GO.voronoi(tuple.(xpoints, ypoints), FT; clip_polygon)
250+
try
251+
GO.voronoi(tuple.(xpoints, ypoints), FT; clip_polygon)
252+
catch
253+
@info "Voronoi failed - floe to fracture likely really small." tstep = tstep
254+
Polys{FT}[]
255+
end
251256
else
252257
Polys{FT}[]
253258
end

0 commit comments

Comments
 (0)