OpenLB 1.7
Loading...
Searching...
No Matches
particle.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2021 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#ifndef PARTICLE_HH
25#define PARTICLE_HH
26
27
30
31namespace olb {
32
33namespace particles{
34
35
36template <typename T, typename PARTICLETYPE>
39 std::vector<std::shared_ptr<dynamics::ParticleDynamics<T,PARTICLETYPE>>>& dynamicsVector,
40 std::size_t iParticle )
41 : _dynamicFieldGroupsD( dynamicFieldGroupsD ),
42 _dynamicsVector( dynamicsVector ),
43 _iParticle( iParticle)
44{}
45
46template <typename T, typename PARTICLETYPE>
48{
49 particles::dynamics::initializeParticle<T, PARTICLETYPE>( _dynamicFieldGroupsD, _iParticle);
50}
51
52template <typename T, typename PARTICLETYPE>
53template<bool multiOutput>
54void Particle<T,PARTICLETYPE>::print(std::size_t iParticle)
55{
56 particles::io::printGenericParticleInfo<T, PARTICLETYPE,multiOutput>( _dynamicFieldGroupsD, iParticle);
57}
58
59template <typename T, typename PARTICLETYPE>
60template<bool multiOutput>
62{
63 print<multiOutput>(_iParticle);
64}
65
66template <typename T, typename PARTICLETYPE>
68{
69 return _iParticle;
70}
71
72template <typename T, typename PARTICLETYPE>
73void Particle<T,PARTICLETYPE>::setId(std::size_t iParticle)
74{
75 _iParticle = iParticle;
76}
77
78template <typename T, typename PARTICLETYPE>
80{
81 ++_iParticle;
82}
83
84template<typename T, typename PARTICLETYPE>
86 std::shared_ptr<dynamics::ParticleDynamics<T,PARTICLETYPE>>& dynamicsSPtr )
87{
88 _dynamicsVector.push_back( dynamicsSPtr );
89}
90
91template<typename T, typename PARTICLETYPE>
92template <typename DYNAMICS, typename ...Args>
94 _dynamicsVector.push_back( std::make_shared<DYNAMICS>(std::forward<Args>(args)...) );
95}
96
97template<typename T, typename PARTICLETYPE>
98template<bool boundsCheck>
100 unsigned iDyn)
101{
102 if constexpr(boundsCheck){
103 return _dynamicsVector.at(iDyn).get();
104 } else {
105 return _dynamicsVector[iDyn].get();
106 }
107}
108
109template<typename T, typename PARTICLETYPE>
110void Particle<T,PARTICLETYPE>::process(T timeStepSize, unsigned short iDyn)
111{
113 getDynamics(iDyn)->process(*this, timeStepSize);
114 }
115}
116
118
119
120template <typename T, typename PARTICLETYPE>
121template <typename GROUP, typename FIELD>
122std::enable_if_t<(
123 PARTICLETYPE::template size<
124 typename PARTICLETYPE::template derivedField<GROUP>::template derivedField<FIELD>
125 >() > 1),
126 FieldD<T,PARTICLETYPE,
127 typename PARTICLETYPE::template derivedField<GROUP>::template derivedField<FIELD>>
128>
130{
131 using GROUP_EVAL = typename PARTICLETYPE
132 ::template derivedField<GROUP>;
133 using FIELD_EVAL = typename GROUP_EVAL
134 ::template derivedField<FIELD>;
135 return _dynamicFieldGroupsD.template get<GROUP_EVAL>()
136 .template get<FIELD_EVAL>()
137 .getRowPointer(_iParticle);
138}
139
140
141template <typename T, typename PARTICLETYPE>
142template <typename GROUP, typename FIELD>
143std::enable_if_t<(
144 PARTICLETYPE::template size<
145 typename PARTICLETYPE::template derivedField<GROUP>::template derivedField<FIELD>
146 >() == 1),
147 typename PARTICLETYPE::template derivedField<GROUP>::template derivedField<FIELD>::template value_type<T>>
149{
150 using GROUP_EVAL = typename PARTICLETYPE
151 ::template derivedField<GROUP>;
152 using FIELD_EVAL = typename GROUP_EVAL
153 ::template derivedField<FIELD>;
154 return _dynamicFieldGroupsD.template get<GROUP_EVAL>()
155 .template get<FIELD_EVAL>()
156 .getRowPointer(_iParticle)[0];
157}
158
159template <typename T, typename PARTICLETYPE>
160template <typename GROUP, typename FIELD>
161std::enable_if_t<(PARTICLETYPE::template size<
162 typename PARTICLETYPE::template derivedField<GROUP>::template derivedField<FIELD>
163 >() > 1), void>
165 const FieldD<T,PARTICLETYPE,
166 typename PARTICLETYPE::template derivedField<GROUP>
167 ::template derivedField<FIELD>>& v )
168{
169 using GROUP_EVAL = typename PARTICLETYPE
170 ::template derivedField<GROUP>;
171 using FIELD_EVAL = typename GROUP_EVAL
172 ::template derivedField<FIELD>;
173 //Analogous to BlockStaticFieldsD
174 auto& field = _dynamicFieldGroupsD.template get<GROUP_EVAL>()
175 .template get<FIELD_EVAL>();
176 for (unsigned iDim=0; iDim < PARTICLETYPE::template size<FIELD_EVAL>(); ++iDim) {
177 field[iDim][_iParticle] = v[iDim];
178 }
179}
180
181template <typename T, typename PARTICLETYPE>
182template <typename GROUP, typename FIELD>
183std::enable_if_t<(PARTICLETYPE::template size<
184 typename PARTICLETYPE::template derivedField<GROUP>::template derivedField<FIELD>
185 >() == 1), void>
187 typename PARTICLETYPE::template derivedField<GROUP>
188 ::template derivedField<FIELD>
189 ::template value_type<T> value)
190{
191 using GROUP_EVAL = typename PARTICLETYPE
192 ::template derivedField<GROUP>;
193 using FIELD_EVAL = typename GROUP_EVAL
194 ::template derivedField<FIELD>;
195 _dynamicFieldGroupsD.template get<GROUP_EVAL>()
196 .template get<FIELD_EVAL>()
197 .getRowPointer(_iParticle)[0] = value;
198}
199
200} //namespace particles
201
202} //namespace olb
203
204#endif
Storage for dynamic field groups (Prototype for ParticleSystem)
Plain old scalar vector.
Definition vector.h:47
void init()
Initialize.
Definition particle.hh:47
std::enable_if_t<(PARTICLETYPE::template size< typename PARTICLETYPE::template derivedField< GROUP >::template derivedField< FIELD > >() > 1), void > setField(const FieldD< T, PARTICLETYPE, typename PARTICLETYPE::template derivedField< GROUP > ::template derivedField< FIELD > > &v)
Set descriptor-declared FIELD.
Definition particle.hh:164
std::size_t getId() const
Return memory ID of the currently represented particle.
Definition particle.hh:67
void addDynamics(std::shared_ptr< dynamics::ParticleDynamics< T, PARTICLETYPE > > &dynamicsSPtr)
Add dynamics.
Definition particle.hh:85
void advanceId()
Jump to next particle in linearization sequence.
Definition particle.hh:79
dynamics::ParticleDynamics< T, PARTICLETYPE > * getDynamics(unsigned iDyn=0)
Get a pointer to specific dynamics.
Definition particle.hh:99
void defineDynamics(Args &&...args)
Define dynamics (factory method)
Definition particle.hh:93
Particle(DATA &dynamicFieldGroupsD, std::vector< std::shared_ptr< dynamics::ParticleDynamics< T, PARTICLETYPE > > > &dynamicsVector, std::size_t iParticle)
Definition particle.hh:37
std::enable_if_t<(PARTICLETYPE::template size< typename PARTICLETYPE::template derivedField< GROUP >::template derivedField< FIELD > >() > 1), FieldD< T, PARTICLETYPE, typename PARTICLETYPE::template derivedField< GROUP >::template derivedField< FIELD > > getField()
Return copy of descriptor-declared FIELD as a vector.
void process(T timeStepSize, unsigned short iDyn=0)
Apply processing to the particle according to dynamics at iDyn.
Definition particle.hh:110
void setId(std::size_t iParticle)
Jump to arbitrary particle memory ID.
Definition particle.hh:73
bool isMotionComputationEnabled(Particle< T, PARTICLETYPE > &particle)
Check if motion is enabled.
Top level namespace for all of OpenLB.
virtual void process(Particle< T, PARTICLETYPE > &particle, T timeStepSize)=0
Implementation of the processing step.