FML
Loading...
Searching...
No Matches
FML::FOF::FoFHalo< T, NDIM > Class Template Reference

This class defines how to compute the halos from the particles. More...

#include <FoFBinning.h>

Public Member Functions

constexpr int get_ndim () const
 
double * get_pos ()
 
double * get_vel ()
 
double get_halo_mass () const
 
size_t get_npart () const
 
size_t get_id () const
 
std::array< double, NDIM > get_velocity_dispersion () const
 
 FoFHalo ()=default
 
 FoFHalo (size_t _id)
 
void add (T &particle, bool periodic=true)
 Add a new particle to the FoF group.
 
void finalize (bool periodic=true)
 This method is called after all particles has been added to the halo and we can do any normalization etc we want.
 

Data Fields

size_t id {0}
 Id of the halo.
 
size_t np {0}
 Number of particles in the halo.
 
double mass {0.0}
 Mass of the halo (units is the same as those in the particles; get_mass)
 
std::array< double, NDIM > pos {}
 Center of the halo.
 
std::array< double, NDIM > vel {}
 Velocity of the halo.
 
std::array< double, NDIM > vel_rms {}
 RMS velocity of the particles in the halo (velocity dispersion per dimension) Contains <v^2> before finalizing.
 
std::vector< T * > member_particles
 

Detailed Description

template<class T, int NDIM>
class FML::FOF::FoFHalo< T, NDIM >

This class defines how to compute the halos from the particles.

If you want to compute more things then make your own class like this one and supply as template parameter to the FriendsOfFriends method.

NB: The computation of the COM has to be done incrementally: we add up the mean values as we go along instead of doing it in the end. For other quantities you can do it as you wish.

If you want access to all particles then one can add a vector of pointers to the particles, push them in this vector during add and then process them in finalize.

Definition at line 30 of file FoFBinning.h.

Constructor & Destructor Documentation

◆ FoFHalo() [1/2]

template<class T , int NDIM>
FML::FOF::FoFHalo< T, NDIM >::FoFHalo ( )
default

◆ FoFHalo() [2/2]

template<class T , int NDIM>
FML::FOF::FoFHalo< T, NDIM >::FoFHalo ( size_t _id)
inline

Definition at line 66 of file FoFBinning.h.

66{ id = _id; }

Member Function Documentation

◆ add()

template<class T , int NDIM>
void FML::FOF::FoFHalo< T, NDIM >::add ( T & particle,
bool periodic = true )
inline

Add a new particle to the FoF group.

We update the center of mass position to be that of the particles added so far.

Parameters
[in]particleThe particle we are to add to the halo
[in]periodic(Optional) Is the box periodic?

Definition at line 72 of file FoFBinning.h.

72 {
73 const double _mass = FML::PARTICLE::GetMass(particle);
74 static_assert(FML::PARTICLE::has_get_pos<T>());
75 const auto * _pos = FML::PARTICLE::GetPos(particle);
76
77 // Sanity check
78 assert_mpi(_mass > 0.0, "FoFBinning::add::Particle mass is negative or zero, this is not normal!");
79
80#ifdef STORE_MEMBERS_PTRS
81 // If you want access to all particles in finalize
82 member_particles.push_back(&particle);
83#endif
84
85 // Initialize
86 if (np == 0) {
87 for (int idim = 0; idim < NDIM; idim++) {
88 pos[idim] = 0.0;
89 vel[idim] = 0.0;
90 vel_rms[idim] = 0.0;
91 }
92 mass = 0.0;
93 }
94
95 // Update center of mass
96 std::array<double, NDIM> dx;
97 double weight = _mass / (mass + _mass);
98 for (int idim = 0; idim < NDIM; idim++) {
99 dx[idim] = _pos[idim] - pos[idim];
100 if (periodic) {
101 if (dx[idim] < -0.5)
102 dx[idim] += 1;
103 if (dx[idim] >= 0.5)
104 dx[idim] -= 1;
105 }
106 pos[idim] += dx[idim] * weight;
107 if (periodic) {
108 if (pos[idim] < 0.0)
109 pos[idim] += 1;
110 if (pos[idim] >= 1.0)
111 pos[idim] -= 1;
112 }
113 }
114
115 // Add velocity if particle has velocity
116 if constexpr (FML::PARTICLE::has_get_vel<T>()) {
117 auto _vel = FML::PARTICLE::GetVel(particle);
118 for (int idim = 0; idim < NDIM; idim++) {
119 vel[idim] = vel[idim] * (1 - weight) + _vel[idim] * weight;
120 vel_rms[idim] = vel_rms[idim] * (1 - weight) + _vel[idim] * _vel[idim] * weight;
121 }
122 }
123
124 // Update this last
125 np++;
126 mass += _mass;
127 }
const int NDIM
double mass
Mass of the halo (units is the same as those in the particles; get_mass)
Definition FoFBinning.h:37
std::array< double, NDIM > pos
Center of the halo.
Definition FoFBinning.h:39
std::vector< T * > member_particles
Definition FoFBinning.h:62
size_t np
Number of particles in the halo.
Definition FoFBinning.h:35
std::array< double, NDIM > vel_rms
RMS velocity of the particles in the halo (velocity dispersion per dimension) Contains <v^2> before f...
Definition FoFBinning.h:44
std::array< double, NDIM > vel
Velocity of the halo.
Definition FoFBinning.h:41
get_vel constexpr double * GetPos(...)
constexpr double * GetVel(...)
set_mass constexpr double GetMass(Args &... args)
double periodic(double d)

◆ finalize()

template<class T , int NDIM>
void FML::FOF::FoFHalo< T, NDIM >::finalize ( bool periodic = true)
inline

This method is called after all particles has been added to the halo and we can do any normalization etc we want.

Parameters
[in]periodic(Optional) Is the box periodic?

Definition at line 132 of file FoFBinning.h.

132 {
133
134 // Velocity dispersion. v_rms contains <v^2> at this point (<v^2> - <v>^2 can be slightly negative from
135 // round-off when all the particles have (nearly) the same velocity)
136 for (int idim = 0; idim < NDIM; idim++)
137 vel_rms[idim] = std::sqrt(std::max(0.0, vel_rms[idim] - vel[idim] * vel[idim]));
138
139#ifdef STORE_MEMBERS_PTRS
140 // Free up memory
141 member_particles = std::vector<T *>();
142#endif
143 }

◆ get_halo_mass()

template<class T , int NDIM>
double FML::FOF::FoFHalo< T, NDIM >::get_halo_mass ( ) const
inline

Definition at line 54 of file FoFBinning.h.

54{ return mass; };

◆ get_id()

template<class T , int NDIM>
size_t FML::FOF::FoFHalo< T, NDIM >::get_id ( ) const
inline

Definition at line 57 of file FoFBinning.h.

57{ return id; };
size_t id
Id of the halo.
Definition FoFBinning.h:33

◆ get_ndim()

template<class T , int NDIM>
int FML::FOF::FoFHalo< T, NDIM >::get_ndim ( ) const
inlineconstexpr

Definition at line 47 of file FoFBinning.h.

47{ return NDIM; }

◆ get_npart()

template<class T , int NDIM>
size_t FML::FOF::FoFHalo< T, NDIM >::get_npart ( ) const
inline

Definition at line 56 of file FoFBinning.h.

56{ return np; };

◆ get_pos()

template<class T , int NDIM>
double * FML::FOF::FoFHalo< T, NDIM >::get_pos ( )
inline

Definition at line 48 of file FoFBinning.h.

48{ return pos.data(); }

◆ get_vel()

template<class T , int NDIM>
double * FML::FOF::FoFHalo< T, NDIM >::get_vel ( )
inline

Definition at line 49 of file FoFBinning.h.

49{ return vel.data(); }

◆ get_velocity_dispersion()

template<class T , int NDIM>
std::array< double, NDIM > FML::FOF::FoFHalo< T, NDIM >::get_velocity_dispersion ( ) const
inline

Definition at line 58 of file FoFBinning.h.

58{ return vel_rms; };

Field Documentation

◆ id

template<class T , int NDIM>
size_t FML::FOF::FoFHalo< T, NDIM >::id {0}

Id of the halo.

Definition at line 33 of file FoFBinning.h.

33{0};

◆ mass

template<class T , int NDIM>
double FML::FOF::FoFHalo< T, NDIM >::mass {0.0}

Mass of the halo (units is the same as those in the particles; get_mass)

Definition at line 37 of file FoFBinning.h.

37{0.0};

◆ member_particles

template<class T , int NDIM>
std::vector<T *> FML::FOF::FoFHalo< T, NDIM >::member_particles

Definition at line 62 of file FoFBinning.h.

◆ np

template<class T , int NDIM>
size_t FML::FOF::FoFHalo< T, NDIM >::np {0}

Number of particles in the halo.

Definition at line 35 of file FoFBinning.h.

35{0};

◆ pos

template<class T , int NDIM>
std::array<double, NDIM> FML::FOF::FoFHalo< T, NDIM >::pos {}

Center of the halo.

Definition at line 39 of file FoFBinning.h.

39{};

◆ vel

template<class T , int NDIM>
std::array<double, NDIM> FML::FOF::FoFHalo< T, NDIM >::vel {}

Velocity of the halo.

Definition at line 41 of file FoFBinning.h.

41{};

◆ vel_rms

template<class T , int NDIM>
std::array<double, NDIM> FML::FOF::FoFHalo< T, NDIM >::vel_rms {}

RMS velocity of the particles in the halo (velocity dispersion per dimension) Contains <v^2> before finalizing.

Definition at line 44 of file FoFBinning.h.

44{};

The documentation for this class was generated from the following file: