28 alter_particle_position,
29 use_continuous_particles_sequences,
35 Translate one step of species into mesh traversal
37 Takes one step of the species and adds it to the list of steps. That is,
38 you get one more entry within mesh_traversals. Further to that, the
39 routine also appends a boolean arker to alter_particle_position. It
40 shows if the mesh will change the particle position (or search radius)
41 or not. This is decided from step.effect, i.e. whether it is one of the
42 CHANGE_POSITION_OR_INTERACTION_RADIUS(_AND_MIGHT_RERUN) variants.
43 @see AlgorithmStep.may_trigger_rerun()
45 This routine is a helper routine of map_initialisation_steps_onto_separate_mesh_traversals()
46 for example. Note that the returned steps are not fully functionally.
47 If a step alters the particles within the mesh, you still have to resort
48 the particles. That's not done in the step added by this routine, i.e.
49 these steps lack the actual particle sorting. Any sorting has to spread
50 over two steps, so it makes no sense to add it here. Instead, we befill
51 the alter_particle_position, and we expect the calling routine to
52 supplement the actual particle sorting later on in a postprocessing
53 step once all steps are assembled.
56 @param current_species_set: Particle
57 You get a specific algorithmic step as input. The current_species_set
58 highlights to which this step originally belonged to.
60 @param mesh_traversals: [peano4.api.solversteps.Step]
61 Inout parameter. We append a new step to this sequence.
63 @param alter_particle_position: [Bool]
64 Inout parameter. We append a new marker to this sequence.
68 "{}{}{}_sweep{}".format(
69 get_observer_prefix(step_type),
70 current_species_set.particle_model.name,
74 add_user_defined_actions=
False,
78 automatically_set_marker_in_leave_cell=
True,
79 make_reset_separate_task=
False,
82 action_set_update_marker.descend_invocation_order = (
83 new_step.highest_descend_invocation_order() + 1
85 action_set_update_marker.parallel =
True
86 new_step.add_action_set(action_set_update_marker)
96 if step.dependencies == AlgorithmStep.Dependencies.NEIGHBOURS:
97 if use_continuous_particles_sequences:
100 "GRAPH COMPILER DEBUG [translate_one_step_of_species_into_mesh_traversal]: step no {} ({}) on particle {} can use the peano4.api.toolbox.particles.UpdateParticle_MultiLevelInteraction_StackOfLists_ContiguousParticles action set and hence optimise aggressively".format(
101 len(mesh_traversals),
103 current_species_set.particle_model.name,
107 particle_set=current_species_set,
108 particle_particle_interaction_kernel=step.cell_kernel,
109 touch_vertex_first_time_compute_particle_update_kernel=step.touch_vertex_first_time_kernel,
110 touch_vertex_last_time_compute_particle_update_kernel=step.touch_vertex_last_time_kernel,
111 prepare_traversal_kernel=step.prepare_traversal_kernel,
112 unprepare_traversal_kernel=step.unprepare_traversal_kernel,
113 additional_includes=step.includes,
114 active_particle_set=step.input_particles,
119 "GRAPH COMPILER DEBUG [translate_one_step_of_species_into_mesh_traversal]: step no {} ({}) on particle {} uses the peano4.api.toolbox.particles.UpdateParticle_MultiLevelInteraction_Sets".format(
120 len(mesh_traversals),
122 current_species_set.particle_model.name,
126 particle_set=current_species_set,
127 particle_particle_interaction_kernel=step.cell_kernel,
128 touch_vertex_first_time_compute_particle_update_kernel=step.touch_vertex_first_time_kernel,
129 touch_vertex_last_time_compute_particle_update_kernel=step.touch_vertex_last_time_kernel,
130 prepare_traversal_kernel=step.prepare_traversal_kernel,
131 unprepare_traversal_kernel=step.unprepare_traversal_kernel,
132 additional_includes=step.includes,
133 active_particle_set=step.input_particles,
135 action_set_particle_particle_interaction.descend_invocation_order = (
136 new_step.highest_descend_invocation_order() + 1
138 action_set_particle_particle_interaction.parallel =
True
139 new_step.add_action_set(action_set_particle_particle_interaction)
140 elif step.dependencies == AlgorithmStep.Dependencies.SELF:
141 if use_continuous_particles_sequences:
144 "GRAPH COMPILER DEBUG [translate_one_step_of_species_into_mesh_traversal]: step no {} ({}) on particle {} uses peano4.api.toolbox.particles.UpdateParticle_SingleLevelInteraction_ContiguousParticles action set".format(
145 len(mesh_traversals),
147 current_species_set.particle_model.name,
152 particle_set=current_species_set,
153 particle_cell_update_kernel=step.cell_kernel,
154 touch_vertex_first_time_compute_particle_update_kernel=step.touch_vertex_first_time_kernel,
155 touch_vertex_last_time_compute_particle_update_kernel=step.touch_vertex_last_time_kernel,
156 prepare_traversal_kernel=step.prepare_traversal_kernel,
157 unprepare_traversal_kernel=step.unprepare_traversal_kernel,
158 additional_includes=step.includes,
159 active_particle_set=step.input_particles,
161 action_set_particle_update.descend_invocation_order = (
162 new_step.highest_descend_invocation_order() + 1
164 action_set_particle_update.parallel =
True
165 new_step.add_action_set(action_set_particle_update)
169 "GRAPH COMPILER DEBUG [translate_one_step_of_species_into_mesh_traversal]: step no {} ({}) on particle {} uses peano4.api.toolbox.particles.UpdateParticle_SingleLevelInteraction action set".format(
170 len(mesh_traversals),
172 current_species_set.particle_model.name,
177 particle_set=current_species_set,
178 particle_cell_update_kernel=step.cell_kernel,
179 touch_vertex_first_time_compute_particle_update_kernel=step.touch_vertex_first_time_kernel,
180 touch_vertex_last_time_compute_particle_update_kernel=step.touch_vertex_last_time_kernel,
181 prepare_traversal_kernel=step.prepare_traversal_kernel,
182 unprepare_traversal_kernel=step.unprepare_traversal_kernel,
183 additional_includes=step.includes,
184 active_particle_set=step.input_particles,
186 action_set_particle_update.descend_invocation_order = (
187 new_step.highest_descend_invocation_order() + 1
189 action_set_particle_update.parallel =
True
190 new_step.add_action_set(action_set_particle_update)
192 assert False,
"step {} seems to have no action at all".format(step)
198 step.effect== AlgorithmStep.Effect.CHANGE_POSITION_OR_INTERACTION_RADIUS_AND_MIGHT_RERUN
200 step.effect == AlgorithmStep.Effect.CHANGE_POSITION_OR_INTERACTION_RADIUS
202 alter_particle_position.append(
True)
204 alter_particle_position.append(
False)
206 mesh_traversals.append(new_step)
209def map_onto_separate_mesh_traversals_with_generic_mapper(
211 particle_sorting_and_storage: ParticleSortingAndStorage,
218 Generic mapper of separate steps of separate particles onto mesh traversals
220 expects a mapper that then defines how to actually map the species plus
225 alter_particle_position = []
229 "GRAPH COMPILER DEBUG [map_onto_separate_mesh_traversals]: start graph construction with particle sorting {} and step type {}".format(
230 particle_sorting_and_storage, step_type
234 for current_entry_from_total_sequence_of_steps
in sequence_of_steps:
235 current_species_set = current_entry_from_total_sequence_of_steps[0]
236 current_step_of_species = current_entry_from_total_sequence_of_steps[1]
239 particle_sorting_and_storage == ParticleSortingAndStorage.SORT_ON_THE_FLY_SCATTERED_PARTICLE_STORAGE
241 use_continuous_particles_sequences =
False
242 add_additional_dummy_sweep = AddAdditionalDummySweep.NO
244 particle_sorting_and_storage == ParticleSortingAndStorage.SORT_ON_THE_FLY_COALESCED_PARTICLE_STORAGE
246 use_continuous_particles_sequences =
True
247 add_additional_dummy_sweep = AddAdditionalDummySweep.NO
249 particle_sorting_and_storage == ParticleSortingAndStorage.SORT_WITH_LIFTS_AND_DROPS_SCATTERED_PARTICLE_STORAGE
250 and len(alter_particle_position) > 0
251 and alter_particle_position[-1]
253 use_continuous_particles_sequences =
False
254 add_additional_dummy_sweep = AddAdditionalDummySweep.BEFORE
256 particle_sorting_and_storage == ParticleSortingAndStorage.SORT_WITH_LIFTS_AND_DROPS_SCATTERED_PARTICLE_STORAGE
258 use_continuous_particles_sequences =
False
259 add_additional_dummy_sweep = AddAdditionalDummySweep.NO
261 particle_sorting_and_storage == ParticleSortingAndStorage.SORT_WITH_LIFTS_AND_DROPS_COALESCED_PARTICLE_STORAGE
262 and len(alter_particle_position) > 0
263 and alter_particle_position[-1]
265 use_continuous_particles_sequences =
True
266 add_additional_dummy_sweep = AddAdditionalDummySweep.BEFORE
268 particle_sorting_and_storage == ParticleSortingAndStorage.SORT_WITH_LIFTS_AND_DROPS_COALESCED_PARTICLE_STORAGE
270 use_continuous_particles_sequences =
True
271 add_additional_dummy_sweep = AddAdditionalDummySweep.NO
273 assert False,
"variant {} x {} not supported".format(particle_sorting_and_storage,alter_particle_position)
275 if add_additional_dummy_sweep == AddAdditionalDummySweep.BEFORE:
278 "GRAPH COMPILER DEBUG [map_onto_separate_mesh_traversals]: step no {} ({}) on particle {} has to be dummy step to clean up sorting. Will not alter particle position itself".format(
279 len(mesh_traversals),
280 current_step_of_species.name,
281 current_species_set.particle_model.name,
285 "DummyStep{}{}_sweep{}".format(
286 current_species_set.particle_model.name,
287 current_step_of_species.name,
288 len(mesh_traversals),
290 add_user_defined_actions=
False,
293 mesh_traversals.append(new_step)
294 alter_particle_position.append(
False)
297 step=current_step_of_species,
298 current_species_set=current_species_set,
299 mesh_traversals=mesh_traversals,
300 alter_particle_position=alter_particle_position,
301 use_continuous_particles_sequences=use_continuous_particles_sequences,
306 if add_additional_dummy_sweep == AddAdditionalDummySweep.AFTER:
309 "GRAPH COMPILER DEBUG [map_onto_separate_mesh_traversals]: step no {} ({}) on particle {} has to be dummy step to clean up sorting. Will not alter the particle position itself".format(
310 len(mesh_traversals),
311 current_step_of_species.name,
312 current_species_set.particle_model.name,
316 "DummyStep{}{}_sweep{}".format(
317 current_species_set.particle_model.name,
318 current_step_of_species.name,
319 len(mesh_traversals),
321 add_user_defined_actions=
False,
324 mesh_traversals.append(new_step)
325 alter_particle_position.append(
False)
327 if step_type == StepType.INITIALISATION
and len(alter_particle_position) > 0:
336 alter_particle_position[0] =
True
337 alter_particle_position[-1] =
True
341 particle_sorting_and_storage==ParticleSortingAndStorage.SORT_WITH_LIFTS_AND_DROPS_SCATTERED_PARTICLE_STORAGE
343 particle_sorting_and_storage==ParticleSortingAndStorage.SORT_WITH_LIFTS_AND_DROPS_COALESCED_PARTICLE_STORAGE
345 sort_with_lifts_and_drops =
True
347 particle_sorting_and_storage==ParticleSortingAndStorage.SORT_ON_THE_FLY_SCATTERED_PARTICLE_STORAGE
349 particle_sorting_and_storage==ParticleSortingAndStorage.SORT_ON_THE_FLY_COALESCED_PARTICLE_STORAGE
351 sort_with_lifts_and_drops =
False
353 assert False,
"variant {} not implemented".format(particle_sorting_and_storage)
356 add_dynamic_mesh_refinement_and_particle_resorting(
358 alter_particle_position,
359 get_species_set(sequence_of_steps),
360 sort_with_lifts_and_drops=sort_with_lifts_and_drops,
366 "GRAPH COMPILER DEBUG [map_onto_separate_mesh_traversals]: finished graph construction"
369 return mesh_traversals