Peano 4
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 """
41
43 self,
44 name,
45 cfl_factor,
46 initial_time_step_size,
47 enter_cell_kernel="",
48 touch_particles_of_set_first_time_kernel="",
49 touch_particles_of_set_last_time_kernel="",
50 particles_per_cell=0,
51 min_h=0.005,
52 max_h=0.3,
53 ):
54 super(LeapfrogFixedSearchRadius, self).__init__(
55 name,
56 particles_per_cell,
57 min_h,
58 max_h,
59 )
60
61 self.cfl_factor = cfl_factor
62 self.initial_time_step_size = initial_time_step_size
63
64 # Particle attributes
67 self.data.add_attribute(self.velocity)
68 self.data.add_attribute(self.accelerator)
69
71
72 self.enter_cell_kernel = enter_cell_kernel
74 touch_particles_of_set_first_time_kernel
75 )
77 touch_particles_of_set_last_time_kernel
78 )
79 pass
80
81 @property
83 return self._algorithm_steps_algorithm_steps[ "ForceCalculation" ].touch_vertex_first_time_kernel
84
85 @touch_particles_of_set_first_time_kernel.setter
87 self._algorithm_steps_algorithm_steps[ "ForceCalculation" ].touch_vertex_first_time_kernel = value
88
89 @property
91 return self._algorithm_steps_algorithm_steps[ "ForceCalculation" ].touch_vertex_last_time_kernel
92
93 @touch_particles_of_set_first_time_kernel.setter
95 self._algorithm_steps_algorithm_steps[ "ForceCalculation" ].touch_vertex_last_time_kernel = value
96
97 @property
98 def cell_kernel(self):
99 return self._algorithm_steps_algorithm_steps[ "ForceCalculation" ].cell_kernel
100
101 @cell_kernel.setter
102 def cell_kernel(self, value):
103 self._algorithm_steps_algorithm_steps[ "ForceCalculation" ].cell_kernel = value
104
105 def add_to_reduction(self, value):
106 self._algorithm_steps_algorithm_steps["ReduceGlobalQuantities"].unprepare_traversal_kernel += value
107
109 """!
110
111 Create a repository of algorithmic steps which are then
112 ordered into the actual time stepping sequence.
113
114 """
115
116 PARTICLE = self.namenamename
117 CFL_FACTOR = self.cfl_factor
118 TIME_STEP_SIZE = self.initial_time_step_size
119
121 "ForceCalculation": AlgorithmStep(
122 name="ForceCalculation",
123 dependencies=AlgorithmStep.Dependencies.NEIGHBOURS,
124 effect=AlgorithmStep.Effect.ALTER_LOCAL_STATE,
125 touch_vertex_first_time_kernel="",
126 cell_kernel="",
127 touch_vertex_last_time_kernel="",
128 ),
129 "Kick": AlgorithmStep(
130 name="Kick1",
131 dependencies=AlgorithmStep.Dependencies.SELF,
132 effect=AlgorithmStep.Effect.ALTER_LOCAL_STATE,
133 touch_vertex_first_time_kernel=f"""::swift2::kernels::forAllParticles( marker, assignedParticles, ::swift2::timestepping::leapfrogKickWithGlobalTimeStepSize<globaldata::{PARTICLE}> );""",
134 prepare_traversal_kernel=f"""::swift2::timestepping::computeAdmissibleTimeStepSizeFromGlobalMeshSizeAndMaximumVelocity<globaldata::{PARTICLE}>({CFL_FACTOR},{TIME_STEP_SIZE});""",
135 includes="""
136 #include "swift2/timestepping/Leapfrog.h"
137 #include "swift2/timestepping/GlobalTimeStepping.h"
138 #include "swift2/timestepping/TimeStepping.h"
139 """,
140 ),
141 "Drift": AlgorithmStep(
142 name="Drift",
143 dependencies=AlgorithmStep.Dependencies.SELF,
144 effect=AlgorithmStep.Effect.CHANGE_POSITION_OR_INTERACTION_RADIUS,
145 touch_vertex_first_time_kernel=f"""::swift2::kernels::forAllParticles( marker, assignedParticles, ::swift2::timestepping::resetMovedParticleMarker<globaldata::{PARTICLE}> );""",
146 touch_vertex_last_time_kernel=f"""
147 auto oldParticlePositions = ::toolbox::particles::assignmentchecks::recordParticlePositions(assignedParticles);
148 ::swift2::kernels::forAllParticles( marker, assignedParticles, ::swift2::timestepping::leapfrogDriftWithGlobalTimeStepSize<globaldata::{PARTICLE}> );
149 ::toolbox::particles::assignmentchecks::traceParticleMovements(assignedParticles, oldParticlePositions, _spacetreeId);
150 """,
151 includes="""
152 #include "swift2/timestepping/Leapfrog.h"
153 #include "swift2/timestepping/GlobalTimeStepping.h"
154 #include "swift2/timestepping/TimeStepping.h"
155 """,
156 ),
157 "ReduceVelocityAndDetermineTimeStepSize": AlgorithmStep(
158 name="ReduceVelocityAndDetermineTimeStepSize",
159 dependencies=AlgorithmStep.Dependencies.SELF,
160 effect=AlgorithmStep.Effect.CHANGE_POSITION_OR_INTERACTION_RADIUS,
161 prepare_traversal_kernel=f"""::swift2::timestepping::computeAdmissibleTimeStepSizeFromGlobalMeshSizeAndMaximumVelocity<globaldata::{PARTICLE}>({CFL_FACTOR},{TIME_STEP_SIZE});""",
162 includes="""
163 #include "swift2/timestepping/Euler.h"
164 #include "swift2/timestepping/GlobalTimeStepping.h"
165 #include "swift2/timestepping/TimeStepping.h"
166 """,
167 ),
168 "ReduceGlobalQuantities": AlgorithmStep(
169 name="ReduceGlobalQuantities",
170 dependencies=AlgorithmStep.Dependencies.SELF,
171 effect=AlgorithmStep.Effect.ALTER_GLOBAL_STATE,
172 touch_vertex_first_time_kernel=f"""::swift2::kernels::forAllParticles( marker, assignedParticles, ::swift2::statistics::reduceVelocityAndSearchRadius<globaldata::{PARTICLE}> );""",
173 prepare_traversal_kernel=f"""
174 globaldata::{PARTICLE}::getSpecies().clearSearchRadius();
175 globaldata::{PARTICLE}::getSpecies().clearVelocity();
176 """,
177 unprepare_traversal_kernel=f"""
178 globaldata::{PARTICLE}::getSpecies().allReduce();
179 globaldata::{PARTICLE}::getSpecies().setTimeStamp( globaldata::{PARTICLE}::getSpecies().getMinTimeStamp() + globaldata::{PARTICLE}::getSpecies().getMinTimeStepSize(), false );
180 ::swift2::statistics::reportSearchRadiusVTDt<globaldata::{PARTICLE}>( "{PARTICLE}" );
181 """,
182 includes="""
183 #include "swift2/statistics/Reports.h"
184 #include "swift2/statistics/Statistics.h"
185 """,
186 ),
187 }
188
190 """!
191
192 Create algorithm steps behind leapfrog
193
194 Leapfrog consists basically of four steps per particle. We first
195 determine the force. Then we update the velocity by half a timestep and move
196 the particle by a full timestep. Then the force is re-computed and the
197 second half of the velocity update is done.
198 Some variations of this KDK form re-arrange the steps executed per timestep
199 to avoid a second force loop.
200
201 """
202 return [
203 self._algorithm_steps_algorithm_steps["ForceCalculation"],
206 self._algorithm_steps_algorithm_steps["ForceCalculation"],
208 self._algorithm_steps_algorithm_steps["ReduceGlobalQuantities"],
209 ]
210
212 """!
213
214 No particular initialisation required, but we reduce once, so we get
215 the initial stats right before we jump into the time stepping.
216
217 """
218 return [
219 self._algorithm_steps_algorithm_steps["ReduceVelocityAndDetermineTimeStepSize"],
220 ]
221
222 @property
224 return (
225 super(LeapfrogFixedSearchRadius, self).readme_descriptor
226 + """
227
228 Time integrator: Leapfrog
229
230 - search radius: fixed
231 - CFL factor: """
232 + str(self.cfl_factor)
233 + """
234 - dt_initial: """
235 + str(self.initial_time_step_size)
236 + """
237
238 """
239 )
Specialisation of dastgen2.attributes.DoubleArray which relies on Peano's tarch.
Defines the meta data around one algorithmic step per 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...
__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)
Initialise the particle.
Base class for any particle in the project.
Definition Particle.py:10