Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
InitialFromFile.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file InitialFromFile.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 "InitialFromFile.h"
17 
18 // Register the module with the base class
20 
22  SetId("InitialFromFile");
23  h5_helper_ = new HydroinfoH5;
24  event_id_ = -1;
25 }
26 
28  delete h5_helper_;
29 }
30 
32 
34  Clear();
35  Jetscape::JSINFO << "Read initial condition from file";
36  try {
37 
38  std::string initialProfilePath =
39  GetXMLElementText({"IS", "initial_profile_path"});
40 
41  event_id_++;
42  std::ostringstream path_with_filename;
43  path_with_filename << initialProfilePath << "/event-" << event_id_
44  << "/initial.hdf5";
45  JSINFO << "External initial profile path is" << path_with_filename.str();
46 
47  herr_t status;
48  std::ostringstream event_group;
49 
50  event_group << "/event_0";
51  JSINFO << "event_group=" << event_group.str().c_str();
52  H5file_ptr_ = H5Fopen(path_with_filename.str().c_str(), H5F_ACC_RDONLY,
53  H5P_DEFAULT); //H5F_ACC_RDWR, H5F_ACC_RDONLY
54  H5group_ptr_ = H5Gopen(H5file_ptr_, event_group.str().c_str(), H5P_DEFAULT);
55 
56  ReadConfigs();
57  ReadNbcDist();
59 
60  status = H5Gclose(H5group_ptr_);
61  status = H5Fclose(H5file_ptr_);
62 
63  } catch (std::exception &err) {
64  Jetscape::JSWARN << err.what();
65  std::exit(-1);
66  }
67 }
68 
70  Jetscape::JSINFO << "Read initial state configurations from file";
71  double grid_step = h5_helper_->readH5Attribute_double(H5group_ptr_, "dxy");
74  double xmax = dim_x_ * grid_step / 2;
75  SetRanges(xmax, xmax, 0.0);
76  SetSteps(grid_step, grid_step, 0.0);
77  Jetscape::JSINFO << "xmax = " << xmax;
78 
82 }
83 
85  Jetscape::JSINFO << "Read number of binary collisions from file";
86  auto dataset = H5Dopen(H5group_ptr_, "Ncoll_density", H5P_DEFAULT);
87  int dimx = dim_x_;
88  int dimy = dim_y_;
89  double temp_data[dimx][dimy];
90  auto status = H5Dread(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL,
91  H5P_DEFAULT, temp_data);
92  for (int i = 0; i < dimx; i++) {
93  for (int j = 0; j < dimy; j++) {
94  num_of_binary_collisions_.push_back(temp_data[i][j]);
95  }
96  }
97  status = H5Dclose(dataset);
98 }
99 
101  Jetscape::JSINFO << "Read initial entropy density distribution from file";
102  auto dataset = H5Dopen(H5group_ptr_, "matter_density", H5P_DEFAULT);
103  int dimx = dim_x_;
104  int dimy = dim_y_;
105  double temp_data[dimx][dimy];
106  auto status = H5Dread(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL,
107  H5P_DEFAULT, temp_data);
108  for (int i = 0; i < dimx; i++) {
109  for (int j = 0; j < dimy; j++) {
110  entropy_density_distribution_.push_back(temp_data[i][j]);
111  }
112  }
113  status = H5Dclose(dataset);
114 }
115 
117  Jetscape::JSINFO << "clear initial condition vectors";
120 }
121 
122 void InitialFromFile::Write(weak_ptr<JetScapeWriter> w) {}