19 if (not cell_sizes_.empty())
20 SetTolerancesFromCellSize(cell_sizes_[cell.
local_id_]);
24 bool intersection_found =
false;
25 bool backward_tolerance_hit =
false;
28 TraceSlab(cell, pos_i, omega_i,
30 backward_tolerance_hit,
33 TracePolygon(cell, pos_i, omega_i,
35 backward_tolerance_hit,
38 TracePolyhedron(cell, pos_i, omega_i,
40 backward_tolerance_hit,
43 throw std::logic_error(
"Unsupported cell type encountered in call to "
44 "chi_mesh::RayTrace.");
46 if (!intersection_found)
48 if (function_depth < 5)
54 oi = TraceRay(cell,pos_i_nudged,omega_i,function_depth+1);
59 if (function_depth < 7)
65 oi = TraceRay(cell,pos_i_nudged,omega_i,function_depth+1);
71 std::stringstream outstr;
74 <<
"Intersection not found at function level " << function_depth <<
"."
75 << ((backward_tolerance_hit)?
" Backward tolerance hit. " :
"")
76 <<
"For particle xyz="
77 << pos_i.
PrintS() <<
" uvw="
78 << omega_i.
PrintS() <<
" " << (pos_i + extension_distance_ * omega_i).PrintS()
79 <<
" " << extension_distance_
81 <<
" with vertices: \n";
83 const auto& grid = Grid();
86 outstr << grid.vertices[vi].PrintS() <<
"\n";
88 for (
auto& face : cell.
faces_)
90 outstr <<
"Face with centroid: " << face.centroid_.PrintS() <<
" ";
91 outstr <<
"n=" << face.normal_.PrintS() <<
"\n";
92 for (
auto vi : face.vertex_ids_)
93 outstr << grid.vertices[vi].PrintS() <<
"\n";
99 auto& v = grid.vertices[vid];
100 outstr <<
"v " << v.x <<
" " << v.y <<
" " << v.z <<
"\n";
103 for (
auto& face : cell.
faces_)
105 auto& v = face.centroid_;
106 outstr <<
"v " << v.x <<
" " << v.y <<
" " << v.z <<
"\n";
109 for (
size_t f=0; f < cell.
faces_.size(); ++f)
111 auto& face = cell.
faces_[f];
113 for (
auto vid : face.vertex_ids_)
115 size_t ref_cell_id=0;
116 for (
size_t cid=0; cid < cell.
vertex_ids_.size(); ++cid)
118 ref_cell_id = cid + 1;
120 outstr << ref_cell_id <<
"// ";
139 const auto cell_type = cell.
Type();
140 const double cell_char_length = cell_sizes_[cell.
local_id_];
141 const auto& grid = reference_grid_;
143 bool intersects_cell =
false;
147 for (
const auto& face : cell.
faces_)
149 if (face.normal_.Dot(omega_i) > 0.0) { ++f;
continue; }
151 const auto& p0 = grid.vertices[face.vertex_ids_[0]];
152 const auto& n = face.normal_;
154 const auto ppos_i = p0 - pos_i;
155 const double d = ppos_i.
Dot(omega_i);
157 const auto pos_ext = pos_i + (d + cell_char_length)*omega_i;
167 const auto& p1 = grid.vertices[face.vertex_ids_[1]];
172 const auto& vids = face.vertex_ids_;
173 const size_t num_sides = face.vertex_ids_.size();
174 for (
size_t s=0; s<num_sides; ++s)
176 uint64_t v0i = vids[s];
177 uint64_t v1i = (s < (num_sides-1))? vids[s+1] : vids[0];
179 const auto& v0 = grid.vertices[v0i];
180 const auto& v1 = grid.vertices[v1i];
181 const auto& v2 = face.centroid_;
184 const auto v01 = v1 - v0;
185 const auto v02 = v2 - v0;
186 const auto n_est = v01.Cross(v02);
188 if (n_est.Dot(omega_i) > 0.0)
continue;
192 if (intersects_cell)
break;
196 if (intersects_cell)
break;
std::vector< CellFace > faces_
std::vector< uint64_t > vertex_ids_
const chi_mesh::MeshContinuum & reference_grid_
RayTracerOutputInformation TraceRay(const Cell &cell, Vector3 &pos_i, Vector3 &omega_i, int function_depth=0)
RayTracerOutputInformation TraceIncidentRay(const Cell &cell, const Vector3 &pos_i, const Vector3 &omega_i)
const chi_mesh::MeshContinuum & Grid() const
bool CheckLineIntersectTriangle2(const chi_mesh::Vector3 &tri_point0, const chi_mesh::Vector3 &tri_point1, const chi_mesh::Vector3 &tri_point2, const chi_mesh::Vector3 &ray_posi, const chi_mesh::Vector3 &ray_dir, chi_mesh::Vector3 &intersection_point, double *distance_to_intersection=nullptr)
bool CheckPlaneLineIntersect(const chi_mesh::Normal &plane_normal, const chi_mesh::Vector3 &plane_point, const chi_mesh::Vector3 &line_point_0, const chi_mesh::Vector3 &line_point_1, chi_mesh::Vector3 &intersection_point, std::pair< double, double > *weights=nullptr)
bool CheckLineIntersectStrip(const chi_mesh::Vector3 &strip_point0, const chi_mesh::Vector3 &strip_point1, const chi_mesh::Vector3 &strip_normal, const chi_mesh::Vector3 &line_point0, const chi_mesh::Vector3 &line_point1, chi_mesh::Vector3 &intersection_point, double *distance_to_intersection=nullptr)
std::string PrintS() const
Vector3 Dot(const chi_mesh::TensorRank2Dim3 &that) const