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_VISC__
0026 #define __CL_VISC__
0027 /*!< Use cpp exceptionn to handel errors */
0028 #define __CL_ENABLE_EXCEPTIONS 
0029 // System includes
0030 //#include <CL/cl.hpp>
0031 #include "clideal.h"
0032 #include "bulkinfo.h"
0033 
0034 namespace clvisc {
0035 
0036 /*! \class CLIdeal c++ wrapper for JetScape 
0037  *  */
0038 class CLVisc
0039 {
0040     private:
0041     Config cfg_;
0042     // CLVisc uses many data and member functions in ideal_
0043     CLIdeal ideal_;
0044     OpenclBackend backend_;
0045 
0046     // store start time to avoid one initilize with multiple evolve()
0047     double tau0_;
0048 
0049     // current time during the evolution
0050     
0051     double tau_;
0052     // size_ = cfg_.nx * cfg_.ny * cfg_.nz
0053     size_t size_;  
0054     std::string compile_option_;
0055 
0056     // notice h_share_pi_ has 10 components
0057     // pi00, 01, 02, 03, 11, 12, 13, 22, 23, 33
0058     std::vector<cl_real> h_shear_pi_;
0059     // notice h_bulk_pi_ has 1 component
0060     std::vector<cl_real> h_bulk_pi_;
0061     // notice h_net_charge_ has 4 components
0062     // net_baryon, net_electric, net_strangeness and one slot for future
0063     std::vector<cl_real4> h_net_charge_;
0064 
0065     cl::Buffer d_shear_pi_[3];
0066     cl::Buffer d_bulk_pi_[3];
0067     cl::Buffer d_net_charge_[3];
0068 
0069     // source term for IS equations
0070     cl::Buffer d_is_shear_pi_src_;
0071     cl::Buffer d_is_bulk_pi_src_;
0072     cl::Buffer d_udx_;
0073     cl::Buffer d_udy_;
0074     cl::Buffer d_udz_;
0075     cl::Buffer d_udiff_;
0076 
0077     // gpu buffer to check the goodness of each cell
0078     cl::Buffer d_goodcell_;
0079 
0080     // kernel functions in kernel_IS.cl
0081     cl::Kernel kernel_is_initialize_;
0082     cl::Kernel kernel_is_src_christoffel_;
0083     cl::Kernel kernel_is_src_alongx_;
0084     cl::Kernel kernel_is_src_alongy_;
0085     cl::Kernel kernel_is_src_alongz_;
0086     cl::Kernel kernel_is_update_pimn_;
0087     cl::Kernel kernel_is_get_udiff_;
0088 
0089     // kernel functions in kernel_visc.cl
0090     cl::Kernel kernel_visc_src_christoffel_;
0091     cl::Kernel kernel_visc_kt_src_alongx_;
0092     cl::Kernel kernel_visc_kt_src_alongy_;
0093     cl::Kernel kernel_visc_kt_src_alongz_;
0094     cl::Kernel kernel_visc_update_ev_;
0095 
0096     void initialize_gpu_buffer_();
0097 
0098     void israel_stewart_initialize_();
0099 
0100     // d_udiff = u_{visc}^{n} - u_{visc}^{n-1}
0101     void update_udiff_();
0102 
0103     void half_step_israel_stewart_(int step);
0104     void half_step_visc_(int step);
0105     // update half step using Runge-Kutta method, step = {1, 2}
0106     void half_step_(int step);
0107 
0108     public:
0109 
0110     CLVisc(const Config & cfg, std::string device_type, int device_id);
0111 
0112     BulkInfo bulkinfo_;
0113 
0114     inline const Config & get_config() {return cfg_;}
0115 
0116     // read initial energy density from external vector
0117     template <typename ValueType>
0118     void read_ini(const std::vector<ValueType> & ed);
0119 
0120     // read initial ed, vx, vy, vz vector
0121     template <typename ValueType>
0122     void read_ini(const std::vector<ValueType> & ed, 
0123                   const std::vector<ValueType> & vx, 
0124                   const std::vector<ValueType> & vy, 
0125                   const std::vector<ValueType> & vz);
0126 
0127     // read initial ed, vx, vy, vz vector and shear viscosity
0128     template <typename ValueType>
0129     void read_ini(const std::vector<ValueType> & ed, 
0130                   const std::vector<ValueType> & vx, 
0131                   const std::vector<ValueType> & vy, 
0132                   const std::vector<ValueType> & vz,
0133                   const std::vector<ValueType> & pi00,
0134                   const std::vector<ValueType> & pi01,
0135                   const std::vector<ValueType> & pi02,
0136                   const std::vector<ValueType> & pi03,
0137                   const std::vector<ValueType> & pi11,
0138                   const std::vector<ValueType> & pi12,
0139                   const std::vector<ValueType> & pi13,
0140                   const std::vector<ValueType> & pi22,
0141                   const std::vector<ValueType> & pi23,
0142                   const std::vector<ValueType> & pi33);
0143 
0144     // read initial ed, vx, vy, vz vector and shear viscosity,
0145     // bulk viscosity and charge current
0146     template <typename ValueType>
0147     void read_ini(const std::vector<ValueType> & ed, 
0148                   const std::vector<ValueType> & vx, 
0149                   const std::vector<ValueType> & vy, 
0150                   const std::vector<ValueType> & vz,
0151                   const std::vector<ValueType> & pi00,
0152                   const std::vector<ValueType> & pi01,
0153                   const std::vector<ValueType> & pi02,
0154                   const std::vector<ValueType> & pi03,
0155                   const std::vector<ValueType> & pi11,
0156                   const std::vector<ValueType> & pi12,
0157                   const std::vector<ValueType> & pi13,
0158                   const std::vector<ValueType> & pi22,
0159                   const std::vector<ValueType> & pi23,
0160                   const std::vector<ValueType> & pi33,
0161                   const std::vector<ValueType> & bulk_pi,
0162                   const std::vector<ValueType> & net_charge_baryon_,
0163                   const std::vector<ValueType> & net_charge_electric,
0164                   const std::vector<ValueType> & net_charge_strange);
0165 
0166 
0167     // run clvisc evolution for one time step
0168     void one_step();
0169 
0170     // run clvisc evolution for all time steps
0171     // stop when max_T < freeze_out_temperature
0172     void evolve();
0173 
0174 
0175     ~CLVisc();
0176 
0177 };
0178 
0179 } // end namespace clvisc
0180 
0181 #endif 
0182 
0183 
0184 /*! \mainpage 
0185  *  \section  */
0186 
0187 /*! 
0188  *  \example 
0189 *
0190  *  \code
0191  *
0192  *
0193 
0194 
0195  * \endcode
0196 */
0197 
0198