Peano
Loading...
Searching...
No Matches
Fixed.py
Go to the documentation of this file.
1# This file is part of the Swift2 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 """!
10
11 Fixed boundary conditions
12
13 Impose fixed boundary conditions within an action set. Such an action set
14 can be injected into each and every grid sweep.
15 @ref swift_boundary_conditions "Swift's generic boundary condition"
16 remarks discuss this realisation variant. It is quite heavy-weight and can
17 yield invalid states prior to the very first time step.
18
19 The action set is used by adding it after you have lowered the Swift 2
20 formalism into a Peano 4 project:
21
22 ~~~~~~~~~~~~~~~~~~~~~~~~~
23project.additional_action_sets_per_solver_step.append(
24 swift2.api.boundaryconditions.Fixed(particle_set=particle_set,
25 damp_particles_as_they_approach_boundary=True
26 )
27)
28 ~~~~~~~~~~~~~~~~~~~~~~~~~
29
30 @param particle_set: swift2.particle.Particle
31 The particle set for which we implement the boundary conditions.
32
33 @param relative_domain_halo: Positive float smaller than 0.5
34 The relative boundary in which we actually check particles at
35 all. This one refers to the cells adjacent to the boundary. So
36 if you pass in a 0.1, it means that 10% of this cell will next
37 to the boundary will actually be read as "on the boundary".
38
39 @param damp_particles_as_they_approach_boundary: Boolean
40
41 """
42
43 def __init__(self,
44 particle_set,
45 relative_domain_halo=0.1
46 ):
47 """!
48
49 Fixed boundary condition
50
51 Fixed boundary conditions are very difficult to impose within SPH. This
52 is a very simplistic realisation of fixed boundary conditions, where
53 particles are forced to come to rest once they approach the domain
54 boundary.
55
56 """
57 super(Fixed, self).__init__()
58 self.d = {}
59 self.d["PARTICLE"] = particle_set.particle_model.name
60 self.d["PARTICLES_CONTAINER"] = particle_set.name
61 self.d["VELOCITY_ATTRIBUTE"] = particle_set.particle_model.velocity.get_accessor_name()
62 self.d["RELATIVE_DOMAIN_HALO"] = relative_domain_halo
63
65 return __name__.replace(".py", "").replace(".", "_")
66
67 __Template_TouchVertexLastTime = jinja2.Template(
68 """
69 // check only boundary vertices
70 if (::swift2::boundaryconditions::isVertexOnGlobalBoundary(marker,DomainOffset,DomainSize)) {
71 for (auto& particle: fineGridVertex{{PARTICLES_CONTAINER}}) {
72 ::swift2::boundaryconditions::applyFixedBoundaryCondition(
73 *particle,
74 marker,
75 DomainOffset,
76 DomainSize,
77 {{RELATIVE_DOMAIN_HALO}},
78 _spacetreeId
79 );
80 } // for loop over particles
81 } // if on marker
82 """
83 )
84
85 def get_body_of_operation(self, operation_name):
86 result = "\n"
87 if operation_name == ActionSet.OPERATION_TOUCH_VERTEX_LAST_TIME:
88 result = self.__Template_TouchVertexLastTime.render(**self.d)
89 return result
90
92 return False
93
94 def get_includes(self):
95 result = jinja2.Template(
96 """
97#include "Constants.h"
98#include "vertexdata/{{PARTICLES_CONTAINER}}.h"
99#include "globaldata/{{PARTICLE}}.h"
100#include "swift2/kernels/ParticleSetIterators.h"
101#include "swift2/boundaryconditions/Utils.h"
102#include "swift2/boundaryconditions/FixedBoundary.h"
103"""
104 )
105 return result.render(**self.d)
106
108 return (
109 super(Fixed, self).get_constructor_body()
110 + """
111 _spacetreeId = treeNumber;
112 """
113 )
114
115 def get_attributes(self):
116 return """
117 int _spacetreeId;
118"""
Action set (reactions to events)
Definition ActionSet.py:6
Fixed boundary conditions.
Definition Fixed.py:8
get_constructor_body(self)
Define a tailored constructor body.
Definition Fixed.py:107
get_attributes(self)
Return attributes as copied and pasted into the generated class.
Definition Fixed.py:115
__init__(self, particle_set, relative_domain_halo=0.1)
Fixed boundary condition.
Definition Fixed.py:46
get_action_set_name(self)
Return unique action set name.
Definition Fixed.py:64
get_includes(self)
Return include statements that you need.
Definition Fixed.py:94
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
Definition Fixed.py:85
user_should_modify_template(self)
Is the user allowed to modify the output.
Definition Fixed.py:91