Canoe
Comprehensive Atmosphere N' Ocean Engine
air_parcel.cpp
Go to the documentation of this file.
1 // application
2 #include <application/exceptions.hpp>
3 
4 // athena
5 #include <athena/mesh/mesh.hpp>
6 
7 // climath
8 #include <climath/core.h> // sqr
9 
10 // canoe
11 #include "air_parcel.hpp"
12 #include "impl.hpp"
13 
14 // microphysics
16 
17 // chemistry
18 #include "c3m/chemistry.hpp"
19 
20 // tracer
21 #include "tracer/tracer.hpp"
22 
23 // snap
25 
26 std::ostream& operator<<(std::ostream& os, AirParcel::Type const& type) {
27  if (type == AirParcel::Type::MassFrac) {
28  os << "Mass Fraction";
29  } else if (type == AirParcel::Type::MassConc) {
30  os << "Mass Concentration";
31  } else if (type == AirParcel::Type::MoleFrac) {
32  os << "Mole Fraction";
33  } else if (type == AirParcel::Type::MoleConc) {
34  os << "Mole Concentration";
35  } else {
36  throw RuntimeError("Variable", "Unknown variable type");
37  }
38 
39  return os;
40 }
41 
42 std::ostream& operator<<(std::ostream& os, AirParcel const& var) {
43  os << var.mytype_ << ": ";
44  for (auto& v : var.data_) os << v << ", ";
45  return os;
46 }
47 
49  if (type == mytype_) {
50  return *this;
51  }
52 
53  if (type == Type::MassFrac) {
55  } else if (type == Type::MassConc) {
57  } else if (type == Type::MoleFrac) {
59  } else if (type == Type::MoleConc) {
61  } else {
62  throw RuntimeError("Variable", "Unknown variable type");
63  }
64 
65  return *this;
66 }
67 
69  if (mytype_ == Type::MassFrac) {
70  return *this;
71  }
72 
73  if (mytype_ == Type::MassConc) {
75  } else if (mytype_ == Type::MoleFrac) {
77  } else if (mytype_ == Type::MoleConc) {
79  } else {
80  throw RuntimeError("Variable", "Unknown variable type");
81  }
82 
83  return *this;
84 }
85 
87  if (mytype_ == Type::MassConc) {
88  return *this;
89  }
90 
91  if (mytype_ == Type::MassFrac) {
93  } else if (mytype_ == Type::MoleFrac) {
95  } else if (mytype_ == Type::MoleConc) {
97  } else {
98  throw RuntimeError("Variable", "Unknown variable type");
99  }
100 
101  return *this;
102 }
103 
105  if (mytype_ == Type::MoleFrac) {
106  return *this;
107  }
108 
109  if (mytype_ == Type::MassFrac) {
111  } else if (mytype_ == Type::MassConc) {
113  } else if (mytype_ == Type::MoleConc) {
115  } else {
116  throw RuntimeError("Variable", "Unknown variable type");
117  }
118 
119  return *this;
120 }
121 
123  if (mytype_ == Type::MoleConc) {
124  return *this;
125  }
126 
127  if (mytype_ == Type::MassFrac) {
129  } else if (mytype_ == Type::MassConc) {
131  } else if (mytype_ == Type::MoleFrac) {
133  } else {
134  throw RuntimeError("Variable", "Unknown variable type");
135  }
136 
137  return *this;
138 }
139 
141  auto pthermo = Thermodynamics::GetInstance();
142 
143  // set molar mixing ratio
144  Real sum1 = 1.;
145 #pragma omp simd reduction(+ : sum1)
146  for (int n = 1; n <= NVAPOR; ++n) {
147  sum1 += w[n] * (pthermo->GetInvMuRatio(n) - 1.);
148  }
149 
150  Real sum = sum1;
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.);
154  sum1 += -c[n];
155  }
156 
157 #pragma omp simd
158  for (int n = 1; n <= NVAPOR; ++n) {
159  w[n] *= pthermo->GetInvMuRatio(n) / sum;
160  }
161 
162 #pragma omp simd
163  for (int n = 0; n < NCLOUD; ++n) {
164  c[n] *= pthermo->GetInvMuRatio(n + 1 + NVAPOR) / sum;
165  }
166 
167  // set temperature
168  w[IDN] = w[IPR] / (w[IDN] * pthermo->GetRd() * sum1);
169 
171 }
172 
174  auto pthermo = Thermodynamics::GetInstance();
175  Real g = 1.;
176 
177  // set mass mixing ratio
178  Real sum = 1.;
179 #pragma omp simd reduction(+ : sum)
180  for (int n = 1; n <= NVAPOR; ++n) {
181  sum += w[n] * (pthermo->GetMuRatio(n) - 1.);
182  }
183 
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.);
187  g += -c[n];
188  }
189 
190 #pragma omp simd
191  for (int n = 1; n <= NVAPOR; ++n) {
192  w[n] *= pthermo->GetMuRatio(n) / sum;
193  }
194 
195 #pragma omp simd
196  for (int n = 0; n < NCLOUD; ++n) {
197  c[n] *= pthermo->GetMuRatio(n + 1 + NVAPOR) / sum;
198  }
199 
200  // set density
201  w[IDN] = sum * w[IPR] / (w[IDN] * g * pthermo->GetRd());
202 
204 }
205 
207  auto pthermo = Thermodynamics::GetInstance();
208 
209  Real rho = 0., sum = 0., cvt = 0., rhoR = 0.;
210  Real inv_rhod = 1. / w[IDN];
211 
212 #pragma omp simd reduction(+ : rho, sum, cvt, rhoR)
213  for (int n = 0; n <= NVAPOR; ++n) {
214  rho += w[n];
215  sum += w[n] * pthermo->GetInvMuRatio(n);
216  cvt += w[n] * pthermo->GetCvMassRef(n);
217  rhoR += w[n] * Constants::Rgas * pthermo->GetInvMu(n);
218  }
219 
220 #pragma omp simd reduction(+ : rho, sum, cvt)
221  for (int n = 0; n < NCLOUD; ++n) {
222  rho += c[n];
223  sum += c[n] * pthermo->GetInvMuRatio(n + 1 + NVAPOR);
224  cvt += c[n] * pthermo->GetCvMassRef(n + 1 + NVAPOR);
225  }
226 
227 #pragma omp simd
228  for (int n = 1; n <= NVAPOR; ++n) {
229  w[n] *= pthermo->GetInvMuRatio(n) / sum;
230  }
231 
232 #pragma omp simd
233  for (int n = 0; n < NCLOUD; ++n) {
234  c[n] *= pthermo->GetInvMuRatio(n + 1 + NVAPOR) / sum;
235  }
236 
237  Real di = 1. / rho;
238 
239  w[IDN] = w[IEN] / cvt;
240  w[IPR] = rhoR * w[IDN];
241  w[IVX] *= di;
242  w[IVY] *= di;
243  w[IVZ] *= di;
244 
245  // tracer
246 #pragma omp simd
247  for (int n = 0; n < NTRACER; ++n) x[n] *= inv_rhod;
248 
250 }
251 
253  auto pthermo = Thermodynamics::GetInstance();
254 
255  Real tem = w[IDN];
256  Real sum = 1., g = 1.;
257 
258 #pragma omp simd reduction(+ : sum)
259  for (int n = 1; n <= NVAPOR; ++n) {
260  sum += w[n] * (pthermo->GetMuRatio(n) - 1.);
261  }
262 
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.);
266  g += -c[n];
267  }
268 
269  Real rho = w[IPR] * sum / (pthermo->GetRd() * tem * g);
270 
271  w[IDN] = rho;
272  w[IEN] = 0.;
273 
274  for (int n = 1; n <= NVAPOR; ++n) {
275  w[n] *= rho * pthermo->GetMuRatio(n) / sum;
276  w[IDN] -= w[n];
277  w[IEN] += w[n] * pthermo->GetCvMassRef(n) * tem;
278  }
279 
280  for (int n = 0; n < NCLOUD; ++n) {
281  c[n] *= rho * pthermo->GetMuRatio(n + 1 + NVAPOR) / sum;
282  w[IDN] -= c[n];
283  w[IEN] += c[n] * pthermo->GetCvMassRef(n + 1 + NVAPOR) * tem;
284  }
285 
286  w[IEN] += w[IDN] * pthermo->GetCvMassRef(0) * tem;
287  w[IVX] *= rho;
288  w[IVY] *= rho;
289  w[IVZ] *= rho;
290 
291  // tracer
292 #pragma omp simd
293  for (int n = 0; n < NTRACER; ++n) x[n] *= w[IDN];
294 
296 }
297 
299  auto pthermo = Thermodynamics::GetInstance();
300  Real igm1 = 1.0 / (pthermo->GetGammadRef() - 1.0);
301 
302  // density
303  Real rho = w[IDN], pres = w[IPR];
304  for (int n = 1; n <= NVAPOR; ++n) {
305  w[n] *= rho;
306  w[IDN] -= w[n];
307  }
308 
309  for (int n = 0; n < NCLOUD; ++n) {
310  c[n] *= rho;
311  w[IDN] -= c[n];
312  }
313 
314  Real fsig = w[IDN], feps = w[IDN];
315  // vapors
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);
320  }
321 
322  // clouds
323 #pragma omp simd reduction(+ : fsig)
324  for (int n = 0; n < NCLOUD; ++n) {
325  fsig += c[n] * pthermo->GetCvRatioMass(n + 1 + NVAPOR);
326  }
327 
328  // internal energy
329  w[IEN] = igm1 * pres * fsig / feps;
330 
331  // momentum
332  w[IVX] *= rho;
333  w[IVY] *= rho;
334  w[IVZ] *= rho;
335 
336  // tracer
337 #pragma omp simd
338  for (int n = 0; n < NTRACER; ++n) x[n] *= w[IDN];
339 
341 }
342 
344  auto pthermo = Thermodynamics::GetInstance();
345  Real gm1 = pthermo->GetGammadRef() - 1.;
346 
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];
350 
351 #pragma omp simd reduction(+ : rho)
352  for (int n = 0; n < NCLOUD; ++n) rho += c[n];
353 
354  w[IDN] = rho;
355  Real di = 1. / rho;
356 
357  // mass mixing ratio
358 #pragma omp simd
359  for (int n = 1; n <= NVAPOR; ++n) w[n] *= di;
360 
361 #pragma omp simd
362  for (int n = 0; n < NCLOUD; ++n) c[n] *= di;
363 
364  Real fsig = 1., feps = 1.;
365  // vapors
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.);
370  }
371 
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.);
375  feps += -c[n];
376  }
377 
378  w[IPR] = gm1 * w[IEN] * feps / fsig;
379 
380  // velocity
381  w[IVX] *= di;
382  w[IVY] *= di;
383  w[IVZ] *= di;
384 
385  // tracer
386 #pragma omp simd
387  for (int n = 0; n < NTRACER; ++n) x[n] *= inv_rhod;
388 
390 }
391 
393  auto pthermo = Thermodynamics::GetInstance();
394  Real tem = w[IDN];
395  Real pres = w[IPR];
396 
397  // total gas moles / m^3
398  Real gmols = pres / (Constants::Rgas * tem);
399 
400  Real xgas = 1., fsig = 1., LE = 0.;
401 #pragma omp simd reduction(+ : xgas, fsig, LE)
402  for (int n = 0; n < NCLOUD; ++n) {
403  xgas += -c[n];
404  fsig += (pthermo->GetCvRatioMole(n + 1 + NVAPOR) - 1.) * c[n];
405  LE += -c[n] * pthermo->GetLatentEnergyMole(n + 1 + NVAPOR);
406  }
407 
408  Real xd = xgas;
409 #pragma omp simd reduction(+ : xd, fsig)
410  for (int n = 1; n <= NVAPOR; ++n) {
411  xd += -w[n];
412  fsig += (pthermo->GetCvRatioMole(n) - 1.) * w[n];
413  }
414 
415  Real tmols = gmols / xgas;
416 
417  w[IDN] = tmols * xd;
418  w[IVX] *= tmols;
419  w[IVY] *= tmols;
420  w[IVZ] *= tmols;
421 
422  Real cvd = Constants::Rgas / (pthermo->GetGammadRef() - 1.);
423  w[IEN] = tmols * (cvd * tem * fsig + LE);
424 
425 #pragma omp simd
426  for (int n = 1; n <= NVAPOR; ++n) w[n] *= tmols;
427 
428 #pragma omp simd
429  for (int n = 0; n < NCLOUD; ++n) c[n] *= tmols;
430 
431  // tracer
432  Real pd = xd / xgas * pres;
433  Real rhod = pd / (tem * pthermo->GetRd());
434 
435 #pragma omp simd
436  for (int n = 0; n < NTRACER; ++n) x[n] *= rhod;
437 
439 }
440 
442  auto pthermo = Thermodynamics::GetInstance();
443  Real tmols = w[IDN], fsig = w[IDN], xgas = 1., LE = 0.;
444 
445 #pragma omp simd reduction(+ : tmols, fsig, LE)
446  for (int n = 0; n < NCLOUD; ++n) {
447  tmols += c[n];
448  fsig += pthermo->GetCvRatioMole(n + 1 + NVAPOR) * c[n];
449  LE += -pthermo->GetLatentEnergyMole(n + 1 + NVAPOR) * c[n];
450  }
451 
452 #pragma omp simd reduction(+ : tmols, fsig)
453  for (int n = 1; n <= NVAPOR; ++n) {
454  tmols += w[n];
455  fsig += pthermo->GetCvRatioMole(n) * w[n];
456  }
457 
458 #pragma omp simd
459  for (int n = 0; n < NCLOUD; ++n) {
460  c[n] /= tmols;
461  xgas += -c[n];
462  }
463 
464  Real xd = xgas;
465 #pragma omp simd
466  for (int n = 1; n <= NVAPOR; ++n) {
467  w[n] /= tmols;
468  xd += -w[n];
469  }
470 
471  w[IVX] /= tmols;
472  w[IVY] /= tmols;
473  w[IVZ] /= tmols;
474 
475  Real cvd = Constants::Rgas / (pthermo->GetGammadRef() - 1.);
476  w[IDN] = (w[IEN] - LE) / (cvd * fsig);
477  w[IPR] = xgas * tmols * Constants::Rgas * w[IDN];
478 
479  // tracer
480  Real pd = xd / xgas * w[IPR];
481  Real inv_rhod = (w[IDN] * pthermo->GetRd()) / pd;
482 
483 #pragma omp simd
484  for (int n = 0; n < NTRACER; ++n) x[n] *= inv_rhod;
485 
487 }
488 
490  throw NotImplementedError("Variable::massFractionToMoleConcentration");
491 }
492 
494  throw NotImplementedError("Variable::moleConcentrationToMassFraction");
495 }
496 
498  throw NotImplementedError("Variable::massConcentrationToMoleConcentration");
499 }
500 
502  throw NotImplementedError("Variable::moleConcentrationToMassConcentration");
503 }
504 
505 namespace AirParcelHelper {
506 
507 AirParcel gather_from_primitive(MeshBlock const* pmb, int k, int j, int i) {
509 
510  auto phydro = pmb->phydro;
511  auto ptracer = pmb->pimpl->ptracer;
512  auto pmicro = pmb->pimpl->pmicro;
513  auto pchem = pmb->pimpl->pchem;
514 
515 #pragma omp simd
516  for (int n = 0; n < NHYDRO; ++n) air.w[n] = phydro->w(n, k, j, i);
517 
518 #pragma omp simd
519  for (int n = 0; n < NCLOUD; ++n) air.c[n] = pmicro->w(n, k, j, i);
520 
521  // scale mass fractions
522  Real rho = air.w[IDN], xd = 1.;
523 
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;
527 
528 #pragma omp simd reduction(+ : rho)
529  for (int n = 0; n < NCLOUD; ++n) rho += rhod * air.c[n];
530 
531  Real inv_rho = 1.0 / rho;
532 
533 #pragma omp simd
534  for (int n = 1; n <= NVAPOR; ++n) {
535  air.w[n] *= air.w[IDN] * inv_rho;
536  }
537 
538 #pragma omp simd
539  for (int n = 0; n < NCLOUD; ++n) {
540  air.c[n] *= rhod * inv_rho;
541  }
542 
543 #pragma omp simd
544  for (int n = 0; n < NCHEMISTRY; ++n)
545  air.q[n] = pchem->w(n, k, j, i) * rhod * inv_rho;
546 
547 #pragma omp simd
548  for (int n = 0; n < NTRACER; ++n) air.x[n] = ptracer->w(n, k, j, i);
549 
550  air.w[IDN] = rho;
551 
552  return air;
553 }
554 
555 AirParcel gather_from_conserved(MeshBlock const* pmb, int k, int j, int i) {
557 
558  auto phydro = pmb->phydro;
559  auto ptracer = pmb->pimpl->ptracer;
560  auto pmicro = pmb->pimpl->pmicro;
561  auto pchem = pmb->pimpl->pchem;
562 
563  auto pthermo = Thermodynamics::GetInstance();
564 
565 #pragma omp simd
566  for (int n = 0; n < NHYDRO; ++n) air.w[n] = phydro->u(n, k, j, i);
567 
568 #pragma omp simd
569  for (int n = 0; n < NCLOUD; ++n) air.c[n] = pmicro->u(n, k, j, i);
570 
571  Real rho = 0., cvt = 0.;
572 #pragma omp simd reduction(+ : rho, cvt)
573  for (int n = 0; n <= NVAPOR; ++n) {
574  rho += air.w[n];
575  cvt += air.w[n] * pthermo->GetCvMassRef(n);
576  }
577 
579  Real KE = 0.5 / rho * (sqr(air.w[IVX]) + sqr(air.w[IVY]) + sqr(air.w[IVZ]));
580 
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;
585 
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;
592  }
593 
594  air.w[IEN] = cvt * tem;
595 
596 #pragma omp simd
597  for (int n = 0; n < NCHEMISTRY; ++n) air.q[n] = pchem->u(n, k, j, i);
598 
599 #pragma omp simd
600  for (int n = 0; n < NTRACER; ++n) air.x[n] = ptracer->u(n, k, j, i);
601 
602  return air;
603 }
604 
605 void distribute_to_primitive(MeshBlock* pmb, int k, int j, int i,
606  AirParcel const& air_in) {
607  AirParcel* air;
608 
609  auto phydro = pmb->phydro;
610  auto ptracer = pmb->pimpl->ptracer;
611  auto pmicro = pmb->pimpl->pmicro;
612  auto pchem = pmb->pimpl->pchem;
613 
614  if (air_in.GetType() != AirParcel::Type::MassFrac) {
615  air = new AirParcel(air_in);
616  air->ToMassFraction();
617  } else {
618  air = const_cast<AirParcel*>(&air_in);
619  }
620 
621  // scale mass fractions back
622  Real rho = air->w[IDN];
623  Real rhod = rho, rhog = rho;
624 
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];
629  }
630 
631 #pragma omp simd reduction(+ : rhod)
632  for (int n = 1; n <= NVAPOR; ++n) rhod += -rho * air->w[n];
633 
634  Real inv_rhod = 1.0 / rhod;
635  Real inv_rhog = 1.0 / rhog;
636 
637  phydro->w(IDN, k, j, i) = rhog;
638 
639 #pragma omp simd
640  for (int n = 1; n <= NVAPOR; ++n)
641  phydro->w(n, k, j, i) = air->w[n] * rho * inv_rhog;
642 
643 #pragma omp simd
644  for (int n = 1 + NVAPOR; n < NHYDRO; ++n) phydro->w(n, k, j, i) = air->w[n];
645 
646 #pragma omp simd
647  for (int n = 0; n < NCLOUD; ++n)
648  pmicro->w(n, k, j, i) = air->c[n] * rho * inv_rhod;
649 
650 #pragma omp simd
651  for (int n = 0; n < NCHEMISTRY; ++n)
652  pchem->w(n, k, j, i) = air->q[n] * rho * inv_rhod;
653 
654 #pragma omp simd
655  for (int n = 0; n < NTRACER; ++n) ptracer->w(n, k, j, i) = air->x[n];
656 
657  if (air_in.GetType() != AirParcel::Type::MassFrac) {
658  delete air;
659  }
660 }
661 
662 void distribute_to_conserved(MeshBlock* pmb, int k, int j, int i,
663  AirParcel const& air_in) {
664  AirParcel* air;
665 
666  auto phydro = pmb->phydro;
667  auto pthermo = Thermodynamics::GetInstance();
668  auto ptracer = pmb->pimpl->ptracer;
669  auto pmicro = pmb->pimpl->pmicro;
670  auto pchem = pmb->pimpl->pchem;
671 
672  if (air_in.GetType() != AirParcel::Type::MassConc) {
673  air = new AirParcel(air_in);
674  air->ToMassConcentration();
675  } else {
676  air = const_cast<AirParcel*>(&air_in);
677  }
678 
679 #pragma omp simd
680  for (int n = 0; n < NHYDRO; ++n) phydro->u(n, k, j, i) = air->w[n];
681 
682 #pragma omp simd
683  for (int n = 0; n < NCLOUD; ++n) pmicro->u(n, k, j, i) = air->c[n];
684 
685  Real rho = 0., cvt = 0.;
686 
687 #pragma omp simd reduction(+ : rho, cvt)
688  for (int n = 0; n <= NVAPOR; ++n) {
689  rho += air->w[n];
690  cvt += air->w[n] * pthermo->GetCvMassRef(n);
691  }
692 
693 #pragma omp simd reduction(+ : rho, cvt)
694  for (int n = 0; n < NCLOUD; ++n) {
695  rho += air->c[n];
696  cvt += air->c[n] * pthermo->GetCvMassRef(n + 1 + NVAPOR);
697  }
698 
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;
703 
704 #pragma omp simd
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;
711  }
712 
713  for (int n = 0; n <= NVAPOR; ++n) {
714  // TODO(cli): not correct for cubed sphere
715  phydro->u(IEN, k, j, i) += 0.5 * air->w[n] * (sqr(vx) + sqr(vy) + sqr(vz));
716  }
717 
718 #pragma omp simd
719  for (int n = 0; n < NCHEMISTRY; ++n) pchem->u(n, k, j, i) = air->q[n];
720 
721 #pragma omp simd
722  for (int n = 0; n < NTRACER; ++n) ptracer->u(n, k, j, i) = air->x[n];
723 
724  if (air_in.GetType() != AirParcel::Type::MassConc) {
725  delete air;
726  }
727 }
728 
729 AirColumn gather_from_primitive(MeshBlock const* pmb, int k, int j) {
730  return gather_from_primitive(pmb, k, j, 0, pmb->ncells1 - 1);
731 }
732 
733 AirColumn gather_from_conserved(MeshBlock const* pmb, int k, int j) {
734  return gather_from_conserved(pmb, k, j, 0, pmb->ncells1 - 1);
735 }
736 
737 void distribute_to_primitive(MeshBlock* pmb, int k, int j,
738  AirColumn const& ac) {
739  distribute_to_primitive(pmb, k, j, 0, pmb->ncells1 - 1, ac);
740 }
741 
742 void distribute_to_conserved(MeshBlock* pmb, int k, int j,
743  AirColumn const& ac) {
744  distribute_to_conserved(pmb, k, j, 0, pmb->ncells1 - 1, ac);
745 }
746 
747 } // namespace AirParcelHelper
std::ostream & operator<<(std::ostream &os, AirParcel::Type const &type)
Definition: air_parcel.cpp:26
std::vector< AirParcel > AirColumn
Definition: air_parcel.hpp:121
std::array< Real, Size > data_
Definition: air_parcel.hpp:28
void moleConcentrationToMassConcentration()
Definition: air_parcel.cpp:501
Type GetType() const
Definition: air_parcel.hpp:90
Real *const x
tracer data
Definition: air_parcel.hpp:45
AirParcel & ToMassConcentration()
Definition: air_parcel.cpp:86
AirParcel & ToMoleFraction()
Definition: air_parcel.cpp:104
Real *const w
Definition: air_parcel.hpp:36
void massConcentrationToMoleFraction()
Definition: air_parcel.cpp:206
Real *const c
cloud data
Definition: air_parcel.hpp:39
AirParcel & ToMoleConcentration()
Definition: air_parcel.cpp:122
void moleFractionToMoleConcentration()
Definition: air_parcel.cpp:392
Type mytype_
Definition: air_parcel.hpp:31
void massFractionToMassConcentration()
Definition: air_parcel.cpp:298
void massConcentrationToMoleConcentration()
Definition: air_parcel.cpp:497
void SetType(Type type)
Definition: air_parcel.hpp:88
void moleConcentrationToMassFraction()
Definition: air_parcel.cpp:493
void moleConcentrationToMoleFraction()
Definition: air_parcel.cpp:441
void massConcentrationToMassFraction()
Definition: air_parcel.cpp:343
AirParcel & ConvertTo(AirParcel::Type type)
Definition: air_parcel.cpp:48
AirParcel & ToMassFraction()
Definition: air_parcel.cpp:68
void massFractionToMoleFraction()
Definition: air_parcel.cpp:140
Real *const q
chemistry data
Definition: air_parcel.hpp:42
void moleFractionToMassFraction()
Definition: air_parcel.cpp:173
void moleFractionToMassConcentration()
Definition: air_parcel.cpp:252
void massFractionToMoleConcentration()
Definition: air_parcel.cpp:489
static Thermodynamics const * GetInstance()
Return a pointer to the one and only instance of Thermodynamics.
double sqr(double x)
Definition: core.h:14
void distribute_to_conserved(MeshBlock *pmb, int k, int j, int i, AirParcel const &air_in)
Definition: air_parcel.cpp:662
void distribute_to_primitive(MeshBlock *pmb, int k, int j, int i, AirParcel const &air_in)
Definition: air_parcel.cpp:605
AirParcel gather_from_primitive(MeshBlock const *pmb, int k, int j, int i)
Definition: air_parcel.cpp:507
AirParcel gather_from_conserved(MeshBlock const *pmb, int k, int j, int i)
Definition: air_parcel.cpp:555
double const Rgas
Definition: constants.hpp:5