Skip to content

Commit bcef2d6

Browse files
Zachary K. Hardygrmnptr
authored andcommitted
Many changes to many things
In this commit, the recomputeKappa_t function is changed to compute boundary temperatures based on boundary sources. The lagrangian_radiation_corrector class is changed to more closely match the predictor class. The recomputeInternalEnergy function in the corrector class is moved to the fields class. That function now computes the predictor or actual value for internal energy based on the boolean input `predictor.' The same is done for the solve for radiation energy. The solve function is moved to the fields class for consistency. A change that should be implemented is to get rid of the density recomputation in the moveMesh function in geometry. Because this is a field variable it is best to be recomputed alongside the other field variables. A conservation check function is added to the fields class. In this code's current state, conservation is achieved for a few cases: 1) Constant initial conditions in all variables, with E(x, 0) = a T^4 and E(bdry, t) = a T^4. 2) Constant initial conditions in all variables, with E(x, 0) = a T^4 and reflective boundary conditions.
1 parent 1b26d4f commit bcef2d6

File tree

7 files changed

+319
-369
lines changed

7 files changed

+319
-369
lines changed

fields.py

Lines changed: 131 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,25 @@ def __init__(self, rp):
1212
self.u = self.initializeAtEdges(self.input.u)
1313
self.u_p = np.copy(self.u)
1414
self.u_old = np.copy(self.u)
15+
self.u_IC = np.copy(self.u)
1516

1617
# Set left velocity BCs as necessary
17-
if self.input.hydro_bL == 'u':
18-
if self.input.hydro_bL_val == None:
19-
self.u_bL = self.input.u(0)
18+
if self.input.hydro_L == 'u':
19+
if self.input.hydro_L_val == None:
20+
self.u_L = self.input.u(0)
2021
else:
21-
self.u_bL = self.input.hydro_bL_val
22+
self.u_L = self.input.hydro_bL_val
2223
else:
23-
self.u_bL = None
24+
self.u_L = None
2425

2526
# Set right velocity BCs as necessary
26-
if self.input.hydro_bR == 'u':
27-
if self.input.hydro_bR_val == None:
28-
self.u_bR = self.input.u(self.geo.r_half_old[-1])
27+
if self.input.hydro_R == 'u':
28+
if self.input.hydro_R_val == None:
29+
self.u_R = self.input.u(self.geo.r_half_old[-1])
2930
else:
30-
self.u_bR = self.input.hydro_bR_val
31+
self.u_R = self.input.hydro_R_val
3132
else:
32-
self.u_bR = None
33+
self.u_R = None
3334

3435
# Temperature (spatial cell centers)
3536
self.T = self.initializeAtCenters(self.input.T)
@@ -40,38 +41,42 @@ def __init__(self, rp):
4041
self.rho = self.initializeAtCenters(self.input.rho)
4142
self.rho_p = np.copy(self.rho)
4243
self.rho_old = np.copy(self.rho)
44+
self.rho_IC = np.copy(self.rho)
4345

4446
# Pressures (spatial cell centers, IC: Eqs. 22 and 23)
4547
self.P = (self.mat.gamma - 1) * self.mat.C_v * self.T * self.rho
4648
self.P_p = np.copy(self.P)
4749
self.P_old = np.copy(self.P)
4850

4951
# Set pressure BCs as necessary
50-
if self.input.hydro_bL == 'P':
51-
self.P_bL = self.input.hydro_bL_val
52+
if self.input.hydro_L == 'P':
53+
self.P_L = self.input.hydro_L_val
5254
else:
53-
self.P_bL = None
54-
if self.input.hydro_bR == 'P':
55-
self.P_bR = self.input.hydro_bR_val
55+
self.P_L = None
56+
if self.input.hydro_R == 'P':
57+
self.P_R = self.input.hydro_R_val
5658
else:
57-
self.P_bR = None
59+
self.P_R = None
5860

5961
# Internal energies (spatial cell centers)
6062
self.e = self.mat.C_v * self.T_old
6163
self.e_p = np.copy(self.e)
6264
self.e_old = np.copy(self.e)
65+
self.e_IC = np.copy(self.e)
6366

6467
# Radiation energies (spatial cell centers)
6568
self.E = self.initializeAtCenters(self.input.E)
6669
self.E_p = np.copy(self.E)
6770
self.E_old = np.copy(self.E)
71+
self.E_IC = np.copy(self.E)
72+
6873
# Set E boundary conditions
69-
if self.input.rad_bL == 'source':
70-
self.E_bL = self.input.rad_bL_val
74+
if self.input.rad_L == 'source':
75+
self.E_bL = self.input.rad_L_val
7176
else:
7277
self.E_bL = None
73-
if self.input.rad_bR == 'source':
74-
self.E_bR = self.input.rad_bR_val
78+
if self.input.rad_R == 'source':
79+
self.E_bR = self.input.rad_R_val
7580
else:
7681
self.E_bR = None
7782

@@ -86,8 +91,6 @@ def stepFields(self):
8691
np.copyto(self.P_old, self.P)
8792
np.copyto(self.e_old, self.e)
8893
np.copyto(self.E_old, self.E)
89-
np.copyto(self.F_L_old, self.F_L)
90-
np.copyto(self.F_R_old, self.F_R)
9194

9295
# Initialize variable with function at the spatial cell centers
9396
def initializeAtCenters(self, function):
@@ -118,32 +121,36 @@ def recomputeRho(self, predictor):
118121
rho_new[i] = m[i] / V_new[i]
119122

120123
# Recompute radiation energy with updated internal energy
121-
def recomputeInternalEnergy(self, dt):
122-
# Query constants for the problem
124+
def recomputeInternalEnergy(self, dt, predictor):
125+
# Constants
123126
m = self.mat.m
124127
a = self.input.a
125128
c = self.input.c
126129
C_v = self.mat.C_v
127130

128-
# Query k-1/2'th variables
129-
T_old = self.T_old
130-
e_old = self.e_old
131+
if predictor:
132+
e = self.e_old
133+
T_old = self.T_old
134+
T_new = self.T_old # this is here for consistency below
135+
E_k = (self.E_p + self.E_old) / 2
136+
e_new = self.e_p
137+
xi = self.rp.radPredictor.xi
138+
else:
139+
e = self.e_p
140+
T_old = self.T_old
141+
T_new = self.T_p
142+
E_k = (self.E + self.E_old) / 2
143+
e_new = self.e
144+
xi = self.rp.radCorrector.xi
131145

132-
# Query absorption opacities
133146
kappa_a = self.mat.kappa_a
134-
135-
# Query parameter from radiation energy solve
136-
xi = self.rp.radPredictor.xi
137-
138-
# Compute average of k-1/2'th and predictor radiation energy
139-
E_k = (self.E_p + self.E_old) / 2
140-
141147
# Compute factor to be added to k-1/2'th internal energy
142-
increment = dt * C_v * (m * kappa_a * c * (E_k - a * T_old**4) + xi)
148+
T4 = (T_old**4 + T_new**4) / 2
149+
increment = dt * C_v * (m * kappa_a * c * (E_k - a * T4) + xi)
143150
increment /= m * C_v + dt * m * kappa_a * c * 2 * a * T_old**3
144151

145152
# Compute predictor internal energy
146-
self.e_p = e_old + increment
153+
e_new = e + increment
147154

148155
# Recompute temperature with updated internal energy
149156
def recomputeT(self, predictor):
@@ -172,8 +179,90 @@ def recomputeP(self, predictor):
172179
P_new[i] = gamma_minus * rho_new[i] * e_new[i]
173180

174181
# Recompute radiation energy density
175-
def recomputeE(self, dt):
176-
# Compute time-averaged parameters, opacities, etc
177-
self.radPredictor.computeAuxiliaryFields(dt)
178-
self.radPredictor.assembleSystem(dt)
179-
self.radPredictor.solveSystem(dt)
182+
def recomputeE(self, dt, predictor):
183+
if predictor:
184+
self.radPredictor.computeAuxiliaryFields(dt)
185+
self.radPredictor.assembleSystem(dt)
186+
self.radPredictor.solveSystem(dt)
187+
else:
188+
self.radCorrector.computeAuxiliaryFields(dt)
189+
self.radCorrector.assembleSystem(dt)
190+
self.radCorrector.solveSystem(dt)
191+
192+
193+
def conservationCheck(self, dt):
194+
# Centered cell and median mesh cell masses
195+
m = self.mat.m
196+
m_half = self.mat.m_half
197+
198+
# Physical constants
199+
a = self.input.a
200+
c = self.input.c
201+
N = self.geo.N
202+
203+
# Initial conditions
204+
u_IC = self.u_IC
205+
e_IC = self.e_IC
206+
E_IC = self.E_IC
207+
rho_IC = self.rho_IC
208+
209+
# k+1/2'th time-step quantities
210+
u = self.u
211+
e = self.e
212+
E = self.E
213+
rho = self.rho
214+
215+
# k'th time-step and predicted k'th time-step variables
216+
A_k = (self.geo.A + self.geo.A_old) / 2
217+
A_pk = (self.geo.A_p + self.geo.A_old) / 2
218+
E_k = (self.E + self.E_old) / 2
219+
E_pk = (self.E_p + self.E_old) / 2
220+
rho_k = (self.rho + self.rho_old) / 2
221+
rho_pk = (self.rho_p + self.rho_old) / 2
222+
dr_k = (self.geo.dr + self.geo.dr_old) / 2
223+
dr_pk = (self.geo.dr_p + self.geo.dr_old) / 2
224+
P_pk = (self.P_p + self.P_old) / 2
225+
u_k = (self.u + self.u_old) / 2
226+
T_k = (self.T + self.T_old) / 2
227+
self.mat.recomputeKappa_t(T_k)
228+
kappa_t_k = self.mat.kappa_t
229+
T_pk = (self.T_p + self.T_old) / 2
230+
self.mat.recomputeKappa_a(T_pk)
231+
kappa_t_pk = self.mat.kappa_a + self.mat.kappa_s
232+
233+
coeff_F_L = -2 * c / (3 * rho_k[0] * dr_k[0] * kappa_t_k[0] + 4)
234+
coeff_F_R = -2 * c / (3 * rho_k[-1] * dr_k[-1] * kappa_t_k[-1] + 4)
235+
coeff_E_L = 3 * rho_pk[0] * dr_pk[0] * kappa_t_pk[0]
236+
coeff_E_R = 3 * rho_pk[-1] * dr_pk[-1] * kappa_t_pk[-1]
237+
238+
if self.input.rad_L is 'source':
239+
E_bL_k = self.E_bL
240+
E_bL_pk = self.E_bL
241+
else:
242+
E_bL_k = E_k[0]
243+
E_bL_pk = E_pk[0]
244+
if self.input.rad_R is 'source':
245+
E_bR_k = self.E_bR
246+
E_bR_pk = self.E_bR
247+
else:
248+
E_bR_k = E_k[-1]
249+
E_bR_pk = E_pk[-1]
250+
251+
F_L = coeff_F_L * (E_k[0] - E_bL_k);
252+
F_R = coeff_F_R * (E_k[-1] - E_bR_k);
253+
254+
E_L = (coeff_E_L * E_bL_pk + 4 * E_pk[0]) / (coeff_E_L + 4);
255+
E_R = (coeff_E_R * E_bR_pk + 4 * E_pk[-1]) / (coeff_E_R + 4);
256+
257+
energy = 0
258+
for i in range(N + 1):
259+
energy += 1/2 * m_half[i] * (u[i]**2 - u_IC[i]**2)
260+
if i < N:
261+
energy += m[i] * (e[i] - e_IC[i])
262+
energy += m[i] * (E[i] / rho[i] - E_IC[i] / rho_IC[i])
263+
264+
energy += (A_k[-1] * F_R - A_k[0] * F_L) * dt
265+
energy += (A_pk[-1] * (1/3 * E_R + P_pk[-1]) * u_k[-1] - \
266+
A_pk[0] * (1/3 * E_L + P_pk[0] ) * u_k[0] ) * dt
267+
268+
return energy

lagrangian_hydro.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ def computeE_BCs(self, predictor):
6666
kappa_t = self.mat.kappa_t
6767

6868
# Reflective condition at left, get from E_1
69-
if self.fields.E_L is None:
69+
if self.fields.E_bL is None:
7070
E_bL = E[0]
7171
# Source condition at left
7272
else:
73-
E_bL = self.fields.E_L
73+
E_bL = self.fields.E_bL
7474
# Reflective condition at right, get from E_N+1/2
75-
if self.fields.E_R is None:
75+
if self.fields.E_bR is None:
7676
E_bR = E[-1]
7777
# Source condition at right
7878
else:
79-
E_bR = self.fields.E_R
79+
E_bR = self.fields.E_bR
8080

8181
# E_1/2 and E_N+1/2 (Eqs. 39 and 40)
8282
weight = 3 * rho[0] * dr[0] * kappa_t[0]

0 commit comments

Comments
 (0)