leaf_stomatal_profit_max
def leaf_stomatal_profit_max(
physcon:plant_hydraulics.parameter_classes.PhysCon, atmos:plant_hydraulics.parameter_classes.Atmos,
leaf:plant_hydraulics.parameter_classes.Leaf, # Must have: g0, g1_medlyn, minl_wp, a_psi.
flux:plant_hydraulics.parameter_classes.Flux
)->plant_hydraulics.parameter_classes.Flux: # With converged gs, An, Tleaf, psi_leaf, etc.Stomatal conductance via Medlyn + profit-maximisation.
Algorithm:
Sweep gs from g0 to gs_max (30 points).
At each gs, compute the full leaf physics chain: boundary layer → energy balance → photosynthesis → water potential.
Compute normalised GAIN = An/An_max and COST = vulnerability(ψ_leaf).
PROFIT = GAIN - COST. Find the gs that maximises profit.
Clamp to Medlyn gs (hydraulics can only reduce gs, never increase it).
Recompute final fluxes at the optimal gs.
Parameters
physcon : PhysCon atmos : Atmos leaf : Leaf Must have: g0, g1_medlyn, minl_wp, a_psi. flux : Flux
Returns
flux : Flux With converged gs, An, Tleaf, psi_leaf, etc.