Peano
Loading...
Searching...
No Matches
MatterBasedDynamicKernel.py
Go to the documentation of this file.
1import sympy
2from sympy import Matrix, symbols
3from sympy.tensor.array import Array, tensorcontraction, tensorproduct
4import numpy as np
5
6import peano4
7import exahype2
8
9
11 '''
12 function to created the relativistic hydrodynamic kernel in the conserved formulation
13 We treat the primitive variables and spacetime variables as auxiliary variables
14
15 Variables labeling:
16 for now the default order of the file is following the FV solvers persepective (thus require adjust data arrangement)
17 if we only have current infrastructure, the order here have to be adjusted. We can have
18 {Q_spacetime, Q_hydro_evo}
19
20 Reconstruction of primitive variables:
21 For RK1 we can naturally insert the reconstruction into the preprocess stage.
22 It becomes tricky when we do higher RK where we need reconstruction for every RK stage
23 (still working but find a better place to insert)
24 The reconstruction function would be (tilde{gamma}_ij, phi, Q_hydro_evo) -> Q_hydro_primitive
25
26 '''
27 hydro_pde= exahype2.symhype.FirstOrderConservativePDEFormulation(
28 unknowns=5, auxiliary_variables=5+51+1, dimensions=3)
29
30 #evolving quantities
31 tildeD = hydro_pde.name_Q_entry(0,"tildeD")
32 tildeS1 = hydro_pde.name_Q_entry(1,"tildeS1")
33 tildeS2 = hydro_pde.name_Q_entry(2,"tildeS2")
34 tildeS3 = hydro_pde.name_Q_entry(3,"tildeS3")
35 tildetau= hydro_pde.name_Q_entry(4,"tildetau")
36
37 #primitive quantities, those should be calculated before the kernel
38 rho0 = hydro_pde.name_auxiliary_variable(0,"rho0")
39 v1 = hydro_pde.name_auxiliary_variable(1,"v1")
40 v2 = hydro_pde.name_auxiliary_variable(2,"v2")
41 v3 = hydro_pde.name_auxiliary_variable(3,"v3")
42 epsilon = hydro_pde.name_auxiliary_variable(4,"epsilon")
43 W = hydro_pde.name_auxiliary_variable(56,"W") #lorentz factor, can be recalculated with the primitives, but receiving it saves computations
44
45 #spacetime quantities
46 tg11 = hydro_pde.name_auxiliary_variable(5,"tg11"); tg12 = hydro_pde.name_auxiliary_variable(6,"tg12")
47 tg13 = hydro_pde.name_auxiliary_variable(7,"tg13"); tg22 = hydro_pde.name_auxiliary_variable(8,"tg22")
48 tg23 = hydro_pde.name_auxiliary_variable(9,"tg23"); tg33 = hydro_pde.name_auxiliary_variable(10,"tg33")
49
50 tA11 = hydro_pde.name_auxiliary_variable(11,"tA11"); tA12 = hydro_pde.name_auxiliary_variable(12,"tA12")
51 tA13 = hydro_pde.name_auxiliary_variable(13,"tA13"); tA22 = hydro_pde.name_auxiliary_variable(14,"tA22")
52 tA23 = hydro_pde.name_auxiliary_variable(15,"tA23"); tA33 = hydro_pde.name_auxiliary_variable(16,"tA33")
53 #notice we do not need \Theta and \hat{\Gamma}^i
54 alpha = hydro_pde.name_auxiliary_variable(17,"alpha")
55 beta1 = hydro_pde.name_auxiliary_variable(18,"beta1")
56 beta2 = hydro_pde.name_auxiliary_variable(19,"beta2")
57 beta3 = hydro_pde.name_auxiliary_variable(20,"beta3")
58
59 A1 = hydro_pde.name_auxiliary_variable(21,"A1")
60 A2 = hydro_pde.name_auxiliary_variable(22,"A2")
61 A3 = hydro_pde.name_auxiliary_variable(23,"A3")
62
63 B11 = hydro_pde.name_auxiliary_variable(24,"B11")
64 B12 = hydro_pde.name_auxiliary_variable(25,"B12")
65 B13 = hydro_pde.name_auxiliary_variable(26,"B13")
66 B21 = hydro_pde.name_auxiliary_variable(27,"B21")
67 B22 = hydro_pde.name_auxiliary_variable(28,"B22")
68 B23 = hydro_pde.name_auxiliary_variable(29,"B23")
69 B31 = hydro_pde.name_auxiliary_variable(30,"B31")
70 B32 = hydro_pde.name_auxiliary_variable(31,"B32")
71 B33 = hydro_pde.name_auxiliary_variable(32,"B33")
72
73 D111 = hydro_pde.name_auxiliary_variable(33,"D111"); D112 = hydro_pde.name_auxiliary_variable(34,"D112"); D113 = hydro_pde.name_auxiliary_variable(35,"D113");
74 D122 = hydro_pde.name_auxiliary_variable(36,"D122"); D123 = hydro_pde.name_auxiliary_variable(37,"D123"); D133 = hydro_pde.name_auxiliary_variable(38,"D133");
75 D211 = hydro_pde.name_auxiliary_variable(39,"D211"); D212 = hydro_pde.name_auxiliary_variable(40,"D212"); D213 = hydro_pde.name_auxiliary_variable(41,"D213");
76 D222 = hydro_pde.name_auxiliary_variable(42,"D222"); D223 = hydro_pde.name_auxiliary_variable(43,"D223"); D233 = hydro_pde.name_auxiliary_variable(44,"D233");
77 D311 = hydro_pde.name_auxiliary_variable(45,"D311"); D312 = hydro_pde.name_auxiliary_variable(46,"D312"); D313 = hydro_pde.name_auxiliary_variable(47,"D313");
78 D322 = hydro_pde.name_auxiliary_variable(48,"D322"); D323 = hydro_pde.name_auxiliary_variable(49,"D323"); D333 = hydro_pde.name_auxiliary_variable(50,"D333");
79
80 K = hydro_pde.name_auxiliary_variable(51,"K")
81 phi = hydro_pde.name_auxiliary_variable(52,"phi")
82 P1 = hydro_pde.name_auxiliary_variable(53,"P1")
83 P2 = hydro_pde.name_auxiliary_variable(54,"P2")
84 P3 = hydro_pde.name_auxiliary_variable(55,"P3")
85
86 #construct tensors/vectors
87 tildeS = Array([tildeS1, tildeS2, tildeS3])
88 v = Array([v1, v2, v3])
89 tg = Array([[tg11, tg12, tg13],
90 [tg12, tg22, tg23],
91 [tg13, tg23, tg33]])
92 tA = Array([[tA11, tA12, tA13],
93 [tA12, tA22, tA23],
94 [tA13, tA23, tA33]])
95 beta = Array([beta1, beta2, beta3])
96 A = Array([A1, A2, A3])
97 B = Array([[B11, B12, B13],
98 [B21, B22, B23],
99 [B31, B32, B33]])
100 Dijk = Array([[[D111, D112, D113], [D112, D122, D123], [D113, D123, D133]],
101 [[D211, D212, D213], [D212, D222, D223], [D213, D223, D233]],
102 [[D311, D312, D313], [D312, D322, D323], [D313, D323, D333]]])
103 P = Array([P1, P2, P3])
104
105 #main calculation
106 Gamma_index = 4/3
107
108 g = tg / (phi*phi) #\gamma_ij
109 detg = Matrix(g).det()
110 g_up = Array(Matrix(g).inv().tolist()) #\gamma^ij
111 tg_up = Array(Matrix(tg).inv().tolist()) #\tilde{\gamma}^ij
112
113 p = (Gamma_index-1)*rho0*epsilon #assuming \Gamma-1 law, the value of \Gamma depends on physics scenarios
114 h = 1+epsilon+p/rho0 #specific enthalpy
115 V = alpha*tensorcontraction(tensorproduct(g_up, v), (1,2)) - beta #transport velocity, V^i=\alpha \gamma^ij v_j - \beta^i
116 v_up = tensorcontraction(tensorproduct(g_up, v), (1,2)) #v^i
117 D = tildeD/detg #unscaled density
118 tau = tildetau/detg #unscaled energy variables
119
120 #source components in Tij
121 E = rho0*h*W**2 - p
122 S = rho0*h*W**2*v #S_j
123 Sij = tensorproduct(S, S)/(rho0*h*W**2) + p*g #S_ij
124
125 Kij = tA/(phi*phi) + (1/3)*K*g #K_ij
126 Kij_up = tensorcontraction(tensorproduct(g_up, g_up, Kij), (1,4), (3,5)) #K^ij
127 dg_up = 2*phi*tensorproduct(P, tg_up)-2*phi**2*tensorcontraction(tensorproduct(tg_up, tg_up, Dijk), (1, 5), (3, 6)) #\partial_i \gamma^jk
128
129 # -EA_i + S_k B_i^k -0.5 \aplha S_jk \partial_i \gamma^jk
130 S_source = -E*A + tensorcontraction(tensorproduct(S, B), (0,2)) - 0.5*alpha*tensorcontraction(tensorproduct(Sij, dg_up), (0, 3), (1, 4))
131
132 # \alpha S_ij K^ij - \gamma^ij S_j A_i
133 tau_source = alpha*tensorcontraction(tensorproduct(Sij, Kij_up), (0, 2), (1, 3)) - tensorcontraction(tensorproduct(g_up, S, A), (0, 3), (1, 2))
134
135 # Flux [unknowns, dimensions]
136 for i in range(3):
137 hydro_pde.F[0,i] = detg*D*V[i]
138 hydro_pde.F[4,i] = tau*V[i] + alpha*p*v_up[i]
139
140 hydro_pde.F[1,0] = detg *(S[0]*V[0]+alpha*p)
141 hydro_pde.F[1,1] = detg * S[0]*V[1]
142 hydro_pde.F[1,2] = detg * S[0]*V[2]
143 hydro_pde.F[2,0] = detg * S[1]*V[0]
144 hydro_pde.F[2,1] = detg *(S[1]*V[1]+alpha*p)
145 hydro_pde.F[2,2] = detg * S[1]*V[2]
146 hydro_pde.F[3,0] = detg * S[2]*V[0]
147 hydro_pde.F[3,1] = detg * S[2]*V[1]
148 hydro_pde.F[3,2] = detg *(S[2]*V[2]+alpha*p)
149
150 # Source [unknowns]
151 hydro_pde.sources[0] = 0
152 hydro_pde.sources[1] = S_source[0]
153 hydro_pde.sources[2] = S_source[1]
154 hydro_pde.sources[3] = S_source[2]
155 hydro_pde.sources[4] = tau_source
156
157 v_mag_2 = 1 - 1/W**2 # =\gamma_ij v^i v^j
158 c_s_2 = Gamma_index*(Gamma_index-1)*epsilon/(1+Gamma_index*epsilon) #assuming \Gamma-1 law, (c_s)^2, square of sound speed
159 # Eigenvalues [unknowns, dimensions]
160 # only max value matters, so the assignment is not strictly aligned
161 for i in range(3):
162 # \lambda_+
163 hydro_pde.eigenvalues[0, i]= -beta[i]+ alpha/(1-c_s_2*v_mag_2) * ( v[i]*(1-c_s_2) + (c_s_2*(1-v_mag_2)*(g[i][i]*(1-c_s_2*v_mag_2)-v_up[i]*v_up[i]*(1-c_s_2)))**0.5 )
164 # \lambda_-
165 hydro_pde.eigenvalues[4, i]= -beta[i]+ alpha/(1-c_s_2*v_mag_2) * ( v[i]*(1-c_s_2) - (c_s_2*(1-v_mag_2)*(g[i][i]*(1-c_s_2*v_mag_2)-v_up[i]*v_up[i]*(1-c_s_2)))**0.5 )
166
167 hydro_pde.eigenvalues[1, i]= V[i]
168 hydro_pde.eigenvalues[2, i]= V[i]
169 hydro_pde.eigenvalues[3, i]= V[i]
170
171
172 # no initial condition and boundary condition yet
173
174 print(hydro_pde.implementation_of_flux())
175
176 return hydro_pde
177
178
180 #TODO
181 return None
182
183
184
prepare_hydrodynamic_kernel()
function to created the relativistic hydrodynamic kernel in the conserved formulation We treat the pr...