Peano 4
Loading...
Searching...
No Matches
UpdateParticleMarker.py
Go to the documentation of this file.
1# This file is part of the Peano project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3from peano4.solversteps.ActionSet import ActionSet
4
5import jinja2
6
7
9 def __init__(self,
10 particle_set,
11 automatically_set_marker_in_leave_cell):
12 """!
13
14 Update particles marker
15
16 Particles do not uniquely belong to one cell or the other. If they sit
17 exactly on the face in-between two cells, they belong to both. If they
18 sit on a vertex location, they can belong to up to 2^d cells. We cannot
19 avoid such an ambivalency, as we work with floating point numbers, and
20 as particles are stored within the vertices. If they were stored within
21 cells, the association would be unique by definition.
22
23 Therefore, we introduce a boolean per particle which indicates if a
24 particle has been updated by a cell already. That is, we do not make
25 the association unique artificially, but we realise a "whoever grabs it
26 first"-policy.
27
28 The realisation of this marker is straightforward: The
29 swift2.particle.Particle base class defines the marker, which is a simple
30 bool. When we touch a vertex for the first time, we implicitly also touch
31 all particles associated with this vertex for the first time. So we set
32 the marker to false.
33
34 When we leave a cell, we set all the flags to true. We can be sure that
35 this routine is called before we store the vertices and we can be sure that
36 it is called before we enter any adjacent cell. This statement implies that
37 you shall not change a vertex position prior to touchVertexLastTime().
38
39 For a task-based version, we cannot set the flags to true in
40 touchCellLastTime(). At this point, the cell's task might not have run yet,
41 so if we reset the particle state, we run risk that we break the code
42 semantics of the task functor, as they typically check for the update
43 flag. So if we use tasks, it has to be the task itself which sets the
44 "have updated" flag to true. This is realised within swift2::CellTask.
45
46 We note that the marker's name is unfortunate: It is not really that we
47 have updated a particle necessary. But we keep track that we have at least
48 studied one.
49
50 """
51 self._particle_set = particle_set
52 self.d = {}
53 self.d[ "PARTICLE" ] = particle_set.particle_model.name
54 self.d[ "PARTICLES_CONTAINER" ] = particle_set.name
55 self._automatically_set_marker_in_leave_cell = automatically_set_marker_in_leave_cell
56
57
58 __Template_TouchVertexFirstTime = jinja2.Template("""
59 auto& particles = fineGridVertex{{PARTICLES_CONTAINER}};
60
61 for (auto* particle: particles) {
62 particle->setCellHasUpdatedParticle(false);
63 }
64""")
65
66
67 __Template_TouchCellLastTime = jinja2.Template("""
68 for (int i=0; i<TwoPowerD; i++) {
69 for (auto* particle: fineGridVertices{{PARTICLES_CONTAINER}}(i) ) {
70 if ( marker.isContained( particle->getX() ) ) {
71 particle->setCellHasUpdatedParticle(true);
72 }
73 }
74 }
75""")
76
77
78 def get_body_of_operation(self,operation_name):
79 result = "\n"
80 if self._automatically_set_marker_in_leave_cell and operation_name==ActionSet.OPERATION_TOUCH_CELL_LAST_TIME:
81 result = self.__Template_TouchCellLastTime.render(**self.d)
82 if operation_name==ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME:
83 result = self.__Template_TouchVertexFirstTime.render(**self.d)
84 return result
85
86
88 return " return std::vector< peano4::grid::GridControlEvent >();\n"
89
90
91 #def get_body_of_prepareTraversal(self):
92 # return self.d[ "PREPARE_TRAVERSAL_KERNEL" ]
93
94
95 #def get_body_of_unprepareTraversal(self):
96 # return self.d[ "UNPREPARE_TRAVERSAL_KERNEL" ]
97
98
100 return __name__.replace(".py", "").replace(".", "_")
101
102
104 return False
105
106
107 def get_includes(self):
108 return jinja2.Template( """
109#include "vertexdata/{{PARTICLES_CONTAINER}}.h"
110#include "globaldata/{{PARTICLE}}.h"
111""" ).render( **self.d )
112
Action set (reactions to observations made by the grid traversal observer)
Definition ActionSet.py:6
__init__(self, particle_set, automatically_set_marker_in_leave_cell)
Update particles marker.
get_includes(self)
Return include statements that you need.
user_should_modify_template(self)
Is the user allowed to modify the output.
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.