23
23
#endif
24
24
25
25
#include < singularity-eos/base/constants.hpp>
26
+ #include < singularity-eos/base/robust_utils.hpp>
26
27
#include < singularity-eos/eos/eos.hpp>
27
28
#include < test/eos_unit_test_helpers.hpp>
28
29
29
30
using singularity::CarnahanStarling;
30
31
using singularity::IdealGas;
32
+ namespace robust = singularity::robust;
31
33
using EOS = singularity::Variant<IdealGas, CarnahanStarling>;
32
34
33
35
SCENARIO (" CarnahanStarling1" , " [CarnahanStarling][CarnahanStarling1]" ) {
@@ -39,6 +41,8 @@ SCENARIO("CarnahanStarling1", "[CarnahanStarling][CarnahanStarling1]") {
39
41
// Create the EOS
40
42
EOS host_eos = CarnahanStarling (gm1, Cv, bb, qq);
41
43
EOS eos = host_eos.GetOnDevice ();
44
+ Real rho_0, T_0, e_0, P_0, cv_0, bmod_0, dpde_0, dvdt_0;
45
+ host_eos.ValuesAtReferenceState (rho_0, T_0, e_0, P_0, cv_0, bmod_0, dpde_0, dvdt_0);
42
46
GIVEN (" Densities and energies" ) {
43
47
constexpr int num = 4 ;
44
48
#ifdef PORTABILITY_STRATEGY_KOKKOS
@@ -121,7 +125,7 @@ SCENARIO("CarnahanStarling1", "[CarnahanStarling][CarnahanStarling1]") {
121
125
#endif // PORTABILITY_STRATEGY_KOKKOS
122
126
THEN (" The returned P(rho, e) should be equal to the true value" ) {
123
127
array_compare (num, density, energy, h_pressure, pressure_true, " Density" ,
124
- " Energy" );
128
+ " Energy" , 1e-12 * P_0 );
125
129
}
126
130
}
127
131
@@ -133,7 +137,7 @@ SCENARIO("CarnahanStarling1", "[CarnahanStarling][CarnahanStarling1]") {
133
137
#endif // PORTABILITY_STRATEGY_KOKKOS
134
138
THEN (" The returned B_S(rho, e) should be equal to the true value" ) {
135
139
array_compare (num, density, energy, h_bulkmodulus, bulkmodulus_true, " Density" ,
136
- " Energy" );
140
+ " Energy" , 1e-12 * bmod_0 );
137
141
}
138
142
}
139
143
@@ -145,7 +149,7 @@ SCENARIO("CarnahanStarling1", "[CarnahanStarling][CarnahanStarling1]") {
145
149
#endif // PORTABILITY_STRATEGY_KOKKOS
146
150
THEN (" The returned B_S(rho, e) should be equal to the true value" ) {
147
151
array_compare (num, density, energy, h_temperature, temperature_true, " Density" ,
148
- " Energy" );
152
+ " Energy" , 1e-12 * T_0 );
149
153
}
150
154
}
151
155
@@ -158,7 +162,7 @@ SCENARIO("CarnahanStarling1", "[CarnahanStarling][CarnahanStarling1]") {
158
162
#endif // PORTABILITY_STRATEGY_KOKKOS
159
163
THEN (" The returned Gamma(rho, e) should be equal to the true value" ) {
160
164
array_compare (num, density, energy, h_gruneisen, gruneisen_true, " Density" ,
161
- " Energy" );
165
+ " Energy" , 1e-12 * dpde_0 / rho_0 );
162
166
}
163
167
}
164
168
@@ -189,6 +193,8 @@ SCENARIO("CarnahanStarling2", "[CarnahanStarling][CarnahanStarling2]") {
189
193
// Create the EOS
190
194
EOS host_eos = CarnahanStarling (gm1, Cv, bb, qq, qp, T0, P0);
191
195
EOS eos = host_eos.GetOnDevice ();
196
+ Real rho_0, T_0, e_0, P_0, cv_0, bmod_0, dpde_0, dvdt_0;
197
+ host_eos.ValuesAtReferenceState (rho_0, T_0, e_0, P_0, cv_0, bmod_0, dpde_0, dvdt_0);
192
198
GIVEN (" Densities and energies" ) {
193
199
constexpr int num = 4 ;
194
200
#ifdef PORTABILITY_STRATEGY_KOKKOS
@@ -271,7 +277,7 @@ SCENARIO("CarnahanStarling2", "[CarnahanStarling][CarnahanStarling2]") {
271
277
#endif // PORTABILITY_STRATEGY_KOKKOS
272
278
THEN (" The returned P(rho, e) should be equal to the true value" ) {
273
279
array_compare (num, density, energy, h_pressure, pressure_true, " Density" ,
274
- " Energy" );
280
+ " Energy" , 1e-12 * P_0 );
275
281
}
276
282
}
277
283
@@ -283,7 +289,7 @@ SCENARIO("CarnahanStarling2", "[CarnahanStarling][CarnahanStarling2]") {
283
289
#endif // PORTABILITY_STRATEGY_KOKKOS
284
290
THEN (" The returned B_S(rho, e) should be equal to the true value" ) {
285
291
array_compare (num, density, energy, h_bulkmodulus, bulkmodulus_true, " Density" ,
286
- " Energy" );
292
+ " Energy" , 1e-12 * bmod_0 );
287
293
}
288
294
}
289
295
@@ -295,7 +301,7 @@ SCENARIO("CarnahanStarling2", "[CarnahanStarling][CarnahanStarling2]") {
295
301
#endif // PORTABILITY_STRATEGY_KOKKOS
296
302
THEN (" The returned B_S(rho, e) should be equal to the true value" ) {
297
303
array_compare (num, density, energy, h_temperature, temperature_true, " Density" ,
298
- " Energy" );
304
+ " Energy" , 1e-12 * T_0 );
299
305
}
300
306
}
301
307
@@ -308,7 +314,7 @@ SCENARIO("CarnahanStarling2", "[CarnahanStarling][CarnahanStarling2]") {
308
314
#endif // PORTABILITY_STRATEGY_KOKKOS
309
315
THEN (" The returned Gamma(rho, e) should be equal to the true value" ) {
310
316
array_compare (num, density, energy, h_gruneisen, gruneisen_true, " Density" ,
311
- " Energy" );
317
+ " Energy" , 1e-12 * dpde_0 / rho_0 );
312
318
}
313
319
}
314
320
}
@@ -325,6 +331,10 @@ SCENARIO("(C-S EoS) Isentropic Bulk Modulus Analytic vs. FD",
325
331
// Create the EOS
326
332
EOS host_eos = CarnahanStarling (gm1, Cv, bb, qq);
327
333
EOS eos = host_eos.GetOnDevice ();
334
+ Real rho_0, T_0, e_0, P_0, cv_0, bmod_0, dpde_0, dvdt_0;
335
+ host_eos.ValuesAtReferenceState (rho_0, T_0, e_0, P_0, cv_0, bmod_0, dpde_0, dvdt_0);
336
+ const Real c_0 = std::sqrt (bmod_0 / rho_0);
337
+
328
338
GIVEN (" Density and energy" ) {
329
339
constexpr Real density = 1.1833012071291069e-03 ;
330
340
constexpr Real energy = 2.1407169999999998e+09 ;
@@ -337,7 +347,7 @@ SCENARIO("(C-S EoS) Isentropic Bulk Modulus Analytic vs. FD",
337
347
INFO (" Density: " << density << " Energy: " << energy
338
348
<< " Sound speed: " << sound_speed
339
349
<< " cm/s True sound speed: " << true_sound_speed << " cm/s" );
340
- REQUIRE (isClose (sound_speed, true_sound_speed, 1e-12 ));
350
+ REQUIRE (isClose (sound_speed, true_sound_speed, 1e-12 * c_0 ));
341
351
}
342
352
}
343
353
WHEN (" A finite difference approximation is used for the bulk modulus" ) {
@@ -359,7 +369,7 @@ SCENARIO("(C-S EoS) Isentropic Bulk Modulus Analytic vs. FD",
359
369
INFO (" Density: " << density << " Energy: " << energy
360
370
<< " Sound speed: " << sound_speed
361
371
<< " cm/s Approximate sound speed: " << ss_approx << " cm/s" );
362
- REQUIRE (isClose (sound_speed, ss_approx, 1e-5 ));
372
+ REQUIRE (isClose (sound_speed, ss_approx, 1e-5 * c_0 ));
363
373
}
364
374
}
365
375
}
@@ -370,12 +380,14 @@ SCENARIO("Recover Ideal Gas from C-S", "[CarnahanStarling][CarnahanStarling4]")
370
380
GIVEN (" Parameters for a CarnahanStarling EOS" ) {
371
381
constexpr Real gm1 = 0.4 ;
372
382
constexpr Real Cv = 7180000.0 ;
373
- constexpr Real bb = 0 ;
383
+ constexpr Real bb = robust::EPS () ;
374
384
constexpr Real qq = 0 ;
375
385
// Create the EOS
376
386
EOS host_eos = CarnahanStarling (gm1, Cv, bb, qq);
377
387
EOS eos = host_eos.GetOnDevice ();
378
388
EOS ideal_eos = singularity::IdealGas (gm1, Cv);
389
+ Real rho_0, T_0, e_0, P_0, cv_0, bmod_0, dpde_0, dvdt_0;
390
+ host_eos.ValuesAtReferenceState (rho_0, T_0, e_0, P_0, cv_0, bmod_0, dpde_0, dvdt_0);
379
391
GIVEN (" Densities and energies" ) {
380
392
constexpr int num = 1 ;
381
393
#ifdef PORTABILITY_STRATEGY_KOKKOS
@@ -448,7 +460,7 @@ SCENARIO("Recover Ideal Gas from C-S", "[CarnahanStarling][CarnahanStarling4]")
448
460
ideal_eos.PressureFromDensityInternalEnergy (density[i], energy[i]);
449
461
}
450
462
array_compare (num, density, energy, h_pressure, pressure_true, " Density" ,
451
- " Energy" );
463
+ " Energy" , 1e-12 * P_0 );
452
464
}
453
465
}
454
466
@@ -464,7 +476,7 @@ SCENARIO("Recover Ideal Gas from C-S", "[CarnahanStarling][CarnahanStarling4]")
464
476
ideal_eos.BulkModulusFromDensityInternalEnergy (density[i], energy[i]);
465
477
}
466
478
array_compare (num, density, energy, h_bulkmodulus, bulkmodulus_true, " Density" ,
467
- " Energy" );
479
+ " Energy" , 1e-12 * bmod_0 );
468
480
}
469
481
}
470
482
@@ -480,7 +492,7 @@ SCENARIO("Recover Ideal Gas from C-S", "[CarnahanStarling][CarnahanStarling4]")
480
492
ideal_eos.TemperatureFromDensityInternalEnergy (density[i], energy[i]);
481
493
}
482
494
array_compare (num, density, energy, h_temperature, temperature_true, " Density" ,
483
- " Energy" );
495
+ " Energy" , 1e-12 * T_0 );
484
496
}
485
497
}
486
498
@@ -497,7 +509,7 @@ SCENARIO("Recover Ideal Gas from C-S", "[CarnahanStarling][CarnahanStarling4]")
497
509
ideal_eos.GruneisenParamFromDensityInternalEnergy (density[i], energy[i]);
498
510
}
499
511
array_compare (num, density, energy, h_gruneisen, gruneisen_true, " Density" ,
500
- " Energy" );
512
+ " Energy" , 1e-12 * dpde_0 / rho_0 );
501
513
}
502
514
}
503
515
}
@@ -516,6 +528,8 @@ SCENARIO("Test C-S Entropy Calls", "[CarnahanStarling][CarnahanStarling5]") {
516
528
// Create the EOS
517
529
EOS host_eos = CarnahanStarling (gm1, Cv, bb, qq, qp, T0, P0);
518
530
EOS eos = host_eos.GetOnDevice ();
531
+ Real rho_0, T_0, e_0, P_0, cv_0, bmod_0, dpde_0, dvdt_0;
532
+ host_eos.ValuesAtReferenceState (rho_0, T_0, e_0, P_0, cv_0, bmod_0, dpde_0, dvdt_0);
519
533
GIVEN (" Densities and energies" ) {
520
534
constexpr int num = 1 ;
521
535
#ifdef PORTABILITY_STRATEGY_KOKKOS
@@ -549,7 +563,7 @@ SCENARIO("Test C-S Entropy Calls", "[CarnahanStarling][CarnahanStarling5]") {
549
563
// Gold standard values for a subset of lookups
550
564
// constexpr std::array<Real, num> temperature_true{4.0000000000000000e+03};
551
565
constexpr std::array<Real, num> entropy_true{-2.2983150752058342e+10 };
552
-
566
+ constexpr Real entropy_ref = 2.2983150752058342e+10 ;
553
567
#ifdef PORTABILITY_STRATEGY_KOKKOS
554
568
// Create device views for outputs and mirror those views on the host
555
569
Kokkos::View<Real[num]> v_temperature (" Temperature" );
@@ -582,7 +596,7 @@ SCENARIO("Test C-S Entropy Calls", "[CarnahanStarling][CarnahanStarling5]") {
582
596
#endif // PORTABILITY_STRATEGY_KOKKOS
583
597
THEN (" The returned S(rho, e) should be equal to the true value" ) {
584
598
array_compare (num, density, energy, h_entropy, entropy_true, " Density" ,
585
- " Energy" );
599
+ " Energy" , 1e-12 * entropy_ref );
586
600
}
587
601
}
588
602
WHEN (" A S(rho, T(rho,e)) lookup is performed" ) {
@@ -594,7 +608,7 @@ SCENARIO("Test C-S Entropy Calls", "[CarnahanStarling][CarnahanStarling5]") {
594
608
#endif // PORTABILITY_STRATEGY_KOKKOS
595
609
THEN (" The returned S(rho, e) should be equal to the true value" ) {
596
610
array_compare (num, density, energy, h_entropy, entropy_true, " Density" ,
597
- " Energy" );
611
+ " Energy" , 1e-12 * entropy_ref );
598
612
}
599
613
}
600
614
}
@@ -610,6 +624,8 @@ SCENARIO("CarnahanStarling6", "[CarnahanStarling][CarnahanStarling6]") {
610
624
// Create the EOS
611
625
EOS host_eos = CarnahanStarling (gm1, Cv, bb, qq);
612
626
EOS eos = host_eos.GetOnDevice ();
627
+ Real rho_0, T_0, e_0, P_0, cv_0, bmod_0, dpde_0, dvdt_0;
628
+ host_eos.ValuesAtReferenceState (rho_0, T_0, e_0, P_0, cv_0, bmod_0, dpde_0, dvdt_0);
613
629
GIVEN (" Pressure and temperature" ) {
614
630
constexpr int num = 4 ;
615
631
#ifdef PORTABILITY_STRATEGY_KOKKOS
@@ -648,8 +664,8 @@ SCENARIO("CarnahanStarling6", "[CarnahanStarling][CarnahanStarling6]") {
648
664
649
665
// Gold standard values for a subset of lookups
650
666
constexpr std::array<Real, num> density_true{
651
- 1.1833012071291069e -03 , 7.8290736890381501e -03 , 8.5453943327882340e -03 ,
652
- 8.8197619601121831e -03 };
667
+ 1.18330186346892515e -03 , 7.82907368898192423e -03 , 8.54539433271512064e -03 ,
668
+ 8.81976196003179773e -03 };
653
669
654
670
#ifdef PORTABILITY_STRATEGY_KOKKOS
655
671
// Create device views for outputs and mirror those views on the host
@@ -685,7 +701,7 @@ SCENARIO("CarnahanStarling6", "[CarnahanStarling][CarnahanStarling6]") {
685
701
686
702
THEN (" The returned rho(P, T) should be equal to the true value" ) {
687
703
array_compare (num, pressure, temperature, h_density, density_true, " Pressure" ,
688
- " Temperature" );
704
+ " Temperature" , 1e-7 * rho_0 );
689
705
}
690
706
}
691
707
}
0 commit comments