12#include "gadgetconfig.h"
20#include "../data/allvars.h"
21#include "../data/dtypes.h"
22#include "../data/mymalloc.h"
23#include "../domain/domain.h"
25#include "../logs/timer.h"
26#include "../main/simulation.h"
27#include "../mpi_utils/mpi_utils.h"
28#include "../ngbtree/ngbtree.h"
29#include "../sort/peano.h"
30#include "../sph/kernel.h"
31#include "../system/system.h"
32#include "../time_integration/timestep.h"
34#ifdef PRESSURE_ENTROPY_SPH
36#define MAX_ITER_ENTROPY 100
37#define ENTROPY_TOLERANCE 1.0e-5
43void sph::init_entropy(
void)
51 int *targetList = (
int *)
Mem.mymalloc(
"targetlist",
Tp->
NumGas *
sizeof(
int));
58 if(target < 0 || target >=
Tp->
NumGas)
60 targetList[ndensities++] = target;
85 int global_left_particles = 0;
87 MPI_Allreduce(&ndensities, &global_left_particles, 1, MPI_INT, MPI_SUM,
D->Communicator);
110 densities_determine(ndensities, targetList);
112 MPI_Allreduce(MPI_IN_PLACE, &max_ncycles, 1, MPI_INT, MPI_MAX,
D->Communicator);
122 for(
int i = 0; i < ndensities; i++)
124 int target = targetList[i];
132 if(SphP[target].EntropyToInvGammaPred > 0 && SphP[target].Density > 0)
134 entropy_old = SphP[target].
Entropy;
135 SphP[target].PressureSphDensity /= SphP[target].EntropyToInvGammaPred;
138 SphP[target].EntropyToInvGammaPred =
pow(SphP[target].Entropy, 1.0 /
GAMMA);
142 entropy_old = SphP[target].
Entropy;
143 SphP[target].PressureSphDensity = 0;
145 SphP[target].EntropyToInvGammaPred = 0;
148 if(
fabs(entropy_old - SphP[target].Entropy) > ENTROPY_TOLERANCE * entropy_old)
149 targetList[npleft++] = target;
155 MPI_Allreduce(&ndensities, &global_left_particles, 1, MPI_INT, MPI_SUM,
D->Communicator);
163 D->mpi_printf(
"SPH-INIT-ENTROPY: ngb iteration %4d: took %8.3f , need to repeat for %012lld local particles.\n", iter,
167 Terminate(
"failed to converge in neighbour iteration in density()\n");
170 D->mpi_printf(
"SPH-INIT-ENTROPY: ngb iteration %4d: took %8.3f\n", ++iter,
Logs.
timediff(t0, t1));
172 while(global_left_particles > 0);
183 Mem.myfree(targetList);
187 D->mpi_printf(
"SPH-INIT-ENTROPY: entropy calculation is done. took: %8.3f\n",
Logs.
timediff(tstart, tb));
194void sph::setup_entropy_to_invgamma(
void)
global_data_all_processes All
double timediff(double t0, double t1)
double getAllocatedBytesInMB(void)
TimeBinData TimeBinsHydro
long long sum_NumForeignPoints
void cleanup_shared_memory_access(void)
domain< simparticles > * D
long long sum_NumForeignNodes
void prepare_shared_memory_access(void)
foreign_sphpoint_data * Foreign_Points
void tree_initialize_leaf_node_access_info(void)
#define TIMER_START(counter)
Starts the timer counter.
#define TIMER_STOP(counter)
Stops the timer counter.
#define TIMER_STORE
Copies the current value of CPU times to a stored variable, such that differences with respect to thi...
expr pow(half base, half exp)
void set_cosmo_factors_for_current_time(void)
unsigned char getType(void)