1
1
# -*- coding: utf-8 -*-
2
2
import numpy as np
3
3
4
- from ....utils .operators import create_convolution_kernels , apply_convolution_kernel , apply_u_kernel_convolution , apply_v_kernel_convolution_3d
5
- from ....utils .slices import get_inner_slice
4
+ from ....utils .operators import create_convolution_kernels , apply_directional_convolution
5
+ from ....utils .slices import get_inner_slice , get_interface_indices , get_last_dim_inner_slice
6
6
7
7
def recompute_advective_fluxes (flux , Sol , ** kwargs ):
8
- """Recompute the advective fluxes at the cell interfaces."""
8
+ """Recompute the advective fluxes at the cell interfaces.
9
+
10
+ Parameters
11
+ ----------
12
+ flux : list
13
+ List of flux objects for each direction
14
+ Sol : object
15
+ Solution object containing rho, rhoY, rhou, rhov, rhow fields
16
+ **kwargs
17
+ Optional pre-computed velocity components ('u', 'v', 'w')
18
+ """
9
19
ndim = Sol .rho .ndim
10
20
inner_idx = get_inner_slice (ndim )
11
21
kernels = create_convolution_kernels (ndim )
12
22
13
- # Handle 3D w-component first
14
- if ndim == 3 :
15
- rhoYw = Sol .rhoY * Sol .rhow / Sol .rho
16
- flux [2 ].rhoY [inner_idx ] = apply_convolution_kernel (rhoYw , kernels ['w' ])
23
+ # Define the component order and corresponding flux indices
24
+ components = ['u' , 'v' ] if ndim == 2 else ['u' , 'v' , 'w' ]
25
+ rho_components = ['rhou' , 'rhov' ] if ndim == 2 else ['rhou' , 'rhov' , 'rhow' ]
17
26
18
- # u-component (all dimensions)
19
- rhoYu = kwargs .get ("u" , Sol .rhoY * Sol .rhou / Sol .rho )
20
- flux [0 ].rhoY [inner_idx ] = apply_u_kernel_convolution (rhoYu , kernels ['u' ])
21
-
22
- # v-component (all dimensions)
23
- rhoYv = kwargs .get ("v" , Sol .rhoY * Sol .rhov / Sol .rho )
24
- if ndim == 2 :
25
- flux [1 ].rhoY [inner_idx ] = apply_convolution_kernel (rhoYv , kernels ['v' ])
26
- elif ndim == 3 :
27
- flux [1 ].rhoY [inner_idx ] = apply_v_kernel_convolution_3d (rhoYv , kernels ['v' ])
28
-
27
+ for i , (comp , rho_comp ) in enumerate (zip (components , rho_components )):
28
+ # Use provided velocity or compute from momentum
29
+ if comp in kwargs :
30
+ rhoY_vel = kwargs [comp ]
31
+ else :
32
+ momentum = getattr (Sol , rho_comp )
33
+ rhoY_vel = Sol .rhoY * momentum / Sol .rho
34
+
35
+ # Apply directional convolution
36
+ flux [i ].rhoY [inner_idx ] = apply_directional_convolution (
37
+ rhoY_vel , kernels [comp ], comp , ndim
38
+ )
29
39
30
- def hll_solver (flux , Lefts , Rights , Sol , lmbda , ud , th ):
40
+ def hll_solver (mem , flux , Lefts , Rights ):
31
41
"""
32
42
HLL solver for the Riemann problem. Chooses the advected quantities from `Lefts` or `Rights` based on the direction given by `flux`.
33
43
34
- Parameters
35
- ----------
36
- flux : :py:class:`management.variable.States`
37
- Data container for fluxes.
38
- Lefts : :py:class:`management.variable.States`
39
- Container for the quantities on the left of the cell interfaces.
40
- Rights : :py:class:`management.variable.States`
41
- Container for the quantities on the right of the cell interfaces.
42
- Sol : :py:class:`management.variable.Vars`
43
- Solution data container.
44
- lmbda : float
45
- :math:`\\ frac{dt}{dx}`, where :math:`dx` is the grid-size in the direction of the substep.
46
- ud : :py:class:`inputs.user_data.UserDataInit`
47
- Class container for the initial condition.
48
- th : :py:class:`physics.gas_dynamics.thermodynamic.init`
49
- Class container for the thermodynamical constants.
50
-
51
44
Returns
52
45
-------
53
46
:py:class:`management.variable.States`
54
47
`flux` data container with the solution of the Riemann problem.
48
+
55
49
"""
56
- # flux: index 1 to end = Left[inner_idx]: index 0 to -1 = Right[inner_idx]: index 1 to end
50
+ def _compute_flux_component (flux_attr , state_attr = None , state_value = 1.0 ):
51
+ """Helper function to compute a single flux component."""
52
+ left_weight = upl [left_idx ] / Lefts .Y [left_idx ]
53
+ right_weight = upr [right_idx ] / Rights .Y [right_idx ]
54
+
55
+ if state_attr is not None :
56
+ left_val = getattr (Lefts , state_attr )[left_idx ]
57
+ right_val = getattr (Rights , state_attr )[right_idx ]
58
+ else :
59
+ left_val = right_val = state_value
60
+
61
+ getattr (flux , flux_attr )[remove_cols_idx ] = flux .rhoY [remove_cols_idx ] * (
62
+ left_weight * left_val + right_weight * right_val
63
+ )
57
64
58
- ndim = Sol .rho .ndim
59
- left_idx , right_idx , remove_cols_idx = (
60
- [slice (None )] * ndim ,
61
- [slice (None )] * ndim ,
62
- [slice (None )] * ndim ,
63
- )
65
+ ndim = mem .sol .rho .ndim
66
+ left_idx , right_idx , _ = get_interface_indices (ndim )
67
+ remove_cols_idx = get_last_dim_inner_slice (ndim )
64
68
65
- remove_cols_idx [- 1 ] = slice (1 , - 1 )
66
- left_idx [- 1 ] = slice (0 , - 1 )
67
- right_idx [- 1 ] = slice (1 , None )
68
-
69
- left_idx , right_idx , remove_cols_idx = (
70
- tuple (left_idx ),
71
- tuple (right_idx ),
72
- tuple (remove_cols_idx ),
73
- )
74
-
75
- Lefts .primitives (th )
76
- Rights .primitives (th )
69
+ # Compute primitive variables
70
+ Lefts .primitives (mem .th )
71
+ Rights .primitives (mem .th )
77
72
73
+ # Compute upwind weights
78
74
upwind = 0.5 * (1.0 + np .sign (flux .rhoY ))
79
75
upl = upwind [right_idx ]
80
76
upr = 1.0 - upwind [left_idx ]
81
77
82
- flux .rhou [remove_cols_idx ] = flux .rhoY [remove_cols_idx ] * (
83
- upl [left_idx ] / Lefts .Y [left_idx ] * Lefts .u [left_idx ]
84
- + upr [right_idx ] / Rights .Y [right_idx ] * Rights .u [right_idx ]
85
- )
86
- flux .rho [remove_cols_idx ] = flux .rhoY [remove_cols_idx ] * (
87
- upl [left_idx ] / Lefts .Y [left_idx ] * 1.0
88
- + upr [right_idx ] / Rights .Y [right_idx ] * 1.0
89
- )
90
-
91
- flux .rhov [remove_cols_idx ] = flux .rhoY [remove_cols_idx ] * (
92
- upl [left_idx ] / Lefts .Y [left_idx ] * Lefts .v [left_idx ]
93
- + upr [right_idx ] / Rights .Y [right_idx ] * Rights .v [right_idx ]
94
- )
95
- flux .rhow [remove_cols_idx ] = flux .rhoY [remove_cols_idx ] * (
96
- upl [left_idx ] / Lefts .Y [left_idx ] * Lefts .w [left_idx ]
97
- + upr [right_idx ] / Rights .Y [right_idx ] * Rights .w [right_idx ]
98
- )
99
- flux .rhoX [remove_cols_idx ] = flux .rhoY [remove_cols_idx ] * (
100
- upl [left_idx ] / Lefts .Y [left_idx ] * Lefts .X [left_idx ]
101
- + upr [right_idx ] / Rights .Y [right_idx ] * Rights .X [right_idx ]
102
- )
78
+ # Compute all flux components
79
+ _compute_flux_component ('rhou' , 'u' )
80
+ _compute_flux_component ('rho' ) # Uses default state_value=1.0
81
+ _compute_flux_component ('rhov' , 'v' )
82
+ _compute_flux_component ('rhow' , 'w' )
83
+ _compute_flux_component ('rhoX' , 'X' )
103
84
104
- return flux
85
+ return flux
0 commit comments