Skip to content

Commit

Permalink
format the code base using clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
chunshen1987 committed Sep 23, 2024
1 parent f1e1e97 commit fd7e812
Show file tree
Hide file tree
Showing 84 changed files with 13,845 additions and 13,498 deletions.
5 changes: 5 additions & 0 deletions compile.sh
Original file line number Diff line number Diff line change
@@ -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 *
Expand Down
9 changes: 7 additions & 2 deletions formatCode.sh
Original file line number Diff line number Diff line change
@@ -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
214 changes: 111 additions & 103 deletions src/HydroinfoMUSIC.cpp
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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.;
Expand All @@ -42,31 +41,34 @@ void HydroinfoMUSIC::getHydroValues(
eta = z;
}

int ieta = static_cast<int>((hydro_eta_max + eta)/hydroDeta + 0.0001);
int ieta = static_cast<int>((hydro_eta_max + eta) / hydroDeta + 0.0001);
if (boost_invariant) {
ieta = 0;
}

const int itau = static_cast<int>((tau - hydroTau0)/hydroDtau + 0.0001);
const int ix = static_cast<int>((hydroXmax + x)/hydroDx + 0.0001);
const int iy = static_cast<int>((hydroYmax + y)/hydroDy + 0.0001);
const int itau = static_cast<int>((tau - hydroTau0) / hydroDtau + 0.0001);
const int ix = static_cast<int>((hydroXmax + x) / hydroDx + 0.0001);
const int iy = static_cast<int>((hydroYmax + y) / hydroDy + 0.0001);

double xfrac = (x - (static_cast<double>(ix)*hydroDx - hydroXmax))/hydroDx;
double yfrac = (y - (static_cast<double>(iy)*hydroDy - hydroYmax))/hydroDy;
double etafrac = (eta/hydroDeta - static_cast<double>(ieta)
+ 0.5*static_cast<double>(ietamax));
double taufrac = (tau - hydroTau0)/hydroDtau - static_cast<double>(itau);
double xfrac =
(x - (static_cast<double>(ix) * hydroDx - hydroXmax)) / hydroDx;
double yfrac =
(y - (static_cast<double>(iy) * hydroDy - hydroYmax)) / hydroDy;
double etafrac =
(eta / hydroDeta - static_cast<double>(ieta)
+ 0.5 * static_cast<double>(ietamax));
double taufrac = (tau - hydroTau0) / hydroDtau - static_cast<double>(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");

Expand All @@ -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");

Expand Down Expand Up @@ -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)));
}
}
}
Expand Down Expand Up @@ -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<float>(T);
info->vx = static_cast<float>(vx);
Expand Down Expand Up @@ -287,22 +296,21 @@ void HydroinfoMUSIC::getHydroValues(
info->bulkPi = static_cast<float>(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<float>(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<float>(ux/ut);
info->vy = static_cast<float>(uy/ut);
info->vz = static_cast<float>(uz/ut);
double uz = utau * sinh_eta + ueta * cosh_eta;
double ut = utau * cosh_eta + ueta * sinh_eta;
info->vx = static_cast<float>(ux / ut);
info->vy = static_cast<float>(uy / ut);
info->vz = static_cast<float>(uz / ut);

info->ed = static_cast<float>(lattice_ideal[idx].ed);
info->sd = static_cast<float>(lattice_ideal[idx].sd);
Expand All @@ -328,32 +336,32 @@ void HydroinfoMUSIC::get_fluid_cell_with_index(const int idx,
info->bulkPi = static_cast<float>(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<int>((DATA.nx + 1)
/DATA.output_evolution_every_N_x) + 1);
iymax = (static_cast<int>((DATA.ny + 1)
/DATA.output_evolution_every_N_y) + 1);
hydro_eta_max = DATA.eta_size/2.;
ietamax = static_cast<int>(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<int>((DATA.nx - 1)
/DATA.output_evolution_every_N_x) + 1);
ietamax = (static_cast<int>((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<int>((DATA.nx + 1) / DATA.output_evolution_every_N_x) + 1);
iymax =
(static_cast<int>((DATA.ny + 1) / DATA.output_evolution_every_N_y) + 1);
hydro_eta_max = DATA.eta_size / 2.;
ietamax = static_cast<int>(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<int>((DATA.nx - 1) / DATA.output_evolution_every_N_x) + 1);
ietamax =
(static_cast<int>((DATA.neta - 1) / DATA.output_evolution_every_N_eta)
+ 1);
}

void HydroinfoMUSIC::print_grid_information() {
Expand All @@ -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;
Expand Down
Loading

0 comments on commit fd7e812

Please sign in to comment.