Peano
Loading...
Searching...
No Matches
InsertParticlesAlongCartesianLayoutIntoUnrefinedCells.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
11 self,
12 particle_set,
13 distance_between_particles,
14 computational_domain_offset,
15 computational_domain_size,
16 initialisation_call="",
17 noise=True,
18 additional_includes="",
19 guard="true",
20 ):
21 """!
22 Insert particles
23
24
25 :Attibutes:
26
27 particle: ParticleSet
28 I take this as particle set.
29
30 average_distance_between_particles: Float
31 Some positive floating point value.
32
33 initialisation_call: String (C code)
34 Within this code snippet, you have a variable particle which is a pointer to
35 your particle type. You can use it to set the particle attributes.
36
37 computational_domain_offset: [Float]
38 Has to be an array with Dimensions entries that specifies the global domain
39 offset. You can pass in an array of floats, and this is definitely the
40 default use case. However, you can also pass in an arbitrary array of
41 strings, as long as these strings make sense in the generated C++ code
42 and eventually return a double each.
43
44 computational_domain_size: [Float]
45 Defines size of domain.
46
47 guard: String (C code)
48 A simple boolean expression. You can decide if a particle is inserted or not.
49
50 initialisation_call: String (C++ code snippet)
51 Arbitrary code snippet which can work over a pointer particle. The object
52 to which this pointer points to is properly allocated, and its
53 coordinates are set. Furthermore, the object's search radius is
54 initialised with zero. You can alter the particle attributes now, i.e.
55 initialise the domain-specific data. Please also ensure you assign the
56 particle a proper search (interaction) radius if the radius is of
57 relevance for your application.
58
59 Please note that we create a lot of particles and then decide if we
60 actually insert them. Only those particles where we come to the
61 conclusion that we should insert them (as they overlap with the cell)
62 are actually then initialised through this code snippet.
63
64 """
65 super(InsertParticlesAlongCartesianLayoutIntoUnrefinedCells, self).__init__(
66 descend_invocation_order=1, parallel=False
67 )
68
69 self.d = {}
70 self.d["PARTICLE"] = particle_set.particle_model.name
71 self.d["PARTICLES_CONTAINER"] = particle_set.name
72 self.d["INITIALISATION_CALL"] = initialisation_call
73 self.d["DOMAIN_OFFSET"] = computational_domain_offset
74 self.d["DOMAIN_SIZE"] = computational_domain_size
75 self.d["H"] = distance_between_particles
76 self.d["GUARD"] = guard
77 if noise:
78 self.d["NOISE"] = "true"
79 else:
80 self.d["NOISE"] = "false"
81 self.additional_includes = additional_includes
82
83 __Template_TouchCellFirstTime = jinja2.Template(
84 """
85
86 // Start of template in python/peano4/toolbox/particles/InsertParticlesAlongCartesianLayoutIntoUnrefinedCells.py
87
88 if ( not marker.hasBeenRefined() and not marker.willBeRefined() ) {
89 #if Dimensions==2
90 tarch::la::Vector<2,double> domainOffset = { {{DOMAIN_OFFSET[0]}}, {{DOMAIN_OFFSET[1]}} };
91 tarch::la::Vector<2,double> domainSize = { {{DOMAIN_SIZE[0]}}, {{DOMAIN_SIZE[1]}} };
92 #else
93 tarch::la::Vector<3,double> domainOffset = { {{DOMAIN_OFFSET[0]}}, {{DOMAIN_OFFSET[1]}}, {{DOMAIN_OFFSET[2]}} };
94 tarch::la::Vector<3,double> domainSize = { {{DOMAIN_SIZE[0]}}, {{DOMAIN_SIZE[1]}}, {{DOMAIN_SIZE[2]}} };
95 #endif
96 std::vector< globaldata::{{PARTICLE}}* > newParticles = toolbox::particles::createParticlesAlignedWithGlobalCartesianMesh<globaldata::{{PARTICLE}}>(
97 {{H}},
98 marker.x(),
99 marker.h(),
100 domainOffset,
101 domainSize,
102 {{NOISE}}
103 );
104 for (auto* particle: newParticles) {
105 if ( {{GUARD}} ) {
106 // See documentation of constructor on initialisation snippet
107 {{INITIALISATION_CALL}}
108 toolbox::particles::insertParticleIntoCell(
109 marker,
110 particle,
111 fineGridVertices{{PARTICLES_CONTAINER}},
112 _spacetreeId
113 );
114 }
115 else {
116 delete particle;
117 }
118 }
119 }
120
121 // End of template in python/peano4/toolbox/particles/InsertParticlesAlongCartesianLayoutIntoUnrefinedCells.py
122"""
123 )
124
125 def get_body_of_operation(self, operation_name):
126 result = "\n"
127 if operation_name == ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
128 result = self.__Template_TouchCellFirstTime.render(**self.d)
129 return result
130
132 return " return std::vector< peano4::grid::GridControlEvent >();\n"
133
135 return __name__.replace(".py", "").replace(".", "_")
136
138 return False
139
140 def get_includes(self):
141 result = jinja2.Template(
142 """
143#include "vertexdata/{{PARTICLES_CONTAINER}}.h"
144#include "globaldata/{{PARTICLE}}.h"
145#include "toolbox/particles/particles.h"
146#include "toolbox/particles/ParticleFactory.h"
147"""
148 )
149 return result.render(**self.d) + self.additional_includes
150
151 def get_attributes(self):
152 return f"""
153 int _spacetreeId;
154"""
155
157 return """
158 _spacetreeId = treeNumber;
159"""
Action set (reactions to events)
Definition ActionSet.py:6
__init__(self, particle_set, distance_between_particles, computational_domain_offset, computational_domain_size, initialisation_call="", noise=True, additional_includes="", guard="true")
Insert particles.