@@ -235,7 +235,7 @@ namespace
235235 atomicAdd (&camera_count[ij_cam], weight * trans_sun);
236236 }
237237 atomicAdd (&camera_shot[ij_cam], Float (1 .));
238-
238+
239239 }
240240
241241 __device__
@@ -298,19 +298,23 @@ void ray_tracer_kernel_bw(
298298 const Float* __restrict__ mie_ang,
299299 const Float* __restrict__ mie_phase,
300300 const Float* __restrict__ mie_phase_ang,
301- const int mie_table_size)
301+ const int mie_cdf_table_size,
302+ const int mie_phase_table_size)
302303{
303304 extern __shared__ Float shared_arrays[];
304305 Float* mie_cdf_shared = &shared_arrays[0 ];
305- Float* mie_phase_ang_shared = &shared_arrays[mie_table_size ];
306- Float* bg_tau_cum = &shared_arrays[2 *mie_table_size ];
306+ Float* mie_phase_ang_shared = &shared_arrays[mie_cdf_table_size ];
307+ Float* bg_tau_cum = &shared_arrays[mie_phase_table_size+mie_cdf_table_size ];
307308 if (threadIdx .x ==0 )
308309 {
309- if (mie_table_size > 0 )
310+ if (mie_cdf_table_size > 0 )
310311 {
311- for (int mie_i=0 ; mie_i<mie_table_size ; ++mie_i)
312+ for (int mie_i=0 ; mie_i<mie_cdf_table_size ; ++mie_i)
312313 {
313314 mie_cdf_shared[mie_i] = mie_cdf[mie_i];
315+ }
316+ for (int mie_i=0 ; mie_i<mie_phase_table_size; ++mie_i)
317+ {
314318 mie_phase_ang_shared[mie_i] = mie_phase_ang[mie_i];
315319 }
316320 }
@@ -324,11 +328,11 @@ void ray_tracer_kernel_bw(
324328 }
325329
326330 __syncthreads ();
327-
331+
328332 Vector<Float> surface_normal = {0 , 0 , 1 };
329-
333+
330334 const int n = blockDim .x * blockIdx .x + threadIdx .x ;
331-
335+
332336 const Float bg_transmissivity = exp (-bg_tau_cum[0 ]);
333337
334338 const Vector<Float> kn_grid_d = grid_size / kn_grid;
@@ -338,7 +342,7 @@ void ray_tracer_kernel_bw(
338342
339343 const Float s_min = max (max (grid_size.z , grid_size.x ), grid_size.y ) * Float_epsilon;
340344 const Float s_min_bg = max (max (grid_size.x , grid_size.y ), z_top) * Float_epsilon;
341-
345+
342346 while (counter[0 ] < camera.npix *photons_per_pixel)
343347 {
344348 const Int count = atomicAdd (&counter[0 ], 1 );
@@ -677,19 +681,19 @@ void ray_tracer_kernel_bw(
677681 break ;
678682 }
679683 const Float cos_scat = scatter_type == 0 ? rayleigh (rng ()) : // gases -> rayleigh,
680- 1 ? ( (mie_table_size > 0 ) // clouds: Mie or HG
681- ? cos ( mie_sample_angle (mie_cdf_shared, mie_ang, rng (), r_eff[ijk], mie_table_size ) )
684+ 1 ? ( (mie_cdf_table_size > 0 ) // clouds: Mie or HG
685+ ? cos ( mie_sample_angle (mie_cdf_shared, mie_ang, rng (), r_eff[ijk], mie_cdf_table_size ) )
682686 : henyey (g, rng ()))
683687 : henyey (g, rng ()); // aerosols
684688 const Float sin_scat = max (Float (0 .), sqrt (Float (1 .) - cos_scat*cos_scat + Float_epsilon));
685689
686690 // SUN SCATTERING GOES HERE
687691 const Phase_kind kind = scatter_type == 0 ? Phase_kind::Rayleigh :
688- 1 ? (mie_table_size > 0 )
692+ 1 ? (mie_phase_table_size > 0 )
689693 ? Phase_kind::Mie
690694 : Phase_kind::HG
691695 : Phase_kind::HG;
692- const Float p_sun = probability_from_sun (photon, sun_direction, sun_solid_angle, g, mie_phase_ang_shared, mie_phase, r_eff[ijk], mie_table_size ,
696+ const Float p_sun = probability_from_sun (photon, sun_direction, sun_solid_angle, g, mie_phase_ang_shared, mie_phase, r_eff[ijk], mie_phase_table_size ,
693697 surface_normal, kind);
694698 const Float trans_sun = transmission_direct_sun (photon,n,rng,sun_direction,
695699 k_null_grid,k_ext,
@@ -736,23 +740,23 @@ void ray_tracer_kernel_bw(
736740}
737741 __global__
738742 void accumulate_clouds_kernel (
739- const Float* __restrict__ lwp,
740- const Float* __restrict__ iwp,
741- const Float* __restrict__ tau_cloud,
743+ const Float* __restrict__ lwp,
744+ const Float* __restrict__ iwp,
745+ const Float* __restrict__ tau_cloud,
742746 const Vector<Float> grid_d,
743747 const Vector<Float> grid_size,
744748 const Vector<int > grid_cells,
745- Float* __restrict__ liwp_cam,
746- Float* __restrict__ tauc_cam,
747- Float* __restrict__ dist_cam,
748- Float* __restrict__ zen_cam,
749+ Float* __restrict__ liwp_cam,
750+ Float* __restrict__ tauc_cam,
751+ Float* __restrict__ dist_cam,
752+ Float* __restrict__ zen_cam,
749753 const Camera camera)
750754 {
751755 const int pix = blockDim .x * blockIdx .x + threadIdx .x ;
752756 const Float s_eps = max (max (grid_size.z , grid_size.x ), grid_size.y ) * Float_epsilon;
753- Vector<Float> direction;
757+ Vector<Float> direction;
754758 Vector<Float> position;
755-
759+
756760 if (pix < camera.nx * camera.ny )
757761 {
758762 Float liwp_sum = 0 ;
@@ -778,13 +782,13 @@ void ray_tracer_kernel_bw(
778782 {
779783 direction = normalize (camera.cam_width * (Float (2 .)*i-Float (1.0 )) + camera.cam_height * (Float (2 .)*j-Float (1.0 )) + camera.cam_depth );
780784 }
781-
785+
782786 // first bring photon to top of dynamical domain
783787 if ((position.z >= (grid_size.z - s_eps)) && (direction.z < Float (0 .)))
784788 {
785789 const Float s = abs ((position.z - grid_size.z )/direction.z );
786790 position = position + direction * s - s_eps;
787-
791+
788792 // Cyclic boundary condition in x.
789793 position.x = fmod (position.x , grid_size.x );
790794 if (position.x < Float (0 .))
@@ -802,26 +806,26 @@ void ray_tracer_kernel_bw(
802806 const int j = float_to_int (position.y , grid_d.y , grid_cells.y );
803807 const int k = float_to_int (position.z , grid_d.z , grid_cells.z );
804808 const int ijk = i + j*grid_cells.x + k*grid_cells.x *grid_cells.y ;
805-
809+
806810 const Float sx = abs ((direction.x > 0 ) ? ((i+1 ) * grid_d.x - position.x )/direction.x : (i*grid_d.x - position.x )/direction.x );
807811 const Float sy = abs ((direction.y > 0 ) ? ((j+1 ) * grid_d.y - position.y )/direction.y : (j*grid_d.y - position.y )/direction.y );
808812 const Float sz = abs ((direction.z > 0 ) ? ((k+1 ) * grid_d.z - position.z )/direction.z : (k*grid_d.z - position.z )/direction.z );
809813 const Float s_min = min (sx, min (sy, sz));
810-
814+
811815 liwp_sum += s_min * (lwp[ijk] + iwp[ijk]);
812816 tauc_sum += s_min * tau_cloud[ijk];
813817 if (!reached_cloud)
814818 {
815819 dist += s_min;
816820 reached_cloud = tau_cloud[ijk] > 0 ;
817821 }
818-
822+
819823 position = position + direction * s_min;
820824
821825 position.x += direction.x >= 0 ? s_eps : -s_eps;
822826 position.y += direction.y >= 0 ? s_eps : -s_eps;
823827 position.z += direction.z >= 0 ? s_eps : -s_eps;
824-
828+
825829 // Cyclic boundary condition in x.
826830 position.x = fmod (position.x , grid_size.x );
827831 if (position.x < Float (0 .))
@@ -833,7 +837,7 @@ void ray_tracer_kernel_bw(
833837 position.y += grid_size.y ;
834838
835839 }
836-
840+
837841 // divide out initial layer thicknes, equivalent to first converting lwp (g/m2) to lwc (g/m3) or optical depth to k_ext(1/m)
838842 liwp_cam[pix] = liwp_sum / grid_d.z ;
839843 tauc_cam[pix] = tauc_sum / grid_d.z ;
0 commit comments