forked from kcroker/Gadget-2.0.7-ngravs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
longrange.c
144 lines (116 loc) · 2.85 KB
/
longrange.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <mpi.h>
#include "allvars.h"
#include "proto.h"
/*! \file longrange.c
* \brief driver routines for computation of long-range gravitational PM force
*/
#ifdef PMGRID
/*! Calls initializiation routines of periodic or/and non-periodic FFT
* routines.
*/
void long_range_init(void)
{
#ifdef PERIODIC
pm_init_periodic();
#ifdef PLACEHIGHRESREGION
pm_init_nonperiodic();
#endif
#else
pm_init_nonperiodic();
#endif
}
/*! This function calls subroutines that determine the spatial region covered
* by the PM mesh.
*/
void long_range_init_regionsize(void)
{
#ifdef PERIODIC
#ifdef PLACEHIGHRESREGION
if(RestartFlag != 1)
pm_init_regionsize();
pm_setup_nonperiodic_kernel();
#endif
#else
if(RestartFlag != 1)
pm_init_regionsize();
pm_setup_nonperiodic_kernel();
#endif
}
/*! This function is a driver routine for the long-range PM force
* computation. It calls periodic and/or non-periodic FFT routines as needed
* for the present simulation set-up.
*/
void long_range_force(void)
{
int i;
#ifndef PERIODIC
int j;
double fac;
#endif
for(i = 0; i < NumPart; i++)
P[i].GravPM[0] = P[i].GravPM[1] = P[i].GravPM[2] = 0;
#ifdef NOGRAVITY
return;
#endif
#ifdef PERIODIC
pmforce_periodic();
#ifdef PLACEHIGHRESREGION
i = pmforce_nonperiodic(1);
if(i == 1) /* this is returned if a particle lied outside allowed range */
{
pm_init_regionsize();
pm_setup_nonperiodic_kernel();
i = pmforce_nonperiodic(1); /* try again */
}
if(i == 1)
endrun(68686);
#endif
#else
i = pmforce_nonperiodic(0);
if(i == 1) /* this is returned if a particle lied outside allowed range */
{
pm_init_regionsize();
pm_setup_nonperiodic_kernel();
i = pmforce_nonperiodic(0); /* try again */
}
if(i == 1)
endrun(68687);
#ifdef PLACEHIGHRESREGION
i = pmforce_nonperiodic(1);
if(i == 1) /* this is returned if a particle lied outside allowed range */
{
pm_init_regionsize();
pm_setup_nonperiodic_kernel();
/* try again */
for(i = 0; i < NumPart; i++)
P[i].GravPM[0] = P[i].GravPM[1] = P[i].GravPM[2] = 0;
i = pmforce_nonperiodic(0) + pmforce_nonperiodic(1);
}
if(i != 0)
endrun(68688);
#endif
#endif
#ifndef PERIODIC
if(All.ComovingIntegrationOn)
{
fac = 0.5 * All.Hubble * All.Hubble * All.Omega0;
for(i = 0; i < NumPart; i++)
for(j = 0; j < 3; j++)
P[i].GravPM[j] += fac * P[i].Pos[j];
}
/* Finally, the following factor allows a computation of cosmological simulation
with vacuum energy in physical coordinates */
if(All.ComovingIntegrationOn == 0)
{
fac = All.OmegaLambda * All.Hubble * All.Hubble;
for(i = 0; i < NumPart; i++)
for(j = 0; j < 3; j++)
P[i].GravPM[j] += fac * P[i].Pos[j];
}
#endif
}
#endif