MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
petaio.h
Go to the documentation of this file.
1 #ifndef PETAIO_H
2 #define PETAIO_H
3 
4 #include <mpi.h>
5 #include "bigfile.h"
6 #include "utils/paramset.h"
7 #include "partmanager.h"
8 #include "slotsmanager.h"
9 #include "cosmology.h"
10 #include "physconst.h"
11 
12 /* Struct to store information written to each snapshot header. */
14 {
15  /* Local particle counts to be read onto this processor.*/
16  int64_t NLocal[6];
17  /* Total particle counts in this snapshot*/
18  int64_t NTotal[6];
19  /* Total particle counts initially*/
20  int64_t NTotalInit[6];
21  /* Average masses*/
22  double MassTable[6];
23  /* Initial time of simulation*/
24  double TimeIC;
25  /* Time of this snapshot*/
26  double TimeSnapshot;
27  /* Box size*/
28  double BoxSize;
29  /* Unit scales.*/
31  double UnitMass_in_g;
33  /* Number of k values to use for the neutrinos.*/
35 };
36 
37 /* Store parameters for unit conversions
38  * on write*/
40 {
41  double atime;
42  double hubble;
43 };
44 
45 typedef void (*property_getter) (int i, void * result, void * baseptr, void * slotptr, const struct conversions * params);
46 typedef void (*property_setter) (int i, void * target, void * baseptr, void * slotptr, const struct conversions * params);
47 typedef int (*petaio_selection) (int i);
48 
49 typedef struct IOTableEntry {
50  int zorder;
51  char name[64];
52  int ptype;
53  char dtype[8];
54  int items;
55  int required;
59 
60 struct IOTable {
62  int used;
63  int allocated;
64 };
65 
66 #define PTYPE_FOF_GROUP 1024
67 
68 /* Get the full path for a snapshot number. String returned must be freed.*/
69 char * petaio_get_snapshot_fname(int num, const char * OutputDir);
70 /* Populate an IOTable with the default set of blocks to read or write.*/
71 void register_io_blocks(struct IOTable * IOTable, int WriteGroupID, int MetalReturnOn);
72 /* Write (but don't read) some extra output blocks useful for debugging the particle structure*/
74 /* Free the entries in the IOTable.*/
75 void destroy_io_blocks(struct IOTable * IOTable);
76 
78 int GetUsePeculiarVelocity(void);
79 void petaio_init();
80 void petaio_alloc_buffer(BigArray * array, IOTableEntry * ent, int64_t npartLocal);
81 void petaio_build_buffer(BigArray * array, IOTableEntry * ent, const int * selection, const int NumSelection, struct particle_data * Parts, struct slots_manager_type * SlotsManager, struct conversions * conv);
82 void petaio_readout_buffer(BigArray * array, IOTableEntry * ent, struct conversions * conv, struct part_manager_type * PartManager, struct slots_manager_type * SlotsManager);
83 void petaio_destroy_buffer(BigArray * array);
84 
85 void petaio_save_block(BigFile * bf, const char * blockname, BigArray * array, int verbose);
86 int petaio_read_block(BigFile * bf, const char * blockname, BigArray * array, int required);
87 
88 void petaio_save_snapshot(const char * fname, struct IOTable * IOTable, int verbose, const double atime, const Cosmology * CP);
89 void petaio_read_snapshot(int num, const char * OutputDir, Cosmology * CP, struct header_data * header, struct part_manager_type * PartManager, struct slots_manager_type * SlotsManager, MPI_Comm Comm);
90 /* Returns a header struct. Note that this may also change the cosmology values in CP, if those are different from the ones in the parameter file*/
91 struct header_data petaio_read_header(int num, const char * OutputDir, Cosmology * CP);
92 
93 void
94 petaio_build_selection(int * selection,
95  int * ptype_offset,
96  int * ptype_count,
97  const struct particle_data * Parts,
98  const int NumPart,
99  int (*select_func)(int i, const struct particle_data * Parts)
100  );
101 /*
102  * Declares a io block with name (literal, not a string)
103  *
104  * will use GT ## name and PT ## name for getter and putter.
105  * these functions shall be declared in the module IO_REG is called.
106  *
107  * SIMPLE_GETTER defines a simple getter reading property from global particle
108  * arrays.
109  *
110  * IO_REG_TYPE declares an io block which has a type-specific property setter.
111  * IO_REG_WRONLY declares an io block which is written, but is not read on snapshot load.
112  * */
113 #define IO_REG(name, dtype, items, ptype, IOTable) \
114  io_register_io_block(# name, dtype, items, ptype, (property_getter) GT ## name , (property_setter) ST ## name, 1, IOTable)
115 #define IO_REG_TYPE(name, dtype, items, ptype, IOTable) \
116  io_register_io_block(# name, dtype, items, ptype, (property_getter) GT ## ptype ## name , (property_setter) ST ## ptype ## name, 0, IOTable)
117 #define IO_REG_WRONLY(name, dtype, items, ptype, IOTable) \
118  io_register_io_block(# name, dtype, items, ptype, (property_getter) GT ## name , NULL, 1, IOTable)
119 #define IO_REG_NONFATAL(name, dtype, items, ptype, IOTable) \
120  io_register_io_block(# name, dtype, items, ptype, (property_getter) GT ## name , (property_setter) ST ## name, 0, IOTable)
121 void io_register_io_block(const char * name,
122  const char * dtype,
123  int items,
124  int ptype,
125  property_getter getter,
126  property_setter setter,
127  int required,
128  struct IOTable * IOTable
129  );
130 
131 
132 /*
133  * define a simple getter function
134  *
135  * field: for example, P[i].Pos[0].
136  * i can be used to refer to the index of the particle being read.
137  *
138  * type: a C type descr, float / double / int, it describes the
139  * expected format of the output buffer; (compiler knows the format of field)
140  *
141  * items: number of items in one property. 1 for scalars. (3 for pos, eg)
142  *
143  * stype: type of the base pointer to use
144  * */
145 #define SIMPLE_GETTER(name, field, type, items, stype) \
146 static void name(int i, type * out, void * baseptr, void * slotptr, const struct conversions * params) { \
147  int k; \
148  for(k = 0; k < items; k ++) { \
149  out[k] = *(&(((stype *)baseptr)[i].field) + k); \
150  } \
151 }
152 #define SIMPLE_SETTER(name, field, type, items, stype) \
153 static void name(int i, type * out, void * baseptr, void * slotptr, const struct conversions * params) { \
154  int k; \
155  for(k = 0; k < items; k ++) { \
156  *(&(((stype *)baseptr)[i].field) + k) = out[k]; \
157  } \
158 }
159 
160 #endif
const char * name
Definition: densitykernel.c:93
struct part_manager_type PartManager[1]
Definition: partmanager.c:11
void petaio_destroy_buffer(BigArray *array)
Definition: petaio.c:557
void petaio_read_snapshot(int num, const char *OutputDir, Cosmology *CP, struct header_data *header, struct part_manager_type *PartManager, struct slots_manager_type *SlotsManager, MPI_Comm Comm)
Definition: petaio.c:255
void io_register_io_block(const char *name, const char *dtype, int items, int ptype, property_getter getter, property_setter setter, int required, struct IOTable *IOTable)
Definition: petaio.c:658
void petaio_init()
Definition: petaio.c:88
void(* property_setter)(int i, void *target, void *baseptr, void *slotptr, const struct conversions *params)
Definition: petaio.h:46
struct header_data petaio_read_header(int num, const char *OutputDir, Cosmology *CP)
Definition: petaio.c:219
void destroy_io_blocks(struct IOTable *IOTable)
Definition: petaio.c:1034
void(* property_getter)(int i, void *result, void *baseptr, void *slotptr, const struct conversions *params)
Definition: petaio.h:45
void register_io_blocks(struct IOTable *IOTable, int WriteGroupID, int MetalReturnOn)
Definition: petaio.c:909
int petaio_read_block(BigFile *bf, const char *blockname, BigArray *array, int required)
Definition: petaio.c:562
void petaio_alloc_buffer(BigArray *array, IOTableEntry *ent, int64_t npartLocal)
Definition: petaio.c:491
void petaio_save_snapshot(const char *fname, struct IOTable *IOTable, int verbose, const double atime, const Cosmology *CP)
Definition: petaio.c:151
void register_debug_io_blocks(struct IOTable *IOTable)
Definition: petaio.c:1014
char * petaio_get_snapshot_fname(int num, const char *OutputDir)
Definition: petaio.c:207
void petaio_build_selection(int *selection, int *ptype_offset, int *ptype_count, const struct particle_data *Parts, const int NumPart, int(*select_func)(int i, const struct particle_data *Parts))
Definition: petaio.c:113
int GetUsePeculiarVelocity(void)
Definition: petaio.c:79
void set_petaio_params(ParameterSet *ps)
Definition: petaio.c:57
struct IOTableEntry IOTableEntry
int(* petaio_selection)(int i)
Definition: petaio.h:47
void petaio_build_buffer(BigArray *array, IOTableEntry *ent, const int *selection, const int NumSelection, struct particle_data *Parts, struct slots_manager_type *SlotsManager, struct conversions *conv)
Definition: petaio.c:521
void petaio_readout_buffer(BigArray *array, IOTableEntry *ent, struct conversions *conv, struct part_manager_type *PartManager, struct slots_manager_type *SlotsManager)
Definition: petaio.c:506
void petaio_save_block(BigFile *bf, const char *blockname, BigArray *array, int verbose)
Definition: petaio.c:587
static Cosmology * CP
Definition: power.c:27
struct slots_manager_type SlotsManager[1]
Definition: slotsmanager.c:7
int items
Definition: petaio.h:54
char dtype[8]
Definition: petaio.h:53
int zorder
Definition: petaio.h:50
int ptype
Definition: petaio.h:52
int required
Definition: petaio.h:55
property_getter getter
Definition: petaio.h:56
property_setter setter
Definition: petaio.h:57
char name[64]
Definition: petaio.h:51
Definition: petaio.h:60
int used
Definition: petaio.h:62
int allocated
Definition: petaio.h:63
IOTableEntry * ent
Definition: petaio.h:61
double atime
Definition: petaio.h:41
double hubble
Definition: petaio.h:42
double TimeIC
Definition: petaio.h:24
int64_t NTotalInit[6]
Definition: petaio.h:20
double TimeSnapshot
Definition: petaio.h:26
double UnitMass_in_g
Definition: petaio.h:31
int64_t NLocal[6]
Definition: petaio.h:16
double MassTable[6]
Definition: petaio.h:22
double UnitVelocity_in_cm_per_s
Definition: petaio.h:32
double UnitLength_in_cm
Definition: petaio.h:30
int neutrinonk
Definition: petaio.h:34
double BoxSize
Definition: petaio.h:28
int64_t NTotal[6]
Definition: petaio.h:18
static enum TransferType ptype
Definition: zeldovich.c:146