Skip to content

Commit

Permalink
power law opacity
Browse files Browse the repository at this point in the history
  • Loading branch information
brryan committed Sep 25, 2024
1 parent 8c1bd1a commit cf7eb13
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 1 deletion.
181 changes: 181 additions & 0 deletions singularity-opac/photons/powerlaw_opacity_photons.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
// ======================================================================
// © 2024. Triad National Security, LLC. All rights reserved. This
// program was produced under U.S. Government contract
// 89233218CNA000001 for Los Alamos National Laboratory (LANL), which
// is operated by Triad National Security, LLC for the U.S.
// Department of Energy/National Nuclear Security Administration. All
// rights in the program are reserved by Triad National Security, LLC,
// and the U.S. Department of Energy/National Nuclear Security
// Administration. The Government is granted for itself and others
// acting on its behalf a nonexclusive, paid-up, irrevocable worldwide
// license in this material to reproduce, prepare derivative works,
// distribute copies to the public, perform publicly and display
// publicly, and to permit others to do so.
// ======================================================================

#ifndef SINGULARITY_OPAC_PHOTONS_POWERLAW_OPACITY_PHOTONS_
#define SINGULARITY_OPAC_PHOTONS_POWERLAW_OPACITY_PHOTONS_

#include <cassert>
#include <cmath>
#include <cstdio>

#include <ports-of-call/portability.hpp>
#include <singularity-opac/base/opac_error.hpp>
#include <singularity-opac/photons/thermal_distributions_photons.hpp>

namespace singularity {
namespace photons {

template <typename pc = PhysicalConstantsCGS>
class PowerLawOpacity {
public:
PowerLawOpacity() = default;
PowerLawOpacity(const Real kappa0, const Real A, const Real B)
: kappa0_(kappa0), A_(A), B_(B) {}
PowerLawOpacity(const PlanckDistribution<pc> &dist, const Real kappa0,
const Real A, const Real B)
: dist_(dist), kappa0_(kappa0), A_(A), B_(B) {}

GrayOpacity GetOnDevice() { return *this; }
PORTABLE_INLINE_FUNCTION
int nlambda() const noexcept { return 0; }
PORTABLE_INLINE_FUNCTION
void PrintParams() const noexcept {
printf("Power law opacity. kappa0 = %g A = %g B = %g\n", kappa0_, A_, B_);
}
inline void Finalize() noexcept {}

PORTABLE_INLINE_FUNCTION
Real AbsorptionCoefficient(const Real rho, const Real temp, const Real nu,
Real *lambda = nullptr) const {
return dist_.AbsorptionCoefficientFromKirkhoff(*this, rho, temp, nu,
lambda);
}

template <typename FrequencyIndexer, typename DataIndexer>
PORTABLE_INLINE_FUNCTION void
AbsorptionCoefficient(const Real rho, const Real temp,
FrequencyIndexer &nu_bins, DataIndexer &coeffs,
const int nbins, Real *lambda = nullptr) const {
for (int i = 0; i < nbins; ++i) {
coeffs[i] = AbsorptionCoefficient(rho, temp, nu_bins[i], lambda);
}
}

PORTABLE_INLINE_FUNCTION
Real AngleAveragedAbsorptionCoefficient(const Real rho, const Real temp,
const Real nu,
Real *lambda = nullptr) const {
return dist_.AngleAveragedAbsorptionCoefficientFromKirkhoff(
*this, rho, temp, nu, lambda);
}

template <typename FrequencyIndexer, typename DataIndexer>
PORTABLE_INLINE_FUNCTION void AngleAveragedAbsorptionCoefficient(
const Real rho, const Real temp, FrequencyIndexer &nu_bins,
DataIndexer &coeffs, const int nbins, Real *lambda = nullptr) const {
for (int i = 0; i < nbins; ++i) {
coeffs[i] =
AngleAveragedAbsorptionCoefficient(rho, temp, nu_bins[i], lambda);
}
}

PORTABLE_INLINE_FUNCTION
Real EmissivityPerNuOmega(const Real rho, const Real temp, const Real nu,
Real *lambda = nullptr) const {
Real Bnu = dist_.ThermalDistributionOfTNu(temp, nu, lambda);
return rho * (kappa0_ * std::pow(rho, A_) * std::pow(temp, B_) * Bnu;
}

template <typename FrequencyIndexer, typename DataIndexer>
PORTABLE_INLINE_FUNCTION void
EmissivityPerNuOmega(const Real rho, const Real temp,
FrequencyIndexer &nu_bins, DataIndexer &coeffs,
const int nbins, Real *lambda = nullptr) const {
for (int i = 0; i < nbins; ++i) {
coeffs[i] = EmissivityPerNuOmega(rho, temp, nu_bins[i], lambda);
}
}

PORTABLE_INLINE_FUNCTION
Real EmissivityPerNu(const Real rho, const Real temp, const Real nu,
Real *lambda = nullptr) const {
return 4 * M_PI * EmissivityPerNuOmega(rho, temp, nu, lambda);
}

template <typename FrequencyIndexer, typename DataIndexer>
PORTABLE_INLINE_FUNCTION void
EmissivityPerNu(const Real rho, const Real temp, FrequencyIndexer &nu_bins,
DataIndexer &coeffs, const int nbins,
Real *lambda = nullptr) const {
for (int i = 0; i < nbins; ++i) {
coeffs[i] = EmissivityPerNu(rho, temp, nu_bins[i], lambda);
}
}

PORTABLE_INLINE_FUNCTION
Real Emissivity(const Real rho, const Real temp,
Real *lambda = nullptr) const {
Real B = dist_.ThermalDistributionOfT(temp, lambda);
return rho * (kappa0_ * std::pow(rho, A_) * std::pow(temp, B_)) * B;
}

PORTABLE_INLINE_FUNCTION
Real NumberEmissivity(const Real rho, const Real temp,
Real *lambda = nullptr) const {
return (kappa0_ * std::pow(rho, A_) * std::pow(temp, B_)) *
dist_.ThermalNumberDistributionOfT(temp, lambda);
}

PORTABLE_INLINE_FUNCTION
Real ThermalDistributionOfTNu(const Real temp, const Real nu,
Real *lambda = nullptr) const {
return dist_.ThermalDistributionOfTNu(temp, nu, lambda);
}

PORTABLE_INLINE_FUNCTION
Real DThermalDistributionOfTNuDT(const Real temp, const Real nu,
Real *lambda = nullptr) const {
return dist_.DThermalDistributionOfTNuDT(temp, nu, lambda);
}

PORTABLE_INLINE_FUNCTION
Real ThermalDistributionOfT(const Real temp, Real *lambda = nullptr) const {
return dist_.ThermalDistributionOfT(temp, lambda);
}

PORTABLE_INLINE_FUNCTION Real
ThermalNumberDistributionOfT(const Real temp, Real *lambda = nullptr) const {
return dist_.ThermalNumberDistributionOfT(temp, lambda);
}

PORTABLE_INLINE_FUNCTION
Real EnergyDensityFromTemperature(const Real temp,
Real *lambda = nullptr) const {
return dist_.EnergyDensityFromTemperature(temp, lambda);
}

PORTABLE_INLINE_FUNCTION
Real TemperatureFromEnergyDensity(const Real er,
Real *lambda = nullptr) const {
return dist_.TemperatureFromEnergyDensity(er, lambda);
}

PORTABLE_INLINE_FUNCTION
Real NumberDensityFromTemperature(const Real temp,
Real *lambda = nullptr) const {
return dist_.NumberDensityFromTemperature(temp, lambda);
}

private:
Real kappa0_; // Opacity scale. Units of cm^2/g
Real A_; // Power law index of density
Real B_; // Power law index of temperature
PlanckDistribution<pc> dist_;
};

} // namespace photons
} // namespace singularity

#endif // SINGULARITY_OPAC_PHOTONS_POWERLAW_OPACITY_PHOTONS_
2 changes: 1 addition & 1 deletion utils/spiner
Submodule spiner updated 54 files
+1 −2 .github/PULL_REQUEST_TEMPLATE.md
+0 −46 .github/workflows/deps.yml
+0 −40 .github/workflows/docs.yml
+0 −24 .github/workflows/formatting.yml
+0 −36 .github/workflows/install.yml
+6 −11 .github/workflows/tests.yml
+0 −5 .gitignore
+0 −157 .gitlab-ci.yml
+0 −5 .gitlab-ci/config/spack/upstreams.yaml
+4 −3 .gitmodules
+0 −213 CMakeLists.txt
+1 −0 Catch2
+32 −93 README.md
+0 −66 cmake/Format.cmake
+0 −232 cmake/content.cmake
+0 −22 cmake/spinerConfig.cmake.in
+162 −206 databox.hpp
+0 −10 doc/index.html
+0 −1 doc/sphinx/.gitignore
+0 −27 doc/sphinx/Makefile
+0 −3 doc/sphinx/README
+0 −1 doc/sphinx/_static/placeholder
+0 −27 doc/sphinx/_templates/versions.html
+0 −57 doc/sphinx/conf.py
+0 −68 doc/sphinx/index.rst
+0 −35 doc/sphinx/make.bat
+0 −93 doc/sphinx/src/building.rst
+0 −503 doc/sphinx/src/databox.rst
+0 −54 doc/sphinx/src/getting-started.rst
+0 −178 doc/sphinx/src/interpolation.rst
+0 −102 doc/sphinx/src/sphinx-howto.rst
+0 −70 doc/sphinx/src/statement-of-need.rst
+ figs/spiner_interpolation_benchmark.png
+0 −1 installtest/.gitignore
+0 −43 installtest/CMakeLists.txt
+0 −7 installtest/libtest.cpp
+34 −57 interpolation.hpp
+79 −0 ports-of-call/README.md
+232 −0 ports-of-call/portability.hpp
+492 −0 ports-of-call/portable_arrays.hpp
+0 −5 sp5.hpp
+0 −50 spack-repo/packages/ports-of-call/package.py
+0 −106 spack-repo/packages/spiner/package.py
+0 −6 spack-repo/repo.yaml
+0 −21 spiner/interpolation.hpp
+0 −221 spiner/piecewise_grid_1d.hpp
+0 −0 spiner_types.hpp
+0 −112 test/CMakeLists.txt
+71 −0 test/Makefile
+78 −0 test/Makefile.kokkos
+0 −135 test/benchmark.cpp
+7 −8 test/convergence.cpp
+9 −7 test/plot_convergence.py
+22 −196 test/test.cpp

0 comments on commit cf7eb13

Please sign in to comment.