PFASST++
particle_impl.hpp
Go to the documentation of this file.
1 #include "particle.hpp"
2 #include "particle_util.hpp"
3 
4 #include <cassert>
5 #include <iomanip>
6 using namespace std;
7 
8 namespace pfasst
9 {
10  namespace examples
11  {
12  namespace boris
13  {
14  template<typename T>
15  inline el::base::type::ostream_t& operator<<(el::base::type::ostream_t& os, const vector<T>& vec) {
16  os << "[";
17  for (auto iter = vec.cbegin(); iter != vec.cend(); ++iter) {
18  os << *iter;
19  if (iter != vec.cend() - 1) { os << " "; }
20  }
21  os << "]";
22  return os;
23  }
24 
25 
26  template<typename precision>
28  : Particle(dim, precision(1.0), precision(1.0))
29  {}
30 
31  template<typename precision>
32  Particle<precision>::Particle(const size_t dim, const precision charge, const precision mass)
33  : _dim(dim)
34  , _charge(charge)
35  , _mass(mass)
36  , _pos(dim)
37  , _vel(dim)
38  {
39  assert(this->_pos.size() == dim);
40  assert(this->_vel.size() == dim);
41  }
42 
43  template<typename precision>
45  {}
46 
47  template<typename precision>
48  inline size_t Particle<precision>::dim() const
49  {
50  return this->_dim;
51  }
52 
53  template<typename precision>
55  {
56  return this->_pos;
57  }
58  template<typename precision>
60  {
61  return this->_pos;
62  }
63 
64  template<typename precision>
66  {
67  return this->_vel;
68  }
69  template<typename precision>
71  {
72  return this->_vel;
73  }
74 
75  template<typename precision>
76  const precision Particle<precision>::charge() const
77  {
78  return this->_charge;
79  }
80 
81  template<typename precision>
82  const precision Particle<precision>::mass() const
83  {
84  return this->_mass;
85  }
86 
87  template<typename precision>
88  const precision Particle<precision>::alpha() const
89  {
90  return this->_charge / this->_mass;
91  }
92 
93  template<typename precision>
94  void Particle<precision>::set_charge(const precision& charge)
95  {
96  this->_charge = charge;
97  }
98 
99  template<typename precision>
100  void Particle<precision>::set_mass(const precision& mass)
101  {
102  this->_mass = mass;
103  }
104 
105  template<typename precision>
106  void Particle<precision>::log(el::base::type::ostream_t& os) const
107  {
108  os << fixed << setprecision(LOG_PRECISION);
109  os << "Particle(pos=" << this->_pos << ", vel=" << this->_vel << ")";
110  os.unsetf(ios_base::floatfield);
111  }
112 
113 
114  template<typename precision>
115  inline el::base::type::ostream_t& operator<<(el::base::type::ostream_t& os, const shared_ptr<Particle<precision>>& sp_particle)
116  {
117  sp_particle->log(os);
118  return os;
119  }
120  } // ::pfasst::examples::boris
121  } // ::pfasst::examples
122 } // ::pfasst
ParticleComponent< precision > & pos()
ParticleComponent< precision > & vel()
STL namespace.
void set_charge(const precision &charge)
const precision charge() const
ParticleComponent< precision > _pos
Definition: particle.hpp:49
const precision alpha() const
virtual void log(el::base::type::ostream_t &os) const
vector< precision > ParticleComponent
Definition: particle.hpp:27
#define LOG_PRECISION
Definition: logging.hpp:192
void set_mass(const precision &mass)
const precision mass() const
ParticleComponent< precision > _vel
Definition: particle.hpp:50