12#include "gadgetconfig.h"
23#include "../cooling_sfr/cooling.h"
24#include "../data/allvars.h"
25#include "../data/dtypes.h"
26#include "../data/mymalloc.h"
27#include "../logs/logs.h"
28#include "../logs/timer.h"
29#include "../system/system.h"
30#include "../time_integration/timestep.h"
46 double sum_sm, total_sm, rate, sum_mass_stars, total_sum_mass_stars;
47 double p = 0, pall = 0, prob, p_decide;
48 double rate_in_msunperyear;
54 stars_spawned = stars_converted = 0;
56 sum_sm = sum_mass_stars = 0;
75 if(Sp->
SphP[target].Sfr > 0)
85 Sp->
SphP[target].MassMetallicity = Sp->
SphP[target].Metallicity * Sp->
P[target].
getMass();
86 Sp->
P[target].Metallicity = Sp->
SphP[target].Metallicity;
88 mass_of_star = Sp->
P[target].
getMass();
90 prob = Sp->
P[target].
getMass() / mass_of_star * (1 -
exp(-pall));
102 if(p_decide < p / pall)
103 make_star(Sp, target, prob, mass_of_star, &sum_mass_stars);
105 if(Sp->
SphP[target].Sfr > 0)
110 Sp->
SphP[target].MassMetallicity = Sp->
SphP[target].Metallicity * Sp->
P[target].
getMass();
113 Sp->
P[target].Metallicity = Sp->
SphP[target].Metallicity;
117 MPI_Allreduce(&stars_spawned, &tot_stars_spawned, 1, MPI_INT, MPI_SUM, Communicator);
118 MPI_Allreduce(&stars_converted, &tot_stars_converted, 1, MPI_INT, MPI_SUM, Communicator);
120 if(tot_stars_spawned > 0 || tot_stars_converted > 0)
122 mpi_printf(
"SFR: spawned %d stars, converted %d gas particles into stars\n", tot_stars_spawned, tot_stars_converted);
125 tot_altogether_spawned = tot_stars_spawned;
126 altogether_spawned = stars_spawned;
127 if(tot_altogether_spawned)
135 for(
int i = 0; i < Sp->
NumPart; i++)
136 if(Sp->
P[i].
ID.
get() > maxid)
138 maxid = Sp->
P[i].
ID.
get();
143 MPI_Allgather(&maxid,
sizeof(
MyIDType), MPI_BYTE, tmp,
sizeof(
MyIDType), MPI_BYTE, Communicator);
145 for(
int i = 0; i < NTask; i++)
154 int *list = (
int *)
Mem.mymalloc(
"list", NTask *
sizeof(
int));
156 MPI_Allgather(&altogether_spawned, 1, MPI_INT, list, 1, MPI_INT, Communicator);
160 for(
int i = 0; i < ThisTask; i++)
165 for(
int i = 0; i < altogether_spawned; i++)
168 All.MaxID += tot_altogether_spawned;
172 if(tot_stars_spawned > 0 || tot_stars_converted > 0)
180 for(
int bin = 0; bin <
TIMEBINS; bin++)
182 sfrrate += Sp->TimeBinSfr[bin];
184 MPI_Allreduce(&sfrrate, &totsfrrate, 1, MPI_DOUBLE, MPI_SUM, Communicator);
186 MPI_Reduce(&sum_sm, &total_sm, 1, MPI_DOUBLE, MPI_SUM, 0, Communicator);
187 MPI_Reduce(&sum_mass_stars, &total_sum_mass_stars, 1, MPI_DOUBLE, MPI_SUM, 0, Communicator);
196 cum_mass_stars += total_sum_mass_stars;
201 fprintf(
Logs.FdSfr,
"%14e %14e %14e %14e %14e %14e\n",
All.
Time, total_sm, totsfrrate, rate_in_msunperyear, total_sum_mass_stars,
219void coolsfr::convert_sph_particle_into_star(
simparticles *Sp,
int i,
double birthtime)
225#ifdef INDIVIDUAL_GRAVITY_SOFTENING
226 if(((1 << Sp->
P[i].
getType()) & (INDIVIDUAL_GRAVITY_SOFTENING)))
232 Sp->
P[i].StellarAge = birthtime;
251void coolsfr::spawn_star_from_sph_particle(
simparticles *Sp,
int igas,
double birthtime,
int istar,
MyDouble mass_of_star)
253 Sp->
P[istar] = Sp->
P[igas];
258#ifdef INDIVIDUAL_GRAVITY_SOFTENING
259 if(((1 << Sp->
P[istar].
getType()) & (INDIVIDUAL_GRAVITY_SOFTENING)))
269 Sp->
P[istar].StellarAge = birthtime;
291void coolsfr::make_star(
simparticles *Sp,
int i,
double prob,
MyDouble mass_of_star,
double *sum_mass_stars)
293 if(mass_of_star > Sp->
P[i].
getMass())
298 if(mass_of_star == Sp->
P[i].
getMass())
303 *sum_mass_stars += Sp->
P[i].
getMass();
305 convert_sph_particle_into_star(Sp, i,
All.
Time);
310 altogether_spawned = stars_spawned;
312 Terminate(
"NumPart=%d spwawn %d particles no space left (Sp.MaxPart=%d)\n", Sp->
NumPart, altogether_spawned, Sp->
MaxPart);
314 int j = Sp->
NumPart + altogether_spawned;
316 spawn_star_from_sph_particle(Sp, i,
All.
Time, j, mass_of_star);
318 *sum_mass_stars += mass_of_star;
global_data_all_processes All
TimeBinData TimeBinsGravity
TimeBinData TimeBinsHydro
int TimeBinSynchronized[TIMEBINS]
#define TIMER_START(counter)
Starts the timer counter.
#define TIMER_STOP(counter)
Stops the timer counter.
int TimeBinCount[TIMEBINS]
void timebin_add_particle(int i_new, int i_old, int timeBin, int addToListOfActiveParticles)
int SofteningClassOfPartType[NTYPES]
void set_cosmo_factors_for_current_time(void)
void setSofteningClass(unsigned char softclass)
void setMass(MyDouble mass)
unsigned char getTimeBinHydro(void)
unsigned char getType(void)
void setType(unsigned char type)
void myflush(FILE *fstream)
double get_random_number(void)