Canoe
Comprehensive Atmosphere N' Ocean Engine
radiation_band_exchanger.cpp
Go to the documentation of this file.
1 // C/C++
2 #include <algorithm>
3 
4 // canoe
5 #include <configure.hpp>
6 
7 // exchanger
9 
10 // harp
11 #include "radiation_band.hpp"
12 #include "rt_solvers.hpp"
13 
14 #ifdef MPI_PARALLEL
15 #include <mpi.h>
16 #endif // MPI_PARALLEL
17 
19  send_buffer_[0].resize(temf_.size());
20  send_buffer_[0].swap(temf_);
21 }
22 
24  int nblocks = 1;
25  int nlevels = temf_.size();
26  int nlayers = GetNumLayers();
27 #ifdef MPI_PARALLEL
28  MPI_Comm_size(mpi_comm_, &nblocks);
29 #endif // MPI_PARALLEL
30 
31 #ifdef RT_DISORT
32  disort_state *ds = static_cast<disort_state *>(arg);
33 
34  for (int n = 0; n < nblocks; ++n) {
35  for (int i = 0; i <= nlayers; ++i) {
36  ds->temper[n * nlayers + i] = recv_buffer_[0][n * nlevels + i + NGHOST];
37  }
38  }
39 
40  std::reverse(ds->temper, ds->temper + ds->nlyr + 1);
41 #endif // RT_DISORT
42 
43  return true;
44 }
45 
47  int nlayers = GetNumLayers();
48  int npmom = GetNumPhaseMoments();
49  send_buffer_[1].resize(nlayers * (npmom + 3));
50 
51  auto buf = send_buffer_[1].data();
52 
53  for (int i = 0; i < nlayers; ++i) {
54  int i1 = i + NGHOST;
55  *(buf++) = tau_(b, i1);
56  *(buf++) = ssa_(b, i1);
57  for (int j = 0; j <= npmom; ++j) {
58  *(buf++) = pmom_(b, i1, j);
59  }
60  }
61 }
62 
64  int nblocks = 1;
65  int nlayers = GetNumLayers();
66  int npmom = GetNumPhaseMoments();
67 
68 #ifdef MPI_PARALLEL
69  MPI_Comm_size(mpi_comm_, &nblocks);
70 #endif // MPI_PARALLEL
71 
72  auto buf = recv_buffer_[1].data();
73 
74 #ifdef RT_DISORT
75  disort_state *ds = static_cast<disort_state *>(arg);
76 
77  for (int n = 0; n < nblocks; ++n) {
78  for (int i = 0; i < nlayers; ++i) {
79  ds->dtauc[n * nlayers + i] = *(buf++);
80  ds->ssalb[n * nlayers + i] = *(buf++);
81  for (int j = 0; j <= npmom; ++j)
82  ds->pmom[n * nlayers * ds->nmom_nstr + i * ds->nmom_nstr + j] =
83  *(buf++);
84  for (int j = npmom + 1; j < ds->nmom_nstr; ++j)
85  ds->pmom[n * nlayers * ds->nmom_nstr + i * ds->nmom_nstr + j] = 0.;
86  }
87  }
88 
89  // absorption
90  std::reverse(ds->dtauc, ds->dtauc + ds->nlyr);
91 
92  // single scatering albedo
93  std::reverse(ds->ssalb, ds->ssalb + ds->nlyr);
94 
95  // phase function moments
96  std::reverse(ds->pmom, ds->pmom + ds->nlyr * (ds->nmom_nstr + 1));
97  for (int i = 0; i < ds->nlyr; ++i) {
98  std::reverse(ds->pmom + i * (ds->nmom_nstr + 1),
99  ds->pmom + (i + 1) * (ds->nmom_nstr + 1));
100  }
101 #endif // RT_DISORT
102 
103  return true;
104 }
105 
107 void RadiationBand::Transfer(MeshBlock const *pmb, int n) {
108  int nblocks = 1;
109  int nlayers = GetNumLayers();
110  int npmom = GetNumPhaseMoments();
111  int size = send_buffer_[n].size();
112 
113 #ifdef MPI_PARALLEL
114  MPI_Comm_size(mpi_comm_, &nblocks);
115 #endif // MPI_PARALLEL
116 
117  if (n == 0) {
118  recv_buffer_[0].resize(nblocks * size);
119  } else if (n == 1) {
120  recv_buffer_[1].resize(nblocks * nlayers * (npmom + 3));
121  }
122 
123 #ifdef MPI_PARALLEL
124  MPI_Allgather(&send_buffer_[n], size, MessageTraits<RadiationBand>::mpi_type,
126  mpi_comm_);
127 #else
128  recv_buffer_[n].swap(send_buffer_[n]);
129 #endif // MPI_PARALLEL
130 }
BufferType recv_buffer_[MessageTraits< T >::num_buffers]
Definition: exchanger.hpp:89
BufferType send_buffer_[MessageTraits< T >::num_buffers]
Definition: exchanger.hpp:88
bool UnpackTemperature(void *arg)
Unpack temperature at cell face from receive buffer 0.
void PackSpectralGrid(int b)
Pack data in spectral grid b into send buffer 1.
bool UnpackSpectralGrid(void *arg)
Unpack data from receive buffer 1 into spectral grid b.
std::vector< Real > temf_
temperature at cell boundary (face)
AthenaArray< Real > pmom_
spectral bin phase function moments
void Transfer(MeshBlock const *pmb, int n) override
AthenaArray< Real > ssa_
spectral bin single scattering albedo
void PackTemperature()
Pack temperature at cell face into send buffer 0.
size_t GetNumLayers() const
Get number of phase function moments.
AthenaArray< Real > tau_
spectral bin optical depth
size_t GetNumPhaseMoments() const
Get number of phase function moments.
Traits class providing Message information for class T.