8 #include <athena/mesh/mesh.hpp>
9 #include <athena/outputs/outputs.hpp>
10 #include <athena/parameter_input.hpp>
11 #include <athena/utils/utils.hpp>
14 #include <configure.hpp>
20 #include <application/application.hpp>
21 #include <application/exceptions.hpp>
39 Application::Logger app(
"harp");
40 app->Log(
"Initialize RadiationBand " + myname);
43 throw NotFoundError(
"RadiationBand", myname);
46 auto my = rad[myname];
48 if (my[
"parameters"]) {
57 std::string dirstr = my[
"outdir"].as<std::string>();
63 auto names = my[
"opacity"].as<std::vector<std::string>>();
68 if (my[
"rt-solver"]) {
75 snprintf(buf,
sizeof(buf),
"%.2f - %.2f",
wrange_.first,
wrange_.second);
76 app->Log(
"Spectral range", buf);
77 app->Log(
"Number of spectral bins",
pgrid_->spec.size());
81 Application::Logger app(
"harp");
82 app->Log(
"Destroy RadiationBand " +
GetName());
88 temf_.resize(nc1 + 1);
99 pmom_.NewAthenaArray(
pgrid_->spec.size(), nc1, nstr + 1);
109 btau.NewAthenaArray(nc3, nc2, nc1);
110 bssa.NewAthenaArray(nc3, nc2, nc1);
111 bpmom.NewAthenaArray(nstr + 1, nc3, nc2, nc1);
122 if (absorber->GetName() == name) {
127 throw NotFoundError(
"RadiationBand",
"Absorber " + name);
135 for (
int i = il; i <= iu; ++i) {
141 psolver_->CalBandFlux(pmb, k,
j, il, iu);
158 char fname[80], number[6];
159 snprintf(number,
sizeof(number),
"%05d", pout->file_number);
160 snprintf(fname,
sizeof(fname),
"%s.radiance.%s.txt",
GetName().c_str(),
162 FILE *pfile = fopen(fname,
"w");
164 fprintf(pfile,
"# Bin Radiances of Band %s: %.3g - %.3g\n",
GetName().c_str(),
166 fprintf(pfile,
"# Ray output size: %lu\n",
rayOutput_.size());
168 fprintf(pfile,
"# Polar angles: ");
170 fprintf(pfile,
"%.3f",
rad2deg(acos(ray.mu)));
172 fprintf(pfile,
"\n");
174 fprintf(pfile,
"# Azimuthal angles: ");
176 fprintf(pfile,
"%.3f",
rad2deg(ray.phi));
178 fprintf(pfile,
"\n");
180 fprintf(pfile,
"#%12s%12s",
"wave1",
"wave2");
182 fprintf(pfile,
"%12s%lu",
"Radiance",
j + 1);
184 fprintf(pfile,
"%12s\n",
"weight");
192 char fname[80], number[6];
193 snprintf(number,
sizeof(number),
"%05d", pout->file_number);
194 snprintf(fname,
sizeof(fname),
"%s.radiance.%s.txt",
GetName().c_str(),
196 FILE *pfile = fopen(fname,
"w");
198 for (
size_t i = 0; i <
pgrid_->spec.size(); ++i) {
199 fprintf(pfile,
"%13.3g%12.3g",
pgrid_->spec[i].wav1,
pgrid_->spec[i].wav2);
201 fprintf(pfile,
"%12.3f",
toa_(i,
j));
205 fprintf(pfile,
"%12.3g\n",
208 fprintf(pfile,
"%12.3g\n",
pgrid_->spec[i].wght);
216 std::string
const &rt_name, YAML::Node
const &rad) {
217 std::shared_ptr<RTSolver> psolver;
219 if (rt_name ==
"Lambert") {
220 psolver = std::make_shared<RTSolverLambert>(
this, rad);
222 }
else if (rt_name ==
"Disort") {
223 psolver = std::make_shared<RTSolverDisort>(
this, rad);
226 throw NotFoundError(
"RadiationBand", rt_name);
233 Application::Logger app(
"harp");
234 app->Log(
"Load Radiation bands from " + filename);
236 std::vector<RadiationBandPtr> bands;
238 std::ifstream stream(filename);
239 if (stream.good() ==
false) {
240 app->Error(
"Cannot open radiation bands file: " + filename);
242 YAML::Node rad = YAML::Load(stream);
244 for (
auto bname : rad[
"bands"]) {
245 auto p = std::make_shared<RadiationBand>(bname.as<std::string>(), rad);
254 std::vector<RadiationBandPtr> bands;
257 Vectorize<std::string>(pin->GetOrAddString(
"radiation", key,
"").c_str());
259 for (
auto &filename : rt_band_files) {
261 bands.insert(bands.end(), tmp.begin(), tmp.end());
std::shared_ptr< Absorber > AbsorberPtr
static AbsorberPtr CreateFrom(YAML::Node const &my, std::string band_name)
Create an absorber from YAML node.
int TestFlag(uint64_t flag) const
std::string GetName() const
void SetRealsFrom(YAML::Node const &node)
void CalBandFlux(MeshBlock const *pmb, int k, int j, int il, int iu)
Calculate band radiative fluxes.
std::shared_ptr< Absorber > GetAbsorberByName(std::string const &name)
Get an individual absorber by name.
AthenaArray< Real > flxdn_
spectral bin downward flux
std::vector< Real > temf_
temperature at cell boundary (face)
std::pair< Real, Real > wrange_
identify wave- number (wavelength, frequency) range
AthenaArray< Real > bpmom
band phase function moments
void ResizeSolver(int nlyr, int nstr=8, int nuphi=1, int numu=1)
Allocate memory for radiation solver.
std::shared_ptr< RTSolver > psolver_
radiative transfer solver
AthenaArray< Real > pmom_
spectral bin phase function moments
size_t GetNumOutgoingRays()
Get number of outgoing rays.
std::shared_ptr< SpectralGridBase > pgrid_
spectral grid
AthenaArray< Real > toa_
spectral bin top-of-the-atmosphere radiance
void CalBandRadiance(MeshBlock const *pmb, int k, int j)
Calculate band radiances.
AthenaArray< Real > flxup_
spectral bin upward flux
AthenaArray< Real > btau
band optical depth
std::shared_ptr< RTSolver > CreateRTSolverFrom(std::string const &name, YAML::Node const &rad)
Create radiative transfer solver from YAML node.
AthenaArray< Real > bflxup
band upward flux
AthenaArray< Real > ssa_
spectral bin single scattering albedo
AthenaArray< Real > btoa
band top-of-the-atmosphere radiance
std::vector< Real > tem_
temperature at cell center
RadiationBand(std::string name, YAML::Node const &rad)
void WriteAsciiData(OutputParameters const *) const override
std::vector< std::shared_ptr< Absorber > > absorbers_
all absorbers
void Resize(int nc1, int nc2=1, int nc3=1, int nstr=8)
Allocate memory for radiation band.
AthenaArray< Real > tau_
spectral bin optical depth
AthenaArray< Real > bflxdn
band downward flux
void WriteAsciiHeader(OutputParameters const *) const override
std::vector< Direction > rayOutput_
outgoing rays
AthenaArray< Real > bssa
band single scattering albedo
static RadiationBandContainer CreateFrom(ParameterInput *pin, std::string key)
static SpectralGridPtr CreateFrom(YAML::Node const &my)
double rad2deg(double phi)
const uint64_t WriteBinRadiance
std::vector< Direction > parse_radiation_directions(std::string str)
std::vector< RadiationBandPtr > RadiationBandContainer