From 494415f0dc2705b5187088e1340d58f3c37c9a4b Mon Sep 17 00:00:00 2001 From: Skylar Gering Date: Thu, 13 Jun 2024 12:34:48 -0400 Subject: [PATCH] Small fixes --- Project.toml | 4 +++- src/floe_utils.jl | 2 ++ src/physical_processes/coupling.jl | 4 ++-- src/physical_processes/fractures.jl | 2 +- src/physical_processes/simplification.jl | 2 +- src/physical_processes/update_floe.jl | 2 +- src/simulation_components/domain_and_grid.jl | 2 +- src/simulation_components/floe.jl | 11 +++-------- test/test_floe_utils.jl | 2 -- test/test_physical_processes/test_ridge_raft.jl | 2 +- 10 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Project.toml b/Project.toml index 17273bb..815fbbb 100644 --- a/Project.toml +++ b/Project.toml @@ -31,13 +31,15 @@ VoronoiCells = "e3e34ffb-84e9-5012-9490-92c94d0c60a4" BenchmarkTools = "1" CairoMakie = "0.12" DataStructures = "0.18" +Extents = "0.1" GeometryBasics = "0.4" +GeometryOps = "0.1.8" Interpolations = "0.14, 0.15" JLD2 = "0.4" Makie = "0.19, 0.20, 0.21" Measures = "0.3" NCDatasets = "0.12, 0.13, 0.14" -NetCDF = "0.11" +NetCDF = "0.11, 0.12" SplitApplyCombine = "1" StaticArrays = "1" Statistics = "1" diff --git a/src/floe_utils.jl b/src/floe_utils.jl index aa76596..da4cbe5 100644 --- a/src/floe_utils.jl +++ b/src/floe_utils.jl @@ -59,8 +59,10 @@ union_polys(p1, p2; kwargs...) = GO.union(p1, p2; target = GI.PolygonTrait(), fi simplify_poly(p, tol) = GO.simplify(p; tol = tol) make_polygon(coords::PolyVec) = GI.Polygon(GO.tuples(coords)) +make_polygon(tuple_coords) = GI.Polygon(tuple_coords) make_polygon(ring::GI.LinearRing) = GI.Polygon([ring]) make_multipolygon(coords::Vector{<:PolyVec}) = GI.MultiPolygon(GO.tuples(coords)) +make_multipolygon(tuple_coords) = GI.MultiPolygon(tuple_coords) make_multipolygon(polys::Vector{<:GI.Polygon}) = GI.MultiPolygon(polys) """ diff --git a/src/physical_processes/coupling.jl b/src/physical_processes/coupling.jl index 0794ac1..fa204f3 100644 --- a/src/physical_processes/coupling.jl +++ b/src/physical_processes/coupling.jl @@ -183,7 +183,7 @@ function generate_subfloe_points( mc_y = zeros(FT, point_generator.npoints) mc_in = fill(false, point_generator.npoints) # Find bounding box - poly = GI.Polygon(GO.tuples(coords)) + poly = make_polygon(GO.tuples(coords)) (xmin, xmax), (ymin, ymax) = GI.extent(poly) Δx, Δy = xmax - xmin, ymax - ymin while err > point_generator.err @@ -324,7 +324,7 @@ function generate_subfloe_points( end x_sub_floe = repeat(x_interior_points, n_ypoints) y_sub_floe = repeat(y_interior_points, inner = n_xpoints) - poly = GI.Polygon(GO.tuples(coords)) + poly = make_polygon(GO.tuples(coords)) in_floe = [GO.coveredby((x_sub_floe[i], y_sub_floe[i]), poly) for i in eachindex(x_sub_floe)] append!(xpoints, x_sub_floe[in_floe]) diff --git a/src/physical_processes/fractures.jl b/src/physical_processes/fractures.jl index 8267df7..412a023 100644 --- a/src/physical_processes/fractures.jl +++ b/src/physical_processes/fractures.jl @@ -302,7 +302,7 @@ function determine_fractures( ) # Determine if floe stresses are in or out of criteria allowable regions update_criteria!(criteria, floes) - critical_poly = GI.Polygon(GO.tuples(criteria.vertices)) + critical_poly = make_polygon(GO.tuples(criteria.vertices)) # If stresses are outside of criteria regions, we will fracture the floe frac_idx = [!GO.coveredby(eigvals(s), critical_poly) for s in floes.stress] frac_idx[floes.area .< min_floe_area] .= false diff --git a/src/physical_processes/simplification.jl b/src/physical_processes/simplification.jl index 3a51dfe..6c0044b 100644 --- a/src/physical_processes/simplification.jl +++ b/src/physical_processes/simplification.jl @@ -66,7 +66,7 @@ function smooth_floes!( if length(floes.coords[i][1]) > simp_settings.max_vertices poly_list = [simplify_poly(make_polygon(floes.coords[i]), simp_settings.tol)] if !isempty(topography) - poly_list = diff_polys(GI.MultiPolygon(poly_list), GI.MultiPolygon(topography.coords); fix_multipoly = nothing) + poly_list = diff_polys(make_multipolygon(poly_list), make_multipolygon(topography.coords); fix_multipoly = nothing) end simp_poly = if length(poly_list) == 1 diff --git a/src/physical_processes/update_floe.jl b/src/physical_processes/update_floe.jl index bf06add..dd5cf39 100644 --- a/src/physical_processes/update_floe.jl +++ b/src/physical_processes/update_floe.jl @@ -47,7 +47,7 @@ function replace_floe!( floe.height; ρi = floe_settings.ρi, ) - floe.angles = GO.angles(GI.Polygon(floe.coords)) + floe.angles = GO.angles(make_polygon(floe.coords)) floe.α = FT(0) translate!(floe.coords, -floe.centroid[1], -floe.centroid[2]) floe.rmax = sqrt(maximum([sum(c.^2) for c in floe.coords[1]])) diff --git a/src/simulation_components/domain_and_grid.jl b/src/simulation_components/domain_and_grid.jl index 9eacce8..f2a4495 100644 --- a/src/simulation_components/domain_and_grid.jl +++ b/src/simulation_components/domain_and_grid.jl @@ -443,7 +443,7 @@ struct TopographyElement{FT}<:AbstractDomainElement{FT} throw(ArgumentError("Topography element maximum radius must be \ positive and non-zero.")) end - topo_poly = GI.Polygon(rmholes(coords)) + topo_poly = make_polygon(rmholes(coords)) topo_poly = GO.ClosedRing()(topo_poly) new{FT}(GI.coordinates(topo_poly), centroid, rmax) end diff --git a/src/simulation_components/floe.jl b/src/simulation_components/floe.jl index 539af7e..0e6fb02 100644 --- a/src/simulation_components/floe.jl +++ b/src/simulation_components/floe.jl @@ -233,7 +233,7 @@ function Floe{FT}( coords = find_poly_coords(floe) coords = [orient_coords(coords[1])] moment = _calc_moment_inertia(FT, floe, centroid, height; ρi = floe_settings.ρi) - angles = GO.angles(GI.Polygon(coords)) + angles = GO.angles(make_polygon(coords)) translate!(coords, -centroid[1], -centroid[2]) rmax = sqrt(maximum([sum(c.^2) for c in coords[1]])) status = Status() @@ -430,7 +430,7 @@ function initialize_floe_field( floe_polys = [make_polygon(valid_polyvec!(c)) for c in coords] # Remove overlaps with topography if !isempty(domain.topography) - floe_polys = GO.difference(make_multipolygon(floe_polys), make_multipolygon(domain.topography.coords); target = GI.PolygonTrait(),fix_multipoly = nothing) + floe_polys = diff_polys(make_multipolygon(floe_polys), make_multipolygon(domain.topography.coords)) end # Turn polygons into floes for p in floe_polys @@ -511,7 +511,7 @@ function generate_voronoi_coords( ) where {FT <: AbstractFloat} xpoints = Vector{FT}() ypoints = Vector{FT}() - domain_poly = GI.MultiPolygon(GO.tuples(domain_coords)) + domain_poly = make_multipolygon(GO.tuples(domain_coords)) area_frac = GO.area(domain_poly) / reduce(*, scale_fac) # Increase the number of points based on availible percent of bounding box npoints = ceil(Int, desired_points / area_frac) @@ -651,11 +651,6 @@ function initialize_floe_field( # Open water in cell cell_init = make_polygon(rect_coords(xmin, xmin + collen, ymin, ymin + rowlen)) open_cell = intersect_polys(cell_init, open_water_mp) - # open_cell = if !isempty(domain.topography) - # diff_polys(open_cell_init, topography_poly) - # else - # [open_cell_init] - # end open_cell_mpoly = make_multipolygon(open_cell) open_coords = [GI.coordinates(c) for c in open_cell] open_area = sum(GO.area, open_cell; init = 0.0) diff --git a/test/test_floe_utils.jl b/test/test_floe_utils.jl index c349cec..c9097b2 100644 --- a/test/test_floe_utils.jl +++ b/test/test_floe_utils.jl @@ -39,7 +39,6 @@ @test !Subzero.hashole(poly_nohole) @test Subzero.hashole(poly_hole1) @test Subzero.hashole(poly_hole2) - # @test Subzero.hashole(multipoly_hole1) # Test removing holes from polygons and multipolygons @test [ext] == Subzero.rmholes([ext]) @@ -50,7 +49,6 @@ @test GO.equals(Subzero.rmholes(poly_nohole), poly_nohole) @test GO.equals(Subzero.rmholes(poly_hole1), poly_nohole) @test GO.equals(Subzero.rmholes(poly_hole2), poly_nohole) - # @test !Subzero.hashole(Subzero.rmholes(multipoly_hole1)) # Test translating coordinates and polygons @test Subzero.translate([ext], 0.0, 0.0) == [ext] diff --git a/test/test_physical_processes/test_ridge_raft.jl b/test/test_physical_processes/test_ridge_raft.jl index fc72a06..42e0da9 100644 --- a/test/test_physical_processes/test_ridge_raft.jl +++ b/test/test_physical_processes/test_ridge_raft.jl @@ -271,7 +271,7 @@ PeriodicBoundary(East, grid), PeriodicBoundary(West, grid), ) - boundary_poly = GO.UnionIntersectingPolygons()(GI.MultiPolygon([ + boundary_poly = GO.UnionIntersectingPolygons()(Subzero.make_multipolygon([ collision_domain.north.coords, collision_domain.south.coords, collision_domain.east.coords, collision_domain.west.coords]))