Skip to content

Commit 81db248

Browse files
authored
Merge pull request #163 from JuliaGeodynamics/pa-Tvolcano
add condition if `T=nothing`
2 parents 0e47fee + ddc01aa commit 81db248

File tree

1 file changed

+55
-49
lines changed

1 file changed

+55
-49
lines changed

src/Setup_geometry.jl

Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -235,21 +235,23 @@ julia> segments = [((-500.0, -1000.0), (-500.0, 0.0)),
235235
((-250.0, 0.0), (-250.0, 200.0)),
236236
((-750.0, 200.0), (-750.0, 1000.0))];
237237
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,
240240
T=SpreadingRateTemp(SpreadingVel=3), segments=segments)
241241
julia> Grid = addfield(Grid, (; Phases, Temp)); # Add to Cartesian model
242242
julia> write_paraview(Grid, "Ridge_Thermal_Structure") # Save model to Paraview
243243
1-element Vector{String}:
244244
"Ridge_Thermal_Structure.vts"
245245
"""
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
249250
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
253255

254256

255257
# Retrieve 3D data arrays for the grid
@@ -804,33 +806,35 @@ julia> segments = [
804806
((-750.0, 200.0), (-750.0, 1000.0)) # Segment 3
805807
]
806808
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),
813815
segments=segments)
814816
julia> Grid = addfield(Grid, (; Phases, Temp)) # Add fields
815817
julia> write_paraview(Grid, "Plate") # Save model to Paraview
816818
1-element Vector{String}:
817819
"Plate.vts"
818820
"""
819821

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+
)
824828

825829
xlim_ = collect(xlim)
826830
ylim_ = collect(ylim)
827831
zlim_ = collect(zlim)
828832

829-
X, Y, Z = coordinate_grids(Grid, cell=cell)
833+
X, Y, Z = coordinate_grids(Grid, cell = cell)
830834
ind = zeros(Bool, size(X))
831835
ind_slice = zeros(Bool, size(X[:, :, 1]))
832836

833-
for k = 1:size(Z, 3)
837+
for k in 1:size(Z, 3)
834838
if zlim_[1] <= Z[1, 1, k] <= zlim_[2]
835839
inpolygon!(ind_slice, xlim_, ylim_, X[:, :, k], Y[:, :, k])
836840
@views ind[:, :, k] = ind_slice
@@ -948,7 +952,9 @@ function add_volcano!(
948952

949953
# @views Temp[ind .== false] .= 0.0
950954
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
952958
end
953959

954960
return nothing
@@ -1233,31 +1239,31 @@ Note: the thermal age at the mid oceanic ridge is set to 1 year to avoid divisio
12331239
MORside = "left" # side of box where the MOR is located
12341240
SpreadingVel = 3 # spreading velocity [cm/yr]
12351241
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]
12371243
end
12381244

12391245
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
12561262

12571263
else
12581264
error("unknown side")
12591265
end
1260-
1266+
12611267
for i in eachindex(Temp)
12621268
ThermalAge = abs(Distance[i] * 1.0e3 * 1.0e2) / SpreadingVel + AgeRidge * 1.0e6 # Thermal age in years
12631269
if ThermalAge > maxAge * 1.0e6
@@ -1272,7 +1278,7 @@ function compute_thermal_structure(Temp, X, Y, Z, Phase, s::SpreadingRateTemp)
12721278
Temp[i] = (Tsurface .- Tmantle) * erfc((abs.(Z[i]) * 1.0e3) ./ (2 * sqrt(kappa * ThermalAge))) + MantleAdiabaticT[i]
12731279

12741280
end
1275-
1281+
12761282
return Temp
12771283
end
12781284

@@ -1303,14 +1309,14 @@ The thermal age is capped at `maxAge` years, and the temperature is adjusted bas
13031309

13041310
function compute_thermal_structure(Temp, X, Y, Z, Phase, s::SpreadingRateTemp, segments::Vector{Tuple{Tuple{Float64, Float64}, Tuple{Float64, Float64}}})
13051311
@unpack Tsurface, Tmantle, Adiabat, SpreadingVel, AgeRidge, maxAge = s
1306-
kappa = 1e-6;
1312+
kappa = 1.0e-6
13071313
SecYear = 3600 * 24 * 365
1308-
dz = Z[end]-Z[1];
1314+
dz = Z[end] - Z[1]
13091315

13101316
MantleAdiabaticT = Tmantle .+ Adiabat * abs.(Z)
13111317

13121318
#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)]
13141320

13151321
for I in eachindex(X)
13161322
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
13261332
Distance = perpendicular_distance_to_segment(px, py, x1, y1, x2, y2)
13271333

13281334
# 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
13321338
end
13331339

13341340
ThermalAge = ThermalAge * SecYear # Convert to seconds
13351341
if ThermalAge == 0
1336-
ThermalAge = 1e-6 # Avoid zero
1342+
ThermalAge = 1.0e-6 # Avoid zero
13371343
end
13381344

13391345
# 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]
13411347
end
13421348

13431349
return Temp
@@ -1356,7 +1362,7 @@ end
13561362
# Function to determine the side of a point with respect to a line (adjusted for segment direction)
13571363
function side_of_line(x, y, x1, y1, x2, y2, direction)
13581364
side = (x2 - x1) * (y - y1) - (y2 - y1) * (x - x1)
1359-
direction == :left ? side > 0 : side < 0
1365+
return direction == :left ? side > 0 : side < 0
13601366
end
13611367

13621368
# Function to determine in which region a point lies (based on delimiters)

0 commit comments

Comments
 (0)