Skip to content

Add source term in hydro solver#358

Open
ChunYen-Chen wants to merge 30 commits intogamer-project:mainfrom
ChunYen-Chen:add_source_term
Open

Add source term in hydro solver#358
ChunYen-Chen wants to merge 30 commits intogamer-project:mainfrom
ChunYen-Chen:add_source_term

Conversation

@ChunYen-Chen
Copy link
Copy Markdown
Collaborator

This PR contains a simple interface that allows users to add their source term in hydro solver.

Supports

  • Scheme: MHM and MHM_RP
  • With and without MHD

@ChunYen-Chen ChunYen-Chen added enhancement hydro Hydrodynamics mhd Magnetohydrodynamics labels Oct 16, 2024
@hyschive hyschive self-requested a review December 21, 2024 07:09
@hyschive hyschive self-assigned this Dec 21, 2024
Copy link
Copy Markdown
Member

@technic960183 technic960183 left a comment

Choose a reason for hiding this comment

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

Only one doc related issue and compile time warning because the interface is not used by any module for now.

Tested Combination

--flu_scheme=MHM_RP --mhd=false --gpu=false
--flu_scheme=MHM --mhd=false --gpu=false
--flu_scheme=MHM_RP --mhd=false --gpu=true
--flu_scheme=MHM --mhd=false --gpu=true
(Produce compile time warnings. e.g., Model_Hydro/GPU_Hydro/CUFLU_Shared_AddSourceTerm.cu(56): warning #177-D: variable "TDir1" was declared but never referenced

--flu_scheme=MHM_RP --mhd=true --gpu=false
--flu_scheme=MHM --mhd=true --gpu=false
--flu_scheme=MHM_RP --mhd=true --gpu=true
(Produce compile time warnings declared but never referenced)
--flu_scheme=MHM --mhd=true --gpu=true
(Produce compile time warnings declared but never referenced)

Comment thread src/Model_Hydro/CPU_Hydro/CPU_FluidSolver_MHM.cpp
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[BUG] @ChunYen-Chen Do I understand correctly that Hydro_ConFC2PriCC_MHM() must be called even when disabling MHD in order to set g_PriVar_Half[] for Hydro_AddSourceTerm_CCVar_FullStep()?

If this is indeed a bug, I assume it indicates that you haven't tested the case with MHM on and MHD off. Please test it.

Copy link
Copy Markdown
Contributor

@hyschive hyschive left a comment

Choose a reason for hiding this comment

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

@ChunYen-Chen @technic960183 Comments added. There seem to be a few bugs related to MHM w/o MHD, as well as in some example codes. Please double-check and run additional tests if needed.

Comment thread src/Model_Hydro/CPU_Hydro/CPU_Shared_AddSourceTerm.cpp Outdated
Comment on lines +359 to +364
// real div_V[3];
// for (int d=0; d<3; d++)
// {
// div_V[d] = (real)0.5 * ( g_PriVar_Half[DENS+d][idx_hf + didx_hf[d]] -
// g_PriVar_Half[DENS+d][idx_hf - didx_hf[d]] );
// } // for (int d=0; d<3; d++)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just a question. I don't think that, in general, it will yield identical results as the original CR implementation here, since here it computes div(V) from velocity directly instead of mass flux over density. Do you agree? You may want to add a comment to clarify that.

Comment thread src/Model_Hydro/CPU_Hydro/CPU_Shared_AddSourceTerm.cpp Outdated
Comment thread src/Model_Hydro/CPU_Hydro/CPU_Shared_AddSourceTerm.cpp Outdated
Comment on lines +379 to +383
// Description : Add source term on the face-centered magnetic field at full-step update
//
// Note : 1. Shared by both MHM and MHM_RP
// 2. Invoked by CPU/CUFLU_FluidSolver_MHM()
// 3. Must be used after MHD_UpdateMagnetic()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do I understand correctly that one should also update the total energy, which also includes B^2/2, via Hydro_AddSourceTerm_CCVar_FullStep() to treat the B field consistently? If you agree, add a corresponding comment here.

Comment thread src/Model_Hydro/CPU_Hydro/CPU_Shared_AddSourceTerm.cpp Outdated
Comment thread src/Model_Hydro/CPU_Hydro/CPU_Shared_AddSourceTerm.cpp Outdated

const real dt_dh2 = (real)0.5 * dt / dh;
const int N_HF_VAR_P1 = N_HF_VAR + 1;
const int didx_in[3] = { 1, FLU_NXT, SQR(FLU_NXT) };
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about renaming this variable to better reflect the fact that it's for accessing g_ConVar_In[]?

Comment thread src/Model_Hydro/CPU_Hydro/CPU_Shared_AddSourceTerm.cpp Outdated
Comment thread src/Model_Hydro/CPU_Hydro/CPU_Shared_AddSourceTerm.cpp Outdated
ChunYen-Chen and others added 3 commits July 28, 2025 13:52
@hyschive hyschive mentioned this pull request Nov 7, 2025
6 tasks
@hyschive
Copy link
Copy Markdown
Contributor

@ChunYen-Chen Please let me know when this PR is ready for a final review. Thanks!

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

Labels

enhancement hydro Hydrodynamics mhd Magnetohydrodynamics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants