12#include "gadgetconfig.h"
14#if defined(LIGHTCONE) && defined(LIGHTCONE_MASSMAPS)
16#include <gsl/gsl_rng.h>
27#include "../data/allvars.h"
28#include "../data/dtypes.h"
29#include "../data/mymalloc.h"
30#include "../io/hdf5_util.h"
32#include "../lightcone/lightcone.h"
33#include "../lightcone/lightcone_massmap_io.h"
34#include "../main/simulation.h"
35#include "../mpi_utils/mpi_utils.h"
36#include "../system/system.h"
45lightcone_massmap_io::lightcone_massmap_io(mmparticles *Mp_ptr, lightcone *LightCone_ptr, MPI_Comm comm,
int format)
49 LightCone = LightCone_ptr;
51 this->N_IO_Fields = 0;
52 this->N_DataGroups = 1;
53 this->header_size =
sizeof(header);
54 this->header_buf = &header;
56 sprintf(this->info,
"LIGHTCONE: writing mass map data");
58 init_field(
"MAMP",
"Mass",
MEM_DOUBLE,
FILE_MY_IO_FLOAT,
SKIP_ON_READ, 1,
A_MM, &LightCone->MassMap[0], NULL,
MASSMAPS, 1, 0., -1.,
62void lightcone_massmap_io::lightcone_massmap_save(
int num)
68 long long NumLP_tot = LightCone->Mp->NpixLoc;
69 MPI_Allreduce(MPI_IN_PLACE, &NumLP_tot, 1, MPI_LONG_LONG, MPI_SUM, Communicator);
70 mpi_printf(
"\nLIGHTCONE: writing lightcone massmap files #%d ... (Npix_tot = %lld, ascale %g to %g)\n", num, NumLP_tot,
71 LightCone->MassMapBoundariesAscale[num], LightCone->MassMapBoundariesAscale[num + 1]);
81 MPI_Barrier(Communicator);
85 sprintf(buf,
"%s/mapsdir_%03d/%s_%03d",
All.
OutputDir, num,
"maps", num);
91 mpi_printf(
"LIGHTCONE: done with writing mass map.\n");
94 memset(LightCone->MassMap, 0, LightCone->Mp->NpixLoc *
sizeof(
double));
97void lightcone_massmap_io::fill_file_header(
int writeTask,
int lastTask,
long long *n_type,
long long *ntot_type)
101 n_type[0] = LightCone->Mp->NpixLoc;
104 if(ThisTask == writeTask)
106 ntot_type[0] = n_type[0];
108 for(
int task = writeTask + 1; task <= lastTask; task++)
111 MPI_Recv(&nn, 1, MPI_LONG_LONG, task,
TAG_LOCALN, Communicator, MPI_STATUS_IGNORE);
115 for(
int task = writeTask + 1; task <= lastTask; task++)
116 MPI_Send(&ntot_type[0], 1, MPI_LONG_LONG, task,
TAG_N, Communicator);
120 MPI_Send(&n_type[0], 1, MPI_LONG_LONG, writeTask,
TAG_LOCALN, Communicator);
121 MPI_Recv(&ntot_type[0], 1, MPI_LONG_LONG, writeTask,
TAG_N, Communicator, MPI_STATUS_IGNORE);
125 header.nside =
All.LightConeMassMapsNside;
126 header.npix_local = ntot_type[0];
127 header.npix_total = LightCone->Mp->Npix;
130 header.AscaleStart = LightCone->MassMapBoundariesAscale[selected_bnd];
131 header.AscaleEnd = LightCone->MassMapBoundariesAscale[selected_bnd + 1];
132 header.ComDistStart = LightCone->MassMapBoundariesComDist[selected_bnd];
133 header.ComDistEnd = LightCone->MassMapBoundariesComDist[selected_bnd + 1];
136void lightcone_massmap_io::write_header_fields(hid_t handle)
155void lightcone_massmap_io::set_filenr_in_header(
int numfiles) { header.num_files = numfiles; }
157void lightcone_massmap_io::get_datagroup_name(
int type,
char *buf)
160 sprintf(buf,
"/Maps");
165void *lightcone_massmap_io::get_base_address_of_structure(
enum arrays array,
int index)
170 return (
void *)(LightCone->MassMap + index);
173 Terminate(
"we don't expect to get here");
179void lightcone_massmap_io::read_file_header(
const char *fname,
int filenr,
int readTask,
int lastTask,
long long *nloc_part,
180 long long *npart,
int *nstart)
185void lightcone_massmap_io::read_header_fields(
const char *fname)
189void lightcone_massmap_io::read_increase_numbers(
int type,
int n_for_this_task)
193int lightcone_massmap_io::get_filenr_from_header(
void)
199int lightcone_massmap_io::get_type_of_element(
int index)
205void lightcone_massmap_io::set_type_of_element(
int index,
int type)
global_data_all_processes All
void write_scalar_attribute(hid_t handle, const char *attr_name, const void *buf, hid_t mem_type_id)
char OutputDir[MAXLEN_PATH]