19#include "../data/simparticles.h"
20#include "../fof/fof.h"
21#include "../subfind/subfind.h"
23#define NUM_MOST_BOUND_PARTICLES_USED_FOR_TRACKING 16
25class mergertree :
public setcomm
39 void mergertree_determine_descendants_on_the_fly(
int num);
40 void descendants_in_postprocessing(
int num);
41 void halotrees_construct(
int lastsnapnr);
42 void get_previous_size_of_subhalo_for_each_particle(
int num);
44 unsigned long long CurrTotNsubhalos;
45 unsigned long long PrevTotNsubhalos;
62 typedef fof<simparticles>::treehalo_t treehalo_type;
65 struct treehalo_ids_type
70 treehalo_ids_type *HaloIDdata;
72 static bool compare_HaloIDdata_ID(
const treehalo_ids_type &a,
const treehalo_ids_type &b)
74 return a.SubMostBoundID < b.SubMostBoundID;
80 long long PrevSubhaloNr;
81 long long DescSubhaloNr;
83 long long FirstDescSubhaloNr;
84 long long NextProgSubhaloNr;
89 desc_list *Descendants;
96 long long ProgSubhaloNr;
98 long long FirstProgSubhaloNr;
99 long long NextDescSubhaloNr;
101 long long MainProgSubhaloNr;
103 long long FileOffset;
107 prog_list *Progenitors;
109 struct mergertree_particle_data
113 long long FileOffset;
115 long long PrevGroupNr;
116 long long PrevSubhaloNr;
124 unsigned short RankInSubhalo;
125 unsigned short PrevRankInSubhalo;
127 mergertree_particle_data *MtrP, *PrevMtrP;
136 treelink_data *TreeLink;
141 void mergertree_determine_descendants(
int num);
142 void mergertree_determine_descendants_postproc(
int num);
143 void mergertree_save_progenitors(
int num);
144 void mergertree_read_progenitors(
int num);
145 void desc_subfind_init_io_fields(
void);
146 void prog_subfind_init_io_fields(
void);
147 void treelink_subfind_init_io_fields(
void);
148 void mergertree_read_snap_ids(
int num);
149 void mergertree_match_ids_of_previous_snap(
void);
150 void mrgtr_init_io_fields(
void);
151 int halotrees_join_via_descendants(
int num);
152 int halotrees_join_via_progenitors(
int num);
153 void halotrees_assign_global_subhalonr_and_groupnr(
void);
154 void halotrees_load_catalogues(fof<simparticles> *FoF);
155 void halotrees_initial_treeassignment(
void);
156 void halotrees_assign_new_treeindices(
void);
157 void halotrees_save_trees(
void);
158 void halotrees_save_subhalo_treelinks(
void);
159 void halotrees_collect_treehalos(
void);
160 void halotrees_link_trees(
void);
161 void halotrees_propagate_max_branch_length_descendants(
int num);
162 void halotrees_propagate_max_branch_length_progenitors(
int num);
163 void halotrees_determine_mainprogenitor(
void);
164 void halotrees_reshuffle(
char **ptr,
size_t len,
int ncurrent,
int ntarget);
165 void halotrees_remap_treepointers(
void);
166 void mergertree_assign_group_numbers(fof<simparticles> *FoF);
167 void trees_subfind_init_io_fields(
void);
168 long long halotrees_join_trees_via_fof_or_mostboundid_bridges(
int mode);
169 void mergertree_match_ids_of_current_snap(
void);
171 void mergertree_chain_up_progenitors_with_same_descendant(
void);
172 void mergertree_set_first_progenitor_with_same_descendant(
void);
173 void mergertree_select_maximum_score_progenitors(
int nmatch);
174 void mergertree_select_maximum_score_descendants(
int nmatch);
175 int mergertree_find_matching_segments_and_scores(
void);
176 void mergertree_chain_up_descendants_with_same_progenitor(
void);
177 void mergertree_set_first_descendant_with_same_progenitor(
void);
179 struct subhalo_extension
182 int TreeFirstProgenitor;
183 int TreeNextProgenitor;
184 int TreeFirstHaloInFOFgroup;
185 int TreeNextHaloInFOFgroup;
187 int TreeFirstDescendant;
188 int TreeNextDescendant;
189 int TreeMainProgenitor;
191 long long MaxLenProgBranch;
198 static bool compare_MtrP_FileOffset(
const mergertree_particle_data &a,
const mergertree_particle_data &b)
200 return a.FileOffset < b.FileOffset;
203 static bool compare_MtrP_SubhaloNr(
const mergertree_particle_data &a,
const mergertree_particle_data &b)
205 if(a.PrevSubhaloNr < b.PrevSubhaloNr)
207 if(a.PrevSubhaloNr > b.PrevSubhaloNr)
210 if(a.PrevRankInSubhalo < b.PrevRankInSubhalo)
212 if(a.PrevRankInSubhalo > b.PrevRankInSubhalo)
218 static bool compare_Group_FileOffset(
const fof<simparticles>::group_properties &a,
const fof<simparticles>::group_properties &b)
220 return a.FileOffset < b.FileOffset;
223 static bool compare_Subhalo_FileOffset(
const fof<simparticles>::subhalo_properties &a,
224 const fof<simparticles>::subhalo_properties &b)
226 return a.FileOffset < b.FileOffset;
229 static bool compare_MtrP_ID(
const mergertree_particle_data &a,
const mergertree_particle_data &b) {
return a.ID < b.ID; }
231 struct assign_particle_data
234 long long PrevSubhaloNr;
240 static bool compare_AssignP_ID(
const assign_particle_data &a,
const assign_particle_data &b) {
return a.ID < b.ID; }
242 static bool compare_AssignP_Origin(
const assign_particle_data &a,
const assign_particle_data &b)
244 if(a.OriginTask < b.OriginTask)
246 if(a.OriginTask > b.OriginTask)
249 return a.OriginIndex < b.OriginIndex;
272 static bool mergertree_compare_PrevSubNr_NewSubNr(
const desc_partdata &a,
const desc_partdata &b)
274 if(a.PrevSubhaloNr < b.PrevSubhaloNr)
276 if(a.PrevSubhaloNr > b.PrevSubhaloNr)
279 return a.CurrSubhaloNr < b.CurrSubhaloNr;
282 static bool mergertree_compare_NewSubNr_PrevSubNr(
const desc_partdata &a,
const desc_partdata &b)
284 if(a.CurrSubhaloNr < b.CurrSubhaloNr)
286 if(a.CurrSubhaloNr > b.CurrSubhaloNr)
289 return a.PrevSubhaloNr < b.PrevSubhaloNr;
293 static bool mergertree_compare_DescSubhaloNr(
const desc_list &a,
const desc_list &b)
295 if(a.DescSubhaloNr < b.DescSubhaloNr)
297 if(a.DescSubhaloNr > b.DescSubhaloNr)
300 return a.PrevSubhaloNr < b.PrevSubhaloNr;
304 static bool mergertree_compare_ProgSubhaloNr(
const prog_list &a,
const prog_list &b)
306 if(a.ProgSubhaloNr < b.ProgSubhaloNr)
308 if(a.ProgSubhaloNr > b.ProgSubhaloNr)
311 return a.SubhaloNr < b.SubhaloNr;
314 static bool mergertree_compare_SubhaloNr(
const prog_list &a,
const prog_list &b) {
return a.SubhaloNr < b.SubhaloNr; }
317 static bool mergertree_compare_PrevSubhaloNr(
const desc_list &a,
const desc_list &b) {
return a.PrevSubhaloNr < b.PrevSubhaloNr; }
322 struct halo_catalogue
324 fof<simparticles>::group_properties *Group;
325 long long FirstGroup;
326 long long TotNgroups;
330 fof<simparticles>::subhalo_properties *Subhalo;
331 long long FirstSubhalo;
332 long long TotNsubhalos;
336 subhalo_extension *SubExt;
338 desc_list *Descendants;
339 prog_list *Progenitors;
341 halo_catalogue *Cats;
345 long long UniqueGroupNr;
346 long long OrderIndex;
357 static bool compare_tlink_GroupNr(
const tlink &a,
const tlink &b) {
return a.UniqueGroupNr < b.UniqueGroupNr; }
359 static bool compare_tlink_TreeID(
const tlink &a,
const tlink &b) {
return a.TreeID < b.TreeID; }
361 static bool compare_tlink_OrigTask_OrderIndex(
const tlink &a,
const tlink &b)
363 if(a.OrigTask < b.OrigTask)
365 if(a.OrigTask > b.OrigTask)
368 return a.OrderIndex < b.OrderIndex;
371 static bool compare_Halos_TreeID_TreeIndex(
const treehalo_type &a,
const treehalo_type &b)
373 if(a.TreeID < b.TreeID)
375 if(a.TreeID > b.TreeID)
378 return a.TreeIndex < b.TreeIndex;
381 static bool compare_Halos_UniqueGroupNr_SubhaloNr(
const treehalo_type &a,
const treehalo_type &b)
383 if(a.UniqueGroupNr < b.UniqueGroupNr)
385 if(a.UniqueGroupNr > b.UniqueGroupNr)
388 return a.SubhaloNr < b.SubhaloNr;
391 static bool compare_Desc_FileOffset(
const desc_list &a,
const desc_list &b) {
return a.FileOffset < b.FileOffset; }
393 static bool compare_Prog_FileOffset(
const prog_list &a,
const prog_list &b) {
return a.FileOffset < b.FileOffset; }
399 long long targetsubhalonr;
401 long long originsubhalonr;
405 static bool compare_data_list_subhalonnr(
const data_list &a,
const data_list &b) {
return a.targetsubhalonr < b.targetsubhalonr; }
410 int new_treeindexptr;
411 long long targetsubhalonr;
412 long long originsubhalonr;
418 static bool compare_remap_data_subhalonr(
const remap_data &a,
const remap_data &b) {
return a.targetsubhalonr < b.targetsubhalonr; }
420 static bool compare_remap_data_orig_index(
const remap_data &a,
const remap_data &b) {
return a.orig_index < b.orig_index; }
437 static bool compare_assign_data_treeid_origin_num_origin_task_origin_index(
const assign_data &a,
const assign_data &b)
439 if(a.treeid < b.treeid)
441 if(a.treeid > b.treeid)
444 if(a.origin_num > b.origin_num)
446 if(a.origin_num < b.origin_num)
449 if(a.origin_task < b.origin_task)
451 if(a.origin_task > b.origin_task)
454 return a.origin_index < b.origin_index;
457 static bool compare_assign_data_origin_task_origin_num_origin_index(
const assign_data &a,
const assign_data &b)
459 if(a.origin_task < b.origin_task)
461 if(a.origin_task > b.origin_task)
464 if(a.origin_num < b.origin_num)
466 if(a.origin_num > b.origin_num)
469 return a.origin_index < b.origin_index;
474 struct halotrees_data
476 long long descendantnr;
477 long long progenitornr;
485 static bool compare_halotrees_data_descendantnr(
const halotrees_data &a,
const halotrees_data &b)
487 return a.descendantnr < b.descendantnr;
490 static bool compare_halotrees_data_progenitornr(
const halotrees_data &a,
const halotrees_data &b)
492 return a.progenitornr < b.progenitornr;
495 static bool compare_halotrees_data_orig_order(
const halotrees_data &a,
const halotrees_data &b)
497 return a.orig_order < b.orig_order;
500 struct halotrees_propagate_data
502 long long DescSubhaloNr;
503 long long ProgSubhaloNr;
505 long long MaxLenProgBranch;
510 static bool compare_halotrees_propagate_data_orig_order(
const halotrees_propagate_data &a,
const halotrees_propagate_data &b)
512 return a.orig_order < b.orig_order;
515 static bool compare_halotrees_propagate_data_DescSubhaloNr(
const halotrees_propagate_data &a,
const halotrees_propagate_data &b)
517 return a.DescSubhaloNr < b.DescSubhaloNr;
520 static bool compare_halotrees_propagate_data_ProgSubhaloNr(
const halotrees_propagate_data &a,
const halotrees_propagate_data &b)
522 return a.ProgSubhaloNr < b.ProgSubhaloNr;
525 struct halotrees_firstprog_data
527 long long DescSubhaloNr;
531 static bool compare_halotrees_firstprog_data_DescSubhaloNr(
const halotrees_firstprog_data &a,
const halotrees_firstprog_data &b)
533 return a.DescSubhaloNr < b.DescSubhaloNr;
538 long long DescSubhaloNr;
546 static bool compare_sorted_list_descsubhalonr(
const descnr_data &a,
const descnr_data &b)
548 return a.DescSubhaloNr < b.DescSubhaloNr;
553 long long ProgSubhaloNr;
560 static bool compare_sorted_list_progsubhalonr(
const prognr_data &a,
const prognr_data &b)
562 return a.ProgSubhaloNr < b.ProgSubhaloNr;
565 void halotrees_select_interior_min_newtreeid(
int mode, tlink *treehalos,
long long totnsubs);