Peano
Loading...
Searching...
No Matches
SpeciesStepOrdering.py
Go to the documentation of this file.
1# This file is part of the ExaParty project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3
4
5def concatenate_steps_of_species(
6 species_sets,
7 use_initialisation_steps=False,
8):
9 """!
10
11 Take the steps per species and concatenate them
12
13 So we first have all the steps of the first species, then all the steps of
14 the second species, and so forth.
15
16 @return [(Species,Step)]
17 The first entry is the species itself, the second its step. The third
18 entry is the number of the species. All species are enumerationed starting
19 with 0. This index is one way to distinguish them.
20
21 """
22 result = []
23 for current_species_set in species_sets:
24 if use_initialisation_steps:
25 per_species_set = current_species_set.particle_model.initialisation_steps()
26 else:
27 per_species_set = current_species_set.particle_model.algorithm_steps()
28 for step in per_species_set:
29 result.append(
30 (current_species_set, step)
31 )
32 return result
33
34
35def interleave_steps_of_species(
36 species_sets,
37 use_initialisation_steps=False,
38):
39 """!
40
41 Interleave the steps of the species
42
43 Start with the first step of the first species, then the first step of the
44 second species, and so forth.
45
46 """
47
48 if use_initialisation_steps:
49 unassigned_steps = [
50 current_species_set.particle_model.initialisation_steps()
51 for current_species_set in species_sets
52 ]
53 else:
54 unassigned_steps = [
55 current_species_set.particle_model.algorithm_steps()
56 for current_species_set in species_sets
57 ]
58
59 unassigned_steps = [0 for x in current_species_set]
60 result = []
61 added_entry = True
62 while added_entry:
63 added_entry = False
64 for current_species_set in species_sets:
65 current_species_set_number = species_sets.index(current_species_set)
66 if use_initialisation_steps:
67 per_species_set = (
68 current_species_set.particle_model.initialisation_steps()
69 )
70 else:
71 per_species_set = current_species_set.particle_model.algorithm_steps()
72 if active_step[current_species_set_number] < len(per_species_set):
73 result.append(
74 current_species,
75 per_species_set[active_step[current_species_set_number]]
76 )
77 active_step[current_species_set_number] += 1
78 added_entry = True
79 return result