GADGET-4
grav_external.cc
Go to the documentation of this file.
1/*******************************************************************************
2 * \copyright This file is part of the GADGET4 N-body/SPH code developed
3 * \copyright by Volker Springel. Copyright (C) 2014-2020 by Volker Springel
4 * \copyright (vspringel@mpa-garching.mpg.de) and all contributing authors.
5 *******************************************************************************/
6
12#include "gadgetconfig.h"
13
14#ifdef EXTERNALGRAVITY
15
16#include <math.h>
17#include <mpi.h>
18#include <stdlib.h>
19#include <string.h>
20
21#include "../data/allvars.h"
22#include "../data/dtypes.h"
23#include "../data/intposconvert.h"
24#include "../data/mymalloc.h"
25#include "../domain/domain.h"
26#include "../fmm/fmm.h"
27#include "../gravtree/gravtree.h"
28#include "../logs/logs.h"
29#include "../logs/timer.h"
30#include "../main/simulation.h"
31#include "../mpi_utils/mpi_utils.h"
32#include "../pm/pm.h"
33#include "../system/system.h"
34#include "../time_integration/timestep.h"
35
36void sim::gravity_external(void)
37{
38 for(int i = 0; i < Sp.TimeBinsGravity.NActiveParticles; i++)
39 {
41
42#if defined(EVALPOTENTIAL) || defined(OUTPUT_POTENTIAL)
43 Sp.P[target].ExtPotential = 0;
44#endif
45
46#ifdef EXTERNALGRAVITY_STATICHQ
47 {
49 Sp.intpos_to_pos(Sp.P[target].IntPos, pos.da); /* converts the integer coordinate to floating point */
50
51 double r = sqrt(pos.r2());
52
53 double m = All.Mass_StaticHQHalo * pow(r / (r + All.A_StaticHQHalo), 2);
54
55 if(r > 0)
56 Sp.P[target].GravAccel += (-All.G * m / (r * r * r)) * pos;
57
58#if defined(EVALPOTENTIAL) || defined(OUTPUT_POTENTIAL)
59 Sp.P[target].ExtPotential += (-All.G * All.Mass_StaticHQHalo / (r + All.A_StaticHQHalo));
60#endif
61 }
62#endif
63 }
64}
65
66#endif
global_data_all_processes All
Definition: main.cc:40
void intpos_to_pos(MyIntPosType *intpos, T *posdiff)
simparticles Sp
Definition: simulation.h:56
TimeBinData TimeBinsGravity
Definition: simparticles.h:205
particle_data * P
Definition: simparticles.h:54
T r2(void)
Definition: symtensors.h:187
T da[3]
Definition: symtensors.h:106
expr pow(half base, half exp)
Definition: half.hpp:2803
expr sqrt(half arg)
Definition: half.hpp:2777
int NActiveParticles
Definition: timestep.h:18
int * ActiveParticleList
Definition: timestep.h:20
vector< MyFloat > GravAccel
Definition: particle_data.h:55
MyIntPosType IntPos[3]
Definition: particle_data.h:53