12#include "gadgetconfig.h"
20#include "../data/allvars.h"
21#include "../data/dtypes.h"
22#include "../data/intposconvert.h"
23#include "../data/mymalloc.h"
24#include "../domain/domain.h"
25#include "../gravity/ewald.h"
26#include "../gravtree/gravtree.h"
27#include "../gravtree/gwalk.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 "../mpi_utils/shared_mem_handler.h"
34#include "../sort/cxxsort.h"
35#include "../system/system.h"
36#include "../time_integration/timestep.h"
55template <
typename partset>
58 for(
int i = 0; i <=
NTAB; i++)
71 shortrange_factors[i].fac0 = (u > 0) ? (
erfc(u) - 1.0) / u : -2.0 /
sqrt(
M_PI);
72 shortrange_factors[i].fac1 = (u > 0) ? ((1.0 -
erfc(u)) - 2.0 * u /
sqrt(
M_PI) *
exp(-u * u)) / (u * u) : 0;
73#if(MULTIPOLE_ORDER >= 2)
74 shortrange_factors[i].fac2 =
75 (u > 0) ? (-3.0 * (1.0 -
erfc(u)) + (6 * u + 4 *
pow(u, 3)) /
sqrt(
M_PI) *
exp(-u * u)) /
pow(u, 3) : 0;
77#if(MULTIPOLE_ORDER >= 3)
78 shortrange_factors[i].fac3 =
79 (u > 0) ? (15.0 * (1.0 -
erfc(u)) - (30 * u + 20 *
pow(u, 3) + 8 *
pow(u, 5)) /
sqrt(
M_PI) *
exp(-u * u)) /
pow(u, 4) : 0;
81#if(MULTIPOLE_ORDER >= 4)
82 shortrange_factors[i].fac4 =
83 (u > 0) ? (-105.0 * (1.0 -
erfc(u)) +
84 (210.0 * u + 140.0 *
pow(u, 3) + 56.0 *
pow(u, 5) + 16.0 *
pow(u, 7)) /
sqrt(
M_PI) *
exp(-u * u)) /
88#if(MULTIPOLE_ORDER >= 5)
89 shortrange_factors[i].fac5 = (u > 0) ? (945.0 * (1.0 -
erfc(u)) - (1890.0 * u + 1260.0 *
pow(u, 3) + 504.0 *
pow(u, 5) +
90 144.0 *
pow(u, 7) + 32.0 *
pow(u, 9)) /
98template <
typename partset>
101 for(
int i = 0; i < 2; i++)
103 mf[i].rcut2 = Tp->Rcut[i] * Tp->Rcut[i];
104 double dblrcut[3] = {Tp->Rcut[i], Tp->Rcut[i],
109 mf[i].asmthinv1 = 0.5 / Tp->Asmth[i];
113 mf[i].asmthinv2 = mf[i].asmthinv1 * mf[i].asmthinv1;
114#if(MULTIPOLE_ORDER >= 2)
115 mf[i].asmthinv3 = mf[i].asmthinv2 * mf[i].asmthinv1;
117#if(MULTIPOLE_ORDER >= 3)
118 mf[i].asmthinv4 = mf[i].asmthinv3 * mf[i].asmthinv1;
120#if(MULTIPOLE_ORDER >= 4)
121 mf[i].asmthinv5 = mf[i].asmthinv4 * mf[i].asmthinv1;
123#if(MULTIPOLE_ORDER >= 5)
124 mf[i].asmthinv6 = mf[i].asmthinv5 * mf[i].asmthinv1;
127 mf[i].asmthfac = mf[i].asmthinv1 * (
NTAB / (
RCUT / 2.0));
133template <
typename partset>
136 int *send_count = (
int *)
Mem.mymalloc_movable(&send_count,
"send_count",
sizeof(
int) * D->NTask);
137 int *send_offset = (
int *)
Mem.mymalloc_movable(&send_offset,
"send_offset",
sizeof(
int) * D->NTask);
138 int *recv_count = (
int *)
Mem.mymalloc_movable(&recv_count,
"recv_count",
sizeof(
int) * D->NTask);
139 int *recv_offset = (
int *)
Mem.mymalloc_movable(&recv_offset,
"tecv_offset",
sizeof(
int) * D->NTask);
142 for(
int j = 0; j < D->NTask; j++)
147 for(
int i = 0; i < D->NTask; i++)
148 for(
int j = 0; j < Recv_count[i]; j++, n++)
150#ifndef HIERARCHICAL_GRAVITY
151 if(Points[n].ActiveFlag)
154 ResultsActiveImported[k].index = Points[n].index;
159 myMPI_Alltoall(recv_count, 1, MPI_INT, send_count, 1, MPI_INT, D->Communicator);
167 for(
int j = 0; j < D->NTask; j++)
169 Nexport += send_count[j];
170 Nimport += recv_count[j];
173 send_offset[j] = send_offset[j - 1] + send_count[j - 1];
174 recv_offset[j] = recv_offset[j - 1] + recv_count[j - 1];
182 for(
int ngrp = 1; ngrp < (1 << D->PTask); ngrp++)
186 if(recvTask < D->NTask)
188 if(send_count[recvTask] > 0 || recv_count[recvTask] > 0)
191 MPI_BYTE, recvTask,
TAG_FOF_A, &tmp_results[send_offset[recvTask]],
197 for(
int i = 0; i < Nexport; i++)
199 int target = tmp_results[i].
index;
201 for(
int k = 0; k < 3; k++)
202 Tp->P[target].GravAccel[k] += tmp_results[i].
GravAccel[k];
204 Tp->P[target].Potential += tmp_results[i].Potential;
210 Mem.myfree(tmp_results);
212 Mem.myfree(recv_offset);
213 Mem.myfree(recv_count);
214 Mem.myfree(send_offset);
215 Mem.myfree(send_count);
219#include "../data/simparticles.h"
void gravity_exchange_forces(void)
int32_t MySignedIntPosType
int myMPI_Alltoall(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
int myMPI_Sendrecv(void *sendbuf, size_t sendcount, MPI_Datatype sendtype, int dest, int sendtag, void *recvbuf, size_t recvcount, MPI_Datatype recvtype, int source, int recvtag, MPI_Comm comm, MPI_Status *status)
expr pow(half base, half exp)
vector< MyFloat > GravAccel