28 void (*local_kernel)(T*, T*, T*, T*, T*);
43 unsigned long num_particles;
82 std::vector<trajectory<T>>
simulate();
92 std::vector<trajectory<T>>
import_data(std::string filename);
141 this->surface = surface;
143 this->local_kernel = local_kernel;
144 this->incident_velocity = incident_velocity;
145 this->num_particles = num_particles;
146 this->sim_name = sim_name;
153 Matrix<T> unit_incident = this->incident_velocity / this->incident_velocity.
norm() * (-1.0);
155 T theta_i = std::acos(- this->incident_velocity(2, 0) / this->incident_velocity.
norm());
158 bool collided =
true;
159 unsigned int collision_index;
161 std::vector<trajectory<T>> trajectories;
163 std::random_device rd;
164 std::seed_seq fullSeed{rd(), rd(), rd(), rd(), rd(), rd(), rd(), rd(), rd(), rd()};
165 std::mt19937 rng(fullSeed);
166 std::uniform_real_distribution<T> uniformDist(0.0f, 1.0f);
167 std::normal_distribution<T> normDist(0.0f, 1.0f);
169 T offset_size = 15.0;
171 for(
long i = 0; i < this->num_particles; i ++) {
173 std::vector<Matrix<T>> p_positions;
174 std::vector<Matrix<T>> p_velocities;
181 T rotation_angle = uniformDist(rng) * 2.0 * M_PI;
185 Matrix<T> origin = unit_incident / std::cos(theta_i) * 100.0;
186 Matrix<T> offset(3, 1, {2.0 * (uniformDist(rng) - 0.5) * offset_size, 2.0 * (uniformDist(rng) - 0.5) * offset_size, 0.0});
188 Ray<T> ray(origin, incident_velocity, m_dot, 1, -1);
191 std::vector<Ray<T>> new_rays = ray.
propagate(this->surface.
get_geometry(), this->gas, this->local_kernel, &collision_index);
192 if(new_rays.size() == 0) {
196 ray = new_rays.back();
212 std::ofstream myfile;
213 myfile.open(filename);
215 unsigned long num_particles = trajectories.size();
217 for(
auto i = 0; i < num_particles; i ++) {
220 unsigned long num_bounces = p_trajectory.positions.size();
222 myfile << num_bounces <<
"\n";
224 for(
auto j = 0; j < 3; j ++) {
225 for(
auto k = 0; k < num_bounces; k ++) {
226 myfile << p_trajectory.positions[k](j, 0) <<
" ";
231 for(
auto j = 0; j < 3; j ++) {
232 for(
auto k = 0; k < num_bounces; k ++) {
233 myfile << p_trajectory.velocities[k](j, 0) <<
" ";
246 std::ifstream linecounter(filename);
248 std::vector<trajectory<T>> trajectories;
252 while( std::getline(linecounter, line)) {
256 long num_particles = num_lines / 7;
259 std::ifstream myfile(filename);
261 for(
long i = 0; i < num_particles; i ++) {
263 myfile >> num_bounces;
266 std::vector<Matrix<T>> p_positions(num_bounces,
Matrix<T>(3, 1));
267 std::vector<Matrix<T>> p_velocities(num_bounces,
Matrix<T>(3, 1));
269 for(
long k = 0; k < 3; k ++) {
270 for(
long j = 0; j < num_bounces; j ++) {
271 myfile >> p_positions[j](k, 0);
274 for(
long k = 0; k < 3; k ++) {
275 for(
long j = 0; j < num_bounces; j ++) {
276 myfile >> p_velocities[j](k, 0);
289 std::vector<trajectory<T>> trajectories_total;
291 for(
long i = 0; i < num_procs; i ++) {
292 std::vector<trajectory<T>> trajectories = import_data(filename +
"_" + std::to_string(i) +
".dat");
293 trajectories_total.insert(trajectories_total.end(), trajectories.begin(), trajectories.end());
294 std::remove((filename +
"_" + std::to_string(i) +
".dat").c_str());
296 save(trajectories_total, filename +
".dat");
Class representing a Gas with properties such as density, temperature, molar mass,...
Definition Gas.h:10
This class implements a matrix object used for linear algebra and vectorized operations.
Definition Matrix.h:25
T norm()
Calculates the Frobenius norm of the matrix.
Definition Matrix.h:674
Class representing a Ray for simulating particle movement in a geometric domain.
Definition Ray.h:10
Matrix< T > & get_velocity()
Gets the velocity of the ray.
Definition Ray.h:91
std::vector< Ray< T > > propagate(Geometry< T > &geometry, const Gas< T > &gas, void(*kernel)(T *, T *, T *, T *, T *), unsigned int *collision_index)
Propagates the ray through the geometry and handles collision and reflection.
Definition Ray.h:356
Matrix< T > & get_origin()
Gets the origin of the ray.
Definition Ray.h:105
A class that simulates ray tracing through a surface and gas environment.
Definition Raytracer.h:11
void combine_files(std::string filename, int num_procs)
Combines output files from multiple processes into a single file.
Definition Raytracer.h:287
void save(std::vector< trajectory< T > > trajectories, std::string filename)
Saves the simulated trajectories to a file.
Definition Raytracer.h:210
Raytracer()
Default constructor.
Definition Raytracer.h:52
unsigned long get_num_particles()
Retrieves the number of particles in the simulation.
Definition Raytracer.h:134
std::vector< trajectory< T > > simulate()
Simulates ray tracing and generates ray trajectories.
Definition Raytracer.h:151
void set_num_particles(unsigned long num_particles)
Sets the number of particles to simulate.
Definition Raytracer.h:120
std::string & get_sim_name()
Retrieves the name of the simulation.
Definition Raytracer.h:127
std::vector< trajectory< T > > import_data(std::string filename)
Imports trajectory data from a file.
Definition Raytracer.h:244
~Raytracer()
Destructor for the Raytracer class.
Definition Raytracer.h:72
A class representing a surface with geometry and statistical properties.
Definition Surface.h:11
Geometry< T > & get_geometry()
Retrieves the geometry of the surface.
Definition Surface.h:93
Represents a trajectory of a certain type.
Definition PG_Kernel.h:10