Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
bulkinfo.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file bulkinfo.cc
1 /*******************************************************************************
2  * Copyright (c) 2018-2019 LongGang Pang, lgpang@qq.com
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and/or associated documentation files (the
6  * "Materials"), to deal in the Materials without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Materials, and to
9  * permit persons to whom the Materials are furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included
13  * in all copies or substantial portions of the Materials.
14  *
15  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21  * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
22  ******************************************************************************/
23 
24 
26 #define __CL_ENABLE_EXCEPTIONS
27 // System includes
28 //#include <CL/cl.hpp>
29 #include <cstdlib>
30 #include <cstdio>
31 #include <string>
32 #include <vector>
33 #include <cmath>
34 #include <iostream>
35 #include <fstream>
36 #include <sstream>
37 #include <cassert>
38 #include <ctime>
39 #include <algorithm>
40 #include <map>
41 
42 #include <random>
43 
44 #include "include/Config.h"
45 #include "include/opencl_backend.h"
46 #include "include/bulkinfo.h"
47 #include "include/error_msgs.h"
48 
49 namespace clvisc {
50 
51 
52 BulkInfo::BulkInfo(int nx, int ny, int neta,
53  int nx_skip, int ny_skip, int neta_skip,
54  const OpenclBackend & backend,
55  const std::string & compile_option): nx_(nx), ny_(ny), neta_(neta),
56  nx_skip_(nx_skip), ny_skip_(ny_skip), neta_skip_(neta_skip),
57  backend_(backend), compile_option_(compile_option){
58  nx_out_ = int(floor((nx_-1)/nx_skip_)) + 1;
59  ny_out_ = int(floor((ny_-1)/ny_skip_)) + 1;
60  neta_out_ = int(floor((neta_-1)/neta_skip_)) + 1;
63  data_info_.push_back("energy_density");
64  data_info_.push_back("entropy_density");
65  data_info_.push_back("temperature");
66  data_info_.push_back("pressure");
67  data_info_.push_back("vx");
68  data_info_.push_back("vy");
69  data_info_.push_back("vz");
70  data_info_.push_back("qgp_fraction");
71  data_info_.push_back("pi00");
72  data_info_.push_back("pi01");
73  data_info_.push_back("pi02");
74  data_info_.push_back("pi03");
75  data_info_.push_back("pi11");
76  data_info_.push_back("pi12");
77  data_info_.push_back("pi13");
78  data_info_.push_back("pi22");
79  data_info_.push_back("pi23");
80  data_info_.push_back("pi33");
81 
82  size_t size_out = nx_out_ * ny_out_ * neta_out_ * data_info_.size();
83  h_bulk3d_1step_.resize(size_out);
84  try {
85  // build kernels for hydrodynamic evolution
86  auto prg = backend_.BuildProgram("clvisc_kernel/kernel_bulk3d.cl", compile_option_);
87  kernel_bulk3d_ = cl::Kernel(prg, "kernel_bulk3d");
88  d_bulk3d_1step_ = backend_.CreateBuffer(size_out * sizeof(float));
89  } catch (cl::Error & err ){
90  std::cerr<<"Error:"<<err.what()<<"("<<err.err()<<")\n";
91  std::cerr<<"@" << __FILE__ << ":line " << __LINE__ << std::endl;
92  std::cerr<<ErrorMessage(err.err())<<std::endl;
93  throw(err);
94  }
95 }
96 
97 /* push the fluid cell info of one time step back into a big vector */
98 void BulkInfo::add_data(const cl::Buffer & d_ev,
99  const cl::Buffer & d_shear_pi,
100  const cl::Buffer & d_bulk_pi,
101  const cl::Image2D & eos_table){
103  kernel_bulk3d_.setArg(1, d_ev);
104  kernel_bulk3d_.setArg(2, d_shear_pi);
105  kernel_bulk3d_.setArg(3, d_bulk_pi);
106  kernel_bulk3d_.setArg(4, eos_table);
109  cl::NullRange);
111  for (auto val : h_bulk3d_1step_) {
112  bulk_data_.push_back(val);
113  }
114 }
115 
116 const std::vector<float> & BulkInfo::get_data() {
117  return bulk_data_;
118 }
119 
120 const std::vector<std::string> & BulkInfo::get_data_info() {
121  return data_info_;
122 }
123 
124 void BulkInfo::save(const std::string & fpath){
125  // save the data to given fpath
126  std::ofstream fout(fpath);
127  int idx = 0;
128  fout << "# nx=" << nx_out_ << std::endl;
129  fout << "# ny=" << ny_out_ << std::endl;
130  fout << "# nz=" << neta_out_ << std::endl;
131  fout << "# num_entries =" << data_info_.size() << std::endl;
132  fout << "# ";
133  for (auto val : data_info_) {
134  fout << val << " ";
135  }
136  fout << std::endl;
137  for (auto val : bulk_data_) {
138  idx ++;
139  fout << val << " ";
140  if (idx % data_info_.size() == 0) {
141  fout << std::endl;
142  }
143  }
144  fout.close();
145 }
146 
147 } // end namespace clvisc
148 
149