Peano 4
Loading...
Searching...
No Matches
ExplicitEulerDynamicSearchRadius.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
7
8from abc import ABC
9
10
12 """
13
14 Extension of the explicit Euler to support dynamic search radius
15 adoption. We try to keep a constant number of particles.
16
17
18 ## Attributes
19
20 name: String
21 To be in line with other conventions, I recommend you start with an
22 uppercase letter. This has to be a valid C++ identifier, i.e. don't
23 use any special symbols besides an underscore.
24
25
26 @see swift2::kernels::adoptSearchRadiusAndTriggerRerun()
27
28 """
29
31 self,
32 name,
33 cfl_factor,
34 initial_time_step_size,
35 particle_particle_interaction_over_particle_sets_kernel="",
36 touch_particles_of_set_first_time_kernel="",
37 touch_particles_of_set_last_time_kernel="",
38 number_of_interaction_partners=64,
39 particles_per_cell=0, # makes no sense, and should likely be forbidden
40 min_h=0.005,
41 max_h=0.3,
42 ):
43 super(ExplicitEulerDynamicSearchRadius, self).__init__(
44 name,
45 particles_per_cell,
46 min_h,
47 max_h,
48 )
49
52 self.data.add_attribute(self.velocity)
53 self.data.add_attribute(self.accelerator)
54
55 self.cfl_factor = cfl_factor
56 self.initial_time_step_size = initial_time_step_size
57
59 particle_particle_interaction_over_particle_sets_kernel
60 )
62 touch_particles_of_set_first_time_kernel
63 )
65 touch_particles_of_set_last_time_kernel
66 )
67 self.number_of_interaction_partners = number_of_interaction_partners
68
69 pass
70
71 def algorithm_steps(self):
72 """
73
74 The explicit Euler basically consists of two steps per particle. We first
75 determine the force. For this, we need access to the neighbours. The step
76 solely alters the individual particle's state. In the next algorithm step,
77 we need this state, as well as global data (the admissible time step size)
78 to update position and velocity. We also determine the CFL condition here.
79
80 """
81
82 PARTICLE = self.namenamename
83 CFL_FACTOR = self.cfl_factor
84 TIME_STEP_SIZE = self.initial_time_step_size
85 NR_INTERACTION_PARTNERS = self.number_of_interaction_partners
86
87 return [
89 name="DensityCalculation",
90 dependencies=AlgorithmStep.Dependencies.NEIGHBOURS,
91 effect=AlgorithmStep.Effect.CHANGE_POSITION_OR_INTERACTION_RADIUS,
92 touch_vertex_first_time_kernel="",
93 cell_kernel=f"""
94 ::swift2::kernels::adoptSearchRadiusAndTriggerRerun<globaldata::{PARTICLE}>(
95 localParticles,
96 activeParticles,
97 {NR_INTERACTION_PARTNERS}
98 );
99 """,
100 touch_vertex_last_time_kernel="",
101 prepare_traversal_kernel=f"globaldata::{PARTICLE}::getSpecies().clearRerunPreviousGridSweepFlag();",
102 unprepare_traversal_kernel=f"globaldata::{PARTICLE}::getSpecies().allReduce();",
103 includes="""
104 #include "swift2/kernels/ParticleSearchRadiusCalculation.h"
105 """,
106 ),
108 name="ForceCalculation",
109 dependencies=AlgorithmStep.Dependencies.NEIGHBOURS,
110 effect=AlgorithmStep.Effect.ALTER_LOCAL_STATE,
111 touch_vertex_first_time_kernel=self.touch_particles_of_set_first_time_kernel,
112 cell_kernel=f"""
113 ::swift2::kernels::genericInteraction<globaldata::{PARTICLE}>(
114 localParticles,
115 activeParticles,
116 [&] (globaldata::{PARTICLE}* localParticle, const globaldata::{PARTICLE} * const globalParticle) -> void {{
117 {self.particle_particle_interaction_over_particle_sets_kernel}
118 }}
119 );
120 """,
121 touch_vertex_last_time_kernel=self.touch_particles_of_set_last_time_kernel,
122 includes="""
123 #include "swift2/kernels/ParticleParticleInteraction.h"
124 """,
125 ),
127 name="UpdatePositionAndVelocity",
128 dependencies=AlgorithmStep.Dependencies.SELF,
129 effect=AlgorithmStep.Effect.CHANGE_POSITION_OR_INTERACTION_RADIUS,
130 touch_vertex_first_time_kernel="""::swift2::timestepping::resetMovedParticleMarker(assignedParticles);""",
131 touch_vertex_last_time_kernel="""::swift2::timestepping::computeExplicitEulerWithGlobalTimeStepSize( assignedParticles );""",
132 prepare_traversal_kernel=f"""::swift2::timestepping::computeAdmissibleTimeStepSizeFromGlobalMeshSizeAndMaximumVelocity<globaldata::{PARTICLE}>({CFL_FACTOR},{TIME_STEP_SIZE});""",
133 includes="""
134 #include "swift2/timestepping/Euler.h"
135 #include "swift2/timestepping/GlobalTimeStepping.h"
136 #include "swift2/timestepping/TimeStepping.h"
137 """,
138 ),
140 name="ReduceGlobalQuantities",
141 dependencies=AlgorithmStep.Dependencies.SELF,
142 effect=AlgorithmStep.Effect.ALTER_GLOBAL_STATE,
143 cell_kernel="""::swift2::statistics::reduceVelocityAndSearchRadius( localParticles );""",
144 prepare_traversal_kernel="""
145 globaldata::{PARTICLE}::getSpecies().clearSearchRadius();
146 globaldata::{PARTICLE}::getSpecies().clearVelocity();
147 """,
148 unprepare_traversal_kernel=f"""
149 globaldata::{PARTICLE}::getSpecies().allReduce();
150 globaldata::{PARTICLE}::getSpecies().setTimeStamp( globaldata::{PARTICLE}::getSpecies().getMinTimeStamp() + globaldata::{PARTICLE}::getSpecies().getMinTimeStepSize(), false );
151 ::swift2::statistics::reportSearchRadiusVTDt<globaldata::{PARTICLE}>( "{PARTICLE}" );
152 """,
153 includes="""
154 #include "swift2/statistics/Reports.h"
155 #include "swift2/statistics/Statistics.h"
156 """,
157 ),
158 ]
159
161 """!
162
163 No particular initialisation required
164
165 """
166 return []
167
168 # @property
169 # def readme_descriptor(self):
170 # assert False, "not yet written"
171 # return """ I will au aufgerufen werden"""
Specialisation of dastgen2.attributes.DoubleArray which relies on Peano's tarch.
Defines the meta data around one algorithmic step per particle.
Extension of the explicit Euler to support dynamic search radius adoption.
__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="", number_of_interaction_partners=64, particles_per_cell=0, min_h=0.005, max_h=0.3)
Initialise the particle.
algorithm_steps(self)
The explicit Euler basically consists of two steps per particle.
Base class for any particle in the project.
Definition Particle.py:10