def main(): ''' Description of the run file. ''' # Parameters time_step = 0.1 ir_7040 = Cortix(splash=True) ir_7040.network = Network() ir_7040_net = ir_7040.network # DADOS module. dados = Dados() ir_7040_net.module(dados) dados.rs232_filename = 'ir-7040' dados.rs232_request_string = '\r\nP0001 01245689BCDMNVWYZaOdghin 55}' # DataPlot module. data_plot = DataPlot() data_plot.title = 'IR-7040 Data Acquisition' data_plot.dpi = 300 # Network connectivity ir_7040_net.connect( [dados,'rs-232'], [data_plot,'viz-data'] ) rs232_port.connect(plot_port) ir_7040_net.draw() # Run application ir_7040.run()
def run(self): for c,i in enumerate(self.n_list): self.cortix = Cortix(use_mpi=False) self.net = Network() self.cortix.network = self.net self.plot = Plot(self.shape,modules=self.procs,runtime=self.runtime) self.plot.fps = self.fps self.net.add_module(self.plot) print(c,'iterations') self.balls = i self.balleach = int(self.balls/self.procs) self.mod_list = [] for i in range(self.procs): if i <5: app = BallHandler(self.shape, balls=self.balleach,runtime = self.runtime,bn=[2,2,28,28],color='r') if i>=5: app = BallHandler(self.shape, balls=self.balleach,runtime = self.runtime,bn=[43,-38,83,-22],color='b') 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]) self.cortix.run() del self.cortix print('finished sim')
class Simulation: def __init__(self): self.n_list = [15,] self.procs = 15 self.runtime=30 self.t_step = 0.01 self.r=1 self.mod_list = [] self.shape = geo.Polygon([(0, 0), (0, 100), (100, 100),(100,0)]) self.fps = 60 def run(self): for c,i in enumerate(self.n_list): self.cortix = Cortix(use_mpi=False) self.net = Network() self.cortix.network = self.net self.plot = Plot(self.shape,modules=self.procs,runtime=self.runtime) self.plot.fps = self.fps self.net.add_module(self.plot) print(c,'iterations') self.balls = i self.balleach = int(self.balls/self.procs) self.mod_list = [] for i in range(self.procs): app = BallHandler(self.shape, balls=self.balleach,runtime = self.runtime) app.r=self.r 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]) self.cortix.run() del self.cortix print('finished sim')
def test_cortix_add_module(): # Init the Cortix object c = Cortix() c.network = Network() num_modules = 100 module_list = list() # Add 100 modules to the Cortix object for i in range(num_modules): # Initialize the module m = DummyModule() c.network.add_module(m) # Get ports p1 = m.get_port('test1-{}'.format(i)) p2 = m.get_port('test2-{}'.format(i)) # Make sure we have the correct modules assert len(c.network.modules) == num_modules for mod in c.network.modules: assert isinstance(mod, Module) assert len(mod.ports) == 2
def __init__(self): ## self.filename = 'ideal_gas_simulation.csv' ## if os.path.isfile(self.filename): ## print('file exits') ## with open(self.filename,'w') as file: ## file.write('Number,Collisions/Sec\n') n_list = [15, 30, 15, 60, 75, 500, 600, 1200, 2400, 3200, 4200, 5400] for i in n_list: print('starting:', i, 'balls') procs = 15 runtime = 0.5 balls = int(i / procs) cortix = Cortix(use_mpi=False) mod_list = [] shape = geo.box(-30, 0, 30, 50) plot = Plot(number=i, modules=10, runtime=runtime) cortix.add_module(plot) for i in range(procs): time.sleep(0.01) app = BallHandler(shape, balls=balls, runtime=runtime) app.v0 = [40, 40] app.r = 0.1 mod_list.append(app) cortix.add_module(app) for c, i in enumerate(mod_list): i.connect('plot-send{}'.format(c), plot.get_port('plot-receive{}'.format(c))) for j in mod_list: if i == j: continue name = '{}{}'.format(i.timestamp, j.timestamp) name2 = '{}{}'.format(j.timestamp, i.timestamp) j.connect(name, i.get_port(name2)) cortix.run() time.sleep(5)
Run with nprocs = 2*n_droplets + 1 vortex + 1 cortix processes Usage: mpirun -np nprocs run_droplet_multi_plot.py ''' if __name__ == "__main__": # Parameters n_droplets = 3 end_time = 300 time_step = 0.1 cortix = Cortix(use_mpi=True) # Vortex module (single). vortex = Vortex() vortex.show_time = (True,100) vortex.end_time = end_time vortex.time_step = time_step vortex.plot_velocity() for i in range(n_droplets): # Droplet modules. droplet = Droplet() droplet.end_time = end_time droplet.time_step = time_step droplet.bounce = False
from cortix.src.module import Module from cortix.src.port import Port from cortix.util.dataplot import DataPlot from cortix.src.cortix_main import Cortix from dados import Dados ''' Cortix run file for DADOS using the IR-7040 gas ratemeter RS-232 interface. ''' if __name__ == "__main__": # Parameters time_step = 0.1 cortix = Cortix(use_mpi=False) # DADOS module. dados = Dados() # Port def. rs232_port = Port('rs-232') dados.add_port(rs232_port) dados.rs232_filename = 'ir-7040' dados.rs232_request_string = '\r\nP0001 01245689BCDMNVWYZaOdghin 55}' # DataPlot module. data_plot = DataPlot() data_plot.title = 'IR-7040 Data Acquisition' data_plot.dpi = 300 # Port def. plot_port = Port('viz-data')
messengerlis = self.recv(i) for messenger in messengerlis: ball_list.append(messenger) for ball in self.local_balls: ball.messenger.collision = [] for i in self.ports: #Send 'done' string to plot module as end condition if 'plot' in str(i): self.send('done', i) print('Time Elapsed: ', self.elapsed) print('Done') if __name__ == '__main__': cortix = Cortix(use_mpi=False) mod_list = [] shape = geo.box(-30, 0, 30, 50) plot = Plot(shape=shape, modules=10) plot.fps = 10 cortix.add_module(plot) for i in range(10): time.sleep(0.01) app = BallHandler(shape, balls=10, runtime=1) mod_list.append(app) cortix.add_module(app) for c, i in enumerate(mod_list): i.connect('plot-send{}'.format(c),
def test_ball(): cortix = Cortix(use_mpi=False) secs = 4 mod_list = [] shape = geo.box(-30, 0, 30, 50) plot = Plot(shape=shape, length=2) cortix.add_module(plot) ball1 = BouncingBall(shape, runtime=secs) ball1.p0 = [0, 20] ball1.v0 = [20, 4] mod_list.append(ball1) cortix.add_module(ball1) time.sleep(0.01) ball2 = BouncingBall(shape, runtime=secs) ball2.p0 = [17, 22] ball2.v0 = [-5, 1] mod_list.append(ball2) cortix.add_module(ball2) for c, i in enumerate(mod_list): i.connect('plot-send{}'.format(c), plot.get_port('plot-receive{}'.format(c))) for j in mod_list: if i == j: continue name = '{}{}'.format(i.timestamp, j.timestamp) name2 = '{}{}'.format(j.timestamp, i.timestamp) j.connect(name, i.get_port(name2)) cortix.draw_network('network_graph.png') cortix.run() print('bye')