Version: SMASH-1.6
customnucleus.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2018
3  * SMASH Team
4  *
5  * GNU General Public License (GPLv3 or later)
6  */
7 #include <fstream>
8 #include <map>
9 #include <string>
10 #include <vector>
11 
12 #include "smash/collidermodus.h"
13 #include "smash/customnucleus.h"
14 #include "smash/particledata.h"
15 #include "smash/particletype.h"
16 #include "smash/pdgcode.h"
18 
19 namespace smash {
20 
87 std::unique_ptr<std::ifstream> CustomNucleus::filestream_ = nullptr;
89 
90 CustomNucleus::CustomNucleus(Configuration& config, int testparticles) {
91  // Read in file directory from config
92  std::string fd = config.take({"Custom", "File_Directory"});
94  // Read in file name from config
95  std::string fn = config.take({"Custom", "File_Name"});
97 
98  if (particles_.size() != 0) {
99  throw std::runtime_error(
100  "Your Particle List is already filled before reading in from the "
101  "external file."
102  "Something went wrong. Please check your config.");
103  }
104 
105  /*
106  * Counts number of nucleons in one nucleus as it is specialized
107  * by the user in the config file.
108  * It is needed to read in the proper number of nucleons for one
109  * nucleus and to restart at the listreading for the following
110  * nucleus as one does not want to read configurations twice. */
111  std::map<PdgCode, int> particle_list = config.take({"Particles"});
112  for (const auto& particle : particle_list)
113  number_of_nucleons_ += particle.second * testparticles;
114  if (!checkfileopen_) {
115  filestream_ = make_unique<std::ifstream>(
117  // tracked that file was opened once
118  checkfileopen_ = true;
119  }
121 
123  // Inherited from nucleus class (see nucleus.h)
125 }
126 
127 void CustomNucleus::fill_from_list(const std::vector<Nucleoncustom>& vec) {
128  particles_.clear();
129  index = 0;
130  // checking if particle is proton or neutron
131  for (const auto& it : vec) {
132  PdgCode pdgcode;
133  if (it.isospin == 1) {
134  pdgcode = pdg::p;
135  } else if (it.isospin == 0) {
136  pdgcode = pdg::n;
137  } else {
138  throw std::runtime_error(
139  "Your particles charges are not 1 = proton or 0 = neutron."
140  "Check whether your list is correct or there is an error.");
141  }
142  // setting parameters for the particles in the particlelist in smash
143  const ParticleType& current_type = ParticleType::find(pdgcode);
144  double current_mass = current_type.mass();
145  particles_.emplace_back(current_type);
146  particles_.back().set_4momentum(current_mass, 0.0, 0.0, 0.0);
147  }
148 }
149 
151  if (index >= custom_nucleon_.size()) {
153 
155  }
156  const auto& pos = custom_nucleon_.at(index);
157  index++;
158  return ThreeVector(pos.x, pos.y, pos.z);
159 }
160 
161 std::string CustomNucleus::streamfile(const std::string& file_directory,
162  const std::string& file_name) {
163  if (file_directory.back() == '/') {
164  return file_directory + file_name;
165  } else {
166  return file_directory + '/' + file_name;
167  }
168 }
169 
170 std::vector<Nucleoncustom> CustomNucleus::readfile(std::ifstream& infile,
171  int particle_number) const {
172  int A = particle_number;
173  std::string line;
174  std::vector<Nucleoncustom> nucleon;
175  int i = 0;
176  while (std::getline(infile, line)) {
177  Nucleoncustom nuc;
178  std::istringstream iss(line);
179  if (!(iss >> nuc.x >> nuc.y >> nuc.z >> nuc.spinprojection >>
180  nuc.isospin)) {
181  throw std::runtime_error(
182  "SMASH could not read in a line from your initial nuclei input file."
183  "Check if your file has follwing format: x y z spinprojection "
184  "isospin");
185  break;
186  }
187  nucleon.push_back(nuc);
188  // ensuring that only A particles are read in for one nucleus
189  if (++i == A) {
190  break;
191  }
192  }
193  return nucleon;
194 }
195 
196 } // namespace smash
double x
x-coordinate
Definition: customnucleus.h:25
std::vector< Nucleoncustom > readfile(std::ifstream &infile, int particle_number) const
The returned vector contains Data for one nucleus given in the particlelist.
The ThreeVector class represents a physical three-vector with the components .
Definition: threevector.h:30
double y
y-coordinate
Definition: customnucleus.h:27
std::vector< Nucleoncustom > custom_nucleon_
Vector contianing Data for one nucleus given in the particlelist.
Definition: customnucleus.h:89
bool isospin
to differentiate between protons isospin=1 and neutrons isospin=0
Definition: customnucleus.h:33
static bool checkfileopen_
Bool variable to check if the file was already opened.
size_t index
Index needed to read out vector in distribute nucleon.
Definition: customnucleus.h:91
int number_of_nucleons_
of Nucleons per Nucleus Set initally to zero to be modified in the constructor.
Definition: customnucleus.h:87
Interface to the SMASH configuration files.
static std::string streamfile(const std::string &file_directory, const std::string &file_name)
Generates the name of the stream file.
static const ParticleType & find(PdgCode pdgcode)
Returns the ParticleType object for the given pdgcode.
Contains data for one nucleon that is read in from the list.
Definition: customnucleus.h:23
double mass() const
Definition: particletype.h:144
Value take(std::initializer_list< const char * > keys)
The default interface for SMASH to read configuration values.
Particle type contains the static properties of a particle species.
Definition: particletype.h:97
PdgCode stores a Particle Data Group Particle Numbering Scheme particle type number.
Definition: pdgcode.h:108
static std::unique_ptr< std::ifstream > filestream_
Variable carrying the output of the streamfile function.
bool spinprojection
spinprojection of the nucleon
Definition: customnucleus.h:31
void fill_from_list(const std::vector< Nucleoncustom > &vec)
Fills Particlelist from vector containing data for one nucleus.
CustomNucleus(Configuration &config, int testparticles)
Constructor that needs configuration parameters from input file and the number of testparticles...
constexpr int p
Proton.
std::vector< ParticleData > particles_
Particles associated with this nucleus.
Definition: nucleus.h:210
std::string particle_list_file_directory_
Directory where the nucleon configurations are located.
Definition: customnucleus.h:75
constexpr int n
Neutron.
std::string particle_list_file_name_
File name of the nucleon configurations.
Definition: customnucleus.h:80
virtual void set_parameters_automatic()
Sets the deformation parameters of the Woods-Saxon distribution according to the current mass number...
Definition: nucleus.cc:283
ThreeVector distribute_nucleon() override
Returns position of a nucleon as given in the external file.
Definition: action.h:24
double z
z-coordinate
Definition: customnucleus.h:29