Example #1
0
def test_droplet():
    '''
    Run the droplet example
    '''
    pwd = os.path.dirname(__file__)
    full_path_config_file = os.path.join(pwd,
                                         'input/cortix-config-droplet.xml')
    cortix1 = Cortix('cortix-droplet', full_path_config_file)
    cortix1.run_simulations(task_name="droplet-fall")
Example #2
0
def main():

 pwd                   = os.path.dirname(__file__)
 full_path_config_file = os.path.join(pwd, 'input/cortix-config-droplet.xml')

 # NB: if another instantiation of Cortix occurs, the cortix wrk directory specified
 #     in the cortix configuration file must be different, else the logging facility 
 #     will have log file collision.

 cortix1 = Cortix( 'cortix-droplet', full_path_config_file ) # see cortix-config-droplet.xml
#
# cortix1.run_simulations( task_name='solo-droplet-fall' )
 cortix1.run_simulations( task_name='droplet-fall' )
Example #3
0
    def run(self):
        if not isinstance(self.n_list, list):
            self.n_list = [
                self.n_list,
            ]
        for c, i in enumerate(self.n_list):
            self.cortix = Cortix(use_mpi=False)
            self.net = Network()
            self.cortix.network = self.net
            self.plot = Particle_Plot(self.shape,
                                      balls=i,
                                      modules=self.procs,
                                      runtime=self.runtime)
            self.plot.fps = self.fps
            self.net.add_module(self.plot)
            print(c + 1, 'iterations')
            self.balls = i
            self.balleach = int(self.balls / self.procs)
            remainder = self.balls % self.procs
            self.mod_list = []
            for i in range(self.procs):
                balls = self.balleach
                if remainder > 0:
                    balls += 1
                    remainder -= 1
                app = Particle_Handler(self.shape,
                                       balls=balls,
                                       runtime=self.runtime)
                app.r = self.r
                app.a = self.a
                app.cor = self.cor
                app.t_step = 0.01
                self.mod_list.append(app)
                self.net.add_module(app)
            for c, i in enumerate(self.mod_list):
                self.net.connect([i, 'plot-send{}'.format(c)],
                                 [self.plot, 'plot-receive{}'.format(c)])
                for j in self.mod_list:
                    if i == j:
                        continue
                    name = '{}{}'.format(i.name, j.name)
                    name2 = '{}{}'.format(j.name, i.name)
                    self.net.connect([i, name], [j, name2])


##            threading.Thread(target=self.plotting,daemon=True).start()
            self.cortix.run()
            self.cortix.close()
            del self.cortix
            print('finished sim')
Example #4
0
def test_solo_pyplot():
    '''
    Run solo_pyplot and make sure the correct output is generated
    '''
    pwd = os.path.dirname(__file__)
    full_path_config_file = os.path.join(pwd, 'input/cortix-config-pyplot.xml')
    comm = MPI.COMM_WORLD
    rank = comm.Get_rank()
    os.system("cp input/state.xml /tmp")
    if rank == 0:
        cortix1 = Cortix('cortix-dev1', full_path_config_file)
        cortix1.run_simulations(task_name="solo-pyplot")
    for i in range(14):
        assert os.path.exists("pyplot_0-timeseq-dashboard-%02d.png" % i)
    os.system("rm -f *.png")
Example #5
0
def main():

    pwd = os.path.dirname(__file__)
    full_path_config_file = os.path.join(pwd, 'input/cortix-config.xml')

    # NB: if another instantiation of Cortix occurs, the cortix wrk directory specified
    #     in the cortix configuration file must be different, else the logging facility
    #     will have log file collision.

    comm = MPI.COMM_WORLD
    size = comm.Get_size()
    rank = comm.Get_rank()

    if (rank == 0):
        cortix1 = Cortix('cortix1', full_path_config_file)
        cortix1.run_simulations(
            task_name='solo-pyplot')  # see cortix-config.xml
Example #6
0
def test_object_instantiation():
    '''
    Test for successful object instantiation
    '''
    pwd = os.path.dirname(__file__)
    full_path_config_file = os.path.join(pwd, 'input/cortix-config-pyplot.xml')
    comm = MPI.COMM_WORLD
    rank = comm.Get_rank()
    if rank == 0:
        cortix1 = Cortix('cortix-dev1', full_path_config_file)
        assert cortix1 is not None
Example #7
0
def main():

    pwd = os.path.dirname(__file__)
    full_path_config_file = os.path.join(pwd, 'input/cortix-config.xml')

    # NB: if another instantiation of Cortix occurs, the cortix wrk directory specified
    #     in the cortix configuration file must be different, else the logging facility
    #     will have log file collision.

    # comm = MPI.COMM_WORLD
    # size = comm.Get_size()
    # rank = comm.Get_rank()
    # print('size = ',size)
    # print('rank = ',rank)

    # if (rank == 0):
    # Create a PoolExecutor (only one excutor is allowed; to avoid recursion)
    # at the moment, this precludes multiple instantiations of Cortix.
    # Todo: modify in the future if multiple instances of Cortix will be used
    # in the user code.
    #
    # MPI development (pool status: broken)
    # pool_executor = MPIPoolExecutor()
    # usage: mpiexec -n 4 python -m mpi4py.futures main.py
    # pool_executor.bootup(wait=True)

    # concurrent.futures development (pool status: working for thread, issues for process)
    pool_executor = ThreadPoolExecutor()
    # pool_executor = ProcessPoolExecutor()
    #
    cortix1 = Cortix('cortix-dev1', full_path_config_file,
                     pool_executor)  # see cortix-config.xml
    #
    # usage: uncomment only one at a time
    # cortix1.run_simulations( task_name='solo-pyplot' )
    cortix1.run_simulations(task_name='solo-fueldepot')
Example #8
0
def main():

    # Debugging
    make_plots = False
    make_run = False

    # Preamble
    end_time = 75 * unit.minute
    time_step = 1.5 * unit.second
    show_time = (True, 5 * unit.minute)

    plant = Cortix(use_mpi=False, splash=True)  # System top level

    plant_net = plant.network = Network()  # Network

    # Reactor
    reactor = SMPWR()  # Create reactor module
    reactor.name = "SM-PWR"

    reactor.shutdown = (True, 60 * unit.minute)

    plant_net.module(reactor)  # Add reactor module to network

    # Steamer

    steamer = Steamer()  # Create reactor module

    plant_net.module(steamer)  # Add steamer module to network

    # Turbine

    turbine = Turbine()  # Create reactor module

    plant_net.module(turbine)  # Add steamer module to network
    '''Condenser'''

    condenser = Condenser()  # Create condenser module

    plant_net.module(condenser)  # Add condenser module to network`
    '''Feedwater Heating system'''

    water_heater = WaterHeater()  # Create water_heater module

    water_heater.malfunction = (True, 30 * unit.minute, 45 * unit.minute)

    plant_net.module(water_heater)  # Add water_heater module to network

    # Balance of Plant Network Connectivity

    plant_net.connect([reactor, 'coolant-outflow'],
                      [steamer, 'primary-inflow'])
    plant_net.connect([steamer, 'primary-outflow'],
                      [reactor, 'coolant-inflow'])
    plant_net.connect([steamer, 'secondary-outflow'], [turbine, 'inflow'])
    plant_net.connect([turbine, 'outflow'], [condenser, 'inflow'])
    plant_net.connect([turbine, 'process-heat'],
                      [water_heater, 'external-heat'])
    plant_net.connect([condenser, 'outflow'], [water_heater, 'inflow'])
    plant_net.connect([water_heater, 'outflow'], [steamer, 'secondary-inflow'])

    plant_net.draw(engine='circo', node_shape='folder')

    # Run
    if make_run:

        for module in plant_net.modules:
            module.time_step = time_step
            module.end_time = end_time
            module.show_time = show_time

        plant.run()  # Run network dynamics simulation

    # Cortix run closure
    plant.close()  # Properly shutdow plant

    # Plots
    if make_plots and plant.use_multiprocessing or plant.rank == 0:

        # Reactor plots
        reactor = plant_net.modules[0]

        (quant, time_unit
         ) = reactor.neutron_phase.get_quantity_history('neutron-dens')
        quant.plot(x_scaling=1 / unit.minute,
                   y_scaling=1 / max(quant.value),
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')

        plt.grid()
        plt.savefig('reactor-neutron-dens.png', dpi=300)

        (quant, time_unit
         ) = reactor.neutron_phase.get_quantity_history('delayed-neutrons-cc')
        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')

        plt.grid()
        plt.savefig('reactor-delayed-neutrons-cc.png', dpi=300)

        (quant, time_unit
         ) = reactor.coolant_outflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1 / unit.minute,
                   y_shift=273.15,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [C]')

        plt.grid()
        plt.savefig('reactor-coolant-outflow-temp.png', dpi=300)

        (quant,
         time_unit) = reactor.state_phase.get_quantity_history('core-temp')

        quant.plot(x_scaling=1 / unit.minute,
                   y_shift=273.15,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [C]')
        plt.grid()
        plt.savefig('reactor-core-temp.png', dpi=300)

        (quant, time_unit) = reactor.state_phase.get_quantity_history('power')

        quant.plot(x_scaling=1 / unit.minute,
                   y_scaling=1 / unit.mega,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [M' + quant.unit + ']')
        plt.grid()
        plt.savefig('reactor-power.png', dpi=300)

        (quant,
         time_unit) = reactor.state_phase.get_quantity_history('reynolds')

        quant.plot(x_scaling=1 / unit.minute,
                   y_scaling=1 / unit.mega,
                   x_label='Time [m]',
                   y_label=quant.latex_name + r' [$\times 10^6$' + quant.unit +
                   ']')
        plt.grid()
        plt.savefig('reactor-reynolds.png', dpi=300)

        (quant,
         time_unit) = reactor.state_phase.get_quantity_history('prandtl')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + r' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('reactor-prandtl.png', dpi=300)

        (quant, time_unit
         ) = reactor.coolant_outflow_phase.get_quantity_history('flowrate')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + r' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('reactor-flowrate.png', dpi=300)

        (quant,
         time_unit) = reactor.state_phase.get_quantity_history('heatflux')

        quant.plot(x_scaling=1 / unit.minute,
                   y_scaling=1 / unit.mega,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [M' + quant.unit + ']')
        plt.grid()
        plt.savefig('reactor-heatflux.png', dpi=300)

        (quant,
         time_unit) = reactor.state_phase.get_quantity_history('inlet-temp')

        quant.plot(x_scaling=1 / unit.minute,
                   y_shift=273.15,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [C]')
        plt.grid()
        plt.savefig('reactor-coolant-inflow-temp.png', dpi=300)

        (quant,
         time_unit) = reactor.state_phase.get_quantity_history('nusselt')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('reactor-nusselt.png', dpi=300)

        (quant, time_unit) = reactor.state_phase.get_quantity_history('tau')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('reactor-coolant-tau.png', dpi=300)

        (quant, time_unit
         ) = reactor.coolant_outflow_phase.get_quantity_history('quality')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + r' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('reactor-coolant-outflow-quality.png', dpi=300)

        # Steamer plots
        steamer = plant_net.modules[1]

        (quant, time_unit
         ) = steamer.primary_outflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1 / unit.minute,
                   y_shift=273.15,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [C]')
        plt.grid()
        plt.savefig('steamer-primary-outflow-temp.png', dpi=300)

        (quant, time_unit
         ) = steamer.secondary_inflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1 / unit.minute,
                   y_shift=273.15,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [C]')
        plt.grid()
        plt.savefig('steamer-secondary-inflow-temp.png', dpi=300)

        (quant, time_unit
         ) = steamer.secondary_inflow_phase.get_quantity_history('flowrate')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('steamer-secondary-inflow-flowrate.png', dpi=300)

        (quant, time_unit
         ) = steamer.secondary_outflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1 / unit.minute,
                   y_shift=273.15,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [C]')
        plt.grid()
        plt.savefig('steamer-secondary-outflow-temp.png', dpi=300)

        (quant, time_unit
         ) = steamer.secondary_outflow_phase.get_quantity_history('flowrate')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('steamer-secondary-outflow-flowrate.png', dpi=300)

        (quant, time_unit) = steamer.state_phase.get_quantity_history('tau_p')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('steamer-primary-tau.png', dpi=300)

        (quant, time_unit) = steamer.state_phase.get_quantity_history('tau_s')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('steamer-secondary-tau.png', dpi=300)

        (quant, time_unit
         ) = steamer.secondary_outflow_phase.get_quantity_history('quality')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('steamer-secondary-quality.png', dpi=300)

        (quant,
         time_unit) = steamer.state_phase.get_quantity_history('heatflux')

        quant.plot(x_scaling=1 / unit.minute,
                   y_scaling=1 / unit.kilo,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [k' + quant.unit + ']')
        plt.grid()
        plt.savefig('steamer-heatflux.png', dpi=300)

        (quant,
         time_unit) = steamer.state_phase.get_quantity_history('nusselt_p')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('steamer-nusselt_p.png', dpi=300)

        (quant,
         time_unit) = steamer.state_phase.get_quantity_history('nusselt_s')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('steamer-nusselt_s.png', dpi=300)

        # Turbine plots
        turbine = plant_net.modules[2]

        (quant, time_unit) = turbine.state_phase.get_quantity_history('power')

        quant.plot(x_scaling=1 / unit.minute,
                   y_scaling=1 / unit.mega,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [M' + quant.unit + ']')
        plt.grid()
        plt.savefig('turbine-power.png', dpi=300)

        (quant, time_unit) = turbine.outflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1 / unit.minute,
                   y_shift=273.15,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [C]')
        plt.grid()
        plt.savefig('turbine-outflow-temp.png', dpi=300)

        (quant,
         time_unit) = turbine.state_phase.get_quantity_history('rejected-heat')

        quant.plot(x_scaling=1 / unit.minute,
                   y_scaling=1 / unit.mega,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [M' + quant.unit + ']')
        plt.grid()
        plt.savefig('turbine-rejected-heat.png', dpi=300)

        # Condenser plots
        condenser = plant_net.modules[3]

        (quant,
         time_unit) = condenser.inflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1 / unit.minute,
                   y_shift=273.15,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [C]')
        plt.grid()
        plt.savefig('condenser-inflow-temp.png', dpi=300)

        (quant,
         time_unit) = condenser.inflow_phase.get_quantity_history('flowrate')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('condenser-inflow-flowrate.png', dpi=300)

        (quant,
         time_unit) = condenser.outflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1 / unit.minute,
                   y_shift=273.15,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [C]')
        plt.grid()
        plt.savefig('condenser-outflow-temp.png', dpi=300)

        # Water heater plots
        water_heater = plant_net.modules[4]

        (quant,
         time_unit) = water_heater.outflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1 / unit.minute,
                   y_shift=273.15,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [C]')
        plt.grid()
        plt.savefig('water_heater-outflow-temp.png', dpi=300)

        (quant, time_unit
         ) = water_heater.outflow_phase.get_quantity_history('flowrate')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + r' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('water_heater-flowrate.png', dpi=300)

        (quant, time_unit
         ) = water_heater.inflow_phase.get_quantity_history('external-heat')

        quant.plot(x_scaling=1 / unit.minute,
                   y_scaling=1 / unit.mega,
                   x_label='Time [m]',
                   y_label=quant.latex_name + r' [M' + quant.unit + ']')
        plt.grid()
        plt.savefig('water_heater-external-heat.png', dpi=300)

        (quant, time_unit
         ) = water_heater.outflow_phase.get_quantity_history('rejected-heat')

        quant.plot(x_scaling=1 / unit.minute,
                   y_scaling=1 / unit.mega,
                   x_label='Time [m]',
                   y_label=quant.latex_name + r' [M' + quant.unit + ']')
        plt.grid()
        plt.savefig('water_heater-rejected-heat.png', dpi=300)
Example #9
0
def main():

    # Debugging
    make_plots = True
    make_run   = True

    # Preamble
    end_time = 10*unit.minute
    time_step = 1.5*unit.second
    show_time = (True, 5*unit.minute)

    plant = Cortix(use_mpi=False, splash=True) # System top level

    plant_net = plant.network = Network() # Network

    # Steamer

    steamer = Steamer()  # Create reactor module

    # Steady state conditions for NuSCale case
    #primary_inflow_temp = (320.9+273.15)*unit.kelvin
    #secondary_inflow_temp = (149+273.15)*unit.kelvin
    #steamer = Steamer(primary_inflow_temp, secondary_inflow_temp)  # Create reactor module

    steamer.name = 'Steamer'
    steamer.save = True
    steamer.time_step = time_step
    steamer.end_time = end_time
    steamer.show_time = show_time

    plant_net.module(steamer)  # Add steamer module to network

    # Balance of Plant Network Connectivity

    plant_net.draw(engine='circo', node_shape='folder')

    # Run
    if make_run:
        plant.run()  # Run network dynamics simulation

    plant.close()  # Properly shutdow Cortix

    # Plots
    if make_plots and plant.use_multiprocessing or plant.rank == 0:

        # Steamer plots
        steamer = plant_net.modules[0]

        (quant, time_unit) = steamer.primary_outflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1/unit.minute, y_shift=273.15, x_label='Time [m]',
                   y_label=quant.latex_name+' [C]')
        plt.grid()
        plt.savefig('steamer-primary-outflow-temp.png', dpi=300)

        (quant, time_unit) = steamer.primary_outflow_phase.get_quantity_history('flowrate')

        quant.plot(x_scaling=1/unit.minute, x_label='Time [m]',
                   y_label=quant.latex_name+' ['+quant.unit+']')
        plt.grid()
        plt.savefig('steamer-primary-mass-flowrate.png', dpi=300)

        (quant, time_unit) = steamer.secondary_inflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1/unit.minute, y_shift=273.15, x_label='Time [m]',
                   y_label=quant.latex_name+' [C]')
        plt.grid()
        plt.savefig('steamer-secondary-inflow-temp.png', dpi=300)

        (quant, time_unit) = steamer.secondary_outflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1/unit.minute, y_shift=273.15, x_label='Time [m]',
                   y_label=quant.latex_name+' [C]')
        plt.grid()
        plt.savefig('steamer-secondary-outflow-temp.png', dpi=300)

        (quant, time_unit) = steamer.secondary_inflow_phase.get_quantity_history('flowrate')

        quant.plot(x_scaling=1/unit.minute, x_label='Time [m]',
                   y_label=quant.latex_name+' ['+quant.unit+']')
        plt.grid()
        plt.savefig('steamer-secondary-inflow-flowrate.png', dpi=300)

        (quant, time_unit) = steamer.secondary_outflow_phase.get_quantity_history('flowrate')

        quant.plot(x_scaling=1/unit.minute, x_label='Time [m]',
                   y_label=quant.latex_name+' ['+quant.unit+']')
        plt.grid()
        plt.savefig('steamer-secondary-outflow-flowrate.png', dpi=300)

        (quant, time_unit) = steamer.state_phase.get_quantity_history('tau_p')

        quant.plot(x_scaling=1/unit.minute, x_label='Time [m]',
                   y_label=quant.latex_name+' ['+quant.unit+']')
        plt.grid()
        plt.savefig('steamer-primary-tau.png', dpi=300)

        (quant, time_unit) = steamer.state_phase.get_quantity_history('tau_s')

        quant.plot(x_scaling=1/unit.minute, x_label='Time [m]',
                   y_label=quant.latex_name+' ['+quant.unit+']')
        plt.grid()
        plt.savefig('steamer-secondary-tau.png', dpi=300)

        (quant, time_unit) = steamer.secondary_outflow_phase.get_quantity_history('quality')

        quant.plot(x_scaling=1/unit.minute, x_label='Time [m]',
                   y_label=quant.latex_name+' ['+quant.unit+']')
        plt.grid()
        plt.savefig('steamer-secondary-quality.png', dpi=300)

        (quant, time_unit) = steamer.state_phase.get_quantity_history('heatflux')

        quant.plot(x_scaling=1/unit.minute, y_scaling=1/unit.kilo, x_label='Time [m]',
                   y_label=quant.latex_name+' [k'+quant.unit+']')
        plt.grid()
        plt.savefig('steamer-heatflux.png', dpi=300)

        (quant, time_unit) = steamer.state_phase.get_quantity_history('nusselt_p')

        quant.plot(x_scaling=1/unit.minute, x_label='Time [m]',
                   y_label=quant.latex_name+' ['+quant.unit+']')
        plt.grid()
        plt.savefig('steamer-nusselt_p.png', dpi=300)

        (quant, time_unit) = steamer.state_phase.get_quantity_history('nusselt_s')

        quant.plot(x_scaling=1/unit.minute, x_label='Time [m]',
                   y_label=quant.latex_name+' ['+quant.unit+']')
        plt.grid()
        plt.savefig('steamer-nusselt_s.png', dpi=300)
Example #10
0
def main():
    '''Cortix run file for a `Droplet`-`Vortex` network.

    Attributes
    ----------
    n_droplets: int
        Number of droplets to use (one per process).
    end_time: float
        End of the flow time in SI unit.
    time_step: float
        Size of the time step between port communications in SI unit.
    create_plots: bool
        Create various plots and save to files. (all data collected in the
        parent process; it may run out of memory).
    plot_vortex_profile: bool
        Whether to plot (to a file) the vortex function used.
    use_mpi: bool
        If set to `True` use MPI otherwise use Python multiprocessing.

    '''

    # Configuration Parameters
    n_droplets = 5
    end_time   = 3*const.minute
    time_step  = 0.2

    create_plots = True

    if n_droplets >= 2000:
        create_plots = False

    plot_vortex_profile = False # True may crash the X server.

    use_mpi = False # True for MPI; False for Python multiprocessing

    swirl = Cortix(use_mpi=use_mpi, splash=True)

    swirl.network = Network()

    # Vortex module (single).
    vortex = Vortex()
    swirl.network.module(vortex)
    vortex.show_time = (True,1*const.minute)
    vortex.end_time = end_time
    vortex.time_step = time_step
    if plot_vortex_profile:
        vortex.plot_velocity()

    for i in range(n_droplets):

        # Droplet modules (multiple).
        droplet = Droplet()
        swirl.network.module(droplet)
        droplet.end_time = end_time
        droplet.time_step = time_step
        droplet.bounce = False
        droplet.slip = False
        droplet.save = True

        # Network port connectivity (connect modules through their ports)
        swirl.network.connect( [droplet,'external-flow'],
                               [vortex,vortex.get_port('fluid-flow:{}'.format(i))],
                               'bidirectional' )

    swirl.network.draw()

    swirl.run()

    # Plot all droplet trajectories
    if create_plots:

        modules = swirl.network.modules

        if swirl.use_multiprocessing or swirl.rank == 0:

            # All droplets' trajectory

            from mpl_toolkits.mplot3d import Axes3D
            import matplotlib.pyplot as plt

            positions = list()
            for m in swirl.network.modules[1:]:
                positions.append(m.liquid_phase.get_quantity_history('position')[0].value)

            fig = plt.figure(1)
            ax = fig.add_subplot(111,projection='3d')
            ax.set_title('Droplet Trajectories')
            ax.set_xlabel('x')
            ax.set_ylabel('y')
            ax.set_zlabel('z')
            for pos in positions:
                x = [i[0] for i in pos]
                y = [i[1] for i in pos]
                z = [i[2] for i in pos]
                ax.plot(x, y, z)
            fig.savefig('trajectories.png', dpi=300)

            # All droplets' speed
            fig = plt.figure(2)
            plt.xlabel('Time [min]')
            plt.ylabel('Speed [m/s]')
            plt.title('All Droplets')

            for m in modules[1:]:
                speed = m.liquid_phase.get_quantity_history('speed')[0].value
                plt.plot(list(speed.index/60), speed.tolist())

            plt.grid()
            fig.savefig('speeds.png', dpi=300)

            # All droplets' radial position
            fig = plt.figure(3)
            plt.xlabel('Time [min]')
            plt.ylabel('Radial Position [m]')
            plt.title('All Droplets')

            for m in modules[1:]:
                radial_pos = m.liquid_phase.get_quantity_history('radial-position')[0].value
                plt.plot(list(radial_pos.index/60)[1:], radial_pos.tolist()[1:])

            plt.grid()
            fig.savefig('radialpos.png', dpi=300)

    # This properly ends the program
    swirl.close()
Example #11
0
        print("Finished sending!")

if __name__ == "__main__":

    # Cortix built-in DataPlot module
    d = DataPlot()
    #d.set_title("Test Plot")
    #d.set_xlabel("Time")
    #d.set_ylabel("Position")

    d.title = 'Test Plot'
    d.xlabel = 'Time'
    d.ylabel = 'Position'

    # Custom class to send dummy data
    p = PlotData()

    p1 = Port("plot-in")
    p2 = Port("plot-out")
    p1.connect(p2)

    d.ports.append(p1)
    p.ports.append(p2)

    c = Cortix()
    c.network = Network()
    c.network.add_module(d)
    c.network.add_module(p)
    c.use_mpi = False
    c.run()
Example #12
0
def main():
    """Balance of plant of a boiling water nuclear reactor.

    Attributes
    ----------
    end_time: float
        End of the flow time in SI unit.
    time_step: float
        Size of the time step between port communications in SI unit.
    use_mpi: bool
        If set to `True` use MPI otherwise use Python multiprocessing.

    """

    # Preamble

    end_time = 30 * unit.minute
    time_step = 30.0  # seconds
    show_time = (True, 5 * unit.minute)

    use_mpi = False  # True for MPI; False for Python multiprocessing
    plot_results = True  # True for enabling plotting section below
    params = get_params()  # parameters for BoP BWR

    #*****************************************************************************
    # Define Cortix system

    # System top level
    plant = Cortix(use_mpi=use_mpi, splash=True)

    # Network
    plant_net = plant.network = Network()

    params['start-time'] = 0
    params['end-time'] = end_time

    #*****************************************************************************
    # Create reactor module
    reactor = BWR(params)

    reactor.name = 'BWR'
    reactor.save = True
    reactor.time_step = time_step
    reactor.end_time = end_time
    reactor.show_time = show_time

    # Add reactor module to network
    plant_net.module(reactor)

    #*****************************************************************************
    # Create turbine 1 module
    params['turbine_inlet_pressure'] = 2
    params['turbine_outlet_pressure'] = 0.005
    params['high_pressure_turbine'] = True

    #params_turbine = reactor.params
    #params_turbine.inlet_pressure = 2
    #params.turbine_outlet_pressure = 0.5

    turbine1 = Turbine(params)

    turbine1.name = 'High Pressure Turbine'
    turbine1.save = True
    turbine1.time_step = time_step
    turbine1.end_time = end_time

    # Add turbine 1 module to network
    plant_net.module(turbine1)

    #*****************************************************************************
    # Create condenser module
    params['steam flowrate'] = params['steam flowrate'] * 2

    condenser = Condenser(params)

    condenser.name = 'Condenser'
    condenser.save = True
    condenser.time_step = time_step
    condenser.end_time = end_time

    plant_net.module(condenser)

    #*****************************************************************************
    # Create the BoP network connectivity
    plant_net.connect([reactor, 'coolant-outflow'], [turbine1, 'inflow'])
    plant_net.connect([turbine1, 'outflow-1'], [condenser, 'inflow-1'])
    plant_net.connect([condenser, 'outflow'], [reactor, 'coolant-inflow'])

    plant_net.draw()

    #*****************************************************************************
    # Run network dynamics simulation
    plant.run()

    #*****************************************************************************
    # Plot results

    if plot_results and (plant.use_multiprocessing or plant.rank == 0):

        # Reactor plots
        reactor = plant_net.modules[0]

        (quant, time_unit
         ) = reactor.neutron_phase.get_quantity_history('neutron-dens')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')

        plt.grid()
        plt.savefig('test-neutron-dens.png', dpi=300)

        (quant, time_unit
         ) = reactor.neutron_phase.get_quantity_history('delayed-neutrons-cc')
        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')

        plt.grid()
        plt.savefig('test-delayed-neutrons-cc.png', dpi=300)

        (quant, time_unit
         ) = reactor.coolant_outflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')

        plt.grid()
        plt.savefig('test-coolant-outflow-temp.png', dpi=300)

        (quant,
         time_unit) = reactor.reactor_phase.get_quantity_history('fuel-temp')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('test-fuel-temp.png', dpi=300)

        # Turbine1 plots
        turbine1 = plant_net.modules[1]

        (quant,
         time_unit) = turbine1.outflow_phase.get_quantity_history('power')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']',
                   title='High Pressure Turbine Power')
        plt.grid()
        plt.savefig('test-turbine1-power.png', dpi=300)

        (quant,
         time_unit) = turbine1.outflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']',
                   title='High Pressure Turbine Outflow Temperature')
        plt.grid()
        plt.savefig('test-turbine1-outflow-temp.png', dpi=300)

        # Condenser graphs
        condenser = plant_net.modules[-1]

        (quant,
         time_unit) = condenser.outflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('test-condenser-outflow-temp.png', dpi=300)

    # Properly shutdown simulation
    plant.close()
Example #13
0
def main():
    """Cortix run file for a solvent extraction network.

    Attributes
    ----------
    end_time: float
        End of the flow time in SI unit.
    time_step: float
        Size of the time step between port communications in SI unit.
    use_mpi: bool
        If set to `True` use MPI otherwise use Python multiprocessing.

    """

    # Preamble

    end_time = 30 * unit.minute
    time_step = 30.0  # seconds
    show_time = (True, 5 * unit.minute)

    use_mpi = False  # True for MPI; False for Python multiprocessing

    # System top level
    plant = Cortix(use_mpi=use_mpi, splash=True)

    # Network
    plant_net = plant.network = Network()

    params = get_params()
    params['start-time'] = 0
    params['end-time'] = end_time

    # Create reactor module
    reactor = BWR(params)

    reactor.name = 'BWR'
    reactor.save = True
    reactor.time_step = time_step
    reactor.end_time = end_time
    reactor.show_time = show_time

    # Add reactor module to network
    plant_net.module(reactor)

    # Create the network connectivity

    #*****************************************************************************

    plant_net.draw()

    # Run network dynamics simulation
    plant.run()

    plot_results = True

    if plot_results and (plant.use_multiprocessing or plant.rank == 0):

        # Reactor graphs
        reactor = plant_net.modules[0]

        (quant, time_unit
         ) = reactor.neutron_phase.get_quantity_history('neutron-dens')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.formal_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('test-neutron-dens.png', dpi=300)

        (quant, time_unit
         ) = reactor.neutron_phase.get_quantity_history('delayed-neutrons-cc')
        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.formal_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('test-delayed-neutrons-cc.png', dpi=300)

        (quant, time_unit
         ) = reactor.coolant_outflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.formal_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('test-coolant-outflow-temp.png', dpi=300)

        (quant,
         time_unit) = reactor.reactor_phase.get_quantity_history('fuel-temp')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label='Fuel Temp. [k]')
        plt.grid()
        plt.savefig('test-fuel-temp.png', dpi=300)

    # Properly shutdown simulation
    plant.close()
Example #14
0
def main():
    um = False
    sim_time = 365 * 24 * 3600  #157788000.0 * 10
    time_step = 24 * 3600  #25000.0

    universe_rad = 2.5e11

    cortix = Cortix(use_mpi=um)
    cortix.network = Network()

    earth_mass = 5.9740e+24
    earth_pos = np.array([1.4960e+11, 0.0, 0.0])
    earth_vel = np.array([(0.0, 2.9800e+04, 0.0)])
    earth = Body(earth_mass, earth_pos, earth_vel)
    earth.name = "earth"
    cortix.network.module(earth)

    mars_mass = 6.4190e+23
    mars_pos = np.array([2.2790e+11, 0.0, 0.0])
    mars_vel = np.array([0.0, 2.4100e+04, 0.0])
    mars = Body(mars_mass, mars_pos, mars_vel)
    mars.name = "mars"
    cortix.network.module(mars)

    mercury_mass = 3.3020e+23
    mercury_pos = np.array([5.7900e+10, 0.0, 0.0])
    mercury_vel = np.array([0.0, 4.7900e+04, 0.0])
    mercury = Body(mercury_mass, mercury_pos, mercury_vel)
    mercury.name = "mercury"
    cortix.network.module(mercury)

    venus_mass = 4.8690e+24
    venus_pos = np.array([1.0820e+11, 0.0, 0.0])
    venus_vel = np.array([0.0, 3.5000e+04, 0.0])
    venus = Body(venus_mass, venus_pos, venus_vel)
    venus.name = "venus"
    cortix.network.module(venus)

    sun_mass = 1.9890e+30
    sun_pos = np.array([0.0, 0.0, 0.0])
    sun_vel = np.array([0.0, 0.0, 0.0])
    sun = Body(sun_mass, sun_pos, sun_vel)
    sun.name = "sun"
    cortix.network.module(sun)

    for x, i in enumerate(cortix.network.modules):
        i.save = True
        i.dt = time_step
        i.time = sim_time
        for y, j in enumerate(cortix.network.modules):
            pi = Port("body_{}".format(y), um)

            if x != y and pi not in i.ports:
                i.ports.append(pi)

                pj = Port("body_{}".format(x), um)
                j.ports.append(pj)

                pj.connect(pi)
                cortix.network.gv_edges.append((str(x), str(y)))

    cortix.run()
    cortix.network.draw()

    return [(b.name, b.trajectory) for b in cortix.network.modules]
Example #15
0
def main():
    '''Cortix run file for UMass Lowell research nuclear reactor.

    Attributes
    ----------
    end_time: float
        End of the flow time in SI unit.
    time_step: float
        Size of the time step between port communications in SI unit.
    use_mpi: bool
        If set to `True` use MPI otherwise use Python multiprocessing.

    '''

    # Preamble

    end_time = 1.0 * unit.hour
    time_step = 0.5 * unit.minute
    show_time = (True, 15 * unit.minute)

    use_mpi = False  # True for MPI; False for Python multiprocessing

    # System top level
    radlab = Cortix(use_mpi=use_mpi, splash=True)

    # Network
    radlab_net = radlab.network = Network()

    #from shutdown_params import shutdown_params
    #params = shutdown_params()

    # Create reactor module
    reactor = UMLRR()

    reactor.name = 'UMLRR'
    reactor.save = True
    reactor.time_step = time_step
    reactor.end_time = end_time
    reactor.show_time = show_time

    # Add reactor module to network
    radlab_net.module(reactor)

    # Create the network connectivity
    #radlab_net.connect( [reactor, 'none'], [none,'none'] )

    #*****************************************************************************

    radlab_net.draw()

    # Run network dynamics simulation
    radlab.run()

    plot_results = True

    if plot_results and (radlab.use_multiprocessing or radlab.rank == 0):

        # Reactor graphs
        reactor = radlab_net.modules[0]

        (quant, time_unit
         ) = reactor.reactor_phase.get_quantity_history('neutron-dens')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.formal_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('neutron-dens.png', dpi=300)

        (quant, time_unit
         ) = reactor.reactor_phase.get_quantity_history('delayed-neutrons-cc')
        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.formal_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('delayed-neutrons-cc.png', dpi=300)

        (quant,
         time_unit) = reactor.reactor_phase.get_quantity_history('fuel-temp')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.formal_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('fuel-temp.png', dpi=300)

        (quant,
         time_unit) = reactor.reactor_phase.get_quantity_history('power')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_scaling=1 / unit.kilo,
                   y_label=quant.formal_name + ' [' + 'k' + quant.unit + ']')
        plt.grid()
        plt.savefig('power.png', dpi=300)

        (quant, time_unit) = reactor.coolant_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.formal_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('cool-temp.png', dpi=300)

    # Properly shutdow radlab
    radlab.close()
Example #16
0
def main():

    # Debugging
    make_plots = True
    make_run   = True

    # Preamble
    end_time = 60*unit.minute
    time_step = 1.5*unit.second
    show_time = (True, 1*unit.minute)

    plant = Cortix(use_mpi=False, splash=True) # System top level

    plant_net = plant.network = Network() # Network

    # Reactor
    reactor = SMPWR()  # Create reactor module
    reactor.name = "SM-PWR"

    reactor.time_step = time_step
    reactor.end_time = end_time
    reactor.show_time = show_time

    # Steady state condition for NuScale case
    reactor.inflow_cool_temp = unit.convert_temperature(497,'F','K')

    reactor.shutdown = (True, 45*unit.minute)

    plant_net.module(reactor)  # Add reactor module to network

    # Balance of Plant Network Connectivity

    plant_net.draw(engine='circo', node_shape='folder')

    # Run
    if make_run:
        plant.run()  # Run network dynamics simulation

    plant.close()  # Properly shutdow Cortix

    # Plots
    if make_plots and plant.use_multiprocessing or plant.rank == 0:

        # Reactor plots
        reactor = plant_net.modules[0]

        (quant, time_unit) = reactor.neutron_phase.get_quantity_history('neutron-dens')
        #quant.plot(x_scaling=1/unit.minute, y_scaling=1/max(quant.value),
        quant.plot(x_scaling=1/unit.minute,
                   x_label='Time [m]', y_label=quant.latex_name+' ['+quant.unit+']')

        plt.grid()
        plt.savefig('reactor-neutron-dens.png', dpi=300)

        (quant, time_unit) = reactor.neutron_phase.get_quantity_history('delayed-neutrons-cc')
        quant.plot(x_scaling=1/unit.minute, x_label='Time [m]',
                   y_label=quant.latex_name+' ['+quant.unit+']')

        plt.grid()
        plt.savefig('reactor-delayed-neutrons-cc.png', dpi=300)

        (quant, time_unit) = reactor.coolant_outflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1/unit.minute, y_shift=273.15, x_label='Time [m]',
                   y_label=quant.latex_name+' [C]')

        plt.grid()
        plt.savefig('reactor-coolant-outflow-temp.png', dpi=300)

        (quant, time_unit) = reactor.state_phase.get_quantity_history('core-temp')

        quant.plot(x_scaling=1/unit.minute, y_shift=273.15, x_label='Time [m]',
                   y_label=quant.latex_name+' [C]')
        plt.grid()
        plt.savefig('reactor-core-temp.png', dpi=300)

        (quant, time_unit) = reactor.state_phase.get_quantity_history('power')

        quant.plot(x_scaling=1/unit.minute, y_scaling=1/unit.mega, x_label='Time [m]',
                   y_label=quant.latex_name+' [M'+quant.unit+']')
        plt.grid()
        plt.savefig('reactor-power.png', dpi=300)

        (quant, time_unit) = reactor.state_phase.get_quantity_history('reynolds')

        quant.plot(x_scaling=1/unit.minute, y_scaling=1/unit.mega, x_label='Time [m]',
                   y_label=quant.latex_name+r' [$\times 10^6$'+quant.unit+']')
        plt.grid()
        plt.savefig('reactor-reynolds.png', dpi=300)

        (quant, time_unit) = reactor.state_phase.get_quantity_history('prandtl')

        quant.plot(x_scaling=1/unit.minute, x_label='Time [m]',
                   y_label=quant.latex_name+r' ['+quant.unit+']')
        plt.grid()
        plt.savefig('reactor-prandtl.png', dpi=300)

        (quant, time_unit) = reactor.coolant_outflow_phase.get_quantity_history('flowrate')

        quant.plot(x_scaling=1/unit.minute, x_label='Time [m]',
                   y_label=quant.latex_name+r' ['+quant.unit+']')
        plt.grid()
        plt.savefig('reactor-mass-flowrate.png', dpi=300)

        (quant, time_unit) = reactor.state_phase.get_quantity_history('heatflux')

        quant.plot(x_scaling=1/unit.minute, y_scaling=1/unit.mega, x_label='Time [m]',
                   y_label=quant.latex_name+' [M'+quant.unit+']')
        plt.grid()
        plt.savefig('reactor-heatflux.png', dpi=300)

        (quant, time_unit) = reactor.state_phase.get_quantity_history('inlet-temp')

        quant.plot(x_scaling=1/unit.minute, y_shift=273.15, x_label='Time [m]',
                   y_label=quant.latex_name+' [C]')
        plt.grid()
        plt.savefig('reactor-coolant-inflow-temp.png', dpi=300)

        (quant, time_unit) = reactor.state_phase.get_quantity_history('nusselt')

        quant.plot(x_scaling=1/unit.minute, x_label='Time [m]',
                   y_label=quant.latex_name+' ['+quant.unit+']')
        plt.grid()
        plt.savefig('reactor-nusselt.png', dpi=300)

        (quant, time_unit) = reactor.state_phase.get_quantity_history('tau')

        quant.plot(x_scaling=1/unit.minute, x_label='Time [m]',
                   y_label=quant.latex_name+' ['+quant.unit+']')
        plt.grid()
        plt.savefig('reactor-coolant-tau.png', dpi=300)

        (quant, time_unit) = reactor.coolant_outflow_phase.get_quantity_history('quality')

        quant.plot(x_scaling=1/unit.minute, x_label='Time [m]',
                   y_label=quant.latex_name+r' ['+quant.unit+']')
        plt.grid()
        plt.savefig('reactor-coolant-outflow-quality.png', dpi=300)
Example #17
0
def main():
    '''Cortix run file for a criminal justice network.

    Attributes
    ----------
    n_groups : int
        Number of population groups being followed. This must be the same for all
        modules.
    end_time: float
        End of the flow time in SI unit.
    time_step: float
        Size of the time step between port communications in SI unit.
    use_mpi: bool
        If set to `True` use MPI otherwise use Python multiprocessing.

    '''

    # Configuration Parameters
    n_groups = 10  # number of population groups
    end_time = 30 * unit.year
    time_step = 1.0 * unit.day

    use_mpi = False  # True for MPI; False for Python multiprocessing

    city = Cortix(use_mpi=use_mpi, splash=True)

    city.network = Network()

    community = Community(n_groups=n_groups,
                          non_offender_adult_population=100000,
                          offender_pool_size=0)
    city.network.module(community)
    community.end_time = end_time
    community.time_step = time_step
    community.show_time = (True, 30 * unit.day)
    community.save = True

    prison = Prison(n_groups=n_groups, pool_size=0.0)
    city.network.module(prison)
    prison.end_time = end_time
    prison.time_step = time_step
    prison.save = True

    parole = Parole(n_groups=n_groups)
    city.network.module(parole)
    parole.end_time = end_time
    parole.time_step = time_step
    parole.save = True

    adjudication = Adjudication(n_groups=n_groups)
    city.network.module(adjudication)
    adjudication.end_time = end_time
    adjudication.time_step = time_step
    adjudication.save = True

    jail = Jail(n_groups=n_groups)
    city.network.module(jail)
    jail.end_time = end_time
    jail.time_step = time_step
    jail.save = True

    arrested = Arrested(n_groups=n_groups)
    city.network.module(arrested)
    arrested.end_time = end_time
    arrested.time_step = time_step
    arrested.save = True

    probation = Probation(n_groups=n_groups)
    city.network.module(probation)
    probation.end_time = end_time
    probation.time_step = time_step
    probation.save = True

    city.network.connect(prison, parole, 'bidirectional')
    city.network.connect(adjudication, prison)
    city.network.connect(jail, prison)
    city.network.connect(adjudication, jail)
    city.network.connect(arrested, jail)
    city.network.connect(arrested, adjudication)
    city.network.connect(arrested, probation)
    city.network.connect(probation, jail)
    city.network.connect(adjudication, probation)

    city.network.connect(arrested, community, 'bidirectional')
    city.network.connect(jail, community)
    city.network.connect(probation, community)
    city.network.connect(adjudication, community)
    city.network.connect(prison, community)
    city.network.connect(parole, community)

    city.network.draw()

    city.run()

    if city.use_multiprocessing or city.rank == 0:

        total_num_unknowns = n_groups * len(city.network.modules)
        total_num_params = 0

        # Inspect Data Function
        def inspect_module_data(module, quant_name):
            population_phase = module.population_phase
            (fxg_quant,
             time_unit) = population_phase.get_quantity_history(quant_name)

            fxg_quant.plot(x_scaling=1 / unit.year,
                           x_label='Time [y]',
                           y_label=fxg_quant.latex_name + ' [' +
                           fxg_quant.unit + ']')

            # Number of parameters in the prison model
            n_params = (len(population_phase.GetActors()) - 1) * n_groups
            return n_params

        quant_names = {
            'Prison': 'npg',
            'Parole': 'feg',
            'Adjudication': 'f*g',
            'Jail': 'fjg',
            'Arrested': 'frg',
            'Probation': 'fbg',
            'Community': 'f0g'
        }

        for m in city.network.modules:
            quant_name = quant_names[m.name]
            total_num_params += inspect_module_data(m, quant_name)
            plt.grid()
            plt.savefig(m.name + '.png', dpi=300)
            if m.name == 'Community':
                inspect_module_data(m, 'n0')
                plt.grid()
                plt.savefig(m.name + '-n0.png', dpi=300)

        # Total number of unknowns and parameters

        city.log.info('total number of unknowns   =' + str(total_num_unknowns))
        city.log.info('total number of parameters =' + str(total_num_params))

    # Properly shutdow city
    city.close()
Example #18
0
def main():
    """Balance of plant of a boiling water nuclear reactor.

    Attributes
    ----------
    end_time: float
        End of the flow time in SI unit.
    time_step: float
        Size of the time step between port communications in SI unit.
    use_mpi: bool
        If set to `True` use MPI otherwise use Python multiprocessing.

    """

    # Preamble

    end_time = 30.0 * unit.minute
    time_step = 30.0  # seconds
    show_time = (True, 5 * unit.minute)

    use_mpi = False  # True for MPI; False for Python multiprocessing
    plot_results = True  # True for enabling plotting section below
    params = get_params()  # parameters for BoP BWR

    #*****************************************************************************
    # Define Cortix system

    # System top level
    plant = Cortix(use_mpi=use_mpi, splash=True)

    # Network
    plant_net = plant.network = Network()

    params['start-time'] = 0.0
    params['end-time'] = end_time
    params['shutdown-time'] = 999.0 * unit.hour
    params['shutdown-mode'] = False
    #*****************************************************************************
    # Create reactor module
    reactor = BWR(params)

    reactor.name = 'BWR'
    reactor.save = True
    reactor.time_step = time_step
    reactor.end_time = end_time
    reactor.show_time = show_time
    reactor.RCIS = True

    # Add reactor module to network
    plant_net.module(reactor)

    #*****************************************************************************
    # Create turbine high pressure module
    params['turbine_inlet_pressure'] = 2
    params['turbine_outlet_pressure'] = 0.5
    params['high_pressure_turbine'] = True

    #params_turbine = reactor.params
    #params_turbine.inlet_pressure = 2
    #params.turbine_outlet_pressure = 0.5

    turbine_hp = Turbine(params)

    turbine_hp.name = 'High Pressure Turbine'
    turbine_hp.save = True
    turbine_hp.time_step = time_step
    turbine_hp.end_time = end_time

    # Add turbine high pressure module to network
    plant_net.module(turbine_hp)

    #*****************************************************************************
    # Create turbine low pressure module
    params['turbine_inlet_pressure'] = 0.5
    params['turbine_outlet_pressure'] = 0.005
    params['high_pressure_turbine'] = False
    params['steam flowrate'] = params['steam flowrate'] / 2

    turbine_lp1 = Turbine(params)

    turbine_lp1.name = 'Low Pressure Turbine 1'
    turbine_lp1.save = True
    turbine_lp1.time_step = time_step
    turbine_lp1.end_time = end_time

    plant_net.module(turbine_lp1)

    #*****************************************************************************
    # Create turbine low pressure module
    params['turbine_inlet_pressure'] = 0.5
    params['turbine_outlet_pressure'] = 0.005
    params['high_pressure_turbine'] = False

    turbine_lp2 = Turbine(params)

    turbine_lp2.name = 'Low Pressure Turbine 2'
    turbine_lp2.save = True
    turbine_lp2.time_step = time_step
    turbine_lp2.end_time = end_time

    plant_net.module(turbine_lp2)

    #*****************************************************************************
    # Create condenser module
    params['steam flowrate'] = params['steam flowrate'] * 2

    condenser = Condenser()

    condenser.name = 'Condenser'
    condenser.save = True
    condenser.time_step = time_step
    condenser.end_time = end_time

    plant_net.module(condenser)

    #*****************************************************************************
    params['RCIS-shutdown-time'] = 5 * unit.minute
    rcis = Cooler(params)
    rcis.name = 'RCIS'
    rcis.save = True
    rcis.time_step = time_step
    rcis.end_time = end_time

    plant_net.module(rcis)

    #*****************************************************************************
    # Create the BoP network connectivity
    plant_net.connect([reactor, 'coolant-outflow'], [turbine_hp, 'inflow'])
    plant_net.connect([turbine_hp, 'outflow-1'], [turbine_lp1, 'inflow'])
    plant_net.connect([turbine_hp, 'outflow-2'], [turbine_lp2, 'inflow'])
    plant_net.connect([turbine_lp1, 'outflow-1'], [condenser, 'inflow-1'])
    plant_net.connect([turbine_lp2, 'outflow-1'], [condenser, 'inflow-2'])
    plant_net.connect([condenser, 'outflow'], [reactor, 'coolant-inflow'])
    plant_net.connect([reactor, 'RCIS-outflow'], [rcis, 'coolant-inflow'])
    plant_net.connect([rcis, 'coolant-outflow'], [reactor, 'RCIS-inflow'])
    #plant_net.connect([rcis, 'signal-in'], [reactor, 'signal-out'])

    plant_net.draw(engine='dot', node_shape='folder')
    #*****************************************************************************
    # Run network dynamics simulation
    plant.run()

    #*****************************************************************************
    # Plot results

    if plot_results and (plant.use_multiprocessing or plant.rank == 0):

        # Reactor plots
        reactor = plant_net.modules[0]

        (quant, time_unit
         ) = reactor.neutron_phase.get_quantity_history('neutron-dens')
        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')

        plt.grid()
        plt.savefig('startup-neutron-dens.png', dpi=300)

        (quant, time_unit
         ) = reactor.neutron_phase.get_quantity_history('delayed-neutrons-cc')
        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')

        plt.grid()
        plt.savefig('startup-delayed-neutrons-cc.png', dpi=300)

        (quant, time_unit
         ) = reactor.coolant_outflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')

        plt.grid()
        plt.savefig('startup-coolant-outflow-temp.png', dpi=300)

        (quant,
         time_unit) = reactor.reactor_phase.get_quantity_history('fuel-temp')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('startup-fuel-temp.png', dpi=300)

        # Turbine high pressure plots
        turbine_hp = plant_net.modules[1]

        (quant,
         time_unit) = turbine_hp.outflow_phase.get_quantity_history('power')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']',
                   title='High Pressure Turbine Power')
        plt.grid()
        plt.savefig('startup-turbine-hp-power.png', dpi=300)

        (quant,
         time_unit) = turbine_hp.outflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']',
                   title='High Pressure Turbine Outflow Temperature')
        plt.grid()
        plt.savefig('startup-turbine-hp-outflow-temp.png', dpi=300)

        # Turbine low pressure graphs
        turbine_lp1 = plant_net.modules[2]

        (quant,
         time_unit) = turbine_lp1.outflow_phase.get_quantity_history('power')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']',
                   title='Lower Pressure Turbine 1 Power')
        plt.grid()
        plt.savefig('startup-turbine-lp1-power.png', dpi=300)

        (quant,
         time_unit) = turbine_lp1.outflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']',
                   title='Lower Pressure Turbine 1 Outflow Temperature')
        plt.grid()
        plt.savefig('startup-turbine-lp1-outflow-temp.png', dpi=300)

        # Condenser graphs
        condenser = plant_net.modules[3]

        (quant,
         time_unit) = condenser.outflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('startup-condenser-outflow-temp.png', dpi=300)

    #setup initial values for simulation
    turbine1_outflow_temp = turbine_hp.outflow_phase.get_value(
        'temp', end_time)
    turbine1_chi = turbine_hp.outflow_phase.get_value('quality', end_time)
    turbine1_power = turbine_hp.outflow_phase.get_value('power', end_time)

    turbine2_outflow_temp = turbine_lp1.outflow_phase.get_value(
        'temp', end_time)
    turbine2_chi = turbine_lp1.outflow_phase.get_value('quality', end_time)
    turbine2_power = turbine_lp1.outflow_phase.get_value('power', end_time)

    condenser_runoff_temp = condenser.outflow_phase.get_value('temp', end_time)

    delayed_neutron_cc = reactor.neutron_phase.get_value(
        'delayed-neutrons-cc', end_time)
    n_dens = reactor.neutron_phase.get_value('neutron-dens', end_time)
    fuel_temp = reactor.reactor_phase.get_value('fuel-temp', end_time)
    coolant_temp = reactor.coolant_outflow_phase.get_value('temp', end_time)
    # Values loaded into params when they are needed (module instantiation)

    # Properly shutdown simulation
    plant.close()

    # Now we run shutdown as a seperate simulation with starting parameters equal to the ending
    # values of the startup simulation

    #**************************************************************************************************

    # Preamble

    start_time = 0.0 * unit.minute
    end_time = 60 * unit.minute
    time_step = 30.0  # seconds
    show_time = (True, 5 * unit.minute)

    use_mpi = False  # True for MPI; False for Python multiprocessing
    plot_results = True  # True for enabling plotting section below
    params = get_params()  # clear params, just to be safe

    #*****************************************************************************
    # Define Cortix system

    # System top level
    plant = Cortix(use_mpi=use_mpi, splash=True)

    # Network
    plant_net = plant.network = Network()

    params['start-time'] = start_time
    params['end-time'] = end_time
    params['shutdown time'] = 0.0
    params['shutdown-mode'] = True

    #*****************************************************************************
    # Create reactor module
    params['delayed-neutron-cc'] = delayed_neutron_cc
    params['n-dens'] = n_dens
    params['fuel-temp'] = fuel_temp
    params['coolant-temp'] = coolant_temp
    params['operating-mode'] = 'shutdown'
    reactor = BWR(params)

    reactor.name = 'BWR'
    reactor.save = True
    reactor.time_step = time_step
    reactor.end_time = end_time
    reactor.show_time = show_time
    reactor.RCIS = False

    # Add reactor module to network
    plant_net.module(reactor)

    #*****************************************************************************
    # Create turbine high pressure module
    params['turbine_inlet_pressure'] = 2
    params['turbine_outlet_pressure'] = 0.5
    params['high_pressure_turbine'] = True
    params['turbine-outflow-temp'] = turbine1_outflow_temp
    params['turbine-chi'] = turbine1_chi
    params['turbine-work'] = turbine1_power
    params['turbine-inflow-temp'] = coolant_temp

    #params_turbine = reactor.params
    #params_turbine.inlet_pressure = 2
    #params.turbine_outlet_pressure = 0.5

    turbine_hp = Turbine(params)

    turbine_hp.name = 'High Pressure Turbine'
    turbine_hp.save = True
    turbine_hp.time_step = time_step
    turbine_hp.end_time = end_time

    # Add turbine high pressure module to network
    plant_net.module(turbine_hp)

    #*****************************************************************************
    # Create turbine low pressure 1 module
    params['turbine_inlet_pressure'] = 0.5
    params['turbine_outlet_pressure'] = 0.005
    params['high_pressure_turbine'] = False
    params['steam flowrate'] = params['steam flowrate'] / 2
    params['turbine-outflow-temp'] = turbine2_outflow_temp
    params['turbine-inflow-temp'] = turbine1_outflow_temp
    params['turbine-chi'] = turbine2_chi
    params['turbine-work'] = turbine2_power

    turbine_lp1 = Turbine(params)

    turbine_lp1.name = 'Low Pressure Turbine 1'
    turbine_lp1.save = True
    turbine_lp1.time_step = time_step
    turbine_lp1.end_time = end_time

    plant_net.module(turbine_lp1)

    #*****************************************************************************
    # Create turbine low pressure 2 module
    params['turbine_inlet_pressure'] = 0.5
    params['turbine_outlet_pressure'] = 0.005
    params['high_pressure_turbine'] = False

    turbine_lp2 = Turbine(params)

    turbine_lp2.name = 'Low Pressure Turbine 2'
    turbine_lp2.save = True
    turbine_lp2.time_step = time_step
    turbine_lp2.end_time = end_time

    plant_net.module(turbine_lp2)

    #*****************************************************************************
    # Create condenser module
    params['steam flowrate'] = params['steam flowrate'] * 2
    params['condenser-runoff-temp'] = condenser_runoff_temp
    condenser = Condenser()

    condenser.name = 'Condenser'
    condenser.save = True
    condenser.time_step = time_step
    condenser.end_time = end_time

    plant_net.module(condenser)

    #*****************************************************************************
    params['RCIS-shutdown-time'] = -1 * unit.minute
    rcis = Cooler(params)
    rcis.name = 'RCIS'
    rcis.save = True
    rcis.time_step = time_step
    rcis.end_time = end_time

    plant_net.module(rcis)

    #*****************************************************************************
    # Create the BoP network connectivity
    plant_net.connect([reactor, 'coolant-outflow'], [turbine_hp, 'inflow'])
    plant_net.connect([turbine_hp, 'outflow-1'], [turbine_lp1, 'inflow'])
    plant_net.connect([turbine_hp, 'outflow-2'], [turbine_lp2, 'inflow'])
    plant_net.connect([turbine_lp1, 'outflow-1'], [condenser, 'inflow-1'])
    plant_net.connect([turbine_lp2, 'outflow-1'], [condenser, 'inflow-2'])
    plant_net.connect([condenser, 'outflow'], [reactor, 'coolant-inflow'])
    plant_net.connect([reactor, 'RCIS-outflow'], [rcis, 'coolant-inflow'])
    plant_net.connect([rcis, 'coolant-outflow'], [reactor, 'RCIS-inflow'])
    #plant_net.connect([rcis, 'signal-in'], [reactor, 'signal-out'])

    plant_net.draw(engine='dot', node_shape='folder')
    #*****************************************************************************
    # Run network dynamics simulation
    plant.run()

    #*****************************************************************************
    # Plot results

    if plot_results and (plant.use_multiprocessing or plant.rank == 0):

        # Reactor plots
        reactor = plant_net.modules[0]

        (quant, time_unit
         ) = reactor.neutron_phase.get_quantity_history('neutron-dens')
        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')

        plt.grid()
        plt.savefig('shutdown-neutron-dens.png', dpi=300)

        (quant, time_unit
         ) = reactor.neutron_phase.get_quantity_history('delayed-neutrons-cc')
        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')

        plt.grid()
        plt.savefig('shutdown-delayed-neutrons-cc.png', dpi=300)

        (quant, time_unit
         ) = reactor.coolant_outflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')

        plt.grid()
        plt.savefig('shutdown-coolant-outflow-temp.png', dpi=300)

        (quant,
         time_unit) = reactor.reactor_phase.get_quantity_history('fuel-temp')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('shutdown-fuel-temp.png', dpi=300)

        # Turbine high pressure plots
        turbine_hp = plant_net.modules[1]

        (quant,
         time_unit) = turbine_hp.outflow_phase.get_quantity_history('power')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']',
                   title='High Pressure Turbine Power')
        plt.grid()
        plt.savefig('shutdown-turbine-hp-power.png', dpi=300)

        (quant,
         time_unit) = turbine_hp.outflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']',
                   title='High Pressure Turbine Outflow Temperature')
        plt.grid()
        plt.savefig('shutdown-turbine-hp-outflow-temp.png', dpi=300)

        # Turbine low pressure graphs
        turbine_lp1 = plant_net.modules[2]

        (quant,
         time_unit) = turbine_lp1.outflow_phase.get_quantity_history('power')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']',
                   title='Lower Pressure Turbine 1 Power')
        plt.grid()
        plt.savefig('shutdown-turbine-lp1-power.png', dpi=300)

        (quant,
         time_unit) = turbine_lp1.outflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']',
                   title='Lower Pressure Turbine 1 Outflow Temperature')
        plt.grid()
        plt.savefig('shutdown-turbine-lp1-outflow-temp.png', dpi=300)

        # Condenser graphs
        condenser = plant_net.modules[4]

        (quant,
         time_unit) = condenser.outflow_phase.get_quantity_history('temp')

        quant.plot(x_scaling=1 / unit.minute,
                   x_label='Time [m]',
                   y_label=quant.latex_name + ' [' + quant.unit + ']')
        plt.grid()
        plt.savefig('shutdown-condenser-outflow-temp.png', dpi=300)

    # Shutdown The Simulation
    plant.close()