Canoe
Comprehensive Atmosphere N' Ocean Engine
particle_data.cpp
Go to the documentation of this file.
1 
4 // C/C++ headers
5 #include <iostream>
6 
7 // Athena++
8 #include <athena/mesh/mesh.hpp>
9 
10 // canoe
11 #include <configure.hpp>
12 
13 // exchanger
15 
16 // nbody
17 #include "particle_data.hpp"
18 #include "particles.hpp"
19 
20 std::ostream& operator<<(std::ostream& os, ParticleData const& pt) {
21  os << "pid: " << pt.pid << ", tid: " << pt.tid << std::endl
22  << "time: " << pt.time << ", weight: " << pt.weight
23  << ", charge: " << pt.charge << std::endl
24  << "x1: " << pt.x1 << ", v1: " << pt.v1 << ", a1: " << pt.a1 << std::endl
25  << "x2: " << pt.x2 << ", v2: " << pt.v2 << ", a2: " << pt.a2 << std::endl
26  << "x3: " << pt.x3 << ", v3: " << pt.v3 << ", a3: " << pt.a3 << std::endl;
27  os << "extra real data: ";
28  for (int i = 0; i < NREAL_PARTICLE_DATA; ++i) os << pt.rr[i] << ", ";
29  os << std::endl;
30 
31  os << "extra integer data: ";
32  for (int i = 0; i < NREAL_PARTICLE_DATA; ++i) os << pt.ii[i] << ", ";
33  os << std::endl;
34 
35  return os;
36 }
37 
38 namespace ParticlesHelper {
39 
40 bool check_in_meshblock(ParticleData const& pd, MeshBlock const* pmb) {
41  auto pm = pmb->pmy_mesh;
42 
43  bool inblock_x1 =
44  (pd.x1 > pmb->block_size.x1min) && (pd.x1 < pmb->block_size.x1max);
45  bool inblock_x2 =
46  (pd.x2 > pmb->block_size.x2min) && (pd.x2 < pmb->block_size.x2max);
47  bool inblock_x3 =
48  (pd.x3 > pmb->block_size.x3min) && (pd.x3 < pmb->block_size.x3max);
49 
50  return inblock_x1 && (!pm->f2 || inblock_x2) && (!pm->f3 || inblock_x3);
51 }
52 
53 #ifdef MPI_PARALLEL
54 #include <mpi.h>
55 
57  int counts[3] = {1, 2 + NINT_PARTICLE_DATA, 8 + NREAL_PARTICLE_DATA};
58  MPI_Datatype types[3] = {MPI_AINT, MPI_INT, MPI_ATHENA_REAL};
59  MPI_Aint disps[3] = {offsetof(ParticleData, next),
60  offsetof(ParticleData, pid),
61  offsetof(ParticleData, time)};
62 
63  MPI_Type_create_struct(3, counts, disps, types,
65  MPI_Type_commit(&MessageTraits<ParticleBase>::mpi_type);
66 }
67 
70 }
71 
72 #else // NOT_MPI_PARALLEL
73 
76 
77 #endif // MPI_PARALLEL
78 
79 } // namespace ParticlesHelper
void commit_mpi_particle_data()
void free_mpi_particle_data()
bool check_in_meshblock(ParticleData const &pd, MeshBlock const *pmb)
std::ostream & operator<<(std::ostream &os, ParticleData const &pt)
Traits class providing Message information for class T.
std::array< Real, NREAL_PARTICLE_DATA > rr
extra real data
Real v1
velocities
int pid
particle id, type id
Real x1
positions
Real time
time instantiated, weight and charge
Real a1
accelerations
std::array< int, NINT_PARTICLE_DATA > ii
extra integer data