196 Add dependency checks as well as mesh consistency checks to the algorithm steps
198 This function actually modifies the AlgorithmSteps to contain the
199 debug dependency checks. Is called by self._add_dependency_checks()
200 and uses the validation routines from swift2::dependencychecks.
202 The routine is used to either add checks for the init phase or the
203 actual time stepping. Which one is meant is identified through
204 step_type_name. You can obviously call the routine twice: once for
205 init and once for the time stepping. Later on, you might want to
208 Besides the name of interest, we also require a list of algorithmic
209 steps through which the code runs through.
214 If the user does not define bespoke default settings, this routine adds
215 default ones. These are set through instances of swift::dependencychecks::Invariant.
217 - For vertices, this is touch-at-most-once-mask-out-otherwise-all-previous-steps-update-at-least-once.
218 - For cells, this is also touch-at-most-once-mask-out-otherwise-all-previous-steps-update-at-least-once.
220 ## Additional attributes
222 First, the particle is added two counters which count up how often a
223 particle is touched or masked out.
225 @param Steplist: list
226 list of AlgorithmStep objects to work on
228 @param step_type_name: str
229 name of type of steps we're dealing with. Either AlgorithmStep
232 @param peano4_event_enum: list
233 list of enums of peano4 events within a single mesh traversal
234 (e.g. touch vertex first time, cell kernel, ...)
237 the modified list of AlgorithmSteps, now including dependency checks
240 steps = copy.deepcopy(steplist)
242 nevents = AlgorithmStep.PeanoEventUsedBySwift.EVENT_COUNT.value
247 step_name_list = [step.name
for step
in steps]
248 step_name_list.append(
"count")
254 self.
data.add_attribute(step_name_enum)
262 self.
data.add_attribute(number_of_updates)
269 self.
data.add_attribute(number_of_mask_outs)
272 check_template_cell_operation =
"""
273 ::swift2::dependencychecks::check{STEP_TYPE}(
274 ::swift2::dependencychecks::Invariant::{INVARIANT},
278 globaldata::{NAME}::DependencyChecks{STEP_TYPE}LastUpdated::{STEP_NAME},
279 globaldata::{NAME}::{PEANO4_EVENT_TYPE}::{EVENT},
285 check_template_vertex_operation =
"""
286 ::swift2::dependencychecks::check{STEP_TYPE}(
287 ::swift2::dependencychecks::Invariant::{INVARIANT},
290 globaldata::{NAME}::DependencyChecks{STEP_TYPE}LastUpdated::{STEP_NAME},
291 globaldata::{NAME}::{PEANO4_EVENT_TYPE}::{EVENT},
297 mark_template_cell_operation =
"""
298 ::swift2::dependencychecks::mark{STEP_TYPE}(
302 globaldata::{NAME}::DependencyChecks{STEP_TYPE}LastUpdated::{STEP_NAME},
303 globaldata::{NAME}::{PEANO4_EVENT_TYPE}::{EVENT},
304 ::swift2::dependencychecks::Invariant::{INVARIANT},
310 mark_template_vertex_operation =
"""
311 ::swift2::dependencychecks::mark{STEP_TYPE}(
314 globaldata::{NAME}::DependencyChecks{STEP_TYPE}LastUpdated::{STEP_NAME},
315 globaldata::{NAME}::{PEANO4_EVENT_TYPE}::{EVENT},
316 ::swift2::dependencychecks::Invariant::{INVARIANT},
322 check_template_vertex_operation_local_particles_after_sweep =
"""
323 ::swift2::dependencychecks::checkParticlesAssignedToVertexInTouchLastTime{STEP_TYPE}(
324 ::swift2::dependencychecks::Invariant::{INVARIANT},
326 globaldata::{NAME}::DependencyChecks{STEP_TYPE}LastUpdated::{STEP_NAME},
331 for i, step
in enumerate(steps):
334 "STEP_TYPE": step_type_name,
335 "STEP_NAME": step.name,
336 "PEANO4_EVENT_TYPE": peano4_event_enum.get_accessor_name(),
337 "CHECK_FUNCTION":
None,
342 step.prepare_traversal_kernel = (
344 toolbox::particles::assignmentchecks::startMeshSweep( "{}" );
348 + step.prepare_traversal_kernel
352 step.touch_vertex_first_time_dependency_policy ==
None
353 and AlgorithmStep.may_trigger_rerun(step.effect)
357 ] =
"TouchFirstUsage_MaskOutAfterwards_AllPreviousStepsUpdateAtLeastOnce_SweepMayRerun"
358 elif step.touch_vertex_first_time_dependency_policy ==
None:
361 ] =
"TouchFirstUsage_MaskOutAfterwards_AllPreviousStepsUpdateAtLeastOnce"
363 d[
"INVARIANT"] = step.touch_vertex_first_time_dependency_policy
367 d[
"EVENT"] = AlgorithmStep.get_event_name(
368 AlgorithmStep.PeanoEventUsedBySwift.TOUCH_VERTEX_FIRST_TIME
372 ] =
"::swift2::kernels::localParticleCanBeUpdatedInVertexKernel<globaldata::{}>".format(
376 if step.touch_vertex_first_time_kernel
is None:
377 step.touch_vertex_first_time_kernel =
""
382 step.touch_vertex_first_time_kernel = (
383 "\n ::swift2::dependencychecks::clearDependencyChecks"
385 +
"(assignedParticles);\n"
386 + mark_template_vertex_operation.format(**d)
387 + step.touch_vertex_first_time_kernel
390 step.touch_vertex_first_time_kernel = (
391 mark_template_vertex_operation.format(**d)
392 + step.touch_vertex_first_time_kernel
396 step.touch_vertex_first_time_kernel += (
397 check_template_vertex_operation.format(**d)
402 d[
"EVENT"] = AlgorithmStep.get_event_name(
403 AlgorithmStep.PeanoEventUsedBySwift.CELL_KERNEL
407 ] =
"::swift2::kernels::localParticleCanBeUpdatedInCellKernelFromAnyOtherParticle<globaldata::{}>".format(
412 step.cell_kernel_dependency_policy ==
None
413 and AlgorithmStep.may_trigger_rerun(step.effect)
417 ] =
"TouchAtMostOnce_MaskOutOtherwise_AllPreviousStepsUpdateAtLeastOnce_SweepMayRerun"
418 elif step.cell_kernel_dependency_policy ==
None:
421 ] =
"TouchAtMostOnce_MaskOutOtherwise_AllPreviousStepsUpdateAtLeastOnce"
423 d[
"INVARIANT"] = step.cell_kernel_dependency_policy
425 if step.cell_kernel
is None:
426 step.cell_kernel =
""
429 mark_template_cell_operation.format(**d) + step.cell_kernel
433 step.cell_kernel += check_template_cell_operation.format(**d)
437 d[
"EVENT"] = AlgorithmStep.get_event_name(
438 AlgorithmStep.PeanoEventUsedBySwift.TOUCH_VERTEX_LAST_TIME
442 ] =
"::swift2::kernels::localParticleCanBeUpdatedInVertexKernel<globaldata::{}>".format(
447 step.touch_vertex_last_time_dependency_policy ==
None
448 and AlgorithmStep.may_trigger_rerun(step.effect)
452 ] =
"TouchFirstUsage_MaskOutAfterwards_AllPreviousStepsUpdateAtLeastOnce_SweepMayRerun"
453 elif step.touch_vertex_last_time_dependency_policy ==
None:
456 ] =
"TouchFirstUsage_MaskOutAfterwards_AllPreviousStepsUpdateAtLeastOnce"
458 d[
"INVARIANT"] = step.touch_vertex_last_time_dependency_policy
460 if step.touch_vertex_last_time_kernel
is None:
461 step.touch_vertex_last_time_kernel =
""
463 step.touch_vertex_last_time_kernel = (
464 mark_template_vertex_operation.format(**d)
465 + step.touch_vertex_last_time_kernel
469 step.touch_vertex_last_time_kernel += (
470 check_template_vertex_operation.format(**d)
476 step.touch_vertex_last_time_kernel += (
477 check_template_vertex_operation_local_particles_after_sweep.format(**d)