Skip to content

Remove allocation and clipping of Y#1748

Merged
kmdeck merged 1 commit into
mainfrom
kd/co2_fixes
May 18, 2026
Merged

Remove allocation and clipping of Y#1748
kmdeck merged 1 commit into
mainfrom
kd/co2_fixes

Conversation

@kmdeck

@kmdeck kmdeck commented May 18, 2026

Copy link
Copy Markdown
Member

Purpose

This PR removes direct clipping of Y, which would prevent us from conserving carbon (and oxygen). It also removes one allocation of a 3D field. (Im not sure if that could be the culprit for the recent AMIP slowdown @juliasloan25 ? this allocation was added between 1.8.0 and 1.8.1)

I also adjusted some comments to reflect that some of the clipping, while allowing the simulation to carry on with "physical" values, is going to correspond to an incorrect solution to the equations (it will not agree with the solution you would get with a stable simulation). This is problematic because in these columns the solution becomes controlled by clipping etc and not by the physics. we can try and fix this in the future.

Ill try the long run!

To-do

Content


  • I have read and checked the items on the review checklist.

θ_l = soil_moisture(model.drivers.met, p, Y, t, z)
θ_i = soil_ice(model.drivers.met, p, Y, t, z)
Csom = @. lazy(max(Y.soilco2.SOC, 0)) # Clamp SOC to non-negative (lazy, no allocation)
Csom = Y.soilco2.SOC

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think the original line actually clipped Y here, but I am not sure.

@AlexisRenchon AlexisRenchon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the longrun looks okay, let's merge it! (I can have a look when it is out)

@kmdeck kmdeck merged commit e550c9c into main May 18, 2026
16 of 18 checks passed
@kmdeck kmdeck deleted the kd/co2_fixes branch May 18, 2026 19:50
@kmdeck

kmdeck commented May 18, 2026

Copy link
Copy Markdown
Member Author

If the longrun looks okay, let's merge it! (I can have a look when it is out)

no NaNs!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants