15#include "gadgetconfig.h"
19#include "../data/simparticles.h"
20#include "../domain/domain.h"
21#include "../fof/foftree.h"
22#include "../gravtree/gravtree.h"
29template <
typename partset>
47 long long TotNsubhalos;
55 struct group_properties
58 long long OffsetType[
NTYPES];
85 MyFloat M_TopHat200, R_TopHat200;
90#if defined(SUBFIND_ORPHAN_TREATMENT)
94 group_properties *Group;
97 struct subhalo_properties
101 long long OffsetType[
NTYPES];
126 long long UniqueGroupNr;
127 long long FileOffset;
133#if defined(SUBFIND_ORPHAN_TREATMENT)
134 int SubhaloLenPrevMostBnd;
137 subhalo_properties *Subhalo;
139#if defined(MERGERTREE)
145 int TreeFirstProgenitor;
146 int TreeNextProgenitor;
147 int TreeFirstHaloInFOFgroup;
148 int TreeNextHaloInFOFgroup;
150 int TreeFirstDescendant;
151 int TreeNextDescendant;
152 int TreeMainProgenitor;
161 long long UniqueGroupNr;
164 subhalo_properties SubProp;
170 void fof_fof(
int num,
const char *grpcat_basename,
const char *grpcat_dirbasename,
double inner_distance);
171 double fof_get_comoving_linking_length(
void);
172 void fof_subfind_exchange(MPI_Comm Communicator);
173 void fof_subfind_write_file(
char *fname,
int writeTask,
int lastTask,
void *CommBuffer);
174 double fof_find_nearest_dmparticle(
void);
175 double fof_find_groups(
void);
176 void fof_subfind_save_groups(
int num,
const char *basename,
const char *grpcat_dirbasename);
177 void fof_subfind_init_io_fields(
void);
178 void fof_subfind_load_groups(
int num);
179 void fof_assign_group_offset(
void);
180 void fof_reorder_PS(
int *Id,
int Nstart,
int N);
189 void fof_compile_catalogue(
double inner_distance);
190 void fof_compute_group_properties(
int gr,
int start,
int len);
191 void fof_prepare_output_order(
void);
192 void fof_add_in_properties_of_group_segments(
void);
193 void fof_finish_group_properties(
void);
194 void fof_assign_group_numbers(
void);
195 void fof_get_halo_position(
MyIntPosType *intpos,
double *pos);
197#if defined(LIGHTCONE_PARTICLES_GROUPS)
198 double fof_distance_to_origin(
int i);
202 struct fof_particle_list
207#if defined(LIGHTCONE_PARTICLES_GROUPS)
208 double DistanceOrigin;
211 fof_particle_list *FOF_PList;
213 struct fof_group_list
218#if defined(LIGHTCONE_PARTICLES_GROUPS)
219 double DistanceOrigin;
222 fof_group_list *FOF_GList;
237 if(a.SubRankInGr < b.SubRankInGr)
239 if(a.SubRankInGr > b.SubRankInGr)
242 if(a.v.DM_BindingEnergy < b.v.DM_BindingEnergy)
244 if(a.v.DM_BindingEnergy > b.v.DM_BindingEnergy)
251#if defined(MERGERTREE) && defined(SUBFIND)
260 if(a.SubRankInGr < b.SubRankInGr)
262 if(a.SubRankInGr > b.SubRankInGr)
265 return a.v.DM_BindingEnergy < b.v.DM_BindingEnergy;
280 static bool fof_compare_FOF_PList_MinID(
const fof_particle_list &a,
const fof_particle_list &b)
282 return a.MinID.get() < b.MinID.get();
285 static bool fof_compare_FOF_GList_MinID(
const fof_group_list &a,
const fof_group_list &b) {
return a.MinID.get() < b.MinID.get(); }
287 static bool fof_compare_FOF_GList_MinIDTask(
const fof_group_list &a,
const fof_group_list &b) {
return a.MinIDTask < b.MinIDTask; }
289 static bool fof_compare_Group_Len_MinID_DiffOriginTaskMinIDTask(
const group_properties &a,
const group_properties &b)
296 if(a.MinID < b.MinID)
298 if(a.MinID > b.MinID)
301 return labs(a.OriginTask - a.MinIDTask) < labs(b.OriginTask - b.MinIDTask);
304 static bool fof_compare_Group_OriginTask_MinID(
const group_properties &a,
const group_properties &b)
306 if(a.OriginTask < b.OriginTask)
308 if(a.OriginTask > b.OriginTask)
311 return a.MinID < b.MinID;
317 static inline bool fof_compare_Group_GroupNr(
const group_properties &a,
const group_properties &b) {
return a.GroupNr < b.GroupNr; }
319 static bool fof_compare_Group_MinID(
const group_properties &a,
const group_properties &b) {
return a.MinID < b.MinID; }
321 static bool fof_compare_Group_MinIDTask(
const group_properties &a,
const group_properties &b) {
return a.MinIDTask < b.MinIDTask; }
326 unsigned char *ProcessedFlag;
328 unsigned long long GroupNr;
333 int SubNTask, SubThisTask;
336 int NprocsCollective;
337 int MaxSerialGroupLen;
339 void subfind_density_hsml_guess(
void);
340 void subfind_find_subhalos(
int num,
const char *basename,
const char *grpcat_dirbasename);
349 static bool subfind_compare_dist_rotcurve(
const sort_r2list &a,
const sort_r2list &b) {
return a.r < b.r; }
351 double subfind_density(
void);
352 double subfind_overdensity(
void);
353 double subfind_get_overdensity_value(
int type,
double ascale);
354 void subfind_save_final(
int num,
const char *basename,
const char *grpcat_dirbasename);
357 void subfind_potential_compute(
domain<partset> *SubDomain,
int num,
int *d);
358 void subfind_find_linkngb(
domain<partset> *SubDomain,
int num,
int *list);
359 void subfind_find_nearesttwo(
domain<partset> *SubDomain,
int num,
int *list);
360 void subfind_redetermine_groupnr(
void);
362 void subfind_process_groups_serially(
void);
363 void subfind_distribute_particles(MPI_Comm Communicator);
364 void subfind_distribute_groups(
void);
365 double subfind_get_particle_balance(
void);
366 void subfind_assign_subhalo_offsettype(
void);
367 void subfind_match_ids_of_previously_most_bound_ids(partset *Tp);
369 double subfind_locngb_treefind(
MyDouble xyz[3],
int desngb,
double hguess);
370 int subfind_unbind(
domain<partset> *D, MPI_Comm Communicator,
int *unbind_list,
int len);
372 int subfind_determine_sub_halo_properties(
int *d,
int num, subhalo_properties *subhalo, MPI_Comm Communicator);
376 struct proc_assign_data
383 proc_assign_data *ProcAssign;
403 int rank, subnr, parent;
416 coll_cand_dat *coll_candidates;
425 static inline bool subfind_compare_submp_GroupNr_DM_Density(
const submp_data &a,
const submp_data &b)
428 if(a.GroupNr < b.GroupNr)
430 if(a.GroupNr > b.GroupNr)
433 return (a.DM_Density > b.DM_Density);
435 return a.GroupNr < b.GroupNr;
439 static inline bool subfind_compare_binding_energy(
const double &a,
const double &b) {
return a > b; }
441 static inline bool subfind_compare_potential(
const double &a,
const double &b) {
return a < b; }
443 static inline bool subfind_compare_Subhalo_GroupNr_SubRankInGr(
const subhalo_properties &a,
const subhalo_properties &b)
445 if(a.GroupNr < b.GroupNr)
447 if(a.GroupNr > b.GroupNr)
450 return a.SubRankInGr < b.SubRankInGr;
453 static inline bool subfind_compare_procassign_GroupNr(
const proc_assign_data &a,
const proc_assign_data &b)
455 return a.GroupNr < b.GroupNr;
459 long long count_decisions;
460 long long count_different_decisions;
462 struct sort_density_data
471 sort_density_data *sd;
480 void subfind_col_find_coll_candidates(
long long totgrouplen);
482 void subfind_poll_for_requests(
void);
488 void subfind_distlinklist_add_particle(
location index);
489 void subfind_distlinklist_add_bound_particles(
location index,
int nsub);
490 void subfind_distlinklist_mark_particle(
location index,
int target,
int submark);
501 void subfind_get_factors(
double &fac_vel_to_phys,
double &fac_hubbleflow,
double &fac_comov_to_phys);
504 void subfind_unbind_independent_ones(
domain<partset> *SingleDomain,
int count);
505 double subfind_vel_to_phys_factor(
void);
507 void subfind_collective_printf(
const char *fmt, ...)
509 if(SubNTask > 1 && SubThisTask == 0)
518 static bool subfind_compare_densities(
const sort_density_data &a,
const sort_density_data &b)
520 return a.density > b.density;
525 return a.
u.s.
u.DM_Density > b.
u.s.
u.DM_Density;
530 if(a.
u.s.origintask < b.
u.s.origintask)
532 if(a.
u.s.origintask > b.
u.s.origintask)
535 return a.
u.s.originindex < b.
u.s.originindex;
538 static bool subfind_compare_coll_candidates_subnr(
const coll_cand_dat &a,
const coll_cand_dat &b) {
return a.subnr < b.subnr; }
540 static bool subfind_compare_coll_candidates_nsubs(
const coll_cand_dat &a,
const coll_cand_dat &b) {
return a.nsub < b.nsub; }
542 static bool subfind_compare_coll_candidates_boundlength(
const coll_cand_dat &a,
const coll_cand_dat &b)
544 if(a.bound_length > b.bound_length)
546 if(a.bound_length < b.bound_length)
549 return a.rank < b.rank;
552 static bool subfind_compare_coll_candidates_rank(
const coll_cand_dat &a,
const coll_cand_dat &b)
558 return a.len > b.len;
561 static bool subfind_compare_PPS(
const PPS_data &a,
const PPS_data &b) {
return a.submark < b.submark; }
569 int count_cand, max_coll_candidates;
583 static bool subfind_compare_as_density(
const sort_as_data &a,
const sort_as_data &b)
585 return a.density > b.density;
588 static bool subfind_compare_as_origin(
const sort_as_data &a,
const sort_as_data &b)
590 return a.origin < b.origin;
600 static bool subfind_hbt_compare_pcand_subhalonr(
const hbt_pcand_t &a,
const hbt_pcand_t &b) {
return a.SubhaloNr < b.SubhaloNr; }
610 long long summedprevlen;
623 static bool subfind_hbt_compare_subcand_subhalonr(
const hbt_subcand_t &a,
const hbt_subcand_t &b)
625 return a.SubhaloNr < b.SubhaloNr;
628 static bool subfind_hbt_compare_subcand_len(
const hbt_subcand_t &a,
const hbt_subcand_t &b) {
return a.len < b.len; }
630 static bool subfind_hbt_compare_subcand_summedprevlen(
const hbt_subcand_t &a,
const hbt_subcand_t &b)
632 return a.summedprevlen < b.summedprevlen;
644 static bool subfind_hbt_compare_subhalolist_len(
const hbt_subhalo_t &a,
const hbt_subhalo_t &b) {
return a.Len > b.Len; }
646 static bool subfind_hbt_compare_subhalolist_thistask_thisindex(
const hbt_subhalo_t &a,
const hbt_subhalo_t &b)
649 if(a.ThisTask < b.ThisTask)
651 if(a.ThisTask > b.ThisTask)
654 return a.ThisIndex < b.ThisIndex;
657 static bool subfind_hbt_compare_subhalolist_prevsubhalonr(
const hbt_subhalo_t &a,
const hbt_subhalo_t &b)
659 return a.SubhaloNr < b.SubhaloNr;
665inline bool is_type_primary_link_type(
int type)
673inline bool is_type_secondary_link_type(
int type)
#define FOF_PRIMARY_LINK_TYPES
#define FOF_SECONDARY_LINK_TYPES