| 1 |
//---------------------------------------------------------------------------// |
| 2 |
// tstRay_Tracer.cc |
| 3 |
//---------------------------------------------------------------------------// |
| 4 |
|
| 5 |
#include <cmath> |
| 6 |
#include <iostream> |
| 7 |
#include "Ray_Tracer.hh" |
| 8 |
|
| 9 |
using namespace std; |
| 10 |
|
| 11 |
typedef tribits_mixed::Ray_Tracer Tracer; |
| 12 |
typedef Tracer::Vec_Dbl Vec_Dbl; |
| 13 |
typedef Tracer::Space_Vector Space_Vector; |
| 14 |
|
| 15 |
int nfail; |
| 16 |
int npass; |
| 17 |
|
| 18 |
#define UNIT_TEST(a) if (!(a)){ ++nfail; } else { ++npass; } |
| 19 |
|
| 20 |
//---------------------------------------------------------------------------// |
| 21 |
|
| 22 |
void test_tracing() |
| 23 |
{ |
| 24 |
// make simple mesh 5x5x5 |
| 25 |
Vec_Dbl x(6, 0.0), y(6, 0.0), z(6, 0.0); |
| 26 |
double dx = 0.1, dy = 0.15, dz = 0.05; |
| 27 |
for (int n = 1; n < 6; ++n) |
| 28 |
{ |
| 29 |
x[n] = x[n-1] + dx; |
| 30 |
y[n] = y[n-1] + dy; |
| 31 |
z[n] = z[n-1] + dz; |
| 32 |
} |
| 33 |
|
| 34 |
// interaction probabilities (cross sections) |
| 35 |
int N = 125; |
| 36 |
Vec_Dbl sigma(N, 1.1); |
| 37 |
|
| 38 |
// make the ray tracer |
| 39 |
Tracer t(x, y, z, sigma); |
| 40 |
|
| 41 |
// starting point |
| 42 |
Space_Vector b(0.12, 0.44, 0.21); |
| 43 |
Space_Vector e(0.43, 0.11, 0.08); |
| 44 |
|
| 45 |
double tau = t.ray_trace(b, e); |
| 46 |
double ref = 0.47106262853255509 * 1.1; |
| 47 |
|
| 48 |
UNIT_TEST(fabs(tau - ref) < 1.0e-12 * ref); |
| 49 |
} |
| 50 |
|
| 51 |
//---------------------------------------------------------------------------// |
| 52 |
|
| 53 |
int main(int argc, char *argv[]) |
| 54 |
{ |
| 55 |
nfail = 0; |
| 56 |
npass = 0; |
| 57 |
|
| 58 |
test_tracing(); |
| 59 |
|
| 60 |
cout << "Number of passing tests: " << npass << endl; |
| 61 |
cout << "Number of failing tests: " << nfail << endl; |
| 62 |
|
| 63 |
if (nfail == 0) |
| 64 |
{ |
| 65 |
cout << "End Result: TEST PASSED" << endl; |
| 66 |
} |
| 67 |
else |
| 68 |
{ |
| 69 |
cout << "End Result: TEST FAILED" << endl; |
| 70 |
return 1; |
| 71 |
} |
| 72 |
|
| 73 |
return 0; |
| 74 |
} |
| 75 |
|
| 76 |
//---------------------------------------------------------------------------// |
| 77 |
// end of tstRay_Tracer.cc |
| 78 |
//---------------------------------------------------------------------------// |
| 79 |
|