-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtillotson.c
1544 lines (1348 loc) · 44.5 KB
/
tillotson.c
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
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2014-2018 Christian Reinhardt and Joachim Stadel.
*
* This file provides all the functions for the Tillotson EOS library.
* The Tillotson EOS (e.g. Benz 1986) is a relatively simple but reliable
* and convenient to use equation of state that can describe matter over
* a large range of pressures, densities and internal energies.
*
* tillotson.c:
*
* Basic functions:
*
* tillInit: initialise the library (contains all materials and converts to a given unit system).
*
* tillPressureSound: calculate the pressure and soundspeed for a given density and internal enegry using the Tillotson EOS.
*
* tillPressure: calculate the pressure for a given rho and u from the Tillotson EOS (uses tillPressureSound).
*
* tillSoundSpeed: calculate the sound speed for a given rho and u from the Tillotson EOS (uses tillPressureSound).
*
* tillFinalize: free memory.
*/
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <stdio.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_roots.h>
#include "tillotson.h"
/* This will cut the pressure in the cold expanded states for rho/rho0 < 0.8 as suggested in Melosh1989. */
//#define TILL_PRESS_MELOSH
/*
* Initialize a material from the Tillotson library
*
* We do:
* Initialize variables
* Convert quantities to code units
* The memory for the look up table is allocated in tillInitLookup()
*/
TILLMATERIAL *tillInitMaterial(int iMaterial, double dKpcUnit, double dMsolUnit)
{
const double KBOLTZ = 1.38e-16; /* bolzman constant in cgs */
const double MHYDR = 1.67e-24; /* mass of hydrogen atom in grams */
const double MSOLG = 1.99e33; /* solar mass in grams */
const double GCGS = 6.67e-8; /* G in cgs */
const double KPCCM = 3.085678e21; /* kiloparsec in centimeters */
const double NA = 6.022e23; /* Avogadro's number */
TILLMATERIAL *material;
material = (TILLMATERIAL *) calloc(1, sizeof(TILLMATERIAL));
assert(material != NULL);
material->iMaterial = iMaterial;
/* This two parameters define the unit system we use. */
material->dKpcUnit = dKpcUnit;
material->dMsolUnit = dMsolUnit;
material->rhomin = 0.0;
material->rhomax = 0.0;
material->vmax = 0.0;
material->n = 0;
material->dlogrho = 0.0;
material->dv = 0.0;
if (dKpcUnit <= 0.0 && dMsolUnit <= 0.0)
{
/* In this case units are not converted, so the code units are cgs. */
material->dGasConst = KBOLTZ; // dGasConst is NOT KBOLZ !!!!!!!
material->dErgPerGmUnit = 1.0;
material->dGmPerCcUnit = 1.0;
material->dSecUnit = 1.0;
} else {
/*
** Convert kboltz/mhydrogen to system units, assuming that
** G == 1.
*/
material->dGasConst = material->dKpcUnit*KPCCM*KBOLTZ
/MHYDR/GCGS/material->dMsolUnit/MSOLG;
/* code energy per unit mass --> erg per g */
material->dErgPerGmUnit = GCGS*material->dMsolUnit*MSOLG/(material->dKpcUnit*KPCCM);
/* code density --> g per cc */
material->dGmPerCcUnit = (material->dMsolUnit*MSOLG)/pow(material->dKpcUnit*KPCCM,3.0);
/* code time --> seconds */
material->dSecUnit = sqrt(1/(material->dGmPerCcUnit*GCGS));
}
/*
* Set the Tillotson parameters for the material.
*/
switch(iMaterial)
{
case IDEALGAS:
/*
* Ideal gas EOS. Currently we are limited to monoatomic gases. Keep in mind that
* dGasConstant is not R but seems to be kb/mp (where mp is the mean particle mass) in
* Gasoline.
*/
material->dConstGamma = 5.0/3.0;
material->dMeanMolMass = 1.0;
// material->dMeanMolMass = 23.0; // 10x solar value (mu=2.3)
// material->dMeanMolMass = 11.5; // 5x solar value (mu=2.3)
// material->dMeanMolMass = 11.5; // 5x solar value (mu=2.3)
// material->dMeanMolMass = 17.25; // 7.5x solar value (mu=2.3)
// material->dMeanMolMass = 2.3; // solar value (mu=2.3)
// cv = kb/mp
material->cv = KBOLTZ/((material->dConstGamma-1.0)*MHYDR*material->dMeanMolMass);
material->rho0 = 0.001;
/*
* Add a finite volume to each gas particle to avoid crazy densities at large pressure
* but neglect self-interaction.
*
* Hydrogen: b = 26.6 cm^3/mol (Wikipedia)
*
* The code uses b'=b/dMeanMolarMass instead, so be careful when converting the
* parameter ([b] = cm^3/(g*mol)).
*
* For b=0 the ideal gas EOS is obtained.
*
* NOTE: Introducing the parameter b defines a maximum density and the code must
* assert that rho < rho_max.
*/
material->b = 26.6/(material->dMeanMolMass*MHYDR*NA);
material->b = 0.0;
material->a = 0.0;
break;
case GRANITE:
/*
* Material parameters from Benz et al. (1986).
*/
material->a = 0.5;
material->b = 1.3;
material->u0 = 1.6e11; /* in ergs/g */
material->rho0 = 2.7; /* g/cc */
material->A = 1.8e11; /* ergs/cc */
material->B = 1.8e11; /* ergs/cc */
material->us = 3.5e10; /* ergs/g */
material->us2 = 1.8e11; /* ergs/g */
material->alpha = 5.0;
material->beta = 5.0;
material->cv = 0.79e7; /* ergs/g K (or 790 J/kg K) */
break;
case IRON:
/*
* Material parameters from Benz et al. (1987).
*/
material->a = 0.5;
material->b = 1.5;
material->u0 = 9.5e10; /* in ergs/g */
material->rho0 = 7.86; /* g/cc */
material->A = 1.279e12; /* ergs/cc */
material->B = 1.05e12; /* ergs/cc */
material->us = 1.42e10; /* ergs/g */
material->us2 = 8.45e10; /* ergs/g */
material->alpha = 5.0;
material->beta = 5.0;
material->cv = 0.449e7; /* ergs/g K */
break;
case BASALT:
/*
** Material parameters from Benz & Asphaug (1999).
*/
material->a = 0.5;
material->b = 1.5;
material->u0 = 4.87e12; /* in ergs/g */
material->rho0 = 2.7; /* g/cc */
material->A = 2.67e11; /* ergs/cc */
material->B = 2.67e11; /* ergs/cc */
material->us = 4.72e10; /* ergs/g */
material->us2 = 1.82e11; /* ergs/g */
material->alpha = 5.0;
material->beta = 5.0;
material->cv = 0.84e7; /* ergs/g K */
break;
case ICE:
/*
* Material parameters from Benz & Asphaug (1999).
*/
material->a = 0.3;
material->b = 0.1;
material->u0 = 1.0e11; /* in ergs/g */
material->rho0 = 0.917; /* g/cc */
material->A = 9.47e10; /* ergs/cc */
material->B = 9.47e10; /* ergs/cc */
material->us = 7.73e9; /* ergs/g */
material->us2 = 3.04e10; /* ergs/g */
material->alpha = 10.0;
material->beta = 5.0;
/*
* Note that the expression for Pe provided in Benz et al. (1986) does not agree
* in alpha and beta with the one provided in Melosh (1989) or Benz & Asphaug (1999).
* It seems that alpha and beta were switched so we use alpha=5 and beta=10.
*/
material->alpha = 5.0;
material->beta = 10.0;
// Have to look up in more details?
material->cv = 1.0e7; /* ergs/g K */
break;
case WATER:
/*
* Material parameters from Woolfson (2007).
*/
material->a = 0.5;
material->b = 0.9;
material->u0 = 2.0e10; /* in ergs/g */
material->rho0 = 1.00; /* g/cc */
material->A = 2.00e11; /* ergs/cc */
material->B = 1.00e11; /* ergs/cc */
material->us = 4.00e9; /* ergs/g */
material->us2 = 2.04e10; /* ergs/g */
material->alpha = 5.0;
material->beta = 5.0;
// Have to look up in more details?
material->cv = 4.1814e7; /* ergs/g K */
break;
case DUNITE:
/*
* Material parameters that imitate dunite in ANEOS (Thompson 1972).
*/
material->a = 0.5;
material->b = 1.5;
material->u0 = 4.87e12; /* in ergs/g */
// Key difference is the reference density
material->rho0 = 3.32; /* g/cc */
material->A = 2.67e11; /* ergs/cc */
material->B = 2.67e11; /* ergs/cc */
material->us = 4.72e10; /* ergs/g */
material->us2 = 1.82e11; /* ergs/g */
material->alpha = 5.0;
material->beta = 5.0;
material->cv = 0.84e7; /* ergs/g K */
break;
default:
/* Unknown material */
assert(0);
}
/*
* Convert energies and densities to code units!
*/
material->u0 /= material->dErgPerGmUnit;
material->us /= material->dErgPerGmUnit;
material->us2 /= material->dErgPerGmUnit;
material->rho0 /= material->dGmPerCcUnit;
material->A /= (material->dGmPerCcUnit*material->dErgPerGmUnit);
material->B /= (material->dGmPerCcUnit*material->dErgPerGmUnit);
material->cv /= material->dErgPerGmUnit;
/*
* In case of an ideal gas the parameters a and b have to be converted to
* code units too. Note that [b] = cm^3/(g*mol).
*/
if (iMaterial == IDEALGAS)
{
material->b *=material->dGmPerCcUnit;
}
return material;
}
/*
* Free the memory.
*/
void tillFinalizeMaterial(TILLMATERIAL *material)
{
if (material->Lookup != NULL) free(material->Lookup);
// if (material->cold != NULL) free(material->cold);
free(material);
}
/*
* This function stores the materials name in a string string.
*/
void tilliMatString(TILLMATERIAL *material, char *MatName)
{
assert(MatName != NULL);
switch(material->iMaterial)
{
case IDEALGAS:
sprintf(MatName, "IDEAL_GAS");
break;
case GRANITE:
sprintf(MatName, "GRANITE");
break;
case IRON:
sprintf(MatName, "IRON");
break;
case BASALT:
sprintf(MatName, "BASALT");
break;
case ICE:
sprintf(MatName, "ICE");
break;
case WATER:
sprintf(MatName, "WATER");
break;
case DUNITE:
sprintf(MatName, "DUNITE");
break;
default:
/* Unknown material */
assert(0);
}
}
/*
* This function returns an error message for each error code.
*/
void tillErrorString(int iError, char *ErrorString)
{
assert(ErrorString != NULL);
switch(iError)
{
case TILL_LOOKUP_SUCCESS:
sprintf(ErrorString, "TILL_LOOKUP_SUCCESS");
break;
case TILL_LOOKUP_OUTSIDE_RHOMIN:
sprintf(ErrorString, "TILL_LOOKUP_OUTSIDE_RHOMIN");
break;
case TILL_LOOKUP_OUTSIDE_RHOMAX:
sprintf(ErrorString, "TILL_LOOKUP_OUTSIDE_RHOMAX");
break;
case TILL_LOOKUP_OUTSIDE_VMIN:
sprintf(ErrorString, "TILL_LOOKUP_OUTSIDE_VMIN");
break;
case TILL_LOOKUP_OUTSIDE_VMAX:
sprintf(ErrorString, "TILL_LOOKUP_OUTSIDE_VMAX");
break;
default:
sprintf(ErrorString, "UNKNOWN ERROR");
}
}
/*
* This function prints the material constants for a given material.
*/
void tillPrintMat(TILLMATERIAL *material, FILE *fp)
{
char MatName[256];
assert(material != NULL);
tilliMatString(material, MatName);
fprintf(fp,"# Material: %i (%s)\n", material->iMaterial, MatName);
/*
* Currently the ideal gas is treated differently.
*/
if (material->iMaterial == IDEALGAS)
{
fprintf(fp,"# dConstGamma: %g\n", material->dConstGamma);
fprintf(fp,"# dMeanMolMass: %g\n", material->dMeanMolMass);
fprintf(fp,"# rho0: %g\n", material->rho0);
fprintf(fp,"# cv: %g\n", material->cv);
fprintf(fp,"# a: %g\n", material->a);
fprintf(fp,"# b: %g\n", material->b);
} else {
fprintf(fp,"# a: %g\n", material->a);
fprintf(fp,"# b: %g\n", material->b);
fprintf(fp,"# A: %g\n", material->A);
fprintf(fp,"# B: %g\n", material->B);
fprintf(fp,"# rho0: %g\n", material->rho0);
fprintf(fp,"# u0: %g\n", material->u0);
fprintf(fp,"# us: %g\n", material->us);
fprintf(fp,"# us2: %g\n", material->us2);
fprintf(fp,"# alpha: %g\n", material->alpha);
fprintf(fp,"# beta: %g\n", material->beta);
fprintf(fp,"# cv: %g\n", material->cv);
}
}
/*
* These functions provide a more general interface for EOS calls so the user can in principle add
* different EOS (e.g., an ideal gas).
*/
double eosPressureSound(TILLMATERIAL *material, double rho, double u, double *pcSound)
{
if (material->iMaterial == IDEALGAS)
{
/*
* In this case an ideal gas EOS is used.
*/
#if 0
if (pcSound != NULL) *pcSound = material->dConstGamma*(material->dConstGamma-1.0)*u;
return ((material->dConstGamma-1.0)*rho*u);
#endif
/*
* (CR) 25.12.17: Generalized the ideal gas EOS by introducing a volume
* to each gas particle. In the limit b=0 an ideal gas is obtained.
*
* NOTE: For densities larger than 1/b the pressure is negative. This
* must be treated properly or the code will crash.
*/
if (rho >= (1.0/material->b)*0.99)
{
rho = (1.0/material->b)*0.99;
}
if (pcSound != NULL)
*pcSound = sqrt(material->dConstGamma*(material->dConstGamma-1.0)*u/pow(1.0-material->b*rho, 2.0));
return ((material->dConstGamma-1.0)*rho*u/(1.0-material->b*rho));
} else {
return (tillPressureSound(material, rho, u, pcSound));
}
}
double eosPressure(TILLMATERIAL *material, double rho, double u)
{
return (eosPressureSound(material, rho, u, NULL));
}
double eosPressureSoundRhoT(TILLMATERIAL *material, double rho, double T, double *pcSound)
{
double u;
u = eosURhoTemp(material, rho, T);
return eosPressureSound(material, rho, u, pcSound);
}
double eosPressureRhoT(TILLMATERIAL *material, double rho, double T)
{
return (eosPressureSoundRhoT(material, rho, T, NULL));
}
double eosdPdrho(TILLMATERIAL *material, double rho, double u)
{
if (material->iMaterial == IDEALGAS)
{
/*
* In this case an ideal gas EOS is used.
*/
#if 0
return ((material->dConstGamma-1.0)*u);
#endif
/*
* (CR) 25.12.17: Generalized the ideal gas EOS by introducing a volume
* to each gas particle. In the limit b=0 an ideal gas is obtained.
* (CR) 20.01.18: Found a bug in the expression for the ideal gas!
*/
return ((material->dConstGamma-1.0)*u/(pow(1.0-material->b*rho, 2.0)));
} else {
return (tilldPdrho(material, rho, u));
}
}
double eosdPdu(TILLMATERIAL *material, double rho, double u)
{
if (material->iMaterial == IDEALGAS)
{
/*
* In this case an ideal gas EOS is used.
*/
# if 0
return ((material->dConstGamma-1.0)*rho);
#endif
/*
* (CR) 25.12.17: Generalized the ideal gas EOS by introducing a volume
* to each gas particle. In the limit b=0 an ideal gas is obtained.
*/
return ((material->dConstGamma-1.0)*rho/(1.0-material->b*rho));
} else {
return (tilldPdu(material, rho, u));
}
}
/*
* Calculate T(rho,u) for a material. As an approximation we use
*
* u(rho,T) = uc(rho) + cv*T
*
* for condensed materials.
*/
double eosTempRhoU(TILLMATERIAL *material, double rho, double u)
{
assert(material->cv > 0.0);
/*
* For an ideal gas the temperature is independent of the density.
*/
if (material->iMaterial == IDEALGAS)
{
// fprintf(stderr, "(CR) eosTempRhoU(): Ideal gas: rho= %g u= %g gamma= %g cv= %g T= %g\n", rho, u, material->dConstGamma, material->cv, u/material->cv);
return(u/material->cv);
} else {
return(tillTempRhoU(material, rho, u));
}
}
/*
* Calculate rho(P, u) for a given EOS and material using bisection.
*/
double eosRhoPU(TILLMATERIAL *material, double P, double u)
{
double a, b, c, Pa, Pb, Pc;
a = 0.0;
Pa = eosPressure(material, a, u);
b = material->rhomax;
Pb = eosPressure(material, b, u);
/*
* Make sure the root is bracketed.
*/
while (Pb < P)
{
b = 2.0*b;
Pb = eosPressure(material, b, u);
}
fprintf(stderr, "a= %g, Pa= %g, b= %g, Pb= %g\n", a, Pa, b, Pb);
assert(Pa < P && Pb > P);
while ((Pb-Pa) > 1e-10*Pc)
{
c = 0.5*(a + b);
Pc = eosPressure(material, c, u);
if (Pc < P)
{
a = c;
Pa = Pc;
} else {
b = c;
Pb = Pc;
}
}
return(c);
}
/*
* Calculate u(rho, P) for a given EOS and material using bisection.
*/
double eosURhoP(TILLMATERIAL *material, double rho, double P)
{
double a, b, c, Pa, Pb, Pc;
// Use the analytic solution for the ideal gas
if (material->iMaterial == IDEALGAS)
{
}
// umin = 0.0
a = 0.0;
Pa = eosPressure(material, rho, a);
b = 100.0;
Pb = eosPressure(material, rho, b);
/*
* Make sure the root is bracketed.
*/
while (Pb <= P)
{
b = 2.0*b;
Pb = eosPressure(material, rho, b);
fprintf(stderr, "rho= %g P= %g: a= %g, Pa= %g, b= %g, Pb= %g\n", rho, P, a, Pa, b, Pb);
}
fprintf(stderr, "rho= %g P= %g: a= %g, Pa= %g, b= %g, Pb= %g\n", rho, P, a, Pa, b, Pb);
assert(Pa<P && Pb>P);
while ((Pb-Pa) > 1e-10*Pc)
{
c = 0.5*(a + b);
Pc = eosPressure(material, rho, c);
if (Pc < P)
{
a = c;
Pa = Pc;
} else {
b = c;
Pb = Pc;
}
}
return(c);
}
/*
* Calculate u(rho,T) for a material.
*/
double eosURhoTemp(TILLMATERIAL *material, double rho, double T)
{
if (material->iMaterial == IDEALGAS)
{
// For the ideal gas there is no cold term.
return(material->cv*T);
} else {
return tillURhoTemp(material, rho, T);
}
}
/*
* Calculate rho(P, T) for a given EOS and material.
*/
double eosRhoPTemp(TILLMATERIAL *material, double P, double T)
{
double rho;
if (material->iMaterial == IDEALGAS)
{
// For the ideal gas there is an analytic expression.
rho = P/((material->dConstGamma-1.0)*material->cv*T+P*material->b);
// Limit rho to 0.99*rho_min because for larger values the EOS becomes very stiff.
if ((material->b > 0.0) && (rho >= (1.0/material->b)*0.99))
rho = (1.0/material->b)*0.99;
} else {
// If it is a Tillotson material call tillRhoPTemp().
rho = tillRhoPTemp(material, P, T);
}
return rho;
}
/*
* Given rho1, u1 (material 1) solve for rho2, u2 (material 2) at the interface between two material.
*
* The b.c. are:
*
* P1(rho1, u1)=P2(rho2, u2) and T1(rho1, u1)=T2(rho2, u2)
*
* Since P = P(rho, T) and T1=T2 we solve for P2(rho2)-P1=0.
*
* Returns TILL_SUCCESS if successful or TILL_FAIL if not.
*/
int eosSolveBC(TILLMATERIAL *mat1, TILLMATERIAL *mat2, double rho1, double u1, double *prho2, double *pu2)
{
double P, T;
/* Check if there is indeed a material interface. */
if (mat1->iMaterial == mat2->iMaterial)
{
#ifdef TILL_VERBOSE
fprintf(stderr, "eosSolveBC: No material interface (mat1= %i, mat2= %i).\n",
mat1->iMaterial, mat2->iMaterial);
#endif
return TILL_FAIL;
}
if (mat1->iMaterial != IDEALGAS && mat2->iMaterial != IDEALGAS)
{
/* Both materials are not an ideal gas. */
return tillSolveBC(mat1, mat2, rho1, u1, prho2, pu2);
} else if (mat1->iMaterial != IDEALGAS && mat2->iMaterial == IDEALGAS) {
/* Condensed material and ideal gas. */
P = eosPressure(mat1, rho1, u1);
T = eosTempRhoU(mat1, rho1, u1);
/* For an ideal gas there is an analytic solution. */
*pu2 = mat2->cv*T;
*prho2 = P/((mat2->dConstGamma-1.0)*mat2->cv*T);
return TILL_SUCCESS;
} else {
assert(0);
}
return TILL_FAIL;
}
/*
* Calculate phi and gamma as given in Hu et al. (2009).
*/
double eosPhi(TILLMATERIAL *material, double rho, double u)
{
return(eosdPdrho(material, rho, u));
}
double eosGamma(TILLMATERIAL *material, double rho, double u)
{
return(1.0/rho*eosdPdu(material, rho, u));
}
/*
* Calculate dP/drho at constant entropy.
*/
double tilldPdrho_s(TILLMATERIAL *material, double rho, double u)
{
return (1.0/(rho*rho)*(tillSoundSpeed(material,rho, u)-2.0*tillPressure(material,rho,u)/rho));
}
/*
* Calculate the pressure and sound speed from the Tillotson EOS for a material. Set pcSound = NULL
* to only calculate the pressure forces.
*
* Note: tillPressureSoundNP does not pressure or sound speed correction. In most cases we suggest
* using tillPressureSound (e.g., in a hydro code).
*/
double tillPressureSoundNP(TILLMATERIAL *material, double rho, double u, double *pcSound)
{
double eta, mu;
double Pc, Pe;
double c2c, c2e;
double Gammac, Gammae, w0, y, z;
eta = rho/material->rho0;
mu = eta - 1.0;
z = (1.0 - eta)/eta;
w0 = u/(material->u0*eta*eta)+1.0;
/*
* Here we evaluate, which part of the equation of state we need.
*/
if (rho >= material->rho0 || u < material->us) {
/*
* Condensed states (rho > rho0) or expanded cold states.
*/
Gammac = material->a + material->b/w0;
Pc = Gammac*u*rho + material->A*mu + material->B*mu*mu;
if (pcSound != NULL)
{
/* Calculate the sound speed. */
c2c =material->a*u+material->b*u/(w0*w0)*(3.0*w0-2.0)+(material->A+2.0*material->B*mu)/material->rho0 + Pc/(rho*rho)*(material->a*rho+material->b*rho/(w0*w0));
*pcSound = sqrt(c2c);
}
return (Pc);
} else if (u > material->us2) {
/*
* Expanded hot states (rho < rho0 and u > us2).
*/
Gammae = material->a + material->b/w0*exp(-material->beta*z*z);
Pe = Gammae*u*rho + material->A*mu*exp(-(material->alpha*z+material->beta*z*z));
if (pcSound != NULL)
{
/* calculate the sound speed */
c2e = (Gammae+1.0)*Pe/rho + material->A/material->rho0*exp(-(material->alpha*z+material->beta*z*z))*(1.0+mu/(eta*eta)*(material->alpha+2.0*material->beta*z-eta)) + material->b*rho*u/(w0*w0*eta*eta)*exp(-material->beta*z*z)*(2.0*material->beta*z*w0/material->rho0+1.0/(material->u0*rho)*(2.0*u-Pe/rho));
*pcSound = sqrt(c2e);
}
return (Pe);
} else {
/*
* intermediate states (rho < rho0 and us < u < us2)
*/
y = (u - material->us)/(material->us2 - material->us);
Gammac = material->a + material->b/w0;
Pc = Gammac*u*rho + material->A*mu + material->B*mu*mu;
Gammae = material->a + material->b/w0*exp(-material->beta*z*z);
Pe = Gammae*u*rho + material->A*mu*exp(-(material->alpha*z+material->beta*z*z));
/*
* Set Pc to zero if it is negative so it does not contribute to the pressure in the
* expanded, intermediate states.
*/
#ifdef TILL_PRESS_MELOSH
if (eta < 0.8)
{
Pc = 0.0;
}
#endif
#ifdef TILL_PRESS_NP
if (Pc < 0.0) Pc = 0.0;
#endif
if (pcSound != NULL)
{
/* calculate the sound speed */
c2c =material->a*u+material->b*u/(w0*w0)*(3.0*w0-2.0)+(material->A+2.0*material->B*mu)/material->rho0 + Pc/(rho*rho)*(material->a*rho+material->b*rho/(w0*w0));
c2e = (Gammae+1.0)*Pe/rho + material->A/material->rho0*exp(-(material->alpha*z+material->beta*z*z))*(1.0+mu/(eta*eta)*(material->alpha+2.0*material->beta*z-eta)) + material->b*rho*u/(w0*w0*eta*eta)*exp(-material->beta*z*z)*(2.0*material->beta*z*w0/material->rho0+1.0/(material->u0*rho)*(2.0*u-Pe/rho));
*pcSound = sqrt(c2c*(1.0-y)+c2e*y);
}
return (Pc*(1.0-y)+Pe*y);
}
}
/*
* Calculate the pressure and sound speed from the Tillotson EOS for a material. Set pcSound = NULL
* to only calculate the pressure forces.
*/
double tillPressureSound(TILLMATERIAL *material, double rho, double u, double *pcSound)
{
double eta, mu;
double Pc, Pe;
double c2c, c2e;
double Gammac, Gammae, w0, y, z;
eta = rho/material->rho0;
mu = eta - 1.0;
z = (1.0 - eta)/eta;
w0 = u/(material->u0*eta*eta)+1.0;
/*
* Here we evaluate, which part of the equation of state we need.
*/
if (rho >= material->rho0 || u < material->us) {
/*
* Condensed states (rho > rho0) or expanded cold states.
*/
Gammac = material->a + material->b/w0;
Pc = Gammac*u*rho + material->A*mu + material->B*mu*mu;
#ifdef TILL_PRESS_MELOSH
/* Melosh 1989 suggests to cut the pressure in the expanded cold states for rho/rho < 0.8 */
if (eta < 0.8)
{
Pc = 0.0;
}
#endif
#ifdef TILL_PRESS_NP
/* The pressure is set to zero if it becomes negative. */
if (Pc < 0.0) Pc = 0.0;
#endif
if (pcSound != NULL)
{
/* Calculate the sound speed. */
// c2c = (Gammac+1.0)*Pc/rho + (material->A+material->B*(eta*eta-1.0))/rho + material->b/(w0*w0)*(w0-1.0)*(2*u-Pc/rho);
// Altough for P > 0 the two expressions are the same, for P=0 this gives a bigger sound speed.
c2c =material->a*u+material->b*u/(w0*w0)*(3.0*w0-2.0)+(material->A+2.0*material->B*mu)/material->rho0 + Pc/(rho*rho)*(material->a*rho+material->b*rho/(w0*w0));
/*
* Set the minimum sound speed to the uncompressed bulk sound speed to avoid issues when P<0.
*/
c2c = MAX(c2c, material->A/material->rho0);
*pcSound = sqrt(c2c);
}
return (Pc);
} else if (u > material->us2) {
/*
* Expanded hot states (rho < rho0 and u > us2).
*/
Gammae = material->a + material->b/w0*exp(-material->beta*z*z);
Pe = Gammae*u*rho + material->A*mu*exp(-(material->alpha*z+material->beta*z*z));
if (pcSound != NULL)
{
/* calculate the sound speed */
c2e = (Gammae+1.0)*Pe/rho + material->A/material->rho0*exp(-(material->alpha*z+material->beta*z*z))*(1.0+mu/(eta*eta)*(material->alpha+2.0*material->beta*z-eta)) + material->b*rho*u/(w0*w0*eta*eta)*exp(-material->beta*z*z)*(2.0*material->beta*z*w0/material->rho0+1.0/(material->u0*rho)*(2.0*u-Pe/rho));
c2e = MAX(c2e, material->A/material->rho0);
*pcSound = sqrt(c2e);
}
return (Pe);
} else {
/*
* intermediate states (rho < rho0 and us < u < us2)
*/
y = (u - material->us)/(material->us2 - material->us);
Gammac = material->a + material->b/w0;
Pc = Gammac*u*rho + material->A*mu + material->B*mu*mu;
Gammae = material->a + material->b/w0*exp(-material->beta*z*z);
Pe = Gammae*u*rho + material->A*mu*exp(-(material->alpha*z+material->beta*z*z));
#ifdef TILL_PRESS_MELOSH
/* Melosh 1989 suggests to cut the pressure in the expanded cold states for rho/rho < 0.8 */
if (eta < 0.8)
{
Pc = 0.0;
}
#endif
#ifdef TILL_PRESS_NP
/* The pressure is set to zero if it becomes negative. */
if (Pc < 0.0) Pc = 0.0;
#endif
if (pcSound != NULL)
{
/* calculate the sound speed */
c2c =material->a*u+material->b*u/(w0*w0)*(3.0*w0-2.0)+(material->A+2.0*material->B*mu)/material->rho0 + Pc/(rho*rho)*(material->a*rho+material->b*rho/(w0*w0));
c2e = (Gammae+1.0)*Pe/rho + material->A/material->rho0*exp(-(material->alpha*z+material->beta*z*z))*(1.0+mu/(eta*eta)*(material->alpha+2.0*material->beta*z-eta)) + material->b*rho*u/(w0*w0*eta*eta)*exp(-material->beta*z*z)*(2.0*material->beta*z*w0/material->rho0+1.0/(material->u0*rho)*(2.0*u-Pe/rho));
*pcSound = c2c*(1.0-y)+c2e*y;
*pcSound = sqrt(MAX(*pcSound, material->A/material->rho0));
}
return (Pc*(1.0-y)+Pe*y);
}
}
/*
* Calculate the pressure from the Tillotson EOS for a material.
*/
double tillPressure(TILLMATERIAL *material, double rho, double u)
{
double P = tillPressureSound(material, rho, u, NULL);
#ifdef TILL_PRESS_NP
/* Make a pressure cut off, if P < 0. */
if (P < 0.0 ) P = 0.0;
#endif
return P;
}
/*
* Calculate dP/drho at u=const.
*/
double tilldPdrho(TILLMATERIAL *material, double rho, double u)
{
double eta, mu;
double dPcdrho, dPedrho;
double w0, y, z;
eta = rho/material->rho0;
mu = eta - 1.0;
z = (1.0 - eta)/eta;
w0 = u/(material->u0*eta*eta)+1.0;
/*
* Here we evaluate, which part of the equation of state we need.
*/
if (rho >= material->rho0 || u < material->us) {
/*
* Condensed (rho > rho0) or cold expanded states (rho < rho0 and u < us).
*/
dPcdrho = material->a*u + material->b*u/(w0*w0)*(3.0*w0-2.0) + (material->A+2.0*material->B*mu)/material->rho0;
return (dPcdrho);
} else if (u > material->us2) {
/*
* Expanded hot states (rho < rho0 and u > us2).
*/
dPedrho = (material->a + material->b/w0*exp(-material->beta*z*z)*(2.0*material->beta*z/eta+3.0-2.0/w0))*u+material->A/material->rho0*exp(-(material->alpha*z+material->beta*z*z))*(1.0+mu/(eta*eta)*(material->alpha+2.0*material->beta*z-eta));
return (dPedrho);
} else {
/*
* Intermediate states (rho < rho0 and us < u < us2).
*/
y = (u - material->us)/(material->us2 - material->us);
dPcdrho = material->a*u + material->b*u/(w0*w0)*(3.0*w0-2.0) + (material->A+2.0*material->B*mu)/material->rho0;
dPedrho = (material->a + material->b/w0*exp(-material->beta*z*z)*(2.0*material->beta*z/eta+3.0-2.0/w0))*u+material->A/material->rho0*exp(-(material->alpha*z+material->beta*z*z))*(1.0+mu/(eta*eta)*(material->alpha+2.0*material->beta*z-eta));
return (dPcdrho*(1.0-y)+dPedrho*y);
}
}
/*
* Calculate dP/du at rho=const.
*/
double tilldPdu(TILLMATERIAL *material, double rho, double u)
{
double eta, mu;
double dPcdu, dPedu;
double w0, y, z;
eta = rho/material->rho0;
mu = eta - 1.0;
z = (1.0 - eta)/eta;
w0 = u/(material->u0*eta*eta)+1.0;
/*
* Here we evaluate, which part of the equation of state we need.
*/
if (rho >= material->rho0 || u < material->us) {
/*
* Condensed (rho > rho0) or cold expanded states (rho < rho0 and u < us).
*/
dPcdu = material->a*rho + material->b*rho/(w0*w0);
return (dPcdu);
} else if (u > material->us2) {
/*
* Expanded hot states (rho < rho0 and u > us2).
*/
dPedu = (material->a + material->b/(w0*w0)*exp(-material->beta*z*z))*rho;
return (dPedu);
} else {
/*
* Intermediate states (rho < rho0 and us < u < us2).
*/
y = (u - material->us)/(material->us2 - material->us);
dPcdu = material->a*rho + material->b*rho/(w0*w0);
dPedu = (material->a + material->b/(w0*w0)*exp(-material->beta*z*z))*rho;
return (dPcdu*(1.0-y)+dPedu*y);
}
}
double tilldTdrho(TILLMATERIAL *material, double rho, double u)
{
/*
* Calculate dT/drho at u=const.
*/
assert(material->cv > 0.0);