Chi-Tech
raytracing.h
Go to the documentation of this file.
1#ifndef CHI_MESH_RAYTRACING_H
2#define CHI_MESH_RAYTRACING_H
3
4#include "../chi_mesh.h"
5
6namespace chi_mesh
7{
8/**Data structure to hold output info from the raytracer.*/
10{
11 double distance_to_surface = 0.0;
13 unsigned int destination_face_index = 0;
15 bool particle_lost = false;
16 std::string lost_particle_info;
17};
18
19//###################################################################
20/**Raytracer object.*/
22{
23private:
25 std::vector<double> cell_sizes_;
26 double epsilon_nudge_ = 1.0e-8;
27 double backward_tolerance_ = 1.0e-10;
28 double extension_distance_ = 1.0e5;
30
31public:
32 explicit
34 std::vector<double> in_cell_sizes,
35 bool in_perform_concavity_checks = true) :
36 reference_grid_(grid),
37 cell_sizes_(std::move(in_cell_sizes)),
38 perform_concavity_checks_(in_perform_concavity_checks)
39 {}
40
41private:
42 const chi_mesh::MeshContinuum& Grid() const;
43
44 void SetTolerancesFromCellSize(double cell_size)
45 {
46 epsilon_nudge_ = cell_size * 1.0e-2;
47 backward_tolerance_ = cell_size * 1.0e-10;
48 extension_distance_ = 3.0 * cell_size;
49 }
50
51public:
52 /**Traces a ray with an initial position either within the cell or
53 * on the cell surface, and with a direction vector pointing inward
54 * toward the cell. If the ray-trace fails the particle will be marked
55 * as lost.*/
57 TraceRay(const Cell& cell,
58 Vector3& pos_i,
59 Vector3& omega_i,
60 int function_depth=0);
61
62 /**Traces a ray with an initial position, presumed to be outside the cell,
63 * to an incident face.*/
65 TraceIncidentRay(const Cell& cell,
66 const Vector3& pos_i,
67 const Vector3& omega_i);
68
69private:
70 void TraceSlab(const Cell& cell,
71 Vector3& pos_i,
72 Vector3& omega_i,
73 bool& intersection_found,
74 bool& backward_tolerance_hit,
76 void TracePolygon(const Cell& cell,
77 Vector3& pos_i,
78 Vector3& omega_i,
79 bool& intersection_found,
80 bool& backward_tolerance_hit,
82 void TracePolyhedron(const Cell& cell,
83 Vector3& pos_i,
84 Vector3& omega_i,
85 bool& intersection_found,
86 bool& backward_tolerance_hit,
88};
89
90bool
92 const chi_mesh::Vector3& plane_point,
93 const chi_mesh::Vector3& line_point_0,
94 const chi_mesh::Vector3& line_point_1,
95 chi_mesh::Vector3& intersection_point,
96 std::pair<double,double>* weights=nullptr);
97
98bool
100 const chi_mesh::Vector3& strip_point0,
101 const chi_mesh::Vector3& strip_point1,
102 const chi_mesh::Vector3& strip_normal,
103 const chi_mesh::Vector3& line_point0,
104 const chi_mesh::Vector3& line_point1,
105 chi_mesh::Vector3& intersection_point,
106 double* distance_to_intersection = nullptr);
107
108bool
110 const chi_mesh::Vector3& tri_point0,
111 const chi_mesh::Vector3& tri_point1,
112 const chi_mesh::Vector3& tri_point2,
113 const chi_mesh::Vector3& ray_posi,
114 const chi_mesh::Vector3& ray_dir,
115 chi_mesh::Vector3& intersection_point,
116 double* distance_to_intersection = nullptr);
117
118bool
120 const chi_mesh::Vector3& v1,
121 const chi_mesh::Vector3& v2,
122 const chi_mesh::Normal& n,
123 const chi_mesh::Vector3& point);
124
125bool
126CheckPlaneTetIntersect(const chi_mesh::Normal& plane_normal,
127 const chi_mesh::Vector3& plane_point,
128 const std::vector<chi_mesh::Vector3>& tet_points);
129
131 const chi_mesh::MeshContinuum& grid,
132 const Cell& cell,
133 const chi_mesh::Vector3& line_point0,
134 const chi_mesh::Vector3& line_point1,
135 const chi_mesh::Vector3& omega,
136 std::vector<double> &segment_lengths);
137
138
139
140}
141#endif
void SetTolerancesFromCellSize(double cell_size)
Definition: raytracing.h:44
const chi_mesh::MeshContinuum & reference_grid_
Definition: raytracing.h:24
RayTracerOutputInformation TraceRay(const Cell &cell, Vector3 &pos_i, Vector3 &omega_i, int function_depth=0)
Definition: raytracer.cc:14
bool perform_concavity_checks_
Definition: raytracing.h:29
std::vector< double > cell_sizes_
Definition: raytracing.h:25
double extension_distance_
Definition: raytracing.h:28
void TraceSlab(const Cell &cell, Vector3 &pos_i, Vector3 &omega_i, bool &intersection_found, bool &backward_tolerance_hit, RayTracerOutputInformation &oi)
void TracePolyhedron(const Cell &cell, Vector3 &pos_i, Vector3 &omega_i, bool &intersection_found, bool &backward_tolerance_hit, RayTracerOutputInformation &oi)
RayTracerOutputInformation TraceIncidentRay(const Cell &cell, const Vector3 &pos_i, const Vector3 &omega_i)
Definition: raytracer.cc:135
double backward_tolerance_
Definition: raytracing.h:27
void TracePolygon(const Cell &cell, Vector3 &pos_i, Vector3 &omega_i, bool &intersection_found, bool &backward_tolerance_hit, RayTracerOutputInformation &oi)
const chi_mesh::MeshContinuum & Grid() const
Definition: raytracer.cc:7
RayTracer(const chi_mesh::MeshContinuum &grid, std::vector< double > in_cell_sizes, bool in_perform_concavity_checks=true)
Definition: raytracing.h:33
bool CheckPlaneTetIntersect(const chi_mesh::Normal &plane_normal, const chi_mesh::Vector3 &plane_point, const std::vector< chi_mesh::Vector3 > &tet_points)
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)
void PopulateRaySegmentLengths(const chi_mesh::MeshContinuum &grid, const Cell &cell, const chi_mesh::Vector3 &line_point0, const chi_mesh::Vector3 &line_point1, const chi_mesh::Vector3 &omega, std::vector< double > &segment_lengths)
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)
bool CheckPointInTriangle(const chi_mesh::Vector3 &v0, const chi_mesh::Vector3 &v1, const chi_mesh::Vector3 &v2, const chi_mesh::Normal &n, const chi_mesh::Vector3 &point)