Canoe
Comprehensive Atmosphere N' Ocean Engine
particles.cpp
Go to the documentation of this file.
1 
4 // C++ headers
5 #include <string>
6 
7 // application
8 #include <application/application.hpp>
9 #include <application/exceptions.hpp>
10 
11 // Athena++
12 #include <athena/mesh/mesh.hpp>
13 
14 // utils
15 #include <utils/vectorize.hpp>
16 
17 // n-body
18 #include "particle_data.hpp"
19 #include "particles.hpp"
20 
21 // constructor, initializes data structure and parameters
22 ParticleBase::ParticleBase(MeshBlock *pmb, std::string name)
23  : NamedGroup(name), linked_flag_(false), pmy_block_(pmb) {
24  Application::Logger app("n-body");
25  app->Log("Initialize ParticleBase");
26 
27  int nc1 = pmb->ncells1, nc2 = pmb->ncells2, nc3 = pmb->ncells3;
28 
29  weight.NewAthenaArray(nc3, nc2, nc1);
30  charge.NewAthenaArray(nc3, nc2, nc1);
31  pd_in_cell_.NewAthenaArray(nc3, nc2, nc1);
32 }
33 
35  Application::Logger app("n-body");
36  app->Log("Destroy ParticleBase");
37 }
38 
39 AllParticles ParticlesFactory::Create(MeshBlock *pmb, ParameterInput *pin) {
40  AllParticles all_particles;
41 
42  std::string str = pin->GetOrAddString("particles", "particles", "");
43  auto particle_names = Vectorize<std::string>(str.c_str());
44 
45  for (auto const &name : particle_names) {
46  if (name == "2pcp") {
47  all_particles.push_back(std::make_shared<ParticleBase>(pmb, name));
48  } else if (name == "scp") {
49  all_particles.push_back(std::make_shared<ParticleBase>(pmb, name));
50  } else {
51  throw NotImplementedError("Particle '" + name + "' unrecognized.");
52  }
53  }
54 
55  return all_particles;
56 }
57 
58 namespace ParticlesHelper {
59 
60 ParticlePtr find_particle(AllParticles const &pts, std::string name) {
61  for (auto &pt : pts) {
62  if (pt->GetName() == name) return pt;
63  }
64  return nullptr;
65 }
66 
67 } // namespace ParticlesHelper
AthenaArray< ParticleData * > pd_in_cell_
Definition: particles.hpp:75
virtual ~ParticleBase()
Definition: particles.cpp:34
AthenaArray< Real > charge
Definition: particles.hpp:42
AthenaArray< Real > weight
mesh data container
Definition: particles.hpp:42
ParticleBase(MeshBlock *pmb, std::string name)
Definition: particles.cpp:22
static AllParticles Create(MeshBlock *pmb, ParameterInput *pin)
Definition: particles.cpp:39
ParticlePtr find_particle(AllParticles const &pts, std::string name)
Definition: particles.cpp:60
std::shared_ptr< ParticleBase > ParticlePtr
Definition: particles.hpp:85
std::vector< ParticlePtr > AllParticles
Definition: particles.hpp:86