11import numpy as np
22from numba import njit
33
4+ import pyro .mesh .array_indexer as ai
5+ from pyro .util import msg
6+
47
58@njit (cache = True )
69def riemann_cgf (idir , ng ,
@@ -56,12 +59,14 @@ def riemann_cgf(idir, ng,
5659 Returns
5760 -------
5861 out : ndarray
59- Conserved flux
62+ Conserved states.
6063 """
6164
65+ # pylint: disable=unused-variable
66+
6267 qx , qy , nvar = U_l .shape
6368
64- F = np .zeros ((qx , qy , nvar ))
69+ U_out = np .zeros ((qx , qy , nvar ))
6570
6671 smallc = 1.e-10
6772 smallrho = 1.e-10
@@ -286,24 +291,23 @@ def riemann_cgf(idir, ng,
286291 if j == jhi + 1 and upper_solid == 1 :
287292 un_state = 0.0
288293
289- # compute the fluxes
290- F [i , j , idens ] = rho_state * un_state
294+ # update conserved state
295+ U_out [i , j , idens ] = rho_state
291296
292297 if idir == 1 :
293- F [i , j , ixmom ] = rho_state * un_state ** 2 + p_state
294- F [i , j , iymom ] = rho_state * ut_state * un_state
298+ U_out [i , j , ixmom ] = rho_state * un_state
299+ U_out [i , j , iymom ] = rho_state * ut_state
295300 else :
296- F [i , j , ixmom ] = rho_state * ut_state * un_state
297- F [i , j , iymom ] = rho_state * un_state ** 2 + p_state
301+ U_out [i , j , ixmom ] = rho_state * ut_state
302+ U_out [i , j , iymom ] = rho_state * un_state
298303
299- F [i , j , iener ] = rhoe_state * un_state + \
300- 0.5 * rho_state * (un_state ** 2 + ut_state ** 2 ) * un_state + \
301- p_state * un_state
304+ U_out [i , j , iener ] = rhoe_state + \
305+ 0.5 * rho_state * (un_state ** 2 + ut_state ** 2 )
302306
303307 if nspec > 0 :
304- F [i , j , irhoX :irhoX + nspec ] = xn * rho_state * un_state
308+ U_out [i , j , irhoX :irhoX + nspec ] = xn * rho_state
305309
306- return F
310+ return U_out
307311
308312
309313@njit (cache = True )
@@ -623,6 +627,9 @@ def riemann_hllc(idir, ng,
623627 Conserved flux
624628 """
625629
630+ # Only Cartesian2d is supported in HLLC
631+ coord_type = 0
632+
626633 qx , qy , nvar = U_l .shape
627634
628635 F = np .zeros ((qx , qy , nvar ))
@@ -781,7 +788,8 @@ def riemann_hllc(idir, ng,
781788 # R region
782789 U_state [:] = U_r [i , j , :]
783790
784- F [i , j , :] = consFlux (idir , gamma , idens , ixmom , iymom , iener , irhoX , nspec ,
791+ F [i , j , :] = consFlux (idir , coord_type , gamma ,
792+ idens , ixmom , iymom , iener , irhoX , nspec ,
785793 U_state )
786794
787795 elif S_c <= 0.0 < S_r :
@@ -806,7 +814,8 @@ def riemann_hllc(idir, ng,
806814 U_r [i , j , irhoX :irhoX + nspec ] / rho_r
807815
808816 # find the flux on the right interface
809- F [i , j , :] = consFlux (idir , gamma , idens , ixmom , iymom , iener , irhoX , nspec ,
817+ F [i , j , :] = consFlux (idir , coord_type , gamma ,
818+ idens , ixmom , iymom , iener , irhoX , nspec ,
810819 U_r [i , j , :])
811820
812821 # correct the flux
@@ -834,7 +843,8 @@ def riemann_hllc(idir, ng,
834843 U_l [i , j , irhoX :irhoX + nspec ] / rho_l
835844
836845 # find the flux on the left interface
837- F [i , j , :] = consFlux (idir , gamma , idens , ixmom , iymom , iener , irhoX , nspec ,
846+ F [i , j , :] = consFlux (idir , coord_type , gamma ,
847+ idens , ixmom , iymom , iener , irhoX , nspec ,
838848 U_l [i , j , :])
839849
840850 # correct the flux
@@ -844,16 +854,83 @@ def riemann_hllc(idir, ng,
844854 # L region
845855 U_state [:] = U_l [i , j , :]
846856
847- F [i , j , :] = consFlux (idir , gamma , idens , ixmom , iymom , iener , irhoX , nspec ,
857+ F [i , j , :] = consFlux (idir , coord_type , gamma ,
858+ idens , ixmom , iymom , iener , irhoX , nspec ,
848859 U_state )
849860
850861 # we should deal with solid boundaries somehow here
851862
852863 return F
853864
854865
866+ def riemann_flux (idir , U_l , U_r , my_data , rp , ivars ,
867+ lower_solid , upper_solid , tc ):
868+ """
869+ This is the general interface that constructs the unsplit fluxes through
870+ the x and y interfaces using the left and right conserved states by
871+ using the riemann solver.
872+
873+ Parameters
874+ ----------
875+ U_l, U_r: ndarray, ndarray
876+ Conserved states in the left and right interface
877+ my_data : CellCenterData2d object
878+ The data object containing the grid and advective scalar that
879+ we are advecting.
880+ rp : RuntimeParameters object
881+ The runtime parameters for the simulation
882+ ivars : Variables object
883+ The Variables object that tells us which indices refer to which
884+ variables
885+ lower_solid, upper_solid : int
886+ Are we at lower or upper solid boundaries?
887+ tc : TimerCollection object
888+ The timers we are using to profile
889+
890+ Returns
891+ -------
892+ out : ndarray, ndarray
893+ Fluxes in x and y direction
894+ """
895+
896+ tm_riem = tc .timer ("riemann" )
897+ tm_riem .begin ()
898+
899+ myg = my_data .grid
900+
901+ riemann_method = rp .get_param ("compressible.riemann" )
902+ gamma = rp .get_param ("eos.gamma" )
903+
904+ riemann_solvers = {"HLLC" : riemann_hllc , "CGF" : riemann_cgf }
905+
906+ if riemann_method not in riemann_solvers :
907+ msg .fail ("ERROR: Riemann solver undefined" )
908+
909+ riemannFunc = riemann_solvers [riemann_method ]
910+
911+ _f = riemannFunc (idir , myg .ng ,
912+ ivars .idens , ivars .ixmom , ivars .iymom ,
913+ ivars .iener , ivars .irhox , ivars .naux ,
914+ lower_solid , upper_solid ,
915+ gamma , U_l , U_r )
916+
917+ # If riemann_method is not HLLC, then it outputs interface conserved states
918+ if riemann_method != "HLLC" :
919+ _f = consFlux (idir , myg .coord_type , gamma ,
920+ ivars .idens , ivars .ixmom , ivars .iymom ,
921+ ivars .iener , ivars .irhox , ivars .naux ,
922+ _f )
923+
924+ F = ai .ArrayIndexer (d = _f , grid = myg )
925+ tm_riem .end ()
926+
927+ return F
928+
929+
855930@njit (cache = True )
856- def consFlux (idir , gamma , idens , ixmom , iymom , iener , irhoX , nspec , U_state ):
931+ def consFlux (idir , coord_type , gamma ,
932+ idens , ixmom , iymom , iener , irhoX , nspec ,
933+ U_state ):
857934 r"""
858935 Calculate the conservative flux.
859936
@@ -879,27 +956,37 @@ def consFlux(idir, gamma, idens, ixmom, iymom, iener, irhoX, nspec, U_state):
879956
880957 F = np .zeros_like (U_state )
881958
882- u = U_state [ixmom ] / U_state [idens ]
883- v = U_state [iymom ] / U_state [idens ]
959+ u = U_state [..., ixmom ] / U_state [..., idens ]
960+ v = U_state [..., iymom ] / U_state [..., idens ]
884961
885- p = (U_state [iener ] - 0.5 * U_state [idens ] * (u * u + v * v )) * (gamma - 1.0 )
962+ p = (U_state [..., iener ] - 0.5 * U_state [..., idens ] * (u * u + v * v )) * (gamma - 1.0 )
886963
887964 if idir == 1 :
888- F [idens ] = U_state [idens ] * u
889- F [ixmom ] = U_state [ixmom ] * u + p
890- F [iymom ] = U_state [iymom ] * u
891- F [iener ] = (U_state [iener ] + p ) * u
965+ F [..., idens ] = U_state [..., idens ] * u
966+ F [..., ixmom ] = U_state [..., ixmom ] * u
967+
968+ # if Cartesian2d, then add pressure to xmom flux
969+ if coord_type == 0 :
970+ F [..., ixmom ] += p
971+
972+ F [..., iymom ] = U_state [..., iymom ] * u
973+ F [..., iener ] = (U_state [..., iener ] + p ) * u
892974
893975 if nspec > 0 :
894- F [irhoX :irhoX + nspec ] = U_state [irhoX :irhoX + nspec ] * u
976+ F [..., irhoX :irhoX + nspec ] = U_state [..., irhoX :irhoX + nspec ] * u
895977
896978 else :
897- F [idens ] = U_state [idens ] * v
898- F [ixmom ] = U_state [ixmom ] * v
899- F [iymom ] = U_state [iymom ] * v + p
900- F [iener ] = (U_state [iener ] + p ) * v
979+ F [..., idens ] = U_state [..., idens ] * v
980+ F [..., ixmom ] = U_state [..., ixmom ] * v
981+ F [..., iymom ] = U_state [..., iymom ] * v
982+
983+ # if Cartesian2d, then add pressure to ymom flux
984+ if coord_type == 0 :
985+ F [..., iymom ] += p
986+
987+ F [..., iener ] = (U_state [..., iener ] + p ) * v
901988
902989 if nspec > 0 :
903- F [irhoX :irhoX + nspec ] = U_state [irhoX :irhoX + nspec ] * v
990+ F [..., irhoX :irhoX + nspec ] = U_state [..., irhoX :irhoX + nspec ] * v
904991
905992 return F
0 commit comments