def create_table_for_jet(fpath): pce = Eos(1) import cStringIO output = cStringIO.StringIO() fname = os.path.join(fpath, 'bulkinfo.h5') with h5py.File(fname, 'r') as h5: tau_list = h5['coord/tau'][...] x_list = h5['coord/x'][...] y_list = h5['coord/y'][...] for tau in tau_list: tau_str = ('%s' % tau).replace('.', 'p') ed = h5['bulk2d/exy_tau%s' % tau_str][...] vx = h5['bulk2d/vx_xy_tau%s' % tau_str][...] vy = h5['bulk2d/vy_xy_tau%s' % tau_str][...] T = pce.f_T(ed) QGP_fraction = qgp_fraction(T) x, y, ed_new = interp_2d(ed, x_list, y_list) x, y, vx_new = interp_2d(vx, x_list, y_list) x, y, vy_new = interp_2d(vy, x_list, y_list) x, y, T_new = interp_2d(T, x_list, y_list) x, y, frac_new = interp_2d(QGP_fraction, x_list, y_list) for i, xi in enumerate(x): for j, yj in enumerate(y): print >> output, tau, xi, yj, ed_new[i, j], T_new[ i, j], vx_new[i, j], vy_new[i, j], frac_new[i, j], 0.0 with open(os.path.join(fpath, 'bulk.dat'), 'w') as f: f.write(output.getvalue())
def ppcollision(eostype='SU3', outdir = '../results/event0'): print('start ...') t0 = time() if not os.path.exists(outdir): os.mkdir(outdir) if eostype == 'SU3': cfg.eos_type = 'pure_gauge' elif eostype == 'QCD': cfg.eos_type = 'lattice_wb' elif eostype == 'EOSI': cfg.eos_type == 'ideal_gas' eos = Eos(cfg.eos_type) # update the configuration #cfg.Edmax = eos.f_ed(Tmax) cfg.Edmax = 50.0 cfg.fPathOut = outdir cfg.NX = 301 cfg.NY = 301 cfg.NZ = 1 cfg.DT = 0.01 cfg.DX = 0.08 cfg.DY = 0.08 cfg.ntskip = 50 cfg.NumOfNucleons = 1 cfg.Ra = 0.8 cfg.Eta = 0.6 cfg.Si0 = 6.4 cfg.TAU0 = 0.6 cfg.ImpactParameter = 0.0 cfg.ETAOS = 0.0 cfg.SQRTS = 2760 #cfg.Edmax = 600.0 cfg.Hwn = 1.0 write_config(cfg) xmax = cfg.NX/2*cfg.DX ymax = cfg.NY/2*cfg.DY x = np.linspace(-xmax, xmax, cfg.NX) y = np.linspace(-ymax, ymax, cfg.NY) x, y = np.meshgrid(x, y) ed = cfg.Edmax * pp_energydensity(x, y, b=cfg.ImpactParameter) #plt.imshow(ed) #plt.show() ideal = CLIdeal(cfg, gpu_id=1) edv = np.zeros((ideal.size, 4), ideal.cfg.real) print(edv.shape) edv[:, 0] = ed.T.flatten() ideal.load_ini(edv) ideal.evolve(max_loops=1000, save_hypersf=False, to_maxloop=True) t1 = time() print('finished. Total time: {dtime}'.format(dtime = t1-t0 ))
def glueball(Tmax = 0.6, outdir = '../results/event0', eos_type='pure_gauge'): print('start ...') t0 = time() if not os.path.exists(outdir): os.mkdir(outdir) cfg.eos_type = eos_type eos = Eos(cfg.eos_type) # update the configuration #cfg.Edmax = eos.f_ed(Tmax) #cfg.Edmax = 166.0 cfg.Edmax = 55.0 cfg.fPathOut = outdir cfg.NX = 501 cfg.NY = 501 cfg.NZ = 1 cfg.DT = 0.01 cfg.DX = 0.08 cfg.DY = 0.08 #cfg.NumOfNucleons = 208 #cfg.Ra = 6.62 #cfg.Eta = 0.546 #cfg.Si0 = 6.4 cfg.NumOfNucleons = 197 cfg.Ra = 6.4 cfg.Eta = 0.546 cfg.Si0 = 4.0 cfg.TAU0 = 0.4 cfg.ImpactParameter = 7.74 #cfg.ImpactParameter = 0.0 cfg.ETAOS = 0.0 cfg.save_to_hdf5 = False if eos_type == 'pure_gauge': cfg.TFRZ = 0.2 #cfg.Edmax = 600.0 #cfg.Hwn = 1.0 cfg.Hwn = 0.95 write_config(cfg) ideal = CLIdeal(cfg, gpu_id=2) from glauber import Glauber Glauber(cfg, ideal.ctx, ideal.queue, ideal.compile_options, ideal.d_ev[1]) ideal.evolve(max_loops=3000, save_hypersf=False, to_maxloop=True) t1 = time() print('finished. Total time: {dtime}'.format(dtime = t1-t0 )) from subprocess import call call(['python', './spec.py', cfg.fPathOut])
def __init__(self, cfg, ctx, queue, eos_table, compile_options): self.cfg = cfg self.ctx = ctx self.queue = queue self.eos_table = eos_table self.compile_options = list(compile_options) NX, NY, NZ = cfg.NX, cfg.NY, cfg.NZ self.h_ev = np.zeros((NX * NY * NZ, 4), cfg.real) self.h_pi = np.zeros(10 * NX * NY * NZ, self.cfg.real) # one dimensional self.ex, self.ey, self.ez = [], [], [] self.vx, self.vy, self.vz = [], [], [] # in transverse plane (z==0) self.exy, self.vx_xy, self.vy_xy, self.vz_xy = [], [], [], [] self.pixx_xy, self.piyy_xy, self.pitx_xy = [], [], [] # in reaction plane self.exz, self.vx_xz, self.vy_xz, self.vz_xz = [], [], [], [] self.ecc2_vs_rapidity = [] self.ecc1_vs_rapidity = [] self.time = [] self.edmax = [] self.__loadAndBuildCLPrg() self.eos = Eos(cfg.eos_type) self.x = np.linspace(-floor(NX / 2) * cfg.DX, floor(NX / 2) * cfg.DX, NX, endpoint=True) self.y = np.linspace(-floor(NY / 2) * cfg.DY, floor(NY / 2) * cfg.DY, NY, endpoint=True) self.z = np.linspace(-floor(NZ / 2) * cfg.DZ, floor(NZ / 2) * cfg.DZ, NZ, endpoint=True)
def __init__(self, configs, handcrafted_eos=None, gpu_id=0): '''Params: :param configs: hydrodynamic configurations, from configs import cfg :param gpu_id: use which gpu for the calculation if there are many per node ''' # create opencl environment self.cfg = configs self.cwd, cwf = os.path.split(__file__) # create the fPathOut directory if not exists path = self.cfg.fPathOut if not os.path.exists(path): os.makedirs(path) # choose proper real, real4, real8 sizes self.determine_float_size(self.cfg) from backend_opencl import OpenCLBackend self.backend = OpenCLBackend(self.cfg, gpu_id) self.ctx = self.backend.ctx self.queue = self.backend.default_queue self.size = self.cfg.NX * self.cfg.NY * self.cfg.NZ self.tau = self.cfg.real(self.cfg.TAU0) self.compile_options = self.__compile_options() # set eos, create eos table for interpolation # self.eos_table must be before __loadAndBuildCLPrg() to pass # table information to definitions if handcrafted_eos is None: self.eos = Eos(self.cfg.eos_type) else: self.eos = handcrafted_eos chemical_potential_on_hypersf(self.cfg.TFRZ, path, eos_type=self.cfg.eos_type) if handcrafted_eos is not None: self.eos_table = self.eos.create_table(self.ctx, self.compile_options) elif self.cfg.eos_type == 'lattice_pce165': self.eos_table = self.eos.create_table(self.ctx, self.compile_options, nrow=100, ncol=1555) elif self.cfg.eos_type == 'lattice_pce150': self.eos_table = self.eos.create_table(self.ctx, self.compile_options, nrow=100, ncol=1555) elif self.cfg.eos_type == 'hotqcd2014': self.eos_table = self.eos.create_table(self.ctx, self.compile_options, nrow=100, ncol=1555) elif self.cfg.eos_type == 'lattice_wb': self.eos_table = self.eos.create_table(self.ctx, self.compile_options, nrow=4, ncol=1001) else: self.eos_table = self.eos.create_table(self.ctx, self.compile_options) self.efrz = self.eos.f_ed(self.cfg.TFRZ) # store 1D and 2d bulk info at each time step if self.cfg.save_to_hdf5: from bulkinfo_h5 import BulkInfo else: from bulkinfo import BulkInfo self.bulkinfo = BulkInfo(self.cfg, self.ctx, self.queue, self.eos_table, self.compile_options) self.__loadAndBuildCLPrg() #define buffer on device side, d_ev1 stores ed, vx, vy, vz mf = cl.mem_flags self.h_ev1 = np.zeros((self.size, 4), self.cfg.real) self.d_ev = [ cl.Buffer(self.ctx, mf.READ_WRITE | mf.COPY_HOST_PTR, hostbuf=self.h_ev1), cl.Buffer(self.ctx, mf.READ_WRITE | mf.COPY_HOST_PTR, hostbuf=self.h_ev1), cl.Buffer(self.ctx, mf.READ_WRITE | mf.COPY_HOST_PTR, hostbuf=self.h_ev1) ] self.d_Src = cl.Buffer(self.ctx, mf.READ_WRITE | mf.COPY_HOST_PTR, hostbuf=self.h_ev1) self.submax = np.empty(64, self.cfg.real) self.d_submax = cl.Buffer(self.ctx, cl.mem_flags.READ_WRITE, self.submax.nbytes) # d_ev_old: for hypersf calculation; self.d_ev_old = cl.Buffer(self.ctx, mf.READ_WRITE, size=self.h_ev1.nbytes) # d_hypersf: store the dSigma^{mu}, vx, vy, veta, tau, x, y, eta # on freeze out hyper surface self.d_hypersf = cl.Buffer(self.ctx, mf.READ_WRITE, size=1500000 * self.cfg.sz_real8) # the position of the hyper surface in cartersian coordinates self.d_sf_txyz = cl.Buffer(self.ctx, mf.READ_WRITE, size=1500000 * self.cfg.sz_real4) h_num_of_sf = np.zeros(1, np.int32) self.d_num_of_sf = cl.Buffer(self.ctx, mf.READ_WRITE | mf.COPY_HOST_PTR, hostbuf=h_num_of_sf) self.history = []
from time import time from glob import glob import pyopencl as cl import matplotlib.pyplot as plt import h5py from scipy.interpolate import interp2d import os, sys cwd, cwf = os.path.split(__file__) print('cwd=', cwd) sys.path.append(os.path.join(cwd, '../pyvisc')) from eos.eos import Eos pce = Eos(1) def qgp_fraction(T): '''calc the QGP fraction from temperature''' frac = np.zeros_like(T) frac[T > 0.22] = 1.0 frac[T < 0.165] = 0.0 cross_over = np.logical_and(T >= 0.165, T <= 0.22) frac[cross_over] = (T[cross_over] - 0.165) / (0.22 - 0.165) return frac
def __init__(self, cfg, ctx, queue, eos_table, compile_options): self.cfg = cfg self.ctx = ctx self.queue = queue self.eos_table = eos_table self.compile_options = list(compile_options) NX, NY, NZ = cfg.NX, cfg.NY, cfg.NZ if NX % 2 == 1: self.x = np.linspace(-floor(NX / 2) * cfg.DX, floor(NX / 2) * cfg.DX, NX, endpoint=True) self.y = np.linspace(-floor(NY / 2) * cfg.DY, floor(NY / 2) * cfg.DY, NY, endpoint=True) self.z = np.linspace(-floor(NZ / 2) * cfg.DZ, floor(NZ / 2) * cfg.DZ, NZ, endpoint=True) #including grid point 0 elif NX % 2 == 0: self.x = np.linspace(-((NX - 1) / 2.0) * cfg.DX, ((NX - 1) / 2.0) * cfg.DX, NX, endpoint=True) self.y = np.linspace(-((NY - 1) / 2.0) * cfg.DY, ((NY - 1) / 2.0) * cfg.DY, NY, endpoint=True) self.z = np.linspace(-floor(NZ / 2) * cfg.DZ, floor(NZ / 2) * cfg.DZ, NZ, endpoint=True) #NOT including grid point 0 for trento2D self.h_ev = np.zeros((NX * NY * NZ, 4), cfg.real) self.a_ed = cl_array.empty(self.queue, NX * NY * NZ, cfg.real) self.a_entropy = cl_array.empty(self.queue, NX * NY * NZ, cfg.real) # the momentum eccentricity as a function of rapidity self.a_eccp1 = cl_array.empty(self.queue, NZ, cfg.real) self.a_eccp2 = cl_array.empty(self.queue, NZ, cfg.real) # store the data in hdf5 file #h5_path = os.path.join(cfg.fPathOut, 'bulkinfo.h5') #self.f_hdf5 = h5py.File(h5_path, 'w') self.eos = Eos(cfg.eos_type) self.__load_and_build_cl_prg() # time evolution for , edmax and ed, T at (x=0,y=0,etas=0) self.time = [] self.edmax = [] self.edcent = [] self.Tcent = [] # time evolution for total_entropy, eccp, eccx and <vr> self.energy = [] self.entropy = [] self.eccp_vs_tau = [] self.eccx = [] self.vr = [] # time evolution for bulk3D self.Tau_tijk = [] self.X_tijk = [] self.Y_tijk = [] self.Z_tijk = [] self.ED_tijk = [] self.Tp_tijk = [] # self.Frc_tijk = [] self.Vx_tijk = [] self.Vy_tijk = [] self.Vz_tijk = [] # time evolution for bulk2D self.Tau_2d = [] self.X_2d = [] self.Y_2d = [] self.ED_2d = [] self.Tp_2d = [] self.Vx_2d = [] self.Vy_2d = [] self.Vz_2d = [] self.Frc_2d = []
def __init__(self, path): data_path = path print('Loading data file,please wait for a minuts!') datafile = os.path.join(data_path, 'bulk3D.dat') self.data_t = np.loadtxt(datafile) print('Data file loading complete!') self.NX0 = 70 self.NY0 = 70 self.NZ0 = 41 self.TAU0 = 0.6 self.DX0 = 0.3 self.DY0 = 0.3 self.DZ0 = 0.3 self.DT = 0.3 self.NT = self.data_t.shape[0] // (self.NX0 * self.NY0 * self.NZ0) print("steps of Time is %i" % self.NT) self.NX = self.NX0 self.NY = self.NY0 self.NZ = self.NZ0 self.DX = self.DX0 self.DY = self.DY0 self.DZ = self.DZ0 # Switchs self.Dim_Switch = 3 self.Grids_Switch = False self.sEd = True self.sT = False self.sVt = True self.sVz = True self.sFrac = False self.IEOS = 1 self.eos = Eos(self.IEOS) self.OutPutPath = None # self.Ed_txyz = self.data_t[:,0].reshape(self.NT,self.NX0,self.NY0,self.NZ0) # self.Vx_txyz = self.data_t[:,1].reshape(self.NT,self.NX0,self.NY0,self.NZ0) # self.Vy_txyz = self.data_t[:,2].reshape(self.NT,self.NX0,self.NY0,self.NZ0) # self.Vz_txyz = self.data_t[:,3].reshape(self.NT,self.NX0,self.NY0,self.NZ0) self.Block_txyz = np.zeros(self.NT * self.NX0 * self.NY0 * self.NZ0 * 4).reshape(self.NT, self.NX0, self.NY0, self.NZ0, 4) self.Block_txyz[:, :, :, :, 0] = self.data_t[:, 0].reshape(self.NT, self.NX0, self.NY0, self.NZ0) # Ed self.Block_txyz[:, :, :, :, 1] = self.data_t[:, 1].reshape(self.NT, self.NX0, self.NY0, self.NZ0) # Vx self.Block_txyz[:, :, :, :, 2] = self.data_t[:, 2].reshape(self.NT, self.NX0, self.NY0, self.NZ0) # Vy self.Block_txyz[:, :, :, :, 3] = self.data_t[:, 3].reshape(self.NT, self.NX0, self.NY0, self.NZ0) # Vz # self.OutPut_col_shape = [] self.Ed_newGrids = [] self.T_newGrids = [] self.Frac_newGrids = [] self.Vt_newGrids = [] self.Vz_newGrids = [] self.Grids = [] self.Hotel = [] self.todo = []
def test_rootfinding(self): cwd, cwf = os.path.split(__file__) kernel_src = """ #include "helper.h" __kernel void rootfinding_test( global real4 * d_edv, global real * result, const int size, read_only image2d_t eos_table) { int gid = (int) get_global_id(0); if ( gid < size ) { real4 edv = d_edv[gid]; real eps = edv.s0; real pre = P(eps, eos_table); real4 umu = (real4)(1.0f, edv.s1, edv.s2, edv.s3); real u0 = gamma(umu.s1, umu.s2, umu.s3); umu = u0*umu; real4 T0m = (eps+pre)*u0*umu - pre*gm[0]; real M = sqrt(T0m.s1*T0m.s1 + T0m.s2*T0m.s2 + T0m.s3*T0m.s3); real T00 = T0m.s0; real ed_found; rootFinding(&ed_found, T00, M, eos_table); result[gid] = ed_found; } } """ compile_options = ['-I %s' % os.path.join(cwd, '..', 'kernel')] compile_options.append('-D USE_SINGLE_PRECISION') compile_options.append('-D EOSI') eos_table = Eos(cfg).create_table(self.ctx, compile_options) prg = cl.Program(self.ctx, kernel_src).build(compile_options) size = 205 * 205 * 85 edv = np.empty((size, 4), cfg.real) edv[:, 0] = np.random.uniform(1.0, 10.0, size) v_mag = np.random.uniform(0.0, 0.999, size) theta = np.random.uniform(0.0, np.pi, size) phi = np.random.uniform(-np.pi, np.pi, size) edv[:, 1] = v_mag * np.cos(theta) * np.cos(phi) edv[:, 2] = v_mag * np.cos(theta) * np.sin(phi) edv[:, 3] = v_mag * np.sin(theta) final = np.empty(size).astype(np.float32) mf = cl.mem_flags final_gpu = cl.Buffer(self.ctx, mf.READ_WRITE, final.nbytes) edv_gpu = cl.Buffer(self.ctx, mf.READ_WRITE | mf.COPY_HOST_PTR, hostbuf=edv) prg.rootfinding_test(self.queue, (size, ), None, edv_gpu, final_gpu, np.int32(size), eos_table) cl.enqueue_copy(self.queue, final, final_gpu).wait() np.testing.assert_almost_equal(final, edv[:, 0], 2) print('rootfinding test pass')