Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:19:25

0001 /*******************************************************************************
0002  * Copyright (c) The JETSCAPE Collaboration, 2018
0003  *
0004  * Modular, task-based framework for simulating all aspects of heavy-ion collisions
0005  * 
0006  * For the list of contributors see AUTHORS.
0007  *
0008  * Report issues at https://github.com/JETSCAPE/JETSCAPE/issues
0009  *
0010  * or via email to bugs.jetscape@gmail.com
0011  *
0012  * Distributed under the GNU General Public License 3.0 (GPLv3 or later).
0013  * See COPYING for details.
0014  ******************************************************************************/
0015 
0016 #include "InitialFromFile.h"
0017 
0018 // Register the module with the base class
0019 RegisterJetScapeModule<InitialFromFile> InitialFromFile::reg("InitialFromFile");
0020 
0021 InitialFromFile::InitialFromFile() {
0022   SetId("InitialFromFile");
0023   h5_helper_ = new HydroinfoH5;
0024   event_id_ = -1;
0025 }
0026 
0027 InitialFromFile::~InitialFromFile() {
0028   delete h5_helper_;
0029 }
0030 
0031 void InitialFromFile::InitTask() {}
0032 
0033 void InitialFromFile::Exec() {
0034   Clear();
0035   Jetscape::JSINFO << "Read initial condition from file";
0036   try {
0037 
0038     std::string initialProfilePath =
0039         GetXMLElementText({"IS", "initial_profile_path"});
0040 
0041     event_id_++;
0042     std::ostringstream path_with_filename;
0043     path_with_filename << initialProfilePath << "/event-" << event_id_
0044                        << "/initial.hdf5";
0045     JSINFO << "External initial profile path is" << path_with_filename.str();
0046 
0047     herr_t status;
0048     std::ostringstream event_group;
0049 
0050     event_group << "/event_0";
0051     JSINFO << "event_group=" << event_group.str().c_str();
0052     H5file_ptr_ = H5Fopen(path_with_filename.str().c_str(), H5F_ACC_RDONLY,
0053                           H5P_DEFAULT); //H5F_ACC_RDWR, H5F_ACC_RDONLY
0054     H5group_ptr_ = H5Gopen(H5file_ptr_, event_group.str().c_str(), H5P_DEFAULT);
0055 
0056     ReadConfigs();
0057     ReadNbcDist();
0058     ReadEntropyDist();
0059 
0060     status = H5Gclose(H5group_ptr_);
0061     status = H5Fclose(H5file_ptr_);
0062 
0063   } catch (std::exception &err) {
0064     Jetscape::JSWARN << err.what();
0065     std::exit(-1);
0066   }
0067 }
0068 
0069 void InitialFromFile::ReadConfigs() {
0070   Jetscape::JSINFO << "Read initial state configurations from file";
0071   double grid_step = h5_helper_->readH5Attribute_double(H5group_ptr_, "dxy");
0072   dim_x_ = h5_helper_->readH5Attribute_int(H5group_ptr_, "Nx");
0073   dim_y_ = h5_helper_->readH5Attribute_int(H5group_ptr_, "Ny");
0074   double xmax = dim_x_ * grid_step / 2;
0075   SetRanges(xmax, xmax, 0.0);
0076   SetSteps(grid_step, grid_step, 0.0);
0077   Jetscape::JSINFO << "xmax = " << xmax;
0078 
0079   npart = h5_helper_->readH5Attribute_double(H5group_ptr_, "npart");
0080   ncoll = h5_helper_->readH5Attribute_double(H5group_ptr_, "ncoll");
0081   totalentropy = h5_helper_->readH5Attribute_double(H5group_ptr_, "mult");
0082 }
0083 
0084 void InitialFromFile::ReadNbcDist() {
0085   Jetscape::JSINFO << "Read number of binary collisions from file";
0086   auto dataset = H5Dopen(H5group_ptr_, "Ncoll_density", H5P_DEFAULT);
0087   int dimx = dim_x_;
0088   int dimy = dim_y_;
0089   double temp_data[dimx][dimy];
0090   auto status = H5Dread(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL,
0091                         H5P_DEFAULT, temp_data);
0092   for (int i = 0; i < dimx; i++) {
0093     for (int j = 0; j < dimy; j++) {
0094       num_of_binary_collisions_.push_back(temp_data[i][j]);
0095     }
0096   }
0097   status = H5Dclose(dataset);
0098 }
0099 
0100 void InitialFromFile::ReadEntropyDist() {
0101   Jetscape::JSINFO << "Read initial entropy density distribution from file";
0102   auto dataset = H5Dopen(H5group_ptr_, "matter_density", H5P_DEFAULT);
0103   int dimx = dim_x_;
0104   int dimy = dim_y_;
0105   double temp_data[dimx][dimy];
0106   auto status = H5Dread(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL,
0107                         H5P_DEFAULT, temp_data);
0108   for (int i = 0; i < dimx; i++) {
0109     for (int j = 0; j < dimy; j++) {
0110       entropy_density_distribution_.push_back(temp_data[i][j]);
0111     }
0112   }
0113   status = H5Dclose(dataset);
0114 }
0115 
0116 void InitialFromFile::Clear() {
0117   Jetscape::JSINFO << "clear initial condition vectors";
0118   entropy_density_distribution_.clear();
0119   num_of_binary_collisions_.clear();
0120 }
0121 
0122 void InitialFromFile::Write(weak_ptr<JetScapeWriter> w) {}