@@ -235,21 +235,23 @@ julia> segments = [((-500.0, -1000.0), (-500.0, 0.0)),
235
235
((-250.0, 0.0), (-250.0, 200.0)),
236
236
((-750.0, 200.0), (-750.0, 1000.0))];
237
237
julia> lith = LithosphericPhases(Layers=[15 55], Phases=[1 2], Tlab=1250);
238
- julia> add_box!(Phases, Temp, Grid; xlim=(-1000.0, 0.0), ylim=(-500.0, 500.0),
239
- zlim=(-80.0, 0.0), phase=lith,
238
+ julia> add_box!(Phases, Temp, Grid; xlim=(-1000.0, 0.0), ylim=(-500.0, 500.0),
239
+ zlim=(-80.0, 0.0), phase=lith,
240
240
T=SpreadingRateTemp(SpreadingVel=3), segments=segments)
241
241
julia> Grid = addfield(Grid, (; Phases, Temp)); # Add to Cartesian model
242
242
julia> write_paraview(Grid, "Ridge_Thermal_Structure") # Save model to Paraview
243
243
1-element Vector{String}:
244
244
"Ridge_Thermal_Structure.vts"
245
245
"""
246
- function add_box! (Phase, Temp, Grid:: AbstractGeneralGrid ; # required input
247
- xlim:: Tuple = (20 ,100 ), ylim= nothing , zlim:: Tuple = (10 ,80 ), # limits of the box
248
- Origin= nothing , StrikeAngle= 0 , DipAngle= 0 , # origin & dip/strike
246
+ function add_box! (
247
+ Phase, Temp, Grid:: AbstractGeneralGrid ; # required input
248
+ xlim:: Tuple = (20 , 100 ), ylim = nothing , zlim:: Tuple = (10 , 80 ), # limits of the box
249
+ Origin = nothing , StrikeAngle = 0 , DipAngle = 0 , # origin & dip/strike
249
250
phase = ConstantPhase (1 ), # Sets the phase number(s) in the box
250
- T= nothing , # Sets the thermal structure (various functions are available)
251
- segments= nothing , # Allows defining multiple ridge segments
252
- cell= false ) # if true, Phase and Temp are defined on cell centers
251
+ T = nothing , # Sets the thermal structure (various functions are available)
252
+ segments = nothing , # Allows defining multiple ridge segments
253
+ cell = false
254
+ ) # if true, Phase and Temp are defined on cell centers
253
255
254
256
255
257
# Retrieve 3D data arrays for the grid
@@ -804,33 +806,35 @@ julia> segments = [
804
806
((-750.0, 200.0), (-750.0, 1000.0)) # Segment 3
805
807
]
806
808
julia> lith = LithosphericPhases(Layers=[15 55], Phases=[1 2], Tlab=1250)
807
- julia> add_plate!(Phases, Temp, Grid;
808
- xlim=(-1000.0, -750.0, -250.0, 0.0, -250.0, -750.0),
809
- ylim=(0.0, 500.0, 500.0, 0.0, -500.0, -500.0),
810
- zlim=(-150.0, 0.0),
811
- phase=lith,
812
- T=SpreadingRateTemp(SpreadingVel=3),
809
+ julia> add_plate!(Phases, Temp, Grid;
810
+ xlim=(-1000.0, -750.0, -250.0, 0.0, -250.0, -750.0),
811
+ ylim=(0.0, 500.0, 500.0, 0.0, -500.0, -500.0),
812
+ zlim=(-150.0, 0.0),
813
+ phase=lith,
814
+ T=SpreadingRateTemp(SpreadingVel=3),
813
815
segments=segments)
814
816
julia> Grid = addfield(Grid, (; Phases, Temp)) # Add fields
815
817
julia> write_paraview(Grid, "Plate") # Save model to Paraview
816
818
1-element Vector{String}:
817
819
"Plate.vts"
818
820
"""
819
821
820
- function add_plate! (Phase, Temp, Grid:: AbstractGeneralGrid ;
821
- xlim= (), ylim= (), zlim:: Tuple = (0.0 ,0.8 ),
822
- phase = ConstantPhase (1 ),
823
- T= nothing , segments= nothing , cell= false )
822
+ function add_plate! (
823
+ Phase, Temp, Grid:: AbstractGeneralGrid ;
824
+ xlim = (), ylim = (), zlim:: Tuple = (0.0 , 0.8 ),
825
+ phase = ConstantPhase (1 ),
826
+ T = nothing , segments = nothing , cell = false
827
+ )
824
828
825
829
xlim_ = collect (xlim)
826
830
ylim_ = collect (ylim)
827
831
zlim_ = collect (zlim)
828
832
829
- X, Y, Z = coordinate_grids (Grid, cell= cell)
833
+ X, Y, Z = coordinate_grids (Grid, cell = cell)
830
834
ind = zeros (Bool, size (X))
831
835
ind_slice = zeros (Bool, size (X[:, :, 1 ]))
832
836
833
- for k = 1 : size (Z, 3 )
837
+ for k in 1 : size (Z, 3 )
834
838
if zlim_[1 ] <= Z[1 , 1 , k] <= zlim_[2 ]
835
839
inpolygon! (ind_slice, xlim_, ylim_, X[:, :, k], Y[:, :, k])
836
840
@views ind[:, :, k] = ind_slice
@@ -948,7 +952,9 @@ function add_volcano!(
948
952
949
953
# @views Temp[ind .== false] .= 0.0
950
954
if ! isempty (ind_flat)
951
- Temp[ind_flat] = compute_thermal_structure (Temp[ind_flat], Grid. x. val[ind], Grid. y. val[ind], depth[ind], Phases[ind_flat], T)
955
+ if ! isnothing (T)
956
+ Temp[ind_flat] = compute_thermal_structure (Temp[ind_flat], Grid. x. val[ind], Grid. y. val[ind], depth[ind], Phases[ind_flat], T)
957
+ end
952
958
end
953
959
954
960
return nothing
@@ -1233,31 +1239,31 @@ Note: the thermal age at the mid oceanic ridge is set to 1 year to avoid divisio
1233
1239
MORside = " left" # side of box where the MOR is located
1234
1240
SpreadingVel = 3 # spreading velocity [cm/yr]
1235
1241
AgeRidge = 0 # Age of the ridge [Myrs]
1236
- maxAge = 60 # maximum thermal age of plate [Myrs]
1242
+ maxAge = 60 # maximum thermal age of plate [Myrs]
1237
1243
end
1238
1244
1239
1245
function compute_thermal_structure (Temp, X, Y, Z, Phase, s:: SpreadingRateTemp )
1240
- @unpack Tsurface, Tmantle, Adiabat, MORside, SpreadingVel, AgeRidge, maxAge = s
1241
-
1242
- kappa = 1e-6 ;
1243
- SecYear = 3600 * 24 * 365
1244
- dz = Z[end ]- Z[1 ];
1245
-
1246
- MantleAdiabaticT = Tmantle .+ Adiabat* abs .(Z); # Adiabatic temperature of mantle
1247
-
1248
- if MORside== " left"
1249
- Distance = X .- X[1 ,1 , 1 ];
1250
- elseif MORside== " right"
1251
- Distance = X[end ,1 , 1 ] .- X;
1252
- elseif MORside== " front"
1253
- Distance = Y .- Y[1 ,1 , 1 ];
1254
- elseif MORside== " back"
1255
- Distance = Y[1 ,end ,1 ] .- Y;
1246
+ @unpack Tsurface, Tmantle, Adiabat, MORside, SpreadingVel, AgeRidge, maxAge = s
1247
+
1248
+ kappa = 1.0e-6
1249
+ SecYear = 3600 * 24 * 365
1250
+ dz = Z[end ] - Z[1 ]
1251
+
1252
+ MantleAdiabaticT = Tmantle .+ Adiabat * abs .(Z) # Adiabatic temperature of mantle
1253
+
1254
+ if MORside == " left"
1255
+ Distance = X .- X[1 , 1 , 1 ]
1256
+ elseif MORside == " right"
1257
+ Distance = X[end , 1 , 1 ] .- X
1258
+ elseif MORside == " front"
1259
+ Distance = Y .- Y[1 , 1 , 1 ]
1260
+ elseif MORside == " back"
1261
+ Distance = Y[1 , end , 1 ] .- Y
1256
1262
1257
1263
else
1258
1264
error (" unknown side" )
1259
1265
end
1260
-
1266
+
1261
1267
for i in eachindex (Temp)
1262
1268
ThermalAge = abs (Distance[i] * 1.0e3 * 1.0e2 ) / SpreadingVel + AgeRidge * 1.0e6 # Thermal age in years
1263
1269
if ThermalAge > maxAge * 1.0e6
@@ -1272,7 +1278,7 @@ function compute_thermal_structure(Temp, X, Y, Z, Phase, s::SpreadingRateTemp)
1272
1278
Temp[i] = (Tsurface .- Tmantle) * erfc ((abs .(Z[i]) * 1.0e3 ) ./ (2 * sqrt (kappa * ThermalAge))) + MantleAdiabaticT[i]
1273
1279
1274
1280
end
1275
-
1281
+
1276
1282
return Temp
1277
1283
end
1278
1284
@@ -1303,14 +1309,14 @@ The thermal age is capped at `maxAge` years, and the temperature is adjusted bas
1303
1309
1304
1310
function compute_thermal_structure (Temp, X, Y, Z, Phase, s:: SpreadingRateTemp , segments:: Vector{Tuple{Tuple{Float64, Float64}, Tuple{Float64, Float64}}} )
1305
1311
@unpack Tsurface, Tmantle, Adiabat, SpreadingVel, AgeRidge, maxAge = s
1306
- kappa = 1e-6 ;
1312
+ kappa = 1.0e-6
1307
1313
SecYear = 3600 * 24 * 365
1308
- dz = Z[end ]- Z[1 ];
1314
+ dz = Z[end ] - Z[1 ]
1309
1315
1310
1316
MantleAdiabaticT = Tmantle .+ Adiabat * abs .(Z)
1311
1317
1312
1318
# Create delimiters
1313
- delimiters = [(segments[i][2 ], segments[i + 1 ][1 ]) for i in 1 : length (segments) - 1 ]
1319
+ delimiters = [(segments[i][2 ], segments[i + 1 ][1 ]) for i in 1 : ( length (segments) - 1 )]
1314
1320
1315
1321
for I in eachindex (X)
1316
1322
px, py, pz = X[I], Y[I], Z[I]
@@ -1326,18 +1332,18 @@ function compute_thermal_structure(Temp, X, Y, Z, Phase, s::SpreadingRateTemp, s
1326
1332
Distance = perpendicular_distance_to_segment (px, py, x1, y1, x2, y2)
1327
1333
1328
1334
# Calculate thermal age
1329
- ThermalAge = abs (Distance * 1e5 ) / SpreadingVel + AgeRidge * 1e6 # Thermal age in years
1330
- if ThermalAge > maxAge * 1e6
1331
- ThermalAge = maxAge * 1e6
1335
+ ThermalAge = abs (Distance * 1.0e5 ) / SpreadingVel + AgeRidge * 1.0e6 # Thermal age in years
1336
+ if ThermalAge > maxAge * 1.0e6
1337
+ ThermalAge = maxAge * 1.0e6
1332
1338
end
1333
1339
1334
1340
ThermalAge = ThermalAge * SecYear # Convert to seconds
1335
1341
if ThermalAge == 0
1336
- ThermalAge = 1e -6 # Avoid zero
1342
+ ThermalAge = 1.0e -6 # Avoid zero
1337
1343
end
1338
1344
1339
1345
# Calculate temperature
1340
- Temp[I] = (Tsurface - Tmantle) * erfc (abs (pz) * 1e3 / (2 * sqrt (kappa * ThermalAge))) + MantleAdiabaticT[I]
1346
+ Temp[I] = (Tsurface - Tmantle) * erfc (abs (pz) * 1.0e3 / (2 * sqrt (kappa * ThermalAge))) + MantleAdiabaticT[I]
1341
1347
end
1342
1348
1343
1349
return Temp
@@ -1356,7 +1362,7 @@ end
1356
1362
# Function to determine the side of a point with respect to a line (adjusted for segment direction)
1357
1363
function side_of_line (x, y, x1, y1, x2, y2, direction)
1358
1364
side = (x2 - x1) * (y - y1) - (y2 - y1) * (x - x1)
1359
- direction == :left ? side > 0 : side < 0
1365
+ return direction == :left ? side > 0 : side < 0
1360
1366
end
1361
1367
1362
1368
# Function to determine in which region a point lies (based on delimiters)
0 commit comments