GADGET-4
ngbtree.h
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#ifndef NGBTREE_H_
13#define NGBTREE_H_
14
15#include "../data/simparticles.h"
16#include "../time_integration/driftfac.h"
17#include "../tree/tree.h"
18
23{
25 int no;
26};
27
28struct ngbnode : public basenode
29{
30 // we do this ugly trick of using memcpy for our own copy constructor and assignment operator
31 // because the atomic_flag in particle_data has an implicitly deleted copy operator... so that the implicit functions
32 // for this are unavailable. But we know what we are doing here, and surrounding this with an ugly hack
33 // is the easiest way at the moment to work around this in our case unnecessary protection
34
36
37 // declare our own copy constructor
38 ngbnode(ngbnode &other) { memcpy(static_cast<void *>(this), static_cast<void *>(&other), sizeof(ngbnode)); }
39
40 // declare our own assignment operator
42 {
43 memcpy(static_cast<void *>(this), static_cast<void *>(&other), sizeof(ngbnode));
44 return *this;
45 }
46
49
55
56 std::atomic<integertime> Ti_Current;
57
59 {
60 while(access.test_and_set(std::memory_order_acquire))
61 ; // acquire spin lock
62
63 if(Ti_Current != time1)
64 {
65 double dt_drift;
66
68 dt_drift = Driftfac.get_drift_factor(Ti_Current, time1);
69 else
70 dt_drift = (time1 - Ti_Current) * All.Timebase_interval;
71
72 /* get the shift in the enclosing box in coordinate space */
73 double posdiff_min[3];
74 double posdiff_max[3];
75 for(int j = 0; j < 3; j++)
76 {
77 posdiff_min[j] = vmin[j] * dt_drift;
78 posdiff_max[j] = vmax[j] * dt_drift;
79 }
80
81 /* convert to integer coordinate shifts */
82 MySignedIntPosType delta_min[3];
83 MySignedIntPosType delta_max[3];
84 Sp->pos_to_signedintpos(posdiff_min, delta_min);
85 Sp->pos_to_signedintpos(posdiff_max, delta_max);
86
87 /* not adjust the bounding box in integer coordinates */
88 for(int j = 0; j < 3; j++)
89 {
90 center_offset_min[j] += delta_min[j];
91 center_offset_max[j] += delta_max[j];
92 }
93
94 MaxHsml += MaxDtHsml * dt_drift;
95
96 Ti_Current = time1;
97 }
98
99 access.clear(std::memory_order_release);
100 }
101};
102
104{
106
109
111 unsigned char Nextnode_shmrank;
112
113 signed char TimeBinHydro;
114};
115
116class ngbtree : public tree<ngbnode, simparticles, ngbpoint_data, foreign_sphpoint_data>
117{
118 public:
120
121 // The various using statements make sure that we can access the elements from the base class without having to use "this"
123 using basetree::D;
124 using basetree::Father;
128 using basetree::get_Pp;
131 using basetree::MaxNodes;
132 using basetree::MaxPart;
133 using basetree::Nextnode;
135 using basetree::Nodes;
136 using basetree::NumNodes;
141 using basetree::TopNodes;
142 using basetree::Tp;
145
146 void update_velocities(void);
147 void update_maxhsml(void);
148 void update_vbounds(int i, int *nchanged, int *nodelist, char *flag_changed);
149 void check_bounds(void);
150
151 void update_node_recursive(int no, int sib, int mode) override;
152 void exchange_topleafdata(void) override;
153 void fill_in_export_points(ngbpoint_data *exp_point, int i, int no) override;
154 void report_log_message(void) override;
155
156 private: /* private member functions */
157 void finish_vounds_update(int nchanged, int *nodelist);
158 void finish_maxhsml_update(int nchanged, int *nodelist);
159};
160
161#endif
global_data_all_processes All
Definition: main.cc:40
double get_drift_factor(integertime time0, integertime time1)
Definition: driftfac.cc:68
MySignedIntPosType pos_to_signedintpos(T posdiff)
void exchange_topleafdata(void) override
tree< ngbnode, simparticles, ngbpoint_data, foreign_sphpoint_data > basetree
Definition: ngbtree.h:119
void update_vbounds(int i, int *nchanged, int *nodelist, char *flag_changed)
void update_node_recursive(int no, int sib, int mode) override
void update_maxhsml(void)
void update_velocities(void)
void fill_in_export_points(ngbpoint_data *exp_point, int i, int no) override
void report_log_message(void) override
void check_bounds(void)
Definition: tree.h:91
void tree_export_node_threads(int no, int i, thread_data *thread, offset_tuple off=0)
Definition: tree.cc:1301
sph_particle_data * get_SphPp(int n, unsigned char shmrank)
Definition: tree.h:292
int integertime
Definition: constants.h:331
float MyDouble
Definition: dtypes.h:87
uint32_t MyIntPosType
Definition: dtypes.h:35
float MyNgbTreeFloat
Definition: dtypes.h:88
int32_t MySignedIntPosType
Definition: dtypes.h:36
driftfac Driftfac
Definition: main.cc:41
Definition: tree.h:48
std::atomic_flag access
Definition: tree.h:68
unsigned char Nextnode_shmrank
Definition: ngbtree.h:111
sph_particle_data_hydrocore SphCore
Definition: ngbtree.h:105
signed char TimeBinHydro
Definition: ngbtree.h:113
MyIntPosType IntPos[3]
Definition: ngbtree.h:108
std::atomic< integertime > Ti_Current
Definition: ngbtree.h:56
MyNgbTreeFloat vmax[3]
Definition: ngbtree.h:51
ngbnode & operator=(ngbnode &other)
Definition: ngbtree.h:41
MyNgbTreeFloat MaxHsml
Definition: ngbtree.h:52
MySignedIntPosType center_offset_max[3]
Definition: ngbtree.h:48
MyNgbTreeFloat MaxDtHsml
Definition: ngbtree.h:53
ngbnode(ngbnode &other)
Definition: ngbtree.h:38
MySignedIntPosType center_offset_min[3]
Definition: ngbtree.h:47
void drift_node(integertime time1, simparticles *Sp)
Definition: ngbtree.h:58
MyNgbTreeFloat vmin[3]
Definition: ngbtree.h:50
ngbnode()
Definition: ngbtree.h:35
MyNgbTreeFloat MaxCsnd
Definition: ngbtree.h:54
MyIntPosType IntPos[3]
Definition: ngbtree.h:24