Canoe
Comprehensive Atmosphere N' Ocean Engine
air_parcel.hpp
Go to the documentation of this file.
1 #ifndef SRC_AIR_PARCEL_HPP_
2 #define SRC_AIR_PARCEL_HPP_
3 
4 // C/C++
5 #include <array>
6 #include <iostream>
7 #include <vector>
8 
9 // athena
10 #include <athena/athena.hpp> // Real
11 
12 // canoe
13 #include <configure.hpp>
14 
16 // \brief a collection of all physical data in a computational cell
17 class AirParcel {
18  public:
19  enum { Size = NHYDRO + NCLOUD + NCHEMISTRY + NTRACER + NTURBULENCE };
20 
21  enum class Type { MassFrac = 0, MassConc = 1, MoleFrac = 2, MoleConc = 3 };
22 
23  friend std::ostream &operator<<(std::ostream &os, Type const &type);
24  friend std::ostream &operator<<(std::ostream &os, AirParcel const &var);
25 
26  protected:
27  // data holder
28  std::array<Real, Size> data_;
29 
30  // type
32 
33  public:
36  Real *const w;
37 
39  Real *const c;
40 
42  Real *const q;
43 
45  Real *const x;
46 
48  Real *const t;
49 
51  Real const *d;
52 
53  // constructor
54  explicit AirParcel(Type type = Type::MoleFrac)
55  : mytype_(type),
56  w(data_.data()),
57  c(w + NHYDRO),
58  q(c + NCLOUD),
59  x(q + NCHEMISTRY),
60  t(x + NTRACER),
61  d(t + NTURBULENCE) {
62  std::fill(data_.begin(), data_.end(), 0.0);
63  }
64 
65  // copy constructor
66  AirParcel(AirParcel const &other)
67  : mytype_(other.mytype_),
68  data_(other.data_),
69  w(data_.data()),
70  c(w + NHYDRO),
71  q(c + NCLOUD),
72  x(q + NCHEMISTRY),
73  t(x + NTRACER),
74  d(t + NTURBULENCE) {}
75 
76  // Assignment operator
77  AirParcel &operator=(const AirParcel &other) {
78  // Check for self-assignment
79  if (this == &other) {
80  return *this;
81  }
82 
83  data_ = other.data_;
84  mytype_ = other.mytype_;
85  return *this;
86  }
87 
88  void SetType(Type type) { mytype_ = type; }
89 
90  Type GetType() const { return mytype_; }
91 
92  void SetZero() { std::fill(data_.begin(), data_.end(), 0.0); }
93 
95 
100 
101  protected:
104 
107 
110 
113 
116 
119 };
120 
121 using AirColumn = std::vector<AirParcel>;
122 
123 namespace AirParcelHelper {
124 AirParcel gather_from_primitive(MeshBlock const *pmb, int k, int j, int i);
125 AirColumn gather_from_primitive(MeshBlock const *pmb, int k, int j);
126 
127 inline AirColumn gather_from_primitive(MeshBlock const *pmb, int k, int j,
128  int il, int iu) {
129  AirColumn ac(iu - il + 1);
130  for (int i = il; i <= iu; ++i) {
131  ac[i - il] = gather_from_primitive(pmb, k, j, i);
132  }
133 
134  return ac;
135 }
136 
137 AirParcel gather_from_conserved(MeshBlock const *pmb, int k, int j, int i);
138 AirColumn gather_from_conserved(MeshBlock const *pmb, int k, int j);
139 
140 inline AirColumn gather_from_conserved(MeshBlock const *pmb, int k, int j,
141  int il, int iu) {
142  AirColumn ac(iu - il + 1);
143  for (int i = il; i <= iu; ++i) {
144  ac[i - il] = gather_from_conserved(pmb, k, j, i);
145  }
146 
147  return ac;
148 }
149 
150 void distribute_to_primitive(MeshBlock *pmb, int k, int j, int i,
151  AirParcel const &ac);
152 void distribute_to_primitive(MeshBlock *pmb, int k, int j, AirColumn const &ac);
153 
154 inline void distribute_to_primitive(MeshBlock *pmb, int k, int j, int il,
155  int iu, AirColumn const &ac) {
156  for (int i = il; i <= iu; ++i) {
157  distribute_to_primitive(pmb, k, j, i, ac[i - il]);
158  }
159 }
160 
161 void distribute_to_conserved(MeshBlock *pmb, int k, int j, int i,
162  AirParcel const &ac);
163 void distribute_to_conserved(MeshBlock *pmb, int k, int j, AirColumn const &ac);
164 
165 inline void distribute_to_conserved(MeshBlock *pmb, int k, int j, int il,
166  int iu, AirColumn const &ac) {
167  for (int i = il; i <= iu; ++i) {
168  distribute_to_conserved(pmb, k, j, i, ac[i - il]);
169  }
170 }
171 
172 } // namespace AirParcelHelper
173 
174 #endif // SRC_AIR_PARCEL_HPP_
std::vector< AirParcel > AirColumn
Definition: air_parcel.hpp:121
Real *const t
turbulence data
Definition: air_parcel.hpp:48
void SetZero()
Definition: air_parcel.hpp:92
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
AirParcel(AirParcel const &other)
Definition: air_parcel.hpp:66
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
AirParcel & operator=(const AirParcel &other)
Definition: air_parcel.hpp:77
Type mytype_
Definition: air_parcel.hpp:31
void massFractionToMassConcentration()
Definition: air_parcel.cpp:298
AirParcel(Type type=Type::MoleFrac)
Definition: air_parcel.hpp:54
void massConcentrationToMoleConcentration()
Definition: air_parcel.cpp:497
void SetType(Type type)
Definition: air_parcel.hpp:88
void moleConcentrationToMassFraction()
Definition: air_parcel.cpp:493
friend std::ostream & operator<<(std::ostream &os, Type const &type)
Definition: air_parcel.cpp:26
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
Real const * d
particle data
Definition: air_parcel.hpp:51
void massFractionToMoleConcentration()
Definition: air_parcel.cpp:489
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