MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
forcetree.h
Go to the documentation of this file.
1 #ifndef FORCETREE_H
2 #define FORCETREE_H
3 
4 #include "types.h"
5 #include "domain.h"
6 /*
7  * Variables for Tree
8  * ------------------
9  */
10 
11 /* Total allowed number of particle children for a node*/
12 #define NMAXCHILD 8
13 
14 /* Defines for the type of node, classified by type of children.*/
15 #define PARTICLE_NODE_TYPE 0
16 #define NODE_NODE_TYPE 1
17 #define PSEUDO_NODE_TYPE 2
18 
19 /* Define to build a tree containing all types of particles*/
20 #define ALLMASK (1<<30)-1
21 #define GASMASK (1)
22 #define DMMASK (2)
23 #define STARMASK (1<<4)
24 #define BHMASK (1<<5)
25 
26 struct NodeChild
27 {
28  /* Stores the types of the child particles. Uses a bit field, 3 bits per particle.
29  */
30  unsigned int Types;
33  /* Number of daughter particles if node contains particles.
34  * During treebuild >= (1<<16) if node contains nodes.*/
35  int noccupied;
36 };
37 
38 struct NODE
39 {
40  int sibling;
41  int father;
45  struct {
46  unsigned int InternalTopLevel :1; /* TopLevel and has a child which is also TopLevel*/
47  unsigned int TopLevel :1; /* Node corresponding to a toplevel node */
48  unsigned int DependsOnLocalMass :1; /* Intersects with local mass */
49  unsigned int ChildType :2; /* Specify the type of children this node has: particles, other nodes, or pseudo-particles.
50  * (should be an enum, but not standard in C).*/
51  unsigned int unused : 3; /* Spare bits*/
52  } f;
53 
54  struct {
58  } mom;
59 
60  /* If the current node needs to be opened, go to the first element of this array.
61  * In principle storing the full array wastes memory, because we only use it for the leaf nodes.
62  * However, in practice the wasted memory is fairly small: there are sum(1/8^n) ~ 0.15 internal nodes
63  * for each leaf node, and we are losing 30% of the memory per node, so the total lost is 5%.
64  * Any attempt to get it back by using a separate allocation means we lost the ability to resize
65  * the Nodes array and that is always worse.*/
66  struct NodeChild s;
67 };
68 
69 /*Structure containing the Node pointer, and various Tree metadata.*/
70 /*The node index is an integer with unusual properties:
71  * no = 0..ForceTree.firstnode corresponds to a particle.
72  * no = ForceTree.firstnode..ForceTree.lastnode corresponds to actual tree nodes,
73  * and is the only memory allocated in ForceTree.Nodes_base. After the tree is built this becomes
74  * no = ForceTree.firstnode..ForceTree.numnodes which is the only allocated memory.
75  * no > ForceTree.lastnode means a pseudo particle on another processor*/
76 typedef struct ForceTree {
77  /*Is 1 if the tree is allocated. Only used inside force_tree_allocated() and when allocating.*/
79  /* Flags that hmax has been computed for this tree*/
81  /* Flags that the tree has fully computed and exchanged mass moments*/
83  /*Index of first internal node. Difference between Nodes and Nodes_base. == MaxPart*/
84  int firstnode;
85  /*Index of first pseudo-particle node*/
86  int lastnode;
87  /* Number of actually allocated nodes*/
88  int numnodes;
89  /* Types which are included have their bits set to 1*/
90  int mask;
91  /*Pointer to the TopLeaves struct imported from Domain. Sets up the pseudo particles.*/
93  /*Number of TopLeaves*/
97  struct NODE *Nodes;
98  /* The following pointers should only be used via accessors or inside of forcetree.c.
99  * The exception is the crazy memory shifting done in sfr_eff.c*/
100  /*This points to the actual memory allocated for the nodes.*/
101  struct NODE * Nodes_base;
103  int *Father;
104  int nfather;
106  double BoxSize;
108 
109 /*Initialize the internal parameters of the forcetree module*/
110 void init_forcetree_params(const int FastParticleType);
111 
112 int force_tree_allocated(const ForceTree * tt);
113 
114 /* This function propagates changed SPH smoothing lengths up the tree*/
115 void force_update_hmax(int * activeset, int size, ForceTree * tt, DomainDecomp * ddecomp);
116 
117 /* This is the main constructor for the tree structure.
118  The tree shall be either zero-filled, so that force_tree_allocated = 0, or a valid ForceTree.
119 */
120 void force_tree_rebuild(ForceTree * tree, DomainDecomp * ddecomp, const int HybridNuGrav, const int DoMoments, const char * EmergencyOutputDir);
121 
122 /* Main constructor with a mask argument.
123  * Mask is a bitfield, specified as 1 for each type that should be included. Use ALLMASK for all particle types.
124  * This is much than _rebuild: because the particles are sorted by type the merge step is much faster than
125  * with all particle types, and of course the tree is smaller.*/
126 void force_tree_rebuild_mask(ForceTree * tree, DomainDecomp * ddecomp, int mask, const int HybridNuGrav, const char * EmergencyOutputDir);
127 
128 /*Free the memory associated with the tree*/
130 void dump_particles(void);
131 
132 static inline int
133 node_is_pseudo_particle(int no, const ForceTree * tree)
134 {
135  return no >= tree->lastnode;
136 }
137 
138 static inline int
139 node_is_particle(int no, const ForceTree * tree)
140 {
141  return no >= 0 && no < tree->firstnode;
142 }
143 
144 static inline int
145 node_is_node(int no, const ForceTree * tree)
146 {
147  return (no >= tree->firstnode) && (no < tree->firstnode + tree->numnodes);
148 }
149 
150 int
151 force_get_father(int no, const ForceTree * tt);
152 
153 /*Internal API, exposed for tests*/
154 int
155 force_tree_create_nodes(const ForceTree tb, const int npart, int mask, DomainDecomp * ddecomp, const int HybridNuGrav);
156 
157 ForceTree
158 force_treeallocate(int64_t maxnodes, int64_t maxpart, DomainDecomp * ddecomp);
159 
160 void
161 force_update_node_parallel(const ForceTree * tree, const DomainDecomp * ddecomp);
162 
163 
164 #endif
165 
166 
167 
int force_get_father(int no, const ForceTree *tt)
Definition: forcetree.c:905
struct ForceTree ForceTree
void force_update_hmax(int *activeset, int size, ForceTree *tt, DomainDecomp *ddecomp)
Definition: forcetree.c:1271
void force_tree_rebuild(ForceTree *tree, DomainDecomp *ddecomp, const int HybridNuGrav, const int DoMoments, const char *EmergencyOutputDir)
Definition: forcetree.c:140
int force_tree_allocated(const ForceTree *tt)
Definition: forcetree.c:134
int force_tree_create_nodes(const ForceTree tb, const int npart, int mask, DomainDecomp *ddecomp, const int HybridNuGrav)
Definition: forcetree.c:661
ForceTree force_treeallocate(int64_t maxnodes, int64_t maxpart, DomainDecomp *ddecomp)
Definition: forcetree.c:1381
static int node_is_node(int no, const ForceTree *tree)
Definition: forcetree.h:145
void force_update_node_parallel(const ForceTree *tree, const DomainDecomp *ddecomp)
Definition: forcetree.c:1081
void force_tree_rebuild_mask(ForceTree *tree, DomainDecomp *ddecomp, int mask, const int HybridNuGrav, const char *EmergencyOutputDir)
Definition: forcetree.c:161
void init_forcetree_params(const int FastParticleType)
Definition: forcetree.c:43
void dump_particles(void)
static int node_is_particle(int no, const ForceTree *tree)
Definition: forcetree.h:139
static int node_is_pseudo_particle(int no, const ForceTree *tree)
Definition: forcetree.h:133
void force_tree_free(ForceTree *tt)
Definition: forcetree.c:1409
#define NMAXCHILD
Definition: forcetree.h:12
int nfather
Definition: forcetree.h:104
int NTopLeaves
Definition: forcetree.h:94
int moments_computed_flag
Definition: forcetree.h:82
int tree_allocated_flag
Definition: forcetree.h:78
double BoxSize
Definition: forcetree.h:106
int mask
Definition: forcetree.h:90
struct NODE * Nodes_base
Definition: forcetree.h:101
int * Father
Definition: forcetree.h:103
int hmax_computed_flag
Definition: forcetree.h:80
struct topleaf_data * TopLeaves
Definition: forcetree.h:92
struct NODE * Nodes
Definition: forcetree.h:97
int firstnode
Definition: forcetree.h:84
int numnodes
Definition: forcetree.h:88
int lastnode
Definition: forcetree.h:86
Definition: forcetree.h:39
int sibling
Definition: forcetree.h:40
struct NODE::@9 mom
unsigned int DependsOnLocalMass
Definition: forcetree.h:48
MyFloat center[3]
Definition: forcetree.h:43
unsigned int ChildType
Definition: forcetree.h:49
MyFloat mass
Definition: forcetree.h:56
unsigned int unused
Definition: forcetree.h:51
MyFloat hmax
Definition: forcetree.h:57
int father
Definition: forcetree.h:41
MyFloat cofm[3]
Definition: forcetree.h:55
unsigned int TopLevel
Definition: forcetree.h:47
struct NodeChild s
Definition: forcetree.h:66
unsigned int InternalTopLevel
Definition: forcetree.h:46
struct NODE::@8 f
MyFloat len
Definition: forcetree.h:42
int noccupied
Definition: forcetree.h:35
int suns[NMAXCHILD]
Definition: forcetree.h:32
unsigned int Types
Definition: forcetree.h:30
static const double tt[NEXACT]
LOW_PRECISION MyFloat
Definition: types.h:19