Cholla 3.0.1-dev
Cholla - Massively parallel hydro on GPUs
Loading...
Searching...
No Matches
load_cloudy_texture.h
Go to the documentation of this file.
1
4#pragma once
5
6#include <cmath> // pow, log10
7#include <string>
8
9#include "../cooling/texture_utilities.h" // Bilinear_Texture
10#include "../global/global.h"
11#include "../io/ParameterMap.h"
12#include "../utils/shared.h"
13
14namespace cool_component
15{
16
40{
41 // our usage of SharedHandle allows for the wrapped texture objects to be shared
42 // among multiple owners (i.e. multiple copies of CloudyHeatAndCool) and ensures that
43 // texture objects are properly cleaned up when the number of owners go to 0
46
47 public:
55 __host__ explicit CloudyHeatAndCool(std::string filename);
56
58 __host__ explicit CloudyHeatAndCool(ParameterMap& pmap)
59 : CloudyHeatAndCool(pmap.value_or("chemistry.data_file", "")) // delegate to other constructor
60 {
61 }
62
75 template <bool TABLE_ONLY>
76 __device__ __forceinline__ Real calc_contrib_(Real n, Real T) const
77 {
78 Real lambda = 0.0; // log cooling rate, erg s^-1 cm^3
79 Real cooling = 0.0; // cooling per unit volume, erg /s / cm^3
80 Real heating = 0.0; // heating per unit volume, erg /s / cm^3
81
82 // To keep texture code simple, we use floats (which have built-in support) as opposed to doubles (which would
83 // require casting)
84 float log_n, log_T;
85 log_n = log10(n);
86 log_T = log10(T);
87 // this temp.
88 if ((not TABLE_ONLY) and (log10(T) > 9.0)) {
89 lambda = 0.45 * log10(T) - 26.065;
90 } else if (TABLE_ONLY or (log10(T) >= 1.0)) {
91 // remap coordinates for texture
92 // remapped = (input - TABLE_MIN_VALUE)*(1/TABLE_SPACING)
93 // remapped = (input - TABLE_MIN_VALUE)*(NUM_CELLS_PER_DECADE)
94 const Real remap_log_T = (log_T - 1.0) * 10;
95 const Real remap_log_n = (log_n + 6.0) * 10;
96
97 lambda = Bilinear_Texture(this->coolTexObj_.get(), remap_log_T, remap_log_n);
98 const Real H = Bilinear_Texture(this->heatTexObj_.get(), remap_log_T, remap_log_n);
99 heating = pow(10, H);
100 } else {
101 // Do nothing below 10 K
102 return 0.0;
103 }
104
105 cooling = pow(10, lambda);
106 return n * n * (cooling - heating);
107 }
108
121 __device__ Real operator()(Real n, Real T) const { return calc_contrib_<false>(n, T); }
122};
123
124} // namespace cool_component
A class that provides map-like access to parameter files.
Definition ParameterMap.h:74
Wraps a handles while providing shared object semantics.
Definition shared.h:367
__host__ __device__ __forceinline__ HandleT get() const noexcept
Return the stored handle.
Definition shared.h:436
A callable type that uses texture mapping to interpolate Cloudy cooling/heating.
Definition load_cloudy_texture.h:40
__device__ Real operator()(Real n, Real T) const
compute the net cooling/heating rate
Definition load_cloudy_texture.h:121
__device__ __forceinline__ Real calc_contrib_(Real n, Real T) const
compute the net cooling contribution
Definition load_cloudy_texture.h:76
__host__ CloudyHeatAndCool(ParameterMap &pmap)
Construct an instance from the ParameterMap.
Definition load_cloudy_texture.h:58
Describes cooling components.
Definition cool_components.h:52