MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Classes | Functions
metal_return.h File Reference
#include "forcetree.h"
#include "timestep.h"
#include "utils/paramset.h"
#include <gsl/gsl_interp2d.h>
#include <gsl/gsl_integration.h>
#include "slotsmanager.h"
Include dependency graph for metal_return.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  interps
 
struct  MetalReturnPriv
 

Functions

void setup_metal_table_interp (struct interps *interp)
 
void metal_return (const ActiveParticles *act, DomainDecomp *const ddecomp, Cosmology *CP, const double atime, const double AvgGasMass)
 
void set_metal_return_params (ParameterSet *ps)
 
int64_t metal_return_init (const ActiveParticles *act, Cosmology *CP, struct MetalReturnPriv *priv, const double atime)
 
void metal_return_priv_free (struct MetalReturnPriv *priv)
 
void stellar_density (const ActiveParticles *act, MyFloat *StarVolumeSPH, MyFloat *MassReturn, const ForceTree *const tree)
 
int metals_haswork (int i, MyFloat *MassReturn)
 

Function Documentation

◆ metal_return()

void metal_return ( const ActiveParticles act,
DomainDecomp *const  ddecomp,
Cosmology CP,
const double  atime,
const double  AvgGasMass 
)

This function is the driver routine for the calculation of metal return.

Definition at line 517 of file metal_return.c.

518 {
519  /* Do nothing if no stars yet*/
520  int64_t totstar;
521  MPI_Allreduce(&SlotsManager->info[4].size, &totstar, 1, MPI_INT64, MPI_SUM, MPI_COMM_WORLD);
522  if(totstar == 0)
523  return;
524 
525  struct MetalReturnPriv priv[1];
526 
527  int64_t nwork = metal_return_init(act, CP, priv, atime);
528 
529  /* Maximum mass of a gas particle after enrichment: cap it at a few times the initial mass.
530  * FIXME: Ideally we should here fork a new particle with a smaller gas mass. We should
531  * figure out then how set the gas entropy. A possibly better idea is to add
532  * a generic routine to split gas particles into the density code.*/
533  priv->MaxGasMass = 4* AvgGasMass;
534 
535  int64_t totwork;
536  MPI_Allreduce(&nwork, &totwork, 1, MPI_INT64, MPI_SUM, MPI_COMM_WORLD);
537 
538  walltime_measure("/SPH/Metals/Init");
539 
540  if(totwork == 0) {
542  return;
543  }
544 
545  ForceTree gasTree = {0};
546  /* Just gas, no moments*/
547  force_tree_rebuild_mask(&gasTree, ddecomp, GASMASK, 0, NULL);
548 
549  /* Compute total number of weights around each star for actively returning stars*/
550  stellar_density(act, priv->StarVolumeSPH, priv->MassReturn, &gasTree);
551 
552  /* Do the metal return*/
553  TreeWalk tw[1] = {{0}};
554 
555  tw->ev_label = "METALS";
561  tw->reduce = NULL;
565  tw->repeatdisallowed = 1;
566  tw->tree = &gasTree;
567  tw->priv = priv;
568 
569  priv->spin = init_spinlocks(SlotsManager->info[0].size);
571  free_spinlocks(priv->spin);
572 
573  force_tree_free(&gasTree);
575 
576  /* collect some timing information */
577  walltime_measure("/SPH/Metals/Yield");
578 }
void force_tree_rebuild_mask(ForceTree *tree, DomainDecomp *ddecomp, int mask, const int HybridNuGrav, const char *EmergencyOutputDir)
Definition: forcetree.c:161
void force_tree_free(ForceTree *tree)
Definition: forcetree.c:1409
#define GASMASK
Definition: forcetree.h:21
int64_t metal_return_init(const ActiveParticles *act, Cosmology *CP, struct MetalReturnPriv *priv, const double atime)
Definition: metal_return.c:437
static void metal_return_postprocess(int place, TreeWalk *tw)
Definition: metal_return.c:619
void metal_return_priv_free(struct MetalReturnPriv *priv)
Definition: metal_return.c:500
static int metal_return_haswork(int n, TreeWalk *tw)
Definition: metal_return.c:720
void stellar_density(const ActiveParticles *act, MyFloat *StarVolumeSPH, MyFloat *MassReturn, const ForceTree *const tree)
Definition: metal_return.c:923
static void metal_return_copy(int place, TreeWalkQueryMetals *input, TreeWalk *tw)
Definition: metal_return.c:583
static void metal_return_ngbiter(TreeWalkQueryMetals *I, TreeWalkResultMetals *O, TreeWalkNgbIterMetals *iter, LocalTreeWalk *lv)
Definition: metal_return.c:633
static Cosmology * CP
Definition: power.c:27
struct slots_manager_type SlotsManager[1]
Definition: slotsmanager.c:7
void free_spinlocks(struct SpinLocks *spin)
Definition: spinlocks.c:70
struct SpinLocks * init_spinlocks(int NumLock)
Definition: spinlocks.c:49
int * ActiveParticle
Definition: timestep.h:13
int64_t NumActiveParticle
Definition: timestep.h:12
void * priv
Definition: treewalk.h:85
TreeWalkHasWorkFunction haswork
Definition: treewalk.h:100
size_t ngbiter_type_elsize
Definition: treewalk.h:97
const ForceTree * tree
Definition: treewalk.h:88
TreeWalkProcessFunction postprocess
Definition: treewalk.h:104
TreeWalkNgbIterFunction ngbiter
Definition: treewalk.h:103
TreeWalkReduceResultFunction reduce
Definition: treewalk.h:102
const char * ev_label
Definition: treewalk.h:91
TreeWalkVisitFunction visit
Definition: treewalk.h:99
int repeatdisallowed
Definition: treewalk.h:117
size_t result_type_elsize
Definition: treewalk.h:96
TreeWalkFillQueryFunction fill
Definition: treewalk.h:101
size_t query_type_elsize
Definition: treewalk.h:95
int64_t size
Definition: slotsmanager.h:12
struct slot_info info[6]
Definition: slotsmanager.h:112
#define MPI_INT64
Definition: system.h:12
int treewalk_visit_ngbiter(TreeWalkQueryBase *I, TreeWalkResultBase *O, LocalTreeWalk *lv)
Definition: treewalk.c:924
void treewalk_run(TreeWalk *tw, int *active_set, size_t size)
Definition: treewalk.c:619
int(* TreeWalkVisitFunction)(TreeWalkQueryBase *input, TreeWalkResultBase *output, LocalTreeWalk *lv)
Definition: treewalk.h:68
void(* TreeWalkProcessFunction)(const int i, TreeWalk *tw)
Definition: treewalk.h:73
void(* TreeWalkNgbIterFunction)(TreeWalkQueryBase *input, TreeWalkResultBase *output, TreeWalkNgbIterBase *iter, LocalTreeWalk *lv)
Definition: treewalk.h:70
void(* TreeWalkFillQueryFunction)(const int j, TreeWalkQueryBase *query, TreeWalk *tw)
Definition: treewalk.h:75
#define walltime_measure(name)
Definition: walltime.h:8

References ActiveParticles::ActiveParticle, CP, TreeWalk::ev_label, TreeWalk::fill, force_tree_free(), force_tree_rebuild_mask(), free_spinlocks(), GASMASK, TreeWalk::haswork, slots_manager_type::info, init_spinlocks(), MetalReturnPriv::MassReturn, MetalReturnPriv::MaxGasMass, metal_return_copy(), metal_return_haswork(), metal_return_init(), metal_return_ngbiter(), metal_return_postprocess(), metal_return_priv_free(), MPI_INT64, TreeWalk::ngbiter, TreeWalk::ngbiter_type_elsize, ActiveParticles::NumActiveParticle, TreeWalk::postprocess, TreeWalk::priv, TreeWalk::query_type_elsize, TreeWalk::reduce, TreeWalk::repeatdisallowed, TreeWalk::result_type_elsize, slot_info::size, SlotsManager, MetalReturnPriv::spin, MetalReturnPriv::StarVolumeSPH, stellar_density(), TreeWalk::tree, treewalk_run(), treewalk_visit_ngbiter(), TreeWalk::visit, and walltime_measure.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ metal_return_init()

int64_t metal_return_init ( const ActiveParticles act,
Cosmology CP,
struct MetalReturnPriv priv,
const double  atime 
)

Definition at line 437 of file metal_return.c.

438 {
439  int nthread = omp_get_max_threads();
440  priv->gsl_work = ta_malloc("gsl_work", gsl_integration_workspace *, nthread);
441  int i;
442  /* Allocate a workspace for each thread*/
443  for(i=0; i < nthread; i++)
444  priv->gsl_work[i] = gsl_integration_workspace_alloc(GSL_WORKSPACE);
445  priv->hub = CP->HubbleParam;
446 
447  /* Initialize*/
449  priv->StellarAges = (MyFloat *) mymalloc("StellarAges", SlotsManager->info[4].size * sizeof(MyFloat));
450  priv->MassReturn = (MyFloat *) mymalloc("MassReturn", SlotsManager->info[4].size * sizeof(MyFloat));
451  priv->LowDyingMass = (MyFloat *) mymalloc("LowDyingMass", SlotsManager->info[4].size * sizeof(MyFloat));
452  priv->HighDyingMass = (MyFloat *) mymalloc("HighDyingMass", SlotsManager->info[4].size * sizeof(MyFloat));
453  priv->StarVolumeSPH = (MyFloat *) mymalloc("StarVolumeSPH", SlotsManager->info[4].size * sizeof(MyFloat));
454 
455  priv->imf_norm = compute_imf_norm(priv->gsl_work[0]);
456  /* Maximum possible mass return for below*/
457  double maxmassfrac = mass_yield(0, 1/(CP->HubbleParam*HUBBLE * SEC_PER_MEGAYEAR), snii_metallicities[SNII_NMET-1], CP->HubbleParam, &priv->interp, priv->imf_norm, priv->gsl_work[0],agb_masses[0], MAXMASS);
458 
459  int64_t haswork = 0;
460  /* First find the mass return as a fraction of the total mass and the age of the star.
461  * This is done first so we can skip density computation for not active stars*/
462  #pragma omp parallel for reduction(+: haswork)
463  for(i=0; i < act->NumActiveParticle;i++)
464  {
465  int p_i = act->ActiveParticle ? act->ActiveParticle[i] : i;
466  if(P[p_i].Type != 4)
467  continue;
468  int tid = omp_get_thread_num();
469  const int slot = P[p_i].PI;
470  priv->StellarAges[slot] = atime_to_myr(CP, STARP(p_i).FormationTime, atime, priv->gsl_work[tid]);
471  /* Note this takes care of units*/
472  double initialmass = P[p_i].Mass + STARP(p_i).TotalMassReturned;
473  find_mass_bin_limits(&priv->LowDyingMass[slot], &priv->HighDyingMass[slot], STARP(p_i).LastEnrichmentMyr, priv->StellarAges[P[p_i].PI], STARP(p_i).Metallicity, priv->interp.lifetime_interp);
474 
475  priv->MassReturn[slot] = initialmass * mass_yield(STARP(p_i).LastEnrichmentMyr, priv->StellarAges[P[p_i].PI], STARP(p_i).Metallicity, CP->HubbleParam, &priv->interp, priv->imf_norm, priv->gsl_work[tid],priv->LowDyingMass[slot], priv->HighDyingMass[slot]);
476  //message(3, "Particle %d PI %d massgen %g mass %g initmass %g\n", p_i, P[p_i].PI, priv->MassReturn[P[p_i].PI], P[p_i].Mass, initialmass);
477  /* Guard against making a zero mass particle and warn since this should not happen.*/
478  if(STARP(p_i).TotalMassReturned + priv->MassReturn[slot] > initialmass * maxmassfrac) {
479  if(priv->MassReturn[slot] / STARP(p_i).TotalMassReturned > 0.01)
480  message(1, "Large mass return id %ld %g from %d mass %g initial %g (maxfrac %g) age %g lastenrich %g metal %g dymass %g %g\n",
481  P[p_i].ID, priv->MassReturn[slot], p_i, STARP(p_i).TotalMassReturned, initialmass, maxmassfrac, priv->StellarAges[P[p_i].PI], STARP(p_i).LastEnrichmentMyr, STARP(p_i).Metallicity, priv->LowDyingMass[slot], priv->HighDyingMass[slot]);
482  priv->MassReturn[slot] = initialmass * maxmassfrac - STARP(p_i).TotalMassReturned;
483  if(priv->MassReturn[slot] < 0) {
484  priv->MassReturn[slot] = 0;
485  }
486  /* Ensure that we skip this step*/
487  if(!metals_haswork(p_i, priv->MassReturn))
488  STARP(p_i).LastEnrichmentMyr = priv->StellarAges[P[p_i].PI];
489 
490  }
491  /* Keep count of how much work we need to do*/
492  if(metals_haswork(p_i, priv->MassReturn))
493  haswork++;
494  }
495  return haswork;
496 }
void message(int where, const char *fmt,...)
Definition: endrun.c:175
static double mass_yield(double dtmyrstart, double dtmyrend, double stellarmetal, double hub, struct interps *interp, double imf_norm, gsl_integration_workspace *gsl_work, double masslow, double masshigh)
Definition: metal_return.c:395
void find_mass_bin_limits(double *masslow, double *masshigh, const double dtstart, const double dtend, double stellarmetal, gsl_interp2d *lifetime_tables)
Definition: metal_return.c:230
void setup_metal_table_interp(struct interps *interp)
Definition: metal_return.c:76
int metals_haswork(int i, MyFloat *MassReturn)
Definition: metal_return.c:708
double compute_imf_norm(gsl_integration_workspace *gsl_work)
Definition: metal_return.c:314
static double atime_to_myr(Cosmology *CP, double atime1, double atime2, gsl_integration_workspace *gsl_work)
Definition: metal_return.c:161
static const double snii_metallicities[SNII_NMET]
Definition: metal_tables.h:311
static const double agb_masses[AGB_NMASS]
Definition: metal_tables.h:70
#define GSL_WORKSPACE
Definition: metal_tables.h:426
#define SNII_NMET
Definition: metal_tables.h:308
#define MAXMASS
Definition: metal_tables.h:9
#define mymalloc(name, size)
Definition: mymalloc.h:15
#define ta_malloc(name, type, nele)
Definition: mymalloc.h:25
#define P
Definition: partmanager.h:88
#define HUBBLE
Definition: physconst.h:25
#define SEC_PER_MEGAYEAR
Definition: physconst.h:31
#define STARP(i)
Definition: slotsmanager.h:126
double HubbleParam
Definition: cosmology.h:20
gsl_integration_workspace ** gsl_work
Definition: metal_return.h:27
MyFloat * StarVolumeSPH
Definition: metal_return.h:37
MyFloat * HighDyingMass
Definition: metal_return.h:31
MyFloat * StellarAges
Definition: metal_return.h:28
struct interps interp
Definition: metal_return.h:38
MyFloat * MassReturn
Definition: metal_return.h:29
MyFloat * LowDyingMass
Definition: metal_return.h:30
gsl_interp2d * lifetime_interp
Definition: metal_return.h:13
LOW_PRECISION MyFloat
Definition: types.h:19

References ActiveParticles::ActiveParticle, agb_masses, atime_to_myr(), compute_imf_norm(), CP, find_mass_bin_limits(), MetalReturnPriv::gsl_work, GSL_WORKSPACE, MetalReturnPriv::HighDyingMass, MetalReturnPriv::hub, HUBBLE, Cosmology::HubbleParam, MetalReturnPriv::imf_norm, slots_manager_type::info, MetalReturnPriv::interp, interps::lifetime_interp, MetalReturnPriv::LowDyingMass, mass_yield(), MetalReturnPriv::MassReturn, MAXMASS, message(), metals_haswork(), mymalloc, ActiveParticles::NumActiveParticle, P, SEC_PER_MEGAYEAR, setup_metal_table_interp(), slot_info::size, SlotsManager, snii_metallicities, SNII_NMET, STARP, MetalReturnPriv::StarVolumeSPH, MetalReturnPriv::StellarAges, and ta_malloc.

Referenced by metal_return().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ metal_return_priv_free()

void metal_return_priv_free ( struct MetalReturnPriv priv)

Definition at line 500 of file metal_return.c.

501 {
502  myfree(priv->StarVolumeSPH);
503  myfree(priv->HighDyingMass);
504  myfree(priv->LowDyingMass);
505  myfree(priv->MassReturn);
506  myfree(priv->StellarAges);
507 
508  int i;
509  for(i=0; i < omp_get_max_threads(); i++)
510  gsl_integration_workspace_free(priv->gsl_work[i]);
511 
512  ta_free(priv->gsl_work);
513 }
#define ta_free(p)
Definition: mymalloc.h:28
#define myfree(x)
Definition: mymalloc.h:19

References MetalReturnPriv::gsl_work, MetalReturnPriv::HighDyingMass, MetalReturnPriv::LowDyingMass, MetalReturnPriv::MassReturn, myfree, MetalReturnPriv::StarVolumeSPH, MetalReturnPriv::StellarAges, and ta_free.

Referenced by metal_return().

Here is the caller graph for this function:

◆ metals_haswork()

int metals_haswork ( int  i,
MyFloat MassReturn 
)

Definition at line 708 of file metal_return.c.

709 {
710  if(P[i].Type != 4)
711  return 0;
712  int pi = P[i].PI;
713  /* Don't do enrichment from all stars, just those with significant enrichment*/
714  if(MassReturn[pi] < 1e-3 * (P[i].Mass + STARP(i).TotalMassReturned))
715  return 0;
716  return 1;
717 }

References MetalReturnPriv::MassReturn, P, and STARP.

Referenced by metal_return_haswork(), metal_return_init(), and stellar_density_haswork().

Here is the caller graph for this function:

◆ set_metal_return_params()

void set_metal_return_params ( ParameterSet ps)

Definition at line 62 of file metal_return.c.

63 {
64  int ThisTask;
65  MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
66  if(ThisTask == 0) {
67  MetalParams.Sn1aN0 = param_get_double(ps, "MetalsSn1aN0");
68  MetalParams.SPHWeighting = param_get_int(ps, "MetalsSPHWeighting");
69  MetalParams.MaxNgbDeviation = param_get_double(ps, "MetalsMaxNgbDeviation");
70  }
71  MPI_Bcast(&MetalParams, sizeof(struct metal_return_params), MPI_BYTE, 0, MPI_COMM_WORLD);
72 }
static struct metal_return_params MetalParams
double param_get_double(ParameterSet *ps, const char *name)
Definition: paramset.c:336
int param_get_int(ParameterSet *ps, const char *name)
Definition: paramset.c:368
int ThisTask
Definition: test_exchange.c:23

References metal_return_params::MaxNgbDeviation, MetalParams, param_get_double(), param_get_int(), metal_return_params::Sn1aN0, metal_return_params::SPHWeighting, and ThisTask.

Referenced by read_parameter_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_metal_table_interp()

void setup_metal_table_interp ( struct interps interp)

Definition at line 76 of file metal_return.c.

77 {
78  interp->lifetime_interp = gsl_interp2d_alloc(gsl_interp2d_bilinear, LIFE_NMET, LIFE_NMASS);
79  gsl_interp2d_init(interp->lifetime_interp, lifetime_metallicity, lifetime_masses, lifetime, LIFE_NMET, LIFE_NMASS);
80  interp->agb_mass_interp = gsl_interp2d_alloc(gsl_interp2d_bilinear, AGB_NMET, AGB_NMASS);
81  gsl_interp2d_init(interp->agb_mass_interp, agb_metallicities, agb_masses, agb_total_mass, AGB_NMET, AGB_NMASS);
82  interp->agb_metallicity_interp = gsl_interp2d_alloc(gsl_interp2d_bilinear, AGB_NMET, AGB_NMASS);
83  gsl_interp2d_init(interp->agb_metallicity_interp, agb_metallicities, agb_masses, agb_total_metals, AGB_NMET, AGB_NMASS);
84  int i;
85  for(i=0; i<NMETALS; i++) {
86  interp->agb_metals_interp[i] = gsl_interp2d_alloc(gsl_interp2d_bilinear, AGB_NMET, AGB_NMASS);
87  gsl_interp2d_init(interp->agb_metals_interp[i], agb_metallicities, agb_masses, agb_yield[i], AGB_NMET, AGB_NMASS);
88  }
89  interp->snii_mass_interp = gsl_interp2d_alloc(gsl_interp2d_bilinear, SNII_NMET, SNII_NMASS);
90  gsl_interp2d_init(interp->snii_mass_interp, snii_metallicities, snii_masses, snii_total_mass, SNII_NMET, SNII_NMASS);
91  interp->snii_metallicity_interp = gsl_interp2d_alloc(gsl_interp2d_bilinear, SNII_NMET, SNII_NMASS);
92  gsl_interp2d_init(interp->snii_metallicity_interp, snii_metallicities, snii_masses, snii_total_metals, SNII_NMET, SNII_NMASS);
93  for(i=0; i<NMETALS; i++) {
94  interp->snii_metals_interp[i] = gsl_interp2d_alloc(gsl_interp2d_bilinear, SNII_NMET, SNII_NMASS);
95  gsl_interp2d_init(interp->snii_metals_interp[i], snii_metallicities, snii_masses, snii_yield[i], SNII_NMET, SNII_NMASS);
96  }
97 }
Interp interp
#define LIFE_NMET
Definition: metal_tables.h:16
static const double snii_yield[NSPECIES][SNII_NMET *SNII_NMASS]
Definition: metal_tables.h:334
#define AGB_NMET
Definition: metal_tables.h:68
#define LIFE_NMASS
Definition: metal_tables.h:17
#define SNII_NMASS
Definition: metal_tables.h:309
#define AGB_NMASS
Definition: metal_tables.h:69
static const double snii_total_mass[SNII_NMET *SNII_NMASS]
Definition: metal_tables.h:312
static const double agb_total_mass[AGB_NMET *AGB_NMASS]
Definition: metal_tables.h:72
static const double agb_total_metals[AGB_NMET *AGB_NMASS]
Definition: metal_tables.h:94
static const double lifetime_metallicity[LIFE_NMET]
Definition: metal_tables.h:18
static const double lifetime[LIFE_NMASS *LIFE_NMET]
Definition: metal_tables.h:24
static const double agb_yield[NSPECIES][AGB_NMET *AGB_NMASS]
Definition: metal_tables.h:116
static const double snii_masses[SNII_NMASS]
Definition: metal_tables.h:310
static const double lifetime_masses[LIFE_NMASS]
Definition: metal_tables.h:20
static const double snii_total_metals[SNII_NMET *SNII_NMASS]
Definition: metal_tables.h:323
static const double agb_metallicities[AGB_NMET]
Definition: metal_tables.h:71
#define NMETALS
Definition: slotsmanager.h:60

References agb_masses, agb_metallicities, AGB_NMASS, AGB_NMET, agb_total_mass, agb_total_metals, agb_yield, interp, LIFE_NMASS, LIFE_NMET, lifetime, lifetime_masses, lifetime_metallicity, NMETALS, snii_masses, snii_metallicities, SNII_NMASS, SNII_NMET, snii_total_mass, snii_total_metals, and snii_yield.

Referenced by metal_return_init(), and test_yields().

Here is the caller graph for this function:

◆ stellar_density()

void stellar_density ( const ActiveParticles act,
MyFloat StarVolumeSPH,
MyFloat MassReturn,
const ForceTree *const  tree 
)

Definition at line 923 of file metal_return.c.

924 {
925  TreeWalk tw[1] = {{0}};
926  struct StellarDensityPriv priv[1];
927 
928  tw->ev_label = "STELLAR_DENSITY";
930  tw->NoNgblist = 1;
939  tw->priv = priv;
940  tw->tree = tree;
941 
942  int i;
943 
944  priv->MassReturn = MassReturn;
945 
946  priv->Left = (MyFloat *) mymalloc("DENS_PRIV->Left", SlotsManager->info[4].size * sizeof(MyFloat));
947  priv->Right = (MyFloat *) mymalloc("DENS_PRIV->Right", SlotsManager->info[4].size * sizeof(MyFloat));
948  priv->NumNgb = (MyFloat (*) [NHSML]) mymalloc("DENS_PRIV->NumNgb", SlotsManager->info[4].size * sizeof(priv->NumNgb[0]));
949  priv->VolumeSPH = (MyFloat (*) [NHSML]) mymalloc("DENS_PRIV->VolumeSPH", SlotsManager->info[4].size * sizeof(priv->VolumeSPH[0]));
950  priv->maxcmpte = (int *) mymalloc("maxcmpte", SlotsManager->info[4].size * sizeof(int));
951 
952  priv->DesNumNgb = GetNumNgb(GetDensityKernelType());
953 
954  #pragma omp parallel for
955  for(i = 0; i < act->NumActiveParticle; i++) {
956  int a = act->ActiveParticle ? act->ActiveParticle[i] : i;
957  /* Skip the garbage particles */
958  if(P[a].IsGarbage)
959  continue;
960  if(!stellar_density_haswork(a, tw))
961  continue;
962  int pi = P[a].PI;
963  priv->Left[pi] = 0;
964  priv->Right[pi] = tree->BoxSize;
965  }
966 
967  /* allocate buffers to arrange communication */
968 
970  #pragma omp parallel for
971  for(i = 0; i < act->NumActiveParticle; i++) {
972  int a = act->ActiveParticle ? act->ActiveParticle[i] : i;
973  /* Skip the garbage particles */
974  if(P[a].IsGarbage)
975  continue;
976  if(!stellar_density_haswork(a, tw))
977  continue;
978  /* Copy the Star Volume SPH*/
979  StarVolumeSPH[P[a].PI] = priv->VolumeSPH[P[a].PI][0];
980  if(priv->VolumeSPH[P[a].PI][0] == 0)
981  endrun(3, "i = %d pi = %d StarVolumeSPH %g hsml %g\n", a, P[a].PI, priv->VolumeSPH[P[a].PI][0], P[a].Hsml);
982  }
983 
984  myfree(priv->maxcmpte);
985  myfree(priv->VolumeSPH);
986  myfree(priv->NumNgb);
987  myfree(priv->Right);
988  myfree(priv->Left);
989 
990  double timeall = walltime_measure(WALLTIME_IGNORE);
991 
992  double timecomp = tw->timecomp3 + tw->timecomp1 + tw->timecomp2;
993  double timewait = tw->timewait1 + tw->timewait2;
994  double timecomm = tw->timecommsumm1 + tw->timecommsumm2;
995  walltime_add("/SPH/Metals/Density/Compute", timecomp);
996  walltime_add("/SPH/Metals/Density/Wait", timewait);
997  walltime_add("/SPH/Metals/Density/Comm", timecomm);
998  walltime_add("/SPH/Metals/Density/Misc", timeall - (timecomp + timewait + timecomm));
999 
1000  return;
1001 }
double GetNumNgb(enum DensityKernelType KernelType)
Definition: density.c:55
enum DensityKernelType GetDensityKernelType(void)
Definition: density.c:63
void endrun(int where, const char *fmt,...)
Definition: endrun.c:147
void stellar_density_check_neighbours(int i, TreeWalk *tw)
Definition: metal_return.c:820
static void stellar_density_reduce(int place, TreeWalkResultStellarDensity *remote, enum TreeWalkReduceMode mode, TreeWalk *tw)
Definition: metal_return.c:808
#define NHSML
Definition: metal_return.c:726
static int stellar_density_haswork(int i, TreeWalk *tw)
Definition: metal_return.c:765
static void stellar_density_ngbiter(TreeWalkQueryStellarDensity *I, TreeWalkResultStellarDensity *O, TreeWalkNgbIterStellarDensity *iter, LocalTreeWalk *lv)
Definition: metal_return.c:872
static void stellar_density_copy(int place, TreeWalkQueryStellarDensity *I, TreeWalk *tw)
Definition: metal_return.c:800
double BoxSize
Definition: forcetree.h:106
MyFloat * MassReturn
Definition: metal_return.c:755
double timecomp2
Definition: treewalk.h:124
double timecomp3
Definition: treewalk.h:125
double timecommsumm1
Definition: treewalk.h:126
double timewait2
Definition: treewalk.h:122
int NoNgblist
Definition: treewalk.h:156
double timecomp1
Definition: treewalk.h:123
double timewait1
Definition: treewalk.h:121
double timecommsumm2
Definition: treewalk.h:127
int treewalk_visit_nolist_ngbiter(TreeWalkQueryBase *I, TreeWalkResultBase *O, LocalTreeWalk *lv)
Definition: treewalk.c:1143
void treewalk_do_hsml_loop(TreeWalk *tw, int *queue, int64_t queuesize, int update_hsml)
Definition: treewalk.c:1254
void(* TreeWalkReduceResultFunction)(const int j, TreeWalkResultBase *result, const enum TreeWalkReduceMode mode, TreeWalk *tw)
Definition: treewalk.h:76
#define WALLTIME_IGNORE
Definition: walltime.h:6
#define walltime_add(name, dt)
Definition: walltime.h:9

References ActiveParticles::ActiveParticle, ForceTree::BoxSize, StellarDensityPriv::DesNumNgb, endrun(), TreeWalk::ev_label, TreeWalk::fill, GetDensityKernelType(), GetNumNgb(), TreeWalk::haswork, slots_manager_type::info, StellarDensityPriv::Left, StellarDensityPriv::MassReturn, StellarDensityPriv::maxcmpte, myfree, mymalloc, TreeWalk::ngbiter, TreeWalk::ngbiter_type_elsize, NHSML, TreeWalk::NoNgblist, ActiveParticles::NumActiveParticle, StellarDensityPriv::NumNgb, P, TreeWalk::postprocess, TreeWalk::priv, TreeWalk::query_type_elsize, TreeWalk::reduce, TreeWalk::result_type_elsize, StellarDensityPriv::Right, slot_info::size, SlotsManager, stellar_density_check_neighbours(), stellar_density_copy(), stellar_density_haswork(), stellar_density_ngbiter(), stellar_density_reduce(), TreeWalk::timecommsumm1, TreeWalk::timecommsumm2, TreeWalk::timecomp1, TreeWalk::timecomp2, TreeWalk::timecomp3, TreeWalk::timewait1, TreeWalk::timewait2, TreeWalk::tree, treewalk_do_hsml_loop(), treewalk_visit_nolist_ngbiter(), TreeWalk::visit, StellarDensityPriv::VolumeSPH, walltime_add, WALLTIME_IGNORE, and walltime_measure.

Referenced by metal_return().

Here is the call graph for this function:
Here is the caller graph for this function: