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 if ( not marker.hasBeenRefined() and not marker.willBeRefined() ) {
86 #if Dimensions==2
87 tarch::la::Vector<2,double> domainOffset = { {{DOMAIN_OFFSET[0]}}, {{DOMAIN_OFFSET[1]}} };
88 tarch::la::Vector<2,double> domainSize = { {{DOMAIN_SIZE[0]}}, {{DOMAIN_SIZE[1]}} };
89 #else
90 tarch::la::Vector<3,double> domainOffset = { {{DOMAIN_OFFSET[0]}}, {{DOMAIN_OFFSET[1]}}, {{DOMAIN_OFFSET[2]}} };
91 tarch::la::Vector<3,double> domainSize = { {{DOMAIN_SIZE[0]}}, {{DOMAIN_SIZE[1]}}, {{DOMAIN_SIZE[2]}} };
92 #endif
93 std::vector< globaldata::{{PARTICLE}}* > newParticles = toolbox::particles::createParticlesAlignedWithGlobalCartesianMesh<globaldata::{{PARTICLE}}>(
94 {{H}},
95 marker.x(),
96 marker.h(),
97 domainOffset,
98 domainSize,
99 {{NOISE}}
100 );
101 for (auto* particle: newParticles) {
102 if ( {{GUARD}} ) {
103 // See documentation of constructor on initialisation snippet
104 {{INITIALISATION_CALL}}
105 toolbox::particles::insertParticleIntoCell(
106 marker,
107 particle,
108 fineGridVertices{{PARTICLES_CONTAINER}},
109 _spacetreeId
110 );
111 }
112 else {
113 delete particle;
114 }
115 }
116 }
117"""
118 )
119
120 def get_body_of_operation(self, operation_name):
121 result = "\n"
122 if operation_name == ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
123 result = self.__Template_TouchCellFirstTime.render(**self.d)
124 return result
125
127 return " return std::vector< peano4::grid::GridControlEvent >();\n"
128
130 return __name__.replace(".py", "").replace(".", "_")
131
133 return False
134
135 def get_includes(self):
136 result = jinja2.Template(
137 """
138#include "vertexdata/{{PARTICLES_CONTAINER}}.h"
139#include "globaldata/{{PARTICLE}}.h"
140#include "toolbox/particles/particles.h"
141#include "toolbox/particles/ParticleFactory.h"
142"""
143 )
144 return result.render(**self.d) + self.additional_includes
145
146 def get_attributes(self):
147 return f"""
148 int _spacetreeId;
149"""
150
152 return """
153 _spacetreeId = treeNumber;
154"""
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.