Peano
Loading...
Searching...
No Matches
LeapfrogFixedSearchRadius.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
10from abc import ABC
11
12
14 """
15
16 Leapfrog ODE integrator
17
18 Simple particle with a fixed interaction radius h which moves according
19 to leapfrog KDK scheme.
20 By default, it uses global time stepping,
21 i.e. the combination of maximum velocity and minimal mesh size determines
22 the time step size of the subsequent time step. Besides the default
23 variables x and h, the particle has the following properties:
24
25 - a vector a which is the acceleration;
26 - a vector v which is the velocity.
27
28 You can add further properties via
29
30 myparticle.data.add_attribute( peano4.dastgen2.Peano4DoubleArray("myFancyArray","Dimensions") )
31
32 in your code. Or you can create a subclass which adds additional fields
33 after it has called the baseline constructor.
34
35 You will need to add further properties for any SPH project.
36
37 Study swift2.particle.ExplicitEulerFixedSearchRadius for further
38 information including all parameter documentation.
39
40 @param add_partid: Whether to add a particle ID.
41 Normally, that is done in the Particle super class if PeanoDebug > 0.
42 For certain tests however, a particle ID is required even in release mode.
43 So switch this on if you need it and are building release mode.
44
45 """
46
48 self,
49 name,
50 cfl_factor,
51 initial_time_step_size,
52 enter_cell_kernel="",
53 touch_particles_of_set_first_time_kernel="",
54 touch_particles_of_set_last_time_kernel="",
55 particles_per_cell=0,
56 min_h=0.005,
57 max_h=0.3,
58 add_partid=False,
59 ):
60 super(LeapfrogFixedSearchRadius, self).__init__(
61 name,
62 particles_per_cell,
63 min_h,
64 max_h,
65 )
66
67 self.cfl_factor = cfl_factor
68 self.initial_time_step_size = initial_time_step_size
69
70 # Particle attributes
73 self.data.add_attribute(self.velocity)
74 self.data.add_attribute(self.accelerator)
75
76 if add_partid:
77 self.partidpartid = dastgen2.attributes.Integer("partid", initval="0")
78 self.data.add_or_replace_attribute(self.partidpartid)
79
81
82 self.enter_cell_kernel = enter_cell_kernel
84 touch_particles_of_set_first_time_kernel
85 )
87 touch_particles_of_set_last_time_kernel
88 )
89 pass
90
91 @property
93 return self._algorithm_steps_algorithm_steps["ForceCalculation"].touch_vertex_first_time_kernel
94
95 @touch_particles_of_set_first_time_kernel.setter
97 self._algorithm_steps_algorithm_steps["ForceCalculation"].touch_vertex_first_time_kernel = value
98
99 @property
101 return self._algorithm_steps_algorithm_steps["ForceCalculation"].touch_vertex_last_time_kernel
102
103 @touch_particles_of_set_first_time_kernel.setter
105 self._algorithm_steps_algorithm_steps["ForceCalculation"].touch_vertex_last_time_kernel = value
106
107 @property
108 def cell_kernel(self):
109 return self._algorithm_steps_algorithm_steps["ForceCalculation"].cell_kernel
110
111 @cell_kernel.setter
112 def cell_kernel(self, value):
113 self._algorithm_steps_algorithm_steps["ForceCalculation"].cell_kernel = value
114
115 def add_to_reduction(self, value):
117 "ReduceGlobalQuantities"
118 ].unprepare_traversal_kernel += value
119
121 """!
122
123 Create a repository of algorithmic steps which are then
124 ordered into the actual time stepping sequence.
125
126 """
127
128 PARTICLE = self.namenamename
129 CFL_FACTOR = self.cfl_factor
130 TIME_STEP_SIZE = self.initial_time_step_size
131
133 "ForceCalculation": AlgorithmStep(
134 name="ForceCalculation",
135 dependencies=AlgorithmStep.Dependencies.NEIGHBOURS,
136 effect=AlgorithmStep.Effect.ALTER_LOCAL_STATE,
137 touch_vertex_first_time_kernel="",
138 cell_kernel="",
139 touch_vertex_last_time_kernel="",
140 ),
141 "Kick": AlgorithmStep(
142 name="Kick1",
143 dependencies=AlgorithmStep.Dependencies.SELF,
144 effect=AlgorithmStep.Effect.ALTER_LOCAL_STATE,
145 touch_vertex_first_time_kernel=f"""::swift2::kernels::forAllParticles( marker, assignedParticles, numberOfCoalescedAssignedParticles, ::swift2::timestepping::leapfrogKickWithGlobalTimeStepSize<globaldata::{PARTICLE}> );""",
146 prepare_traversal_kernel=f"""::swift2::timestepping::computeAdmissibleTimeStepSizeFromGlobalMeshSizeAndMaximumVelocity<globaldata::{PARTICLE}>({CFL_FACTOR},{TIME_STEP_SIZE});""",
147 includes="""
148 #include "swift2/timestepping/Leapfrog.h"
149 #include "swift2/timestepping/GlobalTimeStepping.h"
150 #include "swift2/timestepping/TimeStepping.h"
151 """,
152 ),
153 "Drift": AlgorithmStep(
154 name="Drift",
155 dependencies=AlgorithmStep.Dependencies.SELF,
156 effect=AlgorithmStep.Effect.CHANGE_POSITION_OR_INTERACTION_RADIUS,
157 touch_vertex_first_time_kernel=f"""::swift2::kernels::forAllParticles( marker, assignedParticles, numberOfCoalescedAssignedParticles, ::swift2::timestepping::resetMovedParticleMarker<globaldata::{PARTICLE}> );""",
158 touch_vertex_last_time_kernel=f"""
159 auto oldParticlePositions = ::toolbox::particles::assignmentchecks::recordParticlePositions(assignedParticles);
160 ::swift2::kernels::forAllParticles( marker, assignedParticles, numberOfCoalescedAssignedParticles, ::swift2::timestepping::leapfrogDriftWithGlobalTimeStepSize<globaldata::{PARTICLE}> );
161 ::toolbox::particles::assignmentchecks::traceParticleMovements(assignedParticles, oldParticlePositions, marker.x(), marker.h(), _spacetreeId);
162 """,
163 includes="""
164 #include "swift2/timestepping/Leapfrog.h"
165 #include "swift2/timestepping/GlobalTimeStepping.h"
166 #include "swift2/timestepping/TimeStepping.h"
167 """,
168 ),
169 "ReduceVelocityAndDetermineTimeStepSize": AlgorithmStep(
170 name="ReduceVelocityAndDetermineTimeStepSize",
171 dependencies=AlgorithmStep.Dependencies.SELF,
172 effect=AlgorithmStep.Effect.CHANGE_POSITION_OR_INTERACTION_RADIUS,
173 prepare_traversal_kernel=f"""::swift2::timestepping::computeAdmissibleTimeStepSizeFromGlobalMeshSizeAndMaximumVelocity<globaldata::{PARTICLE}>({CFL_FACTOR},{TIME_STEP_SIZE});""",
174 includes="""
175 #include "swift2/timestepping/Euler.h"
176 #include "swift2/timestepping/GlobalTimeStepping.h"
177 #include "swift2/timestepping/TimeStepping.h"
178 """,
179 ),
180 "ReduceGlobalQuantities": AlgorithmStep(
181 name="ReduceGlobalQuantities",
182 dependencies=AlgorithmStep.Dependencies.SELF,
183 effect=AlgorithmStep.Effect.ALTER_GLOBAL_STATE,
184 touch_vertex_first_time_kernel=f"""::swift2::kernels::forAllParticles( marker, assignedParticles, numberOfCoalescedAssignedParticles, ::swift2::statistics::reduceVelocityAndSearchRadius<globaldata::{PARTICLE}> );""",
185 prepare_traversal_kernel=f"""
186 globaldata::{PARTICLE}::getSpecies().clearSearchRadius();
187 globaldata::{PARTICLE}::getSpecies().clearVelocity();
188 """,
189 unprepare_traversal_kernel=f"""
190 globaldata::{PARTICLE}::getSpecies().allReduce();
191 globaldata::{PARTICLE}::getSpecies().setTimeStamp( globaldata::{PARTICLE}::getSpecies().getMinTimeStamp() + globaldata::{PARTICLE}::getSpecies().getMinTimeStepSize(), false );
192 ::swift2::statistics::reportSearchRadiusVTDt<globaldata::{PARTICLE}>( "{PARTICLE}" );
193 """,
194 includes="""
195 #include "swift2/statistics/Reports.h"
196 #include "swift2/statistics/Statistics.h"
197 """,
198 ),
199 }
200
202 """!
203
204 Create algorithm steps behind leapfrog
205
206 Leapfrog consists basically of four steps per particle. We first
207 determine the force. Then we update the velocity by half a timestep and move
208 the particle by a full timestep. Then the force is re-computed and the
209 second half of the velocity update is done.
210 Some variations of this KDK form re-arrange the steps executed per timestep
211 to avoid a second force loop.
212
213 """
214 return [
215 self._algorithm_steps_algorithm_steps["ForceCalculation"],
218 self._algorithm_steps_algorithm_steps["ForceCalculation"],
220 self._algorithm_steps_algorithm_steps["ReduceGlobalQuantities"],
221 ]
222
224 """!
225
226 No particular initialisation required, but we reduce once, so we get
227 the initial stats right before we jump into the time stepping.
228
229 """
230 return [
231 self._algorithm_steps_algorithm_steps["ReduceVelocityAndDetermineTimeStepSize"],
232 ]
233
234 @property
236 return (
237 super(LeapfrogFixedSearchRadius, self).readme_descriptor
238 + """
239
240 Time integrator: Leapfrog
241
242 - search radius: fixed
243 - CFL factor: """
244 + str(self.cfl_factor)
245 + """
246 - dt_initial: """
247 + str(self.initial_time_step_size)
248 + """
249
250 """
251 )
Specialisation of dastgen2.attributes.DoubleArray which relies on Peano's tarch.
Defines the meta data around one algorithmic step per particle.
__init__(self, name, cfl_factor, initial_time_step_size, enter_cell_kernel="", touch_particles_of_set_first_time_kernel="", touch_particles_of_set_last_time_kernel="", particles_per_cell=0, min_h=0.005, max_h=0.3, add_partid=False)
Initialise the particle.
__setup_algorithm_steps(self)
Create a repository of algorithmic steps which are then ordered into the actual time stepping sequenc...
initialisation_steps(self)
No particular initialisation required, but we reduce once, so we get the initial stats right before w...
Base class for any particle in the project.
Definition Particle.py:10