Skip to content

Commit 8de5ae1

Browse files
committed
added RISP pulse, seems to be computation error on first RISP pulse in scenario but not second
1 parent 45e04cb commit 8de5ae1

File tree

2 files changed

+112
-45
lines changed

2 files changed

+112
-45
lines changed

mb_scenario.py

Lines changed: 110 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
# TODO: ADJUST TO HANDLE ANY STRAIGHT W 6MM SIMU
2424
mb = 64
2525

26-
2726
# tritium fraction = T/D
2827
PULSE_TYPE_TO_TRITIUM_FRACTION = {
2928
"FP": 0.5,
@@ -192,14 +191,50 @@ def make_mb_model(nb_mb, scenario_file):
192191
pulse_type_to_DINA_data = {
193192
"FP": np.loadtxt("Binned_Flux_Data.dat", skiprows=1),
194193
"ICWC": np.loadtxt("ICWC_data.dat", skiprows=1),
195-
"RISP": np.loadtxt("Binned_Flux_Data.dat", skiprows=1),
196194
"GDC": np.loadtxt("GDC_data.dat", skiprows=1),
197-
"BAKE": np.loadtxt("Binned_Flux_Data.dat", skiprows=1),
198195
}
199196

197+
def RISP_data(monob, time):
198+
"""Returns the correct RISP data file for indicated monoblock
199+
200+
Args:
201+
monob (int): mb number
202+
t (int): time as an integer
203+
204+
Returns:
205+
data (np.array): data from correct file as a numpy array
206+
"""
207+
inner_swept_bins = list(range(46,65))
208+
outer_swept_bins = list(range(19,34))
209+
210+
if monob in inner_swept_bins:
211+
label = "RISP"
212+
div = True
213+
offset_mb = 46
214+
elif monob in outer_swept_bins:
215+
label = "ROSP"
216+
div = True
217+
offset_mb = 19
218+
else:
219+
div = False
220+
offset_mb = 0
221+
222+
t = int(time)
223+
224+
if div:
225+
if t in list(range(1,10)): data = np.loadtxt(label+"_data/time0.dat", skiprows=1)
226+
elif t in list(range(11,99)): data = np.loadtxt(label+"_data/time10.dat", skiprows=1)
227+
elif t in list(range(100,261)): data = np.loadtxt(label+"_data/time"+str(t)+".dat", skiprows=1)
228+
elif t in list(range(261,270)): data = np.loadtxt(label+"_data/time270.dat", skiprows=1)
229+
else: data = np.loadtxt("RISP_Wall_data.dat", skiprows=1)
230+
else:
231+
data = np.loadtxt("RISP_Wall_data.dat", skiprows=1)
232+
233+
return data[monob-offset_mb,:]
234+
200235
############# Temperature Parameters (K) #############
201236

202-
def heat(pulse_type: str) -> float:
237+
def heat(pulse_type: str, t:float) -> float:
203238
"""Returns the surface heat flux for a given pulse type
204239
205240
Args:
@@ -213,12 +248,17 @@ def heat(pulse_type: str) -> float:
213248
"""
214249
if pulse_type not in ["FP", "ICWC", "RISP", "GDC", "BAKE"]:
215250
raise ValueError(f"Invalid pulse type {pulse_type}")
216-
data = pulse_type_to_DINA_data[pulse_type]
217-
return (
218-
data[:, -2][nb_mb - 1]
219-
if pulse_type == "FP"
220-
else data[:, -1][nb_mb - 1]
221-
)
251+
252+
if pulse_type == "RISP":
253+
data = RISP_data(nb_mb, time=t)
254+
else:
255+
data = pulse_type_to_DINA_data[pulse_type]
256+
257+
if pulse_type == "FP": heat_val = data[:, -2][nb_mb - 1]
258+
elif pulse_type == "RISP": heat_val = data[-1]
259+
else: heat_val = data[:, -1][nb_mb - 1]
260+
261+
return heat_val
222262

223263
def T_surface(t: dolfinx.fem.Constant) -> float:
224264
"""Monoblock surface temperature
@@ -230,7 +270,7 @@ def T_surface(t: dolfinx.fem.Constant) -> float:
230270
monoblock surface temperature in K
231271
"""
232272
pulse_type = my_scenario.get_pulse_type(float(t))
233-
return 1.1e-4 * heat(pulse_type) + COOLANT_TEMP
273+
return 1.1e-4 * heat(pulse_type, t=t) + COOLANT_TEMP
234274

235275
def T_rear(t: dolfinx.fem.Constant):
236276
"""Monoblock surface temperature
@@ -242,7 +282,7 @@ def T_rear(t: dolfinx.fem.Constant):
242282
monoblock surface temperature in K
243283
"""
244284
pulse_type = my_scenario.get_pulse_type(float(t))
245-
return 2.2e-5 * heat(pulse_type) + COOLANT_TEMP
285+
return 2.2e-5 * heat(pulse_type, t=t) + COOLANT_TEMP
246286

247287
def T_function(x, t: Constant):
248288
"""Monoblock temperature function
@@ -254,21 +294,28 @@ def T_function(x, t: Constant):
254294
Returns:
255295
pulsed monoblock temperature in K
256296
"""
257-
a = (T_rear(t) - T_surface(t)) / L
258-
b = T_surface(t)
259-
flat_top_value = a * x[0] + b
260297
resting_value = np.full_like(x[0], COOLANT_TEMP)
261298
pulse_row = my_scenario.get_row(float(t))
299+
pulse_type = my_scenario.get_pulse_type(float(t))
300+
301+
if pulse_type == "BAKE":
302+
flat_top_value = 483.15
303+
else:
304+
a = (T_rear(t) - T_surface(t)) / L
305+
b = T_surface(t)
306+
flat_top_value = a * x[0] + b
307+
262308
total_time_on = my_scenario.get_pulse_duration_no_waiting(pulse_row)
263309
total_time_pulse = my_scenario.get_pulse_duration(pulse_row)
264310
time_elapsed = my_scenario.get_time_till_row(pulse_row)
311+
265312
return (
266313
flat_top_value
267314
if (float(t)-time_elapsed) % total_time_pulse < total_time_on and (float(t)-time_elapsed) % total_time_pulse != 0.0
268315
else resting_value
269316
)
270317

271-
times = np.linspace(0, my_scenario.get_maximum_time(), num=100)
318+
# times = np.linspace(0, my_scenario.get_maximum_time(), num=100)
272319

273320
# x = [0]
274321
# Ts = [T_function(x, t) for t in times]
@@ -280,19 +327,38 @@ def T_function(x, t: Constant):
280327

281328
############# Flux Parameters #############
282329

283-
def deuterium_ion_flux(t: float):
284-
pulse_type = my_scenario.get_pulse_type(float(t))
330+
def get_flux(pulse_type, monob, t: float, ion=True):
331+
FP_index = 2
332+
other_index = 0
333+
if not ion:
334+
FP_index += FP_index+1
335+
other_index += other_index+1
336+
285337
if pulse_type == "FP":
286-
ion_flux = pulse_type_to_DINA_data[pulse_type][:, 2][nb_mb - 1]
338+
flux = pulse_type_to_DINA_data[pulse_type][:, FP_index][monob - 1]
339+
elif pulse_type == "RISP":
340+
t_value = int(t.value) if isinstance(t, Constant) else int(t)
341+
flux = RISP_data(monob=nb_mb, time=t_value)[other_index]
342+
elif pulse_type == "BAKE":
343+
flux = 0.0
287344
else:
288-
ion_flux = pulse_type_to_DINA_data[pulse_type][:, 0][nb_mb - 1]
289-
tritium_fraction = PULSE_TYPE_TO_TRITIUM_FRACTION[pulse_type]
290-
flat_top_value = ion_flux * (1 - tritium_fraction)
291-
resting_value = 0
345+
flux = pulse_type_to_DINA_data[pulse_type][:, other_index][monob - 1]
346+
347+
return flux
348+
349+
def deuterium_ion_flux(t: float):
350+
pulse_type = my_scenario.get_pulse_type(float(t))
351+
292352
pulse_row = my_scenario.get_row(float(t))
293353
total_time_on = my_scenario.get_pulse_duration_no_waiting(pulse_row)
294354
total_time_pulse = my_scenario.get_pulse_duration(pulse_row)
295355
time_elapsed = my_scenario.get_time_till_row(pulse_row)
356+
357+
ion_flux = get_flux(pulse_type=pulse_type, monob=nb_mb, t=t-time_elapsed)
358+
tritium_fraction = PULSE_TYPE_TO_TRITIUM_FRACTION[pulse_type]
359+
flat_top_value = ion_flux * (1 - tritium_fraction)
360+
resting_value = 0
361+
296362
return (
297363
flat_top_value
298364
if (float(t)-time_elapsed) % total_time_pulse < total_time_on and (float(t)-time_elapsed) % total_time_pulse != 0.0
@@ -305,17 +371,17 @@ def deuterium_ion_flux(t: float):
305371

306372
def tritium_ion_flux(t: float):
307373
pulse_type = my_scenario.get_pulse_type(float(t))
308-
if pulse_type == "FP":
309-
ion_flux = pulse_type_to_DINA_data[pulse_type][:, 2][nb_mb - 1]
310-
else:
311-
ion_flux = pulse_type_to_DINA_data[pulse_type][:, 0][nb_mb - 1]
312-
tritium_fraction = PULSE_TYPE_TO_TRITIUM_FRACTION[pulse_type]
313-
flat_top_value = ion_flux * tritium_fraction
314-
resting_value = 0
374+
315375
pulse_row = my_scenario.get_row(float(t))
316376
total_time_on = my_scenario.get_pulse_duration_no_waiting(pulse_row)
317377
total_time_pulse = my_scenario.get_pulse_duration(pulse_row)
318378
time_elapsed = my_scenario.get_time_till_row(pulse_row)
379+
380+
ion_flux = get_flux(pulse_type=pulse_type, monob=nb_mb, t=t-time_elapsed)
381+
382+
tritium_fraction = PULSE_TYPE_TO_TRITIUM_FRACTION[pulse_type]
383+
flat_top_value = ion_flux * tritium_fraction
384+
resting_value = 0
319385
return (
320386
flat_top_value
321387
if (float(t)-time_elapsed) % total_time_pulse < total_time_on and (float(t)-time_elapsed) % total_time_pulse != 0.0
@@ -324,17 +390,17 @@ def tritium_ion_flux(t: float):
324390

325391
def deuterium_atom_flux(t: float):
326392
pulse_type = my_scenario.get_pulse_type(float(t))
327-
if pulse_type == "FP":
328-
atom_flux = pulse_type_to_DINA_data[pulse_type][:, 3][nb_mb - 1]
329-
else:
330-
atom_flux = pulse_type_to_DINA_data[pulse_type][:, 1][nb_mb - 1]
331-
tritium_fraction = PULSE_TYPE_TO_TRITIUM_FRACTION[pulse_type]
332-
flat_top_value = atom_flux * (1 - tritium_fraction)
333-
resting_value = 0
393+
334394
pulse_row = my_scenario.get_row(float(t))
335395
total_time_on = my_scenario.get_pulse_duration_no_waiting(pulse_row)
336396
total_time_pulse = my_scenario.get_pulse_duration(pulse_row)
337397
time_elapsed = my_scenario.get_time_till_row(pulse_row)
398+
399+
atom_flux = get_flux(pulse_type=pulse_type, monob=nb_mb, t=t-time_elapsed, ion=False)
400+
401+
tritium_fraction = PULSE_TYPE_TO_TRITIUM_FRACTION[pulse_type]
402+
flat_top_value = atom_flux * (1 - tritium_fraction)
403+
resting_value = 0
338404
return (
339405
flat_top_value
340406
if (float(t)-time_elapsed) % total_time_pulse < total_time_on and (float(t)-time_elapsed) % total_time_pulse != 0.0
@@ -343,17 +409,16 @@ def deuterium_atom_flux(t: float):
343409

344410
def tritium_atom_flux(t: float):
345411
pulse_type = my_scenario.get_pulse_type(float(t))
346-
if pulse_type == "FP":
347-
atom_flux = pulse_type_to_DINA_data[pulse_type][:, 3][nb_mb - 1]
348-
else:
349-
atom_flux = pulse_type_to_DINA_data[pulse_type][:, 1][nb_mb - 1]
350-
tritium_fraction = PULSE_TYPE_TO_TRITIUM_FRACTION[pulse_type]
351-
flat_top_value = atom_flux * tritium_fraction
352-
resting_value = 0
412+
353413
pulse_row = my_scenario.get_row(float(t))
354414
total_time_on = my_scenario.get_pulse_duration_no_waiting(pulse_row)
355415
total_time_pulse = my_scenario.get_pulse_duration(pulse_row)
356416
time_elapsed = my_scenario.get_time_till_row(pulse_row)
417+
418+
atom_flux = get_flux(pulse_type=pulse_type, monob=nb_mb, t=t-time_elapsed, ion=False)
419+
tritium_fraction = PULSE_TYPE_TO_TRITIUM_FRACTION[pulse_type]
420+
flat_top_value = atom_flux * tritium_fraction
421+
resting_value = 0
357422
return (
358423
flat_top_value
359424
if (float(t)-time_elapsed) % total_time_pulse < total_time_on and (float(t)-time_elapsed) % total_time_pulse != 0.0
@@ -453,7 +518,7 @@ def tritium_atom_flux(t: float):
453518
final_time=my_scenario.get_maximum_time()
454519
)
455520

456-
my_model.settings.stepsize = F.Stepsize(initial_value=20)
521+
my_model.settings.stepsize = F.Stepsize(initial_value=1)
457522

458523
return my_model, quantities
459524

scenario_test.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# PULSE TYPE, NUMBER OF PULSES, RAMP UP, RAMP DOWN, STEADY STATE, WAITING
22
FP 2 455 455 650 1000
33
ICWC 2 36 36 180 1000
4+
RISP 2 0 0 0 0
5+

0 commit comments

Comments
 (0)