@@ -915,6 +915,11 @@ void StructuredMesh::raytrace_mesh(
915915 if (total_distance == 0.0 && settings::solver_type != SolverType::RANDOM_RAY)
916916 return ;
917917
918+ // keep a copy of the original global position to pass to get_indices,
919+ // which performs its own transformation to local coordinates
920+ Position global_r = r0;
921+ Position local_r = local_coords (r0);
922+
918923 const int n = n_dimension_;
919924
920925 // Flag if position is inside the mesh
@@ -925,7 +930,7 @@ void StructuredMesh::raytrace_mesh(
925930
926931 // Calculate index of current cell. Offset the position a tiny bit in
927932 // direction of flight
928- MeshIndex ijk = get_indices (r0 + TINY_BIT * u, in_mesh);
933+ MeshIndex ijk = get_indices (global_r + TINY_BIT * u, in_mesh);
929934
930935 // if track is very short, assume that it is completely inside one cell.
931936 // Only the current cell will score and no surfaces
@@ -936,16 +941,10 @@ void StructuredMesh::raytrace_mesh(
936941 return ;
937942 }
938943
939- // translate start and end positions,
940- // this needs to come after the get_indices call because it does its own
941- // translation
942- local_coords (r0);
943- local_coords (r1);
944-
945944 // Calculate initial distances to next surfaces in all three dimensions
946945 std::array<MeshDistance, 3 > distances;
947946 for (int k = 0 ; k < n; ++k) {
948- distances[k] = distance_to_grid_boundary (ijk, k, r0 , u, 0.0 );
947+ distances[k] = distance_to_grid_boundary (ijk, k, local_r , u, 0.0 );
949948 }
950949
951950 // Loop until r = r1 is eventually reached
@@ -975,7 +974,7 @@ void StructuredMesh::raytrace_mesh(
975974 // The two other directions are still valid!
976975 ijk[k] = distances[k].next_index ;
977976 distances[k] =
978- distance_to_grid_boundary (ijk, k, r0 , u, traveled_distance);
977+ distance_to_grid_boundary (ijk, k, local_r , u, traveled_distance);
979978
980979 // Check if we have left the interior of the mesh
981980 in_mesh = ((ijk[k] >= 1 ) && (ijk[k] <= shape_[k]));
@@ -1005,10 +1004,10 @@ void StructuredMesh::raytrace_mesh(
10051004
10061005 // Calculate the new cell index and update all distances to next
10071006 // surfaces.
1008- ijk = get_indices (r0 + (traveled_distance + TINY_BIT) * u, in_mesh);
1007+ ijk = get_indices (global_r + (traveled_distance + TINY_BIT) * u, in_mesh);
10091008 for (int k = 0 ; k < n; ++k) {
10101009 distances[k] =
1011- distance_to_grid_boundary (ijk, k, r0 , u, traveled_distance);
1010+ distance_to_grid_boundary (ijk, k, local_r , u, traveled_distance);
10121011 }
10131012
10141013 // If inside the mesh, Tally inward current
@@ -1482,7 +1481,7 @@ std::string CylindricalMesh::get_mesh_type() const
14821481StructuredMesh::MeshIndex CylindricalMesh::get_indices (
14831482 Position r, bool & in_mesh) const
14841483{
1485- local_coords (r);
1484+ r = local_coords (r);
14861485
14871486 Position mapped_r;
14881487 mapped_r[0 ] = std::hypot (r.x , r.y );
@@ -1630,23 +1629,21 @@ StructuredMesh::MeshDistance CylindricalMesh::distance_to_grid_boundary(
16301629 const MeshIndex& ijk, int i, const Position& r0, const Direction& u,
16311630 double l) const
16321631{
1633- Position r = r0 - origin_;
1634-
16351632 if (i == 0 ) {
16361633
16371634 return std::min (
1638- MeshDistance (ijk[i] + 1 , true , find_r_crossing (r , u, l, ijk[i])),
1639- MeshDistance (ijk[i] - 1 , false , find_r_crossing (r , u, l, ijk[i] - 1 )));
1635+ MeshDistance (ijk[i] + 1 , true , find_r_crossing (r0 , u, l, ijk[i])),
1636+ MeshDistance (ijk[i] - 1 , false , find_r_crossing (r0 , u, l, ijk[i] - 1 )));
16401637
16411638 } else if (i == 1 ) {
16421639
16431640 return std::min (MeshDistance (sanitize_phi (ijk[i] + 1 ), true ,
1644- find_phi_crossing (r , u, l, ijk[i])),
1641+ find_phi_crossing (r0 , u, l, ijk[i])),
16451642 MeshDistance (sanitize_phi (ijk[i] - 1 ), false ,
1646- find_phi_crossing (r , u, l, ijk[i] - 1 )));
1643+ find_phi_crossing (r0 , u, l, ijk[i] - 1 )));
16471644
16481645 } else {
1649- return find_z_crossing (r , u, l, ijk[i]);
1646+ return find_z_crossing (r0 , u, l, ijk[i]);
16501647 }
16511648}
16521649
@@ -1762,7 +1759,7 @@ std::string SphericalMesh::get_mesh_type() const
17621759StructuredMesh::MeshIndex SphericalMesh::get_indices (
17631760 Position r, bool & in_mesh) const
17641761{
1765- local_coords (r);
1762+ r = local_coords (r);
17661763
17671764 Position mapped_r;
17681765 mapped_r[0 ] = r.norm ();
0 commit comments