GADGET-4
lightcone_particle_io.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 LIGHTCONE_IO_H
13#define LIGHTCONE_IO_H
14
15#include "gadgetconfig.h"
16
17#if defined(LIGHTCONE) && defined(LIGHTCONE_PARTICLES)
18
19#include "../data/intposconvert.h"
20#include "../data/lcparticles.h"
21#include "../io/io.h"
22#include "../lightcone/lightcone.h"
23#include "../mergertree/mergertree.h"
24
25class lightcone_particle_io : public IO_Def
26{
27 public:
28#ifdef MERGERTREE
29 lightcone_particle_io(lcparticles *Lp_ptr, lightcone *LightCone_ptr, mergertree *MergerTree_ptr, MPI_Comm comm, int format);
30#else
31 lightcone_particle_io(lcparticles *Lp_ptr, lightcone *LightCone_ptr, MPI_Comm comm, int format);
32#endif
33
34 void lightcone_save(int num, int conenr, bool reordered_flag);
35 void lightcone_read(int num, int conenr);
36
37 /* supplied virtual functions */
38 void fill_file_header(int writeTask, int lastTask, long long *nloc_part, long long *npart);
39 void read_file_header(const char *fname, int filenr, int readTask, int lastTask, long long *nloc_part, long long *npart,
40 int *nstart);
41 void get_datagroup_name(int grnr, char *gname);
42 void write_header_fields(hid_t);
43 void read_header_fields(const char *fname);
44 void read_increase_numbers(int type, int n_for_this_task);
45 int get_filenr_from_header(void);
46 void set_filenr_in_header(int);
47 void *get_base_address_of_structure(enum arrays array, int index);
48 int get_type_of_element(int index);
49 void set_type_of_element(int index, int type);
50
53 struct io_header
54 {
55 long long npart[NTYPES];
56 long long npartTotal[NTYPES];
57
58 long long Ntrees;
59 long long TotNtrees;
60
61 int Npix;
62 int TotNpix;
63
64 int num_files;
65 };
66 io_header header;
68 private:
69 lcparticles *Lp;
70 lightcone *LightCone;
71#ifdef MERGERTREE
72 mergertree *MergerTree;
73#endif
74
75 int cone;
76 bool reorder_flag;
77 long long ntot_type_all[NTYPES];
78
79 /*
80 * special input/output functions for certain fields
81 */
82
83 static void io_func_pos(IO_Def *ptr, int particle, int components, void *buffer, int mode)
84 {
85 /* note: we know that components==3 here */
86 lightcone_particle_io *thisobj = (lightcone_particle_io *)ptr;
87
88 if(mode == 0)
89 {
90 MyDouble *out_buffer = (MyDouble *)buffer;
91
92 double xyz[3];
93 thisobj->Lp->signedintpos_to_pos((MySignedIntPosType *)thisobj->Lp->P[particle].IntPos, xyz);
94
95 for(int k = 0; k < 3; k++)
96 out_buffer[k] = xyz[k];
97 }
98 else
99 {
100 MyDouble *in_buffer = (MyDouble *)buffer;
101
102 /* note: for non-periodic positions, the conversion to integer coordinates is undefined only after the initial read.
103 * We therefore store the coordinates first in a temporary array */
104
105 double xyz[3];
106
107 for(int k = 0; k < 3; k++)
108 xyz[k] = in_buffer[k];
109
110 /* converts floating point representation to integers */
111 thisobj->Lp->pos_to_signedintpos(xyz, (MySignedIntPosType *)thisobj->Lp->P[particle].IntPos);
112 }
113 }
114
115#if defined(LIGHTCONE_OUTPUT_ACCELERATIONS) && defined(OUTPUT_ACCELERATIONS_IN_HALF_PRECISION)
116 static void io_func_accel(IO_Def *ptr, int particle, int components, void *buffer, int mode)
117 {
118 lightcone_particle_io *thisobj = (lightcone_particle_io *)ptr;
119
120 if(mode == 0) // writing
121 {
122 MyFloat *out_buffer = (MyFloat *)buffer;
123 for(int k = 0; k < 3; k++)
124 out_buffer[k] = thisobj->Lp->P[particle].GravAccel[k] / All.accel_normalize_fac;
125 }
126 else // reading
127 {
128 MyFloat *in_buffer = (MyFloat *)buffer;
129 for(int k = 0; k < components; k++)
130 thisobj->Lp->P[particle].GravAccel[k] = All.accel_normalize_fac * in_buffer[k];
131 }
132 }
133#endif
134
135 static void io_func_id(IO_Def *ptr, int particle, int components, void *buffer, int mode)
136 {
137 lightcone_particle_io *thisobj = (lightcone_particle_io *)ptr;
138
139 if(mode == 0)
140 {
141 MyIDType *out_buffer = (MyIDType *)buffer;
142 out_buffer[0] = thisobj->Lp->P[particle].ID.get();
143 }
144 else
145 {
146 MyIDType *in_buffer = (MyIDType *)buffer;
147 thisobj->Lp->P[particle].ID.set(in_buffer[0]);
148 }
149 }
150
151 static void io_func_mass(IO_Def *ptr, int particle, int components, void *buffer, int mode)
152 {
153 lightcone_particle_io *thisobj = (lightcone_particle_io *)ptr;
154
155 if(mode == 0)
156 {
157 MyDouble *out_buffer = (MyDouble *)buffer;
158 out_buffer[0] = thisobj->Lp->P[particle].getMass();
159 }
160 else
161 {
162 MyDouble *in_buffer = (MyDouble *)buffer;
163 thisobj->Lp->P[particle].setMass(in_buffer[0]);
164 }
165 }
166};
167
168#endif
169
170#endif /* LIGHTCONE_IO_H */
global_data_all_processes All
Definition: main.cc:40
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 NTYPES
Definition: constants.h:308
float MyDouble
Definition: dtypes.h:87
float MyFloat
Definition: dtypes.h:86
int32_t MySignedIntPosType
Definition: dtypes.h:36
unsigned int MyIDType
Definition: dtypes.h:68
arrays
Definition: io.h:30