12#include "gadgetconfig.h"
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 "../logs/timer.h"
27#include "../main/simulation.h"
29#include "../system/system.h"
48#ifdef RANDOMIZE_DOMAINCENTER
50 for(
int i = 0; i < Tp->NumPart; i++)
52 for(
int j = 0; j < 3; j++)
53 Tp->P[i].IntPos[j] -= Tp->CurrentShiftVector[j];
55 Tp->constrain_intpos(Tp->P[i].IntPos);
58 for(
int j = 0; j < 3; j++)
59 Tp->CurrentShiftVector[j] = 0;
76 for(
int i = 0; i < Tp->NumPart; i++)
77 for(
int j = 0; j < 3; j++)
79 if(Tp->P[i].IntPos[j] < leftbound)
82 if(Tp->P[i].IntPos[j] > rightbound)
86 MPI_Allreduce(MPI_IN_PLACE, &flag, 1, MPI_INT, MPI_MAX, Communicator);
90 domain_printf(
"DOMAIN: Simulation region has enlarged, need to adjusted mapping.\n");
92 for(
int i = 0; i < Tp->NumPart; i++)
93 for(
int j = 0; j < 3; j++)
96 Tp->FacCoordToInt *= 0.5;
97 Tp->FacIntToCoord *= 2.0;
100 for(
int j = 0; j < 3; j++)
101 Tp->RegionCorner[j] = Tp->RegionCenter[j] - 0.5 * Tp->RegionLen;
103#
if defined(PMGRID) && (!defined(PERIODIC) || defined(PLACEHIGHRESREGION))
105 Tp->OldMeshSize[0] = 0;
106 Tp->OldMeshSize[1] = 0;
119#ifdef RANDOMIZE_DOMAINCENTER
122#if defined(RANDOMIZE_DOMAINCENTER_TYPES) || defined(PLACEHIGHRESREGION)
123 domain_find_type_extension();
128#if defined(RANDOMIZE_DOMAINCENTER_TYPES) || defined(PLACEHIGHRESREGION)
132 for(
int j = 0; j < 3; j++)
135#ifdef POSITIONS_IN_64BIT
136 Tp->CurrentShiftVector[j] <<= 32;
139#ifdef POSITIONS_IN_128BIT
140 Tp->CurrentShiftVector[j] <<= 32;
142 Tp->CurrentShiftVector[j] <<= 32;
144 Tp->CurrentShiftVector[j] <<= 32;
148#if defined(RANDOMIZE_DOMAINCENTER_TYPES) || defined(PLACEHIGHRESREGION)
149 MyIntPosType boxoff = (Tp->CurrentShiftVector[j] & Tp->PlacingMask);
150 MyIntPosType inboxoff = (Tp->CurrentShiftVector[j] - boxoff) % (Tp->PlacingBlocksize - domainInnersize);
152 MyIntPosType off = domainXmintot[j] + domainReferenceIntPos[j] + Tp->CurrentShiftVector[j];
153 Tp->CurrentShiftVector[j] -= off;
154 Tp->CurrentShiftVector[j] += boxoff + inboxoff;
156 if(domain_type_extension_overlap(j))
158 domain_printf(
"(Tp->PlacingBlocksize - domainInnersize)=%g %g\n",
159 (Tp->PlacingBlocksize - domainInnersize) * Tp->FacIntToCoord, inboxoff * Tp->FacIntToCoord);
160 domain_printf(
"DOMAIN: Need to draw shift vector again for j=%d\n", j);
161 Terminate(
"we should not get here anymore\n");
172#ifdef GRAVITY_TALLBOX
173 Tp->CurrentShiftVector[GRAVITY_TALLBOX] = 0;
176 MPI_Bcast(Tp->CurrentShiftVector, 3 *
sizeof(
MyIntPosType), MPI_BYTE, 0, Communicator);
178 for(
int i = 0; i < Tp->NumPart; i++)
180 for(
int j = 0; j < 3; j++)
181 Tp->P[i].IntPos[j] += Tp->CurrentShiftVector[j];
183 Tp->constrain_intpos(Tp->P[i].IntPos);
186 domain_printf(
"DOMAIN: New shift vector determined (%g %g %g)\n",
193#if defined(RANDOMIZE_DOMAINCENTER_TYPES) || defined(PLACEHIGHRESREGION)
195template <
typename partset>
201 MyIntPosType xmin = xmintot[j] + domainReferenceIntPos[j] + Tp->CurrentShiftVector[j];
202 MyIntPosType xmax = xmaxtot[j] + domainReferenceIntPos[j] + Tp->CurrentShiftVector[j];
204 if((xmin & Tp->PlacingMask) != (xmax & Tp->PlacingMask))
210template <
typename partset>
216 int have_high_mesh = NTask;
218 for(
int i = 0; i < Tp->NumPart; i++)
220 if(((1 << Tp->P[i].getType()) & (RANDOMIZE_DOMAINCENTER_TYPES)))
222 for(
int j = 0; j < 3; j++)
223 domainReferenceIntPos[j] = Tp->P[i].IntPos[j];
225 have_high_mesh = ThisTask;
230 int have_global[2] = {have_high_mesh, ThisTask};
232 MPI_Allreduce(MPI_IN_PLACE, have_global, 1, MPI_2INT, MPI_MINLOC, Communicator);
234 if(have_global[0] >= NTask)
235 Terminate(
"have_global[0]=%d >= NTask=%d: Don't we have any particle? Note: RANDOMIZE_DOMAINCENTER_TYPES=%d is a bitmask",
236 have_global[0], NTask, RANDOMIZE_DOMAINCENTER_TYPES);
238 MPI_Bcast(domainReferenceIntPos, 3 *
sizeof(
MyIntPosType), MPI_BYTE, have_global[1], Communicator);
244 for(
int j = 0; j < 3; j++)
250 for(
int i = 0; i < Tp->NumPart; i++)
252 if(((1 << Tp->P[i].getType()) & (RANDOMIZE_DOMAINCENTER_TYPES)))
254 MyIntPosType diff[3] = {Tp->P[i].IntPos[0] - domainReferenceIntPos[0], Tp->P[i].IntPos[1] - domainReferenceIntPos[1],
255 Tp->P[i].IntPos[2] - domainReferenceIntPos[2]};
259 for(
int j = 0; j < 3; j++)
261 if(delta[j] > xmax[j])
263 if(delta[j] < xmin[j])
272 for(
int j = 0; j < 3; j++)
273 domainXmaxtot[j] += 1;
275 domainInnersize = domainXmaxtot[0] - domainXmintot[0];
277 if((
MyIntPosType)(domainXmaxtot[1] - domainXmintot[1]) > domainInnersize)
278 domainInnersize = domainXmaxtot[1] - domainXmintot[1];
280 if((
MyIntPosType)(domainXmaxtot[2] - domainXmintot[2]) > domainInnersize)
281 domainInnersize = domainXmaxtot[2] - domainXmintot[2];
283 domain_printf(
"DOMAIN: Shrink-wrap region size for RANDOMIZE_DOMAINCENTER_TYPES is %g\n", domainInnersize * Tp->FacIntToCoord);
285 if(domainInnersize * Tp->FacIntToCoord >= 0.125 *
All.
BoxSize)
286 Terminate(
"inappropriately big region selection for RANDOMIZE_DOMAINCENTER_TYPES");
290 MyIntPosType ref_size = domainInnersize + (domainInnersize >> 3);
292 Tp->PlacingBlocksize = 1;
297 if(Tp->PlacingBlocksize >= ref_size)
300 Tp->PlacingBlocksize <<= 1;
301 Tp->PlacingMask <<= 1;
304 domain_printf(
"DOMAIN: We enlarge this to %g (%g times smaller than boxsize)\n", Tp->PlacingBlocksize * Tp->FacIntToCoord,
305 All.
BoxSize / (Tp->PlacingBlocksize * Tp->FacIntToCoord));
309#ifdef LIGHTCONE_PARTICLES
316#include "../data/simparticles.h"
319#ifdef LIGHTCONE_PARTICLES
320#include "../data/lcparticles.h"
global_data_all_processes All
int32_t MySignedIntPosType
#define BITS_FOR_POSITIONS
MPI_Datatype MPI_MyIntPosType
MPI_Op MPI_MAX_MySignedIntPosType
MPI_Op MPI_MIN_MySignedIntPosType
expr pow(half base, half exp)
double get_random_number(void)