FML
Loading...
Searching...
No Matches
FML::TRIANGULATION::WatershedBasin< T, NDIM > Struct Template Reference

This is a general binning class for doing watershed based on [quantity] (typically volume) When we bin particles to the watershed basins we compute stuff based on what is in this class. More...

#include <WatershedBinning.h>

Public Member Functions

void init (double *pos)
 
void set_pos_circ (const double *pos)
 
void set_leak_quantity (double q)
 
void add_particle (T *p, double quantity)
 
void merge (const WatershedBasin &other)
 
void finalize ()
 

Data Fields

double pos_min [NDIM]
 
double pos_circ [NDIM]
 
double quantity_leak {0.0}
 
double pos_barycenter [NDIM]
 
double volume {0.0}
 
double volume_min {0.0}
 
double density_min {0.0}
 
double mass {0.0}
 
double mean_quantity {0.0}
 
int ningroup {0}
 

Detailed Description

template<class T, int NDIM>
struct FML::TRIANGULATION::WatershedBasin< T, NDIM >

This is a general binning class for doing watershed based on [quantity] (typically volume) When we bin particles to the watershed basins we compute stuff based on what is in this class.

Definition at line 16 of file WatershedBinning.h.

Member Function Documentation

◆ add_particle()

template<class T , int NDIM>
void FML::TRIANGULATION::WatershedBasin< T, NDIM >::add_particle ( T * p,
double quantity )
inline

Definition at line 56 of file WatershedBinning.h.

56 {
57 double curmass = 1.0;
58 if constexpr (FML::PARTICLE::has_get_mass<T>()) {
59 curmass = FML::PARTICLE::GetMass(*p);
60 }
61 double curvolume = 1.0;
62 if constexpr (FML::PARTICLE::has_get_volume<T>()) {
63 curvolume = FML::PARTICLE::GetVolume(*p);
64 }
65
66 auto * pos = FML::PARTICLE::GetPos(*p);
67 for (int idim = 0; idim < NDIM; idim++) {
68 double dx = pos[idim] - pos_min[idim];
69 if (dx > 0.5)
70 dx -= 1.0;
71 if (dx < -0.5)
72 dx += 1.0;
73 // pos_barycenter[idim] += dx;
74 pos_barycenter[idim] += dx * curvolume;
75 }
76 if (curvolume < volume_min)
77 volume_min = curvolume;
78 double d = curmass / curvolume;
79 if (d < density_min)
80 density_min = d;
81 volume += curvolume;
82 mass += curmass;
83 mean_quantity += quantity;
84 ningroup++;
85 }
const int NDIM
get_vel constexpr double * GetPos(...)
set_volume constexpr double GetVolume(Args &... args)
set_mass constexpr double GetMass(Args &... args)

◆ finalize()

template<class T , int NDIM>
void FML::TRIANGULATION::WatershedBasin< T, NDIM >::finalize ( )
inline

Definition at line 106 of file WatershedBinning.h.

106 {
107 if (ningroup == 0 or volume <= 0.0)
108 return;
109 for (int idim = 0; idim < NDIM; idim++) {
110 double x = pos_min[idim] + pos_barycenter[idim] / volume;
111 if (x < 0)
112 x += 1.0;
113 if (x >= 1.0)
114 x -= 1.0;
115 pos_barycenter[idim] = x;
116 }
117 mean_quantity /= double(ningroup);
118 }

◆ init()

template<class T , int NDIM>
void FML::TRIANGULATION::WatershedBasin< T, NDIM >::init ( double * pos)
inline

Definition at line 31 of file WatershedBinning.h.

31 {
32 for (int idim = 0; idim < NDIM; idim++) {
33 pos_min[idim] = pos[idim];
34 pos_circ[idim] = pos[idim];
35 pos_barycenter[idim] = 0.0;
36 }
37 density_min = 1e100;
38 volume_min = 1e100;
39 volume = 0;
40 mass = 0;
41 mean_quantity = 0;
42 ningroup = 0;
43 }

◆ merge()

template<class T , int NDIM>
void FML::TRIANGULATION::WatershedBasin< T, NDIM >::merge ( const WatershedBasin< T, NDIM > & other)
inline

Definition at line 88 of file WatershedBinning.h.

88 {
89 if (other.ningroup == 0)
90 return;
91 for (int idim = 0; idim < NDIM; idim++) {
92 assert(pos_min[idim] == other.pos_min[idim]);
93 pos_barycenter[idim] += other.pos_barycenter[idim];
94 }
95 volume_min = std::min(volume_min, other.volume_min);
96 density_min = std::min(density_min, other.density_min);
97 volume += other.volume;
98 mass += other.mass;
99 mean_quantity += other.mean_quantity;
100 ningroup += other.ningroup;
101 }

◆ set_leak_quantity()

template<class T , int NDIM>
void FML::TRIANGULATION::WatershedBasin< T, NDIM >::set_leak_quantity ( double q)
inline

Definition at line 52 of file WatershedBinning.h.

◆ set_pos_circ()

template<class T , int NDIM>
void FML::TRIANGULATION::WatershedBasin< T, NDIM >::set_pos_circ ( const double * pos)
inline

Definition at line 46 of file WatershedBinning.h.

46 {
47 for (int idim = 0; idim < NDIM; idim++)
48 pos_circ[idim] = pos[idim];
49 }

Field Documentation

◆ density_min

template<class T , int NDIM>
double FML::TRIANGULATION::WatershedBasin< T, NDIM >::density_min {0.0}

Definition at line 25 of file WatershedBinning.h.

25{0.0};

◆ mass

template<class T , int NDIM>
double FML::TRIANGULATION::WatershedBasin< T, NDIM >::mass {0.0}

Definition at line 26 of file WatershedBinning.h.

26{0.0};

◆ mean_quantity

template<class T , int NDIM>
double FML::TRIANGULATION::WatershedBasin< T, NDIM >::mean_quantity {0.0}

Definition at line 27 of file WatershedBinning.h.

27{0.0};

◆ ningroup

template<class T , int NDIM>
int FML::TRIANGULATION::WatershedBasin< T, NDIM >::ningroup {0}

Definition at line 28 of file WatershedBinning.h.

28{0};

◆ pos_barycenter

template<class T , int NDIM>
double FML::TRIANGULATION::WatershedBasin< T, NDIM >::pos_barycenter[NDIM]

Definition at line 22 of file WatershedBinning.h.

◆ pos_circ

template<class T , int NDIM>
double FML::TRIANGULATION::WatershedBasin< T, NDIM >::pos_circ[NDIM]

Definition at line 19 of file WatershedBinning.h.

◆ pos_min

template<class T , int NDIM>
double FML::TRIANGULATION::WatershedBasin< T, NDIM >::pos_min[NDIM]

Definition at line 17 of file WatershedBinning.h.

◆ quantity_leak

template<class T , int NDIM>
double FML::TRIANGULATION::WatershedBasin< T, NDIM >::quantity_leak {0.0}

Definition at line 21 of file WatershedBinning.h.

21{0.0};

◆ volume

template<class T , int NDIM>
double FML::TRIANGULATION::WatershedBasin< T, NDIM >::volume {0.0}

Definition at line 23 of file WatershedBinning.h.

23{0.0};

◆ volume_min

template<class T , int NDIM>
double FML::TRIANGULATION::WatershedBasin< T, NDIM >::volume_min {0.0}

Definition at line 24 of file WatershedBinning.h.

24{0.0};

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