Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CLViscWrapper.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CLViscWrapper.cc
1 /*******************************************************************************
2  * Copyright (c) The JETSCAPE Collaboration, 2018
3  *
4  * Modular, task-based framework for simulating all aspects of heavy-ion collisions
5  *
6  * For the list of contributors see AUTHORS.
7  *
8  * Report issues at https://github.com/JETSCAPE/JETSCAPE/issues
9  *
10  * or via email to bugs.jetscape@gmail.com
11  *
12  * Distributed under the GNU General Public License 3.0 (GPLv3 or later).
13  * See COPYING for details.
14  ******************************************************************************/
15 
16 #include <stdio.h>
17 #include <sys/stat.h>
18 #include <MakeUniqueHelper.h>
19 
20 #include <string>
21 #include <vector>
22 
23 #include "JetScapeLogger.h"
24 #include "CLViscWrapper.h"
25 
26 using namespace Jetscape;
27 
28 // Register the module with the base class
30 
32  hydro_status = NOT_START;
33  SetId("CLVisc");
34 }
35 
37 
38 void CLVisc::InitializeHydro(Parameter parameter_list) {
39  JSINFO << "Initialize CLVisc ...";
40  VERBOSE(8);
41 
42  std::string s = GetXMLElementText({"Hydro", "CLVisc", "name"});
43  JSDEBUG << s << " to be initialized ...";
44 
46 
47  std::string device_type =
48  GetXMLElementText({"Hydro", "CLVisc", "device_type"});
49 
50  if (device_type == "cpu" || device_type == "CPU") {
51  cfg.block_size = GetXMLElementInt({"Hydro", "CLVisc", "cpu_block_size"});
52  } else {
53  cfg.block_size = GetXMLElementInt({"Hydro", "CLVisc", "gpu_block_size"});
54  }
55  int device_id = GetXMLElementInt({"Hydro", "CLVisc", "device_id"});
56  cfg.etaos_xmin = GetXMLElementInt({"Hydro", "CLVisc", "etaos_xmin"});
57  cfg.etaos_ymin = GetXMLElementInt({"Hydro", "CLVisc", "etaos_ymin"});
58  cfg.etaos_left_slop =
59  GetXMLElementInt({"Hydro", "CLVisc", "etaos_left_slop"});
60  cfg.etaos_right_slop =
61  GetXMLElementInt({"Hydro", "CLVisc", "etaos_right_slop"});
62  cfg.result_directory =
63  GetXMLElementInt({"Hydro", "CLVisc", "result_directory"});
64  doCooperFrye =
65  GetXMLElementInt({"Hydro", "CLVisc", "Perform_CooperFrye_Feezeout"});
66  cfg.tau0 = GetXMLElementDouble({"Hydro", "CLVisc", "tau0"});
67  cfg.dt = GetXMLElementDouble({"Hydro", "CLVisc", "dtau"});
68  cfg.ntskip = GetXMLElementDouble({"Hydro", "CLVisc", "ntau_skip"});
69  cfg.nxskip = GetXMLElementDouble({"Hydro", "CLVisc", "nx_skip"});
70  cfg.nyskip = GetXMLElementDouble({"Hydro", "CLVisc", "ny_skip"});
71  cfg.nzskip = GetXMLElementDouble({"Hydro", "CLVisc", "netas_skip"});
72 
73  cfg.dx = ini->GetXStep();
74  cfg.dy = ini->GetYStep();
75  cfg.dz = ini->GetZStep();
76  cfg.nx = ini->GetXSize();
77  cfg.ny = ini->GetYSize();
78  cfg.nz = ini->GetZSize();
79 
80  hydro_ = std::unique_ptr<clvisc::CLVisc>(
81  new clvisc::CLVisc(cfg, device_type, device_id));
82  initial_condition_scale_factor =
83  GetXMLElementDouble({"Hydro", "CLVisc", "scale_factor"});
84 }
85 
87  VERBOSE(8);
88  JSINFO << "Initialize density profiles in CLVisc ...";
89  std::vector<double> entropy_density = ini->GetEntropyDensityDistribution();
90  double dx = ini->GetXStep();
91  if (pre_eq_ptr == nullptr) {
92  if (initial_condition_scale_factor == 1.0) {
93  hydro_->read_ini(entropy_density);
94  } else {
95  std::for_each(
96  entropy_density.begin(), entropy_density.end(),
97  [&](double &sd) { sd = initial_condition_scale_factor * sd; });
98  hydro_->read_ini(entropy_density);
99  }
100  } else {
101  std::vector<double> vx_, vy_, vz_;
102  for (size_t idx = 0; idx < pre_eq_ptr->ux_.size(); idx++) {
103  vx_.push_back(pre_eq_ptr->ux_.at(idx) / pre_eq_ptr->utau_.at(idx));
104  vy_.push_back(pre_eq_ptr->uy_.at(idx) / pre_eq_ptr->utau_.at(idx));
105  vz_.push_back(pre_eq_ptr->ueta_.at(idx) / pre_eq_ptr->utau_.at(idx));
106  }
107 
108  hydro_->read_ini(pre_eq_ptr->e_, vx_, vy_, vz_, pre_eq_ptr->pi00_,
109  pre_eq_ptr->pi01_, pre_eq_ptr->pi02_, pre_eq_ptr->pi03_,
110  pre_eq_ptr->pi11_, pre_eq_ptr->pi12_, pre_eq_ptr->pi13_,
111  pre_eq_ptr->pi22_, pre_eq_ptr->pi23_, pre_eq_ptr->pi33_);
112  }
113 
114  hydro_status = INITIALIZED;
115  if (hydro_status == INITIALIZED) {
116  JSINFO << "running CLVisc ...";
117  hydro_->evolve();
118  hydro_status = FINISHED;
119 
120  auto cfg = hydro_->get_config();
121  float tau_min = cfg.tau0;
122  float dtau = cfg.dt * cfg.ntskip;
123  float dx = cfg.dx * cfg.nxskip;
124  float dy = cfg.dy * cfg.nyskip;
125  float detas = cfg.dz * cfg.nzskip;
126  float x_min = -0.5f * cfg.nx * cfg.dx;
127  float y_min = -0.5f * cfg.ny * cfg.dy;
128  float etas_min = -0.5f * cfg.nz * cfg.dz;
129  int nx = int(floor((cfg.nx - 1) / cfg.nxskip)) + 1;
130  int ny = int(floor((cfg.ny - 1) / cfg.nyskip)) + 1;
131  int netas = int(floor((cfg.nz - 1) / cfg.nzskip)) + 1;
132 
133  bulk_info.FromVector(hydro_->bulkinfo_.get_data(),
134  hydro_->bulkinfo_.get_data_info(), tau_min, dtau,
135  x_min, dx, nx, y_min, dy, ny, etas_min, detas, netas,
136  false);
137  //hydro_->bulkinfo_.save("bulk_data.csv");
138  }
139  if (hydro_status == FINISHED && doCooperFrye == 1) {
140  JSINFO << "Cooper Frye not implemented yet";
141  }
142 }
143 
146  std::unique_ptr<FluidCellInfo> &fluid_cell_info_ptr) {
147  fluid_cell_info_ptr = make_unique<FluidCellInfo>();
148  if (hydro_status != FINISHED) {
149  throw std::runtime_error("Hydro evolution is not finished ");
150  }
151 
152  if (!bulk_info.tau_eta_is_tz) {
153  Jetscape::real tau = std::sqrt(t * t - z * z);
154  Jetscape::real eta = 0.5 * (std::log(t + z) - std::log(t - z));
155  *fluid_cell_info_ptr = bulk_info.get(tau, x, y, eta);
156  } else {
157  *fluid_cell_info_ptr = bulk_info.get(t, x, y, z);
158  }
159 }