GADGET-4
io_progenitors.h
Go to the documentation of this file.
1/*******************************************************************************
2 * \copyright This file is part of the GADGET4 N-body/SPH code developed
3 * \copyright by Volker Springel. Copyright (C) 2014-2020 by Volker Springel
4 * \copyright (vspringel@mpa-garching.mpg.de) and all contributing authors.
5 *******************************************************************************/
6
12#ifndef PROGENITORS_IO_H
13#define PROGENITORS_IO_H
14
15#include "gadgetconfig.h"
16
17#ifdef MERGERTREE
18
19#include "../data/allvars.h"
20#include "../data/dtypes.h"
21#include "../data/mymalloc.h"
22#include "../fof/fof.h"
23#include "../io/hdf5_util.h"
24#include "../io/io.h"
25#include "../logs/timer.h"
26#include "../main/simulation.h"
27#include "../mergertree/mergertree.h"
28#include "../mpi_utils/mpi_utils.h"
29#include "../sort/parallel_sort.h"
30#include "../subfind/subfind.h"
31#include "../system/system.h"
32
33class progenitors_io : public IO_Def
34{
35 private:
36 mergertree *MergerTree;
37
38 public:
39 progenitors_io(mergertree *MergerTree_ptr, MPI_Comm comm, int format);
40
41 void mergertree_read_progenitors(int num);
42 void mergertree_save_progenitors(int num);
43
44 /* supplied virtual functions */
45 void fill_file_header(int writeTask, int lastTask, long long *nloc_part, long long *npart);
46 void read_file_header(const char *fname, int filenr, int readTask, int lastTask, long long *nloc_part, long long *npart,
47 int *nstart);
48 void get_datagroup_name(int grnr, char *gname);
49 void write_header_fields(hid_t);
50 void read_header_fields(const char *fname);
51 void read_increase_numbers(int type, int n_for_this_task);
52 int get_filenr_from_header(void);
53 void set_filenr_in_header(int);
54 void *get_base_address_of_structure(enum arrays array, int index);
55 int get_type_of_element(int index);
56 void set_type_of_element(int index, int type);
57
60 struct io_header
61 {
62 long long Nsubhalos;
63 long long TotNsubhalos;
64 int num_files;
65 };
66 io_header header;
67
68 int Nsubhalos;
69 long long TotNsubhalos;
70
71 private:
72 static void io_func_progsubhalonr(IO_Def *ptr, int particle, int components, void *buffer, int mode)
73 {
74 progenitors_io *thisobj = (progenitors_io *)ptr;
75
76 if(mode == 0)
77 {
78 long long *out_buffer = (long long *)buffer;
79 out_buffer[0] = thisobj->MergerTree->Progenitors[particle].ProgSubhaloNr;
80 if(out_buffer[0] == HALONR_MAX)
81 out_buffer[0] = -1;
82 }
83 else
84 {
85 long long *in_buffer = (long long *)buffer;
86 thisobj->MergerTree->Progenitors[particle].ProgSubhaloNr = in_buffer[0];
87 if(thisobj->MergerTree->Progenitors[particle].ProgSubhaloNr == -1)
88 thisobj->MergerTree->Progenitors[particle].ProgSubhaloNr = HALONR_MAX;
89 }
90 }
91
92 static void io_func_firstprogsubhalonr(IO_Def *ptr, int particle, int components, void *buffer, int mode)
93 {
94 progenitors_io *thisobj = (progenitors_io *)ptr;
95
96 if(mode == 0)
97 {
98 long long *out_buffer = (long long *)buffer;
99 out_buffer[0] = thisobj->MergerTree->Progenitors[particle].FirstProgSubhaloNr;
100 if(out_buffer[0] == HALONR_MAX)
101 out_buffer[0] = -1;
102 }
103 else
104 {
105 long long *in_buffer = (long long *)buffer;
106 thisobj->MergerTree->Progenitors[particle].FirstProgSubhaloNr = in_buffer[0];
107 if(thisobj->MergerTree->Progenitors[particle].FirstProgSubhaloNr == -1)
108 thisobj->MergerTree->Progenitors[particle].FirstProgSubhaloNr = HALONR_MAX;
109 }
110 }
111
112 static void io_func_nextdescsubhalonr(IO_Def *ptr, int particle, int components, void *buffer, int mode)
113 {
114 progenitors_io *thisobj = (progenitors_io *)ptr;
115
116 if(mode == 0)
117 {
118 long long *out_buffer = (long long *)buffer;
119 out_buffer[0] = thisobj->MergerTree->Progenitors[particle].NextDescSubhaloNr;
120 if(out_buffer[0] == HALONR_MAX)
121 out_buffer[0] = -1;
122 }
123 else
124 {
125 long long *in_buffer = (long long *)buffer;
126 thisobj->MergerTree->Progenitors[particle].NextDescSubhaloNr = in_buffer[0];
127 if(thisobj->MergerTree->Progenitors[particle].NextDescSubhaloNr == -1)
128 thisobj->MergerTree->Progenitors[particle].NextDescSubhaloNr = HALONR_MAX;
129 }
130 }
131};
132
133#endif
134
135#endif /* DESCENDANT_IO_H */
Definition: io.h:129
virtual int get_filenr_from_header(void)=0
virtual void * get_base_address_of_structure(enum arrays array, int index)=0
virtual void set_type_of_element(int index, int type)=0
virtual void read_increase_numbers(int type, int n_for_this_task)=0
virtual void fill_file_header(int writeTask, int lastTask, long long *nloc_part, long long *npart)=0
virtual void read_header_fields(const char *fname)=0
virtual void read_file_header(const char *fname, int filenr, int readTask, int lastTask, long long *nloc_part, long long *npart, int *nstart)=0
virtual void set_filenr_in_header(int)=0
virtual void write_header_fields(hid_t)=0
virtual void get_datagroup_name(int grnr, char *gname)=0
virtual int get_type_of_element(int index)=0
#define HALONR_MAX
Definition: idstorage.h:20
arrays
Definition: io.h:30