Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tr/add get fields atmos #1205

Merged
merged 6 commits into from
Mar 5, 2025
Merged

Tr/add get fields atmos #1205

merged 6 commits into from
Mar 5, 2025

Conversation

imreddyTeja
Copy link
Contributor

@imreddyTeja imreddyTeja commented Feb 24, 2025

Purpose

Add get_field methods that are needed to couple with the full land model.

Also adds update_field for emissivity.

Closes #1200

To-do

  • LHF/SHF

Content

Add air_pressure, air_temperature, humidity, co2, diffuse_fraction, SW_d, LW_d, and cos_zenith_angle
to get_field on AtmosModelSimulation in Interfacer.jl.

Add get_field methods for the above values in
ClimaAtmosSimulation

Add emissivity to update_field on AtmosModelSimulation in Interfacer.jl,
and add a method for it in ClimaAtmosSimulation

Remove co2 from update_field on AtmosModelSimulation in Interfacer.jl and
method definition for ClimaAtmosSimulation


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

@imreddyTeja imreddyTeja force-pushed the tr/add-get_fields-Atmos branch 3 times, most recently from f2d41d5 to 0aed291 Compare February 25, 2025 00:38
@imreddyTeja imreddyTeja force-pushed the tr/add-get_fields-Atmos branch from 0aed291 to 328d9b0 Compare February 25, 2025 18:27
@imreddyTeja imreddyTeja marked this pull request as ready for review February 25, 2025 18:48
@imreddyTeja imreddyTeja requested a review from szy21 February 25, 2025 18:50
@imreddyTeja imreddyTeja force-pushed the tr/add-get_fields-Atmos branch 5 times, most recently from 854a22d to f7c38c9 Compare February 25, 2025 22:16
else
direct_flux_dn = radiation_model.face_sw_direct_flux_dn[1, :]
FT = eltype(total_flux_dn)
diffuse_fractions = (total_flux_dn .- direct_flux_dn) ./ (max.(total_flux_dn, eps(FT)))
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we want to limit it between 0 and 1 just to be exra safe. I don't think it should matter, maybe we can also wait and see if there is a problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

diffuse_fraction is now clamped to [0,1]

Copy link
Member

@szy21 szy21 left a comment

Choose a reason for hiding this comment

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

Thanks!

Comment on lines +239 to +251
function Interfacer.update_field!(sim::ClimaAtmosSimulation, ::Val{:emissivity}, field)
# sets all 16 bands (rows) to the same values
sim.integrator.p.radiation.rrtmgp_model.surface_emissivity .=
reshape(CC.Fields.field2array(field), 1, length(parent(field)))
end
Copy link
Member

Choose a reason for hiding this comment

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

In the long term, maybe we can make the RRTMGPInterface assume every band is the same if only one value is passed in (maybe this is already the behavior not? I'm not sure). This way we don't need to hard code the length(parent) here.

@juliasloan25
Copy link
Member

We recently changed CO2 from being read in within ClimaCoupler and passed to ClimaAtmos, to being read in within ClimaAtmos. We should have removed the update_field! method for co2 but we missed it. Could you remove that method for ClimaAtmos, as well as the mentions of :co2 in src/Interfacer.jl and the tests, in this PR please?

When we use the full land model, we'll need to read in mean global co2 from the atmosphere and pass it to the land model, so we need a get_field for this quantity from atmos. Could you add that in this PR too please?

@juliasloan25
Copy link
Member

@szy21 @Sbozzolo Will the field atmos_sim.integrator.p.radiation.rrtmgp_model.volume_mixing_ratio_co2 only be filled if we run atmos with radiation and the MaunaLoa option for CO2? That seems to be implied by the changes in the ClimaAtmos PR moving the file read to atmos https://github.com/CliMA/ClimaAtmos.jl/pull/3522/files, e.g. in src/solver/type_getters.jl. If so, we'll need to think about what CO2 value to supply to land when atmos doesn't provide CO2

@Sbozzolo
Copy link
Member

@szy21 @Sbozzolo Will the field atmos_sim.integrator.p.radiation.rrtmgp_model.volume_mixing_ratio_co2 only be filled if we run atmos with radiation and the MaunaLoa option for CO2? That seems to be implied by the changes in the ClimaAtmos PR moving the file read to atmos https://github.com/CliMA/ClimaAtmos.jl/pull/3522/files, e.g. in src/solver/type_getters.jl. If so, we'll need to think about what CO2 value to supply to land when atmos doesn't provide CO2

It is always filled.

https://github.com/CliMA/ClimaAtmos.jl/blob/cedbf1b6e27ed084d04a66a559451841a44c31b8/src/parameterized_tendencies/radiation/radiation.jl#L93-L96

Here's how it's filled in the fixedco2 case

@juliasloan25
Copy link
Member

It is always filled.

https://github.com/CliMA/ClimaAtmos.jl/blob/cedbf1b6e27ed084d04a66a559451841a44c31b8/src/parameterized_tendencies/radiation/radiation.jl#L93-L96

Here's how it's filled in the fixedco2 case

What if co2 is set to nothing and we aren't using radiation? I.e. this case:

    (isnothing(co2) && !with_rrtgmp) &&
        @warn ("$(co2) does nothing if RRTGMP is not used")

@Sbozzolo
Copy link
Member

If it's nothing and you arent' using radiation, co2 is not set because rrtgmp is also not defined

Copy link
Member

@juliasloan25 juliasloan25 left a comment

Choose a reason for hiding this comment

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

This looks good! We should update the docs too - could you add a section to the Interfacer.md docs ### AtmosModelSimulation - required functions to run with ClimaLandSimulation that explains which get_field and update_field! methods are required to run with the full land (i.e. the ones you've added here). It would be good to note which ones won't be present if the atmosphere doesn't have radiation, and that because of this we need to enable radiation in the atmosphere when running with the full land model. Thank you!

@imreddyTeja imreddyTeja force-pushed the tr/add-get_fields-Atmos branch from f32cf97 to 11e4d33 Compare February 28, 2025 02:28
Add diffuse_fraction, SW_d, LW_d, and cos of the zenith_angle
to get_field on AtmosModelSimulation in Interfacer.jl.

Add get_field methods for the above values in
ClimaAtmosSimulation

Remove safe_div and use anonymous func

Only calculate on first level for diffuse_frac

Add update_field for emissivity in AtmosModelSim

Add emissivity to update_field in the Interfacer,
and add a method definition for it in climaatmos.jl
All 16 bands are set to the same values.

Clamp diffuse_fraction to [0,1]

Remove :co2 from atmos update_field

:co2 is removed from the default AtmosModelSimulation
update_field. The method definition is also removed for
ClimaAtmosSimulation.

Add atmos get_field for :co2

Add a default get_field for :co2 with AtmosModelSimulation,
and a method definition for ClimaAtmosSimulation. Note that this
returns a scalar.

Add new fields to interfacer_tests

Revert to returning zero when dividing by zero

In get_field(::ClimaAtmosSimulation, ::Val{:diffuse_fraction}
@imreddyTeja imreddyTeja force-pushed the tr/add-get_fields-Atmos branch from 11e4d33 to dd322ff Compare February 28, 2025 17:04
Comment on lines 136 to 145
| Coupler name | Description | Units |
|-------------------|-------------|-------|
| `air_pressure` | boundary air pressure | Pa |
| `air_temperature` | boundary air temperature | K |
| `cos_zenith_angle` | cosine of the zenith angle | |
| `co2` | global mean co2 | ppm |
| `diffuse_fraction` | fraction of downwards shortwave flux that is direct | |
| `humidity` | boundary humidity | kg kg^-1 |
| `LW_d` | downwards longwave flux | W m^-2 |
| `SW_d` | downwards shortwave flux | W m^-2 |
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are these descriptions accurate? Do the pressure and temperature values need air_ prepended to them?

Copy link
Member

Choose a reason for hiding this comment

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

These look good! Prepending air_ is a good idea to distinguish from surface_. Instead of "boundary air pressure/temp/humidity", I would write "air pressure/temp/humidity at the bottom of the atmosphere", to avoid any confusion between the boundary layer of the atmosphere vs boundary surface

@imreddyTeja imreddyTeja force-pushed the tr/add-get_fields-Atmos branch from dd322ff to f20ed1c Compare February 28, 2025 17:43
Add them to the the generic get_field for
AtmosModelSimulations and specific methods
for ClimaAtmosSimulations
It is refered to as `cos_zenith` by atmos and
`cos\thetas` by land. This unifies it with one of
the models.
[skip ci]
@imreddyTeja imreddyTeja force-pushed the tr/add-get_fields-Atmos branch from 9caf01b to 0077d3c Compare February 28, 2025 21:55
CC.Fields.array2field(sim.integrator.p.radiation.rrtmgp_model.face_lw_flux_dn, axes(sim.integrator.u.f)),
CC.Utilities.half,
)
Interfacer.get_field(sim::ClimaAtmosSimulation, ::Val{:humidity}) =
Copy link
Member

Choose a reason for hiding this comment

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

I would call it specific_humidity to be more accurate, but up to you.


| Coupler name | Description | Units |
|-------------------|-------------|-------|
| `air_pressure` | air pressure at the bottom of the atmosphere | Pa |
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
| `air_pressure` | air pressure at the bottom of the atmosphere | Pa |
| `air_pressure` | air pressure at the bottom cell center of the atmosphere | Pa |

(and same for other bottom variables)

Copy link
Member

@juliasloan25 juliasloan25 left a comment

Choose a reason for hiding this comment

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

I just had one comment about throwing errors if the get_fields aren't extended, but this looks good other than that!

@@ -155,12 +155,20 @@ an atmosphere component model.
get_field(
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should error if these get_fields aren't implemented - e.g. if we want to couple a simpler/different atmosphere with the bucket, it doesn't need to extend all these methods required only for the full land model. I was going to suggest that we could give warnings if these aren't extended, but that will print a lot of warnings, so maybe the best thing to do is just remove these fields from here and expect users to read what's required to extend from the documentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought this would only error if the get_field is actually called for that value. So if we used some simple atmosphere with the bucket, it would not need to extend get_field for all the methods listed here, because get_field(::SomeSimpleAtmos, ::Val{:cos_zenith}) would never be called. Is that correct?

I think it might still make sense to split the get_field(::AtmosModelSimulation) default error into what is required for coupling with all land models, and just what is required for coupling with ClimaLand.

@imreddyTeja imreddyTeja force-pushed the tr/add-get_fields-Atmos branch from aee4e44 to c8329ff Compare March 5, 2025 17:39
@imreddyTeja imreddyTeja enabled auto-merge (squash) March 5, 2025 17:40
@imreddyTeja imreddyTeja merged commit a62d04e into main Mar 5, 2025
11 checks passed
@imreddyTeja imreddyTeja deleted the tr/add-get_fields-Atmos branch March 5, 2025 18:59
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.

AtmosSimulation changes needed to couple with full land
4 participants