if (nprocs_realm != NProcs): print("ERROR: ", "Number of processes is not coherent.", file=sys.stderr) MPI.COMM_WORLD.Abort(errorcode=1) # Create cartesian communicator and initialize cpllib.set_timing(0, nsteps, dt) cart_comm = realm_comm.Create_cart([NPx, NPy, NPz]) cpllib.setup_cfd(cart_comm, xyzL, xyz_orig, ncxyz) my_coords = cart_comm.Get_coords(cart_comm.Get_rank()) my_coords = np.array(my_coords, order='F', dtype=np.int32) olap_limits = cpllib.get_olap_limits() # Constrained region cell limits and number of cells cnstFRegion = cpllib.get_cnst_limits() cnstFPortion = cpllib.my_proc_portion(cnstFRegion) [cnstncx, cnstncy, cnstncz] = cpllib.get_no_cells(cnstFPortion) # Velocity averaging region cell limits and number of cells velBCRegion = np.copy(olap_limits) velBCRegion[3] = velBCRegion[2] velBCPortion = cpllib.my_proc_portion(velBCRegion) [velBCncx, velBCncy, velBCncz] = cpllib.get_no_cells(velBCPortion) # Send dummy random stress distribution (constant value of stress = 0) to MD np.random.seed(1000) send_array = 5 * np.array(np.random.rand(9, cnstncx, cnstncy, cnstncz), order='F', dtype=np.float64) # Receive averaged velocities from LAMMPS socket recv_array = np.zeros((4, velBCncx, velBCncy, velBCncz), order='F',
nprocs_realm = realm_comm.Get_size() if (nprocs_realm != NProcs): print("ERROR: ", "Number of processes is not coherent.", file=sys.stderr) MPI.COMM_WORLD.Abort(errorcode=1) # Create cartesian communicator and initialize cart_comm = realm_comm.Create_cart([NPx, NPy, NPz]) CPL.setup_cfd(nsteps, dt, cart_comm, xyzL, xyz_orig, ncxyz, 1.0) my_coords = cart_comm.Get_coords(cart_comm.Get_rank()) my_coords = np.array(my_coords, order='F', dtype=np.int32) olap_limits = CPL.get_olap_limits() # Constrained region cell limits and number of cells cnstFRegion = CPL.get_cnst_limits() cnstFPortion = CPL.my_proc_portion(cnstFRegion) [cnstncx, cnstncy, cnstncz] = CPL.get_no_cells(cnstFPortion) # Velocity averaging region cell limits and number of cells velBCRegion = np.copy(olap_limits) velBCRegion[3] = velBCRegion[2] velBCPortion = CPL.my_proc_portion(velBCRegion) [velBCncx, velBCncy, velBCncz] = CPL.get_no_cells(velBCPortion) # Send dummy stress distribution (constant value of stress = 0) to MD scatter_array = np.random.rand(9, cnstncx, cnstncy, cnstncz) recv_array = np.zeros((9, 0, 0, 0), order='F', dtype=np.float64) CPL.scatter(scatter_array, cnstFRegion, recv_array)
def CFD(xyzL=[1.5E-003, 1.5E-003, 2.50E-003], g=9.81, ncxyz=[8, 8, 8], npxyz=[1, 1, 1], Nsteps=101): #initialise MPI and CPL comm = MPI.COMM_WORLD CPL = CPL() MD_COMM = CPL.init(CPL.CFD_REALM) nprocs_realm = MD_COMM.Get_size() ## Parameters of the cpu topology (cartesian grid) npxyz = np.array(npxyz, order='F', dtype=np.int32) NProcs = np.product(npxyz) xyzL = np.array(xyz, order='F', dtype=np.float64) xyz_orig = np.array([0.0, 0.0, 0.0], order='F', dtype=np.float64) ncxyz = np.array(ncxyz, order='F', dtype=np.int32) if (nprocs_realm != NProcs): print("Non-coherent number of processes in MD ", nprocs_realm, " no equal to ", npxyz[0], " X ", npxyz[1], " X ", npxyz[2]) MPI.Abort(errorcode=1) #Setup coupled simulation cart_comm = MD_COMM.Create_cart([npxyz[0], npxyz[1], npxyz[2]]) CPL.setup_cfd(cart_comm, xyzL, xyz_orig, ncxyz) #Get constraint region cnst_limits = CPL.get_cnst_limits() cnst_portion = CPL.my_proc_portion(cnst_limits) [cnst_ncxl, cnst_ncyl, cnst_nczl] = CPL.get_no_cells(cnst_portion) #Get overlap region olap_limits = CPL.get_olap_limits() BC_limits = np.array([ olap_limits[0], olap_limits[1], olap_limits[2], olap_limits[3], olap_limits[4], olap_limits[5] ], dtype=np.int32) BC_portion = CPL.my_proc_portion(BC_limits) [BC_ncxl, BC_ncyl, BC_nczl] = CPL.get_no_cells(BC_portion) #Allocate send and recv arrays recv_array = np.zeros((4, BC_ncxl, BC_ncyl, BC_nczl), order='F', dtype=np.float64) send_array = np.zeros((9, cnst_ncxl, cnst_ncyl, cnst_nczl), order='F', dtype=np.float64) for time in range(Nsteps): # send data to update send_array[2, :, :, :] = -5.9490638385009208e-08 * g # * mi CPL.send(send_array, cnst_portion) # recv data and plot recv_array, ierr = CPL.recv(recv_array, BC_portion) print(time) CPL.finalize() MPI.Finalize()
MPI.Abort(errorcode=1) # Parameters of the cpu topology (cartesian grid) npxyz = [1, 1, 1] xyzL = np.array([2., 2., 2.], order='F', dtype=np.float64) xyz_orig = np.array([0.0, 0.0, 0.0], order='F', dtype=np.float64) #initialise CPL CPL = CPL() MD_COMM = CPL.init(CPL.MD_REALM) #CPL.set_timing(0, 0, dt) CPL.setup_md(MD_COMM.Create_cart([npxyz[0], npxyz[1], npxyz[2]]), xyzL, xyz_orig) #Setup send and recv buffers cnst_limits = CPL.get_cnst_limits() cnst_portion = CPL.my_proc_portion(cnst_limits) [cnst_ncxl, cnst_ncyl, cnst_nczl] = CPL.get_no_cells(cnst_portion) recvbuf = np.zeros((9, cnst_ncxl, cnst_ncyl, cnst_nczl), order='F', dtype=np.float64) olap_limits = CPL.get_olap_limits() BC_limits = np.array([ olap_limits[0], olap_limits[1], olap_limits[2], olap_limits[3], olap_limits[4], olap_limits[5] ], order='F', dtype=np.int32) BC_portion = CPL.my_proc_portion(BC_limits) [BC_ncxl, BC_ncyl, BC_nczl] = CPL.get_no_cells(BC_portion)
realm_comm = lib.init (CPL.MD_REALM) nprocs_realm = realm_comm.Get_size() if (nprocs_realm != NProcs): print("ERROR: ", "Number of processes is not coherent.", file=sys.stderr) MPI.Abort() # Create cartesian communicator and initialize cart_comm = realm_comm.Create_cart([NPx, NPy, NPz]) nsteps, initial_step = lib.setup_md (dt, cart_comm, xyzL, xyz_orig, 1.0) my_coords = cart_comm.Get_coords(cart_comm.Get_rank()) my_coords = np.array(my_coords, order='F', dtype=np.int32) olap_limits = lib.get_olap_limits() # Constrained region cell limits and number of cells cnstFRegion = lib.get_cnst_limits() cnstFPortion = lib.my_proc_portion(cnstFRegion) [cnstncx, cnstncy, cnstncz] = lib.get_no_cells(cnstFPortion) # Velocity averaging region cell limits and number of cells velBCRegion = np.copy(olap_limits) velBCRegion[3] = velBCRegion[2] velBCPortion = lib.my_proc_portion(velBCRegion) [velBCncx, velBCncy, velBCncz] = lib.get_no_cells(velBCPortion) for step in xrange(nsteps): # Send dummy stress distribution (constant value of stress = 0) to MD send_array = np.zeros((9, 0, 0, 0), order='F', dtype=np.float64) recv_array = np.ones((9, cnstncx, cnstncy, cnstncz), order='F', dtype=np.float64) lib.scatter(send_array, cnstFRegion, recv_array) #if (cnstFPortion[2] >= 0):