Debian Codegraph @

cmake/tribits/examples/TribitsExampleProject/packages/mixed_lang/src/Ray_Tracer.cc

raw
1 //---------------------------------------------------------------------------//
2 // Ray_Tracer.cc
3 //---------------------------------------------------------------------------//
4
5 #include <cmath>
6 #include <algorithm>
7 #include <numeric>
8
9 #include "MixedLang_config.h"
10 #include "Ray_Tracer.hh"
11
12 //---------------------------------------------------------------------------//
13 // Prototypes for FORTRAN function kernels.
14 //---------------------------------------------------------------------------//
15
16 #define BLOCK_TRACER FC_FUNC(block_tracer, BLOCK_TRACER)
17 #define SETUP_RAY_TRACING FC_FUNC(setup_ray_tracing, SETUP_RAY_TRACING)
18 #define CLEANUP_RAY_TRACING FC_FUNC(cleanup_ray_tracing, CLEANUP_RAY_TRACING)
19 #define SET_DIMENSIONS FC_FUNC(set_dimensions, SET_DIMENSIONS)
20
21 extern "C"
22 {
23
24 void BLOCK_TRACER(const double *x, const double *y, const double *z,
25 const double *sigma, double *pos, const double *end,
26 int *ijk, double *tau, int *terminator);
27
28 void SETUP_RAY_TRACING();
29
30 void CLEANUP_RAY_TRACING();
31
32 void SET_DIMENSIONS(int *im, int *jm, int *km);
33 }
34
35 namespace tribits_mixed
36 {
37
38 //---------------------------------------------------------------------------//
39 // CONSTRUCTOR AND DESTRUCTOR
40 //---------------------------------------------------------------------------//
41
42 Ray_Tracer::Ray_Tracer(const Vec_Dbl &x,
43 const Vec_Dbl &y,
44 const Vec_Dbl &z,
45 const Vec_Dbl &sigma)
46 : d_x(x)
47 , d_y(y)
48 , d_z(z)
49 , d_sigma(sigma)
50 {
51 // set the dimensions
52 int i = d_x.size() - 1;
53 int j = d_y.size() - 1;
54 int k = d_z.size() - 1;
55 SET_DIMENSIONS(&i, &j, &k);
56
57 // setup the ray-tracer
58 SETUP_RAY_TRACING();
59 }
60
61 //---------------------------------------------------------------------------//
62
63 Ray_Tracer::~Ray_Tracer()
64 {
65 CLEANUP_RAY_TRACING();
66 }
67
68 //---------------------------------------------------------------------------//
69 // PUBLIC FUNCTIONS
70 //---------------------------------------------------------------------------//
71
72 double Ray_Tracer::ray_trace(const Space_Vector &begin,
73 const Space_Vector &end)
74 {
75 // make a ray
76 Ray ray;
77 ray.p = begin;
78
79 // calculate index of ray
80 int i,j,k;
81 Vec_Dbl::const_iterator ijk;
82
83 // x
84 ijk = std::lower_bound(d_x.begin(), d_x.end(), ray.p[0]);
85 i = ijk - d_x.begin() - 1;
86
87 // y
88 ijk = std::lower_bound(d_y.begin(), d_y.end(), ray.p[1]);
89 j = ijk - d_y.begin() - 1;
90
91 // z
92 ijk = std::lower_bound(d_z.begin(), d_z.end(), ray.p[2]);
93 k = ijk - d_z.begin() - 1;
94
95 ray.index[0] = i;
96 ray.index[1] = j;
97 ray.index[2] = k;
98
99 // reset the tau
100 ray.tau = 0.0;
101
102 // termination condition
103 int terminator = 0;
104
105 // trace through the block using the FORTRAN kernel
106 BLOCK_TRACER(&d_x[0], &d_y[0], &d_z[0], &d_sigma[0], &ray.p[0], &end[0],
107 &ray.index[0], &ray.tau, &terminator);
108
109 // add up tau
110 return ray.tau;
111 }
112
113 } // namespace tribits_mixed
114
115 //---------------------------------------------------------------------------//
116 // end of Ray_Tracer.cc
117 //---------------------------------------------------------------------------//
118