Peano
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 adoption.
15
16 ## Attributes
17
18 @param name: String
19 To be in line with other conventions, I recommend you start with an
20 uppercase letter. This has to be a valid C++ identifier, i.e. don't
21 use any special symbols besides an underscore.
22
23
24 @see swift2::kernels::adoptSearchRadiusAndTriggerRerun()
25
26 """
27
29 self,
30 name,
31 cfl_factor,
32 initial_time_step_size,
33 particle_particle_interaction_over_particle_sets_kernel="",
34 touch_particles_of_set_first_time_kernel="",
35 touch_particles_of_set_last_time_kernel="",
36 number_of_interaction_partners=64,
37 particles_per_cell=0, # makes no sense, and should likely be forbidden
38 min_h=0.005,
39 max_h=0.3,
40 ):
41 super(ExplicitEulerDynamicSearchRadius, self).__init__(
42 name,
43 particles_per_cell,
44 min_h,
45 max_h,
46 )
47
50 self.data.add_attribute(self.velocity)
51 self.data.add_attribute(self.accelerator)
52
53 self.cfl_factor = cfl_factor
54 self.initial_time_step_size = initial_time_step_size
55
57 particle_particle_interaction_over_particle_sets_kernel
58 )
60 touch_particles_of_set_first_time_kernel
61 )
63 touch_particles_of_set_last_time_kernel
64 )
65 self.number_of_interaction_partners = number_of_interaction_partners
66
67 pass
68
69 def algorithm_steps(self):
70 """!
71
72 The explicit Euler basically consists of two steps per particle. We first
73 determine the force. For this, we need access to the neighbours. The step
74 solely alters the individual particle's state. In the next algorithm step,
75 we need this state, as well as global data (the admissible time step size)
76 to update position and velocity. We also determine the CFL condition here.
77
78 """
79
80 PARTICLE = self.namenamename
81 CFL_FACTOR = self.cfl_factor
82 TIME_STEP_SIZE = self.initial_time_step_size
83 NR_INTERACTION_PARTNERS = self.number_of_interaction_partners
84
85 return [
87 name="DensityCalculation",
88 dependencies=AlgorithmStep.Dependencies.NEIGHBOURS,
89 effect=AlgorithmStep.Effect.CHANGE_POSITION_OR_INTERACTION_RADIUS,
90 touch_vertex_first_time_kernel="",
91 cell_kernel=f"""
92 ::swift2::kernels::adoptSearchRadiusAndTriggerRerun<globaldata::{PARTICLE}>(
93 localParticles,
94 activeParticles,
95 {NR_INTERACTION_PARTNERS}
96 );
97 """,
98 touch_vertex_last_time_kernel="",
99 prepare_traversal_kernel=f"globaldata::{PARTICLE}::getSpecies().clearRerunPreviousGridSweepFlag();",
100 unprepare_traversal_kernel=f"globaldata::{PARTICLE}::getSpecies().allReduce();",
101 includes="""
102 #include "swift2/kernels/ParticleSearchRadiusCalculation.h"
103 """,
104 ),
106 name="ForceCalculation",
107 dependencies=AlgorithmStep.Dependencies.NEIGHBOURS,
108 effect=AlgorithmStep.Effect.ALTER_LOCAL_STATE,
109 touch_vertex_first_time_kernel=self.touch_particles_of_set_first_time_kernel,
110 cell_kernel=f"""
111 ::swift2::kernels::genericInteraction<globaldata::{PARTICLE}>(
112 localParticles,
113 activeParticles,
114 [&] (globaldata::{PARTICLE}* localParticle, const globaldata::{PARTICLE} * const globalParticle) -> void {{
115 {self.particle_particle_interaction_over_particle_sets_kernel}
116 }}
117 );
118 """,
119 touch_vertex_last_time_kernel=self.touch_particles_of_set_last_time_kernel,
120 includes="""
121 #include "swift2/kernels/ParticleParticleInteraction.h"
122 """,
123 ),
125 name="UpdatePositionAndVelocity",
126 dependencies=AlgorithmStep.Dependencies.SELF,
127 effect=AlgorithmStep.Effect.CHANGE_POSITION_OR_INTERACTION_RADIUS,
128 touch_vertex_first_time_kernel="""::swift2::timestepping::resetMovedParticleMarker(assignedParticles);""",
129 touch_vertex_last_time_kernel="""::swift2::timestepping::computeExplicitEulerWithGlobalTimeStepSize( assignedParticles );""",
130 prepare_traversal_kernel=f"""::swift2::timestepping::computeAdmissibleTimeStepSizeFromGlobalMeshSizeAndMaximumVelocity<globaldata::{PARTICLE}>({CFL_FACTOR},{TIME_STEP_SIZE});""",
131 includes="""
132 #include "swift2/timestepping/Euler.h"
133 #include "swift2/timestepping/GlobalTimeStepping.h"
134 #include "swift2/timestepping/TimeStepping.h"
135 """,
136 ),
138 name="ReduceGlobalQuantities",
139 dependencies=AlgorithmStep.Dependencies.SELF,
140 effect=AlgorithmStep.Effect.ALTER_GLOBAL_STATE,
141 cell_kernel="""::swift2::statistics::reduceVelocityAndSearchRadius( localParticles );""",
142 prepare_traversal_kernel="""
143 globaldata::{PARTICLE}::getSpecies().clearSearchRadius();
144 globaldata::{PARTICLE}::getSpecies().clearVelocity();
145 """,
146 unprepare_traversal_kernel=f"""
147 globaldata::{PARTICLE}::getSpecies().allReduce();
148 globaldata::{PARTICLE}::getSpecies().setTimeStamp( globaldata::{PARTICLE}::getSpecies().getMinTimeStamp() + globaldata::{PARTICLE}::getSpecies().getMinTimeStepSize(), false );
149 ::swift2::statistics::reportSearchRadiusVTDt<globaldata::{PARTICLE}>( "{PARTICLE}" );
150 """,
151 includes="""
152 #include "swift2/statistics/Reports.h"
153 #include "swift2/statistics/Statistics.h"
154 """,
155 ),
156 ]
157
159 """!
160
161 No particular initialisation required
162
163 """
164 return []
165
Specialisation of array using 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