Peano
Loading...
Searching...
No Matches
DisappearingParticleTest.py
Go to the documentation of this file.
1# This file is part of the SWIFT2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3from swift2.particle.Particle import Particle
4from swift2.particle.AlgorithmStep import AlgorithmStep
5
6import peano4
7import dastgen2
9
10
12 """
13
14 Simple particle with a fixed interaction radius h which moves according
15 to leapfrog KDK scheme.
16 By default, it uses global time stepping,
17 i.e. the combination of maximum velocity and minimal mesh size determines
18 the time step size of the subsequent time step. Besides the default
19 variables x and h, the particle has the following properties:
20
21 - a vector a which is the acceleration;
22 - a vector v which is the velocity.
23
24 You can add further properties via
25
26 myparticle.data.add_attribute( peano4.dastgen2.Peano4DoubleArray("myFancyArray","Dimensions") )
27
28 in your code. Or you can create a subclass which adds additional fields
29 after it has called the baseline constructor.
30
31 You will need to add further properties for any SPH project.
32
33 ## Force calculation
34
35 particle_particle_interaction_over_particle_sets_kernel is a C++ string which defines a force between two
36 particles. It has access to three important objects:
37
38 - localParticles is a container (list) over pointers to local particles
39 - activeParticles is a container (list) over pointers to active particles
40 - marker is a cell marker which identifies the current cell.
41
42 Please consult the guidebook for a definition of local and active particles
43 but take into account that the local particles always are a subset of the
44 active particles.
45
46 Besides the actual particle-to-particle calculation, i.e. a force
47 calculation, users can also provide kernels that kick in when you touch
48 particles for the first time before you actually compute any
49 particle-particle interaction, and there is a plug-in point what you do
50 just once the particle-particle interaction has terminated. The latter
51 point is reached before we do the actual time stepping. In both plug-in
52 points, you have a vertex marker which gives you the position of the
53 vertex to which a particular is associated, and you have the localParticles.
54 This is a vector of pointers in this particular case.
55
56 @see peano4::datamanagement::CellMarker
57 @see peano4::datamanagement::VertexMarker
58
59 """
60
62 self,
63 name,
64 cfl_factor,
65 initial_time_step_size,
66 particle_particle_interaction_over_particle_sets_kernel="",
67 touch_particles_of_set_first_time_kernel="",
68 touch_particles_of_set_last_time_kernel="",
69 ):
70 super(DisappearingParticleTest, self).__init__(name)
71
72 self.cfl_factor = cfl_factor
73 self.initial_time_step_size = initial_time_step_size
74
75 # Particle attributes
78 self.data.add_attribute(self.velocity)
79 self.data.add_attribute(self.accelerator)
80
81 # Dummy SPH arrays for compilation. Not relevant for non-SPH
82 # Required by the Kick2 SPH compute kernel
83 # Altrnatively, we might want to introduce a separate version of this compute kernel
84 self.v_full = peano4.dastgen2.Peano4DoubleArray("v_full", "Dimensions")
91 self.data.add_attribute(self.u)
92 self.data.add_attribute(self.density)
93 self.data.add_attribute(self.pressure)
94 self.data.add_attribute(self.v_full)
95 self.data.add_attribute(self.u_full)
96 self.data.add_attribute(self.soundSpeed)
97 self.data.add_attribute(self.v_sig_AV)
98
100 particle_particle_interaction_over_particle_sets_kernel
101 )
103 touch_particles_of_set_first_time_kernel
104 )
106 touch_particles_of_set_last_time_kernel
107 )
108
109 pass
110
112 """
113
114 Leapfrog consists basically of four steps per particle. We first
115 determine the force. Then we update the velocity by half a timestep and move
116 the particle by a full timestep. Then the force is re-computed and the
117 second half of the velocity update is done.
118 Some variations of this KDK form re-arrange the steps executed per timestep
119 to avoid a second force loop.
120 """
121 return [
123 name="ForceCalculation",
124 dependencies=AlgorithmStep.Dependencies.NEIGHBOURS,
125 effect=AlgorithmStep.Effect.ALTER_LOCAL_STATE,
126 touch_vertex_first_time_kernel=self.touch_particles_of_set_first_time_kernel,
127 cell_kernel="""
128 ::swift2::kernels::genericInteraction<globaldata::{}>(
129 localParticles,
130 activeParticles,
131 [&] (globaldata::{}* localParticle, const globaldata::{} * const globalParticle) -> void {{
132 {}
133 }}
134 );
135 """.format(
137 self.namenamenamename,
138 self.namenamenamename,
140 ),
141 touch_vertex_last_time_kernel=self.touch_particles_of_set_last_time_kernel,
142 includes="""
143 #include "Constants.h"
144 #include "swift2/kernels/ParticleParticleInteraction.h"
145 """,
146 ),
148 name="Kick1",
149 dependencies=AlgorithmStep.Dependencies.SELF,
150 effect=AlgorithmStep.Effect.ALTER_LOCAL_STATE,
151 touch_vertex_first_time_kernel="""::swift2::timestepping::resetMovedParticleMarker(assignedParticles);""",
152 touch_vertex_last_time_kernel="""::swift2::timestepping::computeLeapfrogKickWithGlobalTimeStepSize(
153 assignedParticles, 1 , false);""",
154 prepare_traversal_kernel="""::swift2::timestepping::computeAdmissibleTimeStepSizeFromGlobalMeshSizeAndMaximumVelocity<globaldata::{}>({},{});""".format(
156 ),
157 includes="""
158 #include "Constants.h"
159 #include "swift2/timestepping/Leapfrog.h"
160 #include "swift2/timestepping/GlobalTimeStepping.h"
161 #include "swift2/timestepping/TimeStepping.h"
162
163 #include "swift2/kernels/kernel_hydro.h"
164 #include "swift2/kernels/equation_of_state.h"
165 """,
166 ),
168 name="moveParticleIntoCriticalLine",
169 dependencies=AlgorithmStep.Dependencies.SELF,
170 effect=AlgorithmStep.Effect.CHANGE_POSITION_OR_INTERACTION_RADIUS,
171 touch_vertex_first_time_kernel="""::swift2::timestepping::resetMovedParticleMarker(assignedParticles);""",
172 touch_vertex_last_time_kernel="""::swift2::timestepping::moveParticleIntoCriticalLine( assignedParticles );""",
173 includes="""
174 #include "Constants.h"
175 #include "swift2/timestepping/Leapfrog.h"
176 #include "swift2/timestepping/GlobalTimeStepping.h"
177 #include "swift2/timestepping/TimeStepping.h"
178 """,
179 ),
181 name="ForceCalculation",
182 dependencies=AlgorithmStep.Dependencies.NEIGHBOURS,
183 effect=AlgorithmStep.Effect.ALTER_LOCAL_STATE,
184 touch_vertex_first_time_kernel=self.touch_particles_of_set_first_time_kernel,
185 cell_kernel="""
186 ::swift2::kernels::genericInteraction<globaldata::{}>(
187 localParticles,
188 activeParticles,
189 [&] (globaldata::{}* localParticle, const globaldata::{} * const globalParticle) -> void {{
190 {}
191 }}
192 );
193 """.format(
194 self.namenamenamename,
195 self.namenamenamename,
196 self.namenamenamename,
198 ),
199 touch_vertex_last_time_kernel=self.touch_particles_of_set_last_time_kernel,
200 includes="""
201 #include "Constants.h"
202 #include "swift2/kernels/ParticleParticleInteraction.h"
203 """,
204 ),
206 name="Kick2",
207 dependencies=AlgorithmStep.Dependencies.SELF,
208 effect=AlgorithmStep.Effect.ALTER_LOCAL_STATE,
209 touch_vertex_first_time_kernel="""::swift2::timestepping::resetMovedParticleMarker(assignedParticles);""",
210 touch_vertex_last_time_kernel="""::swift2::timestepping::computeLeapfrogKickWithGlobalTimeStepSize(
211 assignedParticles, 2, false );""",
212 includes="""
213 #include "Constants.h"
214 #include "swift2/timestepping/Leapfrog.h"
215 #include "swift2/timestepping/GlobalTimeStepping.h"
216 #include "swift2/timestepping/TimeStepping.h"
217
218 #include "swift2/kernels/kernel_hydro.h"
219 #include "swift2/kernels/equation_of_state.h"
220 """,
221 ),
223 name="ReduceGlobalQuantities",
224 dependencies=AlgorithmStep.Dependencies.SELF,
225 effect=AlgorithmStep.Effect.ALTER_GLOBAL_STATE,
226 cell_kernel="""::swift2::statistics::reduceVelocityAndSearchRadius( localParticles );""",
227 prepare_traversal_kernel="""
228 globaldata::{PARTICLE}::getSpecies().clearSearchRadius();
229 globaldata::{PARTICLE}::getSpecies().clearVelocity();
230 """.replace(
231 "{PARTICLE}", self.namenamenamename
232 ),
233 unprepare_traversal_kernel="""
234 globaldata::{PARTICLE}::getSpecies().setTimeStamp( globaldata::{PARTICLE}::getSpecies().getMinTimeStamp() + globaldata::{PARTICLE}::getSpecies().getMinTimeStepSize(), false );
235 ::swift2::statistics::reportSearchRadiusVTDt<globaldata::{PARTICLE}>( "{PARTICLE}" );
236 """.replace(
237 "{PARTICLE}", self.namenamenamename
238 ),
239 includes="""
240 #include "Constants.h"
241 #include "swift2/statistics/Reports.h"
242 #include "swift2/statistics/Statistics.h"
243 """,
244 ),
245 ]
246
248 """!
249
250 No particular initialisation required
251
252 """
253 return []
cardinality is a string (you can thus use symbols as well as long as they will be defined at compile ...
Definition Double.py:6
Specialisation of dastgen2.attributes.DoubleArray which relies on Peano's tarch.
Defines the meta data around one algorithmic step per particle.
Base class for any particle in the project.
Definition Particle.py:10
Simple particle with a fixed interaction radius h which moves according to leapfrog KDK scheme.
algorithm_steps(self)
Leapfrog consists basically of four steps per particle.
__init__(self, name, cfl_factor, initial_time_step_size, particle_particle_interaction_over_particle_sets_kernel="", touch_particles_of_set_first_time_kernel="", touch_particles_of_set_last_time_kernel="")
Initialise the particle.