diff --git a/compile.sh b/compile.sh index 4873ce99..91414c56 100755 --- a/compile.sh +++ b/compile.sh @@ -1,5 +1,10 @@ #!/usr/bin/env bash + +# format the code base +bash formatCode.sh + +# compile the code mkdir -p build cd build rm -fr * diff --git a/formatCode.sh b/formatCode.sh index 814b9fbc..e1e634a4 100755 --- a/formatCode.sh +++ b/formatCode.sh @@ -1,4 +1,9 @@ #!/usr/bin/env bash - -find src -iname '*.h' -o -iname '*.cpp' | xargs clang-format -i -style=file +if command -v clang-format &> /dev/null +then + echo "formatting code ..." + find src -iname '*.h' -o -iname '*.cpp' | xargs clang-format -i -style=file +else + echo "clang-format not found, skip formatting code" +fi diff --git a/src/HydroinfoMUSIC.cpp b/src/HydroinfoMUSIC.cpp index 4b0efea2..f959bed2 100644 --- a/src/HydroinfoMUSIC.cpp +++ b/src/HydroinfoMUSIC.cpp @@ -1,16 +1,15 @@ // Copyright Chun Shen @ 2018 -#include "util.h" #include "HydroinfoMUSIC.h" +#include "util.h" + HydroinfoMUSIC::HydroinfoMUSIC() { hydroTauMax = 0.0; itaumax = 0; } -HydroinfoMUSIC::~HydroinfoMUSIC() { - clean_hydro_event(); -} +HydroinfoMUSIC::~HydroinfoMUSIC() { clean_hydro_event(); } void HydroinfoMUSIC::clean_hydro_event() { lattice_ideal.clear(); @@ -19,18 +18,18 @@ void HydroinfoMUSIC::clean_hydro_event() { } void HydroinfoMUSIC::getHydroValues( - const double x, const double y, const double z, const double t, - fluidCell* info) { -// For interpolation of evolution files in tau-eta coordinates. Only the -// reading of MUSIC's evolution_xyeta.dat file is implemented here. -// For simplicity, hydro_eta_max refers to MUSIC's eta_size, and similarly for -// hydroDeta; however, x, y, z, and t are as usual to stay compatible with -// MARTINI. + const double x, const double y, const double z, const double t, + fluidCell *info) { + // For interpolation of evolution files in tau-eta coordinates. Only the + // reading of MUSIC's evolution_xyeta.dat file is implemented here. + // For simplicity, hydro_eta_max refers to MUSIC's eta_size, and similarly + // for hydroDeta; however, x, y, z, and t are as usual to stay compatible + // with MARTINI. double tau, eta; if (use_tau_eta_coordinate == 1) { - if (t*t > z*z) { - tau = sqrt(t*t - z*z); - eta = 0.5*log((t + z)/(t - z)); + if (t * t > z * z) { + tau = sqrt(t * t - z * z); + eta = 0.5 * log((t + z) / (t - z)); } else { tau = 0.; eta = 0.; @@ -42,31 +41,34 @@ void HydroinfoMUSIC::getHydroValues( eta = z; } - int ieta = static_cast((hydro_eta_max + eta)/hydroDeta + 0.0001); + int ieta = static_cast((hydro_eta_max + eta) / hydroDeta + 0.0001); if (boost_invariant) { ieta = 0; } - const int itau = static_cast((tau - hydroTau0)/hydroDtau + 0.0001); - const int ix = static_cast((hydroXmax + x)/hydroDx + 0.0001); - const int iy = static_cast((hydroYmax + y)/hydroDy + 0.0001); + const int itau = static_cast((tau - hydroTau0) / hydroDtau + 0.0001); + const int ix = static_cast((hydroXmax + x) / hydroDx + 0.0001); + const int iy = static_cast((hydroYmax + y) / hydroDy + 0.0001); - double xfrac = (x - (static_cast(ix)*hydroDx - hydroXmax))/hydroDx; - double yfrac = (y - (static_cast(iy)*hydroDy - hydroYmax))/hydroDy; - double etafrac = (eta/hydroDeta - static_cast(ieta) - + 0.5*static_cast(ietamax)); - double taufrac = (tau - hydroTau0)/hydroDtau - static_cast(itau); + double xfrac = + (x - (static_cast(ix) * hydroDx - hydroXmax)) / hydroDx; + double yfrac = + (y - (static_cast(iy) * hydroDy - hydroYmax)) / hydroDy; + double etafrac = + (eta / hydroDeta - static_cast(ieta) + + 0.5 * static_cast(ietamax)); + double taufrac = (tau - hydroTau0) / hydroDtau - static_cast(itau); if (ix < 0 || ix >= ixmax) { music_message << "[HydroinfoMUSIC::getHydroValues]: " - << "WARNING - x out of range x=" << x - << ", ix=" << ix << ", ixmax=" << ixmax; + << "WARNING - x out of range x=" << x << ", ix=" << ix + << ", ixmax=" << ixmax; music_message.flush("warning"); music_message << "x=" << x << " y=" << y << " eta=" << eta << " ix=" << ix << " iy=" << iy << " ieta=" << ieta; music_message.flush("warning"); - music_message << "t=" << t << " tau=" << tau - << " itau=" << itau << " itaumax=" << itaumax; + music_message << "t=" << t << " tau=" << tau << " itau=" << itau + << " itaumax=" << itaumax; music_message.flush("warning"); music_message.flush("warning"); @@ -82,13 +84,13 @@ void HydroinfoMUSIC::getHydroValues( if (iy < 0 || iy >= iymax) { music_message << "[HydroinfoMUSIC::getHydroValues]: " - << "WARNING - y out of range, y=" << y << ", iy=" << iy + << "WARNING - y out of range, y=" << y << ", iy=" << iy << ", iymax=" << iymax; music_message << "x=" << x << " y=" << y << " eta=" << eta << " ix=" << ix << " iy=" << iy << " ieta=" << ieta; music_message.flush("warning"); - music_message << "t=" << t << " tau=" << tau - << " itau=" << itau << " itaumax=" << itaumax; + music_message << "t=" << t << " tau=" << tau << " itau=" << itau + << " itaumax=" << itaumax; music_message.flush("warning"); music_message.flush("warning"); @@ -140,34 +142,34 @@ void HydroinfoMUSIC::getHydroValues( int position[2][2][2][2]; for (int ipx = 0; ipx < 2; ipx++) { int px; - if (ipx == 0 || ix == ixmax-1) { + if (ipx == 0 || ix == ixmax - 1) { px = ix; } else { px = ix + 1; } for (int ipy = 0; ipy < 2; ipy++) { int py; - if (ipy == 0 || iy == iymax-1) { + if (ipy == 0 || iy == iymax - 1) { py = iy; } else { py = iy + 1; } for (int ipeta = 0; ipeta < 2; ipeta++) { int peta; - if (ipeta == 0 || ieta == ietamax-1) { + if (ipeta == 0 || ieta == ietamax - 1) { peta = ieta; } else { peta = ieta + 1; } for (int iptau = 0; iptau < 2; iptau++) { int ptau; - if (iptau == 0 || itau == itaumax-1) { + if (iptau == 0 || itau == itaumax - 1) { ptau = itau; } else { ptau = itau + 1; } - position[ipx][ipy][ipeta][iptau] = ( - px + ixmax*(py + iymax*(peta + ietamax*ptau))); + position[ipx][ipy][ipeta][iptau] = + (px + ixmax * (py + iymax * (peta + ietamax * ptau))); } } } @@ -216,47 +218,54 @@ void HydroinfoMUSIC::getHydroValues( else yfactor = yfrac; - double prefrac = yfactor*etafactor*taufactor; - - HydroCell_ptr1 = ( - &lattice_ideal[position[0][ipy][ipeta][iptau]]); - HydroCell_ptr2 = ( - &lattice_ideal[position[1][ipy][ipeta][iptau]]); - ed += prefrac*((1. - xfrac)*HydroCell_ptr1->ed - + xfrac*HydroCell_ptr2->ed); - sd += prefrac*((1. - xfrac)*HydroCell_ptr1->sd - + xfrac*HydroCell_ptr2->sd); - pressure += prefrac*((1. - xfrac)*HydroCell_ptr1->pressure - + xfrac*HydroCell_ptr2->pressure); - T += prefrac*((1. - xfrac)*HydroCell_ptr1->temperature - + xfrac*HydroCell_ptr2->temperature); - ux += prefrac*((1. - xfrac)*HydroCell_ptr1->ux - + xfrac*HydroCell_ptr2->ux); - uy += prefrac*((1. - xfrac)*HydroCell_ptr1->uy - + xfrac*HydroCell_ptr2->uy); - ueta += prefrac*((1. - xfrac)*HydroCell_ptr1->ueta - + xfrac*HydroCell_ptr2->ueta); + double prefrac = yfactor * etafactor * taufactor; + + HydroCell_ptr1 = + (&lattice_ideal[position[0][ipy][ipeta][iptau]]); + HydroCell_ptr2 = + (&lattice_ideal[position[1][ipy][ipeta][iptau]]); + ed += prefrac + * ((1. - xfrac) * HydroCell_ptr1->ed + + xfrac * HydroCell_ptr2->ed); + sd += prefrac + * ((1. - xfrac) * HydroCell_ptr1->sd + + xfrac * HydroCell_ptr2->sd); + pressure += prefrac + * ((1. - xfrac) * HydroCell_ptr1->pressure + + xfrac * HydroCell_ptr2->pressure); + T += prefrac + * ((1. - xfrac) * HydroCell_ptr1->temperature + + xfrac * HydroCell_ptr2->temperature); + ux += prefrac + * ((1. - xfrac) * HydroCell_ptr1->ux + + xfrac * HydroCell_ptr2->ux); + uy += prefrac + * ((1. - xfrac) * HydroCell_ptr1->uy + + xfrac * HydroCell_ptr2->uy); + ueta += prefrac + * ((1. - xfrac) * HydroCell_ptr1->ueta + + xfrac * HydroCell_ptr2->ueta); } } } - double eta_local = 0.5*log((t + z)/(t - z)); + double eta_local = 0.5 * log((t + z) / (t - z)); double sinh_eta, cosh_eta; if (fabs(eta_local) < 1e-6) { // use Taylor expansion for small eta_s to speed up // avoiding to evaluate sinh and cosh sinh_eta = eta_local; - cosh_eta = 1.0 + 0.5*eta_local*eta_local; + cosh_eta = 1.0 + 0.5 * eta_local * eta_local; } else { sinh_eta = sinh(eta_local); cosh_eta = cosh(eta_local); } - double utau = sqrt(1. + ux*ux + uy*uy + ueta*ueta); - double uz = utau*sinh_eta + ueta*cosh_eta; - double ut = utau*cosh_eta + ueta*sinh_eta; - vx = ux/ut; - vy = uy/ut; - vz = uz/ut; + double utau = sqrt(1. + ux * ux + uy * uy + ueta * ueta); + double uz = utau * sinh_eta + ueta * cosh_eta; + double ut = utau * cosh_eta + ueta * sinh_eta; + vx = ux / ut; + vy = uy / ut; + vz = uz / ut; info->temperature = static_cast(T); info->vx = static_cast(vx); @@ -287,22 +296,21 @@ void HydroinfoMUSIC::getHydroValues( info->bulkPi = static_cast(bulkPi); } - -void HydroinfoMUSIC::get_fluid_cell_with_index(const int idx, - fluidCell *info) const { +void HydroinfoMUSIC::get_fluid_cell_with_index( + const int idx, fluidCell *info) const { info->temperature = static_cast(lattice_ideal[idx].temperature); - - double ux = lattice_ideal[idx].ux; - double uy = lattice_ideal[idx].uy; + + double ux = lattice_ideal[idx].ux; + double uy = lattice_ideal[idx].uy; double ueta = lattice_ideal[idx].ueta; - double utau = sqrt(1. + ux*ux + uy*uy + ueta*ueta); + double utau = sqrt(1. + ux * ux + uy * uy + ueta * ueta); double sinh_eta = sinh(lattice_ideal[idx].eta); double cosh_eta = cosh(lattice_ideal[idx].eta); - double uz = utau*sinh_eta + ueta*cosh_eta; - double ut = utau*cosh_eta + ueta*sinh_eta; - info->vx = static_cast(ux/ut); - info->vy = static_cast(uy/ut); - info->vz = static_cast(uz/ut); + double uz = utau * sinh_eta + ueta * cosh_eta; + double ut = utau * cosh_eta + ueta * sinh_eta; + info->vx = static_cast(ux / ut); + info->vy = static_cast(uy / ut); + info->vz = static_cast(uz / ut); info->ed = static_cast(lattice_ideal[idx].ed); info->sd = static_cast(lattice_ideal[idx].sd); @@ -328,32 +336,32 @@ void HydroinfoMUSIC::get_fluid_cell_with_index(const int idx, info->bulkPi = static_cast(0.0); } - void HydroinfoMUSIC::set_grid_infomatioin(const InitData &DATA) { use_tau_eta_coordinate = 1; boost_invariant = DATA.boost_invariant; hydroTau0 = DATA.tau0; - hydroDtau = DATA.delta_tau*DATA.output_evolution_every_N_timesteps; - hydroXmax = DATA.x_size/2.; - hydroYmax = DATA.y_size/2.; - ixmax = (static_cast((DATA.nx + 1) - /DATA.output_evolution_every_N_x) + 1); - iymax = (static_cast((DATA.ny + 1) - /DATA.output_evolution_every_N_y) + 1); - hydro_eta_max = DATA.eta_size/2.; - ietamax = static_cast(DATA.neta/DATA.output_evolution_every_N_eta); - hydroDx = DATA.delta_x*DATA.output_evolution_every_N_x; - hydroDy = DATA.delta_y*DATA.output_evolution_every_N_y; - hydroDeta = DATA.delta_eta*DATA.output_evolution_every_N_eta; - - hydroXmax = DATA.x_size/2.; - hydro_eta_max = DATA.eta_size/2.; - - ixmax = (static_cast((DATA.nx - 1) - /DATA.output_evolution_every_N_x) + 1); - ietamax = (static_cast((DATA.neta - 1) - /DATA.output_evolution_every_N_eta) + 1); + hydroDtau = DATA.delta_tau * DATA.output_evolution_every_N_timesteps; + hydroXmax = DATA.x_size / 2.; + hydroYmax = DATA.y_size / 2.; + ixmax = + (static_cast((DATA.nx + 1) / DATA.output_evolution_every_N_x) + 1); + iymax = + (static_cast((DATA.ny + 1) / DATA.output_evolution_every_N_y) + 1); + hydro_eta_max = DATA.eta_size / 2.; + ietamax = static_cast(DATA.neta / DATA.output_evolution_every_N_eta); + hydroDx = DATA.delta_x * DATA.output_evolution_every_N_x; + hydroDy = DATA.delta_y * DATA.output_evolution_every_N_y; + hydroDeta = DATA.delta_eta * DATA.output_evolution_every_N_eta; + + hydroXmax = DATA.x_size / 2.; + hydro_eta_max = DATA.eta_size / 2.; + + ixmax = + (static_cast((DATA.nx - 1) / DATA.output_evolution_every_N_x) + 1); + ietamax = + (static_cast((DATA.neta - 1) / DATA.output_evolution_every_N_eta) + + 1); } void HydroinfoMUSIC::print_grid_information() { @@ -372,19 +380,19 @@ void HydroinfoMUSIC::print_grid_information() { music_message.flush("info"); } -void HydroinfoMUSIC::dump_ideal_info_to_memory(double tau, float eta, - float epsilon, float pressure, float entropy, float T, - float ux, float uy, float ueta) { +void HydroinfoMUSIC::dump_ideal_info_to_memory( + double tau, float eta, float epsilon, float pressure, float entropy, + float T, float ux, float uy, float ueta) { if (tau > hydroTauMax) { hydroTauMax = tau; itaumax++; } fluidCell_ideal new_cell; new_cell.eta = eta; - new_cell.temperature = T*Util::hbarc; - new_cell.ed = epsilon*Util::hbarc; + new_cell.temperature = T * Util::hbarc; + new_cell.ed = epsilon * Util::hbarc; new_cell.sd = entropy; - new_cell.pressure = pressure*Util::hbarc; + new_cell.pressure = pressure * Util::hbarc; new_cell.ux = ux; new_cell.uy = uy; new_cell.ueta = ueta; diff --git a/src/HydroinfoMUSIC.h b/src/HydroinfoMUSIC.h index 7c96db91..b8e489c7 100644 --- a/src/HydroinfoMUSIC.h +++ b/src/HydroinfoMUSIC.h @@ -3,27 +3,28 @@ #ifndef SRC_HYDROINFOMUSIC_H_ #define SRC_HYDROINFOMUSIC_H_ -#include #include -#include "data_struct.h" +#include + #include "data.h" +#include "data_struct.h" #include "pretty_ostream.h" class HydroinfoMUSIC { - private: - double hydroTau0; // tau_0 in the hydro data files - double hydroTauMax; // tau_max in the hydro data files - double hydroDtau; // step dtau in fm/c in the hydro data files - double hydroXmax; // maximum x in fm in the hydro data files - // [-xmax, +xmax] for both x and y - double hydroYmax; // maximum y in fm in the hydro data files - // [-ymax, +ymax] for both x and y - double hydro_eta_max; // maximum z in fm in the hydro data files - // [-zmax, +zmax] for 3D hydro - double hydroDx; // step dx in fm in the hydro data files - double hydroDy; // step dy in fm in the hydro data files - double hydroDeta; // step dz in fm in the hydro data files in - // the z-direction for 3D hydro + private: + double hydroTau0; // tau_0 in the hydro data files + double hydroTauMax; // tau_max in the hydro data files + double hydroDtau; // step dtau in fm/c in the hydro data files + double hydroXmax; // maximum x in fm in the hydro data files + // [-xmax, +xmax] for both x and y + double hydroYmax; // maximum y in fm in the hydro data files + // [-ymax, +ymax] for both x and y + double hydro_eta_max; // maximum z in fm in the hydro data files + // [-zmax, +zmax] for 3D hydro + double hydroDx; // step dx in fm in the hydro data files + double hydroDy; // step dy in fm in the hydro data files + double hydroDeta; // step dz in fm in the hydro data files in + // the z-direction for 3D hydro int use_tau_eta_coordinate; bool boost_invariant; @@ -33,38 +34,37 @@ class HydroinfoMUSIC { std::vector lattice_ideal; pretty_ostream music_message; - public: - HydroinfoMUSIC(); // constructor - ~HydroinfoMUSIC(); // destructor + public: + HydroinfoMUSIC(); // constructor + ~HydroinfoMUSIC(); // destructor void clean_hydro_event(); - double get_hydro_tau_max() const {return(hydroTauMax);} - double get_hydro_tau0() const {return(hydroTau0);} - double get_hydro_dtau() const {return(hydroDtau);} - double get_hydro_dx() const {return(hydroDx);} - double get_hydro_dy() const {return(hydroDy);} - double get_hydro_deta() const {return(hydroDeta);} - double get_hydro_eta_max() const {return(hydro_eta_max);} - double get_hydro_x_max() const {return(hydroXmax);} - double get_hydro_y_max() const {return(hydroYmax);} - int get_ntau() const {return(itaumax);} - int get_nx() const {return(ixmax );} - int get_ny() const {return(iymax );} - int get_neta() const {return(ietamax);} - bool is_boost_invariant() const {return(boost_invariant);} + double get_hydro_tau_max() const { return (hydroTauMax); } + double get_hydro_tau0() const { return (hydroTau0); } + double get_hydro_dtau() const { return (hydroDtau); } + double get_hydro_dx() const { return (hydroDx); } + double get_hydro_dy() const { return (hydroDy); } + double get_hydro_deta() const { return (hydroDeta); } + double get_hydro_eta_max() const { return (hydro_eta_max); } + double get_hydro_x_max() const { return (hydroXmax); } + double get_hydro_y_max() const { return (hydroYmax); } + int get_ntau() const { return (itaumax); } + int get_nx() const { return (ixmax); } + int get_ny() const { return (iymax); } + int get_neta() const { return (ietamax); } + bool is_boost_invariant() const { return (boost_invariant); } - void getHydroValues(const double x, const double y, - const double z, const double t, - fluidCell *info); + void getHydroValues( + const double x, const double y, const double z, const double t, + fluidCell *info); void set_grid_infomatioin(const InitData &DATA); void print_grid_information(); - void dump_ideal_info_to_memory(double tau, float eta, float epsilon, - float pressure, float entropy, float T, - float ux, float uy, float ueta); + void dump_ideal_info_to_memory( + double tau, float eta, float epsilon, float pressure, float entropy, + float T, float ux, float uy, float ueta); - int get_number_of_fluid_cells() const {return(lattice_ideal.size());} + int get_number_of_fluid_cells() const { return (lattice_ideal.size()); } void get_fluid_cell_with_index(const int idx, fluidCell *info) const; }; #endif // SRC_HYDROINFO_MUSIC_H_ - diff --git a/src/advance.cpp b/src/advance.cpp index 2621614a..136888f6 100644 --- a/src/advance.cpp +++ b/src/advance.cpp @@ -1,32 +1,33 @@ // Copyright 2011 @ Bjoern Schenke, Sangyong Jeon, and Charles Gale #ifdef _OPENMP - #include +#include #endif #include #include #include -#include "util.h" -#include "data.h" +#include "advance.h" #include "cell.h" -#include "reconst.h" +#include "data.h" #include "eos.h" #include "evolve.h" -#include "advance.h" +#include "reconst.h" +#include "util.h" -using Util::map_2d_idx_to_1d; -using Util::map_1d_idx_to_2d; using Util::hbarc; +using Util::map_1d_idx_to_2d; +using Util::map_2d_idx_to_1d; -Advance::Advance(const EOS &eosIn, const InitData &DATA_in, - std::shared_ptr hydro_source_ptr_in) : - DATA(DATA_in), eos(eosIn), - diss_helper(eosIn, DATA_in), - minmod(DATA_in), - reconst_helper(eos, DATA_in.echo_level, DATA_in.beastMode) { - +Advance::Advance( + const EOS &eosIn, const InitData &DATA_in, + std::shared_ptr hydro_source_ptr_in) + : DATA(DATA_in), + eos(eosIn), + diss_helper(eosIn, DATA_in), + minmod(DATA_in), + reconst_helper(eos, DATA_in.echo_level, DATA_in.beastMode) { hydro_source_terms_ptr = hydro_source_ptr_in; flag_add_hydro_source = false; if (hydro_source_terms_ptr) { @@ -41,67 +42,72 @@ Advance::Advance(const EOS &eosIn, const InitData &DATA_in, } //! this function evolves one Runge-Kutta step in tau -void Advance::AdvanceIt(const double tau, Fields &arenaFieldsPrev, - Fields &arenaFieldsCurr, Fields &arenaFieldsNext, - const int rk_flag) { +void Advance::AdvanceIt( + const double tau, Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, + Fields &arenaFieldsNext, const int rk_flag) { const int grid_neta = arenaFieldsCurr.nEta(); - const int grid_nx = arenaFieldsCurr.nX(); - const int grid_ny = arenaFieldsCurr.nY(); + const int grid_nx = arenaFieldsCurr.nX(); + const int grid_ny = arenaFieldsCurr.nY(); - #pragma omp parallel for collapse(3) schedule(guided) +#pragma omp parallel for collapse(3) schedule(guided) for (int ieta = 0; ieta < grid_neta; ieta++) - for (int ix = 0; ix < grid_nx; ix++ ) - for (int iy = 0; iy < grid_ny; iy++ ) { - int fieldIdx = arenaFieldsCurr.getFieldIdx(ix, iy, ieta); - - double eta_s_local = - DATA.eta_size/2. + ieta*DATA.delta_eta; - double x_local = - DATA.x_size /2. + ix*DATA.delta_x; - double y_local = - DATA.y_size /2. + iy*DATA.delta_y; - - FirstRKStepT(tau, x_local, y_local, eta_s_local, - ix, iy, ieta, rk_flag, - fieldIdx, arenaFieldsCurr, arenaFieldsNext, - arenaFieldsPrev); - - if (DATA.viscosity_flag == 1) { - U_derivative u_derivative_helper(DATA, eos); - u_derivative_helper.MakedU(tau, arenaFieldsPrev, arenaFieldsCurr, - fieldIdx, ix, iy, ieta); - double theta_local = u_derivative_helper.calculate_expansion_rate( - tau, arenaFieldsCurr, fieldIdx); - DumuVec a_local; - u_derivative_helper.calculate_Du_supmu(tau, arenaFieldsCurr, - fieldIdx, a_local); - - VelocityShearVec sigma_local; - u_derivative_helper.calculate_velocity_shear_tensor( - tau, arenaFieldsCurr, fieldIdx, theta_local, - a_local, sigma_local); - - VorticityVec omega_local; - u_derivative_helper.calculate_kinetic_vorticity_with_spatial_projector( - tau, arenaFieldsCurr, fieldIdx, a_local, omega_local); - - DmuMuBoverTVec baryon_diffusion_vector; - u_derivative_helper.get_DmuMuBoverTVec(baryon_diffusion_vector); - - FirstRKStepW(tau, arenaFieldsPrev, arenaFieldsCurr, arenaFieldsNext, - rk_flag,theta_local, a_local, sigma_local, omega_local, - baryon_diffusion_vector, ieta, ix, iy, fieldIdx); - } - } + for (int ix = 0; ix < grid_nx; ix++) + for (int iy = 0; iy < grid_ny; iy++) { + int fieldIdx = arenaFieldsCurr.getFieldIdx(ix, iy, ieta); + + double eta_s_local = + -DATA.eta_size / 2. + ieta * DATA.delta_eta; + double x_local = -DATA.x_size / 2. + ix * DATA.delta_x; + double y_local = -DATA.y_size / 2. + iy * DATA.delta_y; + + FirstRKStepT( + tau, x_local, y_local, eta_s_local, ix, iy, ieta, rk_flag, + fieldIdx, arenaFieldsCurr, arenaFieldsNext, + arenaFieldsPrev); + + if (DATA.viscosity_flag == 1) { + U_derivative u_derivative_helper(DATA, eos); + u_derivative_helper.MakedU( + tau, arenaFieldsPrev, arenaFieldsCurr, fieldIdx, ix, iy, + ieta); + double theta_local = + u_derivative_helper.calculate_expansion_rate( + tau, arenaFieldsCurr, fieldIdx); + DumuVec a_local; + u_derivative_helper.calculate_Du_supmu( + tau, arenaFieldsCurr, fieldIdx, a_local); + + VelocityShearVec sigma_local; + u_derivative_helper.calculate_velocity_shear_tensor( + tau, arenaFieldsCurr, fieldIdx, theta_local, a_local, + sigma_local); + + VorticityVec omega_local; + u_derivative_helper + .calculate_kinetic_vorticity_with_spatial_projector( + tau, arenaFieldsCurr, fieldIdx, a_local, + omega_local); + + DmuMuBoverTVec baryon_diffusion_vector; + u_derivative_helper.get_DmuMuBoverTVec( + baryon_diffusion_vector); + + FirstRKStepW( + tau, arenaFieldsPrev, arenaFieldsCurr, arenaFieldsNext, + rk_flag, theta_local, a_local, sigma_local, omega_local, + baryon_diffusion_vector, ieta, ix, iy, fieldIdx); + } + } } - /* %%%%%%%%%%%%%%%%%%%%%% First steps begins here %%%%%%%%%%%%%%%%%% */ void Advance::FirstRKStepT( - const double tau, const double x_local, const double y_local, - const double eta_s_local, - const int ix, const int iy, const int ieta, const int rk_flag, - const int fieldIdx, Fields &arenaFieldsCurr, - Fields &arenaFieldsNext, Fields &arenaFieldsPrev) { + const double tau, const double x_local, const double y_local, + const double eta_s_local, const int ix, const int iy, const int ieta, + const int rk_flag, const int fieldIdx, Fields &arenaFieldsCurr, + Fields &arenaFieldsNext, Fields &arenaFieldsPrev) { // this advances the ideal part - double tau_rk = tau + rk_flag*(DATA.delta_tau); + double tau_rk = tau + rk_flag * (DATA.delta_tau); auto cellPrev = arenaFieldsPrev.getCellIdeal(fieldIdx); auto cellCurr = arenaFieldsCurr.getCellIdeal(fieldIdx); @@ -117,7 +123,7 @@ void Advance::FirstRKStepT( TJbVec qi = {0}; double pressure = eos.get_pressure(cellCurr.e, cellCurr.rhob); for (int alpha = 0; alpha < 5; alpha++) { - qi[alpha] = get_TJb(cellCurr, alpha, 0, pressure)*tau_rk; + qi[alpha] = get_TJb(cellCurr, alpha, 0, pressure) * tau_rk; } MakeDeltaQI(tau_rk, arenaFieldsCurr, ix, iy, ieta, qi, rk_flag); @@ -130,9 +136,9 @@ void Advance::FirstRKStepT( u_local[ii] = arenaFieldsCurr.u_[ii][fieldIdx]; hydro_source_terms_ptr->get_hydro_energy_source( - tau_rk, x_local, y_local, eta_s_local, u_local, j_mu); + tau_rk, x_local, y_local, eta_s_local, u_local, j_mu); for (int ii = 0; ii < 4; ii++) { - qi_source[ii] = tau_rk*j_mu[ii]; + qi_source[ii] = tau_rk * j_mu[ii]; if (isnan(qi_source[ii])) { music_message << "qi_source is nan. i = " << ii; music_message.flush("error"); @@ -141,39 +147,40 @@ void Advance::FirstRKStepT( } if (DATA.turn_on_rhob == 1) { - qi_source[4] = ( - tau_rk*hydro_source_terms_ptr->get_hydro_rhob_source( - tau_rk, x_local, y_local, eta_s_local, u_local)); + qi_source[4] = + (tau_rk + * hydro_source_terms_ptr->get_hydro_rhob_source( + tau_rk, x_local, y_local, eta_s_local, u_local)); } } // now MakeWSource returns partial_a W^{a mu} // (including geometric terms) - TJbVec dwmn ={0.0}; - diss_helper.MakeWSource(tau_rk, ix, iy, ieta, - dwmn, arenaFieldsCurr, arenaFieldsPrev, fieldIdx); + TJbVec dwmn = {0.0}; + diss_helper.MakeWSource( + tau_rk, ix, iy, ieta, dwmn, arenaFieldsCurr, arenaFieldsPrev, fieldIdx); double pressurePrev = eos.get_pressure(cellPrev.e, cellPrev.rhob); for (int alpha = 0; alpha < 5; alpha++) { /* dwmn is the only one with the minus sign */ - qi[alpha] -= dwmn[alpha]*(DATA.delta_tau); + qi[alpha] -= dwmn[alpha] * (DATA.delta_tau); // add energy moemntum and net baryon density source terms - qi[alpha] += qi_source[alpha]*DATA.delta_tau; + qi[alpha] += qi_source[alpha] * DATA.delta_tau; // set baryon density back to zero if viscous correction made it // non-zero remove/modify if rho_b!=0 // - this is only to remove the viscous correction that // can make rho_b negative which we do not want. - //if (DATA.turn_on_rhob == 0) { + // if (DATA.turn_on_rhob == 0) { // if (alpha == 4 && std::abs(qi[alpha]) > 1e-12) // qi[alpha] = 0.; //} /* if rk_flag > 0, we now have q0 + k1 + k2. * So add q0 and multiply by 1/2 */ - qi[alpha] += rk_flag*get_TJb(cellPrev, alpha, 0, pressurePrev)*tau; - qi[alpha] *= 1./(1. + rk_flag); + qi[alpha] += rk_flag * get_TJb(cellPrev, alpha, 0, pressurePrev) * tau; + qi[alpha] *= 1. / (1. + rk_flag); } double tau_next = tau + DATA.delta_tau; @@ -185,20 +192,17 @@ void Advance::FirstRKStepT( } } - -void Advance::FirstRKStepW(const double tau, Fields &arenaFieldsPrev, - Fields &arenaFieldsCurr, Fields &arenaFieldsNext, - const int rk_flag, const double theta_local, - const DumuVec &a_local, - const VelocityShearVec &sigma_local, - const VorticityVec &omega_local, - const DmuMuBoverTVec &baryon_diffusion_vector, - const int ieta, const int ix, const int iy, - const int fieldIdx) { +void Advance::FirstRKStepW( + const double tau, Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, + Fields &arenaFieldsNext, const int rk_flag, const double theta_local, + const DumuVec &a_local, const VelocityShearVec &sigma_local, + const VorticityVec &omega_local, + const DmuMuBoverTVec &baryon_diffusion_vector, const int ieta, const int ix, + const int iy, const int fieldIdx) { auto grid_c = arenaFieldsCurr.getCell(fieldIdx); auto grid_f = arenaFieldsNext.getCell(fieldIdx); - const double tau_now = tau + rk_flag*DATA.delta_tau; + const double tau_now = tau + rk_flag * DATA.delta_tau; // Solve partial_a (u^a W^{mu nu}) = 0 // Update W^{mu nu} @@ -212,15 +216,17 @@ void Advance::FirstRKStepW(const double tau, Fields &arenaFieldsPrev, // spatial gradients for all viscous quantities std::array w_rhs = {0.}; - diss_helper.Make_uWRHS(tau_now, arenaFieldsCurr, fieldIdx, - ix, iy, ieta, w_rhs, theta_local, a_local); + diss_helper.Make_uWRHS( + tau_now, arenaFieldsCurr, fieldIdx, ix, iy, ieta, w_rhs, theta_local, + a_local); std::vector thermalVec; if (rk_flag == 0) { eos.getThermalVariables(grid_c.epsilon, grid_c.rhob, thermalVec); } else { - eos.getThermalVariables(arenaFieldsPrev.e_[fieldIdx], - arenaFieldsPrev.rhob_[fieldIdx], thermalVec); + eos.getThermalVariables( + arenaFieldsPrev.e_[fieldIdx], arenaFieldsPrev.rhob_[fieldIdx], + thermalVec); } double tempf; @@ -232,14 +238,14 @@ void Advance::FirstRKStepW(const double tau, Fields &arenaFieldsPrev, thermalVec, sourceTerms); for (int idx_1d = 4; idx_1d < 9; idx_1d++) { double WmunuPrev = arenaFieldsPrev.Wmunu_[idx_1d][fieldIdx]; - tempf = ((1. - rk_flag)*(grid_c.Wmunu[idx_1d]*grid_c.u[0]) - + rk_flag*(WmunuPrev*u0Prev) - ); - tempf += sourceTerms[idx_1d-4]*(DATA.delta_tau); - tempf += w_rhs[idx_1d-4]; - tempf += rk_flag*((grid_c.Wmunu[idx_1d])*(grid_c.u[0])); - tempf *= 1./(1. + rk_flag); - grid_f.Wmunu[idx_1d] = tempf/(grid_f.u[0]); + tempf = + ((1. - rk_flag) * (grid_c.Wmunu[idx_1d] * grid_c.u[0]) + + rk_flag * (WmunuPrev * u0Prev)); + tempf += sourceTerms[idx_1d - 4] * (DATA.delta_tau); + tempf += w_rhs[idx_1d - 4]; + tempf += rk_flag * ((grid_c.Wmunu[idx_1d]) * (grid_c.u[0])); + tempf *= 1. / (1. + rk_flag); + grid_f.Wmunu[idx_1d] = tempf / (grid_f.u[0]); } } else { for (int idx_1d = 4; idx_1d < 9; idx_1d++) { @@ -249,15 +255,16 @@ void Advance::FirstRKStepW(const double tau, Fields &arenaFieldsPrev, if (DATA.turn_on_bulk == 1) { double piBulkPrev = arenaFieldsPrev.piBulk_[fieldIdx]; - tempf = ((1. - rk_flag)*(grid_c.pi_b*grid_c.u[0]) - + rk_flag*piBulkPrev*u0Prev); + tempf = + ((1. - rk_flag) * (grid_c.pi_b * grid_c.u[0]) + + rk_flag * piBulkPrev * u0Prev); double temps = diss_helper.Make_uPiSource( - tau_now, grid_c, theta_local, sigma_local, thermalVec); - tempf += temps*(DATA.delta_tau); + tau_now, grid_c, theta_local, sigma_local, thermalVec); + tempf += temps * (DATA.delta_tau); tempf += w_rhs[5]; - tempf += rk_flag*((grid_c.pi_b)*(grid_c.u[0])); - tempf *= 1./(1. + rk_flag); - grid_f.pi_b = tempf/(grid_f.u[0]); + tempf += rk_flag * ((grid_c.pi_b) * (grid_c.u[0])); + tempf *= 1. / (1. + rk_flag); + grid_f.pi_b = tempf / (grid_f.u[0]); } else { grid_f.pi_b = 0.0; } @@ -265,20 +272,20 @@ void Advance::FirstRKStepW(const double tau, Fields &arenaFieldsPrev, // CShen: add source term for baryon diffusion if (DATA.turn_on_diff == 1) { std::array sourceTerms = {0.}; - diss_helper.Make_uqSource(tau_now, grid_c, - theta_local, a_local, sigma_local, - omega_local, baryon_diffusion_vector, - thermalVec, sourceTerms); + diss_helper.Make_uqSource( + tau_now, grid_c, theta_local, a_local, sigma_local, omega_local, + baryon_diffusion_vector, thermalVec, sourceTerms); for (int idx_1d = 11; idx_1d < 14; idx_1d++) { double WmunuPrev = arenaFieldsPrev.Wmunu_[idx_1d][fieldIdx]; - tempf = ((1. - rk_flag)*(grid_c.Wmunu[idx_1d]*grid_c.u[0]) - + rk_flag*WmunuPrev*u0Prev); - tempf += sourceTerms[idx_1d-11]*(DATA.delta_tau); - tempf += w_rhs[idx_1d-5]; - tempf += rk_flag*(grid_c.Wmunu[idx_1d]*grid_c.u[0]); - tempf *= 1./(1. + rk_flag); - - grid_f.Wmunu[idx_1d] = tempf/(grid_f.u[0]); + tempf = + ((1. - rk_flag) * (grid_c.Wmunu[idx_1d] * grid_c.u[0]) + + rk_flag * WmunuPrev * u0Prev); + tempf += sourceTerms[idx_1d - 11] * (DATA.delta_tau); + tempf += w_rhs[idx_1d - 5]; + tempf += rk_flag * (grid_c.Wmunu[idx_1d] * grid_c.u[0]); + tempf *= 1. / (1. + rk_flag); + + grid_f.Wmunu[idx_1d] = tempf / (grid_f.u[0]); } } else { for (int idx_1d = 10; idx_1d < 14; idx_1d++) { @@ -287,37 +294,37 @@ void Advance::FirstRKStepW(const double tau, Fields &arenaFieldsPrev, } // re-make Wmunu[3][3] so that Wmunu[mu][nu] is traceless - double u0sq = grid_f.u[0]*grid_f.u[0]; - grid_f.Wmunu[9] = ( - (2.*( grid_f.u[1]*grid_f.u[2]*grid_f.Wmunu[5] - + grid_f.u[1]*grid_f.u[3]*grid_f.Wmunu[6] - + grid_f.u[2]*grid_f.u[3]*grid_f.Wmunu[8]) - - (u0sq - grid_f.u[1]*grid_f.u[1])*grid_f.Wmunu[4] - - (u0sq - grid_f.u[2]*grid_f.u[2])*grid_f.Wmunu[7]) - /(u0sq - grid_f.u[3]*grid_f.u[3])); + double u0sq = grid_f.u[0] * grid_f.u[0]; + grid_f.Wmunu[9] = + ((2. + * (grid_f.u[1] * grid_f.u[2] * grid_f.Wmunu[5] + + grid_f.u[1] * grid_f.u[3] * grid_f.Wmunu[6] + + grid_f.u[2] * grid_f.u[3] * grid_f.Wmunu[8]) + - (u0sq - grid_f.u[1] * grid_f.u[1]) * grid_f.Wmunu[4] + - (u0sq - grid_f.u[2] * grid_f.u[2]) * grid_f.Wmunu[7]) + / (u0sq - grid_f.u[3] * grid_f.u[3])); // make Wmunu[i][0] using the transversality for (int mu = 1; mu < 4; mu++) { tempf = 0.0; for (int nu = 1; nu < 4; nu++) { int idx_1d = map_2d_idx_to_1d(mu, nu); - tempf += grid_f.Wmunu[idx_1d]*grid_f.u[nu]; + tempf += grid_f.Wmunu[idx_1d] * grid_f.u[nu]; } - grid_f.Wmunu[mu] = tempf/(grid_f.u[0]); + grid_f.Wmunu[mu] = tempf / (grid_f.u[0]); } // make Wmunu[0][0] tempf = 0.0; - for (int nu = 1; nu < 4; nu++) - tempf += grid_f.Wmunu[nu]*grid_f.u[nu]; - grid_f.Wmunu[0] = tempf/(grid_f.u[0]); + for (int nu = 1; nu < 4; nu++) tempf += grid_f.Wmunu[nu] * grid_f.u[nu]; + grid_f.Wmunu[0] = tempf / (grid_f.u[0]); // make qmu[0] using transversality tempf = 0.0; for (int idx_1d = 11; idx_1d < 14; idx_1d++) { - tempf += grid_f.Wmunu[idx_1d]*grid_f.u[idx_1d-10]; + tempf += grid_f.Wmunu[idx_1d] * grid_f.u[idx_1d - 10]; } - grid_f.Wmunu[10] = DATA.turn_on_diff*tempf/(grid_f.u[0]); + grid_f.Wmunu[10] = DATA.turn_on_diff * tempf / (grid_f.u[0]); // If the energy density of the fluid element is smaller than 0.01GeV // reduce Wmunu using the QuestRevert algorithm @@ -333,21 +340,21 @@ void Advance::FirstRKStepW(const double tau, Fields &arenaFieldsPrev, } } - //! this function reduce the size of shear stress tensor and bulk pressure //! in the dilute region to stablize numerical simulations -void Advance::QuestRevert(const double tau, Cell_small &grid_pt, - const int ieta, const int ix, const int iy) { - double eps_scale = 0.1; // 1/fm^4 - double e_local = grid_pt.epsilon; - double rhob = grid_pt.rhob; +void Advance::QuestRevert( + const double tau, Cell_small &grid_pt, const int ieta, const int ix, + const int iy) { + double eps_scale = 0.1; // 1/fm^4 + double e_local = grid_pt.epsilon; + double rhob = grid_pt.rhob; // regulation factor in the default MUSIC // double factor = 300.*tanh(grid_pt.epsilon/eps_scale); double xi = 0.05; - double factor = 10.*DATA.quest_revert_strength*( - 1./(exp(-(e_local - eps_scale)/xi) + 1.) - - 1./(exp(eps_scale/xi) + 1.)); + double factor = 10. * DATA.quest_revert_strength + * (1. / (exp(-(e_local - eps_scale) / xi) + 1.) + - 1. / (exp(eps_scale / xi) + 1.)); double factor_bulk = factor; double pi_00 = grid_pt.Wmunu[0]; @@ -361,19 +368,20 @@ void Advance::QuestRevert(const double tau, Cell_small &grid_pt, double pi_23 = grid_pt.Wmunu[8]; double pi_33 = grid_pt.Wmunu[9]; - double pisize = (pi_00*pi_00 + pi_11*pi_11 + pi_22*pi_22 + pi_33*pi_33 - - 2.*(pi_01*pi_01 + pi_02*pi_02 + pi_03*pi_03) - + 2.*(pi_12*pi_12 + pi_13*pi_13 + pi_23*pi_23)); + double pisize = + (pi_00 * pi_00 + pi_11 * pi_11 + pi_22 * pi_22 + pi_33 * pi_33 + - 2. * (pi_01 * pi_01 + pi_02 * pi_02 + pi_03 * pi_03) + + 2. * (pi_12 * pi_12 + pi_13 * pi_13 + pi_23 * pi_23)); double pi_local = grid_pt.pi_b; - double bulksize = 3.*pi_local*pi_local; + double bulksize = 3. * pi_local * pi_local; double p_local = eos.get_pressure(e_local, rhob); - double eq_size = e_local*e_local + 3.*p_local*p_local; + double eq_size = e_local * e_local + 3. * p_local * p_local; // In default MUSIC - double rho_shear = sqrt(pisize/eq_size)/factor; - double rho_bulk = sqrt(bulksize/eq_size)/factor_bulk; + double rho_shear = sqrt(pisize / eq_size) / factor; + double rho_bulk = sqrt(bulksize / eq_size) / factor_bulk; // Reducing the shear stress tensor double rho_shear_max = 0.1; @@ -385,13 +393,13 @@ void Advance::QuestRevert(const double tau, Cell_small &grid_pt, if (e_local > eps_scale && DATA.echo_level > 5) { music_message << "ieta = " << ieta << ", ix = " << ix << ", iy = " << iy - << ", energy density = " << e_local*hbarc + << ", energy density = " << e_local * hbarc << " GeV/fm^3, shear |pi/(epsilon+3*P)| = " << rho_shear; music_message.flush("warning"); } for (int mu = 0; mu < 10; mu++) { - grid_pt.Wmunu[mu] = (rho_shear_max/rho_shear)*grid_pt.Wmunu[mu]; + grid_pt.Wmunu[mu] = (rho_shear_max / rho_shear) * grid_pt.Wmunu[mu]; } } @@ -401,38 +409,38 @@ void Advance::QuestRevert(const double tau, Cell_small &grid_pt, if (e_local > eps_scale && DATA.echo_level > 5) { music_message << "ieta = " << ieta << ", ix = " << ix << ", iy = " << iy - << ", energy density = " << e_local*hbarc + << ", energy density = " << e_local * hbarc << " GeV/fm^3, bulk |Pi/(epsilon+3*P)| = " << rho_bulk; music_message.flush("warning"); } - grid_pt.pi_b = (rho_bulk_max/rho_bulk)*grid_pt.pi_b; + grid_pt.pi_b = (rho_bulk_max / rho_bulk) * grid_pt.pi_b; } } - //! this function reduce the size of net baryon diffusion current //! in the dilute region to stablize numerical simulations -void Advance::QuestRevert_qmu(const double tau, Cell_small &grid_pt, - const int ieta, const int ix, const int iy) { - double eps_scale = 0.1; // in 1/fm^4 +void Advance::QuestRevert_qmu( + const double tau, Cell_small &grid_pt, const int ieta, const int ix, + const int iy) { + double eps_scale = 0.1; // in 1/fm^4 double xi = 0.05; - double factor = 10.*DATA.quest_revert_strength*( - 1./(exp(-(grid_pt.epsilon - eps_scale)/xi) + 1.) - - 1./(exp(eps_scale/xi) + 1.)); + double factor = 10. * DATA.quest_revert_strength + * (1. / (exp(-(grid_pt.epsilon - eps_scale) / xi) + 1.) + - 1. / (exp(eps_scale / xi) + 1.)); double q_mu_local[4]; for (int i = 0; i < 4; i++) { // copy the value from the grid - q_mu_local[i] = grid_pt.Wmunu[10+i]; + q_mu_local[i] = grid_pt.Wmunu[10 + i]; } // calculate the size of q^\mu double q_size = 0.0; for (int i = 0; i < 4; i++) { double gfac = (i == 0 ? -1.0 : 1.0); - q_size += gfac*q_mu_local[i]*q_mu_local[i]; + q_size += gfac * q_mu_local[i] * q_mu_local[i]; } // first check the positivity of q^mu q_mu @@ -452,108 +460,120 @@ void Advance::QuestRevert_qmu(const double tau, Cell_small &grid_pt, // reduce the size of q^mu according to rhoB double e_local = grid_pt.epsilon; double rhob_local = grid_pt.rhob; - double rho_q = sqrt(q_size/(rhob_local*rhob_local))/factor; + double rho_q = sqrt(q_size / (rhob_local * rhob_local)) / factor; double rho_q_max = 0.1; if (rho_q > rho_q_max) { if (e_local > eps_scale && DATA.echo_level > 5) { music_message << "ieta = " << ieta << ", ix = " << ix << ", iy = " << iy - << ", energy density = " << e_local*hbarc + << ", energy density = " << e_local * hbarc << "GeV/fm^3" << ", rhob = " << rhob_local << "1/fm^3" << "-- diffusion |q/rhob| = " << rho_q; music_message.flush("warning"); } for (int i = 0; i < 4; i++) { - grid_pt.Wmunu[10+i] = (rho_q_max/rho_q)*q_mu_local[i]; + grid_pt.Wmunu[10 + i] = (rho_q_max / rho_q) * q_mu_local[i]; } } } - //! This function computes the rhs array. It computes the spatial //! derivatives of T^\mu\nu using the KT algorithm -void Advance::MakeDeltaQI(const double tau, Fields &arenaFieldsCurr, - const int ix, const int iy, const int ieta, - TJbVec &qi, const int rk_flag) { - const double delta[4] = {0.0, DATA.delta_x, DATA.delta_y, DATA.delta_eta}; +void Advance::MakeDeltaQI( + const double tau, Fields &arenaFieldsCurr, const int ix, const int iy, + const int ieta, TJbVec &qi, const int rk_flag) { + const double delta[4] = {0.0, DATA.delta_x, DATA.delta_y, DATA.delta_eta}; const double tau_fac[4] = {0.0, tau, tau, 1.0}; - TJbVec qiphL = {0.}; - TJbVec qiphR = {0.}; - TJbVec qimhL = {0.}; - TJbVec qimhR = {0.}; + TJbVec qiphL = {0.}; + TJbVec qiphR = {0.}; + TJbVec qimhL = {0.}; + TJbVec qimhR = {0.}; - TJbVec rhs = {0.}; + TJbVec rhs = {0.}; EnergyFlowVec T_eta_m = {0.}; EnergyFlowVec T_eta_p = {0.}; - FieldNeighbourLoopIdeal2(arenaFieldsCurr, ix, iy, ieta, FNLILAMBDAS2{ - double pressureP1 = eos.get_pressure(p1.e, p1.rhob); - double pressureP2 = eos.get_pressure(p2.e, p2.rhob); - double pressureM1 = eos.get_pressure(m1.e, m1.rhob); - double pressureM2 = eos.get_pressure(m2.e, m2.rhob); - for (int alpha = 0; alpha < 5; alpha++) { - const double gphL = qi[alpha]; - const double gphR = tau*get_TJb(p1, alpha, 0, pressureP1); - const double gmhL = tau*get_TJb(m1, alpha, 0, pressureM1); - const double gmhR = qi[alpha]; - const double fphL = 0.5*minmod.minmod_dx(gphR, qi[alpha], gmhL); - const double fphR = -0.5*minmod.minmod_dx( - tau*get_TJb(p2, alpha, 0, pressureP2), - gphR, qi[alpha]); - const double fmhL = 0.5*minmod.minmod_dx( - qi[alpha], gmhL, - tau*get_TJb(m2, alpha, 0, pressureM2)); - const double fmhR = -fphL; - qiphL[alpha] = gphL + fphL; - qiphR[alpha] = gphR + fphR; - qimhL[alpha] = gmhL + fmhL; - qimhR[alpha] = gmhR + fmhR; - } + FieldNeighbourLoopIdeal2( + arenaFieldsCurr, ix, iy, ieta, FNLILAMBDAS2 { + double pressureP1 = eos.get_pressure(p1.e, p1.rhob); + double pressureP2 = eos.get_pressure(p2.e, p2.rhob); + double pressureM1 = eos.get_pressure(m1.e, m1.rhob); + double pressureM2 = eos.get_pressure(m2.e, m2.rhob); + for (int alpha = 0; alpha < 5; alpha++) { + const double gphL = qi[alpha]; + const double gphR = tau * get_TJb(p1, alpha, 0, pressureP1); + const double gmhL = tau * get_TJb(m1, alpha, 0, pressureM1); + const double gmhR = qi[alpha]; + const double fphL = + 0.5 * minmod.minmod_dx(gphR, qi[alpha], gmhL); + const double fphR = -0.5 + * minmod.minmod_dx( + tau * get_TJb(p2, alpha, 0, pressureP2), + gphR, qi[alpha]); + const double fmhL = + 0.5 + * minmod.minmod_dx( + qi[alpha], gmhL, + tau * get_TJb(m2, alpha, 0, pressureM2)); + const double fmhR = -fphL; + qiphL[alpha] = gphL + fphL; + qiphR[alpha] = gphR + fphR; + qimhL[alpha] = gmhL + fmhL; + qimhR[alpha] = gmhR + fmhR; + } - // for each direction, reconstruct half-way cells - // reconstruct e, rhob, and u[4] for half way cells - auto grid_phL = reconst_helper.ReconstIt_shell(tau, qiphL, c); - auto grid_phR = reconst_helper.ReconstIt_shell(tau, qiphR, c); - auto grid_mhL = reconst_helper.ReconstIt_shell(tau, qimhL, c); - auto grid_mhR = reconst_helper.ReconstIt_shell(tau, qimhR, c); - - double aiphL = MaxSpeed(tau, direction, grid_phL, pressureP1); - double aiphR = MaxSpeed(tau, direction, grid_phR, pressureP2); - double aimhL = MaxSpeed(tau, direction, grid_mhL, pressureM1); - double aimhR = MaxSpeed(tau, direction, grid_mhR, pressureM2); - - double aiph = std::max(aiphL, aiphR); - double aimh = std::max(aimhL, aimhR); - for (int alpha = 0; alpha < 5; alpha++) { - double FiphL = (tau_fac[direction] - *get_TJb(grid_phL, alpha, direction, pressureP1)); - double FiphR = (tau_fac[direction] - *get_TJb(grid_phR, alpha, direction, pressureP2)); - double FimhL = (tau_fac[direction] - *get_TJb(grid_mhL, alpha, direction, pressureM1)); - double FimhR = (tau_fac[direction] - *get_TJb(grid_mhR, alpha, direction, pressureM2)); - - // KT: H_{j+1/2} = (f(u^+_{j+1/2}) + f(u^-_{j+1/2}))/2 - // - a_{j+1/2}(u_{j+1/2}^+ - u^-_{j+1/2})/2 - double Fiph = 0.5*((FiphL + FiphR) - - aiph*(qiphR[alpha] - qiphL[alpha])); - double Fimh = 0.5*((FimhL + FimhR) - - aimh*(qimhR[alpha] - qimhL[alpha])); - if (direction == 3 && (alpha == 0 || alpha == 3)) { - T_eta_m[alpha] = Fimh; - T_eta_p[alpha] = Fiph; - } else { - double DFmmp = (Fimh - Fiph)/delta[direction]; - rhs[alpha] += DFmmp*(DATA.delta_tau); + // for each direction, reconstruct half-way cells + // reconstruct e, rhob, and u[4] for half way cells + auto grid_phL = reconst_helper.ReconstIt_shell(tau, qiphL, c); + auto grid_phR = reconst_helper.ReconstIt_shell(tau, qiphR, c); + auto grid_mhL = reconst_helper.ReconstIt_shell(tau, qimhL, c); + auto grid_mhR = reconst_helper.ReconstIt_shell(tau, qimhR, c); + + double aiphL = MaxSpeed(tau, direction, grid_phL, pressureP1); + double aiphR = MaxSpeed(tau, direction, grid_phR, pressureP2); + double aimhL = MaxSpeed(tau, direction, grid_mhL, pressureM1); + double aimhR = MaxSpeed(tau, direction, grid_mhR, pressureM2); + + double aiph = std::max(aiphL, aiphR); + double aimh = std::max(aimhL, aimhR); + for (int alpha = 0; alpha < 5; alpha++) { + double FiphL = + (tau_fac[direction] + * get_TJb(grid_phL, alpha, direction, pressureP1)); + double FiphR = + (tau_fac[direction] + * get_TJb(grid_phR, alpha, direction, pressureP2)); + double FimhL = + (tau_fac[direction] + * get_TJb(grid_mhL, alpha, direction, pressureM1)); + double FimhR = + (tau_fac[direction] + * get_TJb(grid_mhR, alpha, direction, pressureM2)); + + // KT: H_{j+1/2} = (f(u^+_{j+1/2}) + f(u^-_{j+1/2}))/2 + // - a_{j+1/2}(u_{j+1/2}^+ - u^-_{j+1/2})/2 + double Fiph = + 0.5 + * ((FiphL + FiphR) - aiph * (qiphR[alpha] - qiphL[alpha])); + double Fimh = + 0.5 + * ((FimhL + FimhR) - aimh * (qimhR[alpha] - qimhL[alpha])); + if (direction == 3 && (alpha == 0 || alpha == 3)) { + T_eta_m[alpha] = Fimh; + T_eta_p[alpha] = Fiph; + } else { + double DFmmp = (Fimh - Fiph) / delta[direction]; + rhs[alpha] += DFmmp * (DATA.delta_tau); + } } - } - }); + }); // add longitudinal flux with discretized geometric terms - double cosh_deta = cosh(delta[3]/2.)/std::max(delta[3], Util::small_eps); - double sinh_deta = sinh(delta[3]/2.)/std::max(delta[3], Util::small_eps); + double cosh_deta = + cosh(delta[3] / 2.) / std::max(delta[3], Util::small_eps); + double sinh_deta = + sinh(delta[3] / 2.) / std::max(delta[3], Util::small_eps); sinh_deta = std::max(0.5, sinh_deta); if (DATA.boost_invariant) { // if the simulation is boost-invariant, @@ -562,14 +582,18 @@ void Advance::MakeDeltaQI(const double tau, Fields &arenaFieldsCurr, cosh_deta = 0.0; sinh_deta = 0.5; } - rhs[0] += (( (T_eta_m[0] - T_eta_p[0])*cosh_deta - - (T_eta_m[3] + T_eta_p[3])*sinh_deta)*DATA.delta_tau); - rhs[3] += (( (T_eta_m[3] - T_eta_p[3])*cosh_deta - - (T_eta_m[0] + T_eta_p[0])*sinh_deta)*DATA.delta_tau); + rhs[0] += + (((T_eta_m[0] - T_eta_p[0]) * cosh_deta + - (T_eta_m[3] + T_eta_p[3]) * sinh_deta) + * DATA.delta_tau); + rhs[3] += + (((T_eta_m[3] - T_eta_p[3]) * cosh_deta + - (T_eta_m[0] + T_eta_p[0]) * sinh_deta) + * DATA.delta_tau); // geometric terms - //rhs[0] -= get_TJb(arena_current(ix, iy, ieta), 3, 3)*DATA.delta_tau; - //rhs[3] -= get_TJb(arena_current(ix, iy, ieta), 3, 0)*DATA.delta_tau; + // rhs[0] -= get_TJb(arena_current(ix, iy, ieta), 3, 3)*DATA.delta_tau; + // rhs[3] -= get_TJb(arena_current(ix, iy, ieta), 3, 0)*DATA.delta_tau; for (int i = 0; i < 5; i++) { qi[i] += rhs[i]; @@ -577,61 +601,66 @@ void Advance::MakeDeltaQI(const double tau, Fields &arenaFieldsCurr, } // determine the maximum signal propagation speed at the given direction -double Advance::MaxSpeed(const double tau, const int direc, - const ReconstCell &grid_p, double &pressure) { - double g[] = {1., 1., 1./tau}; +double Advance::MaxSpeed( + const double tau, const int direc, const ReconstCell &grid_p, + double &pressure) { + double g[] = {1., 1., 1. / tau}; - double utau = grid_p.u[0]; - double utau2 = utau*utau; - double ux = std::abs(grid_p.u[direc]); - double ut2mux2 = utau2 - ux*ux; + double utau = grid_p.u[0]; + double utau2 = utau * utau; + double ux = std::abs(grid_p.u[direc]); + double ut2mux2 = utau2 - ux * ux; - double eps = grid_p.e; + double eps = grid_p.e; double rhob = grid_p.rhob; - //double vs2 = eos.get_cs2(eps, rhob); + // double vs2 = eos.get_cs2(eps, rhob); double dpde, dpdrhob, vs2; eos.get_pressure_with_gradients(eps, rhob, pressure, dpde, dpdrhob, vs2); - double num_temp_sqrt = (ut2mux2 - (ut2mux2 - 1.)*vs2)*vs2; + double num_temp_sqrt = (ut2mux2 - (ut2mux2 - 1.) * vs2) * vs2; double num; - if (num_temp_sqrt >= 0) { - num = utau*ux*(1. - vs2) + sqrt(num_temp_sqrt); + if (num_temp_sqrt >= 0) { + num = utau * ux * (1. - vs2) + sqrt(num_temp_sqrt); } else { - //double dpde = eos.get_dpde(eps, rhob); + // double dpde = eos.get_dpde(eps, rhob); double h = pressure + eps; if (dpde < 0.001) { - num = (sqrt(-(h*dpde*h*(dpde*(-1.0 + ut2mux2) - ut2mux2))) - - h*(-1.0 + dpde)*utau*ux); + num = + (sqrt(-(h * dpde * h * (dpde * (-1.0 + ut2mux2) - ut2mux2))) + - h * (-1.0 + dpde) * utau * ux); } else { - fprintf(stderr,"WARNING: in MaxSpeed. \n"); - fprintf(stderr, "Expression under sqrt in num=%lf. \n", num_temp_sqrt); - fprintf(stderr,"at value e=%lf. \n",eps); - fprintf(stderr,"at value p=%lf. \n",pressure); - fprintf(stderr,"at value h=%lf. \n",h); - fprintf(stderr,"at value rhob=%lf. \n",rhob); - fprintf(stderr,"at value utau=%lf. \n", utau); - fprintf(stderr,"at value uk=%lf. \n", ux); - fprintf(stderr,"at value vs^2=%lf. \n", vs2); - fprintf(stderr,"at value dpde=%lf. \n", dpde); - fprintf(stderr,"at value dpdrhob=%lf. \n", dpdrhob); - fprintf(stderr, "MaxSpeed: exiting.\n"); - exit(1); + fprintf(stderr, "WARNING: in MaxSpeed. \n"); + fprintf( + stderr, "Expression under sqrt in num=%lf. \n", num_temp_sqrt); + fprintf(stderr, "at value e=%lf. \n", eps); + fprintf(stderr, "at value p=%lf. \n", pressure); + fprintf(stderr, "at value h=%lf. \n", h); + fprintf(stderr, "at value rhob=%lf. \n", rhob); + fprintf(stderr, "at value utau=%lf. \n", utau); + fprintf(stderr, "at value uk=%lf. \n", ux); + fprintf(stderr, "at value vs^2=%lf. \n", vs2); + fprintf(stderr, "at value dpde=%lf. \n", dpde); + fprintf(stderr, "at value dpdrhob=%lf. \n", dpdrhob); + fprintf(stderr, "MaxSpeed: exiting.\n"); + exit(1); } } - double den = utau2*(1. - vs2) + vs2; - double f = num/std::max(den, Util::small_eps); + double den = utau2 * (1. - vs2) + vs2; + double f = num / std::max(den, Util::small_eps); // check for problems if (f < 0.0) { fprintf(stderr, "SpeedMax = %e\n is negative.\n", f); fprintf(stderr, "Can't happen.\n"); exit(0); - } else if (f < ux/utau) { + } else if (f < ux / utau) { if (num != 0.0) { - if (fabs(f-ux/utau)<0.0001) { - f = ux/utau; + if (fabs(f - ux / utau) < 0.0001) { + f = ux / utau; } else { - fprintf(stderr, "SpeedMax-v = %lf\n", f-ux/utau); - fprintf(stderr, "SpeedMax = %e\n is smaller than v = %e.\n", f, ux/utau); + fprintf(stderr, "SpeedMax-v = %lf\n", f - ux / utau); + fprintf( + stderr, "SpeedMax = %e\n is smaller than v = %e.\n", f, + ux / utau); fprintf(stderr, "Can't happen.\n"); exit(0); } @@ -641,22 +670,22 @@ double Advance::MaxSpeed(const double tau, const int direc, fprintf(stderr, "Can't happen.\n"); fprintf(stderr, "SpeedMax = num/den, num = %e, den = %e \n", num, den); fprintf(stderr, "cs2 = %e \n", vs2); - f =1.; + f = 1.; exit(1); } - f *= g[direc-1]; + f *= g[direc - 1]; return f; } - -double Advance::get_TJb(const ReconstCell &grid_p, const int mu, const int nu, - const double pressure) { - //assert(mu < 5); assert(mu > -1); - //assert(nu < 4); assert(nu > -1); +double Advance::get_TJb( + const ReconstCell &grid_p, const int mu, const int nu, + const double pressure) { + // assert(mu < 5); assert(mu > -1); + // assert(nu < 4); assert(nu > -1); double rhob = grid_p.rhob; const double u_nu = grid_p.u[nu]; if (mu == 4) { - return rhob*u_nu; + return rhob * u_nu; } double e = grid_p.e; double gfac = 0.0; @@ -670,6 +699,6 @@ double Advance::get_TJb(const ReconstCell &grid_p, const int mu, const int nu, } else { u_mu = grid_p.u[mu]; } - const double T_munu = (e + pressure)*u_mu*u_nu + pressure*gfac; - return(T_munu); + const double T_munu = (e + pressure) * u_mu * u_nu + pressure * gfac; + return (T_munu); } diff --git a/src/advance.h b/src/advance.h index 3cf62be5..73d83787 100644 --- a/src/advance.h +++ b/src/advance.h @@ -3,18 +3,19 @@ #define SRC_ADVANCE_H_ #include -#include "data.h" + #include "cell.h" -#include "fields.h" +#include "data.h" #include "dissipative.h" -#include "minmod.h" -#include "u_derivative.h" -#include "reconst.h" +#include "fields.h" #include "hydro_source_base.h" +#include "minmod.h" #include "pretty_ostream.h" +#include "reconst.h" +#include "u_derivative.h" class Advance { - private: + private: const InitData &DATA; const EOS &eos; std::shared_ptr hydro_source_terms_ptr; @@ -26,45 +27,47 @@ class Advance { bool flag_add_hydro_source; - public: - Advance(const EOS &eosIn, const InitData &DATA_in, - std::shared_ptr hydro_source_ptr_in); + public: + Advance( + const EOS &eosIn, const InitData &DATA_in, + std::shared_ptr hydro_source_ptr_in); - void AdvanceIt(const double tau_init, Fields &arenaFieldsPrev, - Fields &arenaFieldsCurr, Fields &arenaFieldsNext, - const int rk_flag); + void AdvanceIt( + const double tau_init, Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, + Fields &arenaFieldsNext, const int rk_flag); - void FirstRKStepT(const double tau, const double x_local, - const double y_local, const double eta_s_local, - const int ix, const int iy, - const int ieta, const int rk_flag, - const int fieldIdx, Fields &arenaFieldsCurr, - Fields &arenaFieldsNext, Fields &arenaFieldsPrev); + void FirstRKStepT( + const double tau, const double x_local, const double y_local, + const double eta_s_local, const int ix, const int iy, const int ieta, + const int rk_flag, const int fieldIdx, Fields &arenaFieldsCurr, + Fields &arenaFieldsNext, Fields &arenaFieldsPrev); - void FirstRKStepW(const double tau_it, Fields &arenaFieldsPrev, - Fields &arenaFieldsCurr, Fields &arenaFieldsNext, - const int rk_flag, const double theta_local, - const DumuVec &a_local, - const VelocityShearVec &sigma_local, - const VorticityVec &omega_local, - const DmuMuBoverTVec &baryon_diffusion_vector, - const int ieta, const int ix, const int iy, - const int fieldIdx); + void FirstRKStepW( + const double tau_it, Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, + Fields &arenaFieldsNext, const int rk_flag, const double theta_local, + const DumuVec &a_local, const VelocityShearVec &sigma_local, + const VorticityVec &omega_local, + const DmuMuBoverTVec &baryon_diffusion_vector, const int ieta, + const int ix, const int iy, const int fieldIdx); - void QuestRevert(const double tau, Cell_small &grid_pt, - const int ieta, const int ix, const int iy); - void QuestRevert_qmu(const double tau, Cell_small &grid_pt, - const int ieta, const int ix, const int iy); + void QuestRevert( + const double tau, Cell_small &grid_pt, const int ieta, const int ix, + const int iy); + void QuestRevert_qmu( + const double tau, Cell_small &grid_pt, const int ieta, const int ix, + const int iy); - void MakeDeltaQI(const double tau, Fields &arenaFieldsCurr, - const int ix, const int iy, const int ieta, TJbVec &qi, - const int rk_flag); + void MakeDeltaQI( + const double tau, Fields &arenaFieldsCurr, const int ix, const int iy, + const int ieta, TJbVec &qi, const int rk_flag); - double MaxSpeed(const double tau, const int direc, - const ReconstCell &grid_p, double &pressure); + double MaxSpeed( + const double tau, const int direc, const ReconstCell &grid_p, + double &pressure); - double get_TJb(const ReconstCell &grid_p, const int mu, const int nu, - const double pressure); + double get_TJb( + const ReconstCell &grid_p, const int mu, const int nu, + const double pressure); }; #endif // SRC_ADVANCE_H_ diff --git a/src/cell.h b/src/cell.h index 37e5f2a1..d5839ccd 100644 --- a/src/cell.h +++ b/src/cell.h @@ -2,12 +2,13 @@ #ifndef _SRC_CELL_H_ #define _SRC_CELL_H_ -#include "data_struct.h" #include #include +#include "data_struct.h" + class Cell_small { - public: + public: double epsilon = 0; double rhob = 0; FlowVec u = {1., 0., 0., 0.}; @@ -15,44 +16,43 @@ class Cell_small { ViscousVec Wmunu = {0.}; double pi_b = 0.; - - Cell_small operator + (Cell_small const &obj) { + Cell_small operator+(Cell_small const &obj) { Cell_small res; res.epsilon = epsilon + obj.epsilon; res.rhob = rhob + obj.rhob; res.u[1] = u[1] + obj.u[1]; res.u[2] = u[2] + obj.u[2]; res.u[3] = u[3] + obj.u[3]; - res.u[0] = sqrt(1. + res.u[1]*res.u[1] - + res.u[2]*res.u[2] + res.u[3]*res.u[3]); + res.u[0] = sqrt( + 1. + res.u[1] * res.u[1] + res.u[2] * res.u[2] + + res.u[3] * res.u[3]); for (unsigned int i = 0; i < Wmunu.size(); i++) { res.Wmunu[i] = Wmunu[i] + obj.Wmunu[i]; } res.pi_b = pi_b + obj.pi_b; - return(res); + return (res); } - - Cell_small operator * (const double a) { + Cell_small operator*(const double a) { Cell_small res; - res.epsilon = epsilon*a; - res.rhob = rhob*a; - res.u[1] = u[1]*a; - res.u[2] = u[2]*a; - res.u[3] = u[3]*a; - res.u[0] = sqrt(1. + res.u[1]*res.u[1] - + res.u[2]*res.u[2] + res.u[3]*res.u[3]); + res.epsilon = epsilon * a; + res.rhob = rhob * a; + res.u[1] = u[1] * a; + res.u[2] = u[2] * a; + res.u[3] = u[3] * a; + res.u[0] = sqrt( + 1. + res.u[1] * res.u[1] + res.u[2] * res.u[2] + + res.u[3] * res.u[3]); for (unsigned int i = 0; i < Wmunu.size(); i++) { - res.Wmunu[i] = Wmunu[i]*a; + res.Wmunu[i] = Wmunu[i] * a; } - res.pi_b = pi_b*a; - return(res); + res.pi_b = pi_b * a; + return (res); } }; - class Cell_aux { - public: + public: VorticityVec omega_kSP = {0.}; VorticityVec omega_k = {0.}; VorticityVec omega_th = {0.}; @@ -60,8 +60,7 @@ class Cell_aux { VelocityShearVec sigma_th = {0.}; DmuMuBoverTVec DbetaMu = {0.}; - - Cell_aux operator + (Cell_aux const &obj) { + Cell_aux operator+(Cell_aux const &obj) { Cell_aux res; for (unsigned int i = 0; i < omega_k.size(); i++) { res.omega_kSP[i] = omega_kSP[i] + obj.omega_kSP[i]; @@ -73,23 +72,22 @@ class Cell_aux { res.sigma_th[i] = sigma_th[i] + obj.sigma_th[i]; for (unsigned int i = 0; i < DbetaMu.size(); i++) res.DbetaMu[i] = DbetaMu[i] + obj.DbetaMu[i]; - return(res); + return (res); } - - Cell_aux operator * (const double a) { + Cell_aux operator*(const double a) { Cell_aux res; for (unsigned int i = 0; i < omega_k.size(); i++) { - res.omega_kSP[i] = omega_kSP[i]*a; - res.omega_k[i] = omega_k[i]*a; - res.omega_th[i] = omega_th[i]*a; - res.omega_T[i] = omega_T[i]*a; + res.omega_kSP[i] = omega_kSP[i] * a; + res.omega_k[i] = omega_k[i] * a; + res.omega_th[i] = omega_th[i] * a; + res.omega_T[i] = omega_T[i] * a; } for (unsigned int i = 0; i < sigma_th.size(); i++) - res.sigma_th[i] = sigma_th[i]*a; + res.sigma_th[i] = sigma_th[i] * a; for (unsigned int i = 0; i < DbetaMu.size(); i++) - res.DbetaMu[i] = DbetaMu[i]*a; - return(res); + res.DbetaMu[i] = DbetaMu[i] * a; + return (res); } }; diff --git a/src/cell_unittest.cpp b/src/cell_unittest.cpp index 168cb06c..a5206f3e 100644 --- a/src/cell_unittest.cpp +++ b/src/cell_unittest.cpp @@ -1,8 +1,9 @@ #include "cell.h" -#include "doctest.h" + #include #include +#include "doctest.h" TEST_CASE("Does cell = work") { Cell_small cell1; @@ -19,7 +20,6 @@ TEST_CASE("Does cell = work") { CHECK(cell2.pi_b == cell1.pi_b); } - TEST_CASE("Does cell + work") { Cell_small cell1; Cell_small cell2; @@ -30,7 +30,6 @@ TEST_CASE("Does cell + work") { CHECK(cell3.u[0] == 1.0); } - TEST_CASE("Does cell * work") { Cell_small cell1; cell1.epsilon = 1.0; @@ -38,8 +37,8 @@ TEST_CASE("Does cell * work") { cell1.u[1] = 0.2; double factor = 2.; - Cell_small cell2 = cell1*factor; - CHECK(cell2.epsilon == cell1.epsilon*factor); - CHECK(cell2.rhob == cell1.rhob*factor); - CHECK(cell2.u[1] == cell1.u[1]*factor); + Cell_small cell2 = cell1 * factor; + CHECK(cell2.epsilon == cell1.epsilon * factor); + CHECK(cell2.rhob == cell1.rhob * factor); + CHECK(cell2.u[1] == cell1.u[1] * factor); } diff --git a/src/cornelius.cpp b/src/cornelius.cpp index be85f4d8..3596d143 100644 --- a/src/cornelius.cpp +++ b/src/cornelius.cpp @@ -11,24 +11,26 @@ * Permission to distribute this subroutine is granted, provided that no fee is * charged, and that this copyright and permission notice appear in all the * copies. Permission to modify this subroutine is granted provided that the - * modified subroutine is made publicly available latest when any results obtained - * using the modified subroutine are published, the modified subroutine is - * distributed under terms similar to this notice, and the modified code carries - * both the original copyright notice and notices stating that you modified it, - * and a relevant date/year. + * modified subroutine is made publicly available latest when any results + * obtained using the modified subroutine are published, the modified subroutine + * is distributed under terms similar to this notice, and the modified code + * carries both the original copyright notice and notices stating that you + * modified it, and a relevant date/year. * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of FITNESS FOR A PARTICULAR PURPOSE. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of FITNESS FOR A PARTICULAR + * PURPOSE. * * Last update 03.08.2012 Hannu Holopainen * */ -#include -#include #include #include +#include +#include + using namespace std; /** @@ -37,8 +39,7 @@ using namespace std; * from this. * */ -class GeneralElement -{ +class GeneralElement { protected: static const int DIM = 4; double *centroid; @@ -48,6 +49,7 @@ class GeneralElement virtual void calculate_centroid() {}; virtual void calculate_normal() {}; void check_normal_direction(double *normal, double *out); + public: GeneralElement(); ~GeneralElement(); @@ -57,15 +59,14 @@ class GeneralElement /** * - * Constructor allocates memory for centroid and normal. + * Constructor allocates memory for centroid and normal. * */ -GeneralElement::GeneralElement() -{ - normal_calculated = 0; - centroid_calculated = 0; - centroid = new double[DIM]; - normal = new double[DIM]; +GeneralElement::GeneralElement() { + normal_calculated = 0; + centroid_calculated = 0; + centroid = new double[DIM]; + normal = new double[DIM]; } /** @@ -73,36 +74,34 @@ GeneralElement::GeneralElement() * Destructor frees memory. * */ -GeneralElement::~GeneralElement() -{ - delete[] centroid; - delete[] normal; +GeneralElement::~GeneralElement() { + delete[] centroid; + delete[] normal; } /** * * Checks if the normal is pointing into right direction. If the normal - * is pointing in the wrong direction, it is turned to the right direction. + * is pointing in the wrong direction, it is turned to the right direction. * * @param [in/out] normal The normal vector * @param [in] out Vector pointing into outward direction. * */ -void GeneralElement::check_normal_direction(double *normal, double *out) -{ - //We calculate the dot product, if less than 4 dimensions the elements, - //which are not used, are just zero and do not effect this - double dot_product = 0; - for (int i=0; i < DIM; i++) { - dot_product += out[i]*normal[i]; - } - //If the dot product is negative, the normal is pointing in the - //wrong direction and we have to flip it's direction - if ( dot_product < 0 ) { - for (int i=0; i < DIM; i++) { - normal[i] = -normal[i]; - } - } +void GeneralElement::check_normal_direction(double *normal, double *out) { + // We calculate the dot product, if less than 4 dimensions the elements, + // which are not used, are just zero and do not effect this + double dot_product = 0; + for (int i = 0; i < DIM; i++) { + dot_product += out[i] * normal[i]; + } + // If the dot product is negative, the normal is pointing in the + // wrong direction and we have to flip it's direction + if (dot_product < 0) { + for (int i = 0; i < DIM; i++) { + normal[i] = -normal[i]; + } + } } /** @@ -112,11 +111,9 @@ void GeneralElement::check_normal_direction(double *normal, double *out) * @return Table containing centroid in 4D * */ -double *GeneralElement::get_centroid() -{ - if ( !centroid_calculated ) - calculate_centroid(); - return centroid; +double *GeneralElement::get_centroid() { + if (!centroid_calculated) calculate_centroid(); + return centroid; } /** @@ -126,26 +123,22 @@ double *GeneralElement::get_centroid() * @return Table containing normal in 4D * */ -double *GeneralElement::get_normal() -{ - if ( !normal_calculated ) - calculate_normal(); - return normal; +double *GeneralElement::get_normal() { + if (!normal_calculated) calculate_normal(); + return normal; } - /** * * This class is used for line elements gotten from the squares. Can * calculate the centroid and normal of the line. * */ -class Line : public GeneralElement -{ +class Line : public GeneralElement { private: static const int LINE_CORNERS = 2; static const int LINE_DIM = 2; - int x1,x2; + int x1, x2; int start_point; int end_point; double **corners; @@ -153,10 +146,11 @@ class Line : public GeneralElement int *const_i; void calculate_centroid(); void calculate_normal(); + public: Line(); ~Line(); - void init(double**,double*,int*); + void init(double **, double *, int *); void flip_start_end(); double *get_start(); double *get_end(); @@ -169,15 +163,14 @@ class Line : public GeneralElement * outside and indices of the elements which are constant. * */ -Line::Line() -{ - GeneralElement(); - corners = new double*[LINE_CORNERS]; - for (int i=0; i < LINE_CORNERS; i++) { - corners[i] = new double[DIM]; - } - out = new double[DIM]; - const_i = new int[DIM-LINE_DIM]; +Line::Line() { + GeneralElement(); + corners = new double *[LINE_CORNERS]; + for (int i = 0; i < LINE_CORNERS; i++) { + corners[i] = new double[DIM]; + } + out = new double[DIM]; + const_i = new int[DIM - LINE_DIM]; } /** @@ -185,14 +178,13 @@ Line::Line() * Frees memory allocated in constructor. * */ -Line::~Line() -{ - for (int i=0; i < LINE_CORNERS; i++) { - delete[] corners[i]; - } - delete[] corners; - delete[] out; - delete[] const_i; +Line::~Line() { + for (int i = 0; i < LINE_CORNERS; i++) { + delete[] corners[i]; + } + delete[] corners; + delete[] out; + delete[] const_i; } /** @@ -205,49 +197,54 @@ Line::~Line() * @param [in] o Table containing constant indices * */ -void Line::init(double **p, double *o, int *c) -{ - //We copy the values of the end points and the outside point - for (int i=0; i < LINE_CORNERS; i++) { - for (int j=0; j < DIM; j++) { - corners[i][j] = p[i][j]; - if ( i==0 ) { - out[j] = o[j]; - } - } - } - //Let's set indices for start and end points, so we can conveniently - //flip the start and end point without changing the actual values - start_point = 0; - end_point = 1; - //Here we copy the indices which are constant at this line - for (int i=0; i < DIM-LINE_DIM; i++) { - const_i[i] = c[i]; - } - //Here we fix the non-zero indices in such a way that x1 is - //always smaller - if ( c[0] == 0 ) { - if ( c[1] == 1 ) { - x1 = 2; x2 = 3; - } else if ( c[1] == 2 ) { - x1 = 1; x2 = 3; - } else { - x1 = 1; x2 = 2; +void Line::init(double **p, double *o, int *c) { + // We copy the values of the end points and the outside point + for (int i = 0; i < LINE_CORNERS; i++) { + for (int j = 0; j < DIM; j++) { + corners[i][j] = p[i][j]; + if (i == 0) { + out[j] = o[j]; + } + } } - } else if ( c[0] == 1 ) { - if ( c[1] == 2 ) { - x1 = 0; x2 = 3; + // Let's set indices for start and end points, so we can conveniently + // flip the start and end point without changing the actual values + start_point = 0; + end_point = 1; + // Here we copy the indices which are constant at this line + for (int i = 0; i < DIM - LINE_DIM; i++) { + const_i[i] = c[i]; + } + // Here we fix the non-zero indices in such a way that x1 is + // always smaller + if (c[0] == 0) { + if (c[1] == 1) { + x1 = 2; + x2 = 3; + } else if (c[1] == 2) { + x1 = 1; + x2 = 3; + } else { + x1 = 1; + x2 = 2; + } + } else if (c[0] == 1) { + if (c[1] == 2) { + x1 = 0; + x2 = 3; + } else { + x1 = 0; + x2 = 2; + } } else { - x1 = 0; x2 = 2; - } - } else { - x1 = 0; x2 = 1; - } - //We need to set these to zero so when this function is called - //again we know that normal and centroid are not yet calculated - //with new values - normal_calculated = 0; - centroid_calculated = 0; + x1 = 0; + x2 = 1; + } + // We need to set these to zero so when this function is called + // again we know that normal and centroid are not yet calculated + // with new values + normal_calculated = 0; + centroid_calculated = 0; } /** @@ -256,13 +253,12 @@ void Line::init(double **p, double *o, int *c) * operation. * */ -void Line::calculate_centroid() -{ - //Centroid is just the average of the points - for (int i=0; i < DIM; i++) { - centroid[i] = (corners[0][i] + corners[1][i])/2.0; - } - centroid_calculated = 1; +void Line::calculate_centroid() { + // Centroid is just the average of the points + for (int i = 0; i < DIM; i++) { + centroid[i] = (corners[0][i] + corners[1][i]) / 2.0; + } + centroid_calculated = 1; } /** @@ -270,24 +266,22 @@ void Line::calculate_centroid() * Calculates the normal vector for a line. * */ -void Line::calculate_normal() -{ - //Centroid must be calculated before we can calculate normal - if ( !centroid_calculated ) - calculate_centroid(); - //Normal is just (-dy,dx) - normal[x1] = -(corners[1][x2] - corners[0][x2]); - normal[x2] = corners[1][x1] - corners[0][x1]; - normal[const_i[0]] = 0; - normal[const_i[1]] = 0; - //Now we check if the normal is in the correct direction - double *Vout = new double[DIM]; - for (int j=0; j < DIM; j++) { - Vout[j] = out[j] - centroid[j]; - } - check_normal_direction(normal,Vout); - delete[] Vout; - normal_calculated = 1; +void Line::calculate_normal() { + // Centroid must be calculated before we can calculate normal + if (!centroid_calculated) calculate_centroid(); + // Normal is just (-dy,dx) + normal[x1] = -(corners[1][x2] - corners[0][x2]); + normal[x2] = corners[1][x1] - corners[0][x1]; + normal[const_i[0]] = 0; + normal[const_i[1]] = 0; + // Now we check if the normal is in the correct direction + double *Vout = new double[DIM]; + for (int j = 0; j < DIM; j++) { + Vout[j] = out[j] - centroid[j]; + } + check_normal_direction(normal, Vout); + delete[] Vout; + normal_calculated = 1; } /** @@ -295,11 +289,10 @@ void Line::calculate_normal() * Flips the start and end point of the line. * */ -void Line::flip_start_end() -{ - int temp = start_point; - start_point = end_point; - end_point = temp; +void Line::flip_start_end() { + int temp = start_point; + start_point = end_point; + end_point = temp; } /** @@ -309,10 +302,7 @@ void Line::flip_start_end() * @return Start point as a table * */ -double *Line::get_start() -{ - return corners[start_point]; -} +double *Line::get_start() { return corners[start_point]; } /** * @@ -321,10 +311,7 @@ double *Line::get_start() * @return End point as a table * */ -double *Line::get_end() -{ - return corners[end_point]; -} +double *Line::get_end() { return corners[end_point]; } /** * @@ -333,10 +320,7 @@ double *Line::get_end() * @return Point which is always outside as a table * */ -double *Line::get_out() -{ - return out; -} +double *Line::get_out() { return out; } /** * @@ -344,25 +328,25 @@ double *Line::get_out() * the centroid and normal of the polygon. * */ -class Polygon : public GeneralElement -{ +class Polygon : public GeneralElement { private: static const int MAX_LINES = 24; static const int POLYGON_DIM = 3; Line **lines; int Nlines; - int x1,x2,x3; + int x1, x2, x3; int const_i; void calculate_centroid(); void calculate_normal(); + public: Polygon(); ~Polygon(); void init(int); - bool add_line(Line*,int); + bool add_line(Line *, int); int get_Nlines(); - Line** get_lines(); - void print(ofstream &file,double*); + Line **get_lines(); + void print(ofstream &file, double *); }; /** @@ -371,10 +355,9 @@ class Polygon : public GeneralElement * form the polygon. * */ -Polygon::Polygon() -{ - GeneralElement(); - lines = new Line*[MAX_LINES]; +Polygon::Polygon() { + GeneralElement(); + lines = new Line *[MAX_LINES]; } /** @@ -382,92 +365,86 @@ Polygon::Polygon() * Frees memory allocated at the constructor. * */ -Polygon::~Polygon() -{ - delete[] lines; -} +Polygon::~Polygon() { delete[] lines; } /** * * This initializes the polygon. Can be used several times. - * - * @param [in] c Index which is constant in this polygon - * - */ -void Polygon::init(int c) -{ - //Let's copy the constant index - const_i = c; - //Here we fix the indices which are not constant - x1 = -1; - x2 = -1; - x3 = -1; - for (int i=0; i < DIM; i++) { - if ( i != c ) { - if ( x1 < 0 ) { - x1 = i; - } else if ( x2 < 0 ) { - x2 = i; - } else { - x3 = i; - } - } - } - //We need to set these to zero so when this function is called - //again we know that polygon has no lines added and normal and - //centroid are not yet calculated with new values - Nlines = 0; - normal_calculated = 0; - centroid_calculated = 0; + * + * @param [in] c Index which is constant in this polygon + * + */ +void Polygon::init(int c) { + // Let's copy the constant index + const_i = c; + // Here we fix the indices which are not constant + x1 = -1; + x2 = -1; + x3 = -1; + for (int i = 0; i < DIM; i++) { + if (i != c) { + if (x1 < 0) { + x1 = i; + } else if (x2 < 0) { + x2 = i; + } else { + x3 = i; + } + } + } + // We need to set these to zero so when this function is called + // again we know that polygon has no lines added and normal and + // centroid are not yet calculated with new values + Nlines = 0; + normal_calculated = 0; + centroid_calculated = 0; } /** * * Adds a line to the polygon. This can also check if the line * is connected to the ones already in the polygon and the line - * is added only when the line is connected. - * - * @param [in] l Line which is tried to add to polygon + * is added only when the line is connected. + * + * @param [in] l Line which is tried to add to polygon * @param [in] donotcheck 1 if no check is needed, 0 otherwise * * @return True if line was added, false if not added * */ -bool Polygon::add_line(Line *l, int donotcheck) -{ - double eps = 1e-10; - //If this is the first line or we do not want to check, line is added - //automatically - if ( donotcheck || Nlines == 0 ) { - lines[Nlines] = l; - Nlines++; - return true; - } else { - //Here we check if the new line is connected with the last line in - //polygon. This since lines are ordered. - double *p1 = l->get_start(); - double *p2 = l->get_end(); - double *p3 = lines[Nlines-1]->get_end(); - double diff1 = 0; - double diff2 = 0; - for (int j=0; j < DIM; j++) { - diff1 += fabs(p1[j]-p3[j]); - diff2 += fabs(p2[j]-p3[j]); - } - //If start or end point is the same as the end point of previous line, line - //is connected to polygon and it is added - if ( diff1 < eps || diff2 < eps ) { - //We always want that start point is connected to end so we flip the - //start and end in the new line if needed - if ( diff2 < eps ) - l->flip_start_end(); - lines[Nlines] = l; - Nlines++; - return true; - } - //If we are here, the line was not connected to the current polygon - return false; - } +bool Polygon::add_line(Line *l, int donotcheck) { + double eps = 1e-10; + // If this is the first line or we do not want to check, line is added + // automatically + if (donotcheck || Nlines == 0) { + lines[Nlines] = l; + Nlines++; + return true; + } else { + // Here we check if the new line is connected with the last line in + // polygon. This since lines are ordered. + double *p1 = l->get_start(); + double *p2 = l->get_end(); + double *p3 = lines[Nlines - 1]->get_end(); + double diff1 = 0; + double diff2 = 0; + for (int j = 0; j < DIM; j++) { + diff1 += fabs(p1[j] - p3[j]); + diff2 += fabs(p2[j] - p3[j]); + } + // If start or end point is the same as the end point of previous line, + // line is connected to polygon and it is added + if (diff1 < eps || diff2 < eps) { + // We always want that start point is connected to end so we flip + // the start and end in the new line if needed + if (diff2 < eps) l->flip_start_end(); + lines[Nlines] = l; + Nlines++; + return true; + } + // If we are here, the line was not connected to the current polygon + return false; + } } /** @@ -475,79 +452,82 @@ bool Polygon::add_line(Line *l, int donotcheck) * This determines the centroid (center of mass) of the polygon. * */ -void Polygon::calculate_centroid() -{ - //We need a vector for the mean of the corners. - double *mean = new double[DIM]; - for (int i=0; i < DIM; i++ ) { - mean[i] = 0; - } - //First we determine the mean of the corner points. Every point - //is here twice since lines are not ordered - for (int i=0; i < Nlines; i++ ) { - double *p1 = lines[i]->get_start(); - double *p2 = lines[i]->get_end(); - for (int j=0; j < DIM; j++ ) { - mean[j] += p1[j] + p2[j]; - } - } - for (int j=0; j < DIM; j++ ) { - mean[j] = mean[j]/double(2.0*Nlines); - } - //If only 3 lines, i.e. 3 corners, the polygon is always on a plane - //and centroid is the mean - if ( Nlines == 3 ) { - for (int i=0; i < DIM; i++) { - centroid[i] = mean[i]; +void Polygon::calculate_centroid() { + // We need a vector for the mean of the corners. + double *mean = new double[DIM]; + for (int i = 0; i < DIM; i++) { + mean[i] = 0; + } + // First we determine the mean of the corner points. Every point + // is here twice since lines are not ordered + for (int i = 0; i < Nlines; i++) { + double *p1 = lines[i]->get_start(); + double *p2 = lines[i]->get_end(); + for (int j = 0; j < DIM; j++) { + mean[j] += p1[j] + p2[j]; + } + } + for (int j = 0; j < DIM; j++) { + mean[j] = mean[j] / double(2.0 * Nlines); + } + // If only 3 lines, i.e. 3 corners, the polygon is always on a plane + // and centroid is the mean + if (Nlines == 3) { + for (int i = 0; i < DIM; i++) { + centroid[i] = mean[i]; + } + centroid_calculated = 1; + delete[] mean; + return; + } + // If more than 3 corners, calculation of the centroid is more + // complicated + // Here we from triangles from the lines and the mean point + double *sum_up = new double[DIM]; // areas of the single triangles + double sum_down = 0; // area of all the triangles + for (int i = 0; i < DIM; i++) { + sum_up[i] = 0; + } + // a and b are vectors which from the triangle + double *a = new double[DIM]; + double *b = new double[DIM]; + // centroid of the triangle (this is always on a plane) + double *cm_i = new double[DIM]; + for (int i = 0; i < Nlines; i++) { + double *p1 = lines[i]->get_start(); + double *p2 = lines[i]->get_end(); + for (int j = 0; j < DIM; j++) { + cm_i[j] = (p1[j] + p2[j] + mean[j]) / 3.0; + } + // Triangle is defined by these two vectors + for (int j = 0; j < DIM; j++) { + a[j] = p1[j] - mean[j]; + b[j] = p2[j] - mean[j]; + } + // Area is calculated from cross product of these vectors + double A_i = 0.5 + * sqrt( + pow(a[x2] * b[x3] - a[x3] * b[x2], 2.0) + + pow(a[x1] * b[x3] - a[x3] * b[x1], 2.0) + + pow(a[x2] * b[x1] - a[x1] * b[x2], 2.0)); + // Then we store the area and update the total area + for (int j = 0; j < DIM; j++) { + sum_up[j] += cm_i[j] * A_i; + } + sum_down += A_i; + } + // Now we can determine centroid as a weighted average of the centroids + // of the triangles + for (int i = 0; i < DIM; i++) { + centroid[i] = sum_up[i] / sum_down; } + // centroid is now calculated and memory is freed centroid_calculated = 1; + delete[] sum_up; delete[] mean; - return; - } - //If more than 3 corners, calculation of the centroid is more - //complicated - //Here we from triangles from the lines and the mean point - double *sum_up = new double[DIM]; //areas of the single triangles - double sum_down = 0; //area of all the triangles - for (int i=0; i < DIM; i++) { - sum_up[i] = 0; - } - //a and b are vectors which from the triangle - double *a = new double[DIM]; - double *b = new double[DIM]; - //centroid of the triangle (this is always on a plane) - double *cm_i = new double[DIM]; - for (int i=0; i < Nlines; i++) { - double *p1 = lines[i]->get_start(); - double *p2 = lines[i]->get_end(); - for (int j=0; j < DIM; j++) { - cm_i[j] = (p1[j] + p2[j] + mean[j])/3.0; - } - //Triangle is defined by these two vectors - for (int j=0; j < DIM; j++) { - a[j] = p1[j] - mean[j]; - b[j] = p2[j] - mean[j]; - } - //Area is calculated from cross product of these vectors - double A_i = 0.5*sqrt( pow(a[x2]*b[x3]-a[x3]*b[x2],2.0) + pow(a[x1]*b[x3]-a[x3]*b[x1],2.0) + pow(a[x2]*b[x1]-a[x1]*b[x2],2.0) ); - //Then we store the area and update the total area - for (int j=0; j < DIM; j++) { - sum_up[j] += cm_i[j]*A_i; - } - sum_down += A_i; - } - //Now we can determine centroid as a weighted average of the centroids - //of the triangles - for (int i=0; i < DIM; i++) { - centroid[i] = sum_up[i]/sum_down; - } - //centroid is now calculated and memory is freed - centroid_calculated = 1; - delete[] sum_up; - delete[] mean; - delete[] a; - delete[] b; - delete[] cm_i; + delete[] a; + delete[] b; + delete[] cm_i; } /** @@ -556,64 +536,62 @@ void Polygon::calculate_centroid() * it points in the outward direction. * */ -void Polygon::calculate_normal() -{ - //centroid must be calculated before normal can be determined - if ( !centroid_calculated ) - calculate_centroid(); - //First we find the normal for each triangle formed from - //one edge and centroid - double **normals = new double*[Nlines]; //these are the normals - double *Vout = new double[DIM]; //the point which is always outside - for (int i=0; i < Nlines; i++) { - normals[i] = new double[DIM]; - for (int j=0; j < DIM; j++) { - normals[i][j] = 0; - } - } - //Normal is defined by these two vectors - double *a = new double[DIM]; - double *b = new double[DIM]; - //Loop over all triangles - for (int i=0; i < Nlines; i++) { - //First we calculate the vectors which form the triangle - double *p1 = lines[i]->get_start(); - double *p2 = lines[i]->get_end(); - for (int j=0; j < DIM; j++) { - a[j] = p1[j] - centroid[j]; - b[j] = p2[j] - centroid[j]; - } - //Normal is calculated as a cross product of these vectors - normals[i][x1] = 0.5*(a[x2]*b[x3]-a[x3]*b[x2]); - normals[i][x2] = -0.5*(a[x1]*b[x3]-a[x3]*b[x1]); - normals[i][x3] = 0.5*(a[x1]*b[x2]-a[x2]*b[x1]); - normals[i][const_i] = 0; - //Then we construct a vector which points out - double *o = lines[i]->get_out(); - for (int j=0; j < DIM; j++) { - Vout[j] = o[j] - centroid[j]; - } - //then we check that normal is point in the correct direction - check_normal_direction(normals[i],Vout); - } - //Finally the normal is a sum of the normals of the triangles - for (int i=0; i < DIM; i++) { - normal[i] = 0; - } - for (int i=0; i < Nlines; i++) { - for (int j=0; j < DIM; j++) { - normal[j] += normals[i][j]; - } - } - //Normal is now calculated and memory can be freed - normal_calculated = 1; - delete[] a; - delete[] b; - for (int i=0; i < Nlines; i++) { - delete[] normals[i]; - } - delete[] normals; - delete[] Vout; +void Polygon::calculate_normal() { + // centroid must be calculated before normal can be determined + if (!centroid_calculated) calculate_centroid(); + // First we find the normal for each triangle formed from + // one edge and centroid + double **normals = new double *[Nlines]; // these are the normals + double *Vout = new double[DIM]; // the point which is always outside + for (int i = 0; i < Nlines; i++) { + normals[i] = new double[DIM]; + for (int j = 0; j < DIM; j++) { + normals[i][j] = 0; + } + } + // Normal is defined by these two vectors + double *a = new double[DIM]; + double *b = new double[DIM]; + // Loop over all triangles + for (int i = 0; i < Nlines; i++) { + // First we calculate the vectors which form the triangle + double *p1 = lines[i]->get_start(); + double *p2 = lines[i]->get_end(); + for (int j = 0; j < DIM; j++) { + a[j] = p1[j] - centroid[j]; + b[j] = p2[j] - centroid[j]; + } + // Normal is calculated as a cross product of these vectors + normals[i][x1] = 0.5 * (a[x2] * b[x3] - a[x3] * b[x2]); + normals[i][x2] = -0.5 * (a[x1] * b[x3] - a[x3] * b[x1]); + normals[i][x3] = 0.5 * (a[x1] * b[x2] - a[x2] * b[x1]); + normals[i][const_i] = 0; + // Then we construct a vector which points out + double *o = lines[i]->get_out(); + for (int j = 0; j < DIM; j++) { + Vout[j] = o[j] - centroid[j]; + } + // then we check that normal is point in the correct direction + check_normal_direction(normals[i], Vout); + } + // Finally the normal is a sum of the normals of the triangles + for (int i = 0; i < DIM; i++) { + normal[i] = 0; + } + for (int i = 0; i < Nlines; i++) { + for (int j = 0; j < DIM; j++) { + normal[j] += normals[i][j]; + } + } + // Normal is now calculated and memory can be freed + normal_calculated = 1; + delete[] a; + delete[] b; + for (int i = 0; i < Nlines; i++) { + delete[] normals[i]; + } + delete[] normals; + delete[] Vout; } /** @@ -623,10 +601,7 @@ void Polygon::calculate_normal() * @return Number of lines in this polygon * */ -int Polygon::get_Nlines() -{ - return Nlines; -} +int Polygon::get_Nlines() { return Nlines; } /** * @@ -635,10 +610,7 @@ int Polygon::get_Nlines() * @return Array of pointer to the lines in polygon * */ -Line** Polygon::get_lines() -{ - return lines; -} +Line **Polygon::get_lines() { return lines; } /** * @@ -646,18 +618,20 @@ Line** Polygon::get_lines() * the absolute points, so this file can be used to plot the surface. * * @param [in] file Output stream where the points are printed. - * @param [in] file Absolute position of the cube point (0,0,0) - * - */ -void Polygon::print(ofstream &file, double *pos) -{ - for (int i=0; i < Nlines; i++) { - double *p1 = lines[i]->get_start(); - double *p2 = lines[i]->get_end(); - file << pos[x1] + p1[x1] << " " << pos[x2] + p1[x2] << " " << pos[x3] + p1[x3]; - file << " " << pos[x1] + p2[x1] << " " << pos[x2] + p2[x2] << " " << pos[x3] + p2[x3]; - file << " " << pos[x1] + centroid[x1] << " " << pos[x2] + centroid[x2] << " " << pos[x3] + centroid[x3] << endl; - } + * @param [in] file Absolute position of the cube point (0,0,0) + * + */ +void Polygon::print(ofstream &file, double *pos) { + for (int i = 0; i < Nlines; i++) { + double *p1 = lines[i]->get_start(); + double *p2 = lines[i]->get_end(); + file << pos[x1] + p1[x1] << " " << pos[x2] + p1[x2] << " " + << pos[x3] + p1[x3]; + file << " " << pos[x1] + p2[x1] << " " << pos[x2] + p2[x2] << " " + << pos[x3] + p2[x3]; + file << " " << pos[x1] + centroid[x1] << " " << pos[x2] + centroid[x2] + << " " << pos[x3] + centroid[x3] << endl; + } } /** @@ -666,35 +640,34 @@ void Polygon::print(ofstream &file, double *pos) * the normal and centroid of the polyhedron. * */ -class Polyhedron : public GeneralElement -{ +class Polyhedron : public GeneralElement { private: static const int MAX_POLYGONS = 24; Polygon **polygons; int Npolygons; int Ntetrahedra; - int x1,x2,x3,x4; - bool lines_equal(Line*,Line*); - void tetravolume(double*,double*,double*,double*); + int x1, x2, x3, x4; + bool lines_equal(Line *, Line *); + void tetravolume(double *, double *, double *, double *); void calculate_centroid(); void calculate_normal(); + public: Polyhedron(); ~Polyhedron(); void init(); - bool add_polygon(Polygon*,int); + bool add_polygon(Polygon *, int); }; /** - * + * * Allocates memory for a list pointers to the polygons which form * the polyhedron. * */ -Polyhedron::Polyhedron() -{ - GeneralElement(); - polygons = new Polygon*[MAX_POLYGONS]; +Polyhedron::Polyhedron() { + GeneralElement(); + polygons = new Polygon *[MAX_POLYGONS]; } /** @@ -702,30 +675,26 @@ Polyhedron::Polyhedron() * Frees memory allocated at the constructor. * */ -Polyhedron::~Polyhedron() -{ - delete[] polygons; -} +Polyhedron::~Polyhedron() { delete[] polygons; } /** * * This initializes the polygon. Can be used several times. - * - */ -void Polyhedron::init() -{ - //Here we fix the non-constant indices - x1 = 0; - x2 = 1; - x3 = 2; - x4 = 3; - //We need to set these to zero so when this function is called - //again we know that polyhedron has no polyfons added and normal - //and centroid are not yet calculated with new values - Npolygons = 0; - Ntetrahedra = 0; - normal_calculated = 0; - centroid_calculated = 0; + * + */ +void Polyhedron::init() { + // Here we fix the non-constant indices + x1 = 0; + x2 = 1; + x3 = 2; + x4 = 3; + // We need to set these to zero so when this function is called + // again we know that polyhedron has no polyfons added and normal + // and centroid are not yet calculated with new values + Npolygons = 0; + Ntetrahedra = 0; + normal_calculated = 0; + centroid_calculated = 0; } /** @@ -733,72 +702,69 @@ void Polyhedron::init() * Adds a polygon to the polyhedron. Also possible to check if the new * polygon is connected with previous polygons and only make the addition * if this is the case. - * + * * @param [in] p Polygon which is tried to add to polyhedron * @param [in] donotcheck 1 if no check is needed, 0 otherwise * * @return True if polygon was added, false if not added * */ -bool Polyhedron::add_polygon(Polygon *p, int donocheck) -{ - //If this is the first polygon or we want to add it in any case, we - //just add it automatically - if ( donocheck || Npolygons == 0 ) { - polygons[Npolygons] = p; - Npolygons++; - Ntetrahedra += p->get_Nlines(); - return true; - } else { - //Here we check if the new polygon is connected with the last polygon in - //polyhedron - for (int i=0; i < Npolygons; i++) { - int Nlines1 = p->get_Nlines(); - int Nlines2 = polygons[i]->get_Nlines(); - Line **lines1 = p->get_lines(); - Line **lines2 = polygons[i]->get_lines(); - for (int j=0; j < Nlines1; j++) { - for (int k=0; k < Nlines2; k++) { - if ( lines_equal(lines1[j],lines2[k]) ) { - polygons[Npolygons] = p; - Npolygons++; - Ntetrahedra += p->get_Nlines(); - return true; - } +bool Polyhedron::add_polygon(Polygon *p, int donocheck) { + // If this is the first polygon or we want to add it in any case, we + // just add it automatically + if (donocheck || Npolygons == 0) { + polygons[Npolygons] = p; + Npolygons++; + Ntetrahedra += p->get_Nlines(); + return true; + } else { + // Here we check if the new polygon is connected with the last polygon + // in polyhedron + for (int i = 0; i < Npolygons; i++) { + int Nlines1 = p->get_Nlines(); + int Nlines2 = polygons[i]->get_Nlines(); + Line **lines1 = p->get_lines(); + Line **lines2 = polygons[i]->get_lines(); + for (int j = 0; j < Nlines1; j++) { + for (int k = 0; k < Nlines2; k++) { + if (lines_equal(lines1[j], lines2[k])) { + polygons[Npolygons] = p; + Npolygons++; + Ntetrahedra += p->get_Nlines(); + return true; + } + } + } } - } + // If we are here, the polygon was not connected to polyhedron + return false; } - //If we are here, the polygon was not connected to polyhedron - return false; - } } /** * * Checks if two lines are connected. - * + * * @param [in] l1 Line 1 * @param [in] l2 Line 2 * - * @return true if lines are connected, false if not - * - */ -bool Polyhedron::lines_equal(Line *l1, Line *l2) -{ - double eps = 1e-10; - double *p11 = l1->get_start(); - double *p12 = l1->get_end(); - double *p21 = l2->get_start(); - double diff1 = 0; - double diff2 = 0; - for (int i=0; i < DIM; i++) { - diff1 += fabs(p11[i]-p21[i]); - diff2 += fabs(p12[i]-p21[i]); - if ( diff1 > eps && diff2 > eps ) - return false; - } - //If we are here, the lines are connected - return true; + * @return true if lines are connected, false if not + * + */ +bool Polyhedron::lines_equal(Line *l1, Line *l2) { + double eps = 1e-10; + double *p11 = l1->get_start(); + double *p12 = l1->get_end(); + double *p21 = l2->get_start(); + double diff1 = 0; + double diff2 = 0; + for (int i = 0; i < DIM; i++) { + diff1 += fabs(p11[i] - p21[i]); + diff2 += fabs(p12[i] - p21[i]); + if (diff1 > eps && diff2 > eps) return false; + } + // If we are here, the lines are connected + return true; } /** @@ -812,111 +778,109 @@ bool Polyhedron::lines_equal(Line *l1, Line *l2) * @param [out] n Normal vector for tetrahedra * */ -void Polyhedron::tetravolume(double *a, double *b, double *c, double *n) -{ - double bc01 = b[0]*c[1]-b[1]*c[0]; - double bc02 = b[0]*c[2]-b[2]*c[0]; - double bc03 = b[0]*c[3]-b[3]*c[0]; - double bc12 = b[1]*c[2]-b[2]*c[1]; - double bc13 = b[1]*c[3]-b[3]*c[1]; - double bc23 = b[2]*c[3]-b[3]*c[2]; - n[0] = 1.0/6.0*(a[1]*bc23 - a[2]*bc13 + a[3]*bc12); - n[1] = -1.0/6.0*(a[0]*bc23 - a[2]*bc03 + a[3]*bc02); - n[2] = 1.0/6.0*(a[0]*bc13 - a[1]*bc03 + a[3]*bc01); - n[3] = -1.0/6.0*(a[0]*bc12 - a[1]*bc02 + a[2]*bc01); - /*n[0] = 1.0/6.0*(a[1]*(b[2]*c[3]-b[3]*c[2]) - a[2]*(b[1]*c[3]-b[3]*c[1]) - +a[3]*(b[1]*c[2]-b[2]*c[1])); - n[1] = -1.0/6.0*(a[0]*(b[2]*c[3]-b[3]*c[2]) - a[2]*(b[0]*c[3]-b[3]*c[0]) - +a[3]*(b[0]*c[2]-b[2]*c[0])); - n[2] = 1.0/6.0*(a[0]*(b[1]*c[3]-b[3]*c[1]) - a[1]*(b[0]*c[3]-b[3]*c[0]) - +a[3]*(b[0]*c[1]-b[1]*c[0])); - n[3] = -1.0/6.0*(a[0]*(b[1]*c[2]-b[2]*c[1]) - a[1]*(b[0]*c[2]-b[2]*c[0]) - +a[2]*(b[0]*c[1]-b[1]*c[0]));*/ +void Polyhedron::tetravolume(double *a, double *b, double *c, double *n) { + double bc01 = b[0] * c[1] - b[1] * c[0]; + double bc02 = b[0] * c[2] - b[2] * c[0]; + double bc03 = b[0] * c[3] - b[3] * c[0]; + double bc12 = b[1] * c[2] - b[2] * c[1]; + double bc13 = b[1] * c[3] - b[3] * c[1]; + double bc23 = b[2] * c[3] - b[3] * c[2]; + n[0] = 1.0 / 6.0 * (a[1] * bc23 - a[2] * bc13 + a[3] * bc12); + n[1] = -1.0 / 6.0 * (a[0] * bc23 - a[2] * bc03 + a[3] * bc02); + n[2] = 1.0 / 6.0 * (a[0] * bc13 - a[1] * bc03 + a[3] * bc01); + n[3] = -1.0 / 6.0 * (a[0] * bc12 - a[1] * bc02 + a[2] * bc01); + /*n[0] = 1.0/6.0*(a[1]*(b[2]*c[3]-b[3]*c[2]) - a[2]*(b[1]*c[3]-b[3]*c[1]) + +a[3]*(b[1]*c[2]-b[2]*c[1])); + n[1] = -1.0/6.0*(a[0]*(b[2]*c[3]-b[3]*c[2]) - a[2]*(b[0]*c[3]-b[3]*c[0]) + +a[3]*(b[0]*c[2]-b[2]*c[0])); + n[2] = 1.0/6.0*(a[0]*(b[1]*c[3]-b[3]*c[1]) - a[1]*(b[0]*c[3]-b[3]*c[0]) + +a[3]*(b[0]*c[1]-b[1]*c[0])); + n[3] = -1.0/6.0*(a[0]*(b[1]*c[2]-b[2]*c[1]) - a[1]*(b[0]*c[2]-b[2]*c[0]) + +a[2]*(b[0]*c[1]-b[1]*c[0]));*/ } /** * * This determines the centroid (center of mass) of the polyhedron. - * - */ -void Polyhedron::calculate_centroid() -{ - double *mean = new double[DIM]; - for (int i=0; i < DIM; i++ ) { - mean[i] = 0; - } - //First we determine the mean of the corners - for (int i=0; i < Npolygons; i++ ) { - int Nlines = polygons[i]->get_Nlines(); - Line **lines = polygons[i]->get_lines(); - for (int j=0; j < Nlines; j++ ) { - double *p1 = lines[j]->get_start(); - double *p2 = lines[j]->get_end(); - for (int k=0; k < DIM; k++ ) { - mean[k] += p1[k] + p2[k]; - } - } - } - for (int j=0; j < DIM; j++ ) { - mean[j] = mean[j]/double(2.0*Ntetrahedra); - } - //Some memory allocated for temporary variables - double *a = new double[DIM]; - double *b = new double[DIM]; - double *c = new double[DIM]; - double *n = new double[DIM]; - double *cm_i = new double[DIM]; - double *sum_up = new double[DIM]; - double sum_down = 0; - for (int i=0; i < DIM; i++) { - sum_up[i] = 0; - } - for (int i=0; i < Npolygons; i++ ) { - int Nlines = polygons[i]->get_Nlines(); - Line **lines = polygons[i]->get_lines(); - double *cent = polygons[i]->get_centroid(); - for (int j=0; j < Nlines; j++) { - double *p1 = lines[j]->get_start(); - double *p2 = lines[j]->get_end(); - //CM of the tetrahedra - for (int k=0; k < DIM; k++) { - cm_i[k] = (p1[k] + p2[k] + cent[k] + mean[k])/4.0; - } - //Volume of a tetrahedron is determined next - //Tetrahedron is defined by these three vectors - for (int k=0; k < DIM; k++) { - a[k] = p1[k] - mean[k]; - b[k] = p2[k] - mean[k]; - c[k] = cent[k] - mean[k]; - } - //Then we calculate the volume from the normal n - tetravolume(a,b,c,n); - double V_i = 0; - for (int k=0; k < DIM; k++) { - V_i += n[k]*n[k]; - } - V_i = sqrt(V_i); - //Then we add contributions to sums - for (int k=0; k < DIM; k++) { - sum_up[k] += cm_i[k]*V_i; - } - sum_down += V_i; - } - } - //Now the centroid is the volume weighted average of individual - //tetrahedra - for (int i=0; i < DIM; i++) { - centroid[i] = sum_up[i]/sum_down; - } - //Centroid is now calculated and we can free memory - centroid_calculated = 1; - delete[] a; - delete[] b; - delete[] c; - delete[] n; - delete[] cm_i; - delete[] sum_up; - delete[] mean; + * + */ +void Polyhedron::calculate_centroid() { + double *mean = new double[DIM]; + for (int i = 0; i < DIM; i++) { + mean[i] = 0; + } + // First we determine the mean of the corners + for (int i = 0; i < Npolygons; i++) { + int Nlines = polygons[i]->get_Nlines(); + Line **lines = polygons[i]->get_lines(); + for (int j = 0; j < Nlines; j++) { + double *p1 = lines[j]->get_start(); + double *p2 = lines[j]->get_end(); + for (int k = 0; k < DIM; k++) { + mean[k] += p1[k] + p2[k]; + } + } + } + for (int j = 0; j < DIM; j++) { + mean[j] = mean[j] / double(2.0 * Ntetrahedra); + } + // Some memory allocated for temporary variables + double *a = new double[DIM]; + double *b = new double[DIM]; + double *c = new double[DIM]; + double *n = new double[DIM]; + double *cm_i = new double[DIM]; + double *sum_up = new double[DIM]; + double sum_down = 0; + for (int i = 0; i < DIM; i++) { + sum_up[i] = 0; + } + for (int i = 0; i < Npolygons; i++) { + int Nlines = polygons[i]->get_Nlines(); + Line **lines = polygons[i]->get_lines(); + double *cent = polygons[i]->get_centroid(); + for (int j = 0; j < Nlines; j++) { + double *p1 = lines[j]->get_start(); + double *p2 = lines[j]->get_end(); + // CM of the tetrahedra + for (int k = 0; k < DIM; k++) { + cm_i[k] = (p1[k] + p2[k] + cent[k] + mean[k]) / 4.0; + } + // Volume of a tetrahedron is determined next + // Tetrahedron is defined by these three vectors + for (int k = 0; k < DIM; k++) { + a[k] = p1[k] - mean[k]; + b[k] = p2[k] - mean[k]; + c[k] = cent[k] - mean[k]; + } + // Then we calculate the volume from the normal n + tetravolume(a, b, c, n); + double V_i = 0; + for (int k = 0; k < DIM; k++) { + V_i += n[k] * n[k]; + } + V_i = sqrt(V_i); + // Then we add contributions to sums + for (int k = 0; k < DIM; k++) { + sum_up[k] += cm_i[k] * V_i; + } + sum_down += V_i; + } + } + // Now the centroid is the volume weighted average of individual + // tetrahedra + for (int i = 0; i < DIM; i++) { + centroid[i] = sum_up[i] / sum_down; + } + // Centroid is now calculated and we can free memory + centroid_calculated = 1; + delete[] a; + delete[] b; + delete[] c; + delete[] n; + delete[] cm_i; + delete[] sum_up; + delete[] mean; } /** @@ -925,65 +889,63 @@ void Polyhedron::calculate_centroid() * it points in the outward direction. * */ -void Polyhedron::calculate_normal() -{ - //We need centroid in the following calculation and thus we - //need to check that it is calculated - if ( !centroid_calculated ) - calculate_centroid(); - //First we allocate memory for temporary variables - double *Vout = new double[DIM]; - double *a = new double[DIM]; - double *b = new double[DIM]; - double *c = new double[DIM]; - double **normals = new double*[Ntetrahedra]; - for (int i=0; i < Ntetrahedra; i++) { - normals[i] = new double[DIM]; - } - int Ntetra = 0; //Index of tetrahedron we are dealing with - for (int i=0; i < Npolygons; i++ ) { - int Nlines = polygons[i]->get_Nlines(); - Line **lines = polygons[i]->get_lines(); - double *cent = polygons[i]->get_centroid(); - for (int j=0; j < Nlines; j++) { - double *p1 = lines[j]->get_start(); - double *p2 = lines[j]->get_end(); - //Tetrahedron is defined by these three vectors - for (int k=0; k < DIM; k++) { - a[k] = p1[k] - centroid[k]; - b[k] = p2[k] - centroid[k]; - c[k] = cent[k] - centroid[k]; - } - //Normal is calculated with the same function as volume - tetravolume(a,b,c,normals[Ntetra]); - //Then we determine the direction towards lower energy - double *o = lines[j]->get_out(); - for (int k=0; k < DIM; k++) { - Vout[k] = o[k] - centroid[k]; - } - check_normal_direction(normals[Ntetra],Vout); - Ntetra++; - } - } - //Finally the element normal is a sum of the calculated normals - for (int i=0; i < DIM; i++) { - normal[i] = 0; - } - for (int i=0; i < Ntetrahedra; i++) { - for (int j=0; j < DIM; j++) { - normal[j] += normals[i][j]; - } - } - //Normal is now determined and we can free memory - normal_calculated = 1; - for (int i=0; i < Ntetrahedra; i++) { - delete[] normals[i]; - } - delete[] a; - delete[] b; - delete[] c; - delete[] normals; - delete[] Vout; +void Polyhedron::calculate_normal() { + // We need centroid in the following calculation and thus we + // need to check that it is calculated + if (!centroid_calculated) calculate_centroid(); + // First we allocate memory for temporary variables + double *Vout = new double[DIM]; + double *a = new double[DIM]; + double *b = new double[DIM]; + double *c = new double[DIM]; + double **normals = new double *[Ntetrahedra]; + for (int i = 0; i < Ntetrahedra; i++) { + normals[i] = new double[DIM]; + } + int Ntetra = 0; // Index of tetrahedron we are dealing with + for (int i = 0; i < Npolygons; i++) { + int Nlines = polygons[i]->get_Nlines(); + Line **lines = polygons[i]->get_lines(); + double *cent = polygons[i]->get_centroid(); + for (int j = 0; j < Nlines; j++) { + double *p1 = lines[j]->get_start(); + double *p2 = lines[j]->get_end(); + // Tetrahedron is defined by these three vectors + for (int k = 0; k < DIM; k++) { + a[k] = p1[k] - centroid[k]; + b[k] = p2[k] - centroid[k]; + c[k] = cent[k] - centroid[k]; + } + // Normal is calculated with the same function as volume + tetravolume(a, b, c, normals[Ntetra]); + // Then we determine the direction towards lower energy + double *o = lines[j]->get_out(); + for (int k = 0; k < DIM; k++) { + Vout[k] = o[k] - centroid[k]; + } + check_normal_direction(normals[Ntetra], Vout); + Ntetra++; + } + } + // Finally the element normal is a sum of the calculated normals + for (int i = 0; i < DIM; i++) { + normal[i] = 0; + } + for (int i = 0; i < Ntetrahedra; i++) { + for (int j = 0; j < DIM; j++) { + normal[j] += normals[i][j]; + } + } + // Normal is now determined and we can free memory + normal_calculated = 1; + for (int i = 0; i < Ntetrahedra; i++) { + delete[] normals[i]; + } + delete[] a; + delete[] b; + delete[] c; + delete[] normals; + delete[] Vout; } /** @@ -993,8 +955,7 @@ void Polyhedron::calculate_normal() * correct direction for normal vector. * */ -class Square -{ +class Square { private: static const int DIM = 4; static const int SQUARE_DIM = 2; @@ -1015,14 +976,15 @@ class Square int ambiguous; void ends_of_edge(double); void find_outside(double); + public: Square(); ~Square(); - void init(double**,int*,double*,double*); + void init(double **, int *, double *, double *); void construct_lines(double); int is_ambiguous(); int get_Nlines(); - Line* get_lines(); + Line *get_lines(); }; /** @@ -1031,28 +993,27 @@ class Square * process. * */ -Square::Square() -{ - cuts = new double*[MAX_POINTS]; - out = new double*[MAX_POINTS]; - points = new double*[SQUARE_DIM]; - const_i = new int[DIM-SQUARE_DIM]; - const_value = new double[DIM-SQUARE_DIM]; - lines = new Line[MAX_LINES]; - for (int i=0; i < SQUARE_DIM; i++) { - points[i] = new double[SQUARE_DIM]; - } - for (int i=0; i < MAX_POINTS; i++) { - cuts[i] = new double[SQUARE_DIM]; - out[i] = new double[SQUARE_DIM]; - } - int Npoints = 2; - points_temp = new double*[SQUARE_DIM]; - out_temp = new double[DIM]; - for (int j=0; j < Npoints; j++) { - points_temp[j] = new double[DIM]; - } - ambiguous = 0; +Square::Square() { + cuts = new double *[MAX_POINTS]; + out = new double *[MAX_POINTS]; + points = new double *[SQUARE_DIM]; + const_i = new int[DIM - SQUARE_DIM]; + const_value = new double[DIM - SQUARE_DIM]; + lines = new Line[MAX_LINES]; + for (int i = 0; i < SQUARE_DIM; i++) { + points[i] = new double[SQUARE_DIM]; + } + for (int i = 0; i < MAX_POINTS; i++) { + cuts[i] = new double[SQUARE_DIM]; + out[i] = new double[SQUARE_DIM]; + } + int Npoints = 2; + points_temp = new double *[SQUARE_DIM]; + out_temp = new double[DIM]; + for (int j = 0; j < Npoints; j++) { + points_temp[j] = new double[DIM]; + } + ambiguous = 0; } /** @@ -1060,26 +1021,25 @@ Square::Square() * Destructor frees memory allocated in the constructor. * */ -Square::~Square() -{ - for (int i=0; i < DIM-SQUARE_DIM; i++) { - delete[] points[i]; - } - delete[] points; - for (int i=0; i < MAX_POINTS; i++) { - delete[] cuts[i]; - delete[] out[i]; - } - delete[] cuts; - delete[] out; - delete[] const_i; - delete[] const_value; - delete[] lines; - for (int i=0; i < SQUARE_DIM; i++) { - delete[] points_temp[i]; - } - delete[] points_temp; - delete[] out_temp; +Square::~Square() { + for (int i = 0; i < DIM - SQUARE_DIM; i++) { + delete[] points[i]; + } + delete[] points; + for (int i = 0; i < MAX_POINTS; i++) { + delete[] cuts[i]; + delete[] out[i]; + } + delete[] cuts; + delete[] out; + delete[] const_i; + delete[] const_value; + delete[] lines; + for (int i = 0; i < SQUARE_DIM; i++) { + delete[] points_temp[i]; + } + delete[] points_temp; + delete[] out_temp; } /** @@ -1094,34 +1054,33 @@ Square::~Square() * @param [in] dex Length of sides x and y * */ -void Square::init(double **sq, int *c_i, double *c_v, double *dex) -{ - for (int i=0; i < SQUARE_DIM; i++) { - for (int j=0; j < SQUARE_DIM; j++) { - points[i][j] = sq[i][j]; - } - } - for (int i=0; i < DIM-SQUARE_DIM; i++) { - const_i[i] = c_i[i]; - const_value[i] = c_v[i]; - } - dx = dex; - x1 = -1; - x2 = -1; - for (int i=0; i < DIM; i++) { - if ( i != const_i[0] && i != const_i[1] ) { - if ( x1 < 0 ) { - x1 = i; - } else { - x2 = i; - } - } - } - //We need to set these to zero so when this function is called - //again we know that nothing has been done for this square - Ncuts = 0; - Nlines = 0; - ambiguous = 0; +void Square::init(double **sq, int *c_i, double *c_v, double *dex) { + for (int i = 0; i < SQUARE_DIM; i++) { + for (int j = 0; j < SQUARE_DIM; j++) { + points[i][j] = sq[i][j]; + } + } + for (int i = 0; i < DIM - SQUARE_DIM; i++) { + const_i[i] = c_i[i]; + const_value[i] = c_v[i]; + } + dx = dex; + x1 = -1; + x2 = -1; + for (int i = 0; i < DIM; i++) { + if (i != const_i[0] && i != const_i[1]) { + if (x1 < 0) { + x1 = i; + } else { + x2 = i; + } + } + } + // We need to set these to zero so when this function is called + // again we know that nothing has been done for this square + Ncuts = 0; + Nlines = 0; + ambiguous = 0; } /** @@ -1131,45 +1090,42 @@ void Square::init(double **sq, int *c_i, double *c_v, double *dex) * @param [in] E0 The value which defines surface * */ -void Square::construct_lines(double E0) -{ - //First we check the corner points and see if there are any lines - int above=0; - for (int i=0; i < DIM-SQUARE_DIM; i++) { - for (int j=0; j < DIM-SQUARE_DIM; j++) { - if ( points[i][j] >= E0 ) - above++; +void Square::construct_lines(double E0) { + // First we check the corner points and see if there are any lines + int above = 0; + for (int i = 0; i < DIM - SQUARE_DIM; i++) { + for (int j = 0; j < DIM - SQUARE_DIM; j++) { + if (points[i][j] >= E0) above++; + } + } + // If all corners are above or below the surface value, no lines in this + // square + if (above == 0 || above == 4) { + Nlines = 0; + return; + } + // First we find the cut points and the points which are always outside of + // the surface. Also find_outside() arranges cuts so that first two cuts + // form a line as defined in the algorithm (in case there are 4 cuts) + ends_of_edge(E0); + if (Ncuts > 0) find_outside(E0); + // Then we go through the cut points and form the line elements + for (int i = 0; i < Ncuts; i++) { + points_temp[i % 2][x1] = cuts[i][0]; + points_temp[i % 2][x2] = cuts[i][1]; + points_temp[i % 2][const_i[0]] = const_value[0]; + points_temp[i % 2][const_i[1]] = const_value[1]; + // When we have inserted both endpoints we insert outside point + // and we are ready to create line element. + if (i % 2 == 1) { + out_temp[x1] = out[i / 2][0]; + out_temp[x2] = out[i / 2][1]; + out_temp[const_i[0]] = const_value[0]; + out_temp[const_i[1]] = const_value[1]; + lines[i / 2].init(points_temp, out_temp, const_i); + Nlines++; + } } - } - //If all corners are above or below the surface value, no lines in this - //square - if ( above == 0 || above == 4 ) { - Nlines = 0; - return; - } - //First we find the cut points and the points which are always outside of the - //surface. Also find_outside() arranges cuts so that first two cuts form a line - //as defined in the algorithm (in case there are 4 cuts) - ends_of_edge(E0); - if ( Ncuts > 0 ) - find_outside(E0); - //Then we go through the cut points and form the line elements - for (int i=0; i < Ncuts; i++) { - points_temp[i%2][x1] = cuts[i][0]; - points_temp[i%2][x2] = cuts[i][1]; - points_temp[i%2][const_i[0]] = const_value[0]; - points_temp[i%2][const_i[1]] = const_value[1]; - //When we have inserted both endpoints we insert outside point - //and we are ready to create line element. - if ( i%2 == 1 ) { - out_temp[x1] = out[i/2][0]; - out_temp[x2] = out[i/2][1]; - out_temp[const_i[0]] = const_value[0]; - out_temp[const_i[1]] = const_value[1]; - lines[i/2].init(points_temp,out_temp,const_i); - Nlines++; - } - } } /** @@ -1189,151 +1145,154 @@ void Square::construct_lines(double E0) * @param [in] E0 Value that defines this surface * */ -void Square::ends_of_edge(double E0) -{ - //Edge 1 - if ( (points[0][0]-E0)*(points[1][0]-E0) < 0 ) { - cuts[Ncuts][0] = (points[0][0]-E0)/(points[0][0]-points[1][0])*dx[x1]; - cuts[Ncuts][1] = 0; - Ncuts++; - } else if ( points[0][0] == E0 && points[1][0] < E0 ) { - cuts[Ncuts][0] = 1e-9*dx[x1]; - cuts[Ncuts][1] = 0; - Ncuts++; - } else if ( points[1][0] == E0 && points[0][0] < E0 ) { - cuts[Ncuts][0] = (1.0-1e-9)*dx[x1]; - cuts[Ncuts][1] = 0; - Ncuts++; - } - //Edge 2 - if ( (points[0][0]-E0)*(points[0][1]-E0) < 0 ) { - cuts[Ncuts][0] = 0; - cuts[Ncuts][1] = (points[0][0]-E0)/(points[0][0]-points[0][1])*dx[x2]; - Ncuts++; - } else if ( points[0][0] == E0 && points[0][1] < E0 ) { - cuts[Ncuts][0] = 0; - cuts[Ncuts][1] = 1e-9*dx[x2]; - Ncuts++; - } else if ( points[0][1] == E0 && points[0][0] < E0 ) { - cuts[Ncuts][0] = 0; - cuts[Ncuts][1] = (1.0-1e-9)*dx[x2]; - Ncuts++; - } - //Edge 3 - if ( (points[1][0]-E0)*(points[1][1]-E0) < 0 ) { - cuts[Ncuts][0] = dx[x1]; - cuts[Ncuts][1] = (points[1][0]-E0)/(points[1][0]-points[1][1])*dx[x2]; - Ncuts++; - } else if ( points[1][0] == E0 && points[1][1] < E0 ) { - cuts[Ncuts][0] = dx[x1]; - cuts[Ncuts][1] = 1e-9*dx[x2]; - Ncuts++; - } else if ( points[1][1] == E0 && points[1][0] < E0 ) { - cuts[Ncuts][0] = dx[x1]; - cuts[Ncuts][1] = (1.0-1e-9)*dx[x2]; - Ncuts++; - } - //Edge 4 - if ( (points[0][1]-E0)*(points[1][1]-E0) < 0 ) { - cuts[Ncuts][0] = (points[0][1]-E0)/(points[0][1]-points[1][1])*dx[x1]; - cuts[Ncuts][1] = dx[x2]; - Ncuts++; - } else if ( points[0][1] == E0 && points[1][1] < E0 ) { - cuts[Ncuts][0] = 1e-9*dx[x1]; - cuts[Ncuts][1] = dx[x2]; - Ncuts++; - } else if ( points[1][1] == E0 && points[0][1] < E0 ) { - cuts[Ncuts][0] = (1.0-1e-9)*dx[x1]; - cuts[Ncuts][1] = dx[x2]; - Ncuts++; - } - if ( Ncuts != 0 && Ncuts != 2 && Ncuts != 4 ) { - cout << "Error in EndsOfEdge: Ncuts " << Ncuts << endl; - exit(1); - } +void Square::ends_of_edge(double E0) { + // Edge 1 + if ((points[0][0] - E0) * (points[1][0] - E0) < 0) { + cuts[Ncuts][0] = + (points[0][0] - E0) / (points[0][0] - points[1][0]) * dx[x1]; + cuts[Ncuts][1] = 0; + Ncuts++; + } else if (points[0][0] == E0 && points[1][0] < E0) { + cuts[Ncuts][0] = 1e-9 * dx[x1]; + cuts[Ncuts][1] = 0; + Ncuts++; + } else if (points[1][0] == E0 && points[0][0] < E0) { + cuts[Ncuts][0] = (1.0 - 1e-9) * dx[x1]; + cuts[Ncuts][1] = 0; + Ncuts++; + } + // Edge 2 + if ((points[0][0] - E0) * (points[0][1] - E0) < 0) { + cuts[Ncuts][0] = 0; + cuts[Ncuts][1] = + (points[0][0] - E0) / (points[0][0] - points[0][1]) * dx[x2]; + Ncuts++; + } else if (points[0][0] == E0 && points[0][1] < E0) { + cuts[Ncuts][0] = 0; + cuts[Ncuts][1] = 1e-9 * dx[x2]; + Ncuts++; + } else if (points[0][1] == E0 && points[0][0] < E0) { + cuts[Ncuts][0] = 0; + cuts[Ncuts][1] = (1.0 - 1e-9) * dx[x2]; + Ncuts++; + } + // Edge 3 + if ((points[1][0] - E0) * (points[1][1] - E0) < 0) { + cuts[Ncuts][0] = dx[x1]; + cuts[Ncuts][1] = + (points[1][0] - E0) / (points[1][0] - points[1][1]) * dx[x2]; + Ncuts++; + } else if (points[1][0] == E0 && points[1][1] < E0) { + cuts[Ncuts][0] = dx[x1]; + cuts[Ncuts][1] = 1e-9 * dx[x2]; + Ncuts++; + } else if (points[1][1] == E0 && points[1][0] < E0) { + cuts[Ncuts][0] = dx[x1]; + cuts[Ncuts][1] = (1.0 - 1e-9) * dx[x2]; + Ncuts++; + } + // Edge 4 + if ((points[0][1] - E0) * (points[1][1] - E0) < 0) { + cuts[Ncuts][0] = + (points[0][1] - E0) / (points[0][1] - points[1][1]) * dx[x1]; + cuts[Ncuts][1] = dx[x2]; + Ncuts++; + } else if (points[0][1] == E0 && points[1][1] < E0) { + cuts[Ncuts][0] = 1e-9 * dx[x1]; + cuts[Ncuts][1] = dx[x2]; + Ncuts++; + } else if (points[1][1] == E0 && points[0][1] < E0) { + cuts[Ncuts][0] = (1.0 - 1e-9) * dx[x1]; + cuts[Ncuts][1] = dx[x2]; + Ncuts++; + } + if (Ncuts != 0 && Ncuts != 2 && Ncuts != 4) { + cout << "Error in EndsOfEdge: Ncuts " << Ncuts << endl; + exit(1); + } } /** * - * Finds the points showing the outside direction. + * Finds the points showing the outside direction. * * @param [in] E0 Value that defines this surface * */ -void Square::find_outside(double E0) -{ - if ( Ncuts == 4 ) { //Here the surface is ambiguous - ambiguous = 1; - //Let's calculate the value in the middle of the square - double Emid = 0; - for (int i=0; i < 2; i++) { - for (int j=0; j < 2; j++) { - Emid += 0.25*points[i][j]; - } - } - //The default is that cuts are connected as \\ here - //If both Emid and (0,0) are above or below the criterion - //the cuts should be like // and we have to switch order in cuts - if ( (points[0][0] < E0 && Emid < E0) || (points[0][0] > E0 && Emid > E0) ) { - for (int i=0; i < 2; i++) { - double temp = cuts[1][i]; - cuts[1][i] = cuts[2][i]; - cuts[2][i] = temp; - } - } - //The center is below, so the middle point is always outside - //the surface - if ( (Emid-E0) < 0 ) { - for (int i=0; i < 2; i++) { - for (int j=0; j < 2; j++) { - if ( j == 0 ) - out[i][j] = 0.5*dx[x1]; - else - out[i][j] = 0.5*dx[x2]; - } - } - } else { // The center is above - // Cuts are \\ here so bl and tr corners are outside - if ( (points[0][0]-E0) < 0 ) { - for (int i=0; i < 2; i++) { - out[0][i] = 0; - if ( i == 0 ) - out[1][i] = dx[x1]; - else - out[1][i] = dx[x2]; - } - // Cuts are // here so br and tl corners are outside - } else { - out[0][0] = dx[x1]; - out[0][1] = 0; - out[1][0] = 0; - out[1][1] = dx[x2]; - } - } - } else { //This is the normal case (not ambiguous) - for (int i=0; i < 2; i++) { - for (int j=0; j < 2; j++) { - out[i][j] = 0; - } - } - int Nout = 0; - for (int i=0; i < 2; i++) { - for (int j=0; j < 2; j++) { - if ( points[i][j] < E0 ) { - out[0][0] += i*dx[x1]; - out[0][1] += j*dx[x2]; - Nout++; - } - } - } - if ( Nout > 0 ) { - for (int i=0; i < 2; i++) { - for (int j=0; j < 2; j++) { - out[i][j] = out[i][j]/double(Nout); - } - } - } - } +void Square::find_outside(double E0) { + if (Ncuts == 4) { // Here the surface is ambiguous + ambiguous = 1; + // Let's calculate the value in the middle of the square + double Emid = 0; + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 2; j++) { + Emid += 0.25 * points[i][j]; + } + } + // The default is that cuts are connected as \\ here + // If both Emid and (0,0) are above or below the criterion + // the cuts should be like // and we have to switch order in cuts + if ((points[0][0] < E0 && Emid < E0) + || (points[0][0] > E0 && Emid > E0)) { + for (int i = 0; i < 2; i++) { + double temp = cuts[1][i]; + cuts[1][i] = cuts[2][i]; + cuts[2][i] = temp; + } + } + // The center is below, so the middle point is always outside + // the surface + if ((Emid - E0) < 0) { + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 2; j++) { + if (j == 0) + out[i][j] = 0.5 * dx[x1]; + else + out[i][j] = 0.5 * dx[x2]; + } + } + } else { // The center is above + // Cuts are \\ here so bl and tr corners are outside + if ((points[0][0] - E0) < 0) { + for (int i = 0; i < 2; i++) { + out[0][i] = 0; + if (i == 0) + out[1][i] = dx[x1]; + else + out[1][i] = dx[x2]; + } + // Cuts are // here so br and tl corners are outside + } else { + out[0][0] = dx[x1]; + out[0][1] = 0; + out[1][0] = 0; + out[1][1] = dx[x2]; + } + } + } else { // This is the normal case (not ambiguous) + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 2; j++) { + out[i][j] = 0; + } + } + int Nout = 0; + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 2; j++) { + if (points[i][j] < E0) { + out[0][0] += i * dx[x1]; + out[0][1] += j * dx[x2]; + Nout++; + } + } + } + if (Nout > 0) { + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 2; j++) { + out[i][j] = out[i][j] / double(Nout); + } + } + } + } } /** @@ -1343,22 +1302,16 @@ void Square::find_outside(double E0) * @return Zero if not ambiguous, one if ambiguous * */ -int Square::is_ambiguous() -{ - return ambiguous; -} +int Square::is_ambiguous() { return ambiguous; } /** * * Returns the number of lines in this square. - * + * * @return Number of lines in this square * */ -int Square::get_Nlines() -{ - return Nlines; -} +int Square::get_Nlines() { return Nlines; } /** * @@ -1367,11 +1320,7 @@ int Square::get_Nlines() * @return List of lines found from square * */ -Line* Square::get_lines() -{ - return lines; -} - +Line *Square::get_lines() { return lines; } /** * @@ -1379,8 +1328,7 @@ Line* Square::get_lines() * polygons from the lines given from squares. * */ -class Cube -{ +class Cube { private: static const int DIM = 4; static const int CUBE_DIM = 4; @@ -1396,19 +1344,20 @@ class Cube int ambiguous; int const_i; double const_value; - int x1,x2,x3; + int x1, x2, x3; double *dx; void split_to_squares(); void check_ambiguous(int); + public: Cube(); ~Cube(); - void init(double***&,int,double,double*&); + void init(double ***&, int, double, double *&); void construct_polygons(double); int get_Nlines(); int get_Npolygons(); int is_ambiguous(); - Polygon* get_polygons(); + Polygon *get_polygons(); }; /** @@ -1416,18 +1365,17 @@ class Cube * Constructor allocated memory. * */ -Cube::Cube() -{ - cube = new double**[STEPS]; - for (int i=0; i < STEPS; i++) { - cube[i] = new double*[STEPS]; - for (int j=0; j < STEPS; j++) { - cube[i][j] = new double[STEPS]; +Cube::Cube() { + cube = new double **[STEPS]; + for (int i = 0; i < STEPS; i++) { + cube[i] = new double *[STEPS]; + for (int j = 0; j < STEPS; j++) { + cube[i][j] = new double[STEPS]; + } } - } - lines = new Line*[NSQUARES*2]; //Each square may have max. 2 lines - polygons = new Polygon[MAX_POLY]; - squares = new Square[NSQUARES]; + lines = new Line *[NSQUARES * 2]; // Each square may have max. 2 lines + polygons = new Polygon[MAX_POLY]; + squares = new Square[NSQUARES]; } /** @@ -1435,18 +1383,17 @@ Cube::Cube() * Destructor frees memory allocated in constructor. * */ -Cube::~Cube() -{ - for (int i=0; i < STEPS; i++) { - for (int j=0; j < STEPS; j++) { - delete[] cube[i][j]; +Cube::~Cube() { + for (int i = 0; i < STEPS; i++) { + for (int j = 0; j < STEPS; j++) { + delete[] cube[i][j]; + } + delete[] cube[i]; } - delete[] cube[i]; - } - delete[] cube; - delete[] lines; - delete[] polygons; - delete[] squares; + delete[] cube; + delete[] lines; + delete[] polygons; + delete[] squares; } /** @@ -1460,38 +1407,37 @@ Cube::~Cube() * @param [in] dex Lenghts of the sides * */ -void Cube::init(double ***&c, int c_i, double c_v, double *&dex) -{ - const_i = c_i; - const_value = c_v; - dx = dex; - //Here we fix the non-zero indices - x1 = -1; - x2 = -1; - x3 = -1; - for (int i=0; i < DIM; i++) { - if ( i != c_i ) { - if ( x1 < 0 ) { - x1 = i; - } else if ( x2 < 0 ) { - x2 = i; - } else { - x3 = i; - } - } - } - for (int i=0; i < STEPS; i++) { - for (int j=0; j < STEPS; j++) { - for (int k=0; k < STEPS; k++) { - cube[i][j][k] = c[i][j][k]; - } - } - } - //We need to set these to zero so when this function is called - //again we know that nothing has been done for this cube - Nlines = 0; - Npolygons = 0; - ambiguous = 0; +void Cube::init(double ***&c, int c_i, double c_v, double *&dex) { + const_i = c_i; + const_value = c_v; + dx = dex; + // Here we fix the non-zero indices + x1 = -1; + x2 = -1; + x3 = -1; + for (int i = 0; i < DIM; i++) { + if (i != c_i) { + if (x1 < 0) { + x1 = i; + } else if (x2 < 0) { + x2 = i; + } else { + x3 = i; + } + } + } + for (int i = 0; i < STEPS; i++) { + for (int j = 0; j < STEPS; j++) { + for (int k = 0; k < STEPS; k++) { + cube[i][j][k] = c[i][j][k]; + } + } + } + // We need to set these to zero so when this function is called + // again we know that nothing has been done for this cube + Nlines = 0; + Npolygons = 0; + ambiguous = 0; } /** @@ -1499,46 +1445,45 @@ void Cube::init(double ***&c, int c_i, double c_v, double *&dex) * Splits given cube to squares. * */ -void Cube::split_to_squares() -{ - double **sq = new double*[STEPS]; - int *c_i = new int[STEPS]; - double *c_v = new double[STEPS]; - for (int i=0; i < STEPS; i++) { - sq[i] = new double[STEPS]; - } - int Nsquares = 0; - for (int i=0; i < DIM; i++) { - //i is the index which is kept constant, thus we ignore the index which - //is constant in this cube - if ( i != const_i ) { - c_i[0] = const_i; - c_i[1] = i; - for (int j=0; j < STEPS; j++) { - c_v[0] = const_value; - c_v[1] = j*dx[i]; - for (int ci1=0; ci1 < STEPS; ci1++) { - for (int ci2=0; ci2 < STEPS; ci2++) { - if ( i == x1 ) { - sq[ci1][ci2] = cube[j][ci1][ci2]; - } else if ( i == x2 ) { - sq[ci1][ci2] = cube[ci1][j][ci2]; - } else { - sq[ci1][ci2] = cube[ci1][ci2][j]; +void Cube::split_to_squares() { + double **sq = new double *[STEPS]; + int *c_i = new int[STEPS]; + double *c_v = new double[STEPS]; + for (int i = 0; i < STEPS; i++) { + sq[i] = new double[STEPS]; + } + int Nsquares = 0; + for (int i = 0; i < DIM; i++) { + // i is the index which is kept constant, thus we ignore the index which + // is constant in this cube + if (i != const_i) { + c_i[0] = const_i; + c_i[1] = i; + for (int j = 0; j < STEPS; j++) { + c_v[0] = const_value; + c_v[1] = j * dx[i]; + for (int ci1 = 0; ci1 < STEPS; ci1++) { + for (int ci2 = 0; ci2 < STEPS; ci2++) { + if (i == x1) { + sq[ci1][ci2] = cube[j][ci1][ci2]; + } else if (i == x2) { + sq[ci1][ci2] = cube[ci1][j][ci2]; + } else { + sq[ci1][ci2] = cube[ci1][ci2][j]; + } + } + } + squares[Nsquares].init(sq, c_i, c_v, dx); + Nsquares++; } - } - } - squares[Nsquares].init(sq,c_i,c_v,dx); - Nsquares++; - } - } - } - for (int i=0; i < STEPS; i++) { - delete[] sq[i]; - } - delete[] sq; - delete[] c_i; - delete[] c_v; + } + } + for (int i = 0; i < STEPS; i++) { + delete[] sq[i]; + } + delete[] sq; + delete[] c_i; + delete[] c_v; } /** @@ -1549,75 +1494,75 @@ void Cube::split_to_squares() * polygons we have. * */ -void Cube::construct_polygons(double value0) -{ - //Let's start by splitting the cube to squares and finding - //the lines from them - split_to_squares(); - for (int i=0; i < NSQUARES; i++) { - squares[i].construct_lines(value0); - } - //Then we make a table which contains pointers to the lines - Nlines = 0; - for (int i=0; i < NSQUARES; i++) { - int Nline = squares[i].get_Nlines(); - Line *l = squares[i].get_lines(); - for (int j=0; j < Nline; j++) { - lines[Nlines] = &l[j]; - //double *p = lines[Nlines]->get_start(); - //p = lines[Nlines]->get_end(); - Nlines++; - } - l = NULL; - } - //If no lines were found we may exit. This can happen only in 4D case - if ( Nlines == 0 ) { - return; - } - //Then we check if the surface is ambiguous and continue accordingly - check_ambiguous(Nlines); - if ( ambiguous > 0 ) { - //Surface is ambiguous, so let's connect the lines to polygons and see how - //many polygons we have - int *not_used = new int[Nlines]; - for (int i=0; i < Nlines; i++) { - not_used[i] = 1; - } - int used = 0; //this keeps track how many lines we have used - //We may found several polygons with this - do { - if ( Nlines - used < 3 ) { - cout << "Error: cannot construct polygon from " << Nlines -used << " lines" << endl; - exit(1); - } - //First we initialize polygon - polygons[Npolygons].init(const_i); - //Then we go through all lines and try to add them to polygon - for (int i=0; i < Nlines; i++) { - if ( not_used[i] ) { - //add_line returns true if line is succesfully added - if ( polygons[Npolygons].add_line(lines[i],0) ) { - not_used[i]=0; - used++; - //if line is succesfully added we start the loop from the - //beginning - i=0; - } - } - } - //When we have reached this point one complete polygon is formed - Npolygons++; - } while ( used < Nlines ); - delete[] not_used; - } else { - //Surface is not ambiguous, so we have only one polygons and all lines - //can be added to it without ordering them - polygons[Npolygons].init(const_i); - for (int i=0; i < Nlines; i++) { - polygons[Npolygons].add_line(lines[i],1); - } - Npolygons++; - } +void Cube::construct_polygons(double value0) { + // Let's start by splitting the cube to squares and finding + // the lines from them + split_to_squares(); + for (int i = 0; i < NSQUARES; i++) { + squares[i].construct_lines(value0); + } + // Then we make a table which contains pointers to the lines + Nlines = 0; + for (int i = 0; i < NSQUARES; i++) { + int Nline = squares[i].get_Nlines(); + Line *l = squares[i].get_lines(); + for (int j = 0; j < Nline; j++) { + lines[Nlines] = &l[j]; + // double *p = lines[Nlines]->get_start(); + // p = lines[Nlines]->get_end(); + Nlines++; + } + l = NULL; + } + // If no lines were found we may exit. This can happen only in 4D case + if (Nlines == 0) { + return; + } + // Then we check if the surface is ambiguous and continue accordingly + check_ambiguous(Nlines); + if (ambiguous > 0) { + // Surface is ambiguous, so let's connect the lines to polygons and see + // how many polygons we have + int *not_used = new int[Nlines]; + for (int i = 0; i < Nlines; i++) { + not_used[i] = 1; + } + int used = 0; // this keeps track how many lines we have used + // We may found several polygons with this + do { + if (Nlines - used < 3) { + cout << "Error: cannot construct polygon from " << Nlines - used + << " lines" << endl; + exit(1); + } + // First we initialize polygon + polygons[Npolygons].init(const_i); + // Then we go through all lines and try to add them to polygon + for (int i = 0; i < Nlines; i++) { + if (not_used[i]) { + // add_line returns true if line is succesfully added + if (polygons[Npolygons].add_line(lines[i], 0)) { + not_used[i] = 0; + used++; + // if line is succesfully added we start the loop from + // the beginning + i = 0; + } + } + } + // When we have reached this point one complete polygon is formed + Npolygons++; + } while (used < Nlines); + delete[] not_used; + } else { + // Surface is not ambiguous, so we have only one polygons and all lines + // can be added to it without ordering them + polygons[Npolygons].init(const_i); + for (int i = 0; i < Nlines; i++) { + polygons[Npolygons].add_line(lines[i], 1); + } + Npolygons++; + } } /** @@ -1625,20 +1570,19 @@ void Cube::construct_polygons(double value0) * Checks if the surface is ambiguous in this cube. * */ -void Cube::check_ambiguous(int Nlines) -{ - //First we check if any squares may have ambiguous elements - for (int i=0; i < NSQUARES; i++) { - if ( squares[i].is_ambiguous() ) { - ambiguous++; - } - } - //If the surface is not ambigous already, it is still possible to - //have a ambiguous case if we have exatcly 6 lines, i.e. the surface - //elements are at the opposite corners - if ( ambiguous == 0 && Nlines == 6 ) { - ambiguous++; - } +void Cube::check_ambiguous(int Nlines) { + // First we check if any squares may have ambiguous elements + for (int i = 0; i < NSQUARES; i++) { + if (squares[i].is_ambiguous()) { + ambiguous++; + } + } + // If the surface is not ambigous already, it is still possible to + // have a ambiguous case if we have exatcly 6 lines, i.e. the surface + // elements are at the opposite corners + if (ambiguous == 0 && Nlines == 6) { + ambiguous++; + } } /** @@ -1649,10 +1593,7 @@ void Cube::check_ambiguous(int Nlines) * @return Zero if not ambiguous, non-zero if ambiguous * */ -int Cube::is_ambiguous() -{ - return ambiguous; -} +int Cube::is_ambiguous() { return ambiguous; } /** * @@ -1661,22 +1602,16 @@ int Cube::is_ambiguous() * @return Number of the lines * */ -int Cube::get_Nlines() -{ - return Nlines; -} +int Cube::get_Nlines() { return Nlines; } /** * * Returns the number of the polygons in this cube. - * + * * @return Number of the polygons in this cube * */ -int Cube::get_Npolygons() -{ - return Npolygons; -} +int Cube::get_Npolygons() { return Npolygons; } /** * @@ -1685,19 +1620,15 @@ int Cube::get_Npolygons() * @return List of the polygons found from this cube * */ -Polygon* Cube::get_polygons() -{ - return polygons; -} +Polygon *Cube::get_polygons() { return polygons; } /** * * This class handles 4d-cubes. Splits them into cubes and collects the - * polygons from the cubes and form polyhedrons from these. + * polygons from the cubes and form polyhedrons from these. * */ -class Hypercube -{ +class Hypercube { private: static const int DIM = 4; static const int MAX_POLY = 10; @@ -1709,17 +1640,18 @@ class Hypercube Cube *cubes; int Npolyhedrons; int ambiguous; - int x1,x2,x3,x4; + int x1, x2, x3, x4; double *dx; void split_to_cubes(); void check_ambiguous(double); + public: Hypercube(); ~Hypercube(); - void init(double****,double*); + void init(double ****, double *); void construct_polyhedrons(double); int get_Npolyhedrons(); - Polyhedron* get_polyhedrons(); + Polyhedron *get_polyhedrons(); }; /** @@ -1727,21 +1659,20 @@ class Hypercube * Constructor allocates memory. * */ -Hypercube::Hypercube() -{ - hcube = new double***[STEPS]; - for (int i=0; i < STEPS; i++) { - hcube[i] = new double**[STEPS]; - for (int j=0; j < STEPS; j++) { - hcube[i][j] = new double*[STEPS]; - for (int k=0; k < STEPS; k++) { - hcube[i][j][k] = new double[STEPS]; - } - } - } - polyhedrons = new Polyhedron[MAX_POLY]; - polygons = new Polygon*[NCUBES*10]; - cubes = new Cube[NCUBES]; +Hypercube::Hypercube() { + hcube = new double ***[STEPS]; + for (int i = 0; i < STEPS; i++) { + hcube[i] = new double **[STEPS]; + for (int j = 0; j < STEPS; j++) { + hcube[i][j] = new double *[STEPS]; + for (int k = 0; k < STEPS; k++) { + hcube[i][j][k] = new double[STEPS]; + } + } + } + polyhedrons = new Polyhedron[MAX_POLY]; + polygons = new Polygon *[NCUBES * 10]; + cubes = new Cube[NCUBES]; } /** @@ -1749,21 +1680,20 @@ Hypercube::Hypercube() * Destructor frees memory allocated in the constructor. * */ -Hypercube::~Hypercube() -{ - for (int i=0; i < STEPS; i++) { - for (int j=0; j < STEPS; j++) { - for (int k=0; k < STEPS; k++) { - delete[] hcube[i][j][k]; - } - delete[] hcube[i][j]; - } - delete[] hcube[i]; - } - delete[] hcube; - delete[] polyhedrons; - delete[] polygons; - delete[] cubes; +Hypercube::~Hypercube() { + for (int i = 0; i < STEPS; i++) { + for (int j = 0; j < STEPS; j++) { + for (int k = 0; k < STEPS; k++) { + delete[] hcube[i][j][k]; + } + delete[] hcube[i][j]; + } + delete[] hcube[i]; + } + delete[] hcube; + delete[] polyhedrons; + delete[] polygons; + delete[] cubes; } /** @@ -1775,27 +1705,26 @@ Hypercube::~Hypercube() * @param [in] dex Lenghts of the sides * */ -void Hypercube::init(double ****c, double *dex) -{ - dx = dex; - //Here we fix the non-zero indices - x1 = 0; - x2 = 1; - x3 = 2; - x4 = 3; - for (int i=0; i < STEPS; i++) { - for (int j=0; j < STEPS; j++) { - for (int k=0; k < STEPS; k++) { - for (int l=0; l < STEPS; l++) { - hcube[i][j][k][l] = c[i][j][k][l]; - } - } - } - } - //We need to set these to zero so we can use this function to initialize - //many hypercubes - Npolyhedrons = 0; - ambiguous = 0; +void Hypercube::init(double ****c, double *dex) { + dx = dex; + // Here we fix the non-zero indices + x1 = 0; + x2 = 1; + x3 = 2; + x4 = 3; + for (int i = 0; i < STEPS; i++) { + for (int j = 0; j < STEPS; j++) { + for (int k = 0; k < STEPS; k++) { + for (int l = 0; l < STEPS; l++) { + hcube[i][j][k][l] = c[i][j][k][l]; + } + } + } + } + // We need to set these to zero so we can use this function to initialize + // many hypercubes + Npolyhedrons = 0; + ambiguous = 0; } /** @@ -1803,117 +1732,116 @@ void Hypercube::init(double ****c, double *dex) * Splits given hypercube to cubes. * */ -void Hypercube::split_to_cubes() -{ - double ***cu = new double**[STEPS]; - for (int i=0; i < STEPS; i++) { - cu[i] = new double*[STEPS]; - for (int j=0; j < STEPS; j++) { - cu[i][j] = new double[STEPS]; - } - } - int Ncubes = 0; - for (int i=0; i < DIM; i++) { - //i is the index which is kept constant, thus we ignore the index which - //is constant in this cube - int c_i = i; - for (int j=0; j < STEPS; j++) { - double c_v = j*dx[i]; - for (int ci1=0; ci1 < STEPS; ci1++) { - for (int ci2=0; ci2 < STEPS; ci2++) { - for (int ci3=0; ci3 < STEPS; ci3++) { - if ( i == x1 ) { - cu[ci1][ci2][ci3] = hcube[j][ci1][ci2][ci3]; - } else if ( i == x2 ) { - cu[ci1][ci2][ci3] = hcube[ci1][j][ci2][ci3]; - } else if ( i == x3 ) { - cu[ci1][ci2][ci3] = hcube[ci1][ci2][j][ci3]; - } else { - cu[ci1][ci2][ci3] = hcube[ci1][ci2][ci3][j]; +void Hypercube::split_to_cubes() { + double ***cu = new double **[STEPS]; + for (int i = 0; i < STEPS; i++) { + cu[i] = new double *[STEPS]; + for (int j = 0; j < STEPS; j++) { + cu[i][j] = new double[STEPS]; + } + } + int Ncubes = 0; + for (int i = 0; i < DIM; i++) { + // i is the index which is kept constant, thus we ignore the index which + // is constant in this cube + int c_i = i; + for (int j = 0; j < STEPS; j++) { + double c_v = j * dx[i]; + for (int ci1 = 0; ci1 < STEPS; ci1++) { + for (int ci2 = 0; ci2 < STEPS; ci2++) { + for (int ci3 = 0; ci3 < STEPS; ci3++) { + if (i == x1) { + cu[ci1][ci2][ci3] = hcube[j][ci1][ci2][ci3]; + } else if (i == x2) { + cu[ci1][ci2][ci3] = hcube[ci1][j][ci2][ci3]; + } else if (i == x3) { + cu[ci1][ci2][ci3] = hcube[ci1][ci2][j][ci3]; + } else { + cu[ci1][ci2][ci3] = hcube[ci1][ci2][ci3][j]; + } + } + } } - } + cubes[Ncubes].init(cu, c_i, c_v, dx); + Ncubes++; } - } - cubes[Ncubes].init(cu,c_i,c_v,dx); - Ncubes++; } - } - for (int i=0; i < STEPS; i++) { - for (int j=0; j < STEPS; j++) { - delete[] cu[i][j]; + for (int i = 0; i < STEPS; i++) { + for (int j = 0; j < STEPS; j++) { + delete[] cu[i][j]; + } + delete[] cu[i]; } - delete[] cu[i]; - } - delete[] cu; + delete[] cu; } /** * - * Here we construct polyhedrons from the polygons. First we check if the surface - * is ambiguous and if it is not amibiguous we add all polygons to a single - * polyhedron. If surface is ambiguous we need to connect the polygons one by one - * and see in the end how many polyhedrons we have. - * - */ -void Hypercube::construct_polyhedrons(double value0) -{ - split_to_cubes(); - for (int i=0; i < NCUBES; i++) { - cubes[i].construct_polygons(value0); - } - int Npolygons = 0; - //then polygons are loaded to table - for (int i=0; i < NCUBES; i++) { - int Npoly = cubes[i].get_Npolygons(); - Polygon *p = cubes[i].get_polygons(); - for (int j=0; j < Npoly; j++) { - polygons[Npolygons] = &p[j]; - Npolygons++; - } - } - check_ambiguous(value0); - if ( ambiguous > 0 ) { - //Here surface might be ambiguous and we need to connect the polygons and - //see how many polyhedrons we have - int *not_used = new int[Npolygons]; - for (int i=0; i < Npolygons; i++) { - not_used[i] = 1; - } - int used = 0; //this keeps track how many lines we have used - //We may found several polyhedrons with this - do { - //First we initialize polyhedron - polyhedrons[Npolyhedrons].init(); - //Then we go through all polygons and try to add them to polyhedron - for (int i=0; i < Npolygons; i++) { - if ( not_used[i] ) { - //add_polygon returns true if the polygon is succesfully added - if ( polyhedrons[Npolyhedrons].add_polygon(polygons[i],0) ) { - not_used[i]=0; - used++; - //if polygon is succesfully added we start the loop from the - //beginning - i=0; - } - } - } - //When we have reached this point one complete polyhedron is formed - Npolyhedrons++; - } while ( used < Npolygons ); - delete[] not_used; - /*if ( ambiguous == 0 && Npolyhedrons != 1 ) { - cout << "error" << endl; - }*/ - } else { - //Here surface cannot be ambiguous and all polygons can be added to - //the polygehdron without ordering them - polyhedrons[Npolyhedrons].init(); - for (int i=0; i < Npolygons; i++) { - polyhedrons[Npolyhedrons].add_polygon(polygons[i],1); - } - //When we have reached this point one complete polyhedron is formed - Npolyhedrons++; - } + * Here we construct polyhedrons from the polygons. First we check if the + * surface is ambiguous and if it is not amibiguous we add all polygons to a + * single polyhedron. If surface is ambiguous we need to connect the polygons + * one by one and see in the end how many polyhedrons we have. + * + */ +void Hypercube::construct_polyhedrons(double value0) { + split_to_cubes(); + for (int i = 0; i < NCUBES; i++) { + cubes[i].construct_polygons(value0); + } + int Npolygons = 0; + // then polygons are loaded to table + for (int i = 0; i < NCUBES; i++) { + int Npoly = cubes[i].get_Npolygons(); + Polygon *p = cubes[i].get_polygons(); + for (int j = 0; j < Npoly; j++) { + polygons[Npolygons] = &p[j]; + Npolygons++; + } + } + check_ambiguous(value0); + if (ambiguous > 0) { + // Here surface might be ambiguous and we need to connect the polygons + // and see how many polyhedrons we have + int *not_used = new int[Npolygons]; + for (int i = 0; i < Npolygons; i++) { + not_used[i] = 1; + } + int used = 0; // this keeps track how many lines we have used + // We may found several polyhedrons with this + do { + // First we initialize polyhedron + polyhedrons[Npolyhedrons].init(); + // Then we go through all polygons and try to add them to polyhedron + for (int i = 0; i < Npolygons; i++) { + if (not_used[i]) { + // add_polygon returns true if the polygon is succesfully + // added + if (polyhedrons[Npolyhedrons].add_polygon(polygons[i], 0)) { + not_used[i] = 0; + used++; + // if polygon is succesfully added we start the loop + // from the beginning + i = 0; + } + } + } + // When we have reached this point one complete polyhedron is formed + Npolyhedrons++; + } while (used < Npolygons); + delete[] not_used; + /*if ( ambiguous == 0 && Npolyhedrons != 1 ) { + cout << "error" << endl; + }*/ + } else { + // Here surface cannot be ambiguous and all polygons can be added to + // the polygehdron without ordering them + polyhedrons[Npolyhedrons].init(); + for (int i = 0; i < Npolygons; i++) { + polyhedrons[Npolyhedrons].add_polygon(polygons[i], 1); + } + // When we have reached this point one complete polyhedron is formed + Npolyhedrons++; + } } /** @@ -1921,58 +1849,54 @@ void Hypercube::construct_polyhedrons(double value0) * Checks if the surface is ambiguous in this hypercube. * */ -void Hypercube::check_ambiguous(double value0) -{ - for (int i=0; i < NCUBES; i++) { - if ( cubes[i].is_ambiguous() ) { - ambiguous++; - } - } - if ( ambiguous == 0 ) { - int Nlines = 0; - for (int i=0; i < NCUBES; i++) { - Nlines += cubes[i].get_Nlines(); - } - int points = 0; - for (int i1=0; i1 < STEPS; i1++) { - for (int i2=0; i2 < STEPS; i2++) { - for (int i3=0; i3 < STEPS; i3++) { - for (int i4=0; i4 < STEPS; i4++) { - if ( hcube[i1][i2][i3][i4] < value0 ) { - points++; - } - } +void Hypercube::check_ambiguous(double value0) { + for (int i = 0; i < NCUBES; i++) { + if (cubes[i].is_ambiguous()) { + ambiguous++; } - } - } - if ( points > 8 ) { - points = 16-points; } - /* these are not needed - if ( Nlines == 42 ) { - //ambiguous++; - } else if ( Nlines == 36 && ( points == 5 || points == 4 ) ) { - //ambiguous++; - } else if ( Nlines == 30 && points == 3 ) { - //ambiguous++; - }*/ - if ( Nlines == 24 && points == 2 ) { - ambiguous++; + if (ambiguous == 0) { + int Nlines = 0; + for (int i = 0; i < NCUBES; i++) { + Nlines += cubes[i].get_Nlines(); + } + int points = 0; + for (int i1 = 0; i1 < STEPS; i1++) { + for (int i2 = 0; i2 < STEPS; i2++) { + for (int i3 = 0; i3 < STEPS; i3++) { + for (int i4 = 0; i4 < STEPS; i4++) { + if (hcube[i1][i2][i3][i4] < value0) { + points++; + } + } + } + } + } + if (points > 8) { + points = 16 - points; + } + /* these are not needed + if ( Nlines == 42 ) { + //ambiguous++; + } else if ( Nlines == 36 && ( points == 5 || points == 4 ) ) { + //ambiguous++; + } else if ( Nlines == 30 && points == 3 ) { + //ambiguous++; + }*/ + if (Nlines == 24 && points == 2) { + ambiguous++; + } } - } } /** * * Returns the number of polyhedrons in this cube. - * + * * @return Number of polyhedrons in this hypercube * */ -int Hypercube::get_Npolyhedrons() -{ - return Npolyhedrons; -} +int Hypercube::get_Npolyhedrons() { return Npolyhedrons; } /** * @@ -1981,10 +1905,7 @@ int Hypercube::get_Npolyhedrons() * @return List of polyhedrons found from hypercube * */ -Polyhedron* Hypercube::get_polyhedrons() -{ - return polyhedrons; -} +Polyhedron *Hypercube::get_polyhedrons() { return polyhedrons; } /** * @@ -1996,8 +1917,7 @@ Polyhedron* Hypercube::get_polyhedrons() * code by Pasi Huovinen. * */ -class Cornelius -{ +class Cornelius { private: static const int STEPS = 2; static const int DIM = 4; @@ -2011,26 +1931,27 @@ class Cornelius double value0; double *dx; ofstream output_print; - void surface_3d(double***,double*,int); + void surface_3d(double ***, double *, int); Square cu2d; Cube cu3d; Hypercube cu4d; + public: Cornelius(); ~Cornelius(); - void init(int,double,double*); + void init(int, double, double *); void init_print(string); - void find_surface_2d(double**); - void find_surface_3d(double***); - void find_surface_3d_print(double***,double*); - void find_surface_4d(double****); + void find_surface_2d(double **); + void find_surface_3d(double ***); + void find_surface_3d_print(double ***, double *); + void find_surface_4d(double ****); int get_Nelements(); double **get_normals(); double **get_centroids(); double **get_normals_4d(); double **get_centroids_4d(); - double get_centroid_elem(int,int); - double get_normal_elem(int,int); + double get_centroid_elem(int, int); + double get_normal_elem(int, int); }; /** @@ -2038,17 +1959,16 @@ class Cornelius * Constructor allocates some memory. * */ -Cornelius::Cornelius() -{ - Nelements = 0; - initialized = 0; - print_initialized = 0; - normals = new double*[MAX_ELEMENTS]; - centroids = new double*[MAX_ELEMENTS]; - for (int i=0; i < MAX_ELEMENTS; i++) { - normals[i] = new double[DIM]; - centroids[i] = new double[DIM]; - } +Cornelius::Cornelius() { + Nelements = 0; + initialized = 0; + print_initialized = 0; + normals = new double *[MAX_ELEMENTS]; + centroids = new double *[MAX_ELEMENTS]; + for (int i = 0; i < MAX_ELEMENTS; i++) { + normals[i] = new double[DIM]; + centroids[i] = new double[DIM]; + } } /** @@ -2056,21 +1976,20 @@ Cornelius::Cornelius() * Destructor frees memory and closes printing file is necessary. * */ -Cornelius::~Cornelius() -{ - for (int i=0; i < MAX_ELEMENTS; i++) { - delete[] normals[i]; - delete[] centroids[i]; - } - delete[] normals; - delete[] centroids; - if ( initialized ) { - delete[] dx; - } - //If file for printing was opened we close it here. - if ( print_initialized ) { - output_print.close(); - } +Cornelius::~Cornelius() { + for (int i = 0; i < MAX_ELEMENTS; i++) { + delete[] normals[i]; + delete[] centroids[i]; + } + delete[] normals; + delete[] centroids; + if (initialized) { + delete[] dx; + } + // If file for printing was opened we close it here. + if (print_initialized) { + output_print.close(); + } } /** @@ -2080,207 +1999,199 @@ Cornelius::~Cornelius() * * @param [in] d Dimension of the problem. * @param [in] v0 Value which defines the surface. - * @param [in] dex Length of the sides of the cube. Must contains as many elements as - * the dimension of the problem (dx1,dx2,...). - * - */ -void Cornelius::init(int d, double v0, double *dex) -{ - cube_dim = d; - value0 = v0; - if ( initialized != 1 ) { - dx = new double[DIM]; - } - for (int i=0; i < DIM; i++) { - if ( i < DIM-cube_dim ) { - dx[i] = 1; - } else { - dx[i] = dex[i-(DIM-cube_dim)]; + * @param [in] dex Length of the sides of the cube. Must contains as many + * elements as the dimension of the problem (dx1,dx2,...). + * + */ +void Cornelius::init(int d, double v0, double *dex) { + cube_dim = d; + value0 = v0; + if (initialized != 1) { + dx = new double[DIM]; } - } - initialized = 1; + for (int i = 0; i < DIM; i++) { + if (i < DIM - cube_dim) { + dx[i] = 1; + } else { + dx[i] = dex[i - (DIM - cube_dim)]; + } + } + initialized = 1; } /** * - * This initializes the printing of the surface elements into file. Final elements - * are not printed with this, but instead this is used to print the triangles, - * which are used to construct the final elements. + * This initializes the printing of the surface elements into file. Final + * elements are not printed with this, but instead this is used to print the + * triangles, which are used to construct the final elements. * * @param [in] filename Filename of the file where the information is printed. * */ -void Cornelius::init_print(string filename) -{ - output_print.open(filename.c_str()); - print_initialized = 1; +void Cornelius::init_print(string filename) { + output_print.open(filename.c_str()); + print_initialized = 1; } /** * * Finds the surface elements in 2-dimensional case. * - * @param [in] cube Values at the corners of the cube as a 2d table so that value - * [0][0] is at (0,0,0) and [1][1] is at (dx1,dx2). - * - */ -void Cornelius::find_surface_2d(double **cube) -{ - if ( !initialized || cube_dim != 2 ) { - cout << "Cornelius not initialized for 2D case" << endl; - exit(1); - } - int *c_i = new int[cube_dim]; - double *c_v = new double[cube_dim]; - c_i[0] = 0; - c_i[1] = 1; - c_v[0] = 0; - c_v[1] = 0; - cu2d.init(cube,c_i,c_v,dx); - cu2d.construct_lines(value0); - Nelements = cu2d.get_Nlines(); - Line *l = cu2d.get_lines(); - for (int i=0; i < Nelements; i++) { - for (int j=0; j < DIM; j++) { - normals[i][j] = l[i].get_normal()[j]; - centroids[i][j] = l[i].get_centroid()[j]; - } - } - delete[] c_i; - delete[] c_v; + * @param [in] cube Values at the corners of the cube as a 2d table so that + * value [0][0] is at (0,0,0) and [1][1] is at (dx1,dx2). + * + */ +void Cornelius::find_surface_2d(double **cube) { + if (!initialized || cube_dim != 2) { + cout << "Cornelius not initialized for 2D case" << endl; + exit(1); + } + int *c_i = new int[cube_dim]; + double *c_v = new double[cube_dim]; + c_i[0] = 0; + c_i[1] = 1; + c_v[0] = 0; + c_v[1] = 0; + cu2d.init(cube, c_i, c_v, dx); + cu2d.construct_lines(value0); + Nelements = cu2d.get_Nlines(); + Line *l = cu2d.get_lines(); + for (int i = 0; i < Nelements; i++) { + for (int j = 0; j < DIM; j++) { + normals[i][j] = l[i].get_normal()[j]; + centroids[i][j] = l[i].get_centroid()[j]; + } + } + delete[] c_i; + delete[] c_v; } /** * * Finds the surface elements in 3-dimensional case. * - * @param [in] cube Values at the corners of the cube as a 3d table so that value - * [0][0][0] is at (0,0,0) and [1][1][1] is at (dx1,dx2,dx3). + * @param [in] cube Values at the corners of the cube as a 3d table so that + * value [0][0][0] is at (0,0,0) and [1][1][1] is at (dx1,dx2,dx3). * */ -void Cornelius::find_surface_3d(double ***cube) -{ - double *pos = NULL; - surface_3d(cube,pos,0); +void Cornelius::find_surface_3d(double ***cube) { + double *pos = NULL; + surface_3d(cube, pos, 0); } /** * - * Finds the surface elements in 3-dimensional case and prints the actual triangles - * which are found by the algorithm. + * Finds the surface elements in 3-dimensional case and prints the actual + * triangles which are found by the algorithm. * - * @param [in] cube Values at the corners of the cube as a 3d table so that value - * [0][0][0] is at (0,0,0) and [1][1][1] is at (dx1,dx2,dx3). - * @param [in] pos Absolute position at the point [0][0][0] in form (0,x1,x2,x3). + * @param [in] cube Values at the corners of the cube as a 3d table so that + * value [0][0][0] is at (0,0,0) and [1][1][1] is at (dx1,dx2,dx3). + * @param [in] pos Absolute position at the point [0][0][0] in form + * (0,x1,x2,x3). * */ -void Cornelius::find_surface_3d_print(double ***cube, double *pos) -{ - surface_3d(cube,pos,1); +void Cornelius::find_surface_3d_print(double ***cube, double *pos) { + surface_3d(cube, pos, 1); } /** * * Finds the surface elements in 3-dimensional case. * - * @param [in] cube Values at the corners of the cube as a 3d table so that value - * [0][0][0] is at (0,0,0) and [1][1][1] is at (dx1,dx2,dx3). - * @param [in] pos Absolute position at the point [0][0][0] in form (0,x1,x2,x3). + * @param [in] cube Values at the corners of the cube as a 3d table so that + * value [0][0][0] is at (0,0,0) and [1][1][1] is at (dx1,dx2,dx3). + * @param [in] pos Absolute position at the point [0][0][0] in form + * (0,x1,x2,x3). * @param [in] do_print 1 if triangles are printed, otherwise 0 * */ -void Cornelius::surface_3d(double ***cube, double *pos, int do_print) -{ - if ( !initialized || cube_dim != 3 ) { - cout << "Cornelius not initialized for 3D case" << endl; - exit(1); - } - //First we check if the cube actually contains surface elements. - //If all or none of the elements are below the criterion, no surface - //elements exist. - int above = 0; - for (int i=0; i < STEPS; i++) { - for (int j=0; j < STEPS; j++) { - for (int k=0; k < STEPS; k++) { - if ( cube[i][j][k] >= value0 ) - above++; - } - } - } - if ( above == 0 || above == 8 ) { - //No elements in this cube - Nelements = 0; - return; - } - //This cube has surface elements, so let's start by constructing - //the cube. - int c_i = 0; - double c_v = 0; - cu3d.init(cube,c_i,c_v,dx); - //Then we find the elements - cu3d.construct_polygons(value0); - //Now let's get the information about the elements - Nelements = cu3d.get_Npolygons(); - Polygon *p = cu3d.get_polygons(); - for (int i=0; i < Nelements; i++) { - //Here we always work with 4-dimensions - for (int j=0; j < DIM; j++) { - normals[i][j] = p[i].get_normal()[j]; - centroids[i][j] = p[i].get_centroid()[j]; - } - //If we want to print the actual triangles, which are found, we must do it here - //before polygons are removed from the memory. - if ( print_initialized && do_print ) { - p[i].print(output_print,pos); - } - } +void Cornelius::surface_3d(double ***cube, double *pos, int do_print) { + if (!initialized || cube_dim != 3) { + cout << "Cornelius not initialized for 3D case" << endl; + exit(1); + } + // First we check if the cube actually contains surface elements. + // If all or none of the elements are below the criterion, no surface + // elements exist. + int above = 0; + for (int i = 0; i < STEPS; i++) { + for (int j = 0; j < STEPS; j++) { + for (int k = 0; k < STEPS; k++) { + if (cube[i][j][k] >= value0) above++; + } + } + } + if (above == 0 || above == 8) { + // No elements in this cube + Nelements = 0; + return; + } + // This cube has surface elements, so let's start by constructing + // the cube. + int c_i = 0; + double c_v = 0; + cu3d.init(cube, c_i, c_v, dx); + // Then we find the elements + cu3d.construct_polygons(value0); + // Now let's get the information about the elements + Nelements = cu3d.get_Npolygons(); + Polygon *p = cu3d.get_polygons(); + for (int i = 0; i < Nelements; i++) { + // Here we always work with 4-dimensions + for (int j = 0; j < DIM; j++) { + normals[i][j] = p[i].get_normal()[j]; + centroids[i][j] = p[i].get_centroid()[j]; + } + // If we want to print the actual triangles, which are found, we must do + // it here before polygons are removed from the memory. + if (print_initialized && do_print) { + p[i].print(output_print, pos); + } + } } /** * * Finds the surface elements in 4-dimensional case. * - * @param [in] cube Values at the corners of the cube as a 4d table so that value - * [0][0][0][0] is at (0,0,0,0) and [1][1][1][1] is at - * (dx1,dx2,dx3,dx4). - * - */ -void Cornelius::find_surface_4d(double ****cube) -{ - if ( !initialized || cube_dim != 4 ) { - cout << "Cornelius not initialized for 4D case" << endl; - exit(1); - } - //First we check if the cube actually contains surface elements. - //If all or none of the elements are below the criterion, no surface - //elements exist. - int above = 0; - for (int i=0; i < STEPS; i++) - for (int j=0; j < STEPS; j++) - for (int k=0; k < STEPS; k++) - for (int l=0; l < STEPS; l++) - if ( cube[i][j][k][l] >= value0 ) - above++; - - if ( above == 0 || above == 16 ) { - //No elements in this cube - Nelements = 0; - return; - } - //This cube has surface elements, so let's start by constructing - //the hypercube. - cu4d.init(cube,dx); - //Then we find the elements - cu4d.construct_polyhedrons(value0); - //Now let's get the information about the elements - Nelements = cu4d.get_Npolyhedrons(); - Polyhedron *p = cu4d.get_polyhedrons(); - for (int i=0; i < Nelements; i++) { - for (int j=0; j < DIM; j++) { - centroids[i][j] = p[i].get_centroid()[j]; - normals[i][j] = p[i].get_normal()[j]; - } - } + * @param [in] cube Values at the corners of the cube as a 4d table so that + * value [0][0][0][0] is at (0,0,0,0) and [1][1][1][1] is at (dx1,dx2,dx3,dx4). + * + */ +void Cornelius::find_surface_4d(double ****cube) { + if (!initialized || cube_dim != 4) { + cout << "Cornelius not initialized for 4D case" << endl; + exit(1); + } + // First we check if the cube actually contains surface elements. + // If all or none of the elements are below the criterion, no surface + // elements exist. + int above = 0; + for (int i = 0; i < STEPS; i++) + for (int j = 0; j < STEPS; j++) + for (int k = 0; k < STEPS; k++) + for (int l = 0; l < STEPS; l++) + if (cube[i][j][k][l] >= value0) above++; + + if (above == 0 || above == 16) { + // No elements in this cube + Nelements = 0; + return; + } + // This cube has surface elements, so let's start by constructing + // the hypercube. + cu4d.init(cube, dx); + // Then we find the elements + cu4d.construct_polyhedrons(value0); + // Now let's get the information about the elements + Nelements = cu4d.get_Npolyhedrons(); + Polyhedron *p = cu4d.get_polyhedrons(); + for (int i = 0; i < Nelements; i++) { + for (int j = 0; j < DIM; j++) { + centroids[i][j] = p[i].get_centroid()[j]; + normals[i][j] = p[i].get_normal()[j]; + } + } } /** @@ -2290,127 +2201,120 @@ void Cornelius::find_surface_4d(double ****cube) * @return Number of surface elements in the given cube. * */ -int Cornelius::get_Nelements() -{ - return Nelements; -} +int Cornelius::get_Nelements() { return Nelements; } /** * - * Returns the centroid vectors as a 2d table with the following number of indices - * [number of elements][4]. If the dimension of the problem is smaller than four, - * first (4-dimension) elements are zero. Note that this function allocates memory and - * the user must free it! + * Returns the centroid vectors as a 2d table with the following number of + * indices [number of elements][4]. If the dimension of the problem is smaller + * than four, first (4-dimension) elements are zero. Note that this function + * allocates memory and the user must free it! * * @return Table with dimensions [number of elements][4] containing the normal * vectors of the surface elements. * */ -double** Cornelius::get_centroids_4d() -{ - double **vect = new double*[Nelements]; - for (int i=0; i < Nelements; i++) { - vect[i] = new double[DIM]; - for (int j=0; j < DIM; j++) { - vect[i][j] = centroids[i][j]; +double **Cornelius::get_centroids_4d() { + double **vect = new double *[Nelements]; + for (int i = 0; i < Nelements; i++) { + vect[i] = new double[DIM]; + for (int j = 0; j < DIM; j++) { + vect[i][j] = centroids[i][j]; + } } - } - return vect; + return vect; } /** * * Returns the normal vectors as a 2d table with the following number of indices - * [number of elements][4]. If the dimension of the problem is smaller than four, - * first (4-dimension) elements are zero. This gives \sigma_\mu without - * factors(sqrt(-g)) from the metric. Note that this function allocates memory and - * the user must free it! + * [number of elements][4]. If the dimension of the problem is smaller than + * four, first (4-dimension) elements are zero. This gives \sigma_\mu without + * factors(sqrt(-g)) from the metric. Note that this function allocates memory + * and the user must free it! * * @return Table with dimensions [number of elements][4] containing the normal * vectors of the surface elements. * */ -double** Cornelius::get_normals_4d() -{ - double **vect = new double*[Nelements]; - for (int i=0; i < Nelements; i++) { - vect[i] = new double[DIM]; - for (int j=0; j < DIM; j++) { - vect[i][j] = normals[i][j]; +double **Cornelius::get_normals_4d() { + double **vect = new double *[Nelements]; + for (int i = 0; i < Nelements; i++) { + vect[i] = new double[DIM]; + for (int j = 0; j < DIM; j++) { + vect[i][j] = normals[i][j]; + } } - } - return vect; + return vect; } /** * - * Returns the centroid vectors as a 2d table with the following number of indices - * [number of elements][dimension of the problem]. Note that this function allocates - * memory and the user must free it! + * Returns the centroid vectors as a 2d table with the following number of + * indices [number of elements][dimension of the problem]. Note that this + * function allocates memory and the user must free it! * - * @return Table with dimensions [number of elements][dimensions] containing the centroid - * vectors of the surface elements. + * @return Table with dimensions [number of elements][dimensions] containing the + * centroid vectors of the surface elements. * */ -double** Cornelius::get_centroids() -{ - double **vect = new double*[Nelements]; - for (int i=0; i < Nelements; i++) { - vect[i] = new double[cube_dim]; - for (int j=0; j < cube_dim; j++) { - vect[i][j] = centroids[i][j+(DIM-cube_dim)]; +double **Cornelius::get_centroids() { + double **vect = new double *[Nelements]; + for (int i = 0; i < Nelements; i++) { + vect[i] = new double[cube_dim]; + for (int j = 0; j < cube_dim; j++) { + vect[i][j] = centroids[i][j + (DIM - cube_dim)]; + } } - } - return vect; + return vect; } /** * * Returns the normal vectors as a 2d table with the following number of indices * [number of elements][dimension of the problem]. This gives \sigma_\mu without - * factors(sqrt(-g)) from the metric. Note that this function allocates memory and - * the user must free it! + * factors(sqrt(-g)) from the metric. Note that this function allocates memory + * and the user must free it! * - * @return Table with dimensions [number of elements][dimensions] containing the normal - * vectors of the surface elements. + * @return Table with dimensions [number of elements][dimensions] containing the + * normal vectors of the surface elements. * */ -double** Cornelius::get_normals() -{ - double **vect = new double*[Nelements]; - for (int i=0; i < Nelements; i++) { - vect[i] = new double[cube_dim]; - for (int j=0; j < cube_dim; j++) { - vect[i][j] = normals[i][j+(DIM-cube_dim)]; +double **Cornelius::get_normals() { + double **vect = new double *[Nelements]; + for (int i = 0; i < Nelements; i++) { + vect[i] = new double[cube_dim]; + for (int j = 0; j < cube_dim; j++) { + vect[i][j] = normals[i][j + (DIM - cube_dim)]; + } } - } - return vect; + return vect; } /** * * Returns an element of the centroid vector. * - * @param [in] i Number of surface element whose centroid one wants to get. Valid - * values are [0,number of elements in this cube]. + * @param [in] i Number of surface element whose centroid one wants to get. + * Valid values are [0,number of elements in this cube]. * @param [in] j Index of the element of centroid. Valid values are * [0,dimension of the problem]. * @return Element j of the centroid of the surface element i. * */ -double Cornelius::get_centroid_elem(int i, int j) -{ - if ( i >= Nelements || j >= cube_dim ) { - cout << "Cornelius error: asking for an element which does not exist." << endl; - exit(1); - } - return centroids[i][j+(DIM-cube_dim)]; +double Cornelius::get_centroid_elem(int i, int j) { + if (i >= Nelements || j >= cube_dim) { + cout << "Cornelius error: asking for an element which does not exist." + << endl; + exit(1); + } + return centroids[i][j + (DIM - cube_dim)]; } /** * - * Returns an element of the normal vector. This gives \sigma_\mu without factors - * (sqrt(-g)) from the metric. + * Returns an element of the normal vector. This gives \sigma_\mu without + * factors (sqrt(-g)) from the metric. * * @param [in] i Number of surface element whose normal one wants to get. Valid * values are [0,number of elements in this cube]. @@ -2419,11 +2323,11 @@ double Cornelius::get_centroid_elem(int i, int j) * @return Element j of the normal of the surface element i. * */ -double Cornelius::get_normal_elem(int i, int j) -{ - if ( i >= Nelements || j >= cube_dim ) { - cout << "Cornelius error: asking for an element which does not exist." << endl; - exit(1); - } - return normals[i][j+(DIM-cube_dim)]; +double Cornelius::get_normal_elem(int i, int j) { + if (i >= Nelements || j >= cube_dim) { + cout << "Cornelius error: asking for an element which does not exist." + << endl; + exit(1); + } + return normals[i][j + (DIM - cube_dim)]; } diff --git a/src/cornelius.h b/src/cornelius.h index ce4b8180..b2f4e91a 100644 --- a/src/cornelius.h +++ b/src/cornelius.h @@ -1,12 +1,13 @@ #ifndef CORNELIUS_H #define CORNELIUS_H -#include -#include #include #include -//using namespace std; +#include +#include + +// using namespace std; /** * @@ -14,8 +15,7 @@ * from this. * */ -class GeneralElement -{ +class GeneralElement { protected: static const int DIM = 4; double *centroid; @@ -25,6 +25,7 @@ class GeneralElement virtual void calculate_centroid() {}; virtual void calculate_normal() {}; void check_normal_direction(double *normal, double *out); + public: GeneralElement(); ~GeneralElement(); @@ -38,12 +39,11 @@ class GeneralElement * calculate the centroid and normal of the line. * */ -class Line : public GeneralElement -{ +class Line : public GeneralElement { private: static const int LINE_CORNERS = 2; static const int LINE_DIM = 2; - int x1,x2; + int x1, x2; int start_point; int end_point; double **corners; @@ -51,10 +51,11 @@ class Line : public GeneralElement int *const_i; void calculate_centroid(); void calculate_normal(); + public: Line(); ~Line(); - void init(double**,double*,int*); + void init(double **, double *, int *); void flip_start_end(); double *get_start(); double *get_end(); @@ -67,25 +68,25 @@ class Line : public GeneralElement * the centroid and normal of the polygon. * */ -class Polygon : public GeneralElement -{ +class Polygon : public GeneralElement { private: static const int MAX_LINES = 24; static const int POLYGON_DIM = 3; Line **lines; int Nlines; - int x1,x2,x3; + int x1, x2, x3; int const_i; void calculate_centroid(); void calculate_normal(); + public: Polygon(); ~Polygon(); void init(int); - bool add_line(Line*,int); + bool add_line(Line *, int); int get_Nlines(); - Line** get_lines(); - void print(std::ofstream &file,double*); + Line **get_lines(); + void print(std::ofstream &file, double *); }; /** @@ -94,23 +95,23 @@ class Polygon : public GeneralElement * the normal and centroid of the polyhedron. * */ -class Polyhedron : public GeneralElement -{ +class Polyhedron : public GeneralElement { private: static const int MAX_POLYGONS = 24; Polygon **polygons; int Npolygons; int Ntetrahedra; - int x1,x2,x3,x4; - bool lines_equal(Line*,Line*); - void tetravolume(double*,double*,double*,double*); + int x1, x2, x3, x4; + bool lines_equal(Line *, Line *); + void tetravolume(double *, double *, double *, double *); void calculate_centroid(); void calculate_normal(); + public: Polyhedron(); ~Polyhedron(); void init(); - bool add_polygon(Polygon*,int); + bool add_polygon(Polygon *, int); }; /** @@ -122,8 +123,7 @@ class Polyhedron : public GeneralElement * 13.10.2011 Hannu Holopainen * */ -class Square -{ +class Square { private: static const int DIM = 4; static const int SQUARE_DIM = 2; @@ -144,14 +144,15 @@ class Square int ambiguous; void ends_of_edge(double); void find_outside(double); + public: Square(); ~Square(); - void init(double**,int*,double*,double*); + void init(double **, int *, double *, double *); void construct_lines(double); int is_ambiguous(); int get_Nlines(); - Line* get_lines(); + Line *get_lines(); }; /** @@ -162,8 +163,7 @@ class Square * 13.10.2011 Hannu Holopainen * */ -class Cube -{ +class Cube { private: static const int DIM = 4; static const int CUBE_DIM = 4; @@ -179,22 +179,22 @@ class Cube int ambiguous; int const_i; double const_value; - int x1,x2,x3; + int x1, x2, x3; double *dx; void split_to_squares(); void check_ambiguous(int); + public: Cube(); ~Cube(); - void init(double***&,int,double,double*&); + void init(double ***&, int, double, double *&); void construct_polygons(double); int get_Nlines(); int get_Npolygons(); int is_ambiguous(); - Polygon* get_polygons(); + Polygon *get_polygons(); }; - /** * * This class handles 4d-cubes. Splits them into squares and collects @@ -203,8 +203,7 @@ class Cube * 13.10.2011 Hannu Holopainen * */ -class Hypercube -{ +class Hypercube { private: static const int DIM = 4; static const int MAX_POLY = 10; @@ -216,17 +215,18 @@ class Hypercube Cube *cubes; int Npolyhedrons; int ambiguous; - int x1,x2,x3,x4; + int x1, x2, x3, x4; double *dx; void split_to_cubes(); void check_ambiguous(double); + public: Hypercube(); ~Hypercube(); - void init(double****,double*); + void init(double ****, double *); void construct_polyhedrons(double); int get_Npolyhedrons(); - Polyhedron* get_polyhedrons(); + Polyhedron *get_polyhedrons(); }; /** @@ -241,8 +241,7 @@ class Hypercube * 23.04.2012 Hannu Holopainen * */ -class Cornelius -{ +class Cornelius { private: static const int STEPS = 2; static const int DIM = 4; @@ -256,26 +255,27 @@ class Cornelius double value0; double *dx; std::ofstream output_print; - void surface_3d(double***,double*,int); + void surface_3d(double ***, double *, int); Square cu2d; Cube cu3d; Hypercube cu4d; + public: Cornelius(); ~Cornelius(); - void init(int,double,double*); + void init(int, double, double *); void init_print(std::string); - void find_surface_2d(double**); - void find_surface_3d(double***); - void find_surface_3d_print(double***,double*); - void find_surface_4d(double****); + void find_surface_2d(double **); + void find_surface_3d(double ***); + void find_surface_3d_print(double ***, double *); + void find_surface_4d(double ****); int get_Nelements(); double **get_normals(); double **get_centroids(); double **get_normals_4d(); double **get_centroids_4d(); - double get_centroid_elem(int,int); - double get_normal_elem(int,int); + double get_centroid_elem(int, int); + double get_normal_elem(int, int); }; #endif /* CORNELIUS_H */ diff --git a/src/data.h b/src/data.h index 2e667dcb..f7bce69a 100644 --- a/src/data.h +++ b/src/data.h @@ -4,19 +4,16 @@ #define SMALL (1.0e-16) -#include #include #include + +#include #include //! This is a data structure contains all the parameters for simulation typedef struct init_data { - - std::array, 4> gmunu = - {{{-1,0,0,0}, - { 0,1,0,0}, - { 0,0,1,0}, - { 0,0,0,1}}}; + std::array, 4> gmunu = { + {{-1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}}; int echo_level; @@ -25,12 +22,12 @@ typedef struct init_data { int beastMode; - int mode; //!< 1: do everything; - //!< 2: do hydro evolution only; - //!< 3: do calculation of thermal spectra only; - //!< 4: do resonance decays only + int mode; //!< 1: do everything; + //!< 2: do hydro evolution only; + //!< 3: do calculation of thermal spectra only; + //!< 4: do resonance decays only - std::string initName; //!< filename for initial condition T^{\mu\nu} + std::string initName; //!< filename for initial condition T^{\mu\nu} // parameters for Initial_profile == 11 || 111 std::string initName_TA; //!< filename for nuclear thickness function TA @@ -41,11 +38,11 @@ typedef struct init_data { // parameters for Initial_profile == 30 std::string initName_AMPT; //!< initial state filename from AMPT - double gridPadding; //!< grid padding size from user (default: 3 fm) + double gridPadding; //!< grid padding size from user (default: 3 fm) //! random seed int seed; - double ecm; //!< collision energy [GeV] + double ecm; //!< collision energy [GeV] double beam_rapidity; int initial_eta_rhob_profile; @@ -56,8 +53,8 @@ typedef struct init_data { double eta_rhob_0; //!< peak position double eta_rhob_width; //!< Gaussian width for profile == 1 double eta_rhob_plateau_height; //!< central plateau height profile == 2 - double eta_rhob_width_1; //!< outside tail Gaussian width profile == 2 - double eta_rhob_width_2; //!< inside Gaussian width profile == 2 + double eta_rhob_width_1; //!< outside tail Gaussian width profile == 2 + double eta_rhob_width_2; //!< inside Gaussian width profile == 2 double eta_rhob_asym; double yL_frac; @@ -77,10 +74,10 @@ typedef struct init_data { int neta; int nt; - double x_size; //!< in fermi -x_size/2 < x < x_size/2 - double y_size; //!< in fermi, -y_size/2 < y < y_size/2 - double eta_size; //!< -eta_size/2 < eta < eta_size/2 - double tau_size; //!< tau_0 < tau < tau0+tau_size + double x_size; //!< in fermi -x_size/2 < x < x_size/2 + double y_size; //!< in fermi, -y_size/2 < y < y_size/2 + double eta_size; //!< -eta_size/2 < eta < eta_size/2 + double tau_size; //!< tau_0 < tau < tau0+tau_size double tau0; double delta_x; @@ -94,12 +91,12 @@ typedef struct init_data { int rk_order; double minmod_theta; - double sFactor; //!< overall normalization on energy density profile + double sFactor; //!< overall normalization on energy density profile //! A scale factor for initial shear and bulk viscous pressure double preEqVisFactor; - int whichEOS; //!< type of EoS + int whichEOS; //!< type of EoS //! flag for boost invariant simulations bool boost_invariant; @@ -115,14 +112,14 @@ typedef struct init_data { //! skip step for freeze out surface finder int fac_eta; - int alpha_max; //!< dimension of TJb - int turn_on_rhob; //!< flag to include baryon current + int alpha_max; //!< dimension of TJb + int turn_on_rhob; //!< flag to include baryon current - int viscosity_flag; //!< flag to include viscosity in the simulation - int turn_on_shear; //!< flag to include shear viscosity - int turn_on_bulk; //!< flag to include bulk viscosity - int turn_on_diff; //!< flag to include net baryon diffusion - double shear_to_s; //!< value of specific shear viscosity + int viscosity_flag; //!< flag to include viscosity in the simulation + int turn_on_shear; //!< flag to include shear viscosity + int turn_on_bulk; //!< flag to include bulk viscosity + int turn_on_diff; //!< flag to include net baryon diffusion + double shear_to_s; //!< value of specific shear viscosity double quest_revert_strength; @@ -130,20 +127,21 @@ typedef struct init_data { int T_dependent_shear_to_s; int muB_dependent_shear_to_s; - double shear_muBf0p2; //!< for piece-wise parameterization eta/s(muB) - double shear_muBf0p4; //!< for piece-wise parameterization eta/s(muB) + double shear_muBf0p2; //!< for piece-wise parameterization eta/s(muB) + double shear_muBf0p4; //!< for piece-wise parameterization eta/s(muB) double shear_muBDep_alpha; double shear_muBDep_slope; double shear_muBDep_scale; - - //! flag to control the temperature dependence of eta/s(T) if "T_dependent_shear_to_s==2" + //! flag to control the temperature dependence of eta/s(T) if + //! "T_dependent_shear_to_s==2" double shear_2_min; double shear_2_slope; double shear_2_curv; - //! flag to control the temperature dependence of eta/s(T) if "T_dependent_shear_to_s==3" + //! flag to control the temperature dependence of eta/s(T) if + //! "T_dependent_shear_to_s==3" double shear_3_T_kink_in_GeV; double shear_3_low_T_slope_in_GeV; double shear_3_high_T_slope_in_GeV; @@ -152,25 +150,28 @@ typedef struct init_data { //! flag to include temperature dependent zeta/s(T) int T_dependent_bulk_to_s; - //! flag to control the temperature dependence of zeta/s(T) if "T_dependent_bulk_to_s==2" + //! flag to control the temperature dependence of zeta/s(T) if + //! "T_dependent_bulk_to_s==2" double bulk_2_normalisation; double bulk_2_width_in_GeV; double bulk_2_peak_in_GeV; - //! flag to control the temperature dependence of zeta/s(T) if "T_dependent_bulk_to_s==3" + //! flag to control the temperature dependence of zeta/s(T) if + //! "T_dependent_bulk_to_s==3" double bulk_3_max; double bulk_3_width_in_GeV; double bulk_3_T_peak_in_GeV; double bulk_3_lambda_asymm; - //! flag to control the temperature dependence of zeta/s(T) if "T_dependent_bulk_to_s==10" + //! flag to control the temperature dependence of zeta/s(T) if + //! "T_dependent_bulk_to_s==10" double bulk_10_max; double bulk_10_max_muB0p2; double bulk_10_max_muB0p4; - double bulk_10_width_high; // GeV - double bulk_10_width_low; // GeV - double bulk_10_Tpeak; // GeV - double bulk_10_Tpeak_muBcurv; // GeV + double bulk_10_width_high; // GeV + double bulk_10_width_low; // GeV + double bulk_10_Tpeak; // GeV + double bulk_10_Tpeak_muBcurv; // GeV //! multiplicative factors for the relaxation times double shear_relax_time_factor; @@ -217,7 +218,7 @@ typedef struct init_data { double output_evolution_T_cut; double output_evolution_e_cut; - int doFreezeOut; //!< flag to output freeze-out surface + int doFreezeOut; //!< flag to output freeze-out surface //! flag to include low temperature cell at the initial time int doFreezeOut_lowtemp; @@ -225,15 +226,15 @@ typedef struct init_data { //! Maximum starting time for freeze-out surface double freezeOutTauStartMax; - int freezeOutMethod; //!< freeze-out method + int freezeOutMethod; //!< freeze-out method - double TFO; //!< freeze-out temperature. Used if useEpsFO=0 + double TFO; //!< freeze-out temperature. Used if useEpsFO=0 - int useEpsFO; //!< if 1, use energy density value - //!< to define freeze out condition - //!< if 0 use temperature in TFO + int useEpsFO; //!< if 1, use energy density value + //!< to define freeze out condition + //!< if 0 use temperature in TFO - double epsilonFreeze; //!< freeze-out energy density in GeV/fm^3 + double epsilonFreeze; //!< freeze-out energy density in GeV/fm^3 int N_freeze_out; double eps_freeze_min; double eps_freeze_max; @@ -242,7 +243,7 @@ typedef struct init_data { bool freeze_surface_in_binary; // for calculation of spectra - int pseudofreeze; //! flag to compute spectra in pseudorapdity + int pseudofreeze; //! flag to compute spectra in pseudorapdity double max_pseudorapidity; int pseudo_steps; int phi_steps; @@ -257,10 +258,10 @@ typedef struct init_data { //! 0: all particles int particleSpectrumNumber; - int include_deltaf; //!< flag to include shear delta f - int include_deltaf_qmu; //!< flag to include diffusion delta f - int include_deltaf_bulk; //!< flag to include bulk delta f - int deltaf_14moments; //!< use delta f from 14 moment approxmation + int include_deltaf; //!< flag to include shear delta f + int include_deltaf_qmu; //!< flag to include diffusion delta f + int include_deltaf_bulk; //!< flag to include bulk delta f + int deltaf_14moments; //!< use delta f from 14 moment approxmation // parameters for mode 13 and mode 14 //! rapidity range for dN/dy as a function of y diff --git a/src/data_struct.h b/src/data_struct.h index 7d4b29b3..1f0053e5 100644 --- a/src/data_struct.h +++ b/src/data_struct.h @@ -4,16 +4,16 @@ #include typedef std::array, 4> Mat4x4; -typedef std::array Arr10; - -typedef std::array EnergyFlowVec; -typedef std::array FlowVec; -typedef std::array TJbVec; -typedef std::array DumuVec; -typedef Arr10 VelocityShearVec; -typedef std::array DmuMuBoverTVec; -typedef std::array VorticityVec; -typedef std::array ShearVisVecLRF; +typedef std::array Arr10; + +typedef std::array EnergyFlowVec; +typedef std::array FlowVec; +typedef std::array TJbVec; +typedef std::array DumuVec; +typedef Arr10 VelocityShearVec; +typedef std::array DmuMuBoverTVec; +typedef std::array VorticityVec; +typedef std::array ShearVisVecLRF; typedef std::array ViscousVec; typedef std::array, 5> dUsupMat; @@ -24,10 +24,10 @@ typedef struct { } ReconstCell; typedef struct { - float ed, sd, temperature, pressure; - float vx, vy, vz; - float pi[4][4]; - float bulkPi; + float ed, sd, temperature, pressure; + float vx, vy, vz; + float pi[4][4]; + float bulkPi; } fluidCell; typedef struct { @@ -36,25 +36,24 @@ typedef struct { float ux, uy, ueta; } fluidCell_ideal; -//template -//T assume_aligned(T x) { -// #if defined(__AVX512__) -// constexpr int i = 64; -// #elif defined(__AVX__) -// constexpr int i = 32; -// #elif defined(__SSE2__) -// constexpr int i = 16; -// #else -// #error please set alignment i -// #endif -// #ifdef __ICC -// T r = x; -// __assume_aligned(r,i); -// return r; -// #else -// return reinterpret_cast(__builtin_assume_aligned(x,i)); -// #endif -//} - +// template +// T assume_aligned(T x) { +// #if defined(__AVX512__) +// constexpr int i = 64; +// #elif defined(__AVX__) +// constexpr int i = 32; +// #elif defined(__SSE2__) +// constexpr int i = 16; +// #else +// #error please set alignment i +// #endif +// #ifdef __ICC +// T r = x; +// __assume_aligned(r,i); +// return r; +// #else +// return reinterpret_cast(__builtin_assume_aligned(x,i)); +// #endif +// } #endif // _SRC_DATA_STRUCT_H_ diff --git a/src/dissipative.cpp b/src/dissipative.cpp index 5f5676bc..29807f11 100644 --- a/src/dissipative.cpp +++ b/src/dissipative.cpp @@ -1,22 +1,22 @@ // Copyright 2011 @ Bjoern Schenke, Sangyong Jeon, and Charles Gale -#include -#include -#include +#include "dissipative.h" + #include #include -#include "util.h" +#include +#include +#include + #include "cell.h" #include "data.h" -#include "eos.h" -#include "dissipative.h" +#include "util.h" using Util::hbarc; -using Util::small_eps; using Util::map_1d_idx_to_2d; +using Util::small_eps; -Diss::Diss(const EOS &eosIn, const InitData &Data_in) : - DATA(Data_in), eos(eosIn), minmod(Data_in), - transport_coeffs_(Data_in) {} +Diss::Diss(const EOS &eosIn, const InitData &Data_in) + : DATA(Data_in), eos(eosIn), minmod(Data_in), transport_coeffs_(Data_in) {} /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ /* Dissipative parts */ @@ -25,14 +25,11 @@ Diss::Diss(const EOS &eosIn, const InitData &Data_in) : for everywhere else. also, this change is necessary to use Wmunu[rk_flag][4][mu] as the dissipative baryon current*/ /* this is the only one that is being subtracted in the rhs */ -void Diss::MakeWSource(const double tau, - const int ix, const int iy, const int ieta, - TJbVec &dwmn, - Fields &arenaCurr, Fields &arenaPrev, - const int fieldIdx) { +void Diss::MakeWSource( + const double tau, const int ix, const int iy, const int ieta, TJbVec &dwmn, + Fields &arenaCurr, Fields &arenaPrev, const int fieldIdx) { /* calculate d_m (tau W^{m,alpha}) + (geom source terms) */ - const double delta[4] = {0.0, DATA.delta_x, DATA.delta_y, - DATA.delta_eta}; + const double delta[4] = {0.0, DATA.delta_x, DATA.delta_y, DATA.delta_eta}; const double tau_fac[4] = {0.0, tau, tau, 1.0}; dwmn = {0.}; @@ -47,30 +44,35 @@ void Diss::MakeWSource(const double tau, // dW/dtau // backward time derivative (first order is more stable) int idx_1d_alpha0 = map_2d_idx_to_1d(alpha, 0); - double dWdtau = (( arenaCurr.Wmunu_[idx_1d_alpha0][fieldIdx] - - arenaPrev.Wmunu_[idx_1d_alpha0][fieldIdx]) - /DATA.delta_tau); + double dWdtau = + ((arenaCurr.Wmunu_[idx_1d_alpha0][fieldIdx] + - arenaPrev.Wmunu_[idx_1d_alpha0][fieldIdx]) + / DATA.delta_tau); /* bulk pressure term */ double dPidtau = 0.0; double Pi_alpha0 = 0.0; if (alpha < 4 && DATA.turn_on_bulk == 1) { double gfac = (alpha == 0 ? -1.0 : 0.0); - Pi_alpha0 = (arenaCurr.piBulk_[fieldIdx] - *(gfac + arenaCurr.u_[alpha][fieldIdx] - *arenaCurr.u_[0][fieldIdx])); - dPidtau = ((Pi_alpha0 - arenaPrev.piBulk_[fieldIdx] - *(gfac + arenaPrev.u_[alpha][fieldIdx] - *arenaPrev.u_[0][fieldIdx])) - /DATA.delta_tau); + Pi_alpha0 = + (arenaCurr.piBulk_[fieldIdx] + * (gfac + + arenaCurr.u_[alpha][fieldIdx] + * arenaCurr.u_[0][fieldIdx])); + dPidtau = + ((Pi_alpha0 + - arenaPrev.piBulk_[fieldIdx] + * (gfac + + arenaPrev.u_[alpha][fieldIdx] + * arenaPrev.u_[0][fieldIdx])) + / DATA.delta_tau); } - double sf = tau*dWdtau + arenaCurr.Wmunu_[idx_1d_alpha0][fieldIdx]; - double bf = tau*dPidtau + Pi_alpha0; + double sf = tau * dWdtau + arenaCurr.Wmunu_[idx_1d_alpha0][fieldIdx]; + double bf = tau * dPidtau + Pi_alpha0; dwmn[alpha] += sf + bf; if (std::isnan(sf + bf)) { music_message << "[Error]Diss::MakeWSource: "; - music_message << "sf=" << sf << " bf=" << bf - << " Wmunu =" + music_message << "sf=" << sf << " bf=" << bf << " Wmunu =" << arenaCurr.Wmunu_[idx_1d_alpha0][fieldIdx] << " pi_b =" << arenaCurr.piBulk_[fieldIdx] << " prev_pi_b=" << arenaPrev.piBulk_[fieldIdx]; @@ -85,51 +87,64 @@ void Diss::MakeWSource(const double tau, EnergyFlowVec W_eta_p = {0.}; // save tau*W^{\eta \nu} at eta + deta/2 EnergyFlowVec W_eta_m = {0.}; // save tau*W^{\eta \nu} at eta - deta/2 - FieldNeighbourLoop1(arenaCurr, ix, iy, ieta, FNLLAMBDAS1{ - for (int alpha = 0; alpha < 5; alpha++) { - int idx_1d = map_2d_idx_to_1d(alpha, direction); - double sg = arenaCurr.Wmunu_[idx_1d][Ic]*tau_fac[direction]; - double sgp1 = arenaCurr.Wmunu_[idx_1d][Ip1]*tau_fac[direction]; - double sgm1 = arenaCurr.Wmunu_[idx_1d][Im1]*tau_fac[direction]; - //dWdx += minmod.minmod_dx(sgp1, sg, sgm1)/delta[direction]; - // use central difference to preserve conservation law exactly - double W_m = (sg + sgm1)*0.5; - double W_p = (sg + sgp1)*0.5; - - double Pi_m = 0; - double Pi_p = 0; - if (DATA.turn_on_bulk == 1 && alpha < 4) { - double gfac1 = (alpha == (direction) ? 1.0 : 0.0); - double bgp1 = (arenaCurr.piBulk_[Ip1] - *(gfac1 + arenaCurr.u_[alpha][Ip1] - *arenaCurr.u_[direction][Ip1]) - *tau_fac[direction]); - double bg = (arenaCurr.piBulk_[Ic] - *(gfac1 + arenaCurr.u_[alpha][Ic] - *arenaCurr.u_[direction][Ic]) - *tau_fac[direction]); - double bgm1 = (arenaCurr.piBulk_[Im1] - *(gfac1 + arenaCurr.u_[alpha][Im1] - *arenaCurr.u_[direction][Im1]) - *tau_fac[direction]); - //dPidx += minmod.minmod_dx(bgp1, bg, bgm1)/delta[direction]; - // use central difference to preserve conservation law exactly - Pi_m = (bg + bgm1)*0.5; - Pi_p = (bg + bgp1)*0.5; + FieldNeighbourLoop1( + arenaCurr, ix, iy, ieta, FNLLAMBDAS1 { + for (int alpha = 0; alpha < 5; alpha++) { + int idx_1d = map_2d_idx_to_1d(alpha, direction); + double sg = arenaCurr.Wmunu_[idx_1d][Ic] * tau_fac[direction]; + double sgp1 = + arenaCurr.Wmunu_[idx_1d][Ip1] * tau_fac[direction]; + double sgm1 = + arenaCurr.Wmunu_[idx_1d][Im1] * tau_fac[direction]; + // dWdx += minmod.minmod_dx(sgp1, sg, sgm1)/delta[direction]; + // use central difference to preserve conservation law exactly + double W_m = (sg + sgm1) * 0.5; + double W_p = (sg + sgp1) * 0.5; + + double Pi_m = 0; + double Pi_p = 0; + if (DATA.turn_on_bulk == 1 && alpha < 4) { + double gfac1 = (alpha == (direction) ? 1.0 : 0.0); + double bgp1 = + (arenaCurr.piBulk_[Ip1] + * (gfac1 + + arenaCurr.u_[alpha][Ip1] + * arenaCurr.u_[direction][Ip1]) + * tau_fac[direction]); + double bg = + (arenaCurr.piBulk_[Ic] + * (gfac1 + + arenaCurr.u_[alpha][Ic] + * arenaCurr.u_[direction][Ic]) + * tau_fac[direction]); + double bgm1 = + (arenaCurr.piBulk_[Im1] + * (gfac1 + + arenaCurr.u_[alpha][Im1] + * arenaCurr.u_[direction][Im1]) + * tau_fac[direction]); + // dPidx += minmod.minmod_dx(bgp1, bg, + // bgm1)/delta[direction]; + // use central difference to preserve conservation law + // exactly + Pi_m = (bg + bgm1) * 0.5; + Pi_p = (bg + bgp1) * 0.5; + } + if (direction == 3 && (alpha == 0 || alpha == 3)) { + W_eta_p[alpha] = W_p + Pi_m; + W_eta_m[alpha] = W_m + Pi_p; + } else { + dwmn[alpha] += (W_p - W_m + Pi_p - Pi_m) / delta[direction]; + } } - if (direction == 3 && (alpha == 0 || alpha == 3)) { - W_eta_p[alpha] = W_p + Pi_m; - W_eta_m[alpha] = W_m + Pi_p; - } else { - dwmn[alpha] += (W_p - W_m + Pi_p - Pi_m)/delta[direction]; - } - } - }); + }); // add longitudinal flux with the discretized geometric terms // careful about the boost-invariant case when deta could be arbitary - double cosh_deta = cosh(delta[3]/2.)/std::max(delta[3], Util::small_eps); - double sinh_deta = sinh(delta[3]/2.)/std::max(delta[3], Util::small_eps); + double cosh_deta = + cosh(delta[3] / 2.) / std::max(delta[3], Util::small_eps); + double sinh_deta = + sinh(delta[3] / 2.) / std::max(delta[3], Util::small_eps); sinh_deta = std::max(0.5, sinh_deta); if (DATA.boost_invariant) { // if the simulation is boost-invariant, @@ -138,26 +153,25 @@ void Diss::MakeWSource(const double tau, cosh_deta = 0.0; sinh_deta = 0.5; } - dwmn[0] += ( (W_eta_p[0] - W_eta_m[0])*cosh_deta - + (W_eta_p[3] + W_eta_m[3])*sinh_deta); - dwmn[3] += ( (W_eta_p[3] - W_eta_m[3])*cosh_deta - + (W_eta_p[0] + W_eta_m[0])*sinh_deta); + dwmn[0] += + ((W_eta_p[0] - W_eta_m[0]) * cosh_deta + + (W_eta_p[3] + W_eta_m[3]) * sinh_deta); + dwmn[3] += + ((W_eta_p[3] - W_eta_m[3]) * cosh_deta + + (W_eta_p[0] + W_eta_m[0]) * sinh_deta); // sources due to coordinate transform this is added to partial_m W^mn - //dwmn[0] += grid_pt.Wmunu[9]; - //dwmn[0] += grid_pt.pi_b*(1.0 + grid_pt.u[3]*grid_pt.u[3]); - //dwmn[3] += grid_pt.Wmunu[3]; - //dwmn[3] += grid_pt.pi_b*(grid_pt.u[0]*grid_pt.u[3]); + // dwmn[0] += grid_pt.Wmunu[9]; + // dwmn[0] += grid_pt.pi_b*(1.0 + grid_pt.u[3]*grid_pt.u[3]); + // dwmn[3] += grid_pt.Wmunu[3]; + // dwmn[3] += grid_pt.pi_b*(grid_pt.u[0]*grid_pt.u[3]); } - -void Diss::Make_uWSource(const double tau, const Cell_small &grid_pt, - const double theta_local, - const DumuVec &a_local, - const VelocityShearVec &sigma_1d, - const VorticityVec &omega_1d, - const std::vector &thermalVec, - std::array &sourceTerms) { +void Diss::Make_uWSource( + const double tau, const Cell_small &grid_pt, const double theta_local, + const DumuVec &a_local, const VelocityShearVec &sigma_1d, + const VorticityVec &omega_1d, const std::vector &thermalVec, + std::array &sourceTerms) { auto sigma = Util::UnpackVecToMatrix(sigma_1d); auto Wmunu = Util::UnpackVecToMatrix(grid_pt.Wmunu); @@ -183,28 +197,29 @@ void Diss::Make_uWSource(const double tau, const Cell_small &grid_pt, double shear = 0.; if (DATA.muB_dependent_shear_to_s == 0) { double entropy = thermalVec[12]; - shear = shear_to_s*entropy; + shear = shear_to_s * entropy; } else { - shear = shear_to_s*(epsilon + pressure)/std::max(T, small_eps); + shear = shear_to_s * (epsilon + pressure) / std::max(T, small_eps); } - double tau_pi = (transport_coeffs_.get_shear_relax_time_factor() - *shear/std::max(epsilon + pressure, small_eps)); - tau_pi = std::min(10., std::max(3.*DATA.delta_tau, tau_pi)); + double tau_pi = + (transport_coeffs_.get_shear_relax_time_factor() * shear + / std::max(epsilon + pressure, small_eps)); + tau_pi = std::min(10., std::max(3. * DATA.delta_tau, tau_pi)); // transport coefficient for nonlinear terms -- shear only terms // transport coefficients of a massless gas of single component particles - double transport_coefficient = ( - transport_coeffs_.get_phi7_coeff()*tau_pi/shear*(4./5.)); - double transport_coefficient2 = ( - transport_coeffs_.get_delta_pipi_coeff()*tau_pi); - double transport_coefficient3 = ( - transport_coeffs_.get_tau_pipi_coeff()*tau_pi); + double transport_coefficient = + (transport_coeffs_.get_phi7_coeff() * tau_pi / shear * (4. / 5.)); + double transport_coefficient2 = + (transport_coeffs_.get_delta_pipi_coeff() * tau_pi); + double transport_coefficient3 = + (transport_coeffs_.get_tau_pipi_coeff() * tau_pi); // transport coefficient for nonlinear terms // -- coupling to bulk viscous pressure // transport coefficients not yet known -- fixed to zero - double transport_coefficient_b = ( - transport_coeffs_.get_lambda_pibulkPi_coeff()*tau_pi); + double transport_coefficient_b = + (transport_coeffs_.get_lambda_pibulkPi_coeff() * tau_pi); double transport_coefficient2_b = 0.; int mu = 0; @@ -213,7 +228,7 @@ void Diss::Make_uWSource(const double tau, const Cell_small &grid_pt, map_1d_idx_to_2d(idx_1d, mu, nu); /* This source has many terms */ /* everything in the 1/(tau_pi) piece is here */ - /* third step in the split-operator time evol + /* third step in the split-operator time evol use Wmunu[rk_flag] and u[rk_flag] with rk_flag = 0 */ /////////////////////////////////////////////////////////////////////// @@ -223,8 +238,8 @@ void Diss::Make_uWSource(const double tau, const Cell_small &grid_pt, /////////////////////////////////////////////////////////////////////// // full term is - double tempf = (-(1.0 + transport_coefficient2*theta_local) - *Wmunu[mu][nu]); + double tempf = + (-(1.0 + transport_coefficient2 * theta_local) * Wmunu[mu][nu]); /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// @@ -234,7 +249,7 @@ void Diss::Make_uWSource(const double tau, const Cell_small &grid_pt, // full Navier-Stokes term is // sign changes according to metric sign convention - double NS_term = - 2.*shear*sigma[mu][nu]; + double NS_term = -2. * shear * sigma[mu][nu]; /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// @@ -243,18 +258,16 @@ void Diss::Make_uWSource(const double tau, const Cell_small &grid_pt, /////////////////////////////////////////////////////////////////////// double Vorticity_term = 0.0; if (DATA.include_vorticity_terms) { - double transport_coefficient4 = 2.*tau_pi; + double transport_coefficient4 = 2. * tau_pi; auto omega = Util::UnpackVecToMatrix(omega_1d); - double term1_Vorticity = (- Wmunu[mu][0]*omega[nu][0] - - Wmunu[nu][0]*omega[mu][0] - + Wmunu[mu][1]*omega[nu][1] - + Wmunu[nu][1]*omega[mu][1] - + Wmunu[mu][2]*omega[nu][2] - + Wmunu[nu][2]*omega[mu][2] - + Wmunu[mu][3]*omega[nu][3] - + Wmunu[nu][3]*omega[mu][3])/2.; + double term1_Vorticity = + (-Wmunu[mu][0] * omega[nu][0] - Wmunu[nu][0] * omega[mu][0] + + Wmunu[mu][1] * omega[nu][1] + Wmunu[nu][1] * omega[mu][1] + + Wmunu[mu][2] * omega[nu][2] + Wmunu[nu][2] * omega[mu][2] + + Wmunu[mu][3] * omega[nu][3] + Wmunu[nu][3] * omega[mu][3]) + / 2.; // multiply term by its respective transport coefficient - Vorticity_term = transport_coefficient4*term1_Vorticity; + Vorticity_term = transport_coefficient4 * term1_Vorticity; } /////////////////////////////////////////////////////////////////////// @@ -266,32 +279,29 @@ void Diss::Make_uWSource(const double tau, const Cell_small &grid_pt, /////////////////////////////////////////////////////////////////////// double Wsigma_term = 0.0; if (include_Wsigma_term) { - double Wsigma = ( - Wmunu[0][0]*sigma[0][0] - + Wmunu[1][1]*sigma[1][1] - + Wmunu[2][2]*sigma[2][2] - + Wmunu[3][3]*sigma[3][3] - - 2.*( Wmunu[0][1]*sigma[0][1] - + Wmunu[0][2]*sigma[0][2] - + Wmunu[0][3]*sigma[0][3]) - +2.*( Wmunu[1][2]*sigma[1][2] - + Wmunu[1][3]*sigma[1][3] - + Wmunu[2][3]*sigma[2][3])); - double term1_Wsigma = ( - Wmunu[mu][0]*sigma[nu][0] - - Wmunu[nu][0]*sigma[mu][0] - + Wmunu[mu][1]*sigma[nu][1] - + Wmunu[nu][1]*sigma[mu][1] - + Wmunu[mu][2]*sigma[nu][2] - + Wmunu[nu][2]*sigma[mu][2] - + Wmunu[mu][3]*sigma[nu][3] - + Wmunu[nu][3]*sigma[mu][3])/2.; - - double term2_Wsigma = (-(1./3.)*(DATA.gmunu[mu][nu] - + grid_pt.u[mu] - *grid_pt.u[nu])*Wsigma); + double Wsigma = + (Wmunu[0][0] * sigma[0][0] + Wmunu[1][1] * sigma[1][1] + + Wmunu[2][2] * sigma[2][2] + Wmunu[3][3] * sigma[3][3] + - 2. + * (Wmunu[0][1] * sigma[0][1] + Wmunu[0][2] * sigma[0][2] + + Wmunu[0][3] * sigma[0][3]) + + 2. + * (Wmunu[1][2] * sigma[1][2] + Wmunu[1][3] * sigma[1][3] + + Wmunu[2][3] * sigma[2][3])); + double term1_Wsigma = + (-Wmunu[mu][0] * sigma[nu][0] - Wmunu[nu][0] * sigma[mu][0] + + Wmunu[mu][1] * sigma[nu][1] + Wmunu[nu][1] * sigma[mu][1] + + Wmunu[mu][2] * sigma[nu][2] + Wmunu[nu][2] * sigma[mu][2] + + Wmunu[mu][3] * sigma[nu][3] + Wmunu[nu][3] * sigma[mu][3]) + / 2.; + + double term2_Wsigma = + (-(1. / 3.) + * (DATA.gmunu[mu][nu] + grid_pt.u[mu] * grid_pt.u[nu]) + * Wsigma); // multiply term by its respective transport coefficient - term1_Wsigma = transport_coefficient3*term1_Wsigma; - term2_Wsigma = transport_coefficient3*term2_Wsigma; + term1_Wsigma = transport_coefficient3 * term1_Wsigma; + term2_Wsigma = transport_coefficient3 * term2_Wsigma; // full term is Wsigma_term = -term1_Wsigma - term2_Wsigma; @@ -305,26 +315,26 @@ void Diss::Make_uWSource(const double tau, const Cell_small &grid_pt, /////////////////////////////////////////////////////////////////////// double WW_term = 0.0; if (include_WWterm) { - double Wsquare = ( Wmunu[0][0]*Wmunu[0][0] - + Wmunu[1][1]*Wmunu[1][1] - + Wmunu[2][2]*Wmunu[2][2] - + Wmunu[3][3]*Wmunu[3][3] - - 2.*( Wmunu[0][1]*Wmunu[0][1] - + Wmunu[0][2]*Wmunu[0][2] - + Wmunu[0][3]*Wmunu[0][3]) - + 2.*( Wmunu[1][2]*Wmunu[1][2] - + Wmunu[1][3]*Wmunu[1][3] - + Wmunu[2][3]*Wmunu[2][3])); - double term1_WW = ( - Wmunu[mu][0]*Wmunu[nu][0] - + Wmunu[mu][1]*Wmunu[nu][1] - + Wmunu[mu][2]*Wmunu[nu][2] - + Wmunu[mu][3]*Wmunu[nu][3]); - double term2_WW = (-(1./3.)*(DATA.gmunu[mu][nu] - + grid_pt.u[mu]*grid_pt.u[nu])*Wsquare); + double Wsquare = + (Wmunu[0][0] * Wmunu[0][0] + Wmunu[1][1] * Wmunu[1][1] + + Wmunu[2][2] * Wmunu[2][2] + Wmunu[3][3] * Wmunu[3][3] + - 2. + * (Wmunu[0][1] * Wmunu[0][1] + Wmunu[0][2] * Wmunu[0][2] + + Wmunu[0][3] * Wmunu[0][3]) + + 2. + * (Wmunu[1][2] * Wmunu[1][2] + Wmunu[1][3] * Wmunu[1][3] + + Wmunu[2][3] * Wmunu[2][3])); + double term1_WW = + (-Wmunu[mu][0] * Wmunu[nu][0] + Wmunu[mu][1] * Wmunu[nu][1] + + Wmunu[mu][2] * Wmunu[nu][2] + Wmunu[mu][3] * Wmunu[nu][3]); + double term2_WW = + (-(1. / 3.) + * (DATA.gmunu[mu][nu] + grid_pt.u[mu] * grid_pt.u[nu]) + * Wsquare); // multiply term by its respective transport coefficient - term1_WW = term1_WW*transport_coefficient; - term2_WW = term2_WW*transport_coefficient; + term1_WW = term1_WW * transport_coefficient; + term2_WW = term2_WW * transport_coefficient; // full term is // sign changes according to metric sign convention @@ -340,12 +350,12 @@ void Diss::Make_uWSource(const double tau, const Cell_small &grid_pt, /////////////////////////////////////////////////////////////////////// double Coupling_to_Bulk = 0.0; if (DATA.include_second_order_terms == 1) { - double Bulk_Sigma = grid_pt.pi_b*sigma[mu][nu]; - double Bulk_W = grid_pt.pi_b*Wmunu[mu][nu]; + double Bulk_Sigma = grid_pt.pi_b * sigma[mu][nu]; + double Bulk_W = grid_pt.pi_b * Wmunu[mu][nu]; // multiply term by its respective transport coefficient - double Bulk_Sigma_term = Bulk_Sigma*transport_coefficient_b; - double Bulk_W_term = Bulk_W*transport_coefficient2_b; + double Bulk_Sigma_term = Bulk_Sigma * transport_coefficient_b; + double Bulk_W_term = Bulk_W * transport_coefficient2_b; // full term is // first term: sign changes according to metric sign convention @@ -353,23 +363,22 @@ void Diss::Make_uWSource(const double tau, const Cell_small &grid_pt, } // final answer is - sourceTerms[idx_1d-4] = ( - (NS_term + tempf + Vorticity_term + Wsigma_term - + WW_term + Coupling_to_Bulk)/tau_pi); + sourceTerms[idx_1d - 4] = + ((NS_term + tempf + Vorticity_term + Wsigma_term + WW_term + + Coupling_to_Bulk) + / tau_pi); } } - -void Diss::Make_uWRHS(const double tau, Fields &arena, - const int fieldIdx, - const int ix, const int iy, const int ieta, - std::array &w_rhs, - const double theta_local, const DumuVec &a_local) { +void Diss::Make_uWRHS( + const double tau, Fields &arena, const int fieldIdx, const int ix, + const int iy, const int ieta, std::array &w_rhs, + const double theta_local, const DumuVec &a_local) { auto grid_pt = arena.getCell(fieldIdx); auto Wmunu_local = Util::UnpackVecToMatrix(grid_pt.Wmunu); /* Kurganov-Tadmor for Wmunu */ - /* implement + /* implement partial_tau (utau Wmn) + (1/tau)partial_eta (ueta Wmn) + partial_x (ux Wmn) + partial_y (uy Wmn) + utau Wmn/tau = SW or the right hand side of, @@ -384,7 +393,7 @@ void Diss::Make_uWRHS(const double tau, Fields &arena, Here fRph = ux WmnRph and ax uRph = |ux/utau|_max utau Wmn */ /* This is the second step in the operator splitting. it uses rk_flag+1 as initial condition */ - double delta[4] = {0.0, DATA.delta_x, DATA.delta_y, DATA.delta_eta*tau}; + double delta[4] = {0.0, DATA.delta_x, DATA.delta_y, DATA.delta_eta * tau}; const double delta_tau = DATA.delta_tau; int piIdxArr[9] = {4, 5, 6, 7, 8, 9, 11, 12, 13}; @@ -397,71 +406,74 @@ void Diss::Make_uWRHS(const double tau, Fields &arena, } // pi^\mu\nu is symmetric - FieldNeighbourLoop2(arena, ix, iy, ieta, FNLLAMBDAS2{ - double g, gp1, gp2, gm1, gm2; - double f, fp1, fp2, fm1, fm2; - for (int idx = 0; idx < loopIdx; idx++) { - int idx_1d = piIdxArr[idx]; - /* Get_uWmns */ - if (idx_1d == 9) { - g = arena.piBulk_[Ic ]; - gp2 = arena.piBulk_[Ip2]; - gp1 = arena.piBulk_[Ip1]; - gm1 = arena.piBulk_[Im1]; - gm2 = arena.piBulk_[Im2]; - } else { - g = arena.Wmunu_[idx_1d][Ic ]; - gp2 = arena.Wmunu_[idx_1d][Ip2]; - gp1 = arena.Wmunu_[idx_1d][Ip1]; - gm1 = arena.Wmunu_[idx_1d][Im1]; - gm2 = arena.Wmunu_[idx_1d][Im2]; + FieldNeighbourLoop2( + arena, ix, iy, ieta, FNLLAMBDAS2 { + double g, gp1, gp2, gm1, gm2; + double f, fp1, fp2, fm1, fm2; + for (int idx = 0; idx < loopIdx; idx++) { + int idx_1d = piIdxArr[idx]; + /* Get_uWmns */ + if (idx_1d == 9) { + g = arena.piBulk_[Ic]; + gp2 = arena.piBulk_[Ip2]; + gp1 = arena.piBulk_[Ip1]; + gm1 = arena.piBulk_[Im1]; + gm2 = arena.piBulk_[Im2]; + } else { + g = arena.Wmunu_[idx_1d][Ic]; + gp2 = arena.Wmunu_[idx_1d][Ip2]; + gp1 = arena.Wmunu_[idx_1d][Ip1]; + gm1 = arena.Wmunu_[idx_1d][Im1]; + gm2 = arena.Wmunu_[idx_1d][Im2]; + } + + f = g * arena.u_[direction][Ic]; + g *= arena.u_[0][Ic]; + + fp2 = gp2 * arena.u_[direction][Ip2]; + gp2 *= arena.u_[0][Ip2]; + + fp1 = gp1 * arena.u_[direction][Ip1]; + gp1 *= arena.u_[0][Ip1]; + + fm1 = gm1 * arena.u_[direction][Im1]; + gm1 *= arena.u_[0][Im1]; + + fm2 = gm2 * arena.u_[direction][Im2]; + gm2 *= arena.u_[0][Im2]; + + /* MakeuWmnHalfs */ + /* uWmn */ + double uWphR = fp1 - 0.5 * minmod.minmod_dx(fp2, fp1, f); + double temp = 0.5 * minmod.minmod_dx(fp1, f, fm1); + double uWphL = f + temp; + double uWmhR = f - temp; + double uWmhL = fm1 + 0.5 * minmod.minmod_dx(f, fm1, fm2); + + /* just Wmn */ + double WphR = gp1 - 0.5 * minmod.minmod_dx(gp2, gp1, g); + temp = 0.5 * minmod.minmod_dx(gp1, g, gm1); + double WphL = g + temp; + double WmhR = g - temp; + double WmhL = gm1 + 0.5 * minmod.minmod_dx(g, gm1, gm2); + + double a = std::abs(arena.u_[direction][Ic]) / arena.u_[0][Ic]; + double am1 = + std::abs(arena.u_[direction][Im1]) / arena.u_[0][Im1]; + double ap1 = + std::abs(arena.u_[direction][Ip1]) / arena.u_[0][Ip1]; + + double ax = std::max(a, ap1); + double HWph = ((uWphR + uWphL) - ax * (WphR - WphL)) * 0.5; + + ax = std::max(a, am1); + double HWmh = ((uWmhR + uWmhL) - ax * (WmhR - WmhL)) * 0.5; + + double HW = (HWph - HWmh) / delta[direction]; + /* make partial_i (u^i Wmn) */ + w_rhs[idx] += (-HW) * delta_tau; } - - f = g*arena.u_[direction][Ic]; - g *= arena.u_[0][Ic]; - - fp2 = gp2*arena.u_[direction][Ip2]; - gp2 *= arena.u_[0][Ip2]; - - fp1 = gp1*arena.u_[direction][Ip1]; - gp1 *= arena.u_[0][Ip1]; - - fm1 = gm1*arena.u_[direction][Im1]; - gm1 *= arena.u_[0][Im1]; - - fm2 = gm2*arena.u_[direction][Im2]; - gm2 *= arena.u_[0][Im2]; - - /* MakeuWmnHalfs */ - /* uWmn */ - double uWphR = fp1 - 0.5*minmod.minmod_dx(fp2, fp1, f); - double temp = 0.5*minmod.minmod_dx(fp1, f, fm1); - double uWphL = f + temp; - double uWmhR = f - temp; - double uWmhL = fm1 + 0.5*minmod.minmod_dx(f, fm1, fm2); - - /* just Wmn */ - double WphR = gp1 - 0.5*minmod.minmod_dx(gp2, gp1, g); - temp = 0.5*minmod.minmod_dx(gp1, g, gm1); - double WphL = g + temp; - double WmhR = g - temp; - double WmhL = gm1 + 0.5*minmod.minmod_dx(g, gm1, gm2); - - double a = std::abs(arena.u_[direction][Ic ])/arena.u_[0][Ic ]; - double am1 = std::abs(arena.u_[direction][Im1])/arena.u_[0][Im1]; - double ap1 = std::abs(arena.u_[direction][Ip1])/arena.u_[0][Ip1]; - - double ax = std::max(a, ap1); - double HWph = ((uWphR + uWphL) - ax*(WphR - WphL))*0.5; - - ax = std::max(a, am1); - double HWmh = ((uWmhR + uWmhL) - ax*(WmhR - WmhL))*0.5; - - double HW = (HWph - HWmh)/delta[direction]; - /* make partial_i (u^i Wmn) */ - w_rhs[idx] += (-HW)*delta_tau; - } - }); + }); /* add a source term -u^tau Wmn/tau due to the coordinate change to tau-eta */ @@ -470,49 +482,51 @@ void Diss::Make_uWRHS(const double tau, Fields &arena, /* this term is being added to the rhs so that -4/3 + 1 = -1/3 */ /* other source terms due to the coordinate change to tau-eta */ - // align gmunu in data for faster access - also changed **gmunu in data to gmunu[4][4] - // moved two sums into w_rhs at top and bottom into one sum in the end - // do not symmetrize in the end, just go through all nu's - // vectorized innermost loop more efficiently by iterating over 4 indices - // instead of 3 to avoid masking + // align gmunu in data for faster access - also changed **gmunu in data to + // gmunu[4][4] moved two sums into w_rhs at top and bottom into one sum in + // the end do not symmetrize in the end, just go through all nu's vectorized + // innermost loop more efficiently by iterating over 4 indices instead of 3 + // to avoid masking int mu = 0; int nu = 0; for (int idx_1d = 4; idx_1d < 9; idx_1d++) { map_1d_idx_to_2d(idx_1d, mu, nu); - double tempf = ( - - (DATA.gmunu[3][mu])*(Wmunu_local[0][nu]) - - (DATA.gmunu[3][nu])*(Wmunu_local[0][mu]) - + (DATA.gmunu[0][mu])*(Wmunu_local[3][nu]) - + (DATA.gmunu[0][nu])*(Wmunu_local[3][mu]) - + (Wmunu_local[3][nu])*(grid_pt.u[mu])*(grid_pt.u[0]) - + (Wmunu_local[3][mu])*(grid_pt.u[nu])*(grid_pt.u[0]) - - (Wmunu_local[0][nu])*(grid_pt.u[mu])*(grid_pt.u[3]) - - (Wmunu_local[0][mu])*(grid_pt.u[nu])*(grid_pt.u[3])) - *(grid_pt.u[3]/tau); + double tempf = + (-(DATA.gmunu[3][mu]) * (Wmunu_local[0][nu]) + - (DATA.gmunu[3][nu]) * (Wmunu_local[0][mu]) + + (DATA.gmunu[0][mu]) * (Wmunu_local[3][nu]) + + (DATA.gmunu[0][nu]) * (Wmunu_local[3][mu]) + + (Wmunu_local[3][nu]) * (grid_pt.u[mu]) * (grid_pt.u[0]) + + (Wmunu_local[3][mu]) * (grid_pt.u[nu]) * (grid_pt.u[0]) + - (Wmunu_local[0][nu]) * (grid_pt.u[mu]) * (grid_pt.u[3]) + - (Wmunu_local[0][mu]) * (grid_pt.u[nu]) * (grid_pt.u[3])) + * (grid_pt.u[3] / tau); for (int ic = 0; ic < 4; ic++) { const double ic_fac = (ic == 0 ? -1.0 : 1.0); - tempf += ( - (Wmunu_local[ic][nu])*(grid_pt.u[mu])*(a_local[ic])*ic_fac - + (Wmunu_local[ic][mu])*(grid_pt.u[nu])*(a_local[ic])*ic_fac); + tempf += + ((Wmunu_local[ic][nu]) * (grid_pt.u[mu]) * (a_local[ic]) + * ic_fac + + (Wmunu_local[ic][mu]) * (grid_pt.u[nu]) * (a_local[ic]) + * ic_fac); } - w_rhs[idx_1d-4] += (tempf*(DATA.delta_tau) - + (- (grid_pt.u[0]*Wmunu_local[mu][nu])/tau - + (theta_local*Wmunu_local[mu][nu]))*(DATA.delta_tau)); + w_rhs[idx_1d - 4] += + (tempf * (DATA.delta_tau) + + (-(grid_pt.u[0] * Wmunu_local[mu][nu]) / tau + + (theta_local * Wmunu_local[mu][nu])) + * (DATA.delta_tau)); } if (DATA.turn_on_bulk == 1) { - w_rhs[5] -= (grid_pt.pi_b)*(grid_pt.u[0])/tau*DATA.delta_tau; - w_rhs[5] += (grid_pt.pi_b)*theta_local*DATA.delta_tau; + w_rhs[5] -= (grid_pt.pi_b) * (grid_pt.u[0]) / tau * DATA.delta_tau; + w_rhs[5] += (grid_pt.pi_b) * theta_local * DATA.delta_tau; } } - -double Diss::Make_uPiSource(const double tau, const Cell_small &grid_pt, - const double theta_local, - const VelocityShearVec &sigma_1d, - const std::vector &thermalVec) { +double Diss::Make_uPiSource( + const double tau, const Cell_small &grid_pt, const double theta_local, + const VelocityShearVec &sigma_1d, const std::vector &thermalVec) { double tempf; double bulk; double Bulk_Relax_time; @@ -531,62 +545,60 @@ double Diss::Make_uPiSource(const double tau, const Cell_small &grid_pt, // defining bulk viscosity coefficient // shear viscosity = constant * entropy density - //s_den = eos.get_entropy(epsilon, rhob); - //shear = (DATA.shear_to_s)*s_den; + // s_den = eos.get_entropy(epsilon, rhob); + // shear = (DATA.shear_to_s)*s_den; // shear viscosity = constant * (e + P)/T double epsilon = thermalVec[0]; double temperature = thermalVec[6]; double mu_B = thermalVec[7]; // cs2 is the velocity of sound squared - //double cs2 = eos.get_cs2(epsilon, thermalVec[1]); + // double cs2 = eos.get_cs2(epsilon, thermalVec[1]); double cs2 = thermalVec[5]; double pressure = thermalVec[2]; // T dependent bulk viscosity bulk = transport_coeffs_.get_zeta_over_s(temperature, mu_B); - bulk = bulk*(epsilon + pressure)/temperature; + bulk = bulk * (epsilon + pressure) / temperature; // defining bulk relaxation time and additional transport coefficients // Bulk relaxation time from kinetic theory - double csfactor = std::max(1./3. - cs2, small_eps); - Bulk_Relax_time = (transport_coeffs_.get_bulk_relax_time_factor() - /(csfactor*csfactor) - /std::max(epsilon + pressure, small_eps)*bulk); + double csfactor = std::max(1. / 3. - cs2, small_eps); + Bulk_Relax_time = + (transport_coeffs_.get_bulk_relax_time_factor() / (csfactor * csfactor) + / std::max(epsilon + pressure, small_eps) * bulk); if (DATA.bulk_relaxation_type == 1) { - Bulk_Relax_time = ( - bulk/(transport_coeffs_.get_bulk_relax_time_factor() - *csfactor) - /std::max(epsilon + pressure, small_eps)); + Bulk_Relax_time = + (bulk / (transport_coeffs_.get_bulk_relax_time_factor() * csfactor) + / std::max(epsilon + pressure, small_eps)); } // avoid overflow or underflow of the bulk relaxation time - Bulk_Relax_time = ( - std::min(10., std::max(3.*DATA.delta_tau, Bulk_Relax_time))); + Bulk_Relax_time = + (std::min(10., std::max(3. * DATA.delta_tau, Bulk_Relax_time))); // from kinetic theory, small mass limit - transport_coeff1 = ( - transport_coeffs_.get_delta_bulkPibulkPi_coeff()*Bulk_Relax_time); - transport_coeff2 = ( - transport_coeffs_.get_tau_bulkPibulkPi_coeff()*Bulk_Relax_time); + transport_coeff1 = + (transport_coeffs_.get_delta_bulkPibulkPi_coeff() * Bulk_Relax_time); + transport_coeff2 = + (transport_coeffs_.get_tau_bulkPibulkPi_coeff() * Bulk_Relax_time); // from kinetic theory - transport_coeff1_s = (transport_coeffs_.get_lambda_bulkPipi_coeff() - *(1./3. - cs2)*Bulk_Relax_time); + transport_coeff1_s = + (transport_coeffs_.get_lambda_bulkPipi_coeff() * (1. / 3. - cs2) + * Bulk_Relax_time); transport_coeff2_s = 0.; // not known; put 0 - // Computing Navier-Stokes term (-bulk viscosity * theta) - NS_term = -bulk*theta_local; + NS_term = -bulk * theta_local; // Computing relaxation term and nonlinear term: // - Bulk - transport_coeff1*Bulk*theta - tempf = (-(grid_pt.pi_b) - - transport_coeff1*theta_local*(grid_pt.pi_b)); + tempf = (-(grid_pt.pi_b) - transport_coeff1 * theta_local * (grid_pt.pi_b)); // Computing nonlinear term: + transport_coeff2*Bulk*Bulk if (include_BBterm == 1) { - BB_term = transport_coeff2*(grid_pt.pi_b)*(grid_pt.pi_b); + BB_term = transport_coeff2 * (grid_pt.pi_b) * (grid_pt.pi_b); } else { BB_term = 0.0; } @@ -598,33 +610,31 @@ double Diss::Make_uPiSource(const double tau, const Cell_small &grid_pt, auto sigma = Util::UnpackVecToMatrix(sigma_1d); auto Wmunu = Util::UnpackVecToMatrix(grid_pt.Wmunu); - Wsigma = ( Wmunu[0][0]*sigma[0][0] - + Wmunu[1][1]*sigma[1][1] - + Wmunu[2][2]*sigma[2][2] - + Wmunu[3][3]*sigma[3][3] - - 2.*( Wmunu[0][1]*sigma[0][1] - + Wmunu[0][2]*sigma[0][2] - + Wmunu[0][3]*sigma[0][3]) - + 2.*( Wmunu[1][2]*sigma[1][2] - + Wmunu[1][3]*sigma[1][3] - + Wmunu[2][3]*sigma[2][3])); - - WW = ( Wmunu[0][0]*Wmunu[0][0] - + Wmunu[1][1]*Wmunu[1][1] - + Wmunu[2][2]*Wmunu[2][2] - + Wmunu[3][3]*Wmunu[3][3] - - 2.*( Wmunu[0][1]*Wmunu[0][1] - + Wmunu[0][2]*Wmunu[0][2] - + Wmunu[0][3]*Wmunu[0][3]) - + 2.*( Wmunu[1][2]*Wmunu[1][2] - + Wmunu[1][3]*Wmunu[1][3] - + Wmunu[2][3]*Wmunu[2][3])); + Wsigma = + (Wmunu[0][0] * sigma[0][0] + Wmunu[1][1] * sigma[1][1] + + Wmunu[2][2] * sigma[2][2] + Wmunu[3][3] * sigma[3][3] + - 2. + * (Wmunu[0][1] * sigma[0][1] + Wmunu[0][2] * sigma[0][2] + + Wmunu[0][3] * sigma[0][3]) + + 2. + * (Wmunu[1][2] * sigma[1][2] + Wmunu[1][3] * sigma[1][3] + + Wmunu[2][3] * sigma[2][3])); + + WW = + (Wmunu[0][0] * Wmunu[0][0] + Wmunu[1][1] * Wmunu[1][1] + + Wmunu[2][2] * Wmunu[2][2] + Wmunu[3][3] * Wmunu[3][3] + - 2. + * (Wmunu[0][1] * Wmunu[0][1] + Wmunu[0][2] * Wmunu[0][2] + + Wmunu[0][3] * Wmunu[0][3]) + + 2. + * (Wmunu[1][2] * Wmunu[1][2] + Wmunu[1][3] * Wmunu[1][3] + + Wmunu[2][3] * Wmunu[2][3])); // multiply term by its respective transport coefficient - Shear_Sigma_term = Wsigma*transport_coeff1_s; - Shear_Shear_term = WW*transport_coeff2_s; + Shear_Sigma_term = Wsigma * transport_coeff1_s; + Shear_Shear_term = WW * transport_coeff2_s; // full term that couples to shear is - Coupling_to_Shear = -Shear_Sigma_term + Shear_Shear_term ; + Coupling_to_Shear = -Shear_Sigma_term + Shear_Shear_term; } else { Coupling_to_Shear = 0.0; } @@ -632,67 +642,64 @@ double Diss::Make_uPiSource(const double tau, const Cell_small &grid_pt, // Final Answer Final_Answer = NS_term + tempf + BB_term + Coupling_to_Shear; - return Final_Answer/(Bulk_Relax_time); -}/* Make_uPiSource */ - + return Final_Answer / (Bulk_Relax_time); +} /* Make_uPiSource */ /* Sangyong Nov 18 2014 */ /* baryon current parts */ /* this contains the source terms that is, all the terms that are not part of the current */ -/* for the q part, we don't do tau*u*q we just do u*q - this part contains +/* for the q part, we don't do tau*u*q we just do u*q + this part contains -(1/tau_rho)(q[a] + kappa g[a][b]Dtildemu[b] + kappa u[a] u[b]g[b][c]Dtildemu[c]) +Delta[a][tau] u[eta] q[eta]/tau -Delta[a][eta] u[eta] q[tau]/tau -u[a]u[b]g[b][e] Dq[e] */ -void Diss::Make_uqSource(const double tau, const Cell_small &grid_pt, - const double theta_local, - const DumuVec &a_local, - const VelocityShearVec &sigma_1d, - const VorticityVec &omega_1d, - const DmuMuBoverTVec &baryon_diffusion_vec, - const std::vector &thermalVec, - std::array &sourceTerms) { +void Diss::Make_uqSource( + const double tau, const Cell_small &grid_pt, const double theta_local, + const DumuVec &a_local, const VelocityShearVec &sigma_1d, + const VorticityVec &omega_1d, const DmuMuBoverTVec &baryon_diffusion_vec, + const std::vector &thermalVec, std::array &sourceTerms) { double epsilon = thermalVec[0]; double rhob = thermalVec[1]; double pressure = thermalVec[2]; double T = thermalVec[6]; double kappa_coefficient = DATA.kappa_coefficient; - double tau_rho = kappa_coefficient/std::max(T, small_eps); - tau_rho = std::min(10., std::max(3.*DATA.delta_tau, tau_rho)); + double tau_rho = kappa_coefficient / std::max(T, small_eps); + tau_rho = std::min(10., std::max(3. * DATA.delta_tau, tau_rho)); - double mub = thermalVec[7]; - double alpha = mub/std::max(T, small_eps); + double mub = thermalVec[7]; + double alpha = mub / std::max(T, small_eps); double denorm_safe = std::copysign( - std::max(std::abs(3.*T*tanh(alpha)), small_eps), 3.*T*tanh(alpha)); - double kappa = kappa_coefficient*( - rhob/denorm_safe - - rhob*rhob/std::max(epsilon + pressure, small_eps)); + std::max(std::abs(3. * T * tanh(alpha)), small_eps), + 3. * T * tanh(alpha)); + double kappa = kappa_coefficient + * (rhob / denorm_safe + - rhob * rhob / std::max(epsilon + pressure, small_eps)); if (DATA.Initial_profile == 1) { // for 1+1D numerical test - double denorm_safe = std::copysign( - std::max(std::abs(mub), small_eps), mub); - kappa = kappa_coefficient*(rhob/denorm_safe); + double denorm_safe = + std::copysign(std::max(std::abs(mub), small_eps), mub); + kappa = kappa_coefficient * (rhob / denorm_safe); } // copy the value of \tilde{q^\mu} double q[4]; for (int i = 0; i < 4; i++) { - q[i] = grid_pt.Wmunu[10+i]; + q[i] = grid_pt.Wmunu[10 + i]; } - /* -(1/tau_rho)(q[a] + kappa g[a][b]Dtildemu[b] + /* -(1/tau_rho)(q[a] + kappa g[a][b]Dtildemu[b] * + kappa u[a] u[b]g[b][c]Dtildemu[c]) * + theta q[a] - q[a] u^\tau/tau * + Delta[a][tau] u[eta] q[eta]/tau * - Delta[a][eta] u[eta] q[tau]/tau * - u[a] u[b]g[b][e] Dq[e] -> u[a] q[e] g[e][b] Du[b] - */ + */ // first: (1/tau_rho) part // recall that dUsup[4][i] = partial_i (muB/T) @@ -702,76 +709,76 @@ void Diss::Make_uqSource(const double tau, const Cell_small &grid_pt, // + kappa u[a] u[b]g[b][c]DmuB/T[c]) // a = nu - double transport_coeff = transport_coeffs_.get_delta_qq_coeff()*tau_rho; - double transport_coeff_2 = transport_coeffs_.get_lambda_qq_coeff()*tau_rho; + double transport_coeff = transport_coeffs_.get_delta_qq_coeff() * tau_rho; + double transport_coeff_2 = + transport_coeffs_.get_lambda_qq_coeff() * tau_rho; // add a new non-linear term (-q^\mu \sigma_\mu\nu) auto sigma = Util::UnpackVecToMatrix(sigma_1d); for (int nu = 1; nu < 4; nu++) { - double NS = kappa*(baryon_diffusion_vec[nu] - + grid_pt.u[nu]*a_local[4]); + double NS = + kappa * (baryon_diffusion_vec[nu] + grid_pt.u[nu] * a_local[4]); // add a new non-linear term (- q \theta) - double Nonlinear1 = -transport_coeff*q[nu]*theta_local; + double Nonlinear1 = -transport_coeff * q[nu] * theta_local; double temptemp = 0.0; - for (int i = 0 ; i < 4; i++) { - temptemp += q[i]*sigma[i][nu]*DATA.gmunu[i][i]; + for (int i = 0; i < 4; i++) { + temptemp += q[i] * sigma[i][nu] * DATA.gmunu[i][i]; } - double Nonlinear2 = -transport_coeff_2*temptemp; + double Nonlinear2 = -transport_coeff_2 * temptemp; // add a new non-linear term (-q_\mu \omega^{\mu\nu}) double Nonlinear3 = 0.0; if (DATA.include_vorticity_terms) { - double transport_coeff_3 = 1.0*tau_rho; + double transport_coeff_3 = 1.0 * tau_rho; auto omega = Util::UnpackVecToMatrix(omega_1d); double temp3 = 0.0; - for (int i = 0 ; i < 4; i++) { - temp3 += q[i]*omega[i][nu]*DATA.gmunu[i][i]; + for (int i = 0; i < 4; i++) { + temp3 += q[i] * omega[i][nu] * DATA.gmunu[i][i]; } - Nonlinear3 = -transport_coeff_3*temp3; + Nonlinear3 = -transport_coeff_3 * temp3; } - sourceTerms[nu-1] = ( - (- q[nu] - NS + Nonlinear1 + Nonlinear2 + Nonlinear3)/tau_rho); + sourceTerms[nu - 1] = + ((-q[nu] - NS + Nonlinear1 + Nonlinear2 + Nonlinear3) / tau_rho); if (DATA.Initial_profile == 1) { // for 1+1D numerical test - sourceTerms[nu-1] = (-q[nu] - NS)/tau_rho; + sourceTerms[nu - 1] = (-q[nu] - NS) / tau_rho; } // all other geometric terms.... // + theta q[a] - q[a] u^\tau/tau - sourceTerms[nu-1] += (theta_local - grid_pt.u[0]/tau)*q[nu]; - //if (isnan(SW)) { - // cout << "theta term is nan! " << endl; - //} + sourceTerms[nu - 1] += (theta_local - grid_pt.u[0] / tau) * q[nu]; + // if (isnan(SW)) { + // cout << "theta term is nan! " << endl; + // } // +Delta[a][tau] u[eta] q[eta]/tau - double tempf = ((DATA.gmunu[nu][0] - + grid_pt.u[nu]*grid_pt.u[0]) - *grid_pt.u[3]*q[3]/tau - - (DATA.gmunu[nu][3] - + grid_pt.u[nu]*grid_pt.u[3]) - *grid_pt.u[3]*q[0]/tau); - sourceTerms[nu-1] += tempf; - //if (isnan(tempf)) { - // cout << "Delta^{a \tau} and Delta^{a \eta} terms are nan!" << endl; - //} + double tempf = + ((DATA.gmunu[nu][0] + grid_pt.u[nu] * grid_pt.u[0]) * grid_pt.u[3] + * q[3] / tau + - (DATA.gmunu[nu][3] + grid_pt.u[nu] * grid_pt.u[3]) * grid_pt.u[3] + * q[0] / tau); + sourceTerms[nu - 1] += tempf; + // if (isnan(tempf)) { + // cout << "Delta^{a \tau} and Delta^{a \eta} terms are nan!" << + // endl; + // } // -u[a] u[b]g[b][e] Dq[e] -> u[a] (q[e] g[e][b] Du[b]) tempf = 0.0; for (int i = 0; i < 4; i++) { - tempf += q[i]*Util::gmn(i)*a_local[i]; + tempf += q[i] * Util::gmn(i) * a_local[i]; } - sourceTerms[nu-1] += (grid_pt.u[nu])*tempf; - //if (isnan(tempf)) { - // cout << "u^a q_b Du^b term is nan! " << endl; - //} + sourceTerms[nu - 1] += (grid_pt.u[nu]) * tempf; + // if (isnan(tempf)) { + // cout << "u^a q_b Du^b term is nan! " << endl; + // } } } - //! this function outputs the T and muB dependence of the baryon diffusion //! coefficient, kappa void Diss::output_kappa_T_and_muB_dependence() { @@ -782,56 +789,57 @@ void Diss::output_kappa_T_and_muB_dependence() { << std::endl; // define the grid - double e_min = 1e-5; // fm^-4 - double e_max = 100.0; // fm^-4 + double e_min = 1e-5; // fm^-4 + double e_max = 100.0; // fm^-4 int ne = 1000; - double de = (e_max - e_min)/(ne - 1.); - double rhob_min = 0.0; // fm^-3 + double de = (e_max - e_min) / (ne - 1.); + double rhob_min = 0.0; // fm^-3 double rhob_max = sqrt(10.0); // fm^-3 int nrhob = 1000; - double drhob = (rhob_max - rhob_min)/(nrhob - 1.); + double drhob = (rhob_max - rhob_min) / (nrhob - 1.); for (int i = 0; i < ne; i++) { - double e_local = e_min + i*de; + double e_local = e_min + i * de; for (int j = 0; j < nrhob; j++) { - double rhob_local = rhob_min + j*drhob; + double rhob_local = rhob_min + j * drhob; rhob_local *= rhob_local; double mu_B_local = eos.get_muB(e_local, rhob_local); - if (mu_B_local*hbarc > 0.78) + if (mu_B_local * hbarc > 0.78) continue; // discard points out of the table double p_local = eos.get_pressure(e_local, rhob_local); double T_local = eos.get_temperature(e_local, rhob_local); - double alpha_local = mu_B_local/T_local; + double alpha_local = mu_B_local / T_local; double denorm_safe = std::copysign( - std::max(small_eps, std::abs(3.*T_local*tanh(alpha_local))), - 3.*T_local*tanh(alpha_local)); - double kappa_local = (DATA.kappa_coefficient - *(rhob_local/denorm_safe - - rhob_local*rhob_local/std::max(e_local + p_local, small_eps))); + std::max(small_eps, std::abs(3. * T_local * tanh(alpha_local))), + 3. * T_local * tanh(alpha_local)); + double kappa_local = + (DATA.kappa_coefficient + * (rhob_local / denorm_safe + - rhob_local * rhob_local + / std::max(e_local + p_local, small_eps))); // output of << std::scientific << std::setw(18) << std::setprecision(8) - << e_local*hbarc << " " << rhob_local << " " - << T_local*hbarc << " " << mu_B_local*hbarc << " " + << e_local * hbarc << " " << rhob_local << " " + << T_local * hbarc << " " << mu_B_local * hbarc << " " << kappa_local << std::endl; } } of.close(); // close the file } - //! this function outputs the T and muB dependence of the baryon diffusion //! coefficient, kappa_B, along constant s/n_B trajectories void Diss::output_kappa_along_const_sovernB() { music_message.info( - "output kappa_B(T, mu_B) along constant s/n_B trajectories..."); + "output kappa_B(T, mu_B) along constant s/n_B trajectories..."); double sovernB[] = {10.0, 20.0, 30.0, 51.0, 70.0, 94.0, 144.0, 420.0}; - int array_length = sizeof(sovernB)/sizeof(double); - double s_0 = 0.00; // 1/fm^3 - double s_max = 100.0; // 1/fm^3 - double ds = 0.005; // 1/fm^3 - int ns = static_cast((s_max - s_0)/ds) + 1; + int array_length = sizeof(sovernB) / sizeof(double); + double s_0 = 0.00; // 1/fm^3 + double s_max = 100.0; // 1/fm^3 + double ds = 0.005; // 1/fm^3 + int ns = static_cast((s_max - s_0) / ds) + 1; for (int i = 0; i < array_length; i++) { std::ostringstream file_name; file_name << "kappa_B_sovernB_" << sovernB[i] << ".dat"; @@ -840,35 +848,36 @@ void Diss::output_kappa_along_const_sovernB() { of << "# e (GeV/fm^3) rhob (1/fm^3) s (1/fm^3) " << "T (GeV) mu_B (GeV) kappa (1/fm^2)" << std::endl; for (int j = 0; j < ns; j++) { - double s_local = s_0 + j*ds; - double nB_local = s_local/sovernB[i]; + double s_local = s_0 + j * ds; + double nB_local = s_local / sovernB[i]; double e_local = eos.get_s2e(s_local, nB_local); double s_check = eos.get_entropy(e_local, nB_local); double p_local = eos.get_pressure(e_local, nB_local); double temperature = eos.get_temperature(e_local, nB_local); double mu_B = eos.get_muB(e_local, nB_local); - if (mu_B*hbarc > 0.78) + if (mu_B * hbarc > 0.78) continue; // discard points out of the table - double alpha_local = mu_B/temperature; + double alpha_local = mu_B / temperature; double denorm_safe = std::copysign( - std::max(small_eps, std::abs(3.*temperature*tanh(alpha_local))), - 3.*temperature*tanh(alpha_local)); - double kappa_local = (DATA.kappa_coefficient - *(nB_local/denorm_safe - - nB_local*nB_local/std::max(e_local + p_local, small_eps))); + std::max( + small_eps, std::abs(3. * temperature * tanh(alpha_local))), + 3. * temperature * tanh(alpha_local)); + double kappa_local = + (DATA.kappa_coefficient + * (nB_local / denorm_safe + - nB_local * nB_local + / std::max(e_local + p_local, small_eps))); // output of << std::scientific << std::setw(18) << std::setprecision(8) - << e_local*hbarc << " " << nB_local << " " - << s_check << " " - << temperature*hbarc << " " << mu_B*hbarc << " " + << e_local * hbarc << " " << nB_local << " " << s_check + << " " << temperature * hbarc << " " << mu_B * hbarc << " " << kappa_local << std::endl; } of.close(); // close the file } } - //! this function outputs the T and muB dependence of the specific shear //! viscosity eta/s void Diss::output_eta_over_s_T_and_muB_dependence() { @@ -879,22 +888,22 @@ void Diss::output_eta_over_s_T_and_muB_dependence() { << std::endl; // define the grid - double e_min = 1e-5; // fm^-4 - double e_max = 100.0; // fm^-4 - int ne = 1000; - double de = (e_max - e_min)/(ne - 1.); - double rhob_min = 0.0; // fm^-3 + double e_min = 1e-5; // fm^-4 + double e_max = 100.0; // fm^-4 + int ne = 1000; + double de = (e_max - e_min) / (ne - 1.); + double rhob_min = 0.0; // fm^-3 double rhob_max = sqrt(10.0); // fm^-3 - int nrhob = 1000; - double drhob = (rhob_max - rhob_min)/(nrhob - 1.); + int nrhob = 1000; + double drhob = (rhob_max - rhob_min) / (nrhob - 1.); for (int i = 0; i < ne; i++) { - double e_local = e_min + i*de; + double e_local = e_min + i * de; for (int j = 0; j < nrhob; j++) { - double rhob_local = rhob_min + j*drhob; + double rhob_local = rhob_min + j * drhob; rhob_local *= rhob_local; double mu_B_local = eos.get_muB(e_local, rhob_local); - if (mu_B_local*hbarc > 0.89) + if (mu_B_local * hbarc > 0.89) continue; // discard points out of the table double p_local = eos.get_pressure(e_local, rhob_local); double s_local = eos.get_entropy(e_local, rhob_local); @@ -905,20 +914,20 @@ void Diss::output_eta_over_s_T_and_muB_dependence() { double eta_over_s = shear_to_s; if (DATA.muB_dependent_shear_to_s != 0) { - eta_over_s = shear_to_s*(e_local + p_local)/(T_local*s_local); + eta_over_s = + shear_to_s * (e_local + p_local) / (T_local * s_local); } // output of << std::scientific << std::setw(18) << std::setprecision(8) - << e_local*hbarc << " " << rhob_local << " " - << T_local*hbarc << " " << mu_B_local*hbarc << " " + << e_local * hbarc << " " << rhob_local << " " + << T_local * hbarc << " " << mu_B_local * hbarc << " " << eta_over_s << std::endl; } } of.close(); // close the file } - //! this function outputs the T and muB dependence of the specific shear //! viscosity eta/s along constant s/n_B trajectories void Diss::output_eta_over_s_along_const_sovernB() { @@ -926,11 +935,11 @@ void Diss::output_eta_over_s_along_const_sovernB() { "output eta/s(T, mu_B) along constant s/n_B trajectories..."); double sovernB[] = {10.0, 20.0, 30.0, 51.0, 70.0, 94.0, 144.0, 420.0}; - int array_length = sizeof(sovernB)/sizeof(double); - double s_0 = 0.00; // 1/fm^3 - double s_max = 100.0; // 1/fm^3 - double ds = 0.005; // 1/fm^3 - int ns = static_cast((s_max - s_0)/ds) + 1; + int array_length = sizeof(sovernB) / sizeof(double); + double s_0 = 0.00; // 1/fm^3 + double s_max = 100.0; // 1/fm^3 + double ds = 0.005; // 1/fm^3 + int ns = static_cast((s_max - s_0) / ds) + 1; for (int i = 0; i < array_length; i++) { std::ostringstream file_name; file_name << "eta_over_s_sovernB_" << sovernB[i] << ".dat"; @@ -939,11 +948,11 @@ void Diss::output_eta_over_s_along_const_sovernB() { of << "# e (GeV/fm^3) rhob (1/fm^3) s (1/fm^3) " << "T (GeV) mu_B (GeV) eta/s" << std::endl; for (int j = 0; j < ns; j++) { - double s_local = s_0 + j*ds; - double nB_local = s_local/sovernB[i]; + double s_local = s_0 + j * ds; + double nB_local = s_local / sovernB[i]; double e_local = eos.get_s2e(s_local, nB_local); double mu_B = eos.get_muB(e_local, nB_local); - if (mu_B*hbarc > 0.89) + if (mu_B * hbarc > 0.89) continue; // discard points out of the table double p_local = eos.get_pressure(e_local, nB_local); @@ -955,21 +964,20 @@ void Diss::output_eta_over_s_along_const_sovernB() { double eta_over_s = shear_to_s; if (DATA.muB_dependent_shear_to_s != 0) { - eta_over_s = shear_to_s*(e_local + p_local)/(T_local*s_local); + eta_over_s = + shear_to_s * (e_local + p_local) / (T_local * s_local); } // output of << std::scientific << std::setw(18) << std::setprecision(8) - << e_local*hbarc << " " << nB_local << " " - << s_check << " " - << T_local*hbarc << " " << mu_B*hbarc << " " + << e_local * hbarc << " " << nB_local << " " << s_check + << " " << T_local * hbarc << " " << mu_B * hbarc << " " << eta_over_s << std::endl; } of.close(); // close the file } } - //! this function outputs the T and muB dependence of the specific bulk //! viscosity zeta/s void Diss::output_zeta_over_s_T_and_muB_dependence() { @@ -980,22 +988,22 @@ void Diss::output_zeta_over_s_T_and_muB_dependence() { << std::endl; // define the grid - double e_min = 1e-5; // fm^-4 - double e_max = 100.0; // fm^-4 - int ne = 1000; - double de = (e_max - e_min)/(ne - 1.); - double rhob_min = 0.0; // fm^-3 + double e_min = 1e-5; // fm^-4 + double e_max = 100.0; // fm^-4 + int ne = 1000; + double de = (e_max - e_min) / (ne - 1.); + double rhob_min = 0.0; // fm^-3 double rhob_max = sqrt(10.0); // fm^-3 - int nrhob = 1000; - double drhob = (rhob_max - rhob_min)/(nrhob - 1.); + int nrhob = 1000; + double drhob = (rhob_max - rhob_min) / (nrhob - 1.); for (int i = 0; i < ne; i++) { - double e_local = e_min + i*de; + double e_local = e_min + i * de; for (int j = 0; j < nrhob; j++) { - double rhob_local = rhob_min + j*drhob; + double rhob_local = rhob_min + j * drhob; rhob_local *= rhob_local; double mu_B_local = eos.get_muB(e_local, rhob_local); - if (mu_B_local*hbarc > 0.89) + if (mu_B_local * hbarc > 0.89) continue; // discard points out of the table double p_local = eos.get_pressure(e_local, rhob_local); double s_local = eos.get_entropy(e_local, rhob_local); @@ -1003,19 +1011,19 @@ void Diss::output_zeta_over_s_T_and_muB_dependence() { double mu_B = eos.get_muB(e_local, rhob_local); double bulk = transport_coeffs_.get_zeta_over_s(T_local, mu_B); - double zeta_over_s = bulk*(e_local + p_local)/(T_local*s_local); + double zeta_over_s = + bulk * (e_local + p_local) / (T_local * s_local); // output of << std::scientific << std::setw(18) << std::setprecision(8) - << e_local*hbarc << " " << rhob_local << " " - << T_local*hbarc << " " << mu_B_local*hbarc << " " + << e_local * hbarc << " " << rhob_local << " " + << T_local * hbarc << " " << mu_B_local * hbarc << " " << zeta_over_s << std::endl; } } of.close(); // close the file } - //! this function outputs the T and muB dependence of the specific bulk //! viscosity zeta/s along constant s/n_B trajectories void Diss::output_zeta_over_s_along_const_sovernB() { @@ -1023,11 +1031,11 @@ void Diss::output_zeta_over_s_along_const_sovernB() { "output zeta/s(T, mu_B) along constant s/n_B trajectories..."); double sovernB[] = {10.0, 20.0, 30.0, 51.0, 70.0, 94.0, 144.0, 420.0}; - int array_length = sizeof(sovernB)/sizeof(double); - double s_0 = 0.00; // 1/fm^3 - double s_max = 100.0; // 1/fm^3 - double ds = 0.005; // 1/fm^3 - int ns = static_cast((s_max - s_0)/ds) + 1; + int array_length = sizeof(sovernB) / sizeof(double); + double s_0 = 0.00; // 1/fm^3 + double s_max = 100.0; // 1/fm^3 + double ds = 0.005; // 1/fm^3 + int ns = static_cast((s_max - s_0) / ds) + 1; for (int i = 0; i < array_length; i++) { std::ostringstream file_name; file_name << "zeta_over_s_sovernB_" << sovernB[i] << ".dat"; @@ -1036,11 +1044,11 @@ void Diss::output_zeta_over_s_along_const_sovernB() { of << "# e (GeV/fm^3) rhob (1/fm^3) s (1/fm^3) " << "T (GeV) mu_B (GeV) eta/s" << std::endl; for (int j = 0; j < ns; j++) { - double s_local = s_0 + j*ds; - double nB_local = s_local/sovernB[i]; + double s_local = s_0 + j * ds; + double nB_local = s_local / sovernB[i]; double e_local = eos.get_s2e(s_local, nB_local); double mu_B = eos.get_muB(e_local, nB_local); - if (mu_B*hbarc > 0.89) + if (mu_B * hbarc > 0.89) continue; // discard points out of the table double T_local = eos.get_temperature(e_local, nB_local); @@ -1048,13 +1056,13 @@ void Diss::output_zeta_over_s_along_const_sovernB() { double s_check = eos.get_entropy(e_local, nB_local); double bulk = transport_coeffs_.get_zeta_over_s(T_local, mu_B); - double zeta_over_s = bulk*(e_local + p_local)/(T_local*s_local); + double zeta_over_s = + bulk * (e_local + p_local) / (T_local * s_local); // output of << std::scientific << std::setw(18) << std::setprecision(8) - << e_local*hbarc << " " << nB_local << " " - << s_check << " " - << T_local*hbarc << " " << mu_B*hbarc << " " + << e_local * hbarc << " " << nB_local << " " << s_check + << " " << T_local * hbarc << " " << mu_B * hbarc << " " << zeta_over_s << std::endl; } of.close(); // close the file diff --git a/src/dissipative.h b/src/dissipative.h index 4ebb8885..56549bb5 100644 --- a/src/dissipative.h +++ b/src/dissipative.h @@ -3,64 +3,64 @@ #define SRC_DISSIPATIVE_H_ #include -#include "util.h" + #include "cell.h" #include "data.h" +#include "eos.h" #include "fields.h" -#include "transport_coeffs.h" #include "minmod.h" #include "pretty_ostream.h" +#include "transport_coeffs.h" +#include "util.h" class Diss { - private: + private: const InitData &DATA; const EOS &eos; const Minmod minmod; TransportCoeffs transport_coeffs_; int map_2d_idx_to_1d(int a, int b) { - static const int index_map[5][4] = {{0, 1, 2, 3}, - {1, 4, 5, 6}, - {2, 5, 7, 8}, - {3, 6, 8, 9}, - {10, 11, 12, 13}}; + static const int index_map[5][4] = { + {0, 1, 2, 3}, + {1, 4, 5, 6}, + {2, 5, 7, 8}, + {3, 6, 8, 9}, + {10, 11, 12, 13}}; return index_map[a][b]; } pretty_ostream music_message; - public: + public: Diss(const EOS &eosIn, const InitData &DATA_in); - void MakeWSource(const double tau, - const int ix, const int iy, const int ieta, TJbVec &dwmn, - Fields &arenaFieldsCurr, Fields &arenaFieldsPrev, - const int fieldIdx); + void MakeWSource( + const double tau, const int ix, const int iy, const int ieta, + TJbVec &dwmn, Fields &arenaFieldsCurr, Fields &arenaFieldsPrev, + const int fieldIdx); - void Make_uWSource(const double tau, const Cell_small &grid_pt, - const double theta_local, const DumuVec &a_local, - const VelocityShearVec &sigma_1d, - const VorticityVec &omega_1d, - const std::vector &thermalVec, - std::array &sourceTerms); + void Make_uWSource( + const double tau, const Cell_small &grid_pt, const double theta_local, + const DumuVec &a_local, const VelocityShearVec &sigma_1d, + const VorticityVec &omega_1d, const std::vector &thermalVec, + std::array &sourceTerms); - void Make_uWRHS(const double tau, Fields &arena, - const int fieldIdx, - const int ix, const int iy, const int ieta, - std::array &w_rhs, - const double theta_local, const DumuVec &a_local); + void Make_uWRHS( + const double tau, Fields &arena, const int fieldIdx, const int ix, + const int iy, const int ieta, std::array &w_rhs, + const double theta_local, const DumuVec &a_local); - double Make_uPiSource(const double tau, const Cell_small &grid_pt, - const double theta_local, - const VelocityShearVec &sigma_1d, - const std::vector &thermalVec); + double Make_uPiSource( + const double tau, const Cell_small &grid_pt, const double theta_local, + const VelocityShearVec &sigma_1d, + const std::vector &thermalVec); - void Make_uqSource(const double tau, const Cell_small &grid_pt, - const double theta_local, - const DumuVec &a_local, - const VelocityShearVec &sigma_1d, - const VorticityVec &omega_1d, - const DmuMuBoverTVec &baryon_diffusion_vec, - const std::vector &thermalVec, - std::array &sourceTerms); + void Make_uqSource( + const double tau, const Cell_small &grid_pt, const double theta_local, + const DumuVec &a_local, const VelocityShearVec &sigma_1d, + const VorticityVec &omega_1d, + const DmuMuBoverTVec &baryon_diffusion_vec, + const std::vector &thermalVec, + std::array &sourceTerms); void output_kappa_T_and_muB_dependence(); void output_kappa_along_const_sovernB(); diff --git a/src/doctest.h b/src/doctest.h index 342705d4..3733f4c5 100644 --- a/src/doctest.h +++ b/src/doctest.h @@ -2,7 +2,8 @@ // == DO NOT MODIFY THIS FILE BY HAND - IT IS AUTO GENERATED BY CMAKE! == // ====================================================================== // -// doctest.h - the lightest feature-rich C++ single-header testing framework for unit tests and TDD +// doctest.h - the lightest feature-rich C++ single-header testing framework for +// unit tests and TDD // // Copyright (c) 2016-2018 Viktor Kirilov // @@ -17,22 +18,25 @@ // ================================================================================================= // ================================================================================================= // -// The library is heavily influenced by Catch - https://github.com/philsquared/Catch -// which uses the Boost Software License - Version 1.0 -// see here - https://github.com/philsquared/Catch/blob/master/LICENSE.txt +// The library is heavily influenced by Catch - +// https://github.com/philsquared/Catch which uses the Boost Software License - +// Version 1.0 see here - +// https://github.com/philsquared/Catch/blob/master/LICENSE.txt // -// The concept of subcases (sections in Catch) and expression decomposition are from there. -// Some parts of the code are taken directly: -// - stringification - the detection of "ostream& operator<<(ostream&, const T&)" and StringMaker<> +// The concept of subcases (sections in Catch) and expression decomposition are +// from there. Some parts of the code are taken directly: +// - stringification - the detection of "ostream& operator<<(ostream&, const +// T&)" and StringMaker<> // - the Approx() helper class for floating point comparison // - colors in the console // - breaking into a debugger // - signal / SEH handling // - timer // -// The expression decomposing templates are taken from lest - https://github.com/martinmoene/lest -// which uses the Boost Software License - Version 1.0 -// see here - https://github.com/martinmoene/lest/blob/master/LICENSE.txt +// The expression decomposing templates are taken from lest - +// https://github.com/martinmoene/lest which uses the Boost Software License - +// Version 1.0 see here - +// https://github.com/martinmoene/lest/blob/master/LICENSE.txt // // The type list and the foreach algorithm on it for C++98 are taken from Loki // - http://loki-lib.sourceforge.net/ @@ -48,7 +52,8 @@ #define DOCTEST_LIBRARY_INCLUDED // ================================================================================================= -// == VERSION ====================================================================================== +// == VERSION +// ====================================================================================== // ================================================================================================= #define DOCTEST_VERSION_MAJOR 1 @@ -56,62 +61,74 @@ #define DOCTEST_VERSION_PATCH 7 #define DOCTEST_VERSION_STR "1.2.7" -#define DOCTEST_VERSION \ - (DOCTEST_VERSION_MAJOR * 10000 + DOCTEST_VERSION_MINOR * 100 + DOCTEST_VERSION_PATCH) +#define DOCTEST_VERSION \ + (DOCTEST_VERSION_MAJOR * 10000 + DOCTEST_VERSION_MINOR * 100 \ + + DOCTEST_VERSION_PATCH) // ================================================================================================= -// == COMPILER VERSION ============================================================================= +// == COMPILER VERSION +// ============================================================================= // ================================================================================================= -// ideas for the version stuff are taken from here: https://github.com/cxxstuff/cxx_detect +// ideas for the version stuff are taken from here: +// https://github.com/cxxstuff/cxx_detect -#define DOCTEST_COMPILER(MAJOR, MINOR, PATCH) ((MAJOR)*10000000 + (MINOR)*100000 + (PATCH)) +#define DOCTEST_COMPILER(MAJOR, MINOR, PATCH) \ + ((MAJOR) * 10000000 + (MINOR) * 100000 + (PATCH)) #if defined(_MSC_VER) && defined(_MSC_FULL_VER) #if _MSC_VER == _MSC_FULL_VER / 10000 -#define DOCTEST_MSVC DOCTEST_COMPILER(_MSC_VER / 100, _MSC_VER % 100, _MSC_FULL_VER % 10000) +#define DOCTEST_MSVC \ + DOCTEST_COMPILER(_MSC_VER / 100, _MSC_VER % 100, _MSC_FULL_VER % 10000) #else -#define DOCTEST_MSVC \ - DOCTEST_COMPILER(_MSC_VER / 100, (_MSC_FULL_VER / 100000) % 100, _MSC_FULL_VER % 100000) +#define DOCTEST_MSVC \ + DOCTEST_COMPILER( \ + _MSC_VER / 100, (_MSC_FULL_VER / 100000) % 100, \ + _MSC_FULL_VER % 100000) #endif #elif defined(__clang__) && defined(__clang_minor__) -#define DOCTEST_CLANG DOCTEST_COMPILER(__clang_major__, __clang_minor__, __clang_patchlevel__) -#elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) -#define DOCTEST_GCC DOCTEST_COMPILER(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) +#define DOCTEST_CLANG \ + DOCTEST_COMPILER(__clang_major__, __clang_minor__, __clang_patchlevel__) +#elif defined(__GNUC__) && defined(__GNUC_MINOR__) \ + && defined(__GNUC_PATCHLEVEL__) +#define DOCTEST_GCC \ + DOCTEST_COMPILER(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) #endif #ifndef DOCTEST_MSVC #define DOCTEST_MSVC 0 -#endif // DOCTEST_MSVC +#endif // DOCTEST_MSVC #ifndef DOCTEST_CLANG #define DOCTEST_CLANG 0 -#endif // DOCTEST_CLANG +#endif // DOCTEST_CLANG #ifndef DOCTEST_GCC #define DOCTEST_GCC 0 -#endif // DOCTEST_GCC +#endif // DOCTEST_GCC // ================================================================================================= -// == COMPILER WARNINGS HELPERS ==================================================================== +// == COMPILER WARNINGS HELPERS +// ==================================================================== // ================================================================================================= #if DOCTEST_CLANG #ifdef __has_warning #define DOCTEST_CLANG_HAS_WARNING(x) __has_warning(x) -#endif // __has_warning +#endif // __has_warning #ifdef __has_feature #define DOCTEST_CLANG_HAS_FEATURE(x) __has_feature(x) -#endif // __has_feature +#endif // __has_feature #define DOCTEST_PRAGMA_TO_STR(x) _Pragma(#x) #define DOCTEST_CLANG_SUPPRESS_WARNING_PUSH _Pragma("clang diagnostic push") #define DOCTEST_MSVC_SUPPRESS_WARNING_PUSH #define DOCTEST_GCC_SUPPRESS_WARNING_PUSH -#define DOCTEST_CLANG_SUPPRESS_WARNING(w) DOCTEST_PRAGMA_TO_STR(clang diagnostic ignored w) +#define DOCTEST_CLANG_SUPPRESS_WARNING(w) \ + DOCTEST_PRAGMA_TO_STR(clang diagnostic ignored w) #define DOCTEST_MSVC_SUPPRESS_WARNING(w) #define DOCTEST_GCC_SUPPRESS_WARNING(w) #define DOCTEST_CLANG_SUPPRESS_WARNING_POP _Pragma("clang diagnostic pop") #define DOCTEST_MSVC_SUPPRESS_WARNING_POP #define DOCTEST_GCC_SUPPRESS_WARNING_POP -#define DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH(w) \ +#define DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH(w) \ DOCTEST_CLANG_SUPPRESS_WARNING_PUSH DOCTEST_CLANG_SUPPRESS_WARNING(w) #define DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(w) #define DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH(w) @@ -121,22 +138,23 @@ #define DOCTEST_MSVC_SUPPRESS_WARNING_PUSH #if DOCTEST_GCC >= DOCTEST_COMPILER(4, 7, 0) #define DOCTEST_GCC_SUPPRESS_WARNING_PUSH _Pragma("GCC diagnostic push") -#else // GCC 4.7+ +#else // GCC 4.7+ #define DOCTEST_GCC_SUPPRESS_WARNING_PUSH -#endif // GCC 4.7+ +#endif // GCC 4.7+ #define DOCTEST_CLANG_SUPPRESS_WARNING(w) #define DOCTEST_MSVC_SUPPRESS_WARNING(w) -#define DOCTEST_GCC_SUPPRESS_WARNING(w) DOCTEST_PRAGMA_TO_STR(GCC diagnostic ignored w) +#define DOCTEST_GCC_SUPPRESS_WARNING(w) \ + DOCTEST_PRAGMA_TO_STR(GCC diagnostic ignored w) #define DOCTEST_CLANG_SUPPRESS_WARNING_POP #define DOCTEST_MSVC_SUPPRESS_WARNING_POP #if DOCTEST_GCC >= DOCTEST_COMPILER(4, 7, 0) #define DOCTEST_GCC_SUPPRESS_WARNING_POP _Pragma("GCC diagnostic pop") -#else // GCC 4.7+ +#else // GCC 4.7+ #define DOCTEST_GCC_SUPPRESS_WARNING_POP -#endif // GCC 4.7+ +#endif // GCC 4.7+ #define DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH(w) #define DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(w) -#define DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH(w) \ +#define DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH(w) \ DOCTEST_GCC_SUPPRESS_WARNING_PUSH DOCTEST_GCC_SUPPRESS_WARNING(w) #elif DOCTEST_MSVC #define DOCTEST_PRAGMA_TO_STR(x) @@ -150,21 +168,22 @@ #define DOCTEST_MSVC_SUPPRESS_WARNING_POP __pragma(warning(pop)) #define DOCTEST_GCC_SUPPRESS_WARNING_POP #define DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH(w) -#define DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(w) \ +#define DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(w) \ DOCTEST_MSVC_SUPPRESS_WARNING_PUSH DOCTEST_MSVC_SUPPRESS_WARNING(w) #define DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH(w) -#endif // different compilers - warning suppression macros +#endif // different compilers - warning suppression macros #ifndef DOCTEST_CLANG_HAS_WARNING #define DOCTEST_CLANG_HAS_WARNING(x) 1 -#endif // DOCTEST_CLANG_HAS_WARNING +#endif // DOCTEST_CLANG_HAS_WARNING #ifndef DOCTEST_CLANG_HAS_FEATURE #define DOCTEST_CLANG_HAS_FEATURE(x) 0 -#endif // DOCTEST_CLANG_HAS_FEATURE +#endif // DOCTEST_CLANG_HAS_FEATURE // ================================================================================================= -// == COMPILER WARNINGS ============================================================================ +// == COMPILER WARNINGS +// ============================================================================ // ================================================================================================= DOCTEST_CLANG_SUPPRESS_WARNING_PUSH @@ -176,9 +195,10 @@ DOCTEST_CLANG_SUPPRESS_WARNING("-Wdeprecated") DOCTEST_CLANG_SUPPRESS_WARNING("-Wmissing-prototypes") DOCTEST_CLANG_SUPPRESS_WARNING("-Wunused-local-typedef") DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++11-long-long") -#if DOCTEST_CLANG && DOCTEST_CLANG_HAS_WARNING("-Wzero-as-null-pointer-constant") +#if DOCTEST_CLANG \ + && DOCTEST_CLANG_HAS_WARNING("-Wzero-as-null-pointer-constant") DOCTEST_CLANG_SUPPRESS_WARNING("-Wzero-as-null-pointer-constant") -#endif // clang - 0 as null +#endif // clang - 0 as null DOCTEST_GCC_SUPPRESS_WARNING_PUSH DOCTEST_GCC_SUPPRESS_WARNING("-Wunknown-pragmas") @@ -192,36 +212,44 @@ DOCTEST_GCC_SUPPRESS_WARNING("-Winline") DOCTEST_GCC_SUPPRESS_WARNING("-Wlong-long") #if DOCTEST_GCC >= DOCTEST_COMPILER(4, 7, 0) DOCTEST_GCC_SUPPRESS_WARNING("-Wzero-as-null-pointer-constant") -#endif // GCC 4.7+ +#endif // GCC 4.7+ #if DOCTEST_GCC >= DOCTEST_COMPILER(4, 8, 0) DOCTEST_GCC_SUPPRESS_WARNING("-Wunused-local-typedefs") -#endif // GCC 4.8+ +#endif // GCC 4.8+ #if DOCTEST_GCC >= DOCTEST_COMPILER(5, 4, 0) DOCTEST_GCC_SUPPRESS_WARNING("-Wuseless-cast") -#endif // GCC 5.4+ +#endif // GCC 5.4+ DOCTEST_MSVC_SUPPRESS_WARNING_PUSH -DOCTEST_MSVC_SUPPRESS_WARNING(4616) // invalid compiler warning -DOCTEST_MSVC_SUPPRESS_WARNING(4619) // invalid compiler warning -DOCTEST_MSVC_SUPPRESS_WARNING(4996) // The compiler encountered a deprecated declaration -DOCTEST_MSVC_SUPPRESS_WARNING(4706) // assignment within conditional expression -DOCTEST_MSVC_SUPPRESS_WARNING(4512) // 'class' : assignment operator could not be generated -DOCTEST_MSVC_SUPPRESS_WARNING(4127) // conditional expression is constant -DOCTEST_MSVC_SUPPRESS_WARNING(4820) // padding -DOCTEST_MSVC_SUPPRESS_WARNING(4625) // copy constructor was implicitly defined as deleted -DOCTEST_MSVC_SUPPRESS_WARNING(4626) // assignment operator was implicitly defined as deleted -DOCTEST_MSVC_SUPPRESS_WARNING(5027) // move assignment operator was implicitly defined as deleted -DOCTEST_MSVC_SUPPRESS_WARNING(5026) // move constructor was implicitly defined as deleted -DOCTEST_MSVC_SUPPRESS_WARNING(4623) // default constructor was implicitly defined as deleted -DOCTEST_MSVC_SUPPRESS_WARNING(4640) // construction of local static object is not thread-safe - -// C4548 - expression before comma has no effect; expected expression with side - effect -// C4986 - exception specification does not match previous declaration +DOCTEST_MSVC_SUPPRESS_WARNING(4616) // invalid compiler warning +DOCTEST_MSVC_SUPPRESS_WARNING(4619) // invalid compiler warning +DOCTEST_MSVC_SUPPRESS_WARNING( + 4996) // The compiler encountered a deprecated declaration +DOCTEST_MSVC_SUPPRESS_WARNING(4706) // assignment within conditional expression +DOCTEST_MSVC_SUPPRESS_WARNING( + 4512) // 'class' : assignment operator could not be generated +DOCTEST_MSVC_SUPPRESS_WARNING(4127) // conditional expression is constant +DOCTEST_MSVC_SUPPRESS_WARNING(4820) // padding +DOCTEST_MSVC_SUPPRESS_WARNING( + 4625) // copy constructor was implicitly defined as deleted +DOCTEST_MSVC_SUPPRESS_WARNING( + 4626) // assignment operator was implicitly defined as deleted +DOCTEST_MSVC_SUPPRESS_WARNING( + 5027) // move assignment operator was implicitly defined as deleted +DOCTEST_MSVC_SUPPRESS_WARNING( + 5026) // move constructor was implicitly defined as deleted +DOCTEST_MSVC_SUPPRESS_WARNING( + 4623) // default constructor was implicitly defined as deleted +DOCTEST_MSVC_SUPPRESS_WARNING( + 4640) // construction of local static object is not thread-safe + +// C4548 - expression before comma has no effect; expected expression with side +// - effect C4986 - exception specification does not match previous declaration // C4350 - behavior change: 'member1' called instead of 'member2' -// C4668 - 'x' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' -// C4365 - conversion from 'int' to 'unsigned long', signed/unsigned mismatch -// C4774 - format string expected in argument 'x' is not a string literal -// C4820 - padding in structs +// C4668 - 'x' is not defined as a preprocessor macro, replacing with '0' for +// '#if/#elif' C4365 - conversion from 'int' to 'unsigned long', signed/unsigned +// mismatch C4774 - format string expected in argument 'x' is not a string +// literal C4820 - padding in structs // only 4 should be disabled globally: // - C4514 # unreferenced inline function has been removed @@ -229,278 +257,298 @@ DOCTEST_MSVC_SUPPRESS_WARNING(4640) // construction of local static object is no // - C4710 # function not inlined // - C4711 # function 'x' selected for automatic inline expansion -#define DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_BEGIN \ - DOCTEST_MSVC_SUPPRESS_WARNING_PUSH \ - DOCTEST_MSVC_SUPPRESS_WARNING(4548) \ - DOCTEST_MSVC_SUPPRESS_WARNING(4986) \ - DOCTEST_MSVC_SUPPRESS_WARNING(4350) \ - DOCTEST_MSVC_SUPPRESS_WARNING(4668) \ - DOCTEST_MSVC_SUPPRESS_WARNING(4365) \ - DOCTEST_MSVC_SUPPRESS_WARNING(4774) \ - DOCTEST_MSVC_SUPPRESS_WARNING(4820) \ - DOCTEST_MSVC_SUPPRESS_WARNING(4625) \ - DOCTEST_MSVC_SUPPRESS_WARNING(4626) \ - DOCTEST_MSVC_SUPPRESS_WARNING(5027) \ - DOCTEST_MSVC_SUPPRESS_WARNING(5026) \ - DOCTEST_MSVC_SUPPRESS_WARNING(4623) \ +#define DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_BEGIN \ + DOCTEST_MSVC_SUPPRESS_WARNING_PUSH \ + DOCTEST_MSVC_SUPPRESS_WARNING(4548) \ + DOCTEST_MSVC_SUPPRESS_WARNING(4986) \ + DOCTEST_MSVC_SUPPRESS_WARNING(4350) \ + DOCTEST_MSVC_SUPPRESS_WARNING(4668) \ + DOCTEST_MSVC_SUPPRESS_WARNING(4365) \ + DOCTEST_MSVC_SUPPRESS_WARNING(4774) \ + DOCTEST_MSVC_SUPPRESS_WARNING(4820) \ + DOCTEST_MSVC_SUPPRESS_WARNING(4625) \ + DOCTEST_MSVC_SUPPRESS_WARNING(4626) \ + DOCTEST_MSVC_SUPPRESS_WARNING(5027) \ + DOCTEST_MSVC_SUPPRESS_WARNING(5026) \ + DOCTEST_MSVC_SUPPRESS_WARNING(4623) \ DOCTEST_MSVC_SUPPRESS_WARNING(5039) -#define DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_END DOCTEST_MSVC_SUPPRESS_WARNING_POP +#define DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_END \ + DOCTEST_MSVC_SUPPRESS_WARNING_POP // ================================================================================================= -// == FEATURE DETECTION ============================================================================ +// == FEATURE DETECTION +// ============================================================================ // ================================================================================================= #if __cplusplus >= 201103L #ifndef DOCTEST_CONFIG_WITH_DELETED_FUNCTIONS #define DOCTEST_CONFIG_WITH_DELETED_FUNCTIONS -#endif // DOCTEST_CONFIG_WITH_DELETED_FUNCTIONS +#endif // DOCTEST_CONFIG_WITH_DELETED_FUNCTIONS #ifndef DOCTEST_CONFIG_WITH_RVALUE_REFERENCES #define DOCTEST_CONFIG_WITH_RVALUE_REFERENCES -#endif // DOCTEST_CONFIG_WITH_RVALUE_REFERENCES +#endif // DOCTEST_CONFIG_WITH_RVALUE_REFERENCES #ifndef DOCTEST_CONFIG_WITH_NULLPTR #define DOCTEST_CONFIG_WITH_NULLPTR -#endif // DOCTEST_CONFIG_WITH_NULLPTR +#endif // DOCTEST_CONFIG_WITH_NULLPTR #ifndef DOCTEST_CONFIG_WITH_LONG_LONG #define DOCTEST_CONFIG_WITH_LONG_LONG -#endif // DOCTEST_CONFIG_WITH_LONG_LONG +#endif // DOCTEST_CONFIG_WITH_LONG_LONG #ifndef DOCTEST_CONFIG_WITH_STATIC_ASSERT #define DOCTEST_CONFIG_WITH_STATIC_ASSERT -#endif // DOCTEST_CONFIG_WITH_STATIC_ASSERT +#endif // DOCTEST_CONFIG_WITH_STATIC_ASSERT #ifndef DOCTEST_CONFIG_WITH_VARIADIC_MACROS #define DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#endif // __cplusplus >= 201103L - -// MSVC C++11 feature support table: https://msdn.microsoft.com/en-us/library/hh567368.aspx -// GCC C++11 feature support table: https://gcc.gnu.org/projects/cxx-status.html -// MSVC version table: -// MSVC++ 15.0 _MSC_VER == 1910 (Visual Studio 2017) -// MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015) -// MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013) -// MSVC++ 11.0 _MSC_VER == 1700 (Visual Studio 2012) -// MSVC++ 10.0 _MSC_VER == 1600 (Visual Studio 2010) -// MSVC++ 9.0 _MSC_VER == 1500 (Visual Studio 2008) -// MSVC++ 8.0 _MSC_VER == 1400 (Visual Studio 2005) +#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#endif // __cplusplus >= 201103L + +// MSVC C++11 feature support table: +// https://msdn.microsoft.com/en-us/library/hh567368.aspx GCC C++11 feature +// support table: https://gcc.gnu.org/projects/cxx-status.html MSVC version +// table: MSVC++ 15.0 _MSC_VER == 1910 (Visual Studio 2017) MSVC++ 14.0 _MSC_VER +// == 1900 (Visual Studio 2015) MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio +// 2013) MSVC++ 11.0 _MSC_VER == 1700 (Visual Studio 2012) MSVC++ 10.0 _MSC_VER +// == 1600 (Visual Studio 2010) MSVC++ 9.0 _MSC_VER == 1500 (Visual Studio +// 2008) MSVC++ 8.0 _MSC_VER == 1400 (Visual Studio 2005) // deleted functions #ifndef DOCTEST_CONFIG_WITH_DELETED_FUNCTIONS #if DOCTEST_MSVC >= DOCTEST_COMPILER(18, 0, 0) #define DOCTEST_CONFIG_WITH_DELETED_FUNCTIONS -#endif // MSVC +#endif // MSVC #if DOCTEST_CLANG && DOCTEST_CLANG_HAS_FEATURE(cxx_deleted_functions) #define DOCTEST_CONFIG_WITH_DELETED_FUNCTIONS -#endif // clang -#if DOCTEST_GCC >= DOCTEST_COMPILER(4, 5, 0) && defined(__GXX_EXPERIMENTAL_CXX0X__) +#endif // clang +#if DOCTEST_GCC >= DOCTEST_COMPILER(4, 5, 0) \ + && defined(__GXX_EXPERIMENTAL_CXX0X__) #define DOCTEST_CONFIG_WITH_DELETED_FUNCTIONS -#endif // GCC -#endif // DOCTEST_CONFIG_WITH_DELETED_FUNCTIONS +#endif // GCC +#endif // DOCTEST_CONFIG_WITH_DELETED_FUNCTIONS -#if defined(DOCTEST_CONFIG_NO_DELETED_FUNCTIONS) && defined(DOCTEST_CONFIG_WITH_DELETED_FUNCTIONS) +#if defined(DOCTEST_CONFIG_NO_DELETED_FUNCTIONS) \ + && defined(DOCTEST_CONFIG_WITH_DELETED_FUNCTIONS) #undef DOCTEST_CONFIG_WITH_DELETED_FUNCTIONS -#endif // DOCTEST_CONFIG_NO_DELETED_FUNCTIONS +#endif // DOCTEST_CONFIG_NO_DELETED_FUNCTIONS // rvalue references #ifndef DOCTEST_CONFIG_WITH_RVALUE_REFERENCES #if DOCTEST_MSVC >= DOCTEST_COMPILER(16, 0, 0) #define DOCTEST_CONFIG_WITH_RVALUE_REFERENCES -#endif // MSVC +#endif // MSVC #if DOCTEST_CLANG && DOCTEST_CLANG_HAS_FEATURE(cxx_rvalue_references) #define DOCTEST_CONFIG_WITH_RVALUE_REFERENCES -#endif // clang -#if DOCTEST_GCC >= DOCTEST_COMPILER(4, 3, 0) && defined(__GXX_EXPERIMENTAL_CXX0X__) +#endif // clang +#if DOCTEST_GCC >= DOCTEST_COMPILER(4, 3, 0) \ + && defined(__GXX_EXPERIMENTAL_CXX0X__) #define DOCTEST_CONFIG_WITH_RVALUE_REFERENCES -#endif // GCC -#endif // DOCTEST_CONFIG_WITH_RVALUE_REFERENCES +#endif // GCC +#endif // DOCTEST_CONFIG_WITH_RVALUE_REFERENCES -#if defined(DOCTEST_CONFIG_NO_RVALUE_REFERENCES) && defined(DOCTEST_CONFIG_WITH_RVALUE_REFERENCES) +#if defined(DOCTEST_CONFIG_NO_RVALUE_REFERENCES) \ + && defined(DOCTEST_CONFIG_WITH_RVALUE_REFERENCES) #undef DOCTEST_CONFIG_WITH_RVALUE_REFERENCES -#endif // DOCTEST_CONFIG_NO_RVALUE_REFERENCES +#endif // DOCTEST_CONFIG_NO_RVALUE_REFERENCES // nullptr #ifndef DOCTEST_CONFIG_WITH_NULLPTR #if DOCTEST_CLANG && DOCTEST_CLANG_HAS_FEATURE(cxx_nullptr) #define DOCTEST_CONFIG_WITH_NULLPTR -#endif // clang -#if DOCTEST_GCC >= DOCTEST_COMPILER(4, 6, 0) && defined(__GXX_EXPERIMENTAL_CXX0X__) +#endif // clang +#if DOCTEST_GCC >= DOCTEST_COMPILER(4, 6, 0) \ + && defined(__GXX_EXPERIMENTAL_CXX0X__) #define DOCTEST_CONFIG_WITH_NULLPTR -#endif // GCC +#endif // GCC #if DOCTEST_MSVC >= DOCTEST_COMPILER(16, 0, 0) #define DOCTEST_CONFIG_WITH_NULLPTR -#endif // MSVC -#endif // DOCTEST_CONFIG_WITH_NULLPTR +#endif // MSVC +#endif // DOCTEST_CONFIG_WITH_NULLPTR #if defined(DOCTEST_CONFIG_NO_NULLPTR) && defined(DOCTEST_CONFIG_WITH_NULLPTR) #undef DOCTEST_CONFIG_WITH_NULLPTR -#endif // DOCTEST_CONFIG_NO_NULLPTR +#endif // DOCTEST_CONFIG_NO_NULLPTR // variadic macros #ifndef DOCTEST_CONFIG_WITH_VARIADIC_MACROS #if DOCTEST_MSVC >= DOCTEST_COMPILER(14, 0, 0) && !defined(__EDGE__) #define DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#endif // MSVC -#if(DOCTEST_CLANG || DOCTEST_GCC >= DOCTEST_COMPILER(4, 1, 0)) && \ - defined(__GXX_EXPERIMENTAL_CXX0X__) +#endif // MSVC +#if (DOCTEST_CLANG || DOCTEST_GCC >= DOCTEST_COMPILER(4, 1, 0)) \ + && defined(__GXX_EXPERIMENTAL_CXX0X__) #define DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#endif // GCC and clang -#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#endif // GCC and clang +#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#if defined(DOCTEST_CONFIG_NO_VARIADIC_MACROS) && defined(DOCTEST_CONFIG_WITH_VARIADIC_MACROS) +#if defined(DOCTEST_CONFIG_NO_VARIADIC_MACROS) \ + && defined(DOCTEST_CONFIG_WITH_VARIADIC_MACROS) #undef DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#endif // DOCTEST_CONFIG_NO_VARIADIC_MACROS +#endif // DOCTEST_CONFIG_NO_VARIADIC_MACROS // long long #ifndef DOCTEST_CONFIG_WITH_LONG_LONG #if DOCTEST_MSVC >= DOCTEST_COMPILER(14, 0, 0) #define DOCTEST_CONFIG_WITH_LONG_LONG -#endif // MSVC -#if(DOCTEST_CLANG || DOCTEST_GCC >= DOCTEST_COMPILER(4, 5, 0)) && \ - defined(__GXX_EXPERIMENTAL_CXX0X__) +#endif // MSVC +#if (DOCTEST_CLANG || DOCTEST_GCC >= DOCTEST_COMPILER(4, 5, 0)) \ + && defined(__GXX_EXPERIMENTAL_CXX0X__) #define DOCTEST_CONFIG_WITH_LONG_LONG -#endif // GCC and clang -#endif // DOCTEST_CONFIG_WITH_LONG_LONG +#endif // GCC and clang +#endif // DOCTEST_CONFIG_WITH_LONG_LONG -#if defined(DOCTEST_CONFIG_NO_LONG_LONG) && defined(DOCTEST_CONFIG_WITH_LONG_LONG) +#if defined(DOCTEST_CONFIG_NO_LONG_LONG) \ + && defined(DOCTEST_CONFIG_WITH_LONG_LONG) #undef DOCTEST_CONFIG_WITH_LONG_LONG -#endif // DOCTEST_CONFIG_NO_LONG_LONG +#endif // DOCTEST_CONFIG_NO_LONG_LONG // static_assert #ifndef DOCTEST_CONFIG_WITH_STATIC_ASSERT #if DOCTEST_CLANG && DOCTEST_CLANG_HAS_FEATURE(cxx_static_assert) #define DOCTEST_CONFIG_WITH_STATIC_ASSERT -#endif // clang -#if DOCTEST_GCC >= DOCTEST_COMPILER(4, 3, 0) && defined(__GXX_EXPERIMENTAL_CXX0X__) +#endif // clang +#if DOCTEST_GCC >= DOCTEST_COMPILER(4, 3, 0) \ + && defined(__GXX_EXPERIMENTAL_CXX0X__) #define DOCTEST_CONFIG_WITH_STATIC_ASSERT -#endif // GCC +#endif // GCC #if DOCTEST_MSVC >= DOCTEST_COMPILER(16, 0, 0) #define DOCTEST_CONFIG_WITH_STATIC_ASSERT -#endif // MSVC -#endif // DOCTEST_CONFIG_WITH_STATIC_ASSERT +#endif // MSVC +#endif // DOCTEST_CONFIG_WITH_STATIC_ASSERT -#if defined(DOCTEST_CONFIG_NO_STATIC_ASSERT) && defined(DOCTEST_CONFIG_WITH_STATIC_ASSERT) +#if defined(DOCTEST_CONFIG_NO_STATIC_ASSERT) \ + && defined(DOCTEST_CONFIG_WITH_STATIC_ASSERT) #undef DOCTEST_CONFIG_WITH_STATIC_ASSERT -#endif // DOCTEST_CONFIG_NO_STATIC_ASSERT +#endif // DOCTEST_CONFIG_NO_STATIC_ASSERT // other stuff... -#if defined(DOCTEST_CONFIG_WITH_RVALUE_REFERENCES) || defined(DOCTEST_CONFIG_WITH_LONG_LONG) || \ - defined(DOCTEST_CONFIG_WITH_DELETED_FUNCTIONS) || defined(DOCTEST_CONFIG_WITH_NULLPTR) || \ - defined(DOCTEST_CONFIG_WITH_VARIADIC_MACROS) || defined(DOCTEST_CONFIG_WITH_STATIC_ASSERT) +#if defined(DOCTEST_CONFIG_WITH_RVALUE_REFERENCES) \ + || defined(DOCTEST_CONFIG_WITH_LONG_LONG) \ + || defined(DOCTEST_CONFIG_WITH_DELETED_FUNCTIONS) \ + || defined(DOCTEST_CONFIG_WITH_NULLPTR) \ + || defined(DOCTEST_CONFIG_WITH_VARIADIC_MACROS) \ + || defined(DOCTEST_CONFIG_WITH_STATIC_ASSERT) #define DOCTEST_NO_CPP11_COMPAT -#endif // c++11 stuff +#endif // c++11 stuff #if defined(DOCTEST_NO_CPP11_COMPAT) DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++98-compat") DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++98-compat-pedantic") -#endif // DOCTEST_NO_CPP11_COMPAT +#endif // DOCTEST_NO_CPP11_COMPAT #if DOCTEST_MSVC && !defined(DOCTEST_CONFIG_WINDOWS_SEH) #define DOCTEST_CONFIG_WINDOWS_SEH -#endif // MSVC -#if defined(DOCTEST_CONFIG_NO_WINDOWS_SEH) && defined(DOCTEST_CONFIG_WINDOWS_SEH) +#endif // MSVC +#if defined(DOCTEST_CONFIG_NO_WINDOWS_SEH) \ + && defined(DOCTEST_CONFIG_WINDOWS_SEH) #undef DOCTEST_CONFIG_WINDOWS_SEH -#endif // DOCTEST_CONFIG_NO_WINDOWS_SEH +#endif // DOCTEST_CONFIG_NO_WINDOWS_SEH -#if !defined(_WIN32) && !defined(__QNX__) && !defined(DOCTEST_CONFIG_POSIX_SIGNALS) +#if !defined(_WIN32) && !defined(__QNX__) \ + && !defined(DOCTEST_CONFIG_POSIX_SIGNALS) #define DOCTEST_CONFIG_POSIX_SIGNALS -#endif // _WIN32 -#if defined(DOCTEST_CONFIG_NO_POSIX_SIGNALS) && defined(DOCTEST_CONFIG_POSIX_SIGNALS) +#endif // _WIN32 +#if defined(DOCTEST_CONFIG_NO_POSIX_SIGNALS) \ + && defined(DOCTEST_CONFIG_POSIX_SIGNALS) #undef DOCTEST_CONFIG_POSIX_SIGNALS -#endif // DOCTEST_CONFIG_NO_POSIX_SIGNALS +#endif // DOCTEST_CONFIG_NO_POSIX_SIGNALS #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS -#if(DOCTEST_GCC || DOCTEST_CLANG) && !defined(__EXCEPTIONS) +#if (DOCTEST_GCC || DOCTEST_CLANG) && !defined(__EXCEPTIONS) #define DOCTEST_CONFIG_NO_EXCEPTIONS -#endif // clang and gcc +#endif // clang and gcc // in MSVC _HAS_EXCEPTIONS is defined in a header instead of as a project define // so we can't do the automatic detection for MSVC without including some header -#endif // DOCTEST_CONFIG_NO_EXCEPTIONS +#endif // DOCTEST_CONFIG_NO_EXCEPTIONS #ifdef DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS #define DOCTEST_CONFIG_NO_EXCEPTIONS -#endif // DOCTEST_CONFIG_NO_EXCEPTIONS -#endif // DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS +#endif // DOCTEST_CONFIG_NO_EXCEPTIONS +#endif // DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS -#if defined(DOCTEST_CONFIG_NO_EXCEPTIONS) && !defined(DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS) +#if defined(DOCTEST_CONFIG_NO_EXCEPTIONS) \ + && !defined(DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS) #define DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS -#endif // DOCTEST_CONFIG_NO_EXCEPTIONS && !DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS +#endif // DOCTEST_CONFIG_NO_EXCEPTIONS && + // !DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS -#if defined(DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN) && !defined(DOCTEST_CONFIG_IMPLEMENT) +#if defined(DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN) \ + && !defined(DOCTEST_CONFIG_IMPLEMENT) #define DOCTEST_CONFIG_IMPLEMENT -#endif // DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#endif // DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #if defined _WIN32 || defined __CYGWIN__ #if DOCTEST_MSVC #define DOCTEST_SYMBOL_EXPORT __declspec(dllexport) #define DOCTEST_SYMBOL_IMPORT __declspec(dllimport) -#else // MSVC +#else // MSVC #define DOCTEST_SYMBOL_EXPORT __attribute__((dllexport)) #define DOCTEST_SYMBOL_IMPORT __attribute__((dllimport)) -#endif // MSVC -#else // _WIN32 +#endif // MSVC +#else // _WIN32 #define DOCTEST_SYMBOL_EXPORT __attribute__((visibility("default"))) #define DOCTEST_SYMBOL_IMPORT -#endif // _WIN32 +#endif // _WIN32 #ifdef DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL #ifdef DOCTEST_CONFIG_IMPLEMENT #define DOCTEST_INTERFACE DOCTEST_SYMBOL_EXPORT -#else // DOCTEST_CONFIG_IMPLEMENT +#else // DOCTEST_CONFIG_IMPLEMENT #define DOCTEST_INTERFACE DOCTEST_SYMBOL_IMPORT -#endif // DOCTEST_CONFIG_IMPLEMENT -#else // DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL +#endif // DOCTEST_CONFIG_IMPLEMENT +#else // DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL #define DOCTEST_INTERFACE -#endif // DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL +#endif // DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL #if DOCTEST_MSVC #define DOCTEST_NOINLINE __declspec(noinline) #define DOCTEST_UNUSED -#else // MSVC +#else // MSVC #define DOCTEST_NOINLINE __attribute__((noinline)) #define DOCTEST_UNUSED __attribute__((unused)) -#endif // MSVC +#endif // MSVC #ifndef DOCTEST_CONFIG_NUM_CAPTURES_ON_STACK #define DOCTEST_CONFIG_NUM_CAPTURES_ON_STACK 5 -#endif // DOCTEST_CONFIG_NUM_CAPTURES_ON_STACK +#endif // DOCTEST_CONFIG_NUM_CAPTURES_ON_STACK // ================================================================================================= -// == FEATURE DETECTION END ======================================================================== +// == FEATURE DETECTION END +// ======================================================================== // ================================================================================================= -// internal macros for string concatenation and anonymous variable name generation +// internal macros for string concatenation and anonymous variable name +// generation #define DOCTEST_CAT_IMPL(s1, s2) s1##s2 #define DOCTEST_CAT(s1, s2) DOCTEST_CAT_IMPL(s1, s2) -#ifdef __COUNTER__ // not standard and may be missing for some compilers +#ifdef __COUNTER__ // not standard and may be missing for some compilers #define DOCTEST_ANONYMOUS(x) DOCTEST_CAT(x, __COUNTER__) -#else // __COUNTER__ +#else // __COUNTER__ #define DOCTEST_ANONYMOUS(x) DOCTEST_CAT(x, __LINE__) -#endif // __COUNTER__ +#endif // __COUNTER__ // macro for making a string out of an identifier #ifdef DOCTEST_CONFIG_WITH_VARIADIC_MACROS #define DOCTEST_TOSTR_IMPL(...) #__VA_ARGS__ #define DOCTEST_TOSTR(...) DOCTEST_TOSTR_IMPL(__VA_ARGS__) -#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS #define DOCTEST_TOSTR_IMPL(x) #x #define DOCTEST_TOSTR(x) DOCTEST_TOSTR_IMPL(x) -#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS // counts the number of elements in a C string #define DOCTEST_COUNTOF(x) (sizeof(x) / sizeof(x[0])) #ifndef DOCTEST_CONFIG_ASSERTION_PARAMETERS_BY_VALUE #define DOCTEST_REF_WRAP(x) x& -#else // DOCTEST_CONFIG_ASSERTION_PARAMETERS_BY_VALUE +#else // DOCTEST_CONFIG_ASSERTION_PARAMETERS_BY_VALUE #define DOCTEST_REF_WRAP(x) x -#endif // DOCTEST_CONFIG_ASSERTION_PARAMETERS_BY_VALUE +#endif // DOCTEST_CONFIG_ASSERTION_PARAMETERS_BY_VALUE // not using __APPLE__ because... this is how Catch does it #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) @@ -513,8 +561,9 @@ DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++98-compat-pedantic") #define DOCTEST_PLATFORM_LINUX #endif -#define DOCTEST_GLOBAL_NO_WARNINGS(var) \ - DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH("-Wglobal-constructors") static int var DOCTEST_UNUSED +#define DOCTEST_GLOBAL_NO_WARNINGS(var) \ + DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH("-Wglobal-constructors") \ + static int var DOCTEST_UNUSED #define DOCTEST_GLOBAL_NO_WARNINGS_END() DOCTEST_CLANG_SUPPRESS_WARNING_POP // should probably take a look at https://github.com/scottt/debugbreak @@ -525,23 +574,23 @@ DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++98-compat-pedantic") #elif defined(__MINGW32__) extern "C" __declspec(dllimport) void __stdcall DebugBreak(); #define DOCTEST_BREAK_INTO_DEBUGGER() ::DebugBreak() -#else // linux +#else // linux #define DOCTEST_BREAK_INTO_DEBUGGER() ((void)0) -#endif // linux +#endif // linux #if DOCTEST_CLANG // to detect if libc++ is being used with clang (the _LIBCPP_VERSION identifier) #include -#endif // clang +#endif // clang #ifdef _LIBCPP_VERSION -// not forward declaring ostream for libc++ because I had some problems (inline namespaces vs c++98) -// so the header is used - also it is very light and doesn't drag a ton of stuff +// not forward declaring ostream for libc++ because I had some problems (inline +// namespaces vs c++98) so the header is used - also it is very light +// and doesn't drag a ton of stuff #include -#else // _LIBCPP_VERSION +#else // _LIBCPP_VERSION #ifndef DOCTEST_CONFIG_USE_IOSFWD -namespace std -{ +namespace std { template struct char_traits; template <> @@ -549,105 +598,109 @@ struct char_traits; template class basic_ostream; typedef basic_ostream > ostream; -} // namespace std -#else // DOCTEST_CONFIG_USE_IOSFWD +} // namespace std +#else // DOCTEST_CONFIG_USE_IOSFWD #include -#endif // DOCTEST_CONFIG_USE_IOSFWD -#endif // _LIBCPP_VERSION +#endif // DOCTEST_CONFIG_USE_IOSFWD +#endif // _LIBCPP_VERSION -// static assert macro - because of the c++98 support requires that the message is an -// identifier (no spaces and not a C string) - example without quotes: I_am_a_message -// taken from here: http://stackoverflow.com/a/1980156/3162383 +// static assert macro - because of the c++98 support requires that the message +// is an identifier (no spaces and not a C string) - example without quotes: +// I_am_a_message taken from here: http://stackoverflow.com/a/1980156/3162383 #ifdef DOCTEST_CONFIG_WITH_STATIC_ASSERT -#define DOCTEST_STATIC_ASSERT(expression, message) static_assert(expression, #message) -#else // DOCTEST_CONFIG_WITH_STATIC_ASSERT -#define DOCTEST_STATIC_ASSERT(expression, message) \ - struct DOCTEST_CAT(__static_assertion_at_line_, __LINE__) \ - { \ - doctest::detail::static_assert_impl::StaticAssertion((expression))> \ - DOCTEST_CAT(DOCTEST_CAT(DOCTEST_CAT(STATIC_ASSERTION_FAILED_AT_LINE_, __LINE__), \ - _), \ - message); \ - }; \ - typedef doctest::detail::static_assert_impl::StaticAssertionTest( \ - sizeof(DOCTEST_CAT(__static_assertion_at_line_, __LINE__)))> \ - DOCTEST_CAT(__static_assertion_test_at_line_, __LINE__) -#endif // DOCTEST_CONFIG_WITH_STATIC_ASSERT +#define DOCTEST_STATIC_ASSERT(expression, message) \ + static_assert(expression, #message) +#else // DOCTEST_CONFIG_WITH_STATIC_ASSERT +#define DOCTEST_STATIC_ASSERT(expression, message) \ + struct DOCTEST_CAT(__static_assertion_at_line_, __LINE__) { \ + doctest::detail::static_assert_impl::StaticAssertion< \ + static_cast((expression))> \ + DOCTEST_CAT( \ + DOCTEST_CAT( \ + DOCTEST_CAT(STATIC_ASSERTION_FAILED_AT_LINE_, __LINE__), \ + _), \ + message); \ + }; \ + typedef doctest::detail::static_assert_impl::StaticAssertionTest< \ + static_cast( \ + sizeof(DOCTEST_CAT(__static_assertion_at_line_, __LINE__)))> \ + DOCTEST_CAT(__static_assertion_test_at_line_, __LINE__) +#endif // DOCTEST_CONFIG_WITH_STATIC_ASSERT #ifdef DOCTEST_CONFIG_WITH_NULLPTR #ifdef _LIBCPP_VERSION #include -#else // _LIBCPP_VERSION -namespace std -{ +#else // _LIBCPP_VERSION +namespace std { typedef decltype(nullptr) nullptr_t; } -#endif // _LIBCPP_VERSION -#endif // DOCTEST_CONFIG_WITH_NULLPTR +#endif // _LIBCPP_VERSION +#endif // DOCTEST_CONFIG_WITH_NULLPTR #ifndef DOCTEST_CONFIG_DISABLE #ifdef DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS #include -#endif // DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS - -namespace doctest -{ -namespace detail -{ - struct TestSuite - { - const char* m_test_suite; - const char* m_description; - bool m_skip; - bool m_may_fail; - bool m_should_fail; - int m_expected_failures; - double m_timeout; - - TestSuite& operator*(const char* in) { - m_test_suite = in; - // clear state - m_description = 0; - m_skip = false; - m_may_fail = false; - m_should_fail = false; - m_expected_failures = 0; - m_timeout = 0; - return *this; - } +#endif // DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS + +namespace doctest { +namespace detail { +struct TestSuite { + const char* m_test_suite; + const char* m_description; + bool m_skip; + bool m_may_fail; + bool m_should_fail; + int m_expected_failures; + double m_timeout; + + TestSuite& operator*(const char* in) { + m_test_suite = in; + // clear state + m_description = 0; + m_skip = false; + m_may_fail = false; + m_should_fail = false; + m_expected_failures = 0; + m_timeout = 0; + return *this; + } - template - TestSuite& operator*(const T& in) { - in.fill(*this); - return *this; - } - }; -} // namespace detail -} // namespace doctest + template + TestSuite& operator*(const T& in) { + in.fill(*this); + return *this; + } +}; +} // namespace detail +} // namespace doctest -// in a separate namespace outside of doctest because the DOCTEST_TEST_SUITE macro -// introduces an anonymous namespace in which getCurrentTestSuite gets overridden -namespace doctest_detail_test_suite_ns -{ +// in a separate namespace outside of doctest because the DOCTEST_TEST_SUITE +// macro introduces an anonymous namespace in which getCurrentTestSuite gets +// overridden +namespace doctest_detail_test_suite_ns { DOCTEST_INTERFACE doctest::detail::TestSuite& getCurrentTestSuite(); -} // namespace doctest_detail_test_suite_ns +} // namespace doctest_detail_test_suite_ns -#endif // DOCTEST_CONFIG_DISABLE +#endif // DOCTEST_CONFIG_DISABLE -namespace doctest -{ -// A 24 byte string class (can be as small as 17 for x64 and 13 for x86) that can hold strings with length -// of up to 23 chars on the stack before going on the heap - the last byte of the buffer is used for: -// - "is small" bit - the highest bit - if "0" then it is small - otherwise its "1" (128) +namespace doctest { +// A 24 byte string class (can be as small as 17 for x64 and 13 for x86) that +// can hold strings with length of up to 23 chars on the stack before going on +// the heap - the last byte of the buffer is used for: +// - "is small" bit - the highest bit - if "0" then it is small - otherwise its +// "1" (128) // - if small - capacity left before going on the heap - using the lowest 5 bits // - if small - 2 bits are left unused - the second and third highest ones -// - if small - acts as a null terminator if strlen() is 23 (24 including the null terminator) -// and the "is small" bit remains "0" ("as well as the capacity left") so its OK -// Idea taken from this lecture about the string implementation of facebook/folly - fbstring -// https://www.youtube.com/watch?v=kPR8h4-qZdk +// - if small - acts as a null terminator if strlen() is 23 (24 including the +// null terminator) +// and the "is small" bit remains "0" ("as well as the capacity +// left") so its OK +// Idea taken from this lecture about the string implementation of +// facebook/folly - fbstring https://www.youtube.com/watch?v=kPR8h4-qZdk // TODO: -// - optimizations - like not deleting memory unnecessarily in operator= and etc. +// - optimizations - like not deleting memory unnecessarily in operator= and +// etc. // - resize/reserve/clear // - substr // - replace @@ -656,21 +709,22 @@ namespace doctest // - find & friends // - push_back/pop_back // - assign/insert/erase -// - relational operators as free functions - taking const char* as one of the params -class DOCTEST_INTERFACE String -{ - static const unsigned len = 24; //!OCLINT avoid private static members - static const unsigned last = len - 1; //!OCLINT avoid private static members - - struct view // len should be more than sizeof(view) - because of the final byte for flags +// - relational operators as free functions - taking const char* as one of the +// params +class DOCTEST_INTERFACE String { + static const unsigned len = 24; //! OCLINT avoid private static members + static const unsigned last = + len - 1; //! OCLINT avoid private static members + + struct view // len should be more than sizeof(view) - because of the final + // byte for flags { - char* ptr; + char* ptr; unsigned size; unsigned capacity; }; - union - { + union { char buf[len]; view data; }; @@ -680,7 +734,7 @@ class DOCTEST_INTERFACE String void setOnHeap() { *reinterpret_cast(&buf[last]) = 128; } void setLast(unsigned in = last) { buf[last] = char(in); } -public: + public: String() { buf[0] = '\0'; setLast(); @@ -691,16 +745,16 @@ class DOCTEST_INTERFACE String String(const String& other) { copy(other); } ~String() { - if(!isOnStack()) - delete[] data.ptr; + if (!isOnStack()) delete[] data.ptr; } - // GCC 4.9/5/6 report Wstrict-overflow when optimizations are ON and it got inlined in the vector class somewhere... - // see commit 574ef95f0cd379118be5011704664e4b5351f1e0 and build https://travis-ci.org/onqtam/doctest/builds/230671611 + // GCC 4.9/5/6 report Wstrict-overflow when optimizations are ON and it got + // inlined in the vector class somewhere... see commit + // 574ef95f0cd379118be5011704664e4b5351f1e0 and build + // https://travis-ci.org/onqtam/doctest/builds/230671611 DOCTEST_NOINLINE String& operator=(const String& other) { - if(this != &other) { - if(!isOnStack()) - delete[] data.ptr; + if (this != &other) { + if (!isOnStack()) delete[] data.ptr; copy(other); } @@ -709,38 +763,43 @@ class DOCTEST_INTERFACE String } String& operator+=(const String& other); - String operator+(const String& other) const { return String(*this) += other; } + String operator+(const String& other) const { + return String(*this) += other; + } #ifdef DOCTEST_CONFIG_WITH_RVALUE_REFERENCES String(String&& other); String& operator=(String&& other); -#endif // DOCTEST_CONFIG_WITH_RVALUE_REFERENCES +#endif // DOCTEST_CONFIG_WITH_RVALUE_REFERENCES bool isOnStack() const { return (buf[last] & 128) == 0; } - char operator[](unsigned i) const { return const_cast(this)->operator[](i); } // NOLINT + char operator[](unsigned i) const { + return const_cast(this)->operator[](i); + } // NOLINT char& operator[](unsigned i) { - if(isOnStack()) - return reinterpret_cast(buf)[i]; + if (isOnStack()) return reinterpret_cast(buf)[i]; return data.ptr[i]; } - const char* c_str() const { return const_cast(this)->c_str(); } // NOLINT - char* c_str() { - if(isOnStack()) - return reinterpret_cast(buf); + const char* c_str() const { + return const_cast(this)->c_str(); + } // NOLINT + char* c_str() { + if (isOnStack()) return reinterpret_cast(buf); return data.ptr; } unsigned size() const { - if(isOnStack()) - return last - (unsigned(buf[last]) & 31); // using "last" would work only if "len" is 32 + if (isOnStack()) + return last + - (unsigned(buf[last]) + & 31); // using "last" would work only if "len" is 32 return data.size; } unsigned capacity() const { - if(isOnStack()) - return len; + if (isOnStack()) return len; return data.capacity; } @@ -757,235 +816,218 @@ inline bool operator<=(const String& lhs, const String& rhs) { return (lhs != rh inline bool operator>=(const String& lhs, const String& rhs) { return (lhs != rhs) ? lhs.compare(rhs) > 0 : true; } // clang-format on -DOCTEST_INTERFACE std::ostream& operator<<(std::ostream& stream, const String& in); +DOCTEST_INTERFACE std::ostream& operator<<( + std::ostream& stream, const String& in); -namespace detail -{ +namespace detail { #ifndef DOCTEST_CONFIG_WITH_STATIC_ASSERT - namespace static_assert_impl - { - template - struct StaticAssertion; - - template <> - struct StaticAssertion - {}; - - template - struct StaticAssertionTest - {}; - } // namespace static_assert_impl -#endif // DOCTEST_CONFIG_WITH_STATIC_ASSERT +namespace static_assert_impl { +template +struct StaticAssertion; - template - struct enable_if - {}; +template <> +struct StaticAssertion {}; - template - struct enable_if - { typedef TYPE type; }; +template +struct StaticAssertionTest {}; +} // namespace static_assert_impl +#endif // DOCTEST_CONFIG_WITH_STATIC_ASSERT - template - struct deferred_false - // cppcheck-suppress unusedStructMember - { static const bool value = false; }; +template +struct enable_if {}; - // to silence the warning "-Wzero-as-null-pointer-constant" only for gcc 5 for the Approx template ctor - pragmas don't work for it... - inline void* getNull() { return 0; } +template +struct enable_if { + typedef TYPE type; +}; - namespace has_insertion_operator_impl - { - typedef char no; - typedef char yes[2]; +template +struct deferred_false +// cppcheck-suppress unusedStructMember +{ + static const bool value = false; +}; - struct any_t - { - template - // cppcheck-suppress noExplicitConstructor - any_t(const DOCTEST_REF_WRAP(T)); - }; +// to silence the warning "-Wzero-as-null-pointer-constant" only for gcc 5 for +// the Approx template ctor - pragmas don't work for it... +inline void* getNull() { return 0; } - yes& testStreamable(std::ostream&); - no testStreamable(no); +namespace has_insertion_operator_impl { +typedef char no; +typedef char yes[2]; - no operator<<(const std::ostream&, const any_t&); +struct any_t { + template + // cppcheck-suppress noExplicitConstructor + any_t(const DOCTEST_REF_WRAP(T)); +}; - template - struct has_insertion_operator - { - static std::ostream& s; - static const DOCTEST_REF_WRAP(T) t; - static const bool value = sizeof(testStreamable(s << t)) == sizeof(yes); - }; - } // namespace has_insertion_operator_impl +yes& testStreamable(std::ostream&); +no testStreamable(no); - template - struct has_insertion_operator : has_insertion_operator_impl::has_insertion_operator - {}; +no operator<<(const std::ostream&, const any_t&); - DOCTEST_INTERFACE void my_memcpy(void* dest, const void* src, unsigned num); - DOCTEST_INTERFACE unsigned my_strlen(const char* in); +template +struct has_insertion_operator { + static std::ostream& s; + static const DOCTEST_REF_WRAP(T) t; + static const bool value = sizeof(testStreamable(s << t)) == sizeof(yes); +}; +} // namespace has_insertion_operator_impl - DOCTEST_INTERFACE std::ostream* createStream(); - DOCTEST_INTERFACE String getStreamResult(std::ostream*); - DOCTEST_INTERFACE void freeStream(std::ostream*); +template +struct has_insertion_operator + : has_insertion_operator_impl::has_insertion_operator {}; - template - struct StringMakerBase - { - template - static String convert(const DOCTEST_REF_WRAP(T)) { - return "{?}"; - } - }; +DOCTEST_INTERFACE void my_memcpy(void* dest, const void* src, unsigned num); +DOCTEST_INTERFACE unsigned my_strlen(const char* in); - template <> - struct StringMakerBase - { - template - static String convert(const DOCTEST_REF_WRAP(T) in) { - std::ostream* stream = createStream(); - *stream << in; - String result = getStreamResult(stream); - freeStream(stream); - return result; - } - }; +DOCTEST_INTERFACE std::ostream* createStream(); +DOCTEST_INTERFACE String getStreamResult(std::ostream*); +DOCTEST_INTERFACE void freeStream(std::ostream*); - DOCTEST_INTERFACE String rawMemoryToString(const void* object, unsigned size); +template +struct StringMakerBase { + template + static String convert(const DOCTEST_REF_WRAP(T)) { + return "{?}"; + } +}; +template <> +struct StringMakerBase { template - String rawMemoryToString(const DOCTEST_REF_WRAP(T) object) { - return rawMemoryToString(&object, sizeof(object)); + static String convert(const DOCTEST_REF_WRAP(T) in) { + std::ostream* stream = createStream(); + *stream << in; + String result = getStreamResult(stream); + freeStream(stream); + return result; } +}; - class NullType - { - }; +DOCTEST_INTERFACE String rawMemoryToString(const void* object, unsigned size); - template - struct Typelist - { - typedef T Head; - typedef U Tail; - }; +template +String rawMemoryToString(const DOCTEST_REF_WRAP(T) object) { + return rawMemoryToString(&object, sizeof(object)); +} - // type of recursive function - template - struct ForEachType; +class NullType {}; - // Recursion rule - template - struct ForEachType, Callable> : public ForEachType - { - enum - { - value = 1 + ForEachType::value - }; +template +struct Typelist { + typedef T Head; + typedef U Tail; +}; - explicit ForEachType(Callable& callable) - : ForEachType(callable) { -#if DOCTEST_MSVC && DOCTEST_MSVC < DOCTEST_COMPILER(19, 10, 0) - callable.operator()(); -#else // MSVC - callable.template operator()(); -#endif // MSVC - } - }; +// type of recursive function +template +struct ForEachType; - // Recursion end - template - struct ForEachType, Callable> - { - public: - enum - { - value = 0 - }; +// Recursion rule +template +struct ForEachType, Callable> + : public ForEachType { + enum { value = 1 + ForEachType::value }; - explicit ForEachType(Callable& callable) { + explicit ForEachType(Callable& callable) + : ForEachType(callable) { #if DOCTEST_MSVC && DOCTEST_MSVC < DOCTEST_COMPILER(19, 10, 0) - callable.operator()(); -#else // MSVC - callable.template operator()(); -#endif // MSVC - } - }; + callable.operator()(); +#else // MSVC + callable.template operator()(); +#endif // MSVC + } +}; - template - const char* type_to_string() { - return "<>"; +// Recursion end +template +struct ForEachType, Callable> { + public: + enum { value = 0 }; + + explicit ForEachType(Callable& callable) { +#if DOCTEST_MSVC && DOCTEST_MSVC < DOCTEST_COMPILER(19, 10, 0) + callable.operator()(); +#else // MSVC + callable.template operator()(); +#endif // MSVC } -} // namespace detail - -template -struct Types -{ -private: - typedef typename Types::Result TailResult; - -public: +}; + +template +const char* type_to_string() { + return "<>"; +} +} // namespace detail + +template < + typename T1 = detail::NullType, typename T2 = detail::NullType, + typename T3 = detail::NullType, typename T4 = detail::NullType, + typename T5 = detail::NullType, typename T6 = detail::NullType, + typename T7 = detail::NullType, typename T8 = detail::NullType, + typename T9 = detail::NullType, typename T10 = detail::NullType, + typename T11 = detail::NullType, typename T12 = detail::NullType, + typename T13 = detail::NullType, typename T14 = detail::NullType, + typename T15 = detail::NullType, typename T16 = detail::NullType, + typename T17 = detail::NullType, typename T18 = detail::NullType, + typename T19 = detail::NullType, typename T20 = detail::NullType, + typename T21 = detail::NullType, typename T22 = detail::NullType, + typename T23 = detail::NullType, typename T24 = detail::NullType, + typename T25 = detail::NullType, typename T26 = detail::NullType, + typename T27 = detail::NullType, typename T28 = detail::NullType, + typename T29 = detail::NullType, typename T30 = detail::NullType, + typename T31 = detail::NullType, typename T32 = detail::NullType, + typename T33 = detail::NullType, typename T34 = detail::NullType, + typename T35 = detail::NullType, typename T36 = detail::NullType, + typename T37 = detail::NullType, typename T38 = detail::NullType, + typename T39 = detail::NullType, typename T40 = detail::NullType, + typename T41 = detail::NullType, typename T42 = detail::NullType, + typename T43 = detail::NullType, typename T44 = detail::NullType, + typename T45 = detail::NullType, typename T46 = detail::NullType, + typename T47 = detail::NullType, typename T48 = detail::NullType, + typename T49 = detail::NullType, typename T50 = detail::NullType, + typename T51 = detail::NullType, typename T52 = detail::NullType, + typename T53 = detail::NullType, typename T54 = detail::NullType, + typename T55 = detail::NullType, typename T56 = detail::NullType, + typename T57 = detail::NullType, typename T58 = detail::NullType, + typename T59 = detail::NullType, typename T60 = detail::NullType> +struct Types { + private: + typedef typename Types< + T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, + T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, + T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44, T45, + T46, T47, T48, T49, T50, T51, T52, T53, T54, T55, T56, T57, T58, T59, + T60>::Result TailResult; + + public: typedef detail::Typelist Result; }; template <> -struct Types<> -{ typedef detail::NullType Result; }; +struct Types<> { + typedef detail::NullType Result; +}; template -struct StringMaker : detail::StringMakerBase::value> -{}; +struct StringMaker + : detail::StringMakerBase::value> {}; template -struct StringMaker -{ +struct StringMaker { template static String convert(U* p) { - if(p) - return detail::rawMemoryToString(p); + if (p) return detail::rawMemoryToString(p); return "NULL"; } }; template -struct StringMaker -{ - static String convert(R C::*p) { - if(p) - return detail::rawMemoryToString(p); +struct StringMaker { + static String convert(R C::* p) { + if (p) return detail::rawMemoryToString(p); return "NULL"; } }; @@ -998,7 +1040,7 @@ String toString(const DOCTEST_REF_WRAP(T) value) { #ifdef DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING DOCTEST_INTERFACE String toString(char* in); DOCTEST_INTERFACE String toString(const char* in); -#endif // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING +#endif // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING DOCTEST_INTERFACE String toString(bool in); DOCTEST_INTERFACE String toString(float in); DOCTEST_INTERFACE String toString(double in); @@ -1017,15 +1059,14 @@ DOCTEST_INTERFACE String toString(int long unsigned in); #ifdef DOCTEST_CONFIG_WITH_LONG_LONG DOCTEST_INTERFACE String toString(int long long in); DOCTEST_INTERFACE String toString(int long long unsigned in); -#endif // DOCTEST_CONFIG_WITH_LONG_LONG +#endif // DOCTEST_CONFIG_WITH_LONG_LONG #ifdef DOCTEST_CONFIG_WITH_NULLPTR DOCTEST_INTERFACE String toString(std::nullptr_t in); -#endif // DOCTEST_CONFIG_WITH_NULLPTR +#endif // DOCTEST_CONFIG_WITH_NULLPTR -class DOCTEST_INTERFACE Approx -{ -public: +class DOCTEST_INTERFACE Approx { + public: explicit Approx(double value); Approx operator()(double value) const { @@ -1037,12 +1078,13 @@ class DOCTEST_INTERFACE Approx #ifdef DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS template - explicit Approx(const T& value, - typename detail::enable_if::value>::type* = + explicit Approx( + const T& value, typename detail::enable_if< + std::is_constructible::value>::type* = static_cast(detail::getNull())) { *this = Approx(static_cast(value)); } -#endif // DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS +#endif // DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS // clang-format off // overloads for double - the first one is necessary as it is in the implementation part of doctest @@ -1088,12 +1130,13 @@ class DOCTEST_INTERFACE Approx #ifdef DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS template - typename detail::enable_if::value, Approx&>::type epsilon( - const T& newEpsilon) { + typename detail::enable_if< + std::is_constructible::value, Approx&>::type + epsilon(const T& newEpsilon) { m_epsilon = static_cast(newEpsilon); return *this; } -#endif // DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS +#endif // DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS Approx& scale(double newScale) { m_scale = newScale; @@ -1102,16 +1145,17 @@ class DOCTEST_INTERFACE Approx #ifdef DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS template - typename detail::enable_if::value, Approx&>::type scale( - const T& newScale) { + typename detail::enable_if< + std::is_constructible::value, Approx&>::type + scale(const T& newScale) { m_scale = static_cast(newScale); return *this; } -#endif // DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS +#endif // DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS String toString() const; -private: + private: double m_epsilon; double m_scale; double m_value; @@ -1124,129 +1168,126 @@ inline String toString(const DOCTEST_REF_WRAP(Approx) value) { #if !defined(DOCTEST_CONFIG_DISABLE) -namespace detail -{ - // the function type this library works with - typedef void (*funcType)(); +namespace detail { +// the function type this library works with +typedef void (*funcType)(); - namespace assertType - { - enum Enum - { - // macro traits +namespace assertType { +enum Enum { + // macro traits - is_warn = 1, - is_check = 2, - is_require = 4, + is_warn = 1, + is_check = 2, + is_require = 4, - is_throws = 8, - is_throws_as = 16, - is_nothrow = 32, + is_throws = 8, + is_throws_as = 16, + is_nothrow = 32, - is_fast = 64, // not checked anywhere - used just to distinguish the types - is_false = 128, - is_unary = 256, + is_fast = 64, // not checked anywhere - used just to distinguish the types + is_false = 128, + is_unary = 256, - is_eq = 512, - is_ne = 1024, + is_eq = 512, + is_ne = 1024, - is_lt = 2048, - is_gt = 4096, + is_lt = 2048, + is_gt = 4096, - is_ge = 8192, - is_le = 16384, + is_ge = 8192, + is_le = 16384, - // macro types + // macro types - DT_WARN = is_warn, - DT_CHECK = is_check, - DT_REQUIRE = is_require, + DT_WARN = is_warn, + DT_CHECK = is_check, + DT_REQUIRE = is_require, - DT_WARN_FALSE = is_false | is_warn, - DT_CHECK_FALSE = is_false | is_check, - DT_REQUIRE_FALSE = is_false | is_require, + DT_WARN_FALSE = is_false | is_warn, + DT_CHECK_FALSE = is_false | is_check, + DT_REQUIRE_FALSE = is_false | is_require, - DT_WARN_THROWS = is_throws | is_warn, - DT_CHECK_THROWS = is_throws | is_check, - DT_REQUIRE_THROWS = is_throws | is_require, + DT_WARN_THROWS = is_throws | is_warn, + DT_CHECK_THROWS = is_throws | is_check, + DT_REQUIRE_THROWS = is_throws | is_require, - DT_WARN_THROWS_AS = is_throws_as | is_warn, - DT_CHECK_THROWS_AS = is_throws_as | is_check, - DT_REQUIRE_THROWS_AS = is_throws_as | is_require, + DT_WARN_THROWS_AS = is_throws_as | is_warn, + DT_CHECK_THROWS_AS = is_throws_as | is_check, + DT_REQUIRE_THROWS_AS = is_throws_as | is_require, - DT_WARN_NOTHROW = is_nothrow | is_warn, - DT_CHECK_NOTHROW = is_nothrow | is_check, - DT_REQUIRE_NOTHROW = is_nothrow | is_require, + DT_WARN_NOTHROW = is_nothrow | is_warn, + DT_CHECK_NOTHROW = is_nothrow | is_check, + DT_REQUIRE_NOTHROW = is_nothrow | is_require, - DT_WARN_EQ = is_eq | is_warn, - DT_CHECK_EQ = is_eq | is_check, - DT_REQUIRE_EQ = is_eq | is_require, + DT_WARN_EQ = is_eq | is_warn, + DT_CHECK_EQ = is_eq | is_check, + DT_REQUIRE_EQ = is_eq | is_require, - DT_WARN_NE = is_ne | is_warn, - DT_CHECK_NE = is_ne | is_check, - DT_REQUIRE_NE = is_ne | is_require, + DT_WARN_NE = is_ne | is_warn, + DT_CHECK_NE = is_ne | is_check, + DT_REQUIRE_NE = is_ne | is_require, - DT_WARN_GT = is_gt | is_warn, - DT_CHECK_GT = is_gt | is_check, - DT_REQUIRE_GT = is_gt | is_require, + DT_WARN_GT = is_gt | is_warn, + DT_CHECK_GT = is_gt | is_check, + DT_REQUIRE_GT = is_gt | is_require, - DT_WARN_LT = is_lt | is_warn, - DT_CHECK_LT = is_lt | is_check, - DT_REQUIRE_LT = is_lt | is_require, + DT_WARN_LT = is_lt | is_warn, + DT_CHECK_LT = is_lt | is_check, + DT_REQUIRE_LT = is_lt | is_require, - DT_WARN_GE = is_ge | is_warn, - DT_CHECK_GE = is_ge | is_check, - DT_REQUIRE_GE = is_ge | is_require, + DT_WARN_GE = is_ge | is_warn, + DT_CHECK_GE = is_ge | is_check, + DT_REQUIRE_GE = is_ge | is_require, - DT_WARN_LE = is_le | is_warn, - DT_CHECK_LE = is_le | is_check, - DT_REQUIRE_LE = is_le | is_require, + DT_WARN_LE = is_le | is_warn, + DT_CHECK_LE = is_le | is_check, + DT_REQUIRE_LE = is_le | is_require, - DT_WARN_UNARY = is_unary | is_warn, - DT_CHECK_UNARY = is_unary | is_check, - DT_REQUIRE_UNARY = is_unary | is_require, + DT_WARN_UNARY = is_unary | is_warn, + DT_CHECK_UNARY = is_unary | is_check, + DT_REQUIRE_UNARY = is_unary | is_require, - DT_WARN_UNARY_FALSE = is_false | is_unary | is_warn, - DT_CHECK_UNARY_FALSE = is_false | is_unary | is_check, - DT_REQUIRE_UNARY_FALSE = is_false | is_unary | is_require, + DT_WARN_UNARY_FALSE = is_false | is_unary | is_warn, + DT_CHECK_UNARY_FALSE = is_false | is_unary | is_check, + DT_REQUIRE_UNARY_FALSE = is_false | is_unary | is_require, - DT_FAST_WARN_EQ = is_fast | is_eq | is_warn, - DT_FAST_CHECK_EQ = is_fast | is_eq | is_check, - DT_FAST_REQUIRE_EQ = is_fast | is_eq | is_require, + DT_FAST_WARN_EQ = is_fast | is_eq | is_warn, + DT_FAST_CHECK_EQ = is_fast | is_eq | is_check, + DT_FAST_REQUIRE_EQ = is_fast | is_eq | is_require, - DT_FAST_WARN_NE = is_fast | is_ne | is_warn, - DT_FAST_CHECK_NE = is_fast | is_ne | is_check, - DT_FAST_REQUIRE_NE = is_fast | is_ne | is_require, + DT_FAST_WARN_NE = is_fast | is_ne | is_warn, + DT_FAST_CHECK_NE = is_fast | is_ne | is_check, + DT_FAST_REQUIRE_NE = is_fast | is_ne | is_require, - DT_FAST_WARN_GT = is_fast | is_gt | is_warn, - DT_FAST_CHECK_GT = is_fast | is_gt | is_check, - DT_FAST_REQUIRE_GT = is_fast | is_gt | is_require, + DT_FAST_WARN_GT = is_fast | is_gt | is_warn, + DT_FAST_CHECK_GT = is_fast | is_gt | is_check, + DT_FAST_REQUIRE_GT = is_fast | is_gt | is_require, - DT_FAST_WARN_LT = is_fast | is_lt | is_warn, - DT_FAST_CHECK_LT = is_fast | is_lt | is_check, - DT_FAST_REQUIRE_LT = is_fast | is_lt | is_require, + DT_FAST_WARN_LT = is_fast | is_lt | is_warn, + DT_FAST_CHECK_LT = is_fast | is_lt | is_check, + DT_FAST_REQUIRE_LT = is_fast | is_lt | is_require, - DT_FAST_WARN_GE = is_fast | is_ge | is_warn, - DT_FAST_CHECK_GE = is_fast | is_ge | is_check, - DT_FAST_REQUIRE_GE = is_fast | is_ge | is_require, + DT_FAST_WARN_GE = is_fast | is_ge | is_warn, + DT_FAST_CHECK_GE = is_fast | is_ge | is_check, + DT_FAST_REQUIRE_GE = is_fast | is_ge | is_require, - DT_FAST_WARN_LE = is_fast | is_le | is_warn, - DT_FAST_CHECK_LE = is_fast | is_le | is_check, - DT_FAST_REQUIRE_LE = is_fast | is_le | is_require, + DT_FAST_WARN_LE = is_fast | is_le | is_warn, + DT_FAST_CHECK_LE = is_fast | is_le | is_check, + DT_FAST_REQUIRE_LE = is_fast | is_le | is_require, - DT_FAST_WARN_UNARY = is_fast | is_unary | is_warn, - DT_FAST_CHECK_UNARY = is_fast | is_unary | is_check, - DT_FAST_REQUIRE_UNARY = is_fast | is_unary | is_require, + DT_FAST_WARN_UNARY = is_fast | is_unary | is_warn, + DT_FAST_CHECK_UNARY = is_fast | is_unary | is_check, + DT_FAST_REQUIRE_UNARY = is_fast | is_unary | is_require, - DT_FAST_WARN_UNARY_FALSE = is_fast | is_false | is_unary | is_warn, - DT_FAST_CHECK_UNARY_FALSE = is_fast | is_false | is_unary | is_check, - DT_FAST_REQUIRE_UNARY_FALSE = is_fast | is_false | is_unary | is_require - }; - } // namespace assertType + DT_FAST_WARN_UNARY_FALSE = is_fast | is_false | is_unary | is_warn, + DT_FAST_CHECK_UNARY_FALSE = is_fast | is_false | is_unary | is_check, + DT_FAST_REQUIRE_UNARY_FALSE = is_fast | is_false | is_unary | is_require +}; +} // namespace assertType - DOCTEST_INTERFACE const char* getAssertString(assertType::Enum val); +DOCTEST_INTERFACE const char* getAssertString(assertType::Enum val); - // clang-format off +// clang-format off template struct decay_array { typedef T type; }; template struct decay_array { typedef T* type; }; template struct decay_array { typedef T* type; }; @@ -1256,79 +1297,71 @@ namespace detail template<> struct not_char_pointer { enum { value = 0 }; }; template struct can_use_op : not_char_pointer::type> {}; - // clang-format on +// clang-format on - struct TestFailureException - { - }; +struct TestFailureException {}; - DOCTEST_INTERFACE bool checkIfShouldThrow(assertType::Enum assert_type); - DOCTEST_INTERFACE void fastAssertThrowIfFlagSet(int flags); - DOCTEST_INTERFACE void throwException(); +DOCTEST_INTERFACE bool checkIfShouldThrow(assertType::Enum assert_type); +DOCTEST_INTERFACE void fastAssertThrowIfFlagSet(int flags); +DOCTEST_INTERFACE void throwException(); - struct TestAccessibleContextState - { - bool no_throw; // to skip exceptions-related assertion macros - bool success; // include successful assertions in output - }; +struct TestAccessibleContextState { + bool no_throw; // to skip exceptions-related assertion macros + bool success; // include successful assertions in output +}; - struct ContextState; +struct ContextState; - DOCTEST_INTERFACE TestAccessibleContextState* getTestsContextState(); +DOCTEST_INTERFACE TestAccessibleContextState* getTestsContextState(); - struct DOCTEST_INTERFACE SubcaseSignature - { - const char* m_name; - const char* m_file; - int m_line; +struct DOCTEST_INTERFACE SubcaseSignature { + const char* m_name; + const char* m_file; + int m_line; - SubcaseSignature(const char* name, const char* file, int line) - : m_name(name) - , m_file(file) - , m_line(line) {} + SubcaseSignature(const char* name, const char* file, int line) + : m_name(name), m_file(file), m_line(line) {} - bool operator<(const SubcaseSignature& other) const; - }; + bool operator<(const SubcaseSignature& other) const; +}; - // cppcheck-suppress copyCtorAndEqOperator - struct DOCTEST_INTERFACE Subcase - { - SubcaseSignature m_signature; - bool m_entered; +// cppcheck-suppress copyCtorAndEqOperator +struct DOCTEST_INTERFACE Subcase { + SubcaseSignature m_signature; + bool m_entered; - Subcase(const char* name, const char* file, int line); - Subcase(const Subcase& other); - ~Subcase(); + Subcase(const char* name, const char* file, int line); + Subcase(const Subcase& other); + ~Subcase(); - operator bool() const { return m_entered; } - }; + operator bool() const { return m_entered; } +}; - template - String stringifyBinaryExpr(const DOCTEST_REF_WRAP(L) lhs, const char* op, - const DOCTEST_REF_WRAP(R) rhs) { - return toString(lhs) + op + toString(rhs); - } +template +String stringifyBinaryExpr( + const DOCTEST_REF_WRAP(L) lhs, const char* op, + const DOCTEST_REF_WRAP(R) rhs) { + return toString(lhs) + op + toString(rhs); +} - struct DOCTEST_INTERFACE Result - { - bool m_passed; - String m_decomposition; +struct DOCTEST_INTERFACE Result { + bool m_passed; + String m_decomposition; - ~Result(); + ~Result(); - DOCTEST_NOINLINE Result(bool passed = false, const String& decomposition = String()) - : m_passed(passed) - , m_decomposition(decomposition) {} + DOCTEST_NOINLINE Result( + bool passed = false, const String& decomposition = String()) + : m_passed(passed), m_decomposition(decomposition) {} - DOCTEST_NOINLINE Result(const Result& other) - : m_passed(other.m_passed) - , m_decomposition(other.m_decomposition) {} + DOCTEST_NOINLINE Result(const Result& other) + : m_passed(other.m_passed), m_decomposition(other.m_decomposition) {} - Result& operator=(const Result& other); + Result& operator=(const Result& other); - operator bool() { return !m_passed; } + operator bool() { return !m_passed; } - // clang-format off + // clang-format off // forbidding some expressions based on this table: http://en.cppreference.com/w/cpp/language/operator_precedence template Result& operator& (const R&) { DOCTEST_STATIC_ASSERT(deferred_false::value, Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison); return *this; } template Result& operator^ (const R&) { DOCTEST_STATIC_ASSERT(deferred_false::value, Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison); return *this; } @@ -1352,35 +1385,37 @@ namespace detail template Result& operator&= (const R&) { DOCTEST_STATIC_ASSERT(deferred_false::value, Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison); return *this; } template Result& operator^= (const R&) { DOCTEST_STATIC_ASSERT(deferred_false::value, Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison); return *this; } template Result& operator|= (const R&) { DOCTEST_STATIC_ASSERT(deferred_false::value, Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison); return *this; } - // clang-format on - }; + // clang-format on +}; #ifndef DOCTEST_CONFIG_NO_COMPARISON_WARNING_SUPPRESSION - DOCTEST_CLANG_SUPPRESS_WARNING_PUSH - DOCTEST_CLANG_SUPPRESS_WARNING("-Wsign-conversion") - DOCTEST_CLANG_SUPPRESS_WARNING("-Wsign-compare") - //DOCTEST_CLANG_SUPPRESS_WARNING("-Wdouble-promotion") - //DOCTEST_CLANG_SUPPRESS_WARNING("-Wconversion") - //DOCTEST_CLANG_SUPPRESS_WARNING("-Wfloat-equal") - - DOCTEST_GCC_SUPPRESS_WARNING_PUSH - DOCTEST_GCC_SUPPRESS_WARNING("-Wsign-conversion") - DOCTEST_GCC_SUPPRESS_WARNING("-Wsign-compare") - //#if DOCTEST_GCC >= DOCTEST_COMPILER(4, 6, 0) - //DOCTEST_GCC_SUPPRESS_WARNING("-Wdouble-promotion") - //#endif // GCC - //DOCTEST_GCC_SUPPRESS_WARNING("-Wconversion") - //DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal") - - DOCTEST_MSVC_SUPPRESS_WARNING_PUSH - // http://stackoverflow.com/questions/39479163 what's the difference between C4018 and C4389 - DOCTEST_MSVC_SUPPRESS_WARNING(4388) // signed/unsigned mismatch - DOCTEST_MSVC_SUPPRESS_WARNING(4389) // 'operator' : signed/unsigned mismatch - DOCTEST_MSVC_SUPPRESS_WARNING(4018) // 'expression' : signed/unsigned mismatch - //DOCTEST_MSVC_SUPPRESS_WARNING(4805) // 'operation' : unsafe mix of type 'type' and type 'type' in operation - -#endif // DOCTEST_CONFIG_NO_COMPARISON_WARNING_SUPPRESSION +DOCTEST_CLANG_SUPPRESS_WARNING_PUSH +DOCTEST_CLANG_SUPPRESS_WARNING("-Wsign-conversion") +DOCTEST_CLANG_SUPPRESS_WARNING("-Wsign-compare") +// DOCTEST_CLANG_SUPPRESS_WARNING("-Wdouble-promotion") +// DOCTEST_CLANG_SUPPRESS_WARNING("-Wconversion") +// DOCTEST_CLANG_SUPPRESS_WARNING("-Wfloat-equal") + +DOCTEST_GCC_SUPPRESS_WARNING_PUSH +DOCTEST_GCC_SUPPRESS_WARNING("-Wsign-conversion") +DOCTEST_GCC_SUPPRESS_WARNING("-Wsign-compare") +// #if DOCTEST_GCC >= DOCTEST_COMPILER(4, 6, 0) +// DOCTEST_GCC_SUPPRESS_WARNING("-Wdouble-promotion") +// #endif // GCC +// DOCTEST_GCC_SUPPRESS_WARNING("-Wconversion") +// DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal") + +DOCTEST_MSVC_SUPPRESS_WARNING_PUSH +// http://stackoverflow.com/questions/39479163 what's the difference between +// C4018 and C4389 +DOCTEST_MSVC_SUPPRESS_WARNING(4388) // signed/unsigned mismatch +DOCTEST_MSVC_SUPPRESS_WARNING(4389) // 'operator' : signed/unsigned mismatch +DOCTEST_MSVC_SUPPRESS_WARNING(4018) // 'expression' : signed/unsigned mismatch +// DOCTEST_MSVC_SUPPRESS_WARNING(4805) // 'operation' : unsafe mix of type +// 'type' and type 'type' in operation + +#endif // DOCTEST_CONFIG_NO_COMPARISON_WARNING_SUPPRESSION // clang-format off #ifndef DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING @@ -1401,7 +1436,7 @@ namespace detail template DOCTEST_COMPARISON_RETURN_TYPE gt(const DOCTEST_REF_WRAP(L) lhs, const DOCTEST_REF_WRAP(R) rhs) { return lhs > rhs; } template DOCTEST_COMPARISON_RETURN_TYPE le(const DOCTEST_REF_WRAP(L) lhs, const DOCTEST_REF_WRAP(R) rhs) { return lhs <= rhs; } template DOCTEST_COMPARISON_RETURN_TYPE ge(const DOCTEST_REF_WRAP(L) lhs, const DOCTEST_REF_WRAP(R) rhs) { return lhs >= rhs; } - // clang-format on +// clang-format on #ifndef DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING #define DOCTEST_CMP_EQ(l, r) l == r @@ -1410,198 +1445,196 @@ namespace detail #define DOCTEST_CMP_LT(l, r) l < r #define DOCTEST_CMP_GE(l, r) l >= r #define DOCTEST_CMP_LE(l, r) l <= r -#else // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING +#else // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING #define DOCTEST_CMP_EQ(l, r) eq(l, r) #define DOCTEST_CMP_NE(l, r) ne(l, r) #define DOCTEST_CMP_GT(l, r) gt(l, r) #define DOCTEST_CMP_LT(l, r) lt(l, r) #define DOCTEST_CMP_GE(l, r) ge(l, r) #define DOCTEST_CMP_LE(l, r) le(l, r) -#endif // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING - -#define DOCTEST_DO_BINARY_EXPRESSION_COMPARISON(op, op_str, op_macro) \ - template \ - DOCTEST_NOINLINE Result operator op(const DOCTEST_REF_WRAP(R) rhs) { \ - bool res = op_macro(lhs, rhs); \ - if(m_assert_type & assertType::is_false) \ - res = !res; \ - if(!res || doctest::detail::getTestsContextState()->success) \ - return Result(res, stringifyBinaryExpr(lhs, op_str, rhs)); \ - return Result(res); \ +#endif // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING + +#define DOCTEST_DO_BINARY_EXPRESSION_COMPARISON(op, op_str, op_macro) \ + template \ + DOCTEST_NOINLINE Result operator op(const DOCTEST_REF_WRAP(R) rhs) { \ + bool res = op_macro(lhs, rhs); \ + if (m_assert_type & assertType::is_false) res = !res; \ + if (!res || doctest::detail::getTestsContextState()->success) \ + return Result(res, stringifyBinaryExpr(lhs, op_str, rhs)); \ + return Result(res); \ } -#define DOCTEST_FORBIT_EXPRESSION(op) \ - template \ - Expression_lhs& operator op(const R&) { \ - DOCTEST_STATIC_ASSERT(deferred_false::value, \ - Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison); \ - return *this; \ +#define DOCTEST_FORBIT_EXPRESSION(op) \ + template \ + Expression_lhs& operator op(const R&) { \ + DOCTEST_STATIC_ASSERT( \ + deferred_false::value, \ + Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison); \ + return *this; \ } - template - // cppcheck-suppress copyCtorAndEqOperator - struct Expression_lhs - { - L lhs; - assertType::Enum m_assert_type; +template +// cppcheck-suppress copyCtorAndEqOperator +struct Expression_lhs { + L lhs; + assertType::Enum m_assert_type; - explicit Expression_lhs(L in, assertType::Enum assert_type) - : lhs(in) - , m_assert_type(assert_type) {} + explicit Expression_lhs(L in, assertType::Enum assert_type) + : lhs(in), m_assert_type(assert_type) {} - DOCTEST_NOINLINE operator Result() { - bool res = !!lhs; - if(m_assert_type & assertType::is_false) //!OCLINT bitwise operator in conditional - res = !res; + DOCTEST_NOINLINE operator Result() { + bool res = !!lhs; + if (m_assert_type + & assertType::is_false) //! OCLINT bitwise operator in conditional + res = !res; - if(!res || getTestsContextState()->success) - return Result(res, toString(lhs)); - return Result(res); - } + if (!res || getTestsContextState()->success) + return Result(res, toString(lhs)); + return Result(res); + } - // clang-format off + // clang-format off DOCTEST_DO_BINARY_EXPRESSION_COMPARISON(==, " == ", DOCTEST_CMP_EQ) //!OCLINT bitwise operator in conditional DOCTEST_DO_BINARY_EXPRESSION_COMPARISON(!=, " != ", DOCTEST_CMP_NE) //!OCLINT bitwise operator in conditional DOCTEST_DO_BINARY_EXPRESSION_COMPARISON(>, " > ", DOCTEST_CMP_GT) //!OCLINT bitwise operator in conditional DOCTEST_DO_BINARY_EXPRESSION_COMPARISON(<, " < ", DOCTEST_CMP_LT) //!OCLINT bitwise operator in conditional DOCTEST_DO_BINARY_EXPRESSION_COMPARISON(>=, " >= ", DOCTEST_CMP_GE) //!OCLINT bitwise operator in conditional DOCTEST_DO_BINARY_EXPRESSION_COMPARISON(<=, " <= ", DOCTEST_CMP_LE) //!OCLINT bitwise operator in conditional - // clang-format on + // clang-format on - // forbidding some expressions based on this table: http://en.cppreference.com/w/cpp/language/operator_precedence - DOCTEST_FORBIT_EXPRESSION(&) - DOCTEST_FORBIT_EXPRESSION (^) - DOCTEST_FORBIT_EXPRESSION(|) - DOCTEST_FORBIT_EXPRESSION(&&) - DOCTEST_FORBIT_EXPRESSION(||) - DOCTEST_FORBIT_EXPRESSION(=) - DOCTEST_FORBIT_EXPRESSION(+=) - DOCTEST_FORBIT_EXPRESSION(-=) - DOCTEST_FORBIT_EXPRESSION(*=) - DOCTEST_FORBIT_EXPRESSION(/=) - DOCTEST_FORBIT_EXPRESSION(%=) - DOCTEST_FORBIT_EXPRESSION(<<=) - DOCTEST_FORBIT_EXPRESSION(>>=) - DOCTEST_FORBIT_EXPRESSION(&=) - DOCTEST_FORBIT_EXPRESSION(^=) - DOCTEST_FORBIT_EXPRESSION(|=) - // these 2 are unfortunate because they should be allowed - they have higher precedence over the comparisons, but the - // ExpressionDecomposer class uses the left shift operator to capture the left operand of the binary expression... - DOCTEST_FORBIT_EXPRESSION(<<) - DOCTEST_FORBIT_EXPRESSION(>>) - }; + // forbidding some expressions based on this table: + // http://en.cppreference.com/w/cpp/language/operator_precedence + DOCTEST_FORBIT_EXPRESSION(&) + DOCTEST_FORBIT_EXPRESSION(^) + DOCTEST_FORBIT_EXPRESSION(|) + DOCTEST_FORBIT_EXPRESSION(&&) + DOCTEST_FORBIT_EXPRESSION(||) + DOCTEST_FORBIT_EXPRESSION(=) + DOCTEST_FORBIT_EXPRESSION(+=) + DOCTEST_FORBIT_EXPRESSION(-=) + DOCTEST_FORBIT_EXPRESSION(*=) + DOCTEST_FORBIT_EXPRESSION(/=) + DOCTEST_FORBIT_EXPRESSION(%=) + DOCTEST_FORBIT_EXPRESSION(<<=) + DOCTEST_FORBIT_EXPRESSION(>>=) + DOCTEST_FORBIT_EXPRESSION(&=) + DOCTEST_FORBIT_EXPRESSION(^=) + DOCTEST_FORBIT_EXPRESSION(|=) + // these 2 are unfortunate because they should be allowed - they have higher + // precedence over the comparisons, but the ExpressionDecomposer class uses + // the left shift operator to capture the left operand of the binary + // expression... + DOCTEST_FORBIT_EXPRESSION(<<) + DOCTEST_FORBIT_EXPRESSION(>>) +}; #ifndef DOCTEST_CONFIG_NO_COMPARISON_WARNING_SUPPRESSION - DOCTEST_CLANG_SUPPRESS_WARNING_POP - DOCTEST_MSVC_SUPPRESS_WARNING_POP - DOCTEST_GCC_SUPPRESS_WARNING_POP +DOCTEST_CLANG_SUPPRESS_WARNING_POP +DOCTEST_MSVC_SUPPRESS_WARNING_POP +DOCTEST_GCC_SUPPRESS_WARNING_POP -#endif // DOCTEST_CONFIG_NO_COMPARISON_WARNING_SUPPRESSION +#endif // DOCTEST_CONFIG_NO_COMPARISON_WARNING_SUPPRESSION - struct ExpressionDecomposer - { - assertType::Enum m_assert_type; - - ExpressionDecomposer(assertType::Enum assert_type) - : m_assert_type(assert_type) {} - - // The right operator for capturing expressions is "<=" instead of "<<" (based on the operator precedence table) - // but then there will be warnings from GCC about "-Wparentheses" and since "_Pragma()" is problematic this will stay for now... - // https://github.com/philsquared/Catch/issues/870 - // https://github.com/philsquared/Catch/issues/565 - template - Expression_lhs operator<<(const DOCTEST_REF_WRAP(L) operand) { - return Expression_lhs(operand, m_assert_type); - } - }; +struct ExpressionDecomposer { + assertType::Enum m_assert_type; - struct DOCTEST_INTERFACE TestCase - { - // not used for determining uniqueness - funcType m_test; // a function pointer to the test case - String m_full_name; // contains the name (only for templated test cases!) + the template type - const char* m_name; // name of the test case - const char* m_type; // for templated test cases - gets appended to the real name - const char* m_test_suite; // the test suite in which the test was added - const char* m_description; - bool m_skip; - bool m_may_fail; - bool m_should_fail; - int m_expected_failures; - double m_timeout; - - // fields by which uniqueness of test cases shall be determined - const char* m_file; // the file in which the test was registered - unsigned m_line; // the line where the test was registered - int m_template_id; // an ID used to distinguish between the different versions of a templated test case - - TestCase(funcType test, const char* file, unsigned line, const TestSuite& test_suite, - const char* type = "", int template_id = -1); - - // for gcc 4.7 - DOCTEST_NOINLINE ~TestCase() {} - - TestCase& operator*(const char* in); - - template - TestCase& operator*(const T& in) { - in.fill(*this); - return *this; - } + ExpressionDecomposer(assertType::Enum assert_type) + : m_assert_type(assert_type) {} - TestCase(const TestCase& other) { *this = other; } + // The right operator for capturing expressions is "<=" instead of "<<" + // (based on the operator precedence table) but then there will be warnings + // from GCC about "-Wparentheses" and since "_Pragma()" is problematic this + // will stay for now... https://github.com/philsquared/Catch/issues/870 + // https://github.com/philsquared/Catch/issues/565 + template + Expression_lhs operator<<( + const DOCTEST_REF_WRAP(L) operand) { + return Expression_lhs( + operand, m_assert_type); + } +}; - TestCase& operator=(const TestCase& other); +struct DOCTEST_INTERFACE TestCase { + // not used for determining uniqueness + funcType m_test; // a function pointer to the test case + String m_full_name; // contains the name (only for templated test cases!) + + // the template type + const char* m_name; // name of the test case + const char* + m_type; // for templated test cases - gets appended to the real name + const char* m_test_suite; // the test suite in which the test was added + const char* m_description; + bool m_skip; + bool m_may_fail; + bool m_should_fail; + int m_expected_failures; + double m_timeout; + + // fields by which uniqueness of test cases shall be determined + const char* m_file; // the file in which the test was registered + unsigned m_line; // the line where the test was registered + int m_template_id; // an ID used to distinguish between the different + // versions of a templated test case + + TestCase( + funcType test, const char* file, unsigned line, + const TestSuite& test_suite, const char* type = "", + int template_id = -1); + + // for gcc 4.7 + DOCTEST_NOINLINE ~TestCase() {} + + TestCase& operator*(const char* in); - bool operator<(const TestCase& other) const; - }; + template + TestCase& operator*(const T& in) { + in.fill(*this); + return *this; + } - // forward declarations of functions used by the macros - DOCTEST_INTERFACE int regTest(const TestCase& tc); - DOCTEST_INTERFACE int setTestSuite(const TestSuite& ts); + TestCase(const TestCase& other) { *this = other; } - DOCTEST_INTERFACE void addFailedAssert(assertType::Enum assert_type); + TestCase& operator=(const TestCase& other); - DOCTEST_INTERFACE void logTestStart(const TestCase& tc); - DOCTEST_INTERFACE void logTestEnd(); + bool operator<(const TestCase& other) const; +}; - DOCTEST_INTERFACE void logTestException(const String& what, bool crash = false); +// forward declarations of functions used by the macros +DOCTEST_INTERFACE int regTest(const TestCase& tc); +DOCTEST_INTERFACE int setTestSuite(const TestSuite& ts); - DOCTEST_INTERFACE void logAssert(bool passed, const char* decomposition, bool threw, - const String& exception, const char* expr, - assertType::Enum assert_type, const char* file, int line); +DOCTEST_INTERFACE void addFailedAssert(assertType::Enum assert_type); - DOCTEST_INTERFACE void logAssertThrows(bool threw, const char* expr, - assertType::Enum assert_type, const char* file, - int line); +DOCTEST_INTERFACE void logTestStart(const TestCase& tc); +DOCTEST_INTERFACE void logTestEnd(); - DOCTEST_INTERFACE void logAssertThrowsAs(bool threw, bool threw_as, const char* as, - const String& exception, const char* expr, - assertType::Enum assert_type, const char* file, - int line); +DOCTEST_INTERFACE void logTestException(const String& what, bool crash = false); - DOCTEST_INTERFACE void logAssertNothrow(bool threw, const String& exception, const char* expr, - assertType::Enum assert_type, const char* file, - int line); +DOCTEST_INTERFACE void logAssert( + bool passed, const char* decomposition, bool threw, const String& exception, + const char* expr, assertType::Enum assert_type, const char* file, int line); - DOCTEST_INTERFACE bool isDebuggerActive(); - DOCTEST_INTERFACE void writeToDebugConsole(const String&); +DOCTEST_INTERFACE void logAssertThrows( + bool threw, const char* expr, assertType::Enum assert_type, + const char* file, int line); - namespace binaryAssertComparison - { - enum Enum - { - eq = 0, - ne, - gt, - lt, - ge, - le - }; - } // namespace binaryAssertComparison +DOCTEST_INTERFACE void logAssertThrowsAs( + bool threw, bool threw_as, const char* as, const String& exception, + const char* expr, assertType::Enum assert_type, const char* file, int line); - // clang-format off +DOCTEST_INTERFACE void logAssertNothrow( + bool threw, const String& exception, const char* expr, + assertType::Enum assert_type, const char* file, int line); + +DOCTEST_INTERFACE bool isDebuggerActive(); +DOCTEST_INTERFACE void writeToDebugConsole(const String&); + +namespace binaryAssertComparison { +enum Enum { eq = 0, ne, gt, lt, ge, le }; +} // namespace binaryAssertComparison + +// clang-format off template struct RelationalComparator { bool operator()(const DOCTEST_REF_WRAP(L), const DOCTEST_REF_WRAP(R) ) const { return false; } }; template struct RelationalComparator<0, L, R> { bool operator()(const DOCTEST_REF_WRAP(L) lhs, const DOCTEST_REF_WRAP(R) rhs) const { return eq(lhs, rhs); } }; template struct RelationalComparator<1, L, R> { bool operator()(const DOCTEST_REF_WRAP(L) lhs, const DOCTEST_REF_WRAP(R) rhs) const { return ne(lhs, rhs); } }; @@ -1609,497 +1642,475 @@ namespace detail template struct RelationalComparator<3, L, R> { bool operator()(const DOCTEST_REF_WRAP(L) lhs, const DOCTEST_REF_WRAP(R) rhs) const { return lt(lhs, rhs); } }; template struct RelationalComparator<4, L, R> { bool operator()(const DOCTEST_REF_WRAP(L) lhs, const DOCTEST_REF_WRAP(R) rhs) const { return ge(lhs, rhs); } }; template struct RelationalComparator<5, L, R> { bool operator()(const DOCTEST_REF_WRAP(L) lhs, const DOCTEST_REF_WRAP(R) rhs) const { return le(lhs, rhs); } }; - // clang-format on +// clang-format on - struct DOCTEST_INTERFACE ResultBuilder - { - assertType::Enum m_assert_type; - const char* m_file; - int m_line; - const char* m_expr; - const char* m_exception_type; - - Result m_result; - bool m_threw; - bool m_threw_as; - bool m_failed; - String m_exception; - - ResultBuilder(assertType::Enum assert_type, const char* file, int line, const char* expr, - const char* exception_type = ""); - - ~ResultBuilder(); - - void setResult(const Result& res) { m_result = res; } - - template - DOCTEST_NOINLINE void binary_assert(const DOCTEST_REF_WRAP(L) lhs, - const DOCTEST_REF_WRAP(R) rhs) { - m_result.m_passed = RelationalComparator()(lhs, rhs); - if(!m_result.m_passed || getTestsContextState()->success) - m_result.m_decomposition = stringifyBinaryExpr(lhs, ", ", rhs); - } +struct DOCTEST_INTERFACE ResultBuilder { + assertType::Enum m_assert_type; + const char* m_file; + int m_line; + const char* m_expr; + const char* m_exception_type; - template - DOCTEST_NOINLINE void unary_assert(const DOCTEST_REF_WRAP(L) val) { - m_result.m_passed = !!val; + Result m_result; + bool m_threw; + bool m_threw_as; + bool m_failed; + String m_exception; - if(m_assert_type & assertType::is_false) //!OCLINT bitwise operator in conditional - m_result.m_passed = !m_result.m_passed; + ResultBuilder( + assertType::Enum assert_type, const char* file, int line, + const char* expr, const char* exception_type = ""); - if(!m_result.m_passed || getTestsContextState()->success) - m_result.m_decomposition = toString(val); - } + ~ResultBuilder(); - void unexpectedExceptionOccurred(); + void setResult(const Result& res) { m_result = res; } - bool log(); - void react() const; - }; + template + DOCTEST_NOINLINE void binary_assert( + const DOCTEST_REF_WRAP(L) lhs, const DOCTEST_REF_WRAP(R) rhs) { + m_result.m_passed = RelationalComparator()(lhs, rhs); + if (!m_result.m_passed || getTestsContextState()->success) + m_result.m_decomposition = stringifyBinaryExpr(lhs, ", ", rhs); + } - namespace assertAction - { - enum Enum - { - nothing = 0, - dbgbreak = 1, - shouldthrow = 2 - }; - } // namespace assertAction + template + DOCTEST_NOINLINE void unary_assert(const DOCTEST_REF_WRAP(L) val) { + m_result.m_passed = !!val; - template - DOCTEST_NOINLINE int fast_binary_assert(assertType::Enum assert_type, const char* file, - int line, const char* expr, - const DOCTEST_REF_WRAP(L) lhs, - const DOCTEST_REF_WRAP(R) rhs) { - ResultBuilder rb(assert_type, file, line, expr); + if (m_assert_type + & assertType::is_false) //! OCLINT bitwise operator in conditional + m_result.m_passed = !m_result.m_passed; - rb.m_result.m_passed = RelationalComparator()(lhs, rhs); + if (!m_result.m_passed || getTestsContextState()->success) + m_result.m_decomposition = toString(val); + } - if(!rb.m_result.m_passed || getTestsContextState()->success) - rb.m_result.m_decomposition = stringifyBinaryExpr(lhs, ", ", rhs); + void unexpectedExceptionOccurred(); - int res = 0; + bool log(); + void react() const; +}; - if(rb.log()) - res |= assertAction::dbgbreak; +namespace assertAction { +enum Enum { nothing = 0, dbgbreak = 1, shouldthrow = 2 }; +} // namespace assertAction - if(rb.m_failed && checkIfShouldThrow(assert_type)) - res |= assertAction::shouldthrow; +template +DOCTEST_NOINLINE int fast_binary_assert( + assertType::Enum assert_type, const char* file, int line, const char* expr, + const DOCTEST_REF_WRAP(L) lhs, const DOCTEST_REF_WRAP(R) rhs) { + ResultBuilder rb(assert_type, file, line, expr); -#ifdef DOCTEST_CONFIG_SUPER_FAST_ASSERTS - // ######################################################################################### - // IF THE DEBUGGER BREAKS HERE - GO 1 LEVEL UP IN THE CALLSTACK TO SEE THE FAILING ASSERTION - // THIS IS THE EFFECT OF HAVING 'DOCTEST_CONFIG_SUPER_FAST_ASSERTS' DEFINED - // ######################################################################################### - if(res & assertAction::dbgbreak) - DOCTEST_BREAK_INTO_DEBUGGER(); - fastAssertThrowIfFlagSet(res); -#endif // DOCTEST_CONFIG_SUPER_FAST_ASSERTS - - return res; - } + rb.m_result.m_passed = RelationalComparator()(lhs, rhs); - template - DOCTEST_NOINLINE int fast_unary_assert(assertType::Enum assert_type, const char* file, int line, - const char* val_str, const DOCTEST_REF_WRAP(L) val) { - ResultBuilder rb(assert_type, file, line, val_str); + if (!rb.m_result.m_passed || getTestsContextState()->success) + rb.m_result.m_decomposition = stringifyBinaryExpr(lhs, ", ", rhs); - rb.m_result.m_passed = !!val; + int res = 0; - if(assert_type & assertType::is_false) //!OCLINT bitwise operator in conditional - rb.m_result.m_passed = !rb.m_result.m_passed; + if (rb.log()) res |= assertAction::dbgbreak; - if(!rb.m_result.m_passed || getTestsContextState()->success) - rb.m_result.m_decomposition = toString(val); + if (rb.m_failed && checkIfShouldThrow(assert_type)) + res |= assertAction::shouldthrow; - int res = 0; +#ifdef DOCTEST_CONFIG_SUPER_FAST_ASSERTS + // ######################################################################################### + // IF THE DEBUGGER BREAKS HERE - GO 1 LEVEL UP IN THE CALLSTACK TO SEE THE + // FAILING ASSERTION THIS IS THE EFFECT OF HAVING + // 'DOCTEST_CONFIG_SUPER_FAST_ASSERTS' DEFINED + // ######################################################################################### + if (res & assertAction::dbgbreak) DOCTEST_BREAK_INTO_DEBUGGER(); + fastAssertThrowIfFlagSet(res); +#endif // DOCTEST_CONFIG_SUPER_FAST_ASSERTS + + return res; +} - if(rb.log()) - res |= assertAction::dbgbreak; +template +DOCTEST_NOINLINE int fast_unary_assert( + assertType::Enum assert_type, const char* file, int line, + const char* val_str, const DOCTEST_REF_WRAP(L) val) { + ResultBuilder rb(assert_type, file, line, val_str); - if(rb.m_failed && checkIfShouldThrow(assert_type)) - res |= assertAction::shouldthrow; + rb.m_result.m_passed = !!val; -#ifdef DOCTEST_CONFIG_SUPER_FAST_ASSERTS - // ######################################################################################### - // IF THE DEBUGGER BREAKS HERE - GO 1 LEVEL UP IN THE CALLSTACK TO SEE THE FAILING ASSERTION - // THIS IS THE EFFECT OF HAVING 'DOCTEST_CONFIG_SUPER_FAST_ASSERTS' DEFINED - // ######################################################################################### - if(res & assertAction::dbgbreak) - DOCTEST_BREAK_INTO_DEBUGGER(); - fastAssertThrowIfFlagSet(res); -#endif // DOCTEST_CONFIG_SUPER_FAST_ASSERTS - - return res; - } + if (assert_type + & assertType::is_false) //! OCLINT bitwise operator in conditional + rb.m_result.m_passed = !rb.m_result.m_passed; - struct DOCTEST_INTERFACE IExceptionTranslator - { - virtual ~IExceptionTranslator() {} - virtual bool translate(String&) const = 0; - }; + if (!rb.m_result.m_passed || getTestsContextState()->success) + rb.m_result.m_decomposition = toString(val); - template - class ExceptionTranslator : public IExceptionTranslator //!OCLINT destructor of virtual class - { - public: - explicit ExceptionTranslator(String (*translateFunction)(T)) - : m_translateFunction(translateFunction) {} + int res = 0; - bool translate(String& res) const { -#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS - try { - throw; - // cppcheck-suppress catchExceptionByValue - } catch(T ex) { // NOLINT - res = m_translateFunction(ex); //!OCLINT parameter reassignment - return true; - } catch(...) {} //!OCLINT - empty catch statement -#endif // DOCTEST_CONFIG_NO_EXCEPTIONS - ((void)res); // to silence -Wunused-parameter - return false; - } + if (rb.log()) res |= assertAction::dbgbreak; - protected: - String (*m_translateFunction)(T); - }; + if (rb.m_failed && checkIfShouldThrow(assert_type)) + res |= assertAction::shouldthrow; - DOCTEST_INTERFACE void registerExceptionTranslatorImpl( - const IExceptionTranslator* translateFunction); +#ifdef DOCTEST_CONFIG_SUPER_FAST_ASSERTS + // ######################################################################################### + // IF THE DEBUGGER BREAKS HERE - GO 1 LEVEL UP IN THE CALLSTACK TO SEE THE + // FAILING ASSERTION THIS IS THE EFFECT OF HAVING + // 'DOCTEST_CONFIG_SUPER_FAST_ASSERTS' DEFINED + // ######################################################################################### + if (res & assertAction::dbgbreak) DOCTEST_BREAK_INTO_DEBUGGER(); + fastAssertThrowIfFlagSet(res); +#endif // DOCTEST_CONFIG_SUPER_FAST_ASSERTS + + return res; +} - // FIX FOR VISUAL STUDIO VERSIONS PRIOR TO 2015 - they failed to compile the call to operator<< with - // std::ostream passed as a reference noting that there is a use of an undefined type (which there isn't) - DOCTEST_INTERFACE void writeStringToStream(std::ostream* stream, const String& str); +struct DOCTEST_INTERFACE IExceptionTranslator { + virtual ~IExceptionTranslator() {} + virtual bool translate(String&) const = 0; +}; - template - struct StringStreamBase - { - template - static void convert(std::ostream* stream, const T& in) { - writeStringToStream(stream, toString(in)); - } +template +class ExceptionTranslator + : public IExceptionTranslator //! OCLINT destructor of virtual class +{ + public: + explicit ExceptionTranslator(String (*translateFunction)(T)) + : m_translateFunction(translateFunction) {} - // always treat char* as a string in this context - no matter - // if DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING is defined - static void convert(std::ostream* stream, const char* in) { - writeStringToStream(stream, String(in)); - } - }; + bool translate(String& res) const { +#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS + try { + throw; + // cppcheck-suppress catchExceptionByValue + } catch (T ex) { // NOLINT + res = m_translateFunction(ex); //! OCLINT parameter reassignment + return true; + } catch (...) { + } //! OCLINT - empty catch statement +#endif // DOCTEST_CONFIG_NO_EXCEPTIONS + ((void)res); // to silence -Wunused-parameter + return false; + } - template <> - struct StringStreamBase - { - template - static void convert(std::ostream* stream, const T& in) { - *stream << in; - } - }; + protected: + String (*m_translateFunction)(T); +}; + +DOCTEST_INTERFACE void registerExceptionTranslatorImpl( + const IExceptionTranslator* translateFunction); + +// FIX FOR VISUAL STUDIO VERSIONS PRIOR TO 2015 - they failed to compile the +// call to operator<< with std::ostream passed as a reference noting that there +// is a use of an undefined type (which there isn't) +DOCTEST_INTERFACE void writeStringToStream( + std::ostream* stream, const String& str); +template +struct StringStreamBase { template - struct StringStream : StringStreamBase::value> - {}; + static void convert(std::ostream* stream, const T& in) { + writeStringToStream(stream, toString(in)); + } + + // always treat char* as a string in this context - no matter + // if DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING is defined + static void convert(std::ostream* stream, const char* in) { + writeStringToStream(stream, String(in)); + } +}; +template <> +struct StringStreamBase { template - void toStream(std::ostream* stream, const T& value) { - StringStream::convert(stream, value); + static void convert(std::ostream* stream, const T& in) { + *stream << in; } +}; + +template +struct StringStream : StringStreamBase::value> {}; + +template +void toStream(std::ostream* stream, const T& value) { + StringStream::convert(stream, value); +} #ifdef DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING - DOCTEST_INTERFACE void toStream(std::ostream* stream, char* in); - DOCTEST_INTERFACE void toStream(std::ostream* stream, const char* in); -#endif // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING - DOCTEST_INTERFACE void toStream(std::ostream* stream, bool in); - DOCTEST_INTERFACE void toStream(std::ostream* stream, float in); - DOCTEST_INTERFACE void toStream(std::ostream* stream, double in); - DOCTEST_INTERFACE void toStream(std::ostream* stream, double long in); - - DOCTEST_INTERFACE void toStream(std::ostream* stream, char in); - DOCTEST_INTERFACE void toStream(std::ostream* stream, char signed in); - DOCTEST_INTERFACE void toStream(std::ostream* stream, char unsigned in); - DOCTEST_INTERFACE void toStream(std::ostream* stream, int short in); - DOCTEST_INTERFACE void toStream(std::ostream* stream, int short unsigned in); - DOCTEST_INTERFACE void toStream(std::ostream* stream, int in); - DOCTEST_INTERFACE void toStream(std::ostream* stream, int unsigned in); - DOCTEST_INTERFACE void toStream(std::ostream* stream, int long in); - DOCTEST_INTERFACE void toStream(std::ostream* stream, int long unsigned in); +DOCTEST_INTERFACE void toStream(std::ostream* stream, char* in); +DOCTEST_INTERFACE void toStream(std::ostream* stream, const char* in); +#endif // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING +DOCTEST_INTERFACE void toStream(std::ostream* stream, bool in); +DOCTEST_INTERFACE void toStream(std::ostream* stream, float in); +DOCTEST_INTERFACE void toStream(std::ostream* stream, double in); +DOCTEST_INTERFACE void toStream(std::ostream* stream, double long in); + +DOCTEST_INTERFACE void toStream(std::ostream* stream, char in); +DOCTEST_INTERFACE void toStream(std::ostream* stream, char signed in); +DOCTEST_INTERFACE void toStream(std::ostream* stream, char unsigned in); +DOCTEST_INTERFACE void toStream(std::ostream* stream, int short in); +DOCTEST_INTERFACE void toStream(std::ostream* stream, int short unsigned in); +DOCTEST_INTERFACE void toStream(std::ostream* stream, int in); +DOCTEST_INTERFACE void toStream(std::ostream* stream, int unsigned in); +DOCTEST_INTERFACE void toStream(std::ostream* stream, int long in); +DOCTEST_INTERFACE void toStream(std::ostream* stream, int long unsigned in); #ifdef DOCTEST_CONFIG_WITH_LONG_LONG - DOCTEST_INTERFACE void toStream(std::ostream* stream, int long long in); - DOCTEST_INTERFACE void toStream(std::ostream* stream, int long long unsigned in); -#endif // DOCTEST_CONFIG_WITH_LONG_LONG - - struct IContextScope - { - virtual ~IContextScope() {} - virtual void build(std::ostream*) = 0; - }; +DOCTEST_INTERFACE void toStream(std::ostream* stream, int long long in); +DOCTEST_INTERFACE void toStream( + std::ostream* stream, int long long unsigned in); +#endif // DOCTEST_CONFIG_WITH_LONG_LONG + +struct IContextScope { + virtual ~IContextScope() {} + virtual void build(std::ostream*) = 0; +}; - DOCTEST_INTERFACE void addToContexts(IContextScope* ptr); - DOCTEST_INTERFACE void popFromContexts(); - DOCTEST_INTERFACE void useContextIfExceptionOccurred(IContextScope* ptr); +DOCTEST_INTERFACE void addToContexts(IContextScope* ptr); +DOCTEST_INTERFACE void popFromContexts(); +DOCTEST_INTERFACE void useContextIfExceptionOccurred(IContextScope* ptr); - // cppcheck-suppress copyCtorAndEqOperator - class ContextBuilder - { - friend class ContextScope; +// cppcheck-suppress copyCtorAndEqOperator +class ContextBuilder { + friend class ContextScope; - struct ICapture - { - virtual ~ICapture() {} - virtual void toStream(std::ostream*) const = 0; - }; + struct ICapture { + virtual ~ICapture() {} + virtual void toStream(std::ostream*) const = 0; + }; - template - struct Capture : ICapture //!OCLINT destructor of virtual class - { - const T* capture; + template + struct Capture : ICapture //! OCLINT destructor of virtual class + { + const T* capture; - explicit Capture(const T* in) - : capture(in) {} - virtual void toStream(std::ostream* stream) const { // override - detail::toStream(stream, *capture); - } - }; + explicit Capture(const T* in) : capture(in) {} + virtual void toStream(std::ostream* stream) const { // override + detail::toStream(stream, *capture); + } + }; - struct Chunk - { - char buf[sizeof(Capture)]; // place to construct a Capture - }; + struct Chunk { + char buf[sizeof(Capture)]; // place to construct a Capture + }; - struct Node - { - Chunk chunk; - Node* next; - }; - - Chunk stackChunks[DOCTEST_CONFIG_NUM_CAPTURES_ON_STACK]; - int numCaptures; - Node* head; - Node* tail; - - void build(std::ostream* stream) const { - int curr = 0; - // iterate over small buffer - while(curr < numCaptures && curr < DOCTEST_CONFIG_NUM_CAPTURES_ON_STACK) - reinterpret_cast(stackChunks[curr++].buf)->toStream(stream); - // iterate over list - Node* curr_elem = head; - while(curr < numCaptures) { - reinterpret_cast(curr_elem->chunk.buf)->toStream(stream); - curr_elem = curr_elem->next; - ++curr; - } - } + struct Node { + Chunk chunk; + Node* next; + }; - // steal the contents of the other - acting as a move constructor... - DOCTEST_NOINLINE ContextBuilder(ContextBuilder& other) - : numCaptures(other.numCaptures) - , head(other.head) - , tail(other.tail) { - other.numCaptures = 0; - other.head = 0; - other.tail = 0; - my_memcpy(stackChunks, other.stackChunks, - unsigned(int(sizeof(Chunk)) * DOCTEST_CONFIG_NUM_CAPTURES_ON_STACK)); + Chunk stackChunks[DOCTEST_CONFIG_NUM_CAPTURES_ON_STACK]; + int numCaptures; + Node* head; + Node* tail; + + void build(std::ostream* stream) const { + int curr = 0; + // iterate over small buffer + while (curr < numCaptures + && curr < DOCTEST_CONFIG_NUM_CAPTURES_ON_STACK) + reinterpret_cast(stackChunks[curr++].buf) + ->toStream(stream); + // iterate over list + Node* curr_elem = head; + while (curr < numCaptures) { + reinterpret_cast(curr_elem->chunk.buf) + ->toStream(stream); + curr_elem = curr_elem->next; + ++curr; } + } - ContextBuilder& operator=(const ContextBuilder&); // NOLINT + // steal the contents of the other - acting as a move constructor... + DOCTEST_NOINLINE ContextBuilder(ContextBuilder& other) + : numCaptures(other.numCaptures), head(other.head), tail(other.tail) { + other.numCaptures = 0; + other.head = 0; + other.tail = 0; + my_memcpy( + stackChunks, other.stackChunks, + unsigned( + int(sizeof(Chunk)) * DOCTEST_CONFIG_NUM_CAPTURES_ON_STACK)); + } - public: - // cppcheck-suppress uninitMemberVar - DOCTEST_NOINLINE ContextBuilder() // NOLINT - : numCaptures(0) - , head(0) - , tail(0) {} + ContextBuilder& operator=(const ContextBuilder&); // NOLINT - template - DOCTEST_NOINLINE ContextBuilder& operator<<(T& in) { - Capture temp(&in); + public: + // cppcheck-suppress uninitMemberVar + DOCTEST_NOINLINE ContextBuilder() // NOLINT + : numCaptures(0), head(0), tail(0) {} - // construct either on stack or on heap - // copy the bytes for the whole object - including the vtable because we cant construct - // the object directly in the buffer using placement new - need the header... - if(numCaptures < DOCTEST_CONFIG_NUM_CAPTURES_ON_STACK) { - my_memcpy(stackChunks[numCaptures].buf, &temp, sizeof(Chunk)); + template + DOCTEST_NOINLINE ContextBuilder& operator<<(T& in) { + Capture temp(&in); + + // construct either on stack or on heap + // copy the bytes for the whole object - including the vtable because we + // cant construct the object directly in the buffer using placement new + // - need the header... + if (numCaptures < DOCTEST_CONFIG_NUM_CAPTURES_ON_STACK) { + my_memcpy(stackChunks[numCaptures].buf, &temp, sizeof(Chunk)); + } else { + Node* curr = new Node; + curr->next = 0; + if (tail) { + tail->next = curr; + tail = curr; } else { - Node* curr = new Node; - curr->next = 0; - if(tail) { - tail->next = curr; - tail = curr; - } else { - head = tail = curr; - } - - my_memcpy(tail->chunk.buf, &temp, sizeof(Chunk)); + head = tail = curr; } - ++numCaptures; - return *this; + + my_memcpy(tail->chunk.buf, &temp, sizeof(Chunk)); } + ++numCaptures; + return *this; + } - DOCTEST_NOINLINE ~ContextBuilder() { - // free the linked list - the ones on the stack are left as-is - // no destructors are called at all - there is no need - while(head) { - Node* next = head->next; - delete head; - head = next; - } + DOCTEST_NOINLINE ~ContextBuilder() { + // free the linked list - the ones on the stack are left as-is + // no destructors are called at all - there is no need + while (head) { + Node* next = head->next; + delete head; + head = next; } + } #ifdef DOCTEST_CONFIG_WITH_RVALUE_REFERENCES - template - ContextBuilder& operator<<(const T&&) { - DOCTEST_STATIC_ASSERT( - deferred_false::value, - Cannot_pass_temporaries_or_rvalues_to_the_streaming_operator_because_it_caches_pointers_to_the_passed_objects_for_lazy_evaluation); - return *this; - } -#endif // DOCTEST_CONFIG_WITH_RVALUE_REFERENCES - }; + template + ContextBuilder& operator<<(const T&&) { + DOCTEST_STATIC_ASSERT( + deferred_false::value, + Cannot_pass_temporaries_or_rvalues_to_the_streaming_operator_because_it_caches_pointers_to_the_passed_objects_for_lazy_evaluation); + return *this; + } +#endif // DOCTEST_CONFIG_WITH_RVALUE_REFERENCES +}; - class ContextScope : public IContextScope - { - ContextBuilder contextBuilder; - bool built; - - public: - DOCTEST_NOINLINE explicit ContextScope(ContextBuilder& temp) - : contextBuilder(temp) - , built(false) { - addToContexts(this); - } +class ContextScope : public IContextScope { + ContextBuilder contextBuilder; + bool built; - DOCTEST_NOINLINE ~ContextScope() { - if(!built) - useContextIfExceptionOccurred(this); - popFromContexts(); - } + public: + DOCTEST_NOINLINE explicit ContextScope(ContextBuilder& temp) + : contextBuilder(temp), built(false) { + addToContexts(this); + } - void build(std::ostream* stream) { - built = true; - contextBuilder.build(stream); - } - }; + DOCTEST_NOINLINE ~ContextScope() { + if (!built) useContextIfExceptionOccurred(this); + popFromContexts(); + } - class DOCTEST_INTERFACE MessageBuilder - { - std::ostream* m_stream; - const char* m_file; - int m_line; - assertType::Enum m_severity; - - public: - MessageBuilder(const char* file, int line, assertType::Enum severity); - ~MessageBuilder(); - - template - MessageBuilder& operator<<(const T& in) { - toStream(m_stream, in); - return *this; - } + void build(std::ostream* stream) { + built = true; + contextBuilder.build(stream); + } +}; - bool log(); - void react(); - }; -} // namespace detail +class DOCTEST_INTERFACE MessageBuilder { + std::ostream* m_stream; + const char* m_file; + int m_line; + assertType::Enum m_severity; -struct test_suite -{ + public: + MessageBuilder(const char* file, int line, assertType::Enum severity); + ~MessageBuilder(); + + template + MessageBuilder& operator<<(const T& in) { + toStream(m_stream, in); + return *this; + } + + bool log(); + void react(); +}; +} // namespace detail + +struct test_suite { const char* data; - test_suite(const char* in) - : data(in) {} + test_suite(const char* in) : data(in) {} void fill(detail::TestCase& state) const { state.m_test_suite = data; } void fill(detail::TestSuite& state) const { state.m_test_suite = data; } }; -struct description -{ +struct description { const char* data; - description(const char* in) - : data(in) {} + description(const char* in) : data(in) {} void fill(detail::TestCase& state) const { state.m_description = data; } void fill(detail::TestSuite& state) const { state.m_description = data; } }; -struct skip -{ +struct skip { bool data; - skip(bool in = true) - : data(in) {} + skip(bool in = true) : data(in) {} void fill(detail::TestCase& state) const { state.m_skip = data; } void fill(detail::TestSuite& state) const { state.m_skip = data; } }; -struct timeout -{ +struct timeout { double data; - timeout(double in) - : data(in) {} + timeout(double in) : data(in) {} void fill(detail::TestCase& state) const { state.m_timeout = data; } void fill(detail::TestSuite& state) const { state.m_timeout = data; } }; -struct may_fail -{ +struct may_fail { bool data; - may_fail(bool in = true) - : data(in) {} + may_fail(bool in = true) : data(in) {} void fill(detail::TestCase& state) const { state.m_may_fail = data; } void fill(detail::TestSuite& state) const { state.m_may_fail = data; } }; -struct should_fail -{ +struct should_fail { bool data; - should_fail(bool in = true) - : data(in) {} + should_fail(bool in = true) : data(in) {} void fill(detail::TestCase& state) const { state.m_should_fail = data; } void fill(detail::TestSuite& state) const { state.m_should_fail = data; } }; -struct expected_failures -{ +struct expected_failures { int data; - expected_failures(int in) - : data(in) {} - void fill(detail::TestCase& state) const { state.m_expected_failures = data; } - void fill(detail::TestSuite& state) const { state.m_expected_failures = data; } + expected_failures(int in) : data(in) {} + void fill(detail::TestCase& state) const { + state.m_expected_failures = data; + } + void fill(detail::TestSuite& state) const { + state.m_expected_failures = data; + } }; -#endif // DOCTEST_CONFIG_DISABLE +#endif // DOCTEST_CONFIG_DISABLE #ifndef DOCTEST_CONFIG_DISABLE template int registerExceptionTranslator(String (*translateFunction)(T)) { DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH("-Wexit-time-destructors") - static detail::ExceptionTranslator exceptionTranslator(translateFunction); + static detail::ExceptionTranslator exceptionTranslator( + translateFunction); DOCTEST_CLANG_SUPPRESS_WARNING_POP detail::registerExceptionTranslatorImpl(&exceptionTranslator); return 0; } -#else // DOCTEST_CONFIG_DISABLE +#else // DOCTEST_CONFIG_DISABLE template int registerExceptionTranslator(String (*)(T)) { return 0; } -#endif // DOCTEST_CONFIG_DISABLE +#endif // DOCTEST_CONFIG_DISABLE DOCTEST_INTERFACE bool isRunningInTest(); // cppcheck-suppress noCopyConstructor -class DOCTEST_INTERFACE Context -{ +class DOCTEST_INTERFACE Context { #if !defined(DOCTEST_CONFIG_DISABLE) detail::ContextState* p; - void parseArgs(int argc, const char* const* argv, bool withDefaults = false); + void parseArgs( + int argc, const char* const* argv, bool withDefaults = false); -#endif // DOCTEST_CONFIG_DISABLE +#endif // DOCTEST_CONFIG_DISABLE -public: + public: explicit Context(int argc = 0, const char* const* argv = 0); ~Context(); @@ -2116,238 +2127,245 @@ class DOCTEST_INTERFACE Context int run(); }; -} // namespace doctest +} // namespace doctest // if registering is not disabled #if !defined(DOCTEST_CONFIG_DISABLE) #ifdef DOCTEST_CONFIG_WITH_VARIADIC_MACROS #define DOCTEST_EXPAND_VA_ARGS(...) __VA_ARGS__ -#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS #define DOCTEST_EXPAND_VA_ARGS -#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS #define DOCTEST_STRIP_PARENS(x) x -#define DOCTEST_HANDLE_BRACED_VA_ARGS(expr) DOCTEST_STRIP_PARENS(DOCTEST_EXPAND_VA_ARGS expr) +#define DOCTEST_HANDLE_BRACED_VA_ARGS(expr) \ + DOCTEST_STRIP_PARENS(DOCTEST_EXPAND_VA_ARGS expr) // registers the test by initializing a dummy var with a function -#define DOCTEST_REGISTER_FUNCTION(f, decorators) \ - DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(_DOCTEST_ANON_VAR_)) = doctest::detail::regTest( \ - doctest::detail::TestCase(f, __FILE__, __LINE__, \ - doctest_detail_test_suite_ns::getCurrentTestSuite()) * \ - decorators); \ +#define DOCTEST_REGISTER_FUNCTION(f, decorators) \ + DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(_DOCTEST_ANON_VAR_)) = \ + doctest::detail::regTest( \ + doctest::detail::TestCase( \ + f, __FILE__, __LINE__, \ + doctest_detail_test_suite_ns::getCurrentTestSuite()) \ + * decorators); \ DOCTEST_GLOBAL_NO_WARNINGS_END() -#define DOCTEST_IMPLEMENT_FIXTURE(der, base, func, decorators) \ - namespace \ - { \ - struct der : base \ - { \ - void f(); \ - }; \ - static void func() { \ - der v; \ - v.f(); \ - } \ - DOCTEST_REGISTER_FUNCTION(func, decorators) \ - } \ +#define DOCTEST_IMPLEMENT_FIXTURE(der, base, func, decorators) \ + namespace { \ + struct der : base { \ + void f(); \ + }; \ + static void func() { \ + der v; \ + v.f(); \ + } \ + DOCTEST_REGISTER_FUNCTION(func, decorators) \ + } \ inline DOCTEST_NOINLINE void der::f() -#define DOCTEST_CREATE_AND_REGISTER_FUNCTION(f, decorators) \ - static void f(); \ - DOCTEST_REGISTER_FUNCTION(f, decorators) \ +#define DOCTEST_CREATE_AND_REGISTER_FUNCTION(f, decorators) \ + static void f(); \ + DOCTEST_REGISTER_FUNCTION(f, decorators) \ static void f() // for registering tests -#define DOCTEST_TEST_CASE(decorators) \ - DOCTEST_CREATE_AND_REGISTER_FUNCTION(DOCTEST_ANONYMOUS(_DOCTEST_ANON_FUNC_), decorators) +#define DOCTEST_TEST_CASE(decorators) \ + DOCTEST_CREATE_AND_REGISTER_FUNCTION( \ + DOCTEST_ANONYMOUS(_DOCTEST_ANON_FUNC_), decorators) // for registering tests with a fixture -#define DOCTEST_TEST_CASE_FIXTURE(c, decorators) \ - DOCTEST_IMPLEMENT_FIXTURE(DOCTEST_ANONYMOUS(_DOCTEST_ANON_CLASS_), c, \ - DOCTEST_ANONYMOUS(_DOCTEST_ANON_FUNC_), decorators) +#define DOCTEST_TEST_CASE_FIXTURE(c, decorators) \ + DOCTEST_IMPLEMENT_FIXTURE( \ + DOCTEST_ANONYMOUS(_DOCTEST_ANON_CLASS_), c, \ + DOCTEST_ANONYMOUS(_DOCTEST_ANON_FUNC_), decorators) // for converting types to strings without the header and demangling #ifdef DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#define DOCTEST_TYPE_TO_STRING_IMPL(...) \ - template <> \ - inline const char* type_to_string<__VA_ARGS__>() { \ - return "<" #__VA_ARGS__ ">"; \ +#define DOCTEST_TYPE_TO_STRING_IMPL(...) \ + template <> \ + inline const char* type_to_string<__VA_ARGS__>() { \ + return "<" #__VA_ARGS__ ">"; \ } -#define DOCTEST_TYPE_TO_STRING(...) \ - namespace doctest \ - { \ - namespace detail \ - { \ - DOCTEST_TYPE_TO_STRING_IMPL(__VA_ARGS__) \ - } \ - } \ +#define DOCTEST_TYPE_TO_STRING(...) \ + namespace doctest { \ + namespace detail { \ + DOCTEST_TYPE_TO_STRING_IMPL(__VA_ARGS__) \ + } \ + } \ typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_) -#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#define DOCTEST_TYPE_TO_STRING_IMPL(x) \ - template <> \ - inline const char* type_to_string() { \ - return "<" #x ">"; \ +#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#define DOCTEST_TYPE_TO_STRING_IMPL(x) \ + template <> \ + inline const char* type_to_string() { \ + return "<" #x ">"; \ } -#define DOCTEST_TYPE_TO_STRING(x) \ - namespace doctest \ - { \ - namespace detail \ - { \ - DOCTEST_TYPE_TO_STRING_IMPL(x) \ - } \ - } \ +#define DOCTEST_TYPE_TO_STRING(x) \ + namespace doctest { \ + namespace detail { \ + DOCTEST_TYPE_TO_STRING_IMPL(x) \ + } \ + } \ typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_) -#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS // for typed tests -#define DOCTEST_TEST_CASE_TEMPLATE_IMPL(decorators, T, types, anon) \ - template \ - inline void anon(); \ - struct DOCTEST_CAT(anon, FUNCTOR) \ - { \ - template \ - void operator()() { \ - doctest::detail::regTest( \ - doctest::detail::TestCase(anon, __FILE__, __LINE__, \ - doctest_detail_test_suite_ns::getCurrentTestSuite(), \ - doctest::detail::type_to_string(), Index) * \ - decorators); \ - } \ - }; \ - inline int DOCTEST_CAT(anon, REG_FUNC)() { \ - DOCTEST_CAT(anon, FUNCTOR) registrar; \ - doctest::detail::ForEachType \ - doIt(registrar); \ - return 0; \ - } \ - DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_CAT(anon, DUMMY)) = DOCTEST_CAT(anon, REG_FUNC)(); \ - DOCTEST_GLOBAL_NO_WARNINGS_END() \ - template \ +#define DOCTEST_TEST_CASE_TEMPLATE_IMPL(decorators, T, types, anon) \ + template \ + inline void anon(); \ + struct DOCTEST_CAT(anon, FUNCTOR) { \ + template \ + void operator()() { \ + doctest::detail::regTest( \ + doctest::detail::TestCase( \ + anon, __FILE__, __LINE__, \ + doctest_detail_test_suite_ns::getCurrentTestSuite(), \ + doctest::detail::type_to_string(), Index) \ + * decorators); \ + } \ + }; \ + inline int DOCTEST_CAT(anon, REG_FUNC)() { \ + DOCTEST_CAT(anon, FUNCTOR) registrar; \ + doctest::detail::ForEachType< \ + DOCTEST_HANDLE_BRACED_VA_ARGS(types)::Result, \ + DOCTEST_CAT(anon, FUNCTOR)> \ + doIt(registrar); \ + return 0; \ + } \ + DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_CAT(anon, DUMMY)) = \ + DOCTEST_CAT(anon, REG_FUNC)(); \ + DOCTEST_GLOBAL_NO_WARNINGS_END() \ + template \ inline void anon() #ifdef DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#define DOCTEST_TEST_CASE_TEMPLATE(decorators, T, ...) \ - DOCTEST_TEST_CASE_TEMPLATE_IMPL(decorators, T, (__VA_ARGS__), \ - DOCTEST_ANONYMOUS(_DOCTEST_ANON_TMP_)) -#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#define DOCTEST_TEST_CASE_TEMPLATE(decorators, T, types) \ - DOCTEST_TEST_CASE_TEMPLATE_IMPL(decorators, T, types, DOCTEST_ANONYMOUS(_DOCTEST_ANON_TMP_)) -#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS - -#define DOCTEST_TEST_CASE_TEMPLATE_DEFINE_IMPL(decorators, T, id, anon) \ - template \ - inline void anon(); \ - struct DOCTEST_CAT(id, _FUNCTOR) \ - { \ - int m_line; \ - DOCTEST_CAT(id, _FUNCTOR) \ - (int line) \ - : m_line(line) {} \ - template \ - void operator()() { \ - doctest::detail::regTest( \ - doctest::detail::TestCase(anon, __FILE__, __LINE__, \ - doctest_detail_test_suite_ns::getCurrentTestSuite(), \ - doctest::detail::type_to_string(), \ - m_line * 1000 + Index) * \ - decorators); \ - } \ - }; \ - template \ +#define DOCTEST_TEST_CASE_TEMPLATE(decorators, T, ...) \ + DOCTEST_TEST_CASE_TEMPLATE_IMPL( \ + decorators, T, (__VA_ARGS__), DOCTEST_ANONYMOUS(_DOCTEST_ANON_TMP_)) +#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#define DOCTEST_TEST_CASE_TEMPLATE(decorators, T, types) \ + DOCTEST_TEST_CASE_TEMPLATE_IMPL( \ + decorators, T, types, DOCTEST_ANONYMOUS(_DOCTEST_ANON_TMP_)) +#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS + +#define DOCTEST_TEST_CASE_TEMPLATE_DEFINE_IMPL(decorators, T, id, anon) \ + template \ + inline void anon(); \ + struct DOCTEST_CAT(id, _FUNCTOR) { \ + int m_line; \ + DOCTEST_CAT(id, _FUNCTOR) \ + (int line) : m_line(line) {} \ + template \ + void operator()() { \ + doctest::detail::regTest( \ + doctest::detail::TestCase( \ + anon, __FILE__, __LINE__, \ + doctest_detail_test_suite_ns::getCurrentTestSuite(), \ + doctest::detail::type_to_string(), \ + m_line * 1000 + Index) \ + * decorators); \ + } \ + }; \ + template \ inline void anon() -#define DOCTEST_TEST_CASE_TEMPLATE_DEFINE(decorators, T, id) \ - DOCTEST_TEST_CASE_TEMPLATE_DEFINE_IMPL(decorators, T, id, DOCTEST_ANONYMOUS(_DOCTEST_ANON_TMP_)) - -#define DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE_IMPL(id, types, anon) \ - static int DOCTEST_CAT(anon, REG_FUNC)() { \ - DOCTEST_CAT(id, _FUNCTOR) registrar(__LINE__); \ - doctest::detail::ForEachType \ - doIt(registrar); \ - return 0; \ - } \ - DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_CAT(anon, DUMMY)) = DOCTEST_CAT(anon, REG_FUNC)(); \ - DOCTEST_GLOBAL_NO_WARNINGS_END() typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_) +#define DOCTEST_TEST_CASE_TEMPLATE_DEFINE(decorators, T, id) \ + DOCTEST_TEST_CASE_TEMPLATE_DEFINE_IMPL( \ + decorators, T, id, DOCTEST_ANONYMOUS(_DOCTEST_ANON_TMP_)) + +#define DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE_IMPL(id, types, anon) \ + static int DOCTEST_CAT(anon, REG_FUNC)() { \ + DOCTEST_CAT(id, _FUNCTOR) registrar(__LINE__); \ + doctest::detail::ForEachType< \ + DOCTEST_HANDLE_BRACED_VA_ARGS(types)::Result, \ + DOCTEST_CAT(id, _FUNCTOR)> \ + doIt(registrar); \ + return 0; \ + } \ + DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_CAT(anon, DUMMY)) = \ + DOCTEST_CAT(anon, REG_FUNC)(); \ + DOCTEST_GLOBAL_NO_WARNINGS_END() \ + typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_) #ifdef DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#define DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE(id, ...) \ - DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE_IMPL(id, (__VA_ARGS__), \ - DOCTEST_ANONYMOUS(_DOCTEST_ANON_TMP_)) -#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#define DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE(id, types) \ - DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE_IMPL(id, types, DOCTEST_ANONYMOUS(_DOCTEST_ANON_TMP_)) -#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#define DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE(id, ...) \ + DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE_IMPL( \ + id, (__VA_ARGS__), DOCTEST_ANONYMOUS(_DOCTEST_ANON_TMP_)) +#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#define DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE(id, types) \ + DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE_IMPL( \ + id, types, DOCTEST_ANONYMOUS(_DOCTEST_ANON_TMP_)) +#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS // for subcases -#define DOCTEST_SUBCASE(name) \ - if(const doctest::detail::Subcase & DOCTEST_ANONYMOUS(_DOCTEST_ANON_SUBCASE_) DOCTEST_UNUSED = \ - doctest::detail::Subcase(name, __FILE__, __LINE__)) +#define DOCTEST_SUBCASE(name) \ + if (const doctest::detail::Subcase \ + & DOCTEST_ANONYMOUS(_DOCTEST_ANON_SUBCASE_) DOCTEST_UNUSED = \ + doctest::detail::Subcase(name, __FILE__, __LINE__)) // for grouping tests in test suites by using code blocks -#define DOCTEST_TEST_SUITE_IMPL(decorators, ns_name) \ - namespace ns_name \ - { \ - namespace doctest_detail_test_suite_ns \ - { \ - static DOCTEST_NOINLINE doctest::detail::TestSuite& getCurrentTestSuite() { \ - static doctest::detail::TestSuite data; \ - static bool inited = false; \ - if(!inited) { \ - data* decorators; \ - inited = true; \ - } \ - return data; \ - } \ - } \ - } \ +#define DOCTEST_TEST_SUITE_IMPL(decorators, ns_name) \ + namespace ns_name { \ + namespace doctest_detail_test_suite_ns { \ + static DOCTEST_NOINLINE doctest::detail::TestSuite& \ + getCurrentTestSuite() { \ + static doctest::detail::TestSuite data; \ + static bool inited = false; \ + if (!inited) { \ + data* decorators; \ + inited = true; \ + } \ + return data; \ + } \ + } \ + } \ namespace ns_name -#define DOCTEST_TEST_SUITE(decorators) \ +#define DOCTEST_TEST_SUITE(decorators) \ DOCTEST_TEST_SUITE_IMPL(decorators, DOCTEST_ANONYMOUS(_DOCTEST_ANON_SUITE_)) // for starting a testsuite block -#define DOCTEST_TEST_SUITE_BEGIN(decorators) \ - DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(_DOCTEST_ANON_VAR_)) = \ - doctest::detail::setTestSuite(doctest::detail::TestSuite() * decorators); \ - DOCTEST_GLOBAL_NO_WARNINGS_END() \ +#define DOCTEST_TEST_SUITE_BEGIN(decorators) \ + DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(_DOCTEST_ANON_VAR_)) = \ + doctest::detail::setTestSuite( \ + doctest::detail::TestSuite() * decorators); \ + DOCTEST_GLOBAL_NO_WARNINGS_END() \ typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_) // for ending a testsuite block -#define DOCTEST_TEST_SUITE_END \ - DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(_DOCTEST_ANON_VAR_)) = \ - doctest::detail::setTestSuite(doctest::detail::TestSuite() * ""); \ - DOCTEST_GLOBAL_NO_WARNINGS_END() \ +#define DOCTEST_TEST_SUITE_END \ + DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(_DOCTEST_ANON_VAR_)) = \ + doctest::detail::setTestSuite(doctest::detail::TestSuite() * ""); \ + DOCTEST_GLOBAL_NO_WARNINGS_END() \ typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_) // for registering exception translators -#define DOCTEST_REGISTER_EXCEPTION_TRANSLATOR_IMPL(translatorName, signature) \ - inline doctest::String translatorName(signature); \ - DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(_DOCTEST_ANON_TRANSLATOR_)) = \ - doctest::registerExceptionTranslator(translatorName); \ - DOCTEST_GLOBAL_NO_WARNINGS_END() \ +#define DOCTEST_REGISTER_EXCEPTION_TRANSLATOR_IMPL(translatorName, signature) \ + inline doctest::String translatorName(signature); \ + DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(_DOCTEST_ANON_TRANSLATOR_)) = \ + doctest::registerExceptionTranslator(translatorName); \ + DOCTEST_GLOBAL_NO_WARNINGS_END() \ doctest::String translatorName(signature) -#define DOCTEST_REGISTER_EXCEPTION_TRANSLATOR(signature) \ - DOCTEST_REGISTER_EXCEPTION_TRANSLATOR_IMPL(DOCTEST_ANONYMOUS(_DOCTEST_ANON_TRANSLATOR_), \ - signature) +#define DOCTEST_REGISTER_EXCEPTION_TRANSLATOR(signature) \ + DOCTEST_REGISTER_EXCEPTION_TRANSLATOR_IMPL( \ + DOCTEST_ANONYMOUS(_DOCTEST_ANON_TRANSLATOR_), signature) // for logging -#define DOCTEST_INFO(x) \ - doctest::detail::ContextScope DOCTEST_ANONYMOUS(_DOCTEST_CAPTURE_)( \ - doctest::detail::ContextBuilder() << x) +#define DOCTEST_INFO(x) \ + doctest::detail::ContextScope DOCTEST_ANONYMOUS(_DOCTEST_CAPTURE_)( \ + doctest::detail::ContextBuilder() << x) #define DOCTEST_CAPTURE(x) DOCTEST_INFO(#x " := " << x) -#define DOCTEST_ADD_AT_IMPL(type, file, line, mb, x) \ - do { \ - doctest::detail::MessageBuilder mb(file, line, doctest::detail::assertType::type); \ - mb << x; \ - if(mb.log()) \ - DOCTEST_BREAK_INTO_DEBUGGER(); \ - mb.react(); \ - } while((void)0, 0) +#define DOCTEST_ADD_AT_IMPL(type, file, line, mb, x) \ + do { \ + doctest::detail::MessageBuilder mb( \ + file, line, doctest::detail::assertType::type); \ + mb << x; \ + if (mb.log()) DOCTEST_BREAK_INTO_DEBUGGER(); \ + mb.react(); \ + } while ((void)0, 0) // clang-format off #define DOCTEST_ADD_MESSAGE_AT(file, line, x) DOCTEST_ADD_AT_IMPL(is_warn, file, line, DOCTEST_ANONYMOUS(_DOCTEST_MESSAGE_), x) @@ -2365,58 +2383,69 @@ constexpr T to_lvalue = x; #define DOCTEST_TO_LVALUE(...) to_lvalue #else #ifdef DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#define DOCTEST_TO_LVALUE(...) TO_LVALUE_CAN_BE_USED_ONLY_IN_CPP14_MODE_OR_WITH_VS_2017_OR_NEWER -#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#define DOCTEST_TO_LVALUE(x) TO_LVALUE_CAN_BE_USED_ONLY_IN_CPP14_MODE_OR_WITH_VS_2017_OR_NEWER -#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#endif // TO_LVALUE hack for logging macros like INFO() +#define DOCTEST_TO_LVALUE(...) \ + TO_LVALUE_CAN_BE_USED_ONLY_IN_CPP14_MODE_OR_WITH_VS_2017_OR_NEWER +#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#define DOCTEST_TO_LVALUE(x) \ + TO_LVALUE_CAN_BE_USED_ONLY_IN_CPP14_MODE_OR_WITH_VS_2017_OR_NEWER +#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#endif // TO_LVALUE hack for logging macros like INFO() // common code in asserts - for convenience -#define DOCTEST_ASSERT_LOG_AND_REACT(rb) \ - if(rb.log()) \ - DOCTEST_BREAK_INTO_DEBUGGER(); \ +#define DOCTEST_ASSERT_LOG_AND_REACT(rb) \ + if (rb.log()) DOCTEST_BREAK_INTO_DEBUGGER(); \ rb.react() #ifdef DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS #define DOCTEST_WRAP_IN_TRY(x) x; -#else // DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS -#define DOCTEST_WRAP_IN_TRY(x) \ - try { \ - x; \ - } catch(...) { _DOCTEST_RB.unexpectedExceptionOccurred(); } -#endif // DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS - -#define DOCTEST_ASSERT_IMPLEMENT_2(expr, assert_type) \ - DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH("-Woverloaded-shift-op-parentheses") \ - doctest::detail::ResultBuilder _DOCTEST_RB( \ - doctest::detail::assertType::assert_type, __FILE__, __LINE__, \ - DOCTEST_TOSTR(DOCTEST_HANDLE_BRACED_VA_ARGS(expr))); \ - DOCTEST_WRAP_IN_TRY(_DOCTEST_RB.setResult( \ - doctest::detail::ExpressionDecomposer(doctest::detail::assertType::assert_type) \ - << DOCTEST_HANDLE_BRACED_VA_ARGS(expr))) \ - DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB) \ +#else // DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS +#define DOCTEST_WRAP_IN_TRY(x) \ + try { \ + x; \ + } catch (...) { \ + _DOCTEST_RB.unexpectedExceptionOccurred(); \ + } +#endif // DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS + +#define DOCTEST_ASSERT_IMPLEMENT_2(expr, assert_type) \ + DOCTEST_CLANG_SUPPRESS_WARNING_WITH_PUSH( \ + "-Woverloaded-shift-op-parentheses") \ + doctest::detail::ResultBuilder _DOCTEST_RB( \ + doctest::detail::assertType::assert_type, __FILE__, __LINE__, \ + DOCTEST_TOSTR(DOCTEST_HANDLE_BRACED_VA_ARGS(expr))); \ + DOCTEST_WRAP_IN_TRY(_DOCTEST_RB.setResult( \ + doctest::detail::ExpressionDecomposer( \ + doctest::detail::assertType::assert_type) \ + << DOCTEST_HANDLE_BRACED_VA_ARGS(expr))) \ + DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB) \ DOCTEST_CLANG_SUPPRESS_WARNING_POP -#define DOCTEST_ASSERT_IMPLEMENT_1(expr, assert_type) \ - do { \ - DOCTEST_ASSERT_IMPLEMENT_2(expr, assert_type); \ - } while((void)0, 0) +#define DOCTEST_ASSERT_IMPLEMENT_1(expr, assert_type) \ + do { \ + DOCTEST_ASSERT_IMPLEMENT_2(expr, assert_type); \ + } while ((void)0, 0) #ifdef DOCTEST_CONFIG_WITH_VARIADIC_MACROS #define DOCTEST_WARN(...) DOCTEST_ASSERT_IMPLEMENT_1((__VA_ARGS__), DT_WARN) #define DOCTEST_CHECK(...) DOCTEST_ASSERT_IMPLEMENT_1((__VA_ARGS__), DT_CHECK) -#define DOCTEST_REQUIRE(...) DOCTEST_ASSERT_IMPLEMENT_1((__VA_ARGS__), DT_REQUIRE) -#define DOCTEST_WARN_FALSE(...) DOCTEST_ASSERT_IMPLEMENT_1((__VA_ARGS__), DT_WARN_FALSE) -#define DOCTEST_CHECK_FALSE(...) DOCTEST_ASSERT_IMPLEMENT_1((__VA_ARGS__), DT_CHECK_FALSE) -#define DOCTEST_REQUIRE_FALSE(...) DOCTEST_ASSERT_IMPLEMENT_1((__VA_ARGS__), DT_REQUIRE_FALSE) -#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#define DOCTEST_REQUIRE(...) \ + DOCTEST_ASSERT_IMPLEMENT_1((__VA_ARGS__), DT_REQUIRE) +#define DOCTEST_WARN_FALSE(...) \ + DOCTEST_ASSERT_IMPLEMENT_1((__VA_ARGS__), DT_WARN_FALSE) +#define DOCTEST_CHECK_FALSE(...) \ + DOCTEST_ASSERT_IMPLEMENT_1((__VA_ARGS__), DT_CHECK_FALSE) +#define DOCTEST_REQUIRE_FALSE(...) \ + DOCTEST_ASSERT_IMPLEMENT_1((__VA_ARGS__), DT_REQUIRE_FALSE) +#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS #define DOCTEST_WARN(expr) DOCTEST_ASSERT_IMPLEMENT_1(expr, DT_WARN) #define DOCTEST_CHECK(expr) DOCTEST_ASSERT_IMPLEMENT_1(expr, DT_CHECK) #define DOCTEST_REQUIRE(expr) DOCTEST_ASSERT_IMPLEMENT_1(expr, DT_REQUIRE) #define DOCTEST_WARN_FALSE(expr) DOCTEST_ASSERT_IMPLEMENT_1(expr, DT_WARN_FALSE) -#define DOCTEST_CHECK_FALSE(expr) DOCTEST_ASSERT_IMPLEMENT_1(expr, DT_CHECK_FALSE) -#define DOCTEST_REQUIRE_FALSE(expr) DOCTEST_ASSERT_IMPLEMENT_1(expr, DT_REQUIRE_FALSE) -#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#define DOCTEST_CHECK_FALSE(expr) \ + DOCTEST_ASSERT_IMPLEMENT_1(expr, DT_CHECK_FALSE) +#define DOCTEST_REQUIRE_FALSE(expr) \ + DOCTEST_ASSERT_IMPLEMENT_1(expr, DT_REQUIRE_FALSE) +#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS // clang-format off #ifdef DOCTEST_CONFIG_WITH_VARIADIC_MACROS @@ -2436,49 +2465,58 @@ constexpr T to_lvalue = x; #endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS // clang-format on -#define DOCTEST_ASSERT_THROWS(expr, assert_type) \ - do { \ - if(!doctest::detail::getTestsContextState()->no_throw) { \ - doctest::detail::ResultBuilder _DOCTEST_RB(doctest::detail::assertType::assert_type, \ - __FILE__, __LINE__, #expr); \ - try { \ - expr; \ - } catch(...) { _DOCTEST_RB.m_threw = true; } \ - DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \ - } \ - } while((void)0, 0) - -#define DOCTEST_ASSERT_THROWS_AS(expr, as, assert_type) \ - do { \ - if(!doctest::detail::getTestsContextState()->no_throw) { \ - doctest::detail::ResultBuilder _DOCTEST_RB( \ - doctest::detail::assertType::assert_type, __FILE__, __LINE__, #expr, \ - DOCTEST_TOSTR(DOCTEST_HANDLE_BRACED_VA_ARGS(as))); \ - try { \ - expr; \ - } catch(const DOCTEST_HANDLE_BRACED_VA_ARGS(as)&) { \ - _DOCTEST_RB.m_threw = true; \ - _DOCTEST_RB.m_threw_as = true; \ - } catch(...) { _DOCTEST_RB.unexpectedExceptionOccurred(); } \ - DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \ - } \ - } while((void)0, 0) - -#define DOCTEST_ASSERT_NOTHROW(expr, assert_type) \ - do { \ - if(!doctest::detail::getTestsContextState()->no_throw) { \ - doctest::detail::ResultBuilder _DOCTEST_RB(doctest::detail::assertType::assert_type, \ - __FILE__, __LINE__, #expr); \ - try { \ - expr; \ - } catch(...) { _DOCTEST_RB.unexpectedExceptionOccurred(); } \ - DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \ - } \ - } while((void)0, 0) +#define DOCTEST_ASSERT_THROWS(expr, assert_type) \ + do { \ + if (!doctest::detail::getTestsContextState()->no_throw) { \ + doctest::detail::ResultBuilder _DOCTEST_RB( \ + doctest::detail::assertType::assert_type, __FILE__, __LINE__, \ + #expr); \ + try { \ + expr; \ + } catch (...) { \ + _DOCTEST_RB.m_threw = true; \ + } \ + DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \ + } \ + } while ((void)0, 0) + +#define DOCTEST_ASSERT_THROWS_AS(expr, as, assert_type) \ + do { \ + if (!doctest::detail::getTestsContextState()->no_throw) { \ + doctest::detail::ResultBuilder _DOCTEST_RB( \ + doctest::detail::assertType::assert_type, __FILE__, __LINE__, \ + #expr, DOCTEST_TOSTR(DOCTEST_HANDLE_BRACED_VA_ARGS(as))); \ + try { \ + expr; \ + } catch (const DOCTEST_HANDLE_BRACED_VA_ARGS(as)&) { \ + _DOCTEST_RB.m_threw = true; \ + _DOCTEST_RB.m_threw_as = true; \ + } catch (...) { \ + _DOCTEST_RB.unexpectedExceptionOccurred(); \ + } \ + DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \ + } \ + } while ((void)0, 0) + +#define DOCTEST_ASSERT_NOTHROW(expr, assert_type) \ + do { \ + if (!doctest::detail::getTestsContextState()->no_throw) { \ + doctest::detail::ResultBuilder _DOCTEST_RB( \ + doctest::detail::assertType::assert_type, __FILE__, __LINE__, \ + #expr); \ + try { \ + expr; \ + } catch (...) { \ + _DOCTEST_RB.unexpectedExceptionOccurred(); \ + } \ + DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \ + } \ + } while ((void)0, 0) #define DOCTEST_WARN_THROWS(expr) DOCTEST_ASSERT_THROWS(expr, DT_WARN_THROWS) #define DOCTEST_CHECK_THROWS(expr) DOCTEST_ASSERT_THROWS(expr, DT_CHECK_THROWS) -#define DOCTEST_REQUIRE_THROWS(expr) DOCTEST_ASSERT_THROWS(expr, DT_REQUIRE_THROWS) +#define DOCTEST_REQUIRE_THROWS(expr) \ + DOCTEST_ASSERT_THROWS(expr, DT_REQUIRE_THROWS) // clang-format off #ifdef DOCTEST_CONFIG_WITH_VARIADIC_MACROS @@ -2493,8 +2531,10 @@ constexpr T to_lvalue = x; // clang-format on #define DOCTEST_WARN_NOTHROW(expr) DOCTEST_ASSERT_NOTHROW(expr, DT_WARN_NOTHROW) -#define DOCTEST_CHECK_NOTHROW(expr) DOCTEST_ASSERT_NOTHROW(expr, DT_CHECK_NOTHROW) -#define DOCTEST_REQUIRE_NOTHROW(expr) DOCTEST_ASSERT_NOTHROW(expr, DT_REQUIRE_NOTHROW) +#define DOCTEST_CHECK_NOTHROW(expr) \ + DOCTEST_ASSERT_NOTHROW(expr, DT_CHECK_NOTHROW) +#define DOCTEST_REQUIRE_NOTHROW(expr) \ + DOCTEST_ASSERT_NOTHROW(expr, DT_REQUIRE_NOTHROW) // clang-format off #define DOCTEST_WARN_THROWS_MESSAGE(expr, msg) do { DOCTEST_INFO(msg); DOCTEST_WARN_THROWS(expr); } while((void)0, 0) @@ -2509,151 +2549,201 @@ constexpr T to_lvalue = x; // clang-format on #ifdef DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#define DOCTEST_BINARY_ASSERT(assert_type, expr, comp) \ - do { \ - doctest::detail::ResultBuilder _DOCTEST_RB( \ - doctest::detail::assertType::assert_type, __FILE__, __LINE__, \ - DOCTEST_TOSTR(DOCTEST_HANDLE_BRACED_VA_ARGS(expr))); \ - DOCTEST_WRAP_IN_TRY( \ - _DOCTEST_RB.binary_assert( \ - DOCTEST_HANDLE_BRACED_VA_ARGS(expr))) \ - DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \ - } while((void)0, 0) -#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#define DOCTEST_BINARY_ASSERT(assert_type, lhs, rhs, comp) \ - do { \ - doctest::detail::ResultBuilder _DOCTEST_RB(doctest::detail::assertType::assert_type, \ - __FILE__, __LINE__, #lhs ", " #rhs); \ - DOCTEST_WRAP_IN_TRY( \ - _DOCTEST_RB.binary_assert(lhs, \ - rhs)) \ - DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \ - } while((void)0, 0) -#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS - -#define DOCTEST_UNARY_ASSERT(assert_type, expr) \ - do { \ - doctest::detail::ResultBuilder _DOCTEST_RB( \ - doctest::detail::assertType::assert_type, __FILE__, __LINE__, \ - DOCTEST_TOSTR(DOCTEST_HANDLE_BRACED_VA_ARGS(expr))); \ - DOCTEST_WRAP_IN_TRY(_DOCTEST_RB.unary_assert(DOCTEST_HANDLE_BRACED_VA_ARGS(expr))) \ - DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \ - } while((void)0, 0) +#define DOCTEST_BINARY_ASSERT(assert_type, expr, comp) \ + do { \ + doctest::detail::ResultBuilder _DOCTEST_RB( \ + doctest::detail::assertType::assert_type, __FILE__, __LINE__, \ + DOCTEST_TOSTR(DOCTEST_HANDLE_BRACED_VA_ARGS(expr))); \ + DOCTEST_WRAP_IN_TRY( \ + _DOCTEST_RB \ + .binary_assert( \ + DOCTEST_HANDLE_BRACED_VA_ARGS(expr))) \ + DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \ + } while ((void)0, 0) +#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#define DOCTEST_BINARY_ASSERT(assert_type, lhs, rhs, comp) \ + do { \ + doctest::detail::ResultBuilder _DOCTEST_RB( \ + doctest::detail::assertType::assert_type, __FILE__, __LINE__, \ + #lhs ", " #rhs); \ + DOCTEST_WRAP_IN_TRY( \ + _DOCTEST_RB \ + .binary_assert( \ + lhs, rhs)) \ + DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \ + } while ((void)0, 0) +#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS + +#define DOCTEST_UNARY_ASSERT(assert_type, expr) \ + do { \ + doctest::detail::ResultBuilder _DOCTEST_RB( \ + doctest::detail::assertType::assert_type, __FILE__, __LINE__, \ + DOCTEST_TOSTR(DOCTEST_HANDLE_BRACED_VA_ARGS(expr))); \ + DOCTEST_WRAP_IN_TRY( \ + _DOCTEST_RB.unary_assert(DOCTEST_HANDLE_BRACED_VA_ARGS(expr))) \ + DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \ + } while ((void)0, 0) #ifdef DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#define DOCTEST_WARN_EQ(...) DOCTEST_BINARY_ASSERT(DT_WARN_EQ, (__VA_ARGS__), eq) -#define DOCTEST_CHECK_EQ(...) DOCTEST_BINARY_ASSERT(DT_CHECK_EQ, (__VA_ARGS__), eq) -#define DOCTEST_REQUIRE_EQ(...) DOCTEST_BINARY_ASSERT(DT_REQUIRE_EQ, (__VA_ARGS__), eq) -#define DOCTEST_WARN_NE(...) DOCTEST_BINARY_ASSERT(DT_WARN_NE, (__VA_ARGS__), ne) -#define DOCTEST_CHECK_NE(...) DOCTEST_BINARY_ASSERT(DT_CHECK_NE, (__VA_ARGS__), ne) -#define DOCTEST_REQUIRE_NE(...) DOCTEST_BINARY_ASSERT(DT_REQUIRE_NE, (__VA_ARGS__), ne) -#define DOCTEST_WARN_GT(...) DOCTEST_BINARY_ASSERT(DT_WARN_GT, (__VA_ARGS__), gt) -#define DOCTEST_CHECK_GT(...) DOCTEST_BINARY_ASSERT(DT_CHECK_GT, (__VA_ARGS__), gt) -#define DOCTEST_REQUIRE_GT(...) DOCTEST_BINARY_ASSERT(DT_REQUIRE_GT, (__VA_ARGS__), gt) -#define DOCTEST_WARN_LT(...) DOCTEST_BINARY_ASSERT(DT_WARN_LT, (__VA_ARGS__), lt) -#define DOCTEST_CHECK_LT(...) DOCTEST_BINARY_ASSERT(DT_CHECK_LT, (__VA_ARGS__), lt) -#define DOCTEST_REQUIRE_LT(...) DOCTEST_BINARY_ASSERT(DT_REQUIRE_LT, (__VA_ARGS__), lt) -#define DOCTEST_WARN_GE(...) DOCTEST_BINARY_ASSERT(DT_WARN_GE, (__VA_ARGS__), ge) -#define DOCTEST_CHECK_GE(...) DOCTEST_BINARY_ASSERT(DT_CHECK_GE, (__VA_ARGS__), ge) -#define DOCTEST_REQUIRE_GE(...) DOCTEST_BINARY_ASSERT(DT_REQUIRE_GE, (__VA_ARGS__), ge) -#define DOCTEST_WARN_LE(...) DOCTEST_BINARY_ASSERT(DT_WARN_LE, (__VA_ARGS__), le) -#define DOCTEST_CHECK_LE(...) DOCTEST_BINARY_ASSERT(DT_CHECK_LE, (__VA_ARGS__), le) -#define DOCTEST_REQUIRE_LE(...) DOCTEST_BINARY_ASSERT(DT_REQUIRE_LE, (__VA_ARGS__), le) - -#define DOCTEST_WARN_UNARY(...) DOCTEST_UNARY_ASSERT(DT_WARN_UNARY, (__VA_ARGS__)) -#define DOCTEST_CHECK_UNARY(...) DOCTEST_UNARY_ASSERT(DT_CHECK_UNARY, (__VA_ARGS__)) -#define DOCTEST_REQUIRE_UNARY(...) DOCTEST_UNARY_ASSERT(DT_REQUIRE_UNARY, (__VA_ARGS__)) -#define DOCTEST_WARN_UNARY_FALSE(...) DOCTEST_UNARY_ASSERT(DT_WARN_UNARY_FALSE, (__VA_ARGS__)) -#define DOCTEST_CHECK_UNARY_FALSE(...) DOCTEST_UNARY_ASSERT(DT_CHECK_UNARY_FALSE, (__VA_ARGS__)) -#define DOCTEST_REQUIRE_UNARY_FALSE(...) DOCTEST_UNARY_ASSERT(DT_REQUIRE_UNARY_FALSE, (__VA_ARGS__)) -#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#define DOCTEST_WARN_EQ(lhs, rhs) DOCTEST_BINARY_ASSERT(DT_WARN_EQ, lhs, rhs, eq) -#define DOCTEST_CHECK_EQ(lhs, rhs) DOCTEST_BINARY_ASSERT(DT_CHECK_EQ, lhs, rhs, eq) -#define DOCTEST_REQUIRE_EQ(lhs, rhs) DOCTEST_BINARY_ASSERT(DT_REQUIRE_EQ, lhs, rhs, eq) -#define DOCTEST_WARN_NE(lhs, rhs) DOCTEST_BINARY_ASSERT(DT_WARN_NE, lhs, rhs, ne) -#define DOCTEST_CHECK_NE(lhs, rhs) DOCTEST_BINARY_ASSERT(DT_CHECK_NE, lhs, rhs, ne) -#define DOCTEST_REQUIRE_NE(lhs, rhs) DOCTEST_BINARY_ASSERT(DT_REQUIRE_NE, lhs, rhs, ne) -#define DOCTEST_WARN_GT(lhs, rhs) DOCTEST_BINARY_ASSERT(DT_WARN_GT, lhs, rhs, gt) -#define DOCTEST_CHECK_GT(lhs, rhs) DOCTEST_BINARY_ASSERT(DT_CHECK_GT, lhs, rhs, gt) -#define DOCTEST_REQUIRE_GT(lhs, rhs) DOCTEST_BINARY_ASSERT(DT_REQUIRE_GT, lhs, rhs, gt) -#define DOCTEST_WARN_LT(lhs, rhs) DOCTEST_BINARY_ASSERT(DT_WARN_LT, lhs, rhs, lt) -#define DOCTEST_CHECK_LT(lhs, rhs) DOCTEST_BINARY_ASSERT(DT_CHECK_LT, lhs, rhs, lt) -#define DOCTEST_REQUIRE_LT(lhs, rhs) DOCTEST_BINARY_ASSERT(DT_REQUIRE_LT, lhs, rhs, lt) -#define DOCTEST_WARN_GE(lhs, rhs) DOCTEST_BINARY_ASSERT(DT_WARN_GE, lhs, rhs, ge) -#define DOCTEST_CHECK_GE(lhs, rhs) DOCTEST_BINARY_ASSERT(DT_CHECK_GE, lhs, rhs, ge) -#define DOCTEST_REQUIRE_GE(lhs, rhs) DOCTEST_BINARY_ASSERT(DT_REQUIRE_GE, lhs, rhs, ge) -#define DOCTEST_WARN_LE(lhs, rhs) DOCTEST_BINARY_ASSERT(DT_WARN_LE, lhs, rhs, le) -#define DOCTEST_CHECK_LE(lhs, rhs) DOCTEST_BINARY_ASSERT(DT_CHECK_LE, lhs, rhs, le) -#define DOCTEST_REQUIRE_LE(lhs, rhs) DOCTEST_BINARY_ASSERT(DT_REQUIRE_LE, lhs, rhs, le) +#define DOCTEST_WARN_EQ(...) \ + DOCTEST_BINARY_ASSERT(DT_WARN_EQ, (__VA_ARGS__), eq) +#define DOCTEST_CHECK_EQ(...) \ + DOCTEST_BINARY_ASSERT(DT_CHECK_EQ, (__VA_ARGS__), eq) +#define DOCTEST_REQUIRE_EQ(...) \ + DOCTEST_BINARY_ASSERT(DT_REQUIRE_EQ, (__VA_ARGS__), eq) +#define DOCTEST_WARN_NE(...) \ + DOCTEST_BINARY_ASSERT(DT_WARN_NE, (__VA_ARGS__), ne) +#define DOCTEST_CHECK_NE(...) \ + DOCTEST_BINARY_ASSERT(DT_CHECK_NE, (__VA_ARGS__), ne) +#define DOCTEST_REQUIRE_NE(...) \ + DOCTEST_BINARY_ASSERT(DT_REQUIRE_NE, (__VA_ARGS__), ne) +#define DOCTEST_WARN_GT(...) \ + DOCTEST_BINARY_ASSERT(DT_WARN_GT, (__VA_ARGS__), gt) +#define DOCTEST_CHECK_GT(...) \ + DOCTEST_BINARY_ASSERT(DT_CHECK_GT, (__VA_ARGS__), gt) +#define DOCTEST_REQUIRE_GT(...) \ + DOCTEST_BINARY_ASSERT(DT_REQUIRE_GT, (__VA_ARGS__), gt) +#define DOCTEST_WARN_LT(...) \ + DOCTEST_BINARY_ASSERT(DT_WARN_LT, (__VA_ARGS__), lt) +#define DOCTEST_CHECK_LT(...) \ + DOCTEST_BINARY_ASSERT(DT_CHECK_LT, (__VA_ARGS__), lt) +#define DOCTEST_REQUIRE_LT(...) \ + DOCTEST_BINARY_ASSERT(DT_REQUIRE_LT, (__VA_ARGS__), lt) +#define DOCTEST_WARN_GE(...) \ + DOCTEST_BINARY_ASSERT(DT_WARN_GE, (__VA_ARGS__), ge) +#define DOCTEST_CHECK_GE(...) \ + DOCTEST_BINARY_ASSERT(DT_CHECK_GE, (__VA_ARGS__), ge) +#define DOCTEST_REQUIRE_GE(...) \ + DOCTEST_BINARY_ASSERT(DT_REQUIRE_GE, (__VA_ARGS__), ge) +#define DOCTEST_WARN_LE(...) \ + DOCTEST_BINARY_ASSERT(DT_WARN_LE, (__VA_ARGS__), le) +#define DOCTEST_CHECK_LE(...) \ + DOCTEST_BINARY_ASSERT(DT_CHECK_LE, (__VA_ARGS__), le) +#define DOCTEST_REQUIRE_LE(...) \ + DOCTEST_BINARY_ASSERT(DT_REQUIRE_LE, (__VA_ARGS__), le) + +#define DOCTEST_WARN_UNARY(...) \ + DOCTEST_UNARY_ASSERT(DT_WARN_UNARY, (__VA_ARGS__)) +#define DOCTEST_CHECK_UNARY(...) \ + DOCTEST_UNARY_ASSERT(DT_CHECK_UNARY, (__VA_ARGS__)) +#define DOCTEST_REQUIRE_UNARY(...) \ + DOCTEST_UNARY_ASSERT(DT_REQUIRE_UNARY, (__VA_ARGS__)) +#define DOCTEST_WARN_UNARY_FALSE(...) \ + DOCTEST_UNARY_ASSERT(DT_WARN_UNARY_FALSE, (__VA_ARGS__)) +#define DOCTEST_CHECK_UNARY_FALSE(...) \ + DOCTEST_UNARY_ASSERT(DT_CHECK_UNARY_FALSE, (__VA_ARGS__)) +#define DOCTEST_REQUIRE_UNARY_FALSE(...) \ + DOCTEST_UNARY_ASSERT(DT_REQUIRE_UNARY_FALSE, (__VA_ARGS__)) +#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#define DOCTEST_WARN_EQ(lhs, rhs) \ + DOCTEST_BINARY_ASSERT(DT_WARN_EQ, lhs, rhs, eq) +#define DOCTEST_CHECK_EQ(lhs, rhs) \ + DOCTEST_BINARY_ASSERT(DT_CHECK_EQ, lhs, rhs, eq) +#define DOCTEST_REQUIRE_EQ(lhs, rhs) \ + DOCTEST_BINARY_ASSERT(DT_REQUIRE_EQ, lhs, rhs, eq) +#define DOCTEST_WARN_NE(lhs, rhs) \ + DOCTEST_BINARY_ASSERT(DT_WARN_NE, lhs, rhs, ne) +#define DOCTEST_CHECK_NE(lhs, rhs) \ + DOCTEST_BINARY_ASSERT(DT_CHECK_NE, lhs, rhs, ne) +#define DOCTEST_REQUIRE_NE(lhs, rhs) \ + DOCTEST_BINARY_ASSERT(DT_REQUIRE_NE, lhs, rhs, ne) +#define DOCTEST_WARN_GT(lhs, rhs) \ + DOCTEST_BINARY_ASSERT(DT_WARN_GT, lhs, rhs, gt) +#define DOCTEST_CHECK_GT(lhs, rhs) \ + DOCTEST_BINARY_ASSERT(DT_CHECK_GT, lhs, rhs, gt) +#define DOCTEST_REQUIRE_GT(lhs, rhs) \ + DOCTEST_BINARY_ASSERT(DT_REQUIRE_GT, lhs, rhs, gt) +#define DOCTEST_WARN_LT(lhs, rhs) \ + DOCTEST_BINARY_ASSERT(DT_WARN_LT, lhs, rhs, lt) +#define DOCTEST_CHECK_LT(lhs, rhs) \ + DOCTEST_BINARY_ASSERT(DT_CHECK_LT, lhs, rhs, lt) +#define DOCTEST_REQUIRE_LT(lhs, rhs) \ + DOCTEST_BINARY_ASSERT(DT_REQUIRE_LT, lhs, rhs, lt) +#define DOCTEST_WARN_GE(lhs, rhs) \ + DOCTEST_BINARY_ASSERT(DT_WARN_GE, lhs, rhs, ge) +#define DOCTEST_CHECK_GE(lhs, rhs) \ + DOCTEST_BINARY_ASSERT(DT_CHECK_GE, lhs, rhs, ge) +#define DOCTEST_REQUIRE_GE(lhs, rhs) \ + DOCTEST_BINARY_ASSERT(DT_REQUIRE_GE, lhs, rhs, ge) +#define DOCTEST_WARN_LE(lhs, rhs) \ + DOCTEST_BINARY_ASSERT(DT_WARN_LE, lhs, rhs, le) +#define DOCTEST_CHECK_LE(lhs, rhs) \ + DOCTEST_BINARY_ASSERT(DT_CHECK_LE, lhs, rhs, le) +#define DOCTEST_REQUIRE_LE(lhs, rhs) \ + DOCTEST_BINARY_ASSERT(DT_REQUIRE_LE, lhs, rhs, le) #define DOCTEST_WARN_UNARY(v) DOCTEST_UNARY_ASSERT(DT_WARN_UNARY, v) #define DOCTEST_CHECK_UNARY(v) DOCTEST_UNARY_ASSERT(DT_CHECK_UNARY, v) #define DOCTEST_REQUIRE_UNARY(v) DOCTEST_UNARY_ASSERT(DT_REQUIRE_UNARY, v) #define DOCTEST_WARN_UNARY_FALSE(v) DOCTEST_UNARY_ASSERT(DT_WARN_UNARY_FALSE, v) -#define DOCTEST_CHECK_UNARY_FALSE(v) DOCTEST_UNARY_ASSERT(DT_CHECK_UNARY_FALSE, v) -#define DOCTEST_REQUIRE_UNARY_FALSE(v) DOCTEST_UNARY_ASSERT(DT_REQUIRE_UNARY_FALSE, v) -#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#define DOCTEST_CHECK_UNARY_FALSE(v) \ + DOCTEST_UNARY_ASSERT(DT_CHECK_UNARY_FALSE, v) +#define DOCTEST_REQUIRE_UNARY_FALSE(v) \ + DOCTEST_UNARY_ASSERT(DT_REQUIRE_UNARY_FALSE, v) +#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS #ifndef DOCTEST_CONFIG_SUPER_FAST_ASSERTS #ifdef DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#define DOCTEST_FAST_BINARY_ASSERT(assert_type, expr, comparison) \ - do { \ - int _DOCTEST_FAST_RES = doctest::detail::fast_binary_assert< \ - doctest::detail::binaryAssertComparison::comparison>( \ - doctest::detail::assertType::assert_type, __FILE__, __LINE__, \ - DOCTEST_TOSTR(DOCTEST_HANDLE_BRACED_VA_ARGS(expr)), \ - DOCTEST_HANDLE_BRACED_VA_ARGS(expr)); \ - if(_DOCTEST_FAST_RES & doctest::detail::assertAction::dbgbreak) \ - DOCTEST_BREAK_INTO_DEBUGGER(); \ - doctest::detail::fastAssertThrowIfFlagSet(_DOCTEST_FAST_RES); \ - } while((void)0, 0) -#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#define DOCTEST_FAST_BINARY_ASSERT(assert_type, lhs, rhs, comparison) \ - do { \ - int _DOCTEST_FAST_RES = doctest::detail::fast_binary_assert< \ - doctest::detail::binaryAssertComparison::comparison>( \ - doctest::detail::assertType::assert_type, __FILE__, __LINE__, #lhs ", " #rhs, lhs, \ - rhs); \ - if(_DOCTEST_FAST_RES & doctest::detail::assertAction::dbgbreak) \ - DOCTEST_BREAK_INTO_DEBUGGER(); \ - doctest::detail::fastAssertThrowIfFlagSet(_DOCTEST_FAST_RES); \ - } while((void)0, 0) -#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS - -#define DOCTEST_FAST_UNARY_ASSERT(assert_type, expr) \ - do { \ - int _DOCTEST_FAST_RES = doctest::detail::fast_unary_assert( \ - doctest::detail::assertType::assert_type, __FILE__, __LINE__, \ - DOCTEST_TOSTR(DOCTEST_HANDLE_BRACED_VA_ARGS(expr)), \ - DOCTEST_HANDLE_BRACED_VA_ARGS(expr)); \ - if(_DOCTEST_FAST_RES & doctest::detail::assertAction::dbgbreak) \ - DOCTEST_BREAK_INTO_DEBUGGER(); \ - doctest::detail::fastAssertThrowIfFlagSet(_DOCTEST_FAST_RES); \ - } while((void)0, 0) - -#else // DOCTEST_CONFIG_SUPER_FAST_ASSERTS +#define DOCTEST_FAST_BINARY_ASSERT(assert_type, expr, comparison) \ + do { \ + int _DOCTEST_FAST_RES = doctest::detail::fast_binary_assert< \ + doctest::detail::binaryAssertComparison::comparison>( \ + doctest::detail::assertType::assert_type, __FILE__, __LINE__, \ + DOCTEST_TOSTR(DOCTEST_HANDLE_BRACED_VA_ARGS(expr)), \ + DOCTEST_HANDLE_BRACED_VA_ARGS(expr)); \ + if (_DOCTEST_FAST_RES & doctest::detail::assertAction::dbgbreak) \ + DOCTEST_BREAK_INTO_DEBUGGER(); \ + doctest::detail::fastAssertThrowIfFlagSet(_DOCTEST_FAST_RES); \ + } while ((void)0, 0) +#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#define DOCTEST_FAST_BINARY_ASSERT(assert_type, lhs, rhs, comparison) \ + do { \ + int _DOCTEST_FAST_RES = doctest::detail::fast_binary_assert< \ + doctest::detail::binaryAssertComparison::comparison>( \ + doctest::detail::assertType::assert_type, __FILE__, __LINE__, \ + #lhs ", " #rhs, lhs, rhs); \ + if (_DOCTEST_FAST_RES & doctest::detail::assertAction::dbgbreak) \ + DOCTEST_BREAK_INTO_DEBUGGER(); \ + doctest::detail::fastAssertThrowIfFlagSet(_DOCTEST_FAST_RES); \ + } while ((void)0, 0) +#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS + +#define DOCTEST_FAST_UNARY_ASSERT(assert_type, expr) \ + do { \ + int _DOCTEST_FAST_RES = doctest::detail::fast_unary_assert( \ + doctest::detail::assertType::assert_type, __FILE__, __LINE__, \ + DOCTEST_TOSTR(DOCTEST_HANDLE_BRACED_VA_ARGS(expr)), \ + DOCTEST_HANDLE_BRACED_VA_ARGS(expr)); \ + if (_DOCTEST_FAST_RES & doctest::detail::assertAction::dbgbreak) \ + DOCTEST_BREAK_INTO_DEBUGGER(); \ + doctest::detail::fastAssertThrowIfFlagSet(_DOCTEST_FAST_RES); \ + } while ((void)0, 0) + +#else // DOCTEST_CONFIG_SUPER_FAST_ASSERTS #ifdef DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#define DOCTEST_FAST_BINARY_ASSERT(assert_type, expr, comparison) \ - doctest::detail::fast_binary_assert( \ - doctest::detail::assertType::assert_type, __FILE__, __LINE__, \ - DOCTEST_TOSTR(DOCTEST_HANDLE_BRACED_VA_ARGS(expr)), \ - DOCTEST_HANDLE_BRACED_VA_ARGS(expr)) -#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#define DOCTEST_FAST_BINARY_ASSERT(assert_type, lhs, rhs, comparison) \ - doctest::detail::fast_binary_assert( \ - doctest::detail::assertType::assert_type, __FILE__, __LINE__, #lhs ", " #rhs, lhs, \ - rhs) -#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS - -#define DOCTEST_FAST_UNARY_ASSERT(assert_type, expr) \ - doctest::detail::fast_unary_assert(doctest::detail::assertType::assert_type, __FILE__, \ - __LINE__, \ - DOCTEST_TOSTR(DOCTEST_HANDLE_BRACED_VA_ARGS(expr)), \ - DOCTEST_HANDLE_BRACED_VA_ARGS(expr)) - -#endif // DOCTEST_CONFIG_SUPER_FAST_ASSERTS +#define DOCTEST_FAST_BINARY_ASSERT(assert_type, expr, comparison) \ + doctest::detail::fast_binary_assert< \ + doctest::detail::binaryAssertComparison::comparison>( \ + doctest::detail::assertType::assert_type, __FILE__, __LINE__, \ + DOCTEST_TOSTR(DOCTEST_HANDLE_BRACED_VA_ARGS(expr)), \ + DOCTEST_HANDLE_BRACED_VA_ARGS(expr)) +#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#define DOCTEST_FAST_BINARY_ASSERT(assert_type, lhs, rhs, comparison) \ + doctest::detail::fast_binary_assert< \ + doctest::detail::binaryAssertComparison::comparison>( \ + doctest::detail::assertType::assert_type, __FILE__, __LINE__, \ + #lhs ", " #rhs, lhs, rhs) +#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS + +#define DOCTEST_FAST_UNARY_ASSERT(assert_type, expr) \ + doctest::detail::fast_unary_assert( \ + doctest::detail::assertType::assert_type, __FILE__, __LINE__, \ + DOCTEST_TOSTR(DOCTEST_HANDLE_BRACED_VA_ARGS(expr)), \ + DOCTEST_HANDLE_BRACED_VA_ARGS(expr)) + +#endif // DOCTEST_CONFIG_SUPER_FAST_ASSERTS // clang-format off #ifdef DOCTEST_CONFIG_WITH_VARIADIC_MACROS @@ -2742,11 +2832,11 @@ constexpr T to_lvalue = x; #define DOCTEST_WARN_THROWS_AS(expr, ...) ((void)0) #define DOCTEST_CHECK_THROWS_AS(expr, ...) ((void)0) #define DOCTEST_REQUIRE_THROWS_AS(expr, ...) ((void)0) -#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS #define DOCTEST_WARN_THROWS_AS(expr, ex) ((void)0) #define DOCTEST_CHECK_THROWS_AS(expr, ex) ((void)0) #define DOCTEST_REQUIRE_THROWS_AS(expr, ex) ((void)0) -#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS #define DOCTEST_WARN_NOTHROW(expr) ((void)0) #define DOCTEST_CHECK_NOTHROW(expr) ((void)0) #define DOCTEST_REQUIRE_NOTHROW(expr) ((void)0) @@ -2761,7 +2851,7 @@ constexpr T to_lvalue = x; #define DOCTEST_CHECK_NOTHROW_MESSAGE(expr, msg) ((void)0) #define DOCTEST_REQUIRE_NOTHROW_MESSAGE(expr, msg) ((void)0) -#else // DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS +#else // DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS #undef DOCTEST_REQUIRE #undef DOCTEST_REQUIRE_FALSE @@ -2784,58 +2874,62 @@ constexpr T to_lvalue = x; #undef DOCTEST_FAST_REQUIRE_UNARY #undef DOCTEST_FAST_REQUIRE_UNARY_FALSE -#endif // DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS +#endif // DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS -#endif // DOCTEST_CONFIG_NO_EXCEPTIONS +#endif // DOCTEST_CONFIG_NO_EXCEPTIONS // ================================================================================================= -// == WHAT FOLLOWS IS VERSIONS OF THE MACROS THAT DO NOT DO ANY REGISTERING! == -// == THIS CAN BE ENABLED BY DEFINING DOCTEST_CONFIG_DISABLE GLOBALLY! == +// == WHAT FOLLOWS IS VERSIONS OF THE MACROS THAT DO NOT DO ANY REGISTERING! == +// == THIS CAN BE ENABLED BY DEFINING DOCTEST_CONFIG_DISABLE GLOBALLY! == // ================================================================================================= -#else // DOCTEST_CONFIG_DISABLE - -#define DOCTEST_IMPLEMENT_FIXTURE(der, base, func, name) \ - namespace \ - { \ - template \ - struct der : base \ - { void f(); }; \ - } \ - template \ +#else // DOCTEST_CONFIG_DISABLE + +#define DOCTEST_IMPLEMENT_FIXTURE(der, base, func, name) \ + namespace { \ + template \ + struct der : base { \ + void f(); \ + }; \ + } \ + template \ inline void der::f() -#define DOCTEST_CREATE_AND_REGISTER_FUNCTION(f, name) \ - template \ +#define DOCTEST_CREATE_AND_REGISTER_FUNCTION(f, name) \ + template \ static inline void f() // for registering tests -#define DOCTEST_TEST_CASE(name) \ - DOCTEST_CREATE_AND_REGISTER_FUNCTION(DOCTEST_ANONYMOUS(_DOCTEST_ANON_FUNC_), name) +#define DOCTEST_TEST_CASE(name) \ + DOCTEST_CREATE_AND_REGISTER_FUNCTION( \ + DOCTEST_ANONYMOUS(_DOCTEST_ANON_FUNC_), name) // for registering tests with a fixture -#define DOCTEST_TEST_CASE_FIXTURE(x, name) \ - DOCTEST_IMPLEMENT_FIXTURE(DOCTEST_ANONYMOUS(_DOCTEST_ANON_CLASS_), x, \ - DOCTEST_ANONYMOUS(_DOCTEST_ANON_FUNC_), name) +#define DOCTEST_TEST_CASE_FIXTURE(x, name) \ + DOCTEST_IMPLEMENT_FIXTURE( \ + DOCTEST_ANONYMOUS(_DOCTEST_ANON_CLASS_), x, \ + DOCTEST_ANONYMOUS(_DOCTEST_ANON_FUNC_), name) // for converting types to strings without the header and demangling #ifdef DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#define DOCTEST_TYPE_TO_STRING(...) typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_) +#define DOCTEST_TYPE_TO_STRING(...) \ + typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_) #define DOCTEST_TYPE_TO_STRING_IMPL(...) -#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#define DOCTEST_TYPE_TO_STRING(x) typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_) +#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#define DOCTEST_TYPE_TO_STRING(x) \ + typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_) #define DOCTEST_TYPE_TO_STRING_IMPL(x) -#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS // for typed tests -#define DOCTEST_TEST_CASE_TEMPLATE(name, type, types) \ - template \ +#define DOCTEST_TEST_CASE_TEMPLATE(name, type, types) \ + template \ inline void DOCTEST_ANONYMOUS(_DOCTEST_ANON_TMP_)() -#define DOCTEST_TEST_CASE_TEMPLATE_DEFINE(name, type, id) \ - template \ +#define DOCTEST_TEST_CASE_TEMPLATE_DEFINE(name, type, id) \ + template \ inline void DOCTEST_ANONYMOUS(_DOCTEST_ANON_TMP_)() -#define DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE(id, types) \ +#define DOCTEST_TEST_CASE_TEMPLATE_INSTANTIATE(id, types) \ typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_) // for subcases @@ -2845,14 +2939,17 @@ constexpr T to_lvalue = x; #define DOCTEST_TEST_SUITE(name) namespace // for starting a testsuite block -#define DOCTEST_TEST_SUITE_BEGIN(name) typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_) +#define DOCTEST_TEST_SUITE_BEGIN(name) \ + typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_) // for ending a testsuite block -#define DOCTEST_TEST_SUITE_END typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_) +#define DOCTEST_TEST_SUITE_END \ + typedef int DOCTEST_ANONYMOUS(_DOCTEST_ANON_FOR_SEMICOLON_) -#define DOCTEST_REGISTER_EXCEPTION_TRANSLATOR(signature) \ - template \ - static inline doctest::String DOCTEST_ANONYMOUS(_DOCTEST_ANON_TRANSLATOR_)(signature) +#define DOCTEST_REGISTER_EXCEPTION_TRANSLATOR(signature) \ + template \ + static inline doctest::String DOCTEST_ANONYMOUS( \ + _DOCTEST_ANON_TRANSLATOR_)(signature) #define DOCTEST_INFO(x) ((void)0) #define DOCTEST_CAPTURE(x) ((void)0) @@ -2870,14 +2967,14 @@ constexpr T to_lvalue = x; #define DOCTEST_WARN_FALSE(...) ((void)0) #define DOCTEST_CHECK_FALSE(...) ((void)0) #define DOCTEST_REQUIRE_FALSE(...) ((void)0) -#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS #define DOCTEST_WARN(expr) ((void)0) #define DOCTEST_CHECK(expr) ((void)0) #define DOCTEST_REQUIRE(expr) ((void)0) #define DOCTEST_WARN_FALSE(expr) ((void)0) #define DOCTEST_CHECK_FALSE(expr) ((void)0) #define DOCTEST_REQUIRE_FALSE(expr) ((void)0) -#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS #define DOCTEST_WARN_MESSAGE(cond, msg) ((void)0) #define DOCTEST_CHECK_MESSAGE(cond, msg) ((void)0) @@ -2893,11 +2990,11 @@ constexpr T to_lvalue = x; #define DOCTEST_WARN_THROWS_AS(expr, ...) ((void)0) #define DOCTEST_CHECK_THROWS_AS(expr, ...) ((void)0) #define DOCTEST_REQUIRE_THROWS_AS(expr, ...) ((void)0) -#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS #define DOCTEST_WARN_THROWS_AS(expr, ex) ((void)0) #define DOCTEST_CHECK_THROWS_AS(expr, ex) ((void)0) #define DOCTEST_REQUIRE_THROWS_AS(expr, ex) ((void)0) -#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS #define DOCTEST_WARN_NOTHROW(expr) ((void)0) #define DOCTEST_CHECK_NOTHROW(expr) ((void)0) #define DOCTEST_REQUIRE_NOTHROW(expr) ((void)0) @@ -2966,7 +3063,7 @@ constexpr T to_lvalue = x; #define DOCTEST_FAST_CHECK_UNARY_FALSE(...) ((void)0) #define DOCTEST_FAST_REQUIRE_UNARY_FALSE(...) ((void)0) -#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#else // DOCTEST_CONFIG_WITH_VARIADIC_MACROS #define DOCTEST_WARN_EQ(lhs, rhs) ((void)0) #define DOCTEST_CHECK_EQ(lhs, rhs) ((void)0) @@ -3020,9 +3117,9 @@ constexpr T to_lvalue = x; #define DOCTEST_FAST_CHECK_UNARY_FALSE(val) ((void)0) #define DOCTEST_FAST_REQUIRE_UNARY_FALSE(val) ((void)0) -#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS +#endif // DOCTEST_CONFIG_WITH_VARIADIC_MACROS -#endif // DOCTEST_CONFIG_DISABLE +#endif // DOCTEST_CONFIG_DISABLE // BDD style macros // clang-format off @@ -3156,46 +3253,45 @@ constexpr T to_lvalue = x; #define FAST_CHECK_UNARY_FALSE DOCTEST_FAST_CHECK_UNARY_FALSE #define FAST_REQUIRE_UNARY_FALSE DOCTEST_FAST_REQUIRE_UNARY_FALSE -#endif // DOCTEST_CONFIG_NO_SHORT_MACRO_NAMES +#endif // DOCTEST_CONFIG_NO_SHORT_MACRO_NAMES -// this is here to clear the 'current test suite' for the current translation unit - at the top +// this is here to clear the 'current test suite' for the current translation +// unit - at the top DOCTEST_TEST_SUITE_END(); // add stringification for primitive/fundamental types -namespace doctest -{ -namespace detail -{ - DOCTEST_TYPE_TO_STRING_IMPL(bool) - DOCTEST_TYPE_TO_STRING_IMPL(float) - DOCTEST_TYPE_TO_STRING_IMPL(double) - DOCTEST_TYPE_TO_STRING_IMPL(long double) - DOCTEST_TYPE_TO_STRING_IMPL(char) - DOCTEST_TYPE_TO_STRING_IMPL(signed char) - DOCTEST_TYPE_TO_STRING_IMPL(unsigned char) - DOCTEST_TYPE_TO_STRING_IMPL(wchar_t) - DOCTEST_TYPE_TO_STRING_IMPL(short int) - DOCTEST_TYPE_TO_STRING_IMPL(unsigned short int) - DOCTEST_TYPE_TO_STRING_IMPL(int) - DOCTEST_TYPE_TO_STRING_IMPL(unsigned int) - DOCTEST_TYPE_TO_STRING_IMPL(long int) - DOCTEST_TYPE_TO_STRING_IMPL(unsigned long int) +namespace doctest { +namespace detail { +DOCTEST_TYPE_TO_STRING_IMPL(bool) +DOCTEST_TYPE_TO_STRING_IMPL(float) +DOCTEST_TYPE_TO_STRING_IMPL(double) +DOCTEST_TYPE_TO_STRING_IMPL(long double) +DOCTEST_TYPE_TO_STRING_IMPL(char) +DOCTEST_TYPE_TO_STRING_IMPL(signed char) +DOCTEST_TYPE_TO_STRING_IMPL(unsigned char) +DOCTEST_TYPE_TO_STRING_IMPL(wchar_t) +DOCTEST_TYPE_TO_STRING_IMPL(short int) +DOCTEST_TYPE_TO_STRING_IMPL(unsigned short int) +DOCTEST_TYPE_TO_STRING_IMPL(int) +DOCTEST_TYPE_TO_STRING_IMPL(unsigned int) +DOCTEST_TYPE_TO_STRING_IMPL(long int) +DOCTEST_TYPE_TO_STRING_IMPL(unsigned long int) #ifdef DOCTEST_CONFIG_WITH_LONG_LONG - DOCTEST_TYPE_TO_STRING_IMPL(long long int) - DOCTEST_TYPE_TO_STRING_IMPL(unsigned long long int) -#endif // DOCTEST_CONFIG_WITH_LONG_LONG -} // namespace detail -} // namespace doctest +DOCTEST_TYPE_TO_STRING_IMPL(long long int) +DOCTEST_TYPE_TO_STRING_IMPL(unsigned long long int) +#endif // DOCTEST_CONFIG_WITH_LONG_LONG +} // namespace detail +} // namespace doctest DOCTEST_CLANG_SUPPRESS_WARNING_POP DOCTEST_MSVC_SUPPRESS_WARNING_POP DOCTEST_GCC_SUPPRESS_WARNING_POP -#endif // DOCTEST_LIBRARY_INCLUDED +#endif // DOCTEST_LIBRARY_INCLUDED #ifndef DOCTEST_SINGLE_HEADER #define DOCTEST_SINGLE_HEADER -#endif // DOCTEST_SINGLE_HEADER +#endif // DOCTEST_SINGLE_HEADER #if defined(DOCTEST_CONFIG_IMPLEMENT) || !defined(DOCTEST_SINGLE_HEADER) #ifndef DOCTEST_LIBRARY_IMPLEMENTATION @@ -3203,7 +3299,7 @@ DOCTEST_GCC_SUPPRESS_WARNING_POP #ifndef DOCTEST_SINGLE_HEADER #include "doctest_fwd.h" -#endif // DOCTEST_SINGLE_HEADER +#endif // DOCTEST_SINGLE_HEADER DOCTEST_CLANG_SUPPRESS_WARNING_PUSH DOCTEST_CLANG_SUPPRESS_WARNING("-Wunknown-pragmas") @@ -3223,9 +3319,10 @@ DOCTEST_CLANG_SUPPRESS_WARNING("-Wdisabled-macro-expansion") DOCTEST_CLANG_SUPPRESS_WARNING("-Wmissing-braces") DOCTEST_CLANG_SUPPRESS_WARNING("-Wmissing-field-initializers") DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++11-long-long") -#if DOCTEST_CLANG && DOCTEST_CLANG_HAS_WARNING("-Wzero-as-null-pointer-constant") +#if DOCTEST_CLANG \ + && DOCTEST_CLANG_HAS_WARNING("-Wzero-as-null-pointer-constant") DOCTEST_CLANG_SUPPRESS_WARNING("-Wzero-as-null-pointer-constant") -#endif // clang - 0 as null +#endif // clang - 0 as null DOCTEST_GCC_SUPPRESS_WARNING_PUSH DOCTEST_GCC_SUPPRESS_WARNING("-Wunknown-pragmas") @@ -3245,287 +3342,296 @@ DOCTEST_GCC_SUPPRESS_WARNING("-Wlong-long") DOCTEST_GCC_SUPPRESS_WARNING("-Wold-style-cast") #if DOCTEST_GCC >= DOCTEST_COMPILER(4, 7, 0) DOCTEST_GCC_SUPPRESS_WARNING("-Wzero-as-null-pointer-constant") -#endif // GCC 4.7+ +#endif // GCC 4.7+ #if DOCTEST_GCC >= DOCTEST_COMPILER(4, 8, 0) DOCTEST_GCC_SUPPRESS_WARNING("-Wunused-local-typedefs") -#endif // GCC 4.8+ +#endif // GCC 4.8+ #if DOCTEST_GCC >= DOCTEST_COMPILER(5, 4, 0) DOCTEST_GCC_SUPPRESS_WARNING("-Wuseless-cast") -#endif // GCC 5.4+ +#endif // GCC 5.4+ DOCTEST_MSVC_SUPPRESS_WARNING_PUSH -DOCTEST_MSVC_SUPPRESS_WARNING(4616) // invalid compiler warning -DOCTEST_MSVC_SUPPRESS_WARNING(4619) // invalid compiler warning -DOCTEST_MSVC_SUPPRESS_WARNING(4996) // The compiler encountered a deprecated declaration -DOCTEST_MSVC_SUPPRESS_WARNING(4267) // 'var' : conversion from 'x' to 'y', possible loss of data -DOCTEST_MSVC_SUPPRESS_WARNING(4706) // assignment within conditional expression -DOCTEST_MSVC_SUPPRESS_WARNING(4512) // 'class' : assignment operator could not be generated -DOCTEST_MSVC_SUPPRESS_WARNING(4127) // conditional expression is constant -DOCTEST_MSVC_SUPPRESS_WARNING(4530) // C++ exception handler used, but unwind semantics not enabled -DOCTEST_MSVC_SUPPRESS_WARNING(4577) // 'noexcept' used with no exception handling mode specified -DOCTEST_MSVC_SUPPRESS_WARNING(4774) // format string expected in argument is not a string literal -DOCTEST_MSVC_SUPPRESS_WARNING(4365) // conversion from 'int' to 'unsigned', signed/unsigned mismatch -DOCTEST_MSVC_SUPPRESS_WARNING(4820) // padding in structs -DOCTEST_MSVC_SUPPRESS_WARNING(4640) // construction of local static object is not thread-safe -DOCTEST_MSVC_SUPPRESS_WARNING(5039) // pointer to potentially throwing function passed to extern C +DOCTEST_MSVC_SUPPRESS_WARNING(4616) // invalid compiler warning +DOCTEST_MSVC_SUPPRESS_WARNING(4619) // invalid compiler warning +DOCTEST_MSVC_SUPPRESS_WARNING( + 4996) // The compiler encountered a deprecated declaration +DOCTEST_MSVC_SUPPRESS_WARNING( + 4267) // 'var' : conversion from 'x' to 'y', possible loss of data +DOCTEST_MSVC_SUPPRESS_WARNING(4706) // assignment within conditional expression +DOCTEST_MSVC_SUPPRESS_WARNING( + 4512) // 'class' : assignment operator could not be generated +DOCTEST_MSVC_SUPPRESS_WARNING(4127) // conditional expression is constant +DOCTEST_MSVC_SUPPRESS_WARNING( + 4530) // C++ exception handler used, but unwind semantics not enabled +DOCTEST_MSVC_SUPPRESS_WARNING( + 4577) // 'noexcept' used with no exception handling mode specified +DOCTEST_MSVC_SUPPRESS_WARNING( + 4774) // format string expected in argument is not a string literal +DOCTEST_MSVC_SUPPRESS_WARNING( + 4365) // conversion from 'int' to 'unsigned', signed/unsigned mismatch +DOCTEST_MSVC_SUPPRESS_WARNING(4820) // padding in structs +DOCTEST_MSVC_SUPPRESS_WARNING( + 4640) // construction of local static object is not thread-safe +DOCTEST_MSVC_SUPPRESS_WARNING( + 5039) // pointer to potentially throwing function passed to extern C #if defined(DOCTEST_NO_CPP11_COMPAT) DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++98-compat") DOCTEST_CLANG_SUPPRESS_WARNING("-Wc++98-compat-pedantic") -#endif // DOCTEST_NO_CPP11_COMPAT +#endif // DOCTEST_NO_CPP11_COMPAT // snprintf() not in the C++98 standard #if DOCTEST_MSVC #define DOCTEST_SNPRINTF _snprintf -#else // MSVC +#else // MSVC #define DOCTEST_SNPRINTF std::snprintf -#endif // MSVC +#endif // MSVC -#define DOCTEST_LOG_START() \ - do { \ - if(!contextState->hasLoggedCurrentTestStart) { \ - logTestStart(*contextState->currentTest); \ - contextState->hasLoggedCurrentTestStart = true; \ - } \ - } while(false) +#define DOCTEST_LOG_START() \ + do { \ + if (!contextState->hasLoggedCurrentTestStart) { \ + logTestStart(*contextState->currentTest); \ + contextState->hasLoggedCurrentTestStart = true; \ + } \ + } while (false) DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_BEGIN // required includes - will go only in one translation unit! -#include #include -// borland (Embarcadero) compiler requires math.h and not cmath - https://github.com/onqtam/doctest/pull/37 +#include +// borland (Embarcadero) compiler requires math.h and not cmath - +// https://github.com/onqtam/doctest/pull/37 #ifdef __BORLANDC__ #include -#endif // __BORLANDC__ -#include +#endif // __BORLANDC__ +#include +#include +#include #include #include #include -#include -#include -#include -#include +#include #include -#include +#include +#include #include -#include +#include #include -#include -#include +#include +#include #if !DOCTEST_MSVC #include -#endif // !MSVC +#endif // !MSVC DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_END -namespace doctest -{ -namespace detail -{ - // lowers ascii letters - char tolower(const char c) { return (c >= 'A' && c <= 'Z') ? static_cast(c + 32) : c; } +namespace doctest { +namespace detail { +// lowers ascii letters +char tolower(const char c) { + return (c >= 'A' && c <= 'Z') ? static_cast(c + 32) : c; +} - template - T my_max(const T& lhs, const T& rhs) { - return lhs > rhs ? lhs : rhs; - } +template +T my_max(const T& lhs, const T& rhs) { + return lhs > rhs ? lhs : rhs; +} - // case insensitive strcmp - int stricmp(char const* a, char const* b) { - for(;; a++, b++) { - const int d = tolower(*a) - tolower(*b); - if(d != 0 || !*a) - return d; - } +// case insensitive strcmp +int stricmp(char const* a, char const* b) { + for (;; a++, b++) { + const int d = tolower(*a) - tolower(*b); + if (d != 0 || !*a) return d; } +} - void my_memcpy(void* dest, const void* src, unsigned num) { - const char* csrc = static_cast(src); - char* cdest = static_cast(dest); - for(unsigned i = 0; i < num; ++i) - cdest[i] = csrc[i]; - } +void my_memcpy(void* dest, const void* src, unsigned num) { + const char* csrc = static_cast(src); + char* cdest = static_cast(dest); + for (unsigned i = 0; i < num; ++i) cdest[i] = csrc[i]; +} - // not using std::strlen() because of valgrind errors when optimizations are turned on - // 'Invalid read of size 4' when the test suite len (with '\0') is not a multiple of 4 - // for details see http://stackoverflow.com/questions/35671155 - unsigned my_strlen(const char* in) { - const char* temp = in; - while(temp && *temp) - ++temp; - return unsigned(temp - in); - } +// not using std::strlen() because of valgrind errors when optimizations are +// turned on 'Invalid read of size 4' when the test suite len (with '\0') is not +// a multiple of 4 for details see http://stackoverflow.com/questions/35671155 +unsigned my_strlen(const char* in) { + const char* temp = in; + while (temp && *temp) ++temp; + return unsigned(temp - in); +} - template - String fpToString(T value, int precision) { - std::ostringstream oss; - oss << std::setprecision(precision) << std::fixed << value; - std::string d = oss.str(); - size_t i = d.find_last_not_of('0'); - if(i != std::string::npos && i != d.size() - 1) { - if(d[i] == '.') - i++; - d = d.substr(0, i + 1); - } - return d.c_str(); +template +String fpToString(T value, int precision) { + std::ostringstream oss; + oss << std::setprecision(precision) << std::fixed << value; + std::string d = oss.str(); + size_t i = d.find_last_not_of('0'); + if (i != std::string::npos && i != d.size() - 1) { + if (d[i] == '.') i++; + d = d.substr(0, i + 1); } + return d.c_str(); +} - struct Endianness - { - enum Arch - { - Big, - Little - }; - - static Arch which() { - union _ - { - int asInt; - char asChar[sizeof(int)]; - } u; - - u.asInt = 1; // NOLINT - return (u.asChar[sizeof(int) - 1] == 1) ? Big : Little; // NOLINT - } - }; +struct Endianness { + enum Arch { Big, Little }; - String rawMemoryToString(const void* object, unsigned size) { - // Reverse order for little endian architectures - int i = 0, end = static_cast(size), inc = 1; - if(Endianness::which() == Endianness::Little) { - i = end - 1; - end = inc = -1; - } + static Arch which() { + union _ { + int asInt; + char asChar[sizeof(int)]; + } u; - unsigned char const* bytes = static_cast(object); - std::ostringstream os; - os << "0x" << std::setfill('0') << std::hex; - for(; i != end; i += inc) - os << std::setw(2) << static_cast(bytes[i]); - return os.str().c_str(); + u.asInt = 1; // NOLINT + return (u.asChar[sizeof(int) - 1] == 1) ? Big : Little; // NOLINT } +}; - std::ostream* createStream() { return new std::ostringstream(); } - String getStreamResult(std::ostream* in) { - return static_cast(in)->str().c_str(); // NOLINT +String rawMemoryToString(const void* object, unsigned size) { + // Reverse order for little endian architectures + int i = 0, end = static_cast(size), inc = 1; + if (Endianness::which() == Endianness::Little) { + i = end - 1; + end = inc = -1; } - void freeStream(std::ostream* in) { delete in; } + + unsigned char const* bytes = static_cast(object); + std::ostringstream os; + os << "0x" << std::setfill('0') << std::hex; + for (; i != end; i += inc) + os << std::setw(2) << static_cast(bytes[i]); + return os.str().c_str(); +} + +std::ostream* createStream() { return new std::ostringstream(); } +String getStreamResult(std::ostream* in) { + return static_cast(in)->str().c_str(); // NOLINT +} +void freeStream(std::ostream* in) { delete in; } #ifndef DOCTEST_CONFIG_DISABLE - // this holds both parameters for the command line and runtime data for tests - struct ContextState : TestAccessibleContextState //!OCLINT too many fields - { - // == parameters from the command line - - std::vector > filters; - - String order_by; // how tests should be ordered - unsigned rand_seed; // the seed for rand ordering - - unsigned first; // the first (matching) test to be executed - unsigned last; // the last (matching) test to be executed - - int abort_after; // stop tests after this many failed assertions - int subcase_filter_levels; // apply the subcase filters for the first N levels - bool case_sensitive; // if filtering should be case sensitive - bool exit; // if the program should be exited after the tests are ran/whatever - bool duration; // print the time duration of each test case - bool no_exitcode; // if the framework should return 0 as the exitcode - bool no_run; // to not run the tests at all (can be done with an "*" exclude) - bool no_version; // to not print the version of the framework - bool no_colors; // if output to the console should be colorized - bool force_colors; // forces the use of colors even when a tty cannot be detected - bool no_breaks; // to not break into the debugger - bool no_skip; // don't skip test cases which are marked to be skipped - bool no_path_in_filenames; // if the path to files should be removed from the output - bool no_line_numbers; // if source code line numbers should be omitted from the output - bool no_skipped_summary; // don't print "skipped" in the summary !!! UNDOCUMENTED !!! - - bool help; // to print the help - bool version; // to print the version - bool count; // if only the count of matching tests is to be retreived - bool list_test_cases; // to list all tests matching the filters - bool list_test_suites; // to list all suites matching the filters - - // == data for the tests being ran - - unsigned numTestsPassingFilters; - unsigned numTestSuitesPassingFilters; - unsigned numFailed; - const TestCase* currentTest; - bool hasLoggedCurrentTestStart; - int numAssertionsForCurrentTestcase; - int numAssertions; - int numFailedAssertionsForCurrentTestcase; - int numFailedAssertions; - bool hasCurrentTestFailed; - - std::vector contexts; // for logging with INFO() and friends - std::vector exceptionalContexts; // logging from INFO() due to an exception - - // stuff for subcases - std::set subcasesPassed; - std::set subcasesEnteredLevels; - std::vector subcasesStack; - int subcasesCurrentLevel; - bool subcasesHasSkipped; - - void resetRunData() { - numTestsPassingFilters = 0; - numTestSuitesPassingFilters = 0; - numFailed = 0; - numAssertions = 0; - numFailedAssertions = 0; - numFailedAssertionsForCurrentTestcase = 0; - } +// this holds both parameters for the command line and runtime data for tests +struct ContextState : TestAccessibleContextState //! OCLINT too many fields +{ + // == parameters from the command line + + std::vector > filters; + + String order_by; // how tests should be ordered + unsigned rand_seed; // the seed for rand ordering + + unsigned first; // the first (matching) test to be executed + unsigned last; // the last (matching) test to be executed + + int abort_after; // stop tests after this many failed assertions + int subcase_filter_levels; // apply the subcase filters for the first N + // levels + bool case_sensitive; // if filtering should be case sensitive + bool exit; // if the program should be exited after the tests are + // ran/whatever + bool duration; // print the time duration of each test case + bool no_exitcode; // if the framework should return 0 as the exitcode + bool no_run; // to not run the tests at all (can be done with an "*" + // exclude) + bool no_version; // to not print the version of the framework + bool no_colors; // if output to the console should be colorized + bool force_colors; // forces the use of colors even when a tty cannot be + // detected + bool no_breaks; // to not break into the debugger + bool no_skip; // don't skip test cases which are marked to be skipped + bool no_path_in_filenames; // if the path to files should be removed from + // the output + bool no_line_numbers; // if source code line numbers should be omitted from + // the output + bool no_skipped_summary; // don't print "skipped" in the summary !!! + // UNDOCUMENTED !!! + + bool help; // to print the help + bool version; // to print the version + bool count; // if only the count of matching tests is to be retreived + bool list_test_cases; // to list all tests matching the filters + bool list_test_suites; // to list all suites matching the filters + + // == data for the tests being ran + + unsigned numTestsPassingFilters; + unsigned numTestSuitesPassingFilters; + unsigned numFailed; + const TestCase* currentTest; + bool hasLoggedCurrentTestStart; + int numAssertionsForCurrentTestcase; + int numAssertions; + int numFailedAssertionsForCurrentTestcase; + int numFailedAssertions; + bool hasCurrentTestFailed; + + std::vector + contexts; // for logging with INFO() and friends + std::vector + exceptionalContexts; // logging from INFO() due to an exception + + // stuff for subcases + std::set subcasesPassed; + std::set subcasesEnteredLevels; + std::vector subcasesStack; + int subcasesCurrentLevel; + bool subcasesHasSkipped; + + void resetRunData() { + numTestsPassingFilters = 0; + numTestSuitesPassingFilters = 0; + numFailed = 0; + numAssertions = 0; + numFailedAssertions = 0; + numFailedAssertionsForCurrentTestcase = 0; + } - // cppcheck-suppress uninitMemberVar - ContextState() - : filters(8) // 8 different filters total - { - resetRunData(); - } - }; + // cppcheck-suppress uninitMemberVar + ContextState() + : filters(8) // 8 different filters total + { + resetRunData(); + } +}; - ContextState* contextState = 0; -#endif // DOCTEST_CONFIG_DISABLE -} // namespace detail +ContextState* contextState = 0; +#endif // DOCTEST_CONFIG_DISABLE +} // namespace detail void String::copy(const String& other) { - if(other.isOnStack()) { + if (other.isOnStack()) { detail::my_memcpy(buf, other.buf, len); } else { setOnHeap(); - data.size = other.data.size; + data.size = other.data.size; data.capacity = data.size + 1; - data.ptr = new char[data.capacity]; + data.ptr = new char[data.capacity]; detail::my_memcpy(data.ptr, other.data.ptr, data.size + 1); } } String::String(const char* in) { unsigned in_len = detail::my_strlen(in); - if(in_len <= last) { + if (in_len <= last) { detail::my_memcpy(buf, in, in_len + 1); setLast(last - in_len); } else { setOnHeap(); - data.size = in_len; + data.size = in_len; data.capacity = data.size + 1; - data.ptr = new char[data.capacity]; + data.ptr = new char[data.capacity]; detail::my_memcpy(data.ptr, in, in_len + 1); } } String& String::operator+=(const String& other) { const unsigned my_old_size = size(); - const unsigned other_size = other.size(); - const unsigned total_size = my_old_size + other_size; - if(isOnStack()) { - if(total_size < len) { + const unsigned other_size = other.size(); + const unsigned total_size = my_old_size + other_size; + if (isOnStack()) { + if (total_size < len) { // append to the current stack space detail::my_memcpy(buf + my_old_size, other.c_str(), other_size + 1); setLast(last - total_size); @@ -3533,36 +3639,40 @@ String& String::operator+=(const String& other) { // alloc new chunk char* temp = new char[total_size + 1]; // copy current data to new location before writing in the union - detail::my_memcpy(temp, buf, my_old_size); // skip the +1 ('\0') for speed + detail::my_memcpy( + temp, buf, my_old_size); // skip the +1 ('\0') for speed // update data in union setOnHeap(); - data.size = total_size; + data.size = total_size; data.capacity = data.size + 1; - data.ptr = temp; + data.ptr = temp; // transfer the rest of the data - detail::my_memcpy(data.ptr + my_old_size, other.c_str(), other_size + 1); + detail::my_memcpy( + data.ptr + my_old_size, other.c_str(), other_size + 1); } } else { - if(data.capacity > total_size) { + if (data.capacity > total_size) { // append to the current heap block data.size = total_size; - detail::my_memcpy(data.ptr + my_old_size, other.c_str(), other_size + 1); + detail::my_memcpy( + data.ptr + my_old_size, other.c_str(), other_size + 1); } else { // resize data.capacity *= 2; - if(data.capacity <= total_size) - data.capacity = total_size + 1; + if (data.capacity <= total_size) data.capacity = total_size + 1; // alloc new chunk char* temp = new char[data.capacity]; // copy current data to new location before releasing it - detail::my_memcpy(temp, data.ptr, my_old_size); // skip the +1 ('\0') for speed + detail::my_memcpy( + temp, data.ptr, my_old_size); // skip the +1 ('\0') for speed // release old chunk delete[] data.ptr; // update the rest of the union members data.size = total_size; - data.ptr = temp; + data.ptr = temp; // transfer the rest of the data - detail::my_memcpy(data.ptr + my_old_size, other.c_str(), other_size + 1); + detail::my_memcpy( + data.ptr + my_old_size, other.c_str(), other_size + 1); } } @@ -3577,20 +3687,18 @@ String::String(String&& other) { } String& String::operator=(String&& other) { - if(this != &other) { - if(!isOnStack()) - delete[] data.ptr; + if (this != &other) { + if (!isOnStack()) delete[] data.ptr; detail::my_memcpy(buf, other.buf, len); other.buf[0] = '\0'; other.setLast(); } return *this; } -#endif // DOCTEST_CONFIG_WITH_RVALUE_REFERENCES +#endif // DOCTEST_CONFIG_WITH_RVALUE_REFERENCES int String::compare(const char* other, bool no_case) const { - if(no_case) - return detail::stricmp(c_str(), other); + if (no_case) return detail::stricmp(c_str(), other); return std::strcmp(c_str(), other); } @@ -3604,22 +3712,29 @@ std::ostream& operator<<(std::ostream& stream, const String& in) { } Approx::Approx(double value) - : m_epsilon(static_cast(std::numeric_limits::epsilon()) * 100) - , m_scale(1.0) - , m_value(value) {} + : m_epsilon( + static_cast(std::numeric_limits::epsilon()) * 100), + m_scale(1.0), + m_value(value) {} bool operator==(double lhs, Approx const& rhs) { // Thanks to Richard Harris for his help refining this formula - return std::fabs(lhs - rhs.m_value) < - rhs.m_epsilon * (rhs.m_scale + detail::my_max(std::fabs(lhs), std::fabs(rhs.m_value))); + return std::fabs(lhs - rhs.m_value) + < rhs.m_epsilon + * (rhs.m_scale + + detail::my_max(std::fabs(lhs), std::fabs(rhs.m_value))); } -String Approx::toString() const { return String("Approx( ") + doctest::toString(m_value) + " )"; } +String Approx::toString() const { + return String("Approx( ") + doctest::toString(m_value) + " )"; +} #ifdef DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING String toString(char* in) { return toString(static_cast(in)); } -String toString(const char* in) { return String("\"") + (in ? in : "{null string}") + "\""; } -#endif // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING +String toString(const char* in) { + return String("\"") + (in ? in : "{null string}") + "\""; +} +#endif // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING String toString(bool in) { return in ? "true" : "false"; } String toString(float in) { return detail::fpToString(in, 5) + "f"; } String toString(double in) { return detail::fpToString(in, 10); } @@ -3690,17 +3805,16 @@ String toString(int long long unsigned in) { std::sprintf(buf, "%llu", in); return buf; } -#endif // DOCTEST_CONFIG_WITH_LONG_LONG +#endif // DOCTEST_CONFIG_WITH_LONG_LONG #ifdef DOCTEST_CONFIG_WITH_NULLPTR String toString(std::nullptr_t) { return "nullptr"; } -#endif // DOCTEST_CONFIG_WITH_NULLPTR +#endif // DOCTEST_CONFIG_WITH_NULLPTR -} // namespace doctest +} // namespace doctest #ifdef DOCTEST_CONFIG_DISABLE -namespace doctest -{ +namespace doctest { bool isRunningInTest() { return false; } Context::Context(int, const char* const*) {} Context::~Context() {} @@ -3710,58 +3824,59 @@ void Context::clearFilters() {} void Context::setOption(const char*, int) {} void Context::setOption(const char*, const char*) {} bool Context::shouldExit() { return false; } -int Context::run() { return 0; } -} // namespace doctest -#else // DOCTEST_CONFIG_DISABLE +int Context::run() { return 0; } +} // namespace doctest +#else // DOCTEST_CONFIG_DISABLE #if !defined(DOCTEST_CONFIG_COLORS_NONE) -#if !defined(DOCTEST_CONFIG_COLORS_WINDOWS) && !defined(DOCTEST_CONFIG_COLORS_ANSI) +#if !defined(DOCTEST_CONFIG_COLORS_WINDOWS) \ + && !defined(DOCTEST_CONFIG_COLORS_ANSI) #ifdef DOCTEST_PLATFORM_WINDOWS #define DOCTEST_CONFIG_COLORS_WINDOWS -#else // linux +#else // linux #define DOCTEST_CONFIG_COLORS_ANSI -#endif // platform -#endif // DOCTEST_CONFIG_COLORS_WINDOWS && DOCTEST_CONFIG_COLORS_ANSI -#endif // DOCTEST_CONFIG_COLORS_NONE +#endif // platform +#endif // DOCTEST_CONFIG_COLORS_WINDOWS && DOCTEST_CONFIG_COLORS_ANSI +#endif // DOCTEST_CONFIG_COLORS_NONE -#define DOCTEST_PRINTF_COLORED(buffer, color) \ - do { \ - Color col(color); \ - std::printf("%s", buffer); \ - } while((void)0, 0) +#define DOCTEST_PRINTF_COLORED(buffer, color) \ + do { \ + Color col(color); \ + std::printf("%s", buffer); \ + } while ((void)0, 0) // the buffer size used for snprintf() calls #if !defined(DOCTEST_SNPRINTF_BUFFER_LENGTH) #define DOCTEST_SNPRINTF_BUFFER_LENGTH 1024 -#endif // DOCTEST_SNPRINTF_BUFFER_LENGTH +#endif // DOCTEST_SNPRINTF_BUFFER_LENGTH #if DOCTEST_MSVC || defined(__MINGW32__) #if DOCTEST_MSVC >= DOCTEST_COMPILER(17, 0, 0) #define DOCTEST_WINDOWS_SAL_IN_OPT _In_opt_ -#else // MSVC +#else // MSVC #define DOCTEST_WINDOWS_SAL_IN_OPT -#endif // MSVC +#endif // MSVC extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA( - DOCTEST_WINDOWS_SAL_IN_OPT const char*); + DOCTEST_WINDOWS_SAL_IN_OPT const char*); extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); -#endif // MSVC || __MINGW32__ +#endif // MSVC || __MINGW32__ #ifdef DOCTEST_CONFIG_COLORS_ANSI #include -#endif // DOCTEST_CONFIG_COLORS_ANSI +#endif // DOCTEST_CONFIG_COLORS_ANSI #ifdef DOCTEST_PLATFORM_WINDOWS // defines for a leaner windows.h #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN -#endif // WIN32_LEAN_AND_MEAN +#endif // WIN32_LEAN_AND_MEAN #ifndef VC_EXTRA_LEAN #define VC_EXTRA_LEAN -#endif // VC_EXTRA_LEAN +#endif // VC_EXTRA_LEAN #ifndef NOMINMAX #define NOMINMAX -#endif // NOMINMAX +#endif // NOMINMAX DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_BEGIN @@ -3775,87 +3890,82 @@ DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_BEGIN DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_END -#else // DOCTEST_PLATFORM_WINDOWS +#else // DOCTEST_PLATFORM_WINDOWS #include -#endif // DOCTEST_PLATFORM_WINDOWS +#endif // DOCTEST_PLATFORM_WINDOWS -namespace doctest_detail_test_suite_ns -{ +namespace doctest_detail_test_suite_ns { // holds the current test suite doctest::detail::TestSuite& getCurrentTestSuite() { static doctest::detail::TestSuite data; return data; } -} // namespace doctest_detail_test_suite_ns - -namespace doctest -{ -namespace detail -{ - TestCase::TestCase(funcType test, const char* file, unsigned line, const TestSuite& test_suite, - const char* type, int template_id) - : m_test(test) - , m_name(0) - , m_type(type) - , m_test_suite(test_suite.m_test_suite) - , m_description(test_suite.m_description) - , m_skip(test_suite.m_skip) - , m_may_fail(test_suite.m_may_fail) - , m_should_fail(test_suite.m_should_fail) - , m_expected_failures(test_suite.m_expected_failures) - , m_timeout(test_suite.m_timeout) - , m_file(file) - , m_line(line) - , m_template_id(template_id) {} - - TestCase& TestCase::operator*(const char* in) { - m_name = in; - // make a new name with an appended type for templated test case - if(m_template_id != -1) { - m_full_name = String(m_name) + m_type; - // redirect the name to point to the newly constructed full name - m_name = m_full_name.c_str(); - } - return *this; +} // namespace doctest_detail_test_suite_ns + +namespace doctest { +namespace detail { +TestCase::TestCase( + funcType test, const char* file, unsigned line, const TestSuite& test_suite, + const char* type, int template_id) + : m_test(test), + m_name(0), + m_type(type), + m_test_suite(test_suite.m_test_suite), + m_description(test_suite.m_description), + m_skip(test_suite.m_skip), + m_may_fail(test_suite.m_may_fail), + m_should_fail(test_suite.m_should_fail), + m_expected_failures(test_suite.m_expected_failures), + m_timeout(test_suite.m_timeout), + m_file(file), + m_line(line), + m_template_id(template_id) {} + +TestCase& TestCase::operator*(const char* in) { + m_name = in; + // make a new name with an appended type for templated test case + if (m_template_id != -1) { + m_full_name = String(m_name) + m_type; + // redirect the name to point to the newly constructed full name + m_name = m_full_name.c_str(); } + return *this; +} - TestCase& TestCase::operator=(const TestCase& other) { - m_test = other.m_test; - m_full_name = other.m_full_name; - m_name = other.m_name; - m_type = other.m_type; - m_test_suite = other.m_test_suite; - m_description = other.m_description; - m_skip = other.m_skip; - m_may_fail = other.m_may_fail; - m_should_fail = other.m_should_fail; - m_expected_failures = other.m_expected_failures; - m_timeout = other.m_timeout; - m_file = other.m_file; - m_line = other.m_line; - m_template_id = other.m_template_id; - - if(m_template_id != -1) - m_name = m_full_name.c_str(); - return *this; - } +TestCase& TestCase::operator=(const TestCase& other) { + m_test = other.m_test; + m_full_name = other.m_full_name; + m_name = other.m_name; + m_type = other.m_type; + m_test_suite = other.m_test_suite; + m_description = other.m_description; + m_skip = other.m_skip; + m_may_fail = other.m_may_fail; + m_should_fail = other.m_should_fail; + m_expected_failures = other.m_expected_failures; + m_timeout = other.m_timeout; + m_file = other.m_file; + m_line = other.m_line; + m_template_id = other.m_template_id; + + if (m_template_id != -1) m_name = m_full_name.c_str(); + return *this; +} - bool TestCase::operator<(const TestCase& other) const { - if(m_line != other.m_line) - return m_line < other.m_line; - const int file_cmp = std::strcmp(m_file, other.m_file); - if(file_cmp != 0) - return file_cmp < 0; - return m_template_id < other.m_template_id; - } +bool TestCase::operator<(const TestCase& other) const { + if (m_line != other.m_line) return m_line < other.m_line; + const int file_cmp = std::strcmp(m_file, other.m_file); + if (file_cmp != 0) return file_cmp < 0; + return m_template_id < other.m_template_id; +} - const char* getAssertString(assertType::Enum val) { - DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH( - 4062) // enumerator 'x' in switch of enum 'y' is not handled - switch(val) { //!OCLINT missing default in switch statements - // clang-format off +const char* getAssertString(assertType::Enum val) { + DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH( + 4062) // enumerator 'x' in switch of enum 'y' is not handled + switch (val) { //! OCLINT missing default in switch statements + // clang-format off case assertType::DT_WARN : return "WARN"; case assertType::DT_CHECK : return "CHECK"; case assertType::DT_REQUIRE : return "REQUIRE"; @@ -3927,329 +4037,329 @@ namespace detail case assertType::DT_FAST_WARN_UNARY_FALSE : return "FAST_WARN_UNARY_FALSE"; case assertType::DT_FAST_CHECK_UNARY_FALSE : return "FAST_CHECK_UNARY_FALSE"; case assertType::DT_FAST_REQUIRE_UNARY_FALSE: return "FAST_REQUIRE_UNARY_FALSE"; - // clang-format on - } - DOCTEST_MSVC_SUPPRESS_WARNING_POP - return ""; + // clang-format on } + DOCTEST_MSVC_SUPPRESS_WARNING_POP + return ""; +} - bool checkIfShouldThrow(assertType::Enum assert_type) { - if(assert_type & assertType::is_require) //!OCLINT bitwise operator in conditional - return true; +bool checkIfShouldThrow(assertType::Enum assert_type) { + if (assert_type + & assertType::is_require) //! OCLINT bitwise operator in conditional + return true; - if((assert_type & assertType::is_check) //!OCLINT bitwise operator in conditional - && contextState->abort_after > 0 && - contextState->numFailedAssertions >= contextState->abort_after) - return true; + if ((assert_type + & assertType::is_check) //! OCLINT bitwise operator in conditional + && contextState->abort_after > 0 + && contextState->numFailedAssertions >= contextState->abort_after) + return true; - return false; - } - void fastAssertThrowIfFlagSet(int flags) { - if(flags & assertAction::shouldthrow) //!OCLINT bitwise operator in conditional - throwException(); - } - void throwException() { + return false; +} +void fastAssertThrowIfFlagSet(int flags) { + if (flags + & assertAction::shouldthrow) //! OCLINT bitwise operator in conditional + throwException(); +} +void throwException() { #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS - throw TestFailureException(); -#endif // DOCTEST_CONFIG_NO_EXCEPTIONS - } + throw TestFailureException(); +#endif // DOCTEST_CONFIG_NO_EXCEPTIONS +} - // matching of a string against a wildcard mask (case sensitivity configurable) taken from - // http://www.emoticode.net/c/simple-wildcard-string-compare-globbing-function.html - int wildcmp(const char* str, const char* wild, bool caseSensitive) { - const char* cp = 0; - const char* mp = 0; - - // rolled my own tolower() to not include more headers - while((*str) && (*wild != '*')) { - if((caseSensitive ? (*wild != *str) : (tolower(*wild) != tolower(*str))) && - (*wild != '?')) { - return 0; - } - wild++; - str++; +// matching of a string against a wildcard mask (case sensitivity configurable) +// taken from +// http://www.emoticode.net/c/simple-wildcard-string-compare-globbing-function.html +int wildcmp(const char* str, const char* wild, bool caseSensitive) { + const char* cp = 0; + const char* mp = 0; + + // rolled my own tolower() to not include more headers + while ((*str) && (*wild != '*')) { + if ((caseSensitive ? (*wild != *str) + : (tolower(*wild) != tolower(*str))) + && (*wild != '?')) { + return 0; } + wild++; + str++; + } - while(*str) { - if(*wild == '*') { - if(!*++wild) { - return 1; - } - mp = wild; - cp = str + 1; - } else if((caseSensitive ? (*wild == *str) : (tolower(*wild) == tolower(*str))) || - (*wild == '?')) { - wild++; - str++; - } else { - wild = mp; //!OCLINT parameter reassignment - str = cp++; //!OCLINT parameter reassignment + while (*str) { + if (*wild == '*') { + if (!*++wild) { + return 1; } - } - - while(*wild == '*') { + mp = wild; + cp = str + 1; + } else if ( + (caseSensitive ? (*wild == *str) + : (tolower(*wild) == tolower(*str))) + || (*wild == '?')) { wild++; + str++; + } else { + wild = mp; //! OCLINT parameter reassignment + str = cp++; //! OCLINT parameter reassignment } - return !*wild; } - //// C string hash function (djb2) - taken from http://www.cse.yorku.ca/~oz/hash.html - //unsigned hashStr(unsigned const char* str) { - // unsigned long hash = 5381; - // char c; - // while((c = *str++)) - // hash = ((hash << 5) + hash) + c; // hash * 33 + c - // return hash; - //} - - // checks if the name matches any of the filters (and can be configured what to do when empty) - bool matchesAny(const char* name, const std::vector& filters, int matchEmpty, - bool caseSensitive) { - if(filters.empty() && matchEmpty) - return true; - for(unsigned i = 0; i < filters.size(); ++i) - if(wildcmp(name, filters[i].c_str(), caseSensitive)) - return true; - return false; + while (*wild == '*') { + wild++; } + return !*wild; +} + +//// C string hash function (djb2) - taken from +/// http://www.cse.yorku.ca/~oz/hash.html +// unsigned hashStr(unsigned const char* str) { +// unsigned long hash = 5381; +// char c; +// while((c = *str++)) +// hash = ((hash << 5) + hash) + c; // hash * 33 + c +// return hash; +// } + +// checks if the name matches any of the filters (and can be configured what to +// do when empty) +bool matchesAny( + const char* name, const std::vector& filters, int matchEmpty, + bool caseSensitive) { + if (filters.empty() && matchEmpty) return true; + for (unsigned i = 0; i < filters.size(); ++i) + if (wildcmp(name, filters[i].c_str(), caseSensitive)) return true; + return false; +} #ifdef DOCTEST_PLATFORM_WINDOWS - typedef unsigned long long UInt64; +typedef unsigned long long UInt64; - UInt64 getCurrentTicks() { - static UInt64 hz = 0, hzo = 0; - if(!hz) { - QueryPerformanceFrequency(reinterpret_cast(&hz)); - QueryPerformanceCounter(reinterpret_cast(&hzo)); - } - UInt64 t; - QueryPerformanceCounter(reinterpret_cast(&t)); - return ((t - hzo) * 1000000) / hz; +UInt64 getCurrentTicks() { + static UInt64 hz = 0, hzo = 0; + if (!hz) { + QueryPerformanceFrequency(reinterpret_cast(&hz)); + QueryPerformanceCounter(reinterpret_cast(&hzo)); } -#else // DOCTEST_PLATFORM_WINDOWS + UInt64 t; + QueryPerformanceCounter(reinterpret_cast(&t)); + return ((t - hzo) * 1000000) / hz; +} +#else // DOCTEST_PLATFORM_WINDOWS - typedef uint64_t UInt64; +typedef uint64_t UInt64; - UInt64 getCurrentTicks() { - timeval t; - gettimeofday(&t, 0); - return static_cast(t.tv_sec) * 1000000 + static_cast(t.tv_usec); +UInt64 getCurrentTicks() { + timeval t; + gettimeofday(&t, 0); + return static_cast(t.tv_sec) * 1000000 + + static_cast(t.tv_usec); +} +#endif // DOCTEST_PLATFORM_WINDOWS + +class Timer { + public: + Timer() : m_ticks(0) {} + void start() { m_ticks = getCurrentTicks(); } + unsigned int getElapsedMicroseconds() const { + return static_cast(getCurrentTicks() - m_ticks); + } + unsigned int getElapsedMilliseconds() const { + return static_cast(getElapsedMicroseconds() / 1000); + } + double getElapsedSeconds() const { + return getElapsedMicroseconds() / 1000000.0; } -#endif // DOCTEST_PLATFORM_WINDOWS - class Timer - { - public: - Timer() - : m_ticks(0) {} - void start() { m_ticks = getCurrentTicks(); } - unsigned int getElapsedMicroseconds() const { - return static_cast(getCurrentTicks() - m_ticks); - } - unsigned int getElapsedMilliseconds() const { - return static_cast(getElapsedMicroseconds() / 1000); - } - double getElapsedSeconds() const { return getElapsedMicroseconds() / 1000000.0; } + private: + UInt64 m_ticks; +}; - private: - UInt64 m_ticks; - }; +TestAccessibleContextState* getTestsContextState() { return contextState; } - TestAccessibleContextState* getTestsContextState() { return contextState; } +bool SubcaseSignature::operator<(const SubcaseSignature& other) const { + if (m_line != other.m_line) return m_line < other.m_line; + if (std::strcmp(m_file, other.m_file) != 0) + return std::strcmp(m_file, other.m_file) < 0; + return std::strcmp(m_name, other.m_name) < 0; +} - bool SubcaseSignature::operator<(const SubcaseSignature& other) const { - if(m_line != other.m_line) - return m_line < other.m_line; - if(std::strcmp(m_file, other.m_file) != 0) - return std::strcmp(m_file, other.m_file) < 0; - return std::strcmp(m_name, other.m_name) < 0; - } +Subcase::Subcase(const char* name, const char* file, int line) + : m_signature(name, file, line), m_entered(false) { + ContextState* s = contextState; - Subcase::Subcase(const char* name, const char* file, int line) - : m_signature(name, file, line) - , m_entered(false) { - ContextState* s = contextState; + // if we have already completed it + if (s->subcasesPassed.count(m_signature) != 0) return; - // if we have already completed it - if(s->subcasesPassed.count(m_signature) != 0) + // check subcase filters + if (s->subcasesCurrentLevel < s->subcase_filter_levels) { + if (!matchesAny( + m_signature.m_name, s->filters[6], 1, s->case_sensitive)) return; + if (matchesAny(m_signature.m_name, s->filters[7], 0, s->case_sensitive)) + return; + } - // check subcase filters - if(s->subcasesCurrentLevel < s->subcase_filter_levels) { - if(!matchesAny(m_signature.m_name, s->filters[6], 1, s->case_sensitive)) - return; - if(matchesAny(m_signature.m_name, s->filters[7], 0, s->case_sensitive)) - return; - } + // if a Subcase on the same level has already been entered + if (s->subcasesEnteredLevels.count(s->subcasesCurrentLevel) != 0) { + s->subcasesHasSkipped = true; + return; + } - // if a Subcase on the same level has already been entered - if(s->subcasesEnteredLevels.count(s->subcasesCurrentLevel) != 0) { - s->subcasesHasSkipped = true; - return; - } + s->subcasesStack.push_back(*this); + if (s->hasLoggedCurrentTestStart) logTestEnd(); + s->hasLoggedCurrentTestStart = false; - s->subcasesStack.push_back(*this); - if(s->hasLoggedCurrentTestStart) - logTestEnd(); - s->hasLoggedCurrentTestStart = false; + s->subcasesEnteredLevels.insert(s->subcasesCurrentLevel++); + m_entered = true; +} - s->subcasesEnteredLevels.insert(s->subcasesCurrentLevel++); - m_entered = true; - } +Subcase::Subcase(const Subcase& other) + : m_signature( + other.m_signature.m_name, other.m_signature.m_file, + other.m_signature.m_line), + m_entered(other.m_entered) {} - Subcase::Subcase(const Subcase& other) - : m_signature(other.m_signature.m_name, other.m_signature.m_file, - other.m_signature.m_line) - , m_entered(other.m_entered) {} - - Subcase::~Subcase() { - if(m_entered) { - ContextState* s = contextState; - - s->subcasesCurrentLevel--; - // only mark the subcase as passed if no subcases have been skipped - if(s->subcasesHasSkipped == false) - s->subcasesPassed.insert(m_signature); - - if(!s->subcasesStack.empty()) - s->subcasesStack.pop_back(); - if(s->hasLoggedCurrentTestStart) - logTestEnd(); - s->hasLoggedCurrentTestStart = false; - } +Subcase::~Subcase() { + if (m_entered) { + ContextState* s = contextState; + + s->subcasesCurrentLevel--; + // only mark the subcase as passed if no subcases have been skipped + if (s->subcasesHasSkipped == false) + s->subcasesPassed.insert(m_signature); + + if (!s->subcasesStack.empty()) s->subcasesStack.pop_back(); + if (s->hasLoggedCurrentTestStart) logTestEnd(); + s->hasLoggedCurrentTestStart = false; } +} - Result::~Result() {} +Result::~Result() {} - Result& Result::operator=(const Result& other) { - m_passed = other.m_passed; - m_decomposition = other.m_decomposition; +Result& Result::operator=(const Result& other) { + m_passed = other.m_passed; + m_decomposition = other.m_decomposition; - return *this; - } + return *this; +} - // for sorting tests by file/line - int fileOrderComparator(const void* a, const void* b) { - const TestCase* lhs = *static_cast(a); - const TestCase* rhs = *static_cast(b); +// for sorting tests by file/line +int fileOrderComparator(const void* a, const void* b) { + const TestCase* lhs = *static_cast(a); + const TestCase* rhs = *static_cast(b); #if DOCTEST_MSVC - // this is needed because MSVC gives different case for drive letters - // for __FILE__ when evaluated in a header and a source file - const int res = stricmp(lhs->m_file, rhs->m_file); -#else // MSVC - const int res = std::strcmp(lhs->m_file, rhs->m_file); -#endif // MSVC - if(res != 0) - return res; - return static_cast(lhs->m_line - rhs->m_line); - } + // this is needed because MSVC gives different case for drive letters + // for __FILE__ when evaluated in a header and a source file + const int res = stricmp(lhs->m_file, rhs->m_file); +#else // MSVC + const int res = std::strcmp(lhs->m_file, rhs->m_file); +#endif // MSVC + if (res != 0) return res; + return static_cast(lhs->m_line - rhs->m_line); +} - // for sorting tests by suite/file/line - int suiteOrderComparator(const void* a, const void* b) { - const TestCase* lhs = *static_cast(a); - const TestCase* rhs = *static_cast(b); +// for sorting tests by suite/file/line +int suiteOrderComparator(const void* a, const void* b) { + const TestCase* lhs = *static_cast(a); + const TestCase* rhs = *static_cast(b); - const int res = std::strcmp(lhs->m_test_suite, rhs->m_test_suite); - if(res != 0) - return res; - return fileOrderComparator(a, b); - } + const int res = std::strcmp(lhs->m_test_suite, rhs->m_test_suite); + if (res != 0) return res; + return fileOrderComparator(a, b); +} - // for sorting tests by name/suite/file/line - int nameOrderComparator(const void* a, const void* b) { - const TestCase* lhs = *static_cast(a); - const TestCase* rhs = *static_cast(b); +// for sorting tests by name/suite/file/line +int nameOrderComparator(const void* a, const void* b) { + const TestCase* lhs = *static_cast(a); + const TestCase* rhs = *static_cast(b); - const int res_name = std::strcmp(lhs->m_name, rhs->m_name); - if(res_name != 0) - return res_name; - return suiteOrderComparator(a, b); - } + const int res_name = std::strcmp(lhs->m_name, rhs->m_name); + if (res_name != 0) return res_name; + return suiteOrderComparator(a, b); +} - // sets the current test suite - int setTestSuite(const TestSuite& ts) { - doctest_detail_test_suite_ns::getCurrentTestSuite() = ts; - return 0; - } +// sets the current test suite +int setTestSuite(const TestSuite& ts) { + doctest_detail_test_suite_ns::getCurrentTestSuite() = ts; + return 0; +} - // all the registered tests - std::set& getRegisteredTests() { - static std::set data; - return data; - } +// all the registered tests +std::set& getRegisteredTests() { + static std::set data; + return data; +} - // used by the macros for registering tests - int regTest(const TestCase& tc) { - getRegisteredTests().insert(tc); - return 0; - } +// used by the macros for registering tests +int regTest(const TestCase& tc) { + getRegisteredTests().insert(tc); + return 0; +} - struct Color - { - enum Code - { - None = 0, - White, - Red, - Green, - Blue, - Cyan, - Yellow, - Grey, - - Bright = 0x10, - - BrightRed = Bright | Red, - BrightGreen = Bright | Green, - LightGrey = Bright | Grey, - BrightWhite = Bright | White - }; - explicit Color(Code code) { use(code); } - ~Color() { use(None); } - - static void use(Code code); - static void init(); +struct Color { + enum Code { + None = 0, + White, + Red, + Green, + Blue, + Cyan, + Yellow, + Grey, + + Bright = 0x10, + + BrightRed = Bright | Red, + BrightGreen = Bright | Green, + LightGrey = Bright | Grey, + BrightWhite = Bright | White }; + explicit Color(Code code) { use(code); } + ~Color() { use(None); } + + static void use(Code code); + static void init(); +}; #ifdef DOCTEST_CONFIG_COLORS_WINDOWS - HANDLE g_stdoutHandle; - WORD g_originalForegroundAttributes; - WORD g_originalBackgroundAttributes; - bool g_attrsInitted = false; -#endif // DOCTEST_CONFIG_COLORS_WINDOWS +HANDLE g_stdoutHandle; +WORD g_originalForegroundAttributes; +WORD g_originalBackgroundAttributes; +bool g_attrsInitted = false; +#endif // DOCTEST_CONFIG_COLORS_WINDOWS - void Color::init() { +void Color::init() { #ifdef DOCTEST_CONFIG_COLORS_WINDOWS - if(!g_attrsInitted) { - g_stdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE); - g_attrsInitted = true; - CONSOLE_SCREEN_BUFFER_INFO csbiInfo; - GetConsoleScreenBufferInfo(g_stdoutHandle, &csbiInfo); - g_originalForegroundAttributes = - csbiInfo.wAttributes & - ~(BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY); - g_originalBackgroundAttributes = - csbiInfo.wAttributes & - ~(FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY); - } -#endif // DOCTEST_CONFIG_COLORS_WINDOWS + if (!g_attrsInitted) { + g_stdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE); + g_attrsInitted = true; + CONSOLE_SCREEN_BUFFER_INFO csbiInfo; + GetConsoleScreenBufferInfo(g_stdoutHandle, &csbiInfo); + g_originalForegroundAttributes = + csbiInfo.wAttributes + & ~(BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE + | BACKGROUND_INTENSITY); + g_originalBackgroundAttributes = + csbiInfo.wAttributes + & ~(FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE + | FOREGROUND_INTENSITY); } +#endif // DOCTEST_CONFIG_COLORS_WINDOWS +} - void Color::use(Code +void Color::use(Code #ifndef DOCTEST_CONFIG_COLORS_NONE - code -#endif // DOCTEST_CONFIG_COLORS_NONE - ) { - const ContextState* p = contextState; - if(p->no_colors) - return; + code +#endif // DOCTEST_CONFIG_COLORS_NONE +) { + const ContextState* p = contextState; + if (p->no_colors) return; #ifdef DOCTEST_CONFIG_COLORS_ANSI - if(isatty(STDOUT_FILENO) == false && p->force_colors == false) - return; + if (isatty(STDOUT_FILENO) == false && p->force_colors == false) return; - const char* col = ""; - // clang-format off + const char* col = ""; + // clang-format off switch(code) { //!OCLINT missing break in switch statement / unnecessary default statement in covered switch statement case Color::Red: col = "[0;31m"; break; case Color::Green: col = "[0;32m"; break; @@ -4266,18 +4376,17 @@ namespace detail case Color::White: default: col = "[0m"; } - // clang-format on - std::printf("\033%s", col); -#endif // DOCTEST_CONFIG_COLORS_ANSI + // clang-format on + std::printf("\033%s", col); +#endif // DOCTEST_CONFIG_COLORS_ANSI #ifdef DOCTEST_CONFIG_COLORS_WINDOWS - if(isatty(fileno(stdout)) == false && p->force_colors == false) - return; + if (isatty(fileno(stdout)) == false && p->force_colors == false) return; -#define DOCTEST_SET_ATTR(x) \ +#define DOCTEST_SET_ATTR(x) \ SetConsoleTextAttribute(g_stdoutHandle, x | g_originalBackgroundAttributes) - // clang-format off + // clang-format off switch (code) { case Color::White: DOCTEST_SET_ATTR(FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE); break; case Color::Red: DOCTEST_SET_ATTR(FOREGROUND_RED); break; @@ -4296,28 +4405,31 @@ namespace detail } // clang-format on #undef DOCTEST_SET_ATTR -#endif // DOCTEST_CONFIG_COLORS_WINDOWS - } +#endif // DOCTEST_CONFIG_COLORS_WINDOWS +} - std::vector& getExceptionTranslators() { - static std::vector data; - return data; - } +std::vector& getExceptionTranslators() { + static std::vector data; + return data; +} - void registerExceptionTranslatorImpl(const IExceptionTranslator* translateFunction) { - if(std::find(getExceptionTranslators().begin(), getExceptionTranslators().end(), - translateFunction) == getExceptionTranslators().end()) - getExceptionTranslators().push_back(translateFunction); - } +void registerExceptionTranslatorImpl( + const IExceptionTranslator* translateFunction) { + if (std::find( + getExceptionTranslators().begin(), getExceptionTranslators().end(), + translateFunction) + == getExceptionTranslators().end()) + getExceptionTranslators().push_back(translateFunction); +} - String translateActiveException() { +String translateActiveException() { #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS - String res; - std::vector& translators = getExceptionTranslators(); - for(size_t i = 0; i < translators.size(); ++i) - if(translators[i]->translate(res)) - return res; - // clang-format off + String res; + std::vector& translators = + getExceptionTranslators(); + for (size_t i = 0; i < translators.size(); ++i) + if (translators[i]->translate(res)) return res; + // clang-format off try { throw; } catch(std::exception& ex) { @@ -4330,822 +4442,903 @@ namespace detail return "unknown exception"; } // clang-format on -#else // DOCTEST_CONFIG_NO_EXCEPTIONS - return ""; -#endif // DOCTEST_CONFIG_NO_EXCEPTIONS - } +#else // DOCTEST_CONFIG_NO_EXCEPTIONS + return ""; +#endif // DOCTEST_CONFIG_NO_EXCEPTIONS +} - void writeStringToStream(std::ostream* stream, const String& str) { *stream << str; } +void writeStringToStream(std::ostream* stream, const String& str) { + *stream << str; +} #ifdef DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING - void toStream(std::ostream* stream, char* in) { *stream << in; } - void toStream(std::ostream* stream, const char* in) { *stream << in; } -#endif // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING - void toStream(std::ostream* stream, bool in) { - *stream << std::boolalpha << in << std::noboolalpha; - } - void toStream(std::ostream* stream, float in) { *stream << in; } - void toStream(std::ostream* stream, double in) { *stream << in; } - void toStream(std::ostream* stream, double long in) { *stream << in; } - - void toStream(std::ostream* stream, char in) { *stream << in; } - void toStream(std::ostream* stream, char signed in) { *stream << in; } - void toStream(std::ostream* stream, char unsigned in) { *stream << in; } - void toStream(std::ostream* stream, int short in) { *stream << in; } - void toStream(std::ostream* stream, int short unsigned in) { *stream << in; } - void toStream(std::ostream* stream, int in) { *stream << in; } - void toStream(std::ostream* stream, int unsigned in) { *stream << in; } - void toStream(std::ostream* stream, int long in) { *stream << in; } - void toStream(std::ostream* stream, int long unsigned in) { *stream << in; } +void toStream(std::ostream* stream, char* in) { *stream << in; } +void toStream(std::ostream* stream, const char* in) { *stream << in; } +#endif // DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING +void toStream(std::ostream* stream, bool in) { + *stream << std::boolalpha << in << std::noboolalpha; +} +void toStream(std::ostream* stream, float in) { *stream << in; } +void toStream(std::ostream* stream, double in) { *stream << in; } +void toStream(std::ostream* stream, double long in) { *stream << in; } + +void toStream(std::ostream* stream, char in) { *stream << in; } +void toStream(std::ostream* stream, char signed in) { *stream << in; } +void toStream(std::ostream* stream, char unsigned in) { *stream << in; } +void toStream(std::ostream* stream, int short in) { *stream << in; } +void toStream(std::ostream* stream, int short unsigned in) { *stream << in; } +void toStream(std::ostream* stream, int in) { *stream << in; } +void toStream(std::ostream* stream, int unsigned in) { *stream << in; } +void toStream(std::ostream* stream, int long in) { *stream << in; } +void toStream(std::ostream* stream, int long unsigned in) { *stream << in; } #ifdef DOCTEST_CONFIG_WITH_LONG_LONG - void toStream(std::ostream* stream, int long long in) { *stream << in; } - void toStream(std::ostream* stream, int long long unsigned in) { *stream << in; } -#endif // DOCTEST_CONFIG_WITH_LONG_LONG - - void addToContexts(IContextScope* ptr) { contextState->contexts.push_back(ptr); } - void popFromContexts() { contextState->contexts.pop_back(); } - DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4996) // std::uncaught_exception is deprecated in C++17 - void useContextIfExceptionOccurred(IContextScope* ptr) { - if(std::uncaught_exception()) { - std::ostringstream stream; - ptr->build(&stream); - contextState->exceptionalContexts.push_back(stream.str()); - } +void toStream(std::ostream* stream, int long long in) { *stream << in; } +void toStream(std::ostream* stream, int long long unsigned in) { + *stream << in; +} +#endif // DOCTEST_CONFIG_WITH_LONG_LONG + +void addToContexts(IContextScope* ptr) { + contextState->contexts.push_back(ptr); +} +void popFromContexts() { contextState->contexts.pop_back(); } +DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH( + 4996) // std::uncaught_exception is deprecated in C++17 +void useContextIfExceptionOccurred(IContextScope* ptr) { + if (std::uncaught_exception()) { + std::ostringstream stream; + ptr->build(&stream); + contextState->exceptionalContexts.push_back(stream.str()); } - DOCTEST_MSVC_SUPPRESS_WARNING_POP +} +DOCTEST_MSVC_SUPPRESS_WARNING_POP - void printSummary(); +void printSummary(); -#if !defined(DOCTEST_CONFIG_POSIX_SIGNALS) && !defined(DOCTEST_CONFIG_WINDOWS_SEH) - void reportFatal(const std::string&) {} - struct FatalConditionHandler - { - void reset() {} - }; -#else // DOCTEST_CONFIG_POSIX_SIGNALS || DOCTEST_CONFIG_WINDOWS_SEH +#if !defined(DOCTEST_CONFIG_POSIX_SIGNALS) \ + && !defined(DOCTEST_CONFIG_WINDOWS_SEH) +void reportFatal(const std::string&) {} +struct FatalConditionHandler { + void reset() {} +}; +#else // DOCTEST_CONFIG_POSIX_SIGNALS || DOCTEST_CONFIG_WINDOWS_SEH - void reportFatal(const std::string& message) { - DOCTEST_LOG_START(); +void reportFatal(const std::string& message) { + DOCTEST_LOG_START(); - contextState->numAssertions += contextState->numAssertionsForCurrentTestcase; - logTestException(message.c_str(), true); - logTestEnd(); - contextState->numFailed++; + contextState->numAssertions += + contextState->numAssertionsForCurrentTestcase; + logTestException(message.c_str(), true); + logTestEnd(); + contextState->numFailed++; - printSummary(); - } + printSummary(); +} #ifdef DOCTEST_PLATFORM_WINDOWS - struct SignalDefs - { - DWORD id; - const char* name; - }; - // There is no 1-1 mapping between signals and windows exceptions. - // Windows can easily distinguish between SO and SigSegV, - // but SigInt, SigTerm, etc are handled differently. - SignalDefs signalDefs[] = { - {EXCEPTION_ILLEGAL_INSTRUCTION, "SIGILL - Illegal instruction signal"}, - {EXCEPTION_STACK_OVERFLOW, "SIGSEGV - Stack overflow"}, - {EXCEPTION_ACCESS_VIOLATION, "SIGSEGV - Segmentation violation signal"}, - {EXCEPTION_INT_DIVIDE_BY_ZERO, "Divide by zero error"}, - }; +struct SignalDefs { + DWORD id; + const char* name; +}; +// There is no 1-1 mapping between signals and windows exceptions. +// Windows can easily distinguish between SO and SigSegV, +// but SigInt, SigTerm, etc are handled differently. +SignalDefs signalDefs[] = { + {EXCEPTION_ILLEGAL_INSTRUCTION, "SIGILL - Illegal instruction signal"}, + {EXCEPTION_STACK_OVERFLOW, "SIGSEGV - Stack overflow"}, + {EXCEPTION_ACCESS_VIOLATION, "SIGSEGV - Segmentation violation signal"}, + {EXCEPTION_INT_DIVIDE_BY_ZERO, "Divide by zero error"}, +}; - struct FatalConditionHandler - { - static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) { - for(size_t i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) { - if(ExceptionInfo->ExceptionRecord->ExceptionCode == signalDefs[i].id) { - reportFatal(signalDefs[i].name); - } +struct FatalConditionHandler { + static LONG CALLBACK + handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) { + for (size_t i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) { + if (ExceptionInfo->ExceptionRecord->ExceptionCode + == signalDefs[i].id) { + reportFatal(signalDefs[i].name); } - // If its not an exception we care about, pass it along. - // This stops us from eating debugger breaks etc. - return EXCEPTION_CONTINUE_SEARCH; } + // If its not an exception we care about, pass it along. + // This stops us from eating debugger breaks etc. + return EXCEPTION_CONTINUE_SEARCH; + } - FatalConditionHandler() { - isSet = true; - // 32k seems enough for doctest to handle stack overflow, - // but the value was found experimentally, so there is no strong guarantee - guaranteeSize = 32 * 1024; - exceptionHandlerHandle = 0; - // Register as first handler in current chain - exceptionHandlerHandle = AddVectoredExceptionHandler(1, handleVectoredException); - // Pass in guarantee size to be filled - SetThreadStackGuarantee(&guaranteeSize); - } + FatalConditionHandler() { + isSet = true; + // 32k seems enough for doctest to handle stack overflow, + // but the value was found experimentally, so there is no strong + // guarantee + guaranteeSize = 32 * 1024; + exceptionHandlerHandle = 0; + // Register as first handler in current chain + exceptionHandlerHandle = + AddVectoredExceptionHandler(1, handleVectoredException); + // Pass in guarantee size to be filled + SetThreadStackGuarantee(&guaranteeSize); + } - static void reset() { - if(isSet) { - // Unregister handler and restore the old guarantee - RemoveVectoredExceptionHandler(exceptionHandlerHandle); - SetThreadStackGuarantee(&guaranteeSize); - exceptionHandlerHandle = 0; - isSet = false; - } + static void reset() { + if (isSet) { + // Unregister handler and restore the old guarantee + RemoveVectoredExceptionHandler(exceptionHandlerHandle); + SetThreadStackGuarantee(&guaranteeSize); + exceptionHandlerHandle = 0; + isSet = false; } + } - ~FatalConditionHandler() { reset(); } + ~FatalConditionHandler() { reset(); } - private: - static bool isSet; - static ULONG guaranteeSize; - static PVOID exceptionHandlerHandle; - }; + private: + static bool isSet; + static ULONG guaranteeSize; + static PVOID exceptionHandlerHandle; +}; - bool FatalConditionHandler::isSet = false; - ULONG FatalConditionHandler::guaranteeSize = 0; - PVOID FatalConditionHandler::exceptionHandlerHandle = 0; +bool FatalConditionHandler::isSet = false; +ULONG FatalConditionHandler::guaranteeSize = 0; +PVOID FatalConditionHandler::exceptionHandlerHandle = 0; -#else // DOCTEST_PLATFORM_WINDOWS +#else // DOCTEST_PLATFORM_WINDOWS - struct SignalDefs - { - int id; - const char* name; - }; - SignalDefs signalDefs[] = {{SIGINT, "SIGINT - Terminal interrupt signal"}, - {SIGILL, "SIGILL - Illegal instruction signal"}, - {SIGFPE, "SIGFPE - Floating point error signal"}, - {SIGSEGV, "SIGSEGV - Segmentation violation signal"}, - {SIGTERM, "SIGTERM - Termination request signal"}, - {SIGABRT, "SIGABRT - Abort (abnormal termination) signal"}}; - - struct FatalConditionHandler - { - static bool isSet; - static struct sigaction oldSigActions[sizeof(signalDefs) / sizeof(SignalDefs)]; - static stack_t oldSigStack; - static char altStackMem[SIGSTKSZ]; - - static void handleSignal(int sig) { - std::string name = ""; - for(std::size_t i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) { - SignalDefs& def = signalDefs[i]; - if(sig == def.id) { - name = def.name; - break; - } +struct SignalDefs { + int id; + const char* name; +}; +SignalDefs signalDefs[] = { + {SIGINT, "SIGINT - Terminal interrupt signal"}, + {SIGILL, "SIGILL - Illegal instruction signal"}, + {SIGFPE, "SIGFPE - Floating point error signal"}, + {SIGSEGV, "SIGSEGV - Segmentation violation signal"}, + {SIGTERM, "SIGTERM - Termination request signal"}, + {SIGABRT, "SIGABRT - Abort (abnormal termination) signal"}}; + +struct FatalConditionHandler { + static bool isSet; + static struct sigaction + oldSigActions[sizeof(signalDefs) / sizeof(SignalDefs)]; + static stack_t oldSigStack; + static char altStackMem[SIGSTKSZ]; + + static void handleSignal(int sig) { + std::string name = ""; + for (std::size_t i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); + ++i) { + SignalDefs& def = signalDefs[i]; + if (sig == def.id) { + name = def.name; + break; } - reset(); - reportFatal(name); - raise(sig); } + reset(); + reportFatal(name); + raise(sig); + } - FatalConditionHandler() { - isSet = true; - stack_t sigStack; - sigStack.ss_sp = altStackMem; - sigStack.ss_size = SIGSTKSZ; - sigStack.ss_flags = 0; - sigaltstack(&sigStack, &oldSigStack); - struct sigaction sa = {0}; - - sa.sa_handler = handleSignal; // NOLINT - sa.sa_flags = SA_ONSTACK; - for(std::size_t i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) { - sigaction(signalDefs[i].id, &sa, &oldSigActions[i]); - } + FatalConditionHandler() { + isSet = true; + stack_t sigStack; + sigStack.ss_sp = altStackMem; + sigStack.ss_size = SIGSTKSZ; + sigStack.ss_flags = 0; + sigaltstack(&sigStack, &oldSigStack); + struct sigaction sa = {0}; + + sa.sa_handler = handleSignal; // NOLINT + sa.sa_flags = SA_ONSTACK; + for (std::size_t i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); + ++i) { + sigaction(signalDefs[i].id, &sa, &oldSigActions[i]); } + } - ~FatalConditionHandler() { reset(); } - static void reset() { - if(isSet) { - // Set signals back to previous values -- hopefully nobody overwrote them in the meantime - for(std::size_t i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) { - sigaction(signalDefs[i].id, &oldSigActions[i], 0); - } - // Return the old stack - sigaltstack(&oldSigStack, 0); - isSet = false; + ~FatalConditionHandler() { reset(); } + static void reset() { + if (isSet) { + // Set signals back to previous values -- hopefully nobody overwrote + // them in the meantime + for (std::size_t i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); + ++i) { + sigaction(signalDefs[i].id, &oldSigActions[i], 0); } + // Return the old stack + sigaltstack(&oldSigStack, 0); + isSet = false; } - }; + } +}; - bool FatalConditionHandler::isSet = false; - struct sigaction FatalConditionHandler::oldSigActions[sizeof(signalDefs) / sizeof(SignalDefs)] = - {}; - stack_t FatalConditionHandler::oldSigStack = {}; - char FatalConditionHandler::altStackMem[SIGSTKSZ] = {}; - -#endif // DOCTEST_PLATFORM_WINDOWS -#endif // DOCTEST_CONFIG_POSIX_SIGNALS || DOCTEST_CONFIG_WINDOWS_SEH - - // depending on the current options this will remove the path of filenames - const char* fileForOutput(const char* file) { - if(contextState->no_path_in_filenames) { - const char* back = std::strrchr(file, '\\'); - const char* forward = std::strrchr(file, '/'); - if(back || forward) { - if(back > forward) - forward = back; - return forward + 1; - } +bool FatalConditionHandler::isSet = false; +struct sigaction FatalConditionHandler::oldSigActions + [sizeof(signalDefs) / sizeof(SignalDefs)] = {}; +stack_t FatalConditionHandler::oldSigStack = {}; +char FatalConditionHandler::altStackMem[SIGSTKSZ] = {}; + +#endif // DOCTEST_PLATFORM_WINDOWS +#endif // DOCTEST_CONFIG_POSIX_SIGNALS || DOCTEST_CONFIG_WINDOWS_SEH + +// depending on the current options this will remove the path of filenames +const char* fileForOutput(const char* file) { + if (contextState->no_path_in_filenames) { + const char* back = std::strrchr(file, '\\'); + const char* forward = std::strrchr(file, '/'); + if (back || forward) { + if (back > forward) forward = back; + return forward + 1; } - return file; } + return file; +} - // depending on the current options this will substitute the line numbers with 0 - int lineForOutput(int line) { - if(contextState->no_line_numbers) - return 0; - return line; - } +// depending on the current options this will substitute the line numbers with 0 +int lineForOutput(int line) { + if (contextState->no_line_numbers) return 0; + return line; +} #ifdef DOCTEST_PLATFORM_MAC +#include #include #include -#include - // The following function is taken directly from the following technical note: - // http://developer.apple.com/library/mac/#qa/qa2004/qa1361.html - // Returns true if the current process is being debugged (either - // running under the debugger or has a debugger attached post facto). - bool isDebuggerActive() { - int mib[4]; - kinfo_proc info; - size_t size; - // Initialize the flags so that, if sysctl fails for some bizarre - // reason, we get a predictable result. - info.kp_proc.p_flag = 0; - // Initialize mib, which tells sysctl the info we want, in this case - // we're looking for information about a specific process ID. - mib[0] = CTL_KERN; - mib[1] = KERN_PROC; - mib[2] = KERN_PROC_PID; - mib[3] = getpid(); - // Call sysctl. - size = sizeof(info); - if(sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, 0, 0) != 0) { - fprintf(stderr, "\n** Call to sysctl failed - unable to determine if debugger is " - "active **\n\n"); - return false; - } - // We're being debugged if the P_TRACED flag is set. - return ((info.kp_proc.p_flag & P_TRACED) != 0); +// The following function is taken directly from the following technical note: +// http://developer.apple.com/library/mac/#qa/qa2004/qa1361.html +// Returns true if the current process is being debugged (either +// running under the debugger or has a debugger attached post facto). +bool isDebuggerActive() { + int mib[4]; + kinfo_proc info; + size_t size; + // Initialize the flags so that, if sysctl fails for some bizarre + // reason, we get a predictable result. + info.kp_proc.p_flag = 0; + // Initialize mib, which tells sysctl the info we want, in this case + // we're looking for information about a specific process ID. + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PID; + mib[3] = getpid(); + // Call sysctl. + size = sizeof(info); + if (sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, 0, 0) != 0) { + fprintf( + stderr, + "\n** Call to sysctl failed - unable to determine if debugger is " + "active **\n\n"); + return false; } + // We're being debugged if the P_TRACED flag is set. + return ((info.kp_proc.p_flag & P_TRACED) != 0); +} #elif DOCTEST_MSVC || defined(__MINGW32__) - bool isDebuggerActive() { return ::IsDebuggerPresent() != 0; } +bool isDebuggerActive() { return ::IsDebuggerPresent() != 0; } #else - bool isDebuggerActive() { return false; } -#endif // Platform +bool isDebuggerActive() { return false; } +#endif // Platform #ifdef DOCTEST_PLATFORM_WINDOWS - void myOutputDebugString(const String& text) { ::OutputDebugStringA(text.c_str()); } +void myOutputDebugString(const String& text) { + ::OutputDebugStringA(text.c_str()); +} #else - // TODO: integration with XCode and other IDEs - void myOutputDebugString(const String&) {} -#endif // Platform +// TODO: integration with XCode and other IDEs +void myOutputDebugString(const String&) {} +#endif // Platform - const char* getSeparator() { - return "===============================================================================\n"; - } +const char* getSeparator() { + return "===================================================================" + "============\n"; +} - void printToDebugConsole(const String& text) { - if(isDebuggerActive()) - myOutputDebugString(text.c_str()); - } +void printToDebugConsole(const String& text) { + if (isDebuggerActive()) myOutputDebugString(text.c_str()); +} - void addFailedAssert(assertType::Enum assert_type) { - if((assert_type & assertType::is_warn) == 0) { //!OCLINT bitwise operator in conditional - contextState->numFailedAssertions++; - contextState->numFailedAssertionsForCurrentTestcase++; - contextState->hasCurrentTestFailed = true; - } +void addFailedAssert(assertType::Enum assert_type) { + if ((assert_type & assertType::is_warn) + == 0) { //! OCLINT bitwise operator in conditional + contextState->numFailedAssertions++; + contextState->numFailedAssertionsForCurrentTestcase++; + contextState->hasCurrentTestFailed = true; } +} - void logTestStart(const TestCase& tc) { - char loc[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(loc, DOCTEST_COUNTOF(loc), "%s(%d)\n", fileForOutput(tc.m_file), - lineForOutput(tc.m_line)); - - char ts1[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(ts1, DOCTEST_COUNTOF(ts1), "TEST SUITE: "); - char ts2[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(ts2, DOCTEST_COUNTOF(ts2), "%s\n", tc.m_test_suite); - char n1[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(n1, DOCTEST_COUNTOF(n1), "TEST CASE: "); - char n2[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(n2, DOCTEST_COUNTOF(n2), "%s\n", tc.m_name); - char d1[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(d1, DOCTEST_COUNTOF(d1), "DESCRIPTION: "); - char d2[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(d2, DOCTEST_COUNTOF(d2), "%s\n", tc.m_description); - - // hack for BDD style of macros - to not print "TEST CASE:" - char scenario[] = " Scenario:"; - if(std::string(tc.m_name).substr(0, DOCTEST_COUNTOF(scenario) - 1) == scenario) - n1[0] = '\0'; - - DOCTEST_PRINTF_COLORED(getSeparator(), Color::Yellow); - DOCTEST_PRINTF_COLORED(loc, Color::LightGrey); - - String forDebugConsole; - if(tc.m_description) { - DOCTEST_PRINTF_COLORED(d1, Color::Yellow); - DOCTEST_PRINTF_COLORED(d2, Color::None); - forDebugConsole += d1; - forDebugConsole += d2; - } - if(tc.m_test_suite && tc.m_test_suite[0] != '\0') { - DOCTEST_PRINTF_COLORED(ts1, Color::Yellow); - DOCTEST_PRINTF_COLORED(ts2, Color::None); - forDebugConsole += ts1; - forDebugConsole += ts2; - } - DOCTEST_PRINTF_COLORED(n1, Color::Yellow); - DOCTEST_PRINTF_COLORED(n2, Color::None); - - String subcaseStuff; - std::vector& subcasesStack = contextState->subcasesStack; - for(unsigned i = 0; i < subcasesStack.size(); ++i) { - if(subcasesStack[i].m_signature.m_name[0] != '\0') { - char subcase[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(subcase, DOCTEST_COUNTOF(loc), " %s\n", - subcasesStack[i].m_signature.m_name); - DOCTEST_PRINTF_COLORED(subcase, Color::None); - subcaseStuff += subcase; - } +void logTestStart(const TestCase& tc) { + char loc[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + DOCTEST_SNPRINTF( + loc, DOCTEST_COUNTOF(loc), "%s(%d)\n", fileForOutput(tc.m_file), + lineForOutput(tc.m_line)); + + char ts1[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + DOCTEST_SNPRINTF(ts1, DOCTEST_COUNTOF(ts1), "TEST SUITE: "); + char ts2[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + DOCTEST_SNPRINTF(ts2, DOCTEST_COUNTOF(ts2), "%s\n", tc.m_test_suite); + char n1[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + DOCTEST_SNPRINTF(n1, DOCTEST_COUNTOF(n1), "TEST CASE: "); + char n2[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + DOCTEST_SNPRINTF(n2, DOCTEST_COUNTOF(n2), "%s\n", tc.m_name); + char d1[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + DOCTEST_SNPRINTF(d1, DOCTEST_COUNTOF(d1), "DESCRIPTION: "); + char d2[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + DOCTEST_SNPRINTF(d2, DOCTEST_COUNTOF(d2), "%s\n", tc.m_description); + + // hack for BDD style of macros - to not print "TEST CASE:" + char scenario[] = " Scenario:"; + if (std::string(tc.m_name).substr(0, DOCTEST_COUNTOF(scenario) - 1) + == scenario) + n1[0] = '\0'; + + DOCTEST_PRINTF_COLORED(getSeparator(), Color::Yellow); + DOCTEST_PRINTF_COLORED(loc, Color::LightGrey); + + String forDebugConsole; + if (tc.m_description) { + DOCTEST_PRINTF_COLORED(d1, Color::Yellow); + DOCTEST_PRINTF_COLORED(d2, Color::None); + forDebugConsole += d1; + forDebugConsole += d2; + } + if (tc.m_test_suite && tc.m_test_suite[0] != '\0') { + DOCTEST_PRINTF_COLORED(ts1, Color::Yellow); + DOCTEST_PRINTF_COLORED(ts2, Color::None); + forDebugConsole += ts1; + forDebugConsole += ts2; + } + DOCTEST_PRINTF_COLORED(n1, Color::Yellow); + DOCTEST_PRINTF_COLORED(n2, Color::None); + + String subcaseStuff; + std::vector& subcasesStack = contextState->subcasesStack; + for (unsigned i = 0; i < subcasesStack.size(); ++i) { + if (subcasesStack[i].m_signature.m_name[0] != '\0') { + char subcase[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + DOCTEST_SNPRINTF( + subcase, DOCTEST_COUNTOF(loc), " %s\n", + subcasesStack[i].m_signature.m_name); + DOCTEST_PRINTF_COLORED(subcase, Color::None); + subcaseStuff += subcase; } - - DOCTEST_PRINTF_COLORED("\n", Color::None); - - printToDebugConsole(String(getSeparator()) + loc + forDebugConsole.c_str() + n1 + n2 + - subcaseStuff.c_str() + "\n"); } - void logTestEnd() {} + DOCTEST_PRINTF_COLORED("\n", Color::None); - void logTestException(const String& what, bool crash) { - char msg[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + printToDebugConsole( + String(getSeparator()) + loc + forDebugConsole.c_str() + n1 + n2 + + subcaseStuff.c_str() + "\n"); +} - DOCTEST_SNPRINTF(msg, DOCTEST_COUNTOF(msg), "TEST CASE FAILED!\n"); +void logTestEnd() {} - char info1[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - char info2[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - info1[0] = 0; - info2[0] = 0; - DOCTEST_SNPRINTF(info1, DOCTEST_COUNTOF(info1), - crash ? "crashed:\n" : "threw exception:\n"); - DOCTEST_SNPRINTF(info2, DOCTEST_COUNTOF(info2), " %s\n", what.c_str()); +void logTestException(const String& what, bool crash) { + char msg[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - std::string contextStr; + DOCTEST_SNPRINTF(msg, DOCTEST_COUNTOF(msg), "TEST CASE FAILED!\n"); - if(!contextState->exceptionalContexts.empty()) { - contextStr += "with context:\n"; - for(size_t i = contextState->exceptionalContexts.size(); i > 0; --i) { - contextStr += " "; - contextStr += contextState->exceptionalContexts[i - 1]; - contextStr += "\n"; - } - } + char info1[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + char info2[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + info1[0] = 0; + info2[0] = 0; + DOCTEST_SNPRINTF( + info1, DOCTEST_COUNTOF(info1), + crash ? "crashed:\n" : "threw exception:\n"); + DOCTEST_SNPRINTF(info2, DOCTEST_COUNTOF(info2), " %s\n", what.c_str()); - DOCTEST_PRINTF_COLORED(msg, Color::Red); - DOCTEST_PRINTF_COLORED(info1, Color::None); - DOCTEST_PRINTF_COLORED(info2, Color::Cyan); - DOCTEST_PRINTF_COLORED(contextStr.c_str(), Color::None); - DOCTEST_PRINTF_COLORED("\n", Color::None); + std::string contextStr; - printToDebugConsole(String(msg) + info1 + info2 + contextStr.c_str() + "\n"); - } - - String logContext() { - std::ostringstream stream; - std::vector& contexts = contextState->contexts; - if(!contexts.empty()) - stream << "with context:\n"; - for(size_t i = 0; i < contexts.size(); ++i) { - stream << " "; - contexts[i]->build(&stream); - stream << "\n"; + if (!contextState->exceptionalContexts.empty()) { + contextStr += "with context:\n"; + for (size_t i = contextState->exceptionalContexts.size(); i > 0; --i) { + contextStr += " "; + contextStr += contextState->exceptionalContexts[i - 1]; + contextStr += "\n"; } - return stream.str().c_str(); - } - - const char* getFailString(assertType::Enum assert_type) { - if(assert_type & assertType::is_warn) //!OCLINT bitwise operator in conditional - return "WARNING"; - if(assert_type & assertType::is_check) //!OCLINT bitwise operator in conditional - return "ERROR"; - if(assert_type & assertType::is_require) //!OCLINT bitwise operator in conditional - return "FATAL ERROR"; - return ""; } - void logAssert(bool passed, const char* decomposition, bool threw, const String& exception, - const char* expr, assertType::Enum assert_type, const char* file, int line) { - char loc[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(loc, DOCTEST_COUNTOF(loc), "%s(%d)", fileForOutput(file), - lineForOutput(line)); - - char msg[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(msg, DOCTEST_COUNTOF(msg), " %s!\n", - passed ? "PASSED" : getFailString(assert_type)); - - char info1[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(info1, DOCTEST_COUNTOF(info1), " %s( %s )\n", - getAssertString(assert_type), expr); - - char info2[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - char info3[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - info2[0] = 0; - info3[0] = 0; - if(threw) { - DOCTEST_SNPRINTF(info2, DOCTEST_COUNTOF(info2), "threw exception:\n"); - DOCTEST_SNPRINTF(info3, DOCTEST_COUNTOF(info3), " %s\n", exception.c_str()); - } else { - DOCTEST_SNPRINTF(info2, DOCTEST_COUNTOF(info2), "with expansion:\n"); - DOCTEST_SNPRINTF(info3, DOCTEST_COUNTOF(info3), " %s( %s )\n", - getAssertString(assert_type), decomposition); - } + DOCTEST_PRINTF_COLORED(msg, Color::Red); + DOCTEST_PRINTF_COLORED(info1, Color::None); + DOCTEST_PRINTF_COLORED(info2, Color::Cyan); + DOCTEST_PRINTF_COLORED(contextStr.c_str(), Color::None); + DOCTEST_PRINTF_COLORED("\n", Color::None); - const bool isWarn = assert_type & assertType::is_warn; - DOCTEST_PRINTF_COLORED(loc, Color::LightGrey); - DOCTEST_PRINTF_COLORED(msg, - passed ? Color::BrightGreen : isWarn ? Color::Yellow : Color::Red); - DOCTEST_PRINTF_COLORED(info1, Color::Cyan); - DOCTEST_PRINTF_COLORED(info2, Color::None); - DOCTEST_PRINTF_COLORED(info3, Color::Cyan); - String context = logContext(); - DOCTEST_PRINTF_COLORED(context.c_str(), Color::None); - DOCTEST_PRINTF_COLORED("\n", Color::None); + printToDebugConsole( + String(msg) + info1 + info2 + contextStr.c_str() + "\n"); +} - printToDebugConsole(String(loc) + msg + info1 + info2 + info3 + context.c_str() + "\n"); +String logContext() { + std::ostringstream stream; + std::vector& contexts = contextState->contexts; + if (!contexts.empty()) stream << "with context:\n"; + for (size_t i = 0; i < contexts.size(); ++i) { + stream << " "; + contexts[i]->build(&stream); + stream << "\n"; } + return stream.str().c_str(); +} - void logAssertThrows(bool threw, const char* expr, assertType::Enum assert_type, - const char* file, int line) { - char loc[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(loc, DOCTEST_COUNTOF(loc), "%s(%d)", fileForOutput(file), - lineForOutput(line)); - - char msg[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(msg, DOCTEST_COUNTOF(msg), " %s!\n", - threw ? "PASSED" : getFailString(assert_type)); - - char info1[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(info1, DOCTEST_COUNTOF(info1), " %s( %s )\n", - getAssertString(assert_type), expr); - - char info2[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - info2[0] = 0; - - if(!threw) - DOCTEST_SNPRINTF(info2, DOCTEST_COUNTOF(info2), "didn't throw at all\n"); - - const bool isWarn = assert_type & assertType::is_warn; - DOCTEST_PRINTF_COLORED(loc, Color::LightGrey); - DOCTEST_PRINTF_COLORED(msg, - threw ? Color::BrightGreen : isWarn ? Color::Yellow : Color::Red); - DOCTEST_PRINTF_COLORED(info1, Color::Cyan); - DOCTEST_PRINTF_COLORED(info2, Color::None); - String context = logContext(); - DOCTEST_PRINTF_COLORED(context.c_str(), Color::None); - DOCTEST_PRINTF_COLORED("\n", Color::None); +const char* getFailString(assertType::Enum assert_type) { + if (assert_type + & assertType::is_warn) //! OCLINT bitwise operator in conditional + return "WARNING"; + if (assert_type + & assertType::is_check) //! OCLINT bitwise operator in conditional + return "ERROR"; + if (assert_type + & assertType::is_require) //! OCLINT bitwise operator in conditional + return "FATAL ERROR"; + return ""; +} - printToDebugConsole(String(loc) + msg + info1 + info2 + context.c_str() + "\n"); +void logAssert( + bool passed, const char* decomposition, bool threw, const String& exception, + const char* expr, assertType::Enum assert_type, const char* file, + int line) { + char loc[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + DOCTEST_SNPRINTF( + loc, DOCTEST_COUNTOF(loc), "%s(%d)", fileForOutput(file), + lineForOutput(line)); + + char msg[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + DOCTEST_SNPRINTF( + msg, DOCTEST_COUNTOF(msg), " %s!\n", + passed ? "PASSED" : getFailString(assert_type)); + + char info1[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + DOCTEST_SNPRINTF( + info1, DOCTEST_COUNTOF(info1), " %s( %s )\n", + getAssertString(assert_type), expr); + + char info2[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + char info3[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + info2[0] = 0; + info3[0] = 0; + if (threw) { + DOCTEST_SNPRINTF(info2, DOCTEST_COUNTOF(info2), "threw exception:\n"); + DOCTEST_SNPRINTF( + info3, DOCTEST_COUNTOF(info3), " %s\n", exception.c_str()); + } else { + DOCTEST_SNPRINTF(info2, DOCTEST_COUNTOF(info2), "with expansion:\n"); + DOCTEST_SNPRINTF( + info3, DOCTEST_COUNTOF(info3), " %s( %s )\n", + getAssertString(assert_type), decomposition); } - void logAssertThrowsAs(bool threw, bool threw_as, const char* as, const String& exception, - const char* expr, assertType::Enum assert_type, const char* file, - int line) { - char loc[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(loc, DOCTEST_COUNTOF(loc), "%s(%d)", fileForOutput(file), - lineForOutput(line)); - - char msg[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(msg, DOCTEST_COUNTOF(msg), " %s!\n", - threw_as ? "PASSED" : getFailString(assert_type)); - - char info1[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(info1, DOCTEST_COUNTOF(info1), " %s( %s, %s )\n", - getAssertString(assert_type), expr, as); - - char info2[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - char info3[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - info2[0] = 0; - info3[0] = 0; - - if(!threw) { //!OCLINT inverted logic - DOCTEST_SNPRINTF(info2, DOCTEST_COUNTOF(info2), "didn't throw at all\n"); - } else if(!threw_as) { - DOCTEST_SNPRINTF(info2, DOCTEST_COUNTOF(info2), "threw a different exception:\n"); - DOCTEST_SNPRINTF(info3, DOCTEST_COUNTOF(info3), " %s\n", exception.c_str()); - } + const bool isWarn = assert_type & assertType::is_warn; + DOCTEST_PRINTF_COLORED(loc, Color::LightGrey); + DOCTEST_PRINTF_COLORED( + msg, passed ? Color::BrightGreen + : isWarn ? Color::Yellow + : Color::Red); + DOCTEST_PRINTF_COLORED(info1, Color::Cyan); + DOCTEST_PRINTF_COLORED(info2, Color::None); + DOCTEST_PRINTF_COLORED(info3, Color::Cyan); + String context = logContext(); + DOCTEST_PRINTF_COLORED(context.c_str(), Color::None); + DOCTEST_PRINTF_COLORED("\n", Color::None); + + printToDebugConsole( + String(loc) + msg + info1 + info2 + info3 + context.c_str() + "\n"); +} - const bool isWarn = assert_type & assertType::is_warn; - DOCTEST_PRINTF_COLORED(loc, Color::LightGrey); - DOCTEST_PRINTF_COLORED(msg, - threw_as ? Color::BrightGreen : isWarn ? Color::Yellow : Color::Red); - DOCTEST_PRINTF_COLORED(info1, Color::Cyan); - DOCTEST_PRINTF_COLORED(info2, Color::None); - DOCTEST_PRINTF_COLORED(info3, Color::Cyan); - String context = logContext(); - DOCTEST_PRINTF_COLORED(context.c_str(), Color::None); - DOCTEST_PRINTF_COLORED("\n", Color::None); +void logAssertThrows( + bool threw, const char* expr, assertType::Enum assert_type, + const char* file, int line) { + char loc[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + DOCTEST_SNPRINTF( + loc, DOCTEST_COUNTOF(loc), "%s(%d)", fileForOutput(file), + lineForOutput(line)); + + char msg[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + DOCTEST_SNPRINTF( + msg, DOCTEST_COUNTOF(msg), " %s!\n", + threw ? "PASSED" : getFailString(assert_type)); + + char info1[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + DOCTEST_SNPRINTF( + info1, DOCTEST_COUNTOF(info1), " %s( %s )\n", + getAssertString(assert_type), expr); + + char info2[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + info2[0] = 0; + + if (!threw) + DOCTEST_SNPRINTF( + info2, DOCTEST_COUNTOF(info2), "didn't throw at all\n"); + + const bool isWarn = assert_type & assertType::is_warn; + DOCTEST_PRINTF_COLORED(loc, Color::LightGrey); + DOCTEST_PRINTF_COLORED( + msg, threw ? Color::BrightGreen + : isWarn ? Color::Yellow + : Color::Red); + DOCTEST_PRINTF_COLORED(info1, Color::Cyan); + DOCTEST_PRINTF_COLORED(info2, Color::None); + String context = logContext(); + DOCTEST_PRINTF_COLORED(context.c_str(), Color::None); + DOCTEST_PRINTF_COLORED("\n", Color::None); + + printToDebugConsole( + String(loc) + msg + info1 + info2 + context.c_str() + "\n"); +} - printToDebugConsole(String(loc) + msg + info1 + info2 + info3 + context.c_str() + "\n"); +void logAssertThrowsAs( + bool threw, bool threw_as, const char* as, const String& exception, + const char* expr, assertType::Enum assert_type, const char* file, + int line) { + char loc[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + DOCTEST_SNPRINTF( + loc, DOCTEST_COUNTOF(loc), "%s(%d)", fileForOutput(file), + lineForOutput(line)); + + char msg[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + DOCTEST_SNPRINTF( + msg, DOCTEST_COUNTOF(msg), " %s!\n", + threw_as ? "PASSED" : getFailString(assert_type)); + + char info1[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + DOCTEST_SNPRINTF( + info1, DOCTEST_COUNTOF(info1), " %s( %s, %s )\n", + getAssertString(assert_type), expr, as); + + char info2[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + char info3[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + info2[0] = 0; + info3[0] = 0; + + if (!threw) { //! OCLINT inverted logic + DOCTEST_SNPRINTF( + info2, DOCTEST_COUNTOF(info2), "didn't throw at all\n"); + } else if (!threw_as) { + DOCTEST_SNPRINTF( + info2, DOCTEST_COUNTOF(info2), "threw a different exception:\n"); + DOCTEST_SNPRINTF( + info3, DOCTEST_COUNTOF(info3), " %s\n", exception.c_str()); } - void logAssertNothrow(bool threw, const String& exception, const char* expr, - assertType::Enum assert_type, const char* file, int line) { - char loc[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(loc, DOCTEST_COUNTOF(loc), "%s(%d)", fileForOutput(file), - lineForOutput(line)); - - char msg[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(msg, DOCTEST_COUNTOF(msg), " %s!\n", - threw ? getFailString(assert_type) : "PASSED"); - - char info1[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(info1, DOCTEST_COUNTOF(info1), " %s( %s )\n", - getAssertString(assert_type), expr); - - char info2[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - char info3[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - info2[0] = 0; - info3[0] = 0; - if(threw) { - DOCTEST_SNPRINTF(info2, DOCTEST_COUNTOF(info2), "threw exception:\n"); - DOCTEST_SNPRINTF(info3, DOCTEST_COUNTOF(info3), " %s\n", exception.c_str()); - } - - const bool isWarn = assert_type & assertType::is_warn; - DOCTEST_PRINTF_COLORED(loc, Color::LightGrey); - DOCTEST_PRINTF_COLORED(msg, - threw ? isWarn ? Color::Yellow : Color::Red : Color::BrightGreen); - DOCTEST_PRINTF_COLORED(info1, Color::Cyan); - DOCTEST_PRINTF_COLORED(info2, Color::None); - DOCTEST_PRINTF_COLORED(info3, Color::Cyan); - String context = logContext(); - DOCTEST_PRINTF_COLORED(context.c_str(), Color::None); - DOCTEST_PRINTF_COLORED("\n", Color::None); + const bool isWarn = assert_type & assertType::is_warn; + DOCTEST_PRINTF_COLORED(loc, Color::LightGrey); + DOCTEST_PRINTF_COLORED( + msg, threw_as ? Color::BrightGreen + : isWarn ? Color::Yellow + : Color::Red); + DOCTEST_PRINTF_COLORED(info1, Color::Cyan); + DOCTEST_PRINTF_COLORED(info2, Color::None); + DOCTEST_PRINTF_COLORED(info3, Color::Cyan); + String context = logContext(); + DOCTEST_PRINTF_COLORED(context.c_str(), Color::None); + DOCTEST_PRINTF_COLORED("\n", Color::None); + + printToDebugConsole( + String(loc) + msg + info1 + info2 + info3 + context.c_str() + "\n"); +} - printToDebugConsole(String(loc) + msg + info1 + info2 + info3 + context.c_str() + "\n"); +void logAssertNothrow( + bool threw, const String& exception, const char* expr, + assertType::Enum assert_type, const char* file, int line) { + char loc[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + DOCTEST_SNPRINTF( + loc, DOCTEST_COUNTOF(loc), "%s(%d)", fileForOutput(file), + lineForOutput(line)); + + char msg[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + DOCTEST_SNPRINTF( + msg, DOCTEST_COUNTOF(msg), " %s!\n", + threw ? getFailString(assert_type) : "PASSED"); + + char info1[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + DOCTEST_SNPRINTF( + info1, DOCTEST_COUNTOF(info1), " %s( %s )\n", + getAssertString(assert_type), expr); + + char info2[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + char info3[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + info2[0] = 0; + info3[0] = 0; + if (threw) { + DOCTEST_SNPRINTF(info2, DOCTEST_COUNTOF(info2), "threw exception:\n"); + DOCTEST_SNPRINTF( + info3, DOCTEST_COUNTOF(info3), " %s\n", exception.c_str()); } - ResultBuilder::ResultBuilder(assertType::Enum assert_type, const char* file, int line, - const char* expr, const char* exception_type) - : m_assert_type(assert_type) - , m_file(file) - , m_line(line) - , m_expr(expr) - , m_exception_type(exception_type) - , m_threw(false) - , m_threw_as(false) - , m_failed(false) { + const bool isWarn = assert_type & assertType::is_warn; + DOCTEST_PRINTF_COLORED(loc, Color::LightGrey); + DOCTEST_PRINTF_COLORED( + msg, threw ? isWarn ? Color::Yellow : Color::Red : Color::BrightGreen); + DOCTEST_PRINTF_COLORED(info1, Color::Cyan); + DOCTEST_PRINTF_COLORED(info2, Color::None); + DOCTEST_PRINTF_COLORED(info3, Color::Cyan); + String context = logContext(); + DOCTEST_PRINTF_COLORED(context.c_str(), Color::None); + DOCTEST_PRINTF_COLORED("\n", Color::None); + + printToDebugConsole( + String(loc) + msg + info1 + info2 + info3 + context.c_str() + "\n"); +} + +ResultBuilder::ResultBuilder( + assertType::Enum assert_type, const char* file, int line, const char* expr, + const char* exception_type) + : m_assert_type(assert_type), + m_file(file), + m_line(line), + m_expr(expr), + m_exception_type(exception_type), + m_threw(false), + m_threw_as(false), + m_failed(false) { #if DOCTEST_MSVC - if(m_expr[0] == ' ') // this happens when variadic macros are disabled under MSVC - ++m_expr; -#endif // MSVC - } + if (m_expr[0] + == ' ') // this happens when variadic macros are disabled under MSVC + ++m_expr; +#endif // MSVC +} - ResultBuilder::~ResultBuilder() {} +ResultBuilder::~ResultBuilder() {} - void ResultBuilder::unexpectedExceptionOccurred() { - m_threw = true; +void ResultBuilder::unexpectedExceptionOccurred() { + m_threw = true; - m_exception = translateActiveException(); + m_exception = translateActiveException(); +} + +bool ResultBuilder::log() { + if ((m_assert_type & assertType::is_warn) + == 0) //! OCLINT bitwise operator in conditional + contextState->numAssertionsForCurrentTestcase++; + + if (m_assert_type + & assertType::is_throws) { //! OCLINT bitwise operator in conditional + m_failed = !m_threw; + } else if ( + m_assert_type & //! OCLINT bitwise operator in conditional + assertType::is_throws_as) { + m_failed = !m_threw_as; + } else if ( + m_assert_type & //! OCLINT bitwise operator in conditional + assertType::is_nothrow) { + m_failed = m_threw; + } else { + m_failed = m_result; } - bool ResultBuilder::log() { - if((m_assert_type & assertType::is_warn) == 0) //!OCLINT bitwise operator in conditional - contextState->numAssertionsForCurrentTestcase++; - - if(m_assert_type & assertType::is_throws) { //!OCLINT bitwise operator in conditional - m_failed = !m_threw; - } else if(m_assert_type & //!OCLINT bitwise operator in conditional - assertType::is_throws_as) { - m_failed = !m_threw_as; - } else if(m_assert_type & //!OCLINT bitwise operator in conditional - assertType::is_nothrow) { - m_failed = m_threw; - } else { - m_failed = m_result; - } + if (m_failed || contextState->success) { + DOCTEST_LOG_START(); - if(m_failed || contextState->success) { - DOCTEST_LOG_START(); - - if(m_assert_type & assertType::is_throws) { //!OCLINT bitwise operator in conditional - logAssertThrows(m_threw, m_expr, m_assert_type, m_file, m_line); - } else if(m_assert_type & //!OCLINT bitwise operator in conditional - assertType::is_throws_as) { - logAssertThrowsAs(m_threw, m_threw_as, m_exception_type, m_exception, m_expr, - m_assert_type, m_file, m_line); - } else if(m_assert_type & //!OCLINT bitwise operator in conditional - assertType::is_nothrow) { - logAssertNothrow(m_threw, m_exception, m_expr, m_assert_type, m_file, m_line); - } else { - logAssert(m_result.m_passed, m_result.m_decomposition.c_str(), m_threw, m_exception, - m_expr, m_assert_type, m_file, m_line); - } + if (m_assert_type + & assertType::is_throws) { //! OCLINT bitwise operator in + //! conditional + logAssertThrows(m_threw, m_expr, m_assert_type, m_file, m_line); + } else if ( + m_assert_type & //! OCLINT bitwise operator in conditional + assertType::is_throws_as) { + logAssertThrowsAs( + m_threw, m_threw_as, m_exception_type, m_exception, m_expr, + m_assert_type, m_file, m_line); + } else if ( + m_assert_type & //! OCLINT bitwise operator in conditional + assertType::is_nothrow) { + logAssertNothrow( + m_threw, m_exception, m_expr, m_assert_type, m_file, m_line); + } else { + logAssert( + m_result.m_passed, m_result.m_decomposition.c_str(), m_threw, + m_exception, m_expr, m_assert_type, m_file, m_line); } + } - if(m_failed) - addFailedAssert(m_assert_type); + if (m_failed) addFailedAssert(m_assert_type); - return m_failed && isDebuggerActive() && !contextState->no_breaks; // break into debugger - } + return m_failed && isDebuggerActive() + && !contextState->no_breaks; // break into debugger +} - void ResultBuilder::react() const { - if(m_failed && checkIfShouldThrow(m_assert_type)) - throwException(); - } +void ResultBuilder::react() const { + if (m_failed && checkIfShouldThrow(m_assert_type)) throwException(); +} - MessageBuilder::MessageBuilder(const char* file, int line, assertType::Enum severity) - : m_stream(createStream()) - , m_file(file) - , m_line(line) - , m_severity(severity) {} +MessageBuilder::MessageBuilder( + const char* file, int line, assertType::Enum severity) + : m_stream(createStream()), + m_file(file), + m_line(line), + m_severity(severity) {} - bool MessageBuilder::log() { - DOCTEST_LOG_START(); +bool MessageBuilder::log() { + DOCTEST_LOG_START(); - const bool isWarn = m_severity & assertType::is_warn; + const bool isWarn = m_severity & assertType::is_warn; - // warn is just a message in this context so we dont treat it as an assert - if(!isWarn) { - contextState->numAssertionsForCurrentTestcase++; - addFailedAssert(m_severity); - } + // warn is just a message in this context so we dont treat it as an assert + if (!isWarn) { + contextState->numAssertionsForCurrentTestcase++; + addFailedAssert(m_severity); + } - char loc[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(loc, DOCTEST_COUNTOF(loc), "%s(%d)", fileForOutput(m_file), - lineForOutput(m_line)); - char msg[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(msg, DOCTEST_COUNTOF(msg), " %s!\n", - isWarn ? "MESSAGE" : getFailString(m_severity)); - - DOCTEST_PRINTF_COLORED(loc, Color::LightGrey); - DOCTEST_PRINTF_COLORED(msg, isWarn ? Color::Yellow : Color::Red); - - String info = getStreamResult(m_stream); - if(info.size()) { - DOCTEST_PRINTF_COLORED(" ", Color::None); - DOCTEST_PRINTF_COLORED(info.c_str(), Color::None); - DOCTEST_PRINTF_COLORED("\n", Color::None); - } - String context = logContext(); - DOCTEST_PRINTF_COLORED(context.c_str(), Color::None); + char loc[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + DOCTEST_SNPRINTF( + loc, DOCTEST_COUNTOF(loc), "%s(%d)", fileForOutput(m_file), + lineForOutput(m_line)); + char msg[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + DOCTEST_SNPRINTF( + msg, DOCTEST_COUNTOF(msg), " %s!\n", + isWarn ? "MESSAGE" : getFailString(m_severity)); + + DOCTEST_PRINTF_COLORED(loc, Color::LightGrey); + DOCTEST_PRINTF_COLORED(msg, isWarn ? Color::Yellow : Color::Red); + + String info = getStreamResult(m_stream); + if (info.size()) { + DOCTEST_PRINTF_COLORED(" ", Color::None); + DOCTEST_PRINTF_COLORED(info.c_str(), Color::None); DOCTEST_PRINTF_COLORED("\n", Color::None); + } + String context = logContext(); + DOCTEST_PRINTF_COLORED(context.c_str(), Color::None); + DOCTEST_PRINTF_COLORED("\n", Color::None); - printToDebugConsole(String(loc) + msg + " " + info.c_str() + "\n" + context.c_str() + - "\n"); + printToDebugConsole( + String(loc) + msg + " " + info.c_str() + "\n" + context.c_str() + + "\n"); - return isDebuggerActive() && !contextState->no_breaks && !isWarn; // break into debugger - } + return isDebuggerActive() && !contextState->no_breaks + && !isWarn; // break into debugger +} - void MessageBuilder::react() { - if(m_severity & assertType::is_require) //!OCLINT bitwise operator in conditional - throwException(); - } +void MessageBuilder::react() { + if (m_severity + & assertType::is_require) //! OCLINT bitwise operator in conditional + throwException(); +} - MessageBuilder::~MessageBuilder() { freeStream(m_stream); } - - // the implementation of parseFlag() - bool parseFlagImpl(int argc, const char* const* argv, const char* pattern) { - for(int i = argc - 1; i >= 0; --i) { - const char* temp = std::strstr(argv[i], pattern); - if(temp && my_strlen(temp) == my_strlen(pattern)) { - // eliminate strings in which the chars before the option are not '-' - bool noBadCharsFound = true; //!OCLINT prefer early exits and continue - while(temp != argv[i]) { - if(*--temp != '-') { - noBadCharsFound = false; - break; - } +MessageBuilder::~MessageBuilder() { freeStream(m_stream); } + +// the implementation of parseFlag() +bool parseFlagImpl(int argc, const char* const* argv, const char* pattern) { + for (int i = argc - 1; i >= 0; --i) { + const char* temp = std::strstr(argv[i], pattern); + if (temp && my_strlen(temp) == my_strlen(pattern)) { + // eliminate strings in which the chars before the option are not + // '-' + bool noBadCharsFound = + true; //! OCLINT prefer early exits and continue + while (temp != argv[i]) { + if (*--temp != '-') { + noBadCharsFound = false; + break; } - if(noBadCharsFound && argv[i][0] == '-') - return true; } + if (noBadCharsFound && argv[i][0] == '-') return true; } - return false; } + return false; +} - // locates a flag on the command line - bool parseFlag(int argc, const char* const* argv, const char* pattern) { +// locates a flag on the command line +bool parseFlag(int argc, const char* const* argv, const char* pattern) { #ifndef DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS - if(!parseFlagImpl(argc, argv, pattern)) - return parseFlagImpl(argc, argv, pattern + 3); // 3 for "dt-" - return true; -#else // DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS - return parseFlagImpl(argc, argv, pattern); -#endif // DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS - } + if (!parseFlagImpl(argc, argv, pattern)) + return parseFlagImpl(argc, argv, pattern + 3); // 3 for "dt-" + return true; +#else // DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS + return parseFlagImpl(argc, argv, pattern); +#endif // DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS +} - // the implementation of parseOption() - bool parseOptionImpl(int argc, const char* const* argv, const char* pattern, String& res) { - for(int i = argc - 1; i >= 0; --i) { - const char* temp = std::strstr(argv[i], pattern); - if(temp) { //!OCLINT prefer early exits and continue - // eliminate matches in which the chars before the option are not '-' - bool noBadCharsFound = true; - const char* curr = argv[i]; - while(curr != temp) { - if(*curr++ != '-') { - noBadCharsFound = false; - break; - } +// the implementation of parseOption() +bool parseOptionImpl( + int argc, const char* const* argv, const char* pattern, String& res) { + for (int i = argc - 1; i >= 0; --i) { + const char* temp = std::strstr(argv[i], pattern); + if (temp) { //! OCLINT prefer early exits and continue + // eliminate matches in which the chars before the option are not + // '-' + bool noBadCharsFound = true; + const char* curr = argv[i]; + while (curr != temp) { + if (*curr++ != '-') { + noBadCharsFound = false; + break; } - if(noBadCharsFound && argv[i][0] == '-') { - temp += my_strlen(pattern); - const unsigned len = my_strlen(temp); - if(len) { - res = temp; - return true; - } + } + if (noBadCharsFound && argv[i][0] == '-') { + temp += my_strlen(pattern); + const unsigned len = my_strlen(temp); + if (len) { + res = temp; + return true; } } } - return false; } + return false; +} - // parses an option and returns the string after the '=' character - bool parseOption(int argc, const char* const* argv, const char* pattern, String& res, - const String& defaultVal = String()) { - res = defaultVal; +// parses an option and returns the string after the '=' character +bool parseOption( + int argc, const char* const* argv, const char* pattern, String& res, + const String& defaultVal = String()) { + res = defaultVal; #ifndef DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS - if(!parseOptionImpl(argc, argv, pattern, res)) - return parseOptionImpl(argc, argv, pattern + 3, res); // 3 for "dt-" - return true; -#else // DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS - return parseOptionImpl(argc, argv, pattern, res); -#endif // DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS - } + if (!parseOptionImpl(argc, argv, pattern, res)) + return parseOptionImpl(argc, argv, pattern + 3, res); // 3 for "dt-" + return true; +#else // DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS + return parseOptionImpl(argc, argv, pattern, res); +#endif // DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS +} - // parses a comma separated list of words after a pattern in one of the arguments in argv - bool parseCommaSepArgs(int argc, const char* const* argv, const char* pattern, - std::vector& res) { - String filtersString; - if(parseOption(argc, argv, pattern, filtersString)) { - // tokenize with "," as a separator +// parses a comma separated list of words after a pattern in one of the +// arguments in argv +bool parseCommaSepArgs( + int argc, const char* const* argv, const char* pattern, + std::vector& res) { + String filtersString; + if (parseOption(argc, argv, pattern, filtersString)) { + // tokenize with "," as a separator + // cppcheck-suppress strtokCalled + char* pch = + std::strtok(filtersString.c_str(), ","); // modifies the string + while (pch != 0) { + if (my_strlen(pch)) res.push_back(pch); + // uses the strtok() internal state to go to the next token // cppcheck-suppress strtokCalled - char* pch = std::strtok(filtersString.c_str(), ","); // modifies the string - while(pch != 0) { - if(my_strlen(pch)) - res.push_back(pch); - // uses the strtok() internal state to go to the next token - // cppcheck-suppress strtokCalled - pch = std::strtok(0, ","); - } - return true; + pch = std::strtok(0, ","); } - return false; + return true; } + return false; +} - enum optionType - { - option_bool, - option_int - }; - - // parses an int/bool option from the command line - bool parseIntOption(int argc, const char* const* argv, const char* pattern, optionType type, - int& res) { - String parsedValue; - if(!parseOption(argc, argv, pattern, parsedValue)) - return false; - - if(type == 0) { - // boolean - const char positive[][5] = {"1", "true", "on", "yes"}; // 5 - strlen("true") + 1 - const char negative[][6] = {"0", "false", "off", "no"}; // 6 - strlen("false") + 1 - - // if the value matches any of the positive/negative possibilities - for(unsigned i = 0; i < 4; i++) { - if(parsedValue.compare(positive[i], true) == 0) { - res = 1; //!OCLINT parameter reassignment - return true; - } - if(parsedValue.compare(negative[i], true) == 0) { - res = 0; //!OCLINT parameter reassignment - return true; - } +enum optionType { option_bool, option_int }; + +// parses an int/bool option from the command line +bool parseIntOption( + int argc, const char* const* argv, const char* pattern, optionType type, + int& res) { + String parsedValue; + if (!parseOption(argc, argv, pattern, parsedValue)) return false; + + if (type == 0) { + // boolean + const char positive[][5] = { + "1", "true", "on", "yes"}; // 5 - strlen("true") + 1 + const char negative[][6] = { + "0", "false", "off", "no"}; // 6 - strlen("false") + 1 + + // if the value matches any of the positive/negative possibilities + for (unsigned i = 0; i < 4; i++) { + if (parsedValue.compare(positive[i], true) == 0) { + res = 1; //! OCLINT parameter reassignment + return true; } - } else { - // integer - int theInt = std::atoi(parsedValue.c_str()); // NOLINT - if(theInt != 0) { - res = theInt; //!OCLINT parameter reassignment + if (parsedValue.compare(negative[i], true) == 0) { + res = 0; //! OCLINT parameter reassignment return true; } } - return false; + } else { + // integer + int theInt = std::atoi(parsedValue.c_str()); // NOLINT + if (theInt != 0) { + res = theInt; //! OCLINT parameter reassignment + return true; + } } + return false; +} - void printVersion() { - if(contextState->no_version == false) { - DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan); - std::printf("doctest version is \"%s\"\n", DOCTEST_VERSION_STR); - } +void printVersion() { + if (contextState->no_version == false) { + DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan); + std::printf("doctest version is \"%s\"\n", DOCTEST_VERSION_STR); } +} - void printHelp() { - printVersion(); - // clang-format off +void printHelp() { + printVersion(); + // clang-format off DOCTEST_PRINTF_COLORED("[doctest]\n", Color::Cyan); DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan); std::printf("boolean values: \"1/on/yes/true\" or \"0/off/no/false\"\n"); @@ -5204,98 +5397,119 @@ namespace detail std::printf(" -npf, --no-path-filenames= only filenames and no paths in output\n"); std::printf(" -nln, --no-line-numbers= 0 instead of real line numbers in output\n"); // ========================================================================================= << 79 - // clang-format on + // clang-format on - DOCTEST_PRINTF_COLORED("\n[doctest] ", Color::Cyan); - std::printf("for more information visit the project documentation\n\n"); - } + DOCTEST_PRINTF_COLORED("\n[doctest] ", Color::Cyan); + std::printf("for more information visit the project documentation\n\n"); +} - void printSummary() { - const ContextState* p = contextState; +void printSummary() { + const ContextState* p = contextState; - DOCTEST_PRINTF_COLORED(getSeparator(), Color::Yellow); - if(p->count || p->list_test_cases) { - DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan); - std::printf("unskipped test cases passing the current filters: %u\n", - p->numTestsPassingFilters); - } else if(p->list_test_suites) { - DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan); - std::printf("unskipped test cases passing the current filters: %u\n", - p->numTestsPassingFilters); - DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan); - std::printf("test suites with unskipped test cases passing the current filters: %u\n", - p->numTestSuitesPassingFilters); - } else { - const bool anythingFailed = p->numFailed > 0 || p->numFailedAssertions > 0; - - char buff[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - - DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan); - - DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), "test cases: %6u", - p->numTestsPassingFilters); - DOCTEST_PRINTF_COLORED(buff, Color::None); - DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), " | "); - DOCTEST_PRINTF_COLORED(buff, Color::None); - DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), "%6u passed", - p->numTestsPassingFilters - p->numFailed); - DOCTEST_PRINTF_COLORED(buff, (p->numTestsPassingFilters == 0 || anythingFailed) ? - Color::None : - Color::Green); - DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), " | "); - DOCTEST_PRINTF_COLORED(buff, Color::None); - DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), "%6u failed", p->numFailed); - DOCTEST_PRINTF_COLORED(buff, p->numFailed > 0 ? Color::Red : Color::None); - - DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), " | "); - DOCTEST_PRINTF_COLORED(buff, Color::None); - if(p->no_skipped_summary == false) { - const int numSkipped = static_cast(getRegisteredTests().size()) - - p->numTestsPassingFilters; - DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), "%6d skipped", numSkipped); - DOCTEST_PRINTF_COLORED(buff, numSkipped == 0 ? Color::None : Color::Yellow); - } - DOCTEST_PRINTF_COLORED("\n", Color::None); - - DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan); - - DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), "assertions: %6d", p->numAssertions); - DOCTEST_PRINTF_COLORED(buff, Color::None); - DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), " | "); - DOCTEST_PRINTF_COLORED(buff, Color::None); - DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), "%6d passed", - p->numAssertions - p->numFailedAssertions); - DOCTEST_PRINTF_COLORED(buff, (p->numAssertions == 0 || anythingFailed) ? Color::None : - Color::Green); - DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), " | "); - DOCTEST_PRINTF_COLORED(buff, Color::None); - DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), "%6d failed", p->numFailedAssertions); - DOCTEST_PRINTF_COLORED(buff, p->numFailedAssertions > 0 ? Color::Red : Color::None); - - DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), " |\n"); - DOCTEST_PRINTF_COLORED(buff, Color::None); - - DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan); - DOCTEST_PRINTF_COLORED("Status: ", Color::None); - const char* result = (p->numFailed > 0) ? "FAILURE!\n" : "SUCCESS!\n"; - DOCTEST_PRINTF_COLORED(result, p->numFailed > 0 ? Color::Red : Color::Green); + DOCTEST_PRINTF_COLORED(getSeparator(), Color::Yellow); + if (p->count || p->list_test_cases) { + DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan); + std::printf( + "unskipped test cases passing the current filters: %u\n", + p->numTestsPassingFilters); + } else if (p->list_test_suites) { + DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan); + std::printf( + "unskipped test cases passing the current filters: %u\n", + p->numTestsPassingFilters); + DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan); + std::printf( + "test suites with unskipped test cases passing the current " + "filters: %u\n", + p->numTestSuitesPassingFilters); + } else { + const bool anythingFailed = + p->numFailed > 0 || p->numFailedAssertions > 0; + + char buff[DOCTEST_SNPRINTF_BUFFER_LENGTH]; + + DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan); + + DOCTEST_SNPRINTF( + buff, DOCTEST_COUNTOF(buff), "test cases: %6u", + p->numTestsPassingFilters); + DOCTEST_PRINTF_COLORED(buff, Color::None); + DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), " | "); + DOCTEST_PRINTF_COLORED(buff, Color::None); + DOCTEST_SNPRINTF( + buff, DOCTEST_COUNTOF(buff), "%6u passed", + p->numTestsPassingFilters - p->numFailed); + DOCTEST_PRINTF_COLORED( + buff, (p->numTestsPassingFilters == 0 || anythingFailed) + ? Color::None + : Color::Green); + DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), " | "); + DOCTEST_PRINTF_COLORED(buff, Color::None); + DOCTEST_SNPRINTF( + buff, DOCTEST_COUNTOF(buff), "%6u failed", p->numFailed); + DOCTEST_PRINTF_COLORED( + buff, p->numFailed > 0 ? Color::Red : Color::None); + + DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), " | "); + DOCTEST_PRINTF_COLORED(buff, Color::None); + if (p->no_skipped_summary == false) { + const int numSkipped = + static_cast(getRegisteredTests().size()) + - p->numTestsPassingFilters; + DOCTEST_SNPRINTF( + buff, DOCTEST_COUNTOF(buff), "%6d skipped", numSkipped); + DOCTEST_PRINTF_COLORED( + buff, numSkipped == 0 ? Color::None : Color::Yellow); } + DOCTEST_PRINTF_COLORED("\n", Color::None); + + DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan); + + DOCTEST_SNPRINTF( + buff, DOCTEST_COUNTOF(buff), "assertions: %6d", p->numAssertions); + DOCTEST_PRINTF_COLORED(buff, Color::None); + DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), " | "); + DOCTEST_PRINTF_COLORED(buff, Color::None); + DOCTEST_SNPRINTF( + buff, DOCTEST_COUNTOF(buff), "%6d passed", + p->numAssertions - p->numFailedAssertions); + DOCTEST_PRINTF_COLORED( + buff, (p->numAssertions == 0 || anythingFailed) ? Color::None + : Color::Green); + DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), " | "); + DOCTEST_PRINTF_COLORED(buff, Color::None); + DOCTEST_SNPRINTF( + buff, DOCTEST_COUNTOF(buff), "%6d failed", p->numFailedAssertions); + DOCTEST_PRINTF_COLORED( + buff, p->numFailedAssertions > 0 ? Color::Red : Color::None); + + DOCTEST_SNPRINTF(buff, DOCTEST_COUNTOF(buff), " |\n"); + DOCTEST_PRINTF_COLORED(buff, Color::None); - // remove any coloring - DOCTEST_PRINTF_COLORED("", Color::None); + DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan); + DOCTEST_PRINTF_COLORED("Status: ", Color::None); + const char* result = (p->numFailed > 0) ? "FAILURE!\n" : "SUCCESS!\n"; + DOCTEST_PRINTF_COLORED( + result, p->numFailed > 0 ? Color::Red : Color::Green); } -} // namespace detail + + // remove any coloring + DOCTEST_PRINTF_COLORED("", Color::None); +} +} // namespace detail bool isRunningInTest() { return detail::contextState != 0; } Context::Context(int argc, const char* const* argv) - : p(new detail::ContextState) { + : p(new detail::ContextState) { parseArgs(argc, argv, true); } Context::~Context() { delete p; } -void Context::applyCommandLine(int argc, const char* const* argv) { parseArgs(argc, argv); } +void Context::applyCommandLine(int argc, const char* const* argv) { + parseArgs(argc, argv); +} // parses args void Context::parseArgs(int argc, const char* const* argv, bool withDefaults) { @@ -5320,28 +5534,29 @@ void Context::parseArgs(int argc, const char* const* argv, bool withDefaults) { parseCommaSepArgs(argc, argv, "dt-sce=", p->filters[7]); // clang-format on - int intRes = 0; + int intRes = 0; String strRes; -#define DOCTEST_PARSE_AS_BOOL_OR_FLAG(name, sname, var, default) \ - if(parseIntOption(argc, argv, name "=", option_bool, intRes) || \ - parseIntOption(argc, argv, sname "=", option_bool, intRes)) \ - p->var = !!intRes; \ - else if(parseFlag(argc, argv, name) || parseFlag(argc, argv, sname)) \ - p->var = true; \ - else if(withDefaults) \ +#define DOCTEST_PARSE_AS_BOOL_OR_FLAG(name, sname, var, default) \ + if (parseIntOption(argc, argv, name "=", option_bool, intRes) \ + || parseIntOption(argc, argv, sname "=", option_bool, intRes)) \ + p->var = !!intRes; \ + else if (parseFlag(argc, argv, name) || parseFlag(argc, argv, sname)) \ + p->var = true; \ + else if (withDefaults) \ p->var = default -#define DOCTEST_PARSE_INT_OPTION(name, sname, var, default) \ - if(parseIntOption(argc, argv, name "=", option_int, intRes) || \ - parseIntOption(argc, argv, sname "=", option_int, intRes)) \ - p->var = intRes; \ - else if(withDefaults) \ +#define DOCTEST_PARSE_INT_OPTION(name, sname, var, default) \ + if (parseIntOption(argc, argv, name "=", option_int, intRes) \ + || parseIntOption(argc, argv, sname "=", option_int, intRes)) \ + p->var = intRes; \ + else if (withDefaults) \ p->var = default -#define DOCTEST_PARSE_STR_OPTION(name, sname, var, default) \ - if(parseOption(argc, argv, name "=", strRes, default) || \ - parseOption(argc, argv, sname "=", strRes, default) || withDefaults) \ +#define DOCTEST_PARSE_STR_OPTION(name, sname, var, default) \ + if (parseOption(argc, argv, name "=", strRes, default) \ + || parseOption(argc, argv, sname "=", strRes, default) \ + || withDefaults) \ p->var = strRes // clang-format off @@ -5375,53 +5590,58 @@ void Context::parseArgs(int argc, const char* const* argv, bool withDefaults) { #undef DOCTEST_PARSE_INT_OPTION #undef DOCTEST_PARSE_AS_BOOL_OR_FLAG - if(withDefaults) { - p->help = false; - p->version = false; - p->count = false; - p->list_test_cases = false; + if (withDefaults) { + p->help = false; + p->version = false; + p->count = false; + p->list_test_cases = false; p->list_test_suites = false; } - if(parseFlag(argc, argv, "dt-help") || parseFlag(argc, argv, "dt-h") || - parseFlag(argc, argv, "dt-?")) { + if (parseFlag(argc, argv, "dt-help") || parseFlag(argc, argv, "dt-h") + || parseFlag(argc, argv, "dt-?")) { p->help = true; p->exit = true; } - if(parseFlag(argc, argv, "dt-version") || parseFlag(argc, argv, "dt-v")) { + if (parseFlag(argc, argv, "dt-version") || parseFlag(argc, argv, "dt-v")) { p->version = true; - p->exit = true; + p->exit = true; } - if(parseFlag(argc, argv, "dt-count") || parseFlag(argc, argv, "dt-c")) { + if (parseFlag(argc, argv, "dt-count") || parseFlag(argc, argv, "dt-c")) { p->count = true; - p->exit = true; + p->exit = true; } - if(parseFlag(argc, argv, "dt-list-test-cases") || parseFlag(argc, argv, "dt-ltc")) { + if (parseFlag(argc, argv, "dt-list-test-cases") + || parseFlag(argc, argv, "dt-ltc")) { p->list_test_cases = true; - p->exit = true; + p->exit = true; } - if(parseFlag(argc, argv, "dt-list-test-suites") || parseFlag(argc, argv, "dt-lts")) { + if (parseFlag(argc, argv, "dt-list-test-suites") + || parseFlag(argc, argv, "dt-lts")) { p->list_test_suites = true; - p->exit = true; + p->exit = true; } } // allows the user to add procedurally to the filters from the command line -void Context::addFilter(const char* filter, const char* value) { setOption(filter, value); } +void Context::addFilter(const char* filter, const char* value) { + setOption(filter, value); +} // allows the user to clear all filters from the command line void Context::clearFilters() { - for(unsigned i = 0; i < p->filters.size(); ++i) - p->filters[i].clear(); + for (unsigned i = 0; i < p->filters.size(); ++i) p->filters[i].clear(); } -// allows the user to override procedurally the int/bool options from the command line +// allows the user to override procedurally the int/bool options from the +// command line void Context::setOption(const char* option, int value) { setOption(option, toString(value).c_str()); } -// allows the user to override procedurally the string options from the command line +// allows the user to override procedurally the string options from the command +// line void Context::setOption(const char* option, const char* value) { - String argv = String("-") + option + "=" + value; + String argv = String("-") + option + "=" + value; const char* lvalue = argv.c_str(); parseArgs(1, &lvalue); } @@ -5439,11 +5659,9 @@ int Context::run() { p->resetRunData(); // handle version, help and no_run - if(p->no_run || p->version || p->help) { - if(p->version) - printVersion(); - if(p->help) - printHelp(); + if (p->no_run || p->version || p->help) { + if (p->version) printVersion(); + if (p->help) printHelp(); contextState = 0; @@ -5454,88 +5672,95 @@ int Context::run() { DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan); std::printf("run with \"--help\" for options\n"); - unsigned i = 0; // counter used for loops - here for VC6 + unsigned i = 0; // counter used for loops - here for VC6 std::set& registeredTests = getRegisteredTests(); std::vector testArray; - for(std::set::iterator it = registeredTests.begin(); it != registeredTests.end(); - ++it) + for (std::set::iterator it = registeredTests.begin(); + it != registeredTests.end(); ++it) testArray.push_back(&(*it)); // sort the collected records - if(!testArray.empty()) { - if(p->order_by.compare("file", true) == 0) { - std::qsort(&testArray[0], testArray.size(), sizeof(TestCase*), fileOrderComparator); - } else if(p->order_by.compare("suite", true) == 0) { - std::qsort(&testArray[0], testArray.size(), sizeof(TestCase*), suiteOrderComparator); - } else if(p->order_by.compare("name", true) == 0) { - std::qsort(&testArray[0], testArray.size(), sizeof(TestCase*), nameOrderComparator); - } else if(p->order_by.compare("rand", true) == 0) { + if (!testArray.empty()) { + if (p->order_by.compare("file", true) == 0) { + std::qsort( + &testArray[0], testArray.size(), sizeof(TestCase*), + fileOrderComparator); + } else if (p->order_by.compare("suite", true) == 0) { + std::qsort( + &testArray[0], testArray.size(), sizeof(TestCase*), + suiteOrderComparator); + } else if (p->order_by.compare("name", true) == 0) { + std::qsort( + &testArray[0], testArray.size(), sizeof(TestCase*), + nameOrderComparator); + } else if (p->order_by.compare("rand", true) == 0) { std::srand(p->rand_seed); // random_shuffle implementation const TestCase** first = &testArray[0]; - for(i = testArray.size() - 1; i > 0; --i) { - int idxToSwap = std::rand() % (i + 1); // NOLINT + for (i = testArray.size() - 1; i > 0; --i) { + int idxToSwap = std::rand() % (i + 1); // NOLINT const TestCase* temp = first[i]; - first[i] = first[idxToSwap]; + first[i] = first[idxToSwap]; first[idxToSwap] = temp; } } } - if(p->list_test_cases) { + if (p->list_test_cases) { DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan); std::printf("listing all test case names\n"); DOCTEST_PRINTF_COLORED(getSeparator(), Color::Yellow); } std::set testSuitesPassingFilters; - if(p->list_test_suites) { + if (p->list_test_suites) { DOCTEST_PRINTF_COLORED("[doctest] ", Color::Cyan); std::printf("listing all test suites\n"); DOCTEST_PRINTF_COLORED(getSeparator(), Color::Yellow); } - // invoke the registered functions if they match the filter criteria (or just count them) - for(i = 0; i < testArray.size(); i++) { + // invoke the registered functions if they match the filter criteria (or + // just count them) + for (i = 0; i < testArray.size(); i++) { const TestCase& data = *testArray[i]; - if(data.m_skip && !p->no_skip) - continue; + if (data.m_skip && !p->no_skip) continue; - if(!matchesAny(data.m_file, p->filters[0], 1, p->case_sensitive)) + if (!matchesAny(data.m_file, p->filters[0], 1, p->case_sensitive)) continue; - if(matchesAny(data.m_file, p->filters[1], 0, p->case_sensitive)) + if (matchesAny(data.m_file, p->filters[1], 0, p->case_sensitive)) continue; - if(!matchesAny(data.m_test_suite, p->filters[2], 1, p->case_sensitive)) + if (!matchesAny(data.m_test_suite, p->filters[2], 1, p->case_sensitive)) continue; - if(matchesAny(data.m_test_suite, p->filters[3], 0, p->case_sensitive)) + if (matchesAny(data.m_test_suite, p->filters[3], 0, p->case_sensitive)) continue; - if(!matchesAny(data.m_name, p->filters[4], 1, p->case_sensitive)) + if (!matchesAny(data.m_name, p->filters[4], 1, p->case_sensitive)) continue; - if(matchesAny(data.m_name, p->filters[5], 0, p->case_sensitive)) + if (matchesAny(data.m_name, p->filters[5], 0, p->case_sensitive)) continue; p->numTestsPassingFilters++; - // do not execute the test if we are to only count the number of filter passing tests - if(p->count) - continue; + // do not execute the test if we are to only count the number of filter + // passing tests + if (p->count) continue; // print the name of the test and don't execute it - if(p->list_test_cases) { + if (p->list_test_cases) { std::printf("%s\n", data.m_name); continue; } - // print the name of the test suite if not done already and don't execute it - if(p->list_test_suites) { - if((testSuitesPassingFilters.count(data.m_test_suite) == 0) && - data.m_test_suite[0] != '\0') { + // print the name of the test suite if not done already and don't + // execute it + if (p->list_test_suites) { + if ((testSuitesPassingFilters.count(data.m_test_suite) == 0) + && data.m_test_suite[0] != '\0') { std::printf("%s\n", data.m_test_suite); testSuitesPassingFilters.insert(data.m_test_suite); p->numTestSuitesPassingFilters++; @@ -5544,37 +5769,37 @@ int Context::run() { } // skip the test if it is not in the execution range - if((p->last < p->numTestsPassingFilters && p->first <= p->last) || - (p->first > p->numTestsPassingFilters)) + if ((p->last < p->numTestsPassingFilters && p->first <= p->last) + || (p->first > p->numTestsPassingFilters)) continue; // execute the test if it passes all the filtering { p->currentTest = &data; - bool failed = false; - p->hasLoggedCurrentTestStart = false; + bool failed = false; + p->hasLoggedCurrentTestStart = false; p->numFailedAssertionsForCurrentTestcase = 0; p->subcasesPassed.clear(); double duration = 0; - Timer timer; + Timer timer; timer.start(); do { - // if the start has been logged from a previous iteration of this loop - if(p->hasLoggedCurrentTestStart) - logTestEnd(); + // if the start has been logged from a previous iteration of + // this loop + if (p->hasLoggedCurrentTestStart) logTestEnd(); p->hasLoggedCurrentTestStart = false; // if logging successful tests - force the start log - if(p->success) - DOCTEST_LOG_START(); + if (p->success) DOCTEST_LOG_START(); // reset the assertion state p->numAssertionsForCurrentTestcase = 0; - p->hasCurrentTestFailed = false; + p->hasCurrentTestFailed = false; - // reset some of the fields for subcases (except for the set of fully passed ones) - p->subcasesHasSkipped = false; + // reset some of the fields for subcases (except for the set of + // fully passed ones) + p->subcasesHasSkipped = false; p->subcasesCurrentLevel = 0; p->subcasesEnteredLevels.clear(); @@ -5584,93 +5809,108 @@ int Context::run() { // execute the test #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS try { -#endif // DOCTEST_CONFIG_NO_EXCEPTIONS - FatalConditionHandler fatalConditionHandler; // Handle signals +#endif // DOCTEST_CONFIG_NO_EXCEPTIONS + FatalConditionHandler + fatalConditionHandler; // Handle signals data.m_test(); fatalConditionHandler.reset(); - if(contextState->hasCurrentTestFailed) - failed = true; + if (contextState->hasCurrentTestFailed) failed = true; #ifndef DOCTEST_CONFIG_NO_EXCEPTIONS - } catch(const TestFailureException&) { failed = true; } catch(...) { + } catch (const TestFailureException&) { + failed = true; + } catch (...) { DOCTEST_LOG_START(); logTestException(translateActiveException()); failed = true; } -#endif // DOCTEST_CONFIG_NO_EXCEPTIONS +#endif // DOCTEST_CONFIG_NO_EXCEPTIONS p->numAssertions += p->numAssertionsForCurrentTestcase; // exit this loop if enough assertions have failed - if(p->abort_after > 0 && p->numFailedAssertions >= p->abort_after) { + if (p->abort_after > 0 + && p->numFailedAssertions >= p->abort_after) { p->subcasesHasSkipped = false; - DOCTEST_PRINTF_COLORED("Aborting - too many failed asserts!\n", Color::Red); + DOCTEST_PRINTF_COLORED( + "Aborting - too many failed asserts!\n", Color::Red); } - } while(p->subcasesHasSkipped == true); + } while (p->subcasesHasSkipped == true); duration = timer.getElapsedSeconds(); - if(Approx(p->currentTest->m_timeout).epsilon(DBL_EPSILON) != 0 && - Approx(duration).epsilon(DBL_EPSILON) > p->currentTest->m_timeout) { + if (Approx(p->currentTest->m_timeout).epsilon(DBL_EPSILON) != 0 + && Approx(duration).epsilon(DBL_EPSILON) + > p->currentTest->m_timeout) { failed = true; DOCTEST_LOG_START(); char msg[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(msg, DOCTEST_COUNTOF(msg), - "Test case exceeded time limit of %.6f!\n", - p->currentTest->m_timeout); + DOCTEST_SNPRINTF( + msg, DOCTEST_COUNTOF(msg), + "Test case exceeded time limit of %.6f!\n", + p->currentTest->m_timeout); DOCTEST_PRINTF_COLORED(msg, Color::Red); } - if(p->duration) { + if (p->duration) { char msg[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - DOCTEST_SNPRINTF(msg, DOCTEST_COUNTOF(msg), "%.6f s: %s\n", duration, - p->currentTest->m_name); + DOCTEST_SNPRINTF( + msg, DOCTEST_COUNTOF(msg), "%.6f s: %s\n", duration, + p->currentTest->m_name); DOCTEST_PRINTF_COLORED(msg, Color::None); } - if(data.m_should_fail) { + if (data.m_should_fail) { DOCTEST_LOG_START(); - if(failed) { + if (failed) { failed = false; - DOCTEST_PRINTF_COLORED("Failed as expected so marking it as not failed\n", - Color::Yellow); + DOCTEST_PRINTF_COLORED( + "Failed as expected so marking it as not failed\n", + Color::Yellow); } else { failed = true; - DOCTEST_PRINTF_COLORED("Should have failed but didn't! Marking it as failed!\n", - Color::Red); + DOCTEST_PRINTF_COLORED( + "Should have failed but didn't! Marking it as " + "failed!\n", + Color::Red); } - } else if(failed && data.m_may_fail) { + } else if (failed && data.m_may_fail) { DOCTEST_LOG_START(); failed = false; - DOCTEST_PRINTF_COLORED("Allowed to fail so marking it as not failed\n", - Color::Yellow); - } else if(data.m_expected_failures > 0) { + DOCTEST_PRINTF_COLORED( + "Allowed to fail so marking it as not failed\n", + Color::Yellow); + } else if (data.m_expected_failures > 0) { DOCTEST_LOG_START(); char msg[DOCTEST_SNPRINTF_BUFFER_LENGTH]; - if(p->numFailedAssertionsForCurrentTestcase == data.m_expected_failures) { + if (p->numFailedAssertionsForCurrentTestcase + == data.m_expected_failures) { failed = false; DOCTEST_SNPRINTF( - msg, DOCTEST_COUNTOF(msg), - "Failed exactly %d times as expected so marking it as not failed!\n", - data.m_expected_failures); + msg, DOCTEST_COUNTOF(msg), + "Failed exactly %d times as expected so marking it as " + "not failed!\n", + data.m_expected_failures); DOCTEST_PRINTF_COLORED(msg, Color::Yellow); } else { failed = true; - DOCTEST_SNPRINTF(msg, DOCTEST_COUNTOF(msg), - "Didn't fail exactly %d times so marking it as failed!\n", - data.m_expected_failures); + DOCTEST_SNPRINTF( + msg, DOCTEST_COUNTOF(msg), + "Didn't fail exactly %d times so marking it as " + "failed!\n", + data.m_expected_failures); DOCTEST_PRINTF_COLORED(msg, Color::Red); } } - if(p->hasLoggedCurrentTestStart) - logTestEnd(); + if (p->hasLoggedCurrentTestStart) logTestEnd(); - if(failed) // if any subcase has failed - the whole test case has failed + if (failed) // if any subcase has failed - the whole test case has + // failed p->numFailed++; // stop executing tests if enough assertions have failed - if(p->abort_after > 0 && p->numFailedAssertions >= p->abort_after) + if (p->abort_after > 0 && p->numFailedAssertions >= p->abort_after) break; } } @@ -5679,21 +5919,20 @@ int Context::run() { contextState = 0; - if(p->numFailed && !p->no_exitcode) - return EXIT_FAILURE; + if (p->numFailed && !p->no_exitcode) return EXIT_FAILURE; return EXIT_SUCCESS; } -} // namespace doctest +} // namespace doctest -#endif // DOCTEST_CONFIG_DISABLE +#endif // DOCTEST_CONFIG_DISABLE #ifdef DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN int main(int argc, char** argv) { return doctest::Context(argc, argv).run(); } -#endif // DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#endif // DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN DOCTEST_CLANG_SUPPRESS_WARNING_POP DOCTEST_MSVC_SUPPRESS_WARNING_POP DOCTEST_GCC_SUPPRESS_WARNING_POP -#endif // DOCTEST_LIBRARY_IMPLEMENTATION -#endif // DOCTEST_CONFIG_IMPLEMENT +#endif // DOCTEST_LIBRARY_IMPLEMENTATION +#endif // DOCTEST_CONFIG_IMPLEMENT diff --git a/src/emoji.cpp b/src/emoji.cpp index 9840219f..6a66cd4f 100644 --- a/src/emoji.cpp +++ b/src/emoji.cpp @@ -1,6 +1,7 @@ -#include #include "emoji.h" +#include + //! this is a class that includes ascii-emoji strings. //! I took the text from https://github.com/dysfunc/ascii-emoji @@ -8,34 +9,34 @@ namespace emoji { -std::string success () {return("\xF0\x9F\x98\x81");} -std::string angry () {return("\xF0\x9F\x98\xA4");} -std::string very_angry () {return("\xF0\x9F\x98\xA1");} -std::string innocent () {return("\xF0\x9F\x98\x8B");} -std::string cute () {return("\xF0\x9F\x98\x9D");} -std::string surprise () {return("\xF0\x9F\x98\xB1");} -std::string meh () {return("\xF0\x9F\x98\x85");} -std::string happy () {return("\xF0\x9F\x98\x9C");} -std::string smile_with_sunglass() {return("\xF0\x9F\x98\x8E");} -std::string disagree () {return("\xF0\x9F\x91\x8E");} -std::string sad () {return("\xF0\x9F\x98\x9E");} -std::string confused () {return("\xF0\x9F\x98\xB5");} -std::string dislike () {return("\xF0\x9F\x98\xB0");} -std::string cry_troll () {return("\xF0\x9F\x98\xAD");} -std::string cat () {return("\xF0\x9F\x90\x88");} -std::string thumbup () {return("\xF0\x9F\x91\x8D");} -std::string beer () {return("\xF0\x9F\x8D\xBA");} -std::string beerclinking () {return("\U0001F37B");} -std::string waterwave () {return("\xF0\x9F\x8C\x8A");} -std::string not_supprot () {return("\xF0\x9F\x99\x85");} -std::string raise_hand () {return("\xE2\x9C\x8B");} -std::string clock () {return("\xF0\x9F\x95\x91");} -std::string thinking () {return("\U0001F914");} -std::string stopwatch () {return("\U000023F1");} -std::string information () {return("\U00002139");} -std::string warning () {return("\U000026A0");} -std::string error () {return("\U0001F6AB");} -std::string debug () {return("\U0001F50D");} -std::string music_note () {return("\U0001F3B5");} +std::string success() { return ("\xF0\x9F\x98\x81"); } +std::string angry() { return ("\xF0\x9F\x98\xA4"); } +std::string very_angry() { return ("\xF0\x9F\x98\xA1"); } +std::string innocent() { return ("\xF0\x9F\x98\x8B"); } +std::string cute() { return ("\xF0\x9F\x98\x9D"); } +std::string surprise() { return ("\xF0\x9F\x98\xB1"); } +std::string meh() { return ("\xF0\x9F\x98\x85"); } +std::string happy() { return ("\xF0\x9F\x98\x9C"); } +std::string smile_with_sunglass() { return ("\xF0\x9F\x98\x8E"); } +std::string disagree() { return ("\xF0\x9F\x91\x8E"); } +std::string sad() { return ("\xF0\x9F\x98\x9E"); } +std::string confused() { return ("\xF0\x9F\x98\xB5"); } +std::string dislike() { return ("\xF0\x9F\x98\xB0"); } +std::string cry_troll() { return ("\xF0\x9F\x98\xAD"); } +std::string cat() { return ("\xF0\x9F\x90\x88"); } +std::string thumbup() { return ("\xF0\x9F\x91\x8D"); } +std::string beer() { return ("\xF0\x9F\x8D\xBA"); } +std::string beerclinking() { return ("\U0001F37B"); } +std::string waterwave() { return ("\xF0\x9F\x8C\x8A"); } +std::string not_supprot() { return ("\xF0\x9F\x99\x85"); } +std::string raise_hand() { return ("\xE2\x9C\x8B"); } +std::string clock() { return ("\xF0\x9F\x95\x91"); } +std::string thinking() { return ("\U0001F914"); } +std::string stopwatch() { return ("\U000023F1"); } +std::string information() { return ("\U00002139"); } +std::string warning() { return ("\U000026A0"); } +std::string error() { return ("\U0001F6AB"); } +std::string debug() { return ("\U0001F50D"); } +std::string music_note() { return ("\U0001F3B5"); } -} +} // namespace emoji diff --git a/src/emoji.h b/src/emoji.h index ef8157ad..c97a0fbc 100644 --- a/src/emoji.h +++ b/src/emoji.h @@ -8,35 +8,35 @@ //! I took the text from https://github.com/dysfunc/ascii-emoji //! and http://japaneseemoticons.me namespace emoji { - std::string success (); - std::string angry (); - std::string very_angry (); - std::string innocent (); - std::string cute (); - std::string surprise (); - std::string meh (); - std::string happy (); - std::string disagree (); - std::string sad (); - std::string smile_with_sunglass(); - std::string confused (); - std::string dislike (); - std::string cry_troll (); - std::string cat (); - std::string thumbup (); - std::string beer (); - std::string beerclinking (); - std::string waterwave (); - std::string not_supprot (); - std::string raise_hand (); - std::string clock (); - std::string thinking (); - std::string stopwatch (); - std::string information (); - std::string warning (); - std::string error (); - std::string debug (); - std::string music_note (); -} +std::string success(); +std::string angry(); +std::string very_angry(); +std::string innocent(); +std::string cute(); +std::string surprise(); +std::string meh(); +std::string happy(); +std::string disagree(); +std::string sad(); +std::string smile_with_sunglass(); +std::string confused(); +std::string dislike(); +std::string cry_troll(); +std::string cat(); +std::string thumbup(); +std::string beer(); +std::string beerclinking(); +std::string waterwave(); +std::string not_supprot(); +std::string raise_hand(); +std::string clock(); +std::string thinking(); +std::string stopwatch(); +std::string information(); +std::string warning(); +std::string error(); +std::string debug(); +std::string music_note(); +} // namespace emoji #endif // SRC_EMOJI_H_ diff --git a/src/eos.cpp b/src/eos.cpp index 1ab80430..208bed5c 100644 --- a/src/eos.cpp +++ b/src/eos.cpp @@ -1,38 +1,39 @@ // Copyright 2018 @ Chun Shen #include "eos.h" -#include "eos_idealgas.h" + +#include +#include + #include "eos_EOSQ.h" -#include "eos_s95p.h" +#include "eos_UH.h" #include "eos_WB.h" -#include "eos_hotQCD.h" #include "eos_best.h" +#include "eos_hotQCD.h" +#include "eos_idealgas.h" #include "eos_neos.h" -#include "eos_UH.h" -#include -#include +#include "eos_s95p.h" -EOS::EOS(const int eos_id_in) : eos_id(eos_id_in) { +EOS::EOS(const int eos_id_in) : eos_id(eos_id_in) { if (eos_id == 0) { - eos_ptr = std::unique_ptr (new EOS_idealgas ()); + eos_ptr = std::unique_ptr(new EOS_idealgas()); } else if (eos_id == 1) { - eos_ptr = std::unique_ptr (new EOS_eosQ ()); + eos_ptr = std::unique_ptr(new EOS_eosQ()); } else if (eos_id >= 2 && eos_id <= 7) { - eos_ptr = std::unique_ptr (new EOS_s95p (eos_id)); + eos_ptr = std::unique_ptr(new EOS_s95p(eos_id)); } else if (eos_id == 8) { - eos_ptr = std::unique_ptr (new EOS_WB ()); + eos_ptr = std::unique_ptr(new EOS_WB()); } else if (eos_id == 9 || eos_id == 91) { - eos_ptr = std::unique_ptr (new EOS_hotQCD (eos_id)); + eos_ptr = std::unique_ptr(new EOS_hotQCD(eos_id)); } else if (eos_id >= 10 && eos_id <= 15) { - eos_ptr = std::unique_ptr (new EOS_neos (eos_id)); + eos_ptr = std::unique_ptr(new EOS_neos(eos_id)); } else if (eos_id == 17) { - eos_ptr = std::unique_ptr (new EOS_BEST ()); + eos_ptr = std::unique_ptr(new EOS_BEST()); } else if (eos_id == 19) { - eos_ptr = std::unique_ptr (new EOS_UH ()); + eos_ptr = std::unique_ptr(new EOS_UH()); } else { std::cout << "No EOS for eos_id = " << std::endl; exit(1); } eos_ptr->initialize_eos(); } - diff --git a/src/eos.h b/src/eos.h index 514b13b6..28881a6b 100644 --- a/src/eos.h +++ b/src/eos.h @@ -3,48 +3,71 @@ #ifndef SRC_EOS_H_ #define SRC_EOS_H_ -#include "eos_base.h" #include #include +#include "eos_base.h" + //! This is a wrapper class for the equation of state class EOS { - private: + private: const int eos_id; std::unique_ptr eos_ptr; - public: + public: EOS() = delete; EOS(const int eos_id_in); ~EOS() {}; // functions to call the function pointers - double get_pressure (double e, double rhob) const {return(eos_ptr->get_pressure(e, rhob));} - void get_pressure_with_gradients(double e, double rhob, - double &p, double &dpde, - double &dpdrhob, double &cs2) const { + double get_pressure(double e, double rhob) const { + return (eos_ptr->get_pressure(e, rhob)); + } + void get_pressure_with_gradients( + double e, double rhob, double &p, double &dpde, double &dpdrhob, + double &cs2) const { eos_ptr->get_pressure_with_gradients(e, rhob, p, dpde, dpdrhob, cs2); } - double get_temperature(double e, double rhob) const {return(eos_ptr->get_temperature(e, rhob));} - double get_entropy (double e, double rhob) const {return(eos_ptr->get_entropy(e, rhob));} - double get_cs2 (double e, double rhob) const {return(eos_ptr->get_cs2(e, rhob));} - double get_dpde (double e, double rhob) const {return(eos_ptr->p_e_func(e, rhob));} - double get_dpdrhob (double e, double rhob) const {return(eos_ptr->p_rho_func(e, rhob));} - double get_muB (double e, double rhob) const {return(eos_ptr->get_muB(e, rhob));} - double get_muS (double e, double rhob) const {return(eos_ptr->get_muS(e, rhob));} - double get_muQ (double e, double rhob) const {return(eos_ptr->get_muQ(e, rhob));} - double get_s2e (double s, double rhob) const {return(eos_ptr->get_s2e(s, rhob));} - double get_T2e (double T_in_GeV, double rhob) const {return(eos_ptr->get_T2e(T_in_GeV, rhob));} - - void getThermalVariables(double e, double rhob, - std::vector &thermalVec) const { + double get_temperature(double e, double rhob) const { + return (eos_ptr->get_temperature(e, rhob)); + } + double get_entropy(double e, double rhob) const { + return (eos_ptr->get_entropy(e, rhob)); + } + double get_cs2(double e, double rhob) const { + return (eos_ptr->get_cs2(e, rhob)); + } + double get_dpde(double e, double rhob) const { + return (eos_ptr->p_e_func(e, rhob)); + } + double get_dpdrhob(double e, double rhob) const { + return (eos_ptr->p_rho_func(e, rhob)); + } + double get_muB(double e, double rhob) const { + return (eos_ptr->get_muB(e, rhob)); + } + double get_muS(double e, double rhob) const { + return (eos_ptr->get_muS(e, rhob)); + } + double get_muQ(double e, double rhob) const { + return (eos_ptr->get_muQ(e, rhob)); + } + double get_s2e(double s, double rhob) const { + return (eos_ptr->get_s2e(s, rhob)); + } + double get_T2e(double T_in_GeV, double rhob) const { + return (eos_ptr->get_T2e(T_in_GeV, rhob)); + } + + void getThermalVariables( + double e, double rhob, std::vector &thermalVec) const { eos_ptr->getThermalVariables(e, rhob, thermalVec); } - double get_eps_max() const {return(eos_ptr->get_eps_max());} - void check_eos() const {return(eos_ptr->check_eos());} + double get_eps_max() const { return (eos_ptr->get_eps_max()); } + void check_eos() const { return (eos_ptr->check_eos()); } }; #endif // SRC_EOS_H_ diff --git a/src/eos_EOSQ.cpp b/src/eos_EOSQ.cpp index a609f188..2cc43096 100644 --- a/src/eos_EOSQ.cpp +++ b/src/eos_EOSQ.cpp @@ -1,14 +1,15 @@ // Copyright 2018 @ Chun Shen #include "eos_EOSQ.h" -#include "util.h" -#include -#include #include +#include +#include + +#include "util.h" -using std::stringstream; using std::string; +using std::stringstream; EOS_eosQ::EOS_eosQ() { set_EOS_id(1); @@ -19,18 +20,15 @@ EOS_eosQ::EOS_eosQ() { set_flag_muQ(false); } - EOS_eosQ::~EOS_eosQ() { int ntables = get_number_of_tables(); for (int itable = 0; itable < ntables; itable++) { - Util::mtx_free(mu_B_tb[itable], - nb_length[itable], e_length[itable]); + Util::mtx_free(mu_B_tb[itable], nb_length[itable], e_length[itable]); } } - void EOS_eosQ::initialize_eos() { - // read the lattice EOS pressure, temperature, and + // read the lattice EOS pressure, temperature, and music_message.info("Using EOS-Q from AZHYDRO"); music_message.info("reading EOS eosQ ..."); @@ -43,17 +41,20 @@ void EOS_eosQ::initialize_eos() { resize_table_info_arrays(); string eos_file_string_array[2] = {"1", "2"}; - pressure_tb = new double** [ntables]; - temperature_tb = new double** [ntables]; - mu_B_tb = new double** [ntables]; + pressure_tb = new double **[ntables]; + temperature_tb = new double **[ntables]; + mu_B_tb = new double **[ntables]; for (int itable = 0; itable < ntables; itable++) { - std::ifstream eos_p(envPath + "/EOS/EOS-Q/aa" - + eos_file_string_array[itable] + "_p.dat"); - std::ifstream eos_T(envPath + "/EOS/EOS-Q/aa" - + eos_file_string_array[itable] + "_t.dat"); - std::ifstream eos_mub(envPath + "/EOS/EOS-Q/aa" - + eos_file_string_array[itable] + "_mb.dat"); + std::ifstream eos_p( + envPath + "/EOS/EOS-Q/aa" + eos_file_string_array[itable] + + "_p.dat"); + std::ifstream eos_T( + envPath + "/EOS/EOS-Q/aa" + eos_file_string_array[itable] + + "_t.dat"); + std::ifstream eos_mub( + envPath + "/EOS/EOS-Q/aa" + eos_file_string_array[itable] + + "_mb.dat"); // read the first two lines with general info: // first value of rhob, first value of epsilon // deltaRhob, deltaE, number of rhob points, number of epsilon points @@ -61,13 +62,12 @@ void EOS_eosQ::initialize_eos() { // (number of rhob points + 1, number of epsilon points + 1) int N_e, N_rhob; eos_p >> nb_bounds[itable] >> e_bounds[itable]; - eos_p >> nb_spacing[itable] >> e_spacing[itable] - >> N_rhob >> N_e; + eos_p >> nb_spacing[itable] >> e_spacing[itable] >> N_rhob >> N_e; nb_length[itable] = N_rhob + 1; - e_length[itable] = N_e + 1; + e_length[itable] = N_e + 1; - e_bounds[itable] /= Util::hbarc; // 1/fm^4 - e_spacing[itable] /= Util::hbarc; // 1/fm^4 + e_bounds[itable] /= Util::hbarc; // 1/fm^4 + e_spacing[itable] /= Util::hbarc; // 1/fm^4 // skip the header in T and mu_B files string dummy; @@ -77,12 +77,11 @@ void EOS_eosQ::initialize_eos() { std::getline(eos_mub, dummy); // allocate memory for EOS arrays - pressure_tb[itable] = Util::mtx_malloc(nb_length[itable], - e_length[itable]); - temperature_tb[itable] = Util::mtx_malloc(nb_length[itable], - e_length[itable]); - mu_B_tb[itable] = Util::mtx_malloc(nb_length[itable], - e_length[itable]); + pressure_tb[itable] = + Util::mtx_malloc(nb_length[itable], e_length[itable]); + temperature_tb[itable] = + Util::mtx_malloc(nb_length[itable], e_length[itable]); + mu_B_tb[itable] = Util::mtx_malloc(nb_length[itable], e_length[itable]); // read pressure, temperature and chemical potential values for (int j = 0; j < e_length[itable]; j++) { @@ -91,62 +90,59 @@ void EOS_eosQ::initialize_eos() { eos_T >> temperature_tb[itable][i][j]; eos_mub >> mu_B_tb[itable][i][j]; - pressure_tb[itable][i][j] /= Util::hbarc; // 1/fm^4 - temperature_tb[itable][i][j] /= Util::hbarc; // 1/fm - mu_B_tb[itable][i][j] /= Util::hbarc; // 1/fm + pressure_tb[itable][i][j] /= Util::hbarc; // 1/fm^4 + temperature_tb[itable][i][j] /= Util::hbarc; // 1/fm + mu_B_tb[itable][i][j] /= Util::hbarc; // 1/fm } } } - //double eps_max_in = (e_bounds[1] + e_spacing[1]*e_length[1])/hbarc; - double eps_max_in = e_bounds[1] + e_spacing[1]*e_length[1]; + // double eps_max_in = (e_bounds[1] + e_spacing[1]*e_length[1])/hbarc; + double eps_max_in = e_bounds[1] + e_spacing[1] * e_length[1]; set_eps_max(eps_max_in); music_message.info("Done reading EOS."); } - double EOS_eosQ::p_e_func(double e, double rhob) const { - return(get_dpOverde3(e, rhob)); + return (get_dpOverde3(e, rhob)); } - double EOS_eosQ::p_rho_func(double e, double rhob) const { - return(get_dpOverdrhob2(e, rhob)); + return (get_dpOverdrhob2(e, rhob)); } - //! This function returns the local temperature in [1/fm] //! input local energy density eps [1/fm^4] and rhob [1/fm^3] double EOS_eosQ::get_temperature(double e, double rhob) const { int table_idx = get_table_idx(e); - double T = interpolate2D(e, std::abs(rhob), table_idx, - temperature_tb); // 1/fm - return(std::max(Util::small_eps, T)); + double T = interpolate2D( + e, std::abs(rhob), table_idx, + temperature_tb); // 1/fm + return (std::max(Util::small_eps, T)); } - //! This function returns the local pressure in [1/fm^4] //! the input local energy density [1/fm^4], rhob [1/fm^3] double EOS_eosQ::get_pressure(double e, double rhob) const { int table_idx = get_table_idx(e); double f = interpolate2D(e, std::abs(rhob), table_idx, pressure_tb); - return(std::max(Util::small_eps, f)); + return (std::max(Util::small_eps, f)); } - //! This function returns the local baryon chemical potential mu_B in [1/fm] //! input local energy density eps [1/fm^4] and rhob [1/fm^3] double EOS_eosQ::get_mu(double e, double rhob) const { int table_idx = get_table_idx(e); - double sign = rhob/(std::abs(rhob) + Util::small_eps); - double mu = sign*interpolate2D(e, std::abs(rhob), table_idx, - mu_B_tb); // 1/fm - return(mu); + double sign = rhob / (std::abs(rhob) + Util::small_eps); + double mu = sign + * interpolate2D( + e, std::abs(rhob), table_idx, + mu_B_tb); // 1/fm + return (mu); } - double EOS_eosQ::get_s2e(double s, double rhob) const { double e = get_s2e_finite_rhob(s, rhob); - return(e); + return (e); } diff --git a/src/eos_EOSQ.h b/src/eos_EOSQ.h index 0473ad3b..0d7d5a08 100644 --- a/src/eos_EOSQ.h +++ b/src/eos_EOSQ.h @@ -6,21 +6,20 @@ #include "eos_base.h" class EOS_eosQ : public EOS_base { - private: - - public: + private: + public: EOS_eosQ(); ~EOS_eosQ(); - + void initialize_eos(); - double p_rho_func (double e, double rhob) const; - double p_e_func (double e, double rhob) const; + double p_rho_func(double e, double rhob) const; + double p_e_func(double e, double rhob) const; double get_temperature(double e, double rhob) const; - double get_mu (double e, double rhob) const; - double get_pressure (double e, double rhob) const; - double get_s2e (double s, double rhob) const; + double get_mu(double e, double rhob) const; + double get_pressure(double e, double rhob) const; + double get_s2e(double s, double rhob) const; - void check_eos() const {check_eos_with_finite_muB();} + void check_eos() const { check_eos_with_finite_muB(); } }; #endif // SRC_EOS_EOSQ_H_ diff --git a/src/eos_UH.cpp b/src/eos_UH.cpp index 0cca262d..aadb28b8 100644 --- a/src/eos_UH.cpp +++ b/src/eos_UH.cpp @@ -1,15 +1,16 @@ // Copyright 2020 @ Chun Shen #include "eos_UH.h" -#include "util.h" -#include +#include #include #include -#include +#include + +#include "util.h" -using std::stringstream; using std::string; +using std::stringstream; EOS_UH::EOS_UH() { set_EOS_id(19); @@ -17,20 +18,18 @@ EOS_UH::EOS_UH() { set_eps_max(1e5); } - EOS_UH::~EOS_UH() { int ntables = get_number_of_tables(); for (int itable = 0; itable < ntables; itable++) { - Util::mtx_free(mu_B_tb[itable], - nb_length[itable], e_length[itable]); + Util::mtx_free(mu_B_tb[itable], nb_length[itable], e_length[itable]); } delete[] mu_B_tb; } - void EOS_UH::initialize_eos() { - // read the lattice EOS pressure, temperature, and - music_message.info("Using lattice EOS at finite muB from the UH Collaboration"); + // read the lattice EOS pressure, temperature, and + music_message.info( + "Using lattice EOS at finite muB from the UH Collaboration"); music_message.info("reading EOS UH ..."); stringstream slocalpath; @@ -45,21 +44,22 @@ void EOS_UH::initialize_eos() { resize_table_info_arrays(); string eos_file_string_array[6] = {"0", "1", "2", "3", "4", "5"}; - pressure_tb = new double** [ntables]; - temperature_tb = new double** [ntables]; - mu_B_tb = new double** [ntables]; + pressure_tb = new double **[ntables]; + temperature_tb = new double **[ntables]; + mu_B_tb = new double **[ntables]; for (int itable = 0; itable < ntables; itable++) { - std::ifstream eos_p(path + "UH_eos_p_" - + eos_file_string_array[itable] + ".dat"); - std::ifstream eos_T(path + "UH_eos_T_" - + eos_file_string_array[itable] + ".dat"); - std::ifstream eos_mub(path + "UH_eos_muB_" - + eos_file_string_array[itable] + ".dat"); + std::ifstream eos_p( + path + "UH_eos_p_" + eos_file_string_array[itable] + ".dat"); + std::ifstream eos_T( + path + "UH_eos_T_" + eos_file_string_array[itable] + ".dat"); + std::ifstream eos_mub( + path + "UH_eos_muB_" + eos_file_string_array[itable] + ".dat"); if (!eos_p) { music_message << "Can not found the EoS file! filename: " - << path + "UH_eos_p_" << eos_file_string_array[itable] + ".dat"; + << path + "UH_eos_p_" + << eos_file_string_array[itable] + ".dat"; music_message.flush("error"); exit(1); } @@ -70,19 +70,18 @@ void EOS_UH::initialize_eos() { ss << dummy; // read the first line with general info: ss >> dummy >> dummy >> e_bounds[itable] >> dummy >> e_spacing[itable] - >> dummy >> e_length[itable] >> dummy >> nb_bounds[itable] - >> dummy >> nb_spacing[itable] >> dummy >> nb_length[itable]; + >> dummy >> e_length[itable] >> dummy >> nb_bounds[itable] >> dummy + >> nb_spacing[itable] >> dummy >> nb_length[itable]; - e_bounds[itable] /= Util::hbarc; // 1/fm^4 - e_spacing[itable] /= Util::hbarc; // 1/fm^4 + e_bounds[itable] /= Util::hbarc; // 1/fm^4 + e_spacing[itable] /= Util::hbarc; // 1/fm^4 // allocate memory for EOS arrays - pressure_tb[itable] = Util::mtx_malloc(nb_length[itable], - e_length[itable]); - temperature_tb[itable] = Util::mtx_malloc(nb_length[itable], - e_length[itable]); - mu_B_tb[itable] = Util::mtx_malloc(nb_length[itable], - e_length[itable]); + pressure_tb[itable] = + Util::mtx_malloc(nb_length[itable], e_length[itable]); + temperature_tb[itable] = + Util::mtx_malloc(nb_length[itable], e_length[itable]); + mu_B_tb[itable] = Util::mtx_malloc(nb_length[itable], e_length[itable]); // read pressure, temperature and chemical potential values for (int j = 0; j < e_length[itable]; j++) { @@ -91,61 +90,58 @@ void EOS_UH::initialize_eos() { eos_T >> temperature_tb[itable][i][j]; eos_mub >> mu_B_tb[itable][i][j]; - pressure_tb[itable][i][j] /= Util::hbarc; // 1/fm^4 - temperature_tb[itable][i][j] /= Util::hbarc; // 1/fm - mu_B_tb[itable][i][j] /= Util::hbarc; // 1/fm + pressure_tb[itable][i][j] /= Util::hbarc; // 1/fm^4 + temperature_tb[itable][i][j] /= Util::hbarc; // 1/fm + mu_B_tb[itable][i][j] /= Util::hbarc; // 1/fm } } } - double eps_max_in = e_bounds[5] + e_spacing[5]*e_length[5]; + double eps_max_in = e_bounds[5] + e_spacing[5] * e_length[5]; set_eps_max(eps_max_in); music_message.info("Done reading EOS."); } - double EOS_UH::p_e_func(double e, double rhob) const { - return(get_dpOverde3(e, rhob)); + return (get_dpOverde3(e, rhob)); } - double EOS_UH::p_rho_func(double e, double rhob) const { - return(get_dpOverdrhob2(e, rhob)); + return (get_dpOverdrhob2(e, rhob)); } - //! This function returns the local temperature in [1/fm] //! input local energy density eps [1/fm^4] and rhob [1/fm^3] double EOS_UH::get_temperature(double e, double rhob) const { int table_idx = get_table_idx(e); - double T = interpolate2D(e, std::abs(rhob), table_idx, - temperature_tb); // 1/fm - return(T); + double T = interpolate2D( + e, std::abs(rhob), table_idx, + temperature_tb); // 1/fm + return (T); } - //! This function returns the local pressure in [1/fm^4] //! the input local energy density [1/fm^4], rhob [1/fm^3] double EOS_UH::get_pressure(double e, double rhob) const { int table_idx = get_table_idx(e); double f = interpolate2D(e, std::abs(rhob), table_idx, pressure_tb); - return(f); + return (f); } - //! This function returns the local baryon chemical potential mu_B in [1/fm] //! input local energy density eps [1/fm^4] and rhob [1/fm^3] double EOS_UH::get_muB(double e, double rhob) const { int table_idx = get_table_idx(e); - double sign = rhob/(std::abs(rhob) + Util::small_eps); - double mu = sign*interpolate2D(e, std::abs(rhob), table_idx, - mu_B_tb); // 1/fm - return(mu); + double sign = rhob / (std::abs(rhob) + Util::small_eps); + double mu = sign + * interpolate2D( + e, std::abs(rhob), table_idx, + mu_B_tb); // 1/fm + return (mu); } - double EOS_UH::get_s2e(double s, double rhob) const { double e = get_s2e_finite_rhob(s, rhob); - return(e); + return (e); } diff --git a/src/eos_UH.h b/src/eos_UH.h index ae5af129..922ab225 100644 --- a/src/eos_UH.h +++ b/src/eos_UH.h @@ -6,21 +6,20 @@ #include "eos_base.h" class EOS_UH : public EOS_base { - private: - - public: + private: + public: EOS_UH(); ~EOS_UH(); void initialize_eos(); - double p_rho_func (double e, double rhob) const; - double p_e_func (double e, double rhob) const; + double p_rho_func(double e, double rhob) const; + double p_e_func(double e, double rhob) const; double get_temperature(double e, double rhob) const; - double get_muB (double e, double rhob) const; - double get_pressure (double e, double rhob) const; - double get_s2e (double s, double rhob) const; + double get_muB(double e, double rhob) const; + double get_pressure(double e, double rhob) const; + double get_s2e(double s, double rhob) const; - void check_eos() const {check_eos_with_finite_muB();} + void check_eos() const { check_eos_with_finite_muB(); } }; #endif // SRC_EOS_UH_H_ diff --git a/src/eos_WB.cpp b/src/eos_WB.cpp index 42152359..a6e4c553 100644 --- a/src/eos_WB.cpp +++ b/src/eos_WB.cpp @@ -1,13 +1,14 @@ // Copyright 2018 @ Chun Shen #include "eos_WB.h" -#include "util.h" -#include #include +#include + +#include "util.h" -using std::stringstream; using std::string; +using std::stringstream; EOS_WB::EOS_WB() { set_EOS_id(8); @@ -18,120 +19,117 @@ EOS_WB::EOS_WB() { set_flag_muQ(false); } - void EOS_WB::initialize_eos() { - // read the lattice EOS pressure, temperature, and + // read the lattice EOS pressure, temperature, and music_message.info("Using lattice EOS parameterization from WB"); } - double EOS_WB::get_cs2(double e, double rhob) const { double f = calculate_velocity_of_sound_sq(e, rhob); - return(f); + return (f); } - double EOS_WB::p_e_func(double e_local, double rhob) const { double cs2_local; double e1 = e_local; - double e2 = e1*e1; - double e3 = e2*e1; - double e4 = e3*e1; - double e5 = e4*e1; - double e6 = e5*e1; - double e7 = e6*e1; - double e8 = e7*e1; - double e9 = e8*e1; - double e10 = e9*e1; - double e11 = e10*e1; - double e12 = e11*e1; - double e13 = e12*e1; - cs2_local = ((5.191934309650155e-32 + 4.123605749683891e-23*e1 - + 3.1955868410879504e-16*e2 + 1.4170364808063119e-10*e3 - + 6.087136671592452e-6*e4 + 0.02969737949090831*e5 - + 15.382615282179595*e6 + 460.6487249985994*e7 - + 1612.4245252438795*e8 + 275.0492627924299*e9 - + 58.60283714484669*e10 + 6.504847576502024*e11 - + 0.03009027913262399*e12 + 8.189430244031285e-6*e13) - /(1.4637868900982493e-30 + 6.716598285341542e-22*e1 - + 3.5477700458515908e-15*e2 + 1.1225580509306008e-9*e3 - + 0.00003551782901018317*e4 + 0.13653226327408863*e5 - + 60.85769171450653*e6 + 1800.5461219450308*e7 - + 15190.225535036281*e8 + 590.2572000057821*e9 - + 293.99144775704605*e10 + 21.461303090563028*e11 - + 0.09301685073435291*e12 + 0.000024810902623582917*e13)); - return(cs2_local); + double e2 = e1 * e1; + double e3 = e2 * e1; + double e4 = e3 * e1; + double e5 = e4 * e1; + double e6 = e5 * e1; + double e7 = e6 * e1; + double e8 = e7 * e1; + double e9 = e8 * e1; + double e10 = e9 * e1; + double e11 = e10 * e1; + double e12 = e11 * e1; + double e13 = e12 * e1; + cs2_local = + ((5.191934309650155e-32 + 4.123605749683891e-23 * e1 + + 3.1955868410879504e-16 * e2 + 1.4170364808063119e-10 * e3 + + 6.087136671592452e-6 * e4 + 0.02969737949090831 * e5 + + 15.382615282179595 * e6 + 460.6487249985994 * e7 + + 1612.4245252438795 * e8 + 275.0492627924299 * e9 + + 58.60283714484669 * e10 + 6.504847576502024 * e11 + + 0.03009027913262399 * e12 + 8.189430244031285e-6 * e13) + / (1.4637868900982493e-30 + 6.716598285341542e-22 * e1 + + 3.5477700458515908e-15 * e2 + 1.1225580509306008e-9 * e3 + + 0.00003551782901018317 * e4 + 0.13653226327408863 * e5 + + 60.85769171450653 * e6 + 1800.5461219450308 * e7 + + 15190.225535036281 * e8 + 590.2572000057821 * e9 + + 293.99144775704605 * e10 + 21.461303090563028 * e11 + + 0.09301685073435291 * e12 + 0.000024810902623582917 * e13)); + return (cs2_local); } - //! This function returns the local temperature in [1/fm] //! input local energy density eps [1/fm^4] and rhob [1/fm^3] double EOS_WB::get_temperature(double e_local, double rhob) const { double temperature; double e1 = e_local; - double e2 = e1*e1; - double e3 = e2*e1; - double e4 = e3*e1; - double e5 = e4*e1; - double e6 = e5*e1; - double e7 = e6*e1; - double e8 = e7*e1; - double e9 = e8*e1; - double e10 = e9*e1; - double e11 = e10*e1; - temperature = ((1.510073201405604e-29 + 8.014062800678687e-18*e1 - + 2.4954778310451065e-10*e2 + 0.000063810382643387*e3 - + 0.4873490574161924*e4 + 207.48582344326206*e5 - + 6686.07424325115*e6 + 14109.766109389702*e7 - + 1471.6180520527757*e8 + 14.055788949565482*e9 - + 0.015421252394182246*e10 + 1.5780479034557783e-6*e11) - /(7.558667139355393e-28 + 1.3686372302041508e-16*e1 - + 2.998130743142826e-9*e2 + 0.0005036835870305458*e3 - + 2.316902328874072*e4 + 578.0778724946719*e5 - + 11179.193315394154*e6 + 17965.67607192861*e7 - + 1051.0730543534657*e8 + 5.916312075925817*e9 - + 0.003778342768228011*e10 + 1.8472801679382593e-7*e11)); - return(temperature); + double e2 = e1 * e1; + double e3 = e2 * e1; + double e4 = e3 * e1; + double e5 = e4 * e1; + double e6 = e5 * e1; + double e7 = e6 * e1; + double e8 = e7 * e1; + double e9 = e8 * e1; + double e10 = e9 * e1; + double e11 = e10 * e1; + temperature = + ((1.510073201405604e-29 + 8.014062800678687e-18 * e1 + + 2.4954778310451065e-10 * e2 + 0.000063810382643387 * e3 + + 0.4873490574161924 * e4 + 207.48582344326206 * e5 + + 6686.07424325115 * e6 + 14109.766109389702 * e7 + + 1471.6180520527757 * e8 + 14.055788949565482 * e9 + + 0.015421252394182246 * e10 + 1.5780479034557783e-6 * e11) + / (7.558667139355393e-28 + 1.3686372302041508e-16 * e1 + + 2.998130743142826e-9 * e2 + 0.0005036835870305458 * e3 + + 2.316902328874072 * e4 + 578.0778724946719 * e5 + + 11179.193315394154 * e6 + 17965.67607192861 * e7 + + 1051.0730543534657 * e8 + 5.916312075925817 * e9 + + 0.003778342768228011 * e10 + 1.8472801679382593e-7 * e11)); + return (temperature); } - //! This function returns the local pressure in [1/fm^4] //! the input local energy density [1/fm^4], rhob [1/fm^3] double EOS_WB::get_pressure(double e_local, double rhob) const { double p; double e1 = e_local; - double e2 = e1*e_local; - double e3 = e2*e_local; - double e4 = e3*e_local; - double e5 = e4*e_local; - double e6 = e5*e_local; - double e7 = e6*e_local; - double e8 = e7*e_local; - double e9 = e8*e_local; - double e10 = e9*e_local; - double e11 = e10*e_local; - double e12 = e11*e_local; - - p = (( 1.9531729608963267e-11*e12 + 3.1188455176941583e-7*e11 - + 0.0009417586777847889*e10 + 0.7158279081255019*e9 - + 141.5073484468774*e8 + 6340.448389300905*e7 - + 41913.439282708554*e6 + 334334.4309240126*e5 - + 1.6357487344679043e6*e4 + 3.1729694865420084e6*e3 - + 1.077580993288114e6*e2 + 9737.845799644809*e1 + double e2 = e1 * e_local; + double e3 = e2 * e_local; + double e4 = e3 * e_local; + double e5 = e4 * e_local; + double e6 = e5 * e_local; + double e7 = e6 * e_local; + double e8 = e7 * e_local; + double e9 = e8 * e_local; + double e10 = e9 * e_local; + double e11 = e10 * e_local; + double e12 = e11 * e_local; + + p = + ((1.9531729608963267e-11 * e12 + 3.1188455176941583e-7 * e11 + + 0.0009417586777847889 * e10 + 0.7158279081255019 * e9 + + 141.5073484468774 * e8 + 6340.448389300905 * e7 + + 41913.439282708554 * e6 + 334334.4309240126 * e5 + + 1.6357487344679043e6 * e4 + 3.1729694865420084e6 * e3 + + 1.077580993288114e6 * e2 + 9737.845799644809 * e1 - 0.25181736420168666) - /( 3.2581066229887368e-18*e12 + 5.928138360995685e-11*e11 - + 9.601103399348206e-7*e10 + 0.002962497695527404*e9 - + 2.3405487982094204*e8 + 499.04919730607065*e7 - + 26452.34905933697*e6 + 278581.2989342773*e5 - + 1.7851642641834426e6*e4 + 1.3512402226067686e7*e3 - + 2.0931169138134286e7*e2 + 4.0574329080826794e6*e1 - + 45829.44617893836)); + / (3.2581066229887368e-18 * e12 + 5.928138360995685e-11 * e11 + + 9.601103399348206e-7 * e10 + 0.002962497695527404 * e9 + + 2.3405487982094204 * e8 + 499.04919730607065 * e7 + + 26452.34905933697 * e6 + 278581.2989342773 * e5 + + 1.7851642641834426e6 * e4 + 1.3512402226067686e7 * e3 + + 2.0931169138134286e7 * e2 + 4.0574329080826794e6 * e1 + + 45829.44617893836)); p = std::max(1e-16, p); - return(p); + return (p); } - double EOS_WB::get_s2e(double s, double rhob) const { double e = get_s2e_finite_rhob(s, 0.0); - return(e); + return (e); } diff --git a/src/eos_WB.h b/src/eos_WB.h index e9843951..825a121a 100644 --- a/src/eos_WB.h +++ b/src/eos_WB.h @@ -6,20 +6,19 @@ #include "eos_base.h" class EOS_WB : public EOS_base { - private: - - public: + private: + public: EOS_WB(); ~EOS_WB() {} - + void initialize_eos(); - double get_cs2 (double e, double rhob) const; - double p_e_func (double e, double rhob) const; + double get_cs2(double e, double rhob) const; + double p_e_func(double e, double rhob) const; double get_temperature(double e, double rhob) const; - double get_pressure (double e, double rhob) const; - double get_s2e (double s, double rhob) const; + double get_pressure(double e, double rhob) const; + double get_s2e(double s, double rhob) const; - void check_eos() const {check_eos_no_muB();} + void check_eos() const { check_eos_no_muB(); } }; #endif // SRC_EOS_WB_H_ diff --git a/src/eos_base.cpp b/src/eos_base.cpp index 7207fe28..2b2d8d28 100644 --- a/src/eos_base.cpp +++ b/src/eos_base.cpp @@ -1,29 +1,30 @@ #include "eos_base.h" -#include "util.h" -#include -#include -#include #include +#include +#include +#include + +#include "util.h" -using std::ostringstream; -using std::setw; -using std::setprecision; -using std::scientific; using std::cout; using std::endl; using std::ofstream; +using std::ostringstream; +using std::scientific; +using std::setprecision; +using std::setw; using std::string; using Util::hbarc; using Util::small_eps; EOS_base::~EOS_base() { for (int itable = 0; itable < number_of_tables; itable++) { - Util::mtx_free(pressure_tb[itable], - nb_length[itable], e_length[itable]); - Util::mtx_free(temperature_tb[itable], - nb_length[itable], e_length[itable]); + Util::mtx_free( + pressure_tb[itable], nb_length[itable], e_length[itable]); + Util::mtx_free( + temperature_tb[itable], nb_length[itable], e_length[itable]); } if (number_of_tables > 0) { delete[] pressure_tb; @@ -31,22 +32,21 @@ EOS_base::~EOS_base() { } } - double EOS_base::interpolate1D(double e, int table_idx, double ***table) const { -// This is a generic linear interpolation routine for EOS at zero mu_B -// it assumes the class has already read in -// P(e), T(e), s(e) -// as one-dimensional arrays on an equally spacing lattice grid -// units: e is in 1/fm^4 - //double local_ed = e*hbarc; // [GeV/fm^3] + // This is a generic linear interpolation routine for EOS at zero mu_B + // it assumes the class has already read in + // P(e), T(e), s(e) + // as one-dimensional arrays on an equally spacing lattice grid + // units: e is in 1/fm^4 + // double local_ed = e*hbarc; // [GeV/fm^3] double local_ed = e; - const double e0 = e_bounds[table_idx]; - const double delta_e = e_spacing[table_idx]; - const int N_e = e_length[table_idx]; + const double e0 = e_bounds[table_idx]; + const double delta_e = e_spacing[table_idx]; + const int N_e = e_length[table_idx]; // compute the indices - int idx_e = static_cast((local_ed - e0)/delta_e); + int idx_e = static_cast((local_ed - e0) / delta_e); // treatment for overflow, use the last two points to do extrapolation idx_e = std::max(0, idx_e); @@ -55,85 +55,83 @@ double EOS_base::interpolate1D(double e, int table_idx, double ***table) const { double result = 0.; if (local_ed < e0) { // check underflow - result = table[table_idx][0][0]*local_ed/e0; + result = table[table_idx][0][0] * local_ed / e0; } else { - const double frac_e = (local_ed - (idx_e*delta_e + e0))/delta_e; + const double frac_e = (local_ed - (idx_e * delta_e + e0)) / delta_e; double temp1 = table[table_idx][0][idx_e]; double temp2 = table[table_idx][0][idx_e + 1]; - result = temp1*(1. - frac_e) + temp2*frac_e; + result = temp1 * (1. - frac_e) + temp2 * frac_e; } - return(result); + return (result); } - -void EOS_base::interpolate1D_with_gradients(double e, int table_idx, - double ***table, double &p, double &dpde) const { -// This is a generic linear interpolation routine for EOS at zero mu_B -// it assumes the class has already read in -// P(e), T(e), s(e) -// as one-dimensional arrays on an equally spacing lattice grid -// units: e is in 1/fm^4 -// This function uses the interpolation points to compute the local -// derivatives dP/de. +void EOS_base::interpolate1D_with_gradients( + double e, int table_idx, double ***table, double &p, double &dpde) const { + // This is a generic linear interpolation routine for EOS at zero mu_B + // it assumes the class has already read in + // P(e), T(e), s(e) + // as one-dimensional arrays on an equally spacing lattice grid + // units: e is in 1/fm^4 + // This function uses the interpolation points to compute the local + // derivatives dP/de. const double e0 = e_bounds[table_idx]; const double delta_e = e_spacing[table_idx]; const int N_e = e_length[table_idx]; // compute the indices - int idx_e = static_cast((e - e0)/delta_e); + int idx_e = static_cast((e - e0) / delta_e); // treatment for overflow, use the last two points to do extrapolation idx_e = std::min(N_e - 2, std::max(0, idx_e)); if (e < e0) { // check underflow - dpde = table[table_idx][0][0]/e0; - p = dpde*e; + dpde = table[table_idx][0][0] / e0; + p = dpde * e; } else { double temp1 = table[table_idx][0][idx_e]; double temp2 = table[table_idx][0][idx_e + 1]; - dpde = (temp2 - temp1)/delta_e; - double frac_e = e - (idx_e*delta_e + e0); - p = temp1 + dpde*frac_e; + dpde = (temp2 - temp1) / delta_e; + double frac_e = e - (idx_e * delta_e + e0); + p = temp1 + dpde * frac_e; } } - -double EOS_base::interpolate2D(const double e, const double rhob, - const int table_idx, double ***table) const { -// This is a generic bilinear interpolation routine for EOS at finite mu_B -// it assumes the class has already read in -// P(e, rho_b), T(e, rho_b), s(e, rho_b), mu_b(e, rho_b) -// as two-dimensional arrays on an equally spacing lattice grid -// units: e is in 1/fm^4, rhob is in 1/fm^3 - //double local_ed = e*hbarc; // [GeV/fm^3] - double local_ed = e; // [1/fm^4] - double local_nb = rhob; // [1/fm^3] - - double e0 = e_bounds[table_idx]; - double nb0 = nb_bounds[table_idx]; - double delta_e = e_spacing[table_idx]; +double EOS_base::interpolate2D( + const double e, const double rhob, const int table_idx, + double ***table) const { + // This is a generic bilinear interpolation routine for EOS at finite mu_B + // it assumes the class has already read in + // P(e, rho_b), T(e, rho_b), s(e, rho_b), mu_b(e, rho_b) + // as two-dimensional arrays on an equally spacing lattice grid + // units: e is in 1/fm^4, rhob is in 1/fm^3 + // double local_ed = e*hbarc; // [GeV/fm^3] + double local_ed = e; // [1/fm^4] + double local_nb = rhob; // [1/fm^3] + + double e0 = e_bounds[table_idx]; + double nb0 = nb_bounds[table_idx]; + double delta_e = e_spacing[table_idx]; double delta_nb = nb_spacing[table_idx]; - int N_e = e_length[table_idx]; + int N_e = e_length[table_idx]; int N_nb = nb_length[table_idx]; // compute the indices - int idx_e = static_cast((local_ed - e0)/delta_e); - int idx_nb = static_cast((local_nb - nb0)/delta_nb); + int idx_e = static_cast((local_ed - e0) / delta_e); + int idx_nb = static_cast((local_nb - nb0) / delta_nb); // treatment for overflow, use the last two points to do extrapolation idx_e = std::min(N_e - 1, idx_e); - if (table_idx == number_of_tables - 1) - idx_e = std::min(N_e - 2, idx_e); + if (table_idx == number_of_tables - 1) idx_e = std::min(N_e - 2, idx_e); idx_nb = std::min(N_nb - 2, idx_nb); // check underflow - idx_e = std::max(0, idx_e); + idx_e = std::max(0, idx_e); idx_nb = std::max(0, idx_nb); - double frac_e = (local_ed - (idx_e*delta_e + e0))/delta_e; - double frac_rhob = (local_nb - (idx_nb*delta_nb + nb0))/delta_nb; + double frac_e = (local_ed - (idx_e * delta_e + e0)) / delta_e; + double frac_rhob = (local_nb - (idx_nb * delta_nb + nb0)) / delta_nb; // avoid uncontrolled extrapolation at large net baryon density frac_rhob = std::min(1., frac_rhob); @@ -149,80 +147,79 @@ double EOS_base::interpolate2D(const double e, const double rhob, temp2 = table[table_idx][idx_nb][idx_e + 1]; temp3 = table[table_idx][idx_nb + 1][idx_e + 1]; } - result = ((temp1*(1. - frac_e) + temp2*frac_e)*(1. - frac_rhob) - + (temp3*frac_e + temp4*(1. - frac_e))*frac_rhob); - return(result); + result = + ((temp1 * (1. - frac_e) + temp2 * frac_e) * (1. - frac_rhob) + + (temp3 * frac_e + temp4 * (1. - frac_e)) * frac_rhob); + return (result); } - void EOS_base::interpolate2D_with_gradients( - const double e, const double rhob, const int table_idx, - double ***table, double &p, double &dpde, double &dpdrhob) const { -// This is a generic bilinear interpolation routine for EOS at finite mu_B -// it assumes the class has already read in -// P(e, rho_b), T(e, rho_b), s(e, rho_b), mu_b(e, rho_b) -// as two-dimensional arrays on an equally spacing lattice grid -// units: e is in 1/fm^4, rhob is in 1/fm^3 -// dPde and dPdrhob is also computed with the intepolation points - double e0 = e_bounds[table_idx]; - double nb0 = nb_bounds[table_idx]; - double delta_e = e_spacing[table_idx]; + const double e, const double rhob, const int table_idx, double ***table, + double &p, double &dpde, double &dpdrhob) const { + // This is a generic bilinear interpolation routine for EOS at finite mu_B + // it assumes the class has already read in + // P(e, rho_b), T(e, rho_b), s(e, rho_b), mu_b(e, rho_b) + // as two-dimensional arrays on an equally spacing lattice grid + // units: e is in 1/fm^4, rhob is in 1/fm^3 + // dPde and dPdrhob is also computed with the intepolation points + double e0 = e_bounds[table_idx]; + double nb0 = nb_bounds[table_idx]; + double delta_e = e_spacing[table_idx]; double delta_nb = nb_spacing[table_idx]; - int N_e = e_length[table_idx]; + int N_e = e_length[table_idx]; int N_nb = nb_length[table_idx]; // compute the indices - int idx_e = static_cast((e - e0)/delta_e); - int idx_nb = static_cast((rhob - nb0)/delta_nb); + int idx_e = static_cast((e - e0) / delta_e); + int idx_nb = static_cast((rhob - nb0) / delta_nb); // treatment for overflow, use the last two points to do extrapolation - idx_e = std::min( N_e - 2, idx_e); + idx_e = std::min(N_e - 2, idx_e); idx_nb = std::min(N_nb - 2, idx_nb); // check underflow - idx_e = std::max(0, idx_e); + idx_e = std::max(0, idx_e); idx_nb = std::max(0, idx_nb); - double frac_e = (e - (idx_e*delta_e + e0))/delta_e; - double frac_rhob = (rhob - (idx_nb*delta_nb + nb0))/delta_nb; + double frac_e = (e - (idx_e * delta_e + e0)) / delta_e; + double frac_rhob = (rhob - (idx_nb * delta_nb + nb0)) / delta_nb; // avoid uncontrolled extrapolation at large net baryon density frac_rhob = std::min(1., frac_rhob); - double temp1 = table[table_idx][idx_nb ][idx_e ]; - double temp4 = table[table_idx][idx_nb+1][idx_e ]; - double temp2 = table[table_idx][idx_nb ][idx_e+1]; - double temp3 = table[table_idx][idx_nb+1][idx_e+1]; - - double p1 = temp1*(1 - frac_rhob) + temp4*frac_rhob; - double p2 = temp2*(1 - frac_rhob) + temp3*frac_rhob; - dpde = (p2 - p1)/delta_e; - p1 = temp1*(1 - frac_e) + temp2*frac_e; - p2 = temp4*(1 - frac_e) + temp3*frac_e; - dpdrhob = (p2 - p1)/delta_nb; - p = p1*(1 - frac_rhob) + p2*frac_rhob; + double temp1 = table[table_idx][idx_nb][idx_e]; + double temp4 = table[table_idx][idx_nb + 1][idx_e]; + double temp2 = table[table_idx][idx_nb][idx_e + 1]; + double temp3 = table[table_idx][idx_nb + 1][idx_e + 1]; + + double p1 = temp1 * (1 - frac_rhob) + temp4 * frac_rhob; + double p2 = temp2 * (1 - frac_rhob) + temp3 * frac_rhob; + dpde = (p2 - p1) / delta_e; + p1 = temp1 * (1 - frac_e) + temp2 * frac_e; + p2 = temp4 * (1 - frac_e) + temp3 * frac_e; + dpdrhob = (p2 - p1) / delta_nb; + p = p1 * (1 - frac_rhob) + p2 * frac_rhob; } - //! This function returns entropy density in [1/fm^3] //! The input local energy density e [1/fm^4], rhob[1/fm^3] double EOS_base::get_entropy(double epsilon, double rhob) const { - auto P = get_pressure(epsilon, rhob); - auto T = get_temperature(epsilon, rhob); - auto muB = get_muB(epsilon, rhob); - auto muS = get_muS(epsilon, rhob); - auto muQ = get_muQ(epsilon, rhob); + auto P = get_pressure(epsilon, rhob); + auto T = get_temperature(epsilon, rhob); + auto muB = get_muB(epsilon, rhob); + auto muS = get_muS(epsilon, rhob); + auto muQ = get_muQ(epsilon, rhob); auto rhoS = get_rhoS(epsilon, rhob); auto rhoQ = get_rhoQ(epsilon, rhob); - auto f = (epsilon + P - muB*rhob - muS*rhoS - muQ*rhoQ)/(T + small_eps); - return(std::max(small_eps, f)); + auto f = + (epsilon + P - muB * rhob - muS * rhoS - muQ * rhoQ) / (T + small_eps); + return (std::max(small_eps, f)); } - //! This function returns entropy density in [1/fm^3] //! The input local energy density e [1/fm^4], rhob[1/fm^3] -void EOS_base::getThermalVariables(double epsilon, double rhob, - std::vector &thermalVec) const { +void EOS_base::getThermalVariables( + double epsilon, double rhob, std::vector &thermalVec) const { thermalVec.clear(); thermalVec.push_back(epsilon); thermalVec.push_back(rhob); @@ -238,150 +235,145 @@ void EOS_base::getThermalVariables(double epsilon, double rhob, thermalVec.push_back(get_rhoS(epsilon, rhob)); thermalVec.push_back(get_muQ(epsilon, rhob)); thermalVec.push_back(get_rhoQ(epsilon, rhob)); - double entropy = ((epsilon + p - thermalVec[7]*rhob - - thermalVec[8]*thermalVec[9] - - thermalVec[10]*thermalVec[11]) - /(thermalVec[6] + small_eps)); + double entropy = + ((epsilon + p - thermalVec[7] * rhob - thermalVec[8] * thermalVec[9] + - thermalVec[10] * thermalVec[11]) + / (thermalVec[6] + small_eps)); entropy = std::max(small_eps, entropy); thermalVec.push_back(entropy); } - double EOS_base::get_cs2(double e, double rhob) const { double f = calculate_velocity_of_sound_sq(e, rhob); - return(f); + return (f); } - double EOS_base::calculate_velocity_of_sound_sq(double e, double rhob) const { double v_min = 0.01; - double v_max = 1./3; + double v_max = 1. / 3; double dpde = p_e_func(e, rhob); double dpdrho = p_rho_func(e, rhob); double pressure = get_pressure(e, rhob); - double v_sound = dpde + rhob/(e + pressure + small_eps)*dpdrho; + double v_sound = dpde + rhob / (e + pressure + small_eps) * dpdrho; v_sound = std::max(v_min, std::min(v_max, v_sound)); - return(v_sound); + return (v_sound); } - double EOS_base::get_dpOverde3(double e, double rhob) const { - double de = std::max(0.01, 0.01*e); + double de = std::max(0.01, 0.01 * e); double eLeft = std::max(1e-16, e - de); double eRight = e + de; double pL = get_pressure(eLeft, rhob); // 1/fm^4 double pR = get_pressure(eRight, rhob); // 1/fm^4 - double dpde = (pR - pL)/(eRight - eLeft); + double dpde = (pR - pL) / (eRight - eLeft); return dpde; } - double EOS_base::get_dpOverdrhob2(double e, double rhob) const { int table_idx = get_table_idx(e); double deltaRhob = nb_spacing[table_idx]; - //double rhob_max = nb_bounds[table_idx] + nb_length[table_idx]*deltaRhob; + // double rhob_max = nb_bounds[table_idx] + nb_length[table_idx]*deltaRhob; - double rhobLeft = rhob - deltaRhob*0.5; - double rhobRight = rhob + deltaRhob*0.5; + double rhobLeft = rhob - deltaRhob * 0.5; + double rhobRight = rhob + deltaRhob * 0.5; - double pL = get_pressure(e, rhobLeft); // 1/fm^4 - double pR = get_pressure(e, rhobRight); // 1/fm^4 + double pL = get_pressure(e, rhobLeft); // 1/fm^4 + double pR = get_pressure(e, rhobRight); // 1/fm^4 - double dpdrho = (pR - pL)/(rhobRight - rhobLeft); // 1/fm - return (dpdrho); // in 1/fm + double dpdrho = (pR - pL) / (rhobRight - rhobLeft); // 1/fm + return (dpdrho); // in 1/fm } - int EOS_base::get_table_idx(double e) const { - //double local_ed = e*hbarc; // [GeV/fm^3] + // double local_ed = e*hbarc; // [GeV/fm^3] double local_ed = e; // [1/fm^4] for (int itable = 1; itable < number_of_tables; itable++) { if (local_ed < e_bounds[itable]) { - return(itable - 1); + return (itable - 1); } } - return(std::max(0, number_of_tables - 1)); + return (std::max(0, number_of_tables - 1)); } - //! This function returns local energy density [1/fm^4] from //! a given temperature T [GeV] and rhob [1/fm^3] using binary search double EOS_base::get_T2e_finite_rhob(const double T, const double rhob) const { - double T_goal = T/Util::hbarc; // convert to 1/fm + double T_goal = T / Util::hbarc; // convert to 1/fm double eps_lower = small_eps; double eps_upper = eps_max; - double eps_mid = (eps_upper + eps_lower)/2.; - double T_lower = get_temperature(eps_lower, rhob); - double T_upper = get_temperature(eps_upper, rhob); - int ntol = 1000; + double eps_mid = (eps_upper + eps_lower) / 2.; + double T_lower = get_temperature(eps_lower, rhob); + double T_upper = get_temperature(eps_upper, rhob); + int ntol = 1000; if (T_goal < 0.0 || T_goal > T_upper) { cout << "get_T2e:: T is out of bound, " - << "T = " << T << " GeV, T_upper = " << T_upper*Util::hbarc - << ", T_lower = " << T_lower*Util::hbarc << endl; + << "T = " << T << " GeV, T_upper = " << T_upper * Util::hbarc + << ", T_lower = " << T_lower * Util::hbarc << endl; exit(1); } - if (T_goal < T_lower) return(eps_lower); + if (T_goal < T_lower) return (eps_lower); double rel_accuracy = sqrt(small_eps); double abs_accuracy = small_eps; double T_mid; int iter = 0; - while (((eps_upper - eps_lower)/eps_mid > rel_accuracy - && (eps_upper - eps_lower) > abs_accuracy) && iter < ntol) { + while (((eps_upper - eps_lower) / eps_mid > rel_accuracy + && (eps_upper - eps_lower) > abs_accuracy) + && iter < ntol) { T_mid = get_temperature(eps_mid, rhob); if (T_goal < T_mid) eps_upper = eps_mid; - else + else eps_lower = eps_mid; - eps_mid = (eps_upper + eps_lower)/2.; + eps_mid = (eps_upper + eps_lower) / 2.; iter++; } if (iter == ntol) { cout << "get_T2e_finite_rhob:: max iteration reached, " - << "T = " << T << " GeV, rhob = " << rhob << endl;; - cout << "T_upper = " << T_upper*Util::hbarc - << " , T_lower = " << T_lower*Util::hbarc << endl; - cout << "eps_upper = " << eps_upper - << " , eps_lower = " << eps_lower + << "T = " << T << " GeV, rhob = " << rhob << endl; + ; + cout << "T_upper = " << T_upper * Util::hbarc + << " , T_lower = " << T_lower * Util::hbarc << endl; + cout << "eps_upper = " << eps_upper << " , eps_lower = " << eps_lower << ", diff = " << (eps_upper - eps_lower) << endl; exit(1); } return (eps_mid); } - //! This function returns local energy density [1/fm^4] from //! a given entropy density [1/fm^3] and rhob [1/fm^3] //! using binary search double EOS_base::get_s2e_finite_rhob(double s, double rhob) const { double eps_lower = small_eps; double eps_upper = eps_max; - double eps_mid = (eps_upper + eps_lower)/2.; - double s_lower = get_entropy(eps_lower, rhob); - double s_upper = get_entropy(eps_upper, rhob); - int ntol = 1000; + double eps_mid = (eps_upper + eps_lower) / 2.; + double s_lower = get_entropy(eps_lower, rhob); + double s_upper = get_entropy(eps_upper, rhob); + int ntol = 1000; if (s < 0.0 || s > s_upper) { cout << "get_s2e_finite_rhob:: s is out of bound, " << "s = " << s << ", s_upper = " << s_upper << ", s_lower = " << s_lower << endl; exit(1); } - if (s < s_lower) return(eps_lower); + if (s < s_lower) return (eps_lower); double rel_accuracy = sqrt(small_eps); double abs_accuracy = small_eps; double s_mid; int iter = 0; - while (((eps_upper - eps_lower)/eps_mid > rel_accuracy - && (eps_upper - eps_lower) > abs_accuracy) && iter < ntol) { + while (((eps_upper - eps_lower) / eps_mid > rel_accuracy + && (eps_upper - eps_lower) > abs_accuracy) + && iter < ntol) { s_mid = get_entropy(eps_mid, rhob); if (s < s_mid) eps_upper = eps_mid; - else + else eps_lower = eps_mid; - eps_mid = (eps_upper + eps_lower)/2.; + eps_mid = (eps_upper + eps_lower) / 2.; iter++; } if (iter == ntol) { @@ -389,59 +381,59 @@ double EOS_base::get_s2e_finite_rhob(double s, double rhob) const { << "s = " << s << ", rhob = " << rhob << endl; cout << "s_upper = " << get_entropy(eps_upper, rhob) << " , s_lower = " << get_entropy(eps_lower, rhob) << endl; - cout << "eps_upper = " << eps_upper - << " , eps_lower = " << eps_lower + cout << "eps_upper = " << eps_upper << " , eps_lower = " << eps_lower << ", diff = " << (eps_upper - eps_lower) << endl; exit(1); } return (eps_mid); } - //! This function perform 2D inversion from (T, muB) to (e, rhoB) //! Inputs: T and muB are in [GeV], outputs: e [1/fm^4], rhoB [1/fm^3] -void EOS_base::map_TmuB2erhoB(const double T, const double muB, - double &e, double &rhob) const { - const double muB_goal = muB/Util::hbarc; // convert to 1/fm +void EOS_base::map_TmuB2erhoB( + const double T, const double muB, double &e, double &rhob) const { + const double muB_goal = muB / Util::hbarc; // convert to 1/fm double rhob_lower = 0.; const int table_idx = number_of_tables - 1; - double rhob_upper = (nb_bounds[table_idx] - + nb_length[table_idx]*nb_spacing[table_idx]); - double rhob_mid = (rhob_upper + rhob_lower)/2.; + double rhob_upper = + (nb_bounds[table_idx] + nb_length[table_idx] * nb_spacing[table_idx]); + double rhob_mid = (rhob_upper + rhob_lower) / 2.; double e_lower = get_T2e_finite_rhob(T, rhob_lower); double e_upper = get_T2e_finite_rhob(T, rhob_upper); double muB_lower = get_muB(e_lower, rhob_lower); double muB_upper = get_muB(e_upper, rhob_upper); - int ntol = 1000; + int ntol = 1000; if (muB_goal < 0.0 || muB_goal > muB_upper) { cout << "map_TmuB2erhoB:: muB is out of bound, " - << "muB = " << muB << " GeV, muB_upper = " - << muB_upper*Util::hbarc << " GeV, muB_lower = " - << muB_lower*Util::hbarc << endl; + << "muB = " << muB + << " GeV, muB_upper = " << muB_upper * Util::hbarc + << " GeV, muB_lower = " << muB_lower * Util::hbarc << endl; exit(1); } double rel_accuracy = sqrt(small_eps); double abs_accuracy = small_eps; double muB_mid; - double e_mid = (e_lower + e_upper)/2.; + double e_mid = (e_lower + e_upper) / 2.; int iter = 0; - while (((rhob_upper - rhob_lower)/rhob_mid > rel_accuracy - && (rhob_upper - rhob_lower) > abs_accuracy) && iter < ntol) { + while (((rhob_upper - rhob_lower) / rhob_mid > rel_accuracy + && (rhob_upper - rhob_lower) > abs_accuracy) + && iter < ntol) { e_mid = get_T2e_finite_rhob(T, rhob_mid); muB_mid = get_muB(e_mid, rhob_mid); if (muB_goal < muB_mid) rhob_upper = rhob_mid; else rhob_lower = rhob_mid; - rhob_mid = (rhob_upper + rhob_lower)/2.; + rhob_mid = (rhob_upper + rhob_lower) / 2.; iter++; } if (iter == ntol) { cout << __PRETTY_FUNCTION__ << ":: max iteration reached, " - << "T = " << T << " GeV, muB = " << muB << " GeV" << endl;; - cout << "muB_upper = " << muB_upper*Util::hbarc - << " GeV, muB_lower = " << muB_lower*Util::hbarc << endl; + << "T = " << T << " GeV, muB = " << muB << " GeV" << endl; + ; + cout << "muB_upper = " << muB_upper * Util::hbarc + << " GeV, muB_lower = " << muB_lower * Util::hbarc << endl; cout << "rhob_upper = " << rhob_upper << " , rhob_lower = " << rhob_lower << ", diff = " << (rhob_upper - rhob_lower) << endl; @@ -451,21 +443,18 @@ void EOS_base::map_TmuB2erhoB(const double T, const double muB, rhob = rhob_mid; } - std::string EOS_base::get_hydro_env_path() const { const char *EOSPATH = "HYDROPROGRAMPATH"; char *pre_envPath = getenv(EOSPATH); std::string envPath; if (pre_envPath == 0) { - envPath="."; - } - else { - envPath=pre_envPath; + envPath = "."; + } else { + envPath = pre_envPath; } - return(envPath); + return (envPath); } - void EOS_base::resize_table_info_arrays() { nb_bounds.resize(number_of_tables, 0.0); nb_spacing.resize(number_of_tables, 0.0); @@ -475,7 +464,6 @@ void EOS_base::resize_table_info_arrays() { e_length.resize(number_of_tables, 0); } - void EOS_base::check_eos_no_muB() const { // output EoS as function of e ostringstream file_name; @@ -485,22 +473,21 @@ void EOS_base::check_eos_no_muB() const { double e0 = pow(1e-8, 0.25); double emax = pow(1500., 0.25); double de = 5e-3; - int ne = (emax - e0)/de + 1; + int ne = (emax - e0) / de + 1; for (int i = 0; i < ne; i++) { - double e_local = pow(e0 + i*de, 4)/hbarc; + double e_local = pow(e0 + i * de, 4) / hbarc; double p_local = get_pressure(e_local, 0.0); double s_local = get_entropy(e_local, 0.0); double T_local = get_temperature(e_local, 0.0); double cs2_local = get_cs2(e_local, 0.0); check_file << scientific << setw(18) << setprecision(8) - << e_local*hbarc << " " << p_local*hbarc << " " - << s_local << " " << T_local*hbarc << " " - << cs2_local << endl; + << e_local * hbarc << " " << p_local * hbarc << " " + << s_local << " " << T_local * hbarc << " " << cs2_local + << endl; } check_file.close(); } - void EOS_base::check_eos_with_finite_muB() const { // output EoS as function of e for several rhob double rhob_pick[7] = {0.0, 0.002, 0.02, 0.05, 0.1, 0.2, 0.5}; @@ -514,22 +501,22 @@ void EOS_base::check_eos_with_finite_muB() const { double e0 = 5e-4; double emax = 100.; double de = 5e-3; - int ne = (emax - e0)/de + 1; + int ne = (emax - e0) / de + 1; for (int ie = 0; ie < ne; ie++) { - double e_local = (e0 + ie*de)/hbarc; - double p_local = get_pressure(e_local, rhob_local); - double s_local = get_entropy(e_local, rhob_local); - double T_local = get_temperature(e_local, rhob_local); - double cs2_local = get_cs2(e_local, rhob_local); + double e_local = (e0 + ie * de) / hbarc; + double p_local = get_pressure(e_local, rhob_local); + double s_local = get_entropy(e_local, rhob_local); + double T_local = get_temperature(e_local, rhob_local); + double cs2_local = get_cs2(e_local, rhob_local); double mu_b_local = get_muB(e_local, rhob_local); double mu_s_local = get_muS(e_local, rhob_local); double mu_q_local = get_muQ(e_local, rhob_local); check_file << scientific << setw(18) << setprecision(8) - << e_local*hbarc << " " << p_local*hbarc << " " - << s_local << " " << T_local*hbarc << " " - << cs2_local << " " << mu_b_local*hbarc << " " - << mu_s_local*hbarc << " " - << mu_q_local*hbarc << endl; + << e_local * hbarc << " " << p_local * hbarc << " " + << s_local << " " << T_local * hbarc << " " + << cs2_local << " " << mu_b_local * hbarc << " " + << mu_s_local * hbarc << " " << mu_q_local * hbarc + << endl; } check_file.close(); ostringstream file_name1; @@ -540,17 +527,17 @@ void EOS_base::check_eos_with_finite_muB() const { e0 = 1e-8; emax = 1e-1; de = 2; - ne = log(emax/e0)/log(de) + 1; + ne = log(emax / e0) / log(de) + 1; for (int ie = 0; ie < ne; ie++) { - double e_local = e0*pow(de, ie)/hbarc; + double e_local = e0 * pow(de, ie) / hbarc; double p_local = get_pressure(e_local, rhob_local); double s_local = get_entropy(e_local, rhob_local); double T_local = get_temperature(e_local, rhob_local); double cs2_local = get_cs2(e_local, rhob_local); check_file1 << scientific << setw(18) << setprecision(8) - << e_local*hbarc << " " << p_local*hbarc << " " - << s_local << " " << T_local*hbarc << " " - << cs2_local << endl; + << e_local * hbarc << " " << p_local * hbarc << " " + << s_local << " " << T_local * hbarc << " " + << cs2_local << endl; } check_file1.close(); ostringstream file_name2; @@ -560,29 +547,27 @@ void EOS_base::check_eos_with_finite_muB() const { e0 = 5e-4; emax = 100.; de = 5e-3; - ne = (emax - e0)/de + 1; + ne = (emax - e0) / de + 1; for (int ie = 0; ie < ne; ie++) { - double e_local = (e0 + ie*de)/hbarc; + double e_local = (e0 + ie * de) / hbarc; std::vector thermalVec; getThermalVariables(e_local, rhob_local, thermalVec); check_file2 << scientific << setw(18) << setprecision(8) - << e_local*hbarc << " " - << thermalVec[2]*hbarc << " " - << thermalVec[12] << " " - << thermalVec[6]*hbarc << " " - << thermalVec[5] << " " - << thermalVec[7]*hbarc << " " - << thermalVec[8]*hbarc << " " - << thermalVec[10]*hbarc << endl; + << e_local * hbarc << " " << thermalVec[2] * hbarc + << " " << thermalVec[12] << " " + << thermalVec[6] * hbarc << " " << thermalVec[5] + << " " << thermalVec[7] * hbarc << " " + << thermalVec[8] * hbarc << " " + << thermalVec[10] * hbarc << endl; } check_file2.close(); } // output EoS as a function of rho_b for several energy density - double e_pick[12] = {0.05, 0.1, 0.2, 0.3, 0.35, 0.4, 0.5, 0.6, 0.7, - 1.0, 3.0, 5.0}; + double e_pick[12] = {0.05, 0.1, 0.2, 0.3, 0.35, 0.4, + 0.5, 0.6, 0.7, 1.0, 3.0, 5.0}; for (int i = 0; i < 12; i++) { - double e_local = e_pick[i]/hbarc; + double e_local = e_pick[i] / hbarc; ostringstream file_name; file_name << "check_EoS_PST_e_" << e_pick[i] << ".dat"; ofstream check_file(file_name.str().c_str()); @@ -591,22 +576,22 @@ void EOS_base::check_eos_with_finite_muB() const { double rhob_0 = 0.0; double rhob_max = 1.0; double drhob = 0.01; - int nrhob = (rhob_max - rhob_0)/drhob + 1; + int nrhob = (rhob_max - rhob_0) / drhob + 1; for (int ib = 0; ib < nrhob; ib++) { - double rhob_local = rhob_0 + ib*drhob; - double p_local = get_pressure(e_local, rhob_local); - double s_local = get_entropy(e_local, rhob_local); - double T_local = get_temperature(e_local, rhob_local); - double cs2_local = get_cs2(e_local, rhob_local); + double rhob_local = rhob_0 + ib * drhob; + double p_local = get_pressure(e_local, rhob_local); + double s_local = get_entropy(e_local, rhob_local); + double T_local = get_temperature(e_local, rhob_local); + double cs2_local = get_cs2(e_local, rhob_local); double mu_b_local = get_muB(e_local, rhob_local); double mu_s_local = get_muS(e_local, rhob_local); double mu_q_local = get_muQ(e_local, rhob_local); check_file << scientific << setw(18) << setprecision(8) - << rhob_local << " " << p_local*hbarc << " " - << s_local << " " << T_local*hbarc << " " - << cs2_local << " " << mu_b_local*hbarc << " " - << mu_s_local*hbarc << " " - << mu_q_local*hbarc << endl; + << rhob_local << " " << p_local * hbarc << " " + << s_local << " " << T_local * hbarc << " " + << cs2_local << " " << mu_b_local * hbarc << " " + << mu_s_local * hbarc << " " << mu_q_local * hbarc + << endl; } check_file.close(); } @@ -616,22 +601,22 @@ void EOS_base::check_eos_with_finite_muB() const { string file_name2 = "check_EoS_cs2_2D.dat"; ofstream check_file1(file_name1.c_str()); ofstream check_file2(file_name2.c_str()); - double e_0 = 0.0; // GeV/fm^3 - double e_max = 100.0; // GeV/fm^3 - double de = 0.1; // GeV/fm^3 - int ne = static_cast((e_max - e_0)/de) + 1; - double rhob_0 = 0.0; // 1/fm^3 - double rhob_max = 1.0; // 1/fm^3 - double drhob = 0.01; // 1/fm^3 - int nrhob = static_cast((rhob_max - rhob_0)/drhob) + 1; + double e_0 = 0.0; // GeV/fm^3 + double e_max = 100.0; // GeV/fm^3 + double de = 0.1; // GeV/fm^3 + int ne = static_cast((e_max - e_0) / de) + 1; + double rhob_0 = 0.0; // 1/fm^3 + double rhob_max = 1.0; // 1/fm^3 + double drhob = 0.01; // 1/fm^3 + int nrhob = static_cast((rhob_max - rhob_0) / drhob) + 1; for (int i = 0; i < ne; i++) { - double e_local = e_0 + i*de; + double e_local = e_0 + i * de; for (int j = 0; j < nrhob; j++) { - double rhob_local = rhob_0 + j*drhob; + double rhob_local = rhob_0 + j * drhob; double p_local = get_pressure(e_local, rhob_local); double cs2_local = get_cs2(e_local, rhob_local); - check_file1 << scientific << setw(18) << setprecision(8) - << p_local << " "; + check_file1 << scientific << setw(18) << setprecision(8) << p_local + << " "; check_file2 << scientific << setw(18) << setprecision(8) << cs2_local << " "; } @@ -642,11 +627,11 @@ void EOS_base::check_eos_with_finite_muB() const { check_file2.close(); double sovernB[] = {10.0, 20.0, 30.0, 51.0, 70.0, 94.0, 144.0, 420.0}; - int array_length = sizeof(sovernB)/sizeof(double); - double s_0 = 0.00; // 1/fm^3 - double s_max = 100.0; // 1/fm^3 - double ds = 0.005; // 1/fm^3 - int ns = static_cast((s_max - s_0)/ds) + 1; + int array_length = sizeof(sovernB) / sizeof(double); + double s_0 = 0.00; // 1/fm^3 + double s_max = 100.0; // 1/fm^3 + double ds = 0.005; // 1/fm^3 + int ns = static_cast((s_max - s_0) / ds) + 1; for (int i = 0; i < array_length; i++) { ostringstream file_name; file_name << "check_EoS_cs2_vs_e_sovernB_" << sovernB[i] << ".dat"; @@ -655,57 +640,54 @@ void EOS_base::check_eos_with_finite_muB() const { << "s(1/fm^3) rho_B(1/fm^3) dP/de dP/drho " << "mu_S(GeV) mu_C(GeV)" << endl; for (int j = 0; j < ns; j++) { - double s_local = s_0 + j*ds; - double nB_local = s_local/sovernB[i]; - double e_local = get_s2e(s_local, nB_local); - double s_check = get_entropy(e_local, nB_local); - double cs2_local = get_cs2(e_local, nB_local); - double dpde = p_e_func(e_local, nB_local); - double dpdrho = p_rho_func(e_local, nB_local); - double temperature = get_temperature(e_local, nB_local)*hbarc; - double mu_B = get_muB(e_local, nB_local)*hbarc; - double mu_S = get_muS(e_local, nB_local)*hbarc; - double mu_Q = get_muQ(e_local, nB_local)*hbarc; + double s_local = s_0 + j * ds; + double nB_local = s_local / sovernB[i]; + double e_local = get_s2e(s_local, nB_local); + double s_check = get_entropy(e_local, nB_local); + double cs2_local = get_cs2(e_local, nB_local); + double dpde = p_e_func(e_local, nB_local); + double dpdrho = p_rho_func(e_local, nB_local); + double temperature = get_temperature(e_local, nB_local) * hbarc; + double mu_B = get_muB(e_local, nB_local) * hbarc; + double mu_S = get_muS(e_local, nB_local) * hbarc; + double mu_Q = get_muQ(e_local, nB_local) * hbarc; check_file9 << scientific << setw(18) << setprecision(8) - << e_local*hbarc << " " << temperature << " " - << cs2_local << " " << mu_B << " " - << s_check << " " << nB_local << " " - << dpde << " " << dpdrho << " " + << e_local * hbarc << " " << temperature << " " + << cs2_local << " " << mu_B << " " << s_check << " " + << nB_local << " " << dpde << " " << dpdrho << " " << mu_S << " " << mu_Q << endl; } check_file9.close(); } } - void EOS_base::outputMutable() const { - const double e_min = 0.08; // GeV/fm^3 - const double e_max = 0.8; // GeV/fm^3 - const double de = 0.005; // GeV/fm^3 - const double nB_max = 0.16*4; // 1/fm^3 - const double dnB = 0.001; // 1/fm^3 - const int ne = static_cast((e_max - e_min)/de) + 1; - const int nnB = static_cast(nB_max/dnB) + 1; + const double e_min = 0.08; // GeV/fm^3 + const double e_max = 0.8; // GeV/fm^3 + const double de = 0.005; // GeV/fm^3 + const double nB_max = 0.16 * 4; // 1/fm^3 + const double dnB = 0.001; // 1/fm^3 + const int ne = static_cast((e_max - e_min) / de) + 1; + const int nnB = static_cast(nB_max / dnB) + 1; ostringstream file_name; file_name << "EOS_muTable.dat"; ofstream check_file9(file_name.str().c_str()); check_file9 << "# e(GeV/fm^3) rho_B(1/fm^3) P (GeV/fm^3) S(1/fm^3) " << "T(GeV) mu_B(GeV) mu_S(GeV) mu_Q(GeV)" << endl; for (int j = 0; j < ne; j++) { - double e_local = (e_min + j*de)/hbarc; + double e_local = (e_min + j * de) / hbarc; for (int i = 0; i < nnB; i++) { - double nB_local = i*dnB; - double temperature = get_temperature(e_local, nB_local)*hbarc; - double pressure = get_pressure(e_local, nB_local)*hbarc; - double entropy = get_entropy(e_local, nB_local)*hbarc; - double mu_B = get_muB(e_local, nB_local)*hbarc; - double mu_S = get_muS(e_local, nB_local)*hbarc; - double mu_Q = get_muQ(e_local, nB_local)*hbarc; + double nB_local = i * dnB; + double temperature = get_temperature(e_local, nB_local) * hbarc; + double pressure = get_pressure(e_local, nB_local) * hbarc; + double entropy = get_entropy(e_local, nB_local) * hbarc; + double mu_B = get_muB(e_local, nB_local) * hbarc; + double mu_S = get_muS(e_local, nB_local) * hbarc; + double mu_Q = get_muQ(e_local, nB_local) * hbarc; check_file9 << scientific << setw(18) << setprecision(8) - << e_local*hbarc << " " << nB_local << " " - << pressure << " " << entropy << " " - << temperature << " " << mu_B << " " - << mu_S << " " << mu_Q << endl; + << e_local * hbarc << " " << nB_local << " " + << pressure << " " << entropy << " " << temperature + << " " << mu_B << " " << mu_S << " " << mu_Q << endl; } } check_file9.close(); diff --git a/src/eos_base.h b/src/eos_base.h index 525ea0ad..e85bc556 100644 --- a/src/eos_base.h +++ b/src/eos_base.h @@ -3,13 +3,13 @@ #ifndef SRC_EOS_BASE_H_ #define SRC_EOS_BASE_H_ -#include "pretty_ostream.h" - #include #include +#include "pretty_ostream.h" + class EOS_base { - private: + private: int whichEOS; int number_of_tables; double eps_max; @@ -17,7 +17,7 @@ class EOS_base { bool flag_muS; bool flag_muQ; - public: + public: pretty_ostream music_message; std::vector nb_bounds; std::vector e_bounds; @@ -39,69 +39,78 @@ class EOS_base { std::string get_hydro_env_path() const; - void set_number_of_tables(int ntables) {number_of_tables = ntables;} - int get_number_of_tables() const {return(number_of_tables);} + void set_number_of_tables(int ntables) { number_of_tables = ntables; } + int get_number_of_tables() const { return (number_of_tables); } void resize_table_info_arrays(); - void set_EOS_id(int eos_id) {whichEOS = eos_id;} - int get_EOS_id() const {return(whichEOS);} + void set_EOS_id(int eos_id) { whichEOS = eos_id; } + int get_EOS_id() const { return (whichEOS); } - void set_flag_muB(bool flag_muB_in) {flag_muB = flag_muB_in;} - bool get_flag_muB() const {return(flag_muB);} - void set_flag_muS(bool flag_muS_in) {flag_muS = flag_muS_in;} - bool get_flag_muS() const {return(flag_muS);} - void set_flag_muQ(bool flag_muQ_in) {flag_muQ = flag_muQ_in;} - bool get_flag_muQ() const {return(flag_muQ);} + void set_flag_muB(bool flag_muB_in) { flag_muB = flag_muB_in; } + bool get_flag_muB() const { return (flag_muB); } + void set_flag_muS(bool flag_muS_in) { flag_muS = flag_muS_in; } + bool get_flag_muS() const { return (flag_muS); } + void set_flag_muQ(bool flag_muQ_in) { flag_muQ = flag_muQ_in; } + bool get_flag_muQ() const { return (flag_muQ); } // returns maximum local energy density of the EoS table // in the unit of [1/fm^4] - void set_eps_max(double eps_max_in) {eps_max = eps_max_in;} - double get_eps_max() const {return(eps_max);} + void set_eps_max(double eps_max_in) { eps_max = eps_max_in; } + double get_eps_max() const { return (eps_max); } double interpolate1D(double e, int table_idx, double ***table) const; - void interpolate1D_with_gradients(double e, int table_idx, double ***table, - double &p, double &dpde) const; - double interpolate2D(const double e, const double rhob, - const int table_idx, double ***table) const; - void interpolate2D_with_gradients(const double e, const double rhob, - const int table_idx, double ***table, - double &p, double &dpde, double &dpdrhob) const; - - int get_table_idx(double e) const; - double get_entropy (double epsilon, double rhob) const; - void getThermalVariables(double epsilon, double rhob, - std::vector &thermalVec) const; + void interpolate1D_with_gradients( + double e, int table_idx, double ***table, double &p, + double &dpde) const; + double interpolate2D( + const double e, const double rhob, const int table_idx, + double ***table) const; + void interpolate2D_with_gradients( + const double e, const double rhob, const int table_idx, double ***table, + double &p, double &dpde, double &dpdrhob) const; + + int get_table_idx(double e) const; + double get_entropy(double epsilon, double rhob) const; + void getThermalVariables( + double epsilon, double rhob, std::vector &thermalVec) const; double calculate_velocity_of_sound_sq(double e, double rhob) const; double get_dpOverde3(double e, double rhob) const; double get_dpOverdrhob2(double e, double rhob) const; double get_s2e_finite_rhob(double s, double rhob) const; double get_T2e_finite_rhob(const double T, const double rhob) const; - void map_TmuB2erhoB(const double T, const double muB, - double &e, double &rhob) const; - - virtual void initialize_eos () {} - virtual void initialize_eos (int eos_id_in) {} - virtual double get_cs2 (double e, double rhob) const; - virtual double p_rho_func (double e, double rhob) const {return(0.0);} - virtual double p_e_func (double e, double rhob) const {return(0.0);} - virtual double get_temperature(double epsilon, double rhob) const {return(0.0);} - virtual double get_muB (double epsilon, double rhob) const {return(0.0);} - virtual double get_muS (double epsilon, double rhob) const {return(0.0);} - virtual double get_muQ (double epsilon, double rhob) const {return(0.0);} - virtual double get_rhoS (double epsilon, double rhob) const {return(0.0);} - virtual double get_rhoQ (double epsilon, double rhob) const {return(0.4*rhob);} - virtual double get_pressure (double epsilon, double rhob) const {return(0.0);} - virtual double get_s2e (double s, double rhob) const {return(0.0);} - virtual double get_T2e (double T_in_GeV, double rhob) const {return(0.0);} - virtual void check_eos () const {} - - virtual void get_pressure_with_gradients(double epsilon, double rhob, - double &p, double &dpde, double &dpdrhob, double &cs2) const { + void map_TmuB2erhoB( + const double T, const double muB, double &e, double &rhob) const; + + virtual void initialize_eos() {} + virtual void initialize_eos(int eos_id_in) {} + virtual double get_cs2(double e, double rhob) const; + virtual double p_rho_func(double e, double rhob) const { return (0.0); } + virtual double p_e_func(double e, double rhob) const { return (0.0); } + virtual double get_temperature(double epsilon, double rhob) const { + return (0.0); + } + virtual double get_muB(double epsilon, double rhob) const { return (0.0); } + virtual double get_muS(double epsilon, double rhob) const { return (0.0); } + virtual double get_muQ(double epsilon, double rhob) const { return (0.0); } + virtual double get_rhoS(double epsilon, double rhob) const { return (0.0); } + virtual double get_rhoQ(double epsilon, double rhob) const { + return (0.4 * rhob); + } + virtual double get_pressure(double epsilon, double rhob) const { + return (0.0); + } + virtual double get_s2e(double s, double rhob) const { return (0.0); } + virtual double get_T2e(double T_in_GeV, double rhob) const { return (0.0); } + virtual void check_eos() const {} + + virtual void get_pressure_with_gradients( + double epsilon, double rhob, double &p, double &dpde, double &dpdrhob, + double &cs2) const { p = get_pressure(epsilon, rhob); dpde = get_dpOverde3(epsilon, rhob); dpdrhob = get_dpOverdrhob2(epsilon, rhob); - cs2 = dpde + dpdrhob*rhob/(epsilon + p); + cs2 = dpde + dpdrhob * rhob / (epsilon + p); } void check_eos_with_finite_muB() const; @@ -109,5 +118,4 @@ class EOS_base { void outputMutable() const; }; - #endif // SRC_EOS_BASE_H_ diff --git a/src/eos_best.cpp b/src/eos_best.cpp index 2bdadecb..5162ec3e 100644 --- a/src/eos_best.cpp +++ b/src/eos_best.cpp @@ -1,15 +1,16 @@ // Copyright 2018 @ Chun Shen #include "eos_best.h" -#include "util.h" -#include +#include #include #include -#include +#include + +#include "util.h" -using std::stringstream; using std::string; +using std::stringstream; EOS_BEST::EOS_BEST() { set_EOS_id(17); @@ -17,49 +18,48 @@ EOS_BEST::EOS_BEST() { set_eps_max(1e5); } - EOS_BEST::~EOS_BEST() { int ntables = get_number_of_tables(); for (int itable = 0; itable < ntables; itable++) { - Util::mtx_free(mu_B_tb[itable], - nb_length[itable], e_length[itable]); + Util::mtx_free(mu_B_tb[itable], nb_length[itable], e_length[itable]); } delete[] mu_B_tb; } - void EOS_BEST::initialize_eos() { - // read the lattice EOS pressure, temperature, and - music_message.info("Using lattice EOS at finite muB from the BEST Collaboration"); + // read the lattice EOS pressure, temperature, and + music_message.info( + "Using lattice EOS at finite muB from the BEST Collaboration"); music_message.info("reading EOS BEST ..."); - + stringstream slocalpath; slocalpath << "./EOS/BEST/"; string path = slocalpath.str(); music_message << "from path " << path; music_message.flush("info"); - + const int ntables = 6; set_number_of_tables(ntables); resize_table_info_arrays(); string eos_file_string_array[6] = {"0", "1", "2", "3", "4", "5"}; - pressure_tb = new double** [ntables]; - temperature_tb = new double** [ntables]; - mu_B_tb = new double** [ntables]; + pressure_tb = new double **[ntables]; + temperature_tb = new double **[ntables]; + mu_B_tb = new double **[ntables]; for (int itable = 0; itable < ntables; itable++) { - std::ifstream eos_p(path + "BEST_eos_p_" - + eos_file_string_array[itable] + ".dat"); - std::ifstream eos_T(path + "BEST_eos_T_" - + eos_file_string_array[itable] + ".dat"); - std::ifstream eos_mub(path + "BEST_eos_muB_" - + eos_file_string_array[itable] + ".dat"); - + std::ifstream eos_p( + path + "BEST_eos_p_" + eos_file_string_array[itable] + ".dat"); + std::ifstream eos_T( + path + "BEST_eos_T_" + eos_file_string_array[itable] + ".dat"); + std::ifstream eos_mub( + path + "BEST_eos_muB_" + eos_file_string_array[itable] + ".dat"); + if (!eos_p) { music_message << "Can not found the EoS file! filename: " - << path + "BEST_eos_p_" << eos_file_string_array[itable] + ".dat"; + << path + "BEST_eos_p_" + << eos_file_string_array[itable] + ".dat"; music_message.flush("error"); exit(1); } @@ -70,19 +70,18 @@ void EOS_BEST::initialize_eos() { ss << dummy; // read the first line with general info: ss >> dummy >> dummy >> e_bounds[itable] >> dummy >> e_spacing[itable] - >> dummy >> e_length[itable] >> dummy >> nb_bounds[itable] - >> dummy >> nb_spacing[itable] >> dummy >> nb_length[itable]; + >> dummy >> e_length[itable] >> dummy >> nb_bounds[itable] >> dummy + >> nb_spacing[itable] >> dummy >> nb_length[itable]; - e_bounds[itable] /= Util::hbarc; // 1/fm^4 - e_spacing[itable] /= Util::hbarc; // 1/fm^4 + e_bounds[itable] /= Util::hbarc; // 1/fm^4 + e_spacing[itable] /= Util::hbarc; // 1/fm^4 // allocate memory for EOS arrays - pressure_tb[itable] = Util::mtx_malloc(nb_length[itable], - e_length[itable]); - temperature_tb[itable] = Util::mtx_malloc(nb_length[itable], - e_length[itable]); - mu_B_tb[itable] = Util::mtx_malloc(nb_length[itable], - e_length[itable]); + pressure_tb[itable] = + Util::mtx_malloc(nb_length[itable], e_length[itable]); + temperature_tb[itable] = + Util::mtx_malloc(nb_length[itable], e_length[itable]); + mu_B_tb[itable] = Util::mtx_malloc(nb_length[itable], e_length[itable]); // read pressure, temperature and chemical potential values for (int j = 0; j < e_length[itable]; j++) { @@ -91,61 +90,58 @@ void EOS_BEST::initialize_eos() { eos_T >> temperature_tb[itable][i][j]; eos_mub >> mu_B_tb[itable][i][j]; - pressure_tb[itable][i][j] /= Util::hbarc; // 1/fm^4 - temperature_tb[itable][i][j] /= Util::hbarc; // 1/fm - mu_B_tb[itable][i][j] /= Util::hbarc; // 1/fm + pressure_tb[itable][i][j] /= Util::hbarc; // 1/fm^4 + temperature_tb[itable][i][j] /= Util::hbarc; // 1/fm + mu_B_tb[itable][i][j] /= Util::hbarc; // 1/fm } } } - - double eps_max_in = e_bounds[5] + e_spacing[5]*e_length[5]; + + double eps_max_in = e_bounds[5] + e_spacing[5] * e_length[5]; set_eps_max(eps_max_in); music_message.info("Done reading EOS."); } - double EOS_BEST::p_e_func(double e, double rhob) const { - return(get_dpOverde3(e, rhob)); + return (get_dpOverde3(e, rhob)); } - double EOS_BEST::p_rho_func(double e, double rhob) const { - return(get_dpOverdrhob2(e, rhob)); + return (get_dpOverdrhob2(e, rhob)); } - //! This function returns the local temperature in [1/fm] //! input local energy density eps [1/fm^4] and rhob [1/fm^3] double EOS_BEST::get_temperature(double e, double rhob) const { int table_idx = get_table_idx(e); - double T = interpolate2D(e, std::abs(rhob), table_idx, - temperature_tb); // 1/fm - return(T); + double T = interpolate2D( + e, std::abs(rhob), table_idx, + temperature_tb); // 1/fm + return (T); } - //! This function returns the local pressure in [1/fm^4] //! the input local energy density [1/fm^4], rhob [1/fm^3] double EOS_BEST::get_pressure(double e, double rhob) const { int table_idx = get_table_idx(e); double f = interpolate2D(e, std::abs(rhob), table_idx, pressure_tb); - return(f); + return (f); } - //! This function returns the local baryon chemical potential mu_B in [1/fm] //! input local energy density eps [1/fm^4] and rhob [1/fm^3] double EOS_BEST::get_muB(double e, double rhob) const { int table_idx = get_table_idx(e); - double sign = rhob/(std::abs(rhob) + Util::small_eps); - double mu = sign*interpolate2D(e, std::abs(rhob), table_idx, - mu_B_tb); // 1/fm - return(mu); + double sign = rhob / (std::abs(rhob) + Util::small_eps); + double mu = sign + * interpolate2D( + e, std::abs(rhob), table_idx, + mu_B_tb); // 1/fm + return (mu); } - double EOS_BEST::get_s2e(double s, double rhob) const { double e = get_s2e_finite_rhob(s, rhob); - return(e); + return (e); } diff --git a/src/eos_best.h b/src/eos_best.h index 530a1b56..824ce762 100644 --- a/src/eos_best.h +++ b/src/eos_best.h @@ -6,21 +6,20 @@ #include "eos_base.h" class EOS_BEST : public EOS_base { - private: - - public: + private: + public: EOS_BEST(); ~EOS_BEST(); void initialize_eos(); - double p_rho_func (double e, double rhob) const; - double p_e_func (double e, double rhob) const; + double p_rho_func(double e, double rhob) const; + double p_e_func(double e, double rhob) const; double get_temperature(double e, double rhob) const; - double get_muB (double e, double rhob) const; - double get_pressure (double e, double rhob) const; - double get_s2e (double s, double rhob) const; + double get_muB(double e, double rhob) const; + double get_pressure(double e, double rhob) const; + double get_s2e(double s, double rhob) const; - void check_eos() const {check_eos_with_finite_muB();} + void check_eos() const { check_eos_with_finite_muB(); } }; #endif // SRC_EOS_BEST_H_ diff --git a/src/eos_hotQCD.cpp b/src/eos_hotQCD.cpp index bf3384bd..70a0e34d 100644 --- a/src/eos_hotQCD.cpp +++ b/src/eos_hotQCD.cpp @@ -1,14 +1,15 @@ // Copyright 2018 @ Chun Shen #include "eos_hotQCD.h" -#include "util.h" -#include -#include #include +#include +#include + +#include "util.h" -using std::stringstream; using std::string; +using std::stringstream; EOS_hotQCD::EOS_hotQCD(const int eos_id_in) : eos_id(eos_id_in) { set_EOS_id(eos_id); @@ -19,9 +20,8 @@ EOS_hotQCD::EOS_hotQCD(const int eos_id_in) : eos_id(eos_id_in) { set_flag_muQ(false); } - void EOS_hotQCD::initialize_eos() { - // read the lattice EOS pressure, temperature, and + // read the lattice EOS pressure, temperature, and music_message.info("reading EOS hotQCD ..."); auto envPath = get_hydro_env_path(); @@ -37,16 +37,16 @@ void EOS_hotQCD::initialize_eos() { int ntables = get_number_of_tables(); - pressure_tb = new double** [ntables]; - temperature_tb = new double** [ntables]; + pressure_tb = new double **[ntables]; + temperature_tb = new double **[ntables]; for (int itable = 0; itable < ntables; itable++) { std::ifstream eos_file; if (eos_id == 9) { - eos_file.open(path + "/hrg_hotqcd_eos_binary.dat", - std::ios::binary); + eos_file.open( + path + "/hrg_hotqcd_eos_binary.dat", std::ios::binary); } else if (eos_id == 91) { - eos_file.open(path + "/hrg_hotqcd_eos_SMASH_binary.dat", - std::ios::binary); + eos_file.open( + path + "/hrg_hotqcd_eos_SMASH_binary.dat", std::ios::binary); } if (!eos_file) { @@ -54,28 +54,28 @@ void EOS_hotQCD::initialize_eos() { exit(1); } - e_length[itable] = 100000; + e_length[itable] = 100000; nb_length[itable] = 1; // allocate memory for pressure arrays - pressure_tb[itable] = Util::mtx_malloc(nb_length[itable], - e_length[itable]); - temperature_tb[itable] = Util::mtx_malloc(nb_length[itable], - e_length[itable]); + pressure_tb[itable] = + Util::mtx_malloc(nb_length[itable], e_length[itable]); + temperature_tb[itable] = + Util::mtx_malloc(nb_length[itable], e_length[itable]); double temp; for (int ii = 0; ii < e_length[itable]; ii++) { - eos_file.read((char*)&temp, sizeof(double)); // e - temp /= Util::hbarc; // 1/fm^4 + eos_file.read((char *)&temp, sizeof(double)); // e + temp /= Util::hbarc; // 1/fm^4 if (ii == 0) e_bounds[itable] = temp; if (ii == 1) e_spacing[itable] = temp - e_bounds[itable]; if (ii == e_length[itable] - 1) set_eps_max(temp); - eos_file.read((char*)&temp, sizeof(double)); // P - pressure_tb[itable][0][ii] = temp/Util::hbarc; // 1/fm^4 + eos_file.read((char *)&temp, sizeof(double)); // P + pressure_tb[itable][0][ii] = temp / Util::hbarc; // 1/fm^4 - eos_file.read((char*)&temp, sizeof(double)); // s + eos_file.read((char *)&temp, sizeof(double)); // s - eos_file.read((char*)&temp, sizeof(double)); // T - temp /= Util::hbarc; // 1/fm + eos_file.read((char *)&temp, sizeof(double)); // T + temp /= Util::hbarc; // 1/fm // store T^5 // scaling with T^5 seems to be the best to get a smooth curve temperature_tb[itable][0][ii] = pow(temp, 5); @@ -84,46 +84,42 @@ void EOS_hotQCD::initialize_eos() { music_message.info("Done reading EOS."); } - double EOS_hotQCD::p_e_func(double e, double rhob) const { - return(get_dpOverde3(e, rhob)); + return (get_dpOverde3(e, rhob)); } - //! This function returns the local temperature in [1/fm] //! input local energy density eps [1/fm^4] and rhob [1/fm^3] double EOS_hotQCD::get_temperature(double e, double rhob) const { double T5 = interpolate1D(e, 0, temperature_tb); // e/T^5 - double T = pow(T5, 0.2); // 1/fm - return(std::max(Util::small_eps, T)); + double T = pow(T5, 0.2); // 1/fm + return (std::max(Util::small_eps, T)); } - //! This function returns the local pressure in [1/fm^4] //! the input local energy density [1/fm^4], rhob [1/fm^3] double EOS_hotQCD::get_pressure(double e, double rhob) const { double f = interpolate1D(e, 0, pressure_tb); // 1/fm^4 - return(std::max(Util::small_eps, f)); + return (std::max(Util::small_eps, f)); } - //! This function returns the local pressure in [1/fm^4] //! the input local energy density [1/fm^4], rhob [1/fm^3] -void EOS_hotQCD::get_pressure_with_gradients(double e, double rhob, - double &p, double &dpde, double &dpdrhob, double &cs2) const { +void EOS_hotQCD::get_pressure_with_gradients( + double e, double rhob, double &p, double &dpde, double &dpdrhob, + double &cs2) const { interpolate1D_with_gradients(e, 0, pressure_tb, p, dpde); - p = std::max(Util::small_eps, p); // [1/fm^4] + p = std::max(Util::small_eps, p); // [1/fm^4] dpdrhob = 0.; - cs2 = std::max(0.01, std::min(1./3., dpde)); + cs2 = std::max(0.01, std::min(1. / 3., dpde)); } - double EOS_hotQCD::get_s2e(double s, double rhob) const { double e = get_s2e_finite_rhob(s, 0.0); - return(e); + return (e); } double EOS_hotQCD::get_T2e(double T_in_GeV, double rhob) const { double e = get_T2e_finite_rhob(T_in_GeV, 0.0); - return(e); + return (e); } diff --git a/src/eos_hotQCD.h b/src/eos_hotQCD.h index f635bb83..78795ac6 100644 --- a/src/eos_hotQCD.h +++ b/src/eos_hotQCD.h @@ -6,22 +6,23 @@ #include "eos_base.h" class EOS_hotQCD : public EOS_base { - private: + private: const int eos_id; - public: + public: EOS_hotQCD(const int eos_id_in); void initialize_eos(); - double p_e_func (double e, double rhob) const; + double p_e_func(double e, double rhob) const; double get_temperature(double e, double rhob) const; - double get_pressure (double e, double rhob) const; - double get_s2e (double s, double rhob) const; - double get_T2e (double T, double rhob) const; - void get_pressure_with_gradients(double e, double rhob, - double &p, double &dpde, double &dpdrhob, double &cs2) const; + double get_pressure(double e, double rhob) const; + double get_s2e(double s, double rhob) const; + double get_T2e(double T, double rhob) const; + void get_pressure_with_gradients( + double e, double rhob, double &p, double &dpde, double &dpdrhob, + double &cs2) const; - void check_eos() const {check_eos_no_muB();} + void check_eos() const { check_eos_no_muB(); } }; #endif // SRC_EOS_hotQCD_H_ diff --git a/src/eos_hotQCD_unitetest.cpp b/src/eos_hotQCD_unitetest.cpp index 7340bb38..55de3ba5 100644 --- a/src/eos_hotQCD_unitetest.cpp +++ b/src/eos_hotQCD_unitetest.cpp @@ -1,18 +1,17 @@ // Copyright 2018 @ Chun Shen -#include "eos_hotQCD.h" -#include "doctest.h" - #include #include +#include "doctest.h" +#include "eos_hotQCD.h" + TEST_CASE("test constructor") { EOS_hotQCD test; CHECK(test.get_EOS_id() == 9); CHECK(test.get_number_of_tables() == 0); } - TEST_CASE("test initialize eos") { EOS_hotQCD test; test.initialize_eos(); @@ -20,7 +19,6 @@ TEST_CASE("test initialize eos") { CHECK(test.get_eps_max() == doctest::Approx(769.82367).epsilon(0.0001)); } - TEST_CASE("test speed of sound squared") { // speed of sound squared is a constant 1/3 EOS_hotQCD test; @@ -28,45 +26,35 @@ TEST_CASE("test speed of sound squared") { CHECK(test.get_cs2(1.0, 0.0) == doctest::Approx(0.15963).epsilon(0.0001)); CHECK(test.get_cs2(1.0, 2.0) == doctest::Approx(0.15963).epsilon(0.0001)); CHECK(test.get_cs2(1.0, -3.0) == doctest::Approx(0.15963).epsilon(0.0001)); - } - TEST_CASE("test dPdrho") { // dPdrho = 0. EOS_hotQCD test; - CHECK(test.p_rho_func(1.0, 1.0) == 0.); - CHECK(test.p_rho_func(2.0, 1.0) == 0.); + CHECK(test.p_rho_func(1.0, 1.0) == 0.); + CHECK(test.p_rho_func(2.0, 1.0) == 0.); CHECK(test.p_rho_func(1.0, -1.0) == 0.); } - -TEST_CASE("test dPde") { - EOS_hotQCD test; -} - +TEST_CASE("test dPde") { EOS_hotQCD test; } TEST_CASE("test muB") { // muB = 0.0 EOS_hotQCD test; - CHECK(test.get_mu(1.0, 1.0) == 0.); - CHECK(test.get_mu(2.0, 1.0) == 0.); + CHECK(test.get_mu(1.0, 1.0) == 0.); + CHECK(test.get_mu(2.0, 1.0) == 0.); CHECK(test.get_mu(1.0, -1.0) == 0.); } - TEST_CASE("test muS") { // muS = 0.0 EOS_hotQCD test; - CHECK(test.get_muS(1.0, 1.0) == 0.); - CHECK(test.get_muS(2.0, 1.0) == 0.); + CHECK(test.get_muS(1.0, 1.0) == 0.); + CHECK(test.get_muS(2.0, 1.0) == 0.); CHECK(test.get_muS(1.0, -1.0) == 0.); } - -TEST_CASE("test pressure") { - EOS_hotQCD test; -} +TEST_CASE("test pressure") { EOS_hotQCD test; } TEST_CASE("check eos") { EOS_hotQCD test; diff --git a/src/eos_idealgas.cpp b/src/eos_idealgas.cpp index 1b7deaf5..37f65233 100644 --- a/src/eos_idealgas.cpp +++ b/src/eos_idealgas.cpp @@ -19,20 +19,30 @@ void EOS_idealgas::initialize_eos() { } double EOS_idealgas::get_temperature(double eps, double rhob) const { - return pow(90.0/M_PI/M_PI*(eps/3.0)/(2*(Nc*Nc-1)+7./2*Nc*Nf), .25); + return pow( + 90.0 / M_PI / M_PI * (eps / 3.0) + / (2 * (Nc * Nc - 1) + 7. / 2 * Nc * Nf), + .25); } double EOS_idealgas::get_s2e(double s, double rhob) const { - return(3./4.*s*pow(3.*s/4./(M_PI*M_PI*3.0*(2*(Nc*Nc-1)+7./2*Nc*Nf)/90.0), 1./3.)); // in 1/fm^4 + return ( + 3. / 4. * s + * pow( + 3. * s / 4. + / (M_PI * M_PI * 3.0 * (2 * (Nc * Nc - 1) + 7. / 2 * Nc * Nf) + / 90.0), + 1. / 3.)); // in 1/fm^4 } double EOS_idealgas::get_muB(double e, double rhob) const { double T_local = get_temperature(e, rhob); - double mu_B = 5.*rhob/(T_local*T_local); // [1/fm] - return(mu_B); + double mu_B = 5. * rhob / (T_local * T_local); // [1/fm] + return (mu_B); } double EOS_idealgas::get_T2e(double T_in_GeV, double rhob) const { - double T_in_fm=T_in_GeV/Util::hbarc; - return 3*T_in_fm*T_in_fm*T_in_fm*T_in_fm*M_PI*M_PI/90*(2*(Nc*Nc-1)+7./2*Nc*Nf); + double T_in_fm = T_in_GeV / Util::hbarc; + return 3 * T_in_fm * T_in_fm * T_in_fm * T_in_fm * M_PI * M_PI / 90 + * (2 * (Nc * Nc - 1) + 7. / 2 * Nc * Nf); } diff --git a/src/eos_idealgas.h b/src/eos_idealgas.h index 3d7f5839..ea5bbbb7 100644 --- a/src/eos_idealgas.h +++ b/src/eos_idealgas.h @@ -7,35 +7,39 @@ #include "util.h" class EOS_idealgas : public EOS_base { - private: - double Nc; - double Nf; + private: + double Nc; + double Nf; - public: + public: EOS_idealgas(); ~EOS_idealgas() {} - void set_Nc_and_Nf(double Nc_in, double Nf_in) {Nc = Nc_in; Nf = Nf_in;} + void set_Nc_and_Nf(double Nc_in, double Nf_in) { + Nc = Nc_in; + Nf = Nf_in; + } - void initialize_eos(); - double get_cs2 (double e, double rhob) const {return(1./3.);} - double p_rho_func (double e, double rhob) const {return(0.0);} - double p_e_func (double e, double rhob) const {return(1./3.);} + void initialize_eos(); + double get_cs2(double e, double rhob) const { return (1. / 3.); } + double p_rho_func(double e, double rhob) const { return (0.0); } + double p_e_func(double e, double rhob) const { return (1. / 3.); } double get_temperature(double e, double rhob) const; - double get_muB (double e, double rhob) const; - double get_muS (double e, double rhob) const {return(0.0);} - double get_pressure (double e, double rhob) const {return(1./3.*e);} - double get_s2e (double s, double rhob) const; - double get_T2e (double T_in_GeV, double rhob) const; - virtual void get_pressure_with_gradients(double epsilon, double rhob, - double &p, double &dpde, double &dpdrhob, double &cs2) const { - dpde = 1/3.; - p = dpde*epsilon; + double get_muB(double e, double rhob) const; + double get_muS(double e, double rhob) const { return (0.0); } + double get_pressure(double e, double rhob) const { return (1. / 3. * e); } + double get_s2e(double s, double rhob) const; + double get_T2e(double T_in_GeV, double rhob) const; + virtual void get_pressure_with_gradients( + double epsilon, double rhob, double &p, double &dpde, double &dpdrhob, + double &cs2) const { + dpde = 1 / 3.; + p = dpde * epsilon; dpdrhob = 0.; cs2 = dpde; } - void check_eos() const {check_eos_no_muB();} + void check_eos() const { check_eos_no_muB(); } }; #endif // SRC_EOS_IDEALGAS_H_ diff --git a/src/eos_idealgas_unittest.cpp b/src/eos_idealgas_unittest.cpp index 8c66ea77..7efdde05 100644 --- a/src/eos_idealgas_unittest.cpp +++ b/src/eos_idealgas_unittest.cpp @@ -1,66 +1,61 @@ // Copyright 2018 @ Chun Shen #include "eos_idealgas.h" -#include "doctest.h" #include #include +#include "doctest.h" + TEST_CASE("test constructor") { EOS_idealgas test; CHECK(test.get_EOS_id() == 0); CHECK(test.get_number_of_tables() == 0); } - TEST_CASE("test speed of sound squared") { // speed of sound squared is a constant 1/3 EOS_idealgas test; - CHECK(test.get_cs2(1.0, 1.0) == 1./3.); - CHECK(test.get_cs2(2.0, 1.0) == 1./3.); - CHECK(test.get_cs2(1.0, -1.0) == 1./3.); + CHECK(test.get_cs2(1.0, 1.0) == 1. / 3.); + CHECK(test.get_cs2(2.0, 1.0) == 1. / 3.); + CHECK(test.get_cs2(1.0, -1.0) == 1. / 3.); } - TEST_CASE("test dPdrho") { // dPdrho = 0. EOS_idealgas test; - CHECK(test.p_rho_func(1.0, 1.0) == 0.); - CHECK(test.p_rho_func(2.0, 1.0) == 0.); + CHECK(test.p_rho_func(1.0, 1.0) == 0.); + CHECK(test.p_rho_func(2.0, 1.0) == 0.); CHECK(test.p_rho_func(1.0, -1.0) == 0.); } - TEST_CASE("test dPde") { // dPdrho = 1/3. EOS_idealgas test; - CHECK(test.p_e_func(1.0, 1.0) == 1./3.); - CHECK(test.p_e_func(2.0, 1.0) == 1./3.); - CHECK(test.p_e_func(1.0, -1.0) == 1./3.); + CHECK(test.p_e_func(1.0, 1.0) == 1. / 3.); + CHECK(test.p_e_func(2.0, 1.0) == 1. / 3.); + CHECK(test.p_e_func(1.0, -1.0) == 1. / 3.); } - TEST_CASE("test muB") { // muB = 0.0 EOS_idealgas test; - CHECK(test.get_mu(1.0, 1.0) == 0.); - CHECK(test.get_mu(2.0, 1.0) == 0.); + CHECK(test.get_mu(1.0, 1.0) == 0.); + CHECK(test.get_mu(2.0, 1.0) == 0.); CHECK(test.get_mu(1.0, -1.0) == 0.); } - TEST_CASE("test muS") { // muS = 0.0 EOS_idealgas test; - CHECK(test.get_muS(1.0, 1.0) == 0.); - CHECK(test.get_muS(2.0, 1.0) == 0.); + CHECK(test.get_muS(1.0, 1.0) == 0.); + CHECK(test.get_muS(2.0, 1.0) == 0.); CHECK(test.get_muS(1.0, -1.0) == 0.); } - TEST_CASE("test pressure") { // P = e/3. EOS_idealgas test; - CHECK(test.get_pressure(1.0, 1.0) == 1./3.); - CHECK(test.get_pressure(2.0, 1.0) == 2./3.); - CHECK(test.get_pressure(1.0, -1.0) == 1./3.); + CHECK(test.get_pressure(1.0, 1.0) == 1. / 3.); + CHECK(test.get_pressure(2.0, 1.0) == 2. / 3.); + CHECK(test.get_pressure(1.0, -1.0) == 1. / 3.); } diff --git a/src/eos_neos.cpp b/src/eos_neos.cpp index 5236e1cb..84eb06b6 100644 --- a/src/eos_neos.cpp +++ b/src/eos_neos.cpp @@ -1,14 +1,15 @@ // Copyright 2018 @ Chun Shen #include "eos_neos.h" -#include "util.h" -#include -#include #include +#include +#include + +#include "util.h" -using std::stringstream; using std::string; +using std::stringstream; EOS_neos::EOS_neos(const int eos_id_in) : eos_id(eos_id_in) { set_EOS_id(eos_id); @@ -19,35 +20,32 @@ EOS_neos::EOS_neos(const int eos_id_in) : eos_id(eos_id_in) { set_flag_muQ(false); } - EOS_neos::~EOS_neos() { int ntables = get_number_of_tables(); for (int itable = 0; itable < ntables; itable++) { - Util::mtx_free(mu_B_tb[itable], - nb_length[itable], e_length[itable]); + Util::mtx_free(mu_B_tb[itable], nb_length[itable], e_length[itable]); if (get_flag_muS()) { - Util::mtx_free(mu_S_tb[itable], - nb_length[itable], e_length[itable]); + Util::mtx_free( + mu_S_tb[itable], nb_length[itable], e_length[itable]); } if (get_flag_muQ()) { - Util::mtx_free(mu_Q_tb[itable], - nb_length[itable], e_length[itable]); + Util::mtx_free( + mu_Q_tb[itable], nb_length[itable], e_length[itable]); } } if (ntables > 0) { - delete [] mu_B_tb; + delete[] mu_B_tb; if (get_flag_muS()) { - delete [] mu_S_tb; + delete[] mu_S_tb; } if (get_flag_muQ()) { - delete [] mu_Q_tb; + delete[] mu_Q_tb; } } } - void EOS_neos::initialize_eos() { - // read the lattice EOS pressure, temperature, and + // read the lattice EOS pressure, temperature, and music_message.info("Using lattice EOS at finite muB from A. Monnai"); auto envPath = get_hydro_env_path(); @@ -61,34 +59,39 @@ void EOS_neos::initialize_eos() { music_message.info("reading EOS neos ..."); spath << "/EOS/neos_2/"; string string_tmp[] = {"0a", "0b", "0c", "1a", "2", "3", "4"}; - std::copy(std::begin(string_tmp), std::end(string_tmp), - std::begin(eos_file_string_array)); + std::copy( + std::begin(string_tmp), std::end(string_tmp), + std::begin(eos_file_string_array)); } else if (eos_id == 11) { music_message.info("reading EOS neos3 ..."); spath << "/EOS/neos_3/"; string string_tmp[] = {"1", "2", "3", "4", "5", "6", "7"}; - std::copy(std::begin(string_tmp), std::end(string_tmp), - std::begin(eos_file_string_array)); + std::copy( + std::begin(string_tmp), std::end(string_tmp), + std::begin(eos_file_string_array)); } else if (eos_id == 12) { music_message.info("reading EOS neos_b ..."); spath << "/EOS/neos_b/"; string string_tmp[] = {"1", "2", "3", "4", "5", "6", "7"}; - std::copy(std::begin(string_tmp), std::end(string_tmp), - std::begin(eos_file_string_array)); + std::copy( + std::begin(string_tmp), std::end(string_tmp), + std::begin(eos_file_string_array)); } else if (eos_id == 13) { music_message.info("reading EOS neos_bs ..."); spath << "/EOS/neos_bs/"; string string_tmp[] = {"1s", "2s", "3s", "4s", "5s", "6s", "7s"}; - std::copy(std::begin(string_tmp), std::end(string_tmp), - std::begin(eos_file_string_array)); + std::copy( + std::begin(string_tmp), std::end(string_tmp), + std::begin(eos_file_string_array)); flag_muS = true; set_flag_muS(flag_muS); } else if (eos_id == 14) { music_message.info("reading EOS neos_bqs ..."); spath << "/EOS/neos_bqs/"; string string_tmp[] = {"1qs", "2qs", "3qs", "4qs", "5qs", "6qs", "7qs"}; - std::copy(std::begin(string_tmp), std::end(string_tmp), - std::begin(eos_file_string_array)); + std::copy( + std::begin(string_tmp), std::end(string_tmp), + std::begin(eos_file_string_array)); flag_muS = true; flag_muQ = true; set_flag_muS(flag_muS); @@ -97,8 +100,9 @@ void EOS_neos::initialize_eos() { music_message.info("reading EOS neos_bqs ..."); spath << "/EOS/neos_bqs_muB0.9/"; string string_tmp[] = {"1qs", "2qs", "3qs", "4qs", "5qs", "6qs", "7qs"}; - std::copy(std::begin(string_tmp), std::end(string_tmp), - std::begin(eos_file_string_array)); + std::copy( + std::begin(string_tmp), std::end(string_tmp), + std::begin(eos_file_string_array)); flag_muS = true; flag_muQ = true; set_flag_muS(flag_muS); @@ -113,19 +117,19 @@ void EOS_neos::initialize_eos() { set_number_of_tables(ntables); resize_table_info_arrays(); - pressure_tb = new double** [ntables]; - temperature_tb = new double** [ntables]; - mu_B_tb = new double** [ntables]; + pressure_tb = new double**[ntables]; + temperature_tb = new double**[ntables]; + mu_B_tb = new double**[ntables]; if (flag_muS) { - mu_S_tb = new double** [ntables]; + mu_S_tb = new double**[ntables]; } if (flag_muQ) { - mu_Q_tb = new double** [ntables]; + mu_Q_tb = new double**[ntables]; } for (int itable = 0; itable < ntables; itable++) { - std::ifstream eos_p(path + "neos" + eos_file_string_array[itable] - + "_p.dat"); + std::ifstream eos_p( + path + "neos" + eos_file_string_array[itable] + "_p.dat"); if (!eos_p.is_open()) { music_message << "Can not open EOS files: " << (path + "neos" + eos_file_string_array[itable] @@ -133,15 +137,15 @@ void EOS_neos::initialize_eos() { music_message.flush("error"); exit(1); } - std::ifstream eos_T(path + "neos" + eos_file_string_array[itable] - + "_t.dat"); - std::ifstream eos_mub(path + "neos" + eos_file_string_array[itable] - + "_mub.dat"); + std::ifstream eos_T( + path + "neos" + eos_file_string_array[itable] + "_t.dat"); + std::ifstream eos_mub( + path + "neos" + eos_file_string_array[itable] + "_mub.dat"); std::ifstream eos_muS; std::ifstream eos_muQ; if (flag_muS) { - eos_muS.open(path + "neos" + eos_file_string_array[itable] - + "_mus.dat"); + eos_muS.open( + path + "neos" + eos_file_string_array[itable] + "_mus.dat"); if (!eos_muS.is_open()) { music_message << "Can not open EOS files: " << (path + "neos" + eos_file_string_array[itable] @@ -151,8 +155,8 @@ void EOS_neos::initialize_eos() { } } if (flag_muQ) { - eos_muQ.open(path + "neos" + eos_file_string_array[itable] - + "_muq.dat"); + eos_muQ.open( + path + "neos" + eos_file_string_array[itable] + "_muq.dat"); if (!eos_muQ.is_open()) { music_message << "Can not open EOS files: " << (path + "neos" + eos_file_string_array[itable] @@ -168,13 +172,12 @@ void EOS_neos::initialize_eos() { // (number of rhob points + 1, number of epsilon points + 1) int N_e, N_rhob; eos_p >> nb_bounds[itable] >> e_bounds[itable]; - eos_p >> nb_spacing[itable] >> e_spacing[itable] - >> N_rhob >> N_e; + eos_p >> nb_spacing[itable] >> e_spacing[itable] >> N_rhob >> N_e; nb_length[itable] = N_rhob + 1; - e_length[itable] = N_e + 1; + e_length[itable] = N_e + 1; - e_bounds[itable] /= Util::hbarc; // 1/fm^4 - e_spacing[itable] /= Util::hbarc; // 1/fm^4 + e_bounds[itable] /= Util::hbarc; // 1/fm^4 + e_spacing[itable] /= Util::hbarc; // 1/fm^4 // skip the header in T and mu_B files string dummy; @@ -192,19 +195,18 @@ void EOS_neos::initialize_eos() { } // allocate memory for EOS arrays - pressure_tb[itable] = Util::mtx_malloc(nb_length[itable], - e_length[itable]); - temperature_tb[itable] = Util::mtx_malloc(nb_length[itable], - e_length[itable]); - mu_B_tb[itable] = Util::mtx_malloc(nb_length[itable], - e_length[itable]); + pressure_tb[itable] = + Util::mtx_malloc(nb_length[itable], e_length[itable]); + temperature_tb[itable] = + Util::mtx_malloc(nb_length[itable], e_length[itable]); + mu_B_tb[itable] = Util::mtx_malloc(nb_length[itable], e_length[itable]); if (flag_muS) { - mu_S_tb[itable] = Util::mtx_malloc(nb_length[itable], - e_length[itable]); + mu_S_tb[itable] = + Util::mtx_malloc(nb_length[itable], e_length[itable]); } if (flag_muQ) { - mu_Q_tb[itable] = Util::mtx_malloc(nb_length[itable], - e_length[itable]); + mu_Q_tb[itable] = + Util::mtx_malloc(nb_length[itable], e_length[itable]); } // read pressure, temperature and chemical potential values @@ -216,110 +218,110 @@ void EOS_neos::initialize_eos() { if (flag_muS) { eos_muS >> mu_S_tb[itable][i][j]; - mu_S_tb[itable][i][j] /= Util::hbarc; // 1/fm + mu_S_tb[itable][i][j] /= Util::hbarc; // 1/fm } if (flag_muQ) { eos_muQ >> mu_Q_tb[itable][i][j]; - mu_Q_tb[itable][i][j] /= Util::hbarc; // 1/fm + mu_Q_tb[itable][i][j] /= Util::hbarc; // 1/fm } - pressure_tb[itable][i][j] /= Util::hbarc; // 1/fm^4 - temperature_tb[itable][i][j] /= Util::hbarc; // 1/fm - temperature_tb[itable][i][j] = pow(temperature_tb[itable][i][j], 5.); // 1/fm^5 - mu_B_tb[itable][i][j] /= Util::hbarc; // 1/fm + pressure_tb[itable][i][j] /= Util::hbarc; // 1/fm^4 + temperature_tb[itable][i][j] /= Util::hbarc; // 1/fm + temperature_tb[itable][i][j] = + pow(temperature_tb[itable][i][j], 5.); // 1/fm^5 + mu_B_tb[itable][i][j] /= Util::hbarc; // 1/fm } } } - //double eps_max_in = (e_bounds[6] + e_spacing[6]*e_length[6])/hbarc; - double eps_max_in = e_bounds[6] + e_spacing[6]*e_length[6]; + // double eps_max_in = (e_bounds[6] + e_spacing[6]*e_length[6])/hbarc; + double eps_max_in = e_bounds[6] + e_spacing[6] * e_length[6]; set_eps_max(eps_max_in); music_message.info("Done reading EOS."); } - double EOS_neos::p_e_func(double e, double rhob) const { - return(get_dpOverde3(e, rhob)); + return (get_dpOverde3(e, rhob)); } - double EOS_neos::p_rho_func(double e, double rhob) const { - return(get_dpOverdrhob2(e, rhob)); + return (get_dpOverdrhob2(e, rhob)); } - //! This function returns the local temperature in [1/fm] //! input local energy density eps [1/fm^4] and rhob [1/fm^3] double EOS_neos::get_temperature(double e, double rhob) const { int table_idx = get_table_idx(e); - double T5 = interpolate2D(e, std::abs(rhob), table_idx, - temperature_tb); // 1/fm^5 + double T5 = interpolate2D( + e, std::abs(rhob), table_idx, + temperature_tb); // 1/fm^5 T5 = std::max(Util::small_eps, T5); double T = pow(T5, 0.2); // 1/fm - return(T); + return (T); } - //! This function returns the local pressure in [1/fm^4] //! the input local energy density [1/fm^4], rhob [1/fm^3] double EOS_neos::get_pressure(double e, double rhob) const { int table_idx = get_table_idx(e); double f = interpolate2D(e, std::abs(rhob), table_idx, pressure_tb); f = std::max(Util::small_eps, f); - return(f); + return (f); } - -void EOS_neos::get_pressure_with_gradients(double e, double rhob, - double &p, double &dpde, double &dpdrhob, double &cs2) const { +void EOS_neos::get_pressure_with_gradients( + double e, double rhob, double& p, double& dpde, double& dpdrhob, + double& cs2) const { int table_idx = get_table_idx(e); - interpolate2D_with_gradients(e, std::abs(rhob), table_idx, pressure_tb, - p, dpde, dpdrhob); + interpolate2D_with_gradients( + e, std::abs(rhob), table_idx, pressure_tb, p, dpde, dpdrhob); p = std::max(Util::small_eps, p); - //dpde = std::max(Util::small_eps, dpde); - //dpdrhob = std::max(Util::small_eps, dpdrhob); - cs2 = dpde + rhob/(e + p + Util::small_eps)*dpdrhob; - cs2 = std::max(0.01, std::min(1./3, cs2)); + // dpde = std::max(Util::small_eps, dpde); + // dpdrhob = std::max(Util::small_eps, dpdrhob); + cs2 = dpde + rhob / (e + p + Util::small_eps) * dpdrhob; + cs2 = std::max(0.01, std::min(1. / 3, cs2)); } - //! This function returns the local baryon chemical potential mu_B in [1/fm] //! input local energy density eps [1/fm^4] and rhob [1/fm^3] double EOS_neos::get_muB(double e, double rhob) const { int table_idx = get_table_idx(e); - double sign = rhob/(std::abs(rhob) + Util::small_eps); - double mu = sign*interpolate2D(e, std::abs(rhob), table_idx, - mu_B_tb); // 1/fm - return(mu); + double sign = rhob / (std::abs(rhob) + Util::small_eps); + double mu = sign + * interpolate2D( + e, std::abs(rhob), table_idx, + mu_B_tb); // 1/fm + return (mu); } - //! This function returns the local baryon chemical potential mu_B in [1/fm] //! input local energy density eps [1/fm^4] and rhob [1/fm^3] double EOS_neos::get_muS(double e, double rhob) const { - if (!get_flag_muS()) return(0.0); + if (!get_flag_muS()) return (0.0); int table_idx = get_table_idx(e); - double sign = rhob/(std::abs(rhob) + Util::small_eps); - double mu = sign*interpolate2D(e, std::abs(rhob), table_idx, - mu_S_tb); // 1/fm - return(mu); + double sign = rhob / (std::abs(rhob) + Util::small_eps); + double mu = sign + * interpolate2D( + e, std::abs(rhob), table_idx, + mu_S_tb); // 1/fm + return (mu); } - //! This function returns the local baryon chemical potential mu_B in [1/fm] //! input local energy density eps [1/fm^4] and rhob [1/fm^3] double EOS_neos::get_muQ(double e, double rhob) const { - if (!get_flag_muQ()) return(0.0); + if (!get_flag_muQ()) return (0.0); int table_idx = get_table_idx(e); - double sign = rhob/(std::abs(rhob) + Util::small_eps); - double mu = sign*interpolate2D(e, std::abs(rhob), table_idx, - mu_Q_tb); // 1/fm - return(mu); + double sign = rhob / (std::abs(rhob) + Util::small_eps); + double mu = sign + * interpolate2D( + e, std::abs(rhob), table_idx, + mu_Q_tb); // 1/fm + return (mu); } - double EOS_neos::get_s2e(double s, double rhob) const { double e = get_s2e_finite_rhob(s, rhob); - return(e); + return (e); } diff --git a/src/eos_neos.h b/src/eos_neos.h index 39814ec8..dea910ae 100644 --- a/src/eos_neos.h +++ b/src/eos_neos.h @@ -6,24 +6,25 @@ #include "eos_base.h" class EOS_neos : public EOS_base { - private: + private: const int eos_id; - public: + public: EOS_neos(const int eos_id_in); ~EOS_neos(); void initialize_eos(); - double p_rho_func (double e, double rhob) const; - double p_e_func (double e, double rhob) const; + double p_rho_func(double e, double rhob) const; + double p_e_func(double e, double rhob) const; double get_temperature(double e, double rhob) const; - double get_muB (double e, double rhob) const; - double get_muS (double e, double rhob) const; - double get_muQ (double e, double rhob) const; - double get_pressure (double e, double rhob) const; - double get_s2e (double s, double rhob) const; - void get_pressure_with_gradients(double epsilon, double rhob, - double &p, double &dpde, double &dpdrhob, double &cs2) const; + double get_muB(double e, double rhob) const; + double get_muS(double e, double rhob) const; + double get_muQ(double e, double rhob) const; + double get_pressure(double e, double rhob) const; + double get_s2e(double s, double rhob) const; + void get_pressure_with_gradients( + double epsilon, double rhob, double &p, double &dpde, double &dpdrhob, + double &cs2) const; void check_eos() const { check_eos_with_finite_muB(); diff --git a/src/eos_s95p.cpp b/src/eos_s95p.cpp index 2d2b683c..95a9aed8 100644 --- a/src/eos_s95p.cpp +++ b/src/eos_s95p.cpp @@ -1,13 +1,14 @@ // Copyright 2018 @ Chun Shen #include "eos_s95p.h" -#include "util.h" -#include #include +#include + +#include "util.h" -using std::stringstream; using std::string; +using std::stringstream; EOS_s95p::EOS_s95p(const int eos_id_in) : eos_id(eos_id_in) { set_EOS_id(eos_id); @@ -18,9 +19,8 @@ EOS_s95p::EOS_s95p(const int eos_id_in) : eos_id(eos_id_in) { set_flag_muQ(false); } - void EOS_s95p::initialize_eos() { - // read the lattice EOS pressure, temperature, and + // read the lattice EOS pressure, temperature, and music_message.info("reading EOS s95p ..."); auto envPath = get_hydro_env_path(); @@ -48,7 +48,7 @@ void EOS_s95p::initialize_eos() { } else if (eos_id == 6) { music_message << "Using lattice EOS from Huovinen/Petreczky with " << "partial chemical equilibrium (PCE) chem. f.o. " - << "at 165 MeV"; + << "at 165 MeV"; spath << "/EOS/s95p-PCE165-v0/"; } else if (eos_id == 7) { music_message.info( @@ -70,21 +70,21 @@ void EOS_s95p::initialize_eos() { resize_table_info_arrays(); string eos_file_string_array[7] = {"1", "2", "3", "4", "5", "6", "7"}; - pressure_tb = new double** [ntables]; - temperature_tb = new double** [ntables]; + pressure_tb = new double **[ntables]; + temperature_tb = new double **[ntables]; for (int itable = 0; itable < ntables; itable++) { - std::ifstream eos_d(spath.str() + "dens" - + eos_file_string_array[itable] + ".dat"); - std::ifstream eos_T(spath.str() + "par" - + eos_file_string_array[itable] + ".dat"); + std::ifstream eos_d( + spath.str() + "dens" + eos_file_string_array[itable] + ".dat"); + std::ifstream eos_T( + spath.str() + "par" + eos_file_string_array[itable] + ".dat"); // read the first two lines with general info: // lowest value of epsilon // deltaEpsilon, number of epsilon steps (i.e. # of lines) eos_d >> e_bounds[itable]; eos_d >> e_spacing[itable] >> e_length[itable]; - e_bounds[itable] /= Util::hbarc; // 1/fm^4 - e_spacing[itable] /= Util::hbarc; // 1/fm^4 + e_bounds[itable] /= Util::hbarc; // 1/fm^4 + e_spacing[itable] /= Util::hbarc; // 1/fm^4 // skip the header in T file string dummy; @@ -95,10 +95,10 @@ void EOS_s95p::initialize_eos() { nb_length[itable] = 1; // allocate memory for pressure arrays - pressure_tb[itable] = Util::mtx_malloc(nb_length[itable], - e_length[itable]); - temperature_tb[itable] = Util::mtx_malloc(nb_length[itable], - e_length[itable]); + pressure_tb[itable] = + Util::mtx_malloc(nb_length[itable], e_length[itable]); + temperature_tb[itable] = + Util::mtx_malloc(nb_length[itable], e_length[itable]); // read pressure, temperature and chemical potential values // files have it backwards, so I start with maximum j and count down @@ -107,51 +107,48 @@ void EOS_s95p::initialize_eos() { for (int j = e_length[itable] - 1; j >= 0; j--) { eos_d >> d_dummy; eos_d >> pressure_tb[itable][i][j]; - eos_d >> d_dummy >> dummy >> dummy;; + eos_d >> d_dummy >> dummy >> dummy; + ; eos_T >> temperature_tb[itable][i][j] >> dummy >> dummy; - pressure_tb[itable][i][j] /= Util::hbarc; // 1/fm^4 - temperature_tb[itable][i][j] /= Util::hbarc; // 1/fm + pressure_tb[itable][i][j] /= Util::hbarc; // 1/fm^4 + temperature_tb[itable][i][j] /= Util::hbarc; // 1/fm } } - //double eps_max_in = (e_bounds[6] + e_spacing[6]*e_length[6])/hbarc; - double eps_max_in = e_bounds[6] + e_spacing[6]*e_length[6]; + // double eps_max_in = (e_bounds[6] + e_spacing[6]*e_length[6])/hbarc; + double eps_max_in = e_bounds[6] + e_spacing[6] * e_length[6]; set_eps_max(eps_max_in); music_message.info("Done reading EOS."); } - double EOS_s95p::p_e_func(double e, double rhob) const { - return(get_dpOverde3(e, rhob)); + return (get_dpOverde3(e, rhob)); } - //! This function returns the local temperature in [1/fm] //! input local energy density eps [1/fm^4] and rhob [1/fm^3] double EOS_s95p::get_temperature(double e, double rhob) const { int table_idx = get_table_idx(e); double T = interpolate1D(e, table_idx, temperature_tb); // 1/fm - return(std::max(Util::small_eps, T)); + return (std::max(Util::small_eps, T)); } - //! This function returns the local pressure in [1/fm^4] //! the input local energy density [1/fm^4], rhob [1/fm^3] double EOS_s95p::get_pressure(double e, double rhob) const { int table_idx = get_table_idx(e); double f = interpolate1D(e, table_idx, pressure_tb); // 1/fm^4 - return(std::max(Util::small_eps, f)); + return (std::max(Util::small_eps, f)); } - double EOS_s95p::get_s2e(double s, double rhob) const { double e = get_s2e_finite_rhob(s, 0.0); - return(e); + return (e); } double EOS_s95p::get_T2e(double T_in_GeV, double rhob) const { double e = get_T2e_finite_rhob(T_in_GeV, 0.0); - return(e); + return (e); } diff --git a/src/eos_s95p.h b/src/eos_s95p.h index 4d0dc250..d83f8203 100644 --- a/src/eos_s95p.h +++ b/src/eos_s95p.h @@ -6,20 +6,20 @@ #include "eos_base.h" class EOS_s95p : public EOS_base { - private: + private: const int eos_id; - - public: + + public: EOS_s95p(const int eos_id_in); - + void initialize_eos(); - double p_e_func (double e, double rhob) const; + double p_e_func(double e, double rhob) const; double get_temperature(double e, double rhob) const; - double get_pressure (double e, double rhob) const; - double get_s2e (double s, double rhob) const; - double get_T2e (double T_in_GeV, double rhob) const; + double get_pressure(double e, double rhob) const; + double get_s2e(double s, double rhob) const; + double get_T2e(double T_in_GeV, double rhob) const; - void check_eos() const {check_eos_no_muB();} + void check_eos() const { check_eos_no_muB(); } }; #endif // SRC_EOS_s95p_H_ diff --git a/src/eos_s95p_unittest.cpp b/src/eos_s95p_unittest.cpp index ebec6f4e..31342120 100644 --- a/src/eos_s95p_unittest.cpp +++ b/src/eos_s95p_unittest.cpp @@ -1,18 +1,18 @@ // Copyright 2018 @ Chun Shen #include "eos_s95p.h" -#include "doctest.h" #include #include +#include "doctest.h" + TEST_CASE("test constructor") { EOS_s95p test; CHECK(test.get_EOS_id() == 2); CHECK(test.get_number_of_tables() == 0); } - TEST_CASE("test initialize eos") { EOS_s95p test; test.initialize_eos(3); @@ -21,7 +21,6 @@ TEST_CASE("test initialize eos") { CHECK(test.get_eps_max() == doctest::Approx(769.82367).epsilon(0.0001)); } - TEST_CASE("test speed of sound squared") { // speed of sound squared is a constant 1/3 EOS_s95p test; @@ -30,52 +29,41 @@ TEST_CASE("test speed of sound squared") { CHECK(test.get_cs2(1.0, 0.0) == doctest::Approx(0.15963).epsilon(0.0001)); CHECK(test.get_cs2(1.0, 2.0) == doctest::Approx(0.15963).epsilon(0.0001)); CHECK(test.get_cs2(1.0, -3.0) == doctest::Approx(0.15963).epsilon(0.0001)); - } - TEST_CASE("test dPdrho") { // dPdrho = 0. EOS_s95p test; test.initialize_eos(2); CHECK(test.get_EOS_id() == 2); - CHECK(test.p_rho_func(1.0, 1.0) == 0.); - CHECK(test.p_rho_func(2.0, 1.0) == 0.); + CHECK(test.p_rho_func(1.0, 1.0) == 0.); + CHECK(test.p_rho_func(2.0, 1.0) == 0.); CHECK(test.p_rho_func(1.0, -1.0) == 0.); } - -TEST_CASE("test dPde") { - EOS_s95p test; -} - +TEST_CASE("test dPde") { EOS_s95p test; } TEST_CASE("test muB") { // muB = 0.0 EOS_s95p test; test.initialize_eos(4); CHECK(test.get_EOS_id() == 4); - CHECK(test.get_mu(1.0, 1.0) == 0.); - CHECK(test.get_mu(2.0, 1.0) == 0.); + CHECK(test.get_mu(1.0, 1.0) == 0.); + CHECK(test.get_mu(2.0, 1.0) == 0.); CHECK(test.get_mu(1.0, -1.0) == 0.); } - TEST_CASE("test muS") { // muS = 0.0 EOS_s95p test; test.initialize_eos(5); CHECK(test.get_EOS_id() == 5); - CHECK(test.get_muS(1.0, 1.0) == 0.); - CHECK(test.get_muS(2.0, 1.0) == 0.); + CHECK(test.get_muS(1.0, 1.0) == 0.); + CHECK(test.get_muS(2.0, 1.0) == 0.); CHECK(test.get_muS(1.0, -1.0) == 0.); } - -TEST_CASE("test pressure") { - EOS_s95p test; -} - +TEST_CASE("test pressure") { EOS_s95p test; } TEST_CASE("check eos") { EOS_s95p test; diff --git a/src/eos_unittest.cpp b/src/eos_unittest.cpp index b78be1e7..0e554217 100644 --- a/src/eos_unittest.cpp +++ b/src/eos_unittest.cpp @@ -1,16 +1,17 @@ // Copyright 2018 @ Chun Shen #include "eos.h" -#include "doctest.h" #include #include +#include "doctest.h" + TEST_CASE("test constructor") { EOS test(0); - CHECK(test.get_pressure(1.0, 0.0) == 1./3.); - CHECK(test.get_dpde(1.0, 0.0) == 1./3.); - CHECK(test.get_dpdrhob(1.0, 0.0) == 0.0); - CHECK(test.get_muB(1.0, 1.0) == 0.0); - CHECK(test.get_muS(1.0, -1.0) == 0.0); + CHECK(test.get_pressure(1.0, 0.0) == 1. / 3.); + CHECK(test.get_dpde(1.0, 0.0) == 1. / 3.); + CHECK(test.get_dpdrhob(1.0, 0.0) == 0.0); + CHECK(test.get_muB(1.0, 1.0) == 0.0); + CHECK(test.get_muS(1.0, -1.0) == 0.0); } diff --git a/src/evolve.cpp b/src/evolve.cpp index 6340988f..64d4b7d3 100644 --- a/src/evolve.cpp +++ b/src/evolve.cpp @@ -1,48 +1,50 @@ // Copyright 2012 Bjoern Schenke, Sangyong Jeon, and Charles Gale #ifdef _OPENMP - #include +#include #endif #include -#include #include -#include #include -#include #include +#include +#include +#include -#include "evolve.h" #include "cornelius.h" -#include "u_derivative.h" #include "emoji.h" +#include "evolve.h" +#include "u_derivative.h" #include "util.h" #ifndef _OPENMP - #define omp_get_thread_num() 0 +#define omp_get_thread_num() 0 #endif using Util::hbarc; -Evolve::Evolve(const EOS &eosIn, InitData &DATA_in, - std::shared_ptr hydro_source_ptr_in) : - eos(eosIn), DATA(DATA_in), - grid_info(DATA_in, eosIn), advance(eosIn, DATA_in, hydro_source_ptr_in) { - +Evolve::Evolve( + const EOS &eosIn, InitData &DATA_in, + std::shared_ptr hydro_source_ptr_in) + : eos(eosIn), + DATA(DATA_in), + grid_info(DATA_in, eosIn), + advance(eosIn, DATA_in, hydro_source_ptr_in) { rk_order = DATA_in.rk_order; if (DATA.freezeOutMethod == 4) { initialize_freezeout_surface_info(); } hydro_source_terms_ptr = hydro_source_ptr_in; - } // master control function for hydrodynamic evolution -int Evolve::EvolveIt(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, - Fields &arenaFieldsNext, HydroinfoMUSIC &hydro_info_ptr) { +int Evolve::EvolveIt( + Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, Fields &arenaFieldsNext, + HydroinfoMUSIC &hydro_info_ptr) { // first pass some control parameters - int freezeout_flag = DATA.doFreezeOut; - int freezeout_lowtemp_flag = DATA.doFreezeOut_lowtemp; + int freezeout_flag = DATA.doFreezeOut; + int freezeout_lowtemp_flag = DATA.doFreezeOut_lowtemp; if (DATA.store_hydro_info_in_memory == 1) { hydro_info_ptr.set_grid_infomatioin(DATA); @@ -51,36 +53,37 @@ int Evolve::EvolveIt(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, FO_nBvsEta_.resize(arenaFieldsCurr.nEta(), 0); // main loop starts ... - int itmax = DATA.nt; - double tau0 = DATA.tau0; - double tauMax = DATA.tau0 + (DATA.nt + 0.5)*DATA.delta_tau; + int itmax = DATA.nt; + double tau0 = DATA.tau0; + double tauMax = DATA.tau0 + (DATA.nt + 0.5) * DATA.delta_tau; int iFreezeStart = 0; double source_tau_max = 0.0; if (hydro_source_terms_ptr) { source_tau_max = hydro_source_terms_ptr->get_source_tau_max(); if (freezeout_lowtemp_flag == 1) { - double freezeOutTauStart = ( - hydro_source_terms_ptr->get_source_tauStart_max()); - freezeOutTauStart = std::min(DATA.freezeOutTauStartMax, - freezeOutTauStart); - iFreezeStart = (static_cast((freezeOutTauStart - tau0) - /DATA.delta_tau) + 2); + double freezeOutTauStart = + (hydro_source_terms_ptr->get_source_tauStart_max()); + freezeOutTauStart = + std::min(DATA.freezeOutTauStartMax, freezeOutTauStart); + iFreezeStart = + (static_cast((freezeOutTauStart - tau0) / DATA.delta_tau) + + 2); } } music_message << "Freeze-out surface starts at " - << tau0 + iFreezeStart*DATA.delta_tau << " fm/c."; + << tau0 + iFreezeStart * DATA.delta_tau << " fm/c."; music_message.flush("info"); - Fields* fpPrev = &arenaFieldsPrev; - Fields* fpCurr = &arenaFieldsCurr; - Fields* fpNext = &arenaFieldsNext; + Fields *fpPrev = &arenaFieldsPrev; + Fields *fpCurr = &arenaFieldsCurr; + Fields *fpNext = &arenaFieldsNext; - Fields freezeoutFieldPrev(arenaFieldsCurr.nX(), arenaFieldsCurr.nY(), - arenaFieldsCurr.nEta()); - Fields freezeoutFieldCurr(arenaFieldsCurr.nX(), arenaFieldsCurr.nY(), - arenaFieldsCurr.nEta()); + Fields freezeoutFieldPrev( + arenaFieldsCurr.nX(), arenaFieldsCurr.nY(), arenaFieldsCurr.nEta()); + Fields freezeoutFieldCurr( + arenaFieldsCurr.nX(), arenaFieldsCurr.nY(), arenaFieldsCurr.nEta()); int it = 0; double eps_max_cur = -1.; @@ -89,13 +92,12 @@ int Evolve::EvolveIt(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, const int NtauBlock = 200; while (tau < tauMax) { if (DATA.beastMode == 2 && it > 0 && (it % NtauBlock == 0)) { - if (DATA.delta_x/(2.*DATA.delta_tau) > 5) { - DATA.delta_tau = 2.*DATA.delta_tau; - DATA.facTau = std::max(1, static_cast(DATA.facTau/2.)); - DATA.output_evolution_every_N_timesteps = ( - std::max(1, static_cast( - DATA.output_evolution_every_N_timesteps/2)) - ); + if (DATA.delta_x / (2. * DATA.delta_tau) > 5) { + DATA.delta_tau = 2. * DATA.delta_tau; + DATA.facTau = std::max(1, static_cast(DATA.facTau / 2.)); + DATA.output_evolution_every_N_timesteps = (std::max( + 1, static_cast( + DATA.output_evolution_every_N_timesteps / 2))); } } int facTau = DATA.facTau; @@ -111,13 +113,13 @@ int Evolve::EvolveIt(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, store_previous_step_for_freezeout(*fpCurr, freezeoutFieldCurr); } - //if (DATA.Initial_profile == 13) { - // if (tau >= source_tau_max + dt && tau < source_tau_max + 2*dt) { - // grid_info.output_energy_density_and_rhob_disitrubtion( - // *fpCurr, - // "energy_density_and_rhob_from_source_terms.dat"); - // } - //} + // if (DATA.Initial_profile == 13) { + // if (tau >= source_tau_max + dt && tau < source_tau_max + 2*dt) { + // grid_info.output_energy_density_and_rhob_disitrubtion( + // *fpCurr, + // "energy_density_and_rhob_from_source_terms.dat"); + // } + // } if (it % Nskip_timestep == 0) { if (DATA.outputEvolutionData == 1) { @@ -128,20 +130,20 @@ int Evolve::EvolveIt(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, grid_info.OutputEvolutionDataXYEta_photon(*fpCurr, tau); } else if (DATA.outputEvolutionData == 4) { grid_info.OutputEvolutionDataXYEta_vorticity( - *fpCurr, *fpPrev, tau); + *fpCurr, *fpPrev, tau); } if (DATA.store_hydro_info_in_memory == 1) { - grid_info.OutputEvolutionDataXYEta_memory(*fpCurr, tau, - hydro_info_ptr); + grid_info.OutputEvolutionDataXYEta_memory( + *fpCurr, tau, hydro_info_ptr); } - //if (DATA.output_movie_flag == 1) { - // grid_info.output_evolution_for_movie(*fpCurr, tau); - //} - //if (DATA.output_outofequilibriumsize == 1) { - // grid_info.OutputEvolution_Knudsen_Reynoldsnumbers(*fpCurr, - // tau); - //} + // if (DATA.output_movie_flag == 1) { + // grid_info.output_evolution_for_movie(*fpCurr, tau); + // } + // if (DATA.output_outofequilibriumsize == 1) { + // grid_info.OutputEvolution_Knudsen_Reynoldsnumbers(*fpCurr, + // tau); + // } } if (it == iFreezeStart || it == iFreezeStart + 10 @@ -151,75 +153,76 @@ int Evolve::EvolveIt(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, if (DATA.beastMode == 0) { if (DATA.Initial_profile == 0) { - if ( fabs(tau - 1.0) < 1e-8 || fabs(tau - 1.2) < 1e-8 + if (fabs(tau - 1.0) < 1e-8 || fabs(tau - 1.2) < 1e-8 || fabs(tau - 1.5) < 1e-8 || fabs(tau - 2.0) < 1e-8 || fabs(tau - 3.0) < 1e-8) { grid_info.Gubser_flow_check_file(*fpCurr, tau); } } else if (DATA.Initial_profile == 1) { - if ( fabs(tau - 1.0) < 1e-8 || fabs(tau - 2.0) < 1e-8 - || fabs(tau - 5.0) < 1e-8 || fabs(tau - 10.0) < 1e-8 + if (fabs(tau - 1.0) < 1e-8 || fabs(tau - 2.0) < 1e-8 + || fabs(tau - 5.0) < 1e-8 || fabs(tau - 10.0) < 1e-8 || fabs(tau - 20.0) < 1e-8) { grid_info.output_1p1D_check_file(*fpCurr, tau); } } grid_info.output_momentum_anisotropy_vs_tau( - tau, -0.5, 0.5, *fpCurr); + tau, -0.5, 0.5, *fpCurr); if (DATA.Initial_profile == 13 || DATA.Initial_profile == 131) { grid_info.output_average_phase_diagram_trajectory( - tau, -0.5, 0.5, *fpCurr); + tau, -0.5, 0.5, *fpCurr); grid_info.output_average_phase_diagram_trajectory( - tau, 0.5, 2.0, *fpCurr); + tau, 0.5, 2.0, *fpCurr); grid_info.output_average_phase_diagram_trajectory( - tau, 2.0, 3.0, *fpCurr); + tau, 2.0, 3.0, *fpCurr); grid_info.output_average_phase_diagram_trajectory( - tau, 3.0, 4.0, *fpCurr); + tau, 3.0, 4.0, *fpCurr); grid_info.output_average_phase_diagram_trajectory( - tau, 4.0, 5.0, *fpCurr); + tau, 4.0, 5.0, *fpCurr); } // check energy conservation if (!DATA.boost_invariant) { grid_info.check_conservation_law(*fpCurr, *fpPrev, tau); if (DATA.output_vorticity == 1) { - if ( std::abs(tau - 1.0) < 1e-8 - || std::abs(tau - 2.0) < 1e-8 - || std::abs(tau - 5.0) < 1e-8 + if (std::abs(tau - 1.0) < 1e-8 || std::abs(tau - 2.0) < 1e-8 + || std::abs(tau - 5.0) < 1e-8 || std::abs(tau - 10.0) < 1e-8) { grid_info.output_vorticity_distribution( - *fpCurr, *fpPrev, tau, -0.5, 0.5); + *fpCurr, *fpPrev, tau, -0.5, 0.5); } grid_info.compute_angular_momentum( - *fpCurr, *fpPrev, tau, -0.5, 0.5); + *fpCurr, *fpPrev, tau, -0.5, 0.5); grid_info.output_vorticity_time_evolution( - *fpCurr, *fpPrev, tau, -0.5, 0.5); + *fpCurr, *fpPrev, tau, -0.5, 0.5); grid_info.compute_angular_momentum( - *fpCurr, *fpPrev, tau, -1.0, 1.0); + *fpCurr, *fpPrev, tau, -1.0, 1.0); grid_info.output_vorticity_time_evolution( - *fpCurr, *fpPrev, tau, -1.0, 1.0); + *fpCurr, *fpPrev, tau, -1.0, 1.0); grid_info.compute_angular_momentum( - *fpCurr, *fpPrev, tau, - -DATA.eta_size/2., DATA.eta_size/2.); + *fpCurr, *fpPrev, tau, -DATA.eta_size / 2., + DATA.eta_size / 2.); grid_info.output_vorticity_time_evolution( - *fpCurr, *fpPrev, tau, - -DATA.eta_size/2., DATA.eta_size/2.); + *fpCurr, *fpPrev, tau, -DATA.eta_size / 2., + DATA.eta_size / 2.); } } double emax_loc = 0.; double Tmax_curr = 0.; double nB_max_curr = 0.; - grid_info.get_maximum_energy_density(*fpCurr, emax_loc, - nB_max_curr, Tmax_curr); + grid_info.get_maximum_energy_density( + *fpCurr, emax_loc, nB_max_curr, Tmax_curr); if (tau > source_tau_max + dt && it > iFreezeStart) { if (eps_max_cur < 0.) { eps_max_cur = emax_loc; } else { - if (emax_loc > max_allowed_e_increase_factor*eps_max_cur) { - music_message << "The maximum energy density increased by " - << "more than facotor of " - << max_allowed_e_increase_factor << "! "; + if (emax_loc + > max_allowed_e_increase_factor * eps_max_cur) { + music_message + << "The maximum energy density increased by " + << "more than facotor of " + << max_allowed_e_increase_factor << "! "; music_message << "This should not happen!"; music_message.flush("error"); exit(1); @@ -230,32 +233,32 @@ int Evolve::EvolveIt(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, } if (DATA.output_hydro_debug_info == 1) { - grid_info.monitor_a_fluid_cell(*fpCurr, *fpPrev, - 100, 100, 0, tau); + grid_info.monitor_a_fluid_cell( + *fpCurr, *fpPrev, 100, 100, 0, tau); } } - //determine freeze-out surface + // determine freeze-out surface int frozen = 0; if (freezeout_flag == 1) { if (freezeout_lowtemp_flag == 1 && it == iFreezeStart) { frozen = FreezeOut_equal_tau_Surface(tau, *fpCurr); } // avoid freeze-out at the first time step - if ((it - iFreezeStart)%facTau == 0 && it > iFreezeStart) { + if ((it - iFreezeStart) % facTau == 0 && it > iFreezeStart) { if (!DATA.boost_invariant) { frozen = FindFreezeOutSurface_Cornelius( - tau, *fpPrev, *fpCurr, - freezeoutFieldPrev, freezeoutFieldCurr); + tau, *fpPrev, *fpCurr, freezeoutFieldPrev, + freezeoutFieldCurr); } else { frozen = FindFreezeOutSurface_boostinvariant_Cornelius( - tau, *fpCurr, freezeoutFieldCurr); + tau, *fpCurr, freezeoutFieldCurr); } store_previous_step_for_freezeout(*fpPrev, freezeoutFieldPrev); store_previous_step_for_freezeout(*fpCurr, freezeoutFieldCurr); } if (DATA.reRunHydro) { - return(-1); + return (-1); } } @@ -263,13 +266,11 @@ int Evolve::EvolveIt(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, // all the evolution are at here !!! AdvanceRK(tau, fpPrev, fpCurr, fpNext); - music_message << emoji::clock() - << " Done time step " << it << "/" << itmax - << " tau = " << tau << " fm/c"; + music_message << emoji::clock() << " Done time step " << it << "/" + << itmax << " tau = " << tau << " fm/c"; music_message.flush("info"); if (frozen == 1 && tau > source_tau_max) { - if ( DATA.outputEvolutionData > 1 - && DATA.outputEvolutionData < 5) { + if (DATA.outputEvolutionData > 1 && DATA.outputEvolutionData < 5) { if (eps_max_cur < DATA.output_evolution_e_cut) { music_message << "All cells e < " << DATA.output_evolution_e_cut @@ -289,10 +290,9 @@ int Evolve::EvolveIt(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, std::ofstream FOinfo; FOinfo.open("FO_nBvseta.dat"); for (unsigned int ieta = 0; ieta < FO_nBvsEta_.size(); ieta++) { - double eta = (DATA.delta_eta)*ieta - (DATA.eta_size)/2.0; - FOinfo << std::scientific << std::setprecision(5) - << eta << " " << FO_nBvsEta_[ieta]/DATA.delta_eta - << std::endl; + double eta = (DATA.delta_eta) * ieta - (DATA.eta_size) / 2.0; + FOinfo << std::scientific << std::setprecision(5) << eta << " " + << FO_nBvsEta_[ieta] / DATA.delta_eta << std::endl; } FOinfo.close(); } @@ -304,9 +304,8 @@ int Evolve::EvolveIt(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, return 1; } - -void Evolve::store_previous_step_for_freezeout(Fields &arenaCurr, - Fields &arenaFreeze) { +void Evolve::store_previous_step_for_freezeout( + Fields &arenaCurr, Fields &arenaFreeze) { arenaFreeze.e_ = arenaCurr.e_; arenaFreeze.rhob_ = arenaCurr.rhob_; arenaFreeze.piBulk_ = arenaCurr.piBulk_; @@ -314,64 +313,62 @@ void Evolve::store_previous_step_for_freezeout(Fields &arenaCurr, arenaFreeze.Wmunu_ = arenaCurr.Wmunu_; } -void Evolve::AdvanceRK(double tau, Fields* &fpPrev, Fields* &fpCurr, - Fields* &fpNext) { +void Evolve::AdvanceRK( + double tau, Fields *&fpPrev, Fields *&fpCurr, Fields *&fpNext) { // control function for Runge-Kutta evolution in tau // loop over Runge-Kutta steps for (int rk_flag = 0; rk_flag < rk_order; rk_flag++) { advance.AdvanceIt(tau, *fpPrev, *fpCurr, *fpNext, rk_flag); if (rk_flag == 0) { - Fields* temp2 = fpPrev; + Fields *temp2 = fpPrev; fpPrev = fpCurr; fpCurr = fpNext; fpNext = temp2; } else { - Fields* temp = fpCurr; + Fields *temp = fpCurr; fpCurr = fpNext; fpNext = temp; } - } /* loop over rk_flag */ + } /* loop over rk_flag */ } // Cornelius freeze out (C. Shen, 11/2014) -int Evolve::FindFreezeOutSurface_Cornelius(double tau, - Fields &arena_prev, Fields &arena_current, - Fields &arena_freezeout_prev, Fields &arena_freezeout) { +int Evolve::FindFreezeOutSurface_Cornelius( + double tau, Fields &arena_prev, Fields &arena_current, + Fields &arena_freezeout_prev, Fields &arena_freezeout) { const int neta = arena_current.nEta(); const int fac_eta = 1; int intersections = 0; for (unsigned int i_freezesurf = 0; i_freezesurf < epsFO_list.size(); - i_freezesurf++) { - const double epsFO = epsFO_list[i_freezesurf]/hbarc; // 1/fm^4 + i_freezesurf++) { + const double epsFO = epsFO_list[i_freezesurf] / hbarc; // 1/fm^4 - #pragma omp parallel for reduction(+:intersections) - for (int ieta = 0; ieta < (neta-fac_eta); ieta += fac_eta) { +#pragma omp parallel for reduction(+ : intersections) + for (int ieta = 0; ieta < (neta - fac_eta); ieta += fac_eta) { int thread_id = omp_get_thread_num(); intersections += FindFreezeOutSurface_Cornelius_XY( - tau, ieta, arena_prev, arena_current, - arena_freezeout_prev, arena_freezeout, thread_id, epsFO); + tau, ieta, arena_prev, arena_current, arena_freezeout_prev, + arena_freezeout, thread_id, epsFO); } if (DATA.reRunHydro) { - return(0); + return (0); } } - return(intersections + 1); + return (intersections + 1); } -int Evolve::FindFreezeOutSurface_Cornelius_XY(double tau, int ieta, - Fields &arena_prev, - Fields &arena_current, - Fields &arena_freezeout_prev, - Fields &arena_freezeout, - int thread_id, double epsFO) { +int Evolve::FindFreezeOutSurface_Cornelius_XY( + double tau, int ieta, Fields &arena_prev, Fields &arena_current, + Fields &arena_freezeout_prev, Fields &arena_freezeout, int thread_id, + double epsFO) { const bool surface_in_binary = DATA.freeze_surface_in_binary; const int nx = arena_current.nX(); const int ny = arena_current.nY(); std::stringstream strs_name; - strs_name << "surface_eps_" << std::setprecision(4) << epsFO*hbarc - << "_" << thread_id << ".dat"; + strs_name << "surface_eps_" << std::setprecision(4) << epsFO * hbarc << "_" + << thread_id << ".dat"; std::ofstream s_file; std::ios_base::openmode modes; @@ -385,15 +382,15 @@ int Evolve::FindFreezeOutSurface_Cornelius_XY(double tau, int ieta, const int dim = 4; int intersections = 0; - int facTau = DATA.facTau; // step to skip in tau direction - int fac_x = DATA.fac_x; - int fac_y = DATA.fac_y; + int facTau = DATA.facTau; // step to skip in tau direction + int fac_x = DATA.fac_x; + int fac_y = DATA.fac_y; int fac_eta = 1; - const double DTAU = facTau*DATA.delta_tau; - const double DX = fac_x*DATA.delta_x; - const double DY = fac_y*DATA.delta_y; - const double DETA = fac_eta*DATA.delta_eta; + const double DTAU = facTau * DATA.delta_tau; + const double DX = fac_x * DATA.delta_x; + const double DY = fac_y * DATA.delta_y; + const double DETA = fac_eta * DATA.delta_eta; U_derivative u_derivative_helper(DATA, eos); @@ -403,80 +400,93 @@ int Evolve::FindFreezeOutSurface_Cornelius_XY(double tau, int ieta, cornelius_ptr->init(dim, epsFO, lattice_spacing); // initialize the hyper-cube for Cornelius - Cell_small ****fluid_cube = new Cell_small*** [2]; - Cell_aux ****fluid_aux_cube = new Cell_aux*** [2]; - double ****cube = new double*** [2]; + Cell_small ****fluid_cube = new Cell_small ***[2]; + Cell_aux ****fluid_aux_cube = new Cell_aux ***[2]; + double ****cube = new double ***[2]; for (int i = 0; i < 2; i++) { - fluid_cube[i] = new Cell_small** [2]; - fluid_aux_cube[i] = new Cell_aux** [2]; - cube[i] = new double** [2]; + fluid_cube[i] = new Cell_small **[2]; + fluid_aux_cube[i] = new Cell_aux **[2]; + cube[i] = new double **[2]; for (int j = 0; j < 2; j++) { - fluid_cube[i][j] = new Cell_small* [2]; - fluid_aux_cube[i][j] = new Cell_aux* [2]; - cube[i][j] = new double* [2]; + fluid_cube[i][j] = new Cell_small *[2]; + fluid_aux_cube[i][j] = new Cell_aux *[2]; + cube[i][j] = new double *[2]; for (int k = 0; k < 2; k++) { fluid_cube[i][j][k] = new Cell_small[2]; fluid_aux_cube[i][j][k] = new Cell_aux[2]; cube[i][j][k] = new double[2]; - for (int l = 0; l < 2; l++) - cube[i][j][k][l] = 0.0; + for (int l = 0; l < 2; l++) cube[i][j][k][l] = 0.0; } } } double x_fraction[2][4]; - double eta = (DATA.delta_eta)*ieta - (DATA.eta_size)/2.0; + double eta = (DATA.delta_eta) * ieta - (DATA.eta_size) / 2.0; for (int ix = 0; ix < nx - fac_x; ix += fac_x) { - double x = ix*(DATA.delta_x) - (DATA.x_size/2.0); + double x = ix * (DATA.delta_x) - (DATA.x_size / 2.0); for (int iy = 0; iy < ny - fac_y; iy += fac_y) { - double y = iy*(DATA.delta_y) - (DATA.y_size/2.0); + double y = iy * (DATA.delta_y) - (DATA.y_size / 2.0); int Idx000 = arena_current.getFieldIdx(ix, iy, ieta); - int Idx100 = arena_current.getFieldIdx(ix+fac_x, iy, ieta); - int Idx110 = arena_current.getFieldIdx(ix+fac_x, iy+fac_y, ieta); - int Idx010 = arena_current.getFieldIdx(ix, iy+fac_y, ieta); - int Idx001 = arena_current.getFieldIdx(ix, iy, ieta+fac_eta); - int Idx101 = arena_current.getFieldIdx(ix+fac_x, iy, ieta+fac_eta); - int Idx111 = arena_current.getFieldIdx(ix+fac_x, iy+fac_y, ieta+fac_eta); - int Idx011 = arena_current.getFieldIdx(ix, iy+fac_y, ieta+fac_eta); + int Idx100 = arena_current.getFieldIdx(ix + fac_x, iy, ieta); + int Idx110 = + arena_current.getFieldIdx(ix + fac_x, iy + fac_y, ieta); + int Idx010 = arena_current.getFieldIdx(ix, iy + fac_y, ieta); + int Idx001 = arena_current.getFieldIdx(ix, iy, ieta + fac_eta); + int Idx101 = + arena_current.getFieldIdx(ix + fac_x, iy, ieta + fac_eta); + int Idx111 = arena_current.getFieldIdx( + ix + fac_x, iy + fac_y, ieta + fac_eta); + int Idx011 = + arena_current.getFieldIdx(ix, iy + fac_y, ieta + fac_eta); // judge intersection (from Bjoern) int intersect = 1; - if (( arena_current.e_[Idx111] - epsFO) - *(arena_freezeout.e_[Idx000] - epsFO) > 0.) - if(( arena_current.e_[Idx100] - epsFO) - *(arena_freezeout.e_[Idx011] - epsFO) > 0.) - if(( arena_current.e_[Idx010] - epsFO) - *(arena_freezeout.e_[Idx101] - epsFO) > 0.) - if(( arena_current.e_[Idx001] - epsFO) - *(arena_freezeout.e_[Idx110] - epsFO) > 0.) - if(( arena_current.e_[Idx110] - epsFO) - *(arena_freezeout.e_[Idx001] - epsFO) > 0.) - if(( arena_current.e_[Idx101] - epsFO) - *(arena_freezeout.e_[Idx010] - epsFO) > 0.) - if(( arena_current.e_[Idx011] - epsFO) - *(arena_freezeout.e_[Idx100] - epsFO) > 0.) - if(( arena_current.e_[Idx000] - epsFO) - *(arena_freezeout.e_[Idx111] - epsFO) > 0.) - intersect=0; - - if (intersect==0) continue; - - if (ix == 0 || ix >= nx - 2*fac_x - || iy == 0 || iy >= ny - 2*fac_y) { + if ((arena_current.e_[Idx111] - epsFO) + * (arena_freezeout.e_[Idx000] - epsFO) + > 0.) + if ((arena_current.e_[Idx100] - epsFO) + * (arena_freezeout.e_[Idx011] - epsFO) + > 0.) + if ((arena_current.e_[Idx010] - epsFO) + * (arena_freezeout.e_[Idx101] - epsFO) + > 0.) + if ((arena_current.e_[Idx001] - epsFO) + * (arena_freezeout.e_[Idx110] - epsFO) + > 0.) + if ((arena_current.e_[Idx110] - epsFO) + * (arena_freezeout.e_[Idx001] - epsFO) + > 0.) + if ((arena_current.e_[Idx101] - epsFO) + * (arena_freezeout.e_[Idx010] - epsFO) + > 0.) + if ((arena_current.e_[Idx011] - epsFO) + * (arena_freezeout.e_[Idx100] + - epsFO) + > 0.) + if ((arena_current.e_[Idx000] - epsFO) + * (arena_freezeout.e_[Idx111] + - epsFO) + > 0.) + intersect = 0; + + if (intersect == 0) continue; + + if (ix == 0 || ix >= nx - 2 * fac_x || iy == 0 + || iy >= ny - 2 * fac_y) { music_message << "Freeze-out cell at the boundary! " << "The grid is too small!"; music_message.flush("error"); DATA.reRunHydro = true; - return(0); + return (0); } - if (ix == 0 || ix >= nx - 2*fac_x - || iy == 0 || iy >= ny - 2*fac_y) { + if (ix == 0 || ix >= nx - 2 * fac_x || iy == 0 + || iy >= ny - 2 * fac_y) { music_message << "Freeze-out cell at the boundary! " << "The grid is too small!"; music_message.flush("error"); DATA.reRunHydro = true; - return(0); + return (0); } // if intersect, prepare for the hyper-cube @@ -486,18 +496,18 @@ int Evolve::FindFreezeOutSurface_Cornelius_XY(double tau, int ieta, cube[0][0][1][0] = arena_freezeout.e_[Idx010]; cube[0][1][0][0] = arena_freezeout.e_[Idx100]; cube[0][1][1][0] = arena_freezeout.e_[Idx110]; - cube[1][0][0][0] = arena_current.e_[Idx000]; - cube[1][0][1][0] = arena_current.e_[Idx010]; - cube[1][1][0][0] = arena_current.e_[Idx100]; - cube[1][1][1][0] = arena_current.e_[Idx110]; + cube[1][0][0][0] = arena_current.e_[Idx000]; + cube[1][0][1][0] = arena_current.e_[Idx010]; + cube[1][1][0][0] = arena_current.e_[Idx100]; + cube[1][1][1][0] = arena_current.e_[Idx110]; cube[0][0][0][1] = arena_freezeout.e_[Idx001]; cube[0][0][1][1] = arena_freezeout.e_[Idx011]; cube[0][1][0][1] = arena_freezeout.e_[Idx101]; cube[0][1][1][1] = arena_freezeout.e_[Idx111]; - cube[1][0][0][1] = arena_current.e_[Idx001]; - cube[1][0][1][1] = arena_current.e_[Idx011]; - cube[1][1][0][1] = arena_current.e_[Idx101]; - cube[1][1][1][1] = arena_current.e_[Idx111]; + cube[1][0][0][1] = arena_current.e_[Idx001]; + cube[1][0][1][1] = arena_current.e_[Idx011]; + cube[1][1][0][1] = arena_current.e_[Idx101]; + cube[1][1][1][1] = arena_current.e_[Idx111]; // Now, the magic will happen in the Cornelius ... cornelius_ptr->find_surface_4d(cube); @@ -512,28 +522,28 @@ int Evolve::FindFreezeOutSurface_Cornelius_XY(double tau, int ieta, FULLSU[ii] = cornelius_ptr->get_normal_elem(isurf, ii); // check the size of the surface normal vector - if (std::abs(FULLSU[0]) > (DX*DY*DETA+0.01)) { + if (std::abs(FULLSU[0]) > (DX * DY * DETA + 0.01)) { music_message << "problem: volume in tau direction " - << std::abs(FULLSU[0]) << " > DX*DY*DETA = " - << DX*DY*DETA; + << std::abs(FULLSU[0]) + << " > DX*DY*DETA = " << DX * DY * DETA; music_message.flush("warning"); } - if (std::abs(FULLSU[1]) > (DTAU*DY*DETA+0.01)) { + if (std::abs(FULLSU[1]) > (DTAU * DY * DETA + 0.01)) { music_message << "problem: volume in x direction " << std::abs(FULLSU[1]) - << " > DTAU*DY*DETA = " << DTAU*DY*DETA; + << " > DTAU*DY*DETA = " << DTAU * DY * DETA; music_message.flush("warning"); } - if (std::abs(FULLSU[2]) > (DX*DTAU*DETA+0.01)) { + if (std::abs(FULLSU[2]) > (DX * DTAU * DETA + 0.01)) { music_message << "problem: volume in y direction " << std::abs(FULLSU[2]) - << " > DX*DTAU*DETA = " << DX*DTAU*DETA; + << " > DX*DTAU*DETA = " << DX * DTAU * DETA; music_message.flush("warning"); } - if (std::abs(FULLSU[3]) > (DX*DY*DTAU+0.01)) { + if (std::abs(FULLSU[3]) > (DX * DY * DTAU + 0.01)) { music_message << "problem: volume in eta direction " - << std::abs(FULLSU[3]) << " > DX*DY*DTAU = " - << DX*DY*DTAU; + << std::abs(FULLSU[3]) + << " > DX*DY*DTAU = " << DX * DY * DTAU; music_message.flush("warning"); } @@ -541,53 +551,53 @@ int Evolve::FindFreezeOutSurface_Cornelius_XY(double tau, int ieta, for (int ii = 0; ii < 4; ii++) { x_fraction[1][ii] = cornelius_ptr->get_centroid_elem(isurf, ii); - x_fraction[0][ii] = - lattice_spacing[ii] - x_fraction[1][ii]; + x_fraction[0][ii] = lattice_spacing[ii] - x_fraction[1][ii]; } const double tau_center = tau - DTAU + x_fraction[1][0]; const double x_center = x + x_fraction[1][1]; const double y_center = y + x_fraction[1][2]; const double eta_center = eta + x_fraction[1][3]; - // perform 4-d linear interpolation for all fluid quantities for (int ii = 0; ii < 2; ii++) - for (int jj = 0; jj < 2; jj++) - for (int kk = 0; kk < 2; kk++) { - int fieldIdx = arena_current.getFieldIdx( - ix + ii*fac_x, iy + jj*fac_y, ieta + kk*fac_eta); - fluid_cube[0][ii][jj][kk] = ( - arena_freezeout.getCell(fieldIdx)); - fluid_cube[1][ii][jj][kk] = arena_current.getCell(fieldIdx); - - if (DATA.output_vorticity == 0) continue; - - // compute the vorticity tensors - Cell_aux aux_tmp; - double eta_local = eta + kk*DETA; - u_derivative_helper.compute_vorticity_shell( - tau, arena_prev, arena_current, - ieta + kk*fac_eta, ix + ii*fac_x, iy + jj*fac_y, - fieldIdx, eta_local, - aux_tmp.omega_kSP, aux_tmp.omega_k, - aux_tmp.omega_th, aux_tmp.omega_T, - aux_tmp.sigma_th, aux_tmp.DbetaMu); - fluid_aux_cube[1][ii][jj][kk] = aux_tmp; - u_derivative_helper.compute_vorticity_shell( - tau - DTAU, arena_freezeout_prev, arena_freezeout, - ieta + kk*fac_eta, ix + ii*fac_x, iy + jj*fac_y, - fieldIdx, eta_local, - aux_tmp.omega_kSP, aux_tmp.omega_k, - aux_tmp.omega_th, aux_tmp.omega_T, - aux_tmp.sigma_th, aux_tmp.DbetaMu); - fluid_aux_cube[0][ii][jj][kk] = aux_tmp; - } + for (int jj = 0; jj < 2; jj++) + for (int kk = 0; kk < 2; kk++) { + int fieldIdx = arena_current.getFieldIdx( + ix + ii * fac_x, iy + jj * fac_y, + ieta + kk * fac_eta); + fluid_cube[0][ii][jj][kk] = + (arena_freezeout.getCell(fieldIdx)); + fluid_cube[1][ii][jj][kk] = + arena_current.getCell(fieldIdx); + + if (DATA.output_vorticity == 0) continue; + + // compute the vorticity tensors + Cell_aux aux_tmp; + double eta_local = eta + kk * DETA; + u_derivative_helper.compute_vorticity_shell( + tau, arena_prev, arena_current, + ieta + kk * fac_eta, ix + ii * fac_x, + iy + jj * fac_y, fieldIdx, eta_local, + aux_tmp.omega_kSP, aux_tmp.omega_k, + aux_tmp.omega_th, aux_tmp.omega_T, + aux_tmp.sigma_th, aux_tmp.DbetaMu); + fluid_aux_cube[1][ii][jj][kk] = aux_tmp; + u_derivative_helper.compute_vorticity_shell( + tau - DTAU, arena_freezeout_prev, + arena_freezeout, ieta + kk * fac_eta, + ix + ii * fac_x, iy + jj * fac_y, fieldIdx, + eta_local, aux_tmp.omega_kSP, aux_tmp.omega_k, + aux_tmp.omega_th, aux_tmp.omega_T, + aux_tmp.sigma_th, aux_tmp.DbetaMu); + fluid_aux_cube[0][ii][jj][kk] = aux_tmp; + } auto fluid_center = four_dimension_linear_interpolation( - lattice_spacing, x_fraction, fluid_cube); + lattice_spacing, x_fraction, fluid_cube); Cell_aux fluid_aux_center; if (DATA.output_vorticity == 1) { fluid_aux_center = four_dimension_linear_interpolation( - lattice_spacing, x_fraction, fluid_aux_cube); + lattice_spacing, x_fraction, fluid_aux_cube); } // reconstruct q^\tau from the transverality criteria @@ -628,11 +638,10 @@ int Evolve::FindFreezeOutSurface_Cornelius_XY(double tau, int ieta, fluid_center.Wmunu[9] = Wmunu_regulated[3][3]; // 4-dimension interpolation done - const double TFO = eos.get_temperature(epsFO, - fluid_center.rhob); + const double TFO = + eos.get_temperature(epsFO, fluid_center.rhob); if (TFO < 0) { - music_message << "TFO=" << TFO - << "<0. ERROR. exiting."; + music_message << "TFO=" << TFO << "<0. ERROR. exiting."; music_message.flush("error"); exit(1); } @@ -640,22 +649,22 @@ int Evolve::FindFreezeOutSurface_Cornelius_XY(double tau, int ieta, const double muS = eos.get_muS(epsFO, fluid_center.rhob); const double muQ = eos.get_muQ(epsFO, fluid_center.rhob); - const double pressure = eos.get_pressure(epsFO, - fluid_center.rhob); - const double eps_plus_p_over_T_FO = (epsFO + pressure)/TFO; + const double pressure = + eos.get_pressure(epsFO, fluid_center.rhob); + const double eps_plus_p_over_T_FO = (epsFO + pressure) / TFO; // finally output results !!!! if (surface_in_binary) { - const int FOsize = 34 + DATA.output_vorticity*(24 + 14); + const int FOsize = 34 + DATA.output_vorticity * (24 + 14); float array[FOsize]; array[0] = static_cast(tau_center); array[1] = static_cast(x_center); array[2] = static_cast(y_center); array[3] = static_cast(eta_center); for (int ii = 0; ii < 4; ii++) - array[4+ii] = static_cast(FULLSU[ii]); + array[4 + ii] = static_cast(FULLSU[ii]); for (int ii = 0; ii < 4; ii++) - array[8+ii] = static_cast(fluid_center.u[ii]); + array[8 + ii] = static_cast(fluid_center.u[ii]); array[12] = static_cast(epsFO); array[13] = static_cast(TFO); array[14] = static_cast(muB); @@ -663,75 +672,73 @@ int Evolve::FindFreezeOutSurface_Cornelius_XY(double tau, int ieta, array[16] = static_cast(muQ); array[17] = static_cast(eps_plus_p_over_T_FO); for (int ii = 0; ii < 10; ii++) { - array[18+ii] = static_cast( - fluid_center.Wmunu[ii]); + array[18 + ii] = + static_cast(fluid_center.Wmunu[ii]); } array[28] = static_cast(fluid_center.pi_b); array[29] = static_cast(fluid_center.rhob); for (int ii = 0; ii < 4; ii++) { - array[30+ii] = static_cast( - fluid_center.Wmunu[10+ii]); + array[30 + ii] = + static_cast(fluid_center.Wmunu[10 + ii]); } if (DATA.output_vorticity == 1) { for (int ii = 0; ii < 6; ii++) { // no minus sign because its definition is // opposite to the kinetic vorticity - array[34+ii] = static_cast( - fluid_aux_center.omega_kSP[ii]/TFO); + array[34 + ii] = static_cast( + fluid_aux_center.omega_kSP[ii] / TFO); // the extra minus sign is from metric // output quantities for g = (1, -1, -1, -1) - array[40+ii] = static_cast( - -fluid_aux_center.omega_k[ii]/TFO); - array[46+ii] = static_cast( - -fluid_aux_center.omega_th[ii]); - array[52+ii] = static_cast( - -fluid_aux_center.omega_T[ii]/TFO/TFO); + array[40 + ii] = static_cast( + -fluid_aux_center.omega_k[ii] / TFO); + array[46 + ii] = static_cast( + -fluid_aux_center.omega_th[ii]); + array[52 + ii] = static_cast( + -fluid_aux_center.omega_T[ii] / TFO / TFO); } // the extra minus sign is from metric // output quantities for g = (1, -1, -1, -1) for (int ii = 0; ii < 10; ii++) { - array[58+ii] = static_cast( - -fluid_aux_center.sigma_th[ii]); + array[58 + ii] = static_cast( + -fluid_aux_center.sigma_th[ii]); } for (int ii = 0; ii < 4; ii++) { - array[68+ii] = static_cast( - -fluid_aux_center.DbetaMu[ii]); + array[68 + ii] = static_cast( + -fluid_aux_center.DbetaMu[ii]); } } for (int i = 0; i < FOsize; i++) - s_file.write((char*) &(array[i]), sizeof(float)); + s_file.write((char *)&(array[i]), sizeof(float)); } else { s_file << std::scientific << std::setprecision(10) - << tau_center << " " << x_center << " " - << y_center << " " << eta_center << " " - << FULLSU[0] << " " << FULLSU[1] << " " - << FULLSU[2] << " " << FULLSU[3] << " " - << fluid_center.u[0] << " " << fluid_center.u[1] << " " - << fluid_center.u[2] << " " << fluid_center.u[3] << " " - << epsFO << " " << TFO << " " << muB << " " - << muS << " " << muQ << " " - << eps_plus_p_over_T_FO << " "; + << tau_center << " " << x_center << " " << y_center + << " " << eta_center << " " << FULLSU[0] << " " + << FULLSU[1] << " " << FULLSU[2] << " " << FULLSU[3] + << " " << fluid_center.u[0] << " " + << fluid_center.u[1] << " " << fluid_center.u[2] + << " " << fluid_center.u[3] << " " << epsFO << " " + << TFO << " " << muB << " " << muS << " " << muQ + << " " << eps_plus_p_over_T_FO << " "; for (int ii = 0; ii < 10; ii++) s_file << std::scientific << std::setprecision(10) << fluid_center.Wmunu[ii] << " "; - if (DATA.turn_on_bulk) - s_file << fluid_center.pi_b << " "; - if (DATA.turn_on_rhob) - s_file << fluid_center.rhob << " "; + if (DATA.turn_on_bulk) s_file << fluid_center.pi_b << " "; + if (DATA.turn_on_rhob) s_file << fluid_center.rhob << " "; if (DATA.turn_on_diff) for (int ii = 10; ii < 14; ii++) s_file << std::scientific << std::setprecision(10) << fluid_center.Wmunu[ii] << " "; s_file << std::endl; } - double u_dot_dsigma = tau_center*( - FULLSU[0]*fluid_center.u[0] - + FULLSU[1]*fluid_center.u[1] - + FULLSU[2]*fluid_center.u[2] - + FULLSU[3]*fluid_center.u[3]/tau_center); + double u_dot_dsigma = + tau_center + * (FULLSU[0] * fluid_center.u[0] + + FULLSU[1] * fluid_center.u[1] + + FULLSU[2] * fluid_center.u[2] + + FULLSU[3] * fluid_center.u[3] / tau_center); if (u_dot_dsigma > 0.) { // only count the time-like contribution - FO_nBvsEta_[ieta] += u_dot_dsigma*fluid_center.rhob; + FO_nBvsEta_[ieta] += u_dot_dsigma * fluid_center.rhob; } } } @@ -742,28 +749,26 @@ int Evolve::FindFreezeOutSurface_Cornelius_XY(double tau, int ieta, for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { - delete [] cube[i][j][k]; - delete [] fluid_cube[i][j][k]; - delete [] fluid_aux_cube[i][j][k]; + delete[] cube[i][j][k]; + delete[] fluid_cube[i][j][k]; + delete[] fluid_aux_cube[i][j][k]; } - delete [] cube[i][j]; - delete [] fluid_cube[i][j]; - delete [] fluid_aux_cube[i][j]; + delete[] cube[i][j]; + delete[] fluid_cube[i][j]; + delete[] fluid_aux_cube[i][j]; } - delete [] cube[i]; - delete [] fluid_cube[i]; - delete [] fluid_aux_cube[i]; + delete[] cube[i]; + delete[] fluid_cube[i]; + delete[] fluid_aux_cube[i]; } - delete [] cube; - delete [] fluid_cube; - delete [] fluid_aux_cube; - return(intersections); + delete[] cube; + delete[] fluid_cube; + delete[] fluid_aux_cube; + return (intersections); } - // Cornelius freeze out (C. Shen, 11/2014) -int Evolve::FreezeOut_equal_tau_Surface(double tau, - Fields &arena_current) { +int Evolve::FreezeOut_equal_tau_Surface(double tau, Fields &arena_current) { // this function freeze-out fluid cells between epsFO and epsFO_low // on an equal time hyper-surface at the first time step // this function will be trigged if freezeout_lowtemp_flag == 1 @@ -771,38 +776,36 @@ int Evolve::FreezeOut_equal_tau_Surface(double tau, const int fac_eta = 1; for (unsigned int i_freezesurf = 0; i_freezesurf < epsFO_list.size(); - i_freezesurf++) { - double epsFO = epsFO_list[i_freezesurf]/hbarc; + i_freezesurf++) { + double epsFO = epsFO_list[i_freezesurf] / hbarc; if (!DATA.boost_invariant) { - #pragma omp parallel for +#pragma omp parallel for for (int ieta = 0; ieta < neta - fac_eta; ieta += fac_eta) { int thread_id = omp_get_thread_num(); - FreezeOut_equal_tau_Surface_XY(tau, ieta, arena_current, - thread_id, epsFO); + FreezeOut_equal_tau_Surface_XY( + tau, ieta, arena_current, thread_id, epsFO); } } else { FreezeOut_equal_tau_Surface_XY(tau, 0, arena_current, 0, epsFO); } } - return(0); + return (0); } - -void Evolve::FreezeOut_equal_tau_Surface_XY(double tau, int ieta, - Fields &arena_current, - int thread_id, double epsFO) { +void Evolve::FreezeOut_equal_tau_Surface_XY( + double tau, int ieta, Fields &arena_current, int thread_id, double epsFO) { const bool surface_in_binary = DATA.freeze_surface_in_binary; - double epsFO_low = 0.05/hbarc; // 1/fm^4 + double epsFO_low = 0.05 / hbarc; // 1/fm^4 const int nx = arena_current.nX(); const int ny = arena_current.nY(); std::stringstream strs_name; if (!DATA.boost_invariant) { - strs_name << "surface_eps_" << std::setprecision(4) << epsFO*hbarc + strs_name << "surface_eps_" << std::setprecision(4) << epsFO * hbarc << "_" << thread_id << ".dat"; } else { - strs_name << "surface_eps_" << std::setprecision(4) << epsFO*hbarc + strs_name << "surface_eps_" << std::setprecision(4) << epsFO * hbarc << ".dat"; } std::ofstream s_file; @@ -815,19 +818,19 @@ void Evolve::FreezeOut_equal_tau_Surface_XY(double tau, int ieta, s_file.open(strs_name.str().c_str(), modes); - const int fac_x = DATA.fac_x; - const int fac_y = DATA.fac_y; + const int fac_x = DATA.fac_x; + const int fac_y = DATA.fac_y; const int fac_eta = 1; - const double DX = fac_x*DATA.delta_x; - const double DY = fac_y*DATA.delta_y; - const double DETA = fac_eta*DATA.delta_eta; + const double DX = fac_x * DATA.delta_x; + const double DY = fac_y * DATA.delta_y; + const double DETA = fac_eta * DATA.delta_eta; - double eta = (DATA.delta_eta)*ieta - (DATA.eta_size)/2.0; + double eta = (DATA.delta_eta) * ieta - (DATA.eta_size) / 2.0; for (int ix = 0; ix < nx - fac_x; ix += fac_x) { - double x = ix*(DATA.delta_x) - (DATA.x_size/2.0); + double x = ix * (DATA.delta_x) - (DATA.x_size / 2.0); for (int iy = 0; iy < ny - fac_y; iy += fac_y) { - double y = iy*(DATA.delta_y) - (DATA.y_size/2.0); + double y = iy * (DATA.delta_y) - (DATA.y_size / 2.0); int fieldIdx = arena_current.getFieldIdx(ix, iy, ieta); @@ -836,30 +839,31 @@ void Evolve::FreezeOut_equal_tau_Surface_XY(double tau, int ieta, if (arena_current.e_[fieldIdx] < epsFO_low) continue; // surface normal vector d^3 \sigma_\mu - const double FULLSU[] = {DX*DY*DETA, 0.0, 0.0, 0.0}; + const double FULLSU[] = {DX * DY * DETA, 0.0, 0.0, 0.0}; // get positions of the freeze-out surface const double tau_center = tau; - const double x_center = x; - const double y_center = y; + const double x_center = x; + const double y_center = y; const double eta_center = eta; // flow velocity - const double ux_center = arena_current.u_[1][fieldIdx]; - const double uy_center = arena_current.u_[2][fieldIdx]; - const double ueta_center = arena_current.u_[3][fieldIdx]; // u^eta/tau + const double ux_center = arena_current.u_[1][fieldIdx]; + const double uy_center = arena_current.u_[2][fieldIdx]; + const double ueta_center = + arena_current.u_[3][fieldIdx]; // u^eta/tau // reconstruct u^tau from u^i - const double utau_center = sqrt(1. + ux_center*ux_center - + uy_center*uy_center - + ueta_center*ueta_center); + const double utau_center = sqrt( + 1. + ux_center * ux_center + uy_center * uy_center + + ueta_center * ueta_center); // baryon density rho_b const double rhob_center = arena_current.rhob_[fieldIdx]; // baryon diffusion current double qtau_center = arena_current.Wmunu_[10][fieldIdx]; - double qx_center = arena_current.Wmunu_[11][fieldIdx]; - double qy_center = arena_current.Wmunu_[12][fieldIdx]; + double qx_center = arena_current.Wmunu_[11][fieldIdx]; + double qy_center = arena_current.Wmunu_[12][fieldIdx]; double qeta_center = arena_current.Wmunu_[13][fieldIdx]; // reconstruct q^\tau from the transverality criteria @@ -868,8 +872,8 @@ void Evolve::FreezeOut_equal_tau_Surface_XY(double tau, int ieta, double q_regulated[4] = {0.0, 0.0, 0.0, 0.0}; regulate_qmu(u_flow, q_mu, q_regulated); qtau_center = q_regulated[0]; - qx_center = q_regulated[1]; - qy_center = q_regulated[2]; + qx_center = q_regulated[1]; + qy_center = q_regulated[2]; qeta_center = q_regulated[3]; // bulk viscous pressure pi_b @@ -877,14 +881,14 @@ void Evolve::FreezeOut_equal_tau_Surface_XY(double tau, int ieta, // shear viscous tensor double Wtautau_center = arena_current.Wmunu_[0][fieldIdx]; - double Wtaux_center = arena_current.Wmunu_[1][fieldIdx]; - double Wtauy_center = arena_current.Wmunu_[2][fieldIdx]; + double Wtaux_center = arena_current.Wmunu_[1][fieldIdx]; + double Wtauy_center = arena_current.Wmunu_[2][fieldIdx]; double Wtaueta_center = arena_current.Wmunu_[3][fieldIdx]; - double Wxx_center = arena_current.Wmunu_[4][fieldIdx]; - double Wxy_center = arena_current.Wmunu_[5][fieldIdx]; - double Wxeta_center = arena_current.Wmunu_[6][fieldIdx]; - double Wyy_center = arena_current.Wmunu_[7][fieldIdx]; - double Wyeta_center = arena_current.Wmunu_[8][fieldIdx]; + double Wxx_center = arena_current.Wmunu_[4][fieldIdx]; + double Wxy_center = arena_current.Wmunu_[5][fieldIdx]; + double Wxeta_center = arena_current.Wmunu_[6][fieldIdx]; + double Wyy_center = arena_current.Wmunu_[7][fieldIdx]; + double Wyeta_center = arena_current.Wmunu_[8][fieldIdx]; double Wetaeta_center = arena_current.Wmunu_[9][fieldIdx]; // regulate Wmunu according to transversality and traceless double Wmunu_input[4][4]; @@ -901,21 +905,21 @@ void Evolve::FreezeOut_equal_tau_Surface_XY(double tau, int ieta, Wmunu_input[3][3] = Wetaeta_center; regulate_Wmunu(u_flow, Wmunu_input, Wmunu_regulated); Wtautau_center = Wmunu_regulated[0][0]; - Wtaux_center = Wmunu_regulated[0][1]; - Wtauy_center = Wmunu_regulated[0][2]; + Wtaux_center = Wmunu_regulated[0][1]; + Wtauy_center = Wmunu_regulated[0][2]; Wtaueta_center = Wmunu_regulated[0][3]; - Wxx_center = Wmunu_regulated[1][1]; - Wxy_center = Wmunu_regulated[1][2]; - Wxeta_center = Wmunu_regulated[1][3]; - Wyy_center = Wmunu_regulated[2][2]; - Wyeta_center = Wmunu_regulated[2][3]; + Wxx_center = Wmunu_regulated[1][1]; + Wxy_center = Wmunu_regulated[1][2]; + Wxeta_center = Wmunu_regulated[1][3]; + Wyy_center = Wmunu_regulated[2][2]; + Wyeta_center = Wmunu_regulated[2][3]; Wetaeta_center = Wmunu_regulated[3][3]; Cell_aux fluid_aux_center; // get other thermodynamical quantities - double e_local = arena_current.e_[fieldIdx]; - double T_local = eos.get_temperature(e_local, rhob_center); + double e_local = arena_current.e_[fieldIdx]; + double T_local = eos.get_temperature(e_local, rhob_center); if (T_local < 0) { music_message << "Evolve::FreezeOut_equal_tau_Surface: " << "T_local = " << T_local @@ -928,11 +932,11 @@ void Evolve::FreezeOut_equal_tau_Surface_XY(double tau, int ieta, double muQ_local = eos.get_muQ(e_local, rhob_center); double pressure = eos.get_pressure(e_local, rhob_center); - double eps_plus_p_over_T = (e_local + pressure)/T_local; + double eps_plus_p_over_T = (e_local + pressure) / T_local; // finally output results if (surface_in_binary) { - const int FOsize = 34 + DATA.output_vorticity*(24 + 14); + const int FOsize = 34 + DATA.output_vorticity * (24 + 14); float array[FOsize]; array[0] = static_cast(tau_center); array[1] = static_cast(x_center); @@ -972,73 +976,68 @@ void Evolve::FreezeOut_equal_tau_Surface_XY(double tau, int ieta, for (int ii = 0; ii < 6; ii++) { // no minus sign because its definition is opposite to // the kinetic vorticity - array[34+ii] = static_cast( - fluid_aux_center.omega_kSP[ii]/T_local); + array[34 + ii] = static_cast( + fluid_aux_center.omega_kSP[ii] / T_local); // the extra minus sign is from metric // output quantities for g = (1, -1, -1, -1) - array[40+ii] = static_cast( - -fluid_aux_center.omega_k[ii]/T_local); - array[46+ii] = static_cast( - -fluid_aux_center.omega_th[ii]); - array[52+ii] = static_cast( - -fluid_aux_center.omega_T[ii]/T_local/T_local); + array[40 + ii] = static_cast( + -fluid_aux_center.omega_k[ii] / T_local); + array[46 + ii] = + static_cast(-fluid_aux_center.omega_th[ii]); + array[52 + ii] = static_cast( + -fluid_aux_center.omega_T[ii] / T_local / T_local); } // the extra minus sign is from metric // output quantities for g = (1, -1, -1, -1) for (int ii = 0; ii < 10; ii++) - array[58+ii] = static_cast( - -fluid_aux_center.sigma_th[ii]); + array[58 + ii] = + static_cast(-fluid_aux_center.sigma_th[ii]); for (int ii = 0; ii < 4; ii++) - array[68+ii] = static_cast( - -fluid_aux_center.DbetaMu[ii]); + array[68 + ii] = + static_cast(-fluid_aux_center.DbetaMu[ii]); } for (int i = 0; i < FOsize; i++) { - s_file.write((char*) &(array[i]), sizeof(float)); + s_file.write((char *)&(array[i]), sizeof(float)); } } else { - s_file << std::scientific << std::setprecision(10) - << tau_center << " " << x_center << " " - << y_center << " " << eta_center << " " - << FULLSU[0] << " " << FULLSU[1] << " " - << FULLSU[2] << " " << FULLSU[3] << " " - << utau_center << " " << ux_center << " " - << uy_center << " " << ueta_center << " " - << e_local << " " << T_local << " " - << muB_local << " " << muS_local << " " - << muQ_local << " " << eps_plus_p_over_T << " " - << Wtautau_center << " " << Wtaux_center << " " - << Wtauy_center << " " << Wtaueta_center << " " - << Wxx_center << " " << Wxy_center << " " - << Wxeta_center << " " << Wyy_center << " " - << Wyeta_center << " " << Wetaeta_center << " " ; - if (DATA.turn_on_bulk) - s_file << pi_b_center << " " ; - if (DATA.turn_on_rhob) - s_file << rhob_center << " " ; + s_file << std::scientific << std::setprecision(10) << tau_center + << " " << x_center << " " << y_center << " " + << eta_center << " " << FULLSU[0] << " " << FULLSU[1] + << " " << FULLSU[2] << " " << FULLSU[3] << " " + << utau_center << " " << ux_center << " " << uy_center + << " " << ueta_center << " " << e_local << " " << T_local + << " " << muB_local << " " << muS_local << " " + << muQ_local << " " << eps_plus_p_over_T << " " + << Wtautau_center << " " << Wtaux_center << " " + << Wtauy_center << " " << Wtaueta_center << " " + << Wxx_center << " " << Wxy_center << " " << Wxeta_center + << " " << Wyy_center << " " << Wyeta_center << " " + << Wetaeta_center << " "; + if (DATA.turn_on_bulk) s_file << pi_b_center << " "; + if (DATA.turn_on_rhob) s_file << rhob_center << " "; if (DATA.turn_on_diff) s_file << qtau_center << " " << qx_center << " " - << qy_center << " " << qeta_center << " " ; + << qy_center << " " << qeta_center << " "; s_file << std::endl; } - FO_nBvsEta_[ieta] += FULLSU[0]*rhob_center; + FO_nBvsEta_[ieta] += FULLSU[0] * rhob_center; } } s_file.close(); } - int Evolve::FindFreezeOutSurface_boostinvariant_Cornelius( - double tau, Fields &arena_current, Fields &arena_freezeout) { + double tau, Fields &arena_current, Fields &arena_freezeout) { const bool surface_in_binary = DATA.freeze_surface_in_binary; // find boost-invariant hyper-surfaces int n_freeze_surf = epsFO_list.size(); int *all_frozen = new int[n_freeze_surf]; for (int i_freezesurf = 0; i_freezesurf < n_freeze_surf; i_freezesurf++) { - double epsFO = epsFO_list[i_freezesurf]/hbarc; + double epsFO = epsFO_list[i_freezesurf] / hbarc; std::stringstream strs_name; - strs_name << "surface_eps_" << std::setprecision(4) << epsFO*hbarc + strs_name << "surface_eps_" << std::setprecision(4) << epsFO * hbarc << ".dat"; std::ofstream s_file; @@ -1058,14 +1057,14 @@ int Evolve::FindFreezeOutSurface_boostinvariant_Cornelius( int intersect; int intersections = 0; - int facTau = DATA.facTau; // step to skip in tau direction + int facTau = DATA.facTau; // step to skip in tau direction int fac_x = DATA.fac_x; int fac_y = DATA.fac_y; - const double DX = fac_x*DATA.delta_x; - const double DY = fac_y*DATA.delta_y; + const double DX = fac_x * DATA.delta_x; + const double DY = fac_y * DATA.delta_y; const double DETA = 1.0; - const double DTAU = facTau*DATA.delta_tau; + const double DTAU = facTau * DATA.delta_tau; double lattice_spacing[3] = {DTAU, DX, DY}; double x_fraction[2][3]; @@ -1076,44 +1075,48 @@ int Evolve::FindFreezeOutSurface_boostinvariant_Cornelius( cornelius_ptr->init(dim, epsFO, lattice_spacing); // initialize the hyper-cube for Cornelius - Cell_small ***fluid_cube = new Cell_small ** [2]; - double ***cube = new double ** [2]; + Cell_small ***fluid_cube = new Cell_small **[2]; + double ***cube = new double **[2]; for (int i = 0; i < 2; i++) { - fluid_cube[i] = new Cell_small * [2]; - cube[i] = new double * [2]; + fluid_cube[i] = new Cell_small *[2]; + cube[i] = new double *[2]; for (int j = 0; j < 2; j++) { fluid_cube[i][j] = new Cell_small[2]; cube[i][j] = new double[2]; - for (int k = 0; k < 2; k++) - cube[i][j][k] = 0.0; + for (int k = 0; k < 2; k++) cube[i][j][k] = 0.0; } } - for (int ix=0; ix < nx - fac_x; ix += fac_x) { - double x = ix*(DATA.delta_x) - (DATA.x_size/2.0); - for (int iy=0; iy < ny - fac_y; iy += fac_y) { - double y = iy*(DATA.delta_y) - (DATA.y_size/2.0); + for (int ix = 0; ix < nx - fac_x; ix += fac_x) { + double x = ix * (DATA.delta_x) - (DATA.x_size / 2.0); + for (int iy = 0; iy < ny - fac_y; iy += fac_y) { + double y = iy * (DATA.delta_y) - (DATA.y_size / 2.0); int Idx00 = arena_current.getFieldIdx(ix, iy, 0); - int Idx10 = arena_current.getFieldIdx(ix+fac_x, iy, 0); - int Idx11 = arena_current.getFieldIdx(ix+fac_x, iy+fac_y, 0); - int Idx01 = arena_current.getFieldIdx(ix, iy+fac_y, 0); + int Idx10 = arena_current.getFieldIdx(ix + fac_x, iy, 0); + int Idx11 = + arena_current.getFieldIdx(ix + fac_x, iy + fac_y, 0); + int Idx01 = arena_current.getFieldIdx(ix, iy + fac_y, 0); // judge intersection (from Bjoern) - intersect=1; - if (( arena_current.e_[Idx11] - epsFO) - *(arena_freezeout.e_[Idx00] - epsFO) > 0.) - if (( arena_current.e_[Idx10] - epsFO) - *(arena_freezeout.e_[Idx01] - epsFO) > 0.) - if (( arena_current.e_[Idx01] - epsFO) - *(arena_freezeout.e_[Idx10] - epsFO) > 0.) - if (( arena_current.e_[Idx00] - epsFO) - *(arena_freezeout.e_[Idx11] - epsFO) > 0.) - intersect = 0; + intersect = 1; + if ((arena_current.e_[Idx11] - epsFO) + * (arena_freezeout.e_[Idx00] - epsFO) + > 0.) + if ((arena_current.e_[Idx10] - epsFO) + * (arena_freezeout.e_[Idx01] - epsFO) + > 0.) + if ((arena_current.e_[Idx01] - epsFO) + * (arena_freezeout.e_[Idx10] - epsFO) + > 0.) + if ((arena_current.e_[Idx00] - epsFO) + * (arena_freezeout.e_[Idx11] - epsFO) + > 0.) + intersect = 0; if (intersect == 0) continue; - if (ix == 0 || ix >= nx - 2*fac_x - || iy == 0 || iy >= ny - 2*fac_y) { + if (ix == 0 || ix >= nx - 2 * fac_x || iy == 0 + || iy >= ny - 2 * fac_y) { music_message << "Freeze-out cell at the boundary! " << "The grid is too small!"; music_message.flush("error"); @@ -1126,50 +1129,52 @@ int Evolve::FindFreezeOutSurface_boostinvariant_Cornelius( cube[0][0][1] = arena_freezeout.e_[Idx01]; cube[0][1][0] = arena_freezeout.e_[Idx10]; cube[0][1][1] = arena_freezeout.e_[Idx11]; - cube[1][0][0] = arena_current.e_[Idx00]; - cube[1][0][1] = arena_current.e_[Idx01]; - cube[1][1][0] = arena_current.e_[Idx10]; - cube[1][1][1] = arena_current.e_[Idx11]; + cube[1][0][0] = arena_current.e_[Idx00]; + cube[1][0][1] = arena_current.e_[Idx01]; + cube[1][1][0] = arena_current.e_[Idx10]; + cube[1][1][1] = arena_current.e_[Idx11]; // Now, the magic will happen in the Cornelius ... cornelius_ptr->find_surface_3d(cube); - // get positions of the freeze-out surface + // get positions of the freeze-out surface // and interpolating results - for (int isurf = 0; isurf < cornelius_ptr->get_Nelements(); + for (int isurf = 0; isurf < cornelius_ptr->get_Nelements(); isurf++) { // surface normal vector d^3 \sigma_\mu for (int ii = 0; ii < dim; ii++) FULLSU[ii] = cornelius_ptr->get_normal_elem(isurf, ii); - FULLSU[3] = 0.0; // rapidity direction is set to 0 + FULLSU[3] = 0.0; // rapidity direction is set to 0 // check the size of the surface normal vector - if (fabs(FULLSU[0]) > (DX*DY*DETA + 0.01)) { - music_message << "problem: volume in tau direction " - << fabs(FULLSU[0]) << " > DX*DY*DETA = " - << DX*DY*DETA; + if (fabs(FULLSU[0]) > (DX * DY * DETA + 0.01)) { + music_message << "problem: volume in tau direction " + << fabs(FULLSU[0]) + << " > DX*DY*DETA = " << DX * DY * DETA; music_message.flush("warning"); } - if (fabs(FULLSU[1]) > (DTAU*DY*DETA + 0.01)) { - music_message << "problem: volume in x direction " - << fabs(FULLSU[1]) - << " > DTAU*DY*DETA = " << DTAU*DY*DETA; + if (fabs(FULLSU[1]) > (DTAU * DY * DETA + 0.01)) { + music_message + << "problem: volume in x direction " + << fabs(FULLSU[1]) + << " > DTAU*DY*DETA = " << DTAU * DY * DETA; music_message.flush("warning"); } - if (fabs(FULLSU[2]) > (DX*DTAU*DETA+0.01)) { - music_message << "problem: volume in y direction " - << fabs(FULLSU[2]) - << " > DX*DTAU*DETA = " << DX*DTAU*DETA; + if (fabs(FULLSU[2]) > (DX * DTAU * DETA + 0.01)) { + music_message + << "problem: volume in y direction " + << fabs(FULLSU[2]) + << " > DX*DTAU*DETA = " << DX * DTAU * DETA; music_message.flush("warning"); } // position of the freeze-out fluid cell for (int ii = 0; ii < dim; ii++) { - x_fraction[1][ii] = ( - cornelius_ptr->get_centroid_elem(isurf, ii)); - x_fraction[0][ii] = ( - lattice_spacing[ii] - x_fraction[1][ii]); + x_fraction[1][ii] = + (cornelius_ptr->get_centroid_elem(isurf, ii)); + x_fraction[0][ii] = + (lattice_spacing[ii] - x_fraction[1][ii]); } const double tau_center = tau - DTAU + x_fraction[1][0]; const double x_center = x + x_fraction[1][1]; @@ -1177,16 +1182,22 @@ int Evolve::FindFreezeOutSurface_boostinvariant_Cornelius( const double eta_center = 0.0; // perform 3-d linear interpolation for all fluid quantities - fluid_cube[0][0][0] = arena_freezeout.getCell(ix , iy , 0); - fluid_cube[0][0][1] = arena_freezeout.getCell(ix , iy+fac_y, 0); - fluid_cube[0][1][0] = arena_freezeout.getCell(ix+fac_x, iy , 0); - fluid_cube[0][1][1] = arena_freezeout.getCell(ix+fac_x, iy+fac_y, 0); - fluid_cube[1][0][0] = arena_current.getCell(ix , iy , 0); - fluid_cube[1][0][1] = arena_current.getCell(ix , iy+fac_y, 0); - fluid_cube[1][1][0] = arena_current.getCell(ix+fac_x, iy , 0); - fluid_cube[1][1][1] = arena_current.getCell(ix+fac_x, iy+fac_y, 0); + fluid_cube[0][0][0] = arena_freezeout.getCell(ix, iy, 0); + fluid_cube[0][0][1] = + arena_freezeout.getCell(ix, iy + fac_y, 0); + fluid_cube[0][1][0] = + arena_freezeout.getCell(ix + fac_x, iy, 0); + fluid_cube[0][1][1] = + arena_freezeout.getCell(ix + fac_x, iy + fac_y, 0); + fluid_cube[1][0][0] = arena_current.getCell(ix, iy, 0); + fluid_cube[1][0][1] = + arena_current.getCell(ix, iy + fac_y, 0); + fluid_cube[1][1][0] = + arena_current.getCell(ix + fac_x, iy, 0); + fluid_cube[1][1][1] = + arena_current.getCell(ix + fac_x, iy + fac_y, 0); auto fluid_center = three_dimension_linear_interpolation( - lattice_spacing, x_fraction, fluid_cube); + lattice_spacing, x_fraction, fluid_cube); // reconstruct q^\tau from the transverality criteria FlowVec u_flow = fluid_center.u; @@ -1204,14 +1215,20 @@ int Evolve::FindFreezeOutSurface_boostinvariant_Cornelius( double Wmunu_input[4][4]; double Wmunu_regulated[4][4]; Wmunu_input[0][0] = fluid_center.Wmunu[0]; - Wmunu_input[0][1] = Wmunu_input[1][0] = fluid_center.Wmunu[1]; - Wmunu_input[0][2] = Wmunu_input[2][0] = fluid_center.Wmunu[2]; - Wmunu_input[0][3] = Wmunu_input[3][0] = fluid_center.Wmunu[3]; + Wmunu_input[0][1] = Wmunu_input[1][0] = + fluid_center.Wmunu[1]; + Wmunu_input[0][2] = Wmunu_input[2][0] = + fluid_center.Wmunu[2]; + Wmunu_input[0][3] = Wmunu_input[3][0] = + fluid_center.Wmunu[3]; Wmunu_input[1][1] = fluid_center.Wmunu[4]; - Wmunu_input[1][2] = Wmunu_input[2][1] = fluid_center.Wmunu[5]; - Wmunu_input[1][3] = Wmunu_input[3][1] = fluid_center.Wmunu[6]; + Wmunu_input[1][2] = Wmunu_input[2][1] = + fluid_center.Wmunu[5]; + Wmunu_input[1][3] = Wmunu_input[3][1] = + fluid_center.Wmunu[6]; Wmunu_input[2][2] = fluid_center.Wmunu[7]; - Wmunu_input[2][3] = Wmunu_input[3][2] = fluid_center.Wmunu[8]; + Wmunu_input[2][3] = Wmunu_input[3][2] = + fluid_center.Wmunu[8]; Wmunu_input[3][3] = fluid_center.Wmunu[9]; regulate_Wmunu(u_flow, Wmunu_input, Wmunu_regulated); fluid_center.Wmunu[0] = Wmunu_regulated[0][0]; @@ -1231,14 +1248,14 @@ int Evolve::FindFreezeOutSurface_boostinvariant_Cornelius( double muS = eos.get_muS(epsFO, fluid_center.rhob); double muQ = eos.get_muQ(epsFO, fluid_center.rhob); if (TFO < 0) { - music_message << "TFO=" << TFO - << "<0. ERROR. exiting."; + music_message << "TFO=" << TFO << "<0. ERROR. exiting."; music_message.flush("error"); exit(1); } - double pressure = eos.get_pressure(epsFO, fluid_center.rhob); - double eps_plus_p_over_T_FO = (epsFO + pressure)/TFO; + double pressure = + eos.get_pressure(epsFO, fluid_center.rhob); + double eps_plus_p_over_T_FO = (epsFO + pressure) / TFO; // finally output results !!!! if (surface_in_binary) { @@ -1248,9 +1265,10 @@ int Evolve::FindFreezeOutSurface_boostinvariant_Cornelius( array[2] = static_cast(y_center); array[3] = static_cast(eta_center); for (int ii = 0; ii < 4; ii++) - array[4+ii] = static_cast(FULLSU[ii]); + array[4 + ii] = static_cast(FULLSU[ii]); for (int ii = 0; ii < 4; ii++) - array[8+ii] = static_cast(fluid_center.u[ii]); + array[8 + ii] = + static_cast(fluid_center.u[ii]); array[12] = static_cast(epsFO); array[13] = static_cast(TFO); array[14] = static_cast(muB); @@ -1258,24 +1276,26 @@ int Evolve::FindFreezeOutSurface_boostinvariant_Cornelius( array[16] = static_cast(muQ); array[17] = static_cast(eps_plus_p_over_T_FO); for (int ii = 0; ii < 10; ii++) - array[18+ii] = static_cast(fluid_center.Wmunu[ii]); + array[18 + ii] = + static_cast(fluid_center.Wmunu[ii]); array[28] = fluid_center.pi_b; array[29] = fluid_center.rhob; for (int ii = 0; ii < 4; ii++) - array[30+ii] = static_cast(fluid_center.Wmunu[10+ii]); + array[30 + ii] = + static_cast(fluid_center.Wmunu[10 + ii]); for (int i = 0; i < 34; i++) - s_file.write((char*) &(array[i]), sizeof(float)); + s_file.write((char *)&(array[i]), sizeof(float)); } else { s_file << std::scientific << std::setprecision(10) << tau_center << " " << x_center << " " << y_center << " " << eta_center << " " << FULLSU[0] << " " << FULLSU[1] << " " << FULLSU[2] << " " << FULLSU[3] << " " - << fluid_center.u[0] << " " << fluid_center.u[1] << " " - << fluid_center.u[2] << " " << fluid_center.u[3] << " " - << epsFO << " " << TFO << " " << muB << " " - << muS << " " << muQ << " " - << eps_plus_p_over_T_FO << " "; + << fluid_center.u[0] << " " << fluid_center.u[1] + << " " << fluid_center.u[2] << " " + << fluid_center.u[3] << " " << epsFO << " " + << TFO << " " << muB << " " << muS << " " << muQ + << " " << eps_plus_p_over_T_FO << " "; for (int ii = 0; ii < 10; ii++) s_file << std::scientific << std::setprecision(10) << fluid_center.Wmunu[ii] << " "; @@ -1285,7 +1305,8 @@ int Evolve::FindFreezeOutSurface_boostinvariant_Cornelius( s_file << fluid_center.rhob << " "; if (DATA.turn_on_diff) for (int ii = 10; ii < 14; ii++) - s_file << std::scientific << std::setprecision(10) + s_file << std::scientific + << std::setprecision(10) << fluid_center.Wmunu[ii] << " "; s_file << std::endl; } @@ -1298,19 +1319,18 @@ int Evolve::FindFreezeOutSurface_boostinvariant_Cornelius( // clean up for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { - delete [] cube[i][j]; - delete [] fluid_cube[i][j]; + delete[] cube[i][j]; + delete[] fluid_cube[i][j]; } - delete [] cube[i]; - delete [] fluid_cube[i]; + delete[] cube[i]; + delete[] fluid_cube[i]; } - delete [] cube; - delete [] fluid_cube; + delete[] cube; + delete[] fluid_cube; // judge whether the entire fireball is freeze-out all_frozen[i_freezesurf] = 0; - if (intersections == 0) - all_frozen[i_freezesurf] = 1; + if (intersections == 0) all_frozen[i_freezesurf] = 1; } int all_frozen_flag = 1; @@ -1321,55 +1341,55 @@ int Evolve::FindFreezeOutSurface_boostinvariant_Cornelius( music_message.info("All cells frozen out. Exiting."); } - delete [] all_frozen; - return(all_frozen_flag); + delete[] all_frozen; + return (all_frozen_flag); } -void Evolve::regulate_qmu(const FlowVec u, const double q[], - double q_regulated[]) const { - double u_dot_q = - u[0]*q[0] + u[1]*q[1] + u[2]*q[2] + u[3]*q[3]; +void Evolve::regulate_qmu( + const FlowVec u, const double q[], double q_regulated[]) const { + double u_dot_q = -u[0] * q[0] + u[1] * q[1] + u[2] * q[2] + u[3] * q[3]; for (int i = 0; i < 4; i++) { - q_regulated[i] = q[i] + u[i]*u_dot_q; + q_regulated[i] = q[i] + u[i] * u_dot_q; } } -void Evolve::regulate_Wmunu(const FlowVec u, const double Wmunu[4][4], - double Wmunu_regulated[4][4]) const { - const double gmunu[4][4] = {{-1, 0, 0, 0}, - { 0, 1, 0, 0}, - { 0, 0, 1, 0}, - { 0, 0, 0, 1}}; +void Evolve::regulate_Wmunu( + const FlowVec u, const double Wmunu[4][4], + double Wmunu_regulated[4][4]) const { + const double gmunu[4][4] = { + {-1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}; double u_dot_pi[4]; double u_mu[4]; for (int i = 0; i < 4; i++) { - u_dot_pi[i] = (- u[0]*Wmunu[0][i] + u[1]*Wmunu[1][i] - + u[2]*Wmunu[2][i] + u[3]*Wmunu[3][i]); - u_mu[i] = gmunu[i][i]*u[i]; + u_dot_pi[i] = + (-u[0] * Wmunu[0][i] + u[1] * Wmunu[1][i] + u[2] * Wmunu[2][i] + + u[3] * Wmunu[3][i]); + u_mu[i] = gmunu[i][i] * u[i]; } - double tr_pi = - Wmunu[0][0] + Wmunu[1][1] + Wmunu[2][2] + Wmunu[3][3]; + double tr_pi = -Wmunu[0][0] + Wmunu[1][1] + Wmunu[2][2] + Wmunu[3][3]; double u_dot_pi_dot_u = 0.0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - u_dot_pi_dot_u += u_mu[i]*Wmunu[i][j]*u_mu[j]; + u_dot_pi_dot_u += u_mu[i] * Wmunu[i][j] * u_mu[j]; } } for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - Wmunu_regulated[i][j] = ( - Wmunu[i][j] + u[i]*u_dot_pi[j] + u[j]*u_dot_pi[i] - + u[i]*u[j]*u_dot_pi_dot_u - - 1./3.*(gmunu[i][j] + u[i]*u[j])*(tr_pi + u_dot_pi_dot_u)); + Wmunu_regulated[i][j] = + (Wmunu[i][j] + u[i] * u_dot_pi[j] + u[j] * u_dot_pi[i] + + u[i] * u[j] * u_dot_pi_dot_u + - 1. / 3. * (gmunu[i][j] + u[i] * u[j]) + * (tr_pi + u_dot_pi_dot_u)); } } } void Evolve::initialize_freezeout_surface_info() { if (DATA.useEpsFO == 0) { - const double e_freeze = eos.get_T2e(DATA.TFO, 0.0)*Util::hbarc; + const double e_freeze = eos.get_T2e(DATA.TFO, 0.0) * Util::hbarc; epsFO_list.push_back(e_freeze); - music_message << "Freeze out at a constant temperature T = " - << DATA.TFO << " GeV, e_fo = " - << e_freeze << " GeV/fm^3"; + music_message << "Freeze out at a constant temperature T = " << DATA.TFO + << " GeV, e_fo = " << e_freeze << " GeV/fm^3"; music_message.flush("info"); return; } @@ -1379,22 +1399,23 @@ void Evolve::initialize_freezeout_surface_info() { int n_freeze_surf = DATA.N_freeze_out; double freeze_max_ed = DATA.eps_freeze_max; double freeze_min_ed = DATA.eps_freeze_min; - double d_epsFO = ((freeze_max_ed - freeze_min_ed) - /(n_freeze_surf - 1 + Util::small_eps)); + double d_epsFO = + ((freeze_max_ed - freeze_min_ed) + / (n_freeze_surf - 1 + Util::small_eps)); for (int isurf = 0; isurf < n_freeze_surf; isurf++) { - double temp_epsFO = freeze_min_ed + isurf*d_epsFO; + double temp_epsFO = freeze_min_ed + isurf * d_epsFO; epsFO_list.push_back(temp_epsFO); } - } else if(freeze_eps_flag == 1) { + } else if (freeze_eps_flag == 1) { // read in from a file std::string eps_freeze_list_filename = DATA.freeze_list_filename; - music_message << "read in freeze out surface information from " + music_message << "read in freeze out surface information from " << eps_freeze_list_filename; music_message.flush("info"); std::ifstream freeze_list_file(eps_freeze_list_filename.c_str()); if (!freeze_list_file) { music_message << "Evolve::initialize_freezeout_surface_info: " - << "can not open freeze-out list file: " + << "can not open freeze-out list file: " << eps_freeze_list_filename; music_message.flush("error"); exit(1); @@ -1402,9 +1423,9 @@ void Evolve::initialize_freezeout_surface_info() { std::string dummy; double temp_epsFO, dummyd; getline(freeze_list_file, dummy); // get rid of the comment - while(1) { - freeze_list_file >> temp_epsFO >> dummyd >> dummyd - >> dummyd >> dummyd >> dummyd >> dummyd; + while (1) { + freeze_list_file >> temp_epsFO >> dummyd >> dummyd >> dummyd + >> dummyd >> dummyd >> dummyd; if (!freeze_list_file.eof()) { epsFO_list.push_back(temp_epsFO); } else { @@ -1428,9 +1449,8 @@ void Evolve::initialize_freezeout_surface_info() { } } - Cell_small Evolve::three_dimension_linear_interpolation( - double* lattice_spacing, double fraction[2][3], Cell_small*** cube) { + double *lattice_spacing, double fraction[2][3], Cell_small ***cube) { double denorm = 1.0; for (int i = 0; i < 3; i++) { denorm *= lattice_spacing[i]; @@ -1440,18 +1460,18 @@ Cell_small Evolve::three_dimension_linear_interpolation( for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { - results = results + (cube[i][j][k]*fraction[i][0] - *fraction[j][1]*fraction[k][2]); + results = results + + (cube[i][j][k] * fraction[i][0] * fraction[j][1] + * fraction[k][2]); } } } - results = results*(1./denorm); - return(results); + results = results * (1. / denorm); + return (results); } - Cell_small Evolve::four_dimension_linear_interpolation( - double* lattice_spacing, double fraction[2][4], Cell_small**** cube) { + double *lattice_spacing, double fraction[2][4], Cell_small ****cube) { double denorm = 1.0; Cell_small results; for (int i = 0; i < 4; i++) { @@ -1461,20 +1481,20 @@ Cell_small Evolve::four_dimension_linear_interpolation( for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { for (int l = 0; l < 2; l++) { - results = results + ( - cube[i][j][k][l]*fraction[i][0]*fraction[j][1] - *fraction[k][2]*fraction[l][3]); + results = + results + + (cube[i][j][k][l] * fraction[i][0] * fraction[j][1] + * fraction[k][2] * fraction[l][3]); } } } } - results = results*(1./denorm); + results = results * (1. / denorm); return (results); } - Cell_aux Evolve::three_dimension_linear_interpolation( - double* lattice_spacing, double fraction[2][3], Cell_aux*** cube) { + double *lattice_spacing, double fraction[2][3], Cell_aux ***cube) { double denorm = 1.0; for (int i = 0; i < 3; i++) { denorm *= lattice_spacing[i]; @@ -1484,18 +1504,18 @@ Cell_aux Evolve::three_dimension_linear_interpolation( for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { - results = results + (cube[i][j][k]*fraction[i][0] - *fraction[j][1]*fraction[k][2]); + results = results + + (cube[i][j][k] * fraction[i][0] * fraction[j][1] + * fraction[k][2]); } } } - results = results*(1./denorm); - return(results); + results = results * (1. / denorm); + return (results); } - Cell_aux Evolve::four_dimension_linear_interpolation( - double* lattice_spacing, double fraction[2][4], Cell_aux**** cube) { + double *lattice_spacing, double fraction[2][4], Cell_aux ****cube) { double denorm = 1.0; Cell_aux results; for (int i = 0; i < 4; i++) { @@ -1505,13 +1525,14 @@ Cell_aux Evolve::four_dimension_linear_interpolation( for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { for (int l = 0; l < 2; l++) { - results = results + ( - cube[i][j][k][l]*fraction[i][0]*fraction[j][1] - *fraction[k][2]*fraction[l][3]); + results = + results + + (cube[i][j][k][l] * fraction[i][0] * fraction[j][1] + * fraction[k][2] * fraction[l][3]); } } } } - results = results*(1./denorm); + results = results * (1. / denorm); return (results); } diff --git a/src/evolve.h b/src/evolve.h index 8f8642e8..0f92b39c 100644 --- a/src/evolve.h +++ b/src/evolve.h @@ -4,21 +4,22 @@ #include #include -#include "util.h" -#include "data.h" + +#include "HydroinfoMUSIC.h" +#include "advance.h" #include "cell.h" -#include "grid_info.h" +#include "data.h" #include "eos.h" -#include "advance.h" #include "fields.h" +#include "grid_info.h" #include "hydro_source_base.h" #include "pretty_ostream.h" -#include "HydroinfoMUSIC.h" +#include "util.h" // this is a control class for the hydrodynamic evolution class Evolve { - private: - const EOS &eos; // declare EOS object + private: + const EOS &eos; // declare EOS object InitData &DATA; std::shared_ptr hydro_source_terms_ptr; @@ -35,50 +36,50 @@ class Evolve { std::vector FO_nBvsEta_; - public: - Evolve(const EOS &eos, InitData &DATA_in, - std::shared_ptr hydro_source_ptr_in); - int EvolveIt(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, - Fields &arenaFieldsNext, HydroinfoMUSIC &hydro_info_ptr); + public: + Evolve( + const EOS &eos, InitData &DATA_in, + std::shared_ptr hydro_source_ptr_in); + int EvolveIt( + Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, + Fields &arenaFieldsNext, HydroinfoMUSIC &hydro_info_ptr); - void AdvanceRK(double tau, Fields* &fpPrev, Fields* &fpCurr, - Fields* &fpNext); + void AdvanceRK( + double tau, Fields *&fpPrev, Fields *&fpCurr, Fields *&fpNext); int FreezeOut_equal_tau_Surface(double tau, Fields &arena_current); - void FreezeOut_equal_tau_Surface_XY(double tau, - int ieta, Fields &arena_current, - int thread_id, double epsFO); - int FindFreezeOutSurface_Cornelius(double tau, - Fields &arena_prev, Fields &arena_current, + void FreezeOut_equal_tau_Surface_XY( + double tau, int ieta, Fields &arena_current, int thread_id, + double epsFO); + int FindFreezeOutSurface_Cornelius( + double tau, Fields &arena_prev, Fields &arena_current, Fields &arena_freezeout_prev, Fields &arena_freezeout); - int FindFreezeOutSurface_Cornelius_XY(double tau, int ieta, - Fields &arena_prev, - Fields &arena_current, - Fields &arena_freezeout_prev, - Fields &arena_freezeout, - int thread_id, double epsFO); + int FindFreezeOutSurface_Cornelius_XY( + double tau, int ieta, Fields &arena_prev, Fields &arena_current, + Fields &arena_freezeout_prev, Fields &arena_freezeout, int thread_id, + double epsFO); int FindFreezeOutSurface_boostinvariant_Cornelius( - double tau, Fields &arena_current, Fields &arena_freezeout); + double tau, Fields &arena_current, Fields &arena_freezeout); - void store_previous_step_for_freezeout(Fields &arenaCurr, - Fields &arenaFreeze); - void regulate_qmu(const FlowVec u, const double q[], - double q_regulated[]) const; - void regulate_Wmunu(const FlowVec u, const double Wmunu[4][4], - double Wmunu_regulated[4][4]) const; + void store_previous_step_for_freezeout( + Fields &arenaCurr, Fields &arenaFreeze); + void regulate_qmu( + const FlowVec u, const double q[], double q_regulated[]) const; + void regulate_Wmunu( + const FlowVec u, const double Wmunu[4][4], + double Wmunu_regulated[4][4]) const; void initialize_freezeout_surface_info(); Cell_small four_dimension_linear_interpolation( - double* lattice_spacing, double fraction[2][4], Cell_small**** cube); + double *lattice_spacing, double fraction[2][4], Cell_small ****cube); Cell_small three_dimension_linear_interpolation( - double* lattice_spacing, double fraction[2][3], Cell_small*** cube); + double *lattice_spacing, double fraction[2][3], Cell_small ***cube); Cell_aux four_dimension_linear_interpolation( - double* lattice_spacing, double fraction[2][4], Cell_aux**** cube); + double *lattice_spacing, double fraction[2][4], Cell_aux ****cube); Cell_aux three_dimension_linear_interpolation( - double* lattice_spacing, double fraction[2][3], Cell_aux*** cube); + double *lattice_spacing, double fraction[2][3], Cell_aux ***cube); }; #endif // SRC_EVOLVE_H_ - diff --git a/src/fields.cpp b/src/fields.cpp index e01efdbb..d4b96444 100644 --- a/src/fields.cpp +++ b/src/fields.cpp @@ -1,8 +1,8 @@ // Copyright 2021 Chun Shen #include "fields.h" -#include "cell.h" +#include "cell.h" Fields::~Fields() { e_.clear(); @@ -12,12 +12,11 @@ Fields::~Fields() { Wmunu_.clear(); } - void Fields::resizeFields(int Nx, int Ny, int Neta) { - Nx_ = Nx; - Ny_ = Ny; + Nx_ = Nx; + Ny_ = Ny; Neta_ = Neta; - int Npoints = Nx*Ny*Neta; + int Npoints = Nx * Ny * Neta; e_.resize(Npoints, 0.); rhob_.resize(Npoints, 0.); @@ -35,16 +34,14 @@ void Fields::resizeFields(int Nx, int Ny, int Neta) { } } - Cell_small Fields::getCell(int ix, int iy, int ieta) { - ix = std::max(0, std::min(Nx_-1 , ix )); - iy = std::max(0, std::min(Ny_-1 , iy )); - ieta = std::max(0, std::min(Neta_-1, ieta)); + ix = std::max(0, std::min(Nx_ - 1, ix)); + iy = std::max(0, std::min(Ny_ - 1, iy)); + ieta = std::max(0, std::min(Neta_ - 1, ieta)); int fieldIdx = getFieldIdx(ix, iy, ieta); - return(getCell(fieldIdx)); + return (getCell(fieldIdx)); } - Cell_small Fields::getCell(const int idx) { Cell_small cell; cell.epsilon = e_[idx]; @@ -56,18 +53,16 @@ Cell_small Fields::getCell(const int idx) { cell.Wmunu[i] = Wmunu_[i][idx]; } cell.pi_b = piBulk_[idx]; - return(cell); + return (cell); } - int Fields::getFieldIdxHalo(int ix, int iy, int ieta) { - ix = std::max(0, std::min(Nx_-1 , ix )); - iy = std::max(0, std::min(Ny_-1 , iy )); - ieta = std::max(0, std::min(Neta_-1, ieta)); - return(getFieldIdx(ix, iy, ieta)); + ix = std::max(0, std::min(Nx_ - 1, ix)); + iy = std::max(0, std::min(Ny_ - 1, iy)); + ieta = std::max(0, std::min(Neta_ - 1, ieta)); + return (getFieldIdx(ix, iy, ieta)); } - ReconstCell Fields::getCellIdeal(const int idx) { ReconstCell cell; cell.e = e_[idx]; @@ -75,15 +70,13 @@ ReconstCell Fields::getCellIdeal(const int idx) { for (int i = 0; i < Nu_; i++) { cell.u[i] = u_[i][idx]; } - return(cell); + return (cell); } - ReconstCell Fields::getCellIdeal(int ix, int iy, int ieta) { - ix = std::max(0, std::min(Nx_-1 , ix )); - iy = std::max(0, std::min(Ny_-1 , iy )); - ieta = std::max(0, std::min(Neta_-1, ieta)); + ix = std::max(0, std::min(Nx_ - 1, ix)); + iy = std::max(0, std::min(Ny_ - 1, iy)); + ieta = std::max(0, std::min(Neta_ - 1, ieta)); int fieldIdx = getFieldIdx(ix, iy, ieta); - return(getCellIdeal(fieldIdx)); + return (getCellIdeal(fieldIdx)); } - diff --git a/src/fields.h b/src/fields.h index 98c8e3b1..04c5e33a 100644 --- a/src/fields.h +++ b/src/fields.h @@ -3,20 +3,21 @@ #define FIELDS_H_ #include + #include "cell.h" #include "data_struct.h" class Fields { - private: + private: const int NWmunu_ = 14; // dimension for pi^{\mu\nu} const int Nu_ = 4; // dimension for u^\mu // field size in 3D - int Nx_ = 0; - int Ny_ = 0; + int Nx_ = 0; + int Ny_ = 0; int Neta_ = 0; - public: + public: // Scalar fields std::vector e_; std::vector rhob_; @@ -27,20 +28,18 @@ class Fields { std::vector> Wmunu_; Fields() = default; - Fields(int Nx, int Ny, int Neta) { - resizeFields(Nx, Ny, Neta); - } + Fields(int Nx, int Ny, int Neta) { resizeFields(Nx, Ny, Neta); } ~Fields(); - int nX() const {return(Nx_);} - int nY() const {return(Ny_);} - int nEta() const {return(Neta_);} + int nX() const { return (Nx_); } + int nY() const { return (Ny_); } + int nEta() const { return (Neta_); } void resizeFields(int Nx, int Ny, int Neta); int getFieldIdx(int ix, int iy, int ieta) { - return(ix + Nx_*(iy + Ny_*ieta)); + return (ix + Nx_ * (iy + Ny_ * ieta)); } int getFieldIdxHalo(int ix, int iy, int ieta); @@ -52,110 +51,120 @@ class Fields { ReconstCell getCellIdeal(int ix, int iy, int ieta); }; - -template -void FieldNeighbourLoopIdeal1(Fields &arena, int cx, int cy, int ceta, - Func func) { - const std::array dx = {-1, 1, 0, 0, 0, 0}; - const std::array dy = { 0, 0, -1, 1, 0, 0}; - const std::array deta = { 0, 0, 0, 0, -1, 1}; - for(int dir = 0; dir < 3; dir++) { - int m1nx = dx [2*dir]; - int m1ny = dy [2*dir]; - int m1neta = deta[2*dir]; - int p1nx = dx [2*dir+1]; - int p1ny = dy [2*dir+1]; - int p1neta = deta[2*dir+1]; - const auto Ic = arena.getFieldIdxHalo(cx, cy, ceta ); - const auto Ip1 = arena.getFieldIdxHalo(cx+p1nx, cy+p1ny, ceta+p1neta); - const auto Im1 = arena.getFieldIdxHalo(cx+m1nx, cy+m1ny, ceta+m1neta); - func(Ic, Ip1, Im1, dir+1); +template +void FieldNeighbourLoopIdeal1( + Fields& arena, int cx, int cy, int ceta, Func func) { + const std::array dx = {-1, 1, 0, 0, 0, 0}; + const std::array dy = {0, 0, -1, 1, 0, 0}; + const std::array deta = {0, 0, 0, 0, -1, 1}; + for (int dir = 0; dir < 3; dir++) { + int m1nx = dx[2 * dir]; + int m1ny = dy[2 * dir]; + int m1neta = deta[2 * dir]; + int p1nx = dx[2 * dir + 1]; + int p1ny = dy[2 * dir + 1]; + int p1neta = deta[2 * dir + 1]; + const auto Ic = arena.getFieldIdxHalo(cx, cy, ceta); + const auto Ip1 = + arena.getFieldIdxHalo(cx + p1nx, cy + p1ny, ceta + p1neta); + const auto Im1 = + arena.getFieldIdxHalo(cx + m1nx, cy + m1ny, ceta + m1neta); + func(Ic, Ip1, Im1, dir + 1); } } - -template -void FieldNeighbourLoopIdeal2(Fields &arena, int cx, int cy, int ceta, - Func func) { - const std::array dx = {-1, 1, 0, 0, 0, 0}; - const std::array dy = { 0, 0, -1, 1, 0, 0}; - const std::array deta = { 0, 0, 0, 0, -1, 1}; - for(int dir = 0; dir < 3; dir++) { - int m1nx = dx [2*dir]; - int m1ny = dy [2*dir]; - int m1neta = deta[2*dir]; - int p1nx = dx [2*dir+1]; - int p1ny = dy [2*dir+1]; - int p1neta = deta[2*dir+1]; - int m2nx = 2*m1nx; - int m2ny = 2*m1ny; - int m2neta = 2*m1neta; - int p2nx = 2*p1nx; - int p2ny = 2*p1ny; - int p2neta = 2*p1neta; - auto c = arena.getCellIdeal(cx, cy, ceta ); - const auto p1 = arena.getCellIdeal(cx+p1nx, cy+p1ny, ceta+p1neta); - const auto p2 = arena.getCellIdeal(cx+p2nx, cy+p2ny, ceta+p2neta); - const auto m1 = arena.getCellIdeal(cx+m1nx, cy+m1ny, ceta+m1neta); - const auto m2 = arena.getCellIdeal(cx+m2nx, cy+m2ny, ceta+m2neta); - func(c, p1, p2, m1, m2, dir+1); +template +void FieldNeighbourLoopIdeal2( + Fields& arena, int cx, int cy, int ceta, Func func) { + const std::array dx = {-1, 1, 0, 0, 0, 0}; + const std::array dy = {0, 0, -1, 1, 0, 0}; + const std::array deta = {0, 0, 0, 0, -1, 1}; + for (int dir = 0; dir < 3; dir++) { + int m1nx = dx[2 * dir]; + int m1ny = dy[2 * dir]; + int m1neta = deta[2 * dir]; + int p1nx = dx[2 * dir + 1]; + int p1ny = dy[2 * dir + 1]; + int p1neta = deta[2 * dir + 1]; + int m2nx = 2 * m1nx; + int m2ny = 2 * m1ny; + int m2neta = 2 * m1neta; + int p2nx = 2 * p1nx; + int p2ny = 2 * p1ny; + int p2neta = 2 * p1neta; + auto c = arena.getCellIdeal(cx, cy, ceta); + const auto p1 = arena.getCellIdeal(cx + p1nx, cy + p1ny, ceta + p1neta); + const auto p2 = arena.getCellIdeal(cx + p2nx, cy + p2ny, ceta + p2neta); + const auto m1 = arena.getCellIdeal(cx + m1nx, cy + m1ny, ceta + m1neta); + const auto m2 = arena.getCellIdeal(cx + m2nx, cy + m2ny, ceta + m2neta); + func(c, p1, p2, m1, m2, dir + 1); } } - -template -void FieldNeighbourLoop1(Fields &arena, int cx, int cy, int ceta, Func func) { - const std::array dx = {-1, 1, 0, 0, 0, 0}; - const std::array dy = { 0, 0, -1, 1, 0, 0}; - const std::array deta = { 0, 0, 0, 0, -1, 1}; - for(int dir = 0; dir < 3; dir++) { - int m1nx = dx [2*dir]; - int m1ny = dy [2*dir]; - int m1neta = deta[2*dir]; - int p1nx = dx [2*dir+1]; - int p1ny = dy [2*dir+1]; - int p1neta = deta[2*dir+1]; - const auto Ic = arena.getFieldIdxHalo(cx, cy, ceta ); - const auto Ip1 = arena.getFieldIdxHalo(cx+p1nx, cy+p1ny, ceta+p1neta); - const auto Im1 = arena.getFieldIdxHalo(cx+m1nx, cy+m1ny, ceta+m1neta); - func(Ic, Ip1, Im1, dir+1); +template +void FieldNeighbourLoop1(Fields& arena, int cx, int cy, int ceta, Func func) { + const std::array dx = {-1, 1, 0, 0, 0, 0}; + const std::array dy = {0, 0, -1, 1, 0, 0}; + const std::array deta = {0, 0, 0, 0, -1, 1}; + for (int dir = 0; dir < 3; dir++) { + int m1nx = dx[2 * dir]; + int m1ny = dy[2 * dir]; + int m1neta = deta[2 * dir]; + int p1nx = dx[2 * dir + 1]; + int p1ny = dy[2 * dir + 1]; + int p1neta = deta[2 * dir + 1]; + const auto Ic = arena.getFieldIdxHalo(cx, cy, ceta); + const auto Ip1 = + arena.getFieldIdxHalo(cx + p1nx, cy + p1ny, ceta + p1neta); + const auto Im1 = + arena.getFieldIdxHalo(cx + m1nx, cy + m1ny, ceta + m1neta); + func(Ic, Ip1, Im1, dir + 1); } } - -template -void FieldNeighbourLoop2(Fields &arena, int cx, int cy, int ceta, Func func) { - const std::array dx = {-1, 1, 0, 0, 0, 0}; - const std::array dy = { 0, 0, -1, 1, 0, 0}; - const std::array deta = { 0, 0, 0, 0, -1, 1}; - for(int dir = 0; dir < 3; dir++) { - int m1nx = dx [2*dir]; - int m1ny = dy [2*dir]; - int m1neta = deta[2*dir]; - int p1nx = dx [2*dir+1]; - int p1ny = dy [2*dir+1]; - int p1neta = deta[2*dir+1]; - int m2nx = 2*m1nx; - int m2ny = 2*m1ny; - int m2neta = 2*m1neta; - int p2nx = 2*p1nx; - int p2ny = 2*p1ny; - int p2neta = 2*p1neta; - const auto Ic = arena.getFieldIdxHalo(cx, cy, ceta ); - const auto Ip1 = arena.getFieldIdxHalo(cx+p1nx, cy+p1ny, ceta+p1neta); - const auto Ip2 = arena.getFieldIdxHalo(cx+p2nx, cy+p2ny, ceta+p2neta); - const auto Im1 = arena.getFieldIdxHalo(cx+m1nx, cy+m1ny, ceta+m1neta); - const auto Im2 = arena.getFieldIdxHalo(cx+m2nx, cy+m2ny, ceta+m2neta); - func(Ic, Ip1, Ip2, Im1, Im2, dir+1); +template +void FieldNeighbourLoop2(Fields& arena, int cx, int cy, int ceta, Func func) { + const std::array dx = {-1, 1, 0, 0, 0, 0}; + const std::array dy = {0, 0, -1, 1, 0, 0}; + const std::array deta = {0, 0, 0, 0, -1, 1}; + for (int dir = 0; dir < 3; dir++) { + int m1nx = dx[2 * dir]; + int m1ny = dy[2 * dir]; + int m1neta = deta[2 * dir]; + int p1nx = dx[2 * dir + 1]; + int p1ny = dy[2 * dir + 1]; + int p1neta = deta[2 * dir + 1]; + int m2nx = 2 * m1nx; + int m2ny = 2 * m1ny; + int m2neta = 2 * m1neta; + int p2nx = 2 * p1nx; + int p2ny = 2 * p1ny; + int p2neta = 2 * p1neta; + const auto Ic = arena.getFieldIdxHalo(cx, cy, ceta); + const auto Ip1 = + arena.getFieldIdxHalo(cx + p1nx, cy + p1ny, ceta + p1neta); + const auto Ip2 = + arena.getFieldIdxHalo(cx + p2nx, cy + p2ny, ceta + p2neta); + const auto Im1 = + arena.getFieldIdxHalo(cx + m1nx, cy + m1ny, ceta + m1neta); + const auto Im2 = + arena.getFieldIdxHalo(cx + m2nx, cy + m2ny, ceta + m2neta); + func(Ic, Ip1, Ip2, Im1, Im2, dir + 1); } } -#define FNLILAMBDAS1 [&](const int& Ic, const int& Ip1, const int& Im1, const int direction) +#define FNLILAMBDAS1 \ + [&](const int& Ic, const int& Ip1, const int& Im1, const int direction) -#define FNLILAMBDAS2 [&](ReconstCell& c, const ReconstCell& p1, const ReconstCell& p2, const ReconstCell& m1, const ReconstCell& m2, const int direction) +#define FNLILAMBDAS2 \ + [&](ReconstCell & c, const ReconstCell& p1, const ReconstCell& p2, \ + const ReconstCell& m1, const ReconstCell& m2, const int direction) -#define FNLLAMBDAS1 [&](const int& Ic, const int& Ip1, const int& Im1, const int direction) +#define FNLLAMBDAS1 \ + [&](const int& Ic, const int& Ip1, const int& Im1, const int direction) -#define FNLLAMBDAS2 [&](const int& Ic, const int& Ip1, const int& Ip2, const int& Im1, const int& Im2, const int direction) +#define FNLLAMBDAS2 \ + [&](const int& Ic, const int& Ip1, const int& Ip2, const int& Im1, \ + const int& Im2, const int direction) #endif diff --git a/src/freeze.cpp b/src/freeze.cpp index 925b9fde..06ffa3a5 100644 --- a/src/freeze.cpp +++ b/src/freeze.cpp @@ -1,15 +1,17 @@ -// MUSIC - a 3+1D viscous relativistic hydrodynamic code for heavy ion collisions -// Copyright (C) 2017 Gabriel Denicol, Charles Gale, Sangyong Jeon, Matthew Luzum, Jean-François Paquet, Björn Schenke, Chun Shen +// MUSIC - a 3+1D viscous relativistic hydrodynamic code for heavy ion +// collisions Copyright (C) 2017 Gabriel Denicol, Charles Gale, Sangyong Jeon, +// Matthew Luzum, Jean-François Paquet, Björn Schenke, Chun Shen #include "./freeze.h" + #include using namespace std; -Freeze::Freeze(InitData* DATA_in) { +Freeze::Freeze(InitData *DATA_in) { if (etasize < DATA_in->pseudo_steps + 1) { - music_message << __func__ - << "etasize is smaller than pseudo_steps + 1! " + music_message + << __func__ << "etasize is smaller than pseudo_steps + 1! " << "Please increase the value of etasize >= pseudo_steps + 1 " << "in freeze.h"; music_message.flush("error"); @@ -22,11 +24,11 @@ Freeze::Freeze(InitData* DATA_in) { // for final particle spectra and flow analysis, define the list // of charged hadrons that have a long enough lifetime to reach // the detectors - int temp_list [] = {211, -211, 321, -321, 2212, -2212, 3222, -3222, - 3112, -3112, 3312, -3312}; - charged_hadron_list_length = sizeof(temp_list)/sizeof(int); - charged_hadron_list = new int [charged_hadron_list_length]; - for(int i = 0; i < charged_hadron_list_length; i++) + int temp_list[] = {211, -211, 321, -321, 2212, -2212, + 3222, -3222, 3112, -3112, 3312, -3312}; + charged_hadron_list_length = sizeof(temp_list) / sizeof(int); + charged_hadron_list = new int[charged_hadron_list_length]; + for (int i = 0; i < charged_hadron_list_length; i++) charged_hadron_list[i] = temp_list[i]; particleMax = DATA_ptr->NumberOfParticlesToInclude; @@ -38,10 +40,10 @@ Freeze::Freeze(InitData* DATA_in) { if (DATA_ptr->turn_on_diff == 1 && DATA_ptr->include_deltaf_qmu == 1) { if (DATA_ptr->deltaf_14moments == 1) { load_deltaf_qmu_coeff_table_14mom( - "tables/deltaf_coefficients_14moments.dat"); + "tables/deltaf_coefficients_14moments.dat"); } else if (DATA_ptr->include_deltaf_qmu == 1) { load_deltaf_qmu_coeff_table( - "tables/Coefficients_RTA_diffusion.dat"); + "tables/Coefficients_RTA_diffusion.dat"); } } @@ -50,21 +52,19 @@ Freeze::Freeze(InitData* DATA_in) { // define the gauss integration points along eta_s // the weights already take care of the factor of 2 // from -infty to +infty - double temp_gauss[] = { - 2.4014964e-02, 1.2545322e-01, 3.0358683e-01, - 5.5116454e-01, 8.5805566e-01, 1.2116973e+00, - 1.5976118e+00, 2.0000000e+00, 2.4023882e+00, - 2.7883027e+00, 3.1419444e+00, 3.4488355e+00, - 3.6964132e+00, 3.8745468e+00, 3.9759850e+00 - }; + double temp_gauss[] = {2.4014964e-02, 1.2545322e-01, 3.0358683e-01, + 5.5116454e-01, 8.5805566e-01, 1.2116973e+00, + 1.5976118e+00, 2.0000000e+00, 2.4023882e+00, + 2.7883027e+00, 3.1419444e+00, 3.4488355e+00, + 3.6964132e+00, 3.8745468e+00, 3.9759850e+00}; double temp_gauss_weight[] = { - 1.2301297e-01, 2.8146419e-01, 4.2863688e-01, - 5.5828271e-01, 6.6507682e-01, 7.4464400e-01, - 7.9372594e-01, 8.1031297e-01, 7.9372594e-01, - 7.4464400e-01, 6.6507682e-01, 5.5828271e-01, + 1.2301297e-01, 2.8146419e-01, 4.2863688e-01, 5.5828271e-01, + 6.6507682e-01, 7.4464400e-01, 7.9372594e-01, 8.1031297e-01, + 7.9372594e-01, 7.4464400e-01, 6.6507682e-01, 5.5828271e-01, 4.2863688e-01, 2.8146419e-01, 1.2301297e-01, }; - n_eta_s_integral = static_cast(sizeof(temp_gauss)/sizeof(double)); + n_eta_s_integral = + static_cast(sizeof(temp_gauss) / sizeof(double)); eta_s_inte_array = new double[n_eta_s_integral]; eta_s_inte_weight = new double[n_eta_s_integral]; cosh_eta_s_inte = new double[n_eta_s_integral]; @@ -95,7 +95,7 @@ Freeze::~Freeze() { surface.clear(); } -void Freeze::checkForReadError(FILE *file, const char* name) { +void Freeze::checkForReadError(FILE *file, const char *name) { if (!(file)) { music_message << "file " << name << " not found. Exiting..."; music_message.flush("error"); @@ -103,15 +103,15 @@ void Freeze::checkForReadError(FILE *file, const char* name) { } } -void Freeze::read_particle_PCE_mu(InitData* DATA, EOS *eos) { +void Freeze::read_particle_PCE_mu(InitData *DATA, EOS *eos) { double ef = DATA->epsilonFreeze; music_message << "Determining chemical potentials at freeze out " << "energy density " << ef << " GeV/fm^3."; music_message.flush("info"); // get environment path - const char* EOSPATH = "HYDROPROGRAMPATH"; - char * pre_envPath= getenv(EOSPATH); + const char *EOSPATH = "HYDROPROGRAMPATH"; + char *pre_envPath = getenv(EOSPATH); std::string envPath; if (pre_envPath == 0) { envPath = "."; @@ -129,7 +129,7 @@ void Freeze::read_particle_PCE_mu(InitData* DATA, EOS *eos) { } else if (DATA->whichEOS == 6) { mu_name = envPath + "/EOS/s95p-PCE165-v0/s95p-PCE165-v0_pichem1.dat"; } - music_message << "Reading chemical potentials from file " << mu_name; + music_message << "Reading chemical potentials from file " << mu_name; music_message.flush("info"); ifstream mu_file(mu_name.c_str()); @@ -138,19 +138,19 @@ void Freeze::read_particle_PCE_mu(InitData* DATA, EOS *eos) { music_message.flush("error"); exit(0); } - double EPP1; // start value for \mu_B and epsilon - double deltaEPP1; // step size for \mu_B and epsilon - int NEPP1; // number of entries for \mu_B and epsilon - int numStable = 0; // number of stable particles + double EPP1; // start value for \mu_B and epsilon + double deltaEPP1; // step size for \mu_B and epsilon + int NEPP1; // number of entries for \mu_B and epsilon + int numStable = 0; // number of stable particles double **chemPot; mu_file >> EPP1 >> deltaEPP1 >> NEPP1; mu_file >> numStable; - // chemical potential for every stable particle - chemPot = Util::mtx_malloc(numStable+1, NEPP1+1); + // chemical potential for every stable particle + chemPot = Util::mtx_malloc(numStable + 1, NEPP1 + 1); - for (int j = NEPP1-1; j >= 0; j--) { + for (int j = NEPP1 - 1; j >= 0; j--) { for (int i = 0; i < numStable; i++) { mu_file >> chemPot[i][j]; } @@ -162,11 +162,11 @@ void Freeze::read_particle_PCE_mu(InitData* DATA, EOS *eos) { if (ef < EPP1) { ie1 = 0; ie2 = 1; - frace = ef/(EPP1); + frace = ef / (EPP1); } else { - ie1 = floor((ef-EPP1)/deltaEPP1); - ie2 = floor((ef-EPP1)/deltaEPP1+1); - frace = (ef-(ie1*deltaEPP1+EPP1))/deltaEPP1; + ie1 = floor((ef - EPP1) / deltaEPP1); + ie2 = floor((ef - EPP1) / deltaEPP1 + 1); + frace = (ef - (ie1 * deltaEPP1 + EPP1)) / deltaEPP1; } if (ie1 > NEPP1) { @@ -184,18 +184,18 @@ void Freeze::read_particle_PCE_mu(InitData* DATA, EOS *eos) { } double pa, pb; - double mu[numStable+1]; + double mu[numStable + 1]; music_message << "num_of_stable_particles = " << numStable; music_message.flush("info"); - for(int i = 1; i <= numStable; i++) { - pa = chemPot[i-1][ie1]; - pb = chemPot[i-1][ie2]; + for (int i = 1; i <= numStable; i++) { + pa = chemPot[i - 1][ie1]; + pb = chemPot[i - 1][ie2]; if (ef < EPP1) { - mu[i] = pa*(frace); + mu[i] = pa * (frace); } else { - mu[i] = pa*(1-frace) + pb*frace; + mu[i] = pa * (1 - frace) + pb * frace; } } @@ -204,12 +204,12 @@ void Freeze::read_particle_PCE_mu(InitData* DATA, EOS *eos) { } if (DATA->NumberOfParticlesToInclude >= 8) { - for(int i = 1; i <= 8; i++) { + for (int i = 1; i <= 8; i++) { particleList[i].muAtFreezeOut = mu[i]; } } else { music_message << "Need at least 8 particles. " - << "Increase number of particles to include. Exiting."; + << "Increase number of particles to include. Exiting."; music_message.flush("error"); exit(1); } @@ -219,104 +219,104 @@ void Freeze::read_particle_PCE_mu(InitData* DATA, EOS *eos) { particleList[12].muAtFreezeOut = mu[9]; if (DATA->NumberOfParticlesToInclude >= 17) particleList[17].muAtFreezeOut = mu[10]; - if (DATA->NumberOfParticlesToInclude>=18) + if (DATA->NumberOfParticlesToInclude >= 18) particleList[18].muAtFreezeOut = mu[11]; - if (DATA->NumberOfParticlesToInclude>=19) + if (DATA->NumberOfParticlesToInclude >= 19) particleList[19].muAtFreezeOut = mu[12]; - if (DATA->NumberOfParticlesToInclude>=20) + if (DATA->NumberOfParticlesToInclude >= 20) particleList[20].muAtFreezeOut = mu[13]; - if (DATA->NumberOfParticlesToInclude>=21) + if (DATA->NumberOfParticlesToInclude >= 21) particleList[21].muAtFreezeOut = mu[14]; - if (DATA->NumberOfParticlesToInclude>=26) + if (DATA->NumberOfParticlesToInclude >= 26) particleList[26].muAtFreezeOut = mu[15]; - if (DATA->NumberOfParticlesToInclude>=27) + if (DATA->NumberOfParticlesToInclude >= 27) particleList[27].muAtFreezeOut = mu[16]; - if (DATA->NumberOfParticlesToInclude>=28) + if (DATA->NumberOfParticlesToInclude >= 28) particleList[28].muAtFreezeOut = mu[17]; - if (DATA->NumberOfParticlesToInclude>=30) + if (DATA->NumberOfParticlesToInclude >= 30) particleList[30].muAtFreezeOut = mu[18]; - if (DATA->NumberOfParticlesToInclude>=31) + if (DATA->NumberOfParticlesToInclude >= 31) particleList[31].muAtFreezeOut = mu[19]; - if (DATA->NumberOfParticlesToInclude>=32) + if (DATA->NumberOfParticlesToInclude >= 32) particleList[32].muAtFreezeOut = mu[20]; - if (DATA->NumberOfParticlesToInclude>=33) + if (DATA->NumberOfParticlesToInclude >= 33) particleList[33].muAtFreezeOut = mu[21]; - if (DATA->NumberOfParticlesToInclude>=34) + if (DATA->NumberOfParticlesToInclude >= 34) particleList[34].muAtFreezeOut = mu[22]; - if (DATA->NumberOfParticlesToInclude>=35) + if (DATA->NumberOfParticlesToInclude >= 35) particleList[35].muAtFreezeOut = mu[23]; - if (DATA->NumberOfParticlesToInclude>=60) + if (DATA->NumberOfParticlesToInclude >= 60) particleList[60].muAtFreezeOut = mu[24]; - if (DATA->NumberOfParticlesToInclude>=61) + if (DATA->NumberOfParticlesToInclude >= 61) particleList[61].muAtFreezeOut = mu[25]; - if (DATA->NumberOfParticlesToInclude>=62) + if (DATA->NumberOfParticlesToInclude >= 62) particleList[62].muAtFreezeOut = mu[26]; - if (DATA->NumberOfParticlesToInclude>=63) + if (DATA->NumberOfParticlesToInclude >= 63) particleList[63].muAtFreezeOut = mu[27]; - if (DATA->NumberOfParticlesToInclude>=110) + if (DATA->NumberOfParticlesToInclude >= 110) particleList[110].muAtFreezeOut = mu[28]; - if (DATA->NumberOfParticlesToInclude>=111) + if (DATA->NumberOfParticlesToInclude >= 111) particleList[111].muAtFreezeOut = mu[29]; - if (DATA->NumberOfParticlesToInclude>=117) + if (DATA->NumberOfParticlesToInclude >= 117) particleList[117].muAtFreezeOut = mu[30]; - if (DATA->NumberOfParticlesToInclude>=118) + if (DATA->NumberOfParticlesToInclude >= 118) particleList[118].muAtFreezeOut = mu[31]; - if (DATA->NumberOfParticlesToInclude>=119) + if (DATA->NumberOfParticlesToInclude >= 119) particleList[119].muAtFreezeOut = mu[32]; - if (DATA->NumberOfParticlesToInclude>=120) + if (DATA->NumberOfParticlesToInclude >= 120) particleList[120].muAtFreezeOut = mu[33]; - if (DATA->NumberOfParticlesToInclude>=170) + if (DATA->NumberOfParticlesToInclude >= 170) particleList[170].muAtFreezeOut = mu[34]; - if (DATA->NumberOfParticlesToInclude>=171) + if (DATA->NumberOfParticlesToInclude >= 171) particleList[171].muAtFreezeOut = mu[35]; - } else { - if (DATA->NumberOfParticlesToInclude>=17) + } else { + if (DATA->NumberOfParticlesToInclude >= 17) particleList[17].muAtFreezeOut = mu[9]; - if (DATA->NumberOfParticlesToInclude>=18) + if (DATA->NumberOfParticlesToInclude >= 18) particleList[18].muAtFreezeOut = mu[10]; - if (DATA->NumberOfParticlesToInclude>=19) + if (DATA->NumberOfParticlesToInclude >= 19) particleList[19].muAtFreezeOut = mu[11]; - if (DATA->NumberOfParticlesToInclude>=20) + if (DATA->NumberOfParticlesToInclude >= 20) particleList[20].muAtFreezeOut = mu[12]; - if (DATA->NumberOfParticlesToInclude>=21) + if (DATA->NumberOfParticlesToInclude >= 21) particleList[21].muAtFreezeOut = mu[13]; - if (DATA->NumberOfParticlesToInclude>=26) + if (DATA->NumberOfParticlesToInclude >= 26) particleList[26].muAtFreezeOut = mu[14]; - if (DATA->NumberOfParticlesToInclude>=27) + if (DATA->NumberOfParticlesToInclude >= 27) particleList[27].muAtFreezeOut = mu[15]; - if (DATA->NumberOfParticlesToInclude>=28) + if (DATA->NumberOfParticlesToInclude >= 28) particleList[28].muAtFreezeOut = mu[16]; - if (DATA->NumberOfParticlesToInclude>=30) + if (DATA->NumberOfParticlesToInclude >= 30) particleList[30].muAtFreezeOut = mu[17]; - if (DATA->NumberOfParticlesToInclude>=31) + if (DATA->NumberOfParticlesToInclude >= 31) particleList[31].muAtFreezeOut = mu[18]; - if (DATA->NumberOfParticlesToInclude>=32) + if (DATA->NumberOfParticlesToInclude >= 32) particleList[32].muAtFreezeOut = mu[19]; - if (DATA->NumberOfParticlesToInclude>=33) + if (DATA->NumberOfParticlesToInclude >= 33) particleList[33].muAtFreezeOut = mu[20]; - if (DATA->NumberOfParticlesToInclude>=34) + if (DATA->NumberOfParticlesToInclude >= 34) particleList[34].muAtFreezeOut = mu[21]; - if (DATA->NumberOfParticlesToInclude>=35) + if (DATA->NumberOfParticlesToInclude >= 35) particleList[35].muAtFreezeOut = mu[22]; - if (DATA->NumberOfParticlesToInclude>=60) + if (DATA->NumberOfParticlesToInclude >= 60) particleList[60].muAtFreezeOut = mu[23]; - if (DATA->NumberOfParticlesToInclude>=61) + if (DATA->NumberOfParticlesToInclude >= 61) particleList[61].muAtFreezeOut = mu[24]; - if (DATA->NumberOfParticlesToInclude>=62) + if (DATA->NumberOfParticlesToInclude >= 62) particleList[62].muAtFreezeOut = mu[25]; - if (DATA->NumberOfParticlesToInclude>=63) + if (DATA->NumberOfParticlesToInclude >= 63) particleList[63].muAtFreezeOut = mu[26]; - if (DATA->NumberOfParticlesToInclude>=170) + if (DATA->NumberOfParticlesToInclude >= 170) particleList[170].muAtFreezeOut = mu[27]; - if (DATA->NumberOfParticlesToInclude>=171) + if (DATA->NumberOfParticlesToInclude >= 171) particleList[171].muAtFreezeOut = mu[28]; } music_message << "Got the chemical potentials at freeze out for " @@ -324,7 +324,7 @@ void Freeze::read_particle_PCE_mu(InitData* DATA, EOS *eos) { music_message.flush("info"); int k = 0; - for(int i = 1; i < DATA->NumberOfParticlesToInclude; i++) { + for (int i = 1; i < DATA->NumberOfParticlesToInclude; i++) { // skip the photon (i=0) if (particleList[i].muAtFreezeOut == 0) { if (particleList[i].baryon == -1) { @@ -332,47 +332,49 @@ void Freeze::read_particle_PCE_mu(InitData* DATA, EOS *eos) { } for (int j = 1; j <= particleList[i].decays; j++) { k++; - for (int m=0; m -1) - k++; + if (particleList[i].baryon > -1) k++; } } } - music_message << "Got the chemical potentials at freeze-out for the resonances."; + music_message + << "Got the chemical potentials at freeze-out for the resonances."; music_message.flush("info"); // clean up - Util::mtx_free(chemPot, numStable+1, NEPP1+1); + Util::mtx_free(chemPot, numStable + 1, NEPP1 + 1); } - void Freeze::ReadParticleData(InitData *DATA, EOS *eos) { // read in particle and decay information from file: - partid = new int[MAXINTV]; + partid = new int[MAXINTV]; music_message.info("reading particle data"); // open particle data file: - const char* EOSPATH = "HYDROPROGRAMPATH"; - char * pre_envPath= getenv(EOSPATH); + const char *EOSPATH = "HYDROPROGRAMPATH"; + char *pre_envPath = getenv(EOSPATH); std::string envPath; if (pre_envPath == 0) { - envPath="."; + envPath = "."; } else { - envPath=pre_envPath; + envPath = pre_envPath; } string p_name = envPath + "/EOS/pdg05.dat"; if (DATA->whichEOS == 7 || DATA->whichEOS == 10) { @@ -386,16 +388,15 @@ void Freeze::ReadParticleData(InitData *DATA, EOS *eos) { p_file = fopen(p_name.c_str(), "r"); checkForReadError(p_file, p_name.c_str()); - for (int k = 0; k < MAXINTV; k++) - partid[k] = -1; + for (int k = 0; k < MAXINTV; k++) partid[k] = -1; if (DATA->echo_level > 5) { - music_message << "size_of_Particle= " << sizeof(Particle)/1024/1024 + music_message << "size_of_Particle= " << sizeof(Particle) / 1024 / 1024 << " MB"; music_message.flush("info"); } particleList = (Particle *)malloc( - (DATA->NumberOfParticlesToInclude + 2)*sizeof(Particle)); + (DATA->NumberOfParticlesToInclude + 2) * sizeof(Particle)); if (DATA->echo_level > 5) { music_message << "after first (check if there is enough memory... " << "seg fault may be due to lack of memory)"; @@ -405,60 +406,61 @@ void Freeze::ReadParticleData(InitData *DATA, EOS *eos) { int j = 0; // read particle data: while (i < DATA->NumberOfParticlesToInclude) { - //particleList[i].name = Util::char_malloc(50); - system_status_ = fscanf(p_file, "%d", &particleList[i].number ); - system_status_ = fscanf(p_file, "%s", particleList[i].name ); - system_status_ = fscanf(p_file, "%lf", &particleList[i].mass ); - system_status_ = fscanf(p_file, "%lf", &particleList[i].width ); - system_status_ = fscanf(p_file, "%d", &particleList[i].degeneracy); - system_status_ = fscanf(p_file, "%d", &particleList[i].baryon ); - system_status_ = fscanf(p_file, "%d", &particleList[i].strange); - system_status_ = fscanf(p_file, "%d", &particleList[i].charm ); - system_status_ = fscanf(p_file, "%d", &particleList[i].bottom ); - system_status_ = fscanf(p_file, "%d", &particleList[i].isospin); - system_status_ = fscanf(p_file, "%lf", &particleList[i].charge ); - system_status_ = fscanf(p_file, "%d", &particleList[i].decays ); // number of decays + // particleList[i].name = Util::char_malloc(50); + system_status_ = fscanf(p_file, "%d", &particleList[i].number); + system_status_ = fscanf(p_file, "%s", particleList[i].name); + system_status_ = fscanf(p_file, "%lf", &particleList[i].mass); + system_status_ = fscanf(p_file, "%lf", &particleList[i].width); + system_status_ = fscanf(p_file, "%d", &particleList[i].degeneracy); + system_status_ = fscanf(p_file, "%d", &particleList[i].baryon); + system_status_ = fscanf(p_file, "%d", &particleList[i].strange); + system_status_ = fscanf(p_file, "%d", &particleList[i].charm); + system_status_ = fscanf(p_file, "%d", &particleList[i].bottom); + system_status_ = fscanf(p_file, "%d", &particleList[i].isospin); + system_status_ = fscanf(p_file, "%lf", &particleList[i].charge); + system_status_ = + fscanf(p_file, "%d", &particleList[i].decays); // number of decays partid[MHALF + particleList[i].number] = i; particleList[i].stable = 0; int h; - for(int k = 0; k < particleList[i].decays; k++) { - h = fscanf(p_file, "%i%i%lf%i%i%i%i%i", - &decay[j].reso, &decay[j].numpart, &decay[j].branch, - &decay[j].part[0], &decay[j].part[1], &decay[j].part[2], - &decay[j].part[3], &decay[j].part[4]); + for (int k = 0; k < particleList[i].decays; k++) { + h = fscanf( + p_file, "%i%i%lf%i%i%i%i%i", &decay[j].reso, &decay[j].numpart, + &decay[j].branch, &decay[j].part[0], &decay[j].part[1], + &decay[j].part[2], &decay[j].part[3], &decay[j].part[4]); if (h != 8) { printf("Error in scanf decay \n"); exit(0); } if (decay[j].numpart == 1) { - // "decays" into one particle, i.e. is stable + // "decays" into one particle, i.e. is stable particleList[i].stable = 1; } - j++; // increase the decay counting variable "j" by 1 + j++; // increase the decay counting variable "j" by 1 } // include anti-baryons (there are none in the file) if (particleList[i].baryon != 0) { i++; - //particleList[i].name = Util::char_malloc(50); - particleList[i].width = particleList[i-1].width; - particleList[i].charm = -particleList[i-1].charm; - particleList[i].bottom = -particleList[i-1].bottom; - particleList[i].isospin = particleList[i-1].isospin; - particleList[i].charge = -particleList[i-1].charge; - particleList[i].decays = particleList[i-1].decays; - particleList[i].stable = particleList[i-1].stable; - particleList[i].number = -particleList[i-1].number; - std::string antiName = ("Anti-" - + std::string(particleList[i-1].name)); + // particleList[i].name = Util::char_malloc(50); + particleList[i].width = particleList[i - 1].width; + particleList[i].charm = -particleList[i - 1].charm; + particleList[i].bottom = -particleList[i - 1].bottom; + particleList[i].isospin = particleList[i - 1].isospin; + particleList[i].charge = -particleList[i - 1].charge; + particleList[i].decays = particleList[i - 1].decays; + particleList[i].stable = particleList[i - 1].stable; + particleList[i].number = -particleList[i - 1].number; + std::string antiName = + ("Anti-" + std::string(particleList[i - 1].name)); strcpy(particleList[i].name, antiName.c_str()); - particleList[i].mass = particleList[i-1].mass; - particleList[i].degeneracy = particleList[i-1].degeneracy; - particleList[i].baryon = -particleList[i-1].baryon; - particleList[i].strange = -particleList[i-1].strange; - particleList[i].charge = -particleList[i-1].charge; + particleList[i].mass = particleList[i - 1].mass; + particleList[i].degeneracy = particleList[i - 1].degeneracy; + particleList[i].baryon = -particleList[i - 1].baryon; + particleList[i].strange = -particleList[i - 1].strange; + particleList[i].charge = -particleList[i - 1].charge; partid[MHALF + particleList[i].number] = i; } i++; @@ -477,7 +479,6 @@ void Freeze::ReadParticleData(InitData *DATA, EOS *eos) { music_message.info("Done reading particle data."); } - void Freeze::ReadFreezeOutSurface(InitData *DATA) { music_message.info("reading freeze-out surface"); @@ -490,11 +491,10 @@ void Freeze::ReadFreezeOutSurface(InitData *DATA) { // new counting, mac compatible ... if (surface_in_binary) { - NCells = get_number_of_lines_of_binary_surface_file( - surfdat_stream.str()); + NCells = + get_number_of_lines_of_binary_surface_file(surfdat_stream.str()); } else { - NCells = get_number_of_lines_of_text_surface_file( - surfdat_stream.str()); + NCells = get_number_of_lines_of_text_surface_file(surfdat_stream.str()); } music_message << "NCells = " << NCells; music_message.flush("info"); @@ -506,7 +506,7 @@ void Freeze::ReadFreezeOutSurface(InitData *DATA) { surfdat.open(surfdat_stream.str().c_str()); } // Now allocate memory: array of surfaceElements with length NCells - //surface = (SurfaceElement *) malloc((NCells)*sizeof(SurfaceElement)); + // surface = (SurfaceElement *) malloc((NCells)*sizeof(SurfaceElement)); int i = 0; while (i < NCells) { SurfaceElement temp_cell; @@ -514,7 +514,7 @@ void Freeze::ReadFreezeOutSurface(InitData *DATA) { float array[34]; for (int ii = 0; ii < 34; ii++) { float temp = 0.; - surfdat.read((char*)&temp, sizeof(float)); + surfdat.read((char *)&temp, sizeof(float)); array[ii] = temp; } temp_cell.x[0] = array[0]; @@ -535,11 +535,11 @@ void Freeze::ReadFreezeOutSurface(InitData *DATA) { temp_cell.u[2] = array[10]; temp_cell.u[3] = array[11]; - temp_cell.epsilon_f = array[12]; - temp_cell.T_f = array[13]; - temp_cell.mu_B = array[14]; - temp_cell.mu_S = array[15]; - temp_cell.mu_C = array[16]; + temp_cell.epsilon_f = array[12]; + temp_cell.T_f = array[13]; + temp_cell.mu_B = array[14]; + temp_cell.mu_S = array[15]; + temp_cell.mu_C = array[16]; temp_cell.eps_plus_p_over_T_FO = array[17]; temp_cell.W[0][0] = array[18]; @@ -553,7 +553,7 @@ void Freeze::ReadFreezeOutSurface(InitData *DATA) { temp_cell.W[2][3] = array[26]; temp_cell.W[3][3] = array[27]; - temp_cell.pi_b = array[28]; + temp_cell.pi_b = array[28]; temp_cell.rho_B = array[29]; temp_cell.q[0] = array[30]; @@ -562,27 +562,26 @@ void Freeze::ReadFreezeOutSurface(InitData *DATA) { temp_cell.q[3] = array[33]; } else { // position in (tau, x, y, eta) - surfdat >> temp_cell.x[0] >> temp_cell.x[1] - >> temp_cell.x[2] >> temp_cell.x[3]; + surfdat >> temp_cell.x[0] >> temp_cell.x[1] >> temp_cell.x[2] + >> temp_cell.x[3]; // hypersurface vector in (tau, x, y, eta) - surfdat >> temp_cell.s[0] >> temp_cell.s[1] - >> temp_cell.s[2] >> temp_cell.s[3]; + surfdat >> temp_cell.s[0] >> temp_cell.s[1] >> temp_cell.s[2] + >> temp_cell.s[3]; // flow velocity in (tau, x, y, eta) - surfdat >> temp_cell.u[0] >> temp_cell.u[1] - >> temp_cell.u[2] >> temp_cell.u[3]; + surfdat >> temp_cell.u[0] >> temp_cell.u[1] >> temp_cell.u[2] + >> temp_cell.u[3]; - surfdat >> temp_cell.epsilon_f >> temp_cell.T_f - >> temp_cell.mu_B >> temp_cell.mu_S >> temp_cell.mu_C - >> temp_cell.eps_plus_p_over_T_FO; + surfdat >> temp_cell.epsilon_f >> temp_cell.T_f >> temp_cell.mu_B + >> temp_cell.mu_S >> temp_cell.mu_C + >> temp_cell.eps_plus_p_over_T_FO; // freeze-out Wmunu surfdat >> temp_cell.W[0][0] >> temp_cell.W[0][1] - >> temp_cell.W[0][2] >> temp_cell.W[0][3] - >> temp_cell.W[1][1] >> temp_cell.W[1][2] - >> temp_cell.W[1][3] >> temp_cell.W[2][2] - >> temp_cell.W[2][3] >> temp_cell.W[3][3]; + >> temp_cell.W[0][2] >> temp_cell.W[0][3] >> temp_cell.W[1][1] + >> temp_cell.W[1][2] >> temp_cell.W[1][3] >> temp_cell.W[2][2] + >> temp_cell.W[2][3] >> temp_cell.W[3][3]; if (DATA->turn_on_bulk) { surfdat >> temp_cell.pi_b; } else { @@ -594,8 +593,8 @@ void Freeze::ReadFreezeOutSurface(InitData *DATA) { temp_cell.rho_B = 0.; } if (DATA->turn_on_diff) { - surfdat >> temp_cell.q[0] >> temp_cell.q[1] - >> temp_cell.q[2] >> temp_cell.q[3]; + surfdat >> temp_cell.q[0] >> temp_cell.q[1] >> temp_cell.q[2] + >> temp_cell.q[3]; } else { temp_cell.q[0] = 0.; temp_cell.q[1] = 0.; @@ -606,7 +605,7 @@ void Freeze::ReadFreezeOutSurface(InitData *DATA) { temp_cell.sinh_eta_s = sinh(temp_cell.x[3]); temp_cell.cosh_eta_s = cosh(temp_cell.x[3]); - if (temp_cell.epsilon_f < 0) { + if (temp_cell.epsilon_f < 0) { music_message.error("epsilon_f < 0.!"); exit(1); } @@ -620,21 +619,19 @@ void Freeze::ReadFreezeOutSurface(InitData *DATA) { surfdat.close(); } - int Freeze::get_number_of_lines_of_binary_surface_file(string filename) { std::ifstream surface_file(filename.c_str(), std::ios::binary); int count = 0; float temp = 0.; - while(surface_file) { - surface_file.read((char*) &temp, sizeof(float)); + while (surface_file) { + surface_file.read((char *)&temp, sizeof(float)); count++; } - int counted_line = count/34; + int counted_line = count / 34; surface_file.close(); - return(counted_line); + return (counted_line); } - int Freeze::get_number_of_lines_of_text_surface_file(string filename) { std::ifstream surface_file(filename.c_str(), std::ios::binary); int counted_lines = 0; @@ -643,5 +640,5 @@ int Freeze::get_number_of_lines_of_text_surface_file(string filename) { ++counted_lines; } surface_file.close(); - return(counted_lines); + return (counted_lines); } diff --git a/src/freeze.h b/src/freeze.h index 54365b37..51ef02a8 100644 --- a/src/freeze.h +++ b/src/freeze.h @@ -1,5 +1,6 @@ -// MUSIC - a 3+1D viscous relativistic hydrodynamic code for heavy ion collisions -// Copyright (C) 2017 Gabriel Denicol, Charles Gale, Sangyong Jeon, Matthew Luzum, Jean-François Paquet, Björn Schenke, Chun Shen +// MUSIC - a 3+1D viscous relativistic hydrodynamic code for heavy ion +// collisions Copyright (C) 2017 Gabriel Denicol, Charles Gale, Sangyong Jeon, +// Matthew Luzum, Jean-François Paquet, Björn Schenke, Chun Shen // Copyright @ Bjoern Schenke, Sangyong Jeon, and Charles Gale @@ -7,41 +8,42 @@ #define SRC_FREEZE_H_ #define NUMDECAY 2000 -#define MAXINTV 2000000 // size of arry for Montecarlo numbers - // note that I modified pdg05.dat - // by replacing 90...... 9...... -#define MHALF (MAXINTV/2) -#define NY 200 // size of arry for storage of the y-spectrum -#define NPT 100 // size of arry for storage of the pt-spectrum -#define NPHI 100 // size of arry for storage of the phi-spectrum -#define NPHI1 NPHI + 1 -#define PTS3 20 // normalization of 3-body decay -#define PTS4 20 // inv. mass integral 3-body +#define MAXINTV \ + 2000000 // size of arry for Montecarlo numbers + // note that I modified pdg05.dat + // by replacing 90...... 9...... +#define MHALF (MAXINTV / 2) +#define NY 200 // size of arry for storage of the y-spectrum +#define NPT 100 // size of arry for storage of the pt-spectrum +#define NPHI 100 // size of arry for storage of the phi-spectrum +#define NPHI1 NPHI + 1 +#define PTS3 20 // normalization of 3-body decay +#define PTS4 20 // inv. mass integral 3-body #define PTN1 20 -#define PTN2 20 // 2-body between the poles +#define PTN2 20 // 2-body between the poles #define PTCHANGE 1. -#include -#include -#include +#include + #include #include -#include +#include +#include #include #include #include #include "data.h" -#include "util.h" #include "eos.h" #include "pretty_ostream.h" +#include "util.h" -const int nharmonics = 8; // calculate up to maximum harmonic (n-1) - // -- for nharmonics = 8, calculate from v_0 o v_7 -const int etasize = 200; // max number of points in eta for array -const int ptsize = 100; // max number of points in pt for array +const int nharmonics = 8; // calculate up to maximum harmonic (n-1) + // -- for nharmonics = 8, calculate from v_0 o v_7 +const int etasize = 200; // max number of points in eta for array +const int ptsize = 100; // max number of points in pt for array typedef struct particle { int number; @@ -64,49 +66,45 @@ typedef struct particle { double phimax; double ymax; double deltaY; - double dNdydptdphi[NY][NPT][NPHI+1]; - double pt[NPT]; // pt values for spectrum - double y[NY]; // y values for spectrum - double slope; // assymtotic slope of pt-spectrum - double muAtFreezeOut; // the chemical potential at freeze-out - // for the partial chemical equilibrium EoS + double dNdydptdphi[NY][NPT][NPHI + 1]; + double pt[NPT]; // pt values for spectrum + double y[NY]; // y values for spectrum + double slope; // assymtotic slope of pt-spectrum + double muAtFreezeOut; // the chemical potential at freeze-out + // for the partial chemical equilibrium EoS } Particle; - typedef struct de { - int reso; // Montecarlo number of decaying resonance - int numpart; // number of daughter particles after decay - double branch; // branching ratio - int part[5]; // array of daughter particles Montecarlo number + int reso; // Montecarlo number of decaying resonance + int numpart; // number of daughter particles after decay + double branch; // branching ratio + int part[5]; // array of daughter particles Montecarlo number } de; - typedef struct pblockN { - double pt, mt, y, e, pl; // pt, mt, y of decay product 1 + double pt, mt, y, e, pl; // pt, mt, y of decay product 1 double phi; - double m1, m2, m3; // masses of decay products - double mr; // mass of resonance + double m1, m2, m3; // masses of decay products + double mr; // mass of resonance double costh, sinth; double e0, p0; - int res_num; // Montecarlo number of the Res. + int res_num; // Montecarlo number of the Res. } pblockN; - typedef struct nblock { double a, b, c, d; -} nblock; // for normalisation integral of 3-body decays - +} nblock; // for normalisation integral of 3-body decays typedef struct surfaceElement { - double x[4]; // position in (tau, x, y, eta) - double sinh_eta_s; // caching the sinh and cosh of eta_s + double x[4]; // position in (tau, x, y, eta) + double sinh_eta_s; // caching the sinh and cosh of eta_s double cosh_eta_s; - double s[4]; // hypersurface vector in (tau, x, y, eta) - double u[4]; // flow velocity in (tau, x, y, eta) - double W[4][4]; // W^{\mu\nu} - double q[4]; // baryon diffusion current - double pi_b; // bulk pressure - double rho_B; // net baryon density + double s[4]; // hypersurface vector in (tau, x, y, eta) + double u[4]; // flow velocity in (tau, x, y, eta) + double W[4][4]; // W^{\mu\nu} + double q[4]; // baryon diffusion current + double pi_b; // bulk pressure + double rho_B; // net baryon density double epsilon_f; double T_f; @@ -117,8 +115,8 @@ typedef struct surfaceElement { } SurfaceElement; //! This class perform Cooper-Fyre freeze-out and resonance decays -class Freeze{ - private: +class Freeze { + private: bool surface_in_binary; bool boost_invariant; int n_eta_s_integral; @@ -138,15 +136,15 @@ class Freeze{ double ***sumYPtPhi; int *partid; // array for converting Montecarlo numbers into - // internal numbering of the resonances + // internal numbering of the resonances double *phiArray; int pseudofreeze; - InitData* DATA_ptr; + InitData *DATA_ptr; int *charged_hadron_list; int charged_hadron_list_length; - // net baryon diffusion delta f + // net baryon diffusion delta f int deltaf_qmu_coeff_table_length_T; int deltaf_qmu_coeff_table_length_mu; double delta_qmu_coeff_table_T0, delta_qmu_coeff_table_mu0; @@ -164,33 +162,34 @@ class Freeze{ int bulk_deltaf_kind; - public: - Freeze(InitData* DATA_in); + public: + Freeze(InitData *DATA_in); ~Freeze(); - double gauss(int n, double (Freeze::*f)(double, void *), double xlo, - double xhi, void *optvec); - void read_particle_PCE_mu(InitData* DATA, EOS* eos); + double gauss( + int n, double (Freeze::*f)(double, void *), double xlo, double xhi, + void *optvec); + void read_particle_PCE_mu(InitData *DATA, EOS *eos); int get_number_of_lines_of_binary_surface_file(std::string filename); int get_number_of_lines_of_text_surface_file(std::string filename); void ReadParticleData(InitData *DATA, EOS *eos); void ReadFreezeOutSurface(InitData *DATA); - void ReadSpectra_pseudo(InitData* DATA, int full, int verbose); - void compute_thermal_spectra(int particleSpectrumNumber, InitData* DATA); + void ReadSpectra_pseudo(InitData *DATA, int full, int verbose); + void compute_thermal_spectra(int particleSpectrumNumber, InitData *DATA); void perform_resonance_decays(InitData *DATA); - void compute_thermal_particle_spectra_and_vn(InitData* DATA); - void compute_final_particle_spectra_and_vn(InitData* DATA); + void compute_thermal_particle_spectra_and_vn(InitData *DATA); + void compute_final_particle_spectra_and_vn(InitData *DATA); void ComputeParticleSpectrum_pseudo_improved(InitData *DATA, int number); - void ComputeParticleSpectrum_pseudo_boost_invariant(InitData *DATA, - int number); + void ComputeParticleSpectrum_pseudo_boost_invariant( + InitData *DATA, int number); void load_deltaf_qmu_coeff_table(std::string filename); void load_deltaf_qmu_coeff_table_14mom(std::string filename); double get_deltaf_qmu_coeff(double T, double muB); double get_deltaf_coeff_14moments(double T, double muB, double type); - void getbulkvisCoefficients(double Tdec, double* bulkvisCoefficients); - + void getbulkvisCoefficients(double Tdec, double *bulkvisCoefficients); + // ----------------------------------------------------------------------- // the following routines are adapted from the public version of /* ... the resonance decay calculation using the output */ @@ -203,76 +202,82 @@ class Freeze{ /* J. Sollfrank, P. Koch, and U. Heinz, Phys. Lett B 252 (1990) and */ /* J. Sollfrank, P. Koch, and U. Heinz, Z. Phys. C 52 (1991) */ /* for a description of the formalism utilized in this program. */ - + // this computes "Q(m_R,m_1,m_2,m_3)" - double norm3int (double x, void *paranorm); + double norm3int(double x, void *paranorm); double Edndp3(double yr, double ptr, double phirin, int res_num); - double dnpir2N(double phi, void *para1); - double dnpir1N(double costh, void* para1); - double dn2ptN(double w2, void* para1); - double dn3ptN(double x, void* para1); - double Edndp3_2bodyN(double y, double pt, double phi, double m1, double m2, - double mr, int res_num); - double Edndp3_3bodyN(double y, double pt, double phi, double m1, double m2, - double m3, double mr, double norm3, int res_num); + double dnpir2N(double phi, void *para1); + double dnpir1N(double costh, void *para1); + double dn2ptN(double w2, void *para1); + double dn3ptN(double x, void *para1); + double Edndp3_2bodyN( + double y, double pt, double phi, double m1, double m2, double mr, + int res_num); + double Edndp3_3bodyN( + double y, double pt, double phi, double m1, double m2, double m3, + double mr, double norm3, int res_num); void add_reso(int pn, int pnR, int k, int j); void cal_reso_decays(int maxpart, int maxdecay, int bound); // ----------------------------------------------------------------------- - - void checkForReadError(FILE *file, const char* name); + + void checkForReadError(FILE *file, const char *name); void OutputFullParticleSpectrum_pseudo( - InitData *DATA, int number, int anti, int full); - void CooperFrye_pseudo(int particleSpectrumNumber, int mode, - InitData *DATA, EOS *eos); + InitData *DATA, int number, int anti, int full); + void CooperFrye_pseudo( + int particleSpectrumNumber, int mode, InitData *DATA, EOS *eos); double Rap(double eta, double pt, double m); double PseudoRap(double y, double pt, double m); double dydeta(double eta, double pt, double m); - void rapidity_integrated_flow(InitData *DATA, int number, int yflag, - double minrap, double maxrap, - double vn[nharmonics][2][etasize]); - void pt_and_rapidity_integrated_flow(InitData *DATA, int number, - double minpt, double maxpt, int yflag, - double minrap, double maxrap, - double vn[8][2]); - double get_N(InitData *DATA, int number, double minpt, double maxpt, - int yflag, double minrap, double maxrap); - double get_Nch(InitData *DATA, double minpt, double maxpt, int yflag, - double minrap, double maxrap); - double get_meanpt(InitData *DATA, int number, double minpt, double maxpt, - int yflag, double minrap, double maxrap); - double get_vn_ch(InitData *DATA, double minpt, double maxpt, int yflag, - double minrap, double maxrap, int n, double* vn_results); - double get_psi_n_ch(InitData *DATA, double minpt, double maxpt, - int yflag, double minrap, double maxrap, int n); - double get_vn(InitData *DATA, int number, double minpt, double maxpt, - int yflag, double minrap, double maxrap, int n); - double get_psi_n(InitData *DATA, int number, - double minpt, double maxpt, - int yflag, double minrap, double maxrap, int n); - void weighted_v1(InitData *DATA, int number, double minpt, double maxpt, - int yflag, double minrap, double maxrap, - double vn[2], int ch); - double get_weighted_v1(InitData *DATA, int number, - double minpt, double maxpt, - int yflag, double minrap, double maxrap, int ch); - double get_weighted_psi1(InitData *DATA, int number, - double minpt, double maxpt, - int yflag, double minrap, double maxrap, int ch); + void rapidity_integrated_flow( + InitData *DATA, int number, int yflag, double minrap, double maxrap, + double vn[nharmonics][2][etasize]); + void pt_and_rapidity_integrated_flow( + InitData *DATA, int number, double minpt, double maxpt, int yflag, + double minrap, double maxrap, double vn[8][2]); + double get_N( + InitData *DATA, int number, double minpt, double maxpt, int yflag, + double minrap, double maxrap); + double get_Nch( + InitData *DATA, double minpt, double maxpt, int yflag, double minrap, + double maxrap); + double get_meanpt( + InitData *DATA, int number, double minpt, double maxpt, int yflag, + double minrap, double maxrap); + double get_vn_ch( + InitData *DATA, double minpt, double maxpt, int yflag, double minrap, + double maxrap, int n, double *vn_results); + double get_psi_n_ch( + InitData *DATA, double minpt, double maxpt, int yflag, double minrap, + double maxrap, int n); + double get_vn( + InitData *DATA, int number, double minpt, double maxpt, int yflag, + double minrap, double maxrap, int n); + double get_psi_n( + InitData *DATA, int number, double minpt, double maxpt, int yflag, + double minrap, double maxrap, int n); + void weighted_v1( + InitData *DATA, int number, double minpt, double maxpt, int yflag, + double minrap, double maxrap, double vn[2], int ch); + double get_weighted_v1( + InitData *DATA, int number, double minpt, double maxpt, int yflag, + double minrap, double maxrap, int ch); + double get_weighted_psi1( + InitData *DATA, int number, double minpt, double maxpt, int yflag, + double minrap, double maxrap, int ch); void OutputDifferentialFlowAtMidrapidity( - InitData *DATA, int number, int full); + InitData *DATA, int number, int full); void OutputDifferentialFlowNearMidrapidity( - InitData *DATA, int number, int full); - void OutputIntegratedFlow_vs_y(InitData *DATA, int number, int full, - double pT_min, double pT_max); - void Output_charged_IntegratedFlow(InitData *DATA, - double pT_min, double pT_max, - double eta_min, double eta_max); + InitData *DATA, int number, int full); + void OutputIntegratedFlow_vs_y( + InitData *DATA, int number, int full, double pT_min, double pT_max); + void Output_charged_IntegratedFlow( + InitData *DATA, double pT_min, double pT_max, double eta_min, + double eta_max); void Output_charged_hadrons_eta_differential_spectra( - InitData *DATA, int full, double pT_min ,double pT_max); + InitData *DATA, int full, double pT_min, double pT_max); void Output_charged_hadrons_pT_differential_spectra( - InitData *DATA, int full, double eta_min, double eta_max); + InitData *DATA, int full, double eta_min, double eta_max); }; #endif // SRC_FREEZE_H_ - diff --git a/src/freeze_pseudo.cpp b/src/freeze_pseudo.cpp index 31a433fc..263e0d9f 100644 --- a/src/freeze_pseudo.cpp +++ b/src/freeze_pseudo.cpp @@ -1,26 +1,28 @@ -// MUSIC - a 3+1D viscous relativistic hydrodynamic code for heavy ion collisions -// Copyright (C) 2017 Gabriel Denicol, Charles Gale, Sangyong Jeon, Matthew Luzum, Jean-François Paquet, Björn Schenke, Chun Shen +// MUSIC - a 3+1D viscous relativistic hydrodynamic code for heavy ion +// collisions Copyright (C) 2017 Gabriel Denicol, Charles Gale, Sangyong Jeon, +// Matthew Luzum, Jean-François Paquet, Björn Schenke, Chun Shen // Copyright @ Bjoern Schenke, Sangyong Jeon, and Charles Gale #include -#include #include +#include +#include + +#include +#include -#include -#include -#include #include "freeze.h" -using Util::hbarc; +using std::endl; +using std::ofstream; using std::string; using std::stringstream; -using std::ofstream; -using std::endl; +using Util::hbarc; // read in thermal spectra from file to then perform resonance decays with them // Must set verbose to 1 if you want particleMax to be set by this routine. -void Freeze::ReadSpectra_pseudo(InitData* DATA, int full, int verbose) { +void Freeze::ReadSpectra_pseudo(InitData *DATA, int full, int verbose) { // read in thermal spectra from file: int number, iptmax, iphimax; double deltaeta, etamax, ptmin, ptmax; @@ -32,8 +34,8 @@ void Freeze::ReadSpectra_pseudo(InitData* DATA, int full, int verbose) { } // open particle information file: FILE *p_file; - const char* p_name = "particleInformation.dat"; - const char* pf_name = "FparticleInformation.dat"; + const char *p_name = "particleInformation.dat"; + const char *pf_name = "FparticleInformation.dat"; if (full) p_file = fopen(pf_name, "r"); else @@ -46,34 +48,36 @@ void Freeze::ReadSpectra_pseudo(InitData* DATA, int full, int verbose) { music_message.flush("info"); } // read particle information: - while (fscanf(p_file,"%d %lf %d %lf %lf %d %d ", - &number, &etamax, &ietamax, &ptmin, &ptmax, - &iptmax, &iphimax) == 7) { + while (fscanf( + p_file, "%d %lf %d %lf %lf %d %d ", &number, &etamax, &ietamax, + &ptmin, &ptmax, &iptmax, &iphimax) + == 7) { count++; if (count >= DATA->NumberOfParticlesToInclude) { break; } pseudo_steps = ietamax - 1; - ip = partid[MHALF+number]; + ip = partid[MHALF + number]; particleList[ip].ny = ietamax; particleList[ip].npt = iptmax; particleList[ip].nphi = iphimax; particleList[ip].phimin = 0; - particleList[ip].phimax = 2*M_PI; + particleList[ip].phimax = 2 * M_PI; particleList[ip].slope = 1; particleList[ip].ymax = etamax; deltaeta = 0.; if (pseudo_steps > 0) { - deltaeta = 2*etamax/pseudo_steps; + deltaeta = 2 * etamax / pseudo_steps; } particleList[ip].deltaY = deltaeta; for (int ipt = 0; ipt < iptmax; ipt++) { - particleList[ip].pt[ipt] = ( - ptmin + (ptmax - ptmin)*pow(static_cast(ipt), 2.) - /pow(static_cast(iptmax - 1), 2.)); + particleList[ip].pt[ipt] = + (ptmin + + (ptmax - ptmin) * pow(static_cast(ipt), 2.) + / pow(static_cast(iptmax - 1), 2.)); } for (int ieta = 0; ieta <= pseudo_steps; ieta++) { - particleList[ip].y[ieta] = ieta*deltaeta - etamax; + particleList[ip].y[ieta] = ieta * deltaeta - etamax; } } particleMax = ip + 1; @@ -89,9 +93,9 @@ void Freeze::ReadSpectra_pseudo(InitData* DATA, int full, int verbose) { s_file = fopen(s_name.c_str(), "r"); if (verbose) { - music_message << "ietamax = " << pseudo_steps+1; + music_message << "ietamax = " << pseudo_steps + 1; music_message.flush("info"); - music_message << "cells = " << (pseudo_steps+1)*(iptmax)*iphimax; + music_message << "cells = " << (pseudo_steps + 1) * (iptmax)*iphimax; music_message.flush("info"); music_message << "particleMax = " << particleMax; music_message.flush("info"); @@ -103,12 +107,12 @@ void Freeze::ReadSpectra_pseudo(InitData* DATA, int full, int verbose) { << particleList[ip].name << " ..."; music_message.flush("info"); } - for(int ieta = 0; ieta <= pseudo_steps; ieta++) { + for (int ieta = 0; ieta <= pseudo_steps; ieta++) { for (int ipt = 0; ipt < iptmax; ipt++) { for (int iphi = 0; iphi < iphimax; iphi++) { system_status_ = fscanf( - s_file, "%lf", - &particleList[ip].dNdydptdphi[ieta][ipt][iphi]); + s_file, "%lf", + &particleList[ip].dNdydptdphi[ieta][ipt][iphi]); if (particleList[ip].dNdydptdphi[ieta][ipt][iphi] < 0.) { particleList[ip].dNdydptdphi[ieta][ipt][iphi] = 0; } @@ -122,7 +126,7 @@ void Freeze::ReadSpectra_pseudo(InitData* DATA, int full, int verbose) { if (phiArray == NULL) { phiArray = new double[iphimax]; for (int iphi = 0; iphi < iphimax; iphi++) { - phiArray[iphi] = iphi*2*M_PI/iphimax; + phiArray[iphi] = iphi * 2 * M_PI / iphimax; } } fclose(s_file); @@ -131,10 +135,10 @@ void Freeze::ReadSpectra_pseudo(InitData* DATA, int full, int verbose) { // Modified spectra calculation by ML 05/2013 // Calculates on fixed grid in pseudorapidity, pt, and phi // adapted from ML and improved on performance (C. Shen 2015) -void Freeze::ComputeParticleSpectrum_pseudo_improved(InitData *DATA, - int number) { +void Freeze::ComputeParticleSpectrum_pseudo_improved( + InitData *DATA, int number) { double y_minus_eta_cut = 4.0; - int j = partid[MHALF+number]; + int j = partid[MHALF + number]; // set some parameters double etamax = DATA->max_pseudorapidity; int ietamax = DATA->pseudo_steps + 1; // pseudo_steps is number of steps. @@ -142,24 +146,23 @@ void Freeze::ComputeParticleSpectrum_pseudo_improved(InitData *DATA, // number of points is steps + 1 double deltaeta = 0; if (ietamax > 1) { - deltaeta = 2.*etamax/DATA->pseudo_steps; + deltaeta = 2. * etamax / DATA->pseudo_steps; } double ptmax = DATA->max_pt; double ptmin = DATA->min_pt; - int iptmax = DATA->pt_steps+1; // Number of points is iptmax + 1 - // (ipt goes from 0 to iptmax) - int iphimax = DATA->phi_steps; // number of points - // (phi=2pi equal to phi=0) - double deltaphi = 2*M_PI/iphimax; + int iptmax = DATA->pt_steps + 1; // Number of points is iptmax + 1 + // (ipt goes from 0 to iptmax) + int iphimax = DATA->phi_steps; // number of points + // (phi=2pi equal to phi=0) + double deltaphi = 2 * M_PI / iphimax; // Reuse rapidity variables (Need to reuse variable y // so resonance decay routine can be used as is. // Might as well misuse ymax and deltaY too) - particleList[j].ymax = etamax; + particleList[j].ymax = etamax; particleList[j].deltaY = deltaeta; - music_message << "Doing " << j << ": " - << particleList[j].name << "(" + music_message << "Doing " << j << ": " << particleList[j].name << "(" << particleList[j].number << ") ... "; music_message.flush("info"); @@ -189,25 +192,26 @@ void Freeze::ComputeParticleSpectrum_pseudo_improved(InitData *DATA, // ----------------------------------------------------------------------- // write information in the particle information file FILE *d_file; - const char* d_name = "particleInformation.dat"; + const char *d_name = "particleInformation.dat"; d_file = fopen(d_name, "a"); - fprintf(d_file, "%d %e %d %e %e %d %d \n", - number, etamax, DATA->pseudo_steps+1, ptmin, ptmax, - iptmax, iphimax); + fprintf( + d_file, "%d %e %d %e %e %d %d \n", number, etamax, + DATA->pseudo_steps + 1, ptmin, ptmax, iptmax, iphimax); - // caching - double* cos_phi = new double [iphimax]; - double* sin_phi = new double [iphimax]; + // caching + double *cos_phi = new double[iphimax]; + double *sin_phi = new double[iphimax]; for (int iphi = 0; iphi < iphimax; iphi++) { - double phi_local = deltaphi*iphi; + double phi_local = deltaphi * iphi; cos_phi[iphi] = cos(phi_local); sin_phi[iphi] = sin(phi_local); } - double* pt_array = new double [iptmax]; + double *pt_array = new double[iptmax]; for (int ipt = 0; ipt < iptmax; ipt++) { - double pt = (ptmin + (ptmax - ptmin) - *pow(static_cast(ipt), 2.) - /pow(static_cast(iptmax - 1), 2.)); + double pt = + (ptmin + + (ptmax - ptmin) * pow(static_cast(ipt), 2.) + / pow(static_cast(iptmax - 1), 2.)); pt_array[ipt] = pt; particleList[j].pt[ipt] = pt; } @@ -227,7 +231,7 @@ void Freeze::ComputeParticleSpectrum_pseudo_improved(InitData *DATA, // pt and eta (pseudorapidity) in sumPtPhi: int ieta; for (ieta = 0; ieta < ietamax; ieta++) { - double eta = -etamax + ieta*deltaeta; + double eta = -etamax + ieta * deltaeta; // Use this variable to store pseudorapidity instead of rapidity // May cause confusion in the future, @@ -235,9 +239,9 @@ void Freeze::ComputeParticleSpectrum_pseudo_improved(InitData *DATA, // calculating on a fixed grid in rapidity or pseudorapidity particleList[j].y[ieta] = eta; // store particle pseudo-rapidity - double* rapidity = new double [iptmax]; - double* cosh_y = new double [iptmax]; - double* sinh_y = new double [iptmax]; + double *rapidity = new double[iptmax]; + double *cosh_y = new double[iptmax]; + double *sinh_y = new double[iptmax]; for (int ipt = 0; ipt < iptmax; ipt++) { double pt = pt_array[ipt]; double y_local; @@ -252,15 +256,15 @@ void Freeze::ComputeParticleSpectrum_pseudo_improved(InitData *DATA, sinh_y[ipt] = sinh(y_local); } - double** temp_sum = new double* [iptmax]; + double **temp_sum = new double *[iptmax]; for (int ii = 0; ii < iptmax; ii++) { - temp_sum[ii] = new double [iphimax]; + temp_sum[ii] = new double[iphimax]; for (int jj = 0; jj < iphimax; jj++) { temp_sum[ii][jj] = 0.0; } } - #pragma omp parallel +#pragma omp parallel { // need to perform reduction on a 2d array // first create a private copy for every omp_thread @@ -273,17 +277,17 @@ void Freeze::ComputeParticleSpectrum_pseudo_improved(InitData *DATA, } } - #pragma omp for +#pragma omp for for (int icell = 0; icell < NCells; icell++) { - double tau = surface[icell].x[0]; - double eta_s = surface[icell].x[3]; + double tau = surface[icell].x[0]; + double eta_s = surface[icell].x[3]; double cosh_eta_s = surface[icell].cosh_eta_s; double sinh_eta_s = surface[icell].sinh_eta_s; - double T = surface[icell].T_f*hbarc; // GeV - double muB = surface[icell].mu_B*hbarc; // GeV - double mu = baryon*muB; // GeV - if (DATA->whichEOS>=3 && DATA->whichEOS < 10) { + double T = surface[icell].T_f * hbarc; // GeV + double muB = surface[icell].mu_B * hbarc; // GeV + double mu = baryon * muB; // GeV + if (DATA->whichEOS >= 3 && DATA->whichEOS < 10) { // for PCE use the previously computed mu // at the freeze-out energy density mu += mu_PCE; // GeV @@ -328,7 +332,7 @@ void Freeze::ComputeParticleSpectrum_pseudo_improved(InitData *DATA, Pi_bulk = surface[icell].pi_b; getbulkvisCoefficients(T, bulk_deltaf_coeffs); } - + double qmu_0 = 0.0; double qmu_1 = 0.0; double qmu_2 = 0.0; @@ -347,9 +351,9 @@ void Freeze::ComputeParticleSpectrum_pseudo_improved(InitData *DATA, deltaf_qmu_coeff = get_deltaf_qmu_coeff(T, muB); } else { deltaf_qmu_coeff_14mom_DV = - get_deltaf_coeff_14moments(T, muB, 3); + get_deltaf_coeff_14moments(T, muB, 3); deltaf_qmu_coeff_14mom_BV = - get_deltaf_coeff_14moments(T, muB, 4); + get_deltaf_coeff_14moments(T, muB, 4); } } double rhoB = 0.0; @@ -358,9 +362,10 @@ void Freeze::ComputeParticleSpectrum_pseudo_improved(InitData *DATA, } double eps_plus_P_over_T = surface[icell].eps_plus_p_over_T_FO; - double prefactor_shear = 1./(2.*eps_plus_P_over_T*T*T*T)*hbarc; - // fm^4/GeV^2 - double prefactor_qmu = rhoB/(eps_plus_P_over_T*T); // 1/GeV + double prefactor_shear = + 1. / (2. * eps_plus_P_over_T * T * T * T) * hbarc; + // fm^4/GeV^2 + double prefactor_qmu = rhoB / (eps_plus_P_over_T * T); // 1/GeV for (int ipt = 0; ipt < iptmax; ipt++) { double y = rapidity[ipt]; @@ -368,28 +373,32 @@ void Freeze::ComputeParticleSpectrum_pseudo_improved(InitData *DATA, double pt = pt_array[ipt]; double cosh_y_local = cosh_y[ipt]; double sinh_y_local = sinh_y[ipt]; - double mt = sqrt(m*m + pt*pt); // all in GeV - double ptau = mt*(cosh_y_local*cosh_eta_s - - sinh_y_local*sinh_eta_s); - double peta = mt*(sinh_y_local*cosh_eta_s - - cosh_y_local*sinh_eta_s); + double mt = sqrt(m * m + pt * pt); // all in GeV + double ptau = mt + * (cosh_y_local * cosh_eta_s + - sinh_y_local * sinh_eta_s); + double peta = mt + * (sinh_y_local * cosh_eta_s + - cosh_y_local * sinh_eta_s); for (int iphi = 0; iphi < iphimax; iphi++) { - double px = pt*cos_phi[iphi]; - double py = pt*sin_phi[iphi]; - + double px = pt * cos_phi[iphi]; + double py = pt * sin_phi[iphi]; + double sum; // compute p^mu*dSigma_mu [fm^3*GeV] - double pdSigma = tau*(ptau*sigma_mu[0] - + px*sigma_mu[1] - + py*sigma_mu[2] - + peta/tau*sigma_mu[3]); - double E = (ptau*u_flow[0] - px*u_flow[1] - - py*u_flow[2] - peta*u_flow[3]); + double pdSigma = + tau + * (ptau * sigma_mu[0] + px * sigma_mu[1] + + py * sigma_mu[2] + + peta / tau * sigma_mu[3]); + double E = + (ptau * u_flow[0] - px * u_flow[1] + - py * u_flow[2] - peta * u_flow[3]); // this is the equilibrium f, f_0: - double f = 1./(exp(1./T*(E - mu)) + sign); - + double f = 1. / (exp(1. / T * (E - mu)) + sign); + // now comes the delta_f: check if still correct - // at finite mu_b + // at finite mu_b // we assume here the same C=eta/s for // all particle species because // it is the simplest way to do it. @@ -397,62 +406,64 @@ void Freeze::ComputeParticleSpectrum_pseudo_improved(InitData *DATA, double Wfactor = 0.0; double delta_f_shear = 0.0; if (flag_shear_deltaf == 1) { - Wfactor = (ptau*W00*ptau - 2.*ptau*W01*px - - 2.*ptau*W02*py - - 2.*ptau*W03*peta - + px*W11*px + 2.*px*W12*py - + 2.*px*W13*peta - + py*W22*py + 2.*py*W23*peta - + peta*W33*peta); - delta_f_shear = (f*(1. - sign*f) - *prefactor_shear*Wfactor); - if (DATA->include_deltaf==2) { + Wfactor = + (ptau * W00 * ptau - 2. * ptau * W01 * px + - 2. * ptau * W02 * py + - 2. * ptau * W03 * peta + px * W11 * px + + 2. * px * W12 * py + 2. * px * W13 * peta + + py * W22 * py + 2. * py * W23 * peta + + peta * W33 * peta); + delta_f_shear = + (f * (1. - sign * f) * prefactor_shear + * Wfactor); + if (DATA->include_deltaf == 2) { // if delta f is proportional // to p^(2-alpha): - delta_f_shear = (delta_f_shear - *pow((T/E), 1.*alpha) - *120./(tgamma(6.-alpha))); + delta_f_shear = + (delta_f_shear + * pow((T / E), 1. * alpha) * 120. + / (tgamma(6. - alpha))); } } double delta_f_bulk = 0.0; if (flag_bulk_deltaf == 1) { if (bulk_deltaf_kind == 0) { - delta_f_bulk = ( - - f*(1. - sign*f)*Pi_bulk - *(bulk_deltaf_coeffs[0]*m*m - + bulk_deltaf_coeffs[1]*E - + bulk_deltaf_coeffs[2]*E*E)); + delta_f_bulk = + (-f * (1. - sign * f) * Pi_bulk + * (bulk_deltaf_coeffs[0] * m * m + + bulk_deltaf_coeffs[1] * E + + bulk_deltaf_coeffs[2] * E * E)); } else if (bulk_deltaf_kind == 1) { - double E_over_T = E/T; - double mass_over_T = m/T; - delta_f_bulk = ( - - f*(1. - sign*f)/E_over_T - *bulk_deltaf_coeffs[0] - *(mass_over_T*mass_over_T/3. - - bulk_deltaf_coeffs[1] - *E_over_T*E_over_T) - *Pi_bulk); + double E_over_T = E / T; + double mass_over_T = m / T; + delta_f_bulk = + (-f * (1. - sign * f) / E_over_T + * bulk_deltaf_coeffs[0] + * (mass_over_T * mass_over_T / 3. + - bulk_deltaf_coeffs[1] * E_over_T + * E_over_T) + * Pi_bulk); } else if (bulk_deltaf_kind == 2) { - double E_over_T = E/T; - delta_f_bulk = ( - - f*(1. - sign*f) - *(-bulk_deltaf_coeffs[0] - + bulk_deltaf_coeffs[1]*E_over_T) - *Pi_bulk); + double E_over_T = E / T; + delta_f_bulk = + (-f * (1. - sign * f) + * (-bulk_deltaf_coeffs[0] + + bulk_deltaf_coeffs[1] * E_over_T) + * Pi_bulk); } else if (bulk_deltaf_kind == 3) { - double E_over_T = E/T; - delta_f_bulk = ( - - f*(1.-sign*f)/sqrt(E_over_T) - *(- bulk_deltaf_coeffs[0] - + bulk_deltaf_coeffs[1]*E_over_T) - *Pi_bulk); + double E_over_T = E / T; + delta_f_bulk = + (-f * (1. - sign * f) / sqrt(E_over_T) + * (-bulk_deltaf_coeffs[0] + + bulk_deltaf_coeffs[1] * E_over_T) + * Pi_bulk); } else if (bulk_deltaf_kind == 4) { - double E_over_T = E/T; - delta_f_bulk = ( - - f*(1.-sign*f) - *(bulk_deltaf_coeffs[0] - - bulk_deltaf_coeffs[1]/E_over_T) - *Pi_bulk); + double E_over_T = E / T; + delta_f_bulk = + (-f * (1. - sign * f) + * (bulk_deltaf_coeffs[0] + - bulk_deltaf_coeffs[1] / E_over_T) + * Pi_bulk); } } @@ -461,46 +472,47 @@ void Freeze::ComputeParticleSpectrum_pseudo_improved(InitData *DATA, double delta_f_qmu = 0.0; if (flag_qmu_deltaf == 1) { // p^\mu q_\mu - qmufactor = (ptau*qmu_0 - px*qmu_1 - py*qmu_2 - - peta*qmu_3); + qmufactor = + (ptau * qmu_0 - px * qmu_1 - py * qmu_2 + - peta * qmu_3); if (DATA->deltaf_14moments == 0) { - delta_f_qmu = ( - f*(1. - sign*f) - *(prefactor_qmu - baryon/E)*qmufactor - /deltaf_qmu_coeff); + delta_f_qmu = + (f * (1. - sign * f) + * (prefactor_qmu - baryon / E) + * qmufactor / deltaf_qmu_coeff); } else { - delta_f_qmu = ( - f*(1. - sign*f) - *(baryon*deltaf_qmu_coeff_14mom_DV - + 2.*deltaf_qmu_coeff_14mom_BV*E) - *qmufactor); + delta_f_qmu = + (f * (1. - sign * f) + * (baryon * deltaf_qmu_coeff_14mom_DV + + 2. * deltaf_qmu_coeff_14mom_BV + * E) + * qmufactor); } } double max_ratio = 1.0; - double total_deltaf = (delta_f_shear - + delta_f_bulk - + delta_f_qmu); + double total_deltaf = + (delta_f_shear + delta_f_bulk + delta_f_qmu); - if (fabs(total_deltaf)/f > max_ratio) { - total_deltaf *= f/fabs(total_deltaf); + if (fabs(total_deltaf) / f > max_ratio) { + total_deltaf *= f / fabs(total_deltaf); } - sum = (f + total_deltaf)*pdSigma; - + sum = (f + total_deltaf) * pdSigma; + if (sum > 10000) { - music_message << "sum>10000 in summation. sum = " - << sum - << ", f=" << f << ", deltaf=" - << delta_f_shear - << ", pdSigma=" << pdSigma << ", T=" << T - << ", E=" << E << ", mu=" << mu; + music_message + << "sum>10000 in summation. sum = " << sum + << ", f=" << f + << ", deltaf=" << delta_f_shear + << ", pdSigma=" << pdSigma << ", T=" << T + << ", E=" << E << ", mu=" << mu; music_message.flush("warning"); } if (f < 0.) { music_message << " f_eq < 0.! f_eq = " << f - << ", T = " << T << " GeV, mu = " - << mu << " GeV, E = " - << E << " GeV"; + << ", T = " << T + << " GeV, mu = " << mu + << " GeV, E = " << E << " GeV"; music_message.flush("error"); } temp_sum_private[ipt][iphi] += sum; @@ -508,7 +520,7 @@ void Freeze::ComputeParticleSpectrum_pseudo_improved(InitData *DATA, } } } - #pragma omp critical +#pragma omp critical { for (int ipt = 0; ipt < iptmax; ipt++) { for (int iphi = 0; iphi < iphimax; iphi++) { @@ -517,25 +529,24 @@ void Freeze::ComputeParticleSpectrum_pseudo_improved(InitData *DATA, } } } - double prefactor = deg/(pow(2.*M_PI,3.)*pow(hbarc,3.)); + double prefactor = deg / (pow(2. * M_PI, 3.) * pow(hbarc, 3.)); // store the final results for (int ipt = 0; ipt < iptmax; ipt++) { for (int iphi = 0; iphi < iphimax; iphi++) { - double sum = temp_sum[ipt][iphi]*prefactor; // in GeV^(-2) + double sum = temp_sum[ipt][iphi] * prefactor; // in GeV^(-2) particleList[j].dNdydptdphi[ieta][ipt][iphi] = sum; - fprintf(s_file,"%e ", sum); + fprintf(s_file, "%e ", sum); } - fprintf(s_file,"\n"); + fprintf(s_file, "\n"); } // clean up delete[] rapidity; delete[] cosh_y; delete[] sinh_y; - for (int ipt = 0; ipt < iptmax; ipt++) - delete[] temp_sum[ipt]; + for (int ipt = 0; ipt < iptmax; ipt++) delete[] temp_sum[ipt]; delete[] temp_sum; } - + if (DATA_ptr->turn_on_bulk == 1 && DATA_ptr->include_deltaf_bulk == 1) { delete[] bulk_deltaf_coeffs; } @@ -548,43 +559,40 @@ void Freeze::ComputeParticleSpectrum_pseudo_improved(InitData *DATA, fclose(d_file); } - void Freeze::ComputeParticleSpectrum_pseudo_boost_invariant( - InitData *DATA, int number) { + InitData *DATA, int number) { // this function compute thermal paritcle spectra assuming a // boost-invarianat hyper-surface from hydro simulations - int j = partid[MHALF+number]; + int j = partid[MHALF + number]; // set some parameters double etamax = DATA->max_pseudorapidity; int ietamax = DATA->pseudo_steps + 1; // pseudo_steps is number of steps. // Including edges // number of points is steps + 1 double deltaeta = 1.0; - if (ietamax > 1) - deltaeta = 2.*etamax/DATA->pseudo_steps; + if (ietamax > 1) deltaeta = 2. * etamax / DATA->pseudo_steps; double ptmax = DATA->max_pt; double ptmin = DATA->min_pt; - int iptmax = DATA->pt_steps+1; // Number of points is iptmax + 1 - // (ipt goes from 0 to iptmax) - int iphimax = DATA->phi_steps; // number of points - // (phi=2pi equal to phi=0) - double deltaphi = 2*M_PI/iphimax; - + int iptmax = DATA->pt_steps + 1; // Number of points is iptmax + 1 + // (ipt goes from 0 to iptmax) + int iphimax = DATA->phi_steps; // number of points + // (phi=2pi equal to phi=0) + double deltaphi = 2 * M_PI / iphimax; + // Reuse rapidity variables (Need to reuse variable y // so resonance decay routine can be used as is. // Might as well misuse ymax and deltaY too) - particleList[j].ymax = etamax; + particleList[j].ymax = etamax; particleList[j].deltaY = deltaeta; - music_message << "Doing " << j << ": " - << particleList[j].name << "(" + music_message << "Doing " << j << ": " << particleList[j].name << "(" << particleList[j].number << ") ..."; music_message.flush("info"); - + particleList[j].ny = DATA->pseudo_steps + 1; particleList[j].npt = iptmax; particleList[j].nphi = iphimax; - + // set particle properties double m = particleList[j].mass; int deg = particleList[j].degeneracy; @@ -610,26 +618,27 @@ void Freeze::ComputeParticleSpectrum_pseudo_boost_invariant( // ----------------------------------------------------------------------- // write information in the particle information file - fprintf(d_file, "%d %e %d %e %e %d %d \n", - number, etamax, DATA->pseudo_steps+1, ptmin, ptmax, - iptmax, iphimax); - // caching + fprintf( + d_file, "%d %e %d %e %e %d %d \n", number, etamax, + DATA->pseudo_steps + 1, ptmin, ptmax, iptmax, iphimax); + // caching double *cos_phi = new double[iphimax]; double *sin_phi = new double[iphimax]; for (int iphi = 0; iphi < iphimax; iphi++) { - double phi_local = deltaphi*iphi; + double phi_local = deltaphi * iphi; cos_phi[iphi] = cos(phi_local); sin_phi[iphi] = sin(phi_local); } - double* pt_array = new double[iptmax]; + double *pt_array = new double[iptmax]; for (int ipt = 0; ipt < iptmax; ipt++) { - double pt = (ptmin + (ptmax - ptmin) - *pow(static_cast(ipt), 2.) - /pow(static_cast(iptmax - 1), 2.)); + double pt = + (ptmin + + (ptmax - ptmin) * pow(static_cast(ipt), 2.) + / pow(static_cast(iptmax - 1), 2.)); pt_array[ipt] = pt; particleList[j].pt[ipt] = pt; } - + double *bulk_deltaf_coeffs = new double[3]; if (DATA_ptr->turn_on_bulk == 1 && DATA_ptr->include_deltaf_bulk == 1) { if (bulk_deltaf_kind == 0) { @@ -638,40 +647,40 @@ void Freeze::ComputeParticleSpectrum_pseudo_boost_invariant( bulk_deltaf_coeffs = new double[2]; } } - + double alpha = 0.0; - double** temp_sum = new double* [iptmax]; + double **temp_sum = new double *[iptmax]; for (int ii = 0; ii < iptmax; ii++) { - temp_sum[ii] = new double [iphimax]; + temp_sum[ii] = new double[iphimax]; for (int jj = 0; jj < iphimax; jj++) { temp_sum[ii][jj] = 0.0; } } - + // main loop begins ... // store E dN/d^3p as function of phi, // pt and eta (pseudorapidity) in sumPtPhi: - #pragma omp parallel +#pragma omp parallel { // need to perform reduction on a 2d array // first create a private copy for every omp_thread // use critical clause at the end to add the private 2d arrays // together from individual omp_thread double temp_sum_private[iptmax][iphimax]; - for (int ii = 0; ii < iptmax; ii++) - for (int jj = 0; jj < iphimax; jj++) { - temp_sum_private[ii][jj] = 0.0; - } + for (int ii = 0; ii < iptmax; ii++) + for (int jj = 0; jj < iphimax; jj++) { + temp_sum_private[ii][jj] = 0.0; + } - #pragma omp for +#pragma omp for for (int icell = 0; icell < NCells; icell++) { double tau = surface[icell].x[0]; - double T = surface[icell].T_f*hbarc; // GeV + double T = surface[icell].T_f * hbarc; // GeV double muB = 0.0; - double mu = baryon*muB; // GeV - if (DATA->whichEOS>=3 && DATA->whichEOS < 10) { + double mu = baryon * muB; // GeV + if (DATA->whichEOS >= 3 && DATA->whichEOS < 10) { // for PCE use the previously computed mu // at the freeze-out energy density mu += mu_PCE; // GeV @@ -718,35 +727,37 @@ void Freeze::ComputeParticleSpectrum_pseudo_boost_invariant( } double eps_plus_P_over_T = surface[icell].eps_plus_p_over_T_FO; - double prefactor_shear = 1./(2.*eps_plus_P_over_T*T*T*T)*hbarc; - // fm^4/GeV^2 + double prefactor_shear = + 1. / (2. * eps_plus_P_over_T * T * T * T) * hbarc; + // fm^4/GeV^2 for (int ieta_s = 0; ieta_s < n_eta_s_integral; ieta_s++) { double cosh_eta_s = cosh_eta_s_inte[ieta_s]; double sinh_eta_s = sinh_eta_s_inte[ieta_s]; - for (int ipt=0; iptinclude_deltaf==2) { + Wfactor = + (ptau * W00 * ptau - 2. * ptau * W01 * px + - 2. * ptau * W02 * py - 2. * ptau * W03 * peta + + px * W11 * px + 2. * px * W12 * py + + 2. * px * W13 * peta + py * W22 * py + + 2. * py * W23 * peta + peta * W33 * peta); + delta_f_shear = + (f * (1. - sign * f) * prefactor_shear + * Wfactor); + if (DATA->include_deltaf == 2) { // if delta f is supposed to be proportional // to p^(2-alpha): - delta_f_shear = (delta_f_shear - *pow((T/E), 1.*alpha) - *120./(tgamma(6.-alpha))); + delta_f_shear = + (delta_f_shear * pow((T / E), 1. * alpha) + * 120. / (tgamma(6. - alpha))); } } double delta_f_bulk = 0.0; if (flag_bulk_deltaf == 1) { if (bulk_deltaf_kind == 0) { - delta_f_bulk = ( - - f*(1. - sign*f)*Pi_bulk - *(bulk_deltaf_coeffs[0]*m*m - + bulk_deltaf_coeffs[1]*E - + bulk_deltaf_coeffs[2]*E*E)); + delta_f_bulk = + (-f * (1. - sign * f) * Pi_bulk + * (bulk_deltaf_coeffs[0] * m * m + + bulk_deltaf_coeffs[1] * E + + bulk_deltaf_coeffs[2] * E * E)); } else if (bulk_deltaf_kind == 1) { - double E_over_T = E/T; - double mass_over_T = m/T; - delta_f_bulk = ( - - f*(1. - sign*f)/E_over_T - *bulk_deltaf_coeffs[0] - *(mass_over_T*mass_over_T/3. - - bulk_deltaf_coeffs[1] - *E_over_T*E_over_T) - *Pi_bulk); + double E_over_T = E / T; + double mass_over_T = m / T; + delta_f_bulk = + (-f * (1. - sign * f) / E_over_T + * bulk_deltaf_coeffs[0] + * (mass_over_T * mass_over_T / 3. + - bulk_deltaf_coeffs[1] * E_over_T + * E_over_T) + * Pi_bulk); } else if (bulk_deltaf_kind == 2) { - double E_over_T = E/T; - delta_f_bulk = ( - - f*(1. - sign*f) - *(-bulk_deltaf_coeffs[0] - + bulk_deltaf_coeffs[1]*E_over_T) - *Pi_bulk); + double E_over_T = E / T; + delta_f_bulk = + (-f * (1. - sign * f) + * (-bulk_deltaf_coeffs[0] + + bulk_deltaf_coeffs[1] * E_over_T) + * Pi_bulk); } else if (bulk_deltaf_kind == 3) { - double E_over_T = E/T; - delta_f_bulk = ( - - f*(1.-sign*f)/sqrt(E_over_T) - *(- bulk_deltaf_coeffs[0] - + bulk_deltaf_coeffs[1]*E_over_T) - *Pi_bulk); + double E_over_T = E / T; + delta_f_bulk = + (-f * (1. - sign * f) / sqrt(E_over_T) + * (-bulk_deltaf_coeffs[0] + + bulk_deltaf_coeffs[1] * E_over_T) + * Pi_bulk); } else if (bulk_deltaf_kind == 4) { - double E_over_T = E/T; - delta_f_bulk = ( - - f*(1.-sign*f) - *(bulk_deltaf_coeffs[0] - - bulk_deltaf_coeffs[1]/E_over_T) - *Pi_bulk); + double E_over_T = E / T; + delta_f_bulk = + (-f * (1. - sign * f) + * (bulk_deltaf_coeffs[0] + - bulk_deltaf_coeffs[1] / E_over_T) + * Pi_bulk); } } double total_deltaf = delta_f_shear + delta_f_bulk; double max_ratio = 1.0; - if (fabs(total_deltaf)/f > max_ratio) { - total_deltaf *= f/fabs(total_deltaf); + if (fabs(total_deltaf) / f > max_ratio) { + total_deltaf *= f / fabs(total_deltaf); } - sum = (f + total_deltaf)*pdSigma; + sum = (f + total_deltaf) * pdSigma; if (sum > 10000) { - music_message << "sum>10000 in summation. sum = " - << sum - << ", f=" << f << ", deltaf=" << delta_f_shear - << ", pdSigma=" << pdSigma << ", T=" << T - << ", E=" << E << ", mu=" << mu; + music_message + << "sum>10000 in summation. sum = " << sum + << ", f=" << f << ", deltaf=" << delta_f_shear + << ", pdSigma=" << pdSigma << ", T=" << T + << ", E=" << E << ", mu=" << mu; music_message.flush("warning"); } - temp_sum_private[ipt][iphi] += ( - sum*eta_s_inte_weight[ieta_s]); + temp_sum_private[ipt][iphi] += + (sum * eta_s_inte_weight[ieta_s]); } } } } - #pragma omp critical +#pragma omp critical { for (int ipt = 0; ipt < iptmax; ipt++) { for (int iphi = 0; iphi < iphimax; iphi++) { @@ -842,10 +853,10 @@ void Freeze::ComputeParticleSpectrum_pseudo_boost_invariant( } } } - double prefactor = deg/(pow(2.*M_PI, 3.)*pow(hbarc, 3.)); + double prefactor = deg / (pow(2. * M_PI, 3.) * pow(hbarc, 3.)); for (int ieta = 0; ieta < ietamax; ieta++) { - double eta = -etamax + ieta*deltaeta; + double eta = -etamax + ieta * deltaeta; // Use this variable to store pseudorapidity instead of rapidity // May cause confusion in the future, // but easier to to share code for both options: @@ -854,8 +865,8 @@ void Freeze::ComputeParticleSpectrum_pseudo_boost_invariant( // store the final results for (int ipt = 0; ipt < iptmax; ipt++) { - for(int iphi = 0; iphi < iphimax; iphi++) { - double sum = temp_sum[ipt][iphi]*prefactor; + for (int iphi = 0; iphi < iphimax; iphi++) { + double sum = temp_sum[ipt][iphi] * prefactor; particleList[j].dNdydptdphi[ieta][ipt][iphi] = sum; fprintf(s_file, "%e ", sum); } @@ -868,7 +879,7 @@ void Freeze::ComputeParticleSpectrum_pseudo_boost_invariant( } delete[] temp_sum; if (DATA_ptr->turn_on_bulk == 1 && DATA_ptr->include_deltaf_bulk == 1) { - delete [] bulk_deltaf_coeffs; + delete[] bulk_deltaf_coeffs; } // clean up @@ -879,45 +890,46 @@ void Freeze::ComputeParticleSpectrum_pseudo_boost_invariant( fclose(d_file); } -void Freeze::OutputFullParticleSpectrum_pseudo(InitData *DATA, int number, - int anti, int full) { +void Freeze::OutputFullParticleSpectrum_pseudo( + InitData *DATA, int number, int anti, int full) { FILE *d_file; - const char* d_name = "FparticleInformation.dat"; + const char *d_name = "FparticleInformation.dat"; d_file = fopen(d_name, "a"); - fprintf(d_file, "%d %e %d %e %e %d %d \n", - number, DATA->max_pseudorapidity, DATA->pseudo_steps+1, - DATA->min_pt, DATA->max_pt, DATA->pt_steps+1, DATA->phi_steps); + fprintf( + d_file, "%d %e %d %e %e %d %d \n", number, DATA->max_pseudorapidity, + DATA->pseudo_steps + 1, DATA->min_pt, DATA->max_pt, DATA->pt_steps + 1, + DATA->phi_steps); fclose(d_file); FILE *s_file; - const char* s_name = "FyptphiSpectra.dat"; + const char *s_name = "FyptphiSpectra.dat"; s_file = fopen(s_name, "a"); - int j = partid[MHALF+number]; + int j = partid[MHALF + number]; for (int iy = 0; iy <= DATA->pseudo_steps; iy++) { for (int ipt = 0; ipt <= DATA->pt_steps; ipt++) { for (int iphi = 0; iphi < DATA->phi_steps; iphi++) { - fprintf(s_file, "%e ", - particleList[j].dNdydptdphi[iy][ipt][iphi]); + fprintf( + s_file, "%e ", particleList[j].dNdydptdphi[iy][ipt][iphi]); } - fprintf(s_file,"\n"); + fprintf(s_file, "\n"); } } fclose(s_file); } - //! this function computes particle thermal spectra -void Freeze::compute_thermal_spectra(int particleSpectrumNumber, - InitData* DATA) { +void Freeze::compute_thermal_spectra( + int particleSpectrumNumber, InitData *DATA) { double mass_tol = 1e-3; double mu_tol = 1e-3; // clean up - system_status_ = system("rm yptphiSpectra.dat yptphiSpectra?.dat " - "yptphiSpectra??.dat particleInformation.dat 2> /dev/null"); + system_status_ = system( + "rm yptphiSpectra.dat yptphiSpectra?.dat " + "yptphiSpectra??.dat particleInformation.dat 2> /dev/null"); ReadFreezeOutSurface(DATA); // read freeze out surface if (particleSpectrumNumber == 0) { @@ -930,15 +942,16 @@ void Freeze::compute_thermal_spectra(int particleSpectrumNumber, int computespectrum = 1; // Only calculate particles with unique mass - for(int part = 1; part < i; part++) { - double mass_diff = fabs(particleList[i].mass - - particleList[part].mass); - double mu_diff = fabs(particleList[i].muAtFreezeOut - - particleList[part].muAtFreezeOut); + for (int part = 1; part < i; part++) { + double mass_diff = + fabs(particleList[i].mass - particleList[part].mass); + double mu_diff = fabs( + particleList[i].muAtFreezeOut + - particleList[part].muAtFreezeOut); if (mass_diff < mass_tol && mu_diff < mu_tol && (DATA->turn_on_rhob == 0 - || particleList[i].baryon == particleList[part].baryon) - ) { + || particleList[i].baryon + == particleList[part].baryon)) { // here we assume zero mu_B computespectrum = 0; @@ -959,61 +972,63 @@ void Freeze::compute_thermal_spectra(int particleSpectrumNumber, double etamax = DATA->max_pseudorapidity; // If the particles have a different degeneracy, // we have to multiply by the ratio when copying. - double degen_ratio = ( - static_cast(particleList[i].degeneracy) - /static_cast(particleList[part].degeneracy) - ); + double degen_ratio = + (static_cast(particleList[i].degeneracy) + / static_cast(particleList[part].degeneracy)); // open files to write FILE *d_file; - const char* d_name = "particleInformation.dat"; + const char *d_name = "particleInformation.dat"; d_file = fopen(d_name, "a"); FILE *s_file; - const char* s_name = "yptphiSpectra.dat"; + const char *s_name = "yptphiSpectra.dat"; s_file = fopen(s_name, "a"); - particleList[i].ymax = particleList[part].ymax; + particleList[i].ymax = particleList[part].ymax; particleList[i].deltaY = particleList[part].deltaY; particleList[i].ny = particleList[part].ny; particleList[i].npt = particleList[part].npt; particleList[i].nphi = particleList[part].nphi; - fprintf(d_file, "%d %e %d %e %e %d %d \n", - number, etamax, ietamax, ptmin, ptmax, - iptmax, iphimax); + fprintf( + d_file, "%d %e %d %e %e %d %d \n", number, etamax, + ietamax, ptmin, ptmax, iptmax, iphimax); for (int ieta = 0; ieta < ietamax; ieta++) { for (int ipt = 0; ipt < iptmax; ipt++) { particleList[i].pt[ipt] = - particleList[part].pt[ipt]; + particleList[part].pt[ipt]; particleList[i].y[ieta] = - particleList[part].y[ieta]; + particleList[part].y[ieta]; for (int iphi = 0; iphi < iphimax; iphi++) { particleList[i].dNdydptdphi[ieta][ipt][iphi] = (degen_ratio - *particleList[part].dNdydptdphi[ieta][ipt][iphi]); - fprintf(s_file, "%e ", - particleList[i].dNdydptdphi[ieta][ipt][iphi]); + * particleList[part] + .dNdydptdphi[ieta][ipt][iphi]); + fprintf( + s_file, "%e ", + particleList[i] + .dNdydptdphi[ieta][ipt][iphi]); } fprintf(s_file, "\n"); } } fclose(s_file); fclose(d_file); - part = particleMax_copy; // break out of particle loop + part = particleMax_copy; // break out of particle loop } // if particles have same mass } // loop over particles that have already been calculated if (computespectrum) { if (boost_invariant) { ComputeParticleSpectrum_pseudo_boost_invariant( - DATA, number); + DATA, number); } else { ComputeParticleSpectrum_pseudo_improved(DATA, number); } + system_status_ = + system("cat yptphiSpectra?.dat >> yptphiSpectra.dat"); system_status_ = system( - "cat yptphiSpectra?.dat >> yptphiSpectra.dat"); - system_status_ = system( - "cat yptphiSpectra??.dat >> yptphiSpectra.dat " - "2> /dev/null"); + "cat yptphiSpectra??.dat >> yptphiSpectra.dat " + "2> /dev/null"); } } } else { @@ -1032,26 +1047,27 @@ void Freeze::compute_thermal_spectra(int particleSpectrumNumber, ComputeParticleSpectrum_pseudo_improved(DATA, number); } system_status_ = system("cat yptphiSpectra?.dat >> yptphiSpectra.dat"); - system_status_ = system("cat yptphiSpectra??.dat >> yptphiSpectra.dat " - "2> /dev/null"); + system_status_ = system( + "cat yptphiSpectra??.dat >> yptphiSpectra.dat " + "2> /dev/null"); } } void Freeze::perform_resonance_decays(InitData *DATA) { ReadSpectra_pseudo(DATA, 0, 1); - int bound = 211; //number of lightest particle to calculate. + int bound = 211; // number of lightest particle to calculate. music_message << "particleMax = " << particleMax; music_message.flush("info"); music_message << "doing all from " << particleMax << ": " << particleList[particleMax].name << "to " - << partid[MHALF+bound] << ": " - << particleList[partid[MHALF+bound]].name; + << partid[MHALF + bound] << ": " + << particleList[partid[MHALF + bound]].name; music_message.flush("info"); cal_reso_decays(particleMax, decayMax, bound); - system_status_ = system( - "rm FyptphiSpectra.dat FparticleInformation.dat 2> /dev/null"); + system_status_ = + system("rm FyptphiSpectra.dat FparticleInformation.dat 2> /dev/null"); for (int i = 1; i < particleMax; i++) { int number = particleList[i].number; int b = particleList[i].baryon; @@ -1059,7 +1075,7 @@ void Freeze::perform_resonance_decays(InitData *DATA) { } } -void Freeze::compute_thermal_particle_spectra_and_vn(InitData* DATA) { +void Freeze::compute_thermal_particle_spectra_and_vn(InitData *DATA) { // take tabulated spectra // and compute various observables and integrated quantities int status = mkdir("./outputs", 0755); @@ -1069,18 +1085,18 @@ void Freeze::compute_thermal_particle_spectra_and_vn(InitData* DATA) { } ReadSpectra_pseudo(DATA, 0, 1); - //Make sure the pion, kaon and proton spectra are available + // Make sure the pion, kaon and proton spectra are available if (particleMax < 21) { - music_message << __func__ + music_message << __func__ << ": cannot compute pion, kaon and proton observables, " << "some of the spectra are not available."; music_message.flush("warning"); } else { - int pid_list [] = {211, -211, 321, -321, 2212, -2212}; - int pid_list_length = sizeof(pid_list)/sizeof(int); + int pid_list[] = {211, -211, 321, -321, 2212, -2212}; + int pid_list_length = sizeof(pid_list) / sizeof(int); for (int k = 0; k < pid_list_length; k++) { int number = pid_list[k]; - int id = partid[MHALF+number]; + int id = partid[MHALF + number]; if (id < particleMax) { OutputDifferentialFlowAtMidrapidity(DATA, number, 0); OutputDifferentialFlowNearMidrapidity(DATA, number, 0); @@ -1090,19 +1106,19 @@ void Freeze::compute_thermal_particle_spectra_and_vn(InitData* DATA) { } } -void Freeze::compute_final_particle_spectra_and_vn(InitData* DATA) { +void Freeze::compute_final_particle_spectra_and_vn(InitData *DATA) { // take tabulated post-decay spectra and // compute various observables and integrated quantities - int status = mkdir("./outputs", 0755); // output results folder + int status = mkdir("./outputs", 0755); // output results folder if (status != 0) { music_message << "Can not create folder ./outputs ..."; music_message.flush("warning"); } ReadSpectra_pseudo(DATA, 1, 1); // read in particle spectra information - + if (DATA->NumberOfParticlesToInclude > 200) { - if ((DATA-> whichEOS != 7 && particleMax < 320) - || ((DATA->whichEOS == 7) && particleMax < 327)) { + if ((DATA->whichEOS != 7 && particleMax < 320) + || ((DATA->whichEOS == 7) && particleMax < 327)) { music_message << "Not all hadronic species are computed " << "particleMax = " << particleMax; music_message.flush("warning"); @@ -1124,17 +1140,17 @@ void Freeze::compute_final_particle_spectra_and_vn(InitData* DATA) { } if (particleMax < 21) { - music_message << __func__ + music_message << __func__ << "cannot compute pion, kaon and proton observables, " << "some of the spectra are not available."; music_message.flush("warning"); } else { // calculate spectra and vn for identified particles - int pid_list [] = {211, -211, 321, -321, 2212, -2212}; - int pid_list_length = sizeof(pid_list)/sizeof(int); + int pid_list[] = {211, -211, 321, -321, 2212, -2212}; + int pid_list_length = sizeof(pid_list) / sizeof(int); for (int k = 0; k < pid_list_length; k++) { int number = pid_list[k]; - int id = partid[MHALF+number]; + int id = partid[MHALF + number]; if (id < particleMax) { OutputDifferentialFlowAtMidrapidity(DATA, number, 1); OutputDifferentialFlowNearMidrapidity(DATA, number, 1); @@ -1144,69 +1160,67 @@ void Freeze::compute_final_particle_spectra_and_vn(InitData* DATA) { } } - -void Freeze::CooperFrye_pseudo(int particleSpectrumNumber, int mode, - InitData *DATA, EOS *eos) { +void Freeze::CooperFrye_pseudo( + int particleSpectrumNumber, int mode, InitData *DATA, EOS *eos) { // this is a shell function for Cooper-Frye routine // -- spectra calculated on an equally-spaced grid // in phi and (pseudo)rapidity - ReadParticleData(DATA, eos); // read in data for Cooper-Frye + ReadParticleData(DATA, eos); // read in data for Cooper-Frye if (mode == 3 || mode == 1) { // compute thermal spectra compute_thermal_spectra(particleSpectrumNumber, DATA); } - if (mode==4 || mode==1) { // do resonance decays + if (mode == 4 || mode == 1) { // do resonance decays perform_resonance_decays(DATA); - } - if (mode==13 || mode == 3 || mode == 1) { + } + if (mode == 13 || mode == 3 || mode == 1) { compute_thermal_particle_spectra_and_vn(DATA); - } - if (mode==14 || mode == 4 || mode == 1) { + } + if (mode == 14 || mode == 4 || mode == 1) { compute_final_particle_spectra_and_vn(DATA); - } + } // clean up delete[] partid; free(particleList); } - // returns pseudorapidity for a given rapidity, transverse momentum, and mass double Freeze::PseudoRap(double y, double pt, double m) { - double eta = acosh(2*m*m/pt/pt*sinh(y)*sinh(y) + cosh(2*y))/2.; - if (y < 0) - eta *= -1.; + double eta = + acosh(2 * m * m / pt / pt * sinh(y) * sinh(y) + cosh(2 * y)) / 2.; + if (y < 0) eta *= -1.; return eta; } // returns rapidity for a given pseudorapidity, transverse momentum, and mass double Freeze::Rap(double eta, double pt, double m) { - double y = log((sqrt(m*m + pt*pt*cosh(eta)*cosh(eta)) + pt*sinh(eta)) - /sqrt(m*m+pt*pt)); + double y = + log((sqrt(m * m + pt * pt * cosh(eta) * cosh(eta)) + pt * sinh(eta)) + / sqrt(m * m + pt * pt)); return y; } // jacobian to convert dN/dy to dN/deta: dN/deta = dydeta*dN/dy double Freeze::dydeta(double eta, double pt, double m) { - return pt*cosh(eta)/sqrt(m*m + pt*pt*cosh(eta)*cosh(eta)); + return pt * cosh(eta) / sqrt(m * m + pt * pt * cosh(eta) * cosh(eta)); } - // calculates eta= or y-integrated flow versus rapidity. // format is vn[n][i(real=0 or imaginary part=1)][pt] . // yflag = 0 takes minrap and maxrap as a range in psuedorapidity, // while yflag = 1 uses rapidity // Yield (n=0) is dN/dpt/dy or dN/dpt/deta for minrap==maxrap, -// or dN/dpt otherwise +// or dN/dpt otherwise void Freeze::rapidity_integrated_flow( - InitData *DATA, int number, int yflag, double minrap, double maxrap, - double vn[nharmonics][2][etasize]) { - int j = partid[MHALF+number]; + InitData *DATA, int number, int yflag, double minrap, double maxrap, + double vn[nharmonics][2][etasize]) { + int j = partid[MHALF + number]; int nphi = particleList[j].nphi; int npt = particleList[j].npt; int neta = particleList[j].ny; double intvn[ptsize][nharmonics][2] = {}; double m = particleList[j].mass; - + double testmin; if (yflag) { if (DATA->pseudofreeze == 1) @@ -1217,52 +1231,55 @@ void Freeze::rapidity_integrated_flow( if (DATA->pseudofreeze == 1) testmin = particleList[j].y[0]; else - testmin = PseudoRap(particleList[j].y[0], particleList[j].pt[0], - m); + testmin = PseudoRap(particleList[j].y[0], particleList[j].pt[0], m); } if (minrap < testmin) { - music_message << "Error: called out of range rapidity in rap_integrated_flow, " - << minrap << " < minimum " << testmin << "\n"; - music_message << particleList[j].y[0] << " " << particleList[j].pt[0] << " " - << m; + music_message + << "Error: called out of range rapidity in rap_integrated_flow, " + << minrap << " < minimum " << testmin << "\n"; + music_message << particleList[j].y[0] << " " << particleList[j].pt[0] + << " " << m; music_message.flush("error"); exit(1); } double testmax; if (yflag) { if (DATA->pseudofreeze == 1) - testmax = Rap(particleList[j].y[neta-1], particleList[j].pt[0], m); + testmax = + Rap(particleList[j].y[neta - 1], particleList[j].pt[0], m); else - testmax = particleList[j].y[neta-1]; + testmax = particleList[j].y[neta - 1]; } else { if (DATA->pseudofreeze == 1) - testmax = particleList[j].y[neta-1]; + testmax = particleList[j].y[neta - 1]; else - testmax = Rap(particleList[j].y[neta-1], particleList[j].pt[0], m); + testmax = + Rap(particleList[j].y[neta - 1], particleList[j].pt[0], m); } if (maxrap > testmax) { - music_message << "Error: called out of range rapidity in rap_integrated_flow, " - << maxrap << " > maximum " << testmax; + music_message + << "Error: called out of range rapidity in rap_integrated_flow, " + << maxrap << " > maximum " << testmax; music_message.flush("error"); exit(1); } if (minrap > maxrap) { music_message << "Error in rap_integrated_flow: " - << "minrap must be less than or equal to maxrap"; + << "minrap must be less than or equal to maxrap"; music_message.flush("error"); exit(1); } - + // loop over pt for (int ipt = 0; ipt < npt; ipt++) { double pt = particleList[j].pt[ipt]; - + // Integrate over phi using trapezoid rule for (int iphi = 0; iphi < nphi; iphi++) { double ylist[etasize] = {0}; double etalist[etasize] = {0}; - + // Integrate over pseudorapidity using gsl double dndpt[etasize] = {0}; for (int ieta = 0; ieta < neta; ieta++) { @@ -1270,38 +1287,38 @@ void Freeze::rapidity_integrated_flow( double eta_local, y_local; if (DATA->pseudofreeze == 1) { - eta_local = rap_local; - etalist[ieta] = eta_local; - y_local = Rap(eta_local, pt, m); // get rapidity - ylist[ieta] = y_local; // get rapidity + eta_local = rap_local; + etalist[ieta] = eta_local; + y_local = Rap(eta_local, pt, m); // get rapidity + ylist[ieta] = y_local; // get rapidity } else { - y_local = rap_local; - ylist[ieta] = y_local; - // get Pseudo-rapidity - eta_local = PseudoRap(y_local, pt, m); - etalist[ieta] = eta_local; // get Pseudo-rapidity + y_local = rap_local; + ylist[ieta] = y_local; + // get Pseudo-rapidity + eta_local = PseudoRap(y_local, pt, m); + etalist[ieta] = eta_local; // get Pseudo-rapidity } if (yflag) { - // dN/(dydpTdphi) - dndpt[ieta] = ( - pt*particleList[j].dNdydptdphi[ieta][ipt][iphi]); + // dN/(dydpTdphi) + dndpt[ieta] = + (pt * particleList[j].dNdydptdphi[ieta][ipt][iphi]); } else { - // dN/(detadpTdphi) - dndpt[ieta] = ( - pt*dydeta(eta_local, pt, m) - *particleList[j].dNdydptdphi[ieta][ipt][iphi]); + // dN/(detadpTdphi) + dndpt[ieta] = + (pt * dydeta(eta_local, pt, m) + * particleList[j].dNdydptdphi[ieta][ipt][iphi]); } } - gsl_interp_accel *acc = gsl_interp_accel_alloc (); - gsl_spline *spline = gsl_spline_alloc (gsl_interp_linear, neta); + gsl_interp_accel *acc = gsl_interp_accel_alloc(); + gsl_spline *spline = gsl_spline_alloc(gsl_interp_linear, neta); if (yflag) { // rapidity - gsl_spline_init (spline, ylist, dndpt , neta); + gsl_spline_init(spline, ylist, dndpt, neta); } else { // pseudo-rapidity - gsl_spline_init (spline, etalist, dndpt , neta); + gsl_spline_init(spline, etalist, dndpt, neta); } - + double dNdp; if (minrap < maxrap) { // integrated from minrap to maxrap @@ -1310,64 +1327,63 @@ void Freeze::rapidity_integrated_flow( // value at minrap = maxrap dNdp = gsl_spline_eval(spline, maxrap, acc); } - - double phi = iphi*2*M_PI/nphi; + + double phi = iphi * 2 * M_PI / nphi; for (int i = 0; i < nharmonics; i++) { - intvn[ipt][i][0] += cos(i*phi)*dNdp*2*M_PI/nphi; - intvn[ipt][i][1] += sin(i*phi)*dNdp*2*M_PI/nphi; + intvn[ipt][i][0] += cos(i * phi) * dNdp * 2 * M_PI / nphi; + intvn[ipt][i][1] += sin(i * phi) * dNdp * 2 * M_PI / nphi; } - gsl_spline_free (spline); - gsl_interp_accel_free (acc); + gsl_spline_free(spline); + gsl_interp_accel_free(acc); } // phi loop - + for (int k = 0; k < 2; k++) { - vn[0][k][ipt] = intvn[ipt][0][k]; + vn[0][k][ipt] = intvn[ipt][0][k]; } - + for (int i = 1; i < nharmonics; i++) { - for(int k = 0; k < 2; k++) { - vn[i][k][ipt] = intvn[ipt][i][k]/intvn[ipt][0][0]; - } + for (int k = 0; k < 2; k++) { + vn[i][k][ipt] = intvn[ipt][i][k] / intvn[ipt][0][0]; + } } } // pt loop } - // calculates pt- and (pseudo)rapidity-integrated flow for a given range // in pt and eta or y // format is vn[n][i(real=0 or imaginary part=1)] // the rapidity integral is nested inside the phi integral // inside the pt integral -void Freeze::pt_and_rapidity_integrated_flow(InitData *DATA, int number, - double minpt, double maxpt, int yflag, double minrap, double maxrap, - double vn[nharmonics][2]) { - int j = partid[MHALF+number]; - int npt = particleList[j].npt; - +void Freeze::pt_and_rapidity_integrated_flow( + InitData *DATA, int number, double minpt, double maxpt, int yflag, + double minrap, double maxrap, double vn[nharmonics][2]) { + int j = partid[MHALF + number]; + int npt = particleList[j].npt; + if (minpt < particleList[j].pt[0]) { music_message << "Error: called out of range pt in " - << "pt_and_rapidity_integrated_flow, " - << minpt << " < minimum " << particleList[j].pt[0]; + << "pt_and_rapidity_integrated_flow, " << minpt + << " < minimum " << particleList[j].pt[0]; music_message.flush("error"); exit(1); } - if (maxpt > particleList[j].pt[npt-1]) { + if (maxpt > particleList[j].pt[npt - 1]) { music_message << "Error: called out of range pt in " - << "pt_and_rapidity_integrated_flow, " - << maxpt << " > maximum " << particleList[j].pt[npt-1]; + << "pt_and_rapidity_integrated_flow, " << maxpt + << " > maximum " << particleList[j].pt[npt - 1]; music_message.flush("error"); exit(1); } if (minpt > maxpt) { music_message << "Error in pt_and_rapidity_integrated_flow: " - << "minpt must be less than or equal to maxpt"; + << "minpt must be less than or equal to maxpt"; music_message.flush("error"); exit(1); } - + // do rapidity-integral first double vnpt[nharmonics][2][etasize] = {}; - rapidity_integrated_flow(DATA, number, yflag, minrap, maxrap, vnpt); + rapidity_integrated_flow(DATA, number, yflag, minrap, maxrap, vnpt); double dndpt[ptsize]; for (int ipt = 0; ipt < npt; ipt++) { dndpt[ipt] = vnpt[0][0][ipt]; @@ -1375,22 +1391,22 @@ void Freeze::pt_and_rapidity_integrated_flow(InitData *DATA, int number, for (int n = 0; n < nharmonics; n++) { double vncos[ptsize] = {0}; double vnsin[ptsize] = {0}; - for(int ipt = 0; ipt < npt; ipt++) { + for (int ipt = 0; ipt < npt; ipt++) { double weight; if (n != 0) weight = dndpt[ipt]; else weight = 1; - vncos[ipt] = vnpt[n][0][ipt]*weight; - vnsin[ipt] = vnpt[n][1][ipt]*weight; + vncos[ipt] = vnpt[n][0][ipt] * weight; + vnsin[ipt] = vnpt[n][1][ipt] * weight; } - gsl_interp_accel *cosacc = gsl_interp_accel_alloc (); - gsl_spline *cosspline = gsl_spline_alloc (gsl_interp_linear, npt); - gsl_spline_init (cosspline, particleList[j].pt ,vncos , npt); + gsl_interp_accel *cosacc = gsl_interp_accel_alloc(); + gsl_spline *cosspline = gsl_spline_alloc(gsl_interp_linear, npt); + gsl_spline_init(cosspline, particleList[j].pt, vncos, npt); - gsl_interp_accel *sinacc = gsl_interp_accel_alloc (); - gsl_spline *sinspline = gsl_spline_alloc (gsl_interp_linear, npt); - gsl_spline_init (sinspline, particleList[j].pt ,vnsin , npt); + gsl_interp_accel *sinacc = gsl_interp_accel_alloc(); + gsl_spline *sinspline = gsl_spline_alloc(gsl_interp_linear, npt); + gsl_spline_init(sinspline, particleList[j].pt, vnsin, npt); if (fabs(minpt - maxpt) > 1e-6) { vn[n][0] = gsl_spline_eval_integ(cosspline, minpt, maxpt, cosacc); @@ -1399,95 +1415,90 @@ void Freeze::pt_and_rapidity_integrated_flow(InitData *DATA, int number, vn[n][0] = gsl_spline_eval(cosspline, minpt, cosacc); vn[n][1] = gsl_spline_eval(sinspline, minpt, sinacc); } - + if (n != 0) { for (int i = 0; i < 2; i++) { vn[n][i] /= vn[0][0]; } } - + // clean up - gsl_spline_free (cosspline); - gsl_interp_accel_free (cosacc); - gsl_spline_free (sinspline); - gsl_interp_accel_free (sinacc); + gsl_spline_free(cosspline); + gsl_interp_accel_free(cosacc); + gsl_spline_free(sinspline); + gsl_interp_accel_free(sinacc); } } - // Output yield dN/ptdydpt and v_n at eta=0 as a function of pT void Freeze::OutputDifferentialFlowAtMidrapidity( - InitData *DATA, int number, int full) { + InitData *DATA, int number, int full) { // Define index j used in particleList[j] - int j = partid[MHALF+number]; + int j = partid[MHALF + number]; int npt = particleList[j].npt; music_message << "Calculating flow at midrapidity for particle " << number; music_message.flush("info"); - //Set output file name + // Set output file name string fname; stringstream tmpStr; fname = "./outputs/"; - if (full) - fname += "F"; + if (full) fname += "F"; fname += "vnpt_y-"; tmpStr << number; fname += tmpStr.str(); - fname += ".dat"; - + fname += ".dat"; + string fname2; stringstream tmpStr2; fname2 = "./outputs/"; - if (full) - fname2 += "F"; + if (full) fname2 += "F"; fname2 += "vnpt_eta-"; tmpStr2 << number; fname2 += tmpStr.str(); - fname2 += ".dat"; - + fname2 += ".dat"; + // Open output file for vn ofstream outfilevn; outfilevn.open(fname.c_str()); - + ofstream outfilevn2; outfilevn2.open(fname2.c_str()); - + outfilevn << "#pt dN/ptdYdptdphi v1cos v1sin v2cos v2sin " << "v3cos v3sin v4cos v4sin v5cos v5sin v6cos v6sin " << "v7cos v7sin" << endl; - + outfilevn2 << "#pt dN/ptdYdptdphi v1cos v1sin v2cos v2sin " << "v3cos v3sin v4cos v4sin v5cos v5sin v6cos v6sin " << "v7cos v7sin" << endl; - + double vn[nharmonics][2]; double eta = 0.0; // Loop over pT for (int ipt = 0; ipt < npt; ipt++) { - double pt=particleList[j].pt[ipt]; - pt_and_rapidity_integrated_flow(DATA, number, pt, pt, 1, - eta, eta, vn); // in rapidity + double pt = particleList[j].pt[ipt]; + pt_and_rapidity_integrated_flow( + DATA, number, pt, pt, 1, eta, eta, vn); // in rapidity - //Output result + // Output result outfilevn << pt; - outfilevn << " " << vn[0][0]/pt/(2*M_PI); - for (int i = 1;idNdyptdpt_y_min; double y_max = DATA->dNdyptdpt_y_max; double eta_min = DATA->dNdyptdpt_eta_min; double eta_max = DATA->dNdyptdpt_eta_max; - + music_message << "Calculating flow near midrapidity for particle " << number; music_message.flush("info"); - - //Set output file name + + // Set output file name stringstream fname; if (full) { - fname << "./outputs/Fvnpt-" << number << "_y_" - << y_min << "_" << y_max << ".dat"; + fname << "./outputs/Fvnpt-" << number << "_y_" << y_min << "_" << y_max + << ".dat"; } else { - fname << "./outputs/vnpt-" << number << "_y_" - << y_min << "_" << y_max << ".dat"; + fname << "./outputs/vnpt-" << number << "_y_" << y_min << "_" << y_max + << ".dat"; } - + stringstream fname2; if (full) { - fname2 << "./outputs/Fvnpt-" << number << "_eta_" - << eta_min << "_" << eta_max << ".dat"; + fname2 << "./outputs/Fvnpt-" << number << "_eta_" << eta_min << "_" + << eta_max << ".dat"; } else { - fname2 << "./outputs/vnpt-" << number << "_eta_" - << eta_min << "_" << eta_max << ".dat"; + fname2 << "./outputs/vnpt-" << number << "_eta_" << eta_min << "_" + << eta_max << ".dat"; } - - //Open output file for vn + + // Open output file for vn ofstream outfilevn; outfilevn.open(fname.str().c_str()); - + ofstream outfilevn2; outfilevn2.open(fname2.str().c_str()); - //Set the format of the output + // Set the format of the output outfilevn << "#pt dN/ptdYdptdphi v1cos v1sin v2cos v2sin " << "v3cos v3sin v4cos v4sin v5cos v5sin v6cos v6sin " - << "v7cos v7sin" << endl; // in rapidity - + << "v7cos v7sin" << endl; // in rapidity + outfilevn2 << "#pt dN/ptdYdptdphi v1cos v1sin v2cos v2sin " << "v3cos v3sin v4cos v4sin v5cos v5sin v6cos v6sin " << "v7cos v7sin" << endl; // in pseudo-rapidity double vn[nharmonics][2]; - + // Loop over pT - for (int ipt = 0;ipt < npt; ipt++) { + for (int ipt = 0; ipt < npt; ipt++) { double pt = particleList[j].pt[ipt]; - - pt_and_rapidity_integrated_flow(DATA, number, pt, pt, 1, - y_min, y_max, vn); // rapidity + + pt_and_rapidity_integrated_flow( + DATA, number, pt, pt, 1, y_min, y_max, vn); // rapidity // Output result outfilevn << pt; - outfilevn << " " << vn[0][0]/pt/(y_max - y_min)/(2*M_PI); - for (int i = 1;idNdy_y_min; double y_max = DATA->dNdy_y_max; double eta_min = DATA->dNdy_eta_min; double eta_max = DATA->dNdy_eta_max; int nrap = DATA->dNdy_nrap; - double dy = (y_max - y_min)/(nrap - 1); - double deta = (eta_max - eta_min)/(nrap - 1); + double dy = (y_max - y_min) / (nrap - 1); + double deta = (eta_max - eta_min) / (nrap - 1); // Loop over eta or y for (int irap = 0; irap < nrap; irap++) { - double y_local = y_min + irap*dy; - double eta_local = eta_min + irap*deta; + double y_local = y_min + irap * dy; + double eta_local = eta_min + irap * deta; // rapidity - pt_and_rapidity_integrated_flow(DATA, number, pT_min, pT_max, 1, - y_local, y_local, vn); - + pt_and_rapidity_integrated_flow( + DATA, number, pT_min, pT_max, 1, y_local, y_local, vn); + // Output result outfilevn << std::scientific << std::setprecision(8) << y_local; for (int i = 0; i < nharmonics; i++) { @@ -1646,11 +1655,11 @@ void Freeze::OutputIntegratedFlow_vs_y( } } outfilevn << endl; - + // pseudo-rapidity - pt_and_rapidity_integrated_flow(DATA, number, pT_min, pT_max, 0, - eta_local, eta_local, vn); - + pt_and_rapidity_integrated_flow( + DATA, number, pT_min, pT_max, 0, eta_local, eta_local, vn); + outfilevn2 << std::scientific << std::setprecision(8) << eta_local; for (int i = 0; i < nharmonics; i++) { for (int k = 0; k < 2; k++) { @@ -1659,7 +1668,7 @@ void Freeze::OutputIntegratedFlow_vs_y( } outfilevn2 << endl; } - + // Close file outfilevn.close(); outfilevn2.close(); @@ -1667,35 +1676,35 @@ void Freeze::OutputIntegratedFlow_vs_y( // Output yield dN/deta and v_n integrated over pT and rapidity void Freeze::Output_charged_IntegratedFlow( - InitData *DATA, double pT_min, double pT_max, - double eta_min, double eta_max) { + InitData *DATA, double pT_min, double pT_max, double eta_min, + double eta_max) { music_message << "Calculating charged hadron flow integrated between " - << pT_min << " < p_T < " << pT_max << " and " - << eta_min << " < eta < " << eta_max << "..."; + << pT_min << " < p_T < " << pT_max << " and " << eta_min + << " < eta < " << eta_max << "..."; music_message.flush("info"); - + // Set output file name stringstream fname; - fname << "./outputs/vnch_pT_" << pT_min << "_" << pT_max - << "_eta_" << eta_min << "_" << eta_max << ".dat"; - + fname << "./outputs/vnch_pT_" << pT_min << "_" << pT_max << "_eta_" + << eta_min << "_" << eta_max << ".dat"; + // Open output file for vn ofstream outfile; outfile.open(fname.str().c_str()); - + // header of the files outfile << "#dN/deta v1cos v1sin v2cos v2sin v3cos v3sin " << "v4cos v4sin v5cos v5sin v6cos v6sin v7cos v7sin\n"; - + double dNch = get_Nch(DATA, pT_min, pT_max, 0, eta_min, eta_max); - outfile << std::scientific << std::setw(18) << std::setprecision(8) - << dNch << " "; + outfile << std::scientific << std::setw(18) << std::setprecision(8) << dNch + << " "; int max_flow_order = 7; for (int iorder = 1; iorder < max_flow_order; iorder++) { - double *vn_temp = new double [2]; + double *vn_temp = new double[2]; get_vn_ch(DATA, pT_min, pT_max, 0, eta_min, eta_max, iorder, vn_temp); outfile << vn_temp[0] << " " << vn_temp[1] << " "; - delete [] vn_temp; + delete[] vn_temp; } outfile << endl; outfile.close(); @@ -1703,33 +1712,33 @@ void Freeze::Output_charged_IntegratedFlow( // Output pT and phi integrated charged hadron spectra as a function of eta void Freeze::Output_charged_hadrons_eta_differential_spectra( - InitData *DATA, int full, double pT_min, double pT_max) { + InitData *DATA, int full, double pT_min, double pT_max) { music_message << "Collecting charged hadrons dN/deta and vn vs eta..."; music_message.flush("info"); stringstream tmpStr; tmpStr << "./outputs/vnchdeta_pT_" << pT_min << "_" << pT_max << ".dat"; - + ofstream outfile; outfile.open(tmpStr.str().c_str(), std::ios::trunc); - + outfile << "#eta dNch/deta v1cos v1sin v2cos v2sin v3cos v3sin " << "v4cos v4sin v5cos v5sin v6cos v6sin v7cos v7sin\n"; double eta_min = DATA->dNdy_eta_min; double eta_max = DATA->dNdy_eta_max; int nrap = DATA->dNdy_nrap; - double deta = (eta_max - eta_min)/(nrap - 1); + double deta = (eta_max - eta_min) / (nrap - 1); int max_flow_order = 7; for (int ieta = 0; ieta < nrap; ieta++) { - double eta_local = eta_min + ieta*deta; + double eta_local = eta_min + ieta * deta; double dNch = get_Nch(DATA, pT_min, pT_max, 0, eta_local, eta_local); - outfile << eta_local << " " << dNch << " "; + outfile << eta_local << " " << dNch << " "; for (int iorder = 1; iorder < max_flow_order; iorder++) { - double *vn_temp = new double [2]; - get_vn_ch(DATA, pT_min, pT_max, 0, eta_local, eta_local, - iorder, vn_temp); + double *vn_temp = new double[2]; + get_vn_ch( + DATA, pT_min, pT_max, 0, eta_local, eta_local, iorder, vn_temp); outfile << vn_temp[0] << " " << vn_temp[1] << " "; - delete [] vn_temp; + delete[] vn_temp; } outfile << endl; } @@ -1739,12 +1748,13 @@ void Freeze::Output_charged_hadrons_eta_differential_spectra( // output eta and phi integerated charged hadron spectra and vn as // functions of pT void Freeze::Output_charged_hadrons_pT_differential_spectra( - InitData *DATA, int full, double eta_min, double eta_max) { + InitData *DATA, int full, double eta_min, double eta_max) { double pT_min = particleList[1].pt[0]; - double pT_max = particleList[1].pt[particleList[1].npt-1]; + double pT_max = particleList[1].pt[particleList[1].npt - 1]; int npT = 30; - double dpT = (pT_max - pT_min)/(npT - 1); - music_message << "Collecting charged hadrons dN/detapTdpT and vn(pT) vs pT..."; + double dpT = (pT_max - pT_min) / (npT - 1); + music_message + << "Collecting charged hadrons dN/detapTdpT and vn(pT) vs pT..."; music_message.flush("info"); stringstream tmpStr; @@ -1758,15 +1768,15 @@ void Freeze::Output_charged_hadrons_pT_differential_spectra( int max_flow_order = 7; for (int ipT = 0; ipT < npT; ipT++) { - double pT_local = pT_min + ipT*dpT; + double pT_local = pT_min + ipT * dpT; double dNch = get_Nch(DATA, pT_local, pT_local, 0, eta_min, eta_max); - outfile << pT_local << " " << dNch/pT_local/(2*M_PI) << " "; + outfile << pT_local << " " << dNch / pT_local / (2 * M_PI) << " "; for (int iorder = 1; iorder < max_flow_order; iorder++) { - double *vn_temp = new double [2]; - get_vn_ch(DATA, pT_local, pT_local, 0, eta_min, eta_max, - iorder, vn_temp); + double *vn_temp = new double[2]; + get_vn_ch( + DATA, pT_local, pT_local, 0, eta_min, eta_max, iorder, vn_temp); outfile << vn_temp[0] << " " << vn_temp[1] << " "; - delete [] vn_temp; + delete[] vn_temp; } outfile << endl; } @@ -1774,116 +1784,116 @@ void Freeze::Output_charged_hadrons_pT_differential_spectra( } // Return yield in specified range of phase space -double Freeze::get_N(InitData *DATA, int number, double minpt, double maxpt, - int yflag, double minrap, double maxrap) { +double Freeze::get_N( + InitData *DATA, int number, double minpt, double maxpt, int yflag, + double minrap, double maxrap) { double vn[nharmonics][2]; - pt_and_rapidity_integrated_flow(DATA, number, minpt, maxpt, yflag, - minrap, maxrap, vn); - return(vn[0][0]); + pt_and_rapidity_integrated_flow( + DATA, number, minpt, maxpt, yflag, minrap, maxrap, vn); + return (vn[0][0]); } // Return charged hadron yield in specified range of phase space -// You'll almost certainly want to set yflat=0 to calculate +// You'll almost certainly want to set yflat=0 to calculate // over a fixed range in eta // if minrap==maxrap, returns dN/eta. If minpt==maxpt, dN/dpt. // If both, dN/dpt/deta. Otherwise, total yield N -double Freeze::get_Nch(InitData *DATA, double minpt, double maxpt, int yflag, - double minrap, double maxrap) { +double Freeze::get_Nch( + InitData *DATA, double minpt, double maxpt, int yflag, double minrap, + double maxrap) { double N = 0; for (int k = 0; k < charged_hadron_list_length; k++) { int number = charged_hadron_list[k]; - N+= get_N(DATA, number, minpt, maxpt, yflag, minrap, maxrap); + N += get_N(DATA, number, minpt, maxpt, yflag, minrap, maxrap); } return N; } - // Return charged hadron vn for specified range of phase space -double Freeze::get_vn_ch(InitData *DATA, double minpt, double maxpt, int yflag, - double minrap, double maxrap, int n, - double* vn_results) { +double Freeze::get_vn_ch( + InitData *DATA, double minpt, double maxpt, int yflag, double minrap, + double maxrap, int n, double *vn_results) { if (n > nharmonics - 1) { music_message << "harmonic (" << n << ") too large. " - << "Must increase nharmonics in freeze_pseudo.cpp"; + << "Must increase nharmonics in freeze_pseudo.cpp"; music_message.flush("error"); exit(1); } double numr = 0.; // real part (x projection, \sum N*v_n*cos(Psi_n)) double numi = 0.; // imaginary part (y projection, \sum N*v_n*sin(Psi_n)) double den = 0.; // denominator (\sum N) - for (int k=0; k< charged_hadron_list_length; k++) { + for (int k = 0; k < charged_hadron_list_length; k++) { int number = charged_hadron_list[k]; double vn[nharmonics][2]; - pt_and_rapidity_integrated_flow(DATA, number, minpt, maxpt, yflag, - minrap, maxrap, vn); - numr+= vn[0][0]*vn[n][0]; - numi+= vn[0][0]*vn[n][1]; - den+= vn[0][0]; - } - vn_results[0] = numr/den; - vn_results[1] = numi/den; - return sqrt(numr*numr+numi*numi)/den; + pt_and_rapidity_integrated_flow( + DATA, number, minpt, maxpt, yflag, minrap, maxrap, vn); + numr += vn[0][0] * vn[n][0]; + numi += vn[0][0] * vn[n][1]; + den += vn[0][0]; + } + vn_results[0] = numr / den; + vn_results[1] = numi / den; + return sqrt(numr * numr + numi * numi) / den; } - // Return in specified range of phase space -double Freeze::get_meanpt(InitData *DATA, int number, - double minpt, double maxpt, - int yflag, double minrap, double maxrap) { - int j = partid[MHALF+number]; +double Freeze::get_meanpt( + InitData *DATA, int number, double minpt, double maxpt, int yflag, + double minrap, double maxrap) { + int j = partid[MHALF + number]; int npt = particleList[j].npt; if (minpt < particleList[j].pt[0]) { music_message << "Error: called out of range pt in get_meanpt, " - << minpt << " < minimum " << particleList[j].pt[0]; + << minpt << " < minimum " << particleList[j].pt[0]; music_message.flush("error"); exit(1); } - if (maxpt > particleList[j].pt[npt-1]) { + if (maxpt > particleList[j].pt[npt - 1]) { music_message << "Error: called out of range pt in get_meanpt, " - << maxpt << " > maximum " << particleList[j].pt[npt-1]; + << maxpt << " > maximum " << particleList[j].pt[npt - 1]; music_message.flush("error"); exit(1); } if (minpt > maxpt) { music_message << "Error in get_meanpt: " - << "minpt must be less than or equal to maxpt"; + << "minpt must be less than or equal to maxpt"; music_message.flush("error"); exit(1); } - + double ptdndpt[ptsize]; double dndpt[ptsize]; for (int ipt = 0; ipt < npt; ipt++) { double pt = particleList[j].pt[ipt]; dndpt[ipt] = get_N(DATA, number, pt, pt, yflag, minrap, maxrap); - ptdndpt[ipt] = pt*dndpt[ipt]; - } - gsl_interp_accel *numacc = gsl_interp_accel_alloc (); - gsl_spline *numspline = gsl_spline_alloc (gsl_interp_linear, npt); - gsl_spline_init (numspline, particleList[j].pt ,ptdndpt , npt); - - gsl_interp_accel *denacc = gsl_interp_accel_alloc (); - gsl_spline *denspline = gsl_spline_alloc (gsl_interp_linear, npt); - gsl_spline_init (denspline, particleList[j].pt ,dndpt , npt); - + ptdndpt[ipt] = pt * dndpt[ipt]; + } + gsl_interp_accel *numacc = gsl_interp_accel_alloc(); + gsl_spline *numspline = gsl_spline_alloc(gsl_interp_linear, npt); + gsl_spline_init(numspline, particleList[j].pt, ptdndpt, npt); + + gsl_interp_accel *denacc = gsl_interp_accel_alloc(); + gsl_spline *denspline = gsl_spline_alloc(gsl_interp_linear, npt); + gsl_spline_init(denspline, particleList[j].pt, dndpt, npt); + double num = gsl_spline_eval_integ(numspline, minpt, maxpt, numacc); double den = gsl_spline_eval_integ(denspline, minpt, maxpt, denacc); - - gsl_spline_free (numspline); - gsl_interp_accel_free (numacc); - gsl_spline_free (denspline); - gsl_interp_accel_free (denacc); - - return num/den; -} + gsl_spline_free(numspline); + gsl_interp_accel_free(numacc); + gsl_spline_free(denspline); + gsl_interp_accel_free(denacc); + + return num / den; +} // Return charged hadron Psi_n for specified range of phase space -double Freeze::get_psi_n_ch(InitData *DATA, double minpt, double maxpt, - int yflag, double minrap, double maxrap, int n) { - if (n > nharmonics-1) { +double Freeze::get_psi_n_ch( + InitData *DATA, double minpt, double maxpt, int yflag, double minrap, + double maxrap, int n) { + if (n > nharmonics - 1) { music_message << "harmonic (" << n << ") too large. " - << "Must increase nharmonics in freeze_pseudo.cpp"; + << "Must increase nharmonics in freeze_pseudo.cpp"; music_message.flush("error"); exit(1); } @@ -1892,75 +1902,74 @@ double Freeze::get_psi_n_ch(InitData *DATA, double minpt, double maxpt, for (int k = 0; k < charged_hadron_list_length; k++) { int number = charged_hadron_list[k]; double vn[nharmonics][2]; - pt_and_rapidity_integrated_flow(DATA, number, minpt, maxpt, - yflag, minrap, maxrap, vn); - numr += vn[0][0]*vn[n][0]; - numi += vn[0][0]*vn[n][1]; + pt_and_rapidity_integrated_flow( + DATA, number, minpt, maxpt, yflag, minrap, maxrap, vn); + numr += vn[0][0] * vn[n][0]; + numi += vn[0][0] * vn[n][1]; } - return atan2(numi, numr)/n; + return atan2(numi, numr) / n; } // Return v_n for specified range of phase space -double Freeze::get_vn(InitData *DATA, int number, double minpt, double maxpt, - int yflag, double minrap, double maxrap, int n) { +double Freeze::get_vn( + InitData *DATA, int number, double minpt, double maxpt, int yflag, + double minrap, double maxrap, int n) { if (n > nharmonics - 1) { music_message << "harmonic (" << n << ") too large. " - << "Must increase nharmonics in freeze_pseudo.cpp"; + << "Must increase nharmonics in freeze_pseudo.cpp"; music_message.flush("error"); exit(1); } double vn[nharmonics][2]; - pt_and_rapidity_integrated_flow(DATA, number, minpt, maxpt, - yflag, minrap, maxrap, vn); - return sqrt(vn[n][0]*vn[n][0] + vn[n][1]*vn[n][1]); + pt_and_rapidity_integrated_flow( + DATA, number, minpt, maxpt, yflag, minrap, maxrap, vn); + return sqrt(vn[n][0] * vn[n][0] + vn[n][1] * vn[n][1]); } // Return Psi_n for specified range of phase space -double Freeze::get_psi_n(InitData *DATA, int number, - double minpt, double maxpt, - int yflag, double minrap, double maxrap, int n) { +double Freeze::get_psi_n( + InitData *DATA, int number, double minpt, double maxpt, int yflag, + double minrap, double maxrap, int n) { if (n > nharmonics - 1) { music_message << "harmonic (" << n << ") too large. " - << "Must increase nharmonics in freeze_pseudo.cpp"; + << "Must increase nharmonics in freeze_pseudo.cpp"; music_message.flush("error"); exit(1); } double vn[nharmonics][2]; - pt_and_rapidity_integrated_flow(DATA, number, minpt, maxpt, - yflag, minrap, maxrap, vn); - return atan2(vn[n][1],vn[n][0])/n; + pt_and_rapidity_integrated_flow( + DATA, number, minpt, maxpt, yflag, minrap, maxrap, vn); + return atan2(vn[n][1], vn[n][0]) / n; } - // Calculates v1 and psi_1 with pt-dependent weight (pt - /) // in specified range of phase space // ch == 0 calculates for particle "number", // while ch > 0 calculates for all charged hadrons -void Freeze::weighted_v1(InitData *DATA, int number, - double minpt, double maxpt, - int yflag, double minrap, double maxrap, - double vn[2], int ch) { - int j = partid[MHALF+number]; +void Freeze::weighted_v1( + InitData *DATA, int number, double minpt, double maxpt, int yflag, + double minrap, double maxrap, double vn[2], int ch) { + int j = partid[MHALF + number]; int npt = particleList[j].npt; if (minpt < particleList[j].pt[0]) { music_message << "Error: called out of range pt in get_meanpt, " - << minpt << " < minimum " << particleList[j].pt[0]; + << minpt << " < minimum " << particleList[j].pt[0]; music_message.flush("error"); exit(1); } - if (maxpt > particleList[j].pt[npt-1]) { + if (maxpt > particleList[j].pt[npt - 1]) { music_message << "Error: called out of range pt in get_meanpt, " - << maxpt << " > maximum " << particleList[j].pt[npt-1]; + << maxpt << " > maximum " << particleList[j].pt[npt - 1]; music_message.flush("error"); exit(1); } if (minpt > maxpt) { music_message << "Error in get_meanpt: " - << "minpt must be less than or equal to maxpt"; + << "minpt must be less than or equal to maxpt"; music_message.flush("error"); exit(1); } - + // start by finding and double ptptdndpt[ptsize]; double ptdndpt[ptsize]; @@ -1972,47 +1981,47 @@ void Freeze::weighted_v1(InitData *DATA, int number, } else { dndpt[ipt] = get_N(DATA, number, pt, pt, yflag, minrap, maxrap); } - ptdndpt[ipt] = pt*dndpt[ipt]; - ptptdndpt[ipt] = pt*pt*dndpt[ipt]; - } - - gsl_interp_accel *numacc = gsl_interp_accel_alloc (); - gsl_spline *numspline = gsl_spline_alloc (gsl_interp_linear, npt); - gsl_spline_init (numspline, particleList[j].pt ,ptdndpt , npt); - - gsl_interp_accel *num2acc = gsl_interp_accel_alloc (); - gsl_spline *num2spline = gsl_spline_alloc (gsl_interp_linear, npt); - gsl_spline_init (num2spline, particleList[j].pt, ptptdndpt , npt); - - gsl_interp_accel *denacc = gsl_interp_accel_alloc (); - gsl_spline *denspline = gsl_spline_alloc (gsl_interp_linear, npt); - gsl_spline_init (denspline, particleList[j].pt ,dndpt , npt); - + ptdndpt[ipt] = pt * dndpt[ipt]; + ptptdndpt[ipt] = pt * pt * dndpt[ipt]; + } + + gsl_interp_accel *numacc = gsl_interp_accel_alloc(); + gsl_spline *numspline = gsl_spline_alloc(gsl_interp_linear, npt); + gsl_spline_init(numspline, particleList[j].pt, ptdndpt, npt); + + gsl_interp_accel *num2acc = gsl_interp_accel_alloc(); + gsl_spline *num2spline = gsl_spline_alloc(gsl_interp_linear, npt); + gsl_spline_init(num2spline, particleList[j].pt, ptptdndpt, npt); + + gsl_interp_accel *denacc = gsl_interp_accel_alloc(); + gsl_spline *denspline = gsl_spline_alloc(gsl_interp_linear, npt); + gsl_spline_init(denspline, particleList[j].pt, dndpt, npt); + double num2 = gsl_spline_eval_integ(num2spline, minpt, maxpt, num2acc); double num = gsl_spline_eval_integ(numspline, minpt, maxpt, numacc); double den = gsl_spline_eval_integ(denspline, minpt, maxpt, denacc); - - gsl_spline_free (numspline); - gsl_interp_accel_free (numacc); - gsl_spline_free (num2spline); - gsl_interp_accel_free (num2acc); - gsl_spline_free (denspline); - gsl_interp_accel_free (denacc); - - double meanpt = num/den; - double meanpt2 = num2/den; - + + gsl_spline_free(numspline); + gsl_interp_accel_free(numacc); + gsl_spline_free(num2spline); + gsl_interp_accel_free(num2acc); + gsl_spline_free(denspline); + gsl_interp_accel_free(denacc); + + double meanpt = num / den; + double meanpt2 = num2 / den; + // next calculate integrated v1 and psi1 with weight pt - / double v1cos[ptsize]; double v1sin[ptsize]; double v1den[ptsize]; for (int ipt = 0; ipt < npt; ipt++) { double pt = particleList[j].pt[ipt]; - double weight = (pt - meanpt2/meanpt)*dndpt[ipt]; - + double weight = (pt - meanpt2 / meanpt) * dndpt[ipt]; + double v1; double psi1; - double * vntemp = new double [2]; + double *vntemp = new double[2]; if (ch) { v1 = get_vn_ch(DATA, pt, pt, yflag, minrap, maxrap, 1, vntemp); } else { @@ -2023,45 +2032,42 @@ void Freeze::weighted_v1(InitData *DATA, int number, } else { psi1 = get_psi_n(DATA, number, pt, pt, yflag, minrap, maxrap, 1); } - v1cos[ipt] = weight*v1*cos(psi1); - v1sin[ipt] = weight*v1*sin(psi1); + v1cos[ipt] = weight * v1 * cos(psi1); + v1sin[ipt] = weight * v1 * sin(psi1); v1den[ipt] = weight; - delete [] vntemp; + delete[] vntemp; } - - gsl_spline_init (numspline, particleList[j].pt ,v1cos , npt); - gsl_spline_init (num2spline, particleList[j].pt, v1sin , npt); - gsl_spline_init (denspline, particleList[j].pt ,v1den , npt); - + + gsl_spline_init(numspline, particleList[j].pt, v1cos, npt); + gsl_spline_init(num2spline, particleList[j].pt, v1sin, npt); + gsl_spline_init(denspline, particleList[j].pt, v1den, npt); + num2 = gsl_spline_eval_integ(num2spline, minpt, maxpt, numacc); num = gsl_spline_eval_integ(numspline, minpt, maxpt, numacc); den = gsl_spline_eval_integ(denspline, minpt, maxpt, denacc); - - gsl_spline_free (numspline); - gsl_interp_accel_free (numacc); - gsl_spline_free (num2spline); - gsl_interp_accel_free (num2acc); - gsl_spline_free (denspline); - gsl_interp_accel_free (denacc); - - vn[0] = sqrt(num*num+num2*num2)/den; - vn[1] = atan2(num2,num); -} + gsl_spline_free(numspline); + gsl_interp_accel_free(numacc); + gsl_spline_free(num2spline); + gsl_interp_accel_free(num2acc); + gsl_spline_free(denspline); + gsl_interp_accel_free(denacc); + + vn[0] = sqrt(num * num + num2 * num2) / den; + vn[1] = atan2(num2, num); +} -double Freeze::get_weighted_v1(InitData *DATA, int number, - double minpt, double maxpt, - int yflag, double minrap, double maxrap, - int ch) { +double Freeze::get_weighted_v1( + InitData *DATA, int number, double minpt, double maxpt, int yflag, + double minrap, double maxrap, int ch) { double vn[2]; weighted_v1(DATA, number, minpt, maxpt, yflag, minrap, maxrap, vn, ch); return vn[0]; } -double Freeze::get_weighted_psi1(InitData *DATA, int number, - double minpt, double maxpt, - int yflag, double minrap, double maxrap, - int ch) { +double Freeze::get_weighted_psi1( + InitData *DATA, int number, double minpt, double maxpt, int yflag, + double minrap, double maxrap, int ch) { double vn[2]; weighted_v1(DATA, number, minpt, maxpt, yflag, minrap, maxrap, vn, ch); return vn[1]; @@ -2075,9 +2081,9 @@ void Freeze::load_deltaf_qmu_coeff_table(string filename) { delta_qmu_coeff_table_mu0 = 0.0; delta_qmu_coeff_table_dT = 0.001; delta_qmu_coeff_table_dmu = 0.007892; - deltaf_qmu_coeff_tb = new double* [deltaf_qmu_coeff_table_length_T]; + deltaf_qmu_coeff_tb = new double *[deltaf_qmu_coeff_table_length_T]; for (int i = 0; i < deltaf_qmu_coeff_table_length_T; i++) { - deltaf_qmu_coeff_tb[i] = new double [deltaf_qmu_coeff_table_length_mu]; + deltaf_qmu_coeff_tb[i] = new double[deltaf_qmu_coeff_table_length_mu]; } double dummy; @@ -2098,255 +2104,257 @@ void Freeze::load_deltaf_qmu_coeff_table_14mom(string filename) { delta_coeff_table_14mom_dT = 0.001; delta_coeff_table_14mom_dmu = 0.005; - deltaf_coeff_tb_14mom_DPi = new double* [deltaf_coeff_table_14mom_length_T]; - deltaf_coeff_tb_14mom_BPi = new double* [deltaf_coeff_table_14mom_length_T]; - deltaf_coeff_tb_14mom_BPitilde = - new double* [deltaf_coeff_table_14mom_length_T]; - deltaf_coeff_tb_14mom_DV = new double* [deltaf_coeff_table_14mom_length_T]; - deltaf_coeff_tb_14mom_BV = new double* [deltaf_coeff_table_14mom_length_T]; + deltaf_coeff_tb_14mom_DPi = new double *[deltaf_coeff_table_14mom_length_T]; + deltaf_coeff_tb_14mom_BPi = new double *[deltaf_coeff_table_14mom_length_T]; + deltaf_coeff_tb_14mom_BPitilde = + new double *[deltaf_coeff_table_14mom_length_T]; + deltaf_coeff_tb_14mom_DV = new double *[deltaf_coeff_table_14mom_length_T]; + deltaf_coeff_tb_14mom_BV = new double *[deltaf_coeff_table_14mom_length_T]; deltaf_coeff_tb_14mom_Bpi_shear = - new double* [deltaf_coeff_table_14mom_length_T]; + new double *[deltaf_coeff_table_14mom_length_T]; for (int i = 0; i < deltaf_coeff_table_14mom_length_T; i++) { deltaf_coeff_tb_14mom_DPi[i] = - new double[deltaf_coeff_table_14mom_length_mu]; + new double[deltaf_coeff_table_14mom_length_mu]; deltaf_coeff_tb_14mom_BPi[i] = - new double[deltaf_coeff_table_14mom_length_mu]; + new double[deltaf_coeff_table_14mom_length_mu]; deltaf_coeff_tb_14mom_BPitilde[i] = - new double[deltaf_coeff_table_14mom_length_mu]; + new double[deltaf_coeff_table_14mom_length_mu]; deltaf_coeff_tb_14mom_DV[i] = - new double[deltaf_coeff_table_14mom_length_mu]; + new double[deltaf_coeff_table_14mom_length_mu]; deltaf_coeff_tb_14mom_BV[i] = - new double[deltaf_coeff_table_14mom_length_mu]; + new double[deltaf_coeff_table_14mom_length_mu]; deltaf_coeff_tb_14mom_Bpi_shear[i] = - new double[deltaf_coeff_table_14mom_length_mu]; + new double[deltaf_coeff_table_14mom_length_mu]; } double dummy; for (int i = 0; i < deltaf_coeff_table_14mom_length_T; i++) { for (int j = 0; j < deltaf_coeff_table_14mom_length_mu; j++) { table >> dummy >> dummy >> deltaf_coeff_tb_14mom_DPi[i][j] - >> deltaf_coeff_tb_14mom_BPi[i][j] - >> deltaf_coeff_tb_14mom_BPitilde[i][j] - >> deltaf_coeff_tb_14mom_DV[i][j] - >> deltaf_coeff_tb_14mom_BV[i][j] - >> deltaf_coeff_tb_14mom_Bpi_shear[i][j]; + >> deltaf_coeff_tb_14mom_BPi[i][j] + >> deltaf_coeff_tb_14mom_BPitilde[i][j] + >> deltaf_coeff_tb_14mom_DV[i][j] + >> deltaf_coeff_tb_14mom_BV[i][j] + >> deltaf_coeff_tb_14mom_Bpi_shear[i][j]; } } table.close(); // convert units - double hbarc3 = hbarc*hbarc*hbarc; - double hbarc4 = hbarc3*hbarc; + double hbarc3 = hbarc * hbarc * hbarc; + double hbarc4 = hbarc3 * hbarc; for (int i = 0; i < deltaf_coeff_table_14mom_length_T; i++) { for (int j = 0; j < deltaf_coeff_table_14mom_length_mu; j++) { - deltaf_coeff_tb_14mom_DPi[i][j] *= hbarc4; // fm^4/GeV - deltaf_coeff_tb_14mom_BPi[i][j] *= hbarc4; // fm^4/(GeV^2) - deltaf_coeff_tb_14mom_BPitilde[i][j] *= hbarc4; // fm^4/(GeV^2) - deltaf_coeff_tb_14mom_DV[i][j] *= hbarc3; // fm^3/GeV - deltaf_coeff_tb_14mom_BV[i][j] *= hbarc3; // fm^3/(GeV^2) - deltaf_coeff_tb_14mom_Bpi_shear[i][j] *= hbarc4; // fm^4/(GeV^2) + deltaf_coeff_tb_14mom_DPi[i][j] *= hbarc4; // fm^4/GeV + deltaf_coeff_tb_14mom_BPi[i][j] *= hbarc4; // fm^4/(GeV^2) + deltaf_coeff_tb_14mom_BPitilde[i][j] *= hbarc4; // fm^4/(GeV^2) + deltaf_coeff_tb_14mom_DV[i][j] *= hbarc3; // fm^3/GeV + deltaf_coeff_tb_14mom_BV[i][j] *= hbarc3; // fm^3/(GeV^2) + deltaf_coeff_tb_14mom_Bpi_shear[i][j] *= hbarc4; // fm^4/(GeV^2) } } } double Freeze::get_deltaf_qmu_coeff(double T, double muB) { - int idx_T = static_cast((T - delta_qmu_coeff_table_T0) - /delta_qmu_coeff_table_dT); - int idx_mu = static_cast((muB - delta_qmu_coeff_table_mu0) - /delta_qmu_coeff_table_dmu); - double x_fraction = ((T - delta_qmu_coeff_table_T0) - /delta_qmu_coeff_table_dT - idx_T); - double y_fraction = ((muB - delta_qmu_coeff_table_mu0) - /delta_qmu_coeff_table_dmu - idx_mu); + int idx_T = static_cast( + (T - delta_qmu_coeff_table_T0) / delta_qmu_coeff_table_dT); + int idx_mu = static_cast( + (muB - delta_qmu_coeff_table_mu0) / delta_qmu_coeff_table_dmu); + double x_fraction = + ((T - delta_qmu_coeff_table_T0) / delta_qmu_coeff_table_dT - idx_T); + double y_fraction = + ((muB - delta_qmu_coeff_table_mu0) / delta_qmu_coeff_table_dmu + - idx_mu); // avoid overflow: return a large number so that delta f = 0 if (idx_mu > deltaf_qmu_coeff_table_length_mu - 2) { - return(1e30); + return (1e30); } if (idx_T > deltaf_qmu_coeff_table_length_T - 2) { - return(1e30); + return (1e30); } - + // avoid underflow: return a large number so that delta f = 0 if (idx_mu < 0) { - return(1e30); + return (1e30); } if (idx_T < 0) { - return(1e30); + return (1e30); } - + double f1 = deltaf_qmu_coeff_tb[idx_T][idx_mu]; - double f2 = deltaf_qmu_coeff_tb[idx_T][idx_mu+1]; - double f3 = deltaf_qmu_coeff_tb[idx_T+1][idx_mu+1]; - double f4 = deltaf_qmu_coeff_tb[idx_T+1][idx_mu]; - - double coeff = f1*(1. - x_fraction)*(1. - y_fraction) - + f2*(1. - x_fraction)*y_fraction - + f3*x_fraction*y_fraction - + f4*x_fraction*(1. - y_fraction); - return(coeff); + double f2 = deltaf_qmu_coeff_tb[idx_T][idx_mu + 1]; + double f3 = deltaf_qmu_coeff_tb[idx_T + 1][idx_mu + 1]; + double f4 = deltaf_qmu_coeff_tb[idx_T + 1][idx_mu]; + + double coeff = f1 * (1. - x_fraction) * (1. - y_fraction) + + f2 * (1. - x_fraction) * y_fraction + + f3 * x_fraction * y_fraction + + f4 * x_fraction * (1. - y_fraction); + return (coeff); } double Freeze::get_deltaf_coeff_14moments(double T, double muB, double type) { - int idx_T = static_cast((T - delta_coeff_table_14mom_T0) - /delta_coeff_table_14mom_dT); - int idx_mu = static_cast((muB - delta_coeff_table_14mom_mu0) - /delta_coeff_table_14mom_dmu); - double x_fraction = ((T - delta_coeff_table_14mom_T0) - /delta_coeff_table_14mom_dT - idx_T); - double y_fraction = ((muB - delta_coeff_table_14mom_mu0) - /delta_coeff_table_14mom_dmu - idx_mu); + int idx_T = static_cast( + (T - delta_coeff_table_14mom_T0) / delta_coeff_table_14mom_dT); + int idx_mu = static_cast( + (muB - delta_coeff_table_14mom_mu0) / delta_coeff_table_14mom_dmu); + double x_fraction = + ((T - delta_coeff_table_14mom_T0) / delta_coeff_table_14mom_dT - idx_T); + double y_fraction = + ((muB - delta_coeff_table_14mom_mu0) / delta_coeff_table_14mom_dmu + - idx_mu); double **deltaf_table = NULL; if (type == 0) { - deltaf_table = deltaf_coeff_tb_14mom_DPi; + deltaf_table = deltaf_coeff_tb_14mom_DPi; } else if (type == 1) { - deltaf_table = deltaf_coeff_tb_14mom_BPi; + deltaf_table = deltaf_coeff_tb_14mom_BPi; } else if (type == 2) { - deltaf_table = deltaf_coeff_tb_14mom_BPitilde; + deltaf_table = deltaf_coeff_tb_14mom_BPitilde; } else if (type == 3) { - deltaf_table = deltaf_coeff_tb_14mom_DV; + deltaf_table = deltaf_coeff_tb_14mom_DV; } else if (type == 4) { - deltaf_table = deltaf_coeff_tb_14mom_BV; + deltaf_table = deltaf_coeff_tb_14mom_BV; } else if (type == 5) { - deltaf_table = deltaf_coeff_tb_14mom_Bpi_shear; + deltaf_table = deltaf_coeff_tb_14mom_Bpi_shear; } else { - music_message << "Freeze::get_deltaf_coeff_14moments: unknown type: " - << type; - music_message.flush("error"); - exit(-1); + music_message << "Freeze::get_deltaf_coeff_14moments: unknown type: " + << type; + music_message.flush("error"); + exit(-1); } - + double f1 = deltaf_table[idx_T][idx_mu]; - double f2 = deltaf_table[idx_T][idx_mu+1]; - double f3 = deltaf_table[idx_T+1][idx_mu+1]; - double f4 = deltaf_table[idx_T+1][idx_mu]; - - double coeff = f1*(1. - x_fraction)*(1. - y_fraction) - + f2*(1. - x_fraction)*y_fraction - + f3*x_fraction*y_fraction - + f4*x_fraction*(1. - y_fraction); - return(coeff); + double f2 = deltaf_table[idx_T][idx_mu + 1]; + double f3 = deltaf_table[idx_T + 1][idx_mu + 1]; + double f4 = deltaf_table[idx_T + 1][idx_mu]; + + double coeff = f1 * (1. - x_fraction) * (1. - y_fraction) + + f2 * (1. - x_fraction) * y_fraction + + f3 * x_fraction * y_fraction + + f4 * x_fraction * (1. - y_fraction); + return (coeff); } -void Freeze::getbulkvisCoefficients(double Tdec, double* bulkvisCoefficients) { - double Tdec_fm = Tdec/hbarc; // [1/fm] - double Tdec_fm_power[11]; // cache the polynomial power of Tdec_fm +void Freeze::getbulkvisCoefficients(double Tdec, double *bulkvisCoefficients) { + double Tdec_fm = Tdec / hbarc; // [1/fm] + double Tdec_fm_power[11]; // cache the polynomial power of Tdec_fm Tdec_fm_power[1] = Tdec_fm; for (int ipower = 2; ipower < 11; ipower++) - Tdec_fm_power[ipower] = Tdec_fm_power[ipower-1]*Tdec_fm; - if (bulk_deltaf_kind == 0) { // 14 moment expansion + Tdec_fm_power[ipower] = Tdec_fm_power[ipower - 1] * Tdec_fm; + if (bulk_deltaf_kind == 0) { // 14 moment expansion // parameterization for mu = 0 // B0[fm^3/GeV^3] - bulkvisCoefficients[0] = ( - exp(-15.04512474*Tdec_fm + 11.76194266)/pow(hbarc, 3)); + bulkvisCoefficients[0] = + (exp(-15.04512474 * Tdec_fm + 11.76194266) / pow(hbarc, 3)); // D0 [fm^3/GeV^2] - bulkvisCoefficients[1] = ( - exp( -12.45699277*Tdec_fm + 11.4949293)/hbarc/hbarc); + bulkvisCoefficients[1] = + (exp(-12.45699277 * Tdec_fm + 11.4949293) / hbarc / hbarc); // E0 [fm^3/GeV^3] - bulkvisCoefficients[2] = ( - -exp(-14.45087586*Tdec_fm + 11.62716548)/pow(hbarc, 3)); - } else if(bulk_deltaf_kind == 1) { // relaxation type 1 + bulkvisCoefficients[2] = + (-exp(-14.45087586 * Tdec_fm + 11.62716548) / pow(hbarc, 3)); + } else if (bulk_deltaf_kind == 1) { // relaxation type 1 // parameterization from JF // A Polynomial fit to each coefficient -- temperature in fm^-1 // Both fits are reliable between T=100 -- 180 MeV // do not trust it beyond - bulkvisCoefficients[0] = ( 642096.624265727 - - 8163329.49562861*Tdec_fm_power[1] - + 47162768.4292073*Tdec_fm_power[2] - - 162590040.002683*Tdec_fm_power[3] - + 369637951.096896*Tdec_fm_power[4] - - 578181331.809836*Tdec_fm_power[5] - + 629434830.225675*Tdec_fm_power[6] - - 470493661.096657*Tdec_fm_power[7] - + 230936465.421*Tdec_fm_power[8] - - 67175218.4629078*Tdec_fm_power[9] - + 8789472.32652964*Tdec_fm_power[10]); - - bulkvisCoefficients[1] = ( 1.18171174036192 - - 17.6740645873717*Tdec_fm_power[1] - + 136.298469057177*Tdec_fm_power[2] - - 635.999435106846*Tdec_fm_power[3] - + 1918.77100633321*Tdec_fm_power[4] - - 3836.32258307711*Tdec_fm_power[5] - + 5136.35746882372*Tdec_fm_power[6] - - 4566.22991441914*Tdec_fm_power[7] - + 2593.45375240886*Tdec_fm_power[8] - - 853.908199724349*Tdec_fm_power[9] - + 124.260460450113*Tdec_fm_power[10]); - } else if (bulk_deltaf_kind == 2) { // relaxation type 2 + bulkvisCoefficients[0] = + (642096.624265727 - 8163329.49562861 * Tdec_fm_power[1] + + 47162768.4292073 * Tdec_fm_power[2] + - 162590040.002683 * Tdec_fm_power[3] + + 369637951.096896 * Tdec_fm_power[4] + - 578181331.809836 * Tdec_fm_power[5] + + 629434830.225675 * Tdec_fm_power[6] + - 470493661.096657 * Tdec_fm_power[7] + + 230936465.421 * Tdec_fm_power[8] + - 67175218.4629078 * Tdec_fm_power[9] + + 8789472.32652964 * Tdec_fm_power[10]); + + bulkvisCoefficients[1] = + (1.18171174036192 - 17.6740645873717 * Tdec_fm_power[1] + + 136.298469057177 * Tdec_fm_power[2] + - 635.999435106846 * Tdec_fm_power[3] + + 1918.77100633321 * Tdec_fm_power[4] + - 3836.32258307711 * Tdec_fm_power[5] + + 5136.35746882372 * Tdec_fm_power[6] + - 4566.22991441914 * Tdec_fm_power[7] + + 2593.45375240886 * Tdec_fm_power[8] + - 853.908199724349 * Tdec_fm_power[9] + + 124.260460450113 * Tdec_fm_power[10]); + } else if (bulk_deltaf_kind == 2) { // relaxation type 2 // A Polynomial fit to each coefficient -- temperature in fm^-1 // Both fits are reliable between T=100 -- 180 MeV // do not trust it beyond - bulkvisCoefficients[0] = ( - 21091365.1182649 - 290482229.281782*Tdec_fm_power[1] - + 1800423055.01882*Tdec_fm_power[2] - - 6608608560.99887*Tdec_fm_power[3] - + 15900800422.7138*Tdec_fm_power[4] - - 26194517161.8205*Tdec_fm_power[5] - + 29912485360.2916*Tdec_fm_power[6] - - 23375101221.2855*Tdec_fm_power[7] - + 11960898238.0134*Tdec_fm_power[8] - - 3618358144.18576*Tdec_fm_power[9] - + 491369134.205902*Tdec_fm_power[10]); - - bulkvisCoefficients[1] = ( - 4007863.29316896 - 55199395.3534188*Tdec_fm_power[1] - + 342115196.396492*Tdec_fm_power[2] - - 1255681487.77798*Tdec_fm_power[3] - + 3021026280.08401*Tdec_fm_power[4] - - 4976331606.85766*Tdec_fm_power[5] - + 5682163732.74188*Tdec_fm_power[6] - - 4439937810.57449*Tdec_fm_power[7] - + 2271692965.05568*Tdec_fm_power[8] - - 687164038.128814*Tdec_fm_power[9] - + 93308348.3137008*Tdec_fm_power[10]); - } else if (bulk_deltaf_kind == 3) { // relaxation type 3 - bulkvisCoefficients[0] = ( - 160421664.93603 - 2212807124.97991*Tdec_fm_power[1] - + 13707913981.1425*Tdec_fm_power[2] - - 50204536518.1767*Tdec_fm_power[3] - + 120354649094.362*Tdec_fm_power[4] - - 197298426823.223*Tdec_fm_power[5] - + 223953760788.288*Tdec_fm_power[6] - - 173790947240.829*Tdec_fm_power[7] - + 88231322888.0423*Tdec_fm_power[8] - - 26461154892.6963*Tdec_fm_power[9] - + 3559805050.19592*Tdec_fm_power[10]); - bulkvisCoefficients[1] = ( - 33369186.2536556 - 460293490.420478*Tdec_fm_power[1] - + 2851449676.09981*Tdec_fm_power[2] - - 10443297927.601*Tdec_fm_power[3] - + 25035517099.7809*Tdec_fm_power[4] - - 41040777943.4963*Tdec_fm_power[5] - + 46585225878.8723*Tdec_fm_power[6] - - 36150531001.3718*Tdec_fm_power[7] - + 18353035766.9323*Tdec_fm_power[8] - - 5504165325.05431*Tdec_fm_power[9] - + 740468257.784873*Tdec_fm_power[10]); - } else if (bulk_deltaf_kind == 4) { // relaxation type 4 - bulkvisCoefficients[0] = ( - 1167272041.90731 - 16378866444.6842*Tdec_fm_power[1] - + 103037615761.617*Tdec_fm_power[2] - - 382670727905.111*Tdec_fm_power[3] - + 929111866739.436*Tdec_fm_power[4] - - 1540948583116.54*Tdec_fm_power[5] - + 1767975890298.1*Tdec_fm_power[6] - - 1385606389545*Tdec_fm_power[7] - + 709922576963.213*Tdec_fm_power[8] - - 214726945096.326*Tdec_fm_power[9] - + 29116298091.9219*Tdec_fm_power[10]); - bulkvisCoefficients[1] = ( - 5103633637.7213 - 71612903872.8163*Tdec_fm_power[1] - + 450509014334.964*Tdec_fm_power[2] - - 1673143669281.46*Tdec_fm_power[3] - + 4062340452589.89*Tdec_fm_power[4] - - 6737468792456.4*Tdec_fm_power[5] - + 7730102407679.65*Tdec_fm_power[6] - - 6058276038129.83*Tdec_fm_power[7] - + 3103990764357.81*Tdec_fm_power[8] - - 938850005883.612*Tdec_fm_power[9] - + 127305171097.249*Tdec_fm_power[10]); + bulkvisCoefficients[0] = + (21091365.1182649 - 290482229.281782 * Tdec_fm_power[1] + + 1800423055.01882 * Tdec_fm_power[2] + - 6608608560.99887 * Tdec_fm_power[3] + + 15900800422.7138 * Tdec_fm_power[4] + - 26194517161.8205 * Tdec_fm_power[5] + + 29912485360.2916 * Tdec_fm_power[6] + - 23375101221.2855 * Tdec_fm_power[7] + + 11960898238.0134 * Tdec_fm_power[8] + - 3618358144.18576 * Tdec_fm_power[9] + + 491369134.205902 * Tdec_fm_power[10]); + + bulkvisCoefficients[1] = + (4007863.29316896 - 55199395.3534188 * Tdec_fm_power[1] + + 342115196.396492 * Tdec_fm_power[2] + - 1255681487.77798 * Tdec_fm_power[3] + + 3021026280.08401 * Tdec_fm_power[4] + - 4976331606.85766 * Tdec_fm_power[5] + + 5682163732.74188 * Tdec_fm_power[6] + - 4439937810.57449 * Tdec_fm_power[7] + + 2271692965.05568 * Tdec_fm_power[8] + - 687164038.128814 * Tdec_fm_power[9] + + 93308348.3137008 * Tdec_fm_power[10]); + } else if (bulk_deltaf_kind == 3) { // relaxation type 3 + bulkvisCoefficients[0] = + (160421664.93603 - 2212807124.97991 * Tdec_fm_power[1] + + 13707913981.1425 * Tdec_fm_power[2] + - 50204536518.1767 * Tdec_fm_power[3] + + 120354649094.362 * Tdec_fm_power[4] + - 197298426823.223 * Tdec_fm_power[5] + + 223953760788.288 * Tdec_fm_power[6] + - 173790947240.829 * Tdec_fm_power[7] + + 88231322888.0423 * Tdec_fm_power[8] + - 26461154892.6963 * Tdec_fm_power[9] + + 3559805050.19592 * Tdec_fm_power[10]); + bulkvisCoefficients[1] = + (33369186.2536556 - 460293490.420478 * Tdec_fm_power[1] + + 2851449676.09981 * Tdec_fm_power[2] + - 10443297927.601 * Tdec_fm_power[3] + + 25035517099.7809 * Tdec_fm_power[4] + - 41040777943.4963 * Tdec_fm_power[5] + + 46585225878.8723 * Tdec_fm_power[6] + - 36150531001.3718 * Tdec_fm_power[7] + + 18353035766.9323 * Tdec_fm_power[8] + - 5504165325.05431 * Tdec_fm_power[9] + + 740468257.784873 * Tdec_fm_power[10]); + } else if (bulk_deltaf_kind == 4) { // relaxation type 4 + bulkvisCoefficients[0] = + (1167272041.90731 - 16378866444.6842 * Tdec_fm_power[1] + + 103037615761.617 * Tdec_fm_power[2] + - 382670727905.111 * Tdec_fm_power[3] + + 929111866739.436 * Tdec_fm_power[4] + - 1540948583116.54 * Tdec_fm_power[5] + + 1767975890298.1 * Tdec_fm_power[6] + - 1385606389545 * Tdec_fm_power[7] + + 709922576963.213 * Tdec_fm_power[8] + - 214726945096.326 * Tdec_fm_power[9] + + 29116298091.9219 * Tdec_fm_power[10]); + bulkvisCoefficients[1] = + (5103633637.7213 - 71612903872.8163 * Tdec_fm_power[1] + + 450509014334.964 * Tdec_fm_power[2] + - 1673143669281.46 * Tdec_fm_power[3] + + 4062340452589.89 * Tdec_fm_power[4] + - 6737468792456.4 * Tdec_fm_power[5] + + 7730102407679.65 * Tdec_fm_power[6] + - 6058276038129.83 * Tdec_fm_power[7] + + 3103990764357.81 * Tdec_fm_power[8] + - 938850005883.612 * Tdec_fm_power[9] + + 127305171097.249 * Tdec_fm_power[10]); } return; } diff --git a/src/grid.h b/src/grid.h index 07997595..b992e528 100644 --- a/src/grid.h +++ b/src/grid.h @@ -3,71 +3,88 @@ #include #include + #include "cell.h" #include "grid.h" -template +template class GridT { - private: + private: std::vector grid; - int Nx = 0; - int Ny = 0; + int Nx = 0; + int Ny = 0; int Neta = 0; - T& get(int x, int y, int eta) { - return grid[Nx*(Ny*eta+y)+x]; - } + T& get(int x, int y, int eta) { return grid[Nx * (Ny * eta + y) + x]; } - public: + public: GridT() = default; GridT(int Nx0, int Ny0, int Neta0) { - Nx = Nx0 ; - Ny = Ny0 ; + Nx = Nx0; + Ny = Ny0; Neta = Neta0; - grid.resize(Nx*Ny*Neta); + grid.resize(Nx * Ny * Neta); } - int nX() const {return(Nx ); } - int nY() const {return(Ny ); } - int nEta() const {return(Neta );} - int size() const {return Nx*Ny*Neta;} - - T& getHalo(int x, int y, int eta){ - assert(-2<=x ); assert(x =Nx) x = Nx - 1; - if(y <0) y =0; else if(y >=Ny) y = Ny - 1; - if(eta<0) eta=0; else if(eta>=Neta) eta= Neta - 1; - return get(x,y,eta); + int nX() const { return (Nx); } + int nY() const { return (Ny); } + int nEta() const { return (Neta); } + int size() const { return Nx * Ny * Neta; } + + T& getHalo(int x, int y, int eta) { + assert(-2 <= x); + assert(x < Nx + 2); + assert(-2 <= y); + assert(y < Ny + 2); + assert(-2 <= eta); + assert(eta < Neta + 2); + if (x < 0) + x = 0; + else if (x >= Nx) + x = Nx - 1; + if (y < 0) + y = 0; + else if (y >= Ny) + y = Ny - 1; + if (eta < 0) + eta = 0; + else if (eta >= Neta) + eta = Neta - 1; + return get(x, y, eta); } - const T& getHalo(int x, int y, int eta) const { - return getHalo(x, y, eta); - } + const T& getHalo(int x, int y, int eta) const { return getHalo(x, y, eta); } T& operator()(const int x, const int y, const int eta) { - assert(0<=x ); assert(x SCGrid; -template -void Neighbourloop(GridT &arena, int cx, int cy, int ceta, Func func) { - const std::array dx = {-1, 1, 0, 0, 0, 0}; - const std::array dy = { 0, 0, -1, 1, 0, 0}; - const std::array deta = { 0, 0, 0, 0, -1, 1}; - for(int dir = 0; dir < 3; dir++) { - const int m1nx = dx [2*dir]; - const int m1ny = dy [2*dir]; - const int m1neta = deta[2*dir]; - const int p1nx = dx [2*dir+1]; - const int p1ny = dy [2*dir+1]; - const int p1neta = deta[2*dir+1]; - const int m2nx = 2*m1nx; - const int m2ny = 2*m1ny; - const int m2neta = 2*m1neta; - const int p2nx = 2*p1nx; - const int p2ny = 2*p1ny; - const int p2neta = 2*p1neta; - auto& c = arena (cx, cy, ceta ); - const auto& p1 = arena.getHalo(cx+p1nx, cy+p1ny, ceta+p1neta); - const auto& p2 = arena.getHalo(cx+p2nx, cy+p2ny, ceta+p2neta); - const auto& m1 = arena.getHalo(cx+m1nx, cy+m1ny, ceta+m1neta); - const auto& m2 = arena.getHalo(cx+m2nx, cy+m2ny, ceta+m2neta); - func(c,p1,p2,m1,m2,dir+1); +template +void Neighbourloop(GridT& arena, int cx, int cy, int ceta, Func func) { + const std::array dx = {-1, 1, 0, 0, 0, 0}; + const std::array dy = {0, 0, -1, 1, 0, 0}; + const std::array deta = {0, 0, 0, 0, -1, 1}; + for (int dir = 0; dir < 3; dir++) { + const int m1nx = dx[2 * dir]; + const int m1ny = dy[2 * dir]; + const int m1neta = deta[2 * dir]; + const int p1nx = dx[2 * dir + 1]; + const int p1ny = dy[2 * dir + 1]; + const int p1neta = deta[2 * dir + 1]; + const int m2nx = 2 * m1nx; + const int m2ny = 2 * m1ny; + const int m2neta = 2 * m1neta; + const int p2nx = 2 * p1nx; + const int p2ny = 2 * p1ny; + const int p2neta = 2 * p1neta; + auto& c = arena(cx, cy, ceta); + const auto& p1 = arena.getHalo(cx + p1nx, cy + p1ny, ceta + p1neta); + const auto& p2 = arena.getHalo(cx + p2nx, cy + p2ny, ceta + p2neta); + const auto& m1 = arena.getHalo(cx + m1nx, cy + m1ny, ceta + m1neta); + const auto& m2 = arena.getHalo(cx + m2nx, cy + m2ny, ceta + m2neta); + func(c, p1, p2, m1, m2, dir + 1); } } -#define NLAMBDAS [&](Cell_small& c, const Cell_small& p1, const Cell_small& p2, const Cell_small& m1, const Cell_small& m2, const int direction) +#define NLAMBDAS \ + [&](Cell_small & c, const Cell_small& p1, const Cell_small& p2, \ + const Cell_small& m1, const Cell_small& m2, const int direction) #endif diff --git a/src/grid_info.cpp b/src/grid_info.cpp index af4ef3d9..f91d4a2d 100644 --- a/src/grid_info.cpp +++ b/src/grid_info.cpp @@ -1,37 +1,35 @@ // Copyright Chun Shen @ 2014-2016 -#include +#include "grid_info.h" + +#include #include #include -#include +#include #include #include "util.h" -#include "grid_info.h" -using Util::hbarc; -using Util::small_eps; -using std::string; -using std::scientific; -using std::setw; -using std::setprecision; using std::endl; using std::ofstream; using std::ostringstream; +using std::scientific; +using std::setprecision; +using std::setw; +using std::string; +using Util::hbarc; +using Util::small_eps; -Cell_info::Cell_info(const InitData &DATA_in, const EOS &eos_in) : - DATA(DATA_in), - eos(eos_in), - u_derivative_helper(DATA_in, eos_in) { - +Cell_info::Cell_info(const InitData &DATA_in, const EOS &eos_in) + : DATA(DATA_in), eos(eos_in), u_derivative_helper(DATA_in, eos_in) { // read in tables for delta f coefficients if (DATA.turn_on_diff == 1) { if (DATA.deltaf_14moments == 1) { load_deltaf_qmu_coeff_table_14mom( - "tables/deltaf_coefficients_14moments.dat"); + "tables/deltaf_coefficients_14moments.dat"); } else { if (DATA.include_deltaf_qmu == 1) load_deltaf_qmu_coeff_table( - "tables/Coefficients_RTA_diffusion.dat"); + "tables/Coefficients_RTA_diffusion.dat"); } } Pmu_edge_prev = {0.}; @@ -42,30 +40,29 @@ Cell_info::~Cell_info() { if (DATA.turn_on_diff == 1) { if (DATA.deltaf_14moments == 1) { for (int i = 0; i < deltaf_coeff_table_14mom_length_T; i++) { - delete [] deltaf_coeff_tb_14mom_DPi[i]; - delete [] deltaf_coeff_tb_14mom_BPi[i]; - delete [] deltaf_coeff_tb_14mom_BPitilde[i]; - delete [] deltaf_coeff_tb_14mom_DV[i]; - delete [] deltaf_coeff_tb_14mom_BV[i]; - delete [] deltaf_coeff_tb_14mom_Bpi_shear[i]; + delete[] deltaf_coeff_tb_14mom_DPi[i]; + delete[] deltaf_coeff_tb_14mom_BPi[i]; + delete[] deltaf_coeff_tb_14mom_BPitilde[i]; + delete[] deltaf_coeff_tb_14mom_DV[i]; + delete[] deltaf_coeff_tb_14mom_BV[i]; + delete[] deltaf_coeff_tb_14mom_Bpi_shear[i]; } - delete [] deltaf_coeff_tb_14mom_DPi; - delete [] deltaf_coeff_tb_14mom_BPi; - delete [] deltaf_coeff_tb_14mom_BPitilde; - delete [] deltaf_coeff_tb_14mom_DV; - delete [] deltaf_coeff_tb_14mom_BV; - delete [] deltaf_coeff_tb_14mom_Bpi_shear; + delete[] deltaf_coeff_tb_14mom_DPi; + delete[] deltaf_coeff_tb_14mom_BPi; + delete[] deltaf_coeff_tb_14mom_BPitilde; + delete[] deltaf_coeff_tb_14mom_DV; + delete[] deltaf_coeff_tb_14mom_BV; + delete[] deltaf_coeff_tb_14mom_Bpi_shear; } else { if (DATA.include_deltaf_qmu == 1) { for (int i = 0; i < deltaf_qmu_coeff_table_length_T; i++) - delete [] deltaf_qmu_coeff_tb[i]; - delete [] deltaf_qmu_coeff_tb; + delete[] deltaf_qmu_coeff_tb[i]; + delete[] deltaf_qmu_coeff_tb; } } } } - //! This function outputs a header files for JF and Gojko's EM program void Cell_info::Output_hydro_information_header() { string fname = "hydro_info_header_h"; @@ -75,11 +72,11 @@ void Cell_info::Output_hydro_information_header() { outfile.open(fname.c_str()); int grid_nx = ceil( - (static_cast(DATA.nx + 1))/DATA.output_evolution_every_N_x); + (static_cast(DATA.nx + 1)) / DATA.output_evolution_every_N_x); int grid_ny = ceil( - (static_cast(DATA.ny + 1))/DATA.output_evolution_every_N_y); + (static_cast(DATA.ny + 1)) / DATA.output_evolution_every_N_y); int grid_neta = ceil( - (static_cast(DATA.neta))/DATA.output_evolution_every_N_eta); + (static_cast(DATA.neta)) / DATA.output_evolution_every_N_eta); outfile << "const int MUSIC_real_nx = " << grid_nx << ";" << endl; outfile << "const int MUSIC_real_ny = " << grid_ny << ";" << endl; @@ -88,14 +85,14 @@ void Cell_info::Output_hydro_information_header() { outfile << "const double MUSIC_tau0 = " << DATA.tau0 << ";" << endl; outfile << "const double MUSIC_dx = " - << DATA.delta_x*DATA.output_evolution_every_N_x << ";" << endl; + << DATA.delta_x * DATA.output_evolution_every_N_x << ";" << endl; outfile << "const double MUSIC_dy = " - << DATA.delta_y*DATA.output_evolution_every_N_y << ";" << endl; + << DATA.delta_y * DATA.output_evolution_every_N_y << ";" << endl; outfile << "const double MUSIC_deta = " - << DATA.delta_eta*DATA.output_evolution_every_N_eta << ";" + << DATA.delta_eta * DATA.output_evolution_every_N_eta << ";" << endl; outfile << "const double MUSIC_dtau = " - << DATA.output_evolution_every_N_timesteps*DATA.delta_tau << ";" + << DATA.output_evolution_every_N_timesteps * DATA.delta_tau << ";" << endl; outfile << "const bool MUSIC_with_shear_viscosity = " @@ -112,19 +109,18 @@ void Cell_info::Output_hydro_information_header() { outfile.close(); } - //! This function outputs hydro evolution file in binary format void Cell_info::OutputEvolutionDataXYEta(Fields &arena, double tau) { const string out_name_xyeta = "evolution_xyeta.dat"; const string out_name_W_xyeta = - "evolution_Wmunu_over_epsilon_plus_P_xyeta.dat"; + "evolution_Wmunu_over_epsilon_plus_P_xyeta.dat"; const string out_name_bulkpi_xyeta = "evolution_bulk_pressure_xyeta.dat"; const string out_name_q_xyeta = "evolution_qmu_xyeta.dat"; string out_open_mode; - FILE *out_file_xyeta = NULL; - FILE *out_file_W_xyeta = NULL; + FILE *out_file_xyeta = NULL; + FILE *out_file_W_xyeta = NULL; FILE *out_file_bulkpi_xyeta = NULL; - FILE *out_file_q_xyeta = NULL; + FILE *out_file_q_xyeta = NULL; // If it's the first timestep, overwrite the previous file if (tau == DATA.tau0) { @@ -138,67 +134,68 @@ void Cell_info::OutputEvolutionDataXYEta(Fields &arena, double tau) { } out_file_xyeta = fopen(out_name_xyeta.c_str(), out_open_mode.c_str()); if (DATA.turn_on_shear == 1) { - out_file_W_xyeta = fopen(out_name_W_xyeta.c_str(), - out_open_mode.c_str()); + out_file_W_xyeta = + fopen(out_name_W_xyeta.c_str(), out_open_mode.c_str()); } if (DATA.turn_on_bulk == 1) { - out_file_bulkpi_xyeta = fopen(out_name_bulkpi_xyeta.c_str(), - out_open_mode.c_str()); + out_file_bulkpi_xyeta = + fopen(out_name_bulkpi_xyeta.c_str(), out_open_mode.c_str()); } if (DATA.turn_on_diff == 1) { - out_file_q_xyeta = fopen(out_name_q_xyeta.c_str(), - out_open_mode.c_str()); + out_file_q_xyeta = + fopen(out_name_q_xyeta.c_str(), out_open_mode.c_str()); } - const int n_skip_x = DATA.output_evolution_every_N_x; - const int n_skip_y = DATA.output_evolution_every_N_y; + const int n_skip_x = DATA.output_evolution_every_N_x; + const int n_skip_y = DATA.output_evolution_every_N_y; const int n_skip_eta = DATA.output_evolution_every_N_eta; std::vector thermalVec; for (int ieta = 0; ieta < arena.nEta(); ieta += n_skip_eta) { double eta = 0.0; if (!DATA.boost_invariant) { - eta = ((static_cast(ieta))*(DATA.delta_eta) - - (DATA.eta_size)/2.0); + eta = + ((static_cast(ieta)) * (DATA.delta_eta) + - (DATA.eta_size) / 2.0); } double cosh_eta = cosh(eta); double sinh_eta = sinh(eta); for (int iy = 0; iy < arena.nY(); iy += n_skip_y) { for (int ix = 0; ix < arena.nX(); ix += n_skip_x) { int fieldIdx = arena.getFieldIdx(ix, iy, ieta); - eos.getThermalVariables(arena.e_[fieldIdx], - arena.rhob_[fieldIdx], thermalVec); + eos.getThermalVariables( + arena.e_[fieldIdx], arena.rhob_[fieldIdx], thermalVec); double utau = arena.u_[0][fieldIdx]; - double ux = arena.u_[1][fieldIdx]; - double uy = arena.u_[2][fieldIdx]; + double ux = arena.u_[1][fieldIdx]; + double uy = arena.u_[2][fieldIdx]; double ueta = arena.u_[3][fieldIdx]; - double ut = utau*cosh_eta + ueta*sinh_eta; // gamma factor - double vx = ux/ut; - double vy = uy/ut; - double uz = ueta*cosh_eta + utau*sinh_eta; - double vz = uz/ut; + double ut = utau * cosh_eta + ueta * sinh_eta; // gamma factor + double vx = ux / ut; + double vy = uy / ut; + double uz = ueta * cosh_eta + utau * sinh_eta; + double vz = uz / ut; - double enthropy = thermalVec[0] + thermalVec[2]; // [1/fm^4] + double enthropy = thermalVec[0] + thermalVec[2]; // [1/fm^4] double Wtautau = 0.0; - double Wtaux = 0.0; - double Wtauy = 0.0; + double Wtaux = 0.0; + double Wtauy = 0.0; double Wtaueta = 0.0; - double Wxx = 0.0; - double Wxy = 0.0; - double Wxeta = 0.0; - double Wyy = 0.0; - double Wyeta = 0.0; + double Wxx = 0.0; + double Wxy = 0.0; + double Wxeta = 0.0; + double Wyy = 0.0; + double Wyeta = 0.0; double Wetaeta = 0.0; if (DATA.turn_on_shear == 1) { - Wtautau = arena.Wmunu_[0][fieldIdx]/enthropy; - Wtaux = arena.Wmunu_[1][fieldIdx]/enthropy; - Wtauy = arena.Wmunu_[2][fieldIdx]/enthropy; - Wtaueta = arena.Wmunu_[3][fieldIdx]/enthropy; - Wxx = arena.Wmunu_[4][fieldIdx]/enthropy; - Wxy = arena.Wmunu_[5][fieldIdx]/enthropy; - Wxeta = arena.Wmunu_[6][fieldIdx]/enthropy; - Wyy = arena.Wmunu_[7][fieldIdx]/enthropy; - Wyeta = arena.Wmunu_[8][fieldIdx]/enthropy; - Wetaeta = arena.Wmunu_[9][fieldIdx]/enthropy; + Wtautau = arena.Wmunu_[0][fieldIdx] / enthropy; + Wtaux = arena.Wmunu_[1][fieldIdx] / enthropy; + Wtauy = arena.Wmunu_[2][fieldIdx] / enthropy; + Wtaueta = arena.Wmunu_[3][fieldIdx] / enthropy; + Wxx = arena.Wmunu_[4][fieldIdx] / enthropy; + Wxy = arena.Wmunu_[5][fieldIdx] / enthropy; + Wxeta = arena.Wmunu_[6][fieldIdx] / enthropy; + Wyy = arena.Wmunu_[7][fieldIdx] / enthropy; + Wyeta = arena.Wmunu_[8][fieldIdx] / enthropy; + Wetaeta = arena.Wmunu_[9][fieldIdx] / enthropy; } double bulk_Pi = 0.0; @@ -208,43 +205,46 @@ void Cell_info::OutputEvolutionDataXYEta(Fields &arena, double tau) { // outputs for baryon diffusion part double common_term_q = 0.0; - double qtau = 0.0; - double qx = 0.0; - double qy = 0.0; - double qeta = 0.0; + double qtau = 0.0; + double qx = 0.0; + double qy = 0.0; + double qeta = 0.0; if (DATA.turn_on_diff == 1) { - common_term_q = thermalVec[1]*thermalVec[6]/enthropy; - double kappa_hat = get_deltaf_qmu_coeff(thermalVec[6], - thermalVec[7]); - qtau = arena.Wmunu_[10][fieldIdx]/kappa_hat; - qx = arena.Wmunu_[11][fieldIdx]/kappa_hat; - qy = arena.Wmunu_[12][fieldIdx]/kappa_hat; - qeta = arena.Wmunu_[13][fieldIdx]/kappa_hat; + common_term_q = thermalVec[1] * thermalVec[6] / enthropy; + double kappa_hat = + get_deltaf_qmu_coeff(thermalVec[6], thermalVec[7]); + qtau = arena.Wmunu_[10][fieldIdx] / kappa_hat; + qx = arena.Wmunu_[11][fieldIdx] / kappa_hat; + qy = arena.Wmunu_[12][fieldIdx] / kappa_hat; + qeta = arena.Wmunu_[13][fieldIdx] / kappa_hat; } // exclude the actual coordinates from the output to save space: if (DATA.outputBinaryEvolution == 0) { - fprintf(out_file_xyeta, "%e %e %e %e %e\n", - thermalVec[6]*hbarc, thermalVec[7]*hbarc, - vx, vy, vz); + fprintf( + out_file_xyeta, "%e %e %e %e %e\n", + thermalVec[6] * hbarc, thermalVec[7] * hbarc, vx, vy, + vz); if (DATA.viscosity_flag == 1) { if (DATA.turn_on_shear) { - fprintf(out_file_W_xyeta, - "%e %e %e %e %e %e %e %e %e %e\n", - Wtautau, Wtaux, Wtauy, Wtaueta, Wxx, Wxy, - Wxeta, Wyy, Wyeta, Wetaeta); + fprintf( + out_file_W_xyeta, + "%e %e %e %e %e %e %e %e %e %e\n", Wtautau, + Wtaux, Wtauy, Wtaueta, Wxx, Wxy, Wxeta, Wyy, + Wyeta, Wetaeta); } if (DATA.turn_on_bulk) { - fprintf(out_file_bulkpi_xyeta,"%e %e %e\n", - bulk_Pi, enthropy, thermalVec[5]); + fprintf( + out_file_bulkpi_xyeta, "%e %e %e\n", bulk_Pi, + enthropy, thermalVec[5]); } } } else { - float array[] = {static_cast(thermalVec[6]*hbarc), - static_cast(thermalVec[7]*hbarc), - static_cast(vx), - static_cast(vy), - static_cast(vz)}; + float array[] = { + static_cast(thermalVec[6] * hbarc), + static_cast(thermalVec[7] * hbarc), + static_cast(vx), static_cast(vy), + static_cast(vz)}; fwrite(array, sizeof(float), 5, out_file_xyeta); if (DATA.viscosity_flag == 1) { if (DATA.turn_on_shear == 1) { @@ -258,25 +258,24 @@ void Cell_info::OutputEvolutionDataXYEta(Fields &arena, double tau) { static_cast(Wyy), static_cast(Wyeta), static_cast(Wetaeta)}; - fwrite(array2, sizeof(float), 10, - out_file_W_xyeta); + fwrite(array2, sizeof(float), 10, out_file_W_xyeta); } if (DATA.turn_on_bulk == 1) { - float array1[] = {static_cast(bulk_Pi), - static_cast(enthropy), - static_cast(thermalVec[5]) - }; - fwrite(array1, sizeof(float), 3, - out_file_bulkpi_xyeta); + float array1[] = { + static_cast(bulk_Pi), + static_cast(enthropy), + static_cast(thermalVec[5])}; + fwrite( + array1, sizeof(float), 3, + out_file_bulkpi_xyeta); } if (DATA.turn_on_diff == 1) { - float array3[] = {static_cast(common_term_q), - static_cast(qtau), - static_cast(qx), - static_cast(qy), - static_cast(qeta)}; - fwrite(array3, sizeof(float), 5, - out_file_q_xyeta); + float array3[] = { + static_cast(common_term_q), + static_cast(qtau), + static_cast(qx), static_cast(qy), + static_cast(qeta)}; + fwrite(array3, sizeof(float), 5, out_file_q_xyeta); } } } @@ -295,11 +294,10 @@ void Cell_info::OutputEvolutionDataXYEta(Fields &arena, double tau) { } } - void Cell_info::OutputEvolution_Knudsen_Reynoldsnumbers( - Fields &arena, const double tau) const { + Fields &arena, const double tau) const { const string out_name_xyeta = "evolution_KRnumbers.dat"; - FILE *out_file_xyeta = NULL; + FILE *out_file_xyeta = NULL; // If it's the first timestep, overwrite the previous file string out_open_mode; @@ -315,25 +313,25 @@ void Cell_info::OutputEvolution_Knudsen_Reynoldsnumbers( } out_file_xyeta = fopen(out_name_xyeta.c_str(), out_open_mode.c_str()); - const int n_skip_x = DATA.output_evolution_every_N_x; - const int n_skip_y = DATA.output_evolution_every_N_y; + const int n_skip_x = DATA.output_evolution_every_N_x; + const int n_skip_y = DATA.output_evolution_every_N_y; const int n_skip_eta = DATA.output_evolution_every_N_eta; for (int ieta = 0; ieta < arena.nEta(); ieta += n_skip_eta) { for (int iy = 0; iy < arena.nY(); iy += n_skip_y) { for (int ix = 0; ix < arena.nX(); ix += n_skip_x) { int fieldIdx = arena.getFieldIdx(ix, iy, ieta); - double P_local = eos.get_pressure(arena.e_[fieldIdx], - arena.rhob_[fieldIdx]); + double P_local = + eos.get_pressure(arena.e_[fieldIdx], arena.rhob_[fieldIdx]); double R_pi = 0.0; double R_Pi = 0.0; - calculate_inverse_Reynolds_numbers(arena, fieldIdx, P_local, - R_pi, R_Pi); + calculate_inverse_Reynolds_numbers( + arena, fieldIdx, P_local, R_pi, R_Pi); if (DATA.outputBinaryEvolution == 0) { fprintf(out_file_xyeta, "%e %e\n", R_pi, R_Pi); } else { - float array[] = {static_cast(R_pi), - static_cast(R_Pi)}; + float array[] = { + static_cast(R_pi), static_cast(R_Pi)}; fwrite(array, sizeof(float), 2, out_file_xyeta); } } @@ -342,10 +340,9 @@ void Cell_info::OutputEvolution_Knudsen_Reynoldsnumbers( fclose(out_file_xyeta); } - void Cell_info::calculate_inverse_Reynolds_numbers( - Fields &arena, const int Idx, const double P_local, - double &R_pi, double &R_Pi) const { + Fields &arena, const int Idx, const double P_local, double &R_pi, + double &R_Pi) const { const double pi_00 = arena.Wmunu_[0][Idx]; const double pi_01 = arena.Wmunu_[1][Idx]; const double pi_02 = arena.Wmunu_[2][Idx]; @@ -357,21 +354,20 @@ void Cell_info::calculate_inverse_Reynolds_numbers( const double pi_23 = arena.Wmunu_[8][Idx]; const double pi_33 = arena.Wmunu_[9][Idx]; - const double pisize = ( - pi_00*pi_00 + pi_11*pi_11 + pi_22*pi_22 + pi_33*pi_33 - - 2.*(pi_01*pi_01 + pi_02*pi_02 + pi_03*pi_03) - + 2.*(pi_12*pi_12 + pi_13*pi_13 + pi_23*pi_23)); + const double pisize = + (pi_00 * pi_00 + pi_11 * pi_11 + pi_22 * pi_22 + pi_33 * pi_33 + - 2. * (pi_01 * pi_01 + pi_02 * pi_02 + pi_03 * pi_03) + + 2. * (pi_12 * pi_12 + pi_13 * pi_13 + pi_23 * pi_23)); - R_pi = sqrt(pisize)/P_local; - R_Pi = arena.piBulk_[Idx]/P_local; + R_pi = sqrt(pisize) / P_local; + R_Pi = arena.piBulk_[Idx] / P_local; } - //! This function outputs hydro evolution file into memory for JETSCAPE void Cell_info::OutputEvolutionDataXYEta_memory( - Fields &arena, const double tau, HydroinfoMUSIC &hydro_info_ptr) { - const int n_skip_x = DATA.output_evolution_every_N_x; - const int n_skip_y = DATA.output_evolution_every_N_y; + Fields &arena, const double tau, HydroinfoMUSIC &hydro_info_ptr) { + const int n_skip_x = DATA.output_evolution_every_N_x; + const int n_skip_y = DATA.output_evolution_every_N_y; const int n_skip_eta = DATA.output_evolution_every_N_eta; for (int ix = 0; ix < arena.nX(); ix += n_skip_x) { for (int iy = 0; iy < arena.nY(); iy += n_skip_y) { @@ -379,24 +375,25 @@ void Cell_info::OutputEvolutionDataXYEta_memory( int fieldIdx = arena.getFieldIdx(ix, iy, ieta); double eta = 0.0; if (!DATA.boost_invariant) { - eta = ((static_cast(ieta))*(DATA.delta_eta) - - (DATA.eta_size)/2.0); + eta = + ((static_cast(ieta)) * (DATA.delta_eta) + - (DATA.eta_size) / 2.0); } double cosh_eta = cosh(eta); double sinh_eta = sinh(eta); - double e_local = arena.e_[fieldIdx]; // 1/fm^4 - double rhob_local = arena.rhob_[fieldIdx]; // 1/fm^3 + double e_local = arena.e_[fieldIdx]; // 1/fm^4 + double rhob_local = arena.rhob_[fieldIdx]; // 1/fm^3 double p_local = eos.get_pressure(e_local, rhob_local); double utau = arena.u_[0][fieldIdx]; - double ux = arena.u_[1][fieldIdx]; - double uy = arena.u_[2][fieldIdx]; + double ux = arena.u_[1][fieldIdx]; + double uy = arena.u_[2][fieldIdx]; double ueta = arena.u_[3][fieldIdx]; - double ut = utau*cosh_eta + ueta*sinh_eta; // gamma factor - double vx = ux/ut; - double vy = uy/ut; - double uz = ueta*cosh_eta + utau*sinh_eta; - double vz = uz/ut; + double ut = utau * cosh_eta + ueta * sinh_eta; // gamma factor + double vx = ux / ut; + double vy = uy / ut; + double uz = ueta * cosh_eta + utau * sinh_eta; + double vz = uz / ut; double T_local = eos.get_temperature(e_local, rhob_local); double s_local = eos.get_entropy(e_local, rhob_local); @@ -408,7 +405,6 @@ void Cell_info::OutputEvolutionDataXYEta_memory( } } - //! This function outputs hydro evolution file in binary format void Cell_info::OutputEvolutionDataXYEta_chun(Fields &arena, double tau) { // the format of the file is as follows, @@ -420,13 +416,17 @@ void Cell_info::OutputEvolutionDataXYEta_chun(Fields &arena, double tau) { // if turn_on_rhob == 1: // itau ix iy ieta e P T cs^2 ux uy ueta rho_B mu_B // if turn_on_rhob == 1 and turn_on_shear == 1: - // itau ix iy ieta e P T cs^2 ux uy ueta rho_B mu_B Wxx Wxy Wxeta Wyy Wyeta + // itau ix iy ieta e P T cs^2 ux uy ueta rho_B mu_B Wxx Wxy Wxeta Wyy + // Wyeta // if turn_on_rhob == 1 and turn_on_shear == 1 and turn_on_diff == 1: - // itau ix iy ieta e P T cs^2 ux uy ueta rho_B mu_B Wxx Wxy Wxeta Wyy Wyeta qx qy qeta - // if turn_on_rhob == 1 and turn_on_shear == 1 and turn_on_bulk == 1 and turn_on_diff == 1: - // itau ix iy ieta e P T cs^2 ux uy ueta rho_B mu_B Wxx Wxy Wxeta Wyy Wyeta pi_b qx qy qeta - // Here ueta = tau*ueta, Wieta = tau*Wieta, Wetaeta = tau^2*Wetaeta, qeta = tau*qeta - // Here Wij is reduced variables Wij/(e+P) in the fluid rest frame + // itau ix iy ieta e P T cs^2 ux uy ueta rho_B mu_B Wxx Wxy Wxeta Wyy + // Wyeta qx qy qeta + // if turn_on_rhob == 1 and turn_on_shear == 1 and turn_on_bulk == 1 and + // turn_on_diff == 1: + // itau ix iy ieta e P T cs^2 ux uy ueta rho_B mu_B Wxx Wxy Wxeta Wyy + // Wyeta pi_b qx qy qeta + // Here ueta = tau*ueta, Wieta = tau*Wieta, Wetaeta = tau^2*Wetaeta, qeta = + // tau*qeta Here Wij is reduced variables Wij/(e+P) in the fluid rest frame // and qi is reduced variables qi/kappa_hat in the fluid rest frame const string out_name_xyeta = "evolution_all_xyeta.dat"; string out_open_mode; @@ -439,65 +439,68 @@ void Cell_info::OutputEvolutionDataXYEta_chun(Fields &arena, double tau) { } out_file_xyeta = fopen(out_name_xyeta.c_str(), out_open_mode.c_str()); - int n_skip_tau = DATA.output_evolution_every_N_timesteps; - double output_dtau = DATA.delta_tau*n_skip_tau; - int itau = static_cast((tau - DATA.tau0)/(output_dtau) + 0.1); + int n_skip_tau = DATA.output_evolution_every_N_timesteps; + double output_dtau = DATA.delta_tau * n_skip_tau; + int itau = static_cast((tau - DATA.tau0) / (output_dtau) + 0.1); - int n_skip_x = DATA.output_evolution_every_N_x; - int n_skip_y = DATA.output_evolution_every_N_y; - int n_skip_eta = DATA.output_evolution_every_N_eta; + int n_skip_x = DATA.output_evolution_every_N_x; + int n_skip_y = DATA.output_evolution_every_N_y; + int n_skip_eta = DATA.output_evolution_every_N_eta; // write out header - const int output_nx = static_cast(arena.nX()/n_skip_x); - const int output_ny = static_cast(arena.nY()/n_skip_y); - const int output_neta = static_cast(arena.nEta()/n_skip_eta); - const double output_dx = DATA.delta_x*n_skip_x; - const double output_dy = DATA.delta_y*n_skip_y; - const double output_deta = DATA.delta_eta*n_skip_eta; - const double output_xmin = - DATA.x_size/2.; - const double output_ymin = - DATA.y_size/2.; - const double output_etamin = - DATA.eta_size/2.; - - const int nVar_per_cell = (11 + DATA.turn_on_rhob*2 + DATA.turn_on_shear*5 - + DATA.turn_on_bulk*1 + DATA.turn_on_diff*3); + const int output_nx = static_cast(arena.nX() / n_skip_x); + const int output_ny = static_cast(arena.nY() / n_skip_y); + const int output_neta = static_cast(arena.nEta() / n_skip_eta); + const double output_dx = DATA.delta_x * n_skip_x; + const double output_dy = DATA.delta_y * n_skip_y; + const double output_deta = DATA.delta_eta * n_skip_eta; + const double output_xmin = -DATA.x_size / 2.; + const double output_ymin = -DATA.y_size / 2.; + const double output_etamin = -DATA.eta_size / 2.; + + const int nVar_per_cell = + (11 + DATA.turn_on_rhob * 2 + DATA.turn_on_shear * 5 + + DATA.turn_on_bulk * 1 + DATA.turn_on_diff * 3); if (tau == DATA.tau0) { - float header[] = { - static_cast(DATA.tau0), static_cast(output_dtau), - static_cast(output_nx), static_cast(output_dx), - static_cast(output_xmin), - static_cast(output_ny), static_cast(output_dy), - static_cast(output_ymin), - static_cast(output_neta), static_cast(output_deta), - static_cast(output_etamin), - static_cast(DATA.turn_on_rhob), - static_cast(DATA.turn_on_shear), - static_cast(DATA.turn_on_bulk), - static_cast(DATA.turn_on_diff), - static_cast(nVar_per_cell)}; + float header[] = {static_cast(DATA.tau0), + static_cast(output_dtau), + static_cast(output_nx), + static_cast(output_dx), + static_cast(output_xmin), + static_cast(output_ny), + static_cast(output_dy), + static_cast(output_ymin), + static_cast(output_neta), + static_cast(output_deta), + static_cast(output_etamin), + static_cast(DATA.turn_on_rhob), + static_cast(DATA.turn_on_shear), + static_cast(DATA.turn_on_bulk), + static_cast(DATA.turn_on_diff), + static_cast(nVar_per_cell)}; fwrite(header, sizeof(float), 16, out_file_xyeta); } std::vector thermalVec; for (int ieta = 0; ieta < arena.nEta(); ieta += n_skip_eta) { - double eta_local = - DATA.eta_size/2. + ieta*DATA.delta_eta; + double eta_local = -DATA.eta_size / 2. + ieta * DATA.delta_eta; double cosh_eta = cosh(eta_local); double sinh_eta = sinh(eta_local); for (int iy = 0; iy < arena.nY(); iy += n_skip_y) { for (int ix = 0; ix < arena.nX(); ix += n_skip_x) { int fieldIdx = arena.getFieldIdx(ix, iy, ieta); - double e_local = arena.e_[fieldIdx]; // 1/fm^4 - double rhob_local = arena.rhob_[fieldIdx]; // 1/fm^3 + double e_local = arena.e_[fieldIdx]; // 1/fm^4 + double rhob_local = arena.rhob_[fieldIdx]; // 1/fm^3 - if (e_local*hbarc < DATA.output_evolution_e_cut) continue; + if (e_local * hbarc < DATA.output_evolution_e_cut) continue; // only ouput fluid cells that are above cut-off temperature // check whether the cells are reaching the grid edges - if (ix == 0 || ix == arena.nX() - 1 - || iy == 0 || iy == arena.nY() - 1) { + if (ix == 0 || ix == arena.nX() - 1 || iy == 0 + || iy == arena.nY() - 1) { std::cout << "Physical cells with e > " << DATA.output_evolution_e_cut << " GeV/fm^3, are reaching the grid edge! " - << "ix = " << ix << ", iy = " << iy - << std::endl; + << "ix = " << ix << ", iy = " << iy << std::endl; exit(-1); } @@ -507,9 +510,9 @@ void Cell_info::OutputEvolutionDataXYEta_chun(Fields &arena, double tau) { double ux = arena.u_[1][fieldIdx]; double uy = arena.u_[2][fieldIdx]; - double uz = ( arena.u_[3][fieldIdx]*cosh_eta - + arena.u_[0][fieldIdx]*sinh_eta); - + double uz = + (arena.u_[3][fieldIdx] * cosh_eta + + arena.u_[0][fieldIdx] * sinh_eta); // T_local is in 1/fm double T_local = thermalVec[6]; @@ -517,8 +520,7 @@ void Cell_info::OutputEvolutionDataXYEta_chun(Fields &arena, double tau) { double muB_local = thermalVec[7]; ShearVisVecLRF piLRF; - get_LRF_shear_stress_tensor(arena, fieldIdx, eta_local, - piLRF); + get_LRF_shear_stress_tensor(arena, fieldIdx, eta_local, piLRF); double div_factor = e_local + p_local; // 1/fm^4 double Wxx = 0.0; double Wxy = 0.0; @@ -526,58 +528,58 @@ void Cell_info::OutputEvolutionDataXYEta_chun(Fields &arena, double tau) { double Wyy = 0.0; double Wyz = 0.0; if (DATA.turn_on_shear == 1) { - Wxx = piLRF[0]/div_factor; - Wxy = piLRF[1]/div_factor; - Wxz = piLRF[2]/div_factor; - Wyy = piLRF[3]/div_factor; - Wyz = piLRF[4]/div_factor; + Wxx = piLRF[0] / div_factor; + Wxy = piLRF[1] / div_factor; + Wxz = piLRF[2] / div_factor; + Wyy = piLRF[3] / div_factor; + Wyz = piLRF[4] / div_factor; } double pi_b = 0.0; if (DATA.turn_on_bulk == 1) { - pi_b = arena.piBulk_[fieldIdx]/div_factor; + pi_b = arena.piBulk_[fieldIdx] / div_factor; } // outputs for baryon diffusion part - //double common_term_q = 0.0; + // double common_term_q = 0.0; double qx = 0.0; double qy = 0.0; double qz = 0.0; if (DATA.turn_on_diff == 1) { - //common_term_q = rhob_local*T_local/div_factor; - double kappa_hat = get_deltaf_qmu_coeff(T_local, - muB_local); - qx = piLRF[5]/kappa_hat; - qy = piLRF[6]/kappa_hat; - qz = piLRF[7]/kappa_hat; + // common_term_q = rhob_local*T_local/div_factor; + double kappa_hat = get_deltaf_qmu_coeff(T_local, muB_local); + qx = piLRF[5] / kappa_hat; + qy = piLRF[6] / kappa_hat; + qz = piLRF[7] / kappa_hat; } - float ideal[] = {static_cast(itau), - static_cast(ix/n_skip_x), - static_cast(iy/n_skip_y), - static_cast(ieta/n_skip_eta), - static_cast(e_local*hbarc), - static_cast(p_local*hbarc), - static_cast(T_local*hbarc), - static_cast(cs2), - static_cast(ux), - static_cast(uy), - static_cast(uz)}; + float ideal[] = { + static_cast(itau), + static_cast(ix / n_skip_x), + static_cast(iy / n_skip_y), + static_cast(ieta / n_skip_eta), + static_cast(e_local * hbarc), + static_cast(p_local * hbarc), + static_cast(T_local * hbarc), + static_cast(cs2), + static_cast(ux), + static_cast(uy), + static_cast(uz)}; fwrite(ideal, sizeof(float), 11, out_file_xyeta); if (DATA.turn_on_rhob == 1) { - float mu[] = {static_cast(rhob_local), - static_cast(muB_local*hbarc)}; + float mu[] = { + static_cast(rhob_local), + static_cast(muB_local * hbarc)}; fwrite(mu, sizeof(float), 2, out_file_xyeta); } if (DATA.turn_on_shear == 1) { - float shear_pi[] = {static_cast(Wxx), - static_cast(Wxy), - static_cast(Wxz), - static_cast(Wyy), - static_cast(Wyz)}; + float shear_pi[] = { + static_cast(Wxx), static_cast(Wxy), + static_cast(Wxz), static_cast(Wyy), + static_cast(Wyz)}; fwrite(shear_pi, sizeof(float), 5, out_file_xyeta); } @@ -587,9 +589,9 @@ void Cell_info::OutputEvolutionDataXYEta_chun(Fields &arena, double tau) { } if (DATA.turn_on_diff == 1) { - float diffusion[] = {static_cast(qx), - static_cast(qy), - static_cast(qz)}; + float diffusion[] = { + static_cast(qx), static_cast(qy), + static_cast(qz)}; fwrite(diffusion, sizeof(float), 3, out_file_xyeta); } } @@ -598,8 +600,8 @@ void Cell_info::OutputEvolutionDataXYEta_chun(Fields &arena, double tau) { fclose(out_file_xyeta); } - -//! This function outputs hydro evolution file in binary format for photon production +//! This function outputs hydro evolution file in binary format for photon +//! production void Cell_info::OutputEvolutionDataXYEta_photon(Fields &arena, double tau) { // volume = tau*dtau*dx*dy*deta // the format of the file is as follows, @@ -636,22 +638,23 @@ void Cell_info::OutputEvolutionDataXYEta_photon(Fields &arena, double tau) { double dx = DATA.delta_x; double dy = DATA.delta_y; double deta = DATA.delta_eta; - double volume = tau*n_skip_tau*dtau*n_skip_x*dx*n_skip_y*dy*n_skip_eta*deta; + double volume = tau * n_skip_tau * dtau * n_skip_x * dx * n_skip_y * dy + * n_skip_eta * deta; for (int ieta = 0; ieta < arena.nEta(); ieta += n_skip_eta) { - double eta_local = - DATA.eta_size/2. + ieta*deta; + double eta_local = -DATA.eta_size / 2. + ieta * deta; for (int iy = 0; iy < arena.nY(); iy += n_skip_y) { for (int ix = 0; ix < arena.nX(); ix += n_skip_x) { int fieldIdx = arena.getFieldIdx(ix, iy, ieta); - double e_local = arena.e_[fieldIdx]; // 1/fm^4 + double e_local = arena.e_[fieldIdx]; // 1/fm^4 - if (e_local*hbarc < DATA.output_evolution_e_cut) continue; + if (e_local * hbarc < DATA.output_evolution_e_cut) continue; // only ouput fluid cells that are above cut-off energy density - double rhob_local = arena.rhob_[fieldIdx]; // 1/fm^3 + double rhob_local = arena.rhob_[fieldIdx]; // 1/fm^3 - double ux = arena.u_[1][fieldIdx]; - double uy = arena.u_[2][fieldIdx]; + double ux = arena.u_[1][fieldIdx]; + double uy = arena.u_[2][fieldIdx]; double ueta = arena.u_[3][fieldIdx]; // T_local is in 1/fm @@ -669,16 +672,16 @@ void Cell_info::OutputEvolutionDataXYEta_photon(Fields &arena, double tau) { double Wyy = 0.0; double Wyeta = 0.0; if (DATA.turn_on_shear == 1) { - Wxx = arena.Wmunu_[4][fieldIdx]/div_factor; - Wxy = arena.Wmunu_[5][fieldIdx]/div_factor; - Wxeta = arena.Wmunu_[6][fieldIdx]/div_factor; - Wyy = arena.Wmunu_[7][fieldIdx]/div_factor; - Wyeta = arena.Wmunu_[8][fieldIdx]/div_factor; + Wxx = arena.Wmunu_[4][fieldIdx] / div_factor; + Wxy = arena.Wmunu_[5][fieldIdx] / div_factor; + Wxeta = arena.Wmunu_[6][fieldIdx] / div_factor; + Wyy = arena.Wmunu_[7][fieldIdx] / div_factor; + Wyeta = arena.Wmunu_[8][fieldIdx] / div_factor; } double pi_b = 0.0; if (DATA.turn_on_bulk == 1) { - pi_b = arena.piBulk_[fieldIdx]; // 1/fm^4 + pi_b = arena.piBulk_[fieldIdx]; // 1/fm^4 } // outputs for baryon diffusion part @@ -687,34 +690,33 @@ void Cell_info::OutputEvolutionDataXYEta_photon(Fields &arena, double tau) { double qy = 0.0; double qeta = 0.0; if (DATA.turn_on_diff == 1) { - common_term_q = rhob_local*T_local/div_factor; - double kappa_hat = get_deltaf_qmu_coeff(T_local, - muB_local); - qx = arena.Wmunu_[11][fieldIdx]/kappa_hat; - qy = arena.Wmunu_[12][fieldIdx]/kappa_hat; - qeta = arena.Wmunu_[13][fieldIdx]/kappa_hat; + common_term_q = rhob_local * T_local / div_factor; + double kappa_hat = get_deltaf_qmu_coeff(T_local, muB_local); + qx = arena.Wmunu_[11][fieldIdx] / kappa_hat; + qy = arena.Wmunu_[12][fieldIdx] / kappa_hat; + qeta = arena.Wmunu_[13][fieldIdx] / kappa_hat; } - float ideal[] = {static_cast(volume), - static_cast(eta_local), - static_cast(T_local*hbarc), - static_cast(ux), - static_cast(uy), - static_cast(ueta)}; + float ideal[] = { + static_cast(volume), + static_cast(eta_local), + static_cast(T_local * hbarc), + static_cast(ux), + static_cast(uy), + static_cast(ueta)}; fwrite(ideal, sizeof(float), 6, out_file_xyeta); if (DATA.turn_on_rhob == 1) { - float mu[] = {static_cast(muB_local*hbarc)}; + float mu[] = {static_cast(muB_local * hbarc)}; fwrite(mu, sizeof(float), 1, out_file_xyeta); } if (DATA.turn_on_shear == 1) { - float shear_pi[] = {static_cast(Wxx), - static_cast(Wxy), - static_cast(Wxeta), - static_cast(Wyy), - static_cast(Wyeta)}; + float shear_pi[] = { + static_cast(Wxx), static_cast(Wxy), + static_cast(Wxeta), static_cast(Wyy), + static_cast(Wyeta)}; fwrite(shear_pi, sizeof(float), 5, out_file_xyeta); } @@ -724,10 +726,10 @@ void Cell_info::OutputEvolutionDataXYEta_photon(Fields &arena, double tau) { } if (DATA.turn_on_diff == 1) { - float diffusion[] = {static_cast(common_term_q), - static_cast(qx), - static_cast(qy), - static_cast(qeta)}; + float diffusion[] = { + static_cast(common_term_q), + static_cast(qx), static_cast(qy), + static_cast(qeta)}; fwrite(diffusion, sizeof(float), 4, out_file_xyeta); } } @@ -736,10 +738,9 @@ void Cell_info::OutputEvolutionDataXYEta_photon(Fields &arena, double tau) { fclose(out_file_xyeta); } - //! This function outputs hydro evolution file in binary format void Cell_info::OutputEvolutionDataXYEta_vorticity( - Fields &arena_curr, Fields &arena_prev, double tau) { + Fields &arena_curr, Fields &arena_prev, double tau) { // the format of the file is as follows, // itau ix iy ieta e P T ux uy ueta mu_B // omega^tx omega^ty omega^tz omega^xy omega^xz omega^yz @@ -754,53 +755,56 @@ void Cell_info::OutputEvolutionDataXYEta_vorticity( } out_file_xyeta = fopen(out_name_xyeta.c_str(), out_open_mode.c_str()); - int n_skip_tau = DATA.output_evolution_every_N_timesteps; - double output_dtau = DATA.delta_tau*n_skip_tau; - int itau = static_cast((tau - DATA.tau0)/(output_dtau) + 0.1); + int n_skip_tau = DATA.output_evolution_every_N_timesteps; + double output_dtau = DATA.delta_tau * n_skip_tau; + int itau = static_cast((tau - DATA.tau0) / (output_dtau) + 0.1); - int n_skip_x = DATA.output_evolution_every_N_x; - int n_skip_y = DATA.output_evolution_every_N_y; + int n_skip_x = DATA.output_evolution_every_N_x; + int n_skip_y = DATA.output_evolution_every_N_y; int n_skip_eta = DATA.output_evolution_every_N_eta; // write out header - const int output_nx = static_cast(arena_curr.nX()/n_skip_x); - const int output_ny = static_cast(arena_curr.nY()/n_skip_y); - const int output_neta = static_cast(arena_curr.nEta()/n_skip_eta); - const double output_dx = DATA.delta_x*n_skip_x; - const double output_dy = DATA.delta_y*n_skip_y; - const double output_deta = DATA.delta_eta*n_skip_eta; - const double output_xmin = - DATA.x_size/2.; - const double output_ymin = - DATA.y_size/2.; - const double output_etamin = - DATA.eta_size/2.; + const int output_nx = static_cast(arena_curr.nX() / n_skip_x); + const int output_ny = static_cast(arena_curr.nY() / n_skip_y); + const int output_neta = static_cast(arena_curr.nEta() / n_skip_eta); + const double output_dx = DATA.delta_x * n_skip_x; + const double output_dy = DATA.delta_y * n_skip_y; + const double output_deta = DATA.delta_eta * n_skip_eta; + const double output_xmin = -DATA.x_size / 2.; + const double output_ymin = -DATA.y_size / 2.; + const double output_etamin = -DATA.eta_size / 2.; const int nVar_per_cell = 35; if (tau == DATA.tau0) { - float header[] = { - static_cast(DATA.tau0), static_cast(output_dtau), - static_cast(output_nx), static_cast(output_dx), - static_cast(output_xmin), - static_cast(output_ny), static_cast(output_dy), - static_cast(output_ymin), - static_cast(output_neta), static_cast(output_deta), - static_cast(output_etamin), - static_cast(nVar_per_cell)}; + float header[] = {static_cast(DATA.tau0), + static_cast(output_dtau), + static_cast(output_nx), + static_cast(output_dx), + static_cast(output_xmin), + static_cast(output_ny), + static_cast(output_dy), + static_cast(output_ymin), + static_cast(output_neta), + static_cast(output_deta), + static_cast(output_etamin), + static_cast(nVar_per_cell)}; fwrite(header, sizeof(float), 12, out_file_xyeta); } for (int ieta = 0; ieta < arena_curr.nEta(); ieta += n_skip_eta) { - double eta_local = - DATA.eta_size/2. + ieta*DATA.delta_eta; + double eta_local = -DATA.eta_size / 2. + ieta * DATA.delta_eta; for (int iy = 0; iy < arena_curr.nY(); iy += n_skip_y) { for (int ix = 0; ix < arena_curr.nX(); ix += n_skip_x) { int fieldIdx = arena_curr.getFieldIdx(ix, iy, ieta); - double e_local = arena_curr.e_[fieldIdx]; // 1/fm^4 - double rhob_local = arena_curr.rhob_[fieldIdx]; // 1/fm^3 - double p_local = eos.get_pressure(e_local, rhob_local); + double e_local = arena_curr.e_[fieldIdx]; // 1/fm^4 + double rhob_local = arena_curr.rhob_[fieldIdx]; // 1/fm^3 + double p_local = eos.get_pressure(e_local, rhob_local); - double ux = arena_curr.u_[1][fieldIdx]; - double uy = arena_curr.u_[2][fieldIdx]; + double ux = arena_curr.u_[1][fieldIdx]; + double uy = arena_curr.u_[2][fieldIdx]; double ueta = arena_curr.u_[3][fieldIdx]; - if (e_local*hbarc < DATA.output_evolution_e_cut) continue; + if (e_local * hbarc < DATA.output_evolution_e_cut) continue; // only ouput fluid cells that are above cut-off energy density // T_local, muB_local are in 1/fm @@ -808,9 +812,9 @@ void Cell_info::OutputEvolutionDataXYEta_vorticity( double muB_local = eos.get_muB(e_local, rhob_local); VorticityVec omega_kSP = {0.0}; - VorticityVec omega_k = {0.0}; - VorticityVec omega_th = {0.0}; - VorticityVec omega_T = {0.0}; + VorticityVec omega_k = {0.0}; + VorticityVec omega_th = {0.0}; + VorticityVec omega_T = {0.0}; VelocityShearVec sigma_munu = {0.0}; DmuMuBoverTVec DbetaMu = {0.0}; u_derivative_helper.compute_vorticity_shell( @@ -818,17 +822,18 @@ void Cell_info::OutputEvolutionDataXYEta_vorticity( eta_local, omega_kSP, omega_k, omega_th, omega_T, sigma_munu, DbetaMu); - float ideal[] = {static_cast(itau), - static_cast(ix/n_skip_x), - static_cast(iy/n_skip_y), - static_cast(ieta/n_skip_eta), - static_cast(e_local*hbarc), - static_cast(p_local*hbarc), - static_cast(T_local*hbarc), - static_cast(ux), - static_cast(uy), - static_cast(ueta), - static_cast(muB_local*hbarc)}; + float ideal[] = { + static_cast(itau), + static_cast(ix / n_skip_x), + static_cast(iy / n_skip_y), + static_cast(ieta / n_skip_eta), + static_cast(e_local * hbarc), + static_cast(p_local * hbarc), + static_cast(T_local * hbarc), + static_cast(ux), + static_cast(uy), + static_cast(ueta), + static_cast(muB_local * hbarc)}; fwrite(ideal, sizeof(float), 11, out_file_xyeta); @@ -836,13 +841,15 @@ void Cell_info::OutputEvolutionDataXYEta_vorticity( for (int i = 0; i < 6; i++) { // no minus sign because it has an opposite sign compared // to kinetic vorticity - vor_vec[i] = static_cast(omega_kSP[i]*hbarc); // GeV + vor_vec[i] = + static_cast(omega_kSP[i] * hbarc); // GeV } fwrite(vor_vec, sizeof(float), 6, out_file_xyeta); for (int i = 0; i < 6; i++) { // the minus sign is from metric // output quantities for g = (1, -1, -1 , -1) - vor_vec[i] = static_cast(-omega_k[i]*hbarc); // GeV + vor_vec[i] = + static_cast(-omega_k[i] * hbarc); // GeV } fwrite(vor_vec, sizeof(float), 6, out_file_xyeta); for (int i = 0; i < 6; i++) { @@ -854,7 +861,8 @@ void Cell_info::OutputEvolutionDataXYEta_vorticity( for (int i = 0; i < 6; i++) { // the minus sign is from metric // output quantities for g = (1, -1, -1 , -1) - vor_vec[i] = static_cast(-omega_T[i]*hbarc*hbarc); // GeV^2 + vor_vec[i] = static_cast( + -omega_T[i] * hbarc * hbarc); // GeV^2 } fwrite(vor_vec, sizeof(float), 6, out_file_xyeta); } @@ -863,33 +871,33 @@ void Cell_info::OutputEvolutionDataXYEta_vorticity( fclose(out_file_xyeta); } - //! This function prints to the screen the maximum local energy density, //! the maximum temperature in the current grid void Cell_info::get_maximum_energy_density( - Fields &arena, double &e_max, double &nB_max, double &Tmax) { - double eps_max = 0.0; + Fields &arena, double &e_max, double &nB_max, double &Tmax) { + double eps_max = 0.0; double rhob_max = 0.0; - double T_max = 0.0; + double T_max = 0.0; // get the grid information const int neta = arena.nEta(); - const int nx = arena.nX(); - const int ny = arena.nY(); + const int nx = arena.nX(); + const int ny = arena.nY(); - #pragma omp parallel for collapse(3) reduction(max:eps_max, rhob_max, T_max) +#pragma omp parallel for collapse(3) reduction(max : eps_max, rhob_max, T_max) for (int ieta = 0; ieta < neta; ieta++) - for (int ix = 0; ix < nx; ix++) - for (int iy = 0; iy < ny; iy++) { - int fieldIdx = arena.getFieldIdx(ix, iy, ieta); - const auto eps_local = arena.e_[fieldIdx]; - const auto rhob_local = arena.rhob_[fieldIdx]; - eps_max = std::max(eps_max, eps_local ); - rhob_max = std::max(rhob_max, rhob_local); - T_max = std::max(T_max, eos.get_temperature(eps_local, rhob_local)); - } - eps_max *= Util::hbarc; // GeV/fm^3 - T_max *= Util::hbarc; // GeV + for (int ix = 0; ix < nx; ix++) + for (int iy = 0; iy < ny; iy++) { + int fieldIdx = arena.getFieldIdx(ix, iy, ieta); + const auto eps_local = arena.e_[fieldIdx]; + const auto rhob_local = arena.rhob_[fieldIdx]; + eps_max = std::max(eps_max, eps_local); + rhob_max = std::max(rhob_max, rhob_local); + T_max = + std::max(T_max, eos.get_temperature(eps_local, rhob_local)); + } + eps_max *= Util::hbarc; // GeV/fm^3 + T_max *= Util::hbarc; // GeV if (eps_max > 1e5) { music_message << "The maximum e = " << eps_max << " < 1e5 GeV/fm^3"; @@ -907,14 +915,13 @@ void Cell_info::get_maximum_energy_density( Tmax = T_max; } - //! This function computes global angular momentum at a give proper time void Cell_info::compute_angular_momentum( - Fields &arena, Fields &arena_prev, const double tau, - const double eta_min, const double eta_max) { + Fields &arena, Fields &arena_prev, const double tau, const double eta_min, + const double eta_max) { ostringstream filename; - filename << "global_angular_momentum_eta_" - << eta_min << "_" << eta_max << ".dat"; + filename << "global_angular_momentum_eta_" << eta_min << "_" << eta_max + << ".dat"; ofstream output_file; if (std::abs(tau - DATA.tau0) < 1e-10) { // create new files at the first time step @@ -923,97 +930,101 @@ void Cell_info::compute_angular_momentum( << "L^{tx}[hbarc] L^{ty}[hbarc] L^{tz}[hbarc]" << std::endl; } else { - output_file.open(filename.str().c_str(), - std::fstream::out | std::fstream::app); + output_file.open( + filename.str().c_str(), std::fstream::out | std::fstream::app); } - double Lx = 0.0; - double Ly = 0.0; - double Lz = 0.0; + double Lx = 0.0; + double Ly = 0.0; + double Lz = 0.0; double Ltx = 0.0; double Lty = 0.0; double Ltz = 0.0; const double deta = DATA.delta_eta; - const double dx = DATA.delta_x; - const double dy = DATA.delta_y; + const double dx = DATA.delta_x; + const double dy = DATA.delta_y; const int neta = arena.nEta(); - const int nx = arena.nX(); - const int ny = arena.nY(); - #pragma omp parallel for collapse(3) reduction(+:Lx, Ly, Lz, Ltx, Lty, Ltz) + const int nx = arena.nX(); + const int ny = arena.nY(); +#pragma omp parallel for collapse(3) reduction(+ : Lx, Ly, Lz, Ltx, Lty, Ltz) for (int ieta = 0; ieta < neta; ieta++) - for (int ix = 0; ix < nx; ix++) - for (int iy = 0; iy < ny; iy++) { - const int Idx = arena.getFieldIdx(ix, iy, ieta); + for (int ix = 0; ix < nx; ix++) + for (int iy = 0; iy < ny; iy++) { + const int Idx = arena.getFieldIdx(ix, iy, ieta); - double eta_s = deta*ieta - (DATA.eta_size)/2.0; - if (DATA.boost_invariant) { - eta_s = 0.0; - } + double eta_s = deta * ieta - (DATA.eta_size) / 2.0; + if (DATA.boost_invariant) { + eta_s = 0.0; + } - const double cosh_eta = cosh(eta_s); - const double sinh_eta = sinh(eta_s); - const double t_local = tau*cosh_eta; - const double x_local = DATA.x_size/2. + ix*dx; - const double y_local = DATA.x_size/2. + iy*dy; - const double z_local = tau*sinh_eta; - - const double e_local = arena.e_[Idx]; - const double pressure = eos.get_pressure(e_local, arena.rhob_[Idx]); - const double u0 = arena.u_[0][Idx]; - const double u1 = arena.u_[1][Idx]; - const double u2 = arena.u_[2][Idx]; - const double u3 = arena.u_[3][Idx]; - const double uPrev0 = arena_prev.u_[0][Idx]; - const double uPrev1 = arena_prev.u_[1][Idx]; - const double uPrev2 = arena_prev.u_[2][Idx]; - const double uPrev3 = arena_prev.u_[3][Idx]; - - const double T00_local = (e_local + pressure)*u0*u0 - pressure; - const double Pi00_rk_0 = arena_prev.piBulk_[Idx]*(-1. + uPrev0*uPrev0); - - const double T_tau_tau = (T00_local - + arena_prev.Wmunu_[0][Idx] + Pi00_rk_0); - const double T_tau_x = ( - (e_local + pressure)*u0*u1 + arena_prev.Wmunu_[1][Idx] - + arena_prev.piBulk_[Idx]*uPrev0*uPrev1); - const double T_tau_y = ( - (e_local + pressure)*u0*u2 + arena_prev.Wmunu_[2][Idx] - + arena_prev.piBulk_[Idx]*uPrev0*uPrev2); - const double T_tau_eta = ( - (e_local + pressure)*u0*u3 + arena_prev.Wmunu_[3][Idx] - + arena_prev.piBulk_[Idx]*uPrev0*uPrev3); - const double T_tau_t = T_tau_tau*cosh_eta + T_tau_eta*sinh_eta; - const double T_tau_z = T_tau_tau*sinh_eta + T_tau_eta*cosh_eta; - - if (eta_s < eta_max && eta_s > eta_min) { - Lx += (y_local*T_tau_z - z_local*T_tau_y); - Ly += (z_local*T_tau_x - x_local*T_tau_z); - Lz += (x_local*T_tau_y - y_local*T_tau_x); - Ltx += (t_local*T_tau_x - x_local*T_tau_t); - Lty += (t_local*T_tau_y - y_local*T_tau_t); - Ltz += (t_local*T_tau_z - z_local*T_tau_t); - } - } + const double cosh_eta = cosh(eta_s); + const double sinh_eta = sinh(eta_s); + const double t_local = tau * cosh_eta; + const double x_local = DATA.x_size / 2. + ix * dx; + const double y_local = DATA.x_size / 2. + iy * dy; + const double z_local = tau * sinh_eta; + + const double e_local = arena.e_[Idx]; + const double pressure = + eos.get_pressure(e_local, arena.rhob_[Idx]); + const double u0 = arena.u_[0][Idx]; + const double u1 = arena.u_[1][Idx]; + const double u2 = arena.u_[2][Idx]; + const double u3 = arena.u_[3][Idx]; + const double uPrev0 = arena_prev.u_[0][Idx]; + const double uPrev1 = arena_prev.u_[1][Idx]; + const double uPrev2 = arena_prev.u_[2][Idx]; + const double uPrev3 = arena_prev.u_[3][Idx]; + + const double T00_local = + (e_local + pressure) * u0 * u0 - pressure; + const double Pi00_rk_0 = + arena_prev.piBulk_[Idx] * (-1. + uPrev0 * uPrev0); + + const double T_tau_tau = + (T00_local + arena_prev.Wmunu_[0][Idx] + Pi00_rk_0); + const double T_tau_x = + ((e_local + pressure) * u0 * u1 + arena_prev.Wmunu_[1][Idx] + + arena_prev.piBulk_[Idx] * uPrev0 * uPrev1); + const double T_tau_y = + ((e_local + pressure) * u0 * u2 + arena_prev.Wmunu_[2][Idx] + + arena_prev.piBulk_[Idx] * uPrev0 * uPrev2); + const double T_tau_eta = + ((e_local + pressure) * u0 * u3 + arena_prev.Wmunu_[3][Idx] + + arena_prev.piBulk_[Idx] * uPrev0 * uPrev3); + const double T_tau_t = + T_tau_tau * cosh_eta + T_tau_eta * sinh_eta; + const double T_tau_z = + T_tau_tau * sinh_eta + T_tau_eta * cosh_eta; + + if (eta_s < eta_max && eta_s > eta_min) { + Lx += (y_local * T_tau_z - z_local * T_tau_y); + Ly += (z_local * T_tau_x - x_local * T_tau_z); + Lz += (x_local * T_tau_y - y_local * T_tau_x); + Ltx += (t_local * T_tau_x - x_local * T_tau_t); + Lty += (t_local * T_tau_y - y_local * T_tau_t); + Ltz += (t_local * T_tau_z - z_local * T_tau_t); + } + } // add units - double factor = tau*dx*dy*deta; - Lx *= factor; - Ly *= factor; - Lz *= factor; + double factor = tau * dx * dy * deta; + Lx *= factor; + Ly *= factor; + Lz *= factor; Ltx *= factor; Lty *= factor; Ltz *= factor; // output results - output_file << scientific << setprecision(6) - << tau << " " << Lx << " " << Ly << " " << Lz << " " - << Ltx << " " << Lty << " " << Ltz << std::endl; + output_file << scientific << setprecision(6) << tau << " " << Lx << " " + << Ly << " " << Lz << " " << Ltx << " " << Lty << " " << Ltz + << std::endl; output_file.close(); } - //! This function checks the total energy and total net baryon number //! at a give proper time -void Cell_info::check_conservation_law(Fields &arena, Fields &arena_prev, - const double tau) { +void Cell_info::check_conservation_law( + Fields &arena, Fields &arena_prev, const double tau) { std::string filename = "global_conservation_laws.dat"; ofstream output_file; if (std::abs(tau - DATA.tau0) < 1e-10) { @@ -1021,90 +1032,96 @@ void Cell_info::check_conservation_law(Fields &arena, Fields &arena_prev, output_file << "# tau(fm) E(GeV) Px(GeV) Py(GeV) Pz(GeV) N_B " << std::endl; } else { - output_file.open(filename.c_str(), - std::fstream::out | std::fstream::app); + output_file.open( + filename.c_str(), std::fstream::out | std::fstream::app); } - double N_B = 0.0; + double N_B = 0.0; double T_tau_t = 0.0; double T_tau_x = 0.0; double T_tau_y = 0.0; double T_tau_z = 0.0; - double N_B_edge = 0.0; + double N_B_edge = 0.0; double T_tau_t_edge = 0.0; double T_tau_x_edge = 0.0; double T_tau_y_edge = 0.0; double T_tau_z_edge = 0.0; - double deta = DATA.delta_eta; - double dx = DATA.delta_x; - double dy = DATA.delta_y; + double deta = DATA.delta_eta; + double dx = DATA.delta_x; + double dy = DATA.delta_y; const int neta = arena.nEta(); - const int nx = arena.nX(); - const int ny = arena.nY(); + const int nx = arena.nX(); + const int ny = arena.nY(); - #pragma omp parallel for collapse(3) reduction(+:N_B, T_tau_t, T_tau_x, T_tau_y, T_tau_z, N_B_edge, T_tau_t_edge, T_tau_x_edge, T_tau_y_edge, T_tau_z_edge) +#pragma omp parallel for collapse(3) reduction( \ + + : N_B, T_tau_t, T_tau_x, T_tau_y, T_tau_z, N_B_edge, T_tau_t_edge, \ + T_tau_x_edge, T_tau_y_edge, T_tau_z_edge) for (int ieta = 0; ieta < neta; ieta++) - for (int ix = 0; ix < nx; ix++) - for (int iy = 0; iy < ny; iy++) { - const int Idx = arena.getFieldIdx(ix, iy, ieta); - - const double eta_s = deta*ieta - (DATA.eta_size)/2.0; - const double cosh_eta = cosh(eta_s); - const double sinh_eta = sinh(eta_s); - - N_B += arena.rhob_[Idx]*arena.u_[0][Idx] + arena_prev.Wmunu_[10][Idx]; - const double e_local = arena.e_[Idx]; - const double pressure = eos.get_pressure(e_local, arena.rhob_[Idx]); - const double u0 = arena.u_[0][Idx]; - const double u1 = arena.u_[1][Idx]; - const double u2 = arena.u_[2][Idx]; - const double u3 = arena.u_[3][Idx]; - const double uPrev0 = arena_prev.u_[0][Idx]; - const double uPrev1 = arena_prev.u_[1][Idx]; - const double uPrev2 = arena_prev.u_[2][Idx]; - const double uPrev3 = arena_prev.u_[3][Idx]; - const double T00_local = (e_local + pressure)*u0*u0 - pressure; - const double Pi00_rk_0 = (arena_prev.piBulk_[Idx] - *(-1.0 + arena_prev.u_[0][Idx] - *arena_prev.u_[0][Idx])); - - const double T_tau_tau = (T00_local - + arena_prev.Wmunu_[0][Idx] + Pi00_rk_0); - const double T01_local = ( - (e_local + pressure)*u0*u1 + arena_prev.Wmunu_[1][Idx] - + arena_prev.piBulk_[Idx]*uPrev0*uPrev1); - const double T02_local = ( - (e_local + pressure)*u0*u2 + arena_prev.Wmunu_[2][Idx] - + arena_prev.piBulk_[Idx]*uPrev0*uPrev2); - const double T_tau_eta = ( - (e_local + pressure)*u0*u3 + arena_prev.Wmunu_[3][Idx] - + arena_prev.piBulk_[Idx]*uPrev0*uPrev3); - T_tau_t += T_tau_tau*cosh_eta + T_tau_eta*sinh_eta; - T_tau_x += T01_local; - T_tau_y += T02_local; - T_tau_z += T_tau_tau*sinh_eta + T_tau_eta*cosh_eta; - - // compute the energy-momentum vector on the edge - if (ieta == 0 || ieta == neta - 1 || ix == 0 || ix == nx - 1 - || iy == 0 || iy == ny - 1) { - N_B_edge += arena.rhob_[Idx]*u0 + arena_prev.Wmunu_[10][Idx]; - T_tau_t_edge += T_tau_tau*cosh_eta + T_tau_eta*sinh_eta; - T_tau_x_edge += T01_local; - T_tau_y_edge += T02_local; - T_tau_z_edge += T_tau_tau*sinh_eta + T_tau_eta*cosh_eta; - } - } + for (int ix = 0; ix < nx; ix++) + for (int iy = 0; iy < ny; iy++) { + const int Idx = arena.getFieldIdx(ix, iy, ieta); + + const double eta_s = deta * ieta - (DATA.eta_size) / 2.0; + const double cosh_eta = cosh(eta_s); + const double sinh_eta = sinh(eta_s); + + N_B += arena.rhob_[Idx] * arena.u_[0][Idx] + + arena_prev.Wmunu_[10][Idx]; + const double e_local = arena.e_[Idx]; + const double pressure = + eos.get_pressure(e_local, arena.rhob_[Idx]); + const double u0 = arena.u_[0][Idx]; + const double u1 = arena.u_[1][Idx]; + const double u2 = arena.u_[2][Idx]; + const double u3 = arena.u_[3][Idx]; + const double uPrev0 = arena_prev.u_[0][Idx]; + const double uPrev1 = arena_prev.u_[1][Idx]; + const double uPrev2 = arena_prev.u_[2][Idx]; + const double uPrev3 = arena_prev.u_[3][Idx]; + const double T00_local = + (e_local + pressure) * u0 * u0 - pressure; + const double Pi00_rk_0 = + (arena_prev.piBulk_[Idx] + * (-1.0 + arena_prev.u_[0][Idx] * arena_prev.u_[0][Idx])); + + const double T_tau_tau = + (T00_local + arena_prev.Wmunu_[0][Idx] + Pi00_rk_0); + const double T01_local = + ((e_local + pressure) * u0 * u1 + arena_prev.Wmunu_[1][Idx] + + arena_prev.piBulk_[Idx] * uPrev0 * uPrev1); + const double T02_local = + ((e_local + pressure) * u0 * u2 + arena_prev.Wmunu_[2][Idx] + + arena_prev.piBulk_[Idx] * uPrev0 * uPrev2); + const double T_tau_eta = + ((e_local + pressure) * u0 * u3 + arena_prev.Wmunu_[3][Idx] + + arena_prev.piBulk_[Idx] * uPrev0 * uPrev3); + T_tau_t += T_tau_tau * cosh_eta + T_tau_eta * sinh_eta; + T_tau_x += T01_local; + T_tau_y += T02_local; + T_tau_z += T_tau_tau * sinh_eta + T_tau_eta * cosh_eta; + + // compute the energy-momentum vector on the edge + if (ieta == 0 || ieta == neta - 1 || ix == 0 || ix == nx - 1 + || iy == 0 || iy == ny - 1) { + N_B_edge += + arena.rhob_[Idx] * u0 + arena_prev.Wmunu_[10][Idx]; + T_tau_t_edge += T_tau_tau * cosh_eta + T_tau_eta * sinh_eta; + T_tau_x_edge += T01_local; + T_tau_y_edge += T02_local; + T_tau_z_edge += T_tau_tau * sinh_eta + T_tau_eta * cosh_eta; + } + } // add units - double factor = tau*dx*dy*deta; + double factor = tau * dx * dy * deta; N_B *= factor; - T_tau_t *= factor*Util::hbarc; // GeV - T_tau_x *= factor*Util::hbarc; // GeV - T_tau_y *= factor*Util::hbarc; // GeV - T_tau_z *= factor*Util::hbarc; // GeV + T_tau_t *= factor * Util::hbarc; // GeV + T_tau_x *= factor * Util::hbarc; // GeV + T_tau_y *= factor * Util::hbarc; // GeV + T_tau_z *= factor * Util::hbarc; // GeV N_B_edge *= factor; - T_tau_t_edge *= factor*Util::hbarc; // GeV - T_tau_x_edge *= factor*Util::hbarc; // GeV - T_tau_y_edge *= factor*Util::hbarc; // GeV - T_tau_z_edge *= factor*Util::hbarc; // GeV + T_tau_t_edge *= factor * Util::hbarc; // GeV + T_tau_x_edge *= factor * Util::hbarc; // GeV + T_tau_y_edge *= factor * Util::hbarc; // GeV + T_tau_z_edge *= factor * Util::hbarc; // GeV // compute the outflow flux if (tau > DATA.tau0) { @@ -1114,7 +1131,7 @@ void Cell_info::check_conservation_law(Fields &arena, Fields &arena_prev, outflow_flux[3] += T_tau_z_edge - Pmu_edge_prev[3]; outflow_flux[4] += N_B_edge - Pmu_edge_prev[4]; - N_B += outflow_flux[4]; + N_B += outflow_flux[4]; T_tau_t += outflow_flux[0]; // GeV T_tau_x += outflow_flux[1]; // GeV T_tau_y += outflow_flux[2]; // GeV @@ -1138,19 +1155,18 @@ void Cell_info::check_conservation_law(Fields &arena, Fields &arena_prev, music_message.flush("error"); exit(1); } - output_file << scientific << setprecision(6) - << tau << " " << T_tau_t << " " << T_tau_x << " " - << T_tau_y << " " << T_tau_z << " " << N_B << std::endl; + output_file << scientific << setprecision(6) << tau << " " << T_tau_t + << " " << T_tau_x << " " << T_tau_y << " " << T_tau_z << " " + << N_B << std::endl; output_file.close(); } - //! This function putputs files to check with Gubser flow solution void Cell_info::Gubser_flow_check_file(Fields &arena, const double tau) { if (tau > 1.) { ostringstream filename_analytic; - filename_analytic << "tests/Gubser_flow/y=x_tau=" - << tau << "_SemiAnalytic.dat"; + filename_analytic << "tests/Gubser_flow/y=x_tau=" << tau + << "_SemiAnalytic.dat"; double T_analytic[201], ux_analytic[201], uy_analytic[201]; double pixx_analytic[201], pixy_analytic[201]; @@ -1159,57 +1175,55 @@ void Cell_info::Gubser_flow_check_file(Fields &arena, const double tau) { std::ifstream input_file(filename_analytic.str().c_str()); for (int i = 0; i < 201; i++) { input_file >> dummy >> dummy >> T_analytic[i] >> ux_analytic[i] - >> uy_analytic[i] >> pixx_analytic[i] - >> piyy_analytic[i] >> pixy_analytic[i] - >> pizz_analytic[i]; + >> uy_analytic[i] >> pixx_analytic[i] >> piyy_analytic[i] + >> pixy_analytic[i] >> pizz_analytic[i]; } input_file.close(); - double T_diff = 0.0; - double ux_diff = 0.0; - double uy_diff = 0.0; + double T_diff = 0.0; + double ux_diff = 0.0; + double uy_diff = 0.0; double pixx_diff = 0.0; double pixy_diff = 0.0; double piyy_diff = 0.0; double pizz_diff = 0.0; - double T_sum = 0.0; - double ux_sum = 0.0; - double uy_sum = 0.0; - double pixx_sum = 0.0; - double pixy_sum = 0.0; - double piyy_sum = 0.0; - double pizz_sum = 0.0; + double T_sum = 0.0; + double ux_sum = 0.0; + double uy_sum = 0.0; + double pixx_sum = 0.0; + double pixy_sum = 0.0; + double piyy_sum = 0.0; + double pizz_sum = 0.0; for (int i = 0; i < arena.nX(); i++) { int fieldIdx = arena.getFieldIdx(i, i, 0); double e_local = arena.e_[fieldIdx]; - double T_local = ( - eos.get_temperature(e_local, 0.0)*Util::hbarc); + double T_local = (eos.get_temperature(e_local, 0.0) * Util::hbarc); T_diff += fabs(T_analytic[i] - T_local); T_sum += fabs(T_analytic[i]); ux_diff += fabs(ux_analytic[i] - arena.u_[1][fieldIdx]); ux_sum += fabs(ux_analytic[i]); uy_diff += fabs(uy_analytic[i] - arena.u_[2][fieldIdx]); uy_sum += fabs(uy_analytic[i]); - pixx_diff += (fabs(pixx_analytic[i] - - arena.Wmunu_[4][fieldIdx]*Util::hbarc)); + pixx_diff += (fabs( + pixx_analytic[i] - arena.Wmunu_[4][fieldIdx] * Util::hbarc)); pixx_sum += fabs(pixx_analytic[i]); - pixy_diff += (fabs(pixx_analytic[i] - - arena.Wmunu_[5][fieldIdx]*Util::hbarc)); + pixy_diff += (fabs( + pixx_analytic[i] - arena.Wmunu_[5][fieldIdx] * Util::hbarc)); pixy_sum += fabs(pixx_analytic[i]); - piyy_diff += (fabs(piyy_analytic[i] - - arena.Wmunu_[7][fieldIdx]*Util::hbarc)); + piyy_diff += (fabs( + piyy_analytic[i] - arena.Wmunu_[7][fieldIdx] * Util::hbarc)); piyy_sum += fabs(piyy_analytic[i]); - pizz_diff += (fabs(pizz_analytic[i] - - arena.Wmunu_[9][fieldIdx]*Util::hbarc)); + pizz_diff += (fabs( + pizz_analytic[i] - arena.Wmunu_[9][fieldIdx] * Util::hbarc)); pizz_sum += fabs(pizz_analytic[i]); } - music_message << "Autocheck: T_diff = " << T_diff/T_sum - << ", ux_diff = " << ux_diff/ux_sum - << ", uy_diff = " << uy_diff/uy_sum - << ", pixx_diff = " << pixx_diff/pixx_sum - << ", pixy_diff = " << pixy_diff/pixy_sum - << ", piyy_diff = " << piyy_diff/piyy_sum - << ", pizz_diff = " << pizz_diff/pizz_sum; + music_message << "Autocheck: T_diff = " << T_diff / T_sum + << ", ux_diff = " << ux_diff / ux_sum + << ", uy_diff = " << uy_diff / uy_sum + << ", pixx_diff = " << pixx_diff / pixx_sum + << ", pixy_diff = " << pixy_diff / pixy_sum + << ", piyy_diff = " << piyy_diff / piyy_sum + << ", pizz_diff = " << pizz_diff / pizz_sum; music_message.flush("info"); } @@ -1218,33 +1232,31 @@ void Cell_info::Gubser_flow_check_file(Fields &arena, const double tau) { ofstream output_file(filename.str().c_str()); double dx = DATA.delta_x; - double x_min = -DATA.x_size/2.; + double x_min = -DATA.x_size / 2.; double dy = DATA.delta_y; - double y_min = -DATA.y_size/2.; + double y_min = -DATA.y_size / 2.; for (int ix = 0; ix < arena.nX(); ix++) - for (int iy = 0; iy < arena.nY(); iy++) { - double x_local = x_min + ix*dx; - double y_local = y_min + iy*dy; - int fieldIdx = arena.getFieldIdx(ix, iy, 0); - double e_local = arena.e_[fieldIdx]; - double rhob_local = arena.rhob_[fieldIdx]; - double T_local = eos.get_temperature(e_local, 0.0); - output_file << scientific << setprecision(8) << setw(18) - << x_local << " " << y_local << " " - << e_local*Util::hbarc << " " << rhob_local << " " - << T_local*Util::hbarc << " " - << arena.u_[1][fieldIdx] << " " - << arena.u_[2][fieldIdx] << " " - << arena.Wmunu_[4][fieldIdx]*Util::hbarc << " " - << arena.Wmunu_[7][fieldIdx]*Util::hbarc << " " - << arena.Wmunu_[5][fieldIdx]*Util::hbarc << " " - << arena.Wmunu_[9][fieldIdx]*Util::hbarc << " " - << endl; - } + for (int iy = 0; iy < arena.nY(); iy++) { + double x_local = x_min + ix * dx; + double y_local = y_min + iy * dy; + int fieldIdx = arena.getFieldIdx(ix, iy, 0); + double e_local = arena.e_[fieldIdx]; + double rhob_local = arena.rhob_[fieldIdx]; + double T_local = eos.get_temperature(e_local, 0.0); + output_file << scientific << setprecision(8) << setw(18) << x_local + << " " << y_local << " " << e_local * Util::hbarc + << " " << rhob_local << " " << T_local * Util::hbarc + << " " << arena.u_[1][fieldIdx] << " " + << arena.u_[2][fieldIdx] << " " + << arena.Wmunu_[4][fieldIdx] * Util::hbarc << " " + << arena.Wmunu_[7][fieldIdx] * Util::hbarc << " " + << arena.Wmunu_[5][fieldIdx] * Util::hbarc << " " + << arena.Wmunu_[9][fieldIdx] * Util::hbarc << " " + << endl; + } output_file.close(); } - //! This function outputs files to cross check with 1+1D simulation void Cell_info::output_1p1D_check_file(Fields &arena, const double tau) { ostringstream filename; @@ -1254,19 +1266,17 @@ void Cell_info::output_1p1D_check_file(Fields &arena, const double tau) { double deta = DATA.delta_eta; double eta_min = -6.94; for (int ieta = 0; ieta < arena.nEta(); ieta++) { - double eta_local = eta_min + ieta*deta; + double eta_local = eta_min + ieta * deta; int fieldIdx = arena.getFieldIdx(1, 1, ieta); double e_local = arena.e_[fieldIdx]; double rhob_local = arena.rhob_[fieldIdx]; - output_file << scientific << setprecision(8) << setw(18) - << eta_local << " " - << e_local*Util::hbarc << " " << rhob_local + output_file << scientific << setprecision(8) << setw(18) << eta_local + << " " << e_local * Util::hbarc << " " << rhob_local << endl; } output_file.close(); } - //! This function outputs energy density and n_b for making movies void Cell_info::output_evolution_for_movie(Fields &arena, const double tau) { const string out_name_xyeta = "evolution_for_movie_xyeta.dat"; @@ -1281,87 +1291,91 @@ void Cell_info::output_evolution_for_movie(Fields &arena, const double tau) { out_file_xyeta = fopen(out_name_xyeta.c_str(), out_open_mode.c_str()); int n_skip_tau = DATA.output_evolution_every_N_timesteps; - double output_dtau = DATA.delta_tau*n_skip_tau; - int itau = static_cast((tau - DATA.tau0)/(output_dtau) + 0.1); + double output_dtau = DATA.delta_tau * n_skip_tau; + int itau = static_cast((tau - DATA.tau0) / (output_dtau) + 0.1); - int n_skip_x = DATA.output_evolution_every_N_x; - int n_skip_y = DATA.output_evolution_every_N_y; + int n_skip_x = DATA.output_evolution_every_N_x; + int n_skip_y = DATA.output_evolution_every_N_y; int n_skip_eta = DATA.output_evolution_every_N_eta; - double dx = DATA.delta_x; - double dy = DATA.delta_y; - double deta = DATA.delta_eta; - double volume = tau*output_dtau*n_skip_x*dx*n_skip_y*dy*n_skip_eta*deta; + double dx = DATA.delta_x; + double dy = DATA.delta_y; + double deta = DATA.delta_eta; + double volume = + tau * output_dtau * n_skip_x * dx * n_skip_y * dy * n_skip_eta * deta; const int nVar_per_cell = 14; if (tau == DATA.tau0) { // write out header - const int output_nx = static_cast(arena.nX()/n_skip_x); - const int output_ny = static_cast(arena.nY()/n_skip_y); - const int output_neta = ( - std::max(1, static_cast(arena.nEta()/n_skip_eta))); - const double output_dx = DATA.delta_x*n_skip_x; - const double output_dy = DATA.delta_y*n_skip_y; - const double output_deta = DATA.delta_eta*n_skip_eta; - const double output_xmin = - DATA.x_size/2.; - const double output_ymin = - DATA.y_size/2.; - const double output_etamin = - DATA.eta_size/2.; - float header[] = { - static_cast(DATA.tau0), static_cast(output_dtau), - static_cast(output_nx), static_cast(output_dx), - static_cast(output_xmin), - static_cast(output_ny), static_cast(output_dy), - static_cast(output_ymin), - static_cast(output_neta), static_cast(output_deta), - static_cast(output_etamin), - static_cast(nVar_per_cell)}; + const int output_nx = static_cast(arena.nX() / n_skip_x); + const int output_ny = static_cast(arena.nY() / n_skip_y); + const int output_neta = + (std::max(1, static_cast(arena.nEta() / n_skip_eta))); + const double output_dx = DATA.delta_x * n_skip_x; + const double output_dy = DATA.delta_y * n_skip_y; + const double output_deta = DATA.delta_eta * n_skip_eta; + const double output_xmin = -DATA.x_size / 2.; + const double output_ymin = -DATA.y_size / 2.; + const double output_etamin = -DATA.eta_size / 2.; + float header[] = {static_cast(DATA.tau0), + static_cast(output_dtau), + static_cast(output_nx), + static_cast(output_dx), + static_cast(output_xmin), + static_cast(output_ny), + static_cast(output_dy), + static_cast(output_ymin), + static_cast(output_neta), + static_cast(output_deta), + static_cast(output_etamin), + static_cast(nVar_per_cell)}; fwrite(header, sizeof(float), 12, out_file_xyeta); } for (int ieta = 0; ieta < arena.nEta(); ieta += n_skip_eta) { - double eta_local = - DATA.eta_size/2. + ieta*deta; + double eta_local = -DATA.eta_size / 2. + ieta * deta; if (DATA.boost_invariant) eta_local = 0.; for (int iy = 0; iy < arena.nY(); iy += n_skip_y) { for (int ix = 0; ix < arena.nX(); ix += n_skip_x) { int fieldIdx = arena.getFieldIdx(ix, iy, ieta); - double e_local = arena.e_[fieldIdx]; // 1/fm^4 - double rhob_local = arena.rhob_[fieldIdx]; // 1/fm^3 + double e_local = arena.e_[fieldIdx]; // 1/fm^4 + double rhob_local = arena.rhob_[fieldIdx]; // 1/fm^3 // T_local is in 1/fm - double T_local = eos.get_temperature(e_local, rhob_local); - if (T_local*hbarc < DATA.output_evolution_T_cut) continue; + double T_local = eos.get_temperature(e_local, rhob_local); + if (T_local * hbarc < DATA.output_evolution_T_cut) continue; double muB_local = eos.get_muB(e_local, rhob_local); // 1/fm - double pressure = eos.get_pressure(e_local, rhob_local); - double u0 = arena.u_[0][fieldIdx]; - double u1 = arena.u_[1][fieldIdx]; - double u2 = arena.u_[2][fieldIdx]; - double u3 = arena.u_[3][fieldIdx]; - double T00_ideal = (e_local + pressure)*u0*u0 - pressure; - double T03_ideal = (e_local + pressure)*u0*u3; - double Pi00 = arena.piBulk_[fieldIdx]*(-1.0 + u0*u0); - double Pi03 = arena.piBulk_[fieldIdx]*u0*u3; - double T00_full = ( T00_ideal - + arena.Wmunu_[0][fieldIdx] + Pi00); - double T03_full = ( T03_ideal - + arena.Wmunu_[3][fieldIdx] + Pi03); - double Ttaut = ( T00_full*cosh(eta_local) - + T03_full*sinh(eta_local)); - double JBtau = ( rhob_local*u0 - + arena.Wmunu_[10][fieldIdx]); - float array[] = {static_cast(itau), - static_cast(ix/n_skip_x), - static_cast(iy/n_skip_y), - static_cast(ieta/n_skip_eta), - static_cast(volume), - static_cast(e_local*hbarc), - static_cast(rhob_local), - static_cast(T_local*hbarc), - static_cast(muB_local*hbarc), - static_cast(u1), - static_cast(u2), - static_cast(u3), - static_cast(Ttaut*hbarc), - static_cast(JBtau)}; + double pressure = eos.get_pressure(e_local, rhob_local); + double u0 = arena.u_[0][fieldIdx]; + double u1 = arena.u_[1][fieldIdx]; + double u2 = arena.u_[2][fieldIdx]; + double u3 = arena.u_[3][fieldIdx]; + double T00_ideal = (e_local + pressure) * u0 * u0 - pressure; + double T03_ideal = (e_local + pressure) * u0 * u3; + double Pi00 = arena.piBulk_[fieldIdx] * (-1.0 + u0 * u0); + double Pi03 = arena.piBulk_[fieldIdx] * u0 * u3; + double T00_full = + (T00_ideal + arena.Wmunu_[0][fieldIdx] + Pi00); + double T03_full = + (T03_ideal + arena.Wmunu_[3][fieldIdx] + Pi03); + double Ttaut = + (T00_full * cosh(eta_local) + T03_full * sinh(eta_local)); + double JBtau = (rhob_local * u0 + arena.Wmunu_[10][fieldIdx]); + float array[] = { + static_cast(itau), + static_cast(ix / n_skip_x), + static_cast(iy / n_skip_y), + static_cast(ieta / n_skip_eta), + static_cast(volume), + static_cast(e_local * hbarc), + static_cast(rhob_local), + static_cast(T_local * hbarc), + static_cast(muB_local * hbarc), + static_cast(u1), + static_cast(u2), + static_cast(u3), + static_cast(Ttaut * hbarc), + static_cast(JBtau)}; fwrite(array, sizeof(float), 14, out_file_xyeta); } } @@ -1369,36 +1383,34 @@ void Cell_info::output_evolution_for_movie(Fields &arena, const double tau) { fclose(out_file_xyeta); } - //! This function dumps the energy density and net baryon density -void Cell_info::output_energy_density_and_rhob_disitrubtion(Fields &arena, - string filename) { +void Cell_info::output_energy_density_and_rhob_disitrubtion( + Fields &arena, string filename) { ofstream output_file(filename.c_str()); - const int n_skip_x = DATA.output_evolution_every_N_x; - const int n_skip_y = DATA.output_evolution_every_N_y; + const int n_skip_x = DATA.output_evolution_every_N_x; + const int n_skip_y = DATA.output_evolution_every_N_y; const int n_skip_eta = DATA.output_evolution_every_N_eta; for (int ieta = 0; ieta < arena.nEta(); ieta += n_skip_eta) - for (int ix = 0; ix < arena.nX(); ix += n_skip_x) - for (int iy = 0; iy < arena.nY(); iy += n_skip_y) { - int fieldIdx = arena.getFieldIdx(ix, iy, ieta); - double e_local = arena.e_[fieldIdx]*Util::hbarc; - double rhob_local = arena.rhob_[fieldIdx]; - output_file << scientific << setprecision(5) << setw(18) - << e_local << " " << rhob_local << endl; - } + for (int ix = 0; ix < arena.nX(); ix += n_skip_x) + for (int iy = 0; iy < arena.nY(); iy += n_skip_y) { + int fieldIdx = arena.getFieldIdx(ix, iy, ieta); + double e_local = arena.e_[fieldIdx] * Util::hbarc; + double rhob_local = arena.rhob_[fieldIdx]; + output_file << scientific << setprecision(5) << setw(18) + << e_local << " " << rhob_local << endl; + } output_file.close(); } - //! This function outputs the evolution of hydrodynamic variables at a //! give fluid cell -void Cell_info::monitor_a_fluid_cell(Fields &arena_curr, Fields &arena_prev, - const int ix, const int iy, - const int ieta, const double tau) { +void Cell_info::monitor_a_fluid_cell( + Fields &arena_curr, Fields &arena_prev, const int ix, const int iy, + const int ieta, const double tau) { int fieldIdx = arena_curr.getFieldIdx(ix, iy, ieta); ostringstream filename; - filename << "monitor_fluid_cell_ix_" << ix << "_iy_" << iy - << "_ieta_" << ieta << ".dat"; + filename << "monitor_fluid_cell_ix_" << ix << "_iy_" << iy << "_ieta_" + << ieta << ".dat"; ofstream output_file; if (std::abs(tau - DATA.tau0) < 1e-10) { output_file.open(filename.str().c_str(), std::ofstream::out); @@ -1408,52 +1420,51 @@ void Cell_info::monitor_a_fluid_cell(Fields &arena_curr, Fields &arena_prev, << "pi^{\\mu\\nu}(GeV/fm^3) sigma^{\\mu\\nu}(1/fm) " << "omega^{\\mu\\nu}(1/fm)" << std::endl; } else { - output_file.open(filename.str().c_str(), - std::fstream::out | std::fstream::app); + output_file.open( + filename.str().c_str(), std::fstream::out | std::fstream::app); } - output_file << scientific << setprecision(8) - << tau << " " << arena_curr.e_[fieldIdx]*Util::hbarc - << " " << arena_curr.rhob_[fieldIdx] << " "; + output_file << scientific << setprecision(8) << tau << " " + << arena_curr.e_[fieldIdx] * Util::hbarc << " " + << arena_curr.rhob_[fieldIdx] << " "; for (int i = 0; i < 4; i++) { output_file << scientific << setprecision(8) << arena_curr.u_[i][fieldIdx] << " "; } - u_derivative_helper.MakedU(tau, arena_prev, arena_curr, fieldIdx, - ix, iy, ieta); - auto theta_local = u_derivative_helper.calculate_expansion_rate( - tau, arena_curr, fieldIdx); + u_derivative_helper.MakedU( + tau, arena_prev, arena_curr, fieldIdx, ix, iy, ieta); + auto theta_local = + u_derivative_helper.calculate_expansion_rate(tau, arena_curr, fieldIdx); output_file << scientific << setprecision(8) - << arena_curr.piBulk_[fieldIdx]*Util::hbarc << " " + << arena_curr.piBulk_[fieldIdx] * Util::hbarc << " " << theta_local << " "; DumuVec a_local; u_derivative_helper.calculate_Du_supmu(tau, arena_curr, fieldIdx, a_local); VelocityShearVec sigma_local; u_derivative_helper.calculate_velocity_shear_tensor( - tau, arena_curr, fieldIdx, theta_local, a_local, sigma_local); + tau, arena_curr, fieldIdx, theta_local, a_local, sigma_local); VorticityVec omega_local; u_derivative_helper.calculate_kinetic_vorticity_with_spatial_projector( - tau, arena_curr, fieldIdx, a_local, omega_local); + tau, arena_curr, fieldIdx, a_local, omega_local); for (int i = 0; i < 10; i++) { output_file << scientific << setprecision(8) - << arena_curr.Wmunu_[i][fieldIdx]*Util::hbarc << " " + << arena_curr.Wmunu_[i][fieldIdx] * Util::hbarc << " " << sigma_local[i] << " "; } for (int i = 0; i < 6; i++) { - output_file << scientific << setprecision(8) - << omega_local[i] << " "; + output_file << scientific << setprecision(8) << omega_local[i] << " "; } output_file << endl; output_file.close(); } void Cell_info::output_vorticity_distribution( - Fields &arena_curr, Fields &arena_prev, const double tau, - const double eta_min, const double eta_max) { + Fields &arena_curr, Fields &arena_prev, const double tau, + const double eta_min, const double eta_max) { // This function outputs the vorticity tensor at a given tau ostringstream filename1; - filename1 << "vorticity_dis_kinetic_wSP_eta_" << eta_min - << "_" << eta_max << "_tau_" << tau << ".dat"; + filename1 << "vorticity_dis_kinetic_wSP_eta_" << eta_min << "_" << eta_max + << "_tau_" << tau << ".dat"; std::fstream of1; of1.open(filename1.str().c_str(), std::fstream::out); // write the header @@ -1462,8 +1473,8 @@ void Cell_info::output_vorticity_distribution( << "omega^{tz}/T omega^{xy}/T omega^{xz}/T " << "omega^{yz}/T" << std::endl; ostringstream filename2; - filename2 << "vorticity_dis_kinetic_eta_" << eta_min - << "_" << eta_max << "_tau_" << tau << ".dat"; + filename2 << "vorticity_dis_kinetic_eta_" << eta_min << "_" << eta_max + << "_tau_" << tau << ".dat"; std::fstream of2; of2.open(filename2.str().c_str(), std::fstream::out); // write the header @@ -1472,8 +1483,8 @@ void Cell_info::output_vorticity_distribution( << "omega^{tz}/T omega^{xy}/T omega^{xz}/T " << "omega^{yz}/T" << std::endl; ostringstream filename3; - filename3 << "vorticity_dis_thermal_eta_" << eta_min - << "_" << eta_max << "_tau_" << tau << ".dat"; + filename3 << "vorticity_dis_thermal_eta_" << eta_min << "_" << eta_max + << "_tau_" << tau << ".dat"; std::fstream of3; of3.open(filename3.str().c_str(), std::fstream::out); // write the header @@ -1482,8 +1493,8 @@ void Cell_info::output_vorticity_distribution( << "omega^{tz} omega^{xy} omega^{xz} " << "omega^{yz}" << std::endl; ostringstream filename4; - filename4 << "vorticity_dis_T_eta_" << eta_min - << "_" << eta_max << "_tau_" << tau << ".dat"; + filename4 << "vorticity_dis_T_eta_" << eta_min << "_" << eta_max << "_tau_" + << tau << ".dat"; std::fstream of4; of4.open(filename4.str().c_str(), std::fstream::out); // write the header @@ -1494,75 +1505,74 @@ void Cell_info::output_vorticity_distribution( for (int ix = 0; ix < arena_curr.nX(); ix++) { for (int iy = 0; iy < arena_curr.nY(); iy++) { - const double x_local = -DATA.x_size/2. + ix*DATA.delta_x; - const double y_local = -DATA.y_size/2. + iy*DATA.delta_y; + const double x_local = -DATA.x_size / 2. + ix * DATA.delta_x; + const double y_local = -DATA.y_size / 2. + iy * DATA.delta_y; VorticityVec omega_kSP = {0.0}; - VorticityVec omega_k = {0.0}; - VorticityVec omega_th = {0.0}; - VorticityVec omega_T = {0.0}; + VorticityVec omega_k = {0.0}; + VorticityVec omega_th = {0.0}; + VorticityVec omega_T = {0.0}; double T_avg = 0.0; double muB_avg = 0.0; - double weight = 0.0; + double weight = 0.0; for (int ieta = 0; ieta < arena_curr.nEta(); ieta++) { int fieldIdx = arena_curr.getFieldIdx(ix, iy, ieta); - double eta_local = - DATA.eta_size/2. + ieta*DATA.delta_eta; - if (DATA.boost_invariant) - eta_local = 0.0; + double eta_local = -DATA.eta_size / 2. + ieta * DATA.delta_eta; + if (DATA.boost_invariant) eta_local = 0.0; if (eta_local < eta_max && eta_local > eta_min) { const double e_local = arena_curr.e_[fieldIdx]; if (e_local < 0.1) continue; const double rhob_local = arena_curr.rhob_[fieldIdx]; - const double T_local = ( - eos.get_temperature(e_local, rhob_local)); + const double T_local = + (eos.get_temperature(e_local, rhob_local)); const double muB_local = eos.get_muB(e_local, rhob_local); - T_avg += e_local*T_local*hbarc; - muB_avg += e_local*muB_local*hbarc; + T_avg += e_local * T_local * hbarc; + muB_avg += e_local * muB_local * hbarc; VorticityVec omega_local_1, omega_local_2; VorticityVec omega_local_3, omega_local_4; VelocityShearVec sigma_local = {0.0}; DmuMuBoverTVec DbetaMu = {0.0}; u_derivative_helper.compute_vorticity_shell( - tau, arena_prev, arena_curr, ieta, ix, iy, - fieldIdx, eta_local, omega_local_1, omega_local_2, - omega_local_3, omega_local_4, sigma_local, DbetaMu); + tau, arena_prev, arena_curr, ieta, ix, iy, fieldIdx, + eta_local, omega_local_1, omega_local_2, omega_local_3, + omega_local_4, sigma_local, DbetaMu); for (unsigned int ii = 0; ii < omega_k.size(); ii++) { - omega_kSP[ii] += e_local*omega_local_1[ii]/T_local; - omega_k[ii] += e_local*omega_local_2[ii]/T_local; - omega_th[ii] += e_local*omega_local_3[ii]; - omega_T[ii] += (e_local*omega_local_4[ii] - /T_local/T_local); + omega_kSP[ii] += e_local * omega_local_1[ii] / T_local; + omega_k[ii] += e_local * omega_local_2[ii] / T_local; + omega_th[ii] += e_local * omega_local_3[ii]; + omega_T[ii] += + (e_local * omega_local_4[ii] / T_local / T_local); } weight += e_local; } } weight = std::max(weight, small_eps); - of1 << scientific << setprecision(8) << setw(18) - << x_local << " " << y_local << " " - << T_avg/weight << " " << muB_avg/weight << " "; - of2 << scientific << setprecision(8) << setw(18) - << x_local << " " << y_local << " " - << T_avg/weight << " " << muB_avg/weight << " "; - of3 << scientific << setprecision(8) << setw(18) - << x_local << " " << y_local << " " - << T_avg/weight << " " << muB_avg/weight << " "; - of4 << scientific << setprecision(8) << setw(18) - << x_local << " " << y_local << " " - << T_avg/weight << " " << muB_avg/weight << " "; + of1 << scientific << setprecision(8) << setw(18) << x_local << " " + << y_local << " " << T_avg / weight << " " << muB_avg / weight + << " "; + of2 << scientific << setprecision(8) << setw(18) << x_local << " " + << y_local << " " << T_avg / weight << " " << muB_avg / weight + << " "; + of3 << scientific << setprecision(8) << setw(18) << x_local << " " + << y_local << " " << T_avg / weight << " " << muB_avg / weight + << " "; + of4 << scientific << setprecision(8) << setw(18) << x_local << " " + << y_local << " " << T_avg / weight << " " << muB_avg / weight + << " "; for (unsigned int ii = 0; ii < omega_k.size(); ii++) { // no minus sign because it has an opposite sign to // the kinetic vorticity of1 << scientific << setprecision(8) << setw(18) - << omega_kSP[ii]/weight << " "; + << omega_kSP[ii] / weight << " "; // minus sign from the metric // output quantities in g = (1, -1, -1 , -1) of2 << scientific << setprecision(8) << setw(18) - << -omega_k[ii]/weight << " "; + << -omega_k[ii] / weight << " "; of3 << scientific << setprecision(8) << setw(18) - << -omega_th[ii]/weight << " "; + << -omega_th[ii] / weight << " "; of4 << scientific << setprecision(8) << setw(18) - << -omega_T[ii]/weight << " "; + << -omega_T[ii] / weight << " "; } of1 << std::endl; of2 << std::endl; @@ -1577,12 +1587,12 @@ void Cell_info::output_vorticity_distribution( } void Cell_info::output_vorticity_time_evolution( - Fields &arena_curr, Fields &arena_prev, const double tau, - const double eta_min, const double eta_max) { + Fields &arena_curr, Fields &arena_prev, const double tau, + const double eta_min, const double eta_max) { // This function outputs the time evolution of the vorticity tensor ostringstream filename1; - filename1 << "vorticity_evo_kinetic_wSP_eta_" << eta_min - << "_" << eta_max << ".dat"; + filename1 << "vorticity_evo_kinetic_wSP_eta_" << eta_min << "_" << eta_max + << ".dat"; std::fstream of1; if (std::abs(tau - DATA.tau0) < 1e-10) { of1.open(filename1.str().c_str(), std::fstream::out); @@ -1590,12 +1600,12 @@ void Cell_info::output_vorticity_time_evolution( << "omega^{tz}/T omega^{xy}/T omega^{xz}/T " << "omega^{yz}/T" << std::endl; } else { - of1.open(filename1.str().c_str(), - std::fstream::out | std::fstream::app); + of1.open( + filename1.str().c_str(), std::fstream::out | std::fstream::app); } ostringstream filename2; - filename2 << "vorticity_evo_kinetic_eta_" << eta_min - << "_" << eta_max << ".dat"; + filename2 << "vorticity_evo_kinetic_eta_" << eta_min << "_" << eta_max + << ".dat"; std::fstream of2; if (std::abs(tau - DATA.tau0) < 1e-10) { of2.open(filename2.str().c_str(), std::fstream::out); @@ -1603,12 +1613,12 @@ void Cell_info::output_vorticity_time_evolution( << "omega^{tz}/T omega^{xy}/T omega^{xz}/T " << "omega^{yz}/T" << std::endl; } else { - of2.open(filename2.str().c_str(), - std::fstream::out | std::fstream::app); + of2.open( + filename2.str().c_str(), std::fstream::out | std::fstream::app); } ostringstream filename3; - filename3 << "vorticity_evo_thermal_eta_" << eta_min - << "_" << eta_max << ".dat"; + filename3 << "vorticity_evo_thermal_eta_" << eta_min << "_" << eta_max + << ".dat"; std::fstream of3; if (std::abs(tau - DATA.tau0) < 1e-10) { of3.open(filename3.str().c_str(), std::fstream::out); @@ -1616,12 +1626,11 @@ void Cell_info::output_vorticity_time_evolution( << "omega^{tz} omega^{xy} omega^{xz} " << "omega^{yz}" << std::endl; } else { - of3.open(filename3.str().c_str(), - std::fstream::out | std::fstream::app); + of3.open( + filename3.str().c_str(), std::fstream::out | std::fstream::app); } ostringstream filename4; - filename4 << "vorticity_evo_T_eta_" << eta_min - << "_" << eta_max << ".dat"; + filename4 << "vorticity_evo_T_eta_" << eta_min << "_" << eta_max << ".dat"; std::fstream of4; if (std::abs(tau - DATA.tau0) < 1e-10) { of4.open(filename4.str().c_str(), std::fstream::out); @@ -1629,46 +1638,49 @@ void Cell_info::output_vorticity_time_evolution( << "omega^{tz}/T^2 omega^{xy}/T^2 " << "omega^{xz}/T^2 omega^{yz}/T^2" << std::endl; } else { - of4.open(filename4.str().c_str(), - std::fstream::out | std::fstream::app); + of4.open( + filename4.str().c_str(), std::fstream::out | std::fstream::app); } VorticityVec omega_kSP = {0.0}; - VorticityVec omega_k = {0.0}; - VorticityVec omega_th = {0.0}; - VorticityVec omega_T = {0.0}; + VorticityVec omega_k = {0.0}; + VorticityVec omega_th = {0.0}; + VorticityVec omega_T = {0.0}; double weight = 0.0; for (int ieta = 0; ieta < arena_curr.nEta(); ieta++) { double eta = 0.0; if (!DATA.boost_invariant) { - eta = ((static_cast(ieta))*(DATA.delta_eta) - - (DATA.eta_size)/2.0); + eta = + ((static_cast(ieta)) * (DATA.delta_eta) + - (DATA.eta_size) / 2.0); } if (eta < eta_max && eta > eta_min) { for (int iy = 0; iy < arena_curr.nY(); iy++) - for (int ix = 0; ix < arena_curr.nX(); ix++) { - int fieldIdx = arena_curr.getFieldIdx(ix, iy, ieta); - const double e_local = arena_curr.e_[fieldIdx]; // 1/fm^4 - if (e_local < 0.1) continue; - const double rhob_local = arena_curr.rhob_[fieldIdx]; // 1/fm^3 - const double T_local = ( - eos.get_temperature(e_local, rhob_local)); - VorticityVec omega_local_1, omega_local_2; - VorticityVec omega_local_3, omega_local_4; - VelocityShearVec sigma_local = {0.0}; - DmuMuBoverTVec DbetaMu = {0.0}; - u_derivative_helper.compute_vorticity_shell( - tau, arena_prev, arena_curr, ieta, ix, iy, fieldIdx, - eta, omega_local_1, omega_local_2, - omega_local_3, omega_local_4, sigma_local, DbetaMu); - for (unsigned int ii = 0; ii < omega_k.size(); ii++) { - omega_kSP[ii] += e_local*omega_local_1[ii]/T_local; - omega_k[ii] += e_local*omega_local_2[ii]/T_local; - omega_th[ii] += e_local*omega_local_3[ii]; - omega_T[ii] += e_local*omega_local_4[ii]/T_local/T_local; + for (int ix = 0; ix < arena_curr.nX(); ix++) { + int fieldIdx = arena_curr.getFieldIdx(ix, iy, ieta); + const double e_local = arena_curr.e_[fieldIdx]; // 1/fm^4 + if (e_local < 0.1) continue; + const double rhob_local = + arena_curr.rhob_[fieldIdx]; // 1/fm^3 + const double T_local = + (eos.get_temperature(e_local, rhob_local)); + VorticityVec omega_local_1, omega_local_2; + VorticityVec omega_local_3, omega_local_4; + VelocityShearVec sigma_local = {0.0}; + DmuMuBoverTVec DbetaMu = {0.0}; + u_derivative_helper.compute_vorticity_shell( + tau, arena_prev, arena_curr, ieta, ix, iy, fieldIdx, + eta, omega_local_1, omega_local_2, omega_local_3, + omega_local_4, sigma_local, DbetaMu); + for (unsigned int ii = 0; ii < omega_k.size(); ii++) { + omega_kSP[ii] += e_local * omega_local_1[ii] / T_local; + omega_k[ii] += e_local * omega_local_2[ii] / T_local; + omega_th[ii] += e_local * omega_local_3[ii]; + omega_T[ii] += + e_local * omega_local_4[ii] / T_local / T_local; + } + weight += e_local; } - weight += e_local; - } } } weight = std::max(weight, small_eps); @@ -1680,15 +1692,15 @@ void Cell_info::output_vorticity_time_evolution( for (unsigned int ii = 0; ii < omega_k.size(); ii++) { // no minus sign because it has opposite sign to the kinetic vorcitity of1 << scientific << setprecision(8) << setw(18) - << omega_kSP[ii]/weight << " "; + << omega_kSP[ii] / weight << " "; // minus sign from the metric // output quantities in g = (1, -1, -1 , -1) of2 << scientific << setprecision(8) << setw(18) - << -omega_k[ii]/weight << " "; + << -omega_k[ii] / weight << " "; of3 << scientific << setprecision(8) << setw(18) - << -omega_th[ii]/weight << " "; + << -omega_th[ii] / weight << " "; of4 << scientific << setprecision(8) << setw(18) - << -omega_T[ii]/weight << " "; + << -omega_T[ii] / weight << " "; } of1 << std::endl; of2 << std::endl; @@ -1701,7 +1713,6 @@ void Cell_info::output_vorticity_time_evolution( of4.close(); } - void Cell_info::load_deltaf_qmu_coeff_table(string filename) { std::ifstream table(filename.c_str()); deltaf_qmu_coeff_table_length_T = 150; @@ -1710,18 +1721,17 @@ void Cell_info::load_deltaf_qmu_coeff_table(string filename) { delta_qmu_coeff_table_mu0 = 0.0; delta_qmu_coeff_table_dT = 0.001; delta_qmu_coeff_table_dmu = 0.007892; - deltaf_qmu_coeff_tb = new double* [deltaf_qmu_coeff_table_length_T]; + deltaf_qmu_coeff_tb = new double *[deltaf_qmu_coeff_table_length_T]; for (int i = 0; i < deltaf_qmu_coeff_table_length_T; i++) - deltaf_qmu_coeff_tb[i] = new double[deltaf_qmu_coeff_table_length_mu]; + deltaf_qmu_coeff_tb[i] = new double[deltaf_qmu_coeff_table_length_mu]; double dummy; for (int j = 0; j < deltaf_qmu_coeff_table_length_mu; j++) - for (int i = 0; i < deltaf_qmu_coeff_table_length_T; i++) - table >> dummy >> dummy >> deltaf_qmu_coeff_tb[i][j]; + for (int i = 0; i < deltaf_qmu_coeff_table_length_T; i++) + table >> dummy >> dummy >> deltaf_qmu_coeff_tb[i][j]; table.close(); } - void Cell_info::load_deltaf_qmu_coeff_table_14mom(string filename) { std::ifstream table(filename.c_str()); deltaf_coeff_table_14mom_length_T = 190; @@ -1731,208 +1741,208 @@ void Cell_info::load_deltaf_qmu_coeff_table_14mom(string filename) { delta_coeff_table_14mom_dT = 0.001; delta_coeff_table_14mom_dmu = 0.005; - deltaf_coeff_tb_14mom_DPi = new double* [deltaf_coeff_table_14mom_length_T]; - deltaf_coeff_tb_14mom_BPi = new double* [deltaf_coeff_table_14mom_length_T]; + deltaf_coeff_tb_14mom_DPi = new double *[deltaf_coeff_table_14mom_length_T]; + deltaf_coeff_tb_14mom_BPi = new double *[deltaf_coeff_table_14mom_length_T]; deltaf_coeff_tb_14mom_BPitilde = - new double* [deltaf_coeff_table_14mom_length_T]; - deltaf_coeff_tb_14mom_DV = new double* [deltaf_coeff_table_14mom_length_T]; - deltaf_coeff_tb_14mom_BV = new double* [deltaf_coeff_table_14mom_length_T]; + new double *[deltaf_coeff_table_14mom_length_T]; + deltaf_coeff_tb_14mom_DV = new double *[deltaf_coeff_table_14mom_length_T]; + deltaf_coeff_tb_14mom_BV = new double *[deltaf_coeff_table_14mom_length_T]; deltaf_coeff_tb_14mom_Bpi_shear = - new double* [deltaf_coeff_table_14mom_length_T]; + new double *[deltaf_coeff_table_14mom_length_T]; for (int i = 0; i < deltaf_coeff_table_14mom_length_T; i++) { deltaf_coeff_tb_14mom_DPi[i] = - new double[deltaf_coeff_table_14mom_length_mu]; + new double[deltaf_coeff_table_14mom_length_mu]; deltaf_coeff_tb_14mom_BPi[i] = - new double[deltaf_coeff_table_14mom_length_mu]; + new double[deltaf_coeff_table_14mom_length_mu]; deltaf_coeff_tb_14mom_BPitilde[i] = - new double[deltaf_coeff_table_14mom_length_mu]; + new double[deltaf_coeff_table_14mom_length_mu]; deltaf_coeff_tb_14mom_DV[i] = - new double[deltaf_coeff_table_14mom_length_mu]; + new double[deltaf_coeff_table_14mom_length_mu]; deltaf_coeff_tb_14mom_BV[i] = - new double[deltaf_coeff_table_14mom_length_mu]; + new double[deltaf_coeff_table_14mom_length_mu]; deltaf_coeff_tb_14mom_Bpi_shear[i] = - new double[deltaf_coeff_table_14mom_length_mu]; + new double[deltaf_coeff_table_14mom_length_mu]; } double dummy; for (int i = 0; i < deltaf_coeff_table_14mom_length_T; i++) for (int j = 0; j < deltaf_coeff_table_14mom_length_mu; j++) table >> dummy >> dummy >> deltaf_coeff_tb_14mom_DPi[i][j] - >> deltaf_coeff_tb_14mom_BPi[i][j] - >> deltaf_coeff_tb_14mom_BPitilde[i][j] - >> deltaf_coeff_tb_14mom_DV[i][j] - >> deltaf_coeff_tb_14mom_BV[i][j] - >> deltaf_coeff_tb_14mom_Bpi_shear[i][j]; + >> deltaf_coeff_tb_14mom_BPi[i][j] + >> deltaf_coeff_tb_14mom_BPitilde[i][j] + >> deltaf_coeff_tb_14mom_DV[i][j] + >> deltaf_coeff_tb_14mom_BV[i][j] + >> deltaf_coeff_tb_14mom_Bpi_shear[i][j]; table.close(); // convert units - double hbarc3 = hbarc*hbarc*hbarc; - double hbarc4 = hbarc3*hbarc; + double hbarc3 = hbarc * hbarc * hbarc; + double hbarc4 = hbarc3 * hbarc; for (int i = 0; i < deltaf_coeff_table_14mom_length_T; i++) { for (int j = 0; j < deltaf_coeff_table_14mom_length_mu; j++) { deltaf_coeff_tb_14mom_DPi[i][j] = - deltaf_coeff_tb_14mom_DPi[i][j]*hbarc4; // fm^4/GeV + deltaf_coeff_tb_14mom_DPi[i][j] * hbarc4; // fm^4/GeV deltaf_coeff_tb_14mom_BPi[i][j] = - deltaf_coeff_tb_14mom_BPi[i][j]*hbarc4; // fm^4/(GeV^2) + deltaf_coeff_tb_14mom_BPi[i][j] * hbarc4; // fm^4/(GeV^2) deltaf_coeff_tb_14mom_BPitilde[i][j] = - deltaf_coeff_tb_14mom_BPitilde[i][j]*hbarc4; // fm^4/(GeV^2) + deltaf_coeff_tb_14mom_BPitilde[i][j] * hbarc4; // fm^4/(GeV^2) deltaf_coeff_tb_14mom_DV[i][j] = - deltaf_coeff_tb_14mom_DV[i][j]*hbarc3; // fm^3/GeV + deltaf_coeff_tb_14mom_DV[i][j] * hbarc3; // fm^3/GeV deltaf_coeff_tb_14mom_BV[i][j] = - deltaf_coeff_tb_14mom_BV[i][j]*hbarc3; // fm^3/(GeV^2) + deltaf_coeff_tb_14mom_BV[i][j] * hbarc3; // fm^3/(GeV^2) deltaf_coeff_tb_14mom_Bpi_shear[i][j] = - deltaf_coeff_tb_14mom_Bpi_shear[i][j]*hbarc4; // fm^4/(GeV^2) + deltaf_coeff_tb_14mom_Bpi_shear[i][j] * hbarc4; // fm^4/(GeV^2) } } } - double Cell_info::get_deltaf_qmu_coeff(double T, double muB) { if (muB < 0) { - muB = -muB; + muB = -muB; } int idx_T = static_cast( - (T - delta_qmu_coeff_table_T0)/delta_qmu_coeff_table_dT); + (T - delta_qmu_coeff_table_T0) / delta_qmu_coeff_table_dT); int idx_mu = static_cast( - (muB - delta_qmu_coeff_table_mu0)/delta_qmu_coeff_table_dmu); + (muB - delta_qmu_coeff_table_mu0) / delta_qmu_coeff_table_dmu); - if (idx_T > deltaf_qmu_coeff_table_length_T - 2 || idx_T < 0) - return(1.0); - if (idx_mu > deltaf_qmu_coeff_table_length_mu - 2) - return(1.0); + if (idx_T > deltaf_qmu_coeff_table_length_T - 2 || idx_T < 0) return (1.0); + if (idx_mu > deltaf_qmu_coeff_table_length_mu - 2) return (1.0); - double x_fraction = ((T - delta_qmu_coeff_table_T0) - /delta_qmu_coeff_table_dT - idx_T); - double y_fraction = ((muB - delta_qmu_coeff_table_mu0) - /delta_qmu_coeff_table_dmu - idx_mu); + double x_fraction = + ((T - delta_qmu_coeff_table_T0) / delta_qmu_coeff_table_dT - idx_T); + double y_fraction = + ((muB - delta_qmu_coeff_table_mu0) / delta_qmu_coeff_table_dmu + - idx_mu); double f1 = deltaf_qmu_coeff_tb[idx_T][idx_mu]; - double f2 = deltaf_qmu_coeff_tb[idx_T][idx_mu+1]; - double f3 = deltaf_qmu_coeff_tb[idx_T+1][idx_mu+1]; - double f4 = deltaf_qmu_coeff_tb[idx_T+1][idx_mu]; - - double coeff = (f1*(1. - x_fraction)*(1. - y_fraction) - + f2*(1. - x_fraction)*y_fraction - + f3*x_fraction*y_fraction - + f4*x_fraction*(1. - y_fraction)); - return(coeff); + double f2 = deltaf_qmu_coeff_tb[idx_T][idx_mu + 1]; + double f3 = deltaf_qmu_coeff_tb[idx_T + 1][idx_mu + 1]; + double f4 = deltaf_qmu_coeff_tb[idx_T + 1][idx_mu]; + + double coeff = + (f1 * (1. - x_fraction) * (1. - y_fraction) + + f2 * (1. - x_fraction) * y_fraction + f3 * x_fraction * y_fraction + + f4 * x_fraction * (1. - y_fraction)); + return (coeff); } - -double Cell_info::get_deltaf_coeff_14moments(double T, double muB, - double type) { +double Cell_info::get_deltaf_coeff_14moments( + double T, double muB, double type) { int idx_T = static_cast( - (T - delta_coeff_table_14mom_T0)/delta_coeff_table_14mom_dT); + (T - delta_coeff_table_14mom_T0) / delta_coeff_table_14mom_dT); int idx_mu = static_cast( - (muB - delta_coeff_table_14mom_mu0)/delta_coeff_table_14mom_dmu); - double x_fraction = ( - (T - delta_coeff_table_14mom_T0)/delta_coeff_table_14mom_dT - idx_T); - double y_fraction = ((muB - delta_coeff_table_14mom_mu0) - /delta_coeff_table_14mom_dmu - idx_mu); + (muB - delta_coeff_table_14mom_mu0) / delta_coeff_table_14mom_dmu); + double x_fraction = + ((T - delta_coeff_table_14mom_T0) / delta_coeff_table_14mom_dT - idx_T); + double y_fraction = + ((muB - delta_coeff_table_14mom_mu0) / delta_coeff_table_14mom_dmu + - idx_mu); double **deltaf_table = NULL; if (type == 0) { - deltaf_table = deltaf_coeff_tb_14mom_DPi; + deltaf_table = deltaf_coeff_tb_14mom_DPi; } else if (type == 1) { - deltaf_table = deltaf_coeff_tb_14mom_BPi; + deltaf_table = deltaf_coeff_tb_14mom_BPi; } else if (type == 2) { - deltaf_table = deltaf_coeff_tb_14mom_BPitilde; + deltaf_table = deltaf_coeff_tb_14mom_BPitilde; } else if (type == 3) { - deltaf_table = deltaf_coeff_tb_14mom_DV; + deltaf_table = deltaf_coeff_tb_14mom_DV; } else if (type == 4) { - deltaf_table = deltaf_coeff_tb_14mom_BV; + deltaf_table = deltaf_coeff_tb_14mom_BV; } else if (type == 5) { - deltaf_table = deltaf_coeff_tb_14mom_Bpi_shear; + deltaf_table = deltaf_coeff_tb_14mom_Bpi_shear; } else { - music_message << "Cell_info::get_deltaf_coeff_14moments: unknown type: " - << type; - music_message.flush("error"); - exit(-1); + music_message << "Cell_info::get_deltaf_coeff_14moments: unknown type: " + << type; + music_message.flush("error"); + exit(-1); } double f1 = deltaf_table[idx_T][idx_mu]; - double f2 = deltaf_table[idx_T][idx_mu+1]; - double f3 = deltaf_table[idx_T+1][idx_mu+1]; - double f4 = deltaf_table[idx_T+1][idx_mu]; - - double coeff = (f1*(1. - x_fraction)*(1. - y_fraction) - + f2*(1. - x_fraction)*y_fraction - + f3*x_fraction*y_fraction - + f4*x_fraction*(1. - y_fraction)); - return(coeff); + double f2 = deltaf_table[idx_T][idx_mu + 1]; + double f3 = deltaf_table[idx_T + 1][idx_mu + 1]; + double f4 = deltaf_table[idx_T + 1][idx_mu]; + + double coeff = + (f1 * (1. - x_fraction) * (1. - y_fraction) + + f2 * (1. - x_fraction) * y_fraction + f3 * x_fraction * y_fraction + + f4 * x_fraction * (1. - y_fraction)); + return (coeff); } - //! This function outputs average T and mu_B as a function of proper tau //! within a given space-time rapidity range void Cell_info::output_average_phase_diagram_trajectory( - const double tau, const double eta_min, const double eta_max, - Fields &arena) { + const double tau, const double eta_min, const double eta_max, + Fields &arena) { ostringstream filename; - filename << "averaged_phase_diagram_trajectory_eta_" << eta_min - << "_" << eta_max << ".dat"; + filename << "averaged_phase_diagram_trajectory_eta_" << eta_min << "_" + << eta_max << ".dat"; std::fstream of; if (std::abs(tau - DATA.tau0) < 1e-10) { of.open(filename.str().c_str(), std::fstream::out); of << "# tau(fm) (GeV) std(T)(GeV) (GeV) std(mu_B)(GeV) " << "V4 (fm^4)" << endl; } else { - of.open(filename.str().c_str(), - std::fstream::out | std::fstream::app); + of.open(filename.str().c_str(), std::fstream::out | std::fstream::app); } - double avg_T = 0.0; + double avg_T = 0.0; double avg_mu = 0.0; - double std_T = 0.0; + double std_T = 0.0; double std_mu = 0.0; double weight = 0.0; - double V4 = 0.0; - const double unit_volume = tau*DATA.delta_x*DATA.delta_y*DATA.delta_eta; + double V4 = 0.0; + const double unit_volume = + tau * DATA.delta_x * DATA.delta_y * DATA.delta_eta; for (int ieta = 0; ieta < arena.nEta(); ieta++) { double eta = 0.0; if (!DATA.boost_invariant) { - eta = ((static_cast(ieta))*(DATA.delta_eta) - - (DATA.eta_size)/2.0); + eta = + ((static_cast(ieta)) * (DATA.delta_eta) + - (DATA.eta_size) / 2.0); } if (eta < eta_max && eta > eta_min) { double cosh_eta = cosh(eta); double sinh_eta = sinh(eta); for (int iy = 0; iy < arena.nY(); iy++) - for (int ix = 0; ix < arena.nX(); ix++) { - int fieldIdx = arena.getFieldIdx(ix, iy, ieta); - - double e_local = arena.e_[fieldIdx]; // 1/fm^4 - if (e_local*hbarc > DATA.output_evolution_e_cut) - V4 += unit_volume; - double rhob_local = arena.rhob_[fieldIdx]; // 1/fm^3 - double utau = arena.u_[0][fieldIdx]; - double ueta = arena.u_[3][fieldIdx]; - double ut = utau*cosh_eta + ueta*sinh_eta; // gamma factor - double T_local = eos.get_temperature(e_local, rhob_local); - double muB_local = eos.get_muB(e_local, rhob_local); - double weight_local = e_local*ut; - avg_T += T_local*weight_local; - avg_mu += muB_local*weight_local; - std_T += T_local*T_local*weight_local; - std_mu += muB_local*muB_local*weight_local; - weight += weight_local; - } + for (int ix = 0; ix < arena.nX(); ix++) { + int fieldIdx = arena.getFieldIdx(ix, iy, ieta); + + double e_local = arena.e_[fieldIdx]; // 1/fm^4 + if (e_local * hbarc > DATA.output_evolution_e_cut) + V4 += unit_volume; + double rhob_local = arena.rhob_[fieldIdx]; // 1/fm^3 + double utau = arena.u_[0][fieldIdx]; + double ueta = arena.u_[3][fieldIdx]; + double ut = + utau * cosh_eta + ueta * sinh_eta; // gamma factor + double T_local = eos.get_temperature(e_local, rhob_local); + double muB_local = eos.get_muB(e_local, rhob_local); + double weight_local = e_local * ut; + avg_T += T_local * weight_local; + avg_mu += muB_local * weight_local; + std_T += T_local * T_local * weight_local; + std_mu += muB_local * muB_local * weight_local; + weight += weight_local; + } } } - avg_T = avg_T/std::max(weight, small_eps)*hbarc; - avg_mu = avg_mu/std::max(weight, small_eps)*hbarc; - std_T = sqrt(std_T/std::max(weight, small_eps)*hbarc*hbarc - avg_T*avg_T); - std_mu = sqrt(std_mu/std::max(weight, small_eps)*hbarc*hbarc - avg_mu*avg_mu); - of << scientific << setw(18) << setprecision(8) - << tau << " " << avg_T << " " << std_T << " " - << avg_mu << " " << std_mu << " " << V4 << endl; + avg_T = avg_T / std::max(weight, small_eps) * hbarc; + avg_mu = avg_mu / std::max(weight, small_eps) * hbarc; + std_T = sqrt( + std_T / std::max(weight, small_eps) * hbarc * hbarc - avg_T * avg_T); + std_mu = sqrt( + std_mu / std::max(weight, small_eps) * hbarc * hbarc - avg_mu * avg_mu); + of << scientific << setw(18) << setprecision(8) << tau << " " << avg_T + << " " << std_T << " " << avg_mu << " " << std_mu << " " << V4 + << endl; of.close(); } - //! This function outputs system's eccentricity and momentum anisotropy //! as functions of eta_s void Cell_info::output_momentum_anisotropy_vs_etas( - const double tau, Fields &arena) const { + const double tau, Fields &arena) const { ostringstream filename; filename << "momentum_anisotropy_tau_" << tau << ".dat"; std::fstream of; @@ -1967,8 +1977,9 @@ void Cell_info::output_momentum_anisotropy_vs_etas( for (int ieta = 0; ieta < arena.nEta(); ieta++) { double eta = 0.0; if (!DATA.boost_invariant) { - eta = ((static_cast(ieta))*(DATA.delta_eta) - - (DATA.eta_size)/2.0); + eta = + ((static_cast(ieta)) * (DATA.delta_eta) + - (DATA.eta_size) / 2.0); } // compute the central of mass position @@ -1976,20 +1987,20 @@ void Cell_info::output_momentum_anisotropy_vs_etas( double y_ed_o = 0.0, y_nB_o = 0.0; double w_ed_sum = 0.0, w_nB_sum = 0.0; for (int iy = 0; iy < arena.nY(); iy++) - for (int ix = 0; ix < arena.nX(); ix++) { - int fieldIdx = arena.getFieldIdx(ix, iy, ieta); - double x_local = - DATA.x_size/2. + ix*DATA.delta_x; - double y_local = - DATA.y_size/2. + iy*DATA.delta_y; - double e_local = arena.e_[fieldIdx]; // 1/fm^4 - double nB_local = arena.rhob_[fieldIdx]; // 1/fm^3 - double gamma_perp = arena.u_[0][fieldIdx]; - x_ed_o += x_local*e_local*gamma_perp; - y_ed_o += y_local*e_local*gamma_perp; - w_ed_sum += e_local*gamma_perp; - x_nB_o += x_local*nB_local*gamma_perp; - y_nB_o += y_local*nB_local*gamma_perp; - w_nB_sum += nB_local*gamma_perp; - } + for (int ix = 0; ix < arena.nX(); ix++) { + int fieldIdx = arena.getFieldIdx(ix, iy, ieta); + double x_local = -DATA.x_size / 2. + ix * DATA.delta_x; + double y_local = -DATA.y_size / 2. + iy * DATA.delta_y; + double e_local = arena.e_[fieldIdx]; // 1/fm^4 + double nB_local = arena.rhob_[fieldIdx]; // 1/fm^3 + double gamma_perp = arena.u_[0][fieldIdx]; + x_ed_o += x_local * e_local * gamma_perp; + y_ed_o += y_local * e_local * gamma_perp; + w_ed_sum += e_local * gamma_perp; + x_nB_o += x_local * nB_local * gamma_perp; + y_nB_o += y_local * nB_local * gamma_perp; + w_nB_sum += nB_local * gamma_perp; + } x_ed_o /= std::max(small_eps, w_ed_sum); y_ed_o /= std::max(small_eps, w_ed_sum); x_nB_o /= std::max(small_eps, w_nB_sum); @@ -1998,131 +2009,131 @@ void Cell_info::output_momentum_anisotropy_vs_etas( // compute epsilon_p with ideal, ideal + shear, and full T^{\munu} std::vector ep_num1(3, 0.0); std::vector ep_num2(3, 0.0); - std::vector ep_den (3, 0.0); + std::vector ep_den(3, 0.0); // spatial eccentricity arrays std::vector eccn_ed_num1(norder, 0.0); std::vector eccn_ed_num2(norder, 0.0); - std::vector eccn_ed_den (norder, 0.0); + std::vector eccn_ed_den(norder, 0.0); std::vector eccn_nB_num1(norder, 0.0); std::vector eccn_nB_num2(norder, 0.0); - std::vector eccn_nB_den (norder, 0.0); + std::vector eccn_nB_den(norder, 0.0); std::vector meanpT_est_num(4, 0.0); std::vector meanpT_est_den(1, 0.0); for (int iy = 0; iy < arena.nY(); iy++) - for (int ix = 0; ix < arena.nX(); ix++) { - int fieldIdx = arena.getFieldIdx(ix, iy, ieta); - double x_ed = - DATA.x_size/2. + ix*DATA.delta_x - x_ed_o; - double y_ed = - DATA.y_size/2. + iy*DATA.delta_y - y_ed_o; - double x_nB = - DATA.x_size/2. + ix*DATA.delta_x - x_nB_o; - double y_nB = - DATA.y_size/2. + iy*DATA.delta_y - y_nB_o; - double r_ed = sqrt(x_ed*x_ed + y_ed*y_ed); - double r_nB = sqrt(x_nB*x_nB + y_nB*y_nB); - double phi_ed = atan2(y_ed, x_ed); - double phi_nB = atan2(y_nB, x_nB); - - double e_local = arena.e_[fieldIdx]; // 1/fm^4 - double rhob_local = arena.rhob_[fieldIdx]; // 1/fm^3 - eos.getThermalVariables(e_local, rhob_local, thermalVec); - double P_local = thermalVec[2]; - double enthopy = e_local + P_local; - double s_local = thermalVec[12]; - double u0 = arena.u_[0][fieldIdx]; - double ux = arena.u_[1][fieldIdx]; - double uy = arena.u_[2][fieldIdx]; - double pi_xx = arena.Wmunu_[4][fieldIdx]; - double pi_xy = arena.Wmunu_[5][fieldIdx]; - double pi_yy = arena.Wmunu_[7][fieldIdx]; - double bulk_Pi = arena.piBulk_[fieldIdx]; - - double T_00_ideal = enthopy*u0*u0 - P_local; - double T_xx_ideal = enthopy*ux*ux + P_local; - double T_xy_ideal = enthopy*ux*uy; - double T_yy_ideal = enthopy*uy*uy + P_local; - - double T_xx_shear = T_xx_ideal + pi_xx; - double T_xy_shear = T_xy_ideal + pi_xy; - double T_yy_shear = T_yy_ideal + pi_yy; - - double T_xx_full = T_xx_shear - bulk_Pi*(-1 - ux*ux); - double T_xy_full = T_xy_shear + bulk_Pi*ux*uy; - double T_yy_full = T_yy_shear - bulk_Pi*(-1 - uy*uy); - - ep_num1[0] += T_xx_ideal - T_yy_ideal; - ep_num2[0] += 2.*T_xy_ideal; - ep_den[0] += T_xx_ideal + T_yy_ideal; - ep_num1[1] += T_xx_shear - T_yy_shear; - ep_num2[1] += 2.*T_xy_shear; - ep_den[1] += T_xx_shear + T_yy_shear; - ep_num1[2] += T_xx_full - T_yy_full; - ep_num2[2] += 2.*T_xy_full; - ep_den[2] += T_xx_full + T_yy_full; - - double w_ed = 0.0, w_nB = 0.0; - for (int i = 0; i < norder; i++) { - if (i == 1) { - w_ed = u0*e_local*pow(r_ed, 3); - w_nB = u0*rhob_local*pow(r_nB, 3); - } else { - w_ed = u0*e_local*pow(r_ed, i); - w_nB = u0*rhob_local*pow(r_nB, i); - } - if (i == 0) { - eccn_ed_num1[i] += e_local; - eccn_nB_num1[i] += rhob_local; - } else { - eccn_ed_num1[i] += w_ed*cos(i*phi_ed); - eccn_ed_num2[i] += w_ed*sin(i*phi_ed); - eccn_ed_den [i] += w_ed; - eccn_nB_num1[i] += w_nB*cos(i*phi_nB); - eccn_nB_num2[i] += w_nB*sin(i*phi_nB); - eccn_nB_den [i] += w_nB; + for (int ix = 0; ix < arena.nX(); ix++) { + int fieldIdx = arena.getFieldIdx(ix, iy, ieta); + double x_ed = -DATA.x_size / 2. + ix * DATA.delta_x - x_ed_o; + double y_ed = -DATA.y_size / 2. + iy * DATA.delta_y - y_ed_o; + double x_nB = -DATA.x_size / 2. + ix * DATA.delta_x - x_nB_o; + double y_nB = -DATA.y_size / 2. + iy * DATA.delta_y - y_nB_o; + double r_ed = sqrt(x_ed * x_ed + y_ed * y_ed); + double r_nB = sqrt(x_nB * x_nB + y_nB * y_nB); + double phi_ed = atan2(y_ed, x_ed); + double phi_nB = atan2(y_nB, x_nB); + + double e_local = arena.e_[fieldIdx]; // 1/fm^4 + double rhob_local = arena.rhob_[fieldIdx]; // 1/fm^3 + eos.getThermalVariables(e_local, rhob_local, thermalVec); + double P_local = thermalVec[2]; + double enthopy = e_local + P_local; + double s_local = thermalVec[12]; + double u0 = arena.u_[0][fieldIdx]; + double ux = arena.u_[1][fieldIdx]; + double uy = arena.u_[2][fieldIdx]; + double pi_xx = arena.Wmunu_[4][fieldIdx]; + double pi_xy = arena.Wmunu_[5][fieldIdx]; + double pi_yy = arena.Wmunu_[7][fieldIdx]; + double bulk_Pi = arena.piBulk_[fieldIdx]; + + double T_00_ideal = enthopy * u0 * u0 - P_local; + double T_xx_ideal = enthopy * ux * ux + P_local; + double T_xy_ideal = enthopy * ux * uy; + double T_yy_ideal = enthopy * uy * uy + P_local; + + double T_xx_shear = T_xx_ideal + pi_xx; + double T_xy_shear = T_xy_ideal + pi_xy; + double T_yy_shear = T_yy_ideal + pi_yy; + + double T_xx_full = T_xx_shear - bulk_Pi * (-1 - ux * ux); + double T_xy_full = T_xy_shear + bulk_Pi * ux * uy; + double T_yy_full = T_yy_shear - bulk_Pi * (-1 - uy * uy); + + ep_num1[0] += T_xx_ideal - T_yy_ideal; + ep_num2[0] += 2. * T_xy_ideal; + ep_den[0] += T_xx_ideal + T_yy_ideal; + ep_num1[1] += T_xx_shear - T_yy_shear; + ep_num2[1] += 2. * T_xy_shear; + ep_den[1] += T_xx_shear + T_yy_shear; + ep_num1[2] += T_xx_full - T_yy_full; + ep_num2[2] += 2. * T_xy_full; + ep_den[2] += T_xx_full + T_yy_full; + + double w_ed = 0.0, w_nB = 0.0; + for (int i = 0; i < norder; i++) { + if (i == 1) { + w_ed = u0 * e_local * pow(r_ed, 3); + w_nB = u0 * rhob_local * pow(r_nB, 3); + } else { + w_ed = u0 * e_local * pow(r_ed, i); + w_nB = u0 * rhob_local * pow(r_nB, i); + } + if (i == 0) { + eccn_ed_num1[i] += e_local; + eccn_nB_num1[i] += rhob_local; + } else { + eccn_ed_num1[i] += w_ed * cos(i * phi_ed); + eccn_ed_num2[i] += w_ed * sin(i * phi_ed); + eccn_ed_den[i] += w_ed; + eccn_nB_num1[i] += w_nB * cos(i * phi_nB); + eccn_nB_num2[i] += w_nB * sin(i * phi_nB); + eccn_nB_den[i] += w_nB; + } } - } - meanpT_est_num[0] += tau*s_local*u0; // dS/deta_s - meanpT_est_num[1] += tau*T_00_ideal; // dE/deta_s - meanpT_est_num[2] += s_local*u0*e_local; // [s] - meanpT_est_num[3] += r_ed*r_ed*u0*e_local; // [r^2] - meanpT_est_den[0] += u0*e_local; - } + meanpT_est_num[0] += tau * s_local * u0; // dS/deta_s + meanpT_est_num[1] += tau * T_00_ideal; // dE/deta_s + meanpT_est_num[2] += s_local * u0 * e_local; // [s] + meanpT_est_num[3] += r_ed * r_ed * u0 * e_local; // [r^2] + meanpT_est_den[0] += u0 * e_local; + } // output results - of << scientific << setw(18) << setprecision(8) - << eta << " "; + of << scientific << setw(18) << setprecision(8) << eta << " "; for (int i = 0; i < 3; i++) { - of << ep_num1[i]/std::max(ep_den[i], small_eps) << " " - << ep_num2[i]/std::max(ep_den[i], small_eps)<< " "; + of << ep_num1[i] / std::max(ep_den[i], small_eps) << " " + << ep_num2[i] / std::max(ep_den[i], small_eps) << " "; } of << endl; - of1 << scientific << setw(18) << setprecision(8) - << eta << " " - << eccn_ed_num1[0]*DATA.delta_x*DATA.delta_y*hbarc << " "; + of1 << scientific << setw(18) << setprecision(8) << eta << " " + << eccn_ed_num1[0] * DATA.delta_x * DATA.delta_y * hbarc << " "; for (int i = 1; i < norder; i++) { // the minus sign ensure the vector points to the short axis - of1 << -eccn_ed_num1[i]/std::max(eccn_ed_den[i], small_eps) << " " - << -eccn_ed_num2[i]/std::max(eccn_ed_den[i], small_eps) << " "; + of1 << -eccn_ed_num1[i] / std::max(eccn_ed_den[i], small_eps) + << " " + << -eccn_ed_num2[i] / std::max(eccn_ed_den[i], small_eps) + << " "; } of1 << x_ed_o << " " << y_ed_o; of1 << endl; - of2 << scientific << setw(18) << setprecision(8) - << eta << " " - << eccn_nB_num1[0]*DATA.delta_x*DATA.delta_y << " "; + of2 << scientific << setw(18) << setprecision(8) << eta << " " + << eccn_nB_num1[0] * DATA.delta_x * DATA.delta_y << " "; for (int i = 1; i < norder; i++) { // the minus sign ensure the vector points to the short axis - of2 << -eccn_nB_num1[i]/std::max(eccn_nB_den[i], small_eps) << " " - << -eccn_nB_num2[i]/std::max(eccn_nB_den[i], small_eps) << " "; + of2 << -eccn_nB_num1[i] / std::max(eccn_nB_den[i], small_eps) + << " " + << -eccn_nB_num2[i] / std::max(eccn_nB_den[i], small_eps) + << " "; } of2 << x_nB_o << " " << y_nB_o; of2 << endl; - of3 << scientific << setw(18) << setprecision(8) - << eta << " " - << meanpT_est_num[0]*DATA.delta_x*DATA.delta_y << " " - << meanpT_est_num[1]*hbarc*DATA.delta_x*DATA.delta_y << " " - << meanpT_est_num[2]/meanpT_est_den[0] << " " - << meanpT_est_num[3]/meanpT_est_den[0] << endl; + of3 << scientific << setw(18) << setprecision(8) << eta << " " + << meanpT_est_num[0] * DATA.delta_x * DATA.delta_y << " " + << meanpT_est_num[1] * hbarc * DATA.delta_x * DATA.delta_y << " " + << meanpT_est_num[2] / meanpT_est_den[0] << " " + << meanpT_est_num[3] / meanpT_est_den[0] << endl; } of.close(); of1.close(); @@ -2130,14 +2141,13 @@ void Cell_info::output_momentum_anisotropy_vs_etas( of3.close(); } - //! This function outputs system's momentum anisotropy as a function of tau void Cell_info::output_momentum_anisotropy_vs_tau( - const double tau, const double eta_min, const double eta_max, - Fields &arena) const { + const double tau, const double eta_min, const double eta_max, + Fields &arena) const { ostringstream filename; - filename << "momentum_anisotropy_eta_" << eta_min - << "_" << eta_max << ".dat"; + filename << "momentum_anisotropy_eta_" << eta_min << "_" << eta_max + << ".dat"; std::fstream of; if (std::abs(tau - DATA.tau0) < 1e-10) { of.open(filename.str().c_str(), std::fstream::out); @@ -2149,36 +2159,34 @@ void Cell_info::output_momentum_anisotropy_vs_tau( << "epsilon_2p(full)(cos) epsilon_2p(full)(sin) " << "epsilon_3p(ideal)(cos) epsilon_3p(ideal)(sin) " << "epsilon_3p(shear)(cos) epsilon_3p(shear)(sin) " - << "epsilon_3p(full)(cos) epsilon_3p(full)(sin) " - << endl; + << "epsilon_3p(full)(cos) epsilon_3p(full)(sin) " << endl; } else { - of.open(filename.str().c_str(), - std::fstream::out | std::fstream::app); + of.open(filename.str().c_str(), std::fstream::out | std::fstream::app); } ostringstream filename1; - filename1 << "eccentricities_evo_eta_" << eta_min - << "_" << eta_max << ".dat"; + filename1 << "eccentricities_evo_eta_" << eta_min << "_" << eta_max + << ".dat"; std::fstream of1; if (std::abs(tau - DATA.tau0) < 1e-10) { of1.open(filename1.str().c_str(), std::fstream::out); of1 << "# tau(fm) ecc_n(cos) ecc_n(sin) (n=1-6) x_o (fm) y_o (fm)" << endl; } else { - of1.open(filename1.str().c_str(), - std::fstream::out | std::fstream::app); + of1.open( + filename1.str().c_str(), std::fstream::out | std::fstream::app); } ostringstream filename2; - filename2 << "inverse_Reynolds_number_eta_" << eta_min - << "_" << eta_max << ".dat"; + filename2 << "inverse_Reynolds_number_eta_" << eta_min << "_" << eta_max + << ".dat"; std::fstream of2; if (std::abs(tau - DATA.tau0) < 1e-10) { of2.open(filename2.str().c_str(), std::fstream::out); of2 << "# tau(fm) R_shearpi R_Pi gamma T[GeV]" << endl; } else { - of2.open(filename2.str().c_str(), - std::fstream::out | std::fstream::app); + of2.open( + filename2.str().c_str(), std::fstream::out | std::fstream::app); } ostringstream filename3; @@ -2190,63 +2198,64 @@ void Cell_info::output_momentum_anisotropy_vs_tau( of3 << "# tau (fm) dS/deta_s dE/deta_s (GeV) [s] (1/fm^-3) " << "[r^2] (fm^2)" << endl; } else { - of3.open(filename3.str().c_str(), - std::fstream::out | std::fstream::app); + of3.open( + filename3.str().c_str(), std::fstream::out | std::fstream::app); } double ideal_num1 = 0.0; double ideal_num2 = 0.0; - double ideal_den = 0.0; + double ideal_den = 0.0; double shear_num1 = 0.0; double shear_num2 = 0.0; - double shear_den = 0.0; - double full_num1 = 0.0; - double full_num2 = 0.0; - double full_den = 0.0; + double shear_den = 0.0; + double full_num1 = 0.0; + double full_num2 = 0.0; + double full_den = 0.0; double u_perp_num = 0.0; double u_perp_den = 0.0; - double T_avg_num = 0.0; - double T_avg_den = 0.0; - double R_Pi_num = 0.0; - double R_Pi_den = 0.0; - double R_shearpi_num = 0.0; - double R_shearpi_den = 0.0; + double T_avg_num = 0.0; + double T_avg_den = 0.0; + double R_Pi_num = 0.0; + double R_Pi_den = 0.0; + double R_shearpi_num = 0.0; + double R_shearpi_den = 0.0; // compute epsilon_{p2} and epsilon_{p3} using T^{0\mu} vector // epsilon_{pn} = (\int (T^{0r} exp(i n \phi_u))/(\int T^{0r}) // for every n, we compute T^{0\mu} for ideal, ideal + shear, and full std::vector ep_num1(6, 0.0); std::vector ep_num2(6, 0.0); - std::vector ep_den (6, 0.0); + std::vector ep_den(6, 0.0); const int norder = 6; std::vector eccn_num1(norder, 0.0); std::vector eccn_num2(norder, 0.0); - std::vector eccn_den (norder, 0.0); + std::vector eccn_den(norder, 0.0); std::vector meanpT_est_num(4, 0.0); std::vector meanpT_est_den(1, 0.0); std::vector thermalVec; - double x_o = 0.0; - double y_o = 0.0; + double x_o = 0.0; + double y_o = 0.0; double w_sum = 0.0; for (int ieta = 0; ieta < arena.nEta(); ieta++) { double eta = 0.0; if (!DATA.boost_invariant) { - eta = ((static_cast(ieta))*(DATA.delta_eta) - - (DATA.eta_size)/2.0); + eta = + ((static_cast(ieta)) * (DATA.delta_eta) + - (DATA.eta_size) / 2.0); } if (eta < eta_max && eta > eta_min) { for (int iy = 0; iy < arena.nY(); iy++) - for (int ix = 0; ix < arena.nX(); ix++) { - int fieldIdx = arena.getFieldIdx(ix, iy, ieta); - double x_local = - DATA.x_size/2. + ix*DATA.delta_x; - double y_local = - DATA.y_size/2. + iy*DATA.delta_y; - double e_local = arena.e_[fieldIdx]; // 1/fm^4 - double gamma_perp = arena.u_[0][fieldIdx]; - x_o += x_local*e_local*gamma_perp; - y_o += y_local*e_local*gamma_perp; - w_sum += e_local*gamma_perp; - } + for (int ix = 0; ix < arena.nX(); ix++) { + int fieldIdx = arena.getFieldIdx(ix, iy, ieta); + double x_local = -DATA.x_size / 2. + ix * DATA.delta_x; + double y_local = -DATA.y_size / 2. + iy * DATA.delta_y; + double e_local = arena.e_[fieldIdx]; // 1/fm^4 + double gamma_perp = arena.u_[0][fieldIdx]; + x_o += x_local * e_local * gamma_perp; + y_o += y_local * e_local * gamma_perp; + w_sum += e_local * gamma_perp; + } } } x_o /= w_sum; @@ -2254,168 +2263,173 @@ void Cell_info::output_momentum_anisotropy_vs_tau( for (int ieta = 0; ieta < arena.nEta(); ieta++) { double eta = 0.0; if (!DATA.boost_invariant) { - eta = ((static_cast(ieta))*(DATA.delta_eta) - - (DATA.eta_size)/2.0); + eta = + ((static_cast(ieta)) * (DATA.delta_eta) + - (DATA.eta_size) / 2.0); } if (eta < eta_max && eta > eta_min) { for (int iy = 0; iy < arena.nY(); iy++) - for (int ix = 0; ix < arena.nX(); ix++) { - int fieldIdx = arena.getFieldIdx(ix, iy, ieta); - double x_local = (- DATA.x_size/2. + ix*DATA.delta_x - x_o); - double y_local = (- DATA.y_size/2. + iy*DATA.delta_y - y_o); - double r_local = sqrt(x_local*x_local + y_local*y_local); - double phi_local = atan2(y_local, x_local); - - double e_local = arena.e_[fieldIdx]; // 1/fm^4 - eos.getThermalVariables(e_local, arena.rhob_[fieldIdx], - thermalVec); - double P_local = thermalVec[2]; - double enthopy = e_local + P_local; - double u0 = arena.u_[0][fieldIdx]; - double ux = arena.u_[1][fieldIdx]; - double uy = arena.u_[2][fieldIdx]; - double pi_0x = arena.Wmunu_[1][fieldIdx]; - double pi_0y = arena.Wmunu_[2][fieldIdx]; - double pi_xx = arena.Wmunu_[4][fieldIdx]; - double pi_xy = arena.Wmunu_[5][fieldIdx]; - double pi_yy = arena.Wmunu_[7][fieldIdx]; - double bulk_Pi = arena.piBulk_[fieldIdx]; - - double T_00_ideal = enthopy*u0*u0 - P_local; - double T_0x_ideal = enthopy*u0*ux; - double T_0y_ideal = enthopy*u0*uy; - double T_0r_ideal = sqrt( T_0x_ideal*T_0x_ideal - + T_0y_ideal*T_0y_ideal); - double phi_u_ideal = atan2(T_0y_ideal, T_0x_ideal); - double T_xx_ideal = enthopy*ux*ux + P_local; - double T_xy_ideal = enthopy*ux*uy; - double T_yy_ideal = enthopy*uy*uy + P_local; - - double T_0x_shear = T_0x_ideal + pi_0x; - double T_0y_shear = T_0y_ideal + pi_0y; - double T_0r_shear = sqrt( T_0x_shear*T_0x_shear - + T_0y_shear*T_0y_shear); - double phi_u_shear = atan2(T_0y_shear, T_0x_shear); - double T_xx_shear = T_xx_ideal + pi_xx; - double T_xy_shear = T_xy_ideal + pi_xy; - double T_yy_shear = T_yy_ideal + pi_yy; - - double T_0x_full = T_0x_shear + bulk_Pi*u0*ux; - double T_0y_full = T_0y_shear + bulk_Pi*u0*uy; - double T_0r_full = sqrt( T_0x_full*T_0x_full - + T_0y_full*T_0y_full); - double phi_u_full = atan2(T_0y_full, T_0x_full); - double T_xx_full = T_xx_shear - bulk_Pi*(-1 - ux*ux); - double T_xy_full = T_xy_shear + bulk_Pi*ux*uy; - double T_yy_full = T_yy_shear - bulk_Pi*(-1 - uy*uy); - - ideal_num1 += T_xx_ideal - T_yy_ideal; - ideal_num2 += 2.*T_xy_ideal; - ideal_den += T_xx_ideal + T_yy_ideal; - shear_num1 += T_xx_shear - T_yy_shear; - shear_num2 += 2.*T_xy_shear; - shear_den += T_xx_shear + T_yy_shear; - full_num1 += T_xx_full - T_yy_full; - full_num2 += 2.*T_xy_full; - full_den += T_xx_full + T_yy_full; - - double weight_local = e_local; - u_perp_num += weight_local*u0; - u_perp_den += weight_local; - T_avg_num += weight_local*thermalVec[6]; - T_avg_den += weight_local; - - if (e_local > 1e-3) { - double r_shearpi, r_bulkPi; - calculate_inverse_Reynolds_numbers( + for (int ix = 0; ix < arena.nX(); ix++) { + int fieldIdx = arena.getFieldIdx(ix, iy, ieta); + double x_local = + (-DATA.x_size / 2. + ix * DATA.delta_x - x_o); + double y_local = + (-DATA.y_size / 2. + iy * DATA.delta_y - y_o); + double r_local = + sqrt(x_local * x_local + y_local * y_local); + double phi_local = atan2(y_local, x_local); + + double e_local = arena.e_[fieldIdx]; // 1/fm^4 + eos.getThermalVariables( + e_local, arena.rhob_[fieldIdx], thermalVec); + double P_local = thermalVec[2]; + double enthopy = e_local + P_local; + double u0 = arena.u_[0][fieldIdx]; + double ux = arena.u_[1][fieldIdx]; + double uy = arena.u_[2][fieldIdx]; + double pi_0x = arena.Wmunu_[1][fieldIdx]; + double pi_0y = arena.Wmunu_[2][fieldIdx]; + double pi_xx = arena.Wmunu_[4][fieldIdx]; + double pi_xy = arena.Wmunu_[5][fieldIdx]; + double pi_yy = arena.Wmunu_[7][fieldIdx]; + double bulk_Pi = arena.piBulk_[fieldIdx]; + + double T_00_ideal = enthopy * u0 * u0 - P_local; + double T_0x_ideal = enthopy * u0 * ux; + double T_0y_ideal = enthopy * u0 * uy; + double T_0r_ideal = + sqrt(T_0x_ideal * T_0x_ideal + T_0y_ideal * T_0y_ideal); + double phi_u_ideal = atan2(T_0y_ideal, T_0x_ideal); + double T_xx_ideal = enthopy * ux * ux + P_local; + double T_xy_ideal = enthopy * ux * uy; + double T_yy_ideal = enthopy * uy * uy + P_local; + + double T_0x_shear = T_0x_ideal + pi_0x; + double T_0y_shear = T_0y_ideal + pi_0y; + double T_0r_shear = + sqrt(T_0x_shear * T_0x_shear + T_0y_shear * T_0y_shear); + double phi_u_shear = atan2(T_0y_shear, T_0x_shear); + double T_xx_shear = T_xx_ideal + pi_xx; + double T_xy_shear = T_xy_ideal + pi_xy; + double T_yy_shear = T_yy_ideal + pi_yy; + + double T_0x_full = T_0x_shear + bulk_Pi * u0 * ux; + double T_0y_full = T_0y_shear + bulk_Pi * u0 * uy; + double T_0r_full = + sqrt(T_0x_full * T_0x_full + T_0y_full * T_0y_full); + double phi_u_full = atan2(T_0y_full, T_0x_full); + double T_xx_full = T_xx_shear - bulk_Pi * (-1 - ux * ux); + double T_xy_full = T_xy_shear + bulk_Pi * ux * uy; + double T_yy_full = T_yy_shear - bulk_Pi * (-1 - uy * uy); + + ideal_num1 += T_xx_ideal - T_yy_ideal; + ideal_num2 += 2. * T_xy_ideal; + ideal_den += T_xx_ideal + T_yy_ideal; + shear_num1 += T_xx_shear - T_yy_shear; + shear_num2 += 2. * T_xy_shear; + shear_den += T_xx_shear + T_yy_shear; + full_num1 += T_xx_full - T_yy_full; + full_num2 += 2. * T_xy_full; + full_den += T_xx_full + T_yy_full; + + double weight_local = e_local; + u_perp_num += weight_local * u0; + u_perp_den += weight_local; + T_avg_num += weight_local * thermalVec[6]; + T_avg_den += weight_local; + + if (e_local > 1e-3) { + double r_shearpi, r_bulkPi; + calculate_inverse_Reynolds_numbers( arena, fieldIdx, P_local, r_shearpi, r_bulkPi); - R_shearpi_num += weight_local*r_shearpi; - R_shearpi_den += weight_local; - R_Pi_num += weight_local*r_bulkPi; - R_Pi_den += weight_local; - } + R_shearpi_num += weight_local * r_shearpi; + R_shearpi_den += weight_local; + R_Pi_num += weight_local * r_bulkPi; + R_Pi_den += weight_local; + } - for (int i = 0; i < 2; i++) { - int idx = 3*i; - int iorder = 2+i; - ep_num1[idx] += T_0r_ideal*cos(iorder*phi_u_ideal); - ep_num2[idx] += T_0r_ideal*sin(iorder*phi_u_ideal); - ep_den [idx] += T_0r_ideal; - ep_num1[idx+1] += T_0r_shear*cos(iorder*phi_u_shear); - ep_num2[idx+1] += T_0r_shear*sin(iorder*phi_u_shear); - ep_den [idx+1] += T_0r_shear; - ep_num1[idx+2] += T_0r_full*cos(iorder*phi_u_full); - ep_num2[idx+2] += T_0r_full*sin(iorder*phi_u_full); - ep_den [idx+2] += T_0r_full; - } - for (int i = 1; i <= norder; i++) { - if (i == 1) { - weight_local = u0*e_local*pow(r_local, 3); - } else { - weight_local = u0*e_local*pow(r_local, i); + for (int i = 0; i < 2; i++) { + int idx = 3 * i; + int iorder = 2 + i; + ep_num1[idx] += T_0r_ideal * cos(iorder * phi_u_ideal); + ep_num2[idx] += T_0r_ideal * sin(iorder * phi_u_ideal); + ep_den[idx] += T_0r_ideal; + ep_num1[idx + 1] += + T_0r_shear * cos(iorder * phi_u_shear); + ep_num2[idx + 1] += + T_0r_shear * sin(iorder * phi_u_shear); + ep_den[idx + 1] += T_0r_shear; + ep_num1[idx + 2] += + T_0r_full * cos(iorder * phi_u_full); + ep_num2[idx + 2] += + T_0r_full * sin(iorder * phi_u_full); + ep_den[idx + 2] += T_0r_full; + } + for (int i = 1; i <= norder; i++) { + if (i == 1) { + weight_local = u0 * e_local * pow(r_local, 3); + } else { + weight_local = u0 * e_local * pow(r_local, i); + } + eccn_num1[i - 1] += weight_local * cos(i * phi_local); + eccn_num2[i - 1] += weight_local * sin(i * phi_local); + eccn_den[i - 1] += weight_local; } - eccn_num1[i-1] += weight_local*cos(i*phi_local); - eccn_num2[i-1] += weight_local*sin(i*phi_local); - eccn_den [i-1] += weight_local; - } - meanpT_est_num[0] += tau*thermalVec[12]*u0; // dS/deta_s - meanpT_est_num[1] += tau*T_00_ideal; // dE/deta_s - meanpT_est_num[2] += thermalVec[12]*u0*e_local; // [s] - meanpT_est_num[3] += r_local*r_local*u0*e_local; // [r^2] - meanpT_est_den[0] += u0*e_local; - } + meanpT_est_num[0] += + tau * thermalVec[12] * u0; // dS/deta_s + meanpT_est_num[1] += tau * T_00_ideal; // dE/deta_s + meanpT_est_num[2] += thermalVec[12] * u0 * e_local; // [s] + meanpT_est_num[3] += + r_local * r_local * u0 * e_local; // [r^2] + meanpT_est_den[0] += u0 * e_local; + } } } - double R_shearpi = R_shearpi_num/std::max(R_shearpi_den, small_eps); - double R_Pi = R_Pi_num/std::max(R_Pi_den, small_eps); - double u_avg = u_perp_num/std::max(u_perp_den, small_eps); - double T_avg = T_avg_num/std::max(T_avg_den, small_eps)*hbarc; - - of << scientific << setw(18) << setprecision(8) - << tau << " " - << ideal_num1/std::max(ideal_den, small_eps) << " " - << ideal_num2/std::max(ideal_den, small_eps) << " " - << shear_num1/std::max(shear_den, small_eps) << " " - << shear_num2/std::max(shear_den, small_eps) << " " - << full_num1/std::max(full_den, small_eps) << " " - << full_num2/std::max(full_den, small_eps) << " "; + double R_shearpi = R_shearpi_num / std::max(R_shearpi_den, small_eps); + double R_Pi = R_Pi_num / std::max(R_Pi_den, small_eps); + double u_avg = u_perp_num / std::max(u_perp_den, small_eps); + double T_avg = T_avg_num / std::max(T_avg_den, small_eps) * hbarc; + + of << scientific << setw(18) << setprecision(8) << tau << " " + << ideal_num1 / std::max(ideal_den, small_eps) << " " + << ideal_num2 / std::max(ideal_den, small_eps) << " " + << shear_num1 / std::max(shear_den, small_eps) << " " + << shear_num2 / std::max(shear_den, small_eps) << " " + << full_num1 / std::max(full_den, small_eps) << " " + << full_num2 / std::max(full_den, small_eps) << " "; for (int i = 0; i < 6; i++) { - of << ep_num1[i]/std::max(ep_den[i], small_eps) << " " - << ep_num2[i]/std::max(ep_den[i], small_eps)<< " "; + of << ep_num1[i] / std::max(ep_den[i], small_eps) << " " + << ep_num2[i] / std::max(ep_den[i], small_eps) << " "; } of << endl; of.close(); - of1 << scientific << setw(18) << setprecision(8) - << tau << " "; + of1 << scientific << setw(18) << setprecision(8) << tau << " "; for (int i = 0; i < norder; i++) { // the minus sign ensure the vector points to the short axis - of1 << -eccn_num1[i]/std::max(eccn_den[i], small_eps) << " " - << -eccn_num2[i]/std::max(eccn_den[i], small_eps)<< " "; + of1 << -eccn_num1[i] / std::max(eccn_den[i], small_eps) << " " + << -eccn_num2[i] / std::max(eccn_den[i], small_eps) << " "; } of1 << x_o << " " << y_o; of1 << endl; of1.close(); - of2 << scientific << setw(18) << setprecision(8) - << tau << " " << R_shearpi << " " << R_Pi << " " - << u_avg << " " << T_avg << endl; + of2 << scientific << setw(18) << setprecision(8) << tau << " " << R_shearpi + << " " << R_Pi << " " << u_avg << " " << T_avg << endl; of2.close(); - of3 << scientific << setw(18) << setprecision(8) - << tau << " " - << meanpT_est_num[0]*DATA.delta_x*DATA.delta_y << " " - << meanpT_est_num[1]*hbarc*DATA.delta_x*DATA.delta_y << " " - << meanpT_est_num[2]/meanpT_est_den[0] << " " - << meanpT_est_num[3]/meanpT_est_den[0] << endl; + of3 << scientific << setw(18) << setprecision(8) << tau << " " + << meanpT_est_num[0] * DATA.delta_x * DATA.delta_y << " " + << meanpT_est_num[1] * hbarc * DATA.delta_x * DATA.delta_y << " " + << meanpT_est_num[2] / meanpT_est_den[0] << " " + << meanpT_est_num[3] / meanpT_est_den[0] << endl; of3.close(); } - -void Cell_info::get_LRF_shear_stress_tensor(const Fields &arena, - const int Idx, const double eta_s, - ShearVisVecLRF &res) { +void Cell_info::get_LRF_shear_stress_tensor( + const Fields &arena, const int Idx, const double eta_s, + ShearVisVecLRF &res) { const double cosh_eta = cosh(eta_s); const double sinh_eta = sinh(eta_s); @@ -2423,37 +2437,40 @@ void Cell_info::get_LRF_shear_stress_tensor(const Fields &arena, double ux = arena.u_[1][Idx]; double uy = arena.u_[2][Idx]; double u3 = arena.u_[3][Idx]; - double ut = u0*cosh_eta + u3*sinh_eta; - double uz = u3*cosh_eta + u0*sinh_eta; + double ut = u0 * cosh_eta + u3 * sinh_eta; + double uz = u3 * cosh_eta + u0 * sinh_eta; double LorentzBoost[4][4] = { {ut, -ux, -uy, -uz}, - {-ux, 1. + ux*ux/(ut+1.), ux*uy/(ut+1.), ux*uz/(ut+1.)}, - {-uy, ux*uy/(ut+1.), 1. + uy*uy/(ut+1.), uy*uz/(ut+1.)}, - {-uz, ux*uz/(ut+1.), uy*uz/(ut+1.), 1. + uz*uz/(ut+1.)} - }; + {-ux, 1. + ux * ux / (ut + 1.), ux * uy / (ut + 1.), + ux * uz / (ut + 1.)}, + {-uy, ux * uy / (ut + 1.), 1. + uy * uy / (ut + 1.), + uy * uz / (ut + 1.)}, + {-uz, ux * uz / (ut + 1.), uy * uz / (ut + 1.), + 1. + uz * uz / (ut + 1.)}}; ViscousVec ShearVisVec; for (unsigned int i = 0; i < ShearVisVec.size(); i++) { ShearVisVec[i] = arena.Wmunu_[i][Idx]; } double pi_tz[4][4]; - pi_tz[0][0] = ( ShearVisVec[0]*cosh_eta*cosh_eta - + 2.*ShearVisVec[3]*cosh_eta*sinh_eta - + ShearVisVec[9]*sinh_eta*sinh_eta); - pi_tz[0][1] = ShearVisVec[1]*cosh_eta + ShearVisVec[6]*sinh_eta; - pi_tz[0][2] = ShearVisVec[2]*cosh_eta + ShearVisVec[8]*sinh_eta; - pi_tz[0][3] = ( ShearVisVec[0]*cosh_eta*sinh_eta - + ShearVisVec[3]*(cosh_eta*cosh_eta - + sinh_eta*sinh_eta) - + ShearVisVec[9]*sinh_eta*cosh_eta); + pi_tz[0][0] = + (ShearVisVec[0] * cosh_eta * cosh_eta + + 2. * ShearVisVec[3] * cosh_eta * sinh_eta + + ShearVisVec[9] * sinh_eta * sinh_eta); + pi_tz[0][1] = ShearVisVec[1] * cosh_eta + ShearVisVec[6] * sinh_eta; + pi_tz[0][2] = ShearVisVec[2] * cosh_eta + ShearVisVec[8] * sinh_eta; + pi_tz[0][3] = + (ShearVisVec[0] * cosh_eta * sinh_eta + + ShearVisVec[3] * (cosh_eta * cosh_eta + sinh_eta * sinh_eta) + + ShearVisVec[9] * sinh_eta * cosh_eta); pi_tz[1][0] = pi_tz[0][1]; pi_tz[1][1] = ShearVisVec[4]; pi_tz[1][2] = ShearVisVec[5]; - pi_tz[1][3] = ShearVisVec[1]*sinh_eta + ShearVisVec[6]*cosh_eta; + pi_tz[1][3] = ShearVisVec[1] * sinh_eta + ShearVisVec[6] * cosh_eta; pi_tz[2][0] = pi_tz[0][2]; pi_tz[2][1] = pi_tz[1][2]; pi_tz[2][2] = ShearVisVec[7]; - pi_tz[2][3] = ShearVisVec[2]*sinh_eta + ShearVisVec[8]*cosh_eta; + pi_tz[2][3] = ShearVisVec[2] * sinh_eta + ShearVisVec[8] * cosh_eta; pi_tz[3][0] = pi_tz[0][3]; pi_tz[3][1] = pi_tz[1][3]; pi_tz[3][2] = pi_tz[2][3]; @@ -2464,8 +2481,8 @@ void Cell_info::get_LRF_shear_stress_tensor(const Fields &arena, pi_LRF[i][j] = 0.; for (int a = 0; a < 4; a++) { for (int b = 0; b < 4; b++) { - pi_LRF[i][j] += (LorentzBoost[i][a]*pi_tz[a][b] - *LorentzBoost[b][j]); + pi_LRF[i][j] += + (LorentzBoost[i][a] * pi_tz[a][b] * LorentzBoost[b][j]); } } } @@ -2477,15 +2494,14 @@ void Cell_info::get_LRF_shear_stress_tensor(const Fields &arena, res[4] = pi_LRF[2][3]; double q_tz[4]; - q_tz[0] = ShearVisVec[10]*cosh_eta + ShearVisVec[13]*sinh_eta; + q_tz[0] = ShearVisVec[10] * cosh_eta + ShearVisVec[13] * sinh_eta; q_tz[1] = ShearVisVec[11]; q_tz[2] = ShearVisVec[12]; - q_tz[3] = ShearVisVec[10]*sinh_eta + ShearVisVec[13]*cosh_eta; + q_tz[3] = ShearVisVec[10] * sinh_eta + ShearVisVec[13] * cosh_eta; double q_LRF[4]; for (int i = 1; i < 4; i++) { q_LRF[i] = 0.; - for (int a = 0; a < 4; a++) - q_LRF[i] += LorentzBoost[i][a]*q_tz[a]; + for (int a = 0; a < 4; a++) q_LRF[i] += LorentzBoost[i][a] * q_tz[a]; } res[5] = q_LRF[1]; res[6] = q_LRF[2]; diff --git a/src/grid_info.h b/src/grid_info.h index 6caa213f..d5d2ddde 100644 --- a/src/grid_info.h +++ b/src/grid_info.h @@ -5,17 +5,17 @@ #include +#include "HydroinfoMUSIC.h" +#include "cell.h" #include "data.h" #include "data_struct.h" #include "eos.h" -#include "cell.h" #include "fields.h" -#include "u_derivative.h" #include "pretty_ostream.h" -#include "HydroinfoMUSIC.h" +#include "u_derivative.h" class Cell_info { - private: + private: const InitData &DATA; const EOS &eos; U_derivative u_derivative_helper; @@ -43,7 +43,7 @@ class Cell_info { TJbVec Pmu_edge_prev, outflow_flux; - public: + public: Cell_info(const InitData &DATA_in, const EOS &eos_ptr_in); ~Cell_info(); @@ -56,27 +56,27 @@ class Cell_info { //! This function outputs hydro evolution file in binary format void OutputEvolutionDataXYEta_chun(Fields &arena, double tau); - //! This function outputs hydro evolution file in binary format for photon production + //! This function outputs hydro evolution file in binary format for photon + //! production void OutputEvolutionDataXYEta_photon(Fields &arena, double tau); //! This function outputs hydro evolution file in binary format void OutputEvolutionDataXYEta_vorticity( - Fields &arena_curr, Fields &arena_prev, double tau); + Fields &arena_curr, Fields &arena_prev, double tau); void load_deltaf_qmu_coeff_table(std::string filename); void load_deltaf_qmu_coeff_table_14mom(std::string filename); double get_deltaf_qmu_coeff(double T, double muB); double get_deltaf_coeff_14moments(double T, double muB, double type); - //! This function computes the inverse Reynolds number for a given fluid //! cell at (ix, iy, ieta) - void calculate_inverse_Reynolds_numbers(Fields &arena, const int Idx, - const double P_local, - double &R_pi, double &R_Pi) const; + void calculate_inverse_Reynolds_numbers( + Fields &arena, const int Idx, const double P_local, double &R_pi, + double &R_Pi) const; - void OutputEvolution_Knudsen_Reynoldsnumbers(Fields &arena, - const double tau) const; + void OutputEvolution_Knudsen_Reynoldsnumbers( + Fields &arena, const double tau) const; //! This function outputs files to check with Gubser flow solution void Gubser_flow_check_file(Fields &arena, const double tau); @@ -109,44 +109,44 @@ class Cell_info { const double eta_min, const double eta_max); //! This function dumps the energy density and net baryon density - void output_energy_density_and_rhob_disitrubtion(Fields &arena, - std::string filename); + void output_energy_density_and_rhob_disitrubtion( + Fields &arena, std::string filename); //! This function computes global angular momentum at a give proper time - void compute_angular_momentum(Fields &arena, Fields &arena_prev, - const double tau, - const double eta_min, const double eta_max); + void compute_angular_momentum( + Fields &arena, Fields &arena_prev, const double tau, + const double eta_min, const double eta_max); //! This function checks the total energy and total net baryon number //! at a give proper time - void check_conservation_law(Fields &arena, Fields &arena_prev, - const double tau); + void check_conservation_law( + Fields &arena, Fields &arena_prev, const double tau); //! This function outputs the evolution of hydrodynamic variables at a //! give fluid cell - void monitor_a_fluid_cell(Fields &arena_curr, Fields &arena_prev, - const int ix, const int iy, const int ieta, - const double tau); + void monitor_a_fluid_cell( + Fields &arena_curr, Fields &arena_prev, const int ix, const int iy, + const int ieta, const double tau); //! This function outputs system's momentum anisotropy as a function of tau void output_momentum_anisotropy_vs_tau( - const double tau, const double eta_min, const double eta_max, - Fields &arena) const; + const double tau, const double eta_min, const double eta_max, + Fields &arena) const; //! This function outputs system's eccentricity and momentum anisotropy //! as functions of eta_s - void output_momentum_anisotropy_vs_etas(const double tau, - Fields &arena) const; + void output_momentum_anisotropy_vs_etas( + const double tau, Fields &arena) const; //! This function outputs hydro evolution file into memory for JETSCAPE void OutputEvolutionDataXYEta_memory( - Fields &arena, const double tau, HydroinfoMUSIC &hydro_info_ptr); - + Fields &arena, const double tau, HydroinfoMUSIC &hydro_info_ptr); //! This function computes the pi^{\mu\nu} in the local rest frame //! and in the Cartisian coordinates - void get_LRF_shear_stress_tensor(const Fields &cell, const int Idx, - const double eta_s, ShearVisVecLRF &res); + void get_LRF_shear_stress_tensor( + const Fields &cell, const int Idx, const double eta_s, + ShearVisVecLRF &res); }; #endif // SRC_GRID_INFO_H_ diff --git a/src/grid_unittest.cpp b/src/grid_unittest.cpp index 05e4c57a..e35b119b 100644 --- a/src/grid_unittest.cpp +++ b/src/grid_unittest.cpp @@ -1,9 +1,11 @@ #include "grid.h" -#include "doctest.h" + #include #include -TEST_CASE("Does grid copy work"){ +#include "doctest.h" + +TEST_CASE("Does grid copy work") { SCGrid grid(3, 3, 3); grid(0, 0, 0).epsilon = 3; auto grid2 = grid; @@ -12,74 +14,77 @@ TEST_CASE("Does grid copy work"){ TEST_CASE("check neighbourloop1") { SCGrid grid(1, 1, 1); - grid(0,0,0).epsilon = 3; - Neighbourloop(grid, 0, 0, 0, NLAMBDAS { - CHECK(c.epsilon == p1.epsilon); - CHECK(c.epsilon == p2.epsilon); - CHECK(c.epsilon == m1.epsilon); - CHECK(c.epsilon == m2.epsilon); - }); + grid(0, 0, 0).epsilon = 3; + Neighbourloop( + grid, 0, 0, 0, NLAMBDAS { + CHECK(c.epsilon == p1.epsilon); + CHECK(c.epsilon == p2.epsilon); + CHECK(c.epsilon == m1.epsilon); + CHECK(c.epsilon == m2.epsilon); + }); } - + TEST_CASE("check neighbourloop2") { SCGrid grid1(5, 1, 1); for (int i = 0; i < 5; i++) { grid1(i, 0, 0).epsilon = i + 1; } - Neighbourloop(grid1, 2, 0, 0, NLAMBDAS { - if (direction == 1) { - CHECK(p1.epsilon == 4); - CHECK(p2.epsilon == 5); - CHECK(m1.epsilon == 2); - CHECK(m2.epsilon == 1); - } else { - CHECK(p1.epsilon == c.epsilon); - CHECK(p2.epsilon == c.epsilon); - CHECK(m1.epsilon == c.epsilon); - CHECK(m2.epsilon == c.epsilon); - } - }); + Neighbourloop( + grid1, 2, 0, 0, NLAMBDAS { + if (direction == 1) { + CHECK(p1.epsilon == 4); + CHECK(p2.epsilon == 5); + CHECK(m1.epsilon == 2); + CHECK(m2.epsilon == 1); + } else { + CHECK(p1.epsilon == c.epsilon); + CHECK(p2.epsilon == c.epsilon); + CHECK(m1.epsilon == c.epsilon); + CHECK(m2.epsilon == c.epsilon); + } + }); } - + TEST_CASE("check neighbourloop3") { SCGrid grid2(3, 3, 3); - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - for (int k = 0; k < 3; k++) { - grid2(i, j, k).epsilon = 1; - } + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) + for (int k = 0; k < 3; k++) { + grid2(i, j, k).epsilon = 1; + } - Neighbourloop(grid2, 1, 1, 1, NLAMBDAS { - int sum = 0; - sum += c.epsilon; - sum += p1.epsilon; - sum += p2.epsilon; - sum += m1.epsilon; - sum += m2.epsilon; - CHECK(sum == 5); - }); + Neighbourloop( + grid2, 1, 1, 1, NLAMBDAS { + int sum = 0; + sum += c.epsilon; + sum += p1.epsilon; + sum += p2.epsilon; + sum += m1.epsilon; + sum += m2.epsilon; + CHECK(sum == 5); + }); } -TEST_CASE("check neighbourloop4"){ +TEST_CASE("check neighbourloop4") { SCGrid grid(1, 1, 1); grid(0, 0, 0).epsilon = 1; int sum = 0; - Neighbourloop(grid, 0, 0, 0, NLAMBDAS { - sum += c.epsilon; - sum += p1.epsilon; - sum += p2.epsilon; - sum += m1.epsilon; - sum += m2.epsilon; - }); + Neighbourloop( + grid, 0, 0, 0, NLAMBDAS { + sum += c.epsilon; + sum += p1.epsilon; + sum += p2.epsilon; + sum += m1.epsilon; + sum += m2.epsilon; + }); CHECK(sum == 15); } -TEST_CASE("check dimension"){ - SCGrid grid(1, 2,3); +TEST_CASE("check dimension") { + SCGrid grid(1, 2, 3); - CHECK(grid.nX() == 1); - CHECK(grid.nY() == 2); + CHECK(grid.nX() == 1); + CHECK(grid.nY() == 2); CHECK(grid.nEta() == 3); } - diff --git a/src/hydro_source_TATB.cpp b/src/hydro_source_TATB.cpp index e8c2f5e0..22d18e75 100644 --- a/src/hydro_source_TATB.cpp +++ b/src/hydro_source_TATB.cpp @@ -1,22 +1,21 @@ // Copyright 2019 Chun Shen -#include -#include -#include -#include +#include "hydro_source_TATB.h" + #include #include +#include +#include #include +#include +#include -#include "hydro_source_TATB.h" #include "util.h" using std::string; - -HydroSourceTATB::HydroSourceTATB(InitData &DATA_in) : - DATA_(DATA_in) { - double tau_overlap = 2.*7./(sinh(DATA_.beam_rapidity)); +HydroSourceTATB::HydroSourceTATB(InitData &DATA_in) : DATA_(DATA_in) { + double tau_overlap = 2. * 7. / (sinh(DATA_.beam_rapidity)); tau_source = std::max(DATA_.tau0, tau_overlap); set_source_tau_min(tau_source); set_source_tau_max(tau_source); @@ -32,8 +31,8 @@ HydroSourceTATB::HydroSourceTATB(InitData &DATA_in) : } double N_B = TA_ + TB_; - double total_energy = DATA_.ecm/2.*N_B; - double total_pz = DATA_.ecm/2.*(TA_ - TB_); + double total_energy = DATA_.ecm / 2. * N_B; + double total_pz = DATA_.ecm / 2. * (TA_ - TB_); music_message << "sqrt{s} = " << DATA_.ecm << " GeV, " << "beam rapidity = " << DATA_.beam_rapidity << ", " << "total energy = " << total_energy << " GeV, " @@ -51,18 +50,16 @@ HydroSourceTATB::HydroSourceTATB(InitData &DATA_in) : music_message.flush("info"); } - HydroSourceTATB::~HydroSourceTATB() { profile_TA.clear(); profile_TB.clear(); } - //! This function reads in the spatal information of the nuclear thickness //! functions void HydroSourceTATB::read_in_TATB() { - music_message << "read in TA and TB from " << DATA_.initName_TA - << " and " << DATA_.initName_TB; + music_message << "read in TA and TB from " << DATA_.initName_TA << " and " + << DATA_.initName_TB; music_message.flush("info"); std::ifstream TAfile(DATA_.initName_TA.c_str()); @@ -99,11 +96,10 @@ void HydroSourceTATB::read_in_TATB() { } TAfile.close(); TBfile.close(); - TA_ *= DATA_.delta_x*DATA_.delta_y; - TB_ *= DATA_.delta_x*DATA_.delta_y; + TA_ *= DATA_.delta_x * DATA_.delta_y; + TB_ *= DATA_.delta_x * DATA_.delta_y; } - //! This function reads in the spatal information of the participants //! and compute the nuclear thickness functions void HydroSourceTATB::read_in_participants_and_compute_TATB() { @@ -157,22 +153,19 @@ void HydroSourceTATB::read_in_participants_and_compute_TATB() { for (auto &part_i : partList) { part_i.x -= x_CM; part_i.y -= y_CM; - if (x_max < std::abs(part_i.x)) - x_max = std::abs(part_i.x); - if (y_max < std::abs(part_i.y)) - y_max = std::abs(part_i.y); + if (x_max < std::abs(part_i.x)) x_max = std::abs(part_i.x); + if (y_max < std::abs(part_i.y)) y_max = std::abs(part_i.y); } // adjust transverse grid size - double gridOffset = std::max(3., 5.*DATA_.nucleonWidth); - DATA_.x_size = 2.*(x_max + gridOffset); - DATA_.y_size = 2.*(y_max + gridOffset); - DATA_.delta_x = DATA_.x_size/(DATA_.nx - 1); - DATA_.delta_y = DATA_.y_size/(DATA_.ny - 1); - music_message << "[HydroSourceTATB] Grid info: x_size = " - << DATA_.x_size << ", y_size = " << DATA_.y_size - << ", dx = " << DATA_.delta_x << " fm, dy = " - << DATA_.delta_y << " fm."; + double gridOffset = std::max(3., 5. * DATA_.nucleonWidth); + DATA_.x_size = 2. * (x_max + gridOffset); + DATA_.y_size = 2. * (y_max + gridOffset); + DATA_.delta_x = DATA_.x_size / (DATA_.nx - 1); + DATA_.delta_y = DATA_.y_size / (DATA_.ny - 1); + music_message << "[HydroSourceTATB] Grid info: x_size = " << DATA_.x_size + << ", y_size = " << DATA_.y_size << ", dx = " << DATA_.delta_x + << " fm, dy = " << DATA_.delta_y << " fm."; music_message.flush("info"); for (int i = 0; i < DATA_.nx; i++) { @@ -187,19 +180,19 @@ void HydroSourceTATB::read_in_participants_and_compute_TATB() { } } - -void HydroSourceTATB::computeTATB(const double x_0, const double y_0, - const int dir) { - const double wsq = DATA_.nucleonWidth*DATA_.nucleonWidth; - const double preFact = 1./(2.*M_PI*wsq); +void HydroSourceTATB::computeTATB( + const double x_0, const double y_0, const int dir) { + const double wsq = DATA_.nucleonWidth * DATA_.nucleonWidth; + const double preFact = 1. / (2. * M_PI * wsq); for (int i = 0; i < DATA_.nx; i++) { - double x_local = - DATA_.x_size/2. + i*DATA_.delta_x; + double x_local = -DATA_.x_size / 2. + i * DATA_.delta_x; for (int j = 0; j < DATA_.ny; j++) { - double y_local = - DATA_.y_size/2. + j*DATA_.delta_y; - double dis_sq = ( (x_local - x_0)*(x_local - x_0) - + (y_local - y_0)*(y_local - y_0)); - if (dis_sq < 25.*wsq) { - double rholocal = preFact*exp(-dis_sq/(2.*wsq)); + double y_local = -DATA_.y_size / 2. + j * DATA_.delta_y; + double dis_sq = + ((x_local - x_0) * (x_local - x_0) + + (y_local - y_0) * (y_local - y_0)); + if (dis_sq < 25. * wsq) { + double rholocal = preFact * exp(-dis_sq / (2. * wsq)); if (dir == 1) { profile_TA[i][j] += rholocal; } else { @@ -210,157 +203,160 @@ void HydroSourceTATB::computeTATB(const double x_0, const double y_0, } } - void HydroSourceTATB::get_hydro_energy_source( const double tau, const double x, const double y, const double eta_s, const FlowVec &u_mu, EnergyFlowVec &j_mu) const { const double dtau = DATA_.delta_tau; j_mu = {0}; - if (std::abs((tau - tau_source)) > 1./2.*dtau) return; + if (std::abs((tau - tau_source)) > 1. / 2. * dtau) return; - const int ix = static_cast((x + DATA_.x_size/2.)/DATA_.delta_x + 0.1); - const int iy = static_cast((y + DATA_.y_size/2.)/DATA_.delta_y + 0.1); + const int ix = + static_cast((x + DATA_.x_size / 2.) / DATA_.delta_x + 0.1); + const int iy = + static_cast((y + DATA_.y_size / 2.) / DATA_.delta_y + 0.1); double eta_flat = DATA_.eta_flat; if (DATA_.ecm > 2000.) { // at LHC energies, we vary eta_flat according to TA + TB - double total_num_nucleons = 208.*2.; // for PbPb runs + double total_num_nucleons = 208. * 2.; // for PbPb runs double slope = -0.4; - eta_flat = eta_flat + ((TA_ + TB_)/total_num_nucleons - 0.5)*slope; + eta_flat = eta_flat + ((TA_ + TB_) / total_num_nucleons - 0.5) * slope; } - double y_CM = atanh((profile_TA[ix][iy] - profile_TB[ix][iy]) - /(profile_TA[ix][iy] + profile_TB[ix][iy] - + Util::small_eps) - *tanh(DATA_.beam_rapidity)); - double y_L = yL_frac_*y_CM; - double M_inv = ((profile_TA[ix][iy] + profile_TB[ix][iy]) - *Util::m_N*cosh(DATA_.beam_rapidity)/Util::hbarc); // [1/fm^3] - double eta0 = std::min(eta_flat/2.0, - std::abs(DATA_.beam_rapidity - (y_CM - y_L))); - double eta_envelop = eta_profile_plateau(eta_s - (y_CM - y_L), eta0, - DATA_.eta_fall_off); - double E_norm = tau_source*energy_eta_profile_normalisation( - y_CM, eta0, DATA_.eta_fall_off); - //double eta_envelop = eta_profile_plateau_frag(eta_s - (y_CM - y_L), eta0, - // DATA_.eta_fall_off); - //double E_norm = tau_source*energy_eta_profile_normalisation_numerical( - // y_CM, eta0, DATA_.eta_fall_off); - double epsilon = M_inv*eta_envelop/E_norm/dtau; // [1/fm^5] - j_mu[0] = epsilon*cosh(y_L); // [1/fm^5] - j_mu[3] = epsilon*sinh(y_L); // [1/fm^5] + double y_CM = atanh( + (profile_TA[ix][iy] - profile_TB[ix][iy]) + / (profile_TA[ix][iy] + profile_TB[ix][iy] + Util::small_eps) + * tanh(DATA_.beam_rapidity)); + double y_L = yL_frac_ * y_CM; + double M_inv = + ((profile_TA[ix][iy] + profile_TB[ix][iy]) * Util::m_N + * cosh(DATA_.beam_rapidity) / Util::hbarc); // [1/fm^3] + double eta0 = + std::min(eta_flat / 2.0, std::abs(DATA_.beam_rapidity - (y_CM - y_L))); + double eta_envelop = + eta_profile_plateau(eta_s - (y_CM - y_L), eta0, DATA_.eta_fall_off); + double E_norm = + tau_source + * energy_eta_profile_normalisation(y_CM, eta0, DATA_.eta_fall_off); + // double eta_envelop = eta_profile_plateau_frag(eta_s - (y_CM - y_L), eta0, + // DATA_.eta_fall_off); + // double E_norm = tau_source*energy_eta_profile_normalisation_numerical( + // y_CM, eta0, DATA_.eta_fall_off); + double epsilon = M_inv * eta_envelop / E_norm / dtau; // [1/fm^5] + j_mu[0] = epsilon * cosh(y_L); // [1/fm^5] + j_mu[3] = epsilon * sinh(y_L); // [1/fm^5] } - double HydroSourceTATB::get_hydro_rhob_source( - const double tau, const double x, const double y, const double eta_s, - const FlowVec &u_mu) const { + const double tau, const double x, const double y, const double eta_s, + const FlowVec &u_mu) const { const double dtau = DATA_.delta_tau; double res = 0.; - if (std::abs((tau - tau_source)) > 1./2.*dtau) return(res); + if (std::abs((tau - tau_source)) > 1. / 2. * dtau) return (res); - const int ix = static_cast((x + DATA_.x_size/2.)/DATA_.delta_x + 0.1); - const int iy = static_cast((y + DATA_.y_size/2.)/DATA_.delta_y + 0.1); - double eta_rhob_left = eta_rhob_left_factor(eta_s); + const int ix = + static_cast((x + DATA_.x_size / 2.) / DATA_.delta_x + 0.1); + const int iy = + static_cast((y + DATA_.y_size / 2.) / DATA_.delta_y + 0.1); + double eta_rhob_left = eta_rhob_left_factor(eta_s); double eta_rhob_right = eta_rhob_right_factor(eta_s); - res = 0.5*( - profile_TA[ix][iy]*( (1. + DATA_.eta_rhob_asym)*eta_rhob_right - + (1. - DATA_.eta_rhob_asym)*eta_rhob_left) - + profile_TB[ix][iy]*( (1. + DATA_.eta_rhob_asym)*eta_rhob_left - + (1. - DATA_.eta_rhob_asym)*eta_rhob_right) - ); // [1/fm^3] - res /= dtau; // [1/fm^4] - return(res); + res = 0.5 + * (profile_TA[ix][iy] + * ((1. + DATA_.eta_rhob_asym) * eta_rhob_right + + (1. - DATA_.eta_rhob_asym) * eta_rhob_left) + + profile_TB[ix][iy] + * ((1. + DATA_.eta_rhob_asym) * eta_rhob_left + + (1. - DATA_.eta_rhob_asym) + * eta_rhob_right)); // [1/fm^3] + res /= dtau; // [1/fm^4] + return (res); } - double HydroSourceTATB::eta_rhob_left_factor(const double eta) const { - double eta_0 = -std::abs(DATA_.eta_rhob_0); + double eta_0 = -std::abs(DATA_.eta_rhob_0); double delta_eta_1 = DATA_.eta_rhob_width_1; double delta_eta_2 = DATA_.eta_rhob_width_2; - double norm = 2./(sqrt(M_PI)*tau_source*(delta_eta_1 + delta_eta_2)); - double exp_arg = 0.0; + double norm = 2. / (sqrt(M_PI) * tau_source * (delta_eta_1 + delta_eta_2)); + double exp_arg = 0.0; if (eta < eta_0) { - exp_arg = (eta - eta_0)/delta_eta_1; + exp_arg = (eta - eta_0) / delta_eta_1; } else { - exp_arg = (eta - eta_0)/delta_eta_2; + exp_arg = (eta - eta_0) / delta_eta_2; } - double res = norm*exp(-exp_arg*exp_arg); - return(res); + double res = norm * exp(-exp_arg * exp_arg); + return (res); } - double HydroSourceTATB::eta_rhob_right_factor(const double eta) const { - double eta_0 = std::abs(DATA_.eta_rhob_0); + double eta_0 = std::abs(DATA_.eta_rhob_0); double delta_eta_1 = DATA_.eta_rhob_width_1; double delta_eta_2 = DATA_.eta_rhob_width_2; - double norm = 2./(sqrt(M_PI)*tau_source*(delta_eta_1 + delta_eta_2)); - double exp_arg = 0.0; + double norm = 2. / (sqrt(M_PI) * tau_source * (delta_eta_1 + delta_eta_2)); + double exp_arg = 0.0; if (eta < eta_0) { - exp_arg = (eta - eta_0)/delta_eta_2; + exp_arg = (eta - eta_0) / delta_eta_2; } else { - exp_arg = (eta - eta_0)/delta_eta_1; + exp_arg = (eta - eta_0) / delta_eta_1; } - double res = norm*exp(-exp_arg*exp_arg); - return(res); + double res = norm * exp(-exp_arg * exp_arg); + return (res); } - double HydroSourceTATB::eta_profile_plateau( - const double eta, const double eta_0, const double sigma_eta) const { + const double eta, const double eta_0, const double sigma_eta) const { // this function return the eta envelope profile for energy density // Hirano's plateau + Gaussian fall-off double res; - double exparg1 = (std::abs(eta) - eta_0)/sigma_eta; - double exparg = exparg1*exparg1/2.0; - res = exp(-exparg*Util::theta(exparg1)); + double exparg1 = (std::abs(eta) - eta_0) / sigma_eta; + double exparg = exparg1 * exparg1 / 2.0; + res = exp(-exparg * Util::theta(exparg1)); return res; } - double HydroSourceTATB::energy_eta_profile_normalisation( - const double y_CM, const double eta_0, const double sigma_eta) const { + const double y_CM, const double eta_0, const double sigma_eta) const { // this function returns the normalization of the eta envelope profile // for energy density // \int deta eta_profile_plateau(eta - y_CM, eta_0, sigma_eta)*cosh(eta) - double f1 = ( exp( eta_0)*erfc(-sqrt(0.5)*sigma_eta) - + exp(-eta_0)*erfc( sqrt(0.5)*sigma_eta)); - double f2 = sqrt(M_PI/2.)*sigma_eta*exp(sigma_eta*sigma_eta/2.); + double f1 = + (exp(eta_0) * erfc(-sqrt(0.5) * sigma_eta) + + exp(-eta_0) * erfc(sqrt(0.5) * sigma_eta)); + double f2 = sqrt(M_PI / 2.) * sigma_eta * exp(sigma_eta * sigma_eta / 2.); double f3 = sinh(eta_0 + y_CM) - sinh(-eta_0 + y_CM); - double norm = cosh(y_CM)*f2*f1 + f3; - return(norm); + double norm = cosh(y_CM) * f2 * f1 + f3; + return (norm); } - double HydroSourceTATB::eta_profile_plateau_frag( - const double eta, const double eta_0, const double sigma_eta) const { + const double eta, const double eta_0, const double sigma_eta) const { // this function return the eta envelope profile for energy density // Hirano's plateau + Gaussian fall-off double res; - double exparg1 = (std::abs(eta) - eta_0)/sigma_eta; - double exparg = exparg1*exparg1/2.0; + double exparg1 = (std::abs(eta) - eta_0) / sigma_eta; + double exparg = exparg1 * exparg1 / 2.0; double eta_fragmentation = std::max(eta_0, DATA_.beam_rapidity - 2.0); - double exparg_frag1 = (std::abs(eta) - eta_fragmentation)/0.5; - double exparg_frag = exparg_frag1*exparg_frag1/2.0; - res = (exp(-exparg*Util::theta(exparg1)) - *exp(-exparg_frag*Util::theta(exparg_frag1))); + double exparg_frag1 = (std::abs(eta) - eta_fragmentation) / 0.5; + double exparg_frag = exparg_frag1 * exparg_frag1 / 2.0; + res = + (exp(-exparg * Util::theta(exparg1)) + * exp(-exparg_frag * Util::theta(exparg_frag1))); return res; } - double HydroSourceTATB::energy_eta_profile_normalisation_numerical( - const double y_CM, const double eta_0, const double sigma_eta) const { + const double y_CM, const double eta_0, const double sigma_eta) const { // this function returns the normalization of the eta envelope profile // for energy density by performing numerical integral // \int deta eta_profile_plateau(eta - y_CM, eta_0, sigma_eta)*cosh(eta) const int npoints = 200; const double eta_max = DATA_.beam_rapidity + 3.0; - const double deta = 2.*eta_max/(npoints - 1); + const double deta = 2. * eta_max / (npoints - 1); double f_eta = 0.; for (int i = 0; i < npoints; i++) { - double eta_i = - eta_max + i*deta + y_CM; - f_eta += eta_profile_plateau_frag(eta_i - y_CM, eta_0, sigma_eta)*cosh(eta_i); + double eta_i = -eta_max + i * deta + y_CM; + f_eta += eta_profile_plateau_frag(eta_i - y_CM, eta_0, sigma_eta) + * cosh(eta_i); } f_eta *= deta; - return(f_eta); + return (f_eta); } diff --git a/src/hydro_source_TATB.h b/src/hydro_source_TATB.h index 5d57e378..495d1c67 100644 --- a/src/hydro_source_TATB.h +++ b/src/hydro_source_TATB.h @@ -3,8 +3,9 @@ #ifndef SRC_HYDRO_SOURCE_TATB_H_ #define SRC_HYDRO_SOURCE_TATB_H_ -#include #include +#include + #include "hydro_source_base.h" struct participant { @@ -13,9 +14,8 @@ struct participant { double e; }; - class HydroSourceTATB : public HydroSourceBase { - private: + private: InitData &DATA_; double yL_frac_; double tau_source; @@ -23,7 +23,7 @@ class HydroSourceTATB : public HydroSourceBase { std::vector> profile_TA; std::vector> profile_TB; - public: + public: HydroSourceTATB() = delete; HydroSourceTATB(InitData &DATA_in); ~HydroSourceTATB(); @@ -33,8 +33,7 @@ class HydroSourceTATB : public HydroSourceBase { void read_in_TATB(); void read_in_participants_and_compute_TATB(); - void computeTATB(const double x_0, const double y_0, - const int dir); + void computeTATB(const double x_0, const double y_0, const int dir); double eta_rhob_left_factor(const double eta) const; double eta_rhob_right_factor(const double eta) const; @@ -47,13 +46,13 @@ class HydroSourceTATB : public HydroSourceBase { //! (tau, x, y, eta_s) void get_hydro_energy_source( const double tau, const double x, const double y, const double eta_s, - const FlowVec &u_mu, EnergyFlowVec &j_mu) const ; + const FlowVec &u_mu, EnergyFlowVec &j_mu) const; //! this function returns the net baryon density source term rho //! at a given point (tau, x, y, eta_s) - double get_hydro_rhob_source(const double tau, const double x, - const double y, const double eta_s, - const FlowVec &u_mu) const ; + double get_hydro_rhob_source( + const double tau, const double x, const double y, const double eta_s, + const FlowVec &u_mu) const; double eta_profile_plateau_frag( const double eta, const double eta_0, const double sigma_eta) const; double energy_eta_profile_normalisation_numerical( diff --git a/src/hydro_source_ampt.cpp b/src/hydro_source_ampt.cpp index d2b1403b..6da6c77a 100644 --- a/src/hydro_source_ampt.cpp +++ b/src/hydro_source_ampt.cpp @@ -1,33 +1,29 @@ // Copyright 2019 Chun Shen -#include -#include -#include +#include "hydro_source_ampt.h" + #include #include +#include #include +#include +#include -#include "hydro_source_ampt.h" #include "util.h" using std::string; -HydroSourceAMPT::HydroSourceAMPT(const InitData &DATA_in) : - DATA(DATA_in) { +HydroSourceAMPT::HydroSourceAMPT(const InitData &DATA_in) : DATA(DATA_in) { set_source_tau_min(100.0); set_source_tau_max(0.0); set_sigma_tau(0.1); - set_sigma_x (0.5); + set_sigma_x(0.5); set_sigma_eta(0.2); - parton_quench_factor = 1.0; // no diffusion current from the source + parton_quench_factor = 1.0; // no diffusion current from the source read_in_AMPT_partons(); } - -HydroSourceAMPT::~HydroSourceAMPT() { - parton_list.clear(); -} - +HydroSourceAMPT::~HydroSourceAMPT() { parton_list.clear(); } //! This function reads in the partons information from the AMPT model void HydroSourceAMPT::read_in_AMPT_partons() { @@ -47,7 +43,7 @@ void HydroSourceAMPT::read_in_AMPT_partons() { } int n_partons = 0; - int event_id = 0; + int event_id = 0; int dummy; getline(AMPT_file, text_string); std::stringstream text_stream1(text_string); @@ -61,55 +57,58 @@ void HydroSourceAMPT::read_in_AMPT_partons() { double t_local, z_local, pz_local; int pid; text_stream >> pid >> new_parton->px >> new_parton->py >> pz_local - >> new_parton->mass - >> new_parton->x >> new_parton->y >> z_local >> t_local; + >> new_parton->mass >> new_parton->x >> new_parton->y >> z_local + >> t_local; if (t_local < z_local) continue; if (std::abs(pid) > 3) continue; // Now the parton is inside the light cone - new_parton->E = sqrt( new_parton->mass*new_parton->mass - + new_parton->px*new_parton->px - + new_parton->py*new_parton->py - + pz_local*pz_local); - new_parton->tau = sqrt(t_local*t_local - z_local*z_local); - new_parton->eta_s = 0.5*log( (t_local + z_local) - /(t_local - z_local + Util::small_eps)); - new_parton->rapidity = 0.5*log( (new_parton->E + pz_local) - /(new_parton->E - pz_local)); - double u_perp = (sqrt( new_parton->px*new_parton->px - + new_parton->py*new_parton->py) - /new_parton->mass); + new_parton->E = sqrt( + new_parton->mass * new_parton->mass + + new_parton->px * new_parton->px + new_parton->py * new_parton->py + + pz_local * pz_local); + new_parton->tau = sqrt(t_local * t_local - z_local * z_local); + new_parton->eta_s = + 0.5 + * log((t_local + z_local) / (t_local - z_local + Util::small_eps)); + new_parton->rapidity = + 0.5 * log((new_parton->E + pz_local) / (new_parton->E - pz_local)); + double u_perp = + (sqrt( + new_parton->px * new_parton->px + + new_parton->py * new_parton->py) + / new_parton->mass); new_parton->rapidity_perp = asinh(u_perp); if (pid == 1) { // d quark - new_parton->baryon_number = 1./3.; - new_parton->strangness = 0.0 ; - new_parton->electric_charge = -1./3.; + new_parton->baryon_number = 1. / 3.; + new_parton->strangness = 0.0; + new_parton->electric_charge = -1. / 3.; } else if (pid == -1) { // anti-d quark - new_parton->baryon_number = -1./3.; - new_parton->strangness = 0.0 ; - new_parton->electric_charge = 1./3.; + new_parton->baryon_number = -1. / 3.; + new_parton->strangness = 0.0; + new_parton->electric_charge = 1. / 3.; } else if (pid == 2) { // u quark - new_parton->baryon_number = 1./3.; - new_parton->strangness = 0.0 ; - new_parton->electric_charge = 2./3.; + new_parton->baryon_number = 1. / 3.; + new_parton->strangness = 0.0; + new_parton->electric_charge = 2. / 3.; } else if (pid == -2) { // anti-u quark - new_parton->baryon_number = -1./3.; - new_parton->strangness = 0.0 ; - new_parton->electric_charge = -2./3.; + new_parton->baryon_number = -1. / 3.; + new_parton->strangness = 0.0; + new_parton->electric_charge = -2. / 3.; } else if (pid == 3) { // s quark - new_parton->baryon_number = 1./3.; - new_parton->strangness = -1.0 ; - new_parton->electric_charge = -1./3.; + new_parton->baryon_number = 1. / 3.; + new_parton->strangness = -1.0; + new_parton->electric_charge = -1. / 3.; } else if (pid == -3) { // anti-s quark - new_parton->baryon_number = -1./3.; - new_parton->strangness = 1.0 ; - new_parton->electric_charge = 1./3.; + new_parton->baryon_number = -1. / 3.; + new_parton->strangness = 1.0; + new_parton->electric_charge = 1. / 3.; } else { music_message << "pid = " << pid; music_message.flush("info"); @@ -134,49 +133,46 @@ void HydroSourceAMPT::read_in_AMPT_partons() { music_message.flush("info"); } - void HydroSourceAMPT::prepare_list_for_current_tau_frame( - const double tau_local) { + const double tau_local) { double dtau = DATA.delta_tau; parton_list_current_tau.clear(); - for (auto &it: parton_list) { + for (auto &it : parton_list) { double tau_dis = it->tau - tau_local; if (tau_dis > 0. && tau_dis < dtau) { parton_list_current_tau.push_back(it); } } music_message << "hydro_source: tau = " << tau_local - << " number of source: " - << parton_list_current_tau.size(); + << " number of source: " << parton_list_current_tau.size(); music_message.flush("info"); } - void HydroSourceAMPT::get_hydro_energy_source( - const double tau, const double x, const double y, const double eta_s, + const double tau, const double x, const double y, const double eta_s, const FlowVec &u_mu, EnergyFlowVec &j_mu) const { j_mu = {0}; if (parton_list_current_tau.size() == 0) return; - + const double sigma_tau = get_sigma_tau(); - const double sigma_x = get_sigma_x(); + const double sigma_x = get_sigma_x(); const double sigma_eta = get_sigma_eta(); // flow velocity const double dtau = DATA.delta_tau; - const double prefactor_prep = 1./(M_PI*sigma_x*sigma_x); - const double prefactor_tau = 1./dtau; - const double prefactor_etas = 1./(sqrt(M_PI)*sigma_eta); - const double n_sigma_skip = 5.; - const double skip_dis_x = n_sigma_skip*sigma_x; - const double skip_dis_eta = n_sigma_skip*sigma_eta; - const double exp_tau = 1./tau; + const double prefactor_prep = 1. / (M_PI * sigma_x * sigma_x); + const double prefactor_tau = 1. / dtau; + const double prefactor_etas = 1. / (sqrt(M_PI) * sigma_eta); + const double n_sigma_skip = 5.; + const double skip_dis_x = n_sigma_skip * sigma_x; + const double skip_dis_eta = n_sigma_skip * sigma_eta; + const double exp_tau = 1. / tau; // AMPT parton sources double tau_dis_max = tau - get_source_tau_max(); - if (tau_dis_max < n_sigma_skip*sigma_tau) { - for (auto &it: parton_list_current_tau) { + if (tau_dis_max < n_sigma_skip * sigma_tau) { + for (auto &it : parton_list_current_tau) { double x_dis = x - it->x; if (std::abs(x_dis) > skip_dis_x) continue; @@ -186,21 +182,22 @@ void HydroSourceAMPT::get_hydro_energy_source( double eta_s_dis = eta_s - it->eta_s; if (std::abs(eta_s_dis) > skip_dis_eta) continue; - double exp_xperp = exp(-(x_dis*x_dis + y_dis*y_dis) - /(sigma_x*sigma_x)); - double exp_eta_s = ( - exp(-eta_s_dis*eta_s_dis/(sigma_eta*sigma_eta))); + double exp_xperp = + exp(-(x_dis * x_dis + y_dis * y_dis) / (sigma_x * sigma_x)); + double exp_eta_s = + (exp(-eta_s_dis * eta_s_dis / (sigma_eta * sigma_eta))); - double f_smear = exp_tau*exp_xperp*exp_eta_s; - double p_perp_sq = it->px*it->px + it->py*it->py; - double m_perp = sqrt(it->mass*it->mass + p_perp_sq); - j_mu[0] += m_perp*cosh(it->rapidity - eta_s)*f_smear; - j_mu[1] += it->px*f_smear; - j_mu[2] += it->py*f_smear; - j_mu[3] += m_perp*sinh(it->rapidity - eta_s)*f_smear; + double f_smear = exp_tau * exp_xperp * exp_eta_s; + double p_perp_sq = it->px * it->px + it->py * it->py; + double m_perp = sqrt(it->mass * it->mass + p_perp_sq); + j_mu[0] += m_perp * cosh(it->rapidity - eta_s) * f_smear; + j_mu[1] += it->px * f_smear; + j_mu[2] += it->py * f_smear; + j_mu[3] += m_perp * sinh(it->rapidity - eta_s) * f_smear; } - double norm = DATA.sFactor/Util::hbarc; // 1/fm^4 - double prefactor = norm*prefactor_tau*prefactor_prep*prefactor_etas; + double norm = DATA.sFactor / Util::hbarc; // 1/fm^4 + double prefactor = + norm * prefactor_tau * prefactor_prep * prefactor_etas; j_mu[0] *= prefactor; j_mu[1] *= prefactor; j_mu[2] *= prefactor; @@ -208,35 +205,35 @@ void HydroSourceAMPT::get_hydro_energy_source( } } - double HydroSourceAMPT::get_hydro_rhob_source( - const double tau, const double x, const double y, const double eta_s, - const FlowVec &u_mu) const { + const double tau, const double x, const double y, const double eta_s, + const FlowVec &u_mu) const { double res = 0.; - if (parton_list_current_tau.size() == 0) return(res); - + if (parton_list_current_tau.size() == 0) return (res); + const double sigma_tau = get_sigma_tau(); - const double sigma_x = get_sigma_x(); + const double sigma_x = get_sigma_x(); const double sigma_eta = get_sigma_eta(); // flow velocity - const double gamma_perp_flow = sqrt(1. + u_mu[1]*u_mu[1] + u_mu[2]*u_mu[2]); - const double y_perp_flow = acosh(gamma_perp_flow); - const double y_long_flow = asinh(u_mu[3]/gamma_perp_flow) + eta_s; + const double gamma_perp_flow = + sqrt(1. + u_mu[1] * u_mu[1] + u_mu[2] * u_mu[2]); + const double y_perp_flow = acosh(gamma_perp_flow); + const double y_long_flow = asinh(u_mu[3] / gamma_perp_flow) + eta_s; const double sinh_y_perp_flow = sinh(y_perp_flow); - const double dtau = DATA.delta_tau; + const double dtau = DATA.delta_tau; - const double exp_tau = 1.0/tau; - const double n_sigma_skip = 5.; - const double prefactor_prep = 1./(M_PI*sigma_x*sigma_x); - const double prefactor_etas = 1./(sqrt(M_PI)*sigma_eta); - const double prefactor_tau = 1./dtau; - const double skip_dis_x = n_sigma_skip*sigma_x; - const double skip_dis_eta = n_sigma_skip*sigma_eta; + const double exp_tau = 1.0 / tau; + const double n_sigma_skip = 5.; + const double prefactor_prep = 1. / (M_PI * sigma_x * sigma_x); + const double prefactor_etas = 1. / (sqrt(M_PI) * sigma_eta); + const double prefactor_tau = 1. / dtau; + const double skip_dis_x = n_sigma_skip * sigma_x; + const double skip_dis_eta = n_sigma_skip * sigma_eta; double tau_dis_max = tau - get_source_tau_max(); - if (tau_dis_max < n_sigma_skip*sigma_tau) { - for (auto &it: parton_list_current_tau) { + if (tau_dis_max < n_sigma_skip * sigma_tau) { + for (auto &it : parton_list_current_tau) { // skip the evaluation if the strings is too far away in the // space-time grid double x_dis = x - it->x; @@ -248,21 +245,24 @@ double HydroSourceAMPT::get_hydro_rhob_source( double eta_s_dis = eta_s - it->eta_s; if (std::abs(eta_s_dis) > skip_dis_eta) continue; - double exp_xperp = exp(-(x_dis*x_dis + y_dis*y_dis) - /(sigma_x*sigma_x)); - double exp_eta_s = ( - exp(-eta_s_dis*eta_s_dis/(sigma_eta*sigma_eta))); - double f_smear = exp_tau*exp_xperp*exp_eta_s; - double y_dump = ((1. - parton_quench_factor)*it->rapidity - + parton_quench_factor*y_long_flow); - double y_dump_perp = ((1. - parton_quench_factor)*it->rapidity_perp - + parton_quench_factor*y_perp_flow); - double p_dot_u = (u_mu[0] - - tanh(y_dump_perp)*sinh_y_perp_flow/cosh(y_dump - eta_s) - - tanh(y_dump - eta_s)*u_mu[3]); - res += p_dot_u*f_smear; + double exp_xperp = + exp(-(x_dis * x_dis + y_dis * y_dis) / (sigma_x * sigma_x)); + double exp_eta_s = + (exp(-eta_s_dis * eta_s_dis / (sigma_eta * sigma_eta))); + double f_smear = exp_tau * exp_xperp * exp_eta_s; + double y_dump = + ((1. - parton_quench_factor) * it->rapidity + + parton_quench_factor * y_long_flow); + double y_dump_perp = + ((1. - parton_quench_factor) * it->rapidity_perp + + parton_quench_factor * y_perp_flow); + double p_dot_u = + (u_mu[0] + - tanh(y_dump_perp) * sinh_y_perp_flow / cosh(y_dump - eta_s) + - tanh(y_dump - eta_s) * u_mu[3]); + res += p_dot_u * f_smear; } - res *= prefactor_tau*prefactor_prep*prefactor_etas; + res *= prefactor_tau * prefactor_prep * prefactor_etas; } - return(res); + return (res); } diff --git a/src/hydro_source_ampt.h b/src/hydro_source_ampt.h index f5c6bcb0..a2f7b924 100644 --- a/src/hydro_source_ampt.h +++ b/src/hydro_source_ampt.h @@ -3,8 +3,9 @@ #ifndef SRC_HYDRO_SOURCE_AMPT_H_ #define SRC_HYDRO_SOURCE_AMPT_H_ -#include #include +#include + #include "hydro_source_base.h" //! This data structure stores parton information @@ -19,15 +20,14 @@ struct parton { double electric_charge; }; - class HydroSourceAMPT : public HydroSourceBase { - private: + private: const InitData &DATA; double parton_quench_factor; std::vector> parton_list; std::vector> parton_list_current_tau; - public: + public: HydroSourceAMPT() = delete; HydroSourceAMPT(const InitData &DATA_in); ~HydroSourceAMPT(); @@ -39,16 +39,15 @@ class HydroSourceAMPT : public HydroSourceBase { //! (tau, x, y, eta_s) void get_hydro_energy_source( const double tau, const double x, const double y, const double eta_s, - const FlowVec &u_mu, EnergyFlowVec &j_mu) const ; + const FlowVec &u_mu, EnergyFlowVec &j_mu) const; //! this function returns the net baryon density source term rho //! at a given point (tau, x, y, eta_s) - double get_hydro_rhob_source(const double tau, const double x, - const double y, const double eta_s, - const FlowVec &u_mu) const ; + double get_hydro_rhob_source( + const double tau, const double x, const double y, const double eta_s, + const FlowVec &u_mu) const; void prepare_list_for_current_tau_frame(const double tau_local); }; #endif // SRC_HYDRO_SOURCE_AMPT_H_ - diff --git a/src/hydro_source_base.cpp b/src/hydro_source_base.cpp index 829130e8..f0ce6695 100644 --- a/src/hydro_source_base.cpp +++ b/src/hydro_source_base.cpp @@ -1,24 +1,24 @@ // Copyright 2019 Chun Shen #include "hydro_source_base.h" + #include "data_struct.h" void HydroSourceBase::get_hydro_energy_source_before_tau( const double tau, const double x, const double y, const double eta_s, EnergyFlowVec &j_mu) const { - FlowVec u = {1., 0., 0., 0.}; EnergyFlowVec j_mu_one_step = {0}; double tau0 = 0.0; double dtau = 0.005; - int n_tau_steps = static_cast((tau - tau0)/dtau); + int n_tau_steps = static_cast((tau - tau0) / dtau); for (int i = 0; i < n_tau_steps; i++) { j_mu_one_step = {0}; - const double tau_local = tau0 + (i + 0.5)*dtau; + const double tau_local = tau0 + (i + 0.5) * dtau; get_hydro_energy_source(tau_local, x, y, eta_s, u, j_mu_one_step); for (int j = 0; j < 4; j++) { - j_mu[j] += tau_local*j_mu_one_step[j]*dtau; + j_mu[j] += tau_local * j_mu_one_step[j] * dtau; } } for (int j = 0; j < 4; j++) { @@ -27,21 +27,21 @@ void HydroSourceBase::get_hydro_energy_source_before_tau( } double HydroSourceBase::get_hydro_rhob_source_before_tau( - const double tau, const double x, - const double y, const double eta_s) const { + const double tau, const double x, const double y, + const double eta_s) const { FlowVec u = {1., 0., 0., 0.}; - double res = 0.; + double res = 0.; double tau0 = 0.0; double dtau = 0.005; - int n_tau_steps = static_cast((tau - tau0)/dtau); + int n_tau_steps = static_cast((tau - tau0) / dtau); for (int i = 0; i < n_tau_steps; i++) { - const double tau_local = tau0 + (i + 0.5)*dtau; - const double res_local = get_hydro_rhob_source( - tau_local, x, y, eta_s, u); - res += tau_local*res_local*dtau; + const double tau_local = tau0 + (i + 0.5) * dtau; + const double res_local = + get_hydro_rhob_source(tau_local, x, y, eta_s, u); + res += tau_local * res_local * dtau; } - return(res/tau); + return (res / tau); } diff --git a/src/hydro_source_base.h b/src/hydro_source_base.h index a1be9417..df43d381 100644 --- a/src/hydro_source_base.h +++ b/src/hydro_source_base.h @@ -3,11 +3,11 @@ #define SRC_HYDRO_SOURCE_BASE_H_ #include "data.h" -#include "pretty_ostream.h" #include "data_struct.h" +#include "pretty_ostream.h" class HydroSourceBase { - private: + private: double source_tau_max_ = 0.; double source_tau_min_ = 0.; double source_tauStart_max_ = 0.; @@ -15,30 +15,32 @@ class HydroSourceBase { double sigma_x_ = 0.1; double sigma_eta_ = 0.1; - public: + public: pretty_ostream music_message; HydroSourceBase() = default; virtual ~HydroSourceBase() {} - virtual int get_number_of_sources() const {return(0);} + virtual int get_number_of_sources() const { return (0); } - void set_sigma_tau(double sigma_tau_in) {sigma_tau_ = sigma_tau_in;} - void set_sigma_x (double sigma_x_in ) {sigma_x_ = sigma_x_in ;} - void set_sigma_eta(double sigma_eta_in) {sigma_eta_ = sigma_eta_in;} - double get_sigma_tau() const {return(sigma_tau_);} - double get_sigma_x () const {return(sigma_x_ );} - double get_sigma_eta() const {return(sigma_eta_);} + void set_sigma_tau(double sigma_tau_in) { sigma_tau_ = sigma_tau_in; } + void set_sigma_x(double sigma_x_in) { sigma_x_ = sigma_x_in; } + void set_sigma_eta(double sigma_eta_in) { sigma_eta_ = sigma_eta_in; } + double get_sigma_tau() const { return (sigma_tau_); } + double get_sigma_x() const { return (sigma_x_); } + double get_sigma_eta() const { return (sigma_eta_); } //! Set the minimum and maximum tau for the source term - void set_source_tau_min(double tau_in) {source_tau_min_ = tau_in;} - void set_source_tau_max(double tau_in) {source_tau_max_ = tau_in;} - void set_source_tauStart_max(double tau_in) {source_tauStart_max_ = tau_in;} + void set_source_tau_min(double tau_in) { source_tau_min_ = tau_in; } + void set_source_tau_max(double tau_in) { source_tau_max_ = tau_in; } + void set_source_tauStart_max(double tau_in) { + source_tauStart_max_ = tau_in; + } //! Get the minimum and maximum tau for the source term - double get_source_tau_min() const {return(source_tau_min_);} - double get_source_tau_max() const {return(source_tau_max_);} - double get_source_tauStart_max() const {return(source_tauStart_max_);} + double get_source_tau_min() const { return (source_tau_min_); } + double get_source_tau_max() const { return (source_tau_max_); } + double get_source_tauStart_max() const { return (source_tauStart_max_); } //! this function returns the energy source term J^\mu at a given point //! (tau, x, y, eta_s) @@ -50,10 +52,10 @@ class HydroSourceBase { //! this function returns the net baryon density source term rho //! at a given point (tau, x, y, eta_s) - virtual double get_hydro_rhob_source(const double tau, const double x, - const double y, const double eta_s, - const FlowVec &u_mu) const { - return(0.0); + virtual double get_hydro_rhob_source( + const double tau, const double x, const double y, const double eta_s, + const FlowVec &u_mu) const { + return (0.0); } //! this function returns the energy source term J^\mu up to a given point @@ -64,9 +66,9 @@ class HydroSourceBase { //! this function returns the net baryon density source term rho //! up to a given point (tau, x, y, eta_s) - double get_hydro_rhob_source_before_tau(const double tau, const double x, - const double y, - const double eta_s) const; + double get_hydro_rhob_source_before_tau( + const double tau, const double x, const double y, + const double eta_s) const; virtual void prepare_list_for_current_tau_frame(const double tau_local) {} }; diff --git a/src/hydro_source_strings.cpp b/src/hydro_source_strings.cpp index af8bae27..e8c14266 100644 --- a/src/hydro_source_strings.cpp +++ b/src/hydro_source_strings.cpp @@ -1,51 +1,46 @@ // Copyright 2019 Chun Shen -#include -#include -#include -#include +#include "hydro_source_strings.h" + #include #include +#include +#include #include +#include +#include -#include "hydro_source_strings.h" #include "util.h" using std::string; -HydroSourceStrings::HydroSourceStrings(InitData &DATA_in) : - DATA(DATA_in) { +HydroSourceStrings::HydroSourceStrings(InitData &DATA_in) : DATA(DATA_in) { set_source_tau_min(100.0); set_source_tau_max(0.0); set_source_tauStart_max(0.0); set_sigma_tau(0.1); - set_sigma_x (DATA.stringSourceSigmaX); + set_sigma_x(DATA.stringSourceSigmaX); set_sigma_eta(DATA.stringSourceSigmaEta); - string_dump_mode = DATA.string_dump_mode; + string_dump_mode = DATA.string_dump_mode; string_quench_factor = DATA.string_quench_factor; - parton_quench_factor = 1.0; // no diffusion current from the source + parton_quench_factor = 1.0; // no diffusion current from the source stringTransverseShiftFrac_ = DATA.stringTransverseShiftFrac; preEqFlowFactor_ = DATA.preEqFlowFactor; read_in_QCD_strings_and_partons(); } - -HydroSourceStrings::~HydroSourceStrings() { - QCD_strings_list.clear(); -} - +HydroSourceStrings::~HydroSourceStrings() { QCD_strings_list.clear(); } double HydroSourceStrings::getStringEndTau( - const double tau_0, const double tau_form, - const double eta_s_0, const double eta_s) const { - double temp_factor1 = tau_0*tau_0 - tau_form*tau_form; - double temp_factor2 = tau_0*cosh(eta_s - eta_s_0); - double tau_end_local = (temp_factor2 - + sqrt(temp_factor2*temp_factor2 - temp_factor1)); - return(tau_end_local); + const double tau_0, const double tau_form, const double eta_s_0, + const double eta_s) const { + double temp_factor1 = tau_0 * tau_0 - tau_form * tau_form; + double temp_factor2 = tau_0 * cosh(eta_s - eta_s_0); + double tau_end_local = + (temp_factor2 + sqrt(temp_factor2 * temp_factor2 - temp_factor1)); + return (tau_end_local); } - //! This function reads in the spatal information of the strings and partons //! which are produced from the MC-Glauber-LEXUS model void HydroSourceStrings::read_in_QCD_strings_and_partons() { @@ -82,28 +77,23 @@ void HydroSourceStrings::read_in_QCD_strings_and_partons() { std::stringstream text_stream(text_string); std::shared_ptr new_string(new QCD_string); text_stream >> new_string->mass >> new_string->m_over_sigma - >> new_string->tau_form - >> new_string->tau_0 >> new_string->eta_s_0 - >> new_string->x_perp >> new_string->y_perp - >> new_string->x_pl >> new_string->y_pl - >> new_string->x_pr >> new_string->y_pr - >> new_string->eta_s_left >> new_string->eta_s_right - >> new_string->y_l >> new_string->y_r - >> new_string->remnant_l >> new_string->remnant_r - >> new_string->y_l_i >> new_string->y_r_i - >> new_string->eta_s_baryon_left - >> new_string->eta_s_baryon_right - >> new_string->y_l_baryon - >> new_string->y_r_baryon - >> new_string->baryon_frac_l; + >> new_string->tau_form >> new_string->tau_0 >> new_string->eta_s_0 + >> new_string->x_perp >> new_string->y_perp >> new_string->x_pl + >> new_string->y_pl >> new_string->x_pr >> new_string->y_pr + >> new_string->eta_s_left >> new_string->eta_s_right + >> new_string->y_l >> new_string->y_r >> new_string->remnant_l + >> new_string->remnant_r >> new_string->y_l_i >> new_string->y_r_i + >> new_string->eta_s_baryon_left >> new_string->eta_s_baryon_right + >> new_string->y_l_baryon >> new_string->y_r_baryon + >> new_string->baryon_frac_l; if (!text_stream.eof()) { // read in the last element text_stream >> new_string->baryon_frac_r; } else { // the string is too short music_message << "read_in_QCD_strings_and_partons: " - << "the format of file" - << QCD_strings_filename << "is wrong~"; + << "the format of file" << QCD_strings_filename + << "is wrong~"; music_message.flush("error"); exit(1); } @@ -113,8 +103,8 @@ void HydroSourceStrings::read_in_QCD_strings_and_partons() { if (str_temp.find_first_not_of(' ') != std::string::npos) { // the string is too long music_message << "read_in_QCD_strings_and_partons: " - << "the format of file" - << QCD_strings_filename << "is wrong~"; + << "the format of file" << QCD_strings_filename + << "is wrong~"; music_message.flush("error"); exit(1); } @@ -123,26 +113,26 @@ void HydroSourceStrings::read_in_QCD_strings_and_partons() { if (DATA.Initial_profile == 131) { new_string->tau_0 = 0.; new_string->eta_s_0 = 0.; - //new_string->tau_form = 0.5; + // new_string->tau_form = 0.5; } new_string->sigma_x = get_sigma_x(); new_string->sigma_eta = get_sigma_eta(); // compute the string end tau new_string->tau_end_left = getStringEndTau( - new_string->tau_0, new_string->tau_form, - new_string->eta_s_0, new_string->eta_s_left); + new_string->tau_0, new_string->tau_form, new_string->eta_s_0, + new_string->eta_s_left); new_string->tau_end_right = getStringEndTau( - new_string->tau_0, new_string->tau_form, - new_string->eta_s_0, new_string->eta_s_right); + new_string->tau_0, new_string->tau_form, new_string->eta_s_0, + new_string->eta_s_right); // compute the baryon number tau new_string->tau_baryon_left = getStringEndTau( - new_string->tau_0, new_string->tau_form, - new_string->eta_s_0, new_string->eta_s_baryon_left); + new_string->tau_0, new_string->tau_form, new_string->eta_s_0, + new_string->eta_s_baryon_left); new_string->tau_baryon_right = getStringEndTau( - new_string->tau_0, new_string->tau_form, - new_string->eta_s_0, new_string->eta_s_baryon_right); + new_string->tau_0, new_string->tau_form, new_string->eta_s_0, + new_string->eta_s_baryon_right); // determine the tau_start and eta_s_start of the string if (new_string->eta_s_left > new_string->eta_s_0) { @@ -196,7 +186,7 @@ void HydroSourceStrings::read_in_QCD_strings_and_partons() { music_message.flush("info"); double total_baryon_number = 0; - for (auto const& it : QCD_strings_list) { + for (auto const &it : QCD_strings_list) { total_baryon_number += it->baryon_frac_l + it->baryon_frac_r; } music_message << "total baryon number = " << total_baryon_number; @@ -205,13 +195,14 @@ void HydroSourceStrings::read_in_QCD_strings_and_partons() { music_message.flush("info"); compute_norm_for_strings(); - DATA.beam_rapidity = acosh(total_energy/(total_baryon_number*Util::m_N)); - DATA.eta_size = 2.*(DATA.beam_rapidity + DATA.gridPadding - 1); - DATA.delta_eta = DATA.eta_size/(DATA.neta - 1); + DATA.beam_rapidity = + acosh(total_energy / (total_baryon_number * Util::m_N)); + DATA.eta_size = 2. * (DATA.beam_rapidity + DATA.gridPadding - 1); + DATA.delta_eta = DATA.eta_size / (DATA.neta - 1); double xMax = 0.; double yMax = 0.; - for (auto const& it : QCD_strings_list) { + for (auto const &it : QCD_strings_list) { xMax = std::max(xMax, std::abs(it->x_perp)); xMax = std::max(xMax, std::abs(it->x_pl)); xMax = std::max(xMax, std::abs(it->x_pr)); @@ -221,132 +212,135 @@ void HydroSourceStrings::read_in_QCD_strings_and_partons() { } // adjust transverse grid size - double energyAddRadius = sqrt(total_energy - /std::max(1., total_baryon_number)/2760.); - double npartAddRadius = total_baryon_number/500.; - double reRunAddRadius = DATA.reRunCount*2.; - double gridOffset = (DATA.gridPadding + energyAddRadius - + npartAddRadius + reRunAddRadius); - gridOffset = std::max(gridOffset, 5.*DATA.stringSourceSigmaX); - DATA.x_size = 2.*(xMax + gridOffset); - DATA.y_size = 2.*(yMax + gridOffset); - DATA.delta_x = DATA.x_size/(DATA.nx - 1); - DATA.delta_y = DATA.y_size/(DATA.ny - 1); + double energyAddRadius = + sqrt(total_energy / std::max(1., total_baryon_number) / 2760.); + double npartAddRadius = total_baryon_number / 500.; + double reRunAddRadius = DATA.reRunCount * 2.; + double gridOffset = + (DATA.gridPadding + energyAddRadius + npartAddRadius + reRunAddRadius); + gridOffset = std::max(gridOffset, 5. * DATA.stringSourceSigmaX); + DATA.x_size = 2. * (xMax + gridOffset); + DATA.y_size = 2. * (yMax + gridOffset); + DATA.delta_x = DATA.x_size / (DATA.nx - 1); + DATA.delta_y = DATA.y_size / (DATA.ny - 1); if (DATA.resetDtau) { // make sure delta_tau is not too large for delta_x and delta_y - DATA.delta_tau = std::min(DATA.delta_tau, - std::min(DATA.delta_x*DATA.dtaudxRatio, - DATA.delta_y*DATA.dtaudxRatio)); + DATA.delta_tau = std::min( + DATA.delta_tau, std::min( + DATA.delta_x * DATA.dtaudxRatio, + DATA.delta_y * DATA.dtaudxRatio)); if (DATA.delta_tau > 0.001) - DATA.delta_tau = (static_cast(DATA.delta_tau*1000))/1000.; - DATA.nt = static_cast(DATA.tau_size/DATA.delta_tau + 0.5); + DATA.delta_tau = (static_cast(DATA.delta_tau * 1000)) / 1000.; + DATA.nt = static_cast(DATA.tau_size / DATA.delta_tau + 0.5); } - music_message << "[HydroSource] Grid info: x_size = " - << DATA.x_size << ", y_size = " << DATA.y_size - << ", dx = " << DATA.delta_x << " fm, dy = " - << DATA.delta_y << " fm, eta_size = " << DATA.eta_size + music_message << "[HydroSource] Grid info: x_size = " << DATA.x_size + << ", y_size = " << DATA.y_size << ", dx = " << DATA.delta_x + << " fm, dy = " << DATA.delta_y + << " fm, eta_size = " << DATA.eta_size << ", deta = " << DATA.delta_eta << ", dtau = " << DATA.delta_tau << " fm"; music_message.flush("info"); } - void HydroSourceStrings::compute_norm_for_strings() { const int neta = 500; const double eta_range = 12.; - const double deta = 2.*eta_range/(neta - 1); + const double deta = 2. * eta_range / (neta - 1); - double E_string_total = 0.0; + double E_string_total = 0.0; double E_remnant_total = 0.0; - double Pz_string_total = 0.0; + double Pz_string_total = 0.0; double Pz_remnant_total = 0.0; - for (auto &it: QCD_strings_list) { + for (auto &it : QCD_strings_list) { const double sigma_eta = it->sigma_eta; - const double prefactor_etas = 1./(sqrt(2.*M_PI)*sigma_eta); + const double prefactor_etas = 1. / (sqrt(2. * M_PI) * sigma_eta); - double E_string_norm = 0.; + double E_string_norm = 0.; double E_remnant_L_norm = 0.; double E_remnant_R_norm = 0.; for (int ieta = 0; ieta < neta; ieta++) { - double eta_local = - eta_range + ieta*deta; + double eta_local = -eta_range + ieta * deta; double Delta_eta = it->eta_s_right - it->eta_s_left; double denorm_safe = std::copysign( std::max(Util::small_eps, std::abs(Delta_eta)), Delta_eta); - double y_eta = (it->y_l + (it->y_r - it->y_l)/denorm_safe - *(eta_local - it->eta_s_left)); - double expon_left = ( - (it->eta_s_left - eta_local)/(sqrt(2.)*sigma_eta)); - double expon_right = ( - (it->eta_s_right - eta_local)/(sqrt(2.)*sigma_eta)); - double e_eta = 0.5*(- erf(expon_left) + erf(expon_right)); - E_string_norm += e_eta*cosh(y_eta); - - double e_remnant_L = exp(-expon_left*expon_left); - double e_remnant_R = exp(-expon_right*expon_right); - E_remnant_L_norm += e_remnant_L*cosh(it->y_l); - E_remnant_R_norm += e_remnant_R*cosh(it->y_r); + double y_eta = + (it->y_l + + (it->y_r - it->y_l) / denorm_safe + * (eta_local - it->eta_s_left)); + double expon_left = + ((it->eta_s_left - eta_local) / (sqrt(2.) * sigma_eta)); + double expon_right = + ((it->eta_s_right - eta_local) / (sqrt(2.) * sigma_eta)); + double e_eta = 0.5 * (-erf(expon_left) + erf(expon_right)); + E_string_norm += e_eta * cosh(y_eta); + + double e_remnant_L = exp(-expon_left * expon_left); + double e_remnant_R = exp(-expon_right * expon_right); + E_remnant_L_norm += e_remnant_L * cosh(it->y_l); + E_remnant_R_norm += e_remnant_R * cosh(it->y_r); } - E_string_norm *= prefactor_etas*deta; - double E_string = (it->mass*cosh(it->y_l_i) + it->mass*cosh(it->y_r_i) - - it->mass*cosh(it->y_l) - it->mass*cosh(it->y_r)); - it->norm = E_string/std::max(E_string_norm, Util::small_eps); + E_string_norm *= prefactor_etas * deta; + double E_string = + (it->mass * cosh(it->y_l_i) + it->mass * cosh(it->y_r_i) + - it->mass * cosh(it->y_l) - it->mass * cosh(it->y_r)); + it->norm = E_string / std::max(E_string_norm, Util::small_eps); E_string_total += E_string; - double Pz_string = ( it->mass*sinh(it->y_l_i) - it->mass*sinh(it->y_l) - + it->mass*sinh(it->y_r_i) - it->mass*sinh(it->y_r)); + double Pz_string = + (it->mass * sinh(it->y_l_i) - it->mass * sinh(it->y_l) + + it->mass * sinh(it->y_r_i) - it->mass * sinh(it->y_r)); Pz_string_total += Pz_string; // here the E_norm is for the energy of remnants at the string ends - E_remnant_L_norm *= prefactor_etas*deta; - E_remnant_R_norm *= prefactor_etas*deta; - double E_remnant_L = it->remnant_l*it->mass*cosh(it->y_l); - double E_remnant_R = it->remnant_r*it->mass*cosh(it->y_r); - it->E_remnant_norm_L = (E_remnant_L - /std::max(E_remnant_L_norm, Util::small_eps)); - it->E_remnant_norm_R = (E_remnant_R - /std::max(E_remnant_R_norm, Util::small_eps)); + E_remnant_L_norm *= prefactor_etas * deta; + E_remnant_R_norm *= prefactor_etas * deta; + double E_remnant_L = it->remnant_l * it->mass * cosh(it->y_l); + double E_remnant_R = it->remnant_r * it->mass * cosh(it->y_r); + it->E_remnant_norm_L = + (E_remnant_L / std::max(E_remnant_L_norm, Util::small_eps)); + it->E_remnant_norm_R = + (E_remnant_R / std::max(E_remnant_R_norm, Util::small_eps)); E_remnant_total += E_remnant_L + E_remnant_R; - double Pz_remnant_L = it->remnant_l*it->mass*sinh(it->y_l); - double Pz_remnant_R = it->remnant_r*it->mass*sinh(it->y_r); + double Pz_remnant_L = it->remnant_l * it->mass * sinh(it->y_l); + double Pz_remnant_R = it->remnant_r * it->mass * sinh(it->y_r); Pz_remnant_total += Pz_remnant_L + Pz_remnant_R; } - music_message << "E_total = " - << E_string_total + E_remnant_total << " GeV. " + music_message << "E_total = " << E_string_total + E_remnant_total + << " GeV. " << "E_string_total = " << E_string_total << " GeV, " << "E_remnant_total = " << E_remnant_total << " GeV."; music_message.flush("info"); - music_message << "Pz_total = " - << Pz_string_total + Pz_remnant_total << " GeV. " + music_message << "Pz_total = " << Pz_string_total + Pz_remnant_total + << " GeV. " << "Pz_string_total = " << Pz_string_total << " GeV, " << "Pz_remnant_total = " << Pz_remnant_total << " GeV."; music_message.flush("info"); } - void HydroSourceStrings::prepare_list_for_current_tau_frame( - const double tau_local) { + const double tau_local) { double dtau = DATA.delta_tau; QCD_strings_list_current_tau.clear(); QCD_strings_baryon_list_current_tau.clear(); QCD_strings_remnant_list_current_tau.clear(); - for (auto &it: QCD_strings_list) { - if (( it->tau_baryon_left >= (tau_local - 1./2.*dtau) - && it->tau_baryon_left < (tau_local + 3./2.*dtau) + for (auto &it : QCD_strings_list) { + if ((it->tau_baryon_left >= (tau_local - 1. / 2. * dtau) + && it->tau_baryon_left < (tau_local + 3. / 2. * dtau) && it->baryon_frac_l > 0.) - || ( it->tau_baryon_right >= (tau_local - 1./2.*dtau) - && it->tau_baryon_right < (tau_local + 3./2.*dtau) - && it->baryon_frac_r > 0.) - ) { + || (it->tau_baryon_right >= (tau_local - 1. / 2. * dtau) + && it->tau_baryon_right < (tau_local + 3. / 2. * dtau) + && it->baryon_frac_r > 0.)) { QCD_strings_baryon_list_current_tau.push_back(it); } - if (( it->tau_end_left >= (tau_local - 1./2.*dtau) - && it->tau_end_left < (tau_local + 3./2.*dtau)) - || ( it->tau_end_right >= (tau_local - 1./2.*dtau) - && it->tau_end_right < (tau_local + 3./2.*dtau))) { + if ((it->tau_end_left >= (tau_local - 1. / 2. * dtau) + && it->tau_end_left < (tau_local + 3. / 2. * dtau)) + || (it->tau_end_right >= (tau_local - 1. / 2. * dtau) + && it->tau_end_right < (tau_local + 3. / 2. * dtau))) { QCD_strings_remnant_list_current_tau.push_back(it); } - if ( it->tau_start <= tau_local + 3./2.*dtau - && std::max(it->tau_end_left, it->tau_end_right) >= tau_local - dtau/2.) { + if (it->tau_start <= tau_local + 3. / 2. * dtau + && std::max(it->tau_end_left, it->tau_end_right) + >= tau_local - dtau / 2.) { QCD_strings_list_current_tau.push_back(it); } } @@ -358,49 +352,50 @@ void HydroSourceStrings::prepare_list_for_current_tau_frame( music_message.flush("info"); } - void HydroSourceStrings::get_hydro_energy_source( const double tau, const double x, const double y, const double eta_s, const FlowVec &u_mu, EnergyFlowVec &j_mu) const { j_mu = {0}; - if ( QCD_strings_list_current_tau.size() == 0 - && QCD_strings_remnant_list_current_tau.size() == 0) return; + if (QCD_strings_list_current_tau.size() == 0 + && QCD_strings_remnant_list_current_tau.size() == 0) + return; const double dtau = DATA.delta_tau; const double n_sigma_skip = 8.; - const double exp_tau = 1./tau; - for (auto const&it: QCD_strings_list_current_tau) { + const double exp_tau = 1. / tau; + for (auto const &it : QCD_strings_list_current_tau) { const double sigma_x = it->sigma_x; - const double sigma_x_sq = sigma_x*sigma_x; + const double sigma_x_sq = sigma_x * sigma_x; const double sigma_eta = it->sigma_eta; - const double alpsig = preEqFlowFactor_*sigma_x; - const double prefactor_prep = ( - 1./(2.*M_PI*(sigma_x_sq - + exp(alpsig*alpsig/2.)*sqrt(M_PI/2) - *alpsig*sigma_x_sq*erf(alpsig/sqrt(2.))) - ) - ); - const double prefactor_etas = 1./(sqrt(2.*M_PI)*sigma_eta); - const double skip_dis_x = n_sigma_skip*sigma_x; - const double skip_dis_eta = n_sigma_skip*sigma_eta; + const double alpsig = preEqFlowFactor_ * sigma_x; + const double prefactor_prep = + (1. + / (2. * M_PI + * (sigma_x_sq + + exp(alpsig * alpsig / 2.) * sqrt(M_PI / 2) * alpsig + * sigma_x_sq * erf(alpsig / sqrt(2.))))); + const double prefactor_etas = 1. / (sqrt(2. * M_PI) * sigma_eta); + const double skip_dis_x = n_sigma_skip * sigma_x; + const double skip_dis_eta = n_sigma_skip * sigma_eta; // energy source from strings - const double tau_0 = it->tau_0; + const double tau_0 = it->tau_0; const double delta_tau = it->tau_form; if (eta_s < it->eta_s_left - skip_dis_eta - || eta_s > it->eta_s_right + skip_dis_eta) continue; - double eta_frac = ((eta_s - it->eta_s_left) - /std::max(Util::small_eps, - it->eta_s_right - it->eta_s_left)); + || eta_s > it->eta_s_right + skip_dis_eta) + continue; + double eta_frac = + ((eta_s - it->eta_s_left) + / std::max(Util::small_eps, it->eta_s_right - it->eta_s_left)); eta_frac = std::max(0., std::min(1., eta_frac)); - const double x_perp = getStringTransverseCoord(it->x_pl, it->x_pr, - eta_frac); + const double x_perp = + getStringTransverseCoord(it->x_pl, it->x_pr, eta_frac); double x_dis = x - x_perp; if (std::abs(x_dis) > skip_dis_x) continue; - const double y_perp = getStringTransverseCoord(it->y_pl, it->y_pr, - eta_frac); + const double y_perp = + getStringTransverseCoord(it->y_pl, it->y_pr, eta_frac); double y_dis = y - y_perp; if (std::abs(y_dis) > skip_dis_x) continue; @@ -411,28 +406,26 @@ void HydroSourceStrings::get_hydro_energy_source( // f(eta) = 0.5*(- Erf((eta_L - eta)/sigma) // + Erf((eta_R - eta)/sigma)) double eta_s_shift = 0.0; - double tau_L = tau - dtau/2.; + double tau_L = tau - dtau / 2.; if (tau_L > tau_0 + delta_tau) { - eta_s_shift = acosh((tau_L*tau_L + tau_0*tau_0 - - delta_tau*delta_tau) - /std::max(Util::small_eps, 2.*tau_L*tau_0)); + eta_s_shift = acosh( + (tau_L * tau_L + tau_0 * tau_0 - delta_tau * delta_tau) + / std::max(Util::small_eps, 2. * tau_L * tau_0)); } - double eta_s_L = std::min(it->eta_s_right, - it->eta_s_0 - eta_s_shift); - double eta_s_R = std::max(it->eta_s_left, - it->eta_s_0 + eta_s_shift); + double eta_s_L = std::min(it->eta_s_right, it->eta_s_0 - eta_s_shift); + double eta_s_R = std::max(it->eta_s_left, it->eta_s_0 + eta_s_shift); double eta_s_next_shift = 0.0; - double tau_next = tau + dtau/2.; + double tau_next = tau + dtau / 2.; if (tau_next > tau_0 + delta_tau) { eta_s_next_shift = acosh( - (tau_next*tau_next + tau_0*tau_0 - delta_tau*delta_tau) - /std::max(Util::small_eps, 2.*tau_next*tau_0)); + (tau_next * tau_next + tau_0 * tau_0 - delta_tau * delta_tau) + / std::max(Util::small_eps, 2. * tau_next * tau_0)); } - double eta_s_L_next = std::max(it->eta_s_left, - it->eta_s_0 - eta_s_next_shift); - double eta_s_R_next = std::min(it->eta_s_right, - it->eta_s_0 + eta_s_next_shift); + double eta_s_L_next = + std::max(it->eta_s_left, it->eta_s_0 - eta_s_next_shift); + double eta_s_R_next = + std::min(it->eta_s_right, it->eta_s_0 + eta_s_next_shift); bool flag_left = true; // the left string segment is valid if (eta_s_L_next > eta_s_L) flag_left = false; @@ -442,85 +435,85 @@ void HydroSourceStrings::get_hydro_energy_source( double exp_eta_s = 0.; if (flag_left) { - if ( eta_s > eta_s_L_next - skip_dis_eta + if (eta_s > eta_s_L_next - skip_dis_eta && eta_s < eta_s_L + skip_dis_eta) { - exp_eta_s += 0.5*( - - erf((eta_s_L_next - eta_s)/(sqrt(2.)*sigma_eta)) - + erf((eta_s_L - eta_s)/(sqrt(2.)*sigma_eta))); + exp_eta_s += + 0.5 + * (-erf((eta_s_L_next - eta_s) / (sqrt(2.) * sigma_eta)) + + erf((eta_s_L - eta_s) / (sqrt(2.) * sigma_eta))); } } if (flag_right) { - if ( eta_s > eta_s_R - skip_dis_eta + if (eta_s > eta_s_R - skip_dis_eta && eta_s < eta_s_R_next + skip_dis_eta) { - exp_eta_s += 0.5*( - - erf((eta_s_R - eta_s)/(sqrt(2.)*sigma_eta)) - + erf((eta_s_R_next - eta_s)/(sqrt(2.)*sigma_eta))); + exp_eta_s += + 0.5 + * (-erf((eta_s_R - eta_s) / (sqrt(2.) * sigma_eta)) + + erf((eta_s_R_next - eta_s) / (sqrt(2.) * sigma_eta))); } } - double exp_xperp = exp(-(x_dis*x_dis + y_dis*y_dis) - /(2.*sigma_x*sigma_x)); - double cosh_perp = ( - cosh(preEqFlowFactor_*sqrt(x_dis*x_dis + y_dis*y_dis))); - double sinh_perp = ( - sinh(preEqFlowFactor_*sqrt(x_dis*x_dis + y_dis*y_dis))); + double exp_xperp = + exp(-(x_dis * x_dis + y_dis * y_dis) / (2. * sigma_x * sigma_x)); + double cosh_perp = + (cosh(preEqFlowFactor_ * sqrt(x_dis * x_dis + y_dis * y_dis))); + double sinh_perp = + (sinh(preEqFlowFactor_ * sqrt(x_dis * x_dis + y_dis * y_dis))); double phi_perp = atan2(y_dis, x_dis); - double e_local = exp_tau*exp_xperp*exp_eta_s*it->norm; + double e_local = exp_tau * exp_xperp * exp_eta_s * it->norm; double Delta_eta = it->eta_s_right - it->eta_s_left; double denorm_safe = std::copysign( - std::max(Util::small_eps, std::abs(Delta_eta)), Delta_eta); - double y_string = (it->y_l + (it->y_r - it->y_l)/denorm_safe - *(eta_s - it->eta_s_left)); + std::max(Util::small_eps, std::abs(Delta_eta)), Delta_eta); + double y_string = + (it->y_l + + (it->y_r - it->y_l) / denorm_safe * (eta_s - it->eta_s_left)); double cosh_long = cosh(y_string - eta_s); double sinh_long = sinh(y_string - eta_s); - //double cosh_perp = 1.0; - double local_eperp = prefactor_etas*prefactor_prep*e_local; - j_mu[0] += local_eperp*cosh_long*cosh_perp; + // double cosh_perp = 1.0; + double local_eperp = prefactor_etas * prefactor_prep * e_local; + j_mu[0] += local_eperp * cosh_long * cosh_perp; if (std::isnan(j_mu[0])) { std::cout << local_eperp << " " << cosh_long << std::endl; std::cout << prefactor_etas << " " << prefactor_prep << " " - << e_local << " " << cosh_perp - << std::endl; - std::cout << exp_tau << " " << exp_xperp << " " - << exp_eta_s << " " << it->norm << std::endl; + << e_local << " " << cosh_perp << std::endl; + std::cout << exp_tau << " " << exp_xperp << " " << exp_eta_s + << " " << it->norm << std::endl; std::cout << x_dis << " " << y_dis << " " << sigma_x << std::endl; std::cout << it->x_pl << " " << it->x_pr << " " << eta_frac - << " " << it->eta_s_right << " " - << it->eta_s_left << std::endl; + << " " << it->eta_s_right << " " << it->eta_s_left + << std::endl; } - j_mu[1] += local_eperp*sinh_perp*cos(phi_perp); - j_mu[2] += local_eperp*sinh_perp*sin(phi_perp); - j_mu[3] += local_eperp*sinh_long*cosh_perp; + j_mu[1] += local_eperp * sinh_perp * cos(phi_perp); + j_mu[2] += local_eperp * sinh_perp * sin(phi_perp); + j_mu[3] += local_eperp * sinh_long * cosh_perp; } - for (auto const&it: QCD_strings_remnant_list_current_tau) { + for (auto const &it : QCD_strings_remnant_list_current_tau) { const double sigma_x = it->sigma_x; - const double sigma_x_sq = sigma_x*sigma_x; + const double sigma_x_sq = sigma_x * sigma_x; const double sigma_eta = it->sigma_eta; - const double alpsig = preEqFlowFactor_*sigma_x; - const double prefactor_prep = ( - 1./(2.*M_PI*(sigma_x_sq - + exp(alpsig*alpsig/2.)*sqrt(M_PI/2) - *alpsig*sigma_x_sq*erf(alpsig/sqrt(2.))) - ) - ); - const double prefactor_etas = 1./(sqrt(2.*M_PI)*sigma_eta); - const double prefactors = prefactor_prep*prefactor_etas; - const double skip_dis_x = n_sigma_skip*sigma_x; - const double skip_dis_eta = n_sigma_skip*sigma_eta; + const double alpsig = preEqFlowFactor_ * sigma_x; + const double prefactor_prep = + (1. + / (2. * M_PI + * (sigma_x_sq + + exp(alpsig * alpsig / 2.) * sqrt(M_PI / 2) * alpsig + * sigma_x_sq * erf(alpsig / sqrt(2.))))); + const double prefactor_etas = 1. / (sqrt(2. * M_PI) * sigma_eta); + const double prefactors = prefactor_prep * prefactor_etas; + const double skip_dis_x = n_sigma_skip * sigma_x; + const double skip_dis_eta = n_sigma_skip * sigma_eta; // add remnant energy at the string ends bool flag_left = false; - if ( it->tau_end_left >= tau - dtau/2. - && it->tau_end_left < tau + dtau/2. - && it->remnant_l > 0.) { + if (it->tau_end_left >= tau - dtau / 2. + && it->tau_end_left < tau + dtau / 2. && it->remnant_l > 0.) { flag_left = true; } bool flag_right = false; - if ( it->tau_end_right >= tau - dtau/2. - && it->tau_end_right < tau + dtau/2. - && it->remnant_r > 0.) { + if (it->tau_end_right >= tau - dtau / 2. + && it->tau_end_right < tau + dtau / 2. && it->remnant_r > 0.) { flag_right = true; } @@ -534,94 +527,103 @@ void HydroSourceStrings::get_hydro_energy_source( if (flag_left) { double eta_dis_left = std::abs(eta_s - it->eta_s_left); if (eta_dis_left < skip_dis_eta) { - exp_eta_s_left = (exp(-eta_dis_left*eta_dis_left - /(2.*sigma_eta*sigma_eta))); + exp_eta_s_left = (exp( + -eta_dis_left * eta_dis_left + / (2. * sigma_eta * sigma_eta))); } } double exp_eta_s_right = 0.0; if (flag_right) { double eta_dis_right = std::abs(eta_s - it->eta_s_right); if (eta_dis_right < skip_dis_eta) { - exp_eta_s_right = (exp(-eta_dis_right*eta_dis_right - /(2.*sigma_eta*sigma_eta))); + exp_eta_s_right = (exp( + -eta_dis_right * eta_dis_right + / (2. * sigma_eta * sigma_eta))); } } - double cosh_long = exp_tau*( - exp_eta_s_left*(it->remnant_l)*(it->E_remnant_norm_L)*cosh(it->y_l - eta_s) - + exp_eta_s_right*(it->remnant_r)*(it->E_remnant_norm_R)*cosh(it->y_r - eta_s) - ); - double sinh_long = exp_tau*( - exp_eta_s_left*(it->remnant_l)*(it->E_remnant_norm_L)*sinh(it->y_l - eta_s) - + exp_eta_s_right*(it->remnant_r)*(it->E_remnant_norm_R)*sinh(it->y_r - eta_s) - ); + double cosh_long = + exp_tau + * (exp_eta_s_left * (it->remnant_l) * (it->E_remnant_norm_L) + * cosh(it->y_l - eta_s) + + exp_eta_s_right * (it->remnant_r) * (it->E_remnant_norm_R) + * cosh(it->y_r - eta_s)); + double sinh_long = + exp_tau + * (exp_eta_s_left * (it->remnant_l) * (it->E_remnant_norm_L) + * sinh(it->y_l - eta_s) + + exp_eta_s_right * (it->remnant_r) * (it->E_remnant_norm_R) + * sinh(it->y_r - eta_s)); double cosh_perp = 1.; double sinh_perp = 0.; double phi_perp = 0.; double exp_xperp = 0.; if (cosh_long > 0) { - exp_xperp = (prefactors*exp(-(x_dis*x_dis + y_dis*y_dis) - /(2.*sigma_x*sigma_x))); - cosh_perp = ( - cosh(preEqFlowFactor_*sqrt(x_dis*x_dis + y_dis*y_dis))); - sinh_perp = ( - sinh(preEqFlowFactor_*sqrt(x_dis*x_dis + y_dis*y_dis))); + exp_xperp = + (prefactors + * exp( + -(x_dis * x_dis + y_dis * y_dis) + / (2. * sigma_x * sigma_x))); + cosh_perp = + (cosh(preEqFlowFactor_ * sqrt(x_dis * x_dis + y_dis * y_dis))); + sinh_perp = + (sinh(preEqFlowFactor_ * sqrt(x_dis * x_dis + y_dis * y_dis))); phi_perp = atan2(y_dis, x_dis); } - j_mu[0] += exp_xperp*cosh_long*cosh_perp; - j_mu[1] += exp_xperp*sinh_perp*cos(phi_perp); - j_mu[2] += exp_xperp*sinh_perp*sin(phi_perp); - j_mu[3] += exp_xperp*sinh_long*cosh_perp; + j_mu[0] += exp_xperp * cosh_long * cosh_perp; + j_mu[1] += exp_xperp * sinh_perp * cos(phi_perp); + j_mu[2] += exp_xperp * sinh_perp * sin(phi_perp); + j_mu[3] += exp_xperp * sinh_long * cosh_perp; } - const double prefactor_tau = 1./dtau; - const double unit_convert = 1.0/Util::hbarc; - const double prefactors = prefactor_tau*unit_convert; + const double prefactor_tau = 1. / dtau; + const double unit_convert = 1.0 / Util::hbarc; + const double prefactors = prefactor_tau * unit_convert; j_mu[0] *= prefactors; // 1/fm^4 j_mu[1] *= prefactors; // 1/fm^4 j_mu[2] *= prefactors; // 1/fm^4 j_mu[3] *= prefactors; // 1/fm^4 } - double HydroSourceStrings::get_hydro_rhob_source( - const double tau, const double x, const double y, const double eta_s, - const FlowVec &u_mu) const { + const double tau, const double x, const double y, const double eta_s, + const FlowVec &u_mu) const { double res = 0.; - if (QCD_strings_baryon_list_current_tau.size() == 0) return(res); + if (QCD_strings_baryon_list_current_tau.size() == 0) return (res); // flow velocity - const double gamma_perp_flow = sqrt(1. + u_mu[1]*u_mu[1] + u_mu[2]*u_mu[2]); - const double y_perp_flow = acosh(gamma_perp_flow); - const double y_long_flow = asinh(u_mu[3]/gamma_perp_flow) + eta_s; - const double sin_phi_flow = u_mu[1]/gamma_perp_flow; - const double cos_phi_flow = u_mu[2]/gamma_perp_flow; - const double dtau = DATA.delta_tau; - - const double exp_tau = 1.0/tau; + const double gamma_perp_flow = + sqrt(1. + u_mu[1] * u_mu[1] + u_mu[2] * u_mu[2]); + const double y_perp_flow = acosh(gamma_perp_flow); + const double y_long_flow = asinh(u_mu[3] / gamma_perp_flow) + eta_s; + const double sin_phi_flow = u_mu[1] / gamma_perp_flow; + const double cos_phi_flow = u_mu[2] / gamma_perp_flow; + const double dtau = DATA.delta_tau; + + const double exp_tau = 1.0 / tau; const double n_sigma_skip = 8.; - for (auto &it: QCD_strings_baryon_list_current_tau) { + for (auto &it : QCD_strings_baryon_list_current_tau) { const double sigma_x = it->sigma_x; const double sigma_eta = it->sigma_eta; - const double prefactor_prep = 1./(2.*M_PI*sigma_x*sigma_x); - const double prefactor_etas = 1./(sqrt(2.*M_PI)*sigma_eta); - const double skip_dis_x = n_sigma_skip*sigma_x; - const double skip_dis_eta = n_sigma_skip*sigma_eta; + const double prefactor_prep = 1. / (2. * M_PI * sigma_x * sigma_x); + const double prefactor_etas = 1. / (sqrt(2. * M_PI) * sigma_eta); + const double skip_dis_x = n_sigma_skip * sigma_x; + const double skip_dis_eta = n_sigma_skip * sigma_eta; // skip the evaluation if the strings is too far away in the // space-time grid // dumping energy into the medium from the active strings - //double tau_dis_left = fabs(tau - it->tau_end_left); - //double tau_dis_right = fabs(tau - it->tau_end_right); + // double tau_dis_left = fabs(tau - it->tau_end_left); + // double tau_dis_right = fabs(tau - it->tau_end_right); int flag_left = 0; - if ( it->tau_baryon_left >= tau - dtau/2. - && it->tau_baryon_left < tau + dtau/2. + if (it->tau_baryon_left >= tau - dtau / 2. + && it->tau_baryon_left < tau + dtau / 2. && it->baryon_frac_l > 0.) { flag_left = 1; } int flag_right = 0; - if ( it->tau_baryon_right >= tau - dtau/2. - && it->tau_baryon_right < tau + dtau/2. + if (it->tau_baryon_right >= tau - dtau / 2. + && it->tau_baryon_right < tau + dtau / 2. && it->baryon_frac_r > 0.) { flag_right = 1; } @@ -629,101 +631,102 @@ double HydroSourceStrings::get_hydro_rhob_source( if (flag_left == 0 && flag_right == 0) continue; if (eta_s < it->eta_s_left - skip_dis_eta - || eta_s > it->eta_s_right + skip_dis_eta) continue; - - double eta_frac_left = ( - (eta_s - it->eta_s_left) - /std::max(Util::small_eps, it->eta_s_right - it->eta_s_left)); - double eta_frac_right = ( - (eta_s - it->eta_s_right) - /std::max(Util::small_eps, it->eta_s_right - it->eta_s_left)); + || eta_s > it->eta_s_right + skip_dis_eta) + continue; + + double eta_frac_left = + ((eta_s - it->eta_s_left) + / std::max(Util::small_eps, it->eta_s_right - it->eta_s_left)); + double eta_frac_right = + ((eta_s - it->eta_s_right) + / std::max(Util::small_eps, it->eta_s_right - it->eta_s_left)); eta_frac_left = std::max(0., std::min(1., eta_frac_left)); eta_frac_right = std::max(0., std::min(1., eta_frac_right)); - const double x_perp_left = getStringTransverseCoord( - it->x_pl, it->x_pr, eta_frac_left); - const double x_perp_right = getStringTransverseCoord( - it->x_pl, it->x_pr, eta_frac_right); - const double x_dis_left = x - x_perp_left; + const double x_perp_left = + getStringTransverseCoord(it->x_pl, it->x_pr, eta_frac_left); + const double x_perp_right = + getStringTransverseCoord(it->x_pl, it->x_pr, eta_frac_right); + const double x_dis_left = x - x_perp_left; const double x_dis_right = x - x_perp_right; if (std::abs(x_dis_left) > skip_dis_x - && std::abs(x_dis_right) > skip_dis_x) { + && std::abs(x_dis_right) > skip_dis_x) { continue; } - const double y_perp_left = getStringTransverseCoord( - it->y_pl, it->y_pr, eta_frac_left); - const double y_perp_right = getStringTransverseCoord( - it->y_pl, it->y_pr, eta_frac_right); - const double y_dis_left = y - y_perp_left; + const double y_perp_left = + getStringTransverseCoord(it->y_pl, it->y_pr, eta_frac_left); + const double y_perp_right = + getStringTransverseCoord(it->y_pl, it->y_pr, eta_frac_right); + const double y_dis_left = y - y_perp_left; const double y_dis_right = y - y_perp_right; if (std::abs(y_dis_left) > skip_dis_x - && std::abs(y_dis_right) > skip_dis_x) { + && std::abs(y_dis_right) > skip_dis_x) { continue; } double exp_eta_s_left = 0.0; if (flag_left == 1) { - double eta_dis_left = std::abs(eta_s - - it->eta_s_baryon_left); + double eta_dis_left = std::abs(eta_s - it->eta_s_baryon_left); if (eta_dis_left < skip_dis_eta) { - exp_eta_s_left = (exp(-eta_dis_left*eta_dis_left - /(2.*sigma_eta*sigma_eta))); + exp_eta_s_left = (exp( + -eta_dis_left * eta_dis_left + / (2. * sigma_eta * sigma_eta))); } } double exp_eta_s_right = 0.0; if (flag_right == 1) { - double eta_dis_right = std::abs(eta_s - - it->eta_s_baryon_right); + double eta_dis_right = std::abs(eta_s - it->eta_s_baryon_right); if (eta_dis_right < skip_dis_eta) { - exp_eta_s_right = (exp(-eta_dis_right*eta_dis_right - /(2.*sigma_eta*sigma_eta))); + exp_eta_s_right = (exp( + -eta_dis_right * eta_dis_right + / (2. * sigma_eta * sigma_eta))); } } - double exp_xperp_l = exp( - -(x_dis_left*x_dis_left + y_dis_left*y_dis_left) - /(2.*sigma_x*sigma_x)); - double exp_xperp_r = exp( - -(x_dis_right*x_dis_right + y_dis_right*y_dis_right) - /(2.*sigma_x*sigma_x)); + double exp_xperp_l = + exp(-(x_dis_left * x_dis_left + y_dis_left * y_dis_left) + / (2. * sigma_x * sigma_x)); + double exp_xperp_r = + exp(-(x_dis_right * x_dis_right + y_dis_right * y_dis_right) + / (2. * sigma_x * sigma_x)); - double fsmear = exp_tau*( - exp_xperp_l*exp_eta_s_left*it->baryon_frac_l - + exp_xperp_r*exp_eta_s_right*it->baryon_frac_r); + double fsmear = exp_tau + * (exp_xperp_l * exp_eta_s_left * it->baryon_frac_l + + exp_xperp_r * exp_eta_s_right * it->baryon_frac_r); if (fsmear > 0.) { - double rapidity_local = ( - ( exp_eta_s_left*(it->baryon_frac_l)*(it->y_l_baryon) - + exp_eta_s_right*(it->baryon_frac_r)*(it->y_r_baryon)) - /(std::max(Util::small_eps, - (exp_eta_s_left*(it->baryon_frac_l) - + exp_eta_s_right*(it->baryon_frac_r))) - ) - ); - double y_dump = ((1. - parton_quench_factor)*rapidity_local - + parton_quench_factor*y_long_flow); - double y_dump_perp = parton_quench_factor*y_perp_flow; + double rapidity_local = + ((exp_eta_s_left * (it->baryon_frac_l) * (it->y_l_baryon) + + exp_eta_s_right * (it->baryon_frac_r) * (it->y_r_baryon)) + / (std::max( + Util::small_eps, + (exp_eta_s_left * (it->baryon_frac_l) + + exp_eta_s_right * (it->baryon_frac_r))))); + double y_dump = + ((1. - parton_quench_factor) * rapidity_local + + parton_quench_factor * y_long_flow); + double y_dump_perp = parton_quench_factor * y_perp_flow; double p_dot_u = 1.; if (parton_quench_factor < 1.) { - p_dot_u = ( u_mu[0]*cosh(y_dump)*cosh(y_dump_perp) - - u_mu[1]*sinh(y_dump_perp)*cos_phi_flow - - u_mu[2]*sinh(y_dump_perp)*sin_phi_flow - - u_mu[3]*sinh(y_dump)*cosh(y_dump_perp)); + p_dot_u = + (u_mu[0] * cosh(y_dump) * cosh(y_dump_perp) + - u_mu[1] * sinh(y_dump_perp) * cos_phi_flow + - u_mu[2] * sinh(y_dump_perp) * sin_phi_flow + - u_mu[3] * sinh(y_dump) * cosh(y_dump_perp)); } - res += prefactor_etas*prefactor_prep*p_dot_u*fsmear; + res += prefactor_etas * prefactor_prep * p_dot_u * fsmear; } } - const double prefactor_tau = 1./dtau; + const double prefactor_tau = 1. / dtau; res *= prefactor_tau; - return(res); + return (res); } - double HydroSourceStrings::getStringTransverseCoord( - const double xl, const double xr, const double etaFrac) const { - double xT = ((xl + xr)/2. - + stringTransverseShiftFrac_*(0.5 - etaFrac)*(xl - xr)/2.); - return(xT); + const double xl, const double xr, const double etaFrac) const { + double xT = + ((xl + xr) / 2. + + stringTransverseShiftFrac_ * (0.5 - etaFrac) * (xl - xr) / 2.); + return (xT); } - diff --git a/src/hydro_source_strings.h b/src/hydro_source_strings.h index 198b8281..80a3d00d 100644 --- a/src/hydro_source_strings.h +++ b/src/hydro_source_strings.h @@ -3,26 +3,27 @@ #ifndef SRC_HYDRO_SOURCE_STRINGS_H_ #define SRC_HYDRO_SOURCE_STRINGS_H_ -#include #include +#include + #include "hydro_source_base.h" //! This data structure contains a QCD string object struct QCD_string { - double norm; // normalization for the string energy + double norm; // normalization for the string energy double E_remnant_norm_L, E_remnant_norm_R; - double m_over_sigma; // m/sigma [fm] sigma is the string tension + double m_over_sigma; // m/sigma [fm] sigma is the string tension double mass; double tau_form; double sigma_x, sigma_eta; double tau_start, eta_s_start; double tau_0, eta_s_0; - double x_perp, y_perp; // transverse position of the string + double x_perp, y_perp; // transverse position of the string double x_pl, y_pl, x_pr, y_pr; double tau_end_left, tau_end_right; double eta_s_left, eta_s_right; - double y_l, y_r; // rapidity of the two ends of the string + double y_l, y_r; // rapidity of the two ends of the string double remnant_l, remnant_r; double y_l_i, y_r_i; double tau_baryon_left, tau_baryon_right; @@ -31,9 +32,8 @@ struct QCD_string { double baryon_frac_l, baryon_frac_r; }; - class HydroSourceStrings : public HydroSourceBase { - private: + private: InitData &DATA; int string_dump_mode; double string_quench_factor; @@ -42,10 +42,12 @@ class HydroSourceStrings : public HydroSourceBase { double preEqFlowFactor_; std::vector> QCD_strings_list; std::vector> QCD_strings_list_current_tau; - std::vector> QCD_strings_remnant_list_current_tau; - std::vector> QCD_strings_baryon_list_current_tau; + std::vector> + QCD_strings_remnant_list_current_tau; + std::vector> + QCD_strings_baryon_list_current_tau; - public: + public: HydroSourceStrings() = delete; HydroSourceStrings(InitData &DATA_in); ~HydroSourceStrings(); @@ -54,25 +56,26 @@ class HydroSourceStrings : public HydroSourceBase { //! and partons which are produced from the MC-Glauber-LEXUS model void read_in_QCD_strings_and_partons(); - double getStringEndTau(const double tau0, const double tau_form, - const double eta_s_0, const double eta_s) const; + double getStringEndTau( + const double tau0, const double tau_form, const double eta_s_0, + const double eta_s) const; //! this function returns the energy source term J^\mu at a given point //! (tau, x, y, eta_s) void get_hydro_energy_source( const double tau, const double x, const double y, const double eta_s, - const FlowVec &u_mu, EnergyFlowVec &j_mu) const ; + const FlowVec &u_mu, EnergyFlowVec &j_mu) const; //! this function returns the net baryon density source term rho //! at a given point (tau, x, y, eta_s) - double get_hydro_rhob_source(const double tau, const double x, - const double y, const double eta_s, - const FlowVec &u_mu) const ; + double get_hydro_rhob_source( + const double tau, const double x, const double y, const double eta_s, + const FlowVec &u_mu) const; void prepare_list_for_current_tau_frame(const double tau_local); void compute_norm_for_strings(); - double getStringTransverseCoord(const double xl, const double xr, - const double etaFrac) const; + double getStringTransverseCoord( + const double xl, const double xr, const double etaFrac) const; }; #endif // SRC_HYDRO_SOURCE_STRINGS_H_ diff --git a/src/init.cpp b/src/init.cpp index 8dbec16b..2ac70834 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1,39 +1,40 @@ // Copyright 2011 @ Bjoern Schenke, Sangyong Jeon, and Charles Gale -#include +#include "init.h" + #include -#include #include +#include +#include + #include "util.h" -#include "init.h" #ifndef _OPENMP - #define omp_get_thread_num() 0 - #define omp_get_num_threads() 1 +#define omp_get_thread_num() 0 +#define omp_get_num_threads() 1 #else - #include +#include #endif -using std::vector; using std::ifstream; +using std::vector; using Util::hbarc; - -Init::Init(const EOS &eosIn, InitData &DATA_in, - std::shared_ptr hydro_source_ptr_in) : - DATA(DATA_in), eos(eosIn){ +Init::Init( + const EOS &eosIn, InitData &DATA_in, + std::shared_ptr hydro_source_ptr_in) + : DATA(DATA_in), eos(eosIn) { hydro_source_terms_ptr = hydro_source_ptr_in; } - -void Init::InitArena(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, - Fields &arenaFieldsNext) { +void Init::InitArena( + Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, Fields &arenaFieldsNext) { print_num_of_threads(); music_message.info("initArena"); if (DATA.Initial_profile == 0) { music_message << "Using Initial_profile=" << DATA.Initial_profile; music_message << ", nx=" << DATA.nx << ", ny=" << DATA.ny; - music_message << ", dx=" << DATA.delta_x << " fm, dy=" - << DATA.delta_y << " fm."; + music_message << ", dx=" << DATA.delta_x << " fm, dy=" << DATA.delta_y + << " fm."; music_message.flush("info"); } else if (DATA.Initial_profile == 1) { music_message << "Using Initial_profile=" << DATA.Initial_profile; @@ -44,8 +45,8 @@ void Init::InitArena(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, DATA.delta_y = 0.1; DATA.delta_eta = 0.02; music_message << ", nx=" << DATA.nx << ", ny=" << DATA.ny; - music_message << ", dx=" << DATA.delta_x << " fm, dy=" - << DATA.delta_y << " fm. "; + music_message << ", dx=" << DATA.delta_x << " fm, dy=" << DATA.delta_y + << " fm. "; music_message << "neta=" << DATA.neta << ", deta=" << DATA.delta_eta; music_message.flush("info"); } else if (DATA.Initial_profile == 8) { @@ -61,9 +62,8 @@ void Init::InitArena(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, int nx, ny, neta; double deta, dx, dy, dummy2; // read the first line with general info - profile >> dummy >> dummy >> dummy2 - >> dummy >> neta >> dummy >> nx >> dummy >> ny - >> dummy >> deta >> dummy >> dx >> dummy >> dy; + profile >> dummy >> dummy >> dummy2 >> dummy >> neta >> dummy >> nx + >> dummy >> ny >> dummy >> deta >> dummy >> dx >> dummy >> dy; profile.close(); music_message << "Using Initial_profile=" << DATA.Initial_profile << ". Overwriting transverse lattice dimensions:"; @@ -76,8 +76,9 @@ void Init::InitArena(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, music_message << "deta=" << DATA.delta_eta << ", dx=" << DATA.delta_x << " fm, dy=" << DATA.delta_y << " fm."; music_message.flush("info"); - } else if ( DATA.Initial_profile == 9 || DATA.Initial_profile == 91 - || DATA.Initial_profile == 92 || DATA.Initial_profile == 93) { + } else if ( + DATA.Initial_profile == 9 || DATA.Initial_profile == 91 + || DATA.Initial_profile == 92 || DATA.Initial_profile == 93) { music_message.info(DATA.initName); ifstream profile(DATA.initName.c_str()); if (!profile.is_open()) { @@ -90,9 +91,8 @@ void Init::InitArena(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, int nx, ny, neta; double deta, dx, dy, dummy2; // read the first line with general info - profile >> dummy >> dummy >> dummy2 - >> dummy >> neta >> dummy >> nx >> dummy >> ny - >> dummy >> deta >> dummy >> dx >> dummy >> dy; + profile >> dummy >> dummy >> dummy2 >> dummy >> neta >> dummy >> nx + >> dummy >> ny >> dummy >> deta >> dummy >> dx >> dummy >> dy; profile.close(); music_message << "Using Initial_profile=" << DATA.Initial_profile << ". Overwriting lattice dimensions:"; @@ -101,25 +101,26 @@ void Init::InitArena(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, DATA.delta_x = dx; DATA.delta_y = dy; - music_message << "neta=" << DATA.neta - << ", nx=" << DATA.nx << ", ny=" << DATA.ny; + music_message << "neta=" << DATA.neta << ", nx=" << DATA.nx + << ", ny=" << DATA.ny; music_message << "deta=" << DATA.delta_eta << ", dx=" << DATA.delta_x << " fm, dy=" << DATA.delta_y << " fm."; music_message.flush("info"); } else if (DATA.Initial_profile == 11 || DATA.Initial_profile == 111) { - double tau_overlap = 2.*7./(sinh(DATA.beam_rapidity)); + double tau_overlap = 2. * 7. / (sinh(DATA.beam_rapidity)); DATA.tau0 = std::max(DATA.tau0, tau_overlap); music_message << "tau0 = " << DATA.tau0 << " fm/c."; music_message.flush("info"); } else if (DATA.Initial_profile == 112 || DATA.Initial_profile == 113) { - double tau_overlap = 2.*7./(sinh(DATA.beam_rapidity)); + double tau_overlap = 2. * 7. / (sinh(DATA.beam_rapidity)); DATA.tau0 = std::max(DATA.tau0, tau_overlap) - DATA.delta_tau; music_message << "tau0 = " << DATA.tau0 << " fm/c."; music_message.flush("info"); } else if (DATA.Initial_profile == 13 || DATA.Initial_profile == 131) { - DATA.tau0 = (hydro_source_terms_ptr.lock()->get_source_tau_min() - - DATA.delta_tau); - DATA.tau0 = static_cast(DATA.tau0/0.02)*0.02; + DATA.tau0 = + (hydro_source_terms_ptr.lock()->get_source_tau_min() + - DATA.delta_tau); + DATA.tau0 = static_cast(DATA.tau0 / 0.02) * 0.02; DATA.tau0 = std::max(0.1, DATA.tau0); } else if (DATA.Initial_profile == 30) { DATA.tau0 = hydro_source_terms_ptr.lock()->get_source_tau_min(); @@ -130,22 +131,21 @@ void Init::InitArena(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, music_message.flush("info"); const int nx = static_cast( - sqrt(jetscape_initial_energy_density.size()/DATA.neta)); + sqrt(jetscape_initial_energy_density.size() / DATA.neta)); const int ny = nx; DATA.nx = nx; DATA.ny = ny; - DATA.x_size = DATA.delta_x*nx; - DATA.y_size = DATA.delta_y*ny; + DATA.x_size = DATA.delta_x * nx; + DATA.y_size = DATA.delta_y * ny; - music_message << "neta = " << DATA.neta - << ", nx = " << nx << ", ny = " << ny; + music_message << "neta = " << DATA.neta << ", nx = " << nx + << ", ny = " << ny; music_message.flush("info"); - music_message << "deta=" << DATA.delta_eta - << ", dx=" << DATA.delta_x + music_message << "deta=" << DATA.delta_eta << ", dx=" << DATA.delta_x << " fm, dy=" << DATA.delta_y << " fm."; music_message.flush("info"); - music_message << "x_size = " << DATA.x_size - << " fm, y_size = " << DATA.y_size + music_message << "x_size = " << DATA.x_size + << " fm, y_size = " << DATA.y_size << " fm, eta_size = " << DATA.eta_size; music_message.flush("info"); } else if (DATA.Initial_profile == 101) { @@ -154,8 +154,8 @@ void Init::InitArena(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, music_message << "nx = " << DATA.nx << ", ny = " << DATA.ny << ", neta = " << DATA.neta; music_message.flush("info"); - music_message << "dx = " << DATA.delta_x << " fm, dy = " - << DATA.delta_y << " fm, deta = " << DATA.delta_eta; + music_message << "dx = " << DATA.delta_x << " fm, dy = " << DATA.delta_y + << " fm, deta = " << DATA.delta_eta; music_message.flush("info"); } @@ -170,11 +170,10 @@ void Init::InitArena(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, if (DATA.output_initial_density_profiles == 1) { output_initial_density_profiles(arenaFieldsCurr); } -}/* InitArena */ - +} /* InitArena */ void Init::print_num_of_threads() { - #pragma omp parallel for +#pragma omp parallel for for (int i = 0; i < 2; i++) { if (i == 0) { music_message << "OpenMP: using " << omp_get_num_threads() @@ -184,7 +183,6 @@ void Init::print_num_of_threads() { } } - //! This is a shell function to initial hydrodynamic fields void Init::InitTJb(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr) { if (DATA.Initial_profile == 0) { @@ -192,7 +190,7 @@ void Init::InitTJb(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr) { music_message.info(" Perform Gubser flow test ... "); music_message.info(" ----- information on initial distribution -----"); - #pragma omp parallel for +#pragma omp parallel for for (int ieta = 0; ieta < arenaFieldsCurr.nEta(); ieta++) { initial_Gubser_XY(ieta, arenaFieldsPrev, arenaFieldsCurr); } @@ -207,12 +205,13 @@ void Init::InitTJb(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr) { music_message << "file name used: " << DATA.initName; music_message.flush("info"); - #pragma omp parallel for +#pragma omp parallel for for (int ieta = 0; ieta < arenaFieldsCurr.nEta(); ieta++) { initial_IPGlasma_XY(ieta, arenaFieldsPrev, arenaFieldsCurr); } - } else if ( DATA.Initial_profile == 9 || DATA.Initial_profile == 91 - || DATA.Initial_profile == 92 || DATA.Initial_profile == 93) { + } else if ( + DATA.Initial_profile == 9 || DATA.Initial_profile == 91 + || DATA.Initial_profile == 92 || DATA.Initial_profile == 93) { // read in the profile from file // - IPGlasma initial conditions with initial flow // and initial shear viscous tensor @@ -220,7 +219,7 @@ void Init::InitTJb(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr) { music_message << "file name used: " << DATA.initName; music_message.flush("info"); - #pragma omp parallel for +#pragma omp parallel for for (int ieta = 0; ieta < arenaFieldsCurr.nEta(); ieta++) { initial_IPGlasma_XY_with_pi(ieta, arenaFieldsPrev, arenaFieldsCurr); } @@ -237,20 +236,19 @@ void Init::InitTJb(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr) { initial_MCGlb_with_rhob(arenaFieldsPrev, arenaFieldsCurr); } else if (DATA.Initial_profile == 112 || DATA.Initial_profile == 113) { - music_message.info( - "Initialize hydro with source terms from TA and TB"); - #pragma omp parallel for + music_message.info("Initialize hydro with source terms from TA and TB"); +#pragma omp parallel for for (int ieta = 0; ieta < arenaFieldsCurr.nEta(); ieta++) { initial_with_zero_XY(ieta, arenaFieldsPrev, arenaFieldsCurr); } } else if (DATA.Initial_profile == 13 || DATA.Initial_profile == 131) { music_message.info("Initialize hydro with source terms"); - #pragma omp parallel for +#pragma omp parallel for for (int ieta = 0; ieta < arenaFieldsCurr.nEta(); ieta++) { initial_with_zero_XY(ieta, arenaFieldsPrev, arenaFieldsCurr); } } else if (DATA.Initial_profile == 30) { - #pragma omp parallel for +#pragma omp parallel for for (int ieta = 0; ieta < arenaFieldsCurr.nEta(); ieta++) { initial_AMPT_XY(ieta, arenaFieldsPrev, arenaFieldsCurr); } @@ -259,7 +257,7 @@ void Init::InitTJb(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr) { music_message.info(" ----- information on initial distribution -----"); music_message << "initialized with a JETSCAPE initial condition."; music_message.flush("info"); - #pragma omp parallel for +#pragma omp parallel for for (int ieta = 0; ieta < arenaFieldsCurr.nEta(); ieta++) { initial_with_jetscape(ieta, arenaFieldsPrev, arenaFieldsCurr); } @@ -278,9 +276,9 @@ void Init::InitTJb(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr) { music_message << "Setting the initial viscous tensor to zero."; music_message.flush("info"); const int grid_neta = arenaFieldsCurr.nEta(); - const int grid_nx = arenaFieldsCurr.nX(); - const int grid_ny = arenaFieldsCurr.nY(); - #pragma omp parallel for collapse(3) + const int grid_nx = arenaFieldsCurr.nX(); + const int grid_ny = arenaFieldsCurr.nY(); +#pragma omp parallel for collapse(3) for (int ieta = 0; ieta < grid_neta; ieta++) { for (int ix = 0; ix < grid_nx; ix++) { for (int iy = 0; iy < grid_ny; iy++) { @@ -298,9 +296,8 @@ void Init::InitTJb(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr) { music_message.info("initial distribution done."); } - -void Init::initial_Gubser_XY(int ieta, Fields &arenaFieldsPrev, - Fields &arenaFieldsCurr) { +void Init::initial_Gubser_XY( + int ieta, Fields &arenaFieldsPrev, Fields &arenaFieldsCurr) { std::string input_filename; std::string input_filename_prev; if (DATA.turn_on_shear == 1) { @@ -352,22 +349,19 @@ void Init::initial_Gubser_XY(int ieta, Fields &arenaFieldsPrev, for (int iy = 0; iy < ny; iy++) { if (DATA.turn_on_shear == 1) { profile >> dummy >> dummy >> temp_profile_ed[ix][iy] - >> temp_profile_ux[ix][iy] >> temp_profile_uy[ix][iy]; + >> temp_profile_ux[ix][iy] >> temp_profile_uy[ix][iy]; profile >> temp_profile_pixx[ix][iy] - >> temp_profile_piyy[ix][iy] - >> temp_profile_pixy[ix][iy] - >> temp_profile_pi00[ix][iy] - >> temp_profile_pi0x[ix][iy] - >> temp_profile_pi0y[ix][iy] - >> temp_profile_pi33[ix][iy]; + >> temp_profile_piyy[ix][iy] >> temp_profile_pixy[ix][iy] + >> temp_profile_pi00[ix][iy] >> temp_profile_pi0x[ix][iy] + >> temp_profile_pi0y[ix][iy] >> temp_profile_pi33[ix][iy]; } else { profile >> dummy >> dummy >> temp_profile_ed[ix][iy] - >> temp_profile_rhob[ix][iy] - >> temp_profile_ux[ix][iy] >> temp_profile_uy[ix][iy]; + >> temp_profile_rhob[ix][iy] >> temp_profile_ux[ix][iy] + >> temp_profile_uy[ix][iy]; profile_prev >> dummy >> dummy >> temp_profile_ed_prev[ix][iy] - >> temp_profile_rhob_prev[ix][iy] - >> temp_profile_ux_prev[ix][iy] - >> temp_profile_uy_prev[ix][iy]; + >> temp_profile_rhob_prev[ix][iy] + >> temp_profile_ux_prev[ix][iy] + >> temp_profile_uy_prev[ix][iy]; } } } @@ -377,7 +371,7 @@ void Init::initial_Gubser_XY(int ieta, Fields &arenaFieldsPrev, } for (int ix = 0; ix < nx; ix++) { - for (int iy = 0; iy< ny; iy++) { + for (int iy = 0; iy < ny; iy++) { double rhob = 0.0; if (DATA.turn_on_shear == 0 && DATA.turn_on_rhob == 1) { rhob = temp_profile_rhob[ix][iy]; @@ -390,9 +384,9 @@ void Init::initial_Gubser_XY(int ieta, Fields &arenaFieldsPrev, arenaFieldsPrev.rhob_[idx] = rhob; arenaFieldsCurr.rhob_[idx] = rhob; - double utau_local = sqrt(1. - + temp_profile_ux[ix][iy]*temp_profile_ux[ix][iy] - + temp_profile_uy[ix][iy]*temp_profile_uy[ix][iy]); + double utau_local = sqrt( + 1. + temp_profile_ux[ix][iy] * temp_profile_ux[ix][iy] + + temp_profile_uy[ix][iy] * temp_profile_uy[ix][iy]); arenaFieldsCurr.u_[0][idx] = utau_local; arenaFieldsCurr.u_[1][idx] = temp_profile_ux[ix][iy]; arenaFieldsCurr.u_[2][idx] = temp_profile_uy[ix][iy]; @@ -402,10 +396,12 @@ void Init::initial_Gubser_XY(int ieta, Fields &arenaFieldsPrev, } if (DATA.turn_on_shear == 0) { - double utau_prev = sqrt(1. - + temp_profile_ux_prev[ix][iy]*temp_profile_ux_prev[ix][iy] - + temp_profile_uy_prev[ix][iy]*temp_profile_uy_prev[ix][iy] - ); + double utau_prev = sqrt( + 1. + + temp_profile_ux_prev[ix][iy] + * temp_profile_ux_prev[ix][iy] + + temp_profile_uy_prev[ix][iy] + * temp_profile_uy_prev[ix][iy]); arenaFieldsPrev.u_[0][idx] = utau_prev; arenaFieldsPrev.u_[1][idx] = temp_profile_ux_prev[ix][iy]; arenaFieldsPrev.u_[2][idx] = temp_profile_uy_prev[ix][iy]; @@ -431,7 +427,6 @@ void Init::initial_Gubser_XY(int ieta, Fields &arenaFieldsPrev, } } - void Init::initial_1p1D_eta(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr) { std::string input_ed_filename; std::string input_rhob_filename; @@ -441,8 +436,7 @@ void Init::initial_1p1D_eta(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr) { ifstream profile_ed(input_ed_filename.c_str()); if (!profile_ed.good()) { music_message << "Init::InitTJb: " - << "Can not open the initial file: " - << input_ed_filename; + << "Can not open the initial file: " << input_ed_filename; music_message.flush("error"); exit(1); } @@ -472,9 +466,9 @@ void Init::initial_1p1D_eta(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr) { const int ny = arenaFieldsCurr.nY(); for (int ieta = 0; ieta < neta; ieta++) { double rhob = temp_profile_rhob[ieta]; - double epsilon = temp_profile_ed[ieta]/hbarc; // fm^-4 + double epsilon = temp_profile_ed[ieta] / hbarc; // fm^-4 for (int ix = 0; ix < nx; ix++) { - for (int iy = 0; iy< ny; iy++) { + for (int iy = 0; iy < ny; iy++) { int idx = arenaFieldsCurr.getFieldIdx(ix, iy, ieta); arenaFieldsCurr.e_[idx] = epsilon; arenaFieldsCurr.rhob_[idx] = rhob; @@ -485,9 +479,8 @@ void Init::initial_1p1D_eta(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr) { arenaFieldsPrev.rhob_ = arenaFieldsCurr.rhob_; } - -void Init::initial_IPGlasma_XY(int ieta, Fields &arenaFieldsPrev, - Fields &arenaFieldsCurr) { +void Init::initial_IPGlasma_XY( + int ieta, Fields &arenaFieldsPrev, Fields &arenaFieldsCurr) { ifstream profile(DATA.initName.c_str()); std::string dummy; @@ -506,16 +499,15 @@ void Init::initial_IPGlasma_XY(int ieta, Fields &arenaFieldsPrev, double ux, uy, utau; for (int ix = 0; ix < nx; ix++) { for (int iy = 0; iy < ny; iy++) { - profile >> dummy1 >> dummy2 >> dummy3 - >> density >> utau >> ux >> uy - >> dummy >> dummy >> dummy >> dummy; + profile >> dummy1 >> dummy2 >> dummy3 >> density >> utau >> ux >> uy + >> dummy >> dummy >> dummy >> dummy; temp_profile_ed[ix][iy] = density; temp_profile_ux[ix][iy] = ux; temp_profile_uy[ix][iy] = uy; - temp_profile_utau[ix][iy] = sqrt(1. + ux*ux + uy*uy); + temp_profile_utau[ix][iy] = sqrt(1. + ux * ux + uy * uy); if (ix == 0 && iy == 0) { - DATA.x_size = -dummy2*2; - DATA.y_size = -dummy3*2; + DATA.x_size = -dummy2 * 2; + DATA.y_size = -dummy3 * 2; if (omp_get_thread_num() == 0) { music_message << "eta_size=" << DATA.eta_size << ", x_size=" << DATA.x_size @@ -527,22 +519,23 @@ void Init::initial_IPGlasma_XY(int ieta, Fields &arenaFieldsPrev, } profile.close(); - double eta = (DATA.delta_eta)*ieta - (DATA.eta_size)/2.0; - double eta_envelop_ed = eta_profile_plateau(eta, DATA.eta_flat/2.0, - DATA.eta_fall_off); + double eta = (DATA.delta_eta) * ieta - (DATA.eta_size) / 2.0; + double eta_envelop_ed = + eta_profile_plateau(eta, DATA.eta_flat / 2.0, DATA.eta_fall_off); int entropy_flag = DATA.initializeEntropy; for (int ix = 0; ix < nx; ix++) { - for (int iy = 0; iy< ny; iy++) { + for (int iy = 0; iy < ny; iy++) { int idx = arenaFieldsCurr.getFieldIdx(ix, iy, ieta); double rhob = 0.0; double epsilon = 0.0; if (entropy_flag == 0) { - epsilon = (temp_profile_ed[ix][iy]*eta_envelop_ed - *DATA.sFactor/hbarc); // 1/fm^4 + epsilon = + (temp_profile_ed[ix][iy] * eta_envelop_ed * DATA.sFactor + / hbarc); // 1/fm^4 } else { - double local_sd = (temp_profile_ed[ix][iy]*DATA.sFactor - *eta_envelop_ed); + double local_sd = + (temp_profile_ed[ix][iy] * DATA.sFactor * eta_envelop_ed); epsilon = eos.get_s2e(local_sd, rhob); } epsilon = std::max(Util::small_eps, epsilon); @@ -563,9 +556,8 @@ void Init::initial_IPGlasma_XY(int ieta, Fields &arenaFieldsPrev, } } - -void Init::initial_IPGlasma_XY_with_pi(int ieta, Fields &arenaFieldsPrev, - Fields &arenaFieldsCurr) { +void Init::initial_IPGlasma_XY_with_pi( + int ieta, Fields &arenaFieldsPrev, Fields &arenaFieldsCurr) { // Initial_profile == 9 : full T^\mu\nu // Initial_profile == 91: e and u^\mu // Initial_profile == 92: e only @@ -579,21 +571,21 @@ void Init::initial_IPGlasma_XY_with_pi(int ieta, Fields &arenaFieldsPrev, const int nx = arenaFieldsCurr.nX(); const int ny = arenaFieldsCurr.nY(); - std::vector temp_profile_ed(nx*ny, 0.0); - std::vector temp_profile_utau(nx*ny, 0.0); - std::vector temp_profile_ux(nx*ny, 0.0); - std::vector temp_profile_uy(nx*ny, 0.0); - std::vector temp_profile_ueta(nx*ny, 0.0); - std::vector temp_profile_pitautau(nx*ny, 0.0); - std::vector temp_profile_pitaux(nx*ny, 0.0); - std::vector temp_profile_pitauy(nx*ny, 0.0); - std::vector temp_profile_pitaueta(nx*ny, 0.0); - std::vector temp_profile_pixx(nx*ny, 0.0); - std::vector temp_profile_pixy(nx*ny, 0.0); - std::vector temp_profile_pixeta(nx*ny, 0.0); - std::vector temp_profile_piyy(nx*ny, 0.0); - std::vector temp_profile_piyeta(nx*ny, 0.0); - std::vector temp_profile_pietaeta(nx*ny, 0.0); + std::vector temp_profile_ed(nx * ny, 0.0); + std::vector temp_profile_utau(nx * ny, 0.0); + std::vector temp_profile_ux(nx * ny, 0.0); + std::vector temp_profile_uy(nx * ny, 0.0); + std::vector temp_profile_ueta(nx * ny, 0.0); + std::vector temp_profile_pitautau(nx * ny, 0.0); + std::vector temp_profile_pitaux(nx * ny, 0.0); + std::vector temp_profile_pitauy(nx * ny, 0.0); + std::vector temp_profile_pitaueta(nx * ny, 0.0); + std::vector temp_profile_pixx(nx * ny, 0.0); + std::vector temp_profile_pixy(nx * ny, 0.0); + std::vector temp_profile_pixeta(nx * ny, 0.0); + std::vector temp_profile_piyy(nx * ny, 0.0); + std::vector temp_profile_piyeta(nx * ny, 0.0); + std::vector temp_profile_pietaeta(nx * ny, 0.0); // read the one slice double density, dummy1, dummy2, dummy3; @@ -602,56 +594,58 @@ void Init::initial_IPGlasma_XY_with_pi(int ieta, Fields &arenaFieldsPrev, double pixx, pixy, pixeta, piyy, piyeta, pietaeta; for (int ix = 0; ix < nx; ix++) { for (int iy = 0; iy < ny; iy++) { - int idx = iy + ix*ny; + int idx = iy + ix * ny; std::getline(profile, dummy); std::stringstream ss(dummy); - ss >> dummy1 >> dummy2 >> dummy3 - >> density >> utau >> ux >> uy >> ueta - >> pitautau >> pitaux >> pitauy >> pitaueta - >> pixx >> pixy >> pixeta >> piyy >> piyeta >> pietaeta; - ueta = ueta*tau0; - temp_profile_ed [idx] = density*DATA.sFactor/hbarc; // 1/fm^4 - temp_profile_ux [idx] = ux; - temp_profile_uy [idx] = uy; - temp_profile_ueta [idx] = ueta; - temp_profile_utau [idx] = sqrt(1. + ux*ux + uy*uy + ueta*ueta); + ss >> dummy1 >> dummy2 >> dummy3 >> density >> utau >> ux >> uy + >> ueta >> pitautau >> pitaux >> pitauy >> pitaueta >> pixx + >> pixy >> pixeta >> piyy >> piyeta >> pietaeta; + ueta = ueta * tau0; + temp_profile_ed[idx] = density * DATA.sFactor / hbarc; // 1/fm^4 + temp_profile_ux[idx] = ux; + temp_profile_uy[idx] = uy; + temp_profile_ueta[idx] = ueta; + temp_profile_utau[idx] = sqrt(1. + ux * ux + uy * uy + ueta * ueta); // no hbarc factor for the viscous components // they are already in 1/fm^4 from the IP-Glasma output - double visFactor = DATA.sFactor*DATA.preEqVisFactor; - temp_profile_pixx [idx] = pixx*visFactor; - temp_profile_pixy [idx] = pixy*visFactor; - temp_profile_pixeta[idx] = pixeta*tau0*visFactor; - temp_profile_piyy [idx] = piyy*visFactor; - temp_profile_piyeta[idx] = piyeta*tau0*visFactor; + double visFactor = DATA.sFactor * DATA.preEqVisFactor; + temp_profile_pixx[idx] = pixx * visFactor; + temp_profile_pixy[idx] = pixy * visFactor; + temp_profile_pixeta[idx] = pixeta * tau0 * visFactor; + temp_profile_piyy[idx] = piyy * visFactor; + temp_profile_piyeta[idx] = piyeta * tau0 * visFactor; utau = temp_profile_utau[idx]; - temp_profile_pietaeta[idx] = ( - (2.*( ux*uy*temp_profile_pixy[idx] - + ux*ueta*temp_profile_pixeta[idx] - + uy*ueta*temp_profile_piyeta[idx]) - - (utau*utau - ux*ux)*temp_profile_pixx[idx] - - (utau*utau - uy*uy)*temp_profile_piyy[idx]) - /(utau*utau - ueta*ueta)); - temp_profile_pitaux [idx] = (1./utau - *( temp_profile_pixx[idx]*ux - + temp_profile_pixy[idx]*uy - + temp_profile_pixeta[idx]*ueta)); - temp_profile_pitauy [idx] = (1./utau - *( temp_profile_pixy[idx]*ux - + temp_profile_piyy[idx]*uy - + temp_profile_piyeta[idx]*ueta)); - temp_profile_pitaueta[idx] = (1./utau - *( temp_profile_pixeta[idx]*ux - + temp_profile_piyeta[idx]*uy - + temp_profile_pietaeta[idx]*ueta)); - temp_profile_pitautau[idx] = (1./utau - *( temp_profile_pitaux[idx]*ux - + temp_profile_pitauy[idx]*uy - + temp_profile_pitaueta[idx]*ueta)); + temp_profile_pietaeta[idx] = + ((2. + * (ux * uy * temp_profile_pixy[idx] + + ux * ueta * temp_profile_pixeta[idx] + + uy * ueta * temp_profile_piyeta[idx]) + - (utau * utau - ux * ux) * temp_profile_pixx[idx] + - (utau * utau - uy * uy) * temp_profile_piyy[idx]) + / (utau * utau - ueta * ueta)); + temp_profile_pitaux[idx] = + (1. / utau + * (temp_profile_pixx[idx] * ux + temp_profile_pixy[idx] * uy + + temp_profile_pixeta[idx] * ueta)); + temp_profile_pitauy[idx] = + (1. / utau + * (temp_profile_pixy[idx] * ux + temp_profile_piyy[idx] * uy + + temp_profile_piyeta[idx] * ueta)); + temp_profile_pitaueta[idx] = + (1. / utau + * (temp_profile_pixeta[idx] * ux + + temp_profile_piyeta[idx] * uy + + temp_profile_pietaeta[idx] * ueta)); + temp_profile_pitautau[idx] = + (1. / utau + * (temp_profile_pitaux[idx] * ux + + temp_profile_pitauy[idx] * uy + + temp_profile_pitaueta[idx] * ueta)); if (ix == 0 && iy == 0) { - DATA.x_size = -dummy2*2; - DATA.y_size = -dummy3*2; + DATA.x_size = -dummy2 * 2; + DATA.y_size = -dummy3 * 2; if (omp_get_thread_num() == 0) { music_message << "eta_size=" << DATA.eta_size << ", x_size=" << DATA.x_size @@ -663,15 +657,15 @@ void Init::initial_IPGlasma_XY_with_pi(int ieta, Fields &arenaFieldsPrev, } profile.close(); - double eta = (DATA.delta_eta)*(ieta) - (DATA.eta_size)/2.0; - double eta_envelop_ed = eta_profile_plateau(eta, DATA.eta_flat/2.0, - DATA.eta_fall_off); + double eta = (DATA.delta_eta) * (ieta) - (DATA.eta_size) / 2.0; + double eta_envelop_ed = + eta_profile_plateau(eta, DATA.eta_flat / 2.0, DATA.eta_fall_off); for (int ix = 0; ix < nx; ix++) { - for (int iy = 0; iy< ny; iy++) { - int idx = iy + ix*ny; + for (int iy = 0; iy < ny; iy++) { + int idx = iy + ix * ny; const double rhob = 0.0; - double epsilon = std::max(Util::small_eps, - temp_profile_ed[idx]*eta_envelop_ed); + double epsilon = std::max( + Util::small_eps, temp_profile_ed[idx] * eta_envelop_ed); int Fidx = arenaFieldsCurr.getFieldIdx(ix, iy, ieta); arenaFieldsCurr.e_[Fidx] = epsilon; @@ -705,8 +699,8 @@ void Init::initial_IPGlasma_XY_with_pi(int ieta, Fields &arenaFieldsPrev, if (DATA.Initial_profile == 9) { double pressure = eos.get_pressure(epsilon, rhob); - arenaFieldsCurr.piBulk_[Fidx] = ( - (epsilon/3. - pressure)*DATA.preEqVisFactor); + arenaFieldsCurr.piBulk_[Fidx] = + ((epsilon / 3. - pressure) * DATA.preEqVisFactor); } } @@ -715,17 +709,16 @@ void Init::initial_IPGlasma_XY_with_pi(int ieta, Fields &arenaFieldsPrev, } for (int i = 0; i < 10; i++) { - arenaFieldsPrev.Wmunu_[i][Fidx] = ( - arenaFieldsCurr.Wmunu_[i][Fidx]); + arenaFieldsPrev.Wmunu_[i][Fidx] = + (arenaFieldsCurr.Wmunu_[i][Fidx]); } arenaFieldsPrev.piBulk_[Fidx] = arenaFieldsCurr.piBulk_[Fidx]; } } } - -void Init::initial_MCGlb_with_rhob(Fields &arenaFieldsPrev, - Fields &arenaFieldsCurr) { +void Init::initial_MCGlb_with_rhob( + Fields &arenaFieldsPrev, Fields &arenaFieldsCurr) { // first load in the transverse profile ifstream profile_TA(DATA.initName_TA.c_str()); ifstream profile_TB(DATA.initName_TB.c_str()); @@ -745,8 +738,8 @@ void Init::initial_MCGlb_with_rhob(Fields &arenaFieldsPrev, } profile_TA.close(); profile_TB.close(); - N_B *= DATA.delta_x*DATA.delta_y; - double total_energy = DATA.ecm/2.*N_B; + N_B *= DATA.delta_x * DATA.delta_y; + double total_energy = DATA.ecm / 2. * N_B; music_message << "sqrt{s} = " << DATA.ecm << " GeV, " << "beam rapidity = " << DATA.beam_rapidity << ", " << "total energy = " << total_energy << " GeV, " @@ -754,65 +747,69 @@ void Init::initial_MCGlb_with_rhob(Fields &arenaFieldsPrev, music_message.flush("info"); double T_tau_t = 0.0; - #pragma omp parallel for reduction(+: T_tau_t) +#pragma omp parallel for reduction(+ : T_tau_t) for (int ieta = 0; ieta < neta; ieta++) { - double eta = (DATA.delta_eta)*ieta - (DATA.eta_size)/2.0; + double eta = (DATA.delta_eta) * ieta - (DATA.eta_size) / 2.0; if (DATA.boost_invariant) { eta = 0.0; } - double eta_rhob_left = eta_rhob_left_factor(eta); + double eta_rhob_left = eta_rhob_left_factor(eta); double eta_rhob_right = eta_rhob_right_factor(eta); for (int ix = 0; ix < nx; ix++) { - for (int iy = 0; iy< ny; iy++) { + for (int iy = 0; iy < ny; iy++) { double rhob = 0.0; double epsilon = 0.0; if (DATA.turn_on_rhob == 1) { - rhob = ( temp_profile_TA[ix][iy]*eta_rhob_right - + temp_profile_TB[ix][iy]*eta_rhob_left); + rhob = + (temp_profile_TA[ix][iy] * eta_rhob_right + + temp_profile_TB[ix][iy] * eta_rhob_left); } else { rhob = 0.0; } if (DATA.Initial_profile == 11) { - const double eta_0 = DATA.eta_flat/2.; + const double eta_0 = DATA.eta_flat / 2.; const double sigma_eta = DATA.eta_fall_off; - const double E_norm = energy_eta_profile_normalisation( - 0.0, eta_0, sigma_eta); - const double Pz_norm = Pz_eta_profile_normalisation( - eta_0, sigma_eta); - const double norm_even = ( - 1./(DATA.tau0*E_norm) - *Util::m_N*cosh(DATA.beam_rapidity)); - const double norm_odd = ( - DATA.beam_rapidity/(DATA.tau0*Pz_norm) - *Util::m_N*sinh(DATA.beam_rapidity)); - double eta_envelop = eta_profile_plateau( - eta, eta_0, sigma_eta); - epsilon = ( - (( (temp_profile_TA[ix][iy] + temp_profile_TB[ix][iy]) - *norm_even - + (temp_profile_TA[ix][iy] - temp_profile_TB[ix][iy]) - *norm_odd*eta/DATA.beam_rapidity)*eta_envelop) - /Util::hbarc); + const double E_norm = + energy_eta_profile_normalisation(0.0, eta_0, sigma_eta); + const double Pz_norm = + Pz_eta_profile_normalisation(eta_0, sigma_eta); + const double norm_even = + (1. / (DATA.tau0 * E_norm) * Util::m_N + * cosh(DATA.beam_rapidity)); + const double norm_odd = + (DATA.beam_rapidity / (DATA.tau0 * Pz_norm) * Util::m_N + * sinh(DATA.beam_rapidity)); + double eta_envelop = + eta_profile_plateau(eta, eta_0, sigma_eta); + epsilon = + ((((temp_profile_TA[ix][iy] + temp_profile_TB[ix][iy]) + * norm_even + + (temp_profile_TA[ix][iy] - temp_profile_TB[ix][iy]) + * norm_odd * eta / DATA.beam_rapidity) + * eta_envelop) + / Util::hbarc); } else if (DATA.Initial_profile == 111) { double y_CM = atanh( (temp_profile_TA[ix][iy] - temp_profile_TB[ix][iy]) - /(temp_profile_TA[ix][iy] + temp_profile_TB[ix][iy] - + Util::small_eps) - *tanh(DATA.beam_rapidity)); + / (temp_profile_TA[ix][iy] + temp_profile_TB[ix][iy] + + Util::small_eps) + * tanh(DATA.beam_rapidity)); // local energy density [1/fm] - double E_lrf = ( - (temp_profile_TA[ix][iy] + temp_profile_TB[ix][iy]) - *Util::m_N*cosh(DATA.beam_rapidity)/Util::hbarc); - double eta0 = std::min(DATA.eta_flat/2.0, - std::abs(DATA.beam_rapidity - y_CM)); + double E_lrf = + ((temp_profile_TA[ix][iy] + temp_profile_TB[ix][iy]) + * Util::m_N * cosh(DATA.beam_rapidity) / Util::hbarc); + double eta0 = std::min( + DATA.eta_flat / 2.0, + std::abs(DATA.beam_rapidity - y_CM)); double eta_envelop = eta_profile_plateau( - eta - y_CM, eta0, DATA.eta_fall_off); - double E_norm = ( - DATA.tau0*energy_eta_profile_normalisation( - y_CM, eta0, DATA.eta_fall_off)); - epsilon = E_lrf*eta_envelop/E_norm; + eta - y_CM, eta0, DATA.eta_fall_off); + double E_norm = + (DATA.tau0 + * energy_eta_profile_normalisation( + y_CM, eta0, DATA.eta_fall_off)); + epsilon = E_lrf * eta_envelop / E_norm; } epsilon = std::max(Util::small_eps, epsilon); @@ -820,12 +817,13 @@ void Init::initial_MCGlb_with_rhob(Fields &arenaFieldsPrev, arenaFieldsCurr.e_[idx] = epsilon; arenaFieldsCurr.rhob_[idx] = rhob; - T_tau_t += epsilon*cosh(eta); + T_tau_t += epsilon * cosh(eta); } } } - T_tau_t *= DATA.tau0*DATA.delta_eta*DATA.delta_x*DATA.delta_y*Util::hbarc; - double norm = total_energy/T_tau_t; + T_tau_t *= + DATA.tau0 * DATA.delta_eta * DATA.delta_x * DATA.delta_y * Util::hbarc; + double norm = total_energy / T_tau_t; music_message << "energy norm = " << norm; music_message.flush("info"); @@ -833,9 +831,8 @@ void Init::initial_MCGlb_with_rhob(Fields &arenaFieldsPrev, arenaFieldsPrev.rhob_ = arenaFieldsCurr.rhob_; } - -void Init::initial_with_zero_XY(int ieta, Fields &arenaFieldsPrev, - Fields &arenaFieldsCurr) { +void Init::initial_with_zero_XY( + int ieta, Fields &arenaFieldsPrev, Fields &arenaFieldsCurr) { const int nx = arenaFieldsCurr.nX(); const int ny = arenaFieldsCurr.nY(); for (int ix = 0; ix < nx; ix++) { @@ -851,9 +848,8 @@ void Init::initial_with_zero_XY(int ieta, Fields &arenaFieldsPrev, } } - -void Init::initial_UMN_with_rhob(Fields &arenaFieldsPrev, - Fields &arenaFieldsCurr) { +void Init::initial_UMN_with_rhob( + Fields &arenaFieldsPrev, Fields &arenaFieldsCurr) { // first load in the transverse profile ifstream profile(DATA.initName.c_str()); @@ -865,18 +861,18 @@ void Init::initial_UMN_with_rhob(Fields &arenaFieldsPrev, std::string dummy_s; std::getline(profile, dummy_s); - const int nx = arenaFieldsCurr.nX(); - const int ny = arenaFieldsCurr.nY(); + const int nx = arenaFieldsCurr.nX(); + const int ny = arenaFieldsCurr.nY(); const int neta = arenaFieldsCurr.nEta(); double dummy; double ed_local, rhob_local; for (int ieta = 0; ieta < neta; ieta++) { for (int ix = 0; ix < nx; ix++) { - for (int iy = 0; iy< ny; iy++) { + for (int iy = 0; iy < ny; iy++) { profile >> dummy >> dummy >> dummy >> rhob_local >> ed_local; - double rhob = rhob_local; - double epsilon = ed_local*DATA.sFactor/hbarc; // 1/fm^4 + double rhob = rhob_local; + double epsilon = ed_local * DATA.sFactor / hbarc; // 1/fm^4 epsilon = std::max(Util::small_eps, epsilon); @@ -892,33 +888,33 @@ void Init::initial_UMN_with_rhob(Fields &arenaFieldsPrev, profile.close(); } - -void Init::initial_AMPT_XY(int ieta, Fields &arenaFieldsPrev, - Fields &arenaFieldsCurr) { +void Init::initial_AMPT_XY( + int ieta, Fields &arenaFieldsPrev, Fields &arenaFieldsCurr) { double u[4] = {1.0, 0.0, 0.0, 0.0}; EnergyFlowVec j_mu = {0.0, 0.0, 0.0, 0.0}; - double eta = (DATA.delta_eta)*ieta - (DATA.eta_size)/2.0; + double eta = (DATA.delta_eta) * ieta - (DATA.eta_size) / 2.0; double tau0 = DATA.tau0; const int nx = arenaFieldsCurr.nX(); const int ny = arenaFieldsCurr.nY(); for (int ix = 0; ix < nx; ix++) { - double x_local = - DATA.x_size/2. + ix*DATA.delta_x; + double x_local = -DATA.x_size / 2. + ix * DATA.delta_x; for (int iy = 0; iy < ny; iy++) { - double y_local = - DATA.y_size/2. + iy*DATA.delta_y; + double y_local = -DATA.y_size / 2. + iy * DATA.delta_y; double rhob = 0.0; double epsilon = 0.0; if (DATA.turn_on_rhob == 1) { - rhob = hydro_source_terms_ptr.lock()->get_hydro_rhob_source_before_tau( - tau0, x_local, y_local, eta); + rhob = hydro_source_terms_ptr.lock() + ->get_hydro_rhob_source_before_tau( + tau0, x_local, y_local, eta); } else { rhob = 0.0; } hydro_source_terms_ptr.lock()->get_hydro_energy_source_before_tau( - tau0, x_local, y_local, eta, j_mu); + tau0, x_local, y_local, eta, j_mu); - epsilon = j_mu[0]; // 1/fm^4 + epsilon = j_mu[0]; // 1/fm^4 epsilon = std::max(Util::small_eps, epsilon); @@ -935,50 +931,46 @@ void Init::initial_AMPT_XY(int ieta, Fields &arenaFieldsPrev, } } - void Init::get_jetscape_preequilibrium_vectors( - vector e_in, vector P_in, - vector u_tau_in, vector u_x_in, - vector u_y_in, vector u_eta_in, - vector pi_00_in, vector pi_01_in, - vector pi_02_in, vector pi_03_in, - vector pi_11_in, vector pi_12_in, - vector pi_13_in, vector pi_22_in, - vector pi_23_in, vector pi_33_in, - vector Bulk_pi_in) { + vector e_in, vector P_in, vector u_tau_in, + vector u_x_in, vector u_y_in, vector u_eta_in, + vector pi_00_in, vector pi_01_in, vector pi_02_in, + vector pi_03_in, vector pi_11_in, vector pi_12_in, + vector pi_13_in, vector pi_22_in, vector pi_23_in, + vector pi_33_in, vector Bulk_pi_in) { jetscape_initial_energy_density = e_in; - jetscape_initial_pressure = P_in; - jetscape_initial_u_tau = u_tau_in; - jetscape_initial_u_x = u_x_in; - jetscape_initial_u_y = u_y_in; - jetscape_initial_u_eta = u_eta_in; - jetscape_initial_pi_00 = pi_00_in; - jetscape_initial_pi_01 = pi_01_in; - jetscape_initial_pi_02 = pi_02_in; - jetscape_initial_pi_03 = pi_03_in; - jetscape_initial_pi_11 = pi_11_in; - jetscape_initial_pi_12 = pi_12_in; - jetscape_initial_pi_13 = pi_13_in; - jetscape_initial_pi_22 = pi_22_in; - jetscape_initial_pi_23 = pi_23_in; - jetscape_initial_pi_33 = pi_33_in; - jetscape_initial_bulk_pi = Bulk_pi_in; + jetscape_initial_pressure = P_in; + jetscape_initial_u_tau = u_tau_in; + jetscape_initial_u_x = u_x_in; + jetscape_initial_u_y = u_y_in; + jetscape_initial_u_eta = u_eta_in; + jetscape_initial_pi_00 = pi_00_in; + jetscape_initial_pi_01 = pi_01_in; + jetscape_initial_pi_02 = pi_02_in; + jetscape_initial_pi_03 = pi_03_in; + jetscape_initial_pi_11 = pi_11_in; + jetscape_initial_pi_12 = pi_12_in; + jetscape_initial_pi_13 = pi_13_in; + jetscape_initial_pi_22 = pi_22_in; + jetscape_initial_pi_23 = pi_23_in; + jetscape_initial_pi_33 = pi_33_in; + jetscape_initial_bulk_pi = Bulk_pi_in; } - -void Init::initial_with_jetscape(int ieta, Fields &arenaFieldsPrev, - Fields &arenaFieldsCurr) { +void Init::initial_with_jetscape( + int ieta, Fields &arenaFieldsPrev, Fields &arenaFieldsCurr) { const int nx = arenaFieldsCurr.nX(); const int ny = arenaFieldsCurr.nY(); const int neta = arenaFieldsCurr.nEta(); for (int ix = 0; ix < nx; ix++) { - for (int iy = 0; iy< ny; iy++) { + for (int iy = 0; iy < ny; iy++) { const double rhob = 0.0; double epsilon = 0.0; - const int idx = (ny*neta)*ix + neta*iy + ieta; - epsilon = (jetscape_initial_energy_density[idx] - *DATA.sFactor/hbarc); // 1/fm^4 + const int idx = (ny * neta) * ix + neta * iy + ieta; + epsilon = + (jetscape_initial_energy_density[idx] * DATA.sFactor + / hbarc); // 1/fm^4 epsilon = std::max(Util::small_eps, epsilon); double pressure = eos.get_pressure(epsilon, rhob); @@ -989,21 +981,35 @@ void Init::initial_with_jetscape(int ieta, Fields &arenaFieldsPrev, arenaFieldsCurr.u_[0][Fidx] = jetscape_initial_u_tau[idx]; arenaFieldsCurr.u_[1][Fidx] = jetscape_initial_u_x[idx]; arenaFieldsCurr.u_[2][Fidx] = jetscape_initial_u_y[idx]; - arenaFieldsCurr.u_[3][Fidx] = DATA.tau0*jetscape_initial_u_eta[idx]; - arenaFieldsCurr.piBulk_[Fidx] = (DATA.sFactor/hbarc*( - jetscape_initial_pressure[idx] + jetscape_initial_bulk_pi[idx]) - - pressure); - - arenaFieldsCurr.Wmunu_[0][Fidx] = DATA.sFactor*jetscape_initial_pi_00[idx]/hbarc; - arenaFieldsCurr.Wmunu_[1][Fidx] = DATA.sFactor*jetscape_initial_pi_01[idx]/hbarc; - arenaFieldsCurr.Wmunu_[2][Fidx] = DATA.sFactor*jetscape_initial_pi_02[idx]/hbarc; - arenaFieldsCurr.Wmunu_[3][Fidx] = DATA.sFactor*jetscape_initial_pi_03[idx]/hbarc*DATA.tau0; - arenaFieldsCurr.Wmunu_[4][Fidx] = DATA.sFactor*jetscape_initial_pi_11[idx]/hbarc; - arenaFieldsCurr.Wmunu_[5][Fidx] = DATA.sFactor*jetscape_initial_pi_12[idx]/hbarc; - arenaFieldsCurr.Wmunu_[6][Fidx] = DATA.sFactor*jetscape_initial_pi_13[idx]/hbarc*DATA.tau0; - arenaFieldsCurr.Wmunu_[7][Fidx] = DATA.sFactor*jetscape_initial_pi_22[idx]/hbarc; - arenaFieldsCurr.Wmunu_[8][Fidx] = DATA.sFactor*jetscape_initial_pi_23[idx]/hbarc*DATA.tau0; - arenaFieldsCurr.Wmunu_[9][Fidx] = DATA.sFactor*jetscape_initial_pi_33[idx]/hbarc*DATA.tau0*DATA.tau0; + arenaFieldsCurr.u_[3][Fidx] = + DATA.tau0 * jetscape_initial_u_eta[idx]; + arenaFieldsCurr.piBulk_[Fidx] = + (DATA.sFactor / hbarc + * (jetscape_initial_pressure[idx] + + jetscape_initial_bulk_pi[idx]) + - pressure); + + arenaFieldsCurr.Wmunu_[0][Fidx] = + DATA.sFactor * jetscape_initial_pi_00[idx] / hbarc; + arenaFieldsCurr.Wmunu_[1][Fidx] = + DATA.sFactor * jetscape_initial_pi_01[idx] / hbarc; + arenaFieldsCurr.Wmunu_[2][Fidx] = + DATA.sFactor * jetscape_initial_pi_02[idx] / hbarc; + arenaFieldsCurr.Wmunu_[3][Fidx] = + DATA.sFactor * jetscape_initial_pi_03[idx] / hbarc * DATA.tau0; + arenaFieldsCurr.Wmunu_[4][Fidx] = + DATA.sFactor * jetscape_initial_pi_11[idx] / hbarc; + arenaFieldsCurr.Wmunu_[5][Fidx] = + DATA.sFactor * jetscape_initial_pi_12[idx] / hbarc; + arenaFieldsCurr.Wmunu_[6][Fidx] = + DATA.sFactor * jetscape_initial_pi_13[idx] / hbarc * DATA.tau0; + arenaFieldsCurr.Wmunu_[7][Fidx] = + DATA.sFactor * jetscape_initial_pi_22[idx] / hbarc; + arenaFieldsCurr.Wmunu_[8][Fidx] = + DATA.sFactor * jetscape_initial_pi_23[idx] / hbarc * DATA.tau0; + arenaFieldsCurr.Wmunu_[9][Fidx] = DATA.sFactor + * jetscape_initial_pi_33[idx] + / hbarc * DATA.tau0 * DATA.tau0; arenaFieldsPrev.e_[Fidx] = arenaFieldsCurr.e_[Fidx]; arenaFieldsPrev.rhob_[Fidx] = arenaFieldsPrev.rhob_[Fidx]; @@ -1011,15 +1017,14 @@ void Init::initial_with_jetscape(int ieta, Fields &arenaFieldsPrev, arenaFieldsPrev.u_[i][Fidx] = arenaFieldsCurr.u_[i][Fidx]; } for (int i = 0; i < 10; i++) { - arenaFieldsPrev.Wmunu_[i][Fidx] = ( - arenaFieldsCurr.Wmunu_[i][Fidx]); + arenaFieldsPrev.Wmunu_[i][Fidx] = + (arenaFieldsCurr.Wmunu_[i][Fidx]); } arenaFieldsPrev.piBulk_[Fidx] = arenaFieldsCurr.piBulk_[Fidx]; } } } - void Init::clean_up_jetscape_arrays() { // clean up jetscape_initial_energy_density.clear(); @@ -1041,75 +1046,71 @@ void Init::clean_up_jetscape_arrays() { jetscape_initial_bulk_pi.clear(); } - -double Init::eta_profile_plateau(const double eta, const double eta_0, - const double sigma_eta) const { +double Init::eta_profile_plateau( + const double eta, const double eta_0, const double sigma_eta) const { // this function return the eta envelope profile for energy density // Hirano's plateau + Gaussian fall-off double res; - double exparg1 = (std::abs(eta) - eta_0)/sigma_eta; - double exparg = exparg1*exparg1/2.0; - res = exp(-exparg*Util::theta(exparg1)); + double exparg1 = (std::abs(eta) - eta_0) / sigma_eta; + double exparg = exparg1 * exparg1 / 2.0; + res = exp(-exparg * Util::theta(exparg1)); return res; } - double Init::energy_eta_profile_normalisation( - const double y_CM, const double eta_0, const double sigma_eta) const { + const double y_CM, const double eta_0, const double sigma_eta) const { // this function returns the normalization of the eta envelope profile // for energy density // \int deta eta_profile_plateau(eta - y_CM, eta_0, sigma_eta)*cosh(eta) - double f1 = ( exp( eta_0)*erfc(-sqrt(0.5)*sigma_eta) - + exp(-eta_0)*erfc( sqrt(0.5)*sigma_eta)); - double f2 = sqrt(M_PI/2.)*sigma_eta*exp(sigma_eta*sigma_eta/2.); + double f1 = + (exp(eta_0) * erfc(-sqrt(0.5) * sigma_eta) + + exp(-eta_0) * erfc(sqrt(0.5) * sigma_eta)); + double f2 = sqrt(M_PI / 2.) * sigma_eta * exp(sigma_eta * sigma_eta / 2.); double f3 = sinh(eta_0 + y_CM) - sinh(-eta_0 + y_CM); - double norm = cosh(y_CM)*f2*f1 + f3; - return(norm); + double norm = cosh(y_CM) * f2 * f1 + f3; + return (norm); } - double Init::Pz_eta_profile_normalisation( - const double eta_0, const double sigma_eta) const { + const double eta_0, const double sigma_eta) const { // this function returns the normalization of the eta envelope profile // for longitudinal momentum // \int deta eta_profile_plateau(eta, eta_0, sigma_eta)*eta*sinh(eta) - const double sigma_sq = sigma_eta*sigma_eta; - double f1 = ( exp( eta_0)*(eta_0 + sigma_sq)*erfc(-sqrt(0.5)*sigma_eta) - - exp(-eta_0)*(eta_0 - sigma_sq)*erfc( sqrt(0.5)*sigma_eta)); - double f2 = sqrt(M_PI/2.)*sigma_eta*exp(sigma_sq/2.)/2.; - double f3 = sigma_sq*sinh(eta_0); - double f4 = 2.*eta_0*cosh(eta_0) - 2.*sinh(eta_0); - double norm = 2.*(f2*f1 + f3) + f4; - return(norm); + const double sigma_sq = sigma_eta * sigma_eta; + double f1 = + (exp(eta_0) * (eta_0 + sigma_sq) * erfc(-sqrt(0.5) * sigma_eta) + - exp(-eta_0) * (eta_0 - sigma_sq) * erfc(sqrt(0.5) * sigma_eta)); + double f2 = sqrt(M_PI / 2.) * sigma_eta * exp(sigma_sq / 2.) / 2.; + double f3 = sigma_sq * sinh(eta_0); + double f4 = 2. * eta_0 * cosh(eta_0) - 2. * sinh(eta_0); + double norm = 2. * (f2 * f1 + f3) + f4; + return (norm); } - double Init::eta_profile_left_factor(const double eta) const { // this function return the eta envelope for projectile - double res = eta_profile_plateau( - eta, DATA.eta_flat/2.0, DATA.eta_fall_off); + double res = + eta_profile_plateau(eta, DATA.eta_flat / 2.0, DATA.eta_fall_off); if (std::abs(eta) < DATA.beam_rapidity) { - res = (1. - eta/DATA.beam_rapidity)*res; + res = (1. - eta / DATA.beam_rapidity) * res; } else { res = 0.0; } - return(res); + return (res); } - double Init::eta_profile_right_factor(const double eta) const { // this function return the eta envelope for target - double res = eta_profile_plateau( - eta, DATA.eta_flat/2.0, DATA.eta_fall_off); + double res = + eta_profile_plateau(eta, DATA.eta_flat / 2.0, DATA.eta_fall_off); if (std::abs(eta) < DATA.beam_rapidity) { - res = (1. + eta/DATA.beam_rapidity)*res; + res = (1. + eta / DATA.beam_rapidity) * res; } else { res = 0.0; } - return(res); + return (res); } - double Init::eta_rhob_profile_normalisation(const double eta) const { // this function return the eta envelope profile for net baryon density double res = 0.0; @@ -1118,65 +1119,68 @@ double Init::eta_rhob_profile_normalisation(const double eta) const { double tau0 = DATA.tau0; if (profile_flag == 1) { const double eta_width = DATA.eta_rhob_width; - const double norm = 1./(2.*sqrt(2*M_PI)*eta_width*tau0); - const double exparg1 = (eta - eta_0)/eta_width; - const double exparg2 = (eta + eta_0)/eta_width; - res = norm*(exp(-exparg1*exparg1/2.0) + exp(-exparg2*exparg2/2.0)); + const double norm = 1. / (2. * sqrt(2 * M_PI) * eta_width * tau0); + const double exparg1 = (eta - eta_0) / eta_width; + const double exparg2 = (eta + eta_0) / eta_width; + res = norm + * (exp(-exparg1 * exparg1 / 2.0) + exp(-exparg2 * exparg2 / 2.0)); } else if (profile_flag == 2) { - double eta_abs = fabs(eta); + double eta_abs = fabs(eta); double delta_eta_1 = DATA.eta_rhob_width_1; double delta_eta_2 = DATA.eta_rhob_width_2; - double A = DATA.eta_rhob_plateau_height; - double exparg1 = (eta_abs - eta_0)/delta_eta_1; - double exparg2 = (eta_abs - eta_0)/delta_eta_2; + double A = DATA.eta_rhob_plateau_height; + double exparg1 = (eta_abs - eta_0) / delta_eta_1; + double exparg2 = (eta_abs - eta_0) / delta_eta_2; double theta; - double norm = 1./(tau0*(sqrt(2.*M_PI)*delta_eta_1 - + (1. - A)*sqrt(2.*M_PI)*delta_eta_2 + 2.*A*eta_0)); + double norm = + 1. + / (tau0 + * (sqrt(2. * M_PI) * delta_eta_1 + + (1. - A) * sqrt(2. * M_PI) * delta_eta_2 + 2. * A * eta_0)); if (eta_abs > eta_0) theta = 1.0; else theta = 0.0; - res = norm*(theta*exp(-exparg1*exparg1/2.) - + (1. - theta)*(A + (1. - A)*exp(-exparg2*exparg2/2.))); + res = + norm + * (theta * exp(-exparg1 * exparg1 / 2.) + + (1. - theta) * (A + (1. - A) * exp(-exparg2 * exparg2 / 2.))); } return res; } - double Init::eta_rhob_left_factor(const double eta) const { - double eta_0 = -std::abs(DATA.eta_rhob_0); - double tau0 = DATA.tau0; + double eta_0 = -std::abs(DATA.eta_rhob_0); + double tau0 = DATA.tau0; double delta_eta_1 = DATA.eta_rhob_width_1; double delta_eta_2 = DATA.eta_rhob_width_2; - double norm = 2./(sqrt(M_PI)*tau0*(delta_eta_1 + delta_eta_2)); - double exp_arg = 0.0; + double norm = 2. / (sqrt(M_PI) * tau0 * (delta_eta_1 + delta_eta_2)); + double exp_arg = 0.0; if (eta < eta_0) { - exp_arg = (eta - eta_0)/delta_eta_1; + exp_arg = (eta - eta_0) / delta_eta_1; } else { - exp_arg = (eta - eta_0)/delta_eta_2; + exp_arg = (eta - eta_0) / delta_eta_2; } - double res = norm*exp(-exp_arg*exp_arg); - return(res); + double res = norm * exp(-exp_arg * exp_arg); + return (res); } - double Init::eta_rhob_right_factor(const double eta) const { - double eta_0 = std::abs(DATA.eta_rhob_0); - double tau0 = DATA.tau0; + double eta_0 = std::abs(DATA.eta_rhob_0); + double tau0 = DATA.tau0; double delta_eta_1 = DATA.eta_rhob_width_1; double delta_eta_2 = DATA.eta_rhob_width_2; - double norm = 2./(sqrt(M_PI)*tau0*(delta_eta_1 + delta_eta_2)); - double exp_arg = 0.0; + double norm = 2. / (sqrt(M_PI) * tau0 * (delta_eta_1 + delta_eta_2)); + double exp_arg = 0.0; if (eta < eta_0) { - exp_arg = (eta - eta_0)/delta_eta_2; + exp_arg = (eta - eta_0) / delta_eta_2; } else { - exp_arg = (eta - eta_0)/delta_eta_1; + exp_arg = (eta - eta_0) / delta_eta_1; } - double res = norm*exp(-exp_arg*exp_arg); - return(res); + double res = norm * exp(-exp_arg * exp_arg); + return (res); } - void Init::output_initial_density_profiles(Fields &arena) { // this function outputs the 3d initial energy density profile // and net baryon density profile (if turn_on_rhob == 1) @@ -1184,19 +1188,18 @@ void Init::output_initial_density_profiles(Fields &arena) { music_message.info("output initial density profiles into a file... "); std::ofstream of("check_initial_density_profiles.dat"); of << "# x(fm) y(fm) eta ed(GeV/fm^3)"; - if (DATA.turn_on_rhob == 1) - of << " rhob(1/fm^3)"; + if (DATA.turn_on_rhob == 1) of << " rhob(1/fm^3)"; of << std::endl; for (int ieta = 0; ieta < arena.nEta(); ieta++) { - double eta_local = (DATA.delta_eta)*ieta - (DATA.eta_size)/2.0; - for(int ix = 0; ix < arena.nX(); ix++) { - double x_local = -DATA.x_size/2. + ix*DATA.delta_x; - for(int iy = 0; iy < arena.nY(); iy++) { - double y_local = -DATA.y_size/2. + iy*DATA.delta_y; + double eta_local = (DATA.delta_eta) * ieta - (DATA.eta_size) / 2.0; + for (int ix = 0; ix < arena.nX(); ix++) { + double x_local = -DATA.x_size / 2. + ix * DATA.delta_x; + for (int iy = 0; iy < arena.nY(); iy++) { + double y_local = -DATA.y_size / 2. + iy * DATA.delta_y; int fieldIdx = arena.getFieldIdx(ix, iy, ieta); of << std::scientific << std::setw(18) << std::setprecision(8) - << x_local << " " << y_local << " " - << eta_local << " " << arena.e_[fieldIdx]*hbarc; + << x_local << " " << y_local << " " << eta_local << " " + << arena.e_[fieldIdx] * hbarc; if (DATA.turn_on_rhob == 1) { of << " " << arena.rhob_[fieldIdx]; } diff --git a/src/init.h b/src/init.h index 22105132..666c39c1 100644 --- a/src/init.h +++ b/src/init.h @@ -3,19 +3,20 @@ #define SRC_INIT_H_ #include -#include + #include #include +#include -#include "data.h" #include "cell.h" +#include "data.h" #include "eos.h" #include "fields.h" #include "hydro_source_base.h" #include "pretty_ostream.h" class Init { - private: + private: InitData &DATA; const EOS &eos; std::weak_ptr hydro_source_terms_ptr; @@ -40,37 +41,39 @@ class Init { std::vector jetscape_initial_pi_33; std::vector jetscape_initial_bulk_pi; - public: - Init(const EOS &eos, InitData &DATA_in, - std::shared_ptr hydro_source_ptr_in); + public: + Init( + const EOS &eos, InitData &DATA_in, + std::shared_ptr hydro_source_ptr_in); - void InitArena(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, - Fields &arenaFieldsNext); + void InitArena( + Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, + Fields &arenaFieldsNext); void InitTJb(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr); void print_num_of_threads(); - void initial_Gubser_XY(int ieta, Fields &arenaFieldsPrev, - Fields &arenaFieldsCurr); + void initial_Gubser_XY( + int ieta, Fields &arenaFieldsPrev, Fields &arenaFieldsCurr); void initial_1p1D_eta(Fields &arenaFieldsPrev, Fields &arenaFieldsCurr); - void initial_IPGlasma_XY(int ieta, Fields &arenaFieldsPrev, - Fields &arenaFieldsCurr); - void initial_IPGlasma_XY_with_pi(int ieta, Fields &arenaFieldsPrev, - Fields &arenaFieldsCurr); - void initial_with_zero_XY(int ieta, Fields &arenaFieldsPrev, - Fields &arenaFieldsCurr); - void initial_AMPT_XY(int ieta, Fields &arenaFieldsPrev, - Fields &arenaFieldsCurr); - void initial_MCGlb_with_rhob(Fields &arenaFieldsPrev, - Fields &arenaFieldsCurr); - void initial_UMN_with_rhob(Fields &arenaFieldsPrev, - Fields &arenaFieldsCurr); - void initial_with_jetscape(int ieta, Fields &arenaFieldsPrev, - Fields &arenaFieldsCurr); + void initial_IPGlasma_XY( + int ieta, Fields &arenaFieldsPrev, Fields &arenaFieldsCurr); + void initial_IPGlasma_XY_with_pi( + int ieta, Fields &arenaFieldsPrev, Fields &arenaFieldsCurr); + void initial_with_zero_XY( + int ieta, Fields &arenaFieldsPrev, Fields &arenaFieldsCurr); + void initial_AMPT_XY( + int ieta, Fields &arenaFieldsPrev, Fields &arenaFieldsCurr); + void initial_MCGlb_with_rhob( + Fields &arenaFieldsPrev, Fields &arenaFieldsCurr); + void initial_UMN_with_rhob( + Fields &arenaFieldsPrev, Fields &arenaFieldsCurr); + void initial_with_jetscape( + int ieta, Fields &arenaFieldsPrev, Fields &arenaFieldsCurr); void get_jetscape_preequilibrium_vectors( std::vector e_in, std::vector P_in, std::vector u_tau_in, std::vector u_x_in, - std::vector u_y_in, std::vector u_eta_in, + std::vector u_y_in, std::vector u_eta_in, std::vector pi_00_in, std::vector pi_01_in, std::vector pi_02_in, std::vector pi_03_in, std::vector pi_11_in, std::vector pi_12_in, @@ -79,18 +82,18 @@ class Init { std::vector Bulk_pi_in); void clean_up_jetscape_arrays(); - double eta_profile_plateau(const double eta, const double eta_0, - const double sigma_eta) const; + double eta_profile_plateau( + const double eta, const double eta_0, const double sigma_eta) const; double energy_eta_profile_normalisation( const double y_CM, const double eta_0, const double sigma_eta) const; double Pz_eta_profile_normalisation( const double eta_0, const double sigma_eta) const; - double eta_rhob_profile_normalisation (const double eta) const; - double eta_profile_left_factor (const double eta) const; - double eta_profile_right_factor (const double eta) const; - double eta_rhob_left_factor (const double eta) const; - double eta_rhob_right_factor (const double eta) const; - void output_initial_density_profiles (Fields &arena); + double eta_rhob_profile_normalisation(const double eta) const; + double eta_profile_left_factor(const double eta) const; + double eta_profile_right_factor(const double eta) const; + double eta_rhob_left_factor(const double eta) const; + double eta_rhob_right_factor(const double eta) const; + void output_initial_density_profiles(Fields &arena); }; #endif // SRC_INIT_H_ diff --git a/src/int.h b/src/int.h index 13232f03..500165f7 100644 --- a/src/int.h +++ b/src/int.h @@ -1,17 +1,18 @@ -// MUSIC - a 3+1D viscous relativistic hydrodynamic code for heavy ion collisions -// Copyright (C) 2017 Gabriel Denicol, Charles Gale, Sangyong Jeon, Matthew Luzum, Jean-François Paquet, Björn Schenke, Chun Shen +// MUSIC - a 3+1D viscous relativistic hydrodynamic code for heavy ion +// collisions Copyright (C) 2017 Gabriel Denicol, Charles Gale, Sangyong Jeon, +// Matthew Luzum, Jean-François Paquet, Björn Schenke, Chun Shen #ifndef INT_H #define INT_H #include "freeze.h" - - /************************************************************** - * - * gala?x[], gala?w[] - * - * data for Gauss-Laguerre integration, from Abramowitz, es - ***************************************************************/ + +/************************************************************** + * + * gala?x[], gala?w[] + * + * data for Gauss-Laguerre integration, from Abramowitz, es + ***************************************************************/ // static double // gala4x[] = { 0.322547689619, 1.745761101158, // 4.536620296921, 9.395070912301 }; @@ -43,31 +44,31 @@ // 4.52981402998, 5.59725846184, // 7.21299546093, 10.5438374619 }; -//static double -//gala15x[] = { 0.093307812017, 0.492691740302, -// 1.215595412071, 2.269949526204, -// 3.667622721751, 5.425336627414, -// 7.565916226613, 10.120228568019, -// 13.130282482176, 16.654407708330, -// 20.776478899449, 25.623894226729, -// 31.407519169754, 38.530683306486, -// 48.026085572686 }; -//static double -//gala15w[] = { 0.239578170311, 0.560100842793, -// 0.887008262919, 1.22366440215, -// 1.57444872163, 1.94475197653, -// 2.34150205664, 2.77404192683, -// 3.25564334640, 3.80631171423, -// 4.45847775384, 5.27001778443, -// 6.35956346973, 8.03178763212, -// 11.5277721009 }; +// static double +// gala15x[] = { 0.093307812017, 0.492691740302, +// 1.215595412071, 2.269949526204, +// 3.667622721751, 5.425336627414, +// 7.565916226613, 10.120228568019, +// 13.130282482176, 16.654407708330, +// 20.776478899449, 25.623894226729, +// 31.407519169754, 38.530683306486, +// 48.026085572686 }; +// static double +// gala15w[] = { 0.239578170311, 0.560100842793, +// 0.887008262919, 1.22366440215, +// 1.57444872163, 1.94475197653, +// 2.34150205664, 2.77404192683, +// 3.25564334640, 3.80631171423, +// 4.45847775384, 5.27001778443, +// 6.35956346973, 8.03178763212, +// 11.5277721009 }; /************************************************************** -* -* gahe?x[], gahe?w[] -* -* data for Gauss-Hermite integration, from Abramowitz, es -***************************************************************/ + * + * gahe?x[], gahe?w[] + * + * data for Gauss-Hermite integration, from Abramowitz, es + ***************************************************************/ // static double gahep4[] = { 0.524647623275290, 1.650680123885785 }; // static double gahew4[] = { 1.0599644828950, 1.2402258176958 }; // static double gahep8[] = { 0.381186990207322, 1.157193712446780, @@ -82,112 +83,92 @@ // 0.5632178290882, 0.5812472754009, // 0.6097369582560, 0.6557556728761, // 0.7382456222777, 0.9368744928841 }; -//static double gahep20[] = { 0.2453407083009, 0.7374737285454, +// static double gahep20[] = { 0.2453407083009, 0.7374737285454, // 1.2340762153953, 1.7385377121166, // 2.2549740020893, 2.7888060584281, -// 3.3478545673832, 3.9447640401156, +// 3.3478545673832, 3.9447640401156, // 4.6036824495507, 5.3874808900112}; -//static double gahew20[] = { 0.4909215006677, 0.4938433852721, +// static double gahew20[] = { 0.4909215006677, 0.4938433852721, // 0.4999208713363, 0.5096790271175, // 0.5240803509486, 0.5448517423644, // 0.5752624428525, 0.6222786961914, // 0.7043329611769, 0.8985919614532 }; - /**************************************************************** -* -* gaule?x[], gaule?w[] -* -* data for Gauss-Legendre integration, Abramowitz and other, es -*****************************************************************/ + * + * gaule?x[], gaule?w[] + * + * data for Gauss-Legendre integration, Abramowitz and other, es + *****************************************************************/ -static double gaulep4[] = { 0.8611363115, 0.3399810435 }; -static double gaulew4[] = { 0.3478548451, 0.6521451548 }; -static double gaulep8[] = { 0.9602898564, 0.7966664774, - 0.5255324099, 0.1834346424 }; -static double gaulew8[] = { 0.1012285362, 0.2223810344, - 0.3137066458, 0.3626837833 }; -static double gaulep10[] = { 0.1488743389, 0.4333953941, - 0.6794095682, 0.8650633666, - 0.97390652 }; -static double gaulew10[] = { 0.2955242247, 0.2692667193, - 0.2190863625, 0.1494513491, - 0.06667134 }; -static double gaulep12[] = { 0.9815606342, 0.9041172563, - 0.7699026741, 0.5873179542, - 0.3678314989, 0.1252334085 }; -static double gaulew12[] = { 0.0471753363, 0.1069393259, - 0.1600783285, 0.2031674267, - 0.2334925365, 0.2491470458 }; -static double gaulep16[] = { - 0.989400934991650, 0.944575023073233, - 0.865631202387832, 0.755404408355003, - 0.617876244402644, 0.458016777657227, - 0.281603550779259, 0.095012509837637 }; -static double gaulew16[] = { - 0.027152459411754, 0.062253523938648, - 0.095158511682493, 0.124628971255534, - 0.149595988816577, 0.169156519395003, - 0.182603415044924, 0.189450610455069 }; -static double gaulep20[] = { - 0.993128599185094, 0.963971927277913, - 0.912234428251325, 0.839116971822218, - 0.746331906460150, 0.636053680726515, - 0.510867001950827, 0.373706088715419, - 0.227785851141645, 0.076526521133497 }; -static double gaulew20[] = { - 0.017614007139152, 0.040601429800386, - 0.062672048334109, 0.083276741576704, - 0.101930119817240, 0.118194531961518, - 0.131688638449176, 0.142096109318382, - 0.149172986472603, 0.152753387130725 }; -static double gaulep48[] = { - 0.998771007252426118601, 0.993530172266350757548, - 0.984124583722826857745, 0.970591592546247250461, - 0.952987703160430860723, 0.931386690706554333114, - 0.905879136715569672822, 0.876572020274247885906, - 0.843588261624393530711, 0.807066204029442627083, - 0.767159032515740339254, 0.724034130923814654674, - 0.677872379632663905212, 0.628867396776513623995, - 0.577224726083972703818, 0.523160974722233033678, - 0.466902904750958404545, 0.408686481990716729916, - 0.348755886292160738160, 0.287362487355455576736, - 0.224763790394689061225, 0.161222356068891718056, - 0.097004699209462698930, 0.032380170962869362033 }; -static double gaulew48[] = { - 0.003153346052305838633, 0.007327553901276262102, - 0.011477234579234539490, 0.015579315722943848728, - 0.019616160457355527814, 0.023570760839324379141, - 0.027426509708356948200, 0.031167227832798088902, - 0.034777222564770438893, 0.038241351065830706317, - 0.041545082943464749214, 0.044674560856694280419, - 0.047616658492490474826, 0.050359035553854474958, - 0.052890189485193667096, 0.055199503699984162868, - 0.057277292100403215705, 0.059114839698395635746, - 0.060704439165893880053, 0.062039423159892663904, - 0.063114192286254025657, 0.063924238584648186624, - 0.064466164435950082207, 0.064737696812683922503 }; +static double gaulep4[] = {0.8611363115, 0.3399810435}; +static double gaulew4[] = {0.3478548451, 0.6521451548}; +static double gaulep8[] = { + 0.9602898564, 0.7966664774, 0.5255324099, 0.1834346424}; +static double gaulew8[] = { + 0.1012285362, 0.2223810344, 0.3137066458, 0.3626837833}; +static double gaulep10[] = { + 0.1488743389, 0.4333953941, 0.6794095682, 0.8650633666, 0.97390652}; +static double gaulew10[] = { + 0.2955242247, 0.2692667193, 0.2190863625, 0.1494513491, 0.06667134}; +static double gaulep12[] = {0.9815606342, 0.9041172563, 0.7699026741, + 0.5873179542, 0.3678314989, 0.1252334085}; +static double gaulew12[] = {0.0471753363, 0.1069393259, 0.1600783285, + 0.2031674267, 0.2334925365, 0.2491470458}; +static double gaulep16[] = { + 0.989400934991650, 0.944575023073233, 0.865631202387832, 0.755404408355003, + 0.617876244402644, 0.458016777657227, 0.281603550779259, 0.095012509837637}; +static double gaulew16[] = { + 0.027152459411754, 0.062253523938648, 0.095158511682493, 0.124628971255534, + 0.149595988816577, 0.169156519395003, 0.182603415044924, 0.189450610455069}; +static double gaulep20[] = { + 0.993128599185094, 0.963971927277913, 0.912234428251325, 0.839116971822218, + 0.746331906460150, 0.636053680726515, 0.510867001950827, 0.373706088715419, + 0.227785851141645, 0.076526521133497}; +static double gaulew20[] = { + 0.017614007139152, 0.040601429800386, 0.062672048334109, 0.083276741576704, + 0.101930119817240, 0.118194531961518, 0.131688638449176, 0.142096109318382, + 0.149172986472603, 0.152753387130725}; +static double gaulep48[] = { + 0.998771007252426118601, 0.993530172266350757548, 0.984124583722826857745, + 0.970591592546247250461, 0.952987703160430860723, 0.931386690706554333114, + 0.905879136715569672822, 0.876572020274247885906, 0.843588261624393530711, + 0.807066204029442627083, 0.767159032515740339254, 0.724034130923814654674, + 0.677872379632663905212, 0.628867396776513623995, 0.577224726083972703818, + 0.523160974722233033678, 0.466902904750958404545, 0.408686481990716729916, + 0.348755886292160738160, 0.287362487355455576736, 0.224763790394689061225, + 0.161222356068891718056, 0.097004699209462698930, 0.032380170962869362033}; +static double gaulew48[] = { + 0.003153346052305838633, 0.007327553901276262102, 0.011477234579234539490, + 0.015579315722943848728, 0.019616160457355527814, 0.023570760839324379141, + 0.027426509708356948200, 0.031167227832798088902, 0.034777222564770438893, + 0.038241351065830706317, 0.041545082943464749214, 0.044674560856694280419, + 0.047616658492490474826, 0.050359035553854474958, 0.052890189485193667096, + 0.055199503699984162868, 0.057277292100403215705, 0.059114839698395635746, + 0.060704439165893880053, 0.062039423159892663904, 0.063114192286254025657, + 0.063924238584648186624, 0.064466164435950082207, 0.064737696812683922503}; //! This is a class for gaussian integration -class Int{ - - - public: - - double gauss(int n, double (*f)(double, void *), double xlo, double xhi, void *optvec ); - void gausspts(); /* gausspts( int n, double xlo, xhi; double *x, *w ); */ - double gaussn();/* gaussn(int n, ndiv, double (*func)(), +class Int { + public: + double gauss( + int n, double (*f)(double, void *), double xlo, double xhi, + void *optvec); + void gausspts(); /* gausspts( int n, double xlo, xhi; double *x, *w ); */ + double gaussn(); /* gaussn(int n, ndiv, double (*func)(), double xlo, double xhi, double *para ); */ - double gala(); /* gala(int n, double (*func)(), double xlo,invslope,void *optvec);*/ - double gahe(); /* gahe(int n, double (*func)(), double center, width,void *optvec );*/ - double gauche();/* gauche(int n,double (*func)(),double base,pole,void *optvec ); */ - double gaussp(); - double galap(); - double gahep(); - - double testfunc(); - double testgalafunc(); - - double gaussnbyn(); /* not yet tested */ + double gala(); /* gala(int n, double (*func)(), double xlo,invslope,void + *optvec);*/ + double gahe(); /* gahe(int n, double (*func)(), double center, width,void + *optvec );*/ + double gauche(); /* gauche(int n,double (*func)(),double base,pole,void + *optvec ); */ + double gaussp(); + double galap(); + double gahep(); + + double testfunc(); + double testgalafunc(); + double gaussnbyn(); /* not yet tested */ }; #endif diff --git a/src/main.cpp b/src/main.cpp index ab5e9ab6..56234777 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,9 +2,10 @@ // Massively cleaned up and improved by Chun Shen 2015-2016 #include -#include #include + #include +#include #include "music.h" #include "music_logo.h" @@ -13,16 +14,16 @@ // main program int main(int argc, char *argv[]) { std::string input_file; - InitData DATA __attribute__ ((aligned (64))); + InitData DATA __attribute__((aligned(64))); if (argc > 1) - input_file = *(argv+1); + input_file = *(argv + 1); else input_file = ""; MUSIC_LOGO::welcome_message(); - std::cout << "Version: (git branch:" << GIT_BRANCH << ") Commit:" - << GIT_COMMIT_HASH << std::endl; + std::cout << "Version: (git branch:" << GIT_BRANCH + << ") Commit:" << GIT_COMMIT_HASH << std::endl; int ireRunHydroCount = 0; bool bReRunHydro = false; @@ -39,7 +40,7 @@ int main(int argc, char *argv[]) { } if (running_mode == 1 || running_mode == 3 || running_mode == 4 - || running_mode == 13 || running_mode == 14) { + || running_mode == 13 || running_mode == 14) { music_hydro.run_Cooper_Frye(); } @@ -51,6 +52,5 @@ int main(int argc, char *argv[]) { } ireRunHydroCount++; } while (bReRunHydro && ireRunHydroCount < 10); - return(0); -} /* main */ - + return (0); +} /* main */ diff --git a/src/minmod.h b/src/minmod.h index b44b6577..c2628e5d 100644 --- a/src/minmod.h +++ b/src/minmod.h @@ -5,13 +5,13 @@ #include "data.h" #include "iostream" class Minmod { - private: + private: const double theta_flux; - public: + public: Minmod(const InitData &DATA); Minmod(double theta_in); - double get_theta() const {return(theta_flux);} + double get_theta() const { return (theta_flux); } /* double minmod_dx(const double up1, const double u, const double um1) { */ /* const double diffup = (up1 - u)*theta_flux; */ @@ -20,7 +20,8 @@ class Minmod { /* if ( (diffup > 0.0) && (diffdown > 0.0) && (diffmid > 0.0) ) { */ /* return std::min(std::min(diffdown, diffmid), diffup); */ - /* } else if ( (diffup < 0.0) && (diffdown < 0.0) && (diffmid < 0.0) ) { */ + /* } else if ( (diffup < 0.0) && (diffdown < 0.0) && (diffmid < 0.0) ) { + */ /* return std::max(std::max(diffdown, diffmid), diffup); */ /* } else { */ /* return 0.0; */ @@ -28,15 +29,18 @@ class Minmod { /* }/\* minmod_dx *\/ */ double minmod_dx(const double up1, const double u, const double um1) const { - const double diffup = (up1 - u)*theta_flux; - const double diffdown = (u - um1)*theta_flux; - const double diffmid = (up1 - um1)*0.5; - if (diffup == 0.) - return 0.; - else - return diffup*std::max(0., std::min(1.,std::min(diffdown/diffup, diffmid/diffup))); - }/* minmod_dx */ - + const double diffup = (up1 - u) * theta_flux; + const double diffdown = (u - um1) * theta_flux; + const double diffmid = (up1 - um1) * 0.5; + if (diffup == 0.) + return 0.; + else + return diffup + * std::max( + 0., + std::min( + 1., std::min(diffdown / diffup, diffmid / diffup))); + } /* minmod_dx */ }; #endif // SRC_MINMOD_H_ diff --git a/src/minmod_unittest.cpp b/src/minmod_unittest.cpp index 46ad3e79..3d75a94f 100644 --- a/src/minmod_unittest.cpp +++ b/src/minmod_unittest.cpp @@ -1,6 +1,7 @@ -#include "doctest.h" #include "minmod.h" +#include "doctest.h" + TEST_CASE("Check Minmod theta") { Minmod test(1.5); auto theta_out = test.get_theta(); diff --git a/src/music.cpp b/src/music.cpp index 9e9abb6a..3375a228 100644 --- a/src/music.cpp +++ b/src/music.cpp @@ -1,89 +1,83 @@ // Original copyright 2011 @ Bjoern Schenke, Sangyong Jeon, and Charles Gale // Massively cleaned up and improved by Chun Shen 2015-2016 +#include "music.h" + #include #include -#include -#include +#include #include -#include "music.h" -#include "init.h" -#include "evolve.h" -#include "dissipative.h" +#include + #include "data_struct.h" -#include "hydro_source_strings.h" -#include "hydro_source_ampt.h" +#include "dissipative.h" +#include "evolve.h" #include "hydro_source_TATB.h" +#include "hydro_source_ampt.h" +#include "hydro_source_strings.h" +#include "init.h" #ifdef GSL - #include "freeze.h" +#include "freeze.h" #endif using std::vector; -MUSIC::MUSIC(std::string input_file) : - DATA(ReadInParameters::read_in_parameters(input_file)), - eos(DATA.whichEOS) { - +MUSIC::MUSIC(std::string input_file) + : DATA(ReadInParameters::read_in_parameters(input_file)), + eos(DATA.whichEOS) { DATA.reRunHydro = false; DATA.reRunCount = 0; - mode = DATA.mode; - flag_hydro_run = 0; + mode = DATA.mode; + flag_hydro_run = 0; flag_hydro_initialized = 0; // setup hydro evolution information - hydro_info_ptr = nullptr; + hydro_info_ptr = nullptr; if (DATA.store_hydro_info_in_memory == 1) { - hydro_info_ptr = std::make_shared (); + hydro_info_ptr = std::make_shared(); } // setup source terms hydro_source_terms_ptr = nullptr; } - -MUSIC::~MUSIC() { -} - +MUSIC::~MUSIC() {} //! This function adds hydro source terms pointer void MUSIC::add_hydro_source_terms( - std::shared_ptr hydro_source_ptr_in) { + std::shared_ptr hydro_source_ptr_in) { hydro_source_terms_ptr = hydro_source_ptr_in; } - //! This function setup source terms from dynamical initialization void MUSIC::generate_hydro_source_terms() { if (DATA.Initial_profile == 13 || DATA.Initial_profile == 131) { // MC-Glauber-LEXUS - auto hydro_source_ptr = std::shared_ptr ( - new HydroSourceStrings (DATA)); + auto hydro_source_ptr = + std::shared_ptr(new HydroSourceStrings(DATA)); add_hydro_source_terms(hydro_source_ptr); } else if (DATA.Initial_profile == 30) { // AMPT - auto hydro_source_ptr = std::shared_ptr ( - new HydroSourceAMPT (DATA)); + auto hydro_source_ptr = + std::shared_ptr(new HydroSourceAMPT(DATA)); add_hydro_source_terms(hydro_source_ptr); } else if (DATA.Initial_profile == 112 || DATA.Initial_profile == 113) { // source from TA and TB - auto hydro_source_ptr = std::shared_ptr ( - new HydroSourceTATB (DATA)); + auto hydro_source_ptr = + std::shared_ptr(new HydroSourceTATB(DATA)); add_hydro_source_terms(hydro_source_ptr); } } - void MUSIC::clean_all_the_surface_files() { system_status_ = system("rm surface*.dat 2> /dev/null"); } - //! This function change the parameter value in DATA void MUSIC::set_parameter(std::string parameter_name, double value) { ReadInParameters::set_parameter(DATA, parameter_name, value); } - //! This function initialize hydro void MUSIC::initialize_hydro() { clean_all_the_surface_files(); @@ -95,32 +89,29 @@ void MUSIC::initialize_hydro() { flag_hydro_initialized = 1; } - //! this is a shell function to run hydro int MUSIC::run_hydro() { Evolve evolve_local(eos, DATA, hydro_source_terms_ptr); if (hydro_info_ptr == nullptr && DATA.store_hydro_info_in_memory == 1) { - hydro_info_ptr = std::make_shared (); + hydro_info_ptr = std::make_shared(); } - evolve_local.EvolveIt(arenaFieldsPrev, arenaFieldsCurr, arenaFieldsNext, - (*hydro_info_ptr)); + evolve_local.EvolveIt( + arenaFieldsPrev, arenaFieldsCurr, arenaFieldsNext, (*hydro_info_ptr)); flag_hydro_run = 1; - return(0); + return (0); } - //! this is a shell function to run Cooper-Frye int MUSIC::run_Cooper_Frye() { #ifdef GSL Freeze cooper_frye(&DATA); - cooper_frye.CooperFrye_pseudo(DATA.particleSpectrumNumber, mode, - &DATA, &eos); + cooper_frye.CooperFrye_pseudo( + DATA.particleSpectrumNumber, mode, &DATA, &eos); #endif - return(0); + return (0); } - void MUSIC::check_eos() { music_message << "check eos ..."; music_message.flush("info"); @@ -141,19 +132,14 @@ void MUSIC::output_transport_coefficients() { temp_dissipative_ptr.output_zeta_over_s_along_const_sovernB(); } - void MUSIC::initialize_hydro_from_jetscape_preequilibrium_vectors( - const double dx, const double dz, const double z_max, const int nz, - vector e_in, vector P_in, - vector u_tau_in, vector u_x_in, - vector u_y_in, vector u_eta_in, - vector pi_00_in, vector pi_01_in, - vector pi_02_in, vector pi_03_in, - vector pi_11_in, vector pi_12_in, - vector pi_13_in, vector pi_22_in, - vector pi_23_in, vector pi_33_in, - vector Bulk_pi_in) { - + const double dx, const double dz, const double z_max, const int nz, + vector e_in, vector P_in, vector u_tau_in, + vector u_x_in, vector u_y_in, vector u_eta_in, + vector pi_00_in, vector pi_01_in, vector pi_02_in, + vector pi_03_in, vector pi_11_in, vector pi_12_in, + vector pi_13_in, vector pi_22_in, vector pi_23_in, + vector pi_33_in, vector Bulk_pi_in) { DATA.Initial_profile = 42; clean_all_the_surface_files(); @@ -161,7 +147,7 @@ void MUSIC::initialize_hydro_from_jetscape_preequilibrium_vectors( if (nz > 1) { DATA.boost_invariant = false; DATA.delta_eta = dz; - DATA.eta_size = nz*dz; + DATA.eta_size = nz * dz; } else { DATA.boost_invariant = true; DATA.delta_eta = 0.1; @@ -172,16 +158,16 @@ void MUSIC::initialize_hydro_from_jetscape_preequilibrium_vectors( Init initialization(eos, DATA, hydro_source_terms_ptr); initialization.get_jetscape_preequilibrium_vectors( - e_in, P_in, u_tau_in, u_x_in, u_y_in, u_eta_in, - pi_00_in, pi_01_in, pi_02_in, pi_03_in, pi_11_in, pi_12_in, pi_13_in, - pi_22_in, pi_23_in, pi_33_in, Bulk_pi_in); + e_in, P_in, u_tau_in, u_x_in, u_y_in, u_eta_in, pi_00_in, pi_01_in, + pi_02_in, pi_03_in, pi_11_in, pi_12_in, pi_13_in, pi_22_in, pi_23_in, + pi_33_in, Bulk_pi_in); initialization.InitArena(arenaFieldsPrev, arenaFieldsCurr, arenaFieldsNext); flag_hydro_initialized = 1; } void MUSIC::get_hydro_info( - const double x, const double y, const double z, const double t, - fluidCell* fluid_cell_info) { + const double x, const double y, const double z, const double t, + fluidCell* fluid_cell_info) { if (DATA.store_hydro_info_in_memory == 0 || hydro_info_ptr == nullptr) { music_message << "hydro evolution informaiton is not stored " << "in the momeory! Please set the parameter " diff --git a/src/music.h b/src/music.h index 47ffe29c..3ac0e0d4 100644 --- a/src/music.h +++ b/src/music.h @@ -4,19 +4,19 @@ #include -#include "util.h" +#include "HydroinfoMUSIC.h" #include "cell.h" #include "data.h" #include "eos.h" #include "fields.h" #include "hydro_source_base.h" -#include "read_in_parameters.h" #include "pretty_ostream.h" -#include "HydroinfoMUSIC.h" +#include "read_in_parameters.h" +#include "util.h" //! This is a wrapper class for the MUSIC hydro class MUSIC { - private: + private: //! records running mode int mode; @@ -42,12 +42,12 @@ class MUSIC { pretty_ostream music_message; - public: + public: MUSIC(std::string input_file); ~MUSIC(); //! this function returns the running mode - int get_running_mode() {return(mode);} + int get_running_mode() { return (mode); } //! This function initialize hydro void initialize_hydro(); @@ -63,7 +63,7 @@ class MUSIC { //! this function adds hydro source terms pointer void add_hydro_source_terms( - std::shared_ptr hydro_source_ptr_in); + std::shared_ptr hydro_source_ptr_in); //! This function setup source terms from dynamical initialization void generate_hydro_source_terms(); @@ -81,7 +81,7 @@ class MUSIC { const double dx, const double dz, const double z_max, const int nz, std::vector e_in, std::vector P_in, std::vector u_tau_in, std::vector u_x_in, - std::vector u_y_in, std::vector u_eta_in, + std::vector u_y_in, std::vector u_eta_in, std::vector pi_00_in, std::vector pi_01_in, std::vector pi_02_in, std::vector pi_03_in, std::vector pi_11_in, std::vector pi_12_in, @@ -91,36 +91,38 @@ class MUSIC { void get_hydro_info( const double x, const double y, const double z, const double t, - fluidCell* fluid_cell_info); + fluidCell *fluid_cell_info); int get_number_of_fluid_cells() const { - return(hydro_info_ptr->get_number_of_fluid_cells()); + return (hydro_info_ptr->get_number_of_fluid_cells()); } void get_fluid_cell_with_index(const int idx, fluidCell *info) const { - return(hydro_info_ptr->get_fluid_cell_with_index(idx, info)); + return (hydro_info_ptr->get_fluid_cell_with_index(idx, info)); } void clear_hydro_info_from_memory(); - double get_hydro_tau0() const {return(hydro_info_ptr->get_hydro_tau0());} - double get_hydro_dtau() const {return(hydro_info_ptr->get_hydro_dtau());} + double get_hydro_tau0() const { return (hydro_info_ptr->get_hydro_tau0()); } + double get_hydro_dtau() const { return (hydro_info_ptr->get_hydro_dtau()); } double get_hydro_tau_max() const { - return(hydro_info_ptr->get_hydro_tau_max()); + return (hydro_info_ptr->get_hydro_tau_max()); + } + double get_hydro_dx() const { return (hydro_info_ptr->get_hydro_dx()); } + double get_hydro_x_max() const { + return (hydro_info_ptr->get_hydro_x_max()); } - double get_hydro_dx() const {return(hydro_info_ptr->get_hydro_dx());} - double get_hydro_x_max() const {return(hydro_info_ptr->get_hydro_x_max());} - double get_hydro_deta() const {return(hydro_info_ptr->get_hydro_deta());} + double get_hydro_deta() const { return (hydro_info_ptr->get_hydro_deta()); } double get_hydro_eta_max() const { - return(hydro_info_ptr->get_hydro_eta_max()); + return (hydro_info_ptr->get_hydro_eta_max()); } - int get_ntau() const {return(hydro_info_ptr->get_ntau());} - int get_neta() const {return(hydro_info_ptr->get_neta());} - int get_nx() const {return(hydro_info_ptr->get_nx() );} + int get_ntau() const { return (hydro_info_ptr->get_ntau()); } + int get_neta() const { return (hydro_info_ptr->get_neta()); } + int get_nx() const { return (hydro_info_ptr->get_nx()); } bool is_boost_invariant() const { - return(hydro_info_ptr->is_boost_invariant()); + return (hydro_info_ptr->is_boost_invariant()); } - bool getReRunHydro() const {return(DATA.reRunHydro);} + bool getReRunHydro() const { return (DATA.reRunHydro); } void setReRunHydro(bool flag) { DATA.reRunHydro = flag; } - int getReRunCount() const {return(DATA.reRunCount);} + int getReRunCount() const { return (DATA.reRunCount); } void setReRunCount(int reRunCount) { DATA.reRunCount = reRunCount; } }; diff --git a/src/music_logo.cpp b/src/music_logo.cpp index d649b0e1..9e5b7eb4 100644 --- a/src/music_logo.cpp +++ b/src/music_logo.cpp @@ -1,7 +1,9 @@ #include "music_logo.h" + #include #include -#include + +#include namespace MUSIC_LOGO { @@ -9,76 +11,146 @@ namespace MUSIC_LOGO { void display_logo(int selector) { switch (selector) { case 0: // 3D Diagonal - std::cout << "================================================================" << std::endl; - std::cout << "| ____ |" << std::endl; - std::cout << "| ,' , `. .--.--. ,---, ,----.. |" << std::endl; - std::cout << "| ,-+-,.' _ | ,--, / / '. ,`--.' | / / \\ |" << std::endl; - std::cout << "| ,-+-. ; , || ,'_ /|| : /`. / | : :| : : |" << std::endl; - std::cout << "| ,--.'|' | ;| .--. | | :; | |--` : | '. | ;. / |" << std::endl; - std::cout << "| | | ,', | ':,'_ /| : . || : ;_ | : |. ; /--` |" << std::endl; - std::cout << "| | | / | | ||| ' | | . . \\ \\ `. ' ' ;; | ; |" << std::endl; - std::cout << "| ' | : | : |,| | ' | | | `----. \\| | || : | |" << std::endl; - std::cout << "| ; . | ; |--' : | | : ' ; __ \\ \\ |' : ;. | '___ |" << std::endl; - std::cout << "| | : | | , | ; ' | | ' / /`--' /| | '' ; : .'| |" << std::endl; - std::cout << "| | : ' |/ : | : ; ; |'--'. / ' : |' | '/ : |" << std::endl; - std::cout << "| ; | |`-' ' : `--' \\ `--'---' ; |.' | : / |" << std::endl; - std::cout << "| | ;/ : , .-./ '---' \\ \\ .' |" << std::endl; - std::cout << "| '---' `--`----' `---` |" << std::endl; - std::cout << "================================================================" << std::endl; + std::cout << "=====================================================" + "===========" + << std::endl; + std::cout << "| ____ " + " |" + << std::endl; + std::cout << "| ,' , `. .--.--. ,---, " + ",----.. |" + << std::endl; + std::cout << "| ,-+-,.' _ | ,--, / / '. ,`--.' | " + "/ / \\ |" + << std::endl; + std::cout << "| ,-+-. ; , || ,'_ /|| : /`. / | : :| " + " : : |" + << std::endl; + std::cout << "| ,--.'|' | ;| .--. | | :; | |--` : | '. " + " | ;. / |" + << std::endl; + std::cout << "| | | ,', | ':,'_ /| : . || : ;_ | : |. " + " ; /--` |" + << std::endl; + std::cout << "| | | / | | ||| ' | | . . \\ \\ `. ' ' " + ";; | ; |" + << std::endl; + std::cout << "| ' | : | : |,| | ' | | | `----. \\| | " + "|| : | |" + << std::endl; + std::cout << "| ; . | ; |--' : | | : ' ; __ \\ \\ |' : " + ";. | '___ |" + << std::endl; + std::cout << "| | : | | , | ; ' | | ' / /`--' /| | '' " + " ; : .'| |" + << std::endl; + std::cout << "| | : ' |/ : | : ; ; |'--'. / ' : |' " + " | '/ : |" + << std::endl; + std::cout << "| ; | |`-' ' : `--' \\ `--'---' ; |.' " + "| : / |" + << std::endl; + std::cout << "| | ;/ : , .-./ '---' " + "\\ \\ .' |" + << std::endl; + std::cout << "| '---' `--`----' " + "`---` |" + << std::endl; + std::cout << "=====================================================" + "===========" + << std::endl; break; case 1: // bloody - std::cout << "==============================================" << std::endl; - std::cout << "| ███▄ ▄███▓ █ ██ ██████ ██▓ ▄████▄ |" << std::endl; - std::cout << "| ▓██▒▀█▀ ██▒ ██ ▓██▒▒██ ▒ ▓██▒▒██▀ ▀█ |" << std::endl; - std::cout << "| ▓██ ▓██░▓██ ▒██░░ ▓██▄ ▒██▒▒▓█ ▄ |" << std::endl; - std::cout << "| ▒██ ▒██ ▓▓█ ░██░ ▒ ██▒░██░▒▓▓▄ ▄██▒ |" << std::endl; - std::cout << "| ▒██▒ ░██▒▒▒█████▓ ▒██████▒▒░██░▒ ▓███▀ ░ |" << std::endl; - std::cout << "| ░ ▒░ ░ ░░▒▓▒ ▒ ▒ ▒ ▒▓▒ ▒ ░░▓ ░ ░▒ ▒ ░ |" << std::endl; - std::cout << "| ░ ░ ░░░▒░ ░ ░ ░ ░▒ ░ ░ ▒ ░ ░ ▒ |" << std::endl; - std::cout << "| ░ ░ ░░░ ░ ░ ░ ░ ░ ▒ ░░ |" << std::endl; - std::cout << "| ░ ░ ░ ░ ░ ░ |" << std::endl; - std::cout << "| ░ |" << std::endl; - std::cout << "==============================================" << std::endl; + std::cout << "==============================================" + << std::endl; + std::cout << "| ███▄ ▄███▓ █ ██ ██████ ██▓ ▄████▄ |" + << std::endl; + std::cout << "| ▓██▒▀█▀ ██▒ ██ ▓██▒▒██ ▒ ▓██▒▒██▀ ▀█ |" + << std::endl; + std::cout << "| ▓██ ▓██░▓██ ▒██░░ ▓██▄ ▒██▒▒▓█ ▄ |" + << std::endl; + std::cout << "| ▒██ ▒██ ▓▓█ ░██░ ▒ ██▒░██░▒▓▓▄ ▄██▒ |" + << std::endl; + std::cout << "| ▒██▒ ░██▒▒▒█████▓ ▒██████▒▒░██░▒ ▓███▀ ░ |" + << std::endl; + std::cout << "| ░ ▒░ ░ ░░▒▓▒ ▒ ▒ ▒ ▒▓▒ ▒ ░░▓ ░ ░▒ ▒ ░ |" + << std::endl; + std::cout << "| ░ ░ ░░░▒░ ░ ░ ░ ░▒ ░ ░ ▒ ░ ░ ▒ |" + << std::endl; + std::cout << "| ░ ░ ░░░ ░ ░ ░ ░ ░ ▒ ░░ |" + << std::endl; + std::cout << "| ░ ░ ░ ░ ░ ░ |" + << std::endl; + std::cout << "| ░ |" + << std::endl; + std::cout << "==============================================" + << std::endl; break; case 2: // Dancing font - std::cout << "====================================================" << std::endl; - std::cout << "| __ __ _ _ ____ ____ |" << std::endl; - std::cout << "| U|' \\/ '|uU |\"|u| | / __\"| u ___ U /\"___| |" << std::endl; - std::cout << "| \\| |\\/| |/ \\| |\\| |<\\___ \\/ |_\"_| \\| | u |" << std::endl; - std::cout << "| | | | | | |_| | u___) | | | | |/__ |" << std::endl; - std::cout << "| |_| |_| <<\\___/ |____/>> U/| |\\u \\____| |" << std::endl; - std::cout << "| <<,-,,-. (__) )( )( (__).-,_|___|_,-._// \\\\ |" << std::endl; - std::cout << "| (./ \\.) (__) (__) \\_)-' '-(_/(__)(__) |" << std::endl; - std::cout << "====================================================" << std::endl; + std::cout << "====================================================" + << std::endl; + std::cout << "| __ __ _ _ ____ ____ |" + << std::endl; + std::cout + << "| U|' \\/ '|uU |\"|u| | / __\"| u ___ U /\"___| |" + << std::endl; + std::cout << "| \\| |\\/| |/ \\| |\\| |<\\___ \\/ |_\"_| " + "\\| | u |" + << std::endl; + std::cout << "| | | | | | |_| | u___) | | | | |/__ |" + << std::endl; + std::cout + << "| |_| |_| <<\\___/ |____/>> U/| |\\u \\____| |" + << std::endl; + std::cout + << "| <<,-,,-. (__) )( )( (__).-,_|___|_,-._// \\\\ |" + << std::endl; + std::cout + << "| (./ \\.) (__) (__) \\_)-' '-(_/(__)(__) |" + << std::endl; + std::cout << "====================================================" + << std::endl; break; case 3: // STAR Wars - std::cout << "=====================================================" << std::endl; - std::cout << "| .___ ___. __ __ _______. __ ______ |" << std::endl; - std::cout << "| | \\/ | | | | | / || | / | |" << std::endl; - std::cout << "| | \\ / | | | | | | (----`| | | ,----' |" << std::endl; - std::cout << "| | |\\/| | | | | | \\ \\ | | | | |" << std::endl; - std::cout << "| | | | | | `--' | .----) | | | | `----. |" << std::endl; - std::cout << "| |__| |__| \\______/ |_______/ |__| \\______| |" << std::endl; - std::cout << "=====================================================" << std::endl; + std::cout << "=====================================================" + << std::endl; + std::cout << "| .___ ___. __ __ _______. __ ______ |" + << std::endl; + std::cout + << "| | \\/ | | | | | / || | / | |" + << std::endl; + std::cout + << "| | \\ / | | | | | | (----`| | | ,----' |" + << std::endl; + std::cout + << "| | |\\/| | | | | | \\ \\ | | | | |" + << std::endl; + std::cout << "| | | | | | `--' | .----) | | | | `----. |" + << std::endl; + std::cout + << "| |__| |__| \\______/ |_______/ |__| \\______| |" + << std::endl; + std::cout << "=====================================================" + << std::endl; break; } - } //! This function prints out code desciprtion and copyright information void display_code_description_and_copyright() { std::cout << "MUSIC - a 3+1D viscous relativistic hydrodynamic code for " << "heavy ion collisions" << std::endl; - std::cout << "Copyright (C) 2017 Gabriel Denicol, Charles Gale, Sangyong Jeon, " - << "Matthew Luzum, Jean-François Paquet, Björn Schenke, Chun Shen" - << std::endl; + std::cout + << "Copyright (C) 2017 Gabriel Denicol, Charles Gale, Sangyong Jeon, " + << "Matthew Luzum, Jean-François Paquet, Björn Schenke, Chun Shen" + << std::endl; } //! This function prints out the welcome message void welcome_message() { - srand (time(NULL)); - display_logo(rand()%4); + srand(time(NULL)); + display_logo(rand() % 4); display_code_description_and_copyright(); } -} +} // namespace MUSIC_LOGO diff --git a/src/music_logo.h b/src/music_logo.h index e4cc5166..cc9d05ca 100644 --- a/src/music_logo.h +++ b/src/music_logo.h @@ -2,9 +2,9 @@ #define _SRC_MUSIC_LOGO_H_ namespace MUSIC_LOGO { - void display_logo(int selector); - void display_code_description_and_copyright(); - void welcome_message(); -} +void display_logo(int selector); +void display_code_description_and_copyright(); +void welcome_message(); +} // namespace MUSIC_LOGO #endif // _SRC_MUSIC_LOGO_H_ diff --git a/src/pretty_ostream.cpp b/src/pretty_ostream.cpp index e9e5c495..4f17f1a8 100644 --- a/src/pretty_ostream.cpp +++ b/src/pretty_ostream.cpp @@ -1,12 +1,14 @@ // Copyright Chun Shen @ 2017 // This class is inspired by the JetScapeLogger class written by Joern Putschke -#include -#include +#include "pretty_ostream.h" + #include +#include + #include +#include -#include "pretty_ostream.h" #include "emoji.h" using std::cout; @@ -17,7 +19,6 @@ pretty_ostream::pretty_ostream() {} pretty_ostream::~pretty_ostream() {} - //! This function flushes out message to the screen void pretty_ostream::flush(string type) { std::transform(type.begin(), type.end(), type.begin(), ::tolower); @@ -36,26 +37,23 @@ void pretty_ostream::flush(string type) { //! This function output information message void pretty_ostream::info(string message) { - //cout << "[Info] " << get_memory_usage() << " " << message << endl; - cout << emoji::music_note() << " " << get_memory_usage() << " " - << message << endl; + // cout << "[Info] " << get_memory_usage() << " " << message << endl; + cout << emoji::music_note() << " " << get_memory_usage() << " " << message + << endl; } - //! This function output debug message void pretty_ostream::debug(string message) { cout << CYAN << emoji::debug() << " " << get_memory_usage() << " " << message << RESET << endl; } - //! This function output warning message void pretty_ostream::warning(string message) { - cout << BOLD << YELLOW << emoji::warning() << " " << message - << RESET << endl; + cout << BOLD << YELLOW << emoji::warning() << " " << message << RESET + << endl; } - //! This function output error message void pretty_ostream::error(string message) { cout << BOLD << RED << emoji::error() << " " << message << RESET << endl; @@ -68,15 +66,14 @@ string pretty_ostream::get_memory_usage() { if (getrusage(RUSAGE_SELF, &usage) == 0) { double memory_usage_in_MB = 0.0; #ifdef APPLE - memory_usage_in_MB = usage.ru_maxrss/1024./1024.; // MB in Apple + memory_usage_in_MB = usage.ru_maxrss / 1024. / 1024.; // MB in Apple #else - memory_usage_in_MB = usage.ru_maxrss/1024.; // MB in linux + memory_usage_in_MB = usage.ru_maxrss / 1024.; // MB in linux #endif std::ostringstream memory_usage; - memory_usage << std::setprecision(4) - << memory_usage_in_MB << " MB"; - return(memory_usage.str()); + memory_usage << std::setprecision(4) << memory_usage_in_MB << " MB"; + return (memory_usage.str()); } else { - return(0); + return (0); } } diff --git a/src/pretty_ostream.h b/src/pretty_ostream.h index 166e8410..7a25c8c9 100644 --- a/src/pretty_ostream.h +++ b/src/pretty_ostream.h @@ -1,17 +1,17 @@ // Copyright Chun Shen @ 2017 // This class is inspired by the JetScapeLogger class written by Joern Putschke -#define BOLD "\033[1m" // Bold -#define BLACK "\033[30m" // Black -#define RED "\033[31m" // Red -#define GREEN "\033[32m" // Green -#define YELLOW "\033[33m" // Yellow -#define BLUE "\033[34m" // Blue -#define MAGENTA "\033[35m" // Magenta -#define CYAN "\033[36m" // Cyan -#define WHITE "\033[37m" // White -#define RESET "\033[0m" // reset - +#define BOLD "\033[1m" // Bold +#define BLACK "\033[30m" // Black +#define RED "\033[31m" // Red +#define GREEN "\033[32m" // Green +#define YELLOW "\033[33m" // Yellow +#define BLUE "\033[34m" // Blue +#define MAGENTA "\033[35m" // Magenta +#define CYAN "\033[36m" // Cyan +#define WHITE "\033[37m" // White +#define RESET "\033[0m" // reset + #ifndef PRETTY_OSTREAM_H_ #define PRETTY_OSTREAM_H_ @@ -20,10 +20,10 @@ #include class pretty_ostream { - private: + private: std::ostringstream message_stream; - public: + public: pretty_ostream(); ~pretty_ostream(); @@ -46,9 +46,10 @@ class pretty_ostream { std::string get_memory_usage(); //! reload the << operator - template pretty_ostream& operator<<(T const& value) { + template + pretty_ostream& operator<<(T const& value) { message_stream << value; - return(*this); + return (*this); } }; diff --git a/src/read_in_parameters.cpp b/src/read_in_parameters.cpp index 84f093dd..0009908d 100644 --- a/src/read_in_parameters.cpp +++ b/src/read_in_parameters.cpp @@ -1,7 +1,9 @@ -#include -#include #include "read_in_parameters.h" + +#include +#include + #include "util.h" using namespace std; @@ -34,8 +36,8 @@ InitData read_in_parameters(std::string input_file) { parameter_list.mode = getParameter(input_file, "mode", 2); // Initial_profile: - parameter_list.Initial_profile = ( - getParameter(input_file, "Initial_profile", 1)); + parameter_list.Initial_profile = + (getParameter(input_file, "Initial_profile", 1)); // boost-invariant int temp_boost_invariant = getParameter(input_file, "boost_invariant", 1); @@ -45,32 +47,32 @@ InitData read_in_parameters(std::string input_file) { parameter_list.boost_invariant = true; } - parameter_list.output_initial_density_profiles = ( - getParameter(input_file, "output_initial_density_profiles", 0)); + parameter_list.output_initial_density_profiles = + (getParameter(input_file, "output_initial_density_profiles", 0)); ////////////////////////////////////////////////////////////////////////// // parameters for 3D-Glauber initial condition ////////////////////////////////////////////////////////////////////////// - parameter_list.string_dump_mode = ( - getParameter(input_file, "string_dump_mode", 1)); + parameter_list.string_dump_mode = + (getParameter(input_file, "string_dump_mode", 1)); - parameter_list.stringSourceSigmaX = ( - getParameter(input_file, "string_source_sigma_x", 0.5)); + parameter_list.stringSourceSigmaX = + (getParameter(input_file, "string_source_sigma_x", 0.5)); - parameter_list.stringSourceSigmaEta = ( - getParameter(input_file, "string_source_sigma_eta", 0.5)); + parameter_list.stringSourceSigmaEta = + (getParameter(input_file, "string_source_sigma_eta", 0.5)); - parameter_list.stringTransverseShiftFrac = ( - getParameter(input_file, "stringTransverseShiftFrac", 0.0)); + parameter_list.stringTransverseShiftFrac = + (getParameter(input_file, "stringTransverseShiftFrac", 0.0)); - parameter_list.preEqFlowFactor = ( - getParameter(input_file, "stringPreEqFlowFactor", 0.0)); + parameter_list.preEqFlowFactor = + (getParameter(input_file, "stringPreEqFlowFactor", 0.0)); - parameter_list.string_quench_factor = ( - getParameter(input_file, "string_quench_factor", 0.0)); + parameter_list.string_quench_factor = + (getParameter(input_file, "string_quench_factor", 0.0)); - parameter_list.parton_quench_factor = ( - getParameter(input_file, "parton_quench_factor", 1.0)); + parameter_list.parton_quench_factor = + (getParameter(input_file, "parton_quench_factor", 1.0)); parameter_list.gridPadding = getParameter(input_file, "gridPadding", 3.0); @@ -79,39 +81,35 @@ InitData read_in_parameters(std::string input_file) { ////////////////////////////////////////////////////////////////////////// // Initial_Distribution_input_filename string tempinitName = "initial/initial_ed.dat"; - tempinput = Util::StringFind4(input_file, - "Initial_Distribution_input_filename"); - if (tempinput != "empty") - tempinitName.assign(tempinput); + tempinput = + Util::StringFind4(input_file, "Initial_Distribution_input_filename"); + if (tempinput != "empty") tempinitName.assign(tempinput); parameter_list.initName.assign(tempinitName); // Initial_Distribution_Filename for TA string tempinitName_TA = "initial/initial_TA.dat"; - tempinput = Util::StringFind4(input_file, - "Initial_TA_Distribution_Filename"); - if (tempinput != "empty") - tempinitName_TA.assign(tempinput); + tempinput = + Util::StringFind4(input_file, "Initial_TA_Distribution_Filename"); + if (tempinput != "empty") tempinitName_TA.assign(tempinput); parameter_list.initName_TA.assign(tempinitName_TA); // Initial_Distribution_Filename for TB string tempinitName_TB = "initial/initial_TB.dat"; - tempinput = Util::StringFind4(input_file, - "Initial_TB_Distribution_Filename"); - if (tempinput != "empty") - tempinitName_TB.assign(tempinput); + tempinput = + Util::StringFind4(input_file, "Initial_TB_Distribution_Filename"); + if (tempinput != "empty") tempinitName_TB.assign(tempinput); parameter_list.initName_TB.assign(tempinitName_TB); // Initial_Distribution_Filename for participant list string tempinitName_part = "initial/participantList.dat"; - tempinput = Util::StringFind4(input_file, - "Initial_participantList_Filename"); - if (tempinput != "empty") - tempinitName_part.assign(tempinput); + tempinput = + Util::StringFind4(input_file, "Initial_participantList_Filename"); + if (tempinput != "empty") tempinitName_part.assign(tempinput); parameter_list.initName_participants.assign(tempinitName_part); - parameter_list.nucleonWidth = ( - getParameter(input_file, "nucleon_width", 0.5)); + parameter_list.nucleonWidth = + (getParameter(input_file, "nucleon_width", 0.5)); // compute beam rapidity according to the collision energy parameter_list.ecm = getParameter(input_file, "ecm", 200.); - double y_beam = acosh(parameter_list.ecm/(2.*Util::m_N)); + double y_beam = acosh(parameter_list.ecm / (2. * Util::m_N)); parameter_list.beam_rapidity = y_beam; // Eta_plateau_size: @@ -124,23 +122,23 @@ InitData read_in_parameters(std::string input_file) { parameter_list.yL_frac = getParameter(input_file, "yL_frac", 0.0); // eta envelope function parameter for rhob - parameter_list.initial_eta_rhob_profile = ( - getParameter(input_file, "initial_eta_rhob_profile", 1)); + parameter_list.initial_eta_rhob_profile = + (getParameter(input_file, "initial_eta_rhob_profile", 1)); parameter_list.eta_rhob_0 = getParameter(input_file, "eta_rhob_0", 3.0); - parameter_list.eta_rhob_width = ( - getParameter(input_file, "eta_rhob_width", 1.0)); - parameter_list.eta_rhob_plateau_height = ( - getParameter(input_file, "eta_rhob_plateau_height", 0.5)); - parameter_list.eta_rhob_width_1 = ( - getParameter(input_file, "eta_rhob_width_1", 1.0)); - parameter_list.eta_rhob_width_2 = ( - getParameter(input_file, "eta_rhob_width_2", 1.0)); - parameter_list.eta_rhob_asym = ( - getParameter(input_file, "eta_rhob_asym", 1.0)); - - //initialize_with_entropy: 0: with energy density, 1: with entropy density - parameter_list.initializeEntropy = ( - getParameter(input_file, "initialize_with_entropy", 0)); + parameter_list.eta_rhob_width = + (getParameter(input_file, "eta_rhob_width", 1.0)); + parameter_list.eta_rhob_plateau_height = + (getParameter(input_file, "eta_rhob_plateau_height", 0.5)); + parameter_list.eta_rhob_width_1 = + (getParameter(input_file, "eta_rhob_width_1", 1.0)); + parameter_list.eta_rhob_width_2 = + (getParameter(input_file, "eta_rhob_width_2", 1.0)); + parameter_list.eta_rhob_asym = + (getParameter(input_file, "eta_rhob_asym", 1.0)); + + // initialize_with_entropy: 0: with energy density, 1: with entropy density + parameter_list.initializeEntropy = + (getParameter(input_file, "initialize_with_entropy", 0)); ////////////////////////////////////////////////////////////////////////// // Parameters for IP-Glasma initial conditions @@ -149,19 +147,17 @@ InitData read_in_parameters(std::string input_file) { parameter_list.sFactor = getParameter(input_file, "s_factor", 1.0); // preEqVisFactor: for use with IP-Glasma initial conditions - parameter_list.preEqVisFactor = ( - getParameter(input_file, "preEqVisFactor", 1.0)); - + parameter_list.preEqVisFactor = + (getParameter(input_file, "preEqVisFactor", 1.0)); ////////////////////////////////////////////////////////////////////////// // Parameters for AMPT initial conditions ////////////////////////////////////////////////////////////////////////// // Initial_Distribution_AMPT_filename for AMPT string tempinitName_AMPT = "initial/initial_AMPT.dat"; - tempinput = Util::StringFind4(input_file, - "Initial_Distribution_AMPT_filename"); - if (tempinput != "empty") - tempinitName_AMPT.assign(tempinput); + tempinput = + Util::StringFind4(input_file, "Initial_Distribution_AMPT_filename"); + if (tempinput != "empty") tempinitName_AMPT.assign(tempinput); parameter_list.initName_AMPT.assign(tempinitName_AMPT); ////////////////////////////////////////////////////////////////////////// @@ -180,12 +176,13 @@ InitData read_in_parameters(std::string input_file) { parameter_list.eta_size = getParameter(input_file, "Eta_grid_size", 8.); parameter_list.delta_x = - parameter_list.x_size/static_cast(parameter_list.nx - 1); + parameter_list.x_size / static_cast(parameter_list.nx - 1); parameter_list.delta_y = - parameter_list.y_size/static_cast(parameter_list.ny - 1); + parameter_list.y_size / static_cast(parameter_list.ny - 1); if (parameter_list.neta > 1) { - parameter_list.delta_eta = (parameter_list.eta_size - /static_cast(parameter_list.neta - 1)); + parameter_list.delta_eta = + (parameter_list.eta_size + / static_cast(parameter_list.neta - 1)); } else { parameter_list.delta_eta = 0.1; } @@ -211,10 +208,10 @@ InitData read_in_parameters(std::string input_file) { // Total_evolution_time_tau // total evolution time in [fm]. in case of freeze_out_method = 2,3,4 // evolution will halt earlier if all cells are frozen out. - parameter_list.tau_size = ( - getParameter(input_file, "Total_evolution_time_tau", 50.)); + parameter_list.tau_size = + (getParameter(input_file, "Total_evolution_time_tau", 50.)); parameter_list.nt = static_cast( - parameter_list.tau_size/(parameter_list.delta_tau) + 0.5); + parameter_list.tau_size / (parameter_list.delta_tau) + 0.5); music_message << "read_in_parameters: Time step size = " << parameter_list.delta_tau; music_message.flush("info"); @@ -223,12 +220,12 @@ InitData read_in_parameters(std::string input_file) { music_message.flush("info"); // switch for baryon current propagation - parameter_list.turn_on_rhob = ( - getParameter(input_file, "Include_Rhob_Yes_1_No_0", 0)); + parameter_list.turn_on_rhob = + (getParameter(input_file, "Include_Rhob_Yes_1_No_0", 0)); if (parameter_list.turn_on_rhob == 1) { - parameter_list.alpha_max = 5; + parameter_list.alpha_max = 5; } else { - parameter_list.alpha_max = 4; + parameter_list.alpha_max = 4; } // Runge_Kutta_order: must be 1 or 2 @@ -259,194 +256,186 @@ InitData read_in_parameters(std::string input_file) { parameter_list.whichEOS = getParameter(input_file, "EOS_to_use", 9); // Viscosity_Flag_Yes_1_No_0: set to 0 for ideal hydro - parameter_list.viscosity_flag = ( - getParameter(input_file, "Viscosity_Flag_Yes_1_No_0", 1)); + parameter_list.viscosity_flag = + (getParameter(input_file, "Viscosity_Flag_Yes_1_No_0", 1)); // Include_Shear_Visc_Yes_1_No_0 - parameter_list.turn_on_shear = ( - getParameter(input_file, "Include_Shear_Visc_Yes_1_No_0", 0)); + parameter_list.turn_on_shear = + (getParameter(input_file, "Include_Shear_Visc_Yes_1_No_0", 0)); // Include_Bulk_Visc_Yes_1_No_0 - parameter_list.turn_on_bulk = ( - getParameter(input_file, "Include_Bulk_Visc_Yes_1_No_0", 0)); + parameter_list.turn_on_bulk = + (getParameter(input_file, "Include_Bulk_Visc_Yes_1_No_0", 0)); // Include secord order terms - parameter_list.include_second_order_terms = ( - getParameter(input_file, "Include_second_order_terms", 0)); - int tempturn_on_vorticity_terms = ( - getParameter(input_file, "Include_vorticity_terms", 0)); + parameter_list.include_second_order_terms = + (getParameter(input_file, "Include_second_order_terms", 0)); + int tempturn_on_vorticity_terms = + (getParameter(input_file, "Include_vorticity_terms", 0)); if (tempturn_on_vorticity_terms == 0) { parameter_list.include_vorticity_terms = false; } else { parameter_list.include_vorticity_terms = true; } - parameter_list.turn_on_diff = ( - getParameter(input_file, "turn_on_baryon_diffusion", 0)); + parameter_list.turn_on_diff = + (getParameter(input_file, "turn_on_baryon_diffusion", 0)); // the strength for the viscous regulation - parameter_list.quest_revert_strength = ( - getParameter(input_file, "quest_revert_strength", 10.)); + parameter_list.quest_revert_strength = + (getParameter(input_file, "quest_revert_strength", 10.)); - //Shear_to_S_ratio: constant eta/s - parameter_list.shear_to_s = ( - getParameter(input_file, "Shear_to_S_ratio", 0.08)); + // Shear_to_S_ratio: constant eta/s + parameter_list.shear_to_s = + (getParameter(input_file, "Shear_to_S_ratio", 0.08)); // Relaxation time factors - parameter_list.shear_relax_time_factor = ( - getParameter(input_file, "shear_relax_time_factor", 5.0)); + parameter_list.shear_relax_time_factor = + (getParameter(input_file, "shear_relax_time_factor", 5.0)); - parameter_list.T_dependent_shear_to_s = ( - getParameter(input_file, "T_dependent_Shear_to_S_ratio", 0)); + parameter_list.T_dependent_shear_to_s = + (getParameter(input_file, "T_dependent_Shear_to_S_ratio", 0)); // If "T_dependent_Shear_to_S_ratio==2", - // (eta/s)(T) = eta_over_s_min + eta_over_s_slope*(T − Tc)*(T/Tc)^{eta_over_s_curv} - // with T_c=0.154 GeV - parameter_list.shear_2_min = ( - getParameter(input_file, "shear_viscosity_2_min", 0.08)); - parameter_list.shear_2_slope = ( - getParameter(input_file, "shear_viscosity_2_slope", 1.0)); - parameter_list.shear_2_curv = ( - getParameter(input_file, "shear_viscosity_2_curv", 0.0)); + // (eta/s)(T) = eta_over_s_min + eta_over_s_slope*(T − + // Tc)*(T/Tc)^{eta_over_s_curv} with T_c=0.154 GeV + parameter_list.shear_2_min = + (getParameter(input_file, "shear_viscosity_2_min", 0.08)); + parameter_list.shear_2_slope = + (getParameter(input_file, "shear_viscosity_2_slope", 1.0)); + parameter_list.shear_2_curv = + (getParameter(input_file, "shear_viscosity_2_curv", 0.0)); // If "T_dependent_Shear_to_S_ratio==3", - parameter_list.shear_3_T_kink_in_GeV = ( - getParameter(input_file, - "shear_viscosity_3_eta_over_s_T_kink_in_GeV", 0.16)); - parameter_list.shear_3_low_T_slope_in_GeV = ( - getParameter(input_file, - "shear_viscosity_3_eta_over_s_low_T_slope_in_GeV", 0.0)); - parameter_list.shear_3_high_T_slope_in_GeV = ( - getParameter(input_file, - "shear_viscosity_3_eta_over_s_high_T_slope_in_GeV", 0.0)); - parameter_list.shear_3_at_kink = ( - getParameter(input_file, "shear_viscosity_3_eta_over_s_at_kink", 0.08)); - - parameter_list.muB_dependent_shear_to_s = ( - getParameter(input_file, "muB_dependent_Shear_to_S_ratio", 0)); - parameter_list.shear_muBf0p4 = ( - getParameter(input_file, "shear_muBf0p4", 1.)); - parameter_list.shear_muBf0p2 = ( - getParameter(input_file, "shear_muBf0p2", - (1. + parameter_list.shear_muBf0p4)/2.)); - parameter_list.shear_muBDep_alpha = ( - getParameter(input_file, "shear_muBDep_alpha", 1.)); - parameter_list.shear_muBDep_slope = ( - getParameter(input_file, "shear_muBDep_slope", 1.0)); - parameter_list.shear_muBDep_scale = ( - getParameter(input_file, "shear_muBDep_scale", 0.6)); + parameter_list.shear_3_T_kink_in_GeV = (getParameter( + input_file, "shear_viscosity_3_eta_over_s_T_kink_in_GeV", 0.16)); + parameter_list.shear_3_low_T_slope_in_GeV = (getParameter( + input_file, "shear_viscosity_3_eta_over_s_low_T_slope_in_GeV", 0.0)); + parameter_list.shear_3_high_T_slope_in_GeV = (getParameter( + input_file, "shear_viscosity_3_eta_over_s_high_T_slope_in_GeV", 0.0)); + parameter_list.shear_3_at_kink = (getParameter( + input_file, "shear_viscosity_3_eta_over_s_at_kink", 0.08)); + + parameter_list.muB_dependent_shear_to_s = + (getParameter(input_file, "muB_dependent_Shear_to_S_ratio", 0)); + parameter_list.shear_muBf0p4 = + (getParameter(input_file, "shear_muBf0p4", 1.)); + parameter_list.shear_muBf0p2 = (getParameter( + input_file, "shear_muBf0p2", (1. + parameter_list.shear_muBf0p4) / 2.)); + parameter_list.shear_muBDep_alpha = + (getParameter(input_file, "shear_muBDep_alpha", 1.)); + parameter_list.shear_muBDep_slope = + (getParameter(input_file, "shear_muBDep_slope", 1.0)); + parameter_list.shear_muBDep_scale = + (getParameter(input_file, "shear_muBDep_scale", 0.6)); // type of bulk relaxation time parameterization - parameter_list.bulk_relaxation_type = ( - getParameter(input_file, "Bulk_relaxation_time_type", 0)); - parameter_list.bulk_relax_time_factor = ( - getParameter(input_file, "bulk_relax_time_factor", 1./14.55)); - - parameter_list.T_dependent_bulk_to_s = ( - getParameter(input_file, "T_dependent_Bulk_to_S_ratio", 1)); - parameter_list.T_dependent_bulk_to_s = ( - getParameter(input_file, "T_dependent_zeta_over_s", - parameter_list.T_dependent_bulk_to_s)); + parameter_list.bulk_relaxation_type = + (getParameter(input_file, "Bulk_relaxation_time_type", 0)); + parameter_list.bulk_relax_time_factor = + (getParameter(input_file, "bulk_relax_time_factor", 1. / 14.55)); + + parameter_list.T_dependent_bulk_to_s = + (getParameter(input_file, "T_dependent_Bulk_to_S_ratio", 1)); + parameter_list.T_dependent_bulk_to_s = (getParameter( + input_file, "T_dependent_zeta_over_s", + parameter_list.T_dependent_bulk_to_s)); // "T_dependent_Bulk_to_S_ratio=2", // bulk viscosity is parametrized as with "A", "G" and "Tc" as // "A*(1/(1+((T-Tc)/G)^2)" - parameter_list.bulk_2_normalisation = ( - getParameter(input_file, "bulk_viscosity_2_normalisation", 0.33)); - parameter_list.bulk_2_width_in_GeV = ( - getParameter(input_file, "bulk_viscosity_2_width_in_GeV", 0.08)); - parameter_list.bulk_2_peak_in_GeV = ( - getParameter(input_file, "bulk_viscosity_2_peak_in_GeV", 0.18)); + parameter_list.bulk_2_normalisation = + (getParameter(input_file, "bulk_viscosity_2_normalisation", 0.33)); + parameter_list.bulk_2_width_in_GeV = + (getParameter(input_file, "bulk_viscosity_2_width_in_GeV", 0.08)); + parameter_list.bulk_2_peak_in_GeV = + (getParameter(input_file, "bulk_viscosity_2_peak_in_GeV", 0.18)); // "T_dependent_Bulk_to_S_ratio==3", - parameter_list.bulk_3_max = ( - getParameter(input_file, "bulk_viscosity_3_zeta_over_s_max", 0.1)); - parameter_list.bulk_3_width_in_GeV = ( - getParameter(input_file, - "bulk_viscosity_3_zeta_over_s_width_in_GeV", 0.05)); - parameter_list.bulk_3_T_peak_in_GeV = ( - getParameter(input_file, - "bulk_viscosity_3_zeta_over_s_T_peak_in_GeV", 0.18)); - parameter_list.bulk_3_lambda_asymm = ( - getParameter(input_file, - "bulk_viscosity_3_zeta_over_s_lambda_asymm", 0.0)); + parameter_list.bulk_3_max = + (getParameter(input_file, "bulk_viscosity_3_zeta_over_s_max", 0.1)); + parameter_list.bulk_3_width_in_GeV = (getParameter( + input_file, "bulk_viscosity_3_zeta_over_s_width_in_GeV", 0.05)); + parameter_list.bulk_3_T_peak_in_GeV = (getParameter( + input_file, "bulk_viscosity_3_zeta_over_s_T_peak_in_GeV", 0.18)); + parameter_list.bulk_3_lambda_asymm = (getParameter( + input_file, "bulk_viscosity_3_zeta_over_s_lambda_asymm", 0.0)); // "T_dependent_Bulk_to_S_ratio==10", - parameter_list.bulk_10_max = ( - getParameter(input_file, "bulk_viscosity_10_max", 0.0)); - parameter_list.bulk_10_max_muB0p4 = ( - getParameter(input_file, "bulk_viscosity_10_max_muB0p4", - parameter_list.bulk_10_max)); - parameter_list.bulk_10_max_muB0p2 = ( - getParameter(input_file, "bulk_viscosity_10_max_muB0p2", - (parameter_list.bulk_10_max - + parameter_list.bulk_10_max_muB0p4)/2.)); - parameter_list.bulk_10_width_high = ( - getParameter(input_file, "bulk_viscosity_10_width_high", 0.1)); // GeV - parameter_list.bulk_10_width_low = ( - getParameter(input_file, "bulk_viscosity_10_width_low", 0.015)); // GeV - parameter_list.bulk_10_Tpeak = ( - getParameter(input_file, "bulk_viscosity_10_T_peak", 0.17)); // GeV - parameter_list.bulk_10_Tpeak_muBcurv = ( - getParameter(input_file, "bulk_viscosity_10_T_peak_muBcurv", 0.0)); + parameter_list.bulk_10_max = + (getParameter(input_file, "bulk_viscosity_10_max", 0.0)); + parameter_list.bulk_10_max_muB0p4 = (getParameter( + input_file, "bulk_viscosity_10_max_muB0p4", + parameter_list.bulk_10_max)); + parameter_list.bulk_10_max_muB0p2 = (getParameter( + input_file, "bulk_viscosity_10_max_muB0p2", + (parameter_list.bulk_10_max + parameter_list.bulk_10_max_muB0p4) / 2.)); + parameter_list.bulk_10_width_high = + (getParameter(input_file, "bulk_viscosity_10_width_high", 0.1)); // GeV + parameter_list.bulk_10_width_low = (getParameter( + input_file, "bulk_viscosity_10_width_low", 0.015)); // GeV + parameter_list.bulk_10_Tpeak = + (getParameter(input_file, "bulk_viscosity_10_T_peak", 0.17)); // GeV + parameter_list.bulk_10_Tpeak_muBcurv = + (getParameter(input_file, "bulk_viscosity_10_T_peak_muBcurv", 0.0)); // net baryon diffusion: kappa coefficient - parameter_list.kappa_coefficient = ( - getParameter(input_file, "kappa_coefficient", 0.0)); + parameter_list.kappa_coefficient = + (getParameter(input_file, "kappa_coefficient", 0.0)); - parameter_list.store_hydro_info_in_memory = ( - getParameter(input_file, "store_hydro_info_in_memory", 0)); + parameter_list.store_hydro_info_in_memory = + (getParameter(input_file, "store_hydro_info_in_memory", 0)); // output_evolution_data: // 2: output bulk information in binary format - parameter_list.outputEvolutionData = ( - getParameter(input_file, "output_evolution_data", 0)); + parameter_list.outputEvolutionData = + (getParameter(input_file, "output_evolution_data", 0)); // only works for output_evolution_data == 1 - parameter_list.outputBinaryEvolution = ( - getParameter(input_file, "outputBinaryEvolution", 0)); - parameter_list.output_hydro_params_header = ( - getParameter(input_file, "output_hydro_params_header", 0)); - - parameter_list.output_movie_flag = ( - getParameter(input_file, "output_movie_flag", 0)); - parameter_list.output_outofequilibriumsize = ( - getParameter(input_file, "output_outofequilibriumsize", 0)); - parameter_list.output_vorticity = ( - getParameter(input_file, "output_vorticity", 0)); - parameter_list.output_hydro_debug_info = ( - getParameter(input_file, "output_hydro_debug_info", 0)); + parameter_list.outputBinaryEvolution = + (getParameter(input_file, "outputBinaryEvolution", 0)); + parameter_list.output_hydro_params_header = + (getParameter(input_file, "output_hydro_params_header", 0)); + + parameter_list.output_movie_flag = + (getParameter(input_file, "output_movie_flag", 0)); + parameter_list.output_outofequilibriumsize = + (getParameter(input_file, "output_outofequilibriumsize", 0)); + parameter_list.output_vorticity = + (getParameter(input_file, "output_vorticity", 0)); + parameter_list.output_hydro_debug_info = + (getParameter(input_file, "output_hydro_debug_info", 0)); // The evolution is outputted every // "output_evolution_every_N_timesteps" timesteps - parameter_list.output_evolution_every_N_timesteps = ( - getParameter(input_file, "output_evolution_every_N_timesteps", 1)); - parameter_list.output_evolution_every_N_x = ( - getParameter(input_file, "output_evolution_every_N_x", 1)); - parameter_list.output_evolution_every_N_y = ( - parameter_list.output_evolution_every_N_x); - parameter_list.output_evolution_every_N_eta = ( - getParameter(input_file, "output_evolution_every_N_eta", 1)); - parameter_list.output_evolution_T_cut = ( - getParameter(input_file, "output_evolution_T_cut", 0.105)); - parameter_list.output_evolution_e_cut = ( - getParameter(input_file, "output_evolution_e_cut", 0.15)); // GeV/fm^3 + parameter_list.output_evolution_every_N_timesteps = + (getParameter(input_file, "output_evolution_every_N_timesteps", 1)); + parameter_list.output_evolution_every_N_x = + (getParameter(input_file, "output_evolution_every_N_x", 1)); + parameter_list.output_evolution_every_N_y = + (parameter_list.output_evolution_every_N_x); + parameter_list.output_evolution_every_N_eta = + (getParameter(input_file, "output_evolution_every_N_eta", 1)); + parameter_list.output_evolution_T_cut = + (getParameter(input_file, "output_evolution_T_cut", 0.105)); + parameter_list.output_evolution_e_cut = + (getParameter(input_file, "output_evolution_e_cut", 0.15)); // GeV/fm^3 ////////////////////////////////////////////////////////////////////////// // Freeze-out surface parameters ////////////////////////////////////////////////////////////////////////// // Do_FreezeOut_Yes_1_No_0 // set to 0 to bypass freeze out surface finder - parameter_list.doFreezeOut = ( - getParameter(input_file, "Do_FreezeOut_Yes_1_No_0", 1)); - parameter_list.doFreezeOut_lowtemp = ( - getParameter(input_file, "Do_FreezeOut_lowtemp", 1)); + parameter_list.doFreezeOut = + (getParameter(input_file, "Do_FreezeOut_Yes_1_No_0", 1)); + parameter_list.doFreezeOut_lowtemp = + (getParameter(input_file, "Do_FreezeOut_lowtemp", 1)); // freeze_out_method: // 2: Schenke's more complex method // 4: Cornelius - parameter_list.freezeOutMethod = ( - getParameter(input_file, "freeze_out_method", 4)); + parameter_list.freezeOutMethod = + (getParameter(input_file, "freeze_out_method", 4)); // use_eps_for_freeze_out: // 0: freeze out at constant temperature T_freeze // 1: freeze out at constant energy density epsilon_freeze // if set in input input_file, overide above defaults - parameter_list.useEpsFO = ( - getParameter(input_file, "use_eps_for_freeze_out", 1)); - parameter_list.freeze_eps_flag = ( - getParameter(input_file, "freeze_eps_flag", 0)); + parameter_list.useEpsFO = + (getParameter(input_file, "use_eps_for_freeze_out", 1)); + parameter_list.freeze_eps_flag = + (getParameter(input_file, "freeze_eps_flag", 0)); // T_freeze: freeze out temperature // only used with use_eps_for_freeze_out = 0 @@ -458,39 +447,38 @@ InitData read_in_parameters(std::string input_file) { // epsilon_freeze: freeze-out energy density in GeV/fm^3 // only used with use_eps_for_freeze_out = 1 // allow multiple parameter names for backward compitibility - parameter_list.epsilonFreeze = ( - getParameter(input_file, "eps_switch", 0.18)); // GeV/fm^3 - parameter_list.epsilonFreeze = ( - getParameter(input_file, "epsilon_freeze", - parameter_list.epsilonFreeze)); // GeV/fm^3 - parameter_list.epsilonFreeze = ( - getParameter(input_file, "eps_freeze_max", - parameter_list.epsilonFreeze)); // GeV/fm^3 - parameter_list.N_freeze_out = ( - getParameter(input_file, "N_freeze_out", 1)); + parameter_list.epsilonFreeze = + (getParameter(input_file, "eps_switch", 0.18)); // GeV/fm^3 + parameter_list.epsilonFreeze = (getParameter( + input_file, "epsilon_freeze", + parameter_list.epsilonFreeze)); // GeV/fm^3 + parameter_list.epsilonFreeze = (getParameter( + input_file, "eps_freeze_max", + parameter_list.epsilonFreeze)); // GeV/fm^3 + parameter_list.N_freeze_out = + (getParameter(input_file, "N_freeze_out", 1)); } if (parameter_list.N_freeze_out > 1) { - parameter_list.eps_freeze_max = ( - getParameter(input_file, "eps_freeze_max", 0.18)); - parameter_list.eps_freeze_min = ( - getParameter(input_file, "eps_freeze_min", 0.18)); + parameter_list.eps_freeze_max = + (getParameter(input_file, "eps_freeze_max", 0.18)); + parameter_list.eps_freeze_min = + (getParameter(input_file, "eps_freeze_min", 0.18)); } else { parameter_list.eps_freeze_min = parameter_list.epsilonFreeze; parameter_list.eps_freeze_max = parameter_list.epsilonFreeze; } //! Maximum starting time for freeze-out surface - parameter_list.freezeOutTauStartMax = ( - getParameter(input_file, "freeze_out_tau_start_max", 2.)); + parameter_list.freezeOutTauStartMax = + (getParameter(input_file, "freeze_out_tau_start_max", 2.)); string temp_freeze_list_filename = "eps_freeze_list_s95p_v1.dat"; tempinput = Util::StringFind4(input_file, "freeze_list_filename"); - if (tempinput != "empty") - temp_freeze_list_filename.assign(tempinput); + if (tempinput != "empty") temp_freeze_list_filename.assign(tempinput); parameter_list.freeze_list_filename.assign(temp_freeze_list_filename); - int temp_freeze_surface_binary = ( - getParameter(input_file, "freeze_surface_in_binary", 1)); + int temp_freeze_surface_binary = + (getParameter(input_file, "freeze_surface_in_binary", 1)); if (temp_freeze_surface_binary == 0) { parameter_list.freeze_surface_in_binary = false; } else { @@ -499,14 +487,12 @@ InitData read_in_parameters(std::string input_file) { // average_surface_over_this_many_time_steps: // Only save every N timesteps for finding freeze out surface - parameter_list.facTau = ( - getParameter(input_file, - "average_surface_over_this_many_time_steps", 1)); + parameter_list.facTau = (getParameter( + input_file, "average_surface_over_this_many_time_steps", 1)); parameter_list.fac_x = getParameter(input_file, "freeze_Ncell_x_step", 1); parameter_list.fac_y = parameter_list.fac_x; - parameter_list.fac_eta = ( - getParameter(input_file, "freeze_Ncell_eta_step", 1)); - + parameter_list.fac_eta = + (getParameter(input_file, "freeze_Ncell_eta_step", 1)); ////////////////////////////////////////////////////////////////////////// // Cooper-Frye (mode 3) @@ -514,21 +500,21 @@ InitData read_in_parameters(std::string input_file) { // particle_spectrum_to_compute: // 0: Do all up to number_of_particles_to_include // any natural number: Do the particle with this (internal) ID - parameter_list.particleSpectrumNumber = ( - getParameter(input_file, "particle_spectrum_to_compute", 0)); + parameter_list.particleSpectrumNumber = + (getParameter(input_file, "particle_spectrum_to_compute", 0)); // number_of_particles_to_include: // This determines up to which particle in the list spectra // should be computed (mode=3) or resonances should be included (mode=4) // current maximum = 319 - parameter_list.NumberOfParticlesToInclude = ( - getParameter(input_file, "number_of_particles_to_include", 2)); + parameter_list.NumberOfParticlesToInclude = + (getParameter(input_file, "number_of_particles_to_include", 2)); // for calculation of spectra: // max_pseudorapidity: // spectra calculated from zero to this pseudorapidity in +eta and -eta - parameter_list.max_pseudorapidity = ( - getParameter(input_file, "max_pseudorapidity", 5.0)); + parameter_list.max_pseudorapidity = + (getParameter(input_file, "max_pseudorapidity", 5.0)); parameter_list.pseudo_steps = getParameter(input_file, "pseudo_steps", 51); // steps in azimuthal angle in calculation of spectra @@ -548,34 +534,34 @@ InitData read_in_parameters(std::string input_file) { // Include_deltaf: // Looks like 0 sets delta_f=0, 1 uses standard quadratic ansatz, // and 2 is supposed to use p^(2-alpha) - parameter_list.include_deltaf = ( - getParameter(input_file, "Include_deltaf", 1)); - parameter_list.include_deltaf_bulk = ( - getParameter(input_file, "Include_deltaf_bulk", 0)); - parameter_list.include_deltaf_qmu = ( - getParameter(input_file, "Include_deltaf_qmu", 0)); - parameter_list.deltaf_14moments = ( - getParameter(input_file, "deltaf_14moments", 0)); + parameter_list.include_deltaf = + (getParameter(input_file, "Include_deltaf", 1)); + parameter_list.include_deltaf_bulk = + (getParameter(input_file, "Include_deltaf_bulk", 0)); + parameter_list.include_deltaf_qmu = + (getParameter(input_file, "Include_deltaf_qmu", 0)); + parameter_list.deltaf_14moments = + (getParameter(input_file, "deltaf_14moments", 0)); ////////////////////////////////////////////////////////////////////////// // spectra vn analysis for mode 13 and 14 ////////////////////////////////////////////////////////////////////////// parameter_list.dNdy_y_min = getParameter(input_file, "dNdy_y_min", -0.5); parameter_list.dNdy_y_max = getParameter(input_file, "dNdy_y_max", 0.5); - parameter_list.dNdy_eta_min = ( - getParameter(input_file, "dNdy_eta_min", -2.0)); - parameter_list.dNdy_eta_max = ( - getParameter(input_file, "dNdy_eta_max", 2.0)); + parameter_list.dNdy_eta_min = + (getParameter(input_file, "dNdy_eta_min", -2.0)); + parameter_list.dNdy_eta_max = + (getParameter(input_file, "dNdy_eta_max", 2.0)); parameter_list.dNdy_nrap = getParameter(input_file, "dNdy_nrap", 30); - parameter_list.dNdyptdpt_y_min = ( - getParameter(input_file, "dNdyptdpt_y_min", -0.5)); - parameter_list.dNdyptdpt_y_max = ( - getParameter(input_file, "dNdyptdpt_y_max", 0.5)); - parameter_list.dNdyptdpt_eta_min = ( - getParameter(input_file, "dNdyptdpt_eta_min", -0.5)); - parameter_list.dNdyptdpt_eta_max = ( - getParameter(input_file, "dNdyptdpt_eta_max", 0.5)); + parameter_list.dNdyptdpt_y_min = + (getParameter(input_file, "dNdyptdpt_y_min", -0.5)); + parameter_list.dNdyptdpt_y_max = + (getParameter(input_file, "dNdyptdpt_y_max", 0.5)); + parameter_list.dNdyptdpt_eta_min = + (getParameter(input_file, "dNdyptdpt_eta_min", -0.5)); + parameter_list.dNdyptdpt_eta_max = + (getParameter(input_file, "dNdyptdpt_eta_max", 0.5)); music_message.info("Done read_in_parameters."); check_parameters(parameter_list, input_file); @@ -583,14 +569,12 @@ InitData read_in_parameters(std::string input_file) { return parameter_list; } - -void set_parameter(InitData ¶meter_list, std::string parameter_name, - double value) { +void set_parameter( + InitData ¶meter_list, std::string parameter_name, double value) { if (parameter_name == "MUSIC_mode") parameter_list.mode = static_cast(value); - if (parameter_name == "Initial_time_tau_0") - parameter_list.tau0 = value; + if (parameter_name == "Initial_time_tau_0") parameter_list.tau0 = value; if (parameter_name == "output_evolution_data") parameter_list.outputEvolutionData = static_cast(value); @@ -607,11 +591,9 @@ void set_parameter(InitData ¶meter_list, std::string parameter_name, if (parameter_name == "Include_Shear_Visc_Yes_1_No_0") parameter_list.turn_on_shear = static_cast(value); - if (parameter_name == "Shear_to_S_ratio") - parameter_list.shear_to_s = value; + if (parameter_name == "Shear_to_S_ratio") parameter_list.shear_to_s = value; - if (parameter_name == "T_freeze") - parameter_list.TFO = value; + if (parameter_name == "T_freeze") parameter_list.TFO = value; if (parameter_name == "Include_Bulk_Visc_Yes_1_No_0") parameter_list.turn_on_bulk = static_cast(value); @@ -658,7 +640,6 @@ void set_parameter(InitData ¶meter_list, std::string parameter_name, parameter_list.bulk_3_lambda_asymm = value; } - void check_parameters(InitData ¶meter_list, std::string input_file) { music_message.info("Checking input parameter list ... "); @@ -670,7 +651,7 @@ void check_parameters(InitData ¶meter_list, std::string input_file) { } if (parameter_list.initializeEntropy > 1 - || parameter_list.initializeEntropy < 0) { + || parameter_list.initializeEntropy < 0) { music_message.error("Must initialize with entropy or energy"); exit(1); } @@ -685,7 +666,7 @@ void check_parameters(InitData ¶meter_list, std::string input_file) { } else { if (parameter_list.epsilonFreeze <= 0) { music_message.error( - "Freeze out energy density must be greater than zero"); + "Freeze out energy density must be greater than zero"); exit(1); } } @@ -693,8 +674,7 @@ void check_parameters(InitData ¶meter_list, std::string input_file) { if (parameter_list.useEpsFO > 1 || parameter_list.useEpsFO < 0) { music_message << "did not set either freeze out energy density " << "or temperature, or invalid option for " - << "use_eps_for_freeze_out:" - << parameter_list.useEpsFO; + << "use_eps_for_freeze_out:" << parameter_list.useEpsFO; music_message.flush("error"); exit(1); } @@ -715,7 +695,7 @@ void check_parameters(InitData ¶meter_list, std::string input_file) { } if (parameter_list.whichEOS > 1 && parameter_list.whichEOS < 7 - && parameter_list.NumberOfParticlesToInclude > 320) { + && parameter_list.NumberOfParticlesToInclude > 320) { music_message << "Invalid option for number_of_particles_to_include:" << parameter_list.NumberOfParticlesToInclude; music_message.flush("error"); @@ -735,7 +715,7 @@ void check_parameters(InitData ¶meter_list, std::string input_file) { exit(1); } - double freeze_dtau = parameter_list.facTau*parameter_list.delta_tau; + double freeze_dtau = parameter_list.facTau * parameter_list.delta_tau; if (freeze_dtau > 1.) { music_message << "freeze-out time setp is too large! " << "freeze_dtau = " << freeze_dtau @@ -765,7 +745,7 @@ void check_parameters(InitData ¶meter_list, std::string input_file) { } if (parameter_list.neta < 2 && !parameter_list.boost_invariant) { - music_message << "Grid size in eta = " << parameter_list.neta + music_message << "Grid size in eta = " << parameter_list.neta << "is too small for a (3+1)-d run! " << "Please increase Grid_size_in_eta to be " << "larger than 2 at least!"; @@ -774,8 +754,8 @@ void check_parameters(InitData ¶meter_list, std::string input_file) { } if (parameter_list.boost_invariant && parameter_list.neta > 1) { - music_message << "Grid size in eta is set to " - << parameter_list.neta << " for a (2+1)-d simulation! " + music_message << "Grid size in eta is set to " << parameter_list.neta + << " for a (2+1)-d simulation! " << "This is redundant! Reset neta to 1! "; music_message.flush("warning"); parameter_list.neta = 1; @@ -789,32 +769,32 @@ void check_parameters(InitData ¶meter_list, std::string input_file) { parameter_list.eta_size = 0.0; } - if (parameter_list.delta_tau/parameter_list.delta_x - > parameter_list.dtaudxRatio) { + if (parameter_list.delta_tau / parameter_list.delta_x + > parameter_list.dtaudxRatio) { music_message << "Warning: Delta_Tau = " << parameter_list.delta_tau << " maybe too large! "; music_message.flush("warning"); bool reset_dtau_use_CFL_condition = true; int temp_CFL_condition = 1; - string tempinput = Util::StringFind4( - input_file, "reset_dtau_use_CFL_condition"); + string tempinput = + Util::StringFind4(input_file, "reset_dtau_use_CFL_condition"); if (tempinput != "empty") istringstream(tempinput) >> temp_CFL_condition; - if (temp_CFL_condition == 0) - reset_dtau_use_CFL_condition = false; + if (temp_CFL_condition == 0) reset_dtau_use_CFL_condition = false; parameter_list.resetDtau = reset_dtau_use_CFL_condition; if (reset_dtau_use_CFL_condition) { music_message.info("reset dtau using CFL condition."); double dtau_CFL = std::min( - std::min(parameter_list.delta_x*parameter_list.dtaudxRatio, - parameter_list.delta_y*parameter_list.dtaudxRatio), - parameter_list.tau0*parameter_list.delta_eta - *parameter_list.dtaudxRatio); + std::min( + parameter_list.delta_x * parameter_list.dtaudxRatio, + parameter_list.delta_y * parameter_list.dtaudxRatio), + parameter_list.tau0 * parameter_list.delta_eta + * parameter_list.dtaudxRatio); parameter_list.delta_tau = dtau_CFL; parameter_list.nt = static_cast( - parameter_list.tau_size/(parameter_list.delta_tau) + 0.5); + parameter_list.tau_size / (parameter_list.delta_tau) + 0.5); music_message << "read_in_parameters: Time step size = " << parameter_list.delta_tau; music_message.flush("info"); @@ -853,8 +833,7 @@ void check_parameters(InitData ¶meter_list, std::string input_file) { music_message.flush("info"); } - if (parameter_list.minmod_theta < 1. - || parameter_list.minmod_theta > 2.) { + if (parameter_list.minmod_theta < 1. || parameter_list.minmod_theta > 2.) { music_message << "minmod = " << parameter_list.minmod_theta << " is out of allowed range [1., 2]"; music_message.flush("error"); @@ -864,14 +843,13 @@ void check_parameters(InitData ¶meter_list, std::string input_file) { if (parameter_list.turn_on_shear == 0 && parameter_list.shear_to_s > 0) { music_message << "non-zero eta/s = " << parameter_list.shear_to_s << " is set with " - << "Include_Shear_Visc = " - << parameter_list.turn_on_shear + << "Include_Shear_Visc = " << parameter_list.turn_on_shear << ". Please check you want to run ideal hydro!"; music_message.flush("warning"); } if (parameter_list.turn_on_shear == 0 - && parameter_list.include_deltaf == 1) { + && parameter_list.include_deltaf == 1) { music_message << "hydro with zero shear viscosity does not need " << "shear delta f in Cooper-Frye! "; music_message << "input Include_deltaf = " @@ -882,7 +860,7 @@ void check_parameters(InitData ¶meter_list, std::string input_file) { } if (parameter_list.turn_on_bulk == 0 - && parameter_list.include_deltaf_bulk == 1) { + && parameter_list.include_deltaf_bulk == 1) { music_message << "hydro with zero bulk viscosity does not need " << "bulk delta f in Cooper-Frye!"; music_message << "input Include_deltaf_bulk = " @@ -913,7 +891,7 @@ void check_parameters(InitData ¶meter_list, std::string input_file) { } if (parameter_list.dNdy_y_min > parameter_list.dNdy_y_max) { - music_message << "dNdy_y_min = " << parameter_list.dNdy_y_min << " < " + music_message << "dNdy_y_min = " << parameter_list.dNdy_y_min << " < " << "dNdy_y_max = " << parameter_list.dNdy_y_max << "!"; music_message.flush("error"); exit(1); @@ -921,7 +899,7 @@ void check_parameters(InitData ¶meter_list, std::string input_file) { if (parameter_list.dNdy_eta_min > parameter_list.dNdy_eta_max) { music_message << "dNdy_eta_min = " << parameter_list.dNdy_eta_min - << " < " + << " < " << "dNdy_eta_max = " << parameter_list.dNdy_eta_max << "!"; music_message.flush("error"); @@ -929,18 +907,17 @@ void check_parameters(InitData ¶meter_list, std::string input_file) { } if (parameter_list.dNdyptdpt_y_min > parameter_list.dNdyptdpt_y_max) { - music_message << "dNdyptdpt_y_min = " - << parameter_list.dNdyptdpt_y_min << " < " - << "dNdyptdpt_y_max = " - << parameter_list.dNdyptdpt_y_max << "!"; + music_message << "dNdyptdpt_y_min = " << parameter_list.dNdyptdpt_y_min + << " < " + << "dNdyptdpt_y_max = " << parameter_list.dNdyptdpt_y_max + << "!"; music_message.flush("error"); exit(1); } - if (parameter_list.dNdyptdpt_eta_min - > parameter_list.dNdyptdpt_eta_max) { + if (parameter_list.dNdyptdpt_eta_min > parameter_list.dNdyptdpt_eta_max) { music_message << "dNdyptdpt_eta_min = " - << parameter_list.dNdyptdpt_eta_min << " < " + << parameter_list.dNdyptdpt_eta_min << " < " << "dNdyptdpt_eta_max = " << parameter_list.dNdyptdpt_eta_max << "!"; music_message.flush("error"); @@ -948,11 +925,10 @@ void check_parameters(InitData ¶meter_list, std::string input_file) { } music_message << "Finished checking input parameter list. " - << "Everything looks reasonable so far " - << emoji::success() << emoji::thumbup() - << emoji::beer() << emoji::beer() + << "Everything looks reasonable so far " << emoji::success() + << emoji::thumbup() << emoji::beer() << emoji::beer() << emoji::beerclinking() << emoji::beerclinking(); music_message.flush("info"); } -} +} // namespace ReadInParameters diff --git a/src/read_in_parameters.h b/src/read_in_parameters.h index becc5b04..b7000a29 100644 --- a/src/read_in_parameters.h +++ b/src/read_in_parameters.h @@ -4,16 +4,16 @@ #include #include "data.h" -#include "util.h" #include "emoji.h" #include "pretty_ostream.h" +#include "util.h" //! This class handles read in parameters namespace ReadInParameters { - InitData read_in_parameters(std::string input_file); - void check_parameters(InitData ¶meter_list, std::string input_file); - void set_parameter(InitData ¶meter_list, std::string parameter_name, - double value); -} +InitData read_in_parameters(std::string input_file); +void check_parameters(InitData ¶meter_list, std::string input_file); +void set_parameter( + InitData ¶meter_list, std::string parameter_name, double value); +} // namespace ReadInParameters #endif // SRC_READ_IN_PARAMETERS_H_ diff --git a/src/reconst.cpp b/src/reconst.cpp index dfd0021a..6a458200 100644 --- a/src/reconst.cpp +++ b/src/reconst.cpp @@ -1,16 +1,18 @@ // Copyright 2011 @ Bjoern Schenke, Sangyong Jeon, and Charles Gale -#include +#include "reconst.h" + #include #include +#include + #include "cell.h" #include "eos.h" -#include "reconst.h" -Reconst::Reconst(const EOS &eosIn, const int echo_level_in, int beastMode) : - eos(eosIn), - max_iter(100), - v_critical(0.563624), - echo_level(echo_level_in) { +Reconst::Reconst(const EOS &eosIn, const int echo_level_in, int beastMode) + : eos(eosIn), + max_iter(100), + v_critical(0.563624), + echo_level(echo_level_in) { if (beastMode != 0) { abs_err = 1e-8; rel_err = 1e-6; @@ -20,15 +22,13 @@ Reconst::Reconst(const EOS &eosIn, const int echo_level_in, int beastMode) : } } - - -ReconstCell Reconst::ReconstIt_shell(double tau, const TJbVec &tauq_vec, - const ReconstCell &grid_pt) { +ReconstCell Reconst::ReconstIt_shell( + double tau, const TJbVec &tauq_vec, const ReconstCell &grid_pt) { ReconstCell grid_p1; TJbVec q_vec; for (int i = 0; i < 5; i++) { - q_vec[i] = tauq_vec[i]/tau; + q_vec[i] = tauq_vec[i] / tau; } int flag = ReconstIt_velocity_Newton(grid_p1, tau, q_vec, grid_pt); @@ -42,85 +42,83 @@ ReconstCell Reconst::ReconstIt_shell(double tau, const TJbVec &tauq_vec, return grid_p1; } - //! This function reverts the grid information back its values //! at the previous time step -void Reconst::revert_grid(ReconstCell &grid_current, - const ReconstCell &grid_prev) const { - grid_current.e = grid_prev.e; +void Reconst::revert_grid( + ReconstCell &grid_current, const ReconstCell &grid_prev) const { + grid_current.e = grid_prev.e; grid_current.rhob = grid_prev.rhob; - grid_current.u = grid_prev.u; + grid_current.u = grid_prev.u; } - //! reconstruct TJb from q[0] - q[4] //! reconstruct velocity first for finite mu_B case //! use Newton's method to solve v and u0 -int Reconst::ReconstIt_velocity_Newton(ReconstCell &grid_p, double tau, - const TJbVec &q, - const ReconstCell &grid_pt) { - double K00 = q[1]*q[1] + q[2]*q[2] + q[3]*q[3]; - double M = sqrt(K00); +int Reconst::ReconstIt_velocity_Newton( + ReconstCell &grid_p, double tau, const TJbVec &q, + const ReconstCell &grid_pt) { + double K00 = q[1] * q[1] + q[2] * q[2] + q[3] * q[3]; + double M = sqrt(K00); double T00 = q[0]; - double J0 = q[4]; + double J0 = q[4]; if ((T00 < abs_err)) { // T^{0\mu} is too small, directly set it to // e = abs_err, u^\mu = (1, 0, 0, 0) - return(-2); + return (-2); } if (T00 < M) { if (echo_level > 9) { music_message.warning( - "Reconst:: can not find solution! Revert back~"); + "Reconst:: can not find solution! Revert back~"); music_message << "T00 = " << T00 << ", M = " << M; music_message.flush("warning"); } - return(-1); + return (-1); } double u[4], epsilon, pressure, rhob; double v_solution = 0.0; - double v_guess = sqrt(1. - 1./(grid_pt.u[0]*grid_pt.u[0] + abs_err)); - //if (v_guess != v_guess) { - // v_guess = 0.0; - //} - //int v_status = solve_velocity_Newton(v_guess, T00, M, J0, v_solution); + double v_guess = sqrt(1. - 1. / (grid_pt.u[0] * grid_pt.u[0] + abs_err)); + // if (v_guess != v_guess) { + // v_guess = 0.0; + // } + // int v_status = solve_velocity_Newton(v_guess, T00, M, J0, v_solution); int v_status = solve_v_Hybrid(v_guess, T00, M, J0, v_solution); if (v_status == 0) { - return(-1); + return (-1); } - u[0] = 1./(sqrt(1. - v_solution*v_solution) + v_solution*abs_err); - epsilon = T00 - v_solution*sqrt(K00); - rhob = J0/u[0]; + u[0] = 1. / (sqrt(1. - v_solution * v_solution) + v_solution * abs_err); + epsilon = T00 - v_solution * sqrt(K00); + rhob = J0 / u[0]; if (v_solution > v_critical && epsilon > 1e-6) { // for large velocity, solve u0 double u0_solution = u[0]; - //int u0_status = solve_u0_Newton(u0_guess, T00, K00, M, J0, u0_solution); + // int u0_status = solve_u0_Newton(u0_guess, T00, K00, M, J0, + // u0_solution); int u0_status = solve_u0_Hybrid(u[0], T00, K00, M, J0, u0_solution); if (u0_status == 1) { u[0] = u0_solution; - epsilon = T00 - sqrt((1. - 1./(u0_solution*u0_solution))*K00); - rhob = J0/u0_solution; + epsilon = T00 - sqrt((1. - 1. / (u0_solution * u0_solution)) * K00); + rhob = J0 / u0_solution; } } - double check_u0_var = std::abs(u[0] - grid_pt.u[0])/grid_pt.u[0]; + double check_u0_var = std::abs(u[0] - grid_pt.u[0]) / grid_pt.u[0]; if (check_u0_var > 100.) { if (grid_pt.e > 1e-6 && echo_level > 2) { music_message << "Reconst velocity Newton:: " << "u0 varies more than 100 times compared to " << "its value at previous time step"; music_message.flush("warning"); - music_message << "e = " << grid_pt.e - << ", u[0] = " << u[0] + music_message << "e = " << grid_pt.e << ", u[0] = " << u[0] << ", prev_u[0] = " << grid_pt.u[0]; music_message.flush("warning"); } - return(-1); + return (-1); } grid_p.e = epsilon; @@ -128,16 +126,16 @@ int Reconst::ReconstIt_velocity_Newton(ReconstCell &grid_p, double tau, pressure = eos.get_pressure(epsilon, rhob); // individual components of velocity - double velocity_inverse_factor = u[0]/(T00 + pressure); + double velocity_inverse_factor = u[0] / (T00 + pressure); - u[1] = q[1]*velocity_inverse_factor; - u[2] = q[2]*velocity_inverse_factor; - u[3] = q[3]*velocity_inverse_factor; + u[1] = q[1] * velocity_inverse_factor; + u[2] = q[2] * velocity_inverse_factor; + u[3] = q[3] * velocity_inverse_factor; // Correcting normalization of 4-velocity - double u_mag_sq = u[1]*u[1] + u[2]*u[2] + u[3]*u[3]; - if (std::abs(u[0]*u[0] - u_mag_sq - 1.0) > abs_err) { - double scalef = sqrt((u[0]*u[0] - 1.)/(u_mag_sq + abs_err)); + double u_mag_sq = u[1] * u[1] + u[2] * u[2] + u[3] * u[3]; + if (std::abs(u[0] * u[0] - u_mag_sq - 1.0) > abs_err) { + double scalef = sqrt((u[0] * u[0] - 1.) / (u_mag_sq + abs_err)); u[1] *= scalef; u[2] *= scalef; u[3] *= scalef; @@ -147,10 +145,9 @@ int Reconst::ReconstIt_velocity_Newton(ReconstCell &grid_p, double tau, grid_p.u[mu] = u[mu]; } - return(1); + return (1); } - //! This function regulate the grid information void Reconst::regulate_grid(ReconstCell &grid_cell, double elocal) const { grid_cell.e = std::max(abs_err, elocal); @@ -161,86 +158,85 @@ void Reconst::regulate_grid(ReconstCell &grid_cell, double elocal) const { grid_cell.u[3] = 0.0; } - -int Reconst::solve_velocity_Newton(const double v_guess, const double T00, - const double M, const double J0, - double &v_solution) { - int v_status = 1; - int iter = 0; +int Reconst::solve_velocity_Newton( + const double v_guess, const double T00, const double M, const double J0, + double &v_solution) { + int v_status = 1; + int iter = 0; double rel_error_v = 10.0; double abs_error_v = 10.0; - double v_next = v_guess; - double v_prev = v_guess; + double v_next = v_guess; + double v_prev = v_guess; double fv, dfdv; do { iter++; reconst_velocity_fdf(v_prev, T00, M, J0, fv, dfdv); - v_next = v_prev - (fv/dfdv); + v_next = v_prev - (fv / dfdv); v_next = std::max(0.0, std::min(1.0, v_next)); abs_error_v = fv; - rel_error_v = 2.*abs_error_v/(v_next + v_prev + abs_err); + rel_error_v = 2. * abs_error_v / (v_next + v_prev + abs_err); v_prev = v_next; if (iter > max_iter) { v_status = 0; break; } - } while (std::abs(abs_error_v) > abs_err && std::abs(rel_error_v) > rel_err); + } while (std::abs(abs_error_v) > abs_err + && std::abs(rel_error_v) > rel_err); v_solution = v_next; if (v_status == 0 && echo_level > 5) { music_message.warning( - "Reconst velocity Newton:: can not find solution!"); + "Reconst velocity Newton:: can not find solution!"); music_message.warning("output the results at the last iteration:"); music_message.warning("iter [lower, upper] root err(est)"); - music_message << iter << " [" << v_prev << ", " << v_next - << "] " << abs_error_v << " " << rel_error_v; + music_message << iter << " [" << v_prev << ", " << v_next << "] " + << abs_error_v << " " << rel_error_v; music_message.flush("warning"); } - return(v_status); + return (v_status); } - -int Reconst::solve_v_Hybrid(const double v_guess, const double T00, - const double M, const double J0, - double &v_solution) { +int Reconst::solve_v_Hybrid( + const double v_guess, const double T00, const double M, const double J0, + double &v_solution) { int v_status = 1; double v_l = std::max(0., v_guess - 0.05); double v_h = std::min(1., v_guess + 0.05); double fv_l, fv_h; reconst_velocity_f(v_l, T00, M, J0, fv_l); reconst_velocity_f(v_h, T00, M, J0, fv_h); - if (fv_l*fv_h > 0.) { + if (fv_l * fv_h > 0.) { v_l = 0; v_h = 1; reconst_velocity_f(v_l, T00, M, J0, fv_l); reconst_velocity_f(v_h, T00, M, J0, fv_h); - if (fv_l*fv_h > 0.) { + if (fv_l * fv_h > 0.) { v_status = 0; music_message.error( - "Reconst velocity Hybrid:: can not find solution!"); - return(v_status); + "Reconst velocity Hybrid:: can not find solution!"); + return (v_status); } } if (std::abs(fv_l) < abs_err) { v_solution = v_l; - return(1); + return (1); } if (std::abs(fv_h) < abs_err) { v_solution = v_h; - return(1); + return (1); } double dv_prev = v_h - v_l; double dv_curr = dv_prev; - double v_root = (v_h + v_l)/2.; + double v_root = (v_h + v_l) / 2.; double fv = 0; double dfdv = 0; if (dv_prev > 0.10) { reconst_velocity_fdf(v_root, T00, M, J0, fv, dfdv); } else { reconst_velocity_f(v_root, T00, M, J0, fv); - dfdv = (fv_h - fv_l)/(v_h - v_l); + dfdv = (fv_h - fv_l) / (v_h - v_l); } double abs_error_v = 10.0; double rel_error_v = 10.0; @@ -249,62 +245,59 @@ int Reconst::solve_v_Hybrid(const double v_guess, const double T00, iter_v++; double v_prev = v_root; double fv_prev = fv; - if (((v_root - v_h)*dfdv - fv)*((v_root - v_l)*dfdv - fv) > 0. - || (std::abs(2.*fv) > std::abs(dv_prev*dfdv))) { + if (((v_root - v_h) * dfdv - fv) * ((v_root - v_l) * dfdv - fv) > 0. + || (std::abs(2. * fv) > std::abs(dv_prev * dfdv))) { dv_prev = dv_curr; - dv_curr = (v_h - v_l)/2.; - v_root = v_l + dv_curr; + dv_curr = (v_h - v_l) / 2.; + v_root = v_l + dv_curr; } else { dv_prev = dv_curr; - dv_curr = fv/dfdv; - v_root = v_root - dv_curr; + dv_curr = fv / dfdv; + v_root = v_root - dv_curr; } abs_error_v = std::abs(dv_curr); - rel_error_v = abs_error_v/(v_root + abs_err); + rel_error_v = abs_error_v / (v_root + abs_err); if (std::abs(v_root - v_prev) > 0.1) { reconst_velocity_fdf(v_root, T00, M, J0, fv, dfdv); } else { reconst_velocity_f(v_root, T00, M, J0, fv); - dfdv = (fv - fv_prev)/(v_root - v_prev + abs_err); + dfdv = (fv - fv_prev) / (v_root - v_prev + abs_err); } - if (fv*fv_l < 0.) { - v_h = v_root; + if (fv * fv_l < 0.) { + v_h = v_root; fv_h = fv; } else { - v_l = v_root; + v_l = v_root; fv_l = fv; } if (iter_v > max_iter) { v_status = 0; break; } - //if (iter_v > 10) { - // std::cout << "iter_v = " << iter_v - // << ", v = " << v_root - // << ", abs_err = " << abs_error_v - // << ", rel_err = " << rel_error_v << std::endl; - //} + // if (iter_v > 10) { + // std::cout << "iter_v = " << iter_v + // << ", v = " << v_root + // << ", abs_err = " << abs_error_v + // << ", rel_err = " << rel_error_v << std::endl; + // } } while (abs_error_v > abs_err && rel_error_v > rel_err); v_solution = v_root; if (v_status == 0 && echo_level > 5) { music_message.warning( - "Reconst velocity Hybrid:: can not find solution!"); - music_message.warning( - "output the results at the last iteration:"); + "Reconst velocity Hybrid:: can not find solution!"); + music_message.warning("output the results at the last iteration:"); music_message.warning("iter [lower, upper] root err(est)"); - music_message << iter_v << " [" << v_l << ", " - << v_h << "] " << abs_error_v << " " - << rel_error_v; + music_message << iter_v << " [" << v_l << ", " << v_h << "] " + << abs_error_v << " " << rel_error_v; music_message.flush("warning"); } - return(v_status); + return (v_status); } - -int Reconst::solve_u0_Newton(const double u0_guess, const double T00, - const double K00, const double M, const double J0, - double &u0_solution) { +int Reconst::solve_u0_Newton( + const double u0_guess, const double T00, const double K00, const double M, + const double J0, double &u0_solution) { int u0_status = 1; double u0_prev = u0_guess; double u0_next = u0_prev; @@ -315,10 +308,10 @@ int Reconst::solve_u0_Newton(const double u0_guess, const double T00, do { iter_u0++; reconst_u0_fdf(u0_prev, T00, K00, M, J0, fu0, dfdu0); - u0_next = u0_prev - fu0/dfdu0; + u0_next = u0_prev - fu0 / dfdu0; u0_next = std::max(1.0, u0_next); abs_error_u0 = fu0; - rel_error_u0 = 2.*abs_error_u0/(u0_next + u0_prev + abs_err); + rel_error_u0 = 2. * abs_error_u0 / (u0_next + u0_prev + abs_err); u0_prev = u0_next; if (iter_u0 > max_iter) { u0_status = 0; @@ -330,42 +323,39 @@ int Reconst::solve_u0_Newton(const double u0_guess, const double T00, u0_solution = u0_next; if (u0_status == 0 && echo_level > 5) { music_message.warning( - "Reconst velocity Newton:: can not find solution!"); - music_message.warning( - "output the results at the last iteration:"); + "Reconst velocity Newton:: can not find solution!"); + music_message.warning("output the results at the last iteration:"); music_message.warning("iter [lower, upper] root err(est)"); - music_message << iter_u0 << " [" << u0_prev << ", " - << u0_next << "] " << abs_error_u0 << " " - << rel_error_u0; + music_message << iter_u0 << " [" << u0_prev << ", " << u0_next + << "] " << abs_error_u0 << " " << rel_error_u0; music_message.flush("warning"); } - return(u0_status); + return (u0_status); } - -int Reconst::solve_u0_Hybrid(const double u0_guess, const double T00, - const double K00, const double M, const double J0, - double &u0_solution) { +int Reconst::solve_u0_Hybrid( + const double u0_guess, const double T00, const double K00, const double M, + const double J0, double &u0_solution) { int u0_status = 1; double u0_l = 1.0; double u0_h = 1e5; if (u0_guess >= 1.0) { - u0_l = std::max(u0_l, 0.99*u0_guess); - u0_h = 1.01*u0_guess; + u0_l = std::max(u0_l, 0.99 * u0_guess); + u0_h = 1.01 * u0_guess; } double fu0_l, fu0_h; reconst_u0_f(u0_l, T00, K00, M, J0, fu0_l); reconst_u0_f(u0_h, T00, K00, M, J0, fu0_h); if (std::abs(fu0_l) < abs_err) { u0_solution = u0_l; - return(1); + return (1); } if (std::abs(fu0_h) < abs_err) { u0_solution = u0_h; - return(1); + return (1); } - if (fu0_l*fu0_h > 0.) { + if (fu0_l * fu0_h > 0.) { u0_status = 0; if (echo_level > 5) { music_message << "Reconst u0 Hybrid:: can not find solution!"; @@ -374,15 +364,15 @@ int Reconst::solve_u0_Hybrid(const double u0_guess, const double T00, << ", M = " << M << ", J0 = " << J0; music_message.flush("error"); } - return(u0_status); + return (u0_status); } double du0_prev = u0_h - u0_l; double du0_curr = du0_prev; - double u0_root = (u0_h + u0_l)/2.; + double u0_root = (u0_h + u0_l) / 2.; double fu0 = 0; reconst_u0_f(u0_root, T00, K00, M, J0, fu0); - double dfdu0 = (fu0_h - fu0_l)/(u0_h - u0_l); + double dfdu0 = (fu0_h - fu0_l) / (u0_h - u0_l); double abs_error_u0 = 10.0; double rel_error_u0 = 10.0; int iter_u0 = 0; @@ -390,163 +380,155 @@ int Reconst::solve_u0_Hybrid(const double u0_guess, const double T00, iter_u0++; double u0_prev = u0_root; double fu0_prev = fu0; - if (((u0_root - u0_h)*dfdu0 - fu0)*((u0_root - u0_l)*dfdu0 - fu0) > 0. - || (std::abs(2.*fu0) > std::abs(du0_prev*dfdu0))) { + if (((u0_root - u0_h) * dfdu0 - fu0) * ((u0_root - u0_l) * dfdu0 - fu0) + > 0. + || (std::abs(2. * fu0) > std::abs(du0_prev * dfdu0))) { du0_prev = du0_curr; - du0_curr = (u0_h - u0_l)/2.; - u0_root = u0_l + du0_curr; + du0_curr = (u0_h - u0_l) / 2.; + u0_root = u0_l + du0_curr; } else { du0_prev = du0_curr; - du0_curr = fu0/dfdu0; - u0_root = u0_root - du0_curr; + du0_curr = fu0 / dfdu0; + u0_root = u0_root - du0_curr; } if (u0_root != u0_root) { u0_status = 0; break; } reconst_u0_f(u0_root, T00, K00, M, J0, fu0); - dfdu0 = (fu0 - fu0_prev)/(u0_root - u0_prev); + dfdu0 = (fu0 - fu0_prev) / (u0_root - u0_prev); abs_error_u0 = du0_curr; - rel_error_u0 = du0_curr/u0_root; - if (fu0*fu0_l < 0.) { - u0_h = u0_root; + rel_error_u0 = du0_curr / u0_root; + if (fu0 * fu0_l < 0.) { + u0_h = u0_root; fu0_h = fu0; } else { - u0_l = u0_root; + u0_l = u0_root; fu0_l = fu0; } if (iter_u0 > max_iter) { u0_status = 0; break; } - } while ( std::abs(abs_error_u0) > abs_err + } while (std::abs(abs_error_u0) > abs_err && std::abs(rel_error_u0) > rel_err); u0_solution = u0_root; - //std::cout << "iter_u0 = " << iter_u0 << std::endl; + // std::cout << "iter_u0 = " << iter_u0 << std::endl; if (u0_status == 0 && echo_level > 5) { music_message.warning( - "Reconst velocity Hybrid:: can not find solution!"); - music_message.warning( - "output the results at the last iteration:"); + "Reconst velocity Hybrid:: can not find solution!"); + music_message.warning("output the results at the last iteration:"); music_message.warning("iter [lower, upper] root err(est)"); - music_message << iter_u0 << " [" << u0_l << ", " - << u0_h << "] " << abs_error_u0 << " " - << rel_error_u0; + music_message << iter_u0 << " [" << u0_l << ", " << u0_h << "] " + << abs_error_u0 << " " << rel_error_u0; music_message.flush("warning"); } - return(u0_status); + return (u0_status); } - -void Reconst::reconst_velocity_f(const double v, const double T00, - const double M, const double J0, - double &fv) const { - const double epsilon = T00 - v*M; - const double rho = J0*sqrt(1. - v*v); +void Reconst::reconst_velocity_f( + const double v, const double T00, const double M, const double J0, + double &fv) const { + const double epsilon = T00 - v * M; + const double rho = J0 * sqrt(1. - v * v); double pressure = eos.get_pressure(epsilon, rho); - fv = v - M/(T00 + pressure); + fv = v - M / (T00 + pressure); } - -//void Reconst::reconst_velocity_fdf(const double v, const double T00, -// const double M, const double J0B, -// const double J0Q, const double J0S, -// double &fv, double &dfdv) const { -// const double epsilon = T00 - v*M; -// const double temp = sqrt(1. - v*v); -// const double rhob = J0B*temp; +// void Reconst::reconst_velocity_fdf(const double v, const double T00, +// const double M, const double J0B, +// const double J0Q, const double J0S, +// double &fv, double &dfdv) const { +// const double epsilon = T00 - v*M; +// const double temp = sqrt(1. - v*v); +// const double rhob = J0B*temp; // -// const double rhoq = J0Q*temp; -// const double rhos = J0S*temp; +// const double rhoq = J0Q*temp; +// const double rhos = J0S*temp; // -// double pressure = 0; -// double dPde = 0; -// double dPdrhob = 0; -// double dPdrhoq = 0; -// double dPdrhos = 0; -// eos.get_pressure_with_gradients(epsilon, rhob, rhoq, rhos, pressure, -// dPde, dPdrhob, dPdrhoq, dPdrhos); +// double pressure = 0; +// double dPde = 0; +// double dPdrhob = 0; +// double dPdrhoq = 0; +// double dPdrhos = 0; +// eos.get_pressure_with_gradients(epsilon, rhob, rhoq, rhos, pressure, +// dPde, dPdrhob, dPdrhoq, dPdrhos); // -// const double temp1 = T00 + pressure; -// const double temp2 = v/std::max(abs_err, temp); +// const double temp1 = T00 + pressure; +// const double temp2 = v/std::max(abs_err, temp); // -// fv = v - M/temp1; -// dfdv = 1. - M/(temp1*temp1)*(M*dPde + J0B*temp2*dPdrhob -// + J0Q*temp2*dPdrhoq + J0S*temp2*dPdrhos); -//} - - -void Reconst::reconst_velocity_fdf(const double v, const double T00, - const double M, const double J0, - double &fv, double &dfdv) const { +// fv = v - M/temp1; +// dfdv = 1. - M/(temp1*temp1)*(M*dPde + J0B*temp2*dPdrhob +// + J0Q*temp2*dPdrhoq + J0S*temp2*dPdrhos); +// } + +void Reconst::reconst_velocity_fdf( + const double v, const double T00, const double M, const double J0, + double &fv, double &dfdv) const { reconst_velocity_f(v, T00, M, J0, fv); double fv1; - double v1 = v*0.999; + double v1 = v * 0.999; reconst_velocity_f(v1, T00, M, J0, fv1); - dfdv = (fv - fv1)/(v - v1); + dfdv = (fv - fv1) / (v - v1); } - -void Reconst::reconst_u0_fdf(const double u0, const double T00, - const double K00, const double M, const double J0, - double &fu0, double &dfdu0) const { +void Reconst::reconst_u0_fdf( + const double u0, const double T00, const double K00, const double M, + const double J0, double &fu0, double &dfdu0) const { reconst_u0_f(u0, T00, K00, M, J0, fu0); - double u02 = u0*1.001; + double u02 = u0 * 1.001; double fu02; reconst_u0_f(u02, T00, K00, M, J0, fu02); - dfdu0 = (fu02 - fu0)/(u02 - u0); + dfdu0 = (fu02 - fu0) / (u02 - u0); } +void Reconst::reconst_u0_f( + const double u0, const double T00, const double K00, const double M, + const double J0B, double &fu0) const { + const double u0_inv = 1. / u0; + const double v = sqrt(1. - u0_inv * u0_inv); -void Reconst::reconst_u0_f(const double u0, const double T00, - const double K00, const double M, const double J0B, - double &fu0) const { - const double u0_inv = 1./u0; - const double v = sqrt(1. - u0_inv*u0_inv); - - const double epsilon = T00 - v*M; - const double rhob = J0B*u0_inv; + const double epsilon = T00 - v * M; + const double rhob = J0B * u0_inv; double pressure = eos.get_pressure(epsilon, rhob); - const double temp1 = 1. - K00/((T00 + pressure)*(T00 + pressure)); - fu0 = u0 - 1./sqrt(temp1); + const double temp1 = 1. - K00 / ((T00 + pressure) * (T00 + pressure)); + fu0 = u0 - 1. / sqrt(temp1); } - -//void Reconst::reconst_u0_fdf(const double u0, const double T00, -// const double K00, const double M, const double J0B, -// const double J0Q, const double J0S, -// double &fu0, double &dfdu0) const { -// const double u0_inv = 1./u0; -// const double v = sqrt(1. - u0_inv*u0_inv); +// void Reconst::reconst_u0_fdf(const double u0, const double T00, +// const double K00, const double M, const double +// J0B, const double J0Q, const double J0S, double +// &fu0, double &dfdu0) const { +// const double u0_inv = 1./u0; +// const double v = sqrt(1. - u0_inv*u0_inv); // -// const double epsilon = T00 - v*M; -// const double rhob = J0B*u0_inv; -// const double rhoq = J0Q*u0_inv; -// const double rhos = J0S*u0_inv; +// const double epsilon = T00 - v*M; +// const double rhob = J0B*u0_inv; +// const double rhoq = J0Q*u0_inv; +// const double rhos = J0S*u0_inv; // -// const double dedu0 = - M/std::max(abs_err, u0*u0*u0*v); -// const double drhobdu0 = - J0B/(u0*u0); -// const double drhoqdu0 = - J0Q/(u0*u0); -// const double drhosdu0 = - J0S/(u0*u0); +// const double dedu0 = - M/std::max(abs_err, u0*u0*u0*v); +// const double drhobdu0 = - J0B/(u0*u0); +// const double drhoqdu0 = - J0Q/(u0*u0); +// const double drhosdu0 = - J0S/(u0*u0); // -// double pressure = 0; -// double dPde = 0; -// double dPdrhob = 0; -// double dPdrhoq = 0; -// double dPdrhos = 0; -// eos.get_pressure_with_gradients(epsilon, rhob, rhoq, rhos, pressure, -// dPde, dPdrhob, dPdrhoq, dPdrhos); +// double pressure = 0; +// double dPde = 0; +// double dPdrhob = 0; +// double dPdrhoq = 0; +// double dPdrhos = 0; +// eos.get_pressure_with_gradients(epsilon, rhob, rhoq, rhos, pressure, +// dPde, dPdrhob, dPdrhoq, dPdrhos); // -// const double temp1 = std::max(abs_err*abs_err, -// (T00 + pressure)*(T00 + pressure) - K00); -// const double denorm1 = sqrt(temp1); -// const double temp = (T00 + pressure)/denorm1; +// const double temp1 = std::max(abs_err*abs_err, +// (T00 + pressure)*(T00 + pressure) - K00); +// const double denorm1 = sqrt(temp1); +// const double temp = (T00 + pressure)/denorm1; // -// fu0 = u0 - temp; -// dfdu0 = 1. + (dedu0*dPde + drhobdu0*dPdrhob + drhoqdu0*dPdrhoq -// + drhosdu0*dPdrhos)*K00/(temp1*denorm1); -//} - +// fu0 = u0 - temp; +// dfdu0 = 1. + (dedu0*dPde + drhobdu0*dPdrhob + drhoqdu0*dPdrhoq +// + drhosdu0*dPdrhos)*K00/(temp1*denorm1); +// } diff --git a/src/reconst.h b/src/reconst.h index 251379ab..c4ad88be 100644 --- a/src/reconst.h +++ b/src/reconst.h @@ -4,14 +4,15 @@ #include #include -#include "util.h" + #include "cell.h" +#include "data_struct.h" #include "eos.h" #include "pretty_ostream.h" -#include "data_struct.h" +#include "util.h" class Reconst { - private: + private: const EOS &eos; pretty_ostream music_message; @@ -22,51 +23,53 @@ class Reconst { const double v_critical; const int echo_level; - public: + public: Reconst() = delete; Reconst(const EOS &eos, const int echo_level_in, int beastMode); - ReconstCell ReconstIt_shell(double tau, const TJbVec &tauq_vec, - const ReconstCell &grid_pt); - - int get_max_iter() const {return(max_iter);} - int get_echo_level() const {return(echo_level);} - double get_abs_err() const {return(abs_err);} - double get_v_critical() const {return(v_critical);} - - void revert_grid(ReconstCell &grid_current, - const ReconstCell &grid_prev) const; - - int ReconstIt_velocity_Newton(ReconstCell &grid_p, double tau, - const TJbVec &q, const ReconstCell &grid_pt); - - void reconst_velocity_fdf(const double v, const double T00, const double M, - const double J0, double &fv, double &dfdv) const; - void reconst_velocity_f(const double v, const double T00, const double M, - const double J0, double &fv) const; - - int solve_velocity_Newton(const double v_guess, const double T00, - const double M, const double J0, - double &v_solution); - int solve_v_Hybrid(const double v_guess, const double T00, - const double M, const double J0, - double &v_solution); + ReconstCell ReconstIt_shell( + double tau, const TJbVec &tauq_vec, const ReconstCell &grid_pt); + + int get_max_iter() const { return (max_iter); } + int get_echo_level() const { return (echo_level); } + double get_abs_err() const { return (abs_err); } + double get_v_critical() const { return (v_critical); } + + void revert_grid( + ReconstCell &grid_current, const ReconstCell &grid_prev) const; + + int ReconstIt_velocity_Newton( + ReconstCell &grid_p, double tau, const TJbVec &q, + const ReconstCell &grid_pt); + + void reconst_velocity_fdf( + const double v, const double T00, const double M, const double J0, + double &fv, double &dfdv) const; + void reconst_velocity_f( + const double v, const double T00, const double M, const double J0, + double &fv) const; + + int solve_velocity_Newton( + const double v_guess, const double T00, const double M, const double J0, + double &v_solution); + int solve_v_Hybrid( + const double v_guess, const double T00, const double M, const double J0, + double &v_solution); void reconst_u0_f( - const double u0, const double T00, const double K00, - const double M, const double J0B, double &fu0) const; + const double u0, const double T00, const double K00, const double M, + const double J0B, double &fu0) const; void reconst_u0_fdf( - const double u0, const double T00, const double K00, - const double M, const double J0B, - double &fu0, double &dfdu0) const; + const double u0, const double T00, const double K00, const double M, + const double J0B, double &fu0, double &dfdu0) const; - int solve_u0_Newton(const double u0_guess, const double T00, - const double K00, const double M, const double J0, - double &u0_solution); + int solve_u0_Newton( + const double u0_guess, const double T00, const double K00, + const double M, const double J0, double &u0_solution); - int solve_u0_Hybrid(const double u0_guess, const double T00, - const double K00, const double M, const double J0, - double &u0_solution); + int solve_u0_Hybrid( + const double u0_guess, const double T00, const double K00, + const double M, const double J0, double &u0_solution); void regulate_grid(ReconstCell &grid_cell, double elocal) const; }; diff --git a/src/reconst_unittest.cpp b/src/reconst_unittest.cpp index 86c6035f..1aa6dce3 100644 --- a/src/reconst_unittest.cpp +++ b/src/reconst_unittest.cpp @@ -1,10 +1,12 @@ -#include -#include "eos.h" #include "reconst.h" -#include "doctest.h" -#include "data_struct.h" + +#include + #include "cell.h" +#include "data_struct.h" +#include "doctest.h" +#include "eos.h" TEST_CASE("Check Reconst constructor") { EOS eos_ideal(0); @@ -12,7 +14,9 @@ TEST_CASE("Check Reconst constructor") { CHECK(reconst_test.get_max_iter() == 100); CHECK(reconst_test.get_echo_level() == 9); CHECK(reconst_test.get_abs_err() == doctest::Approx(1e-16).epsilon(1e-16)); - CHECK(reconst_test.get_v_critical() == doctest::Approx(0.563624).epsilon(0.00001)); + CHECK( + reconst_test.get_v_critical() + == doctest::Approx(0.563624).epsilon(0.00001)); } TEST_CASE("Test Newton solver v") { @@ -24,63 +28,63 @@ TEST_CASE("Test Newton solver v") { double M0 = 1.0; double M = 0.5; - double v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); + double v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); std::cout << "check v = " << v_correct << std::endl; reconst_test.solve_velocity_Newton(0.0, M0, M, 0.0, v_sol); CHECK(v_sol == doctest::Approx(v_correct).epsilon(1e-16)); - + M0 = 1.0; M = 0.99; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); std::cout << "check v = " << v_correct << std::endl; reconst_test.solve_velocity_Newton(0.0, M0, M, 0.0, v_sol); CHECK(v_sol == doctest::Approx(v_correct).epsilon(1e-16)); - + M0 = 1.0; M = 1.0 - 1e-6; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); std::cout << "check v = " << v_correct << std::endl; reconst_test.solve_velocity_Newton(0.0, M0, M, 0.0, v_sol); CHECK(v_sol == doctest::Approx(v_correct).epsilon(1e-16)); - + M0 = 1.0; M = 1e-6; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); std::cout << "check v = " << v_correct << std::endl; reconst_test.solve_velocity_Newton(0.0, M0, M, 0.0, v_sol); CHECK(v_sol == doctest::Approx(v_correct).epsilon(1e-16)); - + M0 = 1.0; M = 1.0 - 1e-10; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); std::cout << "check v = " << v_correct << std::endl; reconst_test.solve_velocity_Newton(0.0, M0, M, 0.0, v_sol); CHECK(v_sol == doctest::Approx(v_correct).epsilon(1e-16)); - + M0 = 1.0; M = 1e-10; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); std::cout << "check v = " << v_correct << std::endl; reconst_test.solve_velocity_Newton(0.0, M0, M, 0.0, v_sol); CHECK(v_sol == doctest::Approx(v_correct).epsilon(1e-16)); - + M0 = 1e-8; M = 1e-12; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); std::cout << "check v = " << v_correct << std::endl; reconst_test.solve_velocity_Newton(0.0, M0, M, 0.0, v_sol); CHECK(v_sol == doctest::Approx(v_correct).epsilon(1e-16)); - + M0 = 1e-12; M = 3.23e-15; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); std::cout << "check v = " << v_correct << std::endl; reconst_test.solve_velocity_Newton(0.0, M0, M, 0.0, v_sol); CHECK(v_sol == doctest::Approx(v_correct).epsilon(1e-16)); - + M0 = 1e-14; M = M0 - 2.43e-18; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); std::cout << "check v = " << v_correct << std::endl; reconst_test.solve_velocity_Newton(0.0, M0, M, 0.0, v_sol); CHECK(v_sol == doctest::Approx(v_correct).epsilon(1e-16)); @@ -95,62 +99,62 @@ TEST_CASE("Test hybrid solver v") { double M0 = 1.0; double M = 0.5; - double v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); + double v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); std::cout << "check v = " << v_correct << std::endl; reconst_test.solve_v_Hybrid(0.0, M0, M, 0.0, v_sol); CHECK(v_sol == doctest::Approx(v_correct).epsilon(1e-16)); - + M0 = 1.0; M = 0.99; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); std::cout << "check v = " << v_correct << std::endl; reconst_test.solve_v_Hybrid(0.0, M0, M, 0.0, v_sol); CHECK(v_sol == doctest::Approx(v_correct).epsilon(1e-16)); - + M0 = 1.0; M = 1.0 - 1e-6; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); std::cout << "check v = " << v_correct << std::endl; reconst_test.solve_v_Hybrid(0.0, M0, M, 0.0, v_sol); CHECK(v_sol == doctest::Approx(v_correct).epsilon(2e-16)); - + M0 = 1.0; M = 1e-6; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); std::cout << "check v = " << v_correct << std::endl; reconst_test.solve_v_Hybrid(0.0, M0, M, 0.0, v_sol); - CHECK(v_sol == doctest::Approx(v_correct).epsilon(1e-16)); + CHECK(v_sol == doctest::Approx(v_correct).epsilon(1e-16)); M0 = 1.0; M = 1.0 - 1e-10; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); std::cout << "check v = " << v_correct << std::endl; reconst_test.solve_v_Hybrid(0.0, M0, M, 0.0, v_sol); CHECK(v_sol == doctest::Approx(v_correct).epsilon(1e-16)); - + M0 = 1.0; M = 1e-10; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); std::cout << "check v = " << v_correct << std::endl; reconst_test.solve_v_Hybrid(0.0, M0, M, 0.0, v_sol); CHECK(v_sol == doctest::Approx(v_correct).epsilon(1e-16)); - + M0 = 1e-8; M = 1e-12; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); std::cout << "check v = " << v_correct << std::endl; reconst_test.solve_v_Hybrid(0.0, M0, M, 0.0, v_sol); CHECK(v_sol == doctest::Approx(v_correct).epsilon(1e-16)); - + M0 = 1e-12; M = 3.23e-15; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); std::cout << "check v = " << v_correct << std::endl; reconst_test.solve_v_Hybrid(0.0, M0, M, 0.0, v_sol); CHECK(v_sol == doctest::Approx(v_correct).epsilon(1e-16)); - + M0 = 1e-14; M = M0 - 2.43e-18; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); std::cout << "check v = " << v_correct << std::endl; reconst_test.solve_v_Hybrid(0.0, M0, M, 0.0, v_sol); CHECK(v_sol == doctest::Approx(v_correct).epsilon(1e-16)); @@ -159,142 +163,141 @@ TEST_CASE("Test hybrid solver v") { TEST_CASE("Test Newton solver u0") { EOS eos_ideal(0); Reconst reconst_test(eos_ideal, 9); - + double u0_sol = 0.0; double M0 = 1.0; - double M = 0.0; - double v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); - double u0_correct = 1./sqrt(1. - v_correct*v_correct); - double utol = u0_correct*1e-14; + double M = 0.0; + double v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); + double u0_correct = 1. / sqrt(1. - v_correct * v_correct); + double utol = u0_correct * 1e-14; std::cout << "check u0 = " << u0_correct << std::endl; - reconst_test.solve_u0_Newton(100.0, M0, M*M, M, 0.0, u0_sol); + reconst_test.solve_u0_Newton(100.0, M0, M * M, M, 0.0, u0_sol); CHECK(u0_sol == doctest::Approx(u0_correct).epsilon(utol)); - + M0 = 1.0; - M = 0.5; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); - u0_correct = 1./sqrt(1. - v_correct*v_correct); - utol = u0_correct*1e-14; + M = 0.5; + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); + u0_correct = 1. / sqrt(1. - v_correct * v_correct); + utol = u0_correct * 1e-14; std::cout << "check u0 = " << u0_correct << std::endl; - reconst_test.solve_u0_Newton(100.0, M0, M*M, M, 0.0, u0_sol); + reconst_test.solve_u0_Newton(100.0, M0, M * M, M, 0.0, u0_sol); CHECK(u0_sol == doctest::Approx(u0_correct).epsilon(utol)); - + M0 = 1.0; - M = 1e-4; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); - u0_correct = 1./sqrt(1. - v_correct*v_correct); - utol = u0_correct*1e-14; + M = 1e-4; + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); + u0_correct = 1. / sqrt(1. - v_correct * v_correct); + utol = u0_correct * 1e-14; std::cout << "check u0 = " << u0_correct << std::endl; - reconst_test.solve_u0_Newton(100.0, M0, M*M, M, 0.0, u0_sol); + reconst_test.solve_u0_Newton(100.0, M0, M * M, M, 0.0, u0_sol); CHECK(u0_sol == doctest::Approx(u0_correct).epsilon(utol)); - + M0 = 1.0; - M = 0.999; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); - u0_correct = 1./sqrt(1. - v_correct*v_correct); - utol = u0_correct*1e-14; + M = 0.999; + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); + u0_correct = 1. / sqrt(1. - v_correct * v_correct); + utol = u0_correct * 1e-14; std::cout << "check u0 = " << u0_correct << std::endl; - reconst_test.solve_u0_Newton(100.0, M0, M*M, M, 0.0, u0_sol); + reconst_test.solve_u0_Newton(100.0, M0, M * M, M, 0.0, u0_sol); CHECK(u0_sol == doctest::Approx(u0_correct).epsilon(utol)); - + M0 = 1.0; - M = 1.0 - 1e-4; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); - u0_correct = 1./sqrt(1. - v_correct*v_correct); - utol = u0_correct*1e-14; + M = 1.0 - 1e-4; + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); + u0_correct = 1. / sqrt(1. - v_correct * v_correct); + utol = u0_correct * 1e-14; std::cout << "check u0 = " << u0_correct << std::endl; - reconst_test.solve_u0_Newton(100.0, M0, M*M, M, 0.0, u0_sol); + reconst_test.solve_u0_Newton(100.0, M0, M * M, M, 0.0, u0_sol); CHECK(u0_sol == doctest::Approx(u0_correct).epsilon(utol)); - + M0 = 1e-15; - M = M0 - 3.463e-18; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); - u0_correct = 1./sqrt(1. - v_correct*v_correct); - utol = u0_correct*1e-14; + M = M0 - 3.463e-18; + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); + u0_correct = 1. / sqrt(1. - v_correct * v_correct); + utol = u0_correct * 1e-14; std::cout << "check u0 = " << u0_correct << std::endl; - reconst_test.solve_u0_Newton(100.0, M0, M*M, M, 0.0, u0_sol); + reconst_test.solve_u0_Newton(100.0, M0, M * M, M, 0.0, u0_sol); CHECK(u0_sol == doctest::Approx(u0_correct).epsilon(utol)); - + M0 = 1e-15; - M = 3.463e-18; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); - u0_correct = 1./sqrt(1. - v_correct*v_correct); - utol = u0_correct*1e-14; + M = 3.463e-18; + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); + u0_correct = 1. / sqrt(1. - v_correct * v_correct); + utol = u0_correct * 1e-14; std::cout << "check u0 = " << u0_correct << std::endl; - reconst_test.solve_u0_Newton(100.0, M0, M*M, M, 0.0, u0_sol); + reconst_test.solve_u0_Newton(100.0, M0, M * M, M, 0.0, u0_sol); CHECK(u0_sol == doctest::Approx(u0_correct).epsilon(utol)); } TEST_CASE("Test Newton solver u0 hybrid") { EOS eos_ideal(0); Reconst reconst_test(eos_ideal, 9); - + double u0_sol = 0.0; double M0 = 1.0; - double M = 0.0; - double v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); - double u0_correct = 1./sqrt(1. - v_correct*v_correct); - double utol = u0_correct*1e-14; + double M = 0.0; + double v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); + double u0_correct = 1. / sqrt(1. - v_correct * v_correct); + double utol = u0_correct * 1e-14; std::cout << "check u0 = " << u0_correct << std::endl; - reconst_test.solve_u0_Hybrid(0.0, M0, M*M, M, 0.0, u0_sol); + reconst_test.solve_u0_Hybrid(0.0, M0, M * M, M, 0.0, u0_sol); CHECK(u0_sol == doctest::Approx(u0_correct).epsilon(utol)); - + M0 = 1.0; - M = 0.5; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); - u0_correct = 1./sqrt(1. - v_correct*v_correct); - utol = u0_correct*1e-14; + M = 0.5; + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); + u0_correct = 1. / sqrt(1. - v_correct * v_correct); + utol = u0_correct * 1e-14; std::cout << "check u0 = " << u0_correct << std::endl; - reconst_test.solve_u0_Hybrid(2.0, M0, M*M, M, 0.0, u0_sol); + reconst_test.solve_u0_Hybrid(2.0, M0, M * M, M, 0.0, u0_sol); CHECK(u0_sol == doctest::Approx(u0_correct).epsilon(utol)); - + M0 = 1.0; - M = 1e-4; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); - u0_correct = 1./sqrt(1. - v_correct*v_correct); - utol = u0_correct*1e-14; + M = 1e-4; + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); + u0_correct = 1. / sqrt(1. - v_correct * v_correct); + utol = u0_correct * 1e-14; std::cout << "check u0 = " << u0_correct << std::endl; - reconst_test.solve_u0_Hybrid(1.0, M0, M*M, M, 0.0, u0_sol); + reconst_test.solve_u0_Hybrid(1.0, M0, M * M, M, 0.0, u0_sol); CHECK(u0_sol == doctest::Approx(u0_correct).epsilon(utol)); - + M0 = 1.0; - M = 0.999; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); - u0_correct = 1./sqrt(1. - v_correct*v_correct); - utol = u0_correct*1e-14; + M = 0.999; + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); + u0_correct = 1. / sqrt(1. - v_correct * v_correct); + utol = u0_correct * 1e-14; std::cout << "check u0 = " << u0_correct << std::endl; - reconst_test.solve_u0_Hybrid(0.0, M0, M*M, M, 0.0, u0_sol); + reconst_test.solve_u0_Hybrid(0.0, M0, M * M, M, 0.0, u0_sol); CHECK(u0_sol == doctest::Approx(u0_correct).epsilon(utol)); - + M0 = 1.0; - M = 1.0 - 1e-4; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); - u0_correct = 1./sqrt(1. - v_correct*v_correct); - utol = u0_correct*1e-14; + M = 1.0 - 1e-4; + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); + u0_correct = 1. / sqrt(1. - v_correct * v_correct); + utol = u0_correct * 1e-14; std::cout << "check u0 = " << u0_correct << std::endl; - reconst_test.solve_u0_Hybrid(0.0, M0, M*M, M, 0.0, u0_sol); + reconst_test.solve_u0_Hybrid(0.0, M0, M * M, M, 0.0, u0_sol); CHECK(u0_sol == doctest::Approx(u0_correct).epsilon(utol)); - + M0 = 1e-15; - M = M0 - 3.463e-18; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); - u0_correct = 1./sqrt(1. - v_correct*v_correct); - utol = u0_correct*1e-14; + M = M0 - 3.463e-18; + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); + u0_correct = 1. / sqrt(1. - v_correct * v_correct); + utol = u0_correct * 1e-14; std::cout << "check u0 = " << u0_correct << std::endl; - reconst_test.solve_u0_Hybrid(0.0, M0, M*M, M, 0.0, u0_sol); + reconst_test.solve_u0_Hybrid(0.0, M0, M * M, M, 0.0, u0_sol); CHECK(u0_sol == doctest::Approx(u0_correct).epsilon(utol)); - + M0 = 1e-15; - M = 3.463e-18; - v_correct = 3.*M/(2.*M0 + sqrt(4.*M0*M0 - 3.*M*M)); - u0_correct = 1./sqrt(1. - v_correct*v_correct); - utol = u0_correct*1e-14; + M = 3.463e-18; + v_correct = 3. * M / (2. * M0 + sqrt(4. * M0 * M0 - 3. * M * M)); + u0_correct = 1. / sqrt(1. - v_correct * v_correct); + utol = u0_correct * 1e-14; std::cout << "check u0 = " << u0_correct << std::endl; - reconst_test.solve_u0_Hybrid(0.0, M0, M*M, M, 0.0, u0_sol); + reconst_test.solve_u0_Hybrid(0.0, M0, M * M, M, 0.0, u0_sol); CHECK(u0_sol == doctest::Approx(u0_correct).epsilon(utol)); } - TEST_CASE("Test reconst main function") { EOS eos_ideal(0); Reconst reconst_test(eos_ideal, 9); @@ -302,193 +305,240 @@ TEST_CASE("Test reconst main function") { const double rel_tol = 1e-12; const double abs_tol = 1e-16; - double tau = 2.0; - double e_local = 1.0; + double tau = 2.0; + double e_local = 1.0; double rhob_local = 0.0; - double p_local = eos_ideal.get_pressure(e_local, rhob_local); - double ux = 0.0; - double uy = 0.0; - double ueta = 0.0; - double utau = sqrt(1. + ux*ux + uy*uy + ueta*ueta); - TJbVec tauq_vec = {tau*((e_local + p_local)*utau*utau - p_local), - tau*(e_local + p_local)*utau*ux, - tau*(e_local + p_local)*utau*uy, - tau*(e_local + p_local)*utau*ueta, - tau*rhob_local*utau}; + double p_local = eos_ideal.get_pressure(e_local, rhob_local); + double ux = 0.0; + double uy = 0.0; + double ueta = 0.0; + double utau = sqrt(1. + ux * ux + uy * uy + ueta * ueta); + TJbVec tauq_vec = { + tau * ((e_local + p_local) * utau * utau - p_local), + tau * (e_local + p_local) * utau * ux, + tau * (e_local + p_local) * utau * uy, + tau * (e_local + p_local) * utau * ueta, tau * rhob_local * utau}; Cell_small temp_grid; temp_grid.epsilon = 1e-5; - temp_grid.u = {1.0, 0.0, 0.0, 0.0}; - temp_grid.Wmunu = {0.0}; + temp_grid.u = {1.0, 0.0, 0.0, 0.0}; + temp_grid.Wmunu = {0.0}; auto cell_sol = reconst_test.ReconstIt_shell(tau, tauq_vec, temp_grid); - CHECK(cell_sol.e == doctest::Approx(e_local).epsilon( - std::max(abs_tol, e_local*rel_tol))); - CHECK(cell_sol.rhob == doctest::Approx(rhob_local).epsilon( - std::max(abs_tol, rhob_local*rel_tol))); - CHECK(cell_sol.u[0] == doctest::Approx(utau).epsilon( - std::max(abs_tol, utau*rel_tol))); - CHECK(cell_sol.u[1] == doctest::Approx(ux).epsilon( - std::max(abs_tol, ux*rel_tol))); - CHECK(cell_sol.u[2] == doctest::Approx(uy).epsilon( - std::max(abs_tol, uy*rel_tol))); - CHECK(cell_sol.u[3] == doctest::Approx(ueta).epsilon( - std::max(abs_tol, ueta*rel_tol))); - - tau = 2.4; - e_local = 12.3; + CHECK( + cell_sol.e + == doctest::Approx(e_local).epsilon( + std::max(abs_tol, e_local * rel_tol))); + CHECK( + cell_sol.rhob + == doctest::Approx(rhob_local) + .epsilon(std::max(abs_tol, rhob_local * rel_tol))); + CHECK( + cell_sol.u[0] + == doctest::Approx(utau).epsilon(std::max(abs_tol, utau * rel_tol))); + CHECK( + cell_sol.u[1] + == doctest::Approx(ux).epsilon(std::max(abs_tol, ux * rel_tol))); + CHECK( + cell_sol.u[2] + == doctest::Approx(uy).epsilon(std::max(abs_tol, uy * rel_tol))); + CHECK( + cell_sol.u[3] + == doctest::Approx(ueta).epsilon(std::max(abs_tol, ueta * rel_tol))); + + tau = 2.4; + e_local = 12.3; rhob_local = 0.2; - p_local = eos_ideal.get_pressure(e_local, rhob_local); - ux = 0.1; - uy = 0.4; - ueta = 0.2; - utau = sqrt(1. + ux*ux + uy*uy + ueta*ueta); - tauq_vec = {tau*((e_local + p_local)*utau*utau - p_local), - tau*(e_local + p_local)*utau*ux, - tau*(e_local + p_local)*utau*uy, - tau*(e_local + p_local)*utau*ueta, - tau*rhob_local*utau}; + p_local = eos_ideal.get_pressure(e_local, rhob_local); + ux = 0.1; + uy = 0.4; + ueta = 0.2; + utau = sqrt(1. + ux * ux + uy * uy + ueta * ueta); + tauq_vec = { + tau * ((e_local + p_local) * utau * utau - p_local), + tau * (e_local + p_local) * utau * ux, + tau * (e_local + p_local) * utau * uy, + tau * (e_local + p_local) * utau * ueta, tau * rhob_local * utau}; cell_sol = reconst_test.ReconstIt_shell(tau, tauq_vec, temp_grid); - CHECK(cell_sol.e == doctest::Approx(e_local).epsilon( - std::max(abs_tol, e_local*rel_tol))); - CHECK(cell_sol.rhob == doctest::Approx(rhob_local).epsilon( - std::max(abs_tol, rhob_local*rel_tol))); - CHECK(cell_sol.u[0] == doctest::Approx(utau).epsilon( - std::max(abs_tol, utau*rel_tol))); - CHECK(cell_sol.u[1] == doctest::Approx(ux).epsilon( - std::max(abs_tol, ux*rel_tol))); - CHECK(cell_sol.u[2] == doctest::Approx(uy).epsilon( - std::max(abs_tol, uy*rel_tol))); - CHECK(cell_sol.u[3] == doctest::Approx(ueta).epsilon( - std::max(abs_tol, ueta*rel_tol))); - - tau = 5.2; - e_local = 2.6; + CHECK( + cell_sol.e + == doctest::Approx(e_local).epsilon( + std::max(abs_tol, e_local * rel_tol))); + CHECK( + cell_sol.rhob + == doctest::Approx(rhob_local) + .epsilon(std::max(abs_tol, rhob_local * rel_tol))); + CHECK( + cell_sol.u[0] + == doctest::Approx(utau).epsilon(std::max(abs_tol, utau * rel_tol))); + CHECK( + cell_sol.u[1] + == doctest::Approx(ux).epsilon(std::max(abs_tol, ux * rel_tol))); + CHECK( + cell_sol.u[2] + == doctest::Approx(uy).epsilon(std::max(abs_tol, uy * rel_tol))); + CHECK( + cell_sol.u[3] + == doctest::Approx(ueta).epsilon(std::max(abs_tol, ueta * rel_tol))); + + tau = 5.2; + e_local = 2.6; rhob_local = 23.; - p_local = eos_ideal.get_pressure(e_local, rhob_local); - ux = 1.3; - uy = 2.4; - ueta = 2.2; - utau = sqrt(1. + ux*ux + uy*uy + ueta*ueta); - tauq_vec = {tau*((e_local + p_local)*utau*utau - p_local), - tau*(e_local + p_local)*utau*ux, - tau*(e_local + p_local)*utau*uy, - tau*(e_local + p_local)*utau*ueta, - tau*rhob_local*utau}; + p_local = eos_ideal.get_pressure(e_local, rhob_local); + ux = 1.3; + uy = 2.4; + ueta = 2.2; + utau = sqrt(1. + ux * ux + uy * uy + ueta * ueta); + tauq_vec = { + tau * ((e_local + p_local) * utau * utau - p_local), + tau * (e_local + p_local) * utau * ux, + tau * (e_local + p_local) * utau * uy, + tau * (e_local + p_local) * utau * ueta, tau * rhob_local * utau}; cell_sol = reconst_test.ReconstIt_shell(tau, tauq_vec, temp_grid); - CHECK(cell_sol.e == doctest::Approx(e_local).epsilon( - std::max(abs_tol, e_local*rel_tol))); - CHECK(cell_sol.rhob == doctest::Approx(rhob_local).epsilon( - std::max(abs_tol, rhob_local*rel_tol))); - CHECK(cell_sol.u[0] == doctest::Approx(utau).epsilon( - std::max(abs_tol, utau*rel_tol))); - CHECK(cell_sol.u[1] == doctest::Approx(ux).epsilon( - std::max(abs_tol, ux*rel_tol))); - CHECK(cell_sol.u[2] == doctest::Approx(uy).epsilon( - std::max(abs_tol, uy*rel_tol))); - CHECK(cell_sol.u[3] == doctest::Approx(ueta).epsilon( - std::max(abs_tol, ueta*rel_tol))); - - tau = 5.2; - e_local = 1e-4; + CHECK( + cell_sol.e + == doctest::Approx(e_local).epsilon( + std::max(abs_tol, e_local * rel_tol))); + CHECK( + cell_sol.rhob + == doctest::Approx(rhob_local) + .epsilon(std::max(abs_tol, rhob_local * rel_tol))); + CHECK( + cell_sol.u[0] + == doctest::Approx(utau).epsilon(std::max(abs_tol, utau * rel_tol))); + CHECK( + cell_sol.u[1] + == doctest::Approx(ux).epsilon(std::max(abs_tol, ux * rel_tol))); + CHECK( + cell_sol.u[2] + == doctest::Approx(uy).epsilon(std::max(abs_tol, uy * rel_tol))); + CHECK( + cell_sol.u[3] + == doctest::Approx(ueta).epsilon(std::max(abs_tol, ueta * rel_tol))); + + tau = 5.2; + e_local = 1e-4; rhob_local = 0.0; - p_local = eos_ideal.get_pressure(e_local, rhob_local); - ux = 10.3; - uy = 2.4; - ueta = 2.2; - utau = sqrt(1. + ux*ux + uy*uy + ueta*ueta); - tauq_vec = {tau*((e_local + p_local)*utau*utau - p_local), - tau*(e_local + p_local)*utau*ux, - tau*(e_local + p_local)*utau*uy, - tau*(e_local + p_local)*utau*ueta, - tau*rhob_local*utau}; + p_local = eos_ideal.get_pressure(e_local, rhob_local); + ux = 10.3; + uy = 2.4; + ueta = 2.2; + utau = sqrt(1. + ux * ux + uy * uy + ueta * ueta); + tauq_vec = { + tau * ((e_local + p_local) * utau * utau - p_local), + tau * (e_local + p_local) * utau * ux, + tau * (e_local + p_local) * utau * uy, + tau * (e_local + p_local) * utau * ueta, tau * rhob_local * utau}; cell_sol = reconst_test.ReconstIt_shell(tau, tauq_vec, temp_grid); - CHECK(cell_sol.e == doctest::Approx(e_local).epsilon( - std::max(abs_tol, e_local*rel_tol))); - CHECK(cell_sol.rhob == doctest::Approx(rhob_local).epsilon( - std::max(abs_tol, rhob_local*rel_tol))); - CHECK(cell_sol.u[0] == doctest::Approx(utau).epsilon( - std::max(abs_tol, utau*rel_tol))); - CHECK(cell_sol.u[1] == doctest::Approx(ux).epsilon( - std::max(abs_tol, ux*rel_tol))); - CHECK(cell_sol.u[2] == doctest::Approx(uy).epsilon( - std::max(abs_tol, uy*rel_tol))); - CHECK(cell_sol.u[3] == doctest::Approx(ueta).epsilon( - std::max(abs_tol, ueta*rel_tol))); - - tau = 15.2; - e_local = 2.45e-8; + CHECK( + cell_sol.e + == doctest::Approx(e_local).epsilon( + std::max(abs_tol, e_local * rel_tol))); + CHECK( + cell_sol.rhob + == doctest::Approx(rhob_local) + .epsilon(std::max(abs_tol, rhob_local * rel_tol))); + CHECK( + cell_sol.u[0] + == doctest::Approx(utau).epsilon(std::max(abs_tol, utau * rel_tol))); + CHECK( + cell_sol.u[1] + == doctest::Approx(ux).epsilon(std::max(abs_tol, ux * rel_tol))); + CHECK( + cell_sol.u[2] + == doctest::Approx(uy).epsilon(std::max(abs_tol, uy * rel_tol))); + CHECK( + cell_sol.u[3] + == doctest::Approx(ueta).epsilon(std::max(abs_tol, ueta * rel_tol))); + + tau = 15.2; + e_local = 2.45e-8; rhob_local = 0.0; - p_local = eos_ideal.get_pressure(e_local, rhob_local); - ux = 1.3; - uy = 2.4; - ueta = 20.2; - utau = sqrt(1. + ux*ux + uy*uy + ueta*ueta); - tauq_vec = {tau*((e_local + p_local)*utau*utau - p_local), - tau*(e_local + p_local)*utau*ux, - tau*(e_local + p_local)*utau*uy, - tau*(e_local + p_local)*utau*ueta, - tau*rhob_local*utau}; + p_local = eos_ideal.get_pressure(e_local, rhob_local); + ux = 1.3; + uy = 2.4; + ueta = 20.2; + utau = sqrt(1. + ux * ux + uy * uy + ueta * ueta); + tauq_vec = { + tau * ((e_local + p_local) * utau * utau - p_local), + tau * (e_local + p_local) * utau * ux, + tau * (e_local + p_local) * utau * uy, + tau * (e_local + p_local) * utau * ueta, tau * rhob_local * utau}; cell_sol = reconst_test.ReconstIt_shell(tau, tauq_vec, temp_grid); - CHECK(cell_sol.e == doctest::Approx(e_local).epsilon( - std::max(abs_tol, e_local*rel_tol))); - CHECK(cell_sol.rhob == doctest::Approx(rhob_local).epsilon( - std::max(abs_tol, rhob_local*rel_tol))); - CHECK(cell_sol.u[0] == doctest::Approx(utau).epsilon( - std::max(abs_tol, utau*rel_tol))); - CHECK(cell_sol.u[1] == doctest::Approx(ux).epsilon( - std::max(abs_tol, ux*rel_tol))); - CHECK(cell_sol.u[2] == doctest::Approx(uy).epsilon( - std::max(abs_tol, uy*rel_tol))); - CHECK(cell_sol.u[3] == doctest::Approx(ueta).epsilon( - std::max(abs_tol, ueta*rel_tol))); - - tau = 7.43; - e_local = 3.21e-13; + CHECK( + cell_sol.e + == doctest::Approx(e_local).epsilon( + std::max(abs_tol, e_local * rel_tol))); + CHECK( + cell_sol.rhob + == doctest::Approx(rhob_local) + .epsilon(std::max(abs_tol, rhob_local * rel_tol))); + CHECK( + cell_sol.u[0] + == doctest::Approx(utau).epsilon(std::max(abs_tol, utau * rel_tol))); + CHECK( + cell_sol.u[1] + == doctest::Approx(ux).epsilon(std::max(abs_tol, ux * rel_tol))); + CHECK( + cell_sol.u[2] + == doctest::Approx(uy).epsilon(std::max(abs_tol, uy * rel_tol))); + CHECK( + cell_sol.u[3] + == doctest::Approx(ueta).epsilon(std::max(abs_tol, ueta * rel_tol))); + + tau = 7.43; + e_local = 3.21e-13; rhob_local = 0.0; - p_local = eos_ideal.get_pressure(e_local, rhob_local); - ux = 1.3; - uy = 65.4; - ueta = 0.2; - utau = sqrt(1. + ux*ux + uy*uy + ueta*ueta); - tauq_vec = {tau*((e_local + p_local)*utau*utau - p_local), - tau*(e_local + p_local)*utau*ux, - tau*(e_local + p_local)*utau*uy, - tau*(e_local + p_local)*utau*ueta, - tau*rhob_local*utau}; + p_local = eos_ideal.get_pressure(e_local, rhob_local); + ux = 1.3; + uy = 65.4; + ueta = 0.2; + utau = sqrt(1. + ux * ux + uy * uy + ueta * ueta); + tauq_vec = { + tau * ((e_local + p_local) * utau * utau - p_local), + tau * (e_local + p_local) * utau * ux, + tau * (e_local + p_local) * utau * uy, + tau * (e_local + p_local) * utau * ueta, tau * rhob_local * utau}; cell_sol = reconst_test.ReconstIt_shell(tau, tauq_vec, temp_grid); - CHECK(cell_sol.e == doctest::Approx(e_local).epsilon( - std::max(abs_tol, e_local*rel_tol))); - CHECK(cell_sol.rhob == doctest::Approx(rhob_local).epsilon( - std::max(abs_tol, rhob_local*rel_tol))); - CHECK(cell_sol.u[0] == doctest::Approx(utau).epsilon( - std::max(abs_tol, utau*rel_tol))); - CHECK(cell_sol.u[1] == doctest::Approx(ux).epsilon( - std::max(abs_tol, ux*rel_tol))); - CHECK(cell_sol.u[2] == doctest::Approx(uy).epsilon( - std::max(abs_tol, uy*rel_tol))); - CHECK(cell_sol.u[3] == doctest::Approx(ueta).epsilon( - std::max(abs_tol, ueta*rel_tol))); - + CHECK( + cell_sol.e + == doctest::Approx(e_local).epsilon( + std::max(abs_tol, e_local * rel_tol))); + CHECK( + cell_sol.rhob + == doctest::Approx(rhob_local) + .epsilon(std::max(abs_tol, rhob_local * rel_tol))); + CHECK( + cell_sol.u[0] + == doctest::Approx(utau).epsilon(std::max(abs_tol, utau * rel_tol))); + CHECK( + cell_sol.u[1] + == doctest::Approx(ux).epsilon(std::max(abs_tol, ux * rel_tol))); + CHECK( + cell_sol.u[2] + == doctest::Approx(uy).epsilon(std::max(abs_tol, uy * rel_tol))); + CHECK( + cell_sol.u[3] + == doctest::Approx(ueta).epsilon(std::max(abs_tol, ueta * rel_tol))); + temp_grid.u = {100.0, 0.0, 0.0, 0.0}; - tau = 1.0; - e_local = 3.21e-13; + tau = 1.0; + e_local = 3.21e-13; rhob_local = 0.0; - p_local = eos_ideal.get_pressure(e_local, rhob_local); - ux = 5642.; - uy = 65.4; - ueta = 0.2; - utau = sqrt(1. + ux*ux + uy*uy + ueta*ueta); - tauq_vec = {tau*((e_local + p_local)*utau*utau - p_local), - tau*(e_local + p_local)*utau*ux, - tau*(e_local + p_local)*utau*uy, - tau*(e_local + p_local)*utau*ueta, - tau*rhob_local*utau}; + p_local = eos_ideal.get_pressure(e_local, rhob_local); + ux = 5642.; + uy = 65.4; + ueta = 0.2; + utau = sqrt(1. + ux * ux + uy * uy + ueta * ueta); + tauq_vec = { + tau * ((e_local + p_local) * utau * utau - p_local), + tau * (e_local + p_local) * utau * ux, + tau * (e_local + p_local) * utau * uy, + tau * (e_local + p_local) * utau * ueta, tau * rhob_local * utau}; cell_sol = reconst_test.ReconstIt_shell(tau, tauq_vec, temp_grid); CHECK(cell_sol.e == doctest::Approx(e_local).epsilon(1e-20)); CHECK(cell_sol.rhob == doctest::Approx(rhob_local).epsilon(1e-20)); - CHECK(cell_sol.u[0] == doctest::Approx(utau).epsilon(utau*1e-11)); - CHECK(cell_sol.u[1] == doctest::Approx(ux).epsilon(ux*1e-11)); - CHECK(cell_sol.u[2] == doctest::Approx(uy).epsilon(uy*1e-9)); - CHECK(cell_sol.u[3] == doctest::Approx(ueta).epsilon(ueta*2e-8)); + CHECK(cell_sol.u[0] == doctest::Approx(utau).epsilon(utau * 1e-11)); + CHECK(cell_sol.u[1] == doctest::Approx(ux).epsilon(ux * 1e-11)); + CHECK(cell_sol.u[2] == doctest::Approx(uy).epsilon(uy * 1e-9)); + CHECK(cell_sol.u[3] == doctest::Approx(ueta).epsilon(ueta * 2e-8)); } - diff --git a/src/reso_decay.cpp b/src/reso_decay.cpp index accbb973..c4d40128 100644 --- a/src/reso_decay.cpp +++ b/src/reso_decay.cpp @@ -1,33 +1,33 @@ // ------------ resonance decays. adapted from azhydro ----------------- // -// These functions were adapted by Björn Schenke from the public version of the -// resonance decay calculation using the output -// generated by the hydrodynamical code azhydro0p2. The majority of the code was -// developed by Josef Sollfrank and Peter Kolb. Additional work and comments -// were added by Evan Frodermann, September 2005. -// Please refer to the papers -// J. Sollfrank, P. Koch, and U. Heinz, Phys. Lett B 252 (1990) and -// J. Sollfrank, P. Koch, and U. Heinz, Z. Phys. C 52 (1991) -// for a description of the formalism utilized in this program. +// These functions were adapted by Björn Schenke from the public version of the +// resonance decay calculation using the output +// generated by the hydrodynamical code azhydro0p2. The majority of the code +// was developed by Josef Sollfrank and Peter Kolb. Additional work and +// comments were added by Evan Frodermann, September 2005. Please refer to the +// papers J. Sollfrank, P. Koch, and U. Heinz, Phys. Lett B 252 (1990) and J. +// Sollfrank, P. Koch, and U. Heinz, Z. Phys. C 52 (1991) for a description of +// the formalism utilized in this program. #include + #include "freeze.h" #include "int.h" /************************************************* -* -* Edndp3 -* -* -**************************************************/ + * + * Edndp3 + * + * + **************************************************/ // This function interpolates the needed spectra for a given y, pt and phi. double Freeze::Edndp3(double yr, double ptr, double phirin, int res_num) { -// if pseudofreeze flag is set, yr is the *pseudorapidity* of the resonance + // if pseudofreeze flag is set, yr is the *pseudorapidity* of the resonance if (phirin < 0.0) { printf("ERROR: phir %15.8le < 0 !!! \n", phirin); exit(0); } - if(phirin > 2.0*M_PI) { + if (phirin > 2.0 * M_PI) { printf("ERROR: phir %15.8le > 2PI !!! \n", phirin); exit(0); } @@ -35,14 +35,14 @@ double Freeze::Edndp3(double yr, double ptr, double phirin, int res_num) { int pn = partid[MHALF + res_num]; // If pseudofreeze flag is set, - // dNdydptdphi is on a fixed grid in pseudorapidity. + // dNdydptdphi is on a fixed grid in pseudorapidity. // Set yr to the *pseudorapidity* of the resonance, // and then interpolate the yield at that value. if (pseudofreeze) { double yrtemp = yr; yr = PseudoRap(yrtemp, ptr, particleList[pn].mass); } - + if (ptr > particleList[pn].pt[particleList[pn].npt - 1]) { return 0.; } @@ -51,294 +51,352 @@ double Freeze::Edndp3(double yr, double ptr, double phirin, int res_num) { return 0.; } - int nphi = 1; - while ((phir > phiArray[nphi]) && (nphi<(particleList[pn].nphi-1))) { + int nphi = 1; + while ((phir > phiArray[nphi]) && (nphi < (particleList[pn].nphi - 1))) { nphi++; } - int npt = 1; - while (ptr > particleList[pn].pt[npt] && npt<(particleList[pn].npt - 1)) { + int npt = 1; + while (ptr > particleList[pn].pt[npt] && npt < (particleList[pn].npt - 1)) { npt++; } - int ny = 1; + int ny = 1; while (yr > particleList[pn].y[ny] && ny < (particleList[pn].ny - 1)) { ny++; } /* phi interpolation */ double f1 = Util::lin_int( - phiArray[nphi-1], phiArray[nphi], - particleList[pn].dNdydptdphi[ny-1][npt-1][nphi-1], - particleList[pn].dNdydptdphi[ny-1][npt-1][nphi], phir); + phiArray[nphi - 1], phiArray[nphi], + particleList[pn].dNdydptdphi[ny - 1][npt - 1][nphi - 1], + particleList[pn].dNdydptdphi[ny - 1][npt - 1][nphi], phir); double f2 = Util::lin_int( - phiArray[nphi-1], phiArray[nphi], - particleList[pn].dNdydptdphi[ny-1][npt][nphi-1], - particleList[pn].dNdydptdphi[ny-1][npt][nphi], phir); + phiArray[nphi - 1], phiArray[nphi], + particleList[pn].dNdydptdphi[ny - 1][npt][nphi - 1], + particleList[pn].dNdydptdphi[ny - 1][npt][nphi], phir); // security: if for some reason we got a negative number of particles // (happened in the viscous code at large eta sometimes) - if (f1 < 0.) - f1 = 1e-30; - if (f2 < 0.) - f2 = 1e-30; - + if (f1 < 0.) f1 = 1e-30; + if (f2 < 0.) f2 = 1e-30; + double f1s = f1; double f2s = f2; if (ptr > PTCHANGE && f1s > 0 && f2s > 0) { - f1 = log(f1); + f1 = log(f1); f2 = log(f2); } - double val1 = Util::lin_int(particleList[pn].pt[npt-1], - particleList[pn].pt[npt], f1, f2, ptr); + double val1 = Util::lin_int( + particleList[pn].pt[npt - 1], particleList[pn].pt[npt], f1, f2, ptr); if (ptr > PTCHANGE && f1s > 0 && f2s > 0) { val1 = exp(val1); } - + if (std::isnan(val1)) { - fprintf(stderr,"\n number=%d\n\n",res_num); - fprintf(stderr,"val1=%f\n",val1); - fprintf(stderr,"f1=%f\n",f1); - fprintf(stderr,"f2=%f\n",f2); - fprintf(stderr,"f1s=%f\n",f1s); - fprintf(stderr,"f2s=%f\n",f2s); - - fprintf(stderr,"pn=%d\n",pn); - fprintf(stderr,"ny=%d\n",ny); - fprintf(stderr,"npt=%d\n",npt); - fprintf(stderr,"nphi=%d\n",nphi); - fprintf(stderr,"dN..=%e\n",particleList[pn].dNdydptdphi[ny-1][npt-1][nphi-1]); - fprintf(stderr,"dN..=%e\n",particleList[pn].dNdydptdphi[ny][npt-1][nphi-1]); - fprintf(stderr,"dN..=%e\n",particleList[pn].dNdydptdphi[ny-1][npt][nphi-1]); - fprintf(stderr,"dN..=%e\n",particleList[pn].dNdydptdphi[ny-1][npt-1][nphi]); - fprintf(stderr,"dN..=%e\n",particleList[pn].dNdydptdphi[ny][npt][nphi-1]); - fprintf(stderr,"dN..=%e\n",particleList[pn].dNdydptdphi[ny-1][npt][nphi]); - fprintf(stderr,"dN..=%e\n",particleList[pn].dNdydptdphi[ny][npt-1][nphi]); - fprintf(stderr,"dN..=%e\n",particleList[pn].dNdydptdphi[ny][npt][nphi]); - fprintf(stderr,"phi1=%f\n",phiArray[nphi-1]); - fprintf(stderr,"phi2=%f\n",phiArray[nphi]); - fprintf(stderr,"pt1=%f\n",particleList[pn].pt[npt-1]); - fprintf(stderr,"pt2=%f\n",particleList[pn].pt[npt]); - fprintf(stderr,"y1=%f\n",particleList[pn].y[ny-1]); - fprintf(stderr,"y2=%f\n",particleList[pn].y[ny]); + fprintf(stderr, "\n number=%d\n\n", res_num); + fprintf(stderr, "val1=%f\n", val1); + fprintf(stderr, "f1=%f\n", f1); + fprintf(stderr, "f2=%f\n", f2); + fprintf(stderr, "f1s=%f\n", f1s); + fprintf(stderr, "f2s=%f\n", f2s); + + fprintf(stderr, "pn=%d\n", pn); + fprintf(stderr, "ny=%d\n", ny); + fprintf(stderr, "npt=%d\n", npt); + fprintf(stderr, "nphi=%d\n", nphi); + fprintf( + stderr, "dN..=%e\n", + particleList[pn].dNdydptdphi[ny - 1][npt - 1][nphi - 1]); + fprintf( + stderr, "dN..=%e\n", + particleList[pn].dNdydptdphi[ny][npt - 1][nphi - 1]); + fprintf( + stderr, "dN..=%e\n", + particleList[pn].dNdydptdphi[ny - 1][npt][nphi - 1]); + fprintf( + stderr, "dN..=%e\n", + particleList[pn].dNdydptdphi[ny - 1][npt - 1][nphi]); + fprintf( + stderr, "dN..=%e\n", + particleList[pn].dNdydptdphi[ny][npt][nphi - 1]); + fprintf( + stderr, "dN..=%e\n", + particleList[pn].dNdydptdphi[ny - 1][npt][nphi]); + fprintf( + stderr, "dN..=%e\n", + particleList[pn].dNdydptdphi[ny][npt - 1][nphi]); + fprintf( + stderr, "dN..=%e\n", particleList[pn].dNdydptdphi[ny][npt][nphi]); + fprintf(stderr, "phi1=%f\n", phiArray[nphi - 1]); + fprintf(stderr, "phi2=%f\n", phiArray[nphi]); + fprintf(stderr, "pt1=%f\n", particleList[pn].pt[npt - 1]); + fprintf(stderr, "pt2=%f\n", particleList[pn].pt[npt]); + fprintf(stderr, "y1=%f\n", particleList[pn].y[ny - 1]); + fprintf(stderr, "y2=%f\n", particleList[pn].y[ny]); } - f1 = Util::lin_int(phiArray[nphi-1], phiArray[nphi], - particleList[pn].dNdydptdphi[ny][npt-1][nphi-1], - particleList[pn].dNdydptdphi[ny][npt-1][nphi], phir); - f2 = Util::lin_int(phiArray[nphi-1], phiArray[nphi], - particleList[pn].dNdydptdphi[ny][npt][nphi-1], - particleList[pn].dNdydptdphi[ny][npt][nphi], phir); - + f1 = Util::lin_int( + phiArray[nphi - 1], phiArray[nphi], + particleList[pn].dNdydptdphi[ny][npt - 1][nphi - 1], + particleList[pn].dNdydptdphi[ny][npt - 1][nphi], phir); + f2 = Util::lin_int( + phiArray[nphi - 1], phiArray[nphi], + particleList[pn].dNdydptdphi[ny][npt][nphi - 1], + particleList[pn].dNdydptdphi[ny][npt][nphi], phir); + // security: if for some reason we got a negative number of particles // (happened in the viscous code at large eta sometimes) - if (f1 < 0.) - f1 = 1e-30; - if (f2 < 0.) - f2 = 1e-30; - + if (f1 < 0.) f1 = 1e-30; + if (f2 < 0.) f2 = 1e-30; + f1s = f1; f2s = f2; - if (ptr > PTCHANGE && f1s > 0 && f2s > 0){ - f1 = log(f1); + if (ptr > PTCHANGE && f1s > 0 && f2s > 0) { + f1 = log(f1); f2 = log(f2); } - double val2 = Util::lin_int(particleList[pn].pt[npt-1], - particleList[pn].pt[npt], f1, f2, ptr); + double val2 = Util::lin_int( + particleList[pn].pt[npt - 1], particleList[pn].pt[npt], f1, f2, ptr); - if (ptr > PTCHANGE && f1s > 0 && f2s > 0){ + if (ptr > PTCHANGE && f1s > 0 && f2s > 0) { val2 = exp(val2); } - - double val = Util::lin_int(particleList[pn].y[ny-1], - particleList[pn].y[ny], val1, val2, yr); + + double val = Util::lin_int( + particleList[pn].y[ny - 1], particleList[pn].y[ny], val1, val2, yr); if (std::isnan(val)) { - fprintf(stderr,"val=%f\n",val); - fprintf(stderr,"val1=%f\n",val1); - fprintf(stderr,"val2=%f\n",val2); - fprintf(stderr,"f1=%f\n",f1); - fprintf(stderr,"f2=%f\n",f2); - fprintf(stderr,"f1s=%f\n",f1s); - fprintf(stderr,"f2s=%f\n",f2s); - fprintf(stderr,"ny=%d\n",ny); - fprintf(stderr,"npt=%d\n",npt); - fprintf(stderr,"nphi=%d\n",nphi); - fprintf(stderr,"dN..=%e\n",particleList[pn].dNdydptdphi[ny-1][npt-1][nphi-1]); - fprintf(stderr,"dN..=%e\n",particleList[pn].dNdydptdphi[ny][npt-1][nphi-1]); - fprintf(stderr,"dN..=%e\n",particleList[pn].dNdydptdphi[ny-1][npt][nphi-1]); - fprintf(stderr,"dN..=%e\n",particleList[pn].dNdydptdphi[ny-1][npt-1][nphi]); - fprintf(stderr,"dN..=%e\n",particleList[pn].dNdydptdphi[ny][npt][nphi-1]); - fprintf(stderr,"dN..=%e\n",particleList[pn].dNdydptdphi[ny-1][npt][nphi]); - fprintf(stderr,"dN..=%e\n",particleList[pn].dNdydptdphi[ny][npt-1][nphi]); - fprintf(stderr,"dN..=%e\n",particleList[pn].dNdydptdphi[ny][npt][nphi]); - fprintf(stderr,"phi1=%f\n",phiArray[nphi-1]); - fprintf(stderr,"phi2=%f\n",phiArray[nphi]); - fprintf(stderr,"pt1=%f\n",particleList[pn].pt[npt-1]); - fprintf(stderr,"pt2=%f\n",particleList[pn].pt[npt]); - fprintf(stderr,"y1=%f\n",particleList[pn].y[ny-1]); - fprintf(stderr,"y2=%f\n",particleList[pn].y[ny]); - fprintf(stderr,"yR=%f\n",yr); + fprintf(stderr, "val=%f\n", val); + fprintf(stderr, "val1=%f\n", val1); + fprintf(stderr, "val2=%f\n", val2); + fprintf(stderr, "f1=%f\n", f1); + fprintf(stderr, "f2=%f\n", f2); + fprintf(stderr, "f1s=%f\n", f1s); + fprintf(stderr, "f2s=%f\n", f2s); + fprintf(stderr, "ny=%d\n", ny); + fprintf(stderr, "npt=%d\n", npt); + fprintf(stderr, "nphi=%d\n", nphi); + fprintf( + stderr, "dN..=%e\n", + particleList[pn].dNdydptdphi[ny - 1][npt - 1][nphi - 1]); + fprintf( + stderr, "dN..=%e\n", + particleList[pn].dNdydptdphi[ny][npt - 1][nphi - 1]); + fprintf( + stderr, "dN..=%e\n", + particleList[pn].dNdydptdphi[ny - 1][npt][nphi - 1]); + fprintf( + stderr, "dN..=%e\n", + particleList[pn].dNdydptdphi[ny - 1][npt - 1][nphi]); + fprintf( + stderr, "dN..=%e\n", + particleList[pn].dNdydptdphi[ny][npt][nphi - 1]); + fprintf( + stderr, "dN..=%e\n", + particleList[pn].dNdydptdphi[ny - 1][npt][nphi]); + fprintf( + stderr, "dN..=%e\n", + particleList[pn].dNdydptdphi[ny][npt - 1][nphi]); + fprintf( + stderr, "dN..=%e\n", particleList[pn].dNdydptdphi[ny][npt][nphi]); + fprintf(stderr, "phi1=%f\n", phiArray[nphi - 1]); + fprintf(stderr, "phi2=%f\n", phiArray[nphi]); + fprintf(stderr, "pt1=%f\n", particleList[pn].pt[npt - 1]); + fprintf(stderr, "pt2=%f\n", particleList[pn].pt[npt]); + fprintf(stderr, "y1=%f\n", particleList[pn].y[ny - 1]); + fprintf(stderr, "y2=%f\n", particleList[pn].y[ny]); + fprintf(stderr, "yR=%f\n", yr); } - + return val; } - -double Freeze::dnpir2N (double phi, void *para1) -{ - pblockN *para = (pblockN *) para1; - double D; - double eR, plR, ptR, yR, phiR, sume, jac; - double cphiR, sphiR; - double dnr; /* dn/mtdmt of resonance */ - - sume = para->e + para->e0; - - D = para->e * para->e0 + para->pl * para->p0 * para->costh + - para->pt * para->p0 * para->sinth * cos (phi) + para->m1 * para->m1; - - eR = para->mr * (sume * sume / D - 1.0); - jac = para->mr + eR; - plR = para->mr * sume * (para->pl - para->p0 * para->costh) / D; - ptR = (eR * eR - plR * plR - para->mr * para->mr); - - if (ptR < 0.0) - ptR = 0.0; - - else - ptR = sqrt (ptR); - - yR = 0.5 * log ((eR + plR) / (eR - plR)); - cphiR = -jac * (para->p0 * para->sinth * cos (phi + para->phi) - - para->pt * cos (para->phi)) / (sume * ptR); - sphiR = -jac * (para->p0 * para->sinth * sin (phi + para->phi) - - para->pt * sin (para->phi)) / (sume * ptR); - - if ((fabs (cphiR) > 1.000) || (fabs (sphiR) > 1.000)) - { - if ((fabs (cphiR) > 1.01) || (fabs (sphiR) > 1.01)) - { - // printf (" |phir| = %15.8lf > 1 ! \n", phiR); - printf (" phi %15.8le D %15.8le \n", phi, D); - printf (" eR %15.8le plR %15.8le \n", eR, plR); - printf (" ptR %15.8le jac %15.8le \n", ptR, jac); - printf (" sume %15.8le costh %15.8le \n", sume, para->costh); - - printf (" pt %15.8le \n", para->pt); - printf (" mt %15.8le \n", para->mt); - printf (" y %15.8le \n", para->y); - printf (" e %15.8le \n", para->e); - printf (" e0 %15.8le \n", para->e0); - printf (" p0 %15.8le \n", para->p0); - printf (" pl %15.8le \n", para->pl); - printf (" phi %15.8le \n", para->phi); - - printf (" m1 %15.8le \n", para->m1); - printf (" m2 %15.8le \n", para->m2); - printf (" m3 %15.8le \n", para->m3); - printf (" mr %15.8le \n", para->mr); - if (cphiR > 1.0) - cphiR = 1.0; - if (cphiR < -1.0) - cphiR = -1.0; - //exit (0); - } - else - { - if (cphiR > 1.0) - cphiR = 1.0; - if (cphiR < -1.0) - cphiR = -1.0; - } +double Freeze::dnpir2N(double phi, void *para1) { + pblockN *para = (pblockN *)para1; + double D; + double eR, plR, ptR, yR, phiR, sume, jac; + double cphiR, sphiR; + double dnr; /* dn/mtdmt of resonance */ + + sume = para->e + para->e0; + + D = para->e * para->e0 + para->pl * para->p0 * para->costh + + para->pt * para->p0 * para->sinth * cos(phi) + para->m1 * para->m1; + + eR = para->mr * (sume * sume / D - 1.0); + jac = para->mr + eR; + plR = para->mr * sume * (para->pl - para->p0 * para->costh) / D; + ptR = (eR * eR - plR * plR - para->mr * para->mr); + + if (ptR < 0.0) + ptR = 0.0; + + else + ptR = sqrt(ptR); + + yR = 0.5 * log((eR + plR) / (eR - plR)); + cphiR = -jac + * (para->p0 * para->sinth * cos(phi + para->phi) + - para->pt * cos(para->phi)) + / (sume * ptR); + sphiR = -jac + * (para->p0 * para->sinth * sin(phi + para->phi) + - para->pt * sin(para->phi)) + / (sume * ptR); + + if ((fabs(cphiR) > 1.000) || (fabs(sphiR) > 1.000)) { + if ((fabs(cphiR) > 1.01) || (fabs(sphiR) > 1.01)) { + // printf (" |phir| = %15.8lf > 1 ! \n", phiR); + printf(" phi %15.8le D %15.8le \n", phi, D); + printf(" eR %15.8le plR %15.8le \n", eR, plR); + printf(" ptR %15.8le jac %15.8le \n", ptR, jac); + printf(" sume %15.8le costh %15.8le \n", sume, para->costh); + + printf(" pt %15.8le \n", para->pt); + printf(" mt %15.8le \n", para->mt); + printf(" y %15.8le \n", para->y); + printf(" e %15.8le \n", para->e); + printf(" e0 %15.8le \n", para->e0); + printf(" p0 %15.8le \n", para->p0); + printf(" pl %15.8le \n", para->pl); + printf(" phi %15.8le \n", para->phi); + + printf(" m1 %15.8le \n", para->m1); + printf(" m2 %15.8le \n", para->m2); + printf(" m3 %15.8le \n", para->m3); + printf(" mr %15.8le \n", para->mr); + if (cphiR > 1.0) cphiR = 1.0; + if (cphiR < -1.0) cphiR = -1.0; + // exit (0); + } else { + if (cphiR > 1.0) cphiR = 1.0; + if (cphiR < -1.0) cphiR = -1.0; + } } - phiR = acos (cphiR); - if (sphiR < 0.0) - phiR = 2.0 * M_PI - phiR; + phiR = acos(cphiR); + if (sphiR < 0.0) phiR = 2.0 * M_PI - phiR; - dnr = Edndp3 (yR, ptR, phiR, para->res_num); + dnr = Edndp3(yR, ptR, phiR, para->res_num); - /*printf(" phir = %15.8lf ! ", phiR); - printf(" ptR %15.8le jac %15.8le ", ptR, jac ); - printf(" dnr %15.8le \n", dnr); */ + /*printf(" phir = %15.8lf ! ", phiR); + printf(" ptR %15.8le jac %15.8le ", ptR, jac ); + printf(" dnr %15.8le \n", dnr); */ - return dnr * jac * jac / (2.0 * sume * sume); + return dnr * jac * jac / (2.0 * sume * sume); } -double Freeze::norm3int (double x, void *paranorm) // this computes "Q(m_R,m_1,m_2,m_3)" +double Freeze::norm3int( + double x, void *paranorm) // this computes "Q(m_R,m_1,m_2,m_3)" { - nblock *tmp = (nblock *) paranorm; - double res = sqrt ((tmp->a - x) * (tmp->b - x) - * (x - tmp->c) * (x - tmp->d)) / x; - return res; + nblock *tmp = (nblock *)paranorm; + double res = + sqrt((tmp->a - x) * (tmp->b - x) * (x - tmp->c) * (x - tmp->d)) / x; + return res; } -double Freeze::dnpir1N (double costh, void* para1) -{ - pblockN *para = (pblockN *) para1; - double r; - para->costh = costh; - para->sinth = sqrt (1.0 - para->costh * para->costh); - r = gauss (PTN2, &Freeze::dnpir2N, 0.0, 2.0 * M_PI, para); //Integrates the "dnpir2N" kernel over phi using gaussian integration - return r; +double Freeze::dnpir1N(double costh, void *para1) { + pblockN *para = (pblockN *)para1; + double r; + para->costh = costh; + para->sinth = sqrt(1.0 - para->costh * para->costh); + r = gauss( + PTN2, &Freeze::dnpir2N, 0.0, 2.0 * M_PI, + para); // Integrates the "dnpir2N" kernel over phi using gaussian + // integration + return r; } -double Freeze::dn2ptN (double w2, void* para1) -{ - pblockN *para = (pblockN *) para1; - para->e0 = (para->mr * para->mr + para->m1 * para->m1 - w2) / (2 * para->mr); //particle one energy in resonance rest frame - para->p0 = sqrt (para->e0 * para->e0 - para->m1 * para->m1); // particle one absolute value of three momentum on resonance rest frame - return gauss (PTN1, &Freeze::dnpir1N, -1.0, 1.0, para); //Integrate the "dnpir1N" kernel over cos(theta) using gaussian integration +double Freeze::dn2ptN(double w2, void *para1) { + pblockN *para = (pblockN *)para1; + para->e0 = (para->mr * para->mr + para->m1 * para->m1 - w2) + / (2 * para->mr); // particle one energy in resonance rest frame + para->p0 = sqrt( + para->e0 * para->e0 + - para->m1 * para->m1); // particle one absolute value of three + // momentum on resonance rest frame + return gauss( + PTN1, &Freeze::dnpir1N, -1.0, 1.0, + para); // Integrate the "dnpir1N" kernel over cos(theta) using gaussian + // integration } -double Freeze::dn3ptN (double x, void* para1) //The integration kernel for "W" in 3-body decays. x=invariant mass of other particles squared +double Freeze::dn3ptN( + double x, void *para1) // The integration kernel for "W" in 3-body decays. + // x=invariant mass of other particles squared { - pblockN *para = (pblockN *) para1; - double e0 =(para->mr * para->mr + para->m1 * para->m1 - x) / (2 * para->mr); - double p0 = sqrt (e0 * e0 - para->m1 * para->m1); - double a = (para->m2 + para->m3) * (para->m2 + para->m3); - double b = (para->m2 - para->m3) * (para->m2 - para->m3); - double re = p0 * sqrt ((x - a) * (x - b)) / x * dn2ptN (x, para); - return re; + pblockN *para = (pblockN *)para1; + double e0 = + (para->mr * para->mr + para->m1 * para->m1 - x) / (2 * para->mr); + double p0 = sqrt(e0 * e0 - para->m1 * para->m1); + double a = (para->m2 + para->m3) * (para->m2 + para->m3); + double b = (para->m2 - para->m3) * (para->m2 - para->m3); + double re = p0 * sqrt((x - a) * (x - b)) / x * dn2ptN(x, para); + return re; } -double Freeze::gauss(int n, double (Freeze::*f)(double, void *), - double xlo, double xhi, void *optvec) { - double xoffs, xdiff; +double Freeze::gauss( + int n, double (Freeze::*f)(double, void *), double xlo, double xhi, + void *optvec) { + double xoffs, xdiff; int ix; - double s; /* summing up */ - double *p, *w; /* pointing to active list */ + double s; /* summing up */ + double *p, *w; /* pointing to active list */ switch (n) { - case 4: p= gaulep4; w= gaulew4; break; - case 8: p= gaulep8; w= gaulew8; break; - case 10: p=gaulep10; w=gaulew10; break; - case 12: p=gaulep12; w=gaulew12; break; - case 16: p=gaulep16; w=gaulew16; break; - case 20: p=gaulep20; w=gaulew20; break; - case 48: p=gaulep48; w=gaulew48; break; - default: printf("\ngauss():%d points not in list\n",n); - exit(0); - } - xoffs = 0.5 * ( xlo + xhi ); - xdiff = 0.5 * ( xhi - xlo ); + case 4: + p = gaulep4; + w = gaulew4; + break; + case 8: + p = gaulep8; + w = gaulew8; + break; + case 10: + p = gaulep10; + w = gaulew10; + break; + case 12: + p = gaulep12; + w = gaulew12; + break; + case 16: + p = gaulep16; + w = gaulew16; + break; + case 20: + p = gaulep20; + w = gaulew20; + break; + case 48: + p = gaulep48; + w = gaulew48; + break; + default: + printf("\ngauss():%d points not in list\n", n); + exit(0); + } + xoffs = 0.5 * (xlo + xhi); + xdiff = 0.5 * (xhi - xlo); s = 0; - for( ix=0; ix*f)(xoffs+xdiff*p[ix],optvec) - + (this->*f)(xoffs-xdiff*p[ix],optvec) ); - return( s * xdiff ); + for (ix = 0; ix < n / 2; ix++) /* n is even */ + s += w[ix] + * ((this->*f)(xoffs + xdiff * p[ix], optvec) + + (this->*f)(xoffs - xdiff * p[ix], optvec)); + return (s * xdiff); } - - + /******************************************************************** -* -* Edndp3_2bodyN() -* -* transverse momentum spectrum in GeV^-2 from pions out of resonances -*********************************************************************/ -double Freeze::Edndp3_2bodyN (double y, double pt, double phi, double m1, double m2, double mr, int res_num) + * + * Edndp3_2bodyN() + * + * transverse momentum spectrum in GeV^-2 from pions out of resonances + *********************************************************************/ +double Freeze::Edndp3_2bodyN( + double y, double pt, double phi, double m1, double m2, double mr, + int res_num) /* /\* in units of GeV^-2,includes phasespace and volume, */ /* does not include degeneracy factors *\/ */ /* double y; /\* rapidity of particle 1 *\/ */ @@ -346,100 +404,100 @@ double Freeze::Edndp3_2bodyN (double y, double pt, double phi, double m1, double /* double phi; /\* phi angle of particle 1 *\/ */ /* double m1, m2; /\* restmasses of decay particles in MeV *\/ */ /* double mr; /\* restmass of resonance MeV *\/ */ -/* int res_num; /\* Montecarlo number of the Resonance */ +/* int res_num; /\* Montecarlo number of the Resonance */ { - double mt = sqrt (pt * pt + m1 * m1); - double norm2; /* 2-body normalization */ - pblockN para; - double res2; - - para.pt = pt; - para.mt = mt; - para.e = mt * cosh (y); - para.pl = mt * sinh (y); - para.y = y; - para.phi = phi; - para.m1 = m1; - para.m2 = m2; - para.mr = mr; - - para.res_num = res_num; - - norm2 = 1.0 / (2.0 * M_PI); - res2 = norm2 * dn2ptN (m2 * m2, ¶); //Calls the integration routines for 2-body - if (res2<0.) res2=0.; - return res2; /* like Ed3ndp3_2body() */ + double mt = sqrt(pt * pt + m1 * m1); + double norm2; /* 2-body normalization */ + pblockN para; + double res2; + + para.pt = pt; + para.mt = mt; + para.e = mt * cosh(y); + para.pl = mt * sinh(y); + para.y = y; + para.phi = phi; + para.m1 = m1; + para.m2 = m2; + para.mr = mr; + + para.res_num = res_num; + + norm2 = 1.0 / (2.0 * M_PI); + res2 = + norm2 + * dn2ptN(m2 * m2, ¶); // Calls the integration routines for 2-body + if (res2 < 0.) res2 = 0.; + return res2; /* like Ed3ndp3_2body() */ } - /******************************************************************** -* -* Edndp3_3bodyN() -* -* transverse momentum spectrum in GeV^-2 from pions out of resonances -*********************************************************************/ -double Freeze::Edndp3_3bodyN (double y, double pt, double phi, double m1, double m2, - double m3, double mr, double norm3, int res_num) - /* in units of GeV^-2,includes phasespace and volume, - does not include degeneracy factors */ + * + * Edndp3_3bodyN() + * + * transverse momentum spectrum in GeV^-2 from pions out of resonances + *********************************************************************/ +double Freeze::Edndp3_3bodyN( + double y, double pt, double phi, double m1, double m2, double m3, double mr, + double norm3, int res_num) +/* in units of GeV^-2,includes phasespace and volume, + does not include degeneracy factors */ { - double mt = sqrt (pt * pt + m1 * m1); - pblockN para; - double wmin, wmax; - double res3; -// double slope; /* slope of resonance for high mt */ -// int pn; - - para.pt = pt; - para.mt = mt; - para.y = y; - para.e = mt * cosh (y); - para.pl = mt * sinh (y); - para.phi = phi; - - para.m1 = m1; - para.m2 = m2; - para.m3 = m3; - para.mr = mr; - -// pn = partid[MHALF + res_num]; - - para.res_num = res_num; - - wmin = (m2 + m3) * (m2 + m3); - wmax = (mr - m1) * (mr - m1); - res3 = 2.0 * norm3 * gauss (PTS4, &Freeze::dn3ptN, wmin, wmax, ¶) / mr; //Integrates "W" using gaussian - if (res3<0.) res3=0.; - return res3; + double mt = sqrt(pt * pt + m1 * m1); + pblockN para; + double wmin, wmax; + double res3; + // double slope; /* slope of resonance for high mt */ + // int pn; + + para.pt = pt; + para.mt = mt; + para.y = y; + para.e = mt * cosh(y); + para.pl = mt * sinh(y); + para.phi = phi; + + para.m1 = m1; + para.m2 = m2; + para.m3 = m3; + para.mr = mr; + + // pn = partid[MHALF + res_num]; + + para.res_num = res_num; + + wmin = (m2 + m3) * (m2 + m3); + wmax = (mr - m1) * (mr - m1); + res3 = 2.0 * norm3 * gauss(PTS4, &Freeze::dn3ptN, wmin, wmax, ¶) + / mr; // Integrates "W" using gaussian + if (res3 < 0.) res3 = 0.; + return res3; } - //! computes the pt, mt distribution including resonance decays void Freeze::add_reso(int pn, int pnR, int k, int j) { - nblock paranorm; /* for 3body normalization integral */ + nblock paranorm; /* for 3body normalization integral */ double y; double m1, m2, m3, mr; - double norm3; /* normalisation of 3-body integral */ - int pn2, pn3, pn4; /* internal numbers for resonances */ + double norm3; /* normalisation of 3-body integral */ + int pn2, pn3, pn4; /* internal numbers for resonances */ // this variable stores number of points in pseudorapidity int ny = particleList[pn].ny; int npt = particleList[pn].npt; int nphi = particleList[pn].nphi; - double deltaphi = 2*M_PI/nphi; - + double deltaphi = 2 * M_PI / nphi; // Determine the number of particles involved in the decay with the switch switch (abs(decay[j].numpart)) { - case 1: - { + case 1: { // Only 1 particle, if it gets here, by accident, // this prevents any integration for 1 particle chains break; } - case 2: // 2-body decay + case 2: // 2-body decay { if (k == 0) { pn2 = partid[MHALF + decay[j].part[1]]; @@ -452,9 +510,9 @@ void Freeze::add_reso(int pn, int pnR, int k, int j) { mr = particleList[pnR].mass; while ((m1 + m2) > mr) { - mr += 0.25*particleList[pnR].width; - m1 -= 0.5*particleList[pn].width; - m2 -= 0.5*particleList[pn2].width; + mr += 0.25 * particleList[pnR].width; + m1 -= 0.5 * particleList[pn].width; + m2 -= 0.5 * particleList[pn2].width; } // fprintf(stderr,"mr=%f\n",mr); // fprintf(stderr,"m1=%f\n",m1); @@ -462,80 +520,82 @@ void Freeze::add_reso(int pn, int pnR, int k, int j) { if (boost_invariant) { y = 0.0; - #pragma omp parallel for collapse(2) +#pragma omp parallel for collapse(2) for (int l = 0; l < npt; l++) - for (int i = 0; i < nphi; i++) { - if (pseudofreeze) { - y = Rap(y, particleList[pn].pt[l], m1); - } - double phi = 0.0; - if (pseudofreeze) { - phi = i*deltaphi; - } else { - phi = phiArray[i]; - } - double spectrum = Edndp3_2bodyN( - y, particleList[pn].pt[l], phi, - m1, m2, mr, + for (int i = 0; i < nphi; i++) { + if (pseudofreeze) { + y = Rap(y, particleList[pn].pt[l], m1); + } + double phi = 0.0; + if (pseudofreeze) { + phi = i * deltaphi; + } else { + phi = phiArray[i]; + } + double spectrum = Edndp3_2bodyN( + y, particleList[pn].pt[l], phi, m1, m2, mr, particleList[pnR].number); - if (std::isnan(spectrum)) { - fprintf(stderr, "2 pt=%f\n", - particleList[pn].pt[l]); - fprintf(stderr, "2 number=%d\n", + if (std::isnan(spectrum)) { + fprintf( + stderr, "2 pt=%f\n", particleList[pn].pt[l]); + fprintf( + stderr, "2 number=%d\n", particleList[pnR].number); - fprintf(stderr, "2 Edn..=%f\n", spectrum); - } else { - // Call the 2-body decay integral and - // add its contribution to the daughter - // particle of interest - for (int n = 0; n < ny; n++) { - particleList[pn].dNdydptdphi[n][l][i] += ( - decay[j].branch*spectrum); - //if (n == ny/2 && i==0) { - // particleList[pn].resCont[n][l][i] += ( - // decay[j].branch*spectrum); - //} + fprintf(stderr, "2 Edn..=%f\n", spectrum); + } else { + // Call the 2-body decay integral and + // add its contribution to the daughter + // particle of interest + for (int n = 0; n < ny; n++) { + particleList[pn].dNdydptdphi[n][l][i] += + (decay[j].branch * spectrum); + // if (n == ny/2 && i==0) { + // particleList[pn].resCont[n][l][i] += ( + // decay[j].branch*spectrum); + // } + } } } - } } else { - #pragma omp parallel for collapse(3) +#pragma omp parallel for collapse(3) for (int n = 0; n < ny; n++) - for (int l = 0; l < npt; l++) - for (int i = 0; i < nphi; i++) { - y = particleList[pn].y[n]; - if (pseudofreeze) { - y = Rap(particleList[pn].y[n], - particleList[pn].pt[l], m1); - } - double phi = 0.0; - if (pseudofreeze) { - phi = i*deltaphi; - } else { - phi = phiArray[i]; - } - double spectrum = Edndp3_2bodyN( - y, particleList[pn].pt[l], phi, - m1, m2, mr, - particleList[pnR].number); - if (std::isnan(spectrum)) { - fprintf(stderr, "2 pt=%f\n", - particleList[pn].pt[l]); - fprintf(stderr, "2 number=%d\n", + for (int l = 0; l < npt; l++) + for (int i = 0; i < nphi; i++) { + y = particleList[pn].y[n]; + if (pseudofreeze) { + y = + Rap(particleList[pn].y[n], + particleList[pn].pt[l], m1); + } + double phi = 0.0; + if (pseudofreeze) { + phi = i * deltaphi; + } else { + phi = phiArray[i]; + } + double spectrum = Edndp3_2bodyN( + y, particleList[pn].pt[l], phi, m1, m2, mr, particleList[pnR].number); - fprintf(stderr, "2 Edn..=%f\n", spectrum); - } else { - // Call the 2-body decay integral and - // add its contribution to the daughter - // particle of interest - particleList[pn].dNdydptdphi[n][l][i] += ( - decay[j].branch*spectrum); - //if (n == ny/2 && i==0) { - // particleList[pn].resCont[n][l][i] += ( - // decay[j].branch*spectrum); - //} - } - } + if (std::isnan(spectrum)) { + fprintf( + stderr, "2 pt=%f\n", + particleList[pn].pt[l]); + fprintf( + stderr, "2 number=%d\n", + particleList[pnR].number); + fprintf(stderr, "2 Edn..=%f\n", spectrum); + } else { + // Call the 2-body decay integral and + // add its contribution to the daughter + // particle of interest + particleList[pn].dNdydptdphi[n][l][i] += + (decay[j].branch * spectrum); + // if (n == ny/2 && i==0) { + // particleList[pn].resCont[n][l][i] += ( + // decay[j].branch*spectrum); + // } + } + } } break; } @@ -559,88 +619,92 @@ void Freeze::add_reso(int pn, int pnR, int k, int j) { m2 = particleList[pn2].mass; m3 = particleList[pn3].mass; mr = particleList[pnR].mass; - paranorm.a = (mr + m1)*(mr + m1); - paranorm.b = (mr - m1)*(mr - m1); - paranorm.c = (m2 + m3)*(m2 + m3); - paranorm.d = (m2 - m3)*(m2 - m3); - norm3 = mr*mr/(2*M_PI*gauss(PTS3, &Freeze::norm3int, paranorm.c, - paranorm.b, ¶norm)); - + paranorm.a = (mr + m1) * (mr + m1); + paranorm.b = (mr - m1) * (mr - m1); + paranorm.c = (m2 + m3) * (m2 + m3); + paranorm.d = (m2 - m3) * (m2 - m3); + norm3 = mr * mr + / (2 * M_PI + * gauss( + PTS3, &Freeze::norm3int, paranorm.c, paranorm.b, + ¶norm)); + if (boost_invariant) { y = 0.0; - #pragma omp parallel for collapse(2) +#pragma omp parallel for collapse(2) for (int l = 0; l < npt; l++) - for (int i = 0; i < nphi; i++) { - if (pseudofreeze) { - y = Rap(y, particleList[pn].pt[l], m1); - } - double phi; - if (pseudofreeze) { - phi = i*deltaphi; - } else { - phi = phiArray[i]; - } - double spectrum = Edndp3_3bodyN( - y, particleList[pn].pt[l], phi, - m1, m2, m3, mr, norm3, - particleList[pnR].number); - if (std::isnan(spectrum)) { - fprintf(stderr,"3 number=%d\n", + for (int i = 0; i < nphi; i++) { + if (pseudofreeze) { + y = Rap(y, particleList[pn].pt[l], m1); + } + double phi; + if (pseudofreeze) { + phi = i * deltaphi; + } else { + phi = phiArray[i]; + } + double spectrum = Edndp3_3bodyN( + y, particleList[pn].pt[l], phi, m1, m2, m3, mr, + norm3, particleList[pnR].number); + if (std::isnan(spectrum)) { + fprintf( + stderr, "3 number=%d\n", particleList[pnR].number); - fprintf(stderr,"3 Edn..=%f\n", spectrum); - } else { - // Call the 3-body decay integral and - // add its contribution to the daughter - // particle of interest - for (int n = 0; n < ny; n++) { - particleList[pn].dNdydptdphi[n][l][i] += ( - decay[j].branch*spectrum); - //if (n == ny/2 && i==0) { - // particleList[pn].resCont[n][l][i]+= ( - // decay[j].branch*spectrum); - - //} + fprintf(stderr, "3 Edn..=%f\n", spectrum); + } else { + // Call the 3-body decay integral and + // add its contribution to the daughter + // particle of interest + for (int n = 0; n < ny; n++) { + particleList[pn].dNdydptdphi[n][l][i] += + (decay[j].branch * spectrum); + // if (n == ny/2 && i==0) { + // particleList[pn].resCont[n][l][i]+= ( + // decay[j].branch*spectrum); + + //} + } } } - } } else { - #pragma omp parallel for collapse(3) +#pragma omp parallel for collapse(3) for (int n = 0; n < ny; n++) - for (int l = 0; l < npt; l++) - for (int i = 0; i < nphi; i++) { - y = particleList[pn].y[n]; - if (pseudofreeze) { - y = Rap(particleList[pn].y[n], - particleList[pn].pt[l], m1); - } - double phi; - if (pseudofreeze) { - phi = i*deltaphi; - } else { - phi = phiArray[i]; - } - double spectrum = Edndp3_3bodyN( - y, particleList[pn].pt[l], phi, - m1, m2, m3, mr, norm3, - particleList[pnR].number); - if (std::isnan(spectrum)) { - fprintf(stderr,"3 number=%d\n", - particleList[pnR].number); - fprintf(stderr,"3 Edn..=%f\n", spectrum); - } else { - // Call the 3-body decay integral and - // add its contribution to the daughter - // particle of interest - particleList[pn].dNdydptdphi[n][l][i] += ( - decay[j].branch*spectrum); - } - - //if (n == ny/2 && i==0) { - // particleList[pn].resCont[n][l][i]+= ( - // decay[j].branch*spectrum); - - //} - } + for (int l = 0; l < npt; l++) + for (int i = 0; i < nphi; i++) { + y = particleList[pn].y[n]; + if (pseudofreeze) { + y = + Rap(particleList[pn].y[n], + particleList[pn].pt[l], m1); + } + double phi; + if (pseudofreeze) { + phi = i * deltaphi; + } else { + phi = phiArray[i]; + } + double spectrum = Edndp3_3bodyN( + y, particleList[pn].pt[l], phi, m1, m2, m3, mr, + norm3, particleList[pnR].number); + if (std::isnan(spectrum)) { + fprintf( + stderr, "3 number=%d\n", + particleList[pnR].number); + fprintf(stderr, "3 Edn..=%f\n", spectrum); + } else { + // Call the 3-body decay integral and + // add its contribution to the daughter + // particle of interest + particleList[pn].dNdydptdphi[n][l][i] += + (decay[j].branch * spectrum); + } + + // if (n == ny/2 && i==0) { + // particleList[pn].resCont[n][l][i]+= ( + // decay[j].branch*spectrum); + + //} + } } break; } @@ -669,80 +733,84 @@ void Freeze::add_reso(int pn, int pnR, int k, int j) { m1 = particleList[pn].mass; m2 = particleList[pn2].mass; mr = particleList[pnR].mass; - m3 = 0.5*(particleList[pn3].mass + particleList[pn4].mass - + mr - m1 - m2); - paranorm.a = (mr + m1)*(mr + m1); - paranorm.b = (mr - m1)*(mr - m1); - paranorm.c = (m2 + m3)*(m2 + m3); - paranorm.d = (m2 - m3)*(m2 - m3); - norm3 = mr*mr/(2*M_PI*gauss(PTS3, &Freeze::norm3int, paranorm.c, - paranorm.b, ¶norm)); - + m3 = 0.5 + * (particleList[pn3].mass + particleList[pn4].mass + mr - m1 + - m2); + paranorm.a = (mr + m1) * (mr + m1); + paranorm.b = (mr - m1) * (mr - m1); + paranorm.c = (m2 + m3) * (m2 + m3); + paranorm.d = (m2 - m3) * (m2 - m3); + norm3 = mr * mr + / (2 * M_PI + * gauss( + PTS3, &Freeze::norm3int, paranorm.c, paranorm.b, + ¶norm)); + if (boost_invariant) { y = 0.0; - #pragma omp parallel for collapse(2) +#pragma omp parallel for collapse(2) for (int i = 0; i < nphi; i++) - for (int l = 0; l < npt; l++) { - double phi; - if (pseudofreeze) { - phi = i*deltaphi; - } else { - phi = phiArray[i]; - } - if (pseudofreeze) { - y = Rap(y, particleList[pn].pt[l], m1); - } - double spectrum = Edndp3_3bodyN( - y, particleList[pn].pt[l], phi, - m1, m2, m3, mr, norm3, - particleList[pnR].number); - if (std::isnan(spectrum)) { - fprintf(stderr, "3 number=%d\n", + for (int l = 0; l < npt; l++) { + double phi; + if (pseudofreeze) { + phi = i * deltaphi; + } else { + phi = phiArray[i]; + } + if (pseudofreeze) { + y = Rap(y, particleList[pn].pt[l], m1); + } + double spectrum = Edndp3_3bodyN( + y, particleList[pn].pt[l], phi, m1, m2, m3, mr, + norm3, particleList[pnR].number); + if (std::isnan(spectrum)) { + fprintf( + stderr, "3 number=%d\n", particleList[pnR].number); - } else { - for (int n = 0; n < ny; n++) { - particleList[pn].dNdydptdphi[n][l][i] += ( - decay[j].branch*spectrum); + } else { + for (int n = 0; n < ny; n++) { + particleList[pn].dNdydptdphi[n][l][i] += + (decay[j].branch * spectrum); + } } } - } } else { - #pragma omp parallel for collapse(3) +#pragma omp parallel for collapse(3) for (int n = 0; n < ny; n++) - for (int i = 0; i < nphi; i++) - for (int l = 0; l < npt; l++) { - y = particleList[pn].y[n]; - double phi; - if (pseudofreeze) { - phi = i*deltaphi; - } else { - phi = phiArray[i]; - } - if (pseudofreeze) { - y = Rap(particleList[pn].y[n], - particleList[pn].pt[l], m1); - } - double spectrum = Edndp3_3bodyN( - y, particleList[pn].pt[l], phi, - m1, m2, m3, mr, norm3, - particleList[pnR].number); - if (std::isnan(spectrum)) { - fprintf(stderr, "3 number=%d\n", - particleList[pnR].number); - } else { - particleList[pn].dNdydptdphi[n][l][i] += ( - decay[j].branch*spectrum); - } - } + for (int i = 0; i < nphi; i++) + for (int l = 0; l < npt; l++) { + y = particleList[pn].y[n]; + double phi; + if (pseudofreeze) { + phi = i * deltaphi; + } else { + phi = phiArray[i]; + } + if (pseudofreeze) { + y = + Rap(particleList[pn].y[n], + particleList[pn].pt[l], m1); + } + double spectrum = Edndp3_3bodyN( + y, particleList[pn].pt[l], phi, m1, m2, m3, mr, + norm3, particleList[pnR].number); + if (std::isnan(spectrum)) { + fprintf( + stderr, "3 number=%d\n", + particleList[pnR].number); + } else { + particleList[pn].dNdydptdphi[n][l][i] += + (decay[j].branch * spectrum); + } + } } break; } - - default: - { - printf ("ERROR in add_reso! \n"); - printf ("%i decay not implemented ! \n", abs (decay[j].numpart)); - exit (0); + + default: { + printf("ERROR in add_reso! \n"); + printf("%i decay not implemented ! \n", abs(decay[j].numpart)); + exit(0); } } } @@ -751,13 +819,13 @@ void Freeze::cal_reso_decays(int maxpart, int maxdecay, int bound) { music_message << "CALCULATE RESONANCE DECAYS (as fast as I can) ..."; music_message.flush("info"); int pn = partid[MHALF + bound]; - //int ny = particleList[pn].ny; - //int npt = particleList[pn].npt; - //int nphi = particleList[pn].nphi; - - for (int i = maxpart-1; i > pn - 1; i--) { + // int ny = particleList[pn].ny; + // int npt = particleList[pn].npt; + // int nphi = particleList[pn].nphi; + + for (int i = maxpart - 1; i > pn - 1; i--) { // Cycle the particles known from the particle.dat input - //for (int n1 = 0; n1 < ny; n1++) { + // for (int n1 = 0; n1 < ny; n1++) { // for (int n2 = 0; n2 < npt; n2++) { // for (int n3 = 0; n3 < nphi; n3++) { // particleList[pn].resCont[n1][n2][n3] =0.; @@ -766,8 +834,7 @@ void Freeze::cal_reso_decays(int maxpart, int maxdecay, int bound) { //} int part = particleList[i].number; - music_message << "Calculating the decays with " - << particleList[i].name; + music_message << "Calculating the decays with " << particleList[i].name; music_message.flush("info"); switch (particleList[i].baryon) { // Check the particle is baryon, anti-baryon or meson @@ -780,7 +847,7 @@ void Freeze::cal_reso_decays(int maxpart, int maxdecay, int bound) { int pnR = partid[MHALF + decay[j].reso]; for (int k = 0; k < abs(decay[j].numpart); k++) { if ((part == decay[j].part[k]) - && (decay[j].numpart != 1)) { + && (decay[j].numpart != 1)) { // Make sure that the decay channel isn't trivial // and contains the daughter particle music_message << "Partid is " << pnR << ". " @@ -803,12 +870,11 @@ void Freeze::cal_reso_decays(int maxpart, int maxdecay, int bound) { int pnaR = partid[MHALF - decay[j].reso]; for (int k = 0; k < abs(decay[j].numpart); k++) { if ((-part == decay[j].part[k]) - && (decay[j].numpart != 1)) { + && (decay[j].numpart != 1)) { // Make sure that the decay channel isn't trivial // and contains the daughter particle music_message << "Partid is " << pnaR << ". " - << particleList[pnaR].name - << " into " + << particleList[pnaR].name << " into " << particleList[i].name; music_message.flush("info"); add_reso(i, pnaR, k, j); @@ -822,24 +888,22 @@ void Freeze::cal_reso_decays(int maxpart, int maxdecay, int bound) { { for (int j = 0; j < maxdecay; j++) { int pnR = partid[MHALF + decay[j].reso]; - for (int k = 0; k < abs (decay[j].numpart); k++) { + for (int k = 0; k < abs(decay[j].numpart); k++) { if (particleList[pnR].baryon == 1) { int pnaR = partid[MHALF - decay[j].reso]; if ((particleList[i].charge == 0) - && (particleList[i].strange == 0)) { + && (particleList[i].strange == 0)) { if ((part == decay[j].part[k]) && (decay[j].numpart != 1)) { - music_message << "Partid is " << pnR - << ". " + music_message << "Partid is " << pnR << ". " << particleList[pnR].name << " into " << particleList[i].name; music_message.flush("info"); - music_message << "Partid is " << pnaR - << ". " - << particleList[pnaR].name - << " into " - << particleList[i].name; + music_message + << "Partid is " << pnaR << ". " + << particleList[pnaR].name << " into " + << particleList[i].name; music_message.flush("info"); add_reso(i, pnR, k, j); add_reso(i, pnaR, k, j); @@ -847,21 +911,19 @@ void Freeze::cal_reso_decays(int maxpart, int maxdecay, int bound) { } else { if ((part == decay[j].part[k]) && (decay[j].numpart != 1)) { - music_message << "Partid is " << pnR - << ". " + music_message << "Partid is " << pnR << ". " << particleList[pnR].name << " into " << particleList[i].name; music_message.flush("info"); - add_reso (i, pnR, k, j); + add_reso(i, pnR, k, j); } if ((-part == decay[j].part[k]) && (decay[j].numpart != 1)) { - music_message << "Partid is " << pnaR - << ". " - << particleList[pnaR].name - << " into " - << particleList[i].name; + music_message + << "Partid is " << pnaR << ". " + << particleList[pnaR].name << " into " + << particleList[i].name; music_message.flush("info"); add_reso(i, pnaR, k, j); } @@ -869,8 +931,7 @@ void Freeze::cal_reso_decays(int maxpart, int maxdecay, int bound) { } else { if ((part == decay[j].part[k]) && (decay[j].numpart != 1)) { - music_message << "Partid is " << pnR - << ". " + music_message << "Partid is " << pnR << ". " << particleList[pnR].name << " into " << particleList[i].name; @@ -889,4 +950,3 @@ void Freeze::cal_reso_decays(int maxpart, int maxdecay, int bound) { } } } - diff --git a/src/transport_coeffs.cpp b/src/transport_coeffs.cpp index 2df14186..7ee193cb 100644 --- a/src/transport_coeffs.cpp +++ b/src/transport_coeffs.cpp @@ -1,8 +1,10 @@ // Copyright 2011 @ Bjoern Schenke, Sangyong Jeon, and Charles Gale +#include "transport_coeffs.h" + #include + #include "util.h" -#include "transport_coeffs.h" using Util::hbarc; @@ -12,10 +14,9 @@ TransportCoeffs::TransportCoeffs(const InitData &Data_in) shear_muB_(DATA.muB_dependent_shear_to_s), bulk_T_(DATA.T_dependent_bulk_to_s) { shear_relax_time_factor_ = DATA.shear_relax_time_factor; - bulk_relax_time_factor_ = DATA.bulk_relax_time_factor; + bulk_relax_time_factor_ = DATA.bulk_relax_time_factor; } - double TransportCoeffs::get_eta_over_s(const double T, const double muB) const { // inputs T [1/fm], muB [1/fm] // outputs \eta/s @@ -44,86 +45,83 @@ double TransportCoeffs::get_eta_over_s(const double T, const double muB) const { return eta_over_s; } - double TransportCoeffs::get_temperature_dependence_shear_profile( - const double T_in_fm) const { - const double T_in_GeV = T_in_fm*hbarc; + const double T_in_fm) const { + const double T_in_GeV = T_in_fm * hbarc; const double Tc = 0.165; double f_T = 1.0; if (T_in_GeV < Tc) { const double Tslope = 1.2; const double Tlow = 0.1; - f_T += Tslope*(Tc - T_in_GeV)/(Tc - Tlow); + f_T += Tslope * (Tc - T_in_GeV) / (Tc - Tlow); } else { const double Tslope2 = 0.0; const double Thigh = 0.4; - f_T += Tslope2*(T_in_GeV - Tc)/(Thigh - Tc); + f_T += Tslope2 * (T_in_GeV - Tc) / (Thigh - Tc); } - return(f_T); + return (f_T); } - double TransportCoeffs::get_muB_dependence_shear_piecewise( - const double muB_in_fm) const { - const double muB_in_GeV = std::abs(muB_in_fm)*hbarc; + const double muB_in_fm) const { + const double muB_in_GeV = std::abs(muB_in_fm) * hbarc; const double f0 = 1.0; const double f1 = DATA.shear_muBf0p2; const double f2 = DATA.shear_muBf0p4; double f_muB = f0; if (muB_in_GeV < 0.2) { - f_muB = f0 + (f1 - f0)/0.2*muB_in_GeV; + f_muB = f0 + (f1 - f0) / 0.2 * muB_in_GeV; } else if (muB_in_GeV < 0.4) { - f_muB = f1 + (f2 - f1)/0.2*(muB_in_GeV - 0.2); + f_muB = f1 + (f2 - f1) / 0.2 * (muB_in_GeV - 0.2); } else { f_muB = f2; } - return(f_muB); + return (f_muB); } - double TransportCoeffs::get_muB_dependence_shear_profile( - const double muB_in_fm) const { - const double muB_in_GeV = muB_in_fm*hbarc; + const double muB_in_fm) const { + const double muB_in_GeV = muB_in_fm * hbarc; const double alpha = DATA.shear_muBDep_alpha; const double muB_slope = DATA.shear_muBDep_slope; const double muB_scale = DATA.shear_muBDep_scale; - double f_muB = 1. + muB_slope*pow(muB_in_GeV/muB_scale, alpha); - return(f_muB); + double f_muB = 1. + muB_slope * pow(muB_in_GeV / muB_scale, alpha); + return (f_muB); } - double TransportCoeffs::get_temperature_dependent_eta_over_s_default( - const double T) const { - const double Ttr = 0.18/hbarc; // phase transition temperature - const double Tfrac = T/Ttr; + const double T) const { + const double Ttr = 0.18 / hbarc; // phase transition temperature + const double Tfrac = T / Ttr; double eta_over_s; if (Tfrac < 1.) { - eta_over_s = (DATA.shear_to_s + 0.0594*(1. - Tfrac) - + 0.544*(1. - Tfrac*Tfrac)); + eta_over_s = + (DATA.shear_to_s + 0.0594 * (1. - Tfrac) + + 0.544 * (1. - Tfrac * Tfrac)); } else { - eta_over_s = (DATA.shear_to_s + 0.288*(Tfrac - 1.) - + 0.0818*(Tfrac*Tfrac - 1.)); + eta_over_s = + (DATA.shear_to_s + 0.288 * (Tfrac - 1.) + + 0.0818 * (Tfrac * Tfrac - 1.)); } - return(eta_over_s); + return (eta_over_s); } - double TransportCoeffs::get_temperature_dependent_eta_over_s_duke( - const double T_in_fm) const { - double T_in_GeV = T_in_fm*hbarc; + const double T_in_fm) const { + double T_in_GeV = T_in_fm * hbarc; double Ttr_in_GeV = 0.154; - double Tfrac = T_in_GeV/Ttr_in_GeV; + double Tfrac = T_in_GeV / Ttr_in_GeV; - double eta_over_s = (DATA.shear_2_min - + (DATA.shear_2_slope)*(T_in_GeV - Ttr_in_GeV) - *pow(Tfrac,DATA.shear_2_curv)); + double eta_over_s = + (DATA.shear_2_min + + (DATA.shear_2_slope) * (T_in_GeV - Ttr_in_GeV) + * pow(Tfrac, DATA.shear_2_curv)); return eta_over_s; } - double TransportCoeffs::get_temperature_dependent_eta_over_s_sims( - const double T_in_fm) const { - double T_in_GeV = T_in_fm*hbarc; + const double T_in_fm) const { + double T_in_GeV = T_in_fm * hbarc; double T_kink_in_GeV = DATA.shear_3_T_kink_in_GeV; double low_T_slope = DATA.shear_3_low_T_slope_in_GeV; double high_T_slope = DATA.shear_3_high_T_slope_in_GeV; @@ -132,43 +130,44 @@ double TransportCoeffs::get_temperature_dependent_eta_over_s_sims( const double eta_over_s_min = 1e-3; double eta_over_s; if (T_in_GeV < T_kink_in_GeV) { - eta_over_s = (eta_over_s_at_kink - + low_T_slope*(T_in_GeV - T_kink_in_GeV)); + eta_over_s = + (eta_over_s_at_kink + low_T_slope * (T_in_GeV - T_kink_in_GeV)); } else { - eta_over_s = (eta_over_s_at_kink - + high_T_slope*(T_in_GeV - T_kink_in_GeV)); + eta_over_s = + (eta_over_s_at_kink + high_T_slope * (T_in_GeV - T_kink_in_GeV)); } - eta_over_s = std::max(eta_over_s,eta_over_s_min); - return(eta_over_s); + eta_over_s = std::max(eta_over_s, eta_over_s_min); + return (eta_over_s); } - -double TransportCoeffs::get_zeta_over_s(const double T, - const double mu_B) const { +double TransportCoeffs::get_zeta_over_s( + const double T, const double mu_B) const { // input T [1/fm], mu_B [1/fm] - double muB_in_GeV = mu_B*hbarc; + double muB_in_GeV = mu_B * hbarc; double zeta_over_s = 0.; if (bulk_T_ == 10) { // param. for 3D-Glauber + MUSIC + UrQMD double peak_norm = DATA.bulk_10_max; if (muB_in_GeV < 0.2) { - peak_norm = (DATA.bulk_10_max - + (DATA.bulk_10_max_muB0p2 - DATA.bulk_10_max) - /0.2*muB_in_GeV); + peak_norm = + (DATA.bulk_10_max + + (DATA.bulk_10_max_muB0p2 - DATA.bulk_10_max) / 0.2 + * muB_in_GeV); } else if (muB_in_GeV < 0.4) { - peak_norm = (DATA.bulk_10_max_muB0p2 - + (DATA.bulk_10_max_muB0p4 - DATA.bulk_10_max_muB0p2) - /0.2*(muB_in_GeV - 0.2)); + peak_norm = + (DATA.bulk_10_max_muB0p2 + + (DATA.bulk_10_max_muB0p4 - DATA.bulk_10_max_muB0p2) / 0.2 + * (muB_in_GeV - 0.2)); } else { peak_norm = DATA.bulk_10_max_muB0p4; } - const double Tpeak = (DATA.bulk_10_Tpeak - + DATA.bulk_10_Tpeak_muBcurv - *muB_in_GeV*muB_in_GeV); // GeV - const double B_width1 = DATA.bulk_10_width_low; // GeV - const double B_width2 = DATA.bulk_10_width_high; // GeV + const double Tpeak = + (DATA.bulk_10_Tpeak + + DATA.bulk_10_Tpeak_muBcurv * muB_in_GeV * muB_in_GeV); // GeV + const double B_width1 = DATA.bulk_10_width_low; // GeV + const double B_width2 = DATA.bulk_10_width_high; // GeV zeta_over_s = get_temperature_dependent_zeta_over_s_AsymGaussian( - T, peak_norm, B_width1, B_width2, Tpeak); + T, peak_norm, B_width1, B_width2, Tpeak); } else if (bulk_T_ == 8) { // latest param. for IPGlasma + MUSIC + UrQMD // Phys.Rev.C 102 (2020) 4, 044905, e-Print: 2005.14682 [nucl-th] @@ -177,7 +176,7 @@ double TransportCoeffs::get_zeta_over_s(const double T, const double B_width2 = 0.12; const double Tpeak = 0.160; zeta_over_s = get_temperature_dependent_zeta_over_s_AsymGaussian( - T, peak_norm, B_width1, B_width2, Tpeak); + T, peak_norm, B_width1, B_width2, Tpeak); } else if (bulk_T_ == 1) { zeta_over_s = get_temperature_dependent_zeta_over_s_default(T); } else if (bulk_T_ == 2) { @@ -194,138 +193,135 @@ double TransportCoeffs::get_zeta_over_s(const double T, const double B_width2 = 0.12; const double Tpeak = 0.160; zeta_over_s = get_temperature_dependent_zeta_over_s_AsymGaussian( - T, peak_norm, B_width1, B_width2, Tpeak); + T, peak_norm, B_width1, B_width2, Tpeak); } zeta_over_s = std::max(0., zeta_over_s); return zeta_over_s; } - //! Cauchy distribution double TransportCoeffs::get_temperature_dependent_zeta_over_s_duke( - const double T_in_fm) const { + const double T_in_fm) const { const double A = DATA.bulk_2_normalisation; const double G = DATA.bulk_2_width_in_GeV; const double Tpeak_in_GeV = DATA.bulk_2_peak_in_GeV; - const double T_in_GeV = T_in_fm*hbarc; - const double diff_ratio = (T_in_GeV-Tpeak_in_GeV)/G; + const double T_in_GeV = T_in_fm * hbarc; + const double diff_ratio = (T_in_GeV - Tpeak_in_GeV) / G; - //const double T_delta=(T_in_GeV*T_in_GeV)/(Tpeak_in_GeV*Tpeak_in_GeV)-1; - //double bulk_over_sden=A*(G*G)/(T_delta*T_delta+G*G); - return A/(1+diff_ratio*diff_ratio); + // const double T_delta=(T_in_GeV*T_in_GeV)/(Tpeak_in_GeV*Tpeak_in_GeV)-1; + // double bulk_over_sden=A*(G*G)/(T_delta*T_delta+G*G); + return A / (1 + diff_ratio * diff_ratio); } - //! Skewed Cauchy distribution double TransportCoeffs::get_temperature_dependent_zeta_over_s_sims( - const double T_in_fm) const { - const double T_in_GeV = T_in_fm*hbarc; + const double T_in_fm) const { + const double T_in_GeV = T_in_fm * hbarc; const double max = DATA.bulk_3_max; const double width = DATA.bulk_3_width_in_GeV; const double T_peak_in_GeV = DATA.bulk_3_T_peak_in_GeV; const double lambda = DATA.bulk_3_lambda_asymm; - const double diff = T_in_GeV-T_peak_in_GeV; + const double diff = T_in_GeV - T_peak_in_GeV; const double sign = (diff > 0) - (diff < 0); - const double diff_ratio = (diff)/(width*(lambda*sign+1)); + const double diff_ratio = (diff) / (width * (lambda * sign + 1)); - return max/(1+diff_ratio*diff_ratio); + return max / (1 + diff_ratio * diff_ratio); } - //! T dependent bulk viscosity from Gabriel double TransportCoeffs::get_temperature_dependent_zeta_over_s_default( - const double T_in_fm) const { + const double T_in_fm) const { ///////////////////////////////////////////// // Parametrization 1 // ///////////////////////////////////////////// // T dependent bulk viscosity from Gabriel // used in arXiv: 1502.01675 and 1704.04216 - const double T_in_GeV = T_in_fm*hbarc; + const double T_in_GeV = T_in_fm * hbarc; double Ttr = 0.18; - double dummy = T_in_GeV/Ttr; - double A1=-13.77, A2=27.55, A3=13.45; - double lambda1=0.9, lambda2=0.25, lambda3=0.9, lambda4=0.22; - double sigma1=0.025, sigma2=0.13, sigma3=0.0025, sigma4=0.022; - - double bulk = A1*dummy*dummy + A2*dummy - A3; - if (T_in_GeV < 0.995*Ttr) { - bulk = (lambda3*exp((dummy-1)/sigma3) - + lambda4*exp((dummy-1)/sigma4) + 0.03); + double dummy = T_in_GeV / Ttr; + double A1 = -13.77, A2 = 27.55, A3 = 13.45; + double lambda1 = 0.9, lambda2 = 0.25, lambda3 = 0.9, lambda4 = 0.22; + double sigma1 = 0.025, sigma2 = 0.13, sigma3 = 0.0025, sigma4 = 0.022; + + double bulk = A1 * dummy * dummy + A2 * dummy - A3; + if (T_in_GeV < 0.995 * Ttr) { + bulk = + (lambda3 * exp((dummy - 1) / sigma3) + + lambda4 * exp((dummy - 1) / sigma4) + 0.03); } - if (T_in_GeV > 1.05*Ttr) { - bulk = (lambda1*exp(-(dummy-1)/sigma1) - + lambda2*exp(-(dummy-1)/sigma2) + 0.001); + if (T_in_GeV > 1.05 * Ttr) { + bulk = + (lambda1 * exp(-(dummy - 1) / sigma1) + + lambda2 * exp(-(dummy - 1) / sigma2) + 0.001); } ///////////////////////////////////////////// // Parametrization 2 // ///////////////////////////////////////////// - //double Ttr=0.18/0.1973; - //double dummy=temperature/Ttr; - //double A1=-79.53, A2=159.067, A3=79.04; - //double lambda1=0.9, lambda2=0.25, lambda3=0.9, lambda4=0.22; - //double sigma1=0.025, sigma2=0.13, sigma3=0.0025, sigma4=0.022; - - //bulk = A1*dummy*dummy + A2*dummy - A3; - - //if (temperature < 0.997*Ttr) { - // bulk = (lambda3*exp((dummy-1)/sigma3) - // + lambda4*exp((dummy-1)/sigma4) + 0.03); - //} - //if (temperature > 1.04*Ttr) { - // bulk = (lambda1*exp(-(dummy-1)/sigma1) - // + lambda2*exp(-(dummy-1)/sigma2) + 0.001); - //} + // double Ttr=0.18/0.1973; + // double dummy=temperature/Ttr; + // double A1=-79.53, A2=159.067, A3=79.04; + // double lambda1=0.9, lambda2=0.25, lambda3=0.9, lambda4=0.22; + // double sigma1=0.025, sigma2=0.13, sigma3=0.0025, sigma4=0.022; + + // bulk = A1*dummy*dummy + A2*dummy - A3; + + // if (temperature < 0.997*Ttr) { + // bulk = (lambda3*exp((dummy-1)/sigma3) + // + lambda4*exp((dummy-1)/sigma4) + 0.03); + // } + // if (temperature > 1.04*Ttr) { + // bulk = (lambda1*exp(-(dummy-1)/sigma1) + // + lambda2*exp(-(dummy-1)/sigma2) + 0.001); + // } //////////////////////////////////////////// // Parametrization 3 // //////////////////////////////////////////// - //double Ttr=0.18/0.1973; - //double dummy=temperature/Ttr; - //double lambda1=0.9, lambda2=0.25, lambda3=0.9, lambda4=0.22; - //double sigma1=0.025, sigma2=0.13, sigma3=0.0025, sigma4=0.022; - - //if (temperature<0.99945*Ttr) { - // bulk = (lambda3*exp((dummy-1)/sigma3) - // + lambda4*exp((dummy-1)/sigma4) + 0.03); - //} - //if (temperature>0.99945*Ttr) { - // bulk = 0.901*exp(14.5*(1.0-dummy)) + 0.061/dummy/dummy; - //} - - return(bulk); + // double Ttr=0.18/0.1973; + // double dummy=temperature/Ttr; + // double lambda1=0.9, lambda2=0.25, lambda3=0.9, lambda4=0.22; + // double sigma1=0.025, sigma2=0.13, sigma3=0.0025, sigma4=0.022; + + // if (temperature<0.99945*Ttr) { + // bulk = (lambda3*exp((dummy-1)/sigma3) + // + lambda4*exp((dummy-1)/sigma4) + 0.03); + // } + // if (temperature>0.99945*Ttr) { + // bulk = 0.901*exp(14.5*(1.0-dummy)) + 0.061/dummy/dummy; + // } + + return (bulk); } - double TransportCoeffs::get_temperature_dependent_zeta_over_s_bigbroadP( - const double T_in_fm) const { + const double T_in_fm) const { // used in arXiv: 1901.04378 and 1908.06212 - const double T_in_GeV = T_in_fm*hbarc; + const double T_in_GeV = T_in_fm * hbarc; const double B_norm = 0.24; const double B_width = 1.5; const double Tpeak = 0.165; - const double Ttilde = (T_in_GeV/Tpeak - 1.)/B_width; - double bulk = B_norm/(Ttilde*Ttilde + 1.); + const double Ttilde = (T_in_GeV / Tpeak - 1.) / B_width; + double bulk = B_norm / (Ttilde * Ttilde + 1.); if (T_in_GeV < Tpeak) { - const double Tdiff = (T_in_GeV - Tpeak)/0.01; - bulk = B_norm*exp(-Tdiff*Tdiff); + const double Tdiff = (T_in_GeV - Tpeak) / 0.01; + bulk = B_norm * exp(-Tdiff * Tdiff); } - return(bulk); + return (bulk); } - double TransportCoeffs::get_temperature_dependent_zeta_over_s_AsymGaussian( - const double T_in_fm, const double B_norm, const double B_width1, - const double B_width2, const double Tpeak) const { - const double T_in_GeV = T_in_fm*hbarc; - double Tdiff = T_in_GeV - Tpeak; // GeV + const double T_in_fm, const double B_norm, const double B_width1, + const double B_width2, const double Tpeak) const { + const double T_in_GeV = T_in_fm * hbarc; + double Tdiff = T_in_GeV - Tpeak; // GeV if (Tdiff > 0.) { - Tdiff = Tdiff/B_width2; + Tdiff = Tdiff / B_width2; } else { - Tdiff = Tdiff/B_width1; + Tdiff = Tdiff / B_width1; } - double bulk = B_norm*exp(-Tdiff*Tdiff); - return(bulk); + double bulk = B_norm * exp(-Tdiff * Tdiff); + return (bulk); } diff --git a/src/transport_coeffs.h b/src/transport_coeffs.h index 18f89a93..3d4fd7b7 100644 --- a/src/transport_coeffs.h +++ b/src/transport_coeffs.h @@ -5,7 +5,7 @@ #include "data.h" class TransportCoeffs { - private: + private: const InitData &DATA; double shear_relax_time_factor_; double bulk_relax_time_factor_; @@ -14,7 +14,7 @@ class TransportCoeffs { const int shear_muB_; const int bulk_T_; - public: + public: TransportCoeffs() = delete; TransportCoeffs(const InitData &DATA_in); @@ -35,43 +35,41 @@ class TransportCoeffs { double get_temperature_dependence_shear_profile(const double T) const; double get_temperature_dependent_zeta_over_s_bigbroadP( - const double T) const; + const double T) const; double get_temperature_dependent_zeta_over_s_AsymGaussian( const double T_in_fm, const double B_norm, const double B_width1, const double B_width2, const double Tpeak) const; // Second-order coefficients double get_shear_relax_time_factor() const { - return(shear_relax_time_factor_); + return (shear_relax_time_factor_); } double get_bulk_relax_time_factor() const { - return(bulk_relax_time_factor_); + return (bulk_relax_time_factor_); } // shear - double get_tau_pipi_coeff() const { return(10./7.); } - double get_delta_pipi_coeff() const { return(4./3.); } - double get_phi7_coeff() const { return(9./70.); } - double get_lambda_pibulkPi_coeff() const { return(6./5.); } + double get_tau_pipi_coeff() const { return (10. / 7.); } + double get_delta_pipi_coeff() const { return (4. / 3.); } + double get_phi7_coeff() const { return (9. / 70.); } + double get_lambda_pibulkPi_coeff() const { return (6. / 5.); } // bulk - double get_lambda_bulkPipi_coeff() const { return(8./5.); } - double get_delta_bulkPibulkPi_coeff() const { return(2./3.); } - double get_tau_bulkPibulkPi_coeff() const { return(0.); } // unknown - + double get_lambda_bulkPipi_coeff() const { return (8. / 5.); } + double get_delta_bulkPibulkPi_coeff() const { return (2. / 3.); } + double get_tau_bulkPibulkPi_coeff() const { return (0.); } // unknown // net baryon diffusion // from conformal kinetic theory - double get_delta_qq_coeff() const { return(1.0); } + double get_delta_qq_coeff() const { return (1.0); } // from 14-momentum massless - double get_lambda_qq_coeff() const { return(3./5.); } - - double get_l_qpi_coeff() const { return(0.); } - double get_lambda_qpi_coeff() const { return(0.); } + double get_lambda_qq_coeff() const { return (3. / 5.); } + double get_l_qpi_coeff() const { return (0.); } + double get_lambda_qpi_coeff() const { return (0.); } }; #endif // SRC_TRANSPORT_H_ diff --git a/src/u_derivative.cpp b/src/u_derivative.cpp index 7d4af690..def1b9d3 100644 --- a/src/u_derivative.cpp +++ b/src/u_derivative.cpp @@ -1,23 +1,21 @@ -#include "util.h" -#include "data.h" +#include "u_derivative.h" + #include "cell.h" +#include "data.h" #include "minmod.h" -#include "eos.h" -#include "u_derivative.h" +#include "util.h" -U_derivative::U_derivative(const InitData &DATA_in, const EOS &eosIn) : - DATA(DATA_in), - eos(eosIn), - minmod(DATA_in) { - dUsup = {{{0.0}}}; // dUsup[m][n] = partial^n u^m - dUoverTsup = {{{0.0}}}; // dUoverTsup[m][n] = partial^n (u^m/T) - dUTsup = {{{0.0}}}; // dUTsup[m][n] = partial^n (Tu^m) +U_derivative::U_derivative(const InitData &DATA_in, const EOS &eosIn) + : DATA(DATA_in), eos(eosIn), minmod(DATA_in) { + dUsup = {{{0.0}}}; // dUsup[m][n] = partial^n u^m + dUoverTsup = {{{0.0}}}; // dUoverTsup[m][n] = partial^n (u^m/T) + dUTsup = {{{0.0}}}; // dUTsup[m][n] = partial^n (Tu^m) } //! This function is a shell function to calculate parital^\nu u^\mu -void U_derivative::MakedU(const double tau, Fields &arenaFieldsPrev, - Fields &arenaFieldsCurr, const int fieldIdx, - const int ix, const int iy, const int ieta) { +void U_derivative::MakedU( + const double tau, Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, + const int fieldIdx, const int ix, const int iy, const int ieta) { dUsup = {{{0.0}}}; dUoverTsup = {{{0.0}}}; dUTsup = {{{0.0}}}; @@ -28,54 +26,50 @@ void U_derivative::MakedU(const double tau, Fields &arenaFieldsPrev, MakeDTau(tau, arenaFieldsPrev, arenaFieldsCurr, fieldIdx); } - //! this function returns the expansion rate on the grid double U_derivative::calculate_expansion_rate( - const double tau, Fields &arena, const int fieldIdx) { + const double tau, Fields &arena, const int fieldIdx) { double partial_mu_u_supmu = 0.0; for (int mu = 0; mu < 4; mu++) { double gfac = (mu == 0 ? -1.0 : 1.0); // for expansion rate: theta - partial_mu_u_supmu += dUsup[mu][mu]*gfac; + partial_mu_u_supmu += dUsup[mu][mu] * gfac; } - double theta = partial_mu_u_supmu + arena.u_[0][fieldIdx]/tau; - return(theta); + double theta = partial_mu_u_supmu + arena.u_[0][fieldIdx] / tau; + return (theta); } - //! this function returns Du^\mu -void U_derivative::calculate_Du_supmu(const double tau, Fields &arena, - const int fieldIdx, DumuVec &a) { +void U_derivative::calculate_Du_supmu( + const double tau, Fields &arena, const int fieldIdx, DumuVec &a) { for (int mu = 0; mu <= 4; mu++) { double u_supnu_partial_nu_u_supmu = 0.0; for (int nu = 0; nu < 4; nu++) { - double tfac = (nu==0 ? -1.0 : 1.0); - u_supnu_partial_nu_u_supmu += ( - tfac*arena.u_[nu][fieldIdx]*dUsup[mu][nu]); + double tfac = (nu == 0 ? -1.0 : 1.0); + u_supnu_partial_nu_u_supmu += + (tfac * arena.u_[nu][fieldIdx] * dUsup[mu][nu]); } a[mu] = u_supnu_partial_nu_u_supmu; } } - // This is a shell function to compute all 4 kinds of vorticity tensors void U_derivative::compute_vorticity_shell( - const double tau, Fields &arena_prev, Fields &arena_curr, - const int ieta, const int ix, const int iy, - const int fieldIdx, const double eta, - VorticityVec &omega_local_kSP, VorticityVec &omega_local_knoSP, - VorticityVec &omega_local_th, VorticityVec &omega_local_T, - VelocityShearVec &sigma_th_local, DmuMuBoverTVec &DbetaMu) { + const double tau, Fields &arena_prev, Fields &arena_curr, const int ieta, + const int ix, const int iy, const int fieldIdx, const double eta, + VorticityVec &omega_local_kSP, VorticityVec &omega_local_knoSP, + VorticityVec &omega_local_th, VorticityVec &omega_local_T, + VelocityShearVec &sigma_th_local, DmuMuBoverTVec &DbetaMu) { MakedU(tau, arena_prev, arena_curr, fieldIdx, ix, iy, ieta); DumuVec a_local; calculate_Du_supmu(tau, arena_curr, fieldIdx, a_local); VorticityVec omega_local; calculate_kinetic_vorticity_with_spatial_projector( - tau, arena_curr, fieldIdx, a_local, omega_local); + tau, arena_curr, fieldIdx, a_local, omega_local); omega_local_kSP = transform_vorticity_to_tz(omega_local, eta); calculate_kinetic_vorticity_no_spatial_projection( - tau, arena_curr, fieldIdx, omega_local); + tau, arena_curr, fieldIdx, omega_local); omega_local_knoSP = transform_vorticity_to_tz(omega_local, eta); calculate_thermal_vorticity(tau, arena_curr, fieldIdx, omega_local); omega_local_th = transform_vorticity_to_tz(omega_local, eta); @@ -83,77 +77,75 @@ void U_derivative::compute_vorticity_shell( omega_local_T = transform_vorticity_to_tz(omega_local, eta); VelocityShearVec sigma_th_Mline; - calculate_thermal_shear_tensor(tau, arena_curr, fieldIdx, - sigma_th_Mline); + calculate_thermal_shear_tensor(tau, arena_curr, fieldIdx, sigma_th_Mline); sigma_th_local = transform_SigmaMuNu_to_tz(sigma_th_Mline, eta); DmuMuBoverTVec DbetaMu_local; get_DmuMuBoverTVec(DbetaMu_local); DbetaMu = transform_vector_to_tz(DbetaMu_local, eta); } - // This function transforms the vorticity tensor from tau-eta to tz // It outputs (sigma^tt, sigma^tx, sigma^ty, sigma^tz, // sigma^xx, sigma^xy, sigma^xz, // sigma^yy, sigma^yz, // sigma^zz) VelocityShearVec U_derivative::transform_SigmaMuNu_to_tz( - const VelocityShearVec sigma_Mline, const double eta) { + const VelocityShearVec sigma_Mline, const double eta) { VelocityShearVec sigma_Cart; const double cosh_eta = cosh(eta); const double sinh_eta = sinh(eta); - sigma_Cart[0] = (sigma_Mline[0]*cosh_eta*cosh_eta - + 2.*sigma_Mline[3]*cosh_eta*sinh_eta - + sigma_Mline[9]*sinh_eta*sinh_eta); - sigma_Cart[1] = sigma_Mline[1]*cosh_eta + sigma_Mline[6]*sinh_eta; - sigma_Cart[2] = sigma_Mline[2]*cosh_eta + sigma_Mline[8]*sinh_eta; - sigma_Cart[3] = (sigma_Mline[0]*cosh_eta*sinh_eta - + sigma_Mline[3]*(cosh_eta*cosh_eta + sinh_eta*sinh_eta) - + sigma_Mline[9]*sinh_eta*cosh_eta); + sigma_Cart[0] = + (sigma_Mline[0] * cosh_eta * cosh_eta + + 2. * sigma_Mline[3] * cosh_eta * sinh_eta + + sigma_Mline[9] * sinh_eta * sinh_eta); + sigma_Cart[1] = sigma_Mline[1] * cosh_eta + sigma_Mline[6] * sinh_eta; + sigma_Cart[2] = sigma_Mline[2] * cosh_eta + sigma_Mline[8] * sinh_eta; + sigma_Cart[3] = + (sigma_Mline[0] * cosh_eta * sinh_eta + + sigma_Mline[3] * (cosh_eta * cosh_eta + sinh_eta * sinh_eta) + + sigma_Mline[9] * sinh_eta * cosh_eta); sigma_Cart[4] = sigma_Mline[4]; sigma_Cart[5] = sigma_Mline[5]; - sigma_Cart[6] = sigma_Mline[1]*sinh_eta + sigma_Mline[6]*cosh_eta; + sigma_Cart[6] = sigma_Mline[1] * sinh_eta + sigma_Mline[6] * cosh_eta; sigma_Cart[7] = sigma_Mline[7]; - sigma_Cart[8] = sigma_Mline[2]*sinh_eta + sigma_Mline[8]*cosh_eta; - sigma_Cart[9] = (sigma_Mline[0]*sinh_eta*sinh_eta - + 2.*sigma_Mline[3]*cosh_eta*sinh_eta - + sigma_Mline[9]*cosh_eta*cosh_eta); - return(sigma_Cart); + sigma_Cart[8] = sigma_Mline[2] * sinh_eta + sigma_Mline[8] * cosh_eta; + sigma_Cart[9] = + (sigma_Mline[0] * sinh_eta * sinh_eta + + 2. * sigma_Mline[3] * cosh_eta * sinh_eta + + sigma_Mline[9] * cosh_eta * cosh_eta); + return (sigma_Cart); } - // This function transforms the vorticity tensor from tau-eta to tz // It outputs (omega^tx, omega^ty, omega^tz, omega^xy, omega^xz, omega^yz) VorticityVec U_derivative::transform_vorticity_to_tz( - const VorticityVec omega_Mline, const double eta) { + const VorticityVec omega_Mline, const double eta) { VorticityVec omega_Cart; const double cosh_eta = cosh(eta); const double sinh_eta = sinh(eta); - omega_Cart[0] = omega_Mline[0]*cosh_eta - omega_Mline[4]*sinh_eta; - omega_Cart[1] = omega_Mline[1]*cosh_eta - omega_Mline[5]*sinh_eta; + omega_Cart[0] = omega_Mline[0] * cosh_eta - omega_Mline[4] * sinh_eta; + omega_Cart[1] = omega_Mline[1] * cosh_eta - omega_Mline[5] * sinh_eta; omega_Cart[2] = omega_Mline[2]; omega_Cart[3] = omega_Mline[3]; - omega_Cart[4] = omega_Mline[4]*cosh_eta - omega_Mline[0]*sinh_eta; - omega_Cart[5] = omega_Mline[5]*cosh_eta - omega_Mline[1]*sinh_eta; - return(omega_Cart); + omega_Cart[4] = omega_Mline[4] * cosh_eta - omega_Mline[0] * sinh_eta; + omega_Cart[5] = omega_Mline[5] * cosh_eta - omega_Mline[1] * sinh_eta; + return (omega_Cart); } - // This function transforms the vorticity tensor from tau-eta to tz // It outputs (vec^t, vec^x, vec^y, vec^z) DmuMuBoverTVec U_derivative::transform_vector_to_tz( - const DmuMuBoverTVec vec_Mline, const double eta) { + const DmuMuBoverTVec vec_Mline, const double eta) { DmuMuBoverTVec vec_Cart; const double cosh_eta = cosh(eta); const double sinh_eta = sinh(eta); - vec_Cart[0] = vec_Mline[0]*cosh_eta + vec_Mline[3]*sinh_eta; + vec_Cart[0] = vec_Mline[0] * cosh_eta + vec_Mline[3] * sinh_eta; vec_Cart[1] = vec_Mline[1]; vec_Cart[2] = vec_Mline[2]; - vec_Cart[3] = vec_Mline[0]*sinh_eta + vec_Mline[3]*cosh_eta; - return(vec_Cart); + vec_Cart[3] = vec_Mline[0] * sinh_eta + vec_Mline[3] * cosh_eta; + return (vec_Cart); } - //! this function computes the kinetic vorticity with the spatial projectors //! the output omega^{\mu\nu} can be directly used in the EoM for the //! shear viscous tensor and diffusion current @@ -162,8 +154,8 @@ DmuMuBoverTVec U_derivative::transform_vector_to_tz( //! Because MUSIC use the metric g = (-1, 1, 1, 1), the output omega^{\mu\nu} //! differs from the ones with g = (1, -1, -1, -1) by a minus sign void U_derivative::calculate_kinetic_vorticity_with_spatial_projector( - const double tau, Fields &arena, const int fieldIdx, - const DumuVec &a_local, VorticityVec &omega) { + const double tau, Fields &arena, const int fieldIdx, const DumuVec &a_local, + VorticityVec &omega) { FlowVec u_local; double dUsup_local[4][4]; for (int i = 0; i < 4; i++) { @@ -181,16 +173,20 @@ void U_derivative::calculate_kinetic_vorticity_with_spatial_projector( // compute the spatial components of omega^{\mu\nu} for (int mu = 1; mu < 4; mu++) { for (int nu = mu + 1; nu < 4; nu++) { - omega_local[mu][nu] = 0.5*( - (dUsup_local[nu][mu] - dUsup_local[mu][nu]) - + (u_local[mu]*a_local[nu] - u_local[nu]*a_local[mu]) - + u_local[3]*u_local[0]/tau*( u_local[mu]*DATA.gmunu[nu][3] - - u_local[nu]*DATA.gmunu[mu][3]) - //- u_local[3]/tau*(- DATA.gmunu[mu][0]*DATA.gmunu[nu][3] - // + DATA.gmunu[mu][3]*DATA.gmunu[nu][0]) - //+ u_local[3]*u_local[3]/tau*(- u_local[mu]*DATA.gmunu[nu][0] - // + u_local[nu]*DATA.gmunu[mu][0]) - ); + omega_local[mu][nu] = + 0.5 + * ((dUsup_local[nu][mu] - dUsup_local[mu][nu]) + + (u_local[mu] * a_local[nu] - u_local[nu] * a_local[mu]) + + u_local[3] * u_local[0] / tau + * (u_local[mu] * DATA.gmunu[nu][3] + - u_local[nu] * DATA.gmunu[mu][3]) + //- u_local[3]/tau*(- DATA.gmunu[mu][0]*DATA.gmunu[nu][3] + // + DATA.gmunu[mu][3]*DATA.gmunu[nu][0]) + //+ u_local[3]*u_local[3]/tau*(- + // u_local[mu]*DATA.gmunu[nu][0] + // + + // u_local[nu]*DATA.gmunu[mu][0]) + ); omega_local[nu][mu] = -omega_local[mu][nu]; } } @@ -200,9 +196,9 @@ void U_derivative::calculate_kinetic_vorticity_with_spatial_projector( for (int mu = 1; mu < 4; mu++) { double temp = 0.0; for (int nu = 1; nu < 4; nu++) { - temp += omega_local[mu][nu]*u_local[nu]; + temp += omega_local[mu][nu] * u_local[nu]; } - omega_local[0][mu] = temp/u_local[0]; + omega_local[0][mu] = temp / u_local[0]; } omega[0] = omega_local[0][1]; @@ -213,16 +209,14 @@ void U_derivative::calculate_kinetic_vorticity_with_spatial_projector( omega[5] = omega_local[2][3]; } - //! this function computes the thermal vorticity //! it outputs omega^{\mu\nu} in the metric g = (-1, 1, 1, 1) which differs //! from the ones with g = (1, -1, -1, -1) by a minus sign void U_derivative::calculate_thermal_vorticity( - const double tau, Fields &arena, const int fieldIdx, - VorticityVec &omega) { + const double tau, Fields &arena, const int fieldIdx, VorticityVec &omega) { // this function computes the thermal vorticity - double T_local = eos.get_temperature(arena.e_[fieldIdx], - arena.rhob_[fieldIdx]); + double T_local = + eos.get_temperature(arena.e_[fieldIdx], arena.rhob_[fieldIdx]); if (T_local > T_tol) { FlowVec u_local; double dUsup_local[4][4]; @@ -236,12 +230,11 @@ void U_derivative::calculate_thermal_vorticity( double omega_thermal[4][4]; for (int mu = 0; mu < 4; mu++) { for (int nu = mu + 1; nu < 4; nu++) { - omega_thermal[mu][nu] = ( - - 0.5*(dUsup_local[nu][mu] - dUsup_local[mu][nu]) - - u_local[3]/(2.*tau*T_local)*( - DATA.gmunu[mu][0]*DATA.gmunu[nu][3] - - DATA.gmunu[mu][3]*DATA.gmunu[nu][0]) - ); + omega_thermal[mu][nu] = + (-0.5 * (dUsup_local[nu][mu] - dUsup_local[mu][nu]) + - u_local[3] / (2. * tau * T_local) + * (DATA.gmunu[mu][0] * DATA.gmunu[nu][3] + - DATA.gmunu[mu][3] * DATA.gmunu[nu][0])); } } @@ -261,16 +254,15 @@ void U_derivative::calculate_thermal_vorticity( } } - //! this function computes the thermal shear tensor //! it outputs sigma_th^{\mu\nu} in the metric g = (-1, 1, 1, 1) which differs //! from the ones with g = (1, -1, -1, -1) by a minus sign void U_derivative::calculate_thermal_shear_tensor( - const double tau, Fields &arena, const int fieldIdx, - VelocityShearVec &sigma_th) { + const double tau, Fields &arena, const int fieldIdx, + VelocityShearVec &sigma_th) { // this function computes the thermal shear tensor - double T_local = eos.get_temperature(arena.e_[fieldIdx], - arena.rhob_[fieldIdx]); + double T_local = + eos.get_temperature(arena.e_[fieldIdx], arena.rhob_[fieldIdx]); if (T_local > T_tol) { FlowVec u_local; double dUsup_local[4][4]; @@ -284,14 +276,13 @@ void U_derivative::calculate_thermal_shear_tensor( double sigma_thermal[4][4]; for (int mu = 0; mu < 4; mu++) { for (int nu = mu; nu < 4; nu++) { - sigma_thermal[mu][nu] = ( - 0.5*(dUsup_local[nu][mu] + dUsup_local[mu][nu]) - - u_local[3]/(2.*tau*T_local)*( - DATA.gmunu[mu][0]*DATA.gmunu[nu][3] - + DATA.gmunu[mu][3]*DATA.gmunu[nu][0]) - + u_local[0]/(tau*T_local)*( - DATA.gmunu[mu][3]*DATA.gmunu[nu][3]) - ); + sigma_thermal[mu][nu] = + (0.5 * (dUsup_local[nu][mu] + dUsup_local[mu][nu]) + - u_local[3] / (2. * tau * T_local) + * (DATA.gmunu[mu][0] * DATA.gmunu[nu][3] + + DATA.gmunu[mu][3] * DATA.gmunu[nu][0]) + + u_local[0] / (tau * T_local) + * (DATA.gmunu[mu][3] * DATA.gmunu[nu][3])); } } @@ -306,22 +297,19 @@ void U_derivative::calculate_thermal_shear_tensor( sigma_th[8] = sigma_thermal[2][3]; sigma_th[9] = sigma_thermal[3][3]; } else { - for (auto &sigma_i : sigma_th) - sigma_i = 0.; + for (auto &sigma_i : sigma_th) sigma_i = 0.; } } - //! this function computes the temperature- (T-)vorticity //! it outputs omega^{\mu\nu} in the metric g = (-1, 1, 1, 1) which differs //! from the ones with g = (1, -1, -1, -1) by a minus sign void U_derivative::calculate_T_vorticity( - const double tau, Fields &arena, const int fieldIdx, - VorticityVec &omega) { + const double tau, Fields &arena, const int fieldIdx, VorticityVec &omega) { // this function computes the T-vorticity FlowVec u_local; - double T_local = eos.get_temperature(arena.e_[fieldIdx], - arena.rhob_[fieldIdx]); + double T_local = + eos.get_temperature(arena.e_[fieldIdx], arena.rhob_[fieldIdx]); double dUsup_local[4][4]; for (int i = 0; i < 4; i++) { u_local[i] = arena.u_[i][fieldIdx]; @@ -333,12 +321,11 @@ void U_derivative::calculate_T_vorticity( double omega_thermal[4][4]; for (int mu = 0; mu < 4; mu++) { for (int nu = mu + 1; nu < 4; nu++) { - omega_thermal[mu][nu] = ( - - 0.5*(dUsup_local[nu][mu] - dUsup_local[mu][nu]) - - u_local[3]*T_local/(2.*tau)*( - DATA.gmunu[mu][0]*DATA.gmunu[nu][3] - - DATA.gmunu[mu][3]*DATA.gmunu[nu][0]) - ); + omega_thermal[mu][nu] = + (-0.5 * (dUsup_local[nu][mu] - dUsup_local[mu][nu]) + - u_local[3] * T_local / (2. * tau) + * (DATA.gmunu[mu][0] * DATA.gmunu[nu][3] + - DATA.gmunu[mu][3] * DATA.gmunu[nu][0])); } } @@ -350,13 +337,11 @@ void U_derivative::calculate_T_vorticity( omega[5] = omega_thermal[2][3]; } - //! this function computes the conventional kinetic vorticity //! it outputs omega^{\mu\nu} in the metric g = (-1, 1, 1, 1) which differs //! from the ones with g = (1, -1, -1, -1) by a minus sign void U_derivative::calculate_kinetic_vorticity_no_spatial_projection( - const double tau, Fields &arena, const int fieldIdx, - VorticityVec &omega) { + const double tau, Fields &arena, const int fieldIdx, VorticityVec &omega) { // this function computes the full kinetic vorticity without the spatial // projection // omega^{\mu\nu} = \partial^\mu u^\nu - \partial^\nu u^\mu @@ -372,12 +357,11 @@ void U_derivative::calculate_kinetic_vorticity_no_spatial_projection( double omega_thermal[4][4]; for (int mu = 0; mu < 4; mu++) { for (int nu = mu + 1; nu < 4; nu++) { - omega_thermal[mu][nu] = ( - - 0.5*(dUsup_local[nu][mu] - dUsup_local[mu][nu]) - - u_local[3]/(2.*tau)*( - + DATA.gmunu[mu][0]*DATA.gmunu[nu][3] - - DATA.gmunu[mu][3]*DATA.gmunu[nu][0]) - ); + omega_thermal[mu][nu] = + (-0.5 * (dUsup_local[nu][mu] - dUsup_local[mu][nu]) + - u_local[3] / (2. * tau) + * (+DATA.gmunu[mu][0] * DATA.gmunu[nu][3] + - DATA.gmunu[mu][3] * DATA.gmunu[nu][0])); } } @@ -389,15 +373,14 @@ void U_derivative::calculate_kinetic_vorticity_no_spatial_projection( omega[5] = omega_thermal[2][3]; } - //! This funciton returns the velocity shear tensor sigma^{\mu\nu} //! it outputs sigma^{\mu\nu} in the metric g = (-1, 1, 1, 1) //! Please note that this output differs from the sigma^{\mu\nu} in the metric //! g = (1, -1, -1, -1) by a minus sign void U_derivative::calculate_velocity_shear_tensor( - const double tau, Fields &arena, const int fieldIdx, - const double theta_u_local, - const DumuVec &a_local, VelocityShearVec &sigma) { + const double tau, Fields &arena, const int fieldIdx, + const double theta_u_local, const DumuVec &a_local, + VelocityShearVec &sigma) { FlowVec u_local; double dUsup_local[4][4]; for (int i = 0; i < 4; i++) { @@ -415,37 +398,42 @@ void U_derivative::calculate_velocity_shear_tensor( } else { gfac = 0.0; } - sigma_local[a][b] = ((dUsup_local[a][b] + dUsup_local[b][a])/2. - - (gfac + u_local[a]*u_local[b])*theta_u_local/3. - + u_local[0]/tau*DATA.gmunu[a][3]*DATA.gmunu[b][3] - + u_local[3]*u_local[0]/tau/2. - *(DATA.gmunu[a][3]*u_local[b] + DATA.gmunu[b][3]*u_local[a]) - + (u_local[a]*a_local[b] + u_local[b]*a_local[a])/2.); + sigma_local[a][b] = + ((dUsup_local[a][b] + dUsup_local[b][a]) / 2. + - (gfac + u_local[a] * u_local[b]) * theta_u_local / 3. + + u_local[0] / tau * DATA.gmunu[a][3] * DATA.gmunu[b][3] + + u_local[3] * u_local[0] / tau / 2. + * (DATA.gmunu[a][3] * u_local[b] + + DATA.gmunu[b][3] * u_local[a]) + + (u_local[a] * a_local[b] + u_local[b] * a_local[a]) / 2.); sigma_local[b][a] = sigma_local[a][b]; } } // make sigma[3][3] using traceless condition - sigma_local[3][3] = ( - ( 2.*( u_local[1]*u_local[2]*sigma_local[1][2] - + u_local[1]*u_local[3]*sigma_local[1][3] - + u_local[2]*u_local[3]*sigma_local[2][3]) - - (u_local[0]*u_local[0] - u_local[1]*u_local[1])*sigma_local[1][1] - - (u_local[0]*u_local[0] - u_local[2]*u_local[2])*sigma_local[2][2]) - /(u_local[0]*u_local[0] - u_local[3]*u_local[3])); + sigma_local[3][3] = + ((2. + * (u_local[1] * u_local[2] * sigma_local[1][2] + + u_local[1] * u_local[3] * sigma_local[1][3] + + u_local[2] * u_local[3] * sigma_local[2][3]) + - (u_local[0] * u_local[0] - u_local[1] * u_local[1]) + * sigma_local[1][1] + - (u_local[0] * u_local[0] - u_local[2] * u_local[2]) + * sigma_local[2][2]) + / (u_local[0] * u_local[0] - u_local[3] * u_local[3])); // make sigma[0][i] using transversality for (int a = 1; a < 4; a++) { double temp = 0.0; for (int b = 1; b < 4; b++) { - temp += sigma_local[a][b]*u_local[b]; + temp += sigma_local[a][b] * u_local[b]; } - sigma_local[0][a] = temp/u_local[0]; + sigma_local[0][a] = temp / u_local[0]; } // make sigma[0][0] double temp = 0.0; for (int a = 1; a < 4; a++) { - temp += sigma_local[0][a]*u_local[a]; + temp += sigma_local[0][a] * u_local[a]; } - sigma_local[0][0] = temp/u_local[0]; + sigma_local[0][0] = temp / u_local[0]; sigma[0] = sigma_local[0][0]; sigma[1] = sigma_local[0][1]; @@ -459,70 +447,70 @@ void U_derivative::calculate_velocity_shear_tensor( sigma[9] = sigma_local[3][3]; } - //! this function returns the vector D^\mu(\mu_B/T) void U_derivative::get_DmuMuBoverTVec(DmuMuBoverTVec &vec) { - for (int mu = 0; mu < 4; mu++) - vec[mu] = dUsup[4][mu]; + for (int mu = 0; mu < 4; mu++) vec[mu] = dUsup[4][mu]; } - -int U_derivative::MakeDSpatial(const double tau, Fields &arena, - const int fieldIdx, - const int ix, const int iy, const int ieta) { +int U_derivative::MakeDSpatial( + const double tau, Fields &arena, const int fieldIdx, const int ix, + const int iy, const int ieta) { // taken care of the tau factor - const double delta[4] = {0.0, DATA.delta_x, DATA.delta_y, - DATA.delta_eta*tau}; + const double delta[4] = { + 0.0, DATA.delta_x, DATA.delta_y, DATA.delta_eta * tau}; // calculate dUsup[m][n] = partial^n u^m - FieldNeighbourLoopIdeal1(arena, ix, iy, ieta, FNLILAMBDAS1{ - for (int m = 1; m < 4; m++) { - const double f = arena.u_[m][Ic]; - const double fp1 = arena.u_[m][Ip1]; - const double fm1 = arena.u_[m][Im1]; - dUsup[m][direction] = (minmod.minmod_dx(fp1, f, fm1) - /delta[direction]); - } - if (DATA.output_vorticity == 1) { - for (int m = 0; m < 4; m++) { - const double f = arena.u_[m][Ic]; + FieldNeighbourLoopIdeal1( + arena, ix, iy, ieta, FNLILAMBDAS1 { + for (int m = 1; m < 4; m++) { + const double f = arena.u_[m][Ic]; const double fp1 = arena.u_[m][Ip1]; const double fm1 = arena.u_[m][Im1]; - double T = eos.get_temperature(arena.e_[Ic], - arena.rhob_[Ic]); - double Tp1 = eos.get_temperature(arena.e_[Ip1], - arena.rhob_[Ip1]); - double Tm1 = eos.get_temperature(arena.e_[Im1], - arena.rhob_[Im1]); - if (T > T_tol && Tp1 > T_tol && Tm1 > T_tol) { - dUoverTsup[m][direction] = ( - minmod.minmod_dx(fp1/Tp1, f/T, fm1/Tm1) - /delta[direction]); - } else { - dUoverTsup[m][direction] = 0.; + dUsup[m][direction] = + (minmod.minmod_dx(fp1, f, fm1) / delta[direction]); + } + if (DATA.output_vorticity == 1) { + for (int m = 0; m < 4; m++) { + const double f = arena.u_[m][Ic]; + const double fp1 = arena.u_[m][Ip1]; + const double fm1 = arena.u_[m][Im1]; + double T = + eos.get_temperature(arena.e_[Ic], arena.rhob_[Ic]); + double Tp1 = + eos.get_temperature(arena.e_[Ip1], arena.rhob_[Ip1]); + double Tm1 = + eos.get_temperature(arena.e_[Im1], arena.rhob_[Im1]); + if (T > T_tol && Tp1 > T_tol && Tm1 > T_tol) { + dUoverTsup[m][direction] = + (minmod.minmod_dx(fp1 / Tp1, f / T, fm1 / Tm1) + / delta[direction]); + } else { + dUoverTsup[m][direction] = 0.; + } + dUTsup[m][direction] = + (minmod.minmod_dx(fp1 * Tp1, f * T, fm1 * Tm1) + / delta[direction]); } - dUTsup[m][direction] = ( - minmod.minmod_dx(fp1*Tp1, f*T, fm1*Tm1)/delta[direction]); } - } - // Sangyong Nov 18 2014 - // Here we make derivatives of muB/T - // dUsup[rk_flag][4][n] = partial_n (muB/T) - // partial_x (muB/T) and partial_y (muB/T) first - if (DATA.turn_on_diff == 1 || DATA.output_vorticity == 1) { - double f = (eos.get_muB(arena.e_[Ic], arena.rhob_[Ic]) - /eos.get_temperature(arena.e_[Ic], arena.rhob_[Ic])); - double fp1 = (eos.get_muB(arena.e_[Ip1], arena.rhob_[Ip1]) - /eos.get_temperature(arena.e_[Ip1], - arena.rhob_[Ip1])); - double fm1 = (eos.get_muB(arena.e_[Im1], arena.rhob_[Im1]) - /eos.get_temperature(arena.e_[Im1], - arena.rhob_[Im1])); - dUsup[4][direction] = (minmod.minmod_dx(fp1, f, fm1) - /delta[direction]); - } - }); + // Sangyong Nov 18 2014 + // Here we make derivatives of muB/T + // dUsup[rk_flag][4][n] = partial_n (muB/T) + // partial_x (muB/T) and partial_y (muB/T) first + if (DATA.turn_on_diff == 1 || DATA.output_vorticity == 1) { + double f = + (eos.get_muB(arena.e_[Ic], arena.rhob_[Ic]) + / eos.get_temperature(arena.e_[Ic], arena.rhob_[Ic])); + double fp1 = + (eos.get_muB(arena.e_[Ip1], arena.rhob_[Ip1]) + / eos.get_temperature(arena.e_[Ip1], arena.rhob_[Ip1])); + double fm1 = + (eos.get_muB(arena.e_[Im1], arena.rhob_[Im1]) + / eos.get_temperature(arena.e_[Im1], arena.rhob_[Im1])); + dUsup[4][direction] = + (minmod.minmod_dx(fp1, f, fm1) / delta[direction]); + } + }); /* for u[0], use u[0]u[0] = 1 + u[i]u[i] */ /* u[0]_m = u[i]_m (u[i]/u[0]) */ @@ -531,24 +519,23 @@ int U_derivative::MakeDSpatial(const double tau, Fields &arena, double f = 0.0; for (int m = 1; m < 4; m++) { // (partial_n u^m) u[m] - f += dUsup[m][n]*(arena.u_[m][fieldIdx]); + f += dUsup[m][n] * (arena.u_[m][fieldIdx]); } f /= arena.u_[0][fieldIdx]; dUsup[0][n] = f; } return 1; -} /* MakeDSpatial */ - +} /* MakeDSpatial */ -int U_derivative::MakeDTau(const double tau, - const Fields &arenaFieldsPrev, - const Fields &arenaFieldsCurr, const int fieldIdx) { +int U_derivative::MakeDTau( + const double tau, const Fields &arenaFieldsPrev, + const Fields &arenaFieldsCurr, const int fieldIdx) { /* this makes dU[m][0] = partial^tau u^m */ /* note the minus sign at the end because of g[0][0] = -1 */ - const double eps = arenaFieldsCurr.e_[fieldIdx]; + const double eps = arenaFieldsCurr.e_[fieldIdx]; const double rhob = arenaFieldsCurr.rhob_[fieldIdx]; - const double eps_prev = arenaFieldsPrev.e_[fieldIdx]; + const double eps_prev = arenaFieldsPrev.e_[fieldIdx]; const double rhob_prev = arenaFieldsPrev.rhob_[fieldIdx]; const double T = eos.get_temperature(eps, rhob); const double T_prev = eos.get_temperature(eps_prev, rhob_prev); @@ -557,18 +544,19 @@ int U_derivative::MakeDTau(const double tau, // first order is more stable double uCurr = arenaFieldsCurr.u_[m][fieldIdx]; double uPrev = arenaFieldsPrev.u_[m][fieldIdx]; - double f = (uCurr - uPrev)/DATA.delta_tau; + double f = (uCurr - uPrev) / DATA.delta_tau; dUsup[m][0] = -f; // g^{00} = -1 if (DATA.output_vorticity == 1) { if (T > T_tol && T_prev > T_tol) { - double duoverTdtau = (uCurr/T - uPrev/T_prev)/DATA.delta_tau; - dUoverTsup[m][0] = -duoverTdtau; // g^{00} = -1 + double duoverTdtau = + (uCurr / T - uPrev / T_prev) / DATA.delta_tau; + dUoverTsup[m][0] = -duoverTdtau; // g^{00} = -1 } else { dUoverTsup[m][0] = 0.; } - double duTdtau = (uCurr*T - uPrev*T_prev)/DATA.delta_tau; - dUTsup[m][0] = -duTdtau; // g^{00} = -1 + double duTdtau = (uCurr * T - uPrev * T_prev) / DATA.delta_tau; + dUTsup[m][0] = -duTdtau; // g^{00} = -1 } } @@ -580,19 +568,19 @@ int U_derivative::MakeDTau(const double tau, double f = 0.0; for (int m = 1; m < 4; m++) { /* (partial_0 u^m) u[m] */ - f += dUsup[m][0]*arenaFieldsCurr.u_[m][fieldIdx]; + f += dUsup[m][0] * arenaFieldsCurr.u_[m][fieldIdx]; } - dUsup[0][0] = f/arenaFieldsCurr.u_[0][fieldIdx]; + dUsup[0][0] = f / arenaFieldsCurr.u_[0][fieldIdx]; // Sangyong Nov 18 2014 // Here we make the time derivative of (muB/T) int m = 4; // first order is more stable backward derivative const double muB = eos.get_muB(eps, rhob); - const double tildemu = muB/T; + const double tildemu = muB / T; const double muB_prev = eos.get_muB(eps_prev, rhob_prev); - const double tildemu_prev = muB_prev/T_prev; - f = (tildemu - tildemu_prev)/(DATA.delta_tau); - dUsup[m][0] = -f; // g^{00} = -1 + const double tildemu_prev = muB_prev / T_prev; + f = (tildemu - tildemu_prev) / (DATA.delta_tau); + dUsup[m][0] = -f; // g^{00} = -1 return 1; } diff --git a/src/u_derivative.h b/src/u_derivative.h index c0d97127..7111d939 100644 --- a/src/u_derivative.h +++ b/src/u_derivative.h @@ -1,38 +1,41 @@ #ifndef SRC_U_DERIVATIVE_H_ #define SRC_U_DERIVATIVE_H_ -#include "util.h" -#include "data.h" +#include + +#include + #include "cell.h" +#include "data.h" +#include "data_struct.h" +#include "eos.h" #include "fields.h" #include "minmod.h" -#include "data_struct.h" -#include -#include +#include "util.h" class U_derivative { - private: - const InitData &DATA; - const EOS &eos; - const double T_tol = 1e-5; - Minmod minmod; - dUsupMat dUsup; - Mat4x4 dUoverTsup; - Mat4x4 dUTsup; - - public: + private: + const InitData &DATA; + const EOS &eos; + const double T_tol = 1e-5; + Minmod minmod; + dUsupMat dUsup; + Mat4x4 dUoverTsup; + Mat4x4 dUTsup; + + public: U_derivative(const InitData &DATA_in, const EOS &eosIn); - void MakedU(const double tau, - Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, - const int fieldIdx, const int ix, const int iy, const int ieta); + void MakedU( + const double tau, Fields &arenaFieldsPrev, Fields &arenaFieldsCurr, + const int fieldIdx, const int ix, const int iy, const int ieta); //! this function returns the expansion rate on the grid - double calculate_expansion_rate(const double tau, Fields &arena, - const int fieldIdx); + double calculate_expansion_rate( + const double tau, Fields &arena, const int fieldIdx); //! this function returns Du^\mu - void calculate_Du_supmu(const double tau, Fields &arena, - const int fieldIdx, DumuVec &a); + void calculate_Du_supmu( + const double tau, Fields &arena, const int fieldIdx, DumuVec &a); //! this function returns the vector D^\mu(\mu_B/T) void get_DmuMuBoverTVec(DmuMuBoverTVec &vec); @@ -48,47 +51,50 @@ class U_derivative { VorticityVec &omega); //! this function computes the thermal vorticity - void calculate_thermal_vorticity(const double tau, Fields &arena, - const int fieldIdx, VorticityVec &omega); + void calculate_thermal_vorticity( + const double tau, Fields &arena, const int fieldIdx, + VorticityVec &omega); //! this function computes the T-vorticity - void calculate_T_vorticity(const double tau, Fields &arena, - const int fieldIdx, VorticityVec &omega); + void calculate_T_vorticity( + const double tau, Fields &arena, const int fieldIdx, + VorticityVec &omega); //! This funciton returns the velocity shear tensor sigma^\mu\nu void calculate_velocity_shear_tensor( const double tau, Fields &arena, const int fieldIdx, - const double theta_u_local, - const DumuVec &a_local, VelocityShearVec &sigma); + const double theta_u_local, const DumuVec &a_local, + VelocityShearVec &sigma); - int MakeDSpatial(const double tau, Fields &arena, const int fieldIdx, - const int ix, const int iy, const int ieta); + int MakeDSpatial( + const double tau, Fields &arena, const int fieldIdx, const int ix, + const int iy, const int ieta); - int MakeDTau(const double tau, - const Fields &arenaFieldsPrev, - const Fields &arenaFieldsCurr, const int fieldIdx); + int MakeDTau( + const double tau, const Fields &arenaFieldsPrev, + const Fields &arenaFieldsCurr, const int fieldIdx); //! this function computes the thermal shear tensor void calculate_thermal_shear_tensor( - const double tau, Fields &arena, const int fieldIdx, - VelocityShearVec &sigma_th); + const double tau, Fields &arena, const int fieldIdx, + VelocityShearVec &sigma_th); //! This is a shell function to compute all 4 kinds of vorticity tensors void compute_vorticity_shell( const double tau, Fields &arena_prev, Fields &arena_curr, - const int ieta, const int ix, const int iy, - const int fieldIdx, const double eta, - VorticityVec &omega_local_k, VorticityVec &omega_local_knoSP, - VorticityVec &omega_local_th, VorticityVec &omega_local_T, - VelocityShearVec &sigma_local, DmuMuBoverTVec &DbetaMu); + const int ieta, const int ix, const int iy, const int fieldIdx, + const double eta, VorticityVec &omega_local_k, + VorticityVec &omega_local_knoSP, VorticityVec &omega_local_th, + VorticityVec &omega_local_T, VelocityShearVec &sigma_local, + DmuMuBoverTVec &DbetaMu); //! This function transforms the vorticity tensor from tau-eta to tz - VorticityVec transform_vorticity_to_tz(const VorticityVec omega_Mline, - const double eta); + VorticityVec transform_vorticity_to_tz( + const VorticityVec omega_Mline, const double eta); DmuMuBoverTVec transform_vector_to_tz( - const DmuMuBoverTVec vec_Mline, const double eta); + const DmuMuBoverTVec vec_Mline, const double eta); VelocityShearVec transform_SigmaMuNu_to_tz( - const VelocityShearVec sigma_Mline, const double eta); + const VelocityShearVec sigma_Mline, const double eta); }; #endif diff --git a/src/util.cpp b/src/util.cpp index 25bbb5d7..45d8cce3 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,91 +1,78 @@ -// MUSIC - a 3+1D viscous relativistic hydrodynamic code for heavy ion collisions -// Copyright (C) 2017 Gabriel Denicol, Charles Gale, Sangyong Jeon, Matthew Luzum, Jean-François Paquet, Björn Schenke, Chun Shen +// MUSIC - a 3+1D viscous relativistic hydrodynamic code for heavy ion +// collisions Copyright (C) 2017 Gabriel Denicol, Charles Gale, Sangyong Jeon, +// Matthew Luzum, Jean-François Paquet, Björn Schenke, Chun Shen #include "util.h" -#include -#include + #include + #include +#include +#include using std::string; namespace Util { - double theta(const double x) { if (x < 0.) { - return(0.0); + return (0.0); } else { - return(1.0); + return (1.0); } } - double gmn(const int a) { if (a == 0) { - return(-1.0); + return (-1.0); } else { - return(1.0); + return (1.0); } } - double **mtx_malloc(const int n1, const int n2) { - double **d1_ptr; + double **d1_ptr; d1_ptr = new double *[n1]; - for(int i=0; i> paramVal; - return(paramVal); + if (tempinput != "empty") std::istringstream(tempinput) >> paramVal; + return (paramVal); } - -double getParameter(string paramFileName, string paramName, - double defaultValue) { +double getParameter( + string paramFileName, string paramName, double defaultValue) { double paramVal = defaultValue; string tempinput = Util::StringFind4(paramFileName, paramName); - if (tempinput != "empty") - std::istringstream ( tempinput ) >> paramVal; - return(paramVal); + if (tempinput != "empty") std::istringstream(tempinput) >> paramVal; + return (paramVal); } - // support comments in the parameters file // comments need to start with # // case-insensitive @@ -111,7 +98,7 @@ string StringFind4(string file_name, string str_in) { tmp_file << "EndOfData" << std::endl; tmp_file.close(); exit(1); - }/* if isfile */ + } /* if isfile */ // pass checking, now read in the parameter file string temp_string; @@ -127,7 +114,7 @@ string StringFind4(string file_name, string str_in) { std::stringstream temp_ss(temp_string); getline(temp_ss, para_string, '#'); // remove the comments if (para_string.compare("") != 0 - && para_string.find_first_not_of(' ') != std::string::npos) { + && para_string.find_first_not_of(' ') != std::string::npos) { // check the read in string is not empty std::stringstream para_stream(para_string); para_stream >> para_name >> para_val; @@ -135,45 +122,43 @@ string StringFind4(string file_name, string str_in) { // find the desired parameter ind++; input.close(); - return(para_val); - } /* if right, return */ + return (para_val); + } /* if right, return */ } getline(input, temp_string); // read in the next entry } - input.close(); // finish read in and close the file + input.close(); // finish read in and close the file // the desired parameter is not in the parameter file, then return "empty" if (ind == 0) { - return("empty"); + return ("empty"); } // should not cross here !!! std::cout << "Error in StringFind4 !!!\n"; - return("empty"); + return ("empty"); } - // this function convert string to lower case string convert_to_lowercase(string str_in) { std::transform(str_in.begin(), str_in.end(), str_in.begin(), ::tolower); - return(str_in); + return (str_in); } - -double lin_int(double x1,double x2,double f1,double f2,double x) { +double lin_int(double x1, double x2, double f1, double f2, double x) { double aa, bb; if (x2 == x1) { aa = 0.0; } else { - aa =(f2-f1)/(x2-x1); + aa = (f2 - f1) / (x2 - x1); } bb = f1 - aa * x1; - return aa*x + bb; + return aa * x + bb; } double four_dimension_linear_interpolation( - double* lattice_spacing, double fraction[2][4], double**** cube) { + double *lattice_spacing, double fraction[2][4], double ****cube) { double denorm = 1.0; double results = 0.0; for (int i = 0; i < 4; i++) { @@ -183,19 +168,19 @@ double four_dimension_linear_interpolation( for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { for (int l = 0; l < 2; l++) { - results += (cube[i][j][k][l]*fraction[i][0]*fraction[j][1] - *fraction[k][2]*fraction[l][3]); + results += + (cube[i][j][k][l] * fraction[i][0] * fraction[j][1] + * fraction[k][2] * fraction[l][3]); } } } } - results = results/denorm; + results = results / denorm; return (results); } - double three_dimension_linear_interpolation( - double* lattice_spacing, double fraction[2][3], double*** cube) { + double *lattice_spacing, double fraction[2][3], double ***cube) { double denorm = 1.0; double results = 0.0; for (int i = 0; i < 3; i++) { @@ -204,47 +189,47 @@ double three_dimension_linear_interpolation( for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { - results += (cube[i][j][k]*fraction[i][0] - *fraction[j][1]*fraction[k][2]); + results += + (cube[i][j][k] * fraction[i][0] * fraction[j][1] + * fraction[k][2]); } } } - results = results/denorm; - return(results); + results = results / denorm; + return (results); } - -//! this function return the left index of the array where x sits in +//! this function return the left index of the array where x sits in //! between array[idx] and array[idx+1] -//! this function assumes that the input array is monotonic -int binary_search(double* array, int length, double x) { +//! this function assumes that the input array is monotonic +int binary_search(double *array, int length, double x) { if (length < 3) // array is too short - return(0); + return (0); int low_idx, mid_idx, high_idx; low_idx = 0; high_idx = length - 1; // first check the boundaries - if ((array[low_idx] - x)*(array[high_idx] - x) > 0.) { + if ((array[low_idx] - x) * (array[high_idx] - x) > 0.) { fprintf(stderr, "Util::binary_search: can not find idx!\n"); - fprintf(stderr, "a[0] = %e, a[end] = %e, a = %e \n", - array[low_idx], array[high_idx], x); + fprintf( + stderr, "a[0] = %e, a[end] = %e, a = %e \n", array[low_idx], + array[high_idx], x); exit(-1); } // find the index while (high_idx - low_idx > 1) { - mid_idx = (int)((high_idx + low_idx)/2.); - if ((array[low_idx] - x)*(array[mid_idx] - x) > 0.) { + mid_idx = (int)((high_idx + low_idx) / 2.); + if ((array[low_idx] - x) * (array[mid_idx] - x) > 0.) { low_idx = mid_idx; } else { high_idx = mid_idx; } } - return(low_idx); + return (low_idx); } - void print_backtrace_errors() { int nptrs; void *buffer[BT_BUF_SIZE]; @@ -264,17 +249,16 @@ void print_backtrace_errors() { exit(1); } - int map_2d_idx_to_1d(int a, int b) { - static const int index_map[5][4] = {{ 0, 1, 2, 3}, - { 1, 4, 5, 6}, - { 2, 5, 7, 8}, - { 3, 6, 8, 9}, - {10, 11, 12, 13}}; + static const int index_map[5][4] = { + {0, 1, 2, 3}, + {1, 4, 5, 6}, + {2, 5, 7, 8}, + {3, 6, 8, 9}, + {10, 11, 12, 13}}; return index_map[a][b]; } - void map_1d_idx_to_2d(int idx_1d, int &a, int &b) { static const int index_1d_a[5] = {1, 1, 1, 2, 2}; static const int index_1d_b[5] = {1, 2, 3, 2, 3}; @@ -282,7 +266,6 @@ void map_1d_idx_to_2d(int idx_1d, int &a, int &b) { b = index_1d_b[idx_1d - 4]; } - Mat4x4 UnpackVecToMatrix(const Arr10 &in_vector) { Mat4x4 out_matrix; out_matrix[0][0] = in_vector[0]; @@ -304,7 +287,6 @@ Mat4x4 UnpackVecToMatrix(const Arr10 &in_vector) { return out_matrix; } - Mat4x4 UnpackVecToMatrix(const ViscousVec &in_vector) { Mat4x4 out_matrix; out_matrix[0][0] = in_vector[0]; @@ -326,7 +308,6 @@ Mat4x4 UnpackVecToMatrix(const ViscousVec &in_vector) { return out_matrix; } - Mat4x4 UnpackVecToMatrix(const VorticityVec &in_vector) { Mat4x4 out_matrix; out_matrix[0][0] = 0.0; @@ -348,4 +329,4 @@ Mat4x4 UnpackVecToMatrix(const VorticityVec &in_vector) { return out_matrix; } -} +} // namespace Util diff --git a/src/util.h b/src/util.h index cfc5a2dc..5fe1b19b 100644 --- a/src/util.h +++ b/src/util.h @@ -1,69 +1,72 @@ -// MUSIC - a 3+1D viscous relativistic hydrodynamic code for heavy ion collisions -// Copyright (C) 2017 Gabriel Denicol, Charles Gale, Sangyong Jeon, Matthew Luzum, Jean-François Paquet, Björn Schenke, Chun Shen +// MUSIC - a 3+1D viscous relativistic hydrodynamic code for heavy ion +// collisions Copyright (C) 2017 Gabriel Denicol, Charles Gale, Sangyong Jeon, +// Matthew Luzum, Jean-François Paquet, Björn Schenke, Chun Shen #ifndef UTIL_H #define UTIL_H +#include #include #include -#include -#include +#include + #include -#include #include -#include +#include +#include + #include "data_struct.h" //! This is a utility class which contains a collection of helper functions. namespace Util { - const double hbarc = 0.19733; - const double default_tol = 1.0e-8; - const double small_eps = 1e-16; - - //the mass of a nucleon (averaged over proton and neutron) - const double m_N = 0.939; // [GeV] +const double hbarc = 0.19733; +const double default_tol = 1.0e-8; +const double small_eps = 1e-16; - const int BT_BUF_SIZE = 500; +// the mass of a nucleon (averaged over proton and neutron) +const double m_N = 0.939; // [GeV] - double theta(const double x); - double gmn(const int a); +const int BT_BUF_SIZE = 500; - double **mtx_malloc(const int n1, const int n2); +double theta(const double x); +double gmn(const int a); - void mtx_free(double **m, const int n1, const int n2); +double **mtx_malloc(const int n1, const int n2); - int IsFile(std::string); +void mtx_free(double **m, const int n1, const int n2); - int getParameter(std::string paramFileName, std::string paramName, - int defaultValue); - double getParameter(std::string paramFileName, std::string paramName, - double defaultValue); - std::string StringFind4(std::string file_name, std::string str_in); - std::string convert_to_lowercase(std::string str_in); +int IsFile(std::string); - double lin_int(double x1,double x2,double f1,double f2,double x); +int getParameter( + std::string paramFileName, std::string paramName, int defaultValue); +double getParameter( + std::string paramFileName, std::string paramName, double defaultValue); +std::string StringFind4(std::string file_name, std::string str_in); +std::string convert_to_lowercase(std::string str_in); - double four_dimension_linear_interpolation( - double* lattice_spacing, double fraction[2][4], double**** cube); - double three_dimension_linear_interpolation( - double* lattice_spacing, double fraction[2][3], double*** cube); - int binary_search(double* array, int length, double x); - void print_backtrace_errors(); +double lin_int(double x1, double x2, double f1, double f2, double x); - int map_2d_idx_to_1d(int a, int b); - void map_1d_idx_to_2d(int idx_1d, int &a, int &b); +double four_dimension_linear_interpolation( + double *lattice_spacing, double fraction[2][4], double ****cube); +double three_dimension_linear_interpolation( + double *lattice_spacing, double fraction[2][3], double ***cube); +int binary_search(double *array, int length, double x); +void print_backtrace_errors(); - Mat4x4 UnpackVecToMatrix(const Arr10 &in_vector); - Mat4x4 UnpackVecToMatrix(const ViscousVec &in_vector); - Mat4x4 UnpackVecToMatrix(const VorticityVec &in_vector); +int map_2d_idx_to_1d(int a, int b); +void map_1d_idx_to_2d(int idx_1d, int &a, int &b); - // check whether a weak pointer is initialized or not - template - bool weak_ptr_is_uninitialized(std::weak_ptr const& weak) { - using wt = std::weak_ptr; - return !weak.owner_before(wt{}) && !wt{}.owner_before(weak); - } +Mat4x4 UnpackVecToMatrix(const Arr10 &in_vector); +Mat4x4 UnpackVecToMatrix(const ViscousVec &in_vector); +Mat4x4 UnpackVecToMatrix(const VorticityVec &in_vector); +// check whether a weak pointer is initialized or not +template +bool weak_ptr_is_uninitialized(std::weak_ptr const &weak) { + using wt = std::weak_ptr; + return !weak.owner_before(wt {}) && !wt {}.owner_before(weak); } +} // namespace Util + #endif