Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ctrl.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ctrl.cpp
1 #include "ctrl.h"
2 
3 #include "inc.h"
4 #include <ctime>
5 #include <cmath>
6 #include <iomanip>
7 //#include <TMath.h>
8 #include "hdo.h"
9 #include "ickw.h"
10 #include "conv.h"
11 #include "eo3.h"
12 #include "eo1.h"
13 #include "trancoeff.h"
14 #include <unistd.h>
15 
16 #include <execinfo.h>
17 #include <signal.h>
18 
19 ofstream ofile ; // cout + cerr output
20 
21 EoS *eos ;
23 Fluid *f ;
24 IC_KW *ic_kw ;
25 Hydro* h ;
26 time_t start, end ;
27 
28 double tau0, tau_max, dtau ;
29 int maxstep ;
30 //string directory, outkw ;
31 
32 void handler(int sig) {
33  void *array[10];
34  size_t size;
35 
36  // get void*'s for all entries on the stack
37  size = backtrace(array, 10);
38 
39  // print out all the frames to stderr
40  cout<<"Error: signal "<<sig<<endl ;
41  backtrace_symbols_fd(array, size, 2);
42  exit(1);
43 }
44 
46 {
47  signal(SIGSEGV, handler); // handler for segfault
48  ofile.open(filename) ;
49  cout.rdbuf(ofile.rdbuf()) ;
50  cerr.rdbuf(ofile.rdbuf()) ;
51 }
52 
53 void initeoshlle_(char *filename, int* ncols)
54 {
55  eos = new EoSs(filename,*ncols) ; // << CE ; set BAG_ASYMPT !!
56 }
57 
58 
59 void initeoshlle3f_(char *filename, double *B, double *volex0, double *delta0, double *aaa, double *bbb)
60 {
61  eos = new EoS3f(filename, *B, *volex0, *delta0, *aaa, *bbb) ;
62 }
63 
65 {
66  eos = new EoS1f(filename) ;
67 }
68 
69 
70 void inittrcoeff_(double *etaS, double *zetaS)
71 {
72  trcoeff = new TransportCoeff(*etaS, *zetaS, eos) ;
73 }
74 
75 void eoshlle_(double *e, double *nb, double *nq, double *ns, double *T, double *mub, double *muq, double *mus, double *p)
76 {
77  eos->eos(*e, *nb, *nq, *ns, *T, *mub, *muq, *mus, *p) ;
78 }
79 
80 
81 void eosrangeshlle_(double *emax, double *e0, double *nmax, double *n0, int *ne, int *nn)
82 {
83  eos->eosranges(*emax, *e0, *nmax, *n0, *ne, *nn) ;
84 }
85 
86 
87 void initfluidhlle_(int* nx, int* ny, int* nz, double* minx, double* maxx, double* miny, double* maxy, double* minz, double* maxz)
88 {
89  f = new Fluid(eos, trcoeff, *nx, *ny, *nz, *minx, *maxx, *miny, *maxy, *minz, *maxz) ;
90 }
91 
92 
93 
94 void initichlle_(char *filename, double *tau0)
95 {
96  ic_kw = new IC_KW(filename) ; //---------for Klaus
97 // ic_kw->setIC(f, eos, *tau0) ; //!!! z-symmetry is included in ic_kw.cpp
98 }
99 
100 
101 void icgethlle3f_(double* x, double* y, double* eta, double* e, double* nB, double* nQ, double* nS, double* vx, double* vy, double* vz)
102 {
103  double nu, nd, ns ;
104  ic_kw->getICs(*x, *y, *eta, *e, *vx, *vy, *vz, nu, nd, ns) ;
105 // if(*e<1.) *e = 0. ;
106  *nB = 1./3.*(nu + nd + ns) ;
107  *nQ = 1./3.*(2.*nu - nd - ns) ;
108  *nS = - ns ;
109 }
110 
111 
112 void icgethlle_(double* x, double* y, double* eta, double* e, double* nB, double* nQ, double* nS, double* vx, double* vy, double* vz)
113 {
114  double nu, nd, ns ;
115  ic_kw->getICs(*x, *y, *eta, *e, *vx, *vy, *vz, nu, nd, ns) ;
116  *nB = *nQ = *nS = 0. ;
117 }
118 
119 
120 void icsethlle_(int* ix, int* iy, int* iz, double* tau0, double* e, double* nb, double* nq, double* ns, double* vx, double* vy, double* vz)
121 {
122 Cell *c = f->getCell(*ix-1,*iy-1,*iz-1) ;
123 if((*vx)*(*vx)+(*vy)*(*vy)+(*vz)*(*vz)>1.){
124 // cerr << "setIC : " << ix << " " << iy << " " << iz << " e = " << e << " v^2 = " << (*vx)*(*vx)+(*vy)*(*vy)+vz*vz << endl ;
125  double factor = sqrt((*vx)*(*vx)+(*vy)*(*vy)+(*vz)*(*vz)) ;
126  (*vx) = (*vx)*0.99/factor ;
127  (*vy) = (*vy)*0.99/factor ;
128  (*vz) = (*vz)*0.99/factor ;
129  }
130  if(isinf(*e) || isnan(*e) || isinf(*nb) || isnan(*nb) || isinf(*nq) || isnan(*nq) || isinf(*ns) || isnan(*ns) ||
131  isinf(*vx) || isnan(*vx) || isinf(*vy) || isnan(*vy) || isinf(*vz) || isnan(*vz))
132  {cout<<"fluid: bad init,"<<setw(14)<<"e"<<setw(14)<<"nb"<<setw(14)<<"nq"<<setw(14)<<"ns"<<setw(14)<<"vx"<<setw(14)<<"vy"<<setw(14)<<"vz"<<endl ;
133  cout<<"----------------"<<setw(14)<<e<<setw(14)<<nb<<setw(14)<<nq<<setw(14)<<ns<<setw(14)<<vx<<setw(14)<<vy<<setw(14)<<vz<<endl ;
134  cout<<"cell "<<ix<<" "<<iy<<" "<<iz<<endl ;
135  exit(1) ; }
136  c->setPrimVar(eos, *tau0, *e, *nb, *nq, *ns, (*vx), (*vy), (*vz)) ;
137  c->saveQprev() ;
138  if(*e>0.) c->setAllM(1.) ;
139 }
140 
141 
142 void inithydrohlle_(double* _tau0, double* _tau_max, double* _dtau)
143 {
144  tau0 = *_tau0 ;
145  tau_max = *_tau_max ;
146  dtau = *_dtau ;
147  h = new Hydro(f, eos, trcoeff, tau0, dtau) ;
148  maxstep = ceil((tau_max-tau0)/dtau) ;
149 
150  start = 0;
151  time(&start);
152  h->setNSvalues() ; // initialize viscous terms
153 }
154 
155 
156 void dtauhlle_(double* dtau)
157 {
158  h->setDtau(*dtau) ;
159 }
160 
161 
162 void initoutputhlle_(char* dir)
163 {
164  f->initOutput(dir, maxstep, tau0, 2) ;
165  f->outputPDirections(h->getTau());
166  f->outputTransverseAverages(h->getTau()) ;
167 }
168 
169 
171 {
172  return maxstep ;
173 }
174 
175 
176 void makestephlle_(int *i)
177 {
178  h->performStep() ;
179  f->outputPDirections(h->getTau());
180  f->outputTransverseAverages(h->getTau()) ;
181 }
182 
183 
184 void getvalueshlle_(int* ix, int* iy, int* iz, double* e, double *p, double *nb, double *nq, double *ns, double* vx, double* vy, double* vz, double* viscCorrCutFlag)
185 {
186  Cell *c = f->getCell(*ix-1, *iy-1, *iz-1) ;
187  c->getPrimVar(eos, h->getTau(), *e, *p, *nb, *nq, *ns, *vx, *vy, *vz) ;
188  *viscCorrCutFlag = c->getViscCorrCutFlag() ;
189 }
190 
191 
192 void getvflaghlle_(int* ix, int* iy, int* iz, double* viscCorrCutFlag)
193 {
194  *viscCorrCutFlag = f->getCell(*ix-1, *iy-1, *iz-1)->getViscCorrCutFlag() ;
195 }
196 
197 
198 void getvischlle_(int* ix, int* iy, int* iz, double *pi, double *Pi)
199 {
200  Cell* c=f->getCell(*ix-1, *iy-1, *iz-1) ;
201  // fortran and C have reverse array alignment, (a,b) --> [b,a]
202  // but since pi[mu][nu] is symmetric, this is not important
203  for(int i=0; i<4; i++)
204  for(int j=0; j<4; j++){
205  *(pi+4*i+j) = c->getpi(i,j) ;
206  }
207  *Pi=c->getPi();
208  //if(c->Pi!=0.0) cout <<"nonzero Pi: " << c->Pi << endl ;
209 }
210 
211 
212 double getxhlle_(int *ix)
213 {
214  return f->getX(*ix-1) ;
215 }
216 
217 
218 double getyhlle_(int *iy)
219 {
220  return f->getY(*iy-1) ;
221 }
222 
223 
224 double getzhlle_(int *iz)
225 {
226  return f->getZ(*iz-1) ;
227 }
228 
229 
230 void destroyhlle_(void)
231 {
232 // delete ic ; // do we need IC instance?
233  delete f ;
234  delete h ;
235  end=0 ;
236  time(&end); float diff = difftime(end, start);
237 // cout<<"Execution time = "<<diff<< " [sec]" << endl;
238  ofile.close() ; // close output and error file
239 }
240 
241 
242 void destroyeoshlle_(void)
243 {
244  delete eos ;
245 }
246 
247 
248 double gettimehlle_(void)
249 {
250  end=0 ;
251  time(&end); float diff = difftime(end, start);
252  return diff ;
253 }
254 
255 double getenergyhlle_(void)
256 {
257  double ene = 0., e, p, nb, nq, ns, vx, vy, vz, _vx, _vy, _vz ;
258  double tau = h->getTau() ;
259  for(int ix=0; ix<f->getNX(); ix++)
260  for(int iy=0; iy<f->getNY(); iy++)
261  for(int iz=0; iz<f->getNZ(); iz++){
262  f->getCell(ix, iy, iz)->getPrimVar(eos, tau, e, p, nb, nq, ns, _vx, _vy, _vz) ;
263  double eta = f->getZ(iz) ;
264  vx = _vx/(cosh(eta) + _vz*sinh(eta)) ;
265  vy = _vy/(cosh(eta) + _vz*sinh(eta)) ;
266  vz = (_vz*cosh(eta)+sinh(eta))/(cosh(eta) + _vz*sinh(eta)) ;
267  ene += (e+p)/(1.-vx*vx-vy*vy-vz*vz) - p ;
268  }
269  return e ;
270 }