forked from advanced-nuclear-systems/rooster-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB_reactor.py
108 lines (87 loc) · 3.73 KB
/
B_reactor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#--------------------------------------------------------------------------------------------------
# TREE OF CLASSES:
# Reactor
# Control
# Solid
# Structure
# FuelRod
# Fuel
# FuelGrain
# InnerGas
# Clad
# Fluid
# Core
# Mix
# Isotope
# Data
#--------------------------------------------------------------------------------------------------
from B0_control import Control
from B4_data import Data
from B1_solid import Solid
from B2_fluid import Fluid
from B3_core import Core
# SciPy requires installation : python -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose
from scipy.integrate import ode
import time
#--------------------------------------------------------------------------------------------------
class Reactor:
# constructor: self is a 'reactor' object created in A
def __init__(self):
# starting time
self.tic0 = time.time()
self.tic = self.tic0
# create control object
self.control = Control(self)
# list of objects to be solved
self.solve = self.control.input['solve']
# create object fluid
self.fluid = Fluid(self)
# create object solid
self.solid = Solid(self)
# create object core
self.core = Core(self)
# create object data
self.data = Data(self)
# evaluate signals
self.control.evaluate_signals(self, self.control.input['t0'])
# write list of unknowns from self to y0
y0 = self.control.write_to_y(self)
#------------------------------------------------------------------------------------------
# given t and y, function returns the list of the right-hand sides. called by the ODE solver
def compose_rhs(t, y):
# read list of unknowns from y to self
self.control.read_from_y(self, y)
# evaluate signals
self.control.evaluate_signals(self, t)
# compose right-hand side vector
rhs = []
rhs += self.fluid.calculate_rhs(self, t)
rhs += self.solid.compose_rhs(self, t)
rhs += self.core.calculate_rhs(self, t)
return rhs
#------------------------------------------------------------------------------------------
# prepare an output folder, copy input and open output files
fid = self.control.open_output_files(self)
t0 = self.control.input['t0']
self.control.print_output_files(self, fid, t0, 0)
# create ODE solver, initialize and set integrator
solver = ode(compose_rhs, jac = None).set_integrator('vode', method = 'bdf', rtol = self.control.input['tol'][0], atol = self.control.input['tol'][1])
solver.set_initial_value(y0, t0)
#solver.set_integrator
# main integration loop
dtout = 1e-6
for tend in self.control.input['tend'] :
while solver.successful() and solver.t < tend:
t = min(tend, solver.t + dtout)
y = solver.integrate(t)
# next step recommended by the solver
dtout = solver._integrator.rwork[11]
# evaluate signals
self.control.evaluate_signals(self, t)
# print to output files
self.control.print_output_files(self, fid, t, 0)
# close all output files
for f in fid:
f.close()
tac = time.time()
print('Wall time: ','{0:.3f}'.format(tac - self.tic0), ' s')