32 #ifndef MCKL_CORE_PARTICLE_HPP 33 #define MCKL_CORE_PARTICLE_HPP 64 T &
state()
const {
return pptr_->state(); }
90 std::make_signed_t<typename Particle<T>::size_type>;
110 template <
typename IntType>
114 static_cast<difference_type>(this->
i()) +
115 static_cast<difference_type>(n)),
123 "Compare two ParticleIndex objects from two different particle " 126 return idx1.i() == idx2.i();
133 "Compare two ParticleIndex objects from two different particle " 136 return idx1.i() != idx2.i();
142 "Compare two ParticleIndex objects from two different particle " 145 return idx1.i() < idx2.i();
151 "Compare two ParticleIndex objects from two different particle " 154 return idx1.i() > idx2.i();
161 "Compare two ParticleIndex objects from two different particle " 164 return idx1.i() <= idx2.i();
171 "Compare two ParticleIndex objects from two different particle " 174 return idx1.i() >= idx2.i();
203 template <
typename IntType>
207 static_cast<difference_type>(idx.i()) +
208 static_cast<difference_type>(n)),
212 template <
typename IntType>
218 template <
typename IntType>
224 template <
typename IntType>
227 return idx = idx + n;
230 template <
typename IntType>
233 return idx = idx - n;
240 "Substract two ParticleIndex objects from two different " 244 static_cast<difference_type>(idx2.i());
250 template <
typename T>
262 return this->begin()->i();
278 template <
typename T>
290 : weight_(0), rng_set_(0), rng_(
Seed<
rng_type>::instance().get())
298 template <
typename... Args>
300 : state_(N,
std::forward<Args>(args)...)
311 particle.rng_set_.reset();
324 template <
typename InputIter>
327 state_.select(n, index);
354 return rng_set_[
static_cast<std::size_t
>(
i)];
360 return rng_set_[
static_cast<std::size_t
>(
i)];
372 runtime_assert<std::out_of_range>(
373 i <= size(),
"**Particle::at** index out of range");
375 return operator[](i);
407 return p1.weight_ == p2.weight_ && p1.state_ == p2.state_;
422 template <
typename T>
431 #endif // MCKL_CORE_PARTICLE_HPP std::random_access_iterator_tag iterator_category
friend difference_type operator-(const ParticleIndex &idx1, const ParticleIndex &idx2)
friend bool operator<=(const ParticleIndex &idx1, const ParticleIndex &idx2)
friend bool operator==(const Particle &p1, const Particle &p2)
const rng_type & rng(size_type i) const
Get an (parallel) RNG stream for a given particle.
Particle< T >::size_type i() const
void select(size_type n, InputIter index)
Resize by selecting according to user supplied index vector.
typename WeightTypeTrait< T >::type WeightType
Particle()
Default constructor.
friend ParticleIndex operator--(ParticleIndex &idx, int)
friend ParticleIndex operator-(const ParticleIndex &idx, IntType n)
friend bool operator>=(const ParticleIndex &idx1, const ParticleIndex &idx2)
rng_type & rng(size_type i)
Get an (parallel) RNG stream for a given particle.
rng_type & rng()
Get the (sequential) RNG used stream for resampling.
ParticleIndex< T > end()
Get a ParticleIndex<T> object for one pass the last particle.
ParticleIndex operator[](IntType n)
Subscript operator return a new index.
#define MCKL_DEFINE_TYPE_TEMPLATE_DISPATCH_TRAIT(Outer, Inner, Default)
friend ParticleIndex & operator+=(ParticleIndex &idx, IntType n)
typename RNGSetTypeTrait< T >::type RNGSetType
Particle clone() const
Clone the Particle except the RNG engines.
rng_set_type & rng_set()
Read and write access to the RNG collection object.
friend bool operator>(const ParticleIndex &idx1, const ParticleIndex &idx2)
const weight_type & weight() const
Read only access to the weight collection object.
ParticleRange< T > range(size_type ibegin, size_type iend, size_type grainsize=1)
Get a ParticleRange<T> object given a range denoted by integral values.
friend ParticleIndex & operator--(ParticleIndex &idx)
friend bool operator<(const ParticleIndex &idx1, const ParticleIndex &idx2)
Particle< T > & particle() const
friend bool operator!=(const Particle &p1, const Particle &p2)
weight_type & weight()
Read and write access to the weight collection object.
pointer operator->() const noexcept
Member selection operator returns a pointer the index itself.
typename rng_set_type::rng_type rng_type
ParticleIndex< T > begin()
Get a ParticleIndex<T> object for the first particle.
Particle(size_type N, Args &&... args)
Construct a particle system.
Particle< T > * particle_ptr() const
const state_type & state() const
Read only access to the state collection object.
Particle< T > & particle() const
ParticleRange< T > range(size_type grainsize=1)
Get a Range<ParticleItrator<T>> object of all particles.
reference operator*() const noexcept
Dereference operator returns a reference to the index itself.
friend bool operator==(const ParticleIndex &idx1, const ParticleIndex &idx2)
ParticleIndexBase(typename Particle< T >::size_type i, Particle< T > *pptr)
size_type size() const
The number of particles.
friend ParticleIndex & operator-=(ParticleIndex &idx, IntType n)
friend ParticleIndex operator+(const ParticleIndex &idx, IntType n)
ParticleIndex(typename Particle< T >::size_type i, Particle< T > *pptr)
state_type & state()
Read and write access to the state collection object.
friend bool operator!=(const ParticleIndex &idx1, const ParticleIndex &idx2)
friend ParticleIndex operator++(ParticleIndex &idx, int)
Particle< T >::size_type iend() const
A thin wrapper over a complete Particle.
bool is_equal(const float &v1, const float &v2)
const rng_type & rng() const
Get the (sequential) RNG used stream for resampling.
Particle< T >::rng_type & rng() const
const rng_set_type & rng_set() const
Read only access to the RNG collection object.
ParticleIndex< T > at(size_type i)
Get a ParticleIndex<T> object for the i-th particle.
friend ParticleIndex operator+(IntType n, const ParticleIndex &idx)
ParticleIndex< T > operator[](size_type i)
Get a ParticleIndex<T> object for the i-th particle.
RNG default seed generator.
A thin wrapper over a complete Particle.
Particle< T > * particle_ptr() const
std::make_signed_t< typename Particle< T >::size_type > difference_type
void runtime_assert(bool cond, const char *msg, bool soft=false)
Particle< T >::size_type ibegin() const
friend ParticleIndex & operator++(ParticleIndex &idx)
typename SizeTypeTrait< T >::type SizeType