-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenergy.c
More file actions
739 lines (529 loc) · 16.7 KB
/
Copy pathenergy.c
File metadata and controls
739 lines (529 loc) · 16.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
/** @file energy.c
*
* Calculation of total energy and related quantities.
*/
#include "hydro.h"
/** Calculates sum of various components of the total energy, split into
* symmetric and broken phase. Returns as an array of floats.
*
* Sets energies array to be as follows in order:
* rest energy, fluid kinetic energy, kinetic energy scalar, gradient energy scalar, potential
* energy scalar.
* Each energy component is a pair of floats, split into total in symmetric and
* broken phase, in that order.
* Note that this function does not sum over all sites.
*/
void calculate_energies(hydro_fields f, hydro_params p, float *energies) {
float rest_E_symm = 0;
float rest_E_broken = 0;
float kin_fluid_symm = 0;
float kin_fluid_broken = 0;
float kin_phi_symm = 0;
float kin_phi_broken = 0;
float grad_phi_symm = 0;
float grad_phi_broken = 0;
float pot_phi_symm = 0;
float pot_phi_broken = 0;
float vol = p.dx*p.dx*p.dx;
int x, y, z;
float phi_broken;
#ifdef BAG
phi_broken = p.phi_0/2.;
#else
#ifdef SCALAR
phi_broken = (p.alpha*p.Tconst
+ sqrt((p.alpha*p.Tconst)*(p.alpha*p.Tconst)
- 4.0*p.lambda*p.gamma
*(p.Tconst*p.Tconst - p.T0*p.T0))
)/(2.0*p.lambda);
#endif // SCALAR
#endif // BAG
for(x = 1; x <= p.slicex; x++) {
for(y = 1; y <= p.slicey; y++) {
for(z = 0; z < p.Lz; z++) {
#if !defined(SCALAR) && !defined(BAG)
phi_broken = (p.alpha*f.T[x][y][z]
+ sqrt((p.alpha*p.Tconst)*(p.alpha*f.T[x][y][z])
- 4.0*p.lambda*p.gamma
*(f.T[x][y][z]*f.T[x][y][z] - p.T0*p.T0))
)/(2.0*p.lambda);
#endif // !SCALAR && !BAG
if (f.phi[x][y][z] < phi_broken/2){
#ifndef SCALAR
rest_E_symm += (f.E[x][y][z]/f.W[x][y][z])*vol;
kin_fluid_symm += f.kappa[x][y][z]*(f.E[x][y][z]/f.W[x][y][z])
*(f.W[x][y][z]*f.W[x][y][z]-1.0)*vol;
pot_phi_symm += Vf(p, f.T[x][y][z], f.phi[x][y][z])*vol;
#else
pot_phi_symm += Vf(p, p.Tconst, f.phi[x][y][z])*vol;
#endif
grad_phi_symm += 0.5*((f.phi[x+1][y][z] - f.phi[x][y][z])/p.dx)
*((f.phi[x+1][y][z] - f.phi[x][y][z])/p.dx)*vol;
grad_phi_symm += 0.5*((f.phi[x][y+1][z] - f.phi[x][y][z])/p.dx)
*((f.phi[x][y+1][z] - f.phi[x][y][z])/p.dx)*vol;
grad_phi_symm += 0.5*((f.phi[x][y][(z+1)%p.Lz]
- f.phi[x][y][z])/p.dx)
*((f.phi[x][y][(z+1)%p.Lz]
- f.phi[x][y][z])/p.dx)*vol;
kin_phi_symm += 0.5*f.pi_future[x][y][z]*f.pi_future[x][y][z]*vol;
}
else {
#ifndef SCALAR
rest_E_broken += (f.E[x][y][z]/f.W[x][y][z])*vol;
kin_fluid_broken += f.kappa[x][y][z]*(f.E[x][y][z]/f.W[x][y][z])
*(f.W[x][y][z]*f.W[x][y][z]-1.0)*vol;
pot_phi_broken += Vf(p, f.T[x][y][z], f.phi[x][y][z])*vol;
#else
pot_phi_broken += Vf(p, p.Tconst, f.phi[x][y][z])*vol;
#endif
grad_phi_broken += 0.5*((f.phi[x+1][y][z] - f.phi[x][y][z])/p.dx)
*((f.phi[x+1][y][z] - f.phi[x][y][z])/p.dx)*vol;
grad_phi_broken += 0.5*((f.phi[x][y+1][z] - f.phi[x][y][z])/p.dx)
*((f.phi[x][y+1][z] - f.phi[x][y][z])/p.dx)*vol;
grad_phi_broken += 0.5*((f.phi[x][y][(z+1)%p.Lz]
- f.phi[x][y][z])/p.dx)
*((f.phi[x][y][(z+1)%p.Lz]
- f.phi[x][y][z])/p.dx)*vol;
kin_phi_broken += 0.5*f.pi_future[x][y][z]*f.pi_future[x][y][z]*vol;
}
}
}
}
energies[0] = rest_E_symm;
energies[1] = rest_E_broken;
energies[2] = kin_fluid_symm;
energies[3] = kin_fluid_broken;
energies[4] = kin_phi_symm;
energies[5] = kin_phi_broken;
energies[6] = grad_phi_symm;
energies[7] = grad_phi_broken;
energies[8] = pot_phi_symm;
energies[9] = pot_phi_broken;
}
/** Calculates sum the temperature over sites on the core, split into
* symmetric and broken phase. Returns as an array of floats, with symmetric
* first and broken second.
*
* Note that this function does not sum over all sites, only the ones on the
* current core.
*/
void calculate_T_sum(hydro_fields f, hydro_params p, float *T_sum) {
float T_sum_symm = 0;
float T_sum_broken = 0;
float phi_broken;
int x, y, z;
#ifndef SCALAR
#ifdef BAG
phi_broken = p.phi_0;
#endif
for(x = 1; x <= p.slicex; x++) {
for(y = 1; y <= p.slicey; y++) {
for(z = 0; z < p.Lz; z++) {
#ifndef BAG
phi_broken = (p.alpha*f.T[x][y][z]
+ sqrt((p.alpha*p.Tconst)*(p.alpha*f.T[x][y][z])
- 4.0*p.lambda*p.gamma
*(f.T[x][y][z]*f.T[x][y][z] - p.T0*p.T0))
)/(2.0*p.lambda);
#endif
if (f.phi[x][y][z] < phi_broken/2){
T_sum_symm += f.T[x][y][z];
}
else {
T_sum_broken += f.T[x][y][z];
}
}
}
}
#endif // !SCALAR
T_sum[0] = T_sum_symm;
T_sum[1] = T_sum_broken;
}
/** Compute the total pressure. Split this into symmetric and broken phases,
* symmetric first.
*
* NB: This function does _not_ currently sum over all sites.
*/
void calculate_pressure_sum(hydro_fields f, hydro_params p, float *pressure_sum) {
int x, y, z;
float vol;
float press_symm = 0;
float press_broken = 0;
#ifndef SCALAR
vol = p.dx*p.dx*p.dx;
float phi_broken;
#ifdef BAG
phi_broken = p.phi_0/2.;
#endif // BAG
for(x = 1; x <= p.slicex; x++) {
for(y = 1; y <= p.slicey; y++) {
for(z = 0; z < p.Lz; z++) {
#ifndef BAG
phi_broken = (p.alpha*f.T[x][y][z]
+ sqrt((p.alpha*p.Tconst)*(p.alpha*f.T[x][y][z])
- 4.0*p.lambda*p.gamma
*(f.T[x][y][z]*f.T[x][y][z] - p.T0*p.T0))
)/(2.0*p.lambda);
#endif // !BAG
if (f.phi[x][y][z] < phi_broken/2){
press_symm += f.p[x][y][z]*vol;
}
else {
press_broken += f.p[x][y][z]*vol;
}
}
}
}
#endif // !SCALAR
pressure_sum[0] = press_symm;
pressure_sum[1] = press_broken;
}
/** Computes the total energy in the scalar field.
*
* Separately computes the kinetic, gradient and potential energy of
* the scalar field and returns the total, summed over all sites.
*/
float field_energy(hydro_fields f, hydro_params p) {
int x, y, z;
float vol;
float Etot = 0.0;
float a = 0.0;
float b = 0.0;
float c = 0.0;
vol = p.dx*p.dx*p.dx;
for(x = 1; x <= p.slicex; x++) {
for(y = 1; y <= p.slicey; y++) {
for(z = 0; z < p.Lz; z++) {
a += 0.5*f.pi_future[x][y][z]*f.pi_future[x][y][z]*vol;
b += 0.5*((f.phi[x+1][y][z] - f.phi[x][y][z])/p.dx)
*((f.phi[x+1][y][z] - f.phi[x][y][z])/p.dx)*vol;
b += 0.5*((f.phi[x][y+1][z] - f.phi[x][y][z])/p.dx)
*((f.phi[x][y+1][z] - f.phi[x][y][z])/p.dx)*vol;
b += 0.5*((f.phi[x][y][(z+1)%p.Lz] - f.phi[x][y][z])/p.dx)
*((f.phi[x][y][(z+1)%p.Lz] - f.phi[x][y][z])/p.dx)*vol;
#ifndef SCALAR
c += Vf(p, f.T[x][y][z], f.phi[x][y][z])*vol;
#else
c += Vf(p, p.Tconst, f.phi[x][y][z])*vol;
#endif
}
}
}
float atot = reduce_sum(a, p);
float btot = reduce_sum(b, p);
float ctot = reduce_sum(c, p);
#ifdef SCALAR
printf0(p,"Totals: momentum %g gradient %g potential %g\n", atot, btot, ctot);
#endif // SCALAR
return a + b + c;
}
/** Computes the gradient energy in the scalar field.
*
* Note that this does _not_ currently sum over all sites, only those
* on the current core.
*/
float gradient_energy_field(hydro_fields f, hydro_params p) {
int x, y, z;
float vol;
float Etot = 0.0;
vol = p.dx*p.dx*p.dx;
for(x = 1; x <= p.slicex; x++) {
for(y = 1; y <= p.slicey; y++) {
for(z = 0; z < p.Lz; z++) {
Etot += 0.5*((f.phi[x+1][y][z] - f.phi[x][y][z])/p.dx)
*((f.phi[x+1][y][z] - f.phi[x][y][z])/p.dx)*vol;
Etot += 0.5*((f.phi[x][y+1][z] - f.phi[x][y][z])/p.dx)
*((f.phi[x][y+1][z] - f.phi[x][y][z])/p.dx)*vol;
Etot += 0.5*((f.phi[x][y][(z+1)%p.Lz] - f.phi[x][y][z])/p.dx)
*((f.phi[x][y][(z+1)%p.Lz] - f.phi[x][y][z])/p.dx)*vol;
}
}
}
return Etot;
}
/** Computes the kinetic energy in the scalar field.
*
* Note that this does _not_ currently sum over all sites, only those
* on the current core.
*/
float kinetic_energy_field(hydro_fields f, hydro_params p) {
int x, y, z;
float vol;
float Etot = 0.0;
vol = p.dx*p.dx*p.dx;
for(x = 1; x <= p.slicex; x++) {
for(y = 1; y <= p.slicey; y++) {
for(z = 0; z < p.Lz; z++) {
Etot += 0.5*f.pi_future[x][y][z]*f.pi_future[x][y][z]*vol;
}
}
}
return Etot;
}
/** Compute the total internal energy of the system.
*
* Total (field+fluid) energy. Borrowed directly from the
* 1+1D spherical fortran code, which might explain the strange
* way of performing the calculation.
*
* NB: This function currently does _not_ sum over all sites, only
* those on the current core.
*/
float total_energy(hydro_fields f, hydro_params p) {
int x, y, z;
float vol;
float Etot = 0.0;
float restE = 0.0;
float kinE = 0.0;
float kinphi = 0.0;
float grdphi = 0.0;
vol = p.dx*p.dx*p.dx;
for(x = 1; x <= p.slicex; x++) {
for(y = 1; y <= p.slicey; y++) {
for(z = 0; z < p.Lz; z++) {
#ifndef SCALAR
// rest energy
restE += (f.E[x][y][z]/f.W[x][y][z])*vol;
// kinetic energy
kinE += f.kappa[x][y][z]*(f.E[x][y][z]/f.W[x][y][z])
*(f.W[x][y][z]*f.W[x][y][z]-1.0)*vol;
#endif // SCALAR
// momentum squared (scalar field kinetic energy)
kinphi += 0.5*f.pi_future[x][y][z]*f.pi_future[x][y][z]*vol;
// gradient term
grdphi += 0.5*((f.phi[x+1][y][z] - f.phi[x][y][z])/p.dx)
*((f.phi[x+1][y][z] - f.phi[x][y][z])/p.dx)*vol;
grdphi += 0.5*((f.phi[x][y+1][z] - f.phi[x][y][z])/p.dx)
*((f.phi[x][y+1][z] - f.phi[x][y][z])/p.dx)*vol;
grdphi += 0.5*((f.phi[x][y][(z+1)%p.Lz]
- f.phi[x][y][z])/p.dx)
*((f.phi[x][y][(z+1)%p.Lz]
- f.phi[x][y][z])/p.dx)*vol;
}
}
}
Etot = (restE+kinE+kinphi+grdphi);
return Etot;
}
/** Compute the total kinetic energy in the fluid.
*
* NB: This function does _not_ currently sum over all sites.
*/
float kinetic_energy_fluid(hydro_fields f, hydro_params p) {
int x, y, z;
float vol;
float kinE = 0.0;
vol = p.dx*p.dx*p.dx;
for(x = 1; x <= p.slicex; x++) {
for(y = 1; y <= p.slicey; y++) {
for(z = 0; z < p.Lz; z++) {
#ifndef SCALAR
// kinetic energy
kinE += f.kappa[x][y][z]*(f.E[x][y][z]/f.W[x][y][z])
*(f.W[x][y][z]*f.W[x][y][z]-1.0)*vol;
#endif // SCALAR
}
}
}
return kinE;
}
/** Compute the rest energy in the fluid.
*
* NB: This function does _not_ currently sum over all sites.
*/
float rest_energy(hydro_fields f, hydro_params p) {
int x, y, z;
float vol;
float restE = 0.0;
vol = p.dx*p.dx*p.dx;
for(x = 1; x <= p.slicex; x++) {
for(y = 1; y <= p.slicey; y++) {
for(z = 0; z < p.Lz; z++) {
#ifndef SCALAR
// kinetic energy
restE += (f.E[x][y][z]/f.W[x][y][z])*vol;
#endif // SCALAR
}
}
}
return restE; // /vol;
}
/** Compute total energy, i.e. 00 component of stress-energy.
*
* The zero-zero component of the stress energy tensor. It's
* basically just a different way of calculating total_energy(), and
* therefore serves as a cross-check.
*/
float tzerozero(hydro_fields f, hydro_params p) {
float total = 0.0;
int x, y, z;
float vol;
vol = p.dx*p.dx*p.dx;
for(x = 1; x <= p.slicex; x++) {
for(y = 1; y <= p.slicey; y++) {
for(z = 0; z < p.Lz; z++) {
// d_mu phi d^nu phi
// pi field if 00, otherwise grad mu, grad nu
total += f.pi_future[x][y][z]*f.pi_future[x][y][z];
// d_alpha phi d^alpha phi
// (minus sign if 00, otherwise plus)
total -= (0.5*f.pi_future[x][y][z]*f.pi_future[x][y][z]
- 0.125*((f.phi[x+1][y][z] - f.phi[x-1][y][z])/p.dx)
*((f.phi[x+1][y][z] - f.phi[x-1][y][z])/p.dx)
- 0.125*((f.phi[x][y+1][z] - f.phi[x][y-1][z])/p.dx)
*((f.phi[x][y+1][z] - f.phi[x][y-1][z])/p.dx)
- 0.125*((f.phi[x][y][(z+1)%p.Lz]
- f.phi[x][y][(z-1+p.Lz)%p.Lz])/p.dx)
*((f.phi[x][y][(z+1)%p.Lz]
- f.phi[x][y][(z-1+p.Lz)%p.Lz])/p.dx));
#ifndef SCALAR
// radiative fluid pressure
// (minus sign if 00, otherwise plus)
total -= (p.gdeg*f.T[x][y][z]*f.T[x][y][z]*f.T[x][y][z]*f.T[x][y][z]);
// potential
// (minus sign if 00, otherwise plus)
total -= (-1.0*Vf(p, f.T[x][y][z], f.phi[x][y][z]));
#else
total -= (-1.0*Vf(p, p.Tconst, f.phi[x][y][z]));
#endif // SCALAR
#ifndef SCALAR
// fluid energy
// (remember U_mu U_nu's at the end, no other sign)
total += (4.0*p.gdeg
*f.T[x][y][z]*f.T[x][y][z]*f.T[x][y][z]*f.T[x][y][z]
- f.T[x][y][z]*VTf(p, f.T[x][y][z], f.phi[x][y][z]))
*f.W[x][y][z]*f.W[x][y][z];
// U = (W, U1, U2, U3)
#endif // SCALAR
}
}
}
return total;
}
/** Compute sources of metric perturbations.
*
* Terms in the stress-energy tensor that are *LINEAR* in the metric,
* and therefore source metric perturbations.
*/
void stress_energy(hydro_fields f, hydro_params p, float ****Tij) {
int x, y, z;
float traceTij;
for(x = 1; x <= p.slicex; x++) {
for(y = 1; y <= p.slicey; y++) {
for(z = 0; z < p.Lz; z++) {
Tij[CPT_11][x][y][z] = 0.0;
Tij[CPT_21][x][y][z] = 0.0;
Tij[CPT_31][x][y][z] = 0.0;
Tij[CPT_22][x][y][z] = 0.0;
Tij[CPT_32][x][y][z] = 0.0;
Tij[CPT_33][x][y][z] = 0.0;
if(p.gwsource != GW_FIELD) {
#ifndef SCALAR
// fluid bits
Tij[CPT_11][x][y][z] += (4.0*p.gdeg*f.T[x][y][z]
*f.T[x][y][z]*f.T[x][y][z]*f.T[x][y][z]
- f.T[x][y][z]*VTf(p, f.T[x][y][z],
f.phi[x][y][z]))
*f.U[0][x][y][z]*f.U[0][x][y][z];
Tij[CPT_21][x][y][z] += (4.0*p.gdeg*f.T[x][y][z]
*f.T[x][y][z]*f.T[x][y][z]*f.T[x][y][z]
- f.T[x][y][z]*VTf(p, f.T[x][y][z],
f.phi[x][y][z]))
*f.U[1][x][y][z]*f.U[0][x][y][z];
Tij[CPT_31][x][y][z] += (4.0*p.gdeg*f.T[x][y][z]
*f.T[x][y][z]*f.T[x][y][z]*f.T[x][y][z]
- f.T[x][y][z]*VTf(p, f.T[x][y][z],
f.phi[x][y][z]))
*f.U[2][x][y][z]*f.U[0][x][y][z];
Tij[CPT_22][x][y][z] += (4.0*p.gdeg*f.T[x][y][z]
*f.T[x][y][z]*f.T[x][y][z]*f.T[x][y][z]
- f.T[x][y][z]*VTf(p, f.T[x][y][z],
f.phi[x][y][z]))
*f.U[1][x][y][z]*f.U[1][x][y][z];
Tij[CPT_32][x][y][z] += (4.0*p.gdeg*f.T[x][y][z]
*f.T[x][y][z]*f.T[x][y][z]*f.T[x][y][z]
- f.T[x][y][z]*VTf(p, f.T[x][y][z],
f.phi[x][y][z]))
*f.U[2][x][y][z]*f.U[1][x][y][z];
Tij[CPT_33][x][y][z] += (4.0*p.gdeg*f.T[x][y][z]
*f.T[x][y][z]*f.T[x][y][z]*f.T[x][y][z]
- f.T[x][y][z]*VTf(p, f.T[x][y][z],
f.phi[x][y][z]))
*f.U[2][x][y][z]*f.U[2][x][y][z];
#endif // SCALAR
}
if(p.gwsource != GW_FLUID) {
// Gradient bits
Tij[CPT_11][x][y][z] +=
0.25*((f.phi[x+1][y][z]
- f.phi[x-1][y][z])/p.dx)
*((f.phi[x+1][y][z] - f.phi[x-1][y][z])/p.dx);
Tij[CPT_21][x][y][z] +=
0.25*((f.phi[x+1][y][z]
- f.phi[x-1][y][z])/p.dx)
*((f.phi[x][y+1][z] - f.phi[x][y-1][z])/p.dx);
Tij[CPT_31][x][y][z] +=
0.25*((f.phi[x][y][(z+1)%p.Lz]
- f.phi[x][y][(z-1+p.Lz)%p.Lz])/p.dx)
*((f.phi[x+1][y][z] - f.phi[x-1][y][z])/p.dx);
Tij[CPT_22][x][y][z] +=
0.25*((f.phi[x][y+1][z]
- f.phi[x][y-1][z])/p.dx)
*((f.phi[x][y+1][z] - f.phi[x][y-1][z])/p.dx);
Tij[CPT_32][x][y][z] +=
0.25*((f.phi[x][y][(z+1)%p.Lz]
- f.phi[x][y][(z-1+p.Lz)%p.Lz])/p.dx)
*((f.phi[x][y+1][z] - f.phi[x][y-1][z])/p.dx);
Tij[CPT_33][x][y][z] +=
0.25*((f.phi[x][y][(z+1)%p.Lz]
- f.phi[x][y][(z-1+p.Lz)%p.Lz])/p.dx)
*((f.phi[x][y][(z+1)%p.Lz] - f.phi[x][y][(z-1+p.Lz)%p.Lz])/p.dx);
}
#ifdef TRACEFREE
// If trace free compiler flag then remove the trace. In single
// precision the trace of Tij can cause trace of udot to become large and leak into
// hdot:
traceTij = (Tij[CPT_11][x][y][z] + Tij[CPT_22][x][y][z] + Tij[CPT_33][x][y][z])/3.;
Tij[CPT_11][x][y][z] -= traceTij;
Tij[CPT_22][x][y][z] -= traceTij;
Tij[CPT_33][x][y][z] -= traceTij;
#endif // TRACEFREE
}
}
}
}
/** Compute energy density and store as a field.
*
* As for total_energy() but calculated on a per-lattice-site
* basis and then stored in en.
*/
void energy_density(hydro_fields f, hydro_params p, float ***en) {
int x, y, z;
float vol;
vol = p.dx*p.dx*p.dx;
for(x = 1; x <= p.slicex; x++) {
for(y = 1; y <= p.slicey; y++) {
for(z = 0; z < p.Lz; z++) {
en[x][y][z] = 0.0;
#ifndef SCALAR
// rest energy
en[x][y][z] += (f.E[x][y][z]/f.W[x][y][z])*vol;
// kinetic energy
en[x][y][z] += f.kappa[x][y][z]*(f.E[x][y][z]/f.W[x][y][z])
*(f.W[x][y][z]*f.W[x][y][z]-1.0)*vol;
#endif // SCALAR
// momentum squared (scalar field kinetic energy)
en[x][y][z] += 0.5*f.pi_future[x][y][z]*f.pi_future[x][y][z]*vol;
// gradient term
en[x][y][z] += 0.125*((f.phi[x+1][y][z] - f.phi[x-1][y][z])/p.dx)
*((f.phi[x+1][y][z] - f.phi[x-1][y][z])/p.dx)*vol;
en[x][y][z] += 0.125*((f.phi[x][y+1][z] - f.phi[x][y-1][z])/p.dx)
*((f.phi[x][y+1][z] - f.phi[x][y-1][z])/p.dx)*vol;
en[x][y][z] += 0.125*((f.phi[x][y][(z+1)%p.Lz]
- f.phi[x][y][(z-1+p.Lz)%p.Lz])/p.dx)
*((f.phi[x][y][(z+1)%p.Lz]
- f.phi[x][y][(z-1+p.Lz)%p.Lz])/p.dx)*vol;
}
}
}
}