room.send_walls(wall, comm, to_whom=1, tag=i) # wait for reply from room 1 room.receive_walls(comm, from_whom=1, tag=i) else: # wait for solution from rooms 0 and 2 room.receive_walls(comm, from_whom=0, tag=i) room.receive_walls(comm, from_whom=2, tag=i) room.solve() wall = (room[:N, 0] - room[0:N, 1]) / DX room.send_walls(wall, comm, to_whom=0, tag=i) wall = (room[N:, -1] - room[N:, -2]) / DX room.send_walls(wall, comm, to_whom=2, tag=i) if rank == 0 or rank == 2: comm.Send(room.u, dest=1, tag=99) elif rank == 1: # combine walls at the end room0 = np.empty((N, N)) room2 = np.empty((N, N)) comm.Recv(room0, source=0, tag=99) comm.Recv(room2, source=2, tag=99) whole_apartment = combine_rooms(room0, room, room2) plt.imshow(whole_apartment, origin='lower') plt.colorbar() plt.show()
u1[-1, :] += 15 u1[:, 0] += 15 u1[:, -1] += 15 # third room u2 = np.zeros((n, n)) u2[0, :] += 15 u2[-1, :] += 15 u2[:, 0] += -1 u2[:, -1] += 40 # plot rooms u = combine_rooms(u0, u1, u2) plt.figure() plt.imshow(u, origin='lower') plt.colorbar() u0 = linalg.spsolve(A0, -u0.flatten()).reshape(u0.shape) u1 = linalg.spsolve(A1, -u1.flatten()).reshape(u1.shape) u2 = linalg.spsolve(A2, -u2.flatten()).reshape(u2.shape) u = combine_rooms(u0, u1, u2) plt.figure() plt.imshow(u, origin='lower') plt.colorbar() plt.show()