AlmaBTE  1.3
A solver of the space- and time-dependent Boltzmann transport equation for phonons
processes.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 <cstddef>
22 #include <cmath>
23 #include <array>
24 #include <vector>
25 #include <functional>
26 #include <boost/mpi.hpp>
27 #include <boost/math/distributions/normal.hpp>
28 #include <boost/serialization/array.hpp>
29 #include <structures.hpp>
30 #include <qpoint_grid.hpp>
31 
32 // Forward declarations of elements documented later on.
33 // Note that serialization of std::vectors of objects without
34 // a default constructor is broken in Boost version 1.58.0. See:
35 // http://stackoverflow.com/a/30437359/85371
36 // https://svn.boost.org/trac/boost/ticket/11342
37 // This will prevent ALMA from compiling. We check for that
38 // specific version in our cmake configuration.
39 namespace alma {
40 class Threeph_process;
41 }
42 namespace boost {
43 namespace serialization {
44 template <class Archive>
45 inline void save_construct_data(Archive& ar,
46  const alma::Threeph_process* t,
47  const unsigned int file_version);
48 }
49 } // namespace boost
50 
51 namespace alma {
53 enum class threeph_type { emission = -1, absorption = 1 };
56 private:
57  friend class boost::serialization::access;
58  template <class Archive>
59  friend void boost::serialization::save_construct_data(
60  Archive& ar,
61  const Threeph_process* t,
62  const unsigned int file_version);
63 
64  friend void save_bulk_hdf5(const char* filename,
65  const std::string& description,
66  const Crystal_structure& cell,
67  const Symmetry_operations& symmetries,
68  const Gamma_grid& grid,
69  const std::vector<Threeph_process>& processes,
70  const boost::mpi::communicator& comm);
71 
72  friend std::tuple<std::string,
73  std::unique_ptr<Crystal_structure>,
74  std::unique_ptr<Symmetry_operations>,
75  std::unique_ptr<Gamma_grid>,
76  std::unique_ptr<std::vector<Threeph_process>>>
77  load_bulk_hdf5(const char* filename, const boost::mpi::communicator& comm);
78 
80  const double domega;
82  const double sigma;
84  bool gaussian_computed;
87  double gaussian;
89  bool vp2_computed;
91  double vp2;
95  template <class Archive>
96  void serialize(Archive& ar, const unsigned int file_version) {
97  ar & this->gaussian_computed;
98 
99  if (this->gaussian_computed)
100  ar & this->gaussian;
101  ar & this->vp2_computed;
102 
103  if (this->vp2_computed)
104  ar & this->vp2;
105  }
106 
107 
108 public:
110  const std::size_t c;
112  const std::array<std::size_t, 3> q;
114  const std::array<std::size_t, 3> alpha;
118  Threeph_process(std::size_t _c,
119  const std::array<std::size_t, 3>& _q,
120  const std::array<std::size_t, 3>& _alpha,
121  threeph_type _type,
122  double _domega,
123  double _sigma)
124  : domega(_domega), sigma(_sigma), gaussian_computed(false),
125  vp2_computed(false), c(_c), q(std::move(_q)),
126  alpha(std::move(_alpha)), type(_type) {
127  }
128 
129 
132  : domega(original.domega), sigma(original.sigma),
133  gaussian_computed(original.gaussian_computed),
134  gaussian(original.gaussian), vp2_computed(original.vp2_computed),
135  vp2(original.vp2), c(original.c), q(original.q),
136  alpha(original.alpha), type(original.type) {
137  }
138 
139 
146  double compute_gaussian() {
147  if (!this->gaussian_computed) {
148  auto distr = boost::math::normal(0., this->sigma);
149  this->gaussian = boost::math::pdf(distr, this->domega);
150  this->gaussian_computed = true;
151  }
152  return this->gaussian;
153  }
154 
155 
168  double compute_weighted_gaussian(const Gamma_grid& grid, double T);
169 
170 
179  double compute_vp2(const Crystal_structure& cell,
180  const Gamma_grid& grid,
181  const std::vector<Thirdorder_ifcs>& thirdorder);
182 
188  inline double get_vp2() const {
189  if (!this->vp2_computed)
190  throw exception("vp2 is not available");
191  return this->vp2;
192  }
193 
194 
196  inline bool is_vp2_computed() const {
197  return this->vp2_computed;
198  }
199 
200 
207  double compute_gamma(const Gamma_grid& grid, double T);
208 
216  double compute_gamma_reduced(const Gamma_grid& grid, double T);
217 
225  Eigen::ArrayXd compute_collision(const Gamma_grid& grid,
226  const Eigen::ArrayXXd& n0);
227 };
239 std::vector<Threeph_process> find_allowed_threeph(
240  const Gamma_grid& grid,
241  const boost::mpi::communicator& communicator,
242  double scalebroad = 1.0);
243 
252 Eigen::ArrayXXd calc_w0_threeph(const alma::Gamma_grid& grid,
253  std::vector<alma::Threeph_process>& processes,
254  double T,
255  const boost::mpi::communicator& comm);
256 
268 Eigen::ArrayXXd calc_w0_threeph(
269  const alma::Gamma_grid& grid,
270  std::vector<alma::Threeph_process>& processes,
271  double T,
272  std::function<bool(const Threeph_process&)> filter,
273  const boost::mpi::communicator& comm);
274 } // namespace alma
275 
276 namespace boost {
277 namespace serialization {
282 template <class Archive>
283 inline void save_construct_data(Archive& ar,
284  const alma::Threeph_process* t,
285  const unsigned int file_version) {
286  ar << t->c;
287  ar << make_array(t->q.data(), t->q.size());
288  ar << make_array(t->alpha.data(), t->alpha.size());
289  ar << t->type;
290  ar << t->domega;
291  ar << t->sigma;
292 }
293 
294 
300 template <class Archive>
301 inline void load_construct_data(Archive& ar,
303  const unsigned int file_version) {
304  std::size_t c;
305 
306  ar >> c;
307  std::array<std::size_t, 3> q;
308  ar >> make_array(q.data(), q.size());
309  std::array<std::size_t, 3> alpha;
310  ar >> make_array(alpha.data(), alpha.size());
311  alma::threeph_type type;
312  ar >> type;
313  double domega;
314  ar >> domega;
315  double sigma;
316  ar >> sigma;
317  ::new (t) alma::Threeph_process(c, q, alpha, type, domega, sigma);
318 }
319 } // namespace serialization
320 } // namespace boost
std::vector< Threeph_process > find_allowed_threeph(const Gamma_grid &grid, const boost::mpi::communicator &communicator, double scalebroad=1.0)
Look for allowed three-phonon processes in a regular grid.
Definition: processes.cpp:26
Definition: analytic1d.hpp:26
const std::array< std::size_t, 3 > q
q point indices of each of the three phonons involved.
Definition: processes.hpp:112
Definition: isotopic_scattering.hpp:58
const threeph_type type
Type of process.
Definition: processes.hpp:116
void save_construct_data(Archive &ar, const alma::Twoph_process *t, const unsigned int file_version)
Overload required to serialize the const members of alma::Twoph_process.
Definition: isotopic_scattering.hpp:215
void save_bulk_hdf5(const char *filename, const std::string &description, const Crystal_structure &cell, const Symmetry_operations &symmetries, const Gamma_grid &grid, const std::vector< Threeph_process > &processes, const boost::mpi::communicator &comm)
Save all relevant information about a bulk material to an HDF5 file.
Definition: bulk_hdf5.cpp:125
STL namespace.
Eigen::ArrayXXd calc_w0_threeph(const alma::Gamma_grid &grid, std::vector< alma::Threeph_process > &processes, double T, const boost::mpi::communicator &comm)
Compute and store the three-phonon contribution to the RTA scattering rates for all vibrational modes...
Definition: processes.cpp:240
Classes and functions used to manipulate grids in reciprocal space.
double get_vp2() const
Return the modulus squared of the matrix element of the process or throw an exception if it has not b...
Definition: processes.hpp:188
Threeph_process(std::size_t _c, const std::array< std::size_t, 3 > &_q, const std::array< std::size_t, 3 > &_alpha, threeph_type _type, double _domega, double _sigma)
Basic constructor.
Definition: processes.hpp:118
double compute_gaussian()
Compute and return the Gaussian factor of the process, i.e., the amplitude of the regularized delta...
Definition: processes.hpp:146
void load_construct_data(Archive &ar, alma::Twoph_process *t, const unsigned int file_version)
Overload required to deserialize the const members of alma::Twoph_process by calling the non-default ...
Definition: isotopic_scattering.hpp:233
const std::size_t c
Equivalence class of the first phonon.
Definition: processes.hpp:110
Base class for all exceptions in ALMA.
Definition: exceptions.hpp:25
const std::array< std::size_t, 3 > alpha
Mode indices of the three phonons involved.
Definition: processes.hpp:114
Definitions of the basic data-handling classes in ALMA.
Objects of this class hold a subset of the information provided by spg_get_dataset().
Definition: symmetry.hpp:47
bool is_vp2_computed() const
Definition: processes.hpp:196
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
Representation of a three-phonon process.
Definition: processes.hpp:55
std::tuple< std::string, std::unique_ptr< Crystal_structure >, std::unique_ptr< Symmetry_operations >, std::unique_ptr< Gamma_grid >, std::unique_ptr< std::vector< Threeph_process > > > load_bulk_hdf5(const char *filename, const boost::mpi::communicator &comm)
Reconstruct all data structures from a file saved with save_bulk_hdf5().
Definition: bulk_hdf5.cpp:442
threeph_type
Process type (emission or absorption).
Definition: processes.hpp:53
Threeph_process(const Threeph_process &original)
Copy constructor.
Definition: processes.hpp:131