OpenLB 1.7
Loading...
Searching...
No Matches
particleConditions.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2022 Nicolas Hafen, Mathias J. Krause
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24/* Particle contitions provide the possibility to perform filtering
25 * operations on the particle system. Both static (evaluation at compile time)
26 * and dynamic conditions can be evaluated. For now, static conditions are not
27 * intended do be used with template parameters.
28 */
29
30
31#ifndef PARTICLE_CONDITIONS_H
32#define PARTICLE_CONDITIONS_H
33
34
35namespace olb {
36
37namespace particles {
38
39namespace conditions {
40
42 //Properties
43 static constexpr bool value=true;
44 static constexpr bool dynamic=false;
45};
46
48 template<typename T, typename PARTICLETYPE>
49 static bool value(Particle<T,PARTICLETYPE>& particle){
50 return access::isValid( particle );
51 }
52 //Properties
53 static constexpr bool dynamic=true;
54};
55
57 template<typename T, typename PARTICLETYPE>
58 static bool value(Particle<T,PARTICLETYPE>& particle){
59 return !access::isValid( particle );
60 }
61 //Properties
62 static constexpr bool dynamic=true;
63};
64
66 template<typename T, typename PARTICLETYPE>
67 static bool value(Particle<T,PARTICLETYPE>& particle, int globiC){
68 using namespace descriptors;
69 bool valid = access::isValid( particle );
70 bool hasCentre = true;
71 if constexpr ( PARTICLETYPE::template providesNested<PARALLELIZATION,IC>() ) {
72 hasCentre = (particle.template getField<PARALLELIZATION,IC>() == globiC);
73 }
74 return (valid && hasCentre);
75 }
76 //Properties
77 static constexpr bool dynamic=true;
78};
79
81 template<typename T, typename PARTICLETYPE>
82 static bool value(Particle<T,PARTICLETYPE>& particle, int globiC){
83 using namespace descriptors;
84 bool valid = access::isValid( particle );
85 bool hasCentre = true;
86 if constexpr ( PARTICLETYPE::template providesNested<PARALLELIZATION,IC>() ) {
87 hasCentre = (particle.template getField<PARALLELIZATION,IC>() == globiC);
88 }
89 return (valid && !hasCentre);
90 }
91 //Properties
92 static constexpr bool dynamic=true;
93};
94
95//Active particles (implies valid particle)
97 template<typename T, typename PARTICLETYPE>
98 static bool value(Particle<T,PARTICLETYPE>& particle){
99 using namespace descriptors;
100 bool active = access::isActive( particle );
101 bool valid = access::isValid( particle );
102 return (active && valid);
103 }
104 //Properties
105 static constexpr bool dynamic=true;
106};
107
108//Inactive particles (implies valid particle)
110 template<typename T, typename PARTICLETYPE>
111 static bool value(Particle<T,PARTICLETYPE>& particle){
112 using namespace descriptors;
113 bool active = access::isActive( particle );
114 bool valid = access::isValid( particle );
115 return (!active && valid);
116 }
117 //Properties
118 static constexpr bool dynamic=true;
119};
120
121//Active particle centres (implies valid particle)
123 template<typename T, typename PARTICLETYPE>
124 static bool value(Particle<T,PARTICLETYPE>& particle, int globiC){
125 using namespace descriptors;
126 bool active = access::isActive( particle );
127 bool valid = access::isValid( particle );
128 bool hasCentre = true;
129 if constexpr ( PARTICLETYPE::template providesNested<PARALLELIZATION,IC>() ) {
130 hasCentre = (particle.template getField<PARALLELIZATION,IC>() == globiC);
131 }
132 return (active && valid && hasCentre);
133 }
134 //Properties
135 static constexpr bool dynamic=true;
136};
137
138template<std::size_t selectedID>
140 template<typename T, typename PARTICLETYPE>
141 static bool value(Particle<T,PARTICLETYPE>& particle){
142 using namespace descriptors;
143 bool match = false;
144 if constexpr ( PARTICLETYPE::template providesNested<PARALLELIZATION,ID>() ) {
145 match = (particle.template getField<PARALLELIZATION,ID>() == selectedID);
146 } else {
147 match = (particle.getId() == selectedID);
148 }
149 return match;
150 }
151 //Properties
152 static constexpr bool dynamic=true;
153};
154
155template<std::size_t selectedID>
157 template<typename T, typename PARTICLETYPE>
158 static bool value(Particle<T,PARTICLETYPE>& particle){
159 using namespace descriptors;
160 bool valid = access::isValid( particle );
161 bool match = false;
162 if constexpr ( PARTICLETYPE::template providesNested<PARALLELIZATION>() ) {
163 static_assert(PARTICLETYPE::template providesNested<PARALLELIZATION,ID>(), "Field PARALLELIZATION:ID has to be provided");
164 match = (particle.template getField<PARALLELIZATION,ID>() == selectedID);
165 } else {
166 match = (particle.getId() == selectedID);
167 }
168 return (valid && match);
169 }
170 //Properties
171 static constexpr bool dynamic=true;
172};
173
174} //namespace conditions
175
176} //namespace particles
177
178} //namespace olb
179
180
181#endif
std::size_t getId() const
Return memory ID of the currently represented particle.
Definition particle.hh:67
bool isActive(Particle< T, PARTICLETYPE > particle)
bool isValid(Particle< T, PARTICLETYPE > particle)
Top level namespace for all of OpenLB.
static bool value(Particle< T, PARTICLETYPE > &particle, int globiC)
static bool value(Particle< T, PARTICLETYPE > &particle)
static bool value(Particle< T, PARTICLETYPE > &particle)
static bool value(Particle< T, PARTICLETYPE > &particle)
static bool value(Particle< T, PARTICLETYPE > &particle)
static bool value(Particle< T, PARTICLETYPE > &particle, int globiC)
static bool value(Particle< T, PARTICLETYPE > &particle)
static bool value(Particle< T, PARTICLETYPE > &particle, int globiC)
static bool value(Particle< T, PARTICLETYPE > &particle)