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

Add finite depth functionality to SurfaceQG #375

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

Conversation

mncrowe
Copy link
Contributor

@mncrowe mncrowe commented Jan 21, 2025

Addresses issue 374

@mncrowe
Copy link
Contributor Author

mncrowe commented Jan 22, 2025

I've added multiple dispatch to replace the if-else logic. CI failing for documentation, not sure why.

@navidcy navidcy linked an issue Jan 23, 2025 that may be closed by this pull request
@navidcy navidcy self-requested a review January 23, 2025 00:38
Copy link
Member

@navidcy navidcy left a comment

Choose a reason for hiding this comment

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

Suggestion:

At the moment there is no variable for stream function. If we introduce ψh in Vars then we can call streamfunctionfromb! within calcN_advection!. This way, by having multiple dispatch on streamfunctionfromb! we'll sort out the finite/infinite depth cases without having to almost-duplicate calcN_advection!. What do you think?

@navidcy
Copy link
Member

navidcy commented Jan 24, 2025

@mncrowe I tried to simplify. What do you think?

@@ -4,6 +4,7 @@ export
Problem,
set_b!,
updatevars!,
streamfunctionfromb!,
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 end this is not used, right? Delete?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not used. However, it might still be useful as the streamfunction is not available in vars and often it's very useful to know. Removing it would be ok as we have the inversion relation saved, though it's perhaps more user-friendly to have a function that calculates it rather than expecting users to do the Fourier transforms themselves?

Copy link
Member

Choose a reason for hiding this comment

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

Note that "exporting" is really about choosing a stable user-API (not necessarily defining all functions that users need). Its ok to require users to qualify their names or write using GeophysicalFlows: streamfunctionfromb!. Not expressing an opinion about exporting or not here, just want to make sure that the goals are clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this reply was intended to answer this and the question below in one go so I didn't separate removing the function and removing the export. I'll leave the choice of exporting vs not to you but I think including it (or perhaps a non-! version) would be useful.

Copy link
Member

Choose a reason for hiding this comment

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

ah I was confused about @navidcy's suggestion

Copy link
Member

@navidcy navidcy Jan 24, 2025

Choose a reason for hiding this comment

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

ok, sorry if I created confusion.
I think I understand now the point of the method -- thanks @mncrowe

I agree with @glwagner, we can include the method (if we also test it) but we don't necessarily need to export it.

src/surfaceqg.jl Outdated
Comment on lines 360 to 370
"""
streamfunctionfromb!(ψ, bh, params, grid)
streamfunctionfromb!(ψ, prob)

Compute the streamfunction `ψ` from the buoyancy `bh` in Fourier space.
(Note that `bh = prob.sol`.)
"""
function streamfunctionfromb!(ψ, bh, params, grid)
ldiv!(ψ, grid.rfftplan, @. params.ψhfrombh * bh)
return nothing
end
Copy link
Member

@navidcy navidcy Jan 24, 2025

Choose a reason for hiding this comment

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

Delete since it's not used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as above

Copy link
Member

Choose a reason for hiding this comment

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

Since the method anyway allocates memory, wouldn't it be simpler if it was something like:

function get_streamfunction(prob)
  ψh = @. prob.params.ψhfrombh * prob.sol
  return irfft(ψh, prob.grid.nx)
end

Copy link
Contributor Author

@mncrowe mncrowe Jan 24, 2025

Choose a reason for hiding this comment

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

Yes, looks good, this is what I was getting at with 'non-! version' above.

Also, is there a reason (other than the !) why rfft and irfft are used in some places and mul! and ldiv! in others?

Copy link
Member

Choose a reason for hiding this comment

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

We use ldiv! and mul! to avoid allocations when already the arrays we’ll put the values in are pre-existing.

@navidcy
Copy link
Member

navidcy commented Jan 24, 2025

This is ready if we add some tests.

Also if you wanna include the new diagnostic perhaps also a test for that?

@mncrowe
Copy link
Contributor Author

mncrowe commented Jan 24, 2025

This is ready if we add some tests.

Also if you wanna include the new diagnostic perhaps also a test for that?

Will add the diagnostic next week and think about some tests for that. A simple way to test the finite depth bit would be to just create a loop on H in (Inf, 1) for those tests where the value of H leads to different behaviour right?

@navidcy navidcy added 🤥 enhancement New feature or request science 🔬 labels Jan 24, 2025
@navidcy
Copy link
Member

navidcy commented Jan 24, 2025

We should include some finite-depth info at the docs module page:

https://github.com/mncrowe/GeophysicalFlows.jl/blob/main/docs/src/modules/surfaceqg.md

@mncrowe
Copy link
Contributor Author

mncrowe commented Jan 29, 2025

We should include some finite-depth info at the docs module page

I agree, I'll type out some stuff when I get a chance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤥 enhancement New feature or request science 🔬
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add finite depth parameter to SQG model (surfaceqg.jl)
3 participants