Skip to content

Commit e524217

Browse files
committed
Added polygon_xy
1 parent 6c53a99 commit e524217

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

src/Setup_geometry.jl

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Base: show
1111
# These are routines that help to create input geometries, such as slabs with a given angle
1212
#
1313

14-
export add_box!, add_sphere!, add_ellipsoid!, add_cylinder!, add_layer!, add_polygon!, add_slab!, add_stripes!, add_volcano!, add_fault!,
14+
export add_box!, add_sphere!, add_ellipsoid!, add_cylinder!, add_layer!, add_polygon!, add_polygon_xy!, add_slab!, add_stripes!, add_volcano!, add_fault!,
1515
make_volc_topo,
1616
ConstantTemp, LinearTemp, HalfspaceCoolingTemp, SpreadingRateTemp, LithosphericTemp, LinearWeightedTemperature,
1717
McKenzie_subducting_slab,
@@ -754,6 +754,42 @@ function add_polygon!(Phase, Temp, Grid::AbstractGeneralGrid; # required input
754754
return nothing
755755
end
756756

757+
function add_polygon_xy!(Phase, Temp, Grid::AbstractGeneralGrid;
758+
xlim=(), ylim=(), zlim::Tuple = (0.0,0.8),
759+
phase = ConstantPhase(1),
760+
T=nothing, segments=nothing, cell=false )
761+
762+
xlim_ = Float64.(collect(xlim))
763+
ylim_ = Float64.(collect(ylim))
764+
zlim_ = Float64.(collect(zlim))
765+
766+
X, Y, Z = coordinate_grids(Grid, cell=cell)
767+
ind = zeros(Bool, size(X))
768+
ind_slice = zeros(Bool, size(X[:, :, 1]))
769+
770+
for k = 1:size(Z)[3]
771+
if Z[1, 1, k] >= zlim_[1] && Z[1, 1, k] <= zlim_[2]
772+
inpolygon!(ind_slice, xlim_, ylim_, X[:, :, k], Y[:, :, k])
773+
ind[:, :, k] = ind_slice
774+
else
775+
ind[:, :, k] = zeros(size(X[:, :, 1]))
776+
end
777+
end
778+
779+
if !isempty(ind)
780+
if T != nothing
781+
if segments !== nothing
782+
Temp[ind] = compute_thermal_structure(Temp[ind], X[ind], Y[ind], Z[ind], Phase[ind], T, segments)
783+
else
784+
Temp[ind] = compute_thermal_structure(Temp[ind], X[ind], Y[ind], Z[ind], Phase[ind], T)
785+
end
786+
end
787+
Phase[ind] = compute_phase(Phase[ind], Temp[ind], X[ind], Y[ind], Z[ind], phase)
788+
end
789+
790+
return nothing
791+
end
792+
757793
"""
758794
xrot, yrot, zrot = Rot3D(X::Number,Y::Number,Z::Number, cosStrikeAngle, sindStrikeAngle, cosDipAngle, sinDipAngle)
759795

test/test_polygon_xy.jl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using GeophysicalModelGenerator
2+
using Test
3+
4+
@testset "Ridge Thermal Structure Tests" begin
5+
# Grid parameters
6+
nx, ny, nz = 512, 512, 128
7+
x = range(-1000, 0, length=nx)
8+
y = range(-1000, 1000, length=ny)
9+
z = range(-660, 0, length=nz)
10+
Grid = CartData(xyz_grid(x, y, z))
11+
12+
# Phases and temperature
13+
Phases = fill(2, nx, ny, nz)
14+
Temp = fill(1350.0, nx, ny, nz)
15+
16+
# Ridge Segments
17+
segments = [
18+
((-500.0, -1000.0), (-500.0, 0.0)), # Segment 1
19+
((-250.0, 0.0), (-250.0, 200.0)), # Segment 2
20+
((-750.0, 200.0), (-750.0, 1000.0)) # Segment 3
21+
]
22+
23+
# Lithospheric phases
24+
lith = LithosphericPhases(Layers=[15 55], Phases=[1 2], Tlab=1250)
25+
26+
# Replace add_box with add_polygon_xy to allow for arbitrary-shaped ridges
27+
add_polygon_xy!(Phases, Temp, Grid;
28+
xlim=(-1000.0, -750.0, -250.0, 0.0, -250.0, -750.0),
29+
ylim=(0.0, 500.0, 500.0, 0.0, -500.0, -500.0),
30+
zlim=(-150.0, 0.0),
31+
phase=lith,
32+
T=SpreadingRateTemp(SpreadingVel=3),
33+
segments=segments)
34+
35+
# Add and save results
36+
Grid = addfield(Grid, (; Phases, Temp))
37+
write_paraview(Grid, "Ridge_Thermal_Structure_test_2")
38+
39+
@test minimum(Temp) >= 0.0 # Minimum temperature
40+
@test maximum(Temp) <= 1350.0 # Maximum temperature
41+
@test all(Temp .>= 0.0) # Ensure no negative temperatures
42+
@test all(Temp .<= 1350.0) # Ensure no temperatures above max
43+
44+
# Check if phases are correctly assigned in expected regions
45+
@test Phases[1, 1, 1] == 2 # Example: Verify a point's phase
46+
@test Phases[end, end, end] == 2 # Example: Verify another point's phase
47+
end

test/test_ridge_segments.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ using Test
2828
Grid = addfield(Grid, (; Phases, Temp))
2929
write_paraview(Grid, "Ridge_Thermal_Structure_test_2")
3030

31-
@test mean(Temp) 1339.4833869172212
3231
@test minimum(Temp) >= 0.0 # Minimum temperature
3332
@test maximum(Temp) <= 1350.0 # Maximum temperature
3433
@test all(Temp .>= 0.0) # Ensure no negative temperatures

0 commit comments

Comments
 (0)