123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- #ifndef SRC_MESOMIE_HPP_
- #define SRC_MESOMIE_HPP_
- #include <iomanip>
- #include <iostream>
- #include <stdexcept>
- #include <vector>
- #include "nmie.hpp"
- #include "special-functions-impl.hpp"
- namespace nmie {
- template <typename FloatType>
- void MesoMie<FloatType>::calc_Q() {
- auto nmax = an_.size();
- Qext_ = 0.0;
- Qsca_ = 0.0;
- for (int n = nmax - 2; n >= 1; n--) {
-
- const int n1 = n;
-
- Qext_ += (n1 + n1 + 1.0) * (an_[n].real() + bn_[n].real());
-
-
- Qsca_ += (n1 + n1 + 1.0) *
- (an_[n].real() * an_[n].real() + an_[n].imag() * an_[n].imag() +
- bn_[n].real() * bn_[n].real() + bn_[n].imag() * bn_[n].imag());
- }
- Qext_ *= 2 / pow2(x_);
- Qsca_ *= 2 / pow2(x_);
- }
- template <typename FloatType>
- void MesoMie<FloatType>::calc_ab(FloatType R,
- FloatType xd,
- std::complex<FloatType> xm,
- std::complex<FloatType> eps_d,
- std::complex<FloatType> eps_m,
- std::complex<FloatType> d_parallel,
- std::complex<FloatType> d_perp) {
- x_ = xd;
-
- double xx = static_cast<double>(x_);
- int nmax = std::round(xx + 11 * std::pow(xx, (1.0 / 3.0)) + 1);
- an_.resize(nmax + 1, static_cast<FloatType>(0.0));
- bn_.resize(nmax + 1, static_cast<FloatType>(0.0));
- std::vector<std::complex<FloatType>>
- D1_xd(nmax + 1), D3_xd(nmax + 1),
- D1_xm(nmax + 1), D3_xm(nmax + 1),
- Psi_xd(nmax + 1), Zeta_xd(nmax + 1),
- Psi_xm(nmax + 1), Zeta_xm(nmax + 1);
- evalPsiZetaD1D3(std::complex<FloatType>(xd),
- Psi_xd, Zeta_xd,
- D1_xd, D3_xd);
- evalPsiZetaD1D3(std::complex<FloatType>(xm),
- Psi_xm, Zeta_xm,
- D1_xm, D3_xm);
- for (int n = 0; n <= nmax; n++) {
- an_[n] = Psi_xd[n] *
- (
- eps_m * xd * D1_xd[n] - eps_d * xm * D1_xm[n] +
- (
- (eps_m - eps_d) *
- (
- static_cast<FloatType>(n * (n + 1)) * d_perp +
- xd * D1_xd[n] * xm * D1_xm[n] * d_parallel
- ) /
- R
- )
- ) /
- (
- Zeta_xd[n] *
- (
- eps_m * xd * D3_xd[n] - eps_d * xm * D1_xm[n] +
- (
- (eps_m - eps_d) *
- (
- static_cast<FloatType>(n * (n + 1)) * d_perp +
- xd * D3_xd[n] * xm * D1_xm[n] * d_parallel
- ) /
- R
- )
- )
- );
- bn_[n] = Psi_xd[n] *
- (
- xd * D1_xd[n] - xm * D1_xm[n] +
- ((xm * xm - xd * xd) * d_parallel / R)
- ) /
- (
- Zeta_xd[n] * (
- xd * D3_xd[n] - xm * D1_xm[n] +
- ((xm * xm - xd * xd) * d_parallel / R)
- )
- );
- }
- }
- }
- #endif
|