psim  1.0
Generalized 2D phonon transport using a Monte Carlo method
cell.h
Go to the documentation of this file.
1 #ifndef PSIM_CELL_H
2 #define PSIM_CELL_H
3 
4 #include "compositeSurface.h"// for CompositeSurface
5 #include "geometry.h"// for Triangle, Line, Point
6 #include "material.h"// for Material, Material::Table
7 #include "sensor.h"// for Sensor
8 #include <array>// for array
9 #include <cstddef>// for size_t
10 #include <exception>// for exception
11 #include <iosfwd>// for ostream
12 #include <string>// for string
13 #include <string_view>// for string_view
14 
15 class Phonon;
16 
17 
18 // TODO - Inherit from Geometry::Triangle? Composition seems best for Sensor but requires a lot of forwarding
19 class Cell {
20 public:
24 
25  Cell(Triangle cell, Sensor& sensor, double spec = 1.);
26 
27  [[nodiscard]] const Material& getMaterial() const noexcept {
28  return sensor_.getMaterial();
29  }
30  [[nodiscard]] std::size_t getMaterialID() const noexcept {
31  return sensor_.getMaterial().id();
32  }
33  [[nodiscard]] std::size_t getSensorID() const noexcept {
34  return sensor_.getID();
35  }
36  [[nodiscard]] double getHeatCapacityAtFreq(std::size_t freq_index) const noexcept {
37  return sensor_.getHeatCapacityAtFreq(freq_index);
38  }
39  [[nodiscard]] double getArea() const noexcept {
40  return cell_.area();
41  }
42  [[nodiscard]] double getInitTemp() const noexcept {
43  return sensor_.getInitTemp();
44  }
45  [[nodiscard]] double getSteadyTemp(std::size_t step = 0) const noexcept {
46  return sensor_.getSteadyTemp(step);
47  }
48  [[nodiscard]] const auto& getBoundaries() const noexcept {
49  return boundaries_;
50  }
51  [[nodiscard]] std::array<Line, 3> getBoundaryLines() const noexcept;
52 
53  [[nodiscard]] Point getRandPoint(double r1, double r2) const noexcept {// NOLINT
54  return cell_.getRandPoint(r1, r2);
55  }
56  // Throws if the incoming cell overlaps, contains or is contained within this cell - both cells cannot coexist
57  // in the same model
58  void validate(const Cell& other) const;
59  [[nodiscard]] bool setEmitSurface(const Line& line, double temp, double duration, double start_time);
60 
61  [[nodiscard]] double getInitEnergy(double t_eq) const noexcept;
62  [[nodiscard]] double getEmitEnergy(double t_eq) const noexcept;
63 
64  void initialUpdate(Phonon& p, const Material::Table& table) const noexcept {// NOLINT
65  return sensor_.initialUpdate(p, table);
66  }
67  void initialUpdate(Phonon& p) const noexcept {
68  return sensor_.initialUpdate(p);// NOLINT
69  }
70  void scatterUpdate(Phonon& p) const noexcept {
71  return sensor_.scatterUpdate(p);// NOLINT
72  }
73  void updateEmitTables() noexcept;
74  void updateHeatParams(const Phonon& p, std::size_t step) noexcept;// NOLINT
75  void findTransitionSurface(Cell& other);
76  void handleSurfaceCollision(Phonon& p, const Point& poi, double step_time) const noexcept;// NOLINT
77 
78  bool operator==(const Cell& rhs) const;
79  bool operator!=(const Cell& rhs) const;
80 
81  friend std::ostream& operator<<(std::ostream& os, const Cell& cell);// NOLINT
82 
83 private:
84  Triangle cell_;
85  Sensor& sensor_;
86 
87  // Unused space on each line defaults to a boundary surface and portions of this boundary surface
88  // are allocated to different surface types as necessary
89  std::array<CompositeSurface, 3> boundaries_;
90 
91  // std::vector<BoundarySurface> inner_surfaces_; // implement later if req'd
92 
93  [[nodiscard]] std::array<CompositeSurface, 3> buildCompositeSurfaces(double spec) noexcept;
94  [[nodiscard]] bool setTransitionSurface(const Line& line, Cell& cell);
95 };
96 
97 
98 class CellError : public std::exception {
99 public:
100  [[nodiscard]] const char* what() const noexcept override {
101  return message_.c_str();
102  }
103 
104 protected:
105  void setMessage(std::string_view message) {
106  message_ = message;
107  }
108 
109 private:
110  std::string message_;
111 };
112 
113 class IntersectError : public CellError {
114 public:
116 
117 private:
118  Geometry::Triangle existing_;
119  Geometry::Triangle incoming_;
120 };
121 
122 class OverlapError : public CellError {
123 public:
125 
126 private:
127  Geometry::Triangle bigger_;
128  Geometry::Triangle smaller_;
129 };
130 
131 
132 #endif// PSIM_CELL_H
Geometry::Point Point
Definition: cell.cpp:18
Geometry::Line Line
Definition: cell.cpp:17
Definition: cell.h:98
const char * what() const noexcept override
Definition: cell.h:100
void setMessage(std::string_view message)
Definition: cell.h:105
Definition: cell.h:19
const Material & getMaterial() const noexcept
Definition: cell.h:27
void validate(const Cell &other) const
Definition: cell.cpp:29
std::size_t getMaterialID() const noexcept
Definition: cell.h:30
double getHeatCapacityAtFreq(std::size_t freq_index) const noexcept
Definition: cell.h:36
void scatterUpdate(Phonon &p) const noexcept
Definition: cell.h:70
Cell(Triangle cell, Sensor &sensor, double spec=1.)
Definition: cell.cpp:21
void initialUpdate(Phonon &p, const Material::Table &table) const noexcept
Definition: cell.h:64
void handleSurfaceCollision(Phonon &p, const Point &poi, double step_time) const noexcept
Definition: cell.cpp:111
void updateEmitTables() noexcept
Definition: cell.cpp:77
Point getRandPoint(double r1, double r2) const noexcept
Definition: cell.h:53
std::size_t getSensorID() const noexcept
Definition: cell.h:33
void updateHeatParams(const Phonon &p, std::size_t step) noexcept
Definition: cell.cpp:83
double getArea() const noexcept
Definition: cell.h:39
double getEmitEnergy(double t_eq) const noexcept
Definition: cell.cpp:53
void initialUpdate(Phonon &p) const noexcept
Definition: cell.h:67
void findTransitionSurface(Cell &other)
Definition: cell.cpp:89
double getSteadyTemp(std::size_t step=0) const noexcept
Definition: cell.h:45
bool setEmitSurface(const Line &line, double temp, double duration, double start_time)
Definition: cell.cpp:37
std::array< Line, 3 > getBoundaryLines() const noexcept
Definition: cell.cpp:119
const auto & getBoundaries() const noexcept
Definition: cell.h:48
double getInitEnergy(double t_eq) const noexcept
Definition: cell.cpp:46
double getInitTemp() const noexcept
Definition: cell.h:42
Definition: compositeSurface.h:17
Definition: cell.h:113
Definition: material.h:15
std::size_t id() const noexcept
Definition: material.h:29
std::array< std::pair< double, double >, NUM_FREQ_BINS > Table
Definition: material.h:20
Definition: cell.h:122
Definition: phonon.h:16
Definition: sensor.h:14
std::size_t getID() const noexcept
Definition: sensor.h:32
double getHeatCapacityAtFreq(std::size_t freq_index) const noexcept
Definition: sensor.h:41
double getInitTemp() const noexcept
Definition: sensor.h:44
const Material & getMaterial() const noexcept
Definition: sensor.h:35
void scatterUpdate(Phonon &p) const noexcept
Definition: sensor.cpp:44
double getSteadyTemp(std::size_t step=0) const noexcept
Definition: sensor.h:47
void initialUpdate(Phonon &p, const Material::Table &table) const noexcept
Definition: sensor.cpp:36
Geometry::Triangle Triangle
Definition: geometry.cpp:12
Definition: geometry.h:39
Definition: geometry.h:23
Definition: geometry.h:76
Point getRandPoint(double r1, double r2) const noexcept
Definition: geometry.cpp:237
double area() const noexcept
Definition: geometry.cpp:253