Skip to content

Add extension to ConservativeRegridding.jl #4396

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

Open
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

glwagner
Copy link
Member

This PR adds an extension to ConservativeRegridding which ultimately should allow us to "regrid" fields conservatively between grids with different resolutions or alignments. "Conservative" means that regridding conserves the mean value of the field. This should be useful for nesting as well as coupling.

@glwagner
Copy link
Member Author

This depends on JuliaGeo/ConservativeRegridding.jl#7

@milankl @simone-silvestri

Comment on lines 86 to 90
src_cells = compute_cell_matrix(src_field)
dst_cells = compute_cell_matrix(dst_field)

src_polygons = GI.Polygon.(GI.LinearRing.(eachcol(src_cells))) .|> GO.fix
dst_polygons = GI.Polygon.(GI.LinearRing.(eachcol(dst_cells))) .|> GO.fix
Copy link
Collaborator

Choose a reason for hiding this comment

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

I should only be necessary to define a new method for ConservativeRegridding.get_vertices I think!

Copy link
Collaborator

Choose a reason for hiding this comment

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

But cell_matrix is a matrix, so you don't have to do anything!

Copy link
Member Author

Choose a reason for hiding this comment

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

interesting! I think we may want to exert some control here but not sure. For example, we probably want to interpret user input and throw some specific errors. We also want to support regridding in vertical slices and whatnot. So I believe we will want to extend regrid! for Field? Let's see though.

end

ConservativeRegridding.regrid!(dst_field::Field, regridder::ConservativeRegridding.regridder, src_field::AbstractField) =
regrid!(vec(interior(dst_field)), regridder, vec(interior(src_field)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

this wouldn't work for the 3D cases right? In that case you only want to unravel the horizontal dimensions into a vector

Copy link
Member Author

Choose a reason for hiding this comment

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

That's true, but I think it will be easy to support such a thing in this PR by making a stack of vec(interior(field, :, :, k))

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add a quick dispatch for this case

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.

3 participants