#ifndef SWIFT_DUST_IO_T20_H #define SWIFT_DUST_IO_T20_H #include "dust.h" #include "engine.h" #include "io_properties.h" /** * @brief Specifies which particle fields to write to a dataset * * @param parts The particle array. * @param list The list of i/o properties to write. * @param with_cosmology flag indicating if running with cosmology. * * @return Returns the number of fields to write. */ INLINE static int dust_write_particles(const struct part* parts, struct io_props* list, const int with_cosmology) { /* List what we want to write */ list[0] = io_make_output_field("DustMassFractions", FLOAT, dust_grain_species_count, UNIT_CONV_NO_UNITS, 0.f, parts, dust_data.grain_mass_fraction, "Fractions of the particles' masses that are " "in a given species of dust grain"); return 1; } /** * @brief Conversion function for adding explicit depletion back to metal arrays * * * @param e The #engine. * @param p The particle array. * @param xp The extended particle array. * @param ret Output array. */ INLINE static void convert_part_add_back_dust_for_chemistry( const struct engine* e, const struct part* p, const struct xpart* xp, float* ret) { /* first, set to return internal (diffuse phase) elemental abundances */ for (int i = 0; i < chemistry_element_count; i++) { ret[i] = (float)p->chemistry_data.metal_mass_fraction[i]; } const struct dustevo_props* dp = e->dustevo; /* running in paired mode? */ if (dp->pair_to_cooling) { /* put fraction of grain mass back into constituent element * so output arrays represent total metal mass fraction * (depleted + diffuse) instead of diffuse arrays used * internally when running in paired mode. */ for (int grain = 0; grain < dust_grain_species_count; grain++) { const float grain_mass = p->dust_data.grain_mass_fraction[grain]; for (int elem = 0; elem < dp->grain_element_count[grain]; elem++) { const int eldx = dp->grain_element_indices[grain][elem]; ret[eldx] += grain_mass * dp->grain_element_mfrac[grain][elem]; } } } } /** * @brief Specifies which black hole particle fields to write to a dataset * * @param bparts The black hole particle array. * @param list The list of i/o properties to write. * * @return Returns the number of fields to write. */ INLINE static int dust_write_bparticles(const struct bpart* bparts, struct io_props* list) { /* List what we want to write */ list[0] = io_make_output_field( "DustMasses", FLOAT, dust_grain_species_count, UNIT_CONV_MASS, 0.f, bparts, dust_data.grain_mass, "Mass contents of the BH particles in a given dust grain species"); list[1] = io_make_output_field( "DepletedIronMassesFromSNIa", FLOAT, 1, UNIT_CONV_MASS, 0.f, bparts, dust_data.grain_iron_mass_from_SNIa, "Masses of the BH particles in iron that have been " "produced by SNIa stars and depleted onto dust"); return 2; } #ifdef HAVE_HDF5 /** * @brief Writes the current model of dust evolution to the file * @param h_grp The HDF5 group in which to write * @param h_grp_columns The HDF5 group containing named columns * @param e The #engine. */ INLINE static void dust_write_flavour(hid_t h_grp, hid_t h_grp_columns, const struct engine* e) { io_write_attribute_s(h_grp, "Dust Model", "Trayford et. al (2020)"); /* Creatoe an array of grain names */ const int grain_name_length = 32; char grain_names[dust_grain_species_count][grain_name_length]; for (int grain = 0; grain < dust_grain_species_count; ++grain) { sprintf(grain_names[grain], "%s", dust_get_grain_name((enum grain_species)grain)); } /* Add to the named columns */ hsize_t dims[1] = {dust_grain_species_count}; hid_t type = H5Tcopy(H5T_C_S1); H5Tset_size(type, grain_name_length); hid_t space = H5Screate_simple(1, dims, NULL); hid_t dset = H5Dcreate(h_grp_columns, "DustMassFractions", type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Dwrite(dset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, grain_names[0]); H5Dclose(dset); /* dset = H5Dcreate(h_grp_columns, "MetalDiffusionRates", type, space, */ /* H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); */ /* H5Dwrite(dset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, element_names[0]); */ /* H5Dclose(dset); */ H5Tclose(type); H5Sclose(space); } /** * @brief Create and write array for mapping elements to dust grains * @param h_grp The HDF5 group in which to write * @param e The #engine. */ INLINE static void dust_write_composition(hid_t h_grp, const struct engine* e) { const struct dustevo_props* dp = e->dustevo; /* Create an array mapping grains to elements */ int eldx; float grain_mapping[dust_grain_species_count][chemistry_element_count]; for (int grain = 0; grain < dust_grain_species_count; ++grain) { int elgrain = 0; for (int elem = 0; elem < chemistry_element_count; ++elem) { eldx = dp->grain_element_indices[grain][elgrain]; if (eldx == elem) { grain_mapping[grain][elem] = dp->grain_element_mfrac[grain][elgrain]; if (elgrain < dp->grain_element_count[grain] - 1) { elgrain += 1; } } else { grain_mapping[grain][elem] = 0.; } } } /* Write out array */ hsize_t dims[2] = {dust_grain_species_count, chemistry_element_count}; hid_t space = H5Screate_simple(2, dims, NULL); hid_t dset = H5Dcreate(h_grp, "GrainToElementMapping", H5T_NATIVE_FLOAT, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); if (dset < 0) error("Error while creating grain to element map array"); H5Dwrite(dset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &grain_mapping[0][0]); io_write_attribute_s(dset, "Description", "Mass fraction of respective grain type (row)" "constituted by given element (column)"); H5Dclose(dset); H5Sclose(space); } #endif #endif /* SWIFT_DUST_T20_PROPERTIES_H */