Peano
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
ParticleSet.py
Go to the documentation of this file.
1# This file is part of the Peano project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
4
5from peano4.datamodel.DoF import DoF
6from peano4.datamodel.DaStGen2 import DaStGen2Generator
7
8from .Particle import Particle
9
10import dastgen2
11import os
12
13
14from enum import Enum
15
16
19 self,
20 data,
21 gather_particles,
22 ):
23 self._data = data
24 self._gather_particles = gather_particles
25
26 @property
28 return self._gather_particles
29
31 return (
32 "peano4::stacks::STDVectorOverContainerOfPointers< "
33 + self._data.get_full_qualified_type()
34 + " >"
35 )
36
38 return (
39 """
40#include "peano4/stacks/STDVectorOverContainerOfPointers.h"
41#include "../globaldata/"""
42 + self._data.particle_model.name
43 + """.h"
44#include \""""
45 + self._data.namespace[-1]
46 + """/"""
47 + self._data.name
48 + """.h"
49"""
50 )
51
52
54 """!
55
56 Map a particle set onto heap objects indexed by a list
57
58 This class is tied to peano4::stacks::STDVectorOverContainerOfPointers, i.e.
59 Peano's stacks are realised via std::vector from the C++ standard library.
60 Each entry within this vector then resembles a C++ container over pointers
61 to the heap. That is, all particles are stored on the heap. They are
62 scattered. The C++ pointer per stack entry that's used to store all the
63 particle pointers is realised through std::list.
64
65 Please consult @ref page_swift_performance_optimisation "the generic discussion on the impact of storage schemes".
66
67 @image html ParticleSetGenerator_ScatteredOnHeap.png
68
69
70 """
71
72 def __init__(self, data):
73 super(ParticleSetGenerator_ScatteredOnHeap_IndexByList, self).__init__(
74 data, False
75 )
76
77 def construct_output(self, output):
78 d = {"PARTICLE_TYPE": self._data.particle_model.name, "STD_CONTAINER": "list"}
79
80 templatefile_prefix = (
81 os.path.realpath(__file__).replace(".pyc", "").replace(".py", "")
82 )
83
85 templatefile_prefix + "_ScatteredOnHeap_IndexedByStdContainer.template.h",
86 templatefile_prefix + "_ScatteredOnHeap_IndexedByStdContainer.template.cpp",
87 self._data.name,
88 self._data.namespace,
89 self._data.namespace[-1],
90 d,
91 True,
92 )
93 output.add(generated_files)
94 output.makefile.add_cpp_file(
95 self._data.namespace[-1] + "/" + self._data.name + ".cpp", generated=True
96 )
97 pass
98
99
101 """!
102
103 Map a particle set onto heap objects indexed by an std::vector
104
105 This class is tied to peano4::stacks::STDVectorOverContainerOfPointers, i.e.
106 Peano's stacks are realised via std::vector from the C++ standard library.
107 Each entry within this vector then resembles a C++ container over pointers
108 to the heap. That is, all particles are stored on the heap. They are
109 scattered. The C++ pointer per stack entry that's used to store all the
110 particle pointers is realised through std::list.
111
112 Please consult @ref page_swift_performance_optimisation "the generic discussion on the impact of storage schemes".
113
114 @image html ParticleSetGenerator_ScatteredOnHeap.png
115
116
117 """
118
119 def __init__(self, data):
120 super(ParticleSetGenerator_ScatteredOnHeap_IndexByVector, self).__init__(
121 data, False
122 )
123
124 def construct_output(self, output):
125 d = {"PARTICLE_TYPE": self._data.particle_model.name, "STD_CONTAINER": "vector"}
126
127 templatefile_prefix = (
128 os.path.realpath(__file__).replace(".pyc", "").replace(".py", "")
129 )
130
132 templatefile_prefix + "_ScatteredOnHeap_IndexedByStdContainer.template.h",
133 templatefile_prefix + "_ScatteredOnHeap_IndexedByStdContainer.template.cpp",
134 self._data.name,
135 self._data.namespace,
136 self._data.namespace[-1],
137 d,
138 True,
139 )
140 output.add(generated_files)
141 output.makefile.add_cpp_file(
142 self._data.namespace[-1] + "/" + self._data.name + ".cpp", generated=True
143 )
144 pass
145
146
148 """!
149
150 Map a particle set onto heap objects indexed by a list
151
152 This class is tied to peano4::stacks::STDVectorOverContainerOfPointers, i.e.
153 Peano's stacks are realised via std::vector from the C++ standard library.
154 Each entry within this vector then resembles a C++ container over pointers
155 to the heap. That is, all particles are stored on the heap. They are
156 scattered. The C++ pointer per stack entry that's used to store all the
157 particle pointers is realised through std::list.
158
159 Please consult @ref page_swift_performance_optimisation "the generic discussion on the impact of storage schemes".
160
161 @image html ParticleSetGenerator_ContinuousPerVertex.png
162
163 """
164
165 def __init__(self, data):
166 super(ParticleSetGenerator_ContinuousPerVertex, self).__init__(data, True)
167
168 def construct_output(self, output):
169 d = {
170 "PARTICLE_TYPE": self._data.particle_model.name,
171 "MEMORY_POOL_TYPE": "toolbox::particles::memorypool::VertexWiseContinuousMemoryPool",
172 }
173
174 templatefile_prefix = (
175 os.path.realpath(__file__).replace(".pyc", "").replace(".py", "")
176 )
177
179 templatefile_prefix + "_MemoryPool.template.h",
180 templatefile_prefix + "_MemoryPool.template.cpp",
181 self._data.name,
182 self._data.namespace,
183 self._data.namespace[-1],
184 d,
185 True,
186 )
187 output.add(generated_files)
188 output.makefile.add_cpp_file(
189 self._data.namespace[-1] + "/" + self._data.name + ".cpp", generated=True
190 )
191 pass
192
193
195 """!
196
197 Map a particle set onto heap objects indexed by a list
198
199 This class is tied to peano4::stacks::STDVectorOverContainerOfPointers, i.e.
200 Peano's stacks are realised via std::vector from the C++ standard library.
201 Each entry within this vector then resembles a C++ container over pointers
202 to the heap. That is, all particles are stored on the heap. They are
203 scattered. The C++ pointer per stack entry that's used to store all the
204 particle pointers is realised through std::list.
205
206 Please consult @ref page_swift_performance_optimisation "the generic discussion on the impact of storage schemes".
207
208 @image html ParticleSetGenerator_GlobalContinuous.png
209
210 """
211
212 def __init__(self, data):
213 super(ParticleSetGenerator_GlobalContinuous, self).__init__(data, True)
214
215 def construct_output(self, output):
216 d = {
217 "PARTICLE_TYPE": self._data.particle_model.name,
218 "MEMORY_POOL_TYPE": "toolbox::particles::memorypool::GlobalContinuousMemoryPool",
219 }
220
221 templatefile_prefix = (
222 os.path.realpath(__file__).replace(".pyc", "").replace(".py", "")
223 )
224
226 templatefile_prefix + "_MemoryPool.template.h",
227 templatefile_prefix + "_MemoryPool.template.cpp",
228 self._data.name,
229 self._data.namespace,
230 self._data.namespace[-1],
231 d,
232 True,
233 )
234 output.add(generated_files)
235 output.makefile.add_cpp_file(
236 self._data.namespace[-1] + "/" + self._data.name + ".cpp", generated=True
237 )
238 pass
239
240
242 """!
243
244 Represents a particle set
245
246 A particle set is, in principle, a very simple container tied to a vertex.
247 It allows each vertex to point to the particles around. While the
248 realisation on the Python side is simple - after all, the Python model is
249 solely the data model - interesting questions arise once we discuss how the
250 data model is mapped onto C++. This information is not directly stored
251 within the ParticleSet objects, i.e. this class is solely a presentation
252 of the data topology.
253
254 The information how the association is mapped onto Peano's C++ code is held
255 within the generator. By default, this generator maps each particle set onto
256 a vector which in turn hosts particles on the heap. However, there are
257 alternative implementations which you might want to pick by setting the
258 generator attribute to a different value.
259
260 - Study ParticleSetGenerator_ScatteredOnHeap_IndexByList to obtain some
261 information about Peano's default storage scheme.
262 - The generator ParticleSetGenerator_ScatteredOnHeap_IndexByVector is
263 a slightly more memory-compact version.
264
265
266 ## Attributes
267
268 name: String
269 Name of the particle. Has to be a valid C++ class name.
270
271 particle: Particle
272 Link to particle definition
273
274 """
275
276 def __init__(self, particle):
277 DoF.__init__(self, particle.name + "Set")
278
279 if particle.association != peano4.datamodel.DoFAssociation.Global:
280 print(
281 "Warning: particle "
282 + particle.name
283 + " is not (yet) added to project via add_global_object() and thus has invalid DoF association"
284 )
285
286 self.particle_model = particle
287 # self.generator = ParticleSetGenerator_ScatteredOnHeap_IndexByList(self)
289 # self.generator = ParticleSetGenerator_ContinuousPerVertex(self)
290 # self.generator = ParticleSetGenerator_GlobalContinuous(self)
291
292 @property
294 return (
295 """
296### Particle set """
297 + self.particle_model.name
298 + """
299
300The particle set is administered through the container """
301 + self.generator.get_stack_container()
302 + """.
303
304"""
305 )
306
307 @property
309 return """
310
311### Particle handling
312
313The particle handling is based upon the idea of particles in dual trees (PIDT)
314as published in the paper below:
315
316 @article{Weinzierl:2016:PIDT,
317 title = {Two particle-in-grid realisations on spacetrees},
318 journal = {Parallel Computing},
319 volume = {52},
320 pages = {42-64},
321 year = {2016},
322 issn = {0167-8191},
323 doi = {https://doi.org/10.1016/j.parco.2015.12.007},
324 url = {https://www.sciencedirect.com/science/article/pii/S0167819115001635},
325 author = {T. Weinzierl and B. Verleye and P. Henri and D. Roose},
326 keywords = {Particle-in-cell, Spacetree, Particle sorting, AMR, Lagrangian-Eulerian methods, Communication-avoiding},
327 abstract = {The present paper studies two particle management strategies for dynamically adaptive Cartesian grids at hands of a particle-in-cell code. One holds the particles within the grid cells, the other within the grid vertices. The fundamental challenge for the algorithmic strategies results from the fact that particles may run through the grid without velocity constraints. To facilitate this, we rely on multiscale grid representations. They allow us to lift and drop particles between different spatial resolutions. We call this cell-based strategy particle in tree (PIT). Our second approach assigns particles to vertices describing a dual grid (PIDT) and augments the lifts and drops with multiscale linked cells. Our experiments validate the two schemes at hands of an electrostatic particle-in-cell code by retrieving the dispersion relation of Langmuir waves in a thermal plasma. They reveal that different particle and grid characteristics favour different realisations. The possibility that particles can tunnel through an arbitrary number of grid cells implies that most data is exchanged between neighbouring ranks, while very few data is transferred non-locally. This constraints the scalability as the code potentially has to realise global communication. We show that the merger of an analysed tree grammar with PIDT allows us to predict particle movements among several levels and to skip parts of this global communication a priori. It is capable to outperform several established implementations based upon trees and/or space-filling curves.}
328 }
329
330"""
331
332 def __str__(self):
333 return "{{ {}, {} }}".format(self.particle_model.name, self.generator.__class__)
Default superclass for any data model in Peano which is stored within the grid.
Definition DaStGen2.py:47
Map a particle set onto heap objects indexed by a list.
Map a particle set onto heap objects indexed by a list.
Map a particle set onto heap objects indexed by an std::vector.
__init__(self, particle)
Both the association and the namespace are not to be set directly, but through the operation configur...