Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:18:32

0001 /*******************************************************************************
0002  * Copyright (c) 2018-2019 LongGang Pang, lgpang@qq.com
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and/or associated documentation files (the
0006  * "Materials"), to deal in the Materials without restriction, including
0007  * without limitation the rights to use, copy, modify, merge, publish,
0008  * distribute, sublicense, and/or sell copies of the Materials, and to
0009  * permit persons to whom the Materials are furnished to do so, subject to
0010  * the following conditions:
0011  *
0012  * The above copyright notice and this permission notice shall be included
0013  * in all copies or substantial portions of the Materials.
0014  *
0015  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0016  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0017  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
0018  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
0019  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
0020  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
0021  * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
0022  ******************************************************************************/
0023 
0024 
0025 #ifndef __CL_IDEAL__
0026 #define __CL_IDEAL__
0027 /*!< Use cpp exceptionn to handel errors */
0028 #define __CL_ENABLE_EXCEPTIONS 
0029 // System includes
0030 //#include <CL/cl.hpp>
0031 #include <cstdlib>
0032 #include <cstdio>
0033 #include <string>
0034 #include <vector>
0035 #include <cmath>
0036 #include <iostream>
0037 #include <fstream>
0038 #include <sstream>
0039 #include <cassert>
0040 #include <ctime>
0041 #include <algorithm>
0042 #include <map>
0043 
0044 #include <random>
0045 
0046 #include "Config.h"
0047 #include "opencl_backend.h"
0048 
0049 namespace clvisc {
0050 
0051 typedef struct
0052 {
0053     int block_size; // num of threads along one dim on gpu
0054     int nx;  // number of grids along x
0055     int ny;  // number of grids along y
0056     int nz;  // number of grids along etas
0057     double tau0; // initial thermalization time
0058     double dt;   // time step
0059     float dx;   // x step 
0060     float dy;   // y step 
0061     float dz;   // etas step
0062     float etaos_xmin; // parameterized eta/s (T for minimum etaos)
0063     float etaos_ymin; // parameterized eta/s (minumum etaos)
0064     float etaos_left_slop; // parameterized eta/s (left slop)
0065     float etaos_right_slop; // parameterized eta/s (left slop)
0066     int ntskip;  // number of grids to skip for output along tau
0067     int nxskip;  // number of grids to skip for output along x
0068     int nyskip;  // number of grids to skip for output along y
0069     int nzskip;  // number of grids to skip for output along etas
0070     std::string result_directory;
0071 } Config;
0072 
0073 /*! \class CLIdeal c++ wrapper for JetScape 
0074  *  */
0075 class CLIdeal
0076 {
0077     private:
0078     // initial starting time
0079     double tau0_;
0080     // time for the current time step
0081     double tau_;
0082     Config cfg_;
0083     OpenclBackend backend_;
0084 
0085     std::string compile_option_;
0086     // d_submax is used to compute the maximum
0087     // energy density of the fluctuating QGP
0088     cl::Buffer d_submax_;
0089 
0090     // stores the maximum energy density history
0091     std::vector<cl_real> max_ed_history_;
0092 
0093     cl::Kernel kernel_kt_src_christoffel_;
0094     cl::Kernel kernel_kt_src_alongx_;
0095     cl::Kernel kernel_kt_src_alongy_;
0096     cl::Kernel kernel_kt_src_alongz_;
0097     cl::Kernel kernel_update_ev_;
0098     cl::Kernel kernel_reduction_;
0099 
0100     void read_eos_table_(std::string fname, CompileOption &opts_);
0101 
0102     void initialize_gpu_buffer_();
0103 
0104      // update half step using Runge-Kutta method, step = {1, 2}
0105     void half_step_(int step);
0106 
0107     public:
0108     // h_ev_, d_ev_, eos_table_ will be used in class CLVisc
0109     // it would be good to make them public
0110     std::vector<cl_real4> h_ev_;
0111     cl::Buffer d_ev_[3];
0112     cl::Buffer d_src_;
0113     // image2d_t for eos_table
0114     cl::Image2D eos_table_;
0115 
0116     CLIdeal(const Config & cfg, std::string device_type, int device_id);
0117 
0118     inline const Config & get_config() {return cfg_;}
0119 
0120     // read initial energy density from external vector
0121     template <typename ValueType>
0122     void read_ini(const std::vector<ValueType> & ed);
0123 
0124     // read initial ed, vx, vy, vz vector
0125     template <typename ValueType>
0126     void read_ini(const std::vector<ValueType> & ed, 
0127                   const std::vector<ValueType> & vx, 
0128                   const std::vector<ValueType> & vy, 
0129                   const std::vector<ValueType> & vz);
0130 
0131     // run hydrodynamic evolution for one time step
0132     void one_step();
0133 
0134     // predict the first step to get u^{mu} for viscous hydro
0135     void predict_first_step();
0136 
0137     // return the maximum energy density, 
0138     float max_energy_density();
0139 
0140     // run hydrodynamic evolution for all time steps
0141     // stop when max_T < freeze_out_temperature
0142     void evolve();
0143 
0144     OpenclBackend & get_backend();
0145     std::string & get_compile_option();
0146 
0147     ~CLIdeal();
0148 
0149 };
0150 
0151 } // end namespace clvisc
0152 
0153 #endif 
0154 
0155 
0156 /*! \mainpage 
0157  *  \section  */
0158 
0159 /*! 
0160  *  \example 
0161 *
0162  *  \code
0163  *
0164  *
0165 
0166 
0167  * \endcode
0168 */
0169 
0170