Peano
Loading...
Searching...
No Matches
Particle.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.DaStGen2 import DaStGen2
6
7import dastgen2
8
9
11 """!
12
13 Single particle
14
15 Represent a single particle. This is a DaStGen2 wrapper, i.e. I
16 define a DaStGen object and add some particular fields that I always
17 need to administer the particles.
18
19
20 ## Usage
21
22 If you use these particles, please do not add them to your use
23 definitions of the actions/observers. For pidt, you need a second
24 ParticleSet and this one is used by the observers.
25
26 You have to add the particle to your project though via
27
28 my_project.add_global_object
29
30 If you want to attributes to a particle, use the data subattribute.
31 An all-time classic is the call
32
33 add_attribute( peano4.dastgen2.Peano4DoubleArray("v","Dimensions") )
34
35 ## Pre-defined fields
36
37 I actually need only very few fields in Peano's particle toolbox:
38
39 - A position x. You can change this position in your code, but please
40 invoke a particle re-sort once you change a particle's position. Usually,
41 I employ the pidt (particle in dual tree) scheme, i.e. particles are
42 always stored in the closest vertex. If you alter the position of a
43 particle, you might destroy this association and have to re-assign the
44 object to another vertex.
45 - A search radius. Every particle in Peano has a search radius, i.e. a maximal
46 interaction radius. As I only compare particles stored in one vertex to
47 particles stored in a cell-connected vertex, the search radius also
48 implicitly determines the tree grid level that I use to hold a particle.
49 The bigger the search, the higher up in the mesh I have to store a
50 particle.
51 - A state. This state should not be manipulated by the user. A tree owns the
52 particles that are contained within its local tree cells. Furthermore,
53 a tree knows about the particles which are associated to a vertex that's
54 adjacent to a local mesh. The latter particles are virtual. We effectively
55 work with a halo of h/2 per mesh level.
56
57 The only action set that should alter the state is UpdateParallelState.
58
59 ## State updates
60
61 If a particle moves, we have to update its state, and we might have to
62 update its vertex association. This discussion focuses on the state
63 update.
64
65 Details can be found in
66 UpdateParallelState.
67
68
69 ## Debug information
70
71 If any debug level is active, each particle carries a unique identifier.
72
73
74 ## Performance optimisation
75
76 Particles in Peano are typically stored in the vertex next to them. This is
77 the pidt (paricle in dual tree) technique referenced in the Readme.md file
78 that's automatically generated when you use the particle toolbox.
79
80 In the illustration below, the blue paricle is associated to the vertex
81 left above it, the red one belongs to the vertex right of it.
82
83 @image html Particle.png
84
85 The logical information where the "owning" vertex of a particle is is easy
86 to compute at any time from the geometric context. However, we found that
87 this recomputation is quickly becoming excessively expensive. Therefore, we
88 add the field
89
90 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
91 self.data.add_attribute(
92 dastgen2.attributes.BooleanArray("containedInAdjacentCell", "TwoPowerD", compress=True)
93 )
94 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
95
96 to the data model which encodes this information. It is to be set properly
97 by the particle sorting algorithm in use.
98
99 In the example above, the bitfield would hold 010 (read from right to
100 left) for the blue particle and 0100 for the red one. The code is read from
101 the vertex's point of view: If we look at the centre vertex and study the
102 position of particle, it is not in the left bottom adjacent cell. It is
103 however in the right bottom adjacent cell. So we use a lexicographic
104 enumeration of the adjacent cells.
105
106 As the position of a particle within cells is not unique if a particle
107 resides exactly on the face between two cells, the bitfield can hold
108 more than one entry.
109
110 """
111
112 def __init__(self, name):
113 """!
114
115 Constructor
116
117 ## Attributes
118
119 name: String
120 Name of the particle. Has to be a valid C++ class name. We pass this
121 to the superclass as fully qualified name
122
123 """
124 peano4.datamodel.DaStGen2.__init__(self, name)
125
126 self.namename = name
127 # Is used in subclases
128 self.partid = dastgen2.attributes.Integer("partid", ifdefs=["PeanoDebug > 0"], initval="-1")
129
130 self.data.add_attribute(peano4.dastgen2.Peano4DoubleArray("x", "Dimensions"))
131 self.data.add_attribute(
132 peano4.dastgen2.Peano4DoubleArray("cellH", "Dimensions")
133 )
134 self.data.add_attribute(dastgen2.attributes.Double("searchRadius"))
135 self.data.add_attribute(self.partid)
136 self.data.add_attribute(
137 dastgen2.attributes.BooleanArray("containedInAdjacentCell", "TwoPowerD", compress=True)
138 )
139
140 #
141 # Never manipulate as user
142 #
143 self.data.add_attribute(
144 dastgen2.attributes.Enumeration("ParallelState", ["Local", "Virtual"])
145 )
Represent an array of boolean flags.
cardinality is a string (you can thus use symbols as well as long as they will be defined at compile ...
Definition Double.py:6
Wrapper around C++ enumerations which is not a datatype supported natively by MPI.
Definition Enumeration.py:6
Specialisation of array using Peano's tarch.
Default superclass for any data model in Peano which is stored within the grid.
Definition DaStGen2.py:197