Canoe
Comprehensive Atmosphere N' Ocean Engine
concentration_inversion.cpp
Go to the documentation of this file.
1 // C/C++
2 #include <memory>
3 #include <string>
4 
5 // athena
6 #include <athena/hydro/hydro.hpp>
7 #include <athena/mesh/mesh.hpp>
8 #include <athena/parameter_input.hpp>
9 
10 // application
11 #include <application/application.hpp>
12 
13 // utils
14 #include <utils/ndarrays.hpp>
15 #include <utils/vectorize.hpp>
16 
17 // harp
19 
21 
23  ParameterInput *pin,
24  std::string name)
25  : Inversion(pmb, pin, name) {
26  Application::Logger app("inversion");
27  app->Log("Initializing ConcentrationInversion");
28  char buf[80];
29 
30  // species id
31  idx_ =
32  Vectorize<int>(pin->GetString("inversion", name + ".variables").c_str());
33 
34  // read in prior
35  for (auto m : idx_) {
36  if (m == IDN) { // change temperature
37  Xstd_[IDN] = pin->GetReal("inversion", name + ".tem.std");
38  app->Log(name + "::temperature std = " + std::to_string(Xstd_[IDN]));
39  } else {
40  Xstd_[m] = pin->GetReal("inversion", name + ".qvapor" +
41  std::to_string(m) + ".std.gkg") /
42  1.E3;
43  snprintf(buf, sizeof(buf), "%s::vapor %d standard deviation",
44  name.c_str(), m);
45  app->Log(buf + std::to_string(Xstd_[m]));
46  }
47  }
48 
49  int ndim = idx_.size();
50  app->Log(name + "::number of input dimension = " + std::to_string(ndim));
51 
52  // output dimension
53  int nvalue = target_.size();
54  app->Log("number of output dimension = " + std::to_string(nvalue));
55 
56  // number of walkers
57  int nwalker = pmb->block_size.nx3;
58  app->Log("walkers per block = " + std::to_string(nwalker));
59  app->Log("total number of walkers = " +
60  std::to_string(pmb->pmy_mesh->mesh_size.nx3));
61  if ((nwalker < 2) && pmb->pmy_mesh->nlim > 0) {
62  app->Error("nwalker (nx3) must be at least 2");
63  }
64 
65  // initialize mcmc chain
66  InitializeChain(pmb->pmy_mesh->nlim + 1, nwalker, ndim, nvalue);
67 }
68 
70  int nwalker = GetWalkers();
71  int ndim = GetDims();
72  Application::Logger app("inversion");
73 
74  // initialize random positions
75  app->Log("Initializing random positions for walkers");
76 
77  unsigned int seed = time(NULL) + Globals::my_rank;
78  NewCArray(init_pos_, nwalker, ndim);
79 
80  for (int p = 0; p < nwalker; ++p) {
81  for (size_t n = 0; n < idx_.size(); ++n) {
82  int m = idx_[n];
83  init_pos_[p][n] = (1. * rand_r(&seed) / RAND_MAX - 0.5) * Xstd_[m];
84  }
85  }
86 }
87 
88 void ConcentrationInversion::UpdateConcentration(Hydro *phydro, Real *Xp, int k,
89  int jl, int ju) const {
90  Application::Logger app("inversion");
91  app->Log("UpdateConcentration");
92 
93  // int is = pblock_->is, ie = pblock_->ie;
94 }
ConcentrationInversion(MeshBlock *pmb, ParameterInput *pin, std::string name)
void UpdateConcentration(Hydro *phydro, Real *Xp, int k, int jl, int ju) const
void InitializeChain(int nstep, int nwalker, int ndim, int nvalue)
Definition: inversion.cpp:71
Eigen::VectorXd target_
Definition: inversion.hpp:84
int GetDims() const
Definition: inversion.hpp:61
Real ** init_pos_
Definition: inversion.hpp:88
int GetWalkers() const
Definition: inversion.hpp:63
void NewCArray(T **&a, int n1, int n2)
Definition: ndarrays.hpp:5