Canoe
Comprehensive Atmosphere N' Ocean Engine
radiative_flux.cpp
Go to the documentation of this file.
1 // C/C++ headers
2 // MPI headers
3 #ifdef MPI_PARALLEL
4 #include <mpi.h>
5 #endif
6 
7 #include "../coordinates/coordinates.hpp"
8 #include "../radiation/radiation.hpp"
9 #include "diagnostics.hpp"
10 
11 RadiativeFlux::RadiativeFlux(MeshBlock *pmb) : Diagnostics(pmb, "radflux") {
12  type = "VECTORS";
13  grid = "--F";
14  long_name = "total upward radiative flux,total downward radiative flux";
15  units = "w/m^2";
16  // 0: upward flux
17  // 1: downward flux
18  data.NewAthenaArray(2, 1, 1, ncells1_ + 1);
19 }
20 
22  MeshBlock *pmb = pmy_block_;
23 
24  int is = pmb->is, js = pmb->js, ks = pmb->ks;
25  int ie = pmb->ie, je = pmb->je, ke = pmb->ke;
26 
27  if (ncycle == 0) std::fill(data.data(), data.data() + data.GetSize(), 0.);
28 
29  // sum over horizontal grids weighted by area
30  RadiationBand *pband = pmb->prad->pband;
31  while (pband != NULL) {
32  for (int k = ks; k <= ke; ++k)
33  for (int j = js; j <= je; ++j) {
34  pmb->pcoord->Face1Area(k, j, is, ie + 1, x1area_);
35  for (int i = is; i <= ie + 1; ++i) {
36  data(0, i) += x1area_(i) * pband->bflxup(k, j, i);
37  data(1, i) += x1area_(i) * pband->bflxdn(k, j, i);
38  }
39  }
40  pband = pband->next;
41  }
42 
43  ncycle++;
44 }
45 
47  MeshBlock *pmb = pmy_block_;
48 
49  int is = pmb->is, js = pmb->js, ks = pmb->ks;
50  int ie = pmb->ie, je = pmb->je, ke = pmb->ke;
51 
52  Real *total_area = new Real[ncells1_ + 1];
53  std::fill(total_area, total_area + ncells1_ + 1, 0.);
54 
55  // calculate total face area
56  for (int k = ks; k <= ke; ++k)
57  for (int j = js; j <= je; ++j) {
58  pmb->pcoord->Face1Area(k, j, is, ie + 1, x1area_);
59  for (int i = is; i <= ie + 1; ++i) total_area[i] += x1area_(i);
60  }
61 
62  // take time and spatial average
63  if (ncycle > 0) {
64  // sum over all ranks
65 #ifdef MPI_PARALLEL
66  MPI_Allreduce(MPI_IN_PLACE, data.data(), data.GetSize(), MPI_ATHENA_REAL,
67  MPI_SUM, MPI_COMM_WORLD);
68  MPI_Allreduce(MPI_IN_PLACE, total_area, ncells1_ + 1, MPI_ATHENA_REAL,
69  MPI_SUM, MPI_COMM_WORLD);
70 #endif
71  for (int i = is; i <= ie + 1; ++i) {
72  data(0, i) /= ncycle * total_area[i];
73  data(1, i) /= ncycle * total_area[i];
74  }
75  }
76 
77  // clear cycle;
78  delete[] total_area;
79  ncycle = 0;
80 }
std::string units
Definition: diagnostics.hpp:17
std::string long_name
Definition: diagnostics.hpp:17
AthenaArray< Real > x1area_
scratch geometric arrays
Definition: diagnostics.hpp:56
std::string type
Definition: diagnostics.hpp:16
AthenaArray< Real > data
Definition: diagnostics.hpp:19
MeshBlock * pmy_block_
Definition: diagnostics.hpp:44
std::string grid
Definition: diagnostics.hpp:16
AthenaArray< Real > bflxup
band upward flux
AthenaArray< Real > bflxdn
band downward flux
void Finalize(AthenaArray< Real > const &w)
void Progress(AthenaArray< Real > const &w)
RadiativeFlux(MeshBlock *pmb)