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

strang splitting does not work? #12

Open
BenWibking opened this issue Jan 11, 2023 · 12 comments
Open

strang splitting does not work? #12

BenWibking opened this issue Jan 11, 2023 · 12 comments

Comments

@BenWibking
Copy link
Contributor

BenWibking commented Jan 11, 2023

It looks like the gravitational potential is hard-coded to be only a function of radius:

const Real g_r = gravitationalField.g_from_r(r);

In general, it should be a function of all of the coordinates. (For my simulations, it should be a function of height.)

@BenWibking BenWibking changed the title gravitational potential is hard-coded to be a function of radius gravitational potential should be an arbitrary function Jan 11, 2023
@pgrete
Copy link
Contributor

pgrete commented Jan 16, 2023

Does it make sense for your usecase to work with GravitationalField gravitationalField or is your is it a (very simple) function?
In the former case, I could imagine to work with if constexpr inside the function to differentiate between different kinds of potentials.
In the latter case, it may even be easiest/cleanest to just add a problem specific, self-contained source function.

@BenWibking
Copy link
Contributor Author

It's a simple function. Should it go in PostStepMeshUserWorkInLoop?

@pgrete
Copy link
Contributor

pgrete commented Jan 16, 2023

I suggest to hook into the Hydro::ProblemSourceUnsplit or Hydro::ProblemSourceFirstOrder function (cf., the turbulence problem generator).
The "unplit" version is called during every stage of the integrator (i..e, the beta_dt should be used for $\Delta t$) whereas the "first order" one is only called once (so the full $\Delta t$ for the entire cycle should be used).

@BenWibking
Copy link
Contributor Author

Is there a Strang-split version of this? Otherwise I'll just use Hydro::ProblemSourceFirstOrder.

@pgrete
Copy link
Contributor

pgrete commented Jan 16, 2023

Is there a Strang-split version of this? Otherwise I'll just use Hydro::ProblemSourceFirstOrder.

Yes, it's called ProblemSourceStrangSplit 😄

Also this applies: https://github.com/parthenon-hpc-lab/athenapk/blob/main/src/hydro/hydro_driver.cpp#L160

@BenWibking
Copy link
Contributor Author

Well, that's convenient. So I need to read from the cons variables and then update both cons and prim?

@BenWibking
Copy link
Contributor Author

What is the reason for this restriction ? Could this be simplified by adding another conserved -> primitive conversion step in the task list?

@pgrete
Copy link
Contributor

pgrete commented Jan 17, 2023

Well, that's convenient. So I need to read from the cons variables and then update both cons and prim?

yes (that's the "safe" option)

What is the reason for this restriction ? Could this be simplified by adding another conserved -> primitive conversion step in the task list?

The current implementation is mostly motivated by performance concerns, which doesn't mean it has to stay that way.
So far the source terms I've been using update the data they were reading, so I could easily update both prim and cons in those source terms without needing to read and write all data again.
For example, for cooling the update to the pressure is trivial based on required calculations in the kernel whereas a separate ConsToPrim would need to read all data (density, momentum, energy, and potentially magnetic fields) again, just to update the pressure variable.

@BenWibking
Copy link
Contributor Author

Ok, that makes sense. I agree about there being a performance cost, but I'd expect it to be very small - have you measured this?

@pgrete
Copy link
Contributor

pgrete commented Jan 17, 2023

Ok, that makes sense. I agree about there being a performance cost, but I'd expect it to be very small - have you measured this?

Yes, (but it also strongly depends on the total amount of physics included).
IIRC it's double digit percent for MHD because that kernel is extremely memory bound as there virtual no compute for cons to prim conversion.

@BenWibking
Copy link
Contributor Author

I am getting some exceptionally weird (wrong) results when using Strang splitting for gravity:

Working version (first order splitting):
parthenon prim final_Slice_x_Velocity3

Bad version (Strang splitting):
parthenon prim final_Slice_x_Velocity3_strang

Do you have any idea what could be going wrong here?

@BenWibking BenWibking changed the title gravitational potential should be an arbitrary function strang splitting does not work? Jan 26, 2023
@pgrete
Copy link
Contributor

pgrete commented Feb 2, 2023

That does indeed look strange.
If you could provide a reproducer (i.e., the code version/commit to use an a sample input file), I'll have a look.

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

No branches or pull requests

2 participants