Peano
Loading...
Searching...
No Matches
Fixed.py
Go to the documentation of this file.
1# This file is part of the ExaParty project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3from peano4.api.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 exaparty_boundary_conditions "ExaParty'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 ExaParty
20 formalism into a Peano 4 project:
21
22 ~~~~~~~~~~~~~~~~~~~~~~~~~
23project.additional_action_sets_per_solver_step.append(
24 exaparty.api.boundaryconditions.Fixed(particle_set=particle_set,
25 damp_particles_as_they_approach_boundary=True
26 )
27)
28 ~~~~~~~~~~~~~~~~~~~~~~~~~
29
30 @param particle_set: exaparty.api.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 for (auto& particle: fineGridVertex{{PARTICLES_CONTAINER}}) {
70 ::exaparty::boundaryconditions::applyFixedBoundaryCondition(
71 *particle,
72 marker,
73 DomainOffset,
74 DomainSize,
75 {{RELATIVE_DOMAIN_HALO}},
76 _spacetreeId
77 );
78 } // for loop over particles
79 """
80 )
81
82 def get_body_of_operation(self, operation_name):
83 result = "\n"
84 if operation_name == ActionSet.OPERATION_TOUCH_VERTEX_LAST_TIME:
85 result = self.__Template_TouchVertexLastTime.render(**self.d)
86 return result
87
88 def get_guard_of_operation(self, operation_name):
89 """!
90
91 Check only boundary vertices
92
93 """
94 if operation_name == ActionSet.OPERATION_TOUCH_VERTEX_LAST_TIME:
95 return "::exaparty::boundaryconditions::isVertexOnGlobalBoundary(marker,DomainOffset,DomainSize)"
96 return "true"
97
99 return False
100
101 def get_includes(self):
102 result = jinja2.Template(
103 """
104#include "Constants.h"
105#include "vertexdata/{{PARTICLES_CONTAINER}}.h"
106#include "globaldata/{{PARTICLE}}.h"
107#include "exaparty/kernels/ParticleSetIterators.h"
108#include "exaparty/boundaryconditions/Utils.h"
109#include "exaparty/boundaryconditions/FixedBoundary.h"
110"""
111 )
112 return result.render(**self.d)
113
115 return (
116 super(Fixed, self).get_constructor_body()
117 + """
118 _spacetreeId = treeNumber;
119 """
120 )
121
122 def get_attributes(self):
123 return """
124 int _spacetreeId;
125"""
Fixed boundary conditions.
Definition Fixed.py:8
get_guard_of_operation(self, operation_name)
Check only boundary vertices.
Definition Fixed.py:88
get_action_set_name(self)
Return unique action set name.
Definition Fixed.py:64
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
Definition Fixed.py:82
__init__(self, particle_set, relative_domain_halo=0.1)
Fixed boundary condition.
Definition Fixed.py:46
get_constructor_body(self)
Define a tailored constructor body.
Definition Fixed.py:114
get_includes(self)
Return include statements that you need.
Definition Fixed.py:101
get_attributes(self)
Return attributes as copied and pasted into the generated class.
Definition Fixed.py:122
user_should_modify_template(self)
Is the user allowed to modify the output.
Definition Fixed.py:98
Action set (reactions to events)
Definition ActionSet.py:6