@@ -285,9 +285,6 @@ def apply_source_terms(U_xl, U_xr, U_yl, U_yr,
285285 tm_source .begin ()
286286
287287 myg = my_data .grid
288-
289- pres = my_data .get_var ("pressure" )
290-
291288 dens_src = my_aux .get_var ("dens_src" )
292289 xmom_src = my_aux .get_var ("xmom_src" )
293290 ymom_src = my_aux .get_var ("ymom_src" )
@@ -301,11 +298,6 @@ def apply_source_terms(U_xl, U_xr, U_yl, U_yr,
301298 ymom_src [:, :] = U_src [:, :, ivars .iymom ]
302299 E_src [:, :] = U_src [:, :, ivars .iener ]
303300
304- # apply non-conservative pressure gradient
305- if myg .coord_type == 1 :
306- xmom_src .v ()[:, :] += - (pres .ip (1 ) - pres .v ()) / myg .Lx .v ()
307- ymom_src .v ()[:, :] += - (pres .jp (1 ) - pres .v ()) / myg .Ly .v ()
308-
309301 my_aux .fill_BC ("dens_src" )
310302 my_aux .fill_BC ("xmom_src" )
311303 my_aux .fill_BC ("ymom_src" )
@@ -410,25 +402,49 @@ def apply_transverse_flux(U_xl, U_xr, U_yl, U_yr,
410402 with source terms added.
411403 """
412404
405+ myg = my_data .grid
406+
413407 # Use Riemann Solver to get interface flux using the left and right states
414408
415- F_x = riemann .riemann_flux (1 , U_xl , U_xr ,
416- my_data , rp , ivars ,
417- solid .xl , solid .xr , tc )
409+ if myg .coord_type == 1 :
410+ # We need pressure from interface state for transverse update for
411+ # SphericalPolar geometry. So we need interface conserved states.
412+ F_x , U_x = riemann .riemann_flux (1 , U_xl , U_xr ,
413+ my_data , rp , ivars ,
414+ solid .xl , solid .xr , tc ,
415+ return_cons = True )
418416
419- F_y = riemann .riemann_flux (2 , U_yl , U_yr ,
420- my_data , rp , ivars ,
421- solid .yl , solid .yr , tc )
417+ F_y , U_y = riemann .riemann_flux (2 , U_yl , U_yr ,
418+ my_data , rp , ivars ,
419+ solid .yl , solid .yr , tc ,
420+ return_cons = True )
422421
423- # Now we update the conserved states using the transverse fluxes.
422+ gamma = rp . get_param ( "eos.gamma" )
424423
425- myg = my_data .grid
424+ # Find primitive variable since we need pressure in transverse update.
425+ qx = comp .cons_to_prim (U_x , gamma , ivars , myg )
426+ qy = comp .cons_to_prim (U_y , gamma , ivars , myg )
427+
428+ else :
429+ # Directly calculate the interface flux using Riemann Solver
430+ F_x = riemann .riemann_flux (1 , U_xl , U_xr ,
431+ my_data , rp , ivars ,
432+ solid .xl , solid .xr , tc ,
433+ return_cons = False )
434+
435+ F_y = riemann .riemann_flux (2 , U_yl , U_yr ,
436+ my_data , rp , ivars ,
437+ solid .yl , solid .yr , tc ,
438+ return_cons = False )
439+
440+ # Now we update the conserved states using the transverse fluxes.
426441
427442 tm_transverse = tc .timer ("transverse flux addition" )
428443 tm_transverse .begin ()
429444
430445 b = (2 , 1 )
431- hdtV = 0.5 * dt / myg .V
446+ hdt = 0.5 * dt
447+ hdtV = hdt / myg .V
432448
433449 for n in range (ivars .nvar ):
434450
@@ -452,6 +468,25 @@ def apply_transverse_flux(U_xl, U_xr, U_yl, U_yr,
452468 - hdtV .v (buf = b )* (F_x .ip (1 , buf = b , n = n )* myg .Ax .ip (1 , buf = b ) -
453469 F_x .v (buf = b , n = n )* myg .Ax .v (buf = b ))
454470
471+ # apply non-conservative pressure gradient for momentum in spherical geometry
472+ # Note that we should only apply this pressure gradient
473+ # to the momentum corresponding to the transverse direction.
474+ # The momentum in the normal direction already updated pressure during reconstruction.
475+
476+ if myg .coord_type == 1 :
477+
478+ U_xl .v (buf = b , n = ivars .iymom )[:, :] += - hdt * (qy .ip_jp (- 1 , 1 , buf = b , n = ivars .ip ) -
479+ qy .ip (- 1 , buf = b , n = ivars .ip )) / myg .Ly .v (buf = b )
480+
481+ U_xr .v (buf = b , n = ivars .iymom )[:, :] += - hdt * (qy .jp (1 , buf = b , n = ivars .ip ) -
482+ qy .v (buf = b , n = ivars .ip )) / myg .Ly .v (buf = b )
483+
484+ U_yl .v (buf = b , n = ivars .ixmom )[:, :] += - hdt * (qx .ip_jp (1 , - 1 , buf = b , n = ivars .ip ) -
485+ qx .jp (- 1 , buf = b , n = ivars .ip )) / myg .Lx .v (buf = b )
486+
487+ U_yr .v (buf = b , n = ivars .ixmom )[:, :] += - hdt * (qx .ip (1 , buf = b , n = ivars .ip ) -
488+ qx .v (buf = b , n = ivars .ip )) / myg .Lx .v (buf = b )
489+
455490 tm_transverse .end ()
456491
457492 return U_xl , U_xr , U_yl , U_yr
0 commit comments