def test_loop(setup, time): #Get run paramenters from setup CPL, MD_COMM, recvbuf, sendbuf, CAObj, dt, U, nu = setup # Recv data: # [Ux, Uy, Uz, gradPx, gradPy, gradPz, divTaux, divTauy, divTauz] recvbuf, ierr = CPL.recv(recvbuf) # Zero send buffer and set porosity to one # [Ux, Uy, Uz, Fx, Fy, Fz, Cd, e] sendbuf[...] = 0. CPL.send(sendbuf) #Get analytical solution y_anal, u_anal = CAObj.get_vprofile(time*dt) #Assert error bounds for L2 norm ur = np.mean(recvbuf[0,:,:,:],(0,2)) error = np.sum(np.abs(100*(u_anal[1:-1:2] - ur)/U)) print(time, "Error = ", error) if time < 10: assert error < 20., "Error in inital 10 steps greater than 20%" elif time < 30: assert error < 10., "Error between 10 and 30 steps greater than 10%" elif time < 50: assert error < 5., "Error between 30 and 50 steps greater than 5%" elif time < 300: assert error < 3., "Error between 50 and 300 steps greater than 3%" elif time < 500: assert error < 2., "Error between 300 and 500 steps greater than 2%" else: assert error < 1., "Error after 500 steps greater than 1%"
def __init__(self, npxyz, xyzL, xyz_orig, ncxyz): #initialise MPI and CPL self.comm = MPI.COMM_WORLD self.CPL = CPL() self.CFD_COMM = self.CPL.init(CPL.CFD_REALM) self.nprocs_realm = self.CFD_COMM.Get_size() # Parameters of the cpu topology (cartesian grid) self.npxyz = np.array(npxyz, order='F', dtype=np.int32) self.NProcs = np.product(npxyz) self.xyzL = np.array(xyzL, order='F', dtype=np.float64) self.xyz_orig = np.array(xyz_orig, order='F', dtype=np.float64) self.ncxyz = np.array(ncxyz, order='F', dtype=np.int32) if (self.nprocs_realm != self.NProcs): print("Non-coherent number of processes in CFD ", self.nprocs_realm, " no equal to ", self.npxyz[0], " X ", self.npxyz[1], " X ", self.npxyz[2]) MPI.Abort(errorcode=1) #Setup coupled simulation self.cart_comm = self.CFD_COMM.Create_cart( [self.npxyz[0], self.npxyz[1], self.npxyz[2]]) self.CPL.setup_cfd(self.cart_comm, self.xyzL, self.xyz_orig, self.ncxyz) #Get limits of overlap region self.olap_limits = self.CPL.get_olap_limits() self.portion = self.CPL.my_proc_portion(self.olap_limits) [self.ncxl, self.ncyl, self.nczl] = self.CPL.get_no_cells(self.portion) self.dx = self.CPL.get("xl_cfd") / float(self.CPL.get("ncx")) self.dy = self.CPL.get("yl_cfd") / float(self.CPL.get("ncy")) self.dz = self.CPL.get("zl_cfd") / float(self.CPL.get("ncz")) self.ioverlap = (self.CPL.get("icmax_olap") - self.CPL.get("icmin_olap") + 1) self.joverlap = (self.CPL.get("jcmax_olap") - self.CPL.get("jcmin_olap") + 1) self.koverlap = (self.CPL.get("kcmax_olap") - self.CPL.get("kcmin_olap") + 1) self.xoverlap = self.ioverlap * self.dx self.yoverlap = self.joverlap * self.dy self.zoverlap = self.koverlap * self.dz
def setup(): #Import CPL library from cplpy import CPL #initialise MPI from mpi4py import MPI comm = MPI.COMM_WORLD #Check run as part of a coupled run comm.rank # Parameters of the cpu topology (cartesian grid) npxyz = np.array([1, 1, 1], order='F', dtype=np.int32) xyzL = np.array([1., 1., 1.], 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.setup_md(MD_COMM.Create_cart([npxyz[0], npxyz[1], npxyz[2]]), xyzL, xyz_orig) recvbuf, sendbuf = CPL.get_arrays(recv_size=9, send_size=8) #Analytical solution dt = 0.05 U = 1.0 nu = 1.004e-2 Re = xyzL[1]/nu #Note Reynolds in independent of velocity in analytical fn ncx = CPL.get("ncx") ncy = CPL.get("ncy") ncz = CPL.get("ncz") CAObj = CA(Re=Re, U=U, Lmin=0., Lmax=xyzL[1], npoints=2*ncy+1, nmodes=100*ncy) #Yield statement delineates end of setup and start of teardown yield [CPL, MD_COMM, recvbuf, sendbuf, CAObj, dt, U, nu] CPL.finalize() MPI.Finalize()
#!/usr/bin/env python2 from __future__ import print_function, division import sys import cPickle try: from mpi4py import MPI from cplpy import CPL import numpy as np except ImportError as exc: print("ERROR: ", sys.exc_info()[0], exc, file=sys.stderr) MPI.COMM_WORLD.Abort(errorcode=1) cpllib = CPL() cpllib.set("output_mode", 1) try: # Load parameters for the run params = cPickle.load(open("md_params.dic", "rb")) # Parameters of the cpu topology (cartesian grid) NPx = params["npx"] NPy = params["npy"] NPz = params["npz"] # Parameters of the domain Lx = params["lx"] Ly = params["ly"] Lz = params["lz"] except:
#!/usr/bin/env python2 from __future__ import print_function, division from mpi4py import MPI from cplpy import CPL import numpy as np import cPickle import sys comm_world = MPI.COMM_WORLD CPL = CPL() # Do not show any info to the stdin CPL.set("output_mode", 0) # Load parameters for the run params = cPickle.load(open("cfd_params.dic", "rb")) # Test selector flag try: which_test = params["which_test"] except: print("ERROR: ", sys.exc_info()[0], file=sys.stderr) comm_world.Abort(errorcode=1) # Parameters of the cpu topology (cartesian grid) try: NPx = params["npx"] NPy = params["npy"] NPz = params["npz"] except: print("ERROR: ", sys.exc_info()[0], file=sys.stderr)
rhof = mObj.fluid_density dp = mObj.diameter rhop = mObj.density g = -mObj.gravity Vc = ((xyzL[0]-xyz_orig[0])/ncxyz[0])*((xyzL[1]-xyz_orig[1])/ncxyz[1])*((xyzL[2]-xyz_orig[2])/ncxyz[2]) epsf = (Vc - (np.pi/6)*(dp**3))/Vc # Initialise drag force object fObj = Stokes(muf=muf, dp=dp, epsf=epsf) # initialise MPI comm = MPI.COMM_WORLD # Initialise CPL CPL = CPL() CFD_COMM = CPL.init(CPL.CFD_REALM) cart_comm = CFD_COMM.Create_cart([npxyz[0], npxyz[1], npxyz[2]]) CPL.setup_cfd(cart_comm, xyzL, xyz_orig, ncxyz) # Setup send and recv buffers recvbuf, sendbuf = CPL.get_arrays(recv_size=8, send_size=9) # Main time loop for time in range(400): # print(time) if time == 0: Vp = 0. # Send data: Zero send buffer. Set only the fluid velocity and gradP in the
import numpy as np import matplotlib.pyplot as plt from mpi4py import MPI from cplpy import CPL from draw_grid import draw_grid from cfd_oo import CFD #initialise MPI and CPL comm = MPI.COMM_WORLD CPL = CPL() CFD_COMM = CPL.init(CPL.CFD_REALM) nprocs_realm = CFD_COMM.Get_size() # Parameters of the cpu topology (cartesian grid) npxyz = np.array([1, 1, 1], order='F', dtype=np.int32) NProcs = np.product(npxyz) xyzL = np.array([6.70820393, 17.88854382, 1.0], order='F', dtype=np.float64) xyz_orig = np.array([0.0, 0.0, 0.0], order='F', dtype=np.float64) ncxyz = np.array([8, 8, 1], order='F', dtype=np.int32) if (nprocs_realm != NProcs): print("Non-coherent number of processes in CFD ", nprocs_realm, " no equal to ", npxyz[0], " X ", npxyz[1], " X ", npxyz[2]) MPI.Abort(errorcode=1) #Setup coupled simulation cart_comm = CFD_COMM.Create_cart([npxyz[0], npxyz[1], npxyz[2]]) CPL.setup_cfd(cart_comm, xyzL, xyz_orig, ncxyz ) #Setup buffer to get CFD BC from MD
import numpy as np import matplotlib.pyplot as plt from mpi4py import MPI from cplpy import CPL from draw_grid import draw_grid #initialise MPI and CPL comm = MPI.COMM_WORLD CPL = CPL() CFD_COMM = CPL.init(CPL.CFD_REALM) nprocs_realm = CFD_COMM.Get_size() # Parameters of the cpu topology (cartesian grid) npxyz = np.array([1, 1, 1], order='F', dtype=np.int32) NProcs = np.product(npxyz) xyzL = np.array([10.0, 10.0, 10.0], order='F', dtype=np.float64) xyz_orig = np.array([0.0, 0.0, 0.0], order='F', dtype=np.float64) ncxyz = np.array([16, 6, 16], order='F', dtype=np.int32) if (nprocs_realm != NProcs): print("Non-coherent number of processes in CFD ", nprocs_realm, " no equal to ", npxyz[0], " X ", npxyz[1], " X ", npxyz[2]) MPI.Abort(errorcode=1) #Setup coupled simulation cart_comm = CFD_COMM.Create_cart([npxyz[0], npxyz[1], npxyz[2]]) CPL.setup_cfd(cart_comm, xyzL, xyz_orig, ncxyz) # recv data to plot olap_limits = CPL.get_olap_limits()
import numpy as np import matplotlib.pyplot as plt from matplotlib.widgets import Slider from mpi4py import MPI from cplpy import CPL from draw_grid import draw_grid #initialise MPI and CPL comm = MPI.COMM_WORLD CPL = CPL() CFD_COMM = CPL.init(CPL.CFD_REALM) nprocs_realm = CFD_COMM.Get_size() # Parameters of the cpu topology (cartesian grid) npxyz = np.array([1, 1, 1], order='F', dtype=np.int32) NProcs = np.product(npxyz) xyzL = np.array([10.0, 10.0, 10.0], order='F', dtype=np.float64) xyz_orig = np.array([0.0, 0.0, 0.0], order='F', dtype=np.float64) ncxyz = np.array([16, 6, 16], order='F', dtype=np.int32) if (nprocs_realm != NProcs): print("Non-coherent number of processes in CFD ", nprocs_realm, " no equal to ", npxyz[0], " X ", npxyz[1], " X ", npxyz[2]) MPI.Abort(errorcode=1) #Setup coupled simulation cart_comm = CFD_COMM.Create_cart([npxyz[0], npxyz[1], npxyz[2]]) CPL.setup_cfd(cart_comm, xyzL, xyz_orig, ncxyz) #Plot output
#!/usr/bin/env python2 from __future__ import print_function, division import sys import cPickle try: from mpi4py import MPI from cplpy import CPL import numpy as np except ImportError as exc: print("ERROR: ", sys.exc_info()[0], exc, file=sys.stderr) MPI.COMM_WORLD.Abort(errorcode=1) cpllib = CPL() cpllib.set("output_mode", 1) try: # Load parameters for the run params = cPickle.load(open("cfd_params.dic", "rb")) # Parameters of the cpu topology (cartesian grid) NPx = params["npx"] NPy = params["npy"] NPz = params["npz"] # Parameters of the mesh topology (cartesian grid) NCx = params["ncx"] NCy = params["ncy"] NCz = params["ncz"]
from mpi4py import MPI from cplpy import CPL comm = MPI.COMM_WORLD CPL = CPL() MD_COMM = CPL.init(CPL.MD_REALM) nprocs = MD_COMM.Get_size() rank = MD_COMM.Get_rank() print("MD code processor "+ str(rank+1) + " of " + str(nprocs)) CPL.finalize() MPI.Finalize()
#!/usr/bin/env python2 from __future__ import print_function, division from mpi4py import MPI from cplpy import CPL import numpy as np import cPickle import sys comm_world = MPI.COMM_WORLD CPL = CPL() # Do not show any info to the stdin CPL.set("output_mode", 0) dt = 0.1 # Load parameters for the run params = cPickle.load(open("md_params.dic", "rb")) # Parameters of the cpu topology (cartesian grid) try: NPx = params["npx"] NPy = params["npy"] NPz = params["npz"] except: print("ERROR: ", sys.exc_info()[0], file=sys.stderr) comm_world.Abort(errorcode=1) NProcs = NPx * NPy * NPz npxyz = np.array([NPx, NPy, NPz], order='F', dtype=np.int32)
class CFD(): def __init__(self, npxyz, xyzL, xyz_orig, ncxyz): #initialise MPI and CPL self.comm = MPI.COMM_WORLD self.CPL = CPL() self.CFD_COMM = self.CPL.init(CPL.CFD_REALM) self.nprocs_realm = self.CFD_COMM.Get_size() # Parameters of the cpu topology (cartesian grid) self.npxyz = np.array(npxyz, order='F', dtype=np.int32) self.NProcs = np.product(npxyz) self.xyzL = np.array(xyzL, order='F', dtype=np.float64) self.xyz_orig = np.array(xyz_orig, order='F', dtype=np.float64) self.ncxyz = np.array(ncxyz, order='F', dtype=np.int32) if (self.nprocs_realm != self.NProcs): print("Non-coherent number of processes in CFD ", self.nprocs_realm, " no equal to ", self.npxyz[0], " X ", self.npxyz[1], " X ", self.npxyz[2]) MPI.Abort(errorcode=1) #Setup coupled simulation self.cart_comm = self.CFD_COMM.Create_cart( [self.npxyz[0], self.npxyz[1], self.npxyz[2]]) self.CPL.setup_cfd(self.cart_comm, self.xyzL, self.xyz_orig, self.ncxyz) #Get limits of overlap region self.olap_limits = self.CPL.get_olap_limits() self.portion = self.CPL.my_proc_portion(self.olap_limits) [self.ncxl, self.ncyl, self.nczl] = self.CPL.get_no_cells(self.portion) self.dx = self.CPL.get("xl_cfd") / float(self.CPL.get("ncx")) self.dy = self.CPL.get("yl_cfd") / float(self.CPL.get("ncy")) self.dz = self.CPL.get("zl_cfd") / float(self.CPL.get("ncz")) self.ioverlap = (self.CPL.get("icmax_olap") - self.CPL.get("icmin_olap") + 1) self.joverlap = (self.CPL.get("jcmax_olap") - self.CPL.get("jcmin_olap") + 1) self.koverlap = (self.CPL.get("kcmax_olap") - self.CPL.get("kcmin_olap") + 1) self.xoverlap = self.ioverlap * self.dx self.yoverlap = self.joverlap * self.dy self.zoverlap = self.koverlap * self.dz def recv_CPL_data(self): # recv data to plot self.recv_array = np.zeros((1, self.ncxl, self.ncyl, self.nczl), order='F', dtype=np.float64) self.recv_array, ierr = self.CPL.recv(self.recv_array, self.olap_limits) def plot_grid(self, ax): #Plot CFD and coupler Grid draw_grid(ax, nx=self.CPL.get("ncx"), ny=self.CPL.get("ncy"), nz=self.CPL.get("ncz"), px=self.CPL.get("npx_cfd"), py=self.CPL.get("npy_cfd"), pz=self.CPL.get("npz_cfd"), xmin=self.CPL.get("x_orig_cfd"), ymin=self.CPL.get("y_orig_cfd"), zmin=self.CPL.get("z_orig_cfd"), xmax=(self.CPL.get("icmax_olap") + 1) * self.dx, ymax=self.CPL.get("yl_cfd"), zmax=(self.CPL.get("kcmax_olap") + 1) * self.dz, lc='r', label='CFD') #Plot MD domain draw_grid(ax, nx=1, ny=1, nz=1, px=self.CPL.get("npx_md"), py=self.CPL.get("npy_md"), pz=self.CPL.get("npz_md"), xmin=self.CPL.get("x_orig_md"), ymin=-self.CPL.get("yl_md") + self.yoverlap, zmin=self.CPL.get("z_orig_md"), xmax=(self.CPL.get("icmax_olap") + 1) * self.dx, ymax=self.yoverlap, zmax=(self.CPL.get("kcmax_olap") + 1) * self.dz, label='MD') def plot_data(self, ax): # === Plot both grids === #Plot x component on grid x = np.linspace( self.CPL.get("x_orig_cfd") + .5 * self.dx, self.xoverlap - .5 * self.dx, self.ioverlap) z = np.linspace( self.CPL.get("z_orig_cfd") + .5 * self.dz, self.zoverlap - .5 * self.dz, self.koverlap) try: for j in range(self.joverlap): ax.plot( x, 0.5 * self.dy * (self.recv_array[0, :, j, 0] + 1. + 2 * j), 's-') except ValueError: print("Arrays not equal:", x.shape, z.shape, self.recv_array.shape) def finalise(self): self.CPL.finalize() MPI.Finalize()
def read_input(filename): with open(filename, 'r') as f: content = f.read() dic = {} for i in content.split('\n'): if i.find("!") != -1: name = i.split("!")[1] value = i.split('!')[0].replace(' ', '') dic[name] = value return dic comm = MPI.COMM_WORLD CPL = CPL() # Parameters of the cpu topology (cartesian grid) dt = 0.1 NPx = 1 NPy = 1 NPz = 1 NProcs = NPx * NPy * NPz npxyz = np.array([NPx, NPy, NPz], order='F', dtype=np.int32) # Domain topology xyzL = np.array([10.0, 10.0, 10.0], order='F', dtype=np.float64) xyz_orig = np.array([0.0, 0.0, 0.0], order='F', dtype=np.float64) # Create communicators and check that number of processors is consistent MD_COMM = CPL.init(CPL.MD_REALM)
#!/usr/bin/env python from mpi4py import MPI from cplpy import CPL comm = MPI.COMM_WORLD CPL = CPL() MD_COMM = CPL.init(CPL.MD_REALM) CPL.setup_md(MD_COMM.Create_cart([1, 1, 1]), xyzL=[1.0, 1.0, 1.0], xyz_orig=[0.0, 0.0, 0.0]) recv_array, send_array = CPL.get_arrays(recv_size=1, send_size=4) for time in range(5): send_array[0, :, :, :] = 5. * time CPL.send(send_array) recv_array, ierr = CPL.recv(recv_array) print("MD", time, recv_array[0, 0, 0, 0]) CPL.finalize() MPI.Finalize()
import numpy as np from mpi4py import MPI import sys from cplpy import CPL from CouetteAnalytical import CouetteAnalytical as CA #initialise MPI and CPL comm = MPI.COMM_WORLD CPL = CPL() MD_COMM = CPL.init(CPL.MD_REALM) # Parameters of the cpu topology (cartesian grid) npxyz = [1, 1, 1] NProcs = np.product(npxyz) xyzL = np.array([16.795961913825074, 45.349097, 16.795961913825074], order='F', dtype=np.float64) xyz_orig = np.array([0.0, 0.0, 0.0], order='F', dtype=np.float64) if (MD_COMM.Get_size() != NProcs): print("Non-coherent number of processes in MD ", MD_COMM.Get_size(), " 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_md(cart_comm, xyzL, xyz_orig) #Get values from CPL library
from __future__ import print_function, division from mpi4py import MPI from cplpy import CPL import numpy as np import cPickle import sys comm_world = MPI.COMM_WORLD CPL = CPL() # Do not show any info to the stdin CPL.set("output_mode", 0) # Load parameters for the run params = cPickle.load(open("cfd_params.dic", "rb")) # Test selector flag try: which_test = params["which_test"] except: print("ERROR: ", sys.exc_info()[0], file=sys.stderr) comm_world.Abort(errorcode=1) # Parameters of the cpu topology (cartesian grid) try: NPx = params["npx"] NPy = params["npy"] NPz = params["npz"] except:
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()
import numpy as np from mpi4py import MPI import sys from cplpy import CPL #initialise MPI and CPL comm = MPI.COMM_WORLD CPL = CPL() MD_COMM = CPL.init(CPL.MD_REALM) # Parameters of the cpu topology (cartesian grid) npxyz = [1, 1, 1] NProcs = np.product(npxyz) xyzL = np.array([16.795961913825074, 45.349097, 16.795961913825074], order='F', dtype=np.float64) xyz_orig = np.array([0.0, 0.0, 0.0], order='F', dtype=np.float64) if (MD_COMM.Get_size() != NProcs): print("Non-coherent number of processes in MD ", MD_COMM.Get_size(), " 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_md(cart_comm, xyzL, xyz_orig) #Setup send and recv buffers recv_array, send_array = CPL.get_arrays(recv_size=3, send_size=4) #Set velocity U = 2.
import numpy as np import matplotlib.pyplot as plt from mpi4py import MPI from cplpy import CPL from draw_grid import draw_grid from md_oo import MD #initialise MPI and CPL comm = MPI.COMM_WORLD CPL = CPL() CFD_COMM = CPL.init(CPL.MD_REALM) nprocs_realm = CFD_COMM.Get_size() # Parameters of the cpu topology (cartesian grid) npxyz = np.array([1, 1, 1], order='F', dtype=np.int32) NProcs = np.product(npxyz) xyzL = np.array([6.70820393, 17.88854382, 1.0], order='F', dtype=np.float64) xyz_orig = np.array([0.0, 0.0, 0.0], order='F', dtype=np.float64) 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 = CFD_COMM.Create_cart([npxyz[0], npxyz[1], npxyz[2]]) CPL.setup_md(cart_comm, xyzL, xyz_orig) #Setup buffer to send CFD BC from MD ncx = CPL.get("ncx"); dy = CPL.get("yl_cfd")/CPL.get("ncy")
CPL = CPL() # Parameters of the cpu topology (cartesian grid) dt = 0.1 NPx = 4 NPy = 2 NPz = 2 NProcs = NPx * NPy * NPz npxyz = np.array([NPx, NPy, NPz], order="F", dtype=np.int32) # Domain topology xyzL = np.array([10.0, 10.0, 10.0], order="F", dtype=np.float64) xyz_orig = np.array([0.0, 0.0, 0.0], order="F", dtype=np.float64) # Create communicators and check that number of processors is consistent MD_COMM = CPL.init(CPL.MD_REALM) nprocs_realm = MD_COMM.Get_size() if nprocs_realm != NProcs: print("Non-coherent number of processes") MPI.Abort(errorcode=1) cart_comm = MD_COMM.Create_cart([NPx, NPy, NPz]) CPL.setup_md(cart_comm, xyzL, xyz_orig) # recv test olap_limits = CPL.get_olap_limits() portion = CPL.my_proc_portion(olap_limits) [ncxl, ncyl, nczl] = CPL.get_no_cells(portion)
import numpy as np import matplotlib.pyplot as plt from matplotlib.widgets import Slider from mpi4py import MPI from cplpy import CPL #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([1, 1, 1], order='F', dtype=np.int32) NProcs = np.product(npxyz) xyzL = np.array([ 1.5000000000000000E-003, 1.5000000000000000E-003, 2.5000000000000001E-003 ], order='F', dtype=np.float64) xyz_orig = np.array([0.0, 0.0, 0.0], order='F', dtype=np.float64) ncxyz = np.array([8, 8, 8], 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]])
#!/usr/bin/env python from mpi4py import MPI from cplpy import CPL comm = MPI.COMM_WORLD CPL = CPL() CFD_COMM = CPL.init(CPL.CFD_REALM) CPL.setup_cfd(CFD_COMM.Create_cart([1, 1, 1]), xyzL=[1.0, 1.0, 1.0], xyz_orig=[0.0, 0.0, 0.0], ncxyz=[32, 32, 32]) recv_array, send_array = CPL.get_arrays(recv_size=4, send_size=1) for time in range(5): recv_array, ierr = CPL.recv(recv_array) print("CFD", time, recv_array[0,0,0,0]) send_array[0,:,:,:] = 2.*time CPL.send(send_array) CPL.finalize() MPI.Finalize()
import numpy as np import matplotlib.pyplot as plt from mpi4py import MPI from cplpy import CPL from draw_grid import draw_grid from md_oo import MD #initialise MPI and CPL comm = MPI.COMM_WORLD CPL = CPL() CFD_COMM = CPL.init(CPL.MD_REALM) nprocs_realm = CFD_COMM.Get_size() # Parameters of the cpu topology (cartesian grid) npxyz = np.array([1, 1, 1], order='F', dtype=np.int32) NProcs = np.product(npxyz) xyzL = np.array([6.70820393, 17.88854382, 1.0], order='F', dtype=np.float64) xyz_orig = np.array([0.0, 0.0, 0.0], order='F', dtype=np.float64) if (nprocs_realm != NProcs): print("Non-coherent number of processes in MD ", nprocs_realm, " not equal to ", npxyz[0], " X ", npxyz[1], " X ", npxyz[2]) MPI.Abort(errorcode=1) #Setup coupled simulation cart_comm = CFD_COMM.Create_cart([npxyz[0], npxyz[1], npxyz[2]]) CPL.setup_md(cart_comm, xyzL, xyz_orig) #Setup buffer to send CFD BC from MD ncx = CPL.get("ncx")
from mpi4py import MPI from cplpy import CPL import numpy as np comm = MPI.COMM_WORLD CPL = CPL() nsteps = 1 dt = 0.2 density = 0.8 # Parameters of the cpu topology (cartesian grid) NPx = 2 NPy = 2 NPz = 1 NProcs = NPx * NPy * NPz # Parameters of the mesh topology (cartesian grid) ncxyz = np.array([64, 18, 64], order='F', dtype=np.int32) xyzL = np.array([10.0, 10.0, 10.0], order='F', dtype=np.float64) xyz_orig = np.array([0.0, 0.0, 0.0], order='F', dtype=np.float64) # Create communicators and check that number of processors is consistent CFD_COMM = CPL.init(CPL.CFD_REALM) nprocs_realm = CFD_COMM.Get_size() if (nprocs_realm != NProcs): print("ERROR: Non-coherent number of processors.") MPI.Abort(errorcode=1) cart_comm = CFD_COMM.Create_cart([NPx, NPy, NPz]) CPL.setup_cfd(cart_comm, xyzL, xyz_orig, ncxyz)
tplot = 1. OpenFOAMwriteinterval = tplot / dt #initialise MPI comm = MPI.COMM_WORLD if (comm.Get_size() != 1): print("Simplified code only works for one proccesor!") 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([
from mpi4py import MPI from cplpy import CPL comm = MPI.COMM_WORLD CPL = CPL() MD_COMM = CPL.init(CPL.MD_REALM) nprocs = MD_COMM.Get_size() rank = MD_COMM.Get_rank() print("MD code processor " + str(rank + 1) + " of " + str(nprocs)) CPL.finalize() MPI.Finalize()
from __future__ import print_function, division import sys import cPickle try: from mpi4py import MPI from cplpy import CPL import numpy as np except ImportError as exc: print("ERROR: ", sys.exc_info()[0], exc, file=sys.stderr) MPI.COMM_WORLD.Abort(errorcode=1) CPL = CPL() CPL.set("output_mode", 1) try: # Load parameters for the run params = cPickle.load(open("cfd_params.dic", "rb")) # Parameters of the cpu topology (cartesian grid) NPx = params["npx"] NPy = params["npy"] NPz = params["npz"] # Parameters of the mesh topology (cartesian grid) NCx = params["ncx"] NCy = params["ncy"] NCz = params["ncz"]
def read_input(filename): with open(filename, 'r') as f: content = f.read() dic = {} for i in content.split('\n'): if i.find("!") != -1: name = i.split("!")[1] value = i.split('!')[0].replace(' ', '') dic[name] = value return dic comm = MPI.COMM_WORLD #comm.Barrier() CPL = CPL() # Parameters of the cpu topology (cartesian grid) dt = 0.1 NPx = 4 NPy = 2 NPz = 2 NProcs = NPx * NPy * NPz npxyz = np.array([NPx, NPy, NPz], order='F', dtype=np.int32) # Domain topology xyzL = np.array([10.0, 10.0, 10.0], order='F', dtype=np.float64) xyz_orig = np.array([0.0, 0.0, 0.0], order='F', dtype=np.float64) # Create communicators and check that number of processors is consistent MD_COMM = CPL.init(CPL.MD_REALM)
#!/usr/bin/env python2 from __future__ import print_function, division from mpi4py import MPI from cplpy import CPL import numpy as np import cPickle import sys comm_world = MPI.COMM_WORLD CPL = CPL() # Do not show any info to the stdin CPL.set("output_mode", 0) # Load parameters for the run params = cPickle.load(open("md_params.dic", "rb")) # Test selector flag try: which_test = params["which_test"] except: print("ERROR: ", sys.exc_info()[0], file=sys.stderr) comm_world.Abort(errorcode=1) # Parameters of the cpu topology (cartesian grid) try: NPx = params["npx"] NPy = params["npy"] NPz = params["npz"] except: print("ERROR: ", sys.exc_info()[0], file=sys.stderr)
#Import CPL library from cplpy import CPL plot_stuff = False #initialise MPI comm = MPI.COMM_WORLD root = 0 # Parameters of the cpu topology (cartesian grid) npxyz = np.array([1, 1, 1], order='F', dtype=np.int32) xyzL = np.array([1., 1., 1.], 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) cart_COMM = MD_COMM.Create_cart([npxyz[0], npxyz[1], npxyz[2]]) CPL.setup_md(cart_COMM, xyzL, xyz_orig) recvbuf, sendbuf = CPL.get_arrays(recv_size=9, send_size=8) #Analytical solution dt = 0.05 U = 1. nu = 1.004e-2 Re = xyzL[1] * U / nu ncx = CPL.get("ncx") ncy = CPL.get("ncy") ncz = CPL.get("ncz") CAObj = CA(Re=Re, U=U,
from mpi4py import MPI import sys #Import CPL library from cplpy import CPL #initialise MPI comm = MPI.COMM_WORLD # Parameters of the cpu topology (cartesian grid) npxyz = np.array([1, 1, 1], order='F', dtype=np.int32) xyzL = np.array([2., 10., 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.setup_md(MD_COMM.Create_cart([npxyz[0], npxyz[1], npxyz[2]]), xyzL, xyz_orig) #Setup send and recv buffers recvbuf, sendbuf = CPL.get_arrays(recv_size=9, send_size=8) #Main time loop for time in range(1): print(time) # Recv data: # [Ux, Uy, Uz, gradPx, gradPy, gradPz, divTaux, divTauy, divTauz] recvbuf, ierr = CPL.recv(recvbuf)
dt = 0.2 density = 0.8 # Parameters of the cpu topology (cartesian grid) NPx = 2 NPy = 2 NPz = 1 NProcs = NPx*NPy*NPz # Parameters of the mesh topology (cartesian grid) ncxyz = np.array([64, 18, 64], order='F', dtype=np.int32) xyzL = np.array([10.0, 10.0, 10.0], order='F', dtype=np.float64) xyz_orig = np.array([0.0, 0.0, 0.0], order='F', dtype=np.float64) # Create communicators and check that number of processors is consistent CFD_COMM = CPL.init(CPL.CFD_REALM) nprocs_realm = CFD_COMM.Get_size() if (nprocs_realm != NProcs): print "ERROR: Non-coherent number of processors." MPI.Abort(errorcode=1) cart_comm = CFD_COMM.Create_cart([NPx, NPy, NPz]) CPL.setup_cfd(cart_comm, xyzL, xyz_orig, ncxyz) cart_rank = cart_comm.Get_rank() olap_limits = CPL.get_olap_limits() portion = CPL.my_proc_portion(olap_limits) [ncxl, ncyl, nczl] = CPL.get_no_cells(portion) send_array = np.zeros((3, ncxl, ncyl, nczl), order='F', dtype=np.float64)
import numpy as np from mpi4py import MPI from cplpy import CPL g = 9.81 mi = -5.9490638385009208e-08 print("After import") #initialise MPI and CPL comm = MPI.COMM_WORLD CPL = CPL() MD_COMM = CPL.init(CPL.CFD_REALM) print("After CPL init") ## Parameters of the cpu topology (cartesian grid) npxyz = [1, 1, 1] xyzL = [1.5E-003, 1.5E-003, 2.5E-003] xyz_orig = [0.0, 0.0, 0.0] ncxyz = [8, 8, 8] #Setup coupled simulation cart_comm = MD_COMM.Create_cart([npxyz[0], npxyz[1], npxyz[2]]) CPL.setup_cfd(cart_comm, xyzL, xyz_orig, ncxyz) recv_array, send_array = CPL.get_arrays(recv_size=4, send_size=3) print("After CPL setup") ft = True for time in range(100):
import numpy as np import matplotlib.pyplot as plt from mpi4py import MPI from cplpy import CPL from draw_grid import draw_grid from cfd_oo import CFD #initialise MPI and CPL comm = MPI.COMM_WORLD CPL = CPL() CFD_COMM = CPL.init(CPL.CFD_REALM) nprocs_realm = CFD_COMM.Get_size() # Parameters of the cpu topology (cartesian grid) npxyz = np.array([1, 1, 1], order='F', dtype=np.int32) NProcs = np.product(npxyz) xyzL = np.array([6.70820393, 17.88854382, 1.0], order='F', dtype=np.float64) xyz_orig = np.array([0.0, 0.0, 0.0], order='F', dtype=np.float64) ncxyz = np.array([8, 8, 1], order='F', dtype=np.int32) if (nprocs_realm != NProcs): print("Non-coherent number of processes in CFD ", nprocs_realm, " not equal to ", npxyz[0], " X ", npxyz[1], " X ", npxyz[2]) MPI.Abort(errorcode=1) #Setup coupled simulation cart_comm = CFD_COMM.Create_cart([npxyz[0], npxyz[1], npxyz[2]]) CPL.setup_cfd(cart_comm, xyzL, xyz_orig, ncxyz) #Setup buffer to get CFD BC from MD
from __future__ import print_function, division from mpi4py import MPI from cplpy import CPL import numpy as np import cPickle import sys comm_world = MPI.COMM_WORLD CPL = CPL() # Do not show any info to the stdin CPL.set("output_mode", 0) dt = 0.1 # Load parameters for the run params = cPickle.load(open("md_params.dic", "rb")) # Parameters of the cpu topology (cartesian grid) try: NPx = params["npx"] NPy = params["npy"] NPz = params["npz"] except: print("ERROR: ", sys.exc_info()[0], file=sys.stderr) comm_world.Abort(errorcode=1) NProcs = NPx*NPy*NPz npxyz = np.array([NPx, NPy, NPz], order='F', dtype=np.int32) # Parameters of the domain
from __future__ import print_function, division from mpi4py import MPI from cplpy import CPL import numpy as np import cPickle import sys lib = CPL() lib.set("output_mode", 1) # Load parameters for the run params = cPickle.load(open("md_params.dic", "rb")) # Parameters of the cpu topology (cartesian grid) try: NPx = params["npx"] NPy = params["npy"] NPz = params["npz"] except: print("ERROR: ", sys.exc_info()[0], file=sys.stderr) MPI.Abort() # Parameters of the mesh topology (cartesian grid) try: NCx = params["ncx"] NCy = params["ncy"] NCz = params["ncz"] except: