-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstant_gs_with_hydraulics.jl
More file actions
154 lines (128 loc) · 4.16 KB
/
Copy pathconstant_gs_with_hydraulics.jl
File metadata and controls
154 lines (128 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using Photosynthesis
using Photosynthesis: step, Plant
using Plots
using Photosynthesis.PlantEcoPhys_jl: RHtoVPD
# Helper functions for environmental conditions
function f_tair(; t_mid=13, high=30, low=20)
t = 0:23
y = @. low + (high-low)*sin((t+12-t_mid)*pi/24)^2
return y
end
function f_ppfd(; t_start=6, t_end=20, ppfd_max=1500)
y = zeros(24)
t = t_start:t_end
y[t_start+1:t_end+1] = @. sin((t-t_start)*pi/(t_end-t_start))
return y * ppfd_max
end
# Simulation parameters
n_days = 5
gs_constant = 0.15 # mol m-2 s-1
println("Running $(n_days)-day simulation with constant gs = $gs_constant mol m-2 s-1")
println("Includes photosynthesis + hydraulics model\n")
# Create plant with both photosynthesis and hydraulics
plant = Plant()
# Storage for results
n_hours = n_days * 24
time_hours = Float64[]
A_vec = Float64[]
E_vec = Float64[]
P_leaf_vec = Float64[] # Xylem water potential at leaf
PLC_leaf_vec = Float64[] # Percent loss of conductivity at leaf
soil_water_vec = Float64[]
# Run simulation
hour = 0
plant_alive = true
for day in 1:n_days
# Daily environmental conditions
Tair = f_tair(; high=35, low=20)
PPFD = f_ppfd(; ppfd_max=1500)
VPD = RHtoVPD.(50, Tair)
for hour_of_day in 1:24
external = ExternalPhotosynParams(
Tair=Tair[hour_of_day],
VPD=VPD[hour_of_day],
PPFD=PPFD[hour_of_day]
)
# Run one hour with constant gs (includes photosynthesis + hydraulics)
A, dead = step(plant, external, gs_constant)
if dead
println("Plant died at day $day, hour $hour_of_day")
println(" Final soil water ratio: $(plant.hydraulic_state.soil_water_ratio)")
println(" Final leaf PLC: $(plant.hydraulic_state.PLC[end])")
global plant_alive = false
break
end
# Store results
push!(time_hours, hour)
push!(A_vec, A)
# Get transpiration from the last calculation
E, _ = PhotosynEB(plant.leaf, external, gs_constant)
push!(E_vec, E)
# Hydraulic state variables
push!(P_leaf_vec, plant.hydraulic_state.P[end]) # Pressure at top of plant
push!(PLC_leaf_vec, plant.hydraulic_state.PLC[end])
push!(soil_water_vec, plant.hydraulic_state.soil_water_ratio)
global hour += 1
end
!plant_alive && break
println("Day $day complete - Soil water: $(round(plant.hydraulic_state.soil_water_ratio, digits=3)), Leaf PLC: $(round(plant.hydraulic_state.PLC[end], digits=3))")
end
if plant_alive
println("\nPlant survived all $n_days days!")
println("Final soil water ratio: $(round(plant.hydraulic_state.soil_water_ratio, digits=3))")
println("Final leaf PLC: $(round(plant.hydraulic_state.PLC[end], digits=3))")
end
# Calculate totals
total_A = sum(max.(0, A_vec))
total_E = sum(max.(0, E_vec))
println("\nTotal carbon gain: $(round(total_A, digits=1)) umol CO2 m-2")
println("Total water loss: $(round(total_E, digits=1)) mmol H2O m-2")
# Create plots
p1 = plot(time_hours, A_vec,
label=false,
xlabel="Time (hours)",
ylabel="A (umol CO2 m-2 s-1)",
title="Photosynthesis",
linewidth=2
)
p2 = plot(time_hours, E_vec,
label=false,
xlabel="Time (hours)",
ylabel="E (mmol H2O m-2 s-1)",
title="Transpiration",
linewidth=2,
color=:blue
)
p3 = plot(time_hours, P_leaf_vec,
label=false,
xlabel="Time (hours)",
ylabel="Xylem P (MPa)",
title="Leaf Water Potential",
linewidth=2,
color=:red
)
p4 = plot(time_hours, PLC_leaf_vec,
label=false,
xlabel="Time (hours)",
ylabel="PLC (fraction)",
title="Leaf Cavitation (PLC)",
linewidth=2,
color=:orange
)
hline!(p4, [0.7], linestyle=:dash, color=:black, label="Death threshold")
p5 = plot(time_hours, soil_water_vec,
label=false,
xlabel="Time (hours)",
ylabel="Soil water ratio",
title="Soil Water Content",
linewidth=2,
color=:green
)
# Combine plots
plot(p1, p2, p3, p4, p5,
layout=(3,2),
size=(1200, 900),
plot_title="Plant Simulation: Constant gs=$gs_constant (with Hydraulics)"
)
savefig("constant_gs_with_hydraulics.png")
println("\nPlot saved as 'constant_gs_with_hydraulics.png'")