14 self, particle_set, coordinates, initialisation_call, additional_includes=""
18 particle_set: ParticleSet
20 N: number of particles
22 coordinates: [ [Float,Float,Float] ]
23 Coordinates for the particle. So you can write
25 coordinates=[ [0.0,0.0,0.0], [0.2,0.2,0.0]]
27 for example to insert two particles. The code will create two particles.
28 This variant will work with 2d and 3d compiles, where the third
29 coordinate is ignored if you compile in 2d. If you pass in 2d coordinates,
30 then the code will fail (assertion) if you try to compile it in 3d.
32 initialisation_call: String (C++ code snippet)
33 Arbitrary code snippet which can work over a pointer particle. The object
34 to which this pointer points to is properly allocated, and its
35 coordinates are set. Furthermore, the object's search radius is
36 initialised with zero. You can alter the particle attributes now, i.e.
37 initialise the domain-specific data. Please also ensure you assign the
38 particle a proper search (interaction) radius if the radius is of
39 relevance for your application.
42 super(InsertParticlesByCoordinates, self).
__init__(
43 descend_invocation_order=1, parallel=
False
47 self.
d[
"PARTICLE"] = particle_set.particle_model.name
48 self.
d[
"PARTICLES_CONTAINER"] = particle_set.name
49 self.
d[
"N"] = len(coordinates)
50 self.
d[
"INITIALISATION_CALL"] = initialisation_call
55 __Template_TouchCellFirstTime = jinja2.Template(
58 for(int i=0;i<{{N}};i++){
59 // It is important to have this asymmetric comparisons with <= as we
60 // need to ensure that particles right in the centre are either associated
61 // with the vertex left or right.
63 not marker.willBeRefined()
65 marker.isContained(_coordinates[i])
67 globaldata::{{PARTICLE}}* particle = new globaldata::{{PARTICLE}}();
69 toolbox::particles::init(*particle,_coordinates[i],0.0);
71 // See documentation of constructor on initialisation snippet
72 {{INITIALISATION_CALL}}
74 toolbox::particles::insertParticleIntoCell(
77 fineGridVertices{{PARTICLES_CONTAINER}},
87 if operation_name == ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
92 return " return std::vector< peano4::grid::GridControlEvent >();\n"
95 return __name__.replace(
".py",
"").replace(
".",
"_")
101 result = jinja2.Template(
103#include "tarch/multicore/Lock.h"
104#include "vertexdata/{{PARTICLES_CONTAINER}}.h"
105#include "globaldata/{{PARTICLE}}.h"
106#include "toolbox/particles/particles.h"
107#include "toolbox/particles/ParticleFactory.h"
111 return result.render(**self.
d)
116 Initialise the coordinates
118 This routine initialises the coordinates array, but it does so if and only
119 if this hasn't been done yet. Each tree traversal creates its own action
120 set. However, it would be ridiculously stupid to create the coordinates
121 multiple times. Rather, I
126_spacetreeId = treeNumber;
128#pragma clang optimize off
129tarch::multicore::Lock lock (_coordinatesSemaphore);
130if (_coordinates==nullptr) {
131 _coordinates = new tarch::la::Vector<Dimensions,double>["""
138 for i
in range(self.
d[
"N"]):
154 result +=
" #if Dimensions==3\n"
162 result +=
" #endif\n"
165 dimensions == -1
or dimensions == 3
166 ),
"inconsistent data: all coordinates have to have three entries: {}".format(
185 result +=
" assertion(Dimensions==2);\n"
188 dimensions == -1
or dimensions == 2
189 ),
"inconsistent data: all coordinates have to have three entries: {}".format(
195#pragma clang optimize on
202tarch::la::Vector<Dimensions,double>* """
203 + full_qualified_classname
204 +
"""::_coordinates = nullptr;
205tarch::multicore::BooleanSemaphore """
206 + full_qualified_classname
207 +
"""::_coordinatesSemaphore;
213 static tarch::multicore::BooleanSemaphore _coordinatesSemaphore;
214 static tarch::la::Vector<Dimensions,double>* _coordinates;
Default superclass for any data model in Peano which is stored within the grid.
Action set (reactions to events)
get_includes(self)
Return include statements that you need.
get_action_set_name(self)
Return unique action set name.
get_constructor_body(self)
Initialise the coordinates.
get_body_of_getGridControlEvents(self)
user_should_modify_template(self)
Is the user allowed to modify the output.
__Template_TouchCellFirstTime
__init__(self, particle_set, coordinates, initialisation_call, additional_includes="")
particle_set: ParticleSet
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
get_static_initialisations(self, full_qualified_classname)
get_attributes(self)
Return attributes as copied and pasted into the generated class.