2 #include <application/exceptions.hpp>
5 #include <athena/mesh/mesh.hpp>
28 os <<
"Mass Fraction";
30 os <<
"Mass Concentration";
32 os <<
"Mole Fraction";
34 os <<
"Mole Concentration";
36 throw RuntimeError(
"Variable",
"Unknown variable type");
44 for (
auto& v : var.
data_) os << v <<
", ";
62 throw RuntimeError(
"Variable",
"Unknown variable type");
80 throw RuntimeError(
"Variable",
"Unknown variable type");
98 throw RuntimeError(
"Variable",
"Unknown variable type");
116 throw RuntimeError(
"Variable",
"Unknown variable type");
134 throw RuntimeError(
"Variable",
"Unknown variable type");
145 #pragma omp simd reduction(+ : sum1)
146 for (
int n = 1; n <= NVAPOR; ++n) {
147 sum1 +=
w[n] * (pthermo->GetInvMuRatio(n) - 1.);
151 #pragma omp simd reduction(+ : sum, sum1)
152 for (
int n = 0; n < NCLOUD; ++n) {
153 sum +=
c[n] * (pthermo->GetInvMuRatio(n + 1 + NVAPOR) - 1.);
158 for (
int n = 1; n <= NVAPOR; ++n) {
159 w[n] *= pthermo->GetInvMuRatio(n) / sum;
163 for (
int n = 0; n < NCLOUD; ++n) {
164 c[n] *= pthermo->GetInvMuRatio(n + 1 + NVAPOR) / sum;
168 w[IDN] =
w[IPR] / (
w[IDN] * pthermo->GetRd() * sum1);
179 #pragma omp simd reduction(+ : sum)
180 for (
int n = 1; n <= NVAPOR; ++n) {
181 sum +=
w[n] * (pthermo->GetMuRatio(n) - 1.);
184 #pragma omp simd reduction(+ : sum, g)
185 for (
int n = 0; n < NCLOUD; ++n) {
186 sum +=
c[n] * (pthermo->GetMuRatio(n + 1 + NVAPOR) - 1.);
191 for (
int n = 1; n <= NVAPOR; ++n) {
192 w[n] *= pthermo->GetMuRatio(n) / sum;
196 for (
int n = 0; n < NCLOUD; ++n) {
197 c[n] *= pthermo->GetMuRatio(n + 1 + NVAPOR) / sum;
201 w[IDN] = sum *
w[IPR] / (
w[IDN] * g * pthermo->GetRd());
209 Real rho = 0., sum = 0., cvt = 0., rhoR = 0.;
210 Real inv_rhod = 1. /
w[IDN];
212 #pragma omp simd reduction(+ : rho, sum, cvt, rhoR)
213 for (
int n = 0; n <= NVAPOR; ++n) {
215 sum +=
w[n] * pthermo->GetInvMuRatio(n);
216 cvt +=
w[n] * pthermo->GetCvMassRef(n);
220 #pragma omp simd reduction(+ : rho, sum, cvt)
221 for (
int n = 0; n < NCLOUD; ++n) {
223 sum +=
c[n] * pthermo->GetInvMuRatio(n + 1 + NVAPOR);
224 cvt +=
c[n] * pthermo->GetCvMassRef(n + 1 + NVAPOR);
228 for (
int n = 1; n <= NVAPOR; ++n) {
229 w[n] *= pthermo->GetInvMuRatio(n) / sum;
233 for (
int n = 0; n < NCLOUD; ++n) {
234 c[n] *= pthermo->GetInvMuRatio(n + 1 + NVAPOR) / sum;
239 w[IDN] =
w[IEN] / cvt;
240 w[IPR] = rhoR *
w[IDN];
247 for (
int n = 0; n < NTRACER; ++n)
x[n] *= inv_rhod;
256 Real sum = 1., g = 1.;
258 #pragma omp simd reduction(+ : sum)
259 for (
int n = 1; n <= NVAPOR; ++n) {
260 sum +=
w[n] * (pthermo->GetMuRatio(n) - 1.);
263 #pragma omp simd reduction(+ : sum, g)
264 for (
int n = 0; n < NCLOUD; ++n) {
265 sum +=
c[n] * (pthermo->GetMuRatio(n + 1 + NVAPOR) - 1.);
269 Real rho =
w[IPR] * sum / (pthermo->GetRd() * tem * g);
274 for (
int n = 1; n <= NVAPOR; ++n) {
275 w[n] *= rho * pthermo->GetMuRatio(n) / sum;
277 w[IEN] +=
w[n] * pthermo->GetCvMassRef(n) * tem;
280 for (
int n = 0; n < NCLOUD; ++n) {
281 c[n] *= rho * pthermo->GetMuRatio(n + 1 + NVAPOR) / sum;
283 w[IEN] +=
c[n] * pthermo->GetCvMassRef(n + 1 + NVAPOR) * tem;
286 w[IEN] +=
w[IDN] * pthermo->GetCvMassRef(0) * tem;
293 for (
int n = 0; n < NTRACER; ++n)
x[n] *=
w[IDN];
300 Real igm1 = 1.0 / (pthermo->GetGammadRef() - 1.0);
303 Real rho =
w[IDN], pres =
w[IPR];
304 for (
int n = 1; n <= NVAPOR; ++n) {
309 for (
int n = 0; n < NCLOUD; ++n) {
314 Real fsig =
w[IDN], feps =
w[IDN];
316 #pragma omp simd reduction(+ : fsig, feps)
317 for (
int n = 1; n <= NVAPOR; ++n) {
318 fsig +=
w[n] * pthermo->GetCvRatioMass(n);
319 feps +=
w[n] * pthermo->GetInvMuRatio(n);
323 #pragma omp simd reduction(+ : fsig)
324 for (
int n = 0; n < NCLOUD; ++n) {
325 fsig +=
c[n] * pthermo->GetCvRatioMass(n + 1 + NVAPOR);
329 w[IEN] = igm1 * pres * fsig / feps;
338 for (
int n = 0; n < NTRACER; ++n)
x[n] *=
w[IDN];
345 Real gm1 = pthermo->GetGammadRef() - 1.;
347 Real rho = 0., inv_rhod =
w[IDN];
348 #pragma omp simd reduction(+ : rho)
349 for (
int n = 0; n <= NVAPOR; ++n) rho +=
w[n];
351 #pragma omp simd reduction(+ : rho)
352 for (
int n = 0; n < NCLOUD; ++n) rho +=
c[n];
359 for (
int n = 1; n <= NVAPOR; ++n)
w[n] *= di;
362 for (
int n = 0; n < NCLOUD; ++n)
c[n] *= di;
364 Real fsig = 1., feps = 1.;
366 #pragma omp simd reduction(+ : fsig, feps)
367 for (
int n = 1; n <= NVAPOR; ++n) {
368 fsig +=
w[n] * (pthermo->GetCvRatioMass(n) - 1.);
369 feps +=
w[n] * (pthermo->GetInvMuRatio(n) - 1.);
372 #pragma omp simd reduction(+ : fsig, feps)
373 for (
int n = 0; n < NCLOUD; ++n) {
374 fsig +=
c[n] * (pthermo->GetCvRatioMass(n + 1 + NVAPOR) - 1.);
378 w[IPR] = gm1 *
w[IEN] * feps / fsig;
387 for (
int n = 0; n < NTRACER; ++n)
x[n] *= inv_rhod;
400 Real xgas = 1., fsig = 1., LE = 0.;
401 #pragma omp simd reduction(+ : xgas, fsig, LE)
402 for (
int n = 0; n < NCLOUD; ++n) {
404 fsig += (pthermo->GetCvRatioMole(n + 1 + NVAPOR) - 1.) *
c[n];
405 LE += -
c[n] * pthermo->GetLatentEnergyMole(n + 1 + NVAPOR);
409 #pragma omp simd reduction(+ : xd, fsig)
410 for (
int n = 1; n <= NVAPOR; ++n) {
412 fsig += (pthermo->GetCvRatioMole(n) - 1.) *
w[n];
415 Real tmols = gmols / xgas;
423 w[IEN] = tmols * (cvd * tem * fsig + LE);
426 for (
int n = 1; n <= NVAPOR; ++n)
w[n] *= tmols;
429 for (
int n = 0; n < NCLOUD; ++n)
c[n] *= tmols;
432 Real pd = xd / xgas * pres;
433 Real rhod = pd / (tem * pthermo->GetRd());
436 for (
int n = 0; n < NTRACER; ++n)
x[n] *= rhod;
443 Real tmols =
w[IDN], fsig =
w[IDN], xgas = 1., LE = 0.;
445 #pragma omp simd reduction(+ : tmols, fsig, LE)
446 for (
int n = 0; n < NCLOUD; ++n) {
448 fsig += pthermo->GetCvRatioMole(n + 1 + NVAPOR) *
c[n];
449 LE += -pthermo->GetLatentEnergyMole(n + 1 + NVAPOR) *
c[n];
452 #pragma omp simd reduction(+ : tmols, fsig)
453 for (
int n = 1; n <= NVAPOR; ++n) {
455 fsig += pthermo->GetCvRatioMole(n) *
w[n];
459 for (
int n = 0; n < NCLOUD; ++n) {
466 for (
int n = 1; n <= NVAPOR; ++n) {
476 w[IDN] = (
w[IEN] - LE) / (cvd * fsig);
480 Real pd = xd / xgas *
w[IPR];
481 Real inv_rhod = (
w[IDN] * pthermo->GetRd()) / pd;
484 for (
int n = 0; n < NTRACER; ++n)
x[n] *= inv_rhod;
490 throw NotImplementedError(
"Variable::massFractionToMoleConcentration");
494 throw NotImplementedError(
"Variable::moleConcentrationToMassFraction");
498 throw NotImplementedError(
"Variable::massConcentrationToMoleConcentration");
502 throw NotImplementedError(
"Variable::moleConcentrationToMassConcentration");
510 auto phydro = pmb->phydro;
511 auto ptracer = pmb->pimpl->ptracer;
512 auto pmicro = pmb->pimpl->pmicro;
513 auto pchem = pmb->pimpl->pchem;
516 for (
int n = 0; n < NHYDRO; ++n) air.
w[n] = phydro->w(n, k,
j, i);
519 for (
int n = 0; n < NCLOUD; ++n) air.
c[n] = pmicro->w(n, k,
j, i);
522 Real rho = air.
w[IDN], xd = 1.;
524 #pragma omp simd reduction(+ : xd)
525 for (
int n = 1; n <= NVAPOR; ++n) xd += -air.
w[n];
526 Real rhod = air.
w[IDN] * xd;
528 #pragma omp simd reduction(+ : rho)
529 for (
int n = 0; n < NCLOUD; ++n) rho += rhod * air.
c[n];
531 Real inv_rho = 1.0 / rho;
534 for (
int n = 1; n <= NVAPOR; ++n) {
535 air.
w[n] *= air.
w[IDN] * inv_rho;
539 for (
int n = 0; n < NCLOUD; ++n) {
540 air.
c[n] *= rhod * inv_rho;
544 for (
int n = 0; n < NCHEMISTRY; ++n)
545 air.
q[n] = pchem->w(n, k,
j, i) * rhod * inv_rho;
548 for (
int n = 0; n < NTRACER; ++n) air.
x[n] = ptracer->w(n, k,
j, i);
558 auto phydro = pmb->phydro;
559 auto ptracer = pmb->pimpl->ptracer;
560 auto pmicro = pmb->pimpl->pmicro;
561 auto pchem = pmb->pimpl->pchem;
566 for (
int n = 0; n < NHYDRO; ++n) air.
w[n] = phydro->u(n, k,
j, i);
569 for (
int n = 0; n < NCLOUD; ++n) air.
c[n] = pmicro->u(n, k,
j, i);
571 Real rho = 0., cvt = 0.;
572 #pragma omp simd reduction(+ : rho, cvt)
573 for (
int n = 0; n <= NVAPOR; ++n) {
575 cvt += air.
w[n] * pthermo->GetCvMassRef(n);
579 Real KE = 0.5 / rho * (
sqr(air.
w[IVX]) +
sqr(air.
w[IVY]) +
sqr(air.
w[IVZ]));
581 Real tem = (air.
w[IEN] - KE) / cvt;
582 Real vx = air.
w[IVX] / rho;
583 Real vy = air.
w[IVY] / rho;
584 Real vz = air.
w[IVZ] / rho;
586 #pragma omp simd reduction(+ : cvt)
587 for (
int n = 0; n < NCLOUD; ++n) {
588 cvt += air.
c[n] * pthermo->GetCvMassRef(n + 1 + NVAPOR);
589 air.
w[IVX] += air.
c[n] * vx;
590 air.
w[IVY] += air.
c[n] * vy;
591 air.
w[IVZ] += air.
c[n] * vz;
594 air.
w[IEN] = cvt * tem;
597 for (
int n = 0; n < NCHEMISTRY; ++n) air.
q[n] = pchem->u(n, k,
j, i);
600 for (
int n = 0; n < NTRACER; ++n) air.
x[n] = ptracer->u(n, k,
j, i);
609 auto phydro = pmb->phydro;
610 auto ptracer = pmb->pimpl->ptracer;
611 auto pmicro = pmb->pimpl->pmicro;
612 auto pchem = pmb->pimpl->pchem;
622 Real rho = air->
w[IDN];
623 Real rhod = rho, rhog = rho;
625 #pragma omp simd reduction(+ : rhod, rhog)
626 for (
int n = 0; n < NCLOUD; ++n) {
627 rhod += -rho * air->
c[n];
628 rhog += -rho * air->
c[n];
631 #pragma omp simd reduction(+ : rhod)
632 for (
int n = 1; n <= NVAPOR; ++n) rhod += -rho * air->
w[n];
634 Real inv_rhod = 1.0 / rhod;
635 Real inv_rhog = 1.0 / rhog;
637 phydro->w(IDN, k,
j, i) = rhog;
640 for (
int n = 1; n <= NVAPOR; ++n)
641 phydro->w(n, k,
j, i) = air->
w[n] * rho * inv_rhog;
644 for (
int n = 1 + NVAPOR; n < NHYDRO; ++n) phydro->w(n, k,
j, i) = air->
w[n];
647 for (
int n = 0; n < NCLOUD; ++n)
648 pmicro->w(n, k,
j, i) = air->
c[n] * rho * inv_rhod;
651 for (
int n = 0; n < NCHEMISTRY; ++n)
652 pchem->w(n, k,
j, i) = air->
q[n] * rho * inv_rhod;
655 for (
int n = 0; n < NTRACER; ++n) ptracer->w(n, k,
j, i) = air->
x[n];
666 auto phydro = pmb->phydro;
668 auto ptracer = pmb->pimpl->ptracer;
669 auto pmicro = pmb->pimpl->pmicro;
670 auto pchem = pmb->pimpl->pchem;
680 for (
int n = 0; n < NHYDRO; ++n) phydro->u(n, k,
j, i) = air->
w[n];
683 for (
int n = 0; n < NCLOUD; ++n) pmicro->u(n, k,
j, i) = air->
c[n];
685 Real rho = 0., cvt = 0.;
687 #pragma omp simd reduction(+ : rho, cvt)
688 for (
int n = 0; n <= NVAPOR; ++n) {
690 cvt += air->
w[n] * pthermo->GetCvMassRef(n);
693 #pragma omp simd reduction(+ : rho, cvt)
694 for (
int n = 0; n < NCLOUD; ++n) {
696 cvt += air->
c[n] * pthermo->GetCvMassRef(n + 1 + NVAPOR);
699 Real tem = air->
w[IEN] / cvt;
700 Real vx = air->
w[IVX] / rho;
701 Real vy = air->
w[IVY] / rho;
702 Real vz = air->
w[IVZ] / rho;
705 for (
int n = 0; n < NCLOUD; ++n) {
706 phydro->u(IEN, k,
j, i) -=
707 air->
c[n] * pthermo->GetCvMassRef(n + 1 + NVAPOR) * tem;
708 phydro->u(IVX, k,
j, i) -= air->
c[n] * vx;
709 phydro->u(IVY, k,
j, i) -= air->
c[n] * vy;
710 phydro->u(IVZ, k,
j, i) -= air->
c[n] * vz;
713 for (
int n = 0; n <= NVAPOR; ++n) {
715 phydro->u(IEN, k,
j, i) += 0.5 * air->
w[n] * (
sqr(vx) +
sqr(vy) +
sqr(vz));
719 for (
int n = 0; n < NCHEMISTRY; ++n) pchem->u(n, k,
j, i) = air->
q[n];
722 for (
int n = 0; n < NTRACER; ++n) ptracer->u(n, k,
j, i) = air->
x[n];
std::ostream & operator<<(std::ostream &os, AirParcel::Type const &type)
std::vector< AirParcel > AirColumn
std::array< Real, Size > data_
void moleConcentrationToMassConcentration()
AirParcel & ToMassConcentration()
AirParcel & ToMoleFraction()
void massConcentrationToMoleFraction()
AirParcel & ToMoleConcentration()
void moleFractionToMoleConcentration()
void massFractionToMassConcentration()
void massConcentrationToMoleConcentration()
void moleConcentrationToMassFraction()
void moleConcentrationToMoleFraction()
void massConcentrationToMassFraction()
AirParcel & ConvertTo(AirParcel::Type type)
AirParcel & ToMassFraction()
void massFractionToMoleFraction()
Real *const q
chemistry data
void moleFractionToMassFraction()
void moleFractionToMassConcentration()
void massFractionToMoleConcentration()
static Thermodynamics const * GetInstance()
Return a pointer to the one and only instance of Thermodynamics.
void distribute_to_conserved(MeshBlock *pmb, int k, int j, int i, AirParcel const &air_in)
void distribute_to_primitive(MeshBlock *pmb, int k, int j, int i, AirParcel const &air_in)
AirParcel gather_from_primitive(MeshBlock const *pmb, int k, int j, int i)
AirParcel gather_from_conserved(MeshBlock const *pmb, int k, int j, int i)