74 Construct particle interaction iterator call templates given the
75 desired particle interaction kernel realisation. These signature
76 templates are strings containing c++ code snippets of the correct
77 iterator call signature.
79 In total, there are four types of iterators. The essential two are:
81 - The one that's used to run over all particle assigned to a vertex. It
82 is called iterate_over_particles_assigned_to_vertex.
83 - There is one to iterate over all particle pairs associated with a
84 cell. This one is called iterate_over_particles_assigned_to_cell.
86 From hereon, we can define some "derived" iterators:
88 - One special iterator runs over all particles associated with a vertex
89 and allows them to move. This one is titled
90 iterate_over_particles_assigned_to_vertex_for_move and equals
91 iterate_over_particles_assigned_to_vertex. However, it embeds the
92 latter into some bookkeeping for the validation of the
93 vertex-particle assocation.
94 - Another special iterator runs over all particles but allows them to
95 reduce into some global space. If you use vectorisation, this one
96 cannot be vectorised by definition.
98 Both special iterators are constructed to default values unless you
99 explicitly set them beforehand.
101 The iterators require a function to be passed as an argument to
102 act on the particles. In the template snippets being generated here,
103 the functions shall be replaced by a placeholder string '*FUNCTION*'.
105 Finally, the code snippets being returned are stored as a
106 ParticleVertexIteratorTemplate object.
108 @param particle_name: str
109 the particle class name.
112 4 ParticleVertexIteratorTemplate objects containing particle iterator code snippets.
114 @return vertex_for_move: snippet (in a ParticleVertexIteratorTemplate object) to
115 use for particle interactons which will move assigned to a vertex
116 @return cell: snippet (in a ParticleVertexIteratorTemplate object) to use for
117 particle-particle interactions assigned to a cell
118 @return vertex: snippet (in a ParticleVertexIteratorTemplate object) to use for
119 particle interactions assigned to a vertex
120 @return vertex_with_global_reduction: snippet (in a ParticleVertexIteratorTemplate
121 object) to use for particle interactions assigned to a vertex which also
122 contain a global reduction
125 PARTICLE = particle_name
127 iterate_over_particles_assigned_to_vertex_for_move =
None
128 iterate_over_particles_assigned_to_vertex = f
"""
129 // Template in src/exaparty/api/particle/AlgorithmStepLibrary.py
130 // iterate_over_particles_assigned_to_vertex
132 ::exaparty::kernels::forAllParticles(*FUNCTION*<globaldata::{PARTICLE}>,
133 numberOfCoalescedAssignedParticles,
134 *FUNCTION*UpdateParticlePredicate<globaldata::{PARTICLE}>
138 iterate_over_particles_assigned_to_cell = f
"""
139 // Template in src/exaparty/api/particle/AlgorithmStepLibrary.py
140 // iterate_over_particles_assigned_to_cell
142 ::exaparty::kernels::forAllParticlePairs<*FUNCTION*<globaldata::{PARTICLE}>, *FUNCTION*UpdateParticlePredicate<globaldata::{PARTICLE}>, *FUNCTION*EvaluatePairInteractionPredicate<globaldata::{PARTICLE}>>(
146 ::exaparty::kernels::kernelrealisation::Generic
150 iterate_over_particles_assigned_to_vertex_with_global_reduction = f
"""
151 // Template in src/exaparty/api/particle/AlgorithmStepLibrary.py
152 // iterate_over_particles_assigned_to_vertex_with_global_reduction
154 ::exaparty::kernels::forAllParticles<*FUNCTION*<globaldata::{PARTICLE}>, *FUNCTION*UpdateParticlePredicate<globaldata::{PARTICLE}>>(marker,
156 numberOfCoalescedAssignedParticles,
157 ::exaparty::kernels::kernelrealisation::Generic
164 if iterate_over_particles_assigned_to_vertex_for_move
is None:
165 iterate_over_particles_assigned_to_vertex_for_move = f
"""
166 // Template in src/exaparty/api/particle/AlgorithmStepLibrary.py
167 // iterate_over_particles_assigned_to_vertex_for_move
169 auto oldParticlePositions = ::toolbox::particles::assignmentchecks::recordParticlePositions(assignedParticles);
170 ::exaparty::kernels::forAllParticles<*FUNCTION*<globaldata::{PARTICLE}>, *FUNCTION*ParticleUpdatePredicate<globaldata::{PARTICLE}>>(marker,
172 numberOfCoalescedAssignedParticles,
173 ::exaparty::kernels::kernelrealisation::Generic
175 ::toolbox::particles::assignmentchecks::traceParticleMovements(assignedParticles,
176 oldParticlePositions,
184 if iterate_over_particles_assigned_to_cell
is None:
185 raise ValueError(
"We shouldn't be here.")
187 if iterate_over_particles_assigned_to_vertex
is None:
188 raise ValueError(
"We shouldn't be here.")
190 if iterate_over_particles_assigned_to_vertex_with_global_reduction
is None:
191 iterate_over_particles_assigned_to_vertex_with_global_reduction = f
"""
192 // Template in src/exaparty/api/particle/AlgorithmStepLibrary.py,
193 // iterate_over_particles_assigned_to_vertex_with_global_reduction
194 ::exaparty::kernels::forAllParticles<*FUNCTION*<globaldata::{PARTICLE}>,
195 ::exaparty::kernels::alwaysUpdateInVertexKernel<globaldata::{PARTICLE}>>(marker,
197 ::exaparty::kernels::kernelrealisation::Generic
204 iterate_over_particles_assigned_to_vertex_for_move
208 iterate_over_particles_assigned_to_vertex_with_global_reduction
211 iterate_over_particles_assigned_to_vertex_with_global_reduction
214 return vertex_for_move, cell, vertex, vertex_with_global_reduction
217def get_algorithm_step_dict(particle):
220 Sets up a dict of the algorithm steps for this scheme so they can be accessed
221 at various points and by various models.
225 algorithm_steps_dict = {}
227 project_namespace = particle._exaparty_project_namespace
229 PARTICLE = particle.name
230 NAMESPACE =
"::".join(project_namespace)
236 v_iter_with_global_reduction,
243 dependencies=AlgorithmStep.Dependencies.SELF,
244 effect=AlgorithmStep.Effect.ALTER_LOCAL_STATE,
245 touch_vertex_last_time_kernel=v_iter.insert(
246 "::exaparty::kernels::legacy::leapfrogKickWithGlobalTimeStepSize"
248 includes=DefaultIncludes
250 #include "exaparty/kernels/legacy/Leapfrog.h"
253 algorithm_steps_dict[
"SPH_Kick1"] = sph_kick1
270 dependencies=AlgorithmStep.Dependencies.SELF,
271 effect=AlgorithmStep.Effect.CHANGE_POSITION_OR_INTERACTION_RADIUS,
272 touch_vertex_first_time_kernel=v_iter.insert(
273 "::exaparty::timestepping::resetMovedParticleMarker"
275 touch_vertex_last_time_kernel=v_iter_for_move.insert(
276 "::exaparty::kernels::legacy::leapfrogDriftWithGlobalTimeStepSize"
278 includes=DefaultIncludes
280 #include "Constants.h"
281 #include "exaparty/kernels/legacy/Leapfrog.h"
282 #include "exaparty/timestepping/GlobalTimeStepping.h"
283 #include "exaparty/timestepping/TimeStepping.h"
285 cell_kernel_dependency_policy=
"TouchAtLeastOnce_AllPreviousStepsUpdateAtLeastOnce_MayOverwritePreviousCellUpdatesFromSameSweep",
286 touch_vertex_first_time_dependency_policy=
"TouchAtLeastOnce_AllPreviousStepsUpdateAtLeastOnce",
287 touch_vertex_last_time_dependency_policy=
"TouchAtLeastOnce_AllPreviousStepsUpdateAtLeastOnce",
289 algorithm_steps_dict[
"SPH_Drift"] = sph_drift
300 dependencies=AlgorithmStep.Dependencies.SELF,
301 effect=AlgorithmStep.Effect.ALTER_LOCAL_STATE,
302 touch_vertex_first_time_kernel=v_iter.insert(
303 "::exaparty::timestepping::resetMovedParticleMarker"
305 + v_iter.insert(
"::exaparty::kernels::legacy::hydroPredictExtra"),
306 includes=DefaultIncludes
308 #include "Constants.h"
309 #include "exaparty/kernels/legacy/Leapfrog.h"
310 #include "exaparty/timestepping/TimeStepping.h"
312 touch_vertex_first_time_dependency_policy=
"TouchAtLeastOnce_AllPreviousStepsUpdateAtLeastOnce_MayOverwritePreviousCellUpdatesFromSameSweep",
313 cell_kernel_dependency_policy=
"TouchAtLeastOnce_AllPreviousStepsUpdateAtLeastOnce_MayOverwritePreviousCellUpdatesFromSameSweep",
315 algorithm_steps_dict[
"PredictHydro"] = predictHydro
320 name=
"SPH_DensityLoopWithConstantSearchRadius",
321 dependencies=AlgorithmStep.Dependencies.NEIGHBOURS,
322 effect=AlgorithmStep.Effect.ALTER_LOCAL_STATE_AND_MIGHT_RERUN,
323 prepare_traversal_kernel=f
"""globaldata::{PARTICLE}::getSpecies().clearRerunPreviousGridSweepFlag();""",
324 touch_vertex_first_time_kernel=v_iter.insert(
325 "::exaparty::kernels::legacy::prepareDensity"
327 cell_kernel=c_iter.insert(
"::exaparty::kernels::legacy::densityKernel"),
328 touch_vertex_last_time_kernel=(
329 v_iter.insert(
"::exaparty::kernels::legacy::endDensityCalculation")
330 + v_iter_with_global_reduction.insert(
331 "::exaparty::kernels::legacy::updateSmoothingLengthAndRerunIfRequired"
334 includes=DefaultIncludes
336 #include "exaparty/kernels/legacy/SmoothingLength.h"
337 #include "exaparty/kernels/legacy/Density.h"
340 algorithm_steps_dict[
"SPH_Density"] = sph_densityWithConstantSearchRadius
345 name=
"SPH_ForceLoop",
346 dependencies=AlgorithmStep.Dependencies.NEIGHBOURS,
347 effect=AlgorithmStep.Effect.ALTER_LOCAL_STATE,
348 touch_vertex_first_time_kernel=(
350 "::exaparty::kernels::legacy::resetSmoothingLengthIterationCounter"
352 + v_iter.insert(
"::exaparty::kernels::legacy::prepareHydroForce")
353 + v_iter.insert(
"::exaparty::kernels::legacy::resetAcceleration")
355 cell_kernel=c_iter.insert(
"::exaparty::kernels::legacy::forceKernel"),
356 touch_vertex_last_time_kernel=v_iter.insert(
357 "::exaparty::kernels::legacy::endHydroForceCalculation"
359 includes=DefaultIncludes
361 #include "exaparty/kernels/legacy/SmoothingLength.h"
362 #include "exaparty/kernels/legacy/HydroForce.h"
365 algorithm_steps_dict[
"SPH_Force"] = sph_force
371 dependencies=AlgorithmStep.Dependencies.SELF,
372 effect=AlgorithmStep.Effect.ALTER_LOCAL_STATE,
373 touch_vertex_last_time_kernel=(
375 "::exaparty::kernels::legacy::leapfrogKickWithGlobalTimeStepSize"
377 + v_iter.insert(
"::exaparty::kernels::legacy::resetPredictedValues")
379 includes=DefaultIncludes
381 #include "Constants.h"
382 #include "exaparty/kernels/legacy/Leapfrog.h"
385 algorithm_steps_dict[
"SPH_Kick2"] = sph_kick2
391 dependencies=AlgorithmStep.Dependencies.SELF,
392 effect=AlgorithmStep.Effect.ALTER_GLOBAL_STATE,
393 touch_vertex_last_time_kernel=
"::exaparty::kernels::legacy::computeNextTimestep(marker, assignedParticles);",
394 includes=DefaultIncludes
396 #include "Constants.h"
397 #include "exaparty/kernels/legacy/Timestep.h"
400 algorithm_steps_dict[
"SPH_Timestep"] = timestep
405 name=
"SPH_ReduceGlobalQuantities",
406 dependencies=AlgorithmStep.Dependencies.SELF,
407 effect=AlgorithmStep.Effect.ALTER_GLOBAL_STATE,
408 touch_vertex_last_time_kernel=v_iter_with_global_reduction.insert(
409 "::exaparty::statistics::reduceVelocityAndSearchRadius"
411 prepare_traversal_kernel=f
"""
412 globaldata::{PARTICLE}::getSpecies().clearSearchRadius();
413 globaldata::{PARTICLE}::getSpecies().clearVelocity();
415 unprepare_traversal_kernel=f
"""
416 globaldata::{PARTICLE}::getSpecies().setTimeStamp( globaldata::{PARTICLE}::getSpecies().getMinTimeStamp() + globaldata::{PARTICLE}::getSpecies().getMinTimeStepSize(), false );
417 ::exaparty::statistics::reportSearchRadiusVTDt<globaldata::{PARTICLE}>( "{PARTICLE}" );
419 includes=DefaultIncludes
421 #include "Constants.h"
422 #include "exaparty/statistics/Reports.h"
423 #include "exaparty/statistics/Statistics.h"
426 algorithm_steps_dict[
"SPH_ReduceGlobalQuantities"] = sph_reduceGlobals
436 name=
"SPH_FirstInitParticle",
437 dependencies=AlgorithmStep.Dependencies.SELF,
438 effect=AlgorithmStep.Effect.CHANGE_POSITION_OR_INTERACTION_RADIUS,
439 touch_vertex_last_time_kernel=v_iter_for_move.insert(
440 "::exaparty::kernels::legacy::firstInitParticle"
442 includes=DefaultIncludes
444 #include "Constants.h"
445 #include "exaparty/kernels/legacy/Swift.h"
447 cell_kernel_dependency_policy=
"TouchAtLeastOnce_AllPreviousStepsUpdateAtLeastOnce_MayOverwritePreviousCellUpdatesFromSameSweep",
448 touch_vertex_first_time_dependency_policy=
"TouchAtLeastOnce_AllPreviousStepsUpdateAtLeastOnce",
449 touch_vertex_last_time_dependency_policy=
"TouchAtLeastOnce_AllPreviousStepsUpdateAtLeastOnce",
451 algorithm_steps_dict[
"SPH_FirstInitParticle"] = firstInit
453 return algorithm_steps_dict
__init__(self, template)
template: str the string containing the particle interacion iterator template
__init__(self, template)
template: str the string containing the particle interacion iterator template
Defines the meta data around one algorithmic step per particle.
_get_particle_iterator_templates(particle_name)
Construct particle interaction iterator call templates given the desired particle interaction kernel ...