Peano
Loading...
Searching...
No Matches
InsertRandomParticlesIntoUnrefinedCells.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
5
6import jinja2
7
8
10 """!
11
12 Insert particles
13
14 The particles are topologically Cartesian, i.e. they are not totally random. So
15 we embed a Cartesian "grid" of particles into each unrefined cell, and then add
16 some noise to them. As the individual cells are not coupled with each other, and
17 as we do not evaluate any global coordinates, the overall result will not be
18 random, even if you switch off noise completely, as the spacing between two
19 regular particle layouts between two neighbouring cells is not "synchronised".
20
21 """
22
24 self,
25 particle_set,
26 average_distance_between_particles,
27 initialisation_call,
28 round_down=False,
29 noise=True,
30 additional_includes="",
31 ):
32 """!
33
34 Insert particles
35
36 The particles are topologically Cartesian, i.e. they are not totally random. So
37 we embed a Cartesian "grid" of particles into each unrefined cell, and then add
38 some noise to them. As the individual cells are not coupled with each other, and
39 as we do not evaluate any global coordinates, the overall result will not be
40 random, even if you switch off noise completely, as the spacing between two
41 regular particle layouts between two neighbouring cells is not "synchronised".
42
43 :Attibutes:
44
45 particle: ParticleSet
46 I take this as particle set.
47
48 average_distance_between_particles: Float
49 Some positive floating point value. I call it average, as it is an
50 average if you apply noise. Otherwise, it is the precise distance.
51
52 initialisation_call: String (C++ code snippet)
53 Arbitrary code snippet which can work over a pointer particle. The object
54 to which this pointer points to is properly allocated, and its
55 coordinates are set. Furthermore, the object's search radius is
56 initialised with zero. You can alter the particle attributes now, i.e.
57 initialise the domain-specific data. Please also ensure you assign the
58 particle a proper search (interaction) radius if the radius is of
59 relevance for your application.
60
61 Please note that we create a lot of particles and then decide if we
62 actually insert them. Only those particles where we come to the
63 conclusion that we should insert them (as they overlap with the cell)
64 are actually then initialised through this code snippet.
65
66 """
67 super(InsertRandomParticlesIntoUnrefinedCells, self).__init__(
68 descend_invocation_order=1, parallel=False
69 )
70
71 self.d = {}
72 self.d["PARTICLE"] = particle_set.particle_model.name
73 self.d["PARTICLES_CONTAINER"] = particle_set.name
74 self.d["INITIALISATION_CALL"] = initialisation_call
75 self.d["H"] = average_distance_between_particles
76 if noise:
77 self.d["NOISE"] = "true"
78 else:
79 self.d["NOISE"] = "false"
80 if round_down:
81 self.d["ROUND_DOWN"] = "true"
82 else:
83 self.d["ROUND_DOWN"] = "false"
84 self.additional_includes = additional_includes
85
86 __Template_TouchCellFirstTime = jinja2.Template(
87 """
88 if ( not marker.hasBeenRefined() and not marker.willBeRefined() ) {
89 std::vector< globaldata::{{PARTICLE}}* > newParticles = toolbox::particles::createEquallySpacedParticles<globaldata::{{PARTICLE}}>(
90 {{H}},
91 marker.x(),
92 marker.h(),
93 {{ROUND_DOWN}},
94 {{NOISE}}
95 );
96 for (auto* particle: newParticles) {
97 // See documentation of constructor on initialisation snippet
98 {{INITIALISATION_CALL}}
99 }
100 toolbox::particles::insertParticlesIntoCell(
101 marker,
102 newParticles,
103 fineGridVertices{{PARTICLES_CONTAINER}}
104 );
105 }
106"""
107 )
108
109 def get_body_of_operation(self, operation_name):
110 result = "\n"
111 if operation_name == ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
112 result = self.__Template_TouchCellFirstTime.render(**self.d)
113 return result
114
116 return " return std::vector< peano4::grid::GridControlEvent >();\n"
117
119 return __name__.replace(".py", "").replace(".", "_")
120
122 return False
123
124 def get_includes(self):
125 result = jinja2.Template(
126 """
127#include "tarch/multicore/multicore.h"
128#include "toolbox/particles/particles.h"
129#include "vertexdata/{{PARTICLES_CONTAINER}}.h"
130#include "globaldata/{{PARTICLE}}.h"
131#include "toolbox/particles/ParticleFactory.h"
132"""
133 )
134 return result.render(**self.d) + self.additional_includes
Action set (reactions to events)
Definition ActionSet.py:6
__init__(self, particle_set, average_distance_between_particles, initialisation_call, round_down=False, noise=True, additional_includes="")
Insert particles.
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.