|
| 1 | +#pragma once |
| 2 | +#include "compute_factors.hpp" |
| 3 | +#include "constants.hpp" |
| 4 | +#include "specfem_setup.hpp" |
| 5 | +#include <Kokkos_Core.hpp> |
| 6 | +#include <cmath> |
| 7 | +#include <sstream> |
| 8 | +#include <stdexcept> |
| 9 | + |
| 10 | +namespace specfem { |
| 11 | +namespace attenuation { |
| 12 | + |
| 13 | +template <int N_SLS> |
| 14 | +AttenuationPropertyValues<N_SLS> get_attenuation_property_values( |
| 15 | + Kokkos::View<type_real[N_SLS], Kokkos::LayoutRight, Kokkos::HostSpace> |
| 16 | + tau_s, |
| 17 | + Kokkos::View<type_real[N_SLS], Kokkos::LayoutRight, Kokkos::HostSpace> |
| 18 | + tau_eps) { |
| 19 | + |
| 20 | + AttenuationPropertyValues<N_SLS> result; |
| 21 | + result.beta = |
| 22 | + Kokkos::View<type_real[N_SLS], Kokkos::LayoutRight, Kokkos::HostSpace>( |
| 23 | + "beta"); |
| 24 | + |
| 25 | + // See Komatitsch & Tromp 1999, eq. (7) |
| 26 | + // Coefficients beta = tau_eps / tau_s |
| 27 | + for (int i = 0; i < N_SLS; ++i) { |
| 28 | + result.beta(i) = tau_eps(i) / tau_s(i); |
| 29 | + } |
| 30 | + |
| 31 | + // Sum of coefficients beta, then subtract 1 from each beta |
| 32 | + // to get the modulus defect |
| 33 | + result.one_minus_sum_beta = 0.0; |
| 34 | + for (int i = 0; i < N_SLS; ++i) { |
| 35 | + result.one_minus_sum_beta += result.beta(i); |
| 36 | + result.beta(i) -= 1.0; |
| 37 | + } |
| 38 | + |
| 39 | + return result; |
| 40 | +} |
| 41 | + |
| 42 | +template <int N_SLS> |
| 43 | +type_real get_attenuation_scale_factor( |
| 44 | + type_real f_c_source, |
| 45 | + Kokkos::View<type_real[N_SLS], Kokkos::LayoutRight, Kokkos::HostSpace> |
| 46 | + tau_eps, |
| 47 | + Kokkos::View<type_real[N_SLS], Kokkos::LayoutRight, Kokkos::HostSpace> |
| 48 | + tau_sigma, |
| 49 | + type_real Q_val, type_real attenuation_f0_reference) { |
| 50 | + |
| 51 | + // Quantity by which to scale mu_0 to get mu |
| 52 | + // See Liu et al. 1976; Aki & Richards 1980, eq. (5.81) |
| 53 | + const type_real factor_scale_mu0 = |
| 54 | + 1.0 + |
| 55 | + 2.0 * std::log(f_c_source / attenuation_f0_reference) / (pi * Q_val); |
| 56 | + |
| 57 | + // Quantity by which to scale mu to get mu_unrelaxed |
| 58 | + type_real sum_unrelaxed = 1.0; |
| 59 | + type_real sum_weighted = 1.0; |
| 60 | + |
| 61 | + for (int i = 0; i < N_SLS; ++i) { |
| 62 | + const type_real defect = tau_eps(i) / tau_sigma(i) - 1.0; |
| 63 | + sum_unrelaxed += defect / N_SLS; |
| 64 | + |
| 65 | + const type_real omega_tau = 2.0 * pi * f_c_source * tau_sigma(i); |
| 66 | + sum_weighted += |
| 67 | + defect / (1.0 + 1.0 / (omega_tau * omega_tau)) / N_SLS; |
| 68 | + } |
| 69 | + |
| 70 | + const type_real factor_scale_mu = sum_unrelaxed / sum_weighted; |
| 71 | + |
| 72 | + // Total factor by which to scale mu0 to get mu_unrelaxed |
| 73 | + const type_real scale_factor = factor_scale_mu * factor_scale_mu0; |
| 74 | + |
| 75 | + // Check that the correction factor is close to one |
| 76 | + if (scale_factor < 0.5 || scale_factor > 1.5) { |
| 77 | + std::ostringstream msg; |
| 78 | + msg << "Error in get_attenuation_scale_factor(): " |
| 79 | + << "scale factor = " << scale_factor |
| 80 | + << " should be between 0.5 and 1.5. " |
| 81 | + << "factor_scale_mu = " << factor_scale_mu |
| 82 | + << ", factor_scale_mu0 = " << factor_scale_mu0 |
| 83 | + << ", Q = " << Q_val |
| 84 | + << ", f_c_source = " << f_c_source |
| 85 | + << ", attenuation_f0_reference = " << attenuation_f0_reference |
| 86 | + << ". Please check your reference frequency."; |
| 87 | + throw std::runtime_error(msg.str()); |
| 88 | + } |
| 89 | + |
| 90 | + return scale_factor; |
| 91 | +} |
| 92 | + |
| 93 | +} // namespace attenuation |
| 94 | +} // namespace specfem |
0 commit comments