CPP-snippets
0.0.1
A silly C++ project to use for demonstrating code integration
Loading...
Searching...
No Matches
simulation.hpp
1
#pragma once
2
3
#include <Eigen/Core>
4
#include <Eigen/SparseCore>
5
#include <random>
6
7
#include "interface.hpp"
8
#include "poisson.hpp"
9
#include "particles.hpp"
10
11
/**
12
* @class Simulation
13
* @brief Main driver class coordinating IO, Poisson solve, particle push,
14
* and data storage for a 1D PIC simulation.
15
*/
16
class
Simulation
{
17
18
private
:
19
20
/** @brief Interface for input/output handling. */
21
const
IOInterface
* m_interface;
22
/** @brief Poisson equation solver for field computation. */
23
PoissonSolver
* m_poisson;
24
/** @brief Particle container and pusher. */
25
Particles
* m_particles;
26
27
/** @brief Mersenne Twister RNG. */
28
std::mt19937 m_rng;
29
30
/** @brief Number of mesh cells. */
31
int
m_cellnumber;
32
/** @brief Total number of timesteps. */
33
int
m_timesteps;
34
/** @brief Total number of energy bins for postproc. */
35
int
m_bins;
36
/** @brief Current timestep index. */
37
int
m_timestep_idx = 0;
38
39
/** @brief Global time vector (size = timesteps). */
40
Eigen::VectorXd m_time;
41
/** @brief Cell widths. */
42
Eigen::VectorXd m_dx;
43
/** @brief Nodal positions. */
44
Eigen::VectorXd m_nodes;
45
46
/** @brief Charge density history: rows=time, cols=nodes. */
47
Eigen::MatrixXd m_rho;
48
/** @brief Electrostatic potential history. */
49
Eigen::MatrixXd m_phi;
50
/** @brief Electric field history (cell-centered). */
51
Eigen::MatrixXd m_efield;
52
53
/** @brief Collected particle fluxes per timestep. */
54
Eigen::MatrixX4d m_fluxes;
55
56
Eigen::MatrixXd m_energy_dist;
57
public
:
58
59
/**
60
* @brief Construct the simulation from an IO interface.
61
* @param interface Pointer to configuration and IO handler.
62
*/
63
explicit
Simulation
(
const
IOInterface
* interface);
64
65
/**
66
* @brief Execute the complete PIC time integration loop.
67
*/
68
void
run
();
69
70
/**
71
* @brief Write simulation results to output files.
72
*/
73
void
postprocess
();
74
};
75
IOInterface
Definition
interface.hpp:15
Particles
Stores and advances a dynamically sized set of 1D superparticles.
Definition
particles.hpp:13
PoissonSolver
Definition
poisson.hpp:7
Simulation::run
void run()
Execute the complete PIC time integration loop.
Definition
simulation.cpp:52
Simulation::Simulation
Simulation(const IOInterface *interface)
Construct the simulation from an IO interface.
Definition
simulation.cpp:17
Simulation::postprocess
void postprocess()
Write simulation results to output files.
Definition
simulation.cpp:116
src
simulation.hpp
Generated by
1.13.2