/*******************************************************************************
* This file is part of SWIFT.
* Copyright (c) 2018 Folkert Nobels (nobels@strw.leidenuniv.nl)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
******************************************************************************/
#ifndef SWIFT_STAR_FORMATION_COLIBRE_IO_H
#define SWIFT_STAR_FORMATION_COLIBRE_IO_H
/* Config parameters. */
#include
/* Local includes */
#include "io_properties.h"
/**
* @brief Specifies which s-particle fields to read from a dataset
*
* @param sparts The s-particle array.
* @param list The list of i/o properties to read.
*
* @return num_fields The number of i/o fields to read.
*/
INLINE static int star_formation_read_particles(struct spart* sparts,
struct io_props* list) {
return 0;
}
INLINE static void convert_part_sfr(const struct engine* e,
const struct part* p,
const struct xpart* xp, float* ret) {
/* The SFR field contains the SFR if > 0 and
* the (opposite of the) last SF scale-factor (or time) if < 0. */
ret[0] = (xp->sf_data.SFR >= 0.) ? xp->sf_data.SFR : 0.f;
}
INLINE static void convert_part_last_sf_time(const struct engine* e,
const struct part* p,
const struct xpart* xp,
float* ret) {
/* The SFR field contains the SFR if > 0 and
* the (opposite of the) last SF scale-factor (or time) if < 0. */
ret[0] = (xp->sf_data.SFR < 0.) ? -xp->sf_data.SFR : 0.f;
}
/**
* @brief Specifies which particle fields to write to a dataset
*
* @param parts The particle array.
* @param xparts The extended data particle array.
* @param list The list of i/o properties to write.
* @param with_cosmology Are we running a cosmological simulation?
*
* @return Returns the number of fields to write.
*/
__attribute__((always_inline)) INLINE static int star_formation_write_particles(
const struct part* parts, const struct xpart* xparts, struct io_props* list,
const int with_cosmology) {
/* List what we want to write */
list[0] = io_make_output_field_convert_part(
"StarFormationRates", FLOAT, 1, UNIT_CONV_SFR, 0.f, parts, xparts,
convert_part_sfr, "Star formation rates of the particles.");
if (with_cosmology) {
list[1] = io_make_output_field_convert_part(
"LastStarFormationScaleFactors", FLOAT, 1, UNIT_CONV_NO_UNITS, 0.f,
parts, xparts, convert_part_last_sf_time,
"Scale-factors at which the stars last had a non-zero star formation "
"rate.");
} else {
list[1] = io_make_output_field_convert_part(
"LastStarFormationTimes", FLOAT, 1, UNIT_CONV_TIME, 0.f, parts, xparts,
convert_part_last_sf_time,
"Times at which the stars last had a non-zero star formation rate.");
}
list[2] = io_make_output_field(
"VelocityDispersions", FLOAT, 1, UNIT_CONV_VELOCITY_SQUARED, 0.f, parts,
sf_data.sigma_v2,
"Physical velocity dispersions (3D) squared, this is the velocity "
"dispersion of the total velocity (peculiar velocity + Hubble flow, a H "
"x + a (dx/dt) ). Values of the Velocity dispersion that have the value "
"of FLT_MAX are particles that do not have neighbours and therefore the "
"velocity dispersion of these particles cannot be calculated");
return 3;
}
/**
* @brief Specifies which sparticle fields to write to a dataset
*
* @param sparts The star particle array.
* @param list The list of i/o properties to write.
*
* @return Returns the number of fields to write.
*/
__attribute__((always_inline)) INLINE static int
star_formation_write_sparticles(const struct spart* sparts,
struct io_props* list) {
list[0] = io_make_output_field(
"SubgridBirthDensities", FLOAT, 1, UNIT_CONV_DENSITY, 0.f, sparts,
sf_data.birth_subgrid_density,
"Physical subgrid densities at the time of birth of the gas particles "
"that turned into stars (note that we store the physical subgrid density "
"at the birth redshift, no conversion is needed)");
list[1] = io_make_output_field("SubgridBirthTemperatures", FLOAT, 1,
UNIT_CONV_TEMPERATURE, 0.f, sparts,
sf_data.birth_subgrid_temperature,
"Subgrid temperatures at the time of birth of "
"the gas particles that turned into stars");
list[2] = io_make_output_field(
"BirthVelocityDispersions", FLOAT, 1, UNIT_CONV_VELOCITY_SQUARED, 0.f,
sparts, sf_data.birth_velocity_dispersion,
"Physical velocity dispersions (3D) squared at the birth time of the gas "
"particles that turned into stars, this is the velocity dispersion of "
"the total velocity (peculiar velocity + Hubble flow, a H x + a (dx/dt) "
").");
return 3;
}
#endif /* SWIFT_STAR_FORMATION_COLIBRE_IO_H */