8 #include <yaml-cpp/yaml.h>
11 #include <application/application.hpp>
12 #include <application/exceptions.hpp>
15 #include <athena/coordinates/coordinates.hpp>
16 #include <athena/hydro/hydro.hpp>
17 #include <athena/mesh/mesh.hpp>
18 #include <athena/parameter_input.hpp>
38 Application::Logger app(
"harp");
39 app->Log(
"Initialize Radiation");
42 int ncells1 = pmb->ncells1;
43 int ncells2 = pmb->ncells2;
44 int ncells3 = pmb->ncells3;
48 pin->GetOrAddString(
"radiation",
"flags",
"")));
54 std::string str = pin->GetOrAddString(
"radiation",
"indir",
"(0.,0.)");
58 int nstr = pin->GetOrAddInteger(
"radiation",
"nstr", 8);
59 int nuphi = pin->GetOrAddInteger(
"radiation",
"nuphi", 1);
60 int numu = pin->GetOrAddInteger(
"radiation",
"numu", 1);
64 if (pin->DoesParameterExist(
"radiation",
p->GetName() +
".outdir")) {
65 auto str = pin->GetString(
"radiation",
p->GetName() +
".outdir");
67 }
else if (pin->DoesParameterExist(
"radiation",
"outdir")) {
68 auto str = pin->GetString(
"radiation",
"outdir");
73 p->Resize(ncells1, ncells2, ncells3, nstr);
74 p->ResizeSolver(ncells1 - 2 * NGHOST, nstr, nuphi, numu);
80 radiance.NewAthenaArray(nout, ncells3, ncells2);
84 p->btoa.InitWithShallowSlice(
radiance, 3, n,
p->GetNumOutgoingRays());
85 n +=
p->GetNumOutgoingRays();
90 flxup.NewAthenaArray(
bands_.size(), ncells3, ncells2, ncells1 + 1);
91 flxdn.NewAthenaArray(
bands_.size(), ncells3, ncells2, ncells1 + 1);
93 for (
int n = 0; n <
bands_.size(); ++n) {
94 bands_[n]->bflxup.InitWithShallowSlice(
flxup, 4, n, 1);
95 bands_[n]->bflxup.InitWithShallowSlice(
flxdn, 4, n, 1);
103 Application::Logger app(
"harp");
104 app->Log(
"Destroy Radiation");
108 for (
auto &band :
bands_) {
109 if (band->GetName() == name) {
113 throw NotFoundError(
"GetBand",
"Band " + name);
119 num +=
p->GetNumOutgoingRays();
126 auto pcoord = pmb->pcoord;
130 Real grav = -pmb->phydro->hsrc.GetG1();
134 p->SetSpectralProperties(ac, pcoord, grav, k,
j);
135 p->CalBandFlux(pmb, k,
j, il, iu);
140 Application::Logger app(
"harp");
141 app->Log(
"CalRadiance");
143 auto pcoord = pmb->pcoord;
147 Real grav = -pmb->phydro->hsrc.GetG1();
151 p->SetSpectralProperties(ac, pcoord, grav, k,
j);
152 p->CalBandRadiance(pmb, k,
j);
159 for (
size_t b = 0;
b <
bands_.size(); ++
b) {
161 for (
int i = il; i <= iu; ++i)
162 phydro->flux[X1DIR](IEN, k,
j, i) +=
168 return flxup.GetSizeInBytes() +
flxdn.GetSizeInBytes();
174 std::memcpy(pdst + offset,
flxup.data(),
flxup.GetSizeInBytes());
175 offset +=
flxup.GetSizeInBytes();
176 std::memcpy(pdst + offset,
flxdn.data(),
flxdn.GetSizeInBytes());
177 offset +=
flxdn.GetSizeInBytes();
182 Application::Logger app(
"harp");
183 app->Log(
"Radiation restarted");
186 std::memcpy(
flxup.data(), psrc + offset,
flxup.GetSizeInBytes());
187 offset +=
flxup.GetSizeInBytes();
188 std::memcpy(
flxdn.data(), psrc + offset,
flxdn.GetSizeInBytes());
189 offset +=
flxdn.GetSizeInBytes();
196 std::vector<std::string> dstr = Vectorize<std::string>(str.c_str());
197 int nray = dstr.size();
199 std::vector<Direction> ray(nray);
201 auto jt = dstr.begin();
202 for (
auto it = ray.begin(); it != ray.end(); ++it, ++jt) {
204 sscanf(jt->c_str(),
"(%lf,%lf)", &it->mu, &it->phi);
213 uint64_t flags = 0LL;
214 std::stringstream msg;
216 std::vector<std::string> dstr = Vectorize<std::string>(str.c_str(),
" ,");
217 for (
int i = 0; i < dstr.size(); ++i) {
218 if (dstr[i] ==
"static") {
220 }
else if (dstr[i] ==
"dynamic") {
222 }
else if (dstr[i] ==
"bin") {
224 }
else if (dstr[i] ==
"lbl") {
226 }
else if (dstr[i] ==
"ck") {
228 }
else if (dstr[i] ==
"planck") {
230 }
else if (dstr[i] ==
"star") {
232 }
else if (dstr[i] ==
"spher") {
234 }
else if (dstr[i] ==
"only") {
236 }
else if (dstr[i] ==
"normalize") {
238 }
else if (dstr[i] ==
"write_bin_radiance") {
241 msg <<
"flag:" << dstr[i] <<
"unrecognized" << std::endl;
242 throw RuntimeError(
"parse_radiation_flags", msg.str());
248 msg <<
"ck cannot be used with lbl." << std::endl;
249 throw RuntimeError(
"parse_radiation_flags", msg.str());
258 for (
int k = 1; k < npmom; k++) pmom[k] = 0.;
262 if (gg <= -1. || gg >= 1.)
263 std::cout <<
"getmom--bad input variable gg" << std::endl;
264 for (
int k = 1; k <= npmom; k++) pmom[k] = pow(gg, (Real)k);
std::vector< AirParcel > AirColumn
void SetCooldownTime(Real cooldown)
void SetFlag(uint64_t flag)
static RadiationBandContainer CreateFrom(ParameterInput *pin, std::string key)
AthenaArray< Real > flxdn
downward flux of all bands
Radiation(MeshBlock *pmb, ParameterInput *pin)
size_t RestartDataSizeInBytes(Mesh const *pm) const override
std::vector< Direction > rayInput_
incomming rays
std::shared_ptr< RadiationBand > GetBandByName(std::string const &name) const
Get band by name.
void CalRadiativeFlux(MeshBlock const *pmb, int k, int j, int il, int iu)
Calculate the radiative flux.
std::vector< RadiationBandPtr > bands_
all radiation bands
void DumpRestartData(char *pdst) const override
AthenaArray< Real > flxup
upward flux of all bands
size_t LoadRestartData(char *psrt) override
size_t GetNumOutgoingRays() const
Get total number of incoming rays.
static const std::string input_key
radiation input key in the input file [radiation_config]
void CalRadiance(MeshBlock const *pmb, int k, int j)
Calculate the radiance.
void AddRadiativeFlux(Hydro *phydro, int k, int j, int il, int iu) const
Add the radiative flux to hydro energy flux.
AthenaArray< Real > radiance
radiance of all bands
double deg2rad(double phi)
AirParcel gather_from_primitive(MeshBlock const *pmb, int k, int j, int i)
const uint64_t WriteBinRadiance
const uint64_t LineByLine
const uint64_t CorrelatedK
std::vector< Direction > parse_radiation_directions(std::string str)
uint64_t parse_radiation_flags(std::string str)
void get_phase_momentum(Real *pmom, int iphas, Real gg, int npmom)
std::shared_ptr< RadiationBand > RadiationBandPtr