psim  1.0
Generalized 2D phonon transport using a Monte Carlo method
phonon.h
Go to the documentation of this file.
1 #ifndef PSIM_PHONON_H
2 #define PSIM_PHONON_H
3 
4 #include <array>// for array
5 #include <cstddef>// for size_t
6 #include <ostream>// for operator<<, basic_ostream, basic_ostream<>::__ost...
7 #include <utility>// for pair
8 
9 class Cell;
10 
11 namespace Geometry {
12 struct Line;
13 struct Point;
14 }// namespace Geometry
15 
16 class Phonon {
17 public:
18  static constexpr std::size_t NUM_RELAX_RATES = 3;
19  enum class Polarization { LA, TA };
20 
21  using RelaxRates = std::array<double, NUM_RELAX_RATES>;
22 
23  Phonon(signed char sign, double lifetime, Cell* cell);
24 
25  [[nodiscard]] signed char getSign() const noexcept {
26  return sign_;
27  }
28  [[nodiscard]] std::pair<double, double> getPosition() const noexcept {
29  return { px_, py_ };
30  }
31  [[nodiscard]] std::pair<double, double> getVelVector() const noexcept {
32  return { dx_ * velocity_, dy_ * velocity_ };
33  }
34  [[nodiscard]] std::pair<double, double> getDirection() const noexcept {
35  return { dx_, dy_ };
36  }
37  [[nodiscard]] std::size_t getFreqIndex() const noexcept {
38  return freq_index_;
39  }
40  [[nodiscard]] double getFreq() const noexcept {
41  return freq_;
42  }
43  [[nodiscard]] Polarization getPolar() const noexcept {
44  return polar_;
45  }
46  [[nodiscard]] double getLifetime() const noexcept {
47  return lifetime_;
48  }
49  [[nodiscard]] std::size_t getLifeStep() const noexcept {
50  return lifestep_;
51  }
52  [[nodiscard]] bool outsideCell() const noexcept {
53  return cell_ == nullptr;
54  }
55 
56  void scatterUpdate(std::size_t freq_index, double freq, double velocity, Polarization polar) noexcept;
57  void setPosition(double px, double py) noexcept {// NOLINT
58  px_ = px;
59  py_ = py;
60  }
61  void setDirection(double dx, double dy) noexcept {// NOLINT
62  dx_ = dx;
63  dy_ = dy;
64  }
65  void setCell(Cell* cell) noexcept {
66  cell_ = cell;
67  }
68  void setLifeStep(std::size_t step) {
69  lifestep_ = step;
70  }
71  void scatterUpdate();
72  void drift(double time) noexcept;
73  void setRandDirection() noexcept;
74 
75  // All these methods will throw if the phonon is not in a cell (cell_ == nullptr)
76  [[nodiscard]] std::size_t getCellSensorID() const;
77  [[nodiscard]] std::size_t getCellMaterialID() const;
78  [[nodiscard]] double getCellHeatCapacityAtFreq(std::size_t index) const;
79  [[nodiscard]] RelaxRates getRelaxRates(std::size_t step) const;
80  [[nodiscard]] std::array<Geometry::Line, 3> getCellBoundaryLines() const;
81  void handleSurfaceCollision(const Geometry::Point& poi, double step_time);
82  void updateCellHeatParams(std::size_t step) const;
83  void setRandPoint(double r1, double r2);// NOLINT
84 
85  friend std::ostream& operator<<(std::ostream& os, const Phonon& phonon) {// NOLINT
86  os << "px: " << phonon.px_ << " py: " << phonon.py_ << "\nvx_: " << phonon.dx_ * phonon.velocity_
87  << " vy_: " << phonon.dy_ * phonon.velocity_;
88  return os;
89  }
90 
91 private:
92  signed char sign_;// Determines how the phonon energy/flux is handled (-1, 1)
93  double lifetime_;
94  std::size_t lifestep_{ 0 };
95 
96  double px_{ 0. };
97  double py_{ 0. };
98  double dx_{ 0. };
99  double dy_{ 0. };
100 
101  std::size_t freq_index_{ 0 };
102  double freq_{ 0. };
103  double velocity_{ 0. };
104  Polarization polar_{ Polarization::LA };
105 
106  Cell* cell_{ nullptr };
107 };
108 
109 #endif// PSIM_PHONON_H
Definition: cell.h:19
Definition: phonon.h:16
void setRandPoint(double r1, double r2)
Definition: phonon.cpp:97
RelaxRates getRelaxRates(std::size_t step) const
Definition: phonon.cpp:63
void setCell(Cell *cell) noexcept
Definition: phonon.h:65
static constexpr std::size_t NUM_RELAX_RATES
Definition: phonon.h:18
std::pair< double, double > getPosition() const noexcept
Definition: phonon.h:28
bool outsideCell() const noexcept
Definition: phonon.h:52
std::array< Geometry::Line, 3 > getCellBoundaryLines() const
Definition: phonon.cpp:70
void handleSurfaceCollision(const Geometry::Point &poi, double step_time)
Definition: phonon.cpp:78
Phonon(signed char sign, double lifetime, Cell *cell)
Definition: phonon.cpp:13
double getCellHeatCapacityAtFreq(std::size_t index) const
Definition: phonon.cpp:56
Polarization
Definition: phonon.h:19
void scatterUpdate()
Definition: phonon.cpp:85
std::size_t getFreqIndex() const noexcept
Definition: phonon.h:37
std::size_t getCellMaterialID() const
Definition: phonon.cpp:49
void updateCellHeatParams(std::size_t step) const
Definition: phonon.cpp:90
signed char getSign() const noexcept
Definition: phonon.h:25
std::pair< double, double > getVelVector() const noexcept
Definition: phonon.h:31
void setDirection(double dx, double dy) noexcept
Definition: phonon.h:61
Polarization getPolar() const noexcept
Definition: phonon.h:43
double getLifetime() const noexcept
Definition: phonon.h:46
std::size_t getCellSensorID() const
Definition: phonon.cpp:42
std::size_t getLifeStep() const noexcept
Definition: phonon.h:49
void drift(double time) noexcept
Definition: phonon.cpp:30
double getFreq() const noexcept
Definition: phonon.h:40
void setPosition(double px, double py) noexcept
Definition: phonon.h:57
void setLifeStep(std::size_t step)
Definition: phonon.h:68
std::pair< double, double > getDirection() const noexcept
Definition: phonon.h:34
void setRandDirection() noexcept
Definition: phonon.cpp:36
std::array< double, NUM_RELAX_RATES > RelaxRates
Definition: phonon.h:21
Definition: geometry.h:13
Definition: geometry.h:39
Definition: geometry.h:23