-
Notifications
You must be signed in to change notification settings - Fork 5
Power law opacity #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
cf7eb13
power law opacity
brryan b195ff0
fix spiner version
brryan 7d1456a
Testing is behaving
brryan d218895
non-cgs units test
brryan fdb05d9
done
brryan 7781754
Latest submodule versions
brryan e5119b6
I give up
brryan 495499b
Clean up
brryan c6c8689
Extra print statement
brryan 00cd825
extra newline
brryan da8727f
Does CI work with this?
brryan 11f23b7
cleanup various little cmake things that were causing problems
jonahm-LANL dbb44bf
fix more weirdness. Disable package registry when appropriate.
jonahm-LANL dca807f
Add option to README
brryan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
brryan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
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_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.