Canoe
Comprehensive Atmosphere N' Ocean Engine
simple_cloud_particles.cpp
Go to the documentation of this file.
1 
9 // C/C++ header
10 #include <iostream>
11 #include <sstream>
12 #include <stdexcept>
13 
14 // Athena++ header
15 #include "../coordinates/coordinates.hpp"
16 #include "../debugger/debugger.hpp"
17 #include "../hydro/hydro.hpp"
18 #include "../hydro/srcterms/hydro_srcterms.hpp"
19 #include "../math/interpolation.h" // locate
20 #include "../mesh/mesh.hpp"
21 #include "particles.hpp"
22 
23 SimpleCloudParticles::SimpleCloudParticles(MeshBlock *pmb, ParameterInput *pin,
24  std::string name)
25  : Particles(pmb, pin, name, 2) {
26  // ATHENA_LOG("SimpleCloudParticles");
27  pmb->pdebug->Enter("SimpleCloudParticles");
28  std::stringstream &msg = pmb->pdebug->msg;
29  msg << "- first category is " << name + " cloud" << std::endl
30  << "- second category is " << name + " precipitation" << std::endl;
31  cnames_.resize(2);
32  cnames_[0] = "cloud";
33  cnames_[1] = "rain";
34 
35  Real mu = pin->GetReal("particles", name + ".mu");
36  Real cc = pin->GetReal("particles", name + ".cc");
37 
38  mu_.push_back(mu);
39  mu_.push_back(mu);
40 
41  cc_.push_back(cc);
42  cc_.push_back(cc);
43  pmb->pdebug->Leave();
44 }
45 
46 void SimpleCloudParticles::ExchangeHydro(std::vector<MaterialPoint> &mp,
48  AthenaArray<Real> const &w, Real dt) {
49  MeshBlock *pmb = pmy_block;
50  pmb->pdebug->Call("SimpleCloudParticles::ExchangeHydro-" + myname);
51  std::stringstream &msg = pmb->pdebug->msg;
52 
53  Mesh *pm = pmb->pmy_mesh;
54  Coordinates *pcoord = pmb->pcoord;
55  AthenaArray<Real> v1, v2, v3;
56  Real loc[3];
57 
58  v1.InitWithShallowSlice(const_cast<AthenaArray<Real> &>(w), 4, IM1, 1);
59  v2.InitWithShallowSlice(const_cast<AthenaArray<Real> &>(w), 4, IM2, 1);
60  v3.InitWithShallowSlice(const_cast<AthenaArray<Real> &>(w), 4, IM3, 1);
61 
62  Real g1 = pmb->phydro->hsrc.GetG1();
63  Real g2 = pmb->phydro->hsrc.GetG2();
64  Real g3 = pmb->phydro->hsrc.GetG3();
65 
66  int f = pm->f2 + pm->f3;
67  for (std::vector<MaterialPoint>::iterator q = mp.begin(); q != mp.end();
68  ++q) {
69  loc[0] = q->x3;
70  loc[1] = q->x2;
71  loc[2] = q->x1;
72 
73  interpnf(&q->v1, loc + 2 - f, v1.data(), xcenter_.data() + 2 - f,
74  dims_.data() + 2 - f, 1 + f);
75  if (pm->f2)
76  interpnf(&q->v2, loc + 2 - f, v2.data(), xcenter_.data() + 2 - f,
77  dims_.data() + 2 - f, 1 + f);
78  else
79  q->v2 = 0.;
80  if (pm->f3)
81  interpnf(&q->v3, loc + 2 - f, v3.data(), xcenter_.data() + 2 - f,
82  dims_.data() + 2 - f, 1 + f);
83  else
84  q->v3 = 0.;
85 
86  if (std::isnan(q->v1) || std::isnan(q->v2) || std::isnan(q->v3)) {
87  msg << "### FATAL ERROR in SimpleCloudParticle::ExchangeHydro. Particles "
88  << myname << " velocity is nan" << std::endl;
89  msg << "id = " << q->id << std::endl
90  << "type = " << q->type << std::endl
91  << "x1 = " << q->x1 << std::endl
92  << "x2 = " << q->x2 << std::endl
93  << "x3 = " << q->x3 << std::endl
94  << "v1 = " << q->v1 << std::endl
95  << "v2 = " << q->v2 << std::endl
96  << "v3 = " << q->v3 << std::endl;
97  Real k = locate(xcenter_.data(), q->x3, dims_[0]);
98  Real j = locate(xcenter_.data() + dims_[0], q->x2, dims_[1]);
99  Real i = locate(xcenter_.data() + dims_[0] + dims_[1], q->x1, dims_[2]);
100  std::cout << i << " " << pcoord->x1v(i) << " " << pcoord->x1v(i + 1)
101  << std::endl;
102  std::cout << j << " " << pcoord->x2v(j) << " " << pcoord->x2v(j + 1)
103  << std::endl;
104  std::cout << k << " " << pcoord->x3v(k) << " " << pcoord->x3v(k + 1);
105  ATHENA_ERROR(msg);
106  }
107 
108  // \todo TODO: hard coded sedimentation
109  if (q->type == 1) q->v1 += -10.;
110 
111  // add gravititional acceleration
112  int k, j, i;
113  k = locate(xface_.data(), q->x3, dims_[0] + 1);
114  j = locate(xface_.data() + dims_[0] + 1, q->x2, dims_[1] + 1);
115  i = locate(xface_.data() + dims_[0] + dims_[1] + 2, q->x1, dims_[2] + 1);
116 
117  Real src = dt * q->rho;
118  du(IM1, k, j, i) += src * g1;
119  du(IM2, k, j, i) += src * g2;
120  du(IM3, k, j, i) += src * g3;
121  du(IEN, k, j, i) += src * (g1 * q->v1 + g2 * q->v2 + g3 * q->v3);
122  }
123 
124 #if DEBUG_LEVEL > 2
125  pmb->pdebug->CheckConservation("du", du, pmb->is, pmb->ie, pmb->js, pmb->je,
126  pmb->ks, pmb->ke);
127 #endif
128  pmb->pdebug->Leave();
129 }
void interpnf(double *val, double const *coor, double const *data, double const *axis, size_t const *len, int ndim)
Definition: interpnf.c:13
int locate(double const *xx, double x, int n)
Definition: locate.c:7