1
+ using GeophysicalModelGenerator
2
+
3
+ # Grid parameters
4
+ nx, ny, nz = 128 , 128 , 57
5
+ x = range (- 1000 , 1000 , length= nx)
6
+ y = range (- 1000 , 1000 , length= ny)
7
+ z = range (- 660 , 0 , length= nz)
8
+ Grid = CartData (xyz_grid (x, y, z))
9
+
10
+ # Phases and temperature
11
+ Phases = fill (2 , nx, ny, nz)
12
+ Temp = fill (1350.0 , nx, ny, nz)
13
+
14
+ # Ridge Segments
15
+ segments = [
16
+ ((- 500.0 , - 1000.0 ), (- 500.0 , 0.0 )), # Segment 1
17
+ ((- 250.0 , 0.0 ), (- 250.0 , 200.0 )), # Segment 2
18
+ ((- 750.0 , 200.0 ), (- 750.0 , 1000.0 )) # Segment 3
19
+ ]
20
+
21
+ # Create a vector of SpreadingRateTemp parameters (one for each segment)
22
+ s = [
23
+ SpreadingRateTemp (Tsurface= 0.0 , Tmantle= 1350.0 , Adiabat= 0.0 , SpreadingVel= 3.0 , AgeRidge= 0.0 , maxAge= 100.0 ), # Segmento 1
24
+ SpreadingRateTemp (Tsurface= 0.0 , Tmantle= 1350.0 , Adiabat= 0.0 , SpreadingVel= 1.0 , AgeRidge= 0.0 , maxAge= 100.0 ), # Segmento 2
25
+ SpreadingRateTemp (Tsurface= 0.0 , Tmantle= 1350.0 , Adiabat= 0.0 , SpreadingVel= 6.0 , AgeRidge= 0.0 , maxAge= 100.0 ) # Segmento 3
26
+ ]
27
+
28
+ # Lithospheric phases and temperature setup
29
+ lith = LithosphericPhases (Layers= [15 , 55 ], Phases= [1 , 2 ], Tlab= 1250 )
30
+
31
+ # Add a box for the test (adjust parameters as needed)
32
+ add_box! (Phases, Temp, Grid; xlim= (- 1000.0 ,0.0 ), ylim= (- 500.0 , 500.0 ), zlim= (- 80.0 , 0.0 ), phase= lith,
33
+ T= s, 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
+
40
+ # ###############3
41
+ # Case 3: Multiple segments with different parameters
42
+
43
+ function compute_thermal_structure (Temp, X, Y, Z, Phase, s:: Vector{SpreadingRateTemp} , segments:: Vector{Tuple{Tuple{Float64, Float64}, Tuple{Float64, Float64}}} )
44
+ @show " Using compute_thermal_structure with Vector{SpreadingRateTemp_3}"
45
+ kappa = 1e-6
46
+ SecYear = 3600 * 24 * 365
47
+ dz = Z[end ] - Z[1 ]
48
+
49
+ # MantleAdiabaticT debe calcularse fuera del bucle para ser consistente en todas las regiones
50
+ MantleAdiabaticT = [params. Tmantle + params. Adiabat * abs .(Z) for params in s]
51
+
52
+ # Crear delimitadores
53
+ delimiters = [(segments[i][2 ], segments[i + 1 ][1 ]) for i in 1 : length (segments) - 1 ]
54
+
55
+ # Iterar sobre cada índice de X
56
+ for I in eachindex (X)
57
+ px, py, pz = X[I], Y[I], Z[I]
58
+
59
+ # Determinar la región de este punto
60
+ region = determine_region (px, py, delimiters, segments)
61
+
62
+ # Seleccionar el segmento correspondiente y sus parámetros
63
+ segment = segments[region]
64
+ params = s[region] # Parámetros correspondientes al segmento
65
+
66
+ # Desestructuración de los parámetros
67
+ @unpack Tsurface, Tmantle, Adiabat, SpreadingVel, AgeRidge, maxAge = params
68
+
69
+ # Calcular MantleAdiabaticT para este segmento (dentro del bucle)
70
+ MantleAdiabaticT = Tmantle .+ Adiabat .* abs .(pz)
71
+
72
+ x1, y1 = segment[1 ]
73
+ x2, y2 = segment[2 ]
74
+
75
+ # Calcular la distancia al segmento
76
+ Distance = perpendicular_distance_to_segment (px, py, x1, y1, x2, y2)
77
+
78
+ # Calcular la edad térmica
79
+ ThermalAge = abs (Distance * 1e3 * 1e2 ) / SpreadingVel + AgeRidge * 1e6 # Edad térmica en años
80
+ if ThermalAge > maxAge * 1e6
81
+ ThermalAge = maxAge * 1e6
82
+ end
83
+
84
+ ThermalAge = ThermalAge * SecYear # Convertir a segundos
85
+ if ThermalAge == 0
86
+ ThermalAge = 1e-6 # Evitar cero
87
+ end
88
+
89
+ # Calcular temperatura
90
+ Temp[I] = (Tsurface - Tmantle) * erfc (abs (pz) * 1e3 / (2 * sqrt (kappa * ThermalAge))) + MantleAdiabaticT[I]
91
+ end
92
+
93
+ return Temp
94
+ end
95
+
96
+
97
+
98
+
99
+ if segments != = nothing
100
+ if isa (T, Vector{SpreadingRateTemp})
101
+ Temp[ind_flat] = compute_thermal_structure (Temp[ind_flat], X[ind], Y[ind], Z[ind], Phase[ind_flat], T, segments)
102
+ else
103
+ Temp[ind_flat] = compute_thermal_structure (Temp[ind_flat], X[ind], Y[ind], Z[ind], Phase[ind_flat], T, segments)
104
+ end
105
+ else
106
+ Temp[ind_flat] = compute_thermal_structure (Temp[ind_flat], Xrot[ind], Yrot[ind], Zrot[ind], Phase[ind_flat], T)
107
+ end
0 commit comments