AlmaBTE  1.3
A solver of the space- and time-dependent Boltzmann transport equation for phonons
sampling.hpp
Go to the documentation of this file.
1 // Copyright 2015-2018 The ALMA Project Developers
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 // implied. See the License for the specific language governing
13 // permissions and limitations under the License.
14 
15 #pragma once
16 
20 
21 #include <vector>
22 #include <utility>
23 #include <tuple>
24 #include <map>
25 #include <Eigen/Dense>
26 #include <randutils.hpp>
27 #include <structures.hpp>
28 #include <qpoint_grid.hpp>
29 #include <dos.hpp>
30 #include <processes.hpp>
31 #include <deviational_particle.hpp>
32 
33 namespace alma {
38 inline double random_dt(double w, randutils::mt19937_rng& rng) {
39  if (w == 0.)
40  throw value_error("invalid scattering rate");
41  double u = rng.uniform(0., 1.);
42  return -std::log(u) / w;
43 }
44 
45 
48 private:
50  std::vector<double> cumulative;
52  randutils::mt19937_rng& rng;
53 
54 public:
56  const std::size_t nqpoints;
58  const std::size_t nmodes;
62  Grid_distribution(const Gamma_grid& grid, randutils::mt19937_rng& _rng)
63  : rng(_rng), nqpoints(grid.nqpoints),
64  nmodes(grid.get_spectrum_at_q(0).omega.size()) {
65  }
66 
67 
69  virtual ~Grid_distribution() {
70  }
71 
72 
77  void fill_cumulative(const std::vector<double>& p);
78 
83  std::array<std::size_t, 2> sample() {
84  double u = this->rng.uniform(0., 1.);
85  auto pos = std::lower_bound(
86  this->cumulative.begin(), this->cumulative.end(), u) -
87  this->cumulative.begin();
88 
89  std::array<std::size_t, 2> nruter;
90  nruter[0] = pos % this->nmodes;
91  nruter[1] = pos / this->nmodes;
92  return nruter;
93  }
94 };
95 
101 public:
109  const Eigen::Ref<const Eigen::ArrayXXd>& w,
110  double T,
111  randutils::mt19937_rng& _rng);
112 };
113 
121 public:
129  Nabla_T_distribution(const Gamma_grid& grid,
130  const Eigen::Ref<const Eigen::Vector3d>& nablaT,
131  double T,
132  randutils::mt19937_rng& _rng);
133 };
134 
141 public:
151  const Gamma_grid& grid,
152  double Twall,
153  double Teq,
154  const Eigen::Ref<const Eigen::Vector3d>& normal,
155  randutils::mt19937_rng& _rng);
156 };
157 
162 public:
170  double Tref,
171  const Eigen::Ref<const Eigen::Vector3d>& normal,
172  randutils::mt19937_rng& _rng);
173 };
174 
176 
178 private:
180  std::map<char, std::size_t> Nbranches;
182  std::map<char, std::size_t> Ntot;
184  std::map<char, double> volume;
185 
194  using dos_tuple = std::
195  tuple<char, std::size_t, std::size_t, double, double, Gaussian_for_DOS>;
198  typedef std::tuple<char, std::size_t, double> lookup_entry;
200  std::vector<std::vector<lookup_entry>> lookup_incidentA;
202  std::vector<std::vector<lookup_entry>> lookup_incidentB;
204  randutils::mt19937_rng& rng;
206  double Tref;
214  std::vector<dos_tuple> get_modes(
215  const Gamma_grid& gridA,
216  const Gamma_grid& gridB,
217  const Eigen::Ref<const Eigen::Vector3d>& normal,
218  double scalebroad);
219 
220 public:
231  const Gamma_grid& gridA,
232  const Crystal_structure& poscarA,
233  const Gamma_grid& gridB,
234  const Crystal_structure& poscarB,
235  const Eigen::Ref<const Eigen::Vector3d>& normal,
236  double scalebroad,
237  randutils::mt19937_rng& _rng,
238  double Tref = 300.0);
247  char reemit(char incidence, D_particle& particle);
248 };
249 
258 private:
260  std::size_t nqA;
262  std::size_t nqB;
264  std::size_t nmodesA;
266  std::size_t nmodesB;
268  double VA;
270  double VB;
277  using dos_tuple =
278  std::tuple<char, std::size_t, std::size_t, Gaussian_for_DOS>;
281  std::vector<std::vector<double>> cumulative;
283  std::vector<std::vector<std::size_t>> allowed;
286  Eigen::MatrixXd directions;
288  randutils::mt19937_rng& rng;
296  std::vector<dos_tuple> get_all_modes(const Gamma_grid& gridA,
297  const Gamma_grid& gridB,
298  double scalebroad) const;
299 
300 public:
309  const Gamma_grid& gridB,
310  double scalebroad,
311  randutils::mt19937_rng& _rng);
321  char reemit(char incidence,
322  const Eigen::Ref<const Eigen::Vector3d>& normal,
323  D_particle& particle);
324 };
325 
326 // Simple and general class that allows us to simulate completely
327 // random elastic scattering.
329 private:
331  std::size_t nq;
333  std::size_t nmodes;
339  using dos_tuple = std::tuple<std::size_t, std::size_t, Gaussian_for_DOS>;
342  std::vector<std::vector<double>> cumulative;
344  std::vector<std::vector<std::size_t>> allowed;
347  Eigen::MatrixXd directions;
349  randutils::mt19937_rng& rng;
356  std::vector<dos_tuple> get_all_modes(const Gamma_grid& grid,
357  double scalebroad) const;
358 
359 public:
366  Elastic_distribution(const Gamma_grid& grid,
367  double scalebroad,
368  randutils::mt19937_rng& _rng);
373  void scatter(D_particle& particle);
374 
382  void scatter(const Eigen::Ref<const Eigen::Vector3d>& normal,
383  const int refsign,
384  D_particle& particle);
385 };
386 } // namespace alma
Definition: analytic1d.hpp:26
Grid_distribution(const Gamma_grid &grid, randutils::mt19937_rng &_rng)
Constructor.
Definition: sampling.hpp:62
Exception related to the parameters passed to a function.
Definition: exceptions.hpp:33
Classes and functions used to manipulate grids in reciprocal space.
void fill_cumulative(const std::vector< double > &p)
Fill the &#39;cumulative&#39; vector.
Definition: sampling.cpp:26
Objects of this class allow us to sample from a discrete distribution over a q-point grid with a PMF ...
Definition: sampling.hpp:100
virtual ~Grid_distribution()
Trivial virtual destructor.
Definition: sampling.hpp:69
const std::size_t nqpoints
Number of q points.
Definition: sampling.hpp:56
Each object of this class represents a deviational particle in the simulation.
Definition: deviational_particle.hpp:42
std::array< std::size_t, 2 > sample()
Draw a sample from the distribution.
Definition: sampling.hpp:83
Objects of this class allow us to simulate completely diffusive interfaces between two media...
Definition: sampling.hpp:257
Detection and representation of allowed three-phonon processes.
double random_dt(double w, randutils::mt19937_rng &rng)
Generate a random time delta from an exponential distribution.
Definition: sampling.hpp:38
Definitions of the basic data-handling classes in ALMA.
Objects of this class allow us to sample from a discrete distribution over a q-point grid with a PMF ...
Definition: sampling.hpp:120
Definition: sampling.hpp:328
Code used to describe deviational particles.
Objects of this class represent a regular grid with the Gamma point in one corner.
Definition: qpoint_grid.hpp:32
Hold information about a crystal structure.
Definition: structures.hpp:51
const std::size_t nmodes
Number of phonon modes at each q point.
Definition: sampling.hpp:58
Code related to the phonon density fo states (DOS).
Diffuse mismatch distribution.
Definition: sampling.hpp:177
planar_source_distribution Emission probability for outgoing modes is proportional to heat capacity *...
Definition: sampling.hpp:161
Objects of this class allow us to sample from a discrete distribution over a q-point grid with a PMF ...
Definition: sampling.hpp:140
Base class for discrete distributions over a q-point grid.
Definition: sampling.hpp:47