OpenLB 1.7
Loading...
Searching...
No Matches
particleSystem.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2021 Nicolas Hafen
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
25#ifndef PARTICLE_SYSTEM_H
26#define PARTICLE_SYSTEM_H
27
28
29namespace olb {
30
31namespace particles {
32
33
34template<typename T, typename PARTICLETYPE>
36private:
39 Container<T,PARTICLETYPE,DATA> _fieldGroupsContainer;
41 std::vector<std::shared_ptr<dynamics::ParticleDynamics<T,PARTICLETYPE>>> _dynamicsVector;
42 //Additional storage for multiple complex data types linked to particle (extendable by user...)
44 std::vector<std::unique_ptr<SmoothIndicatorF2D<T,T,true>>>,
45 std::vector<std::unique_ptr<SmoothIndicatorF3D<T,T,true>>>
46 >;
47 typename associatedTypes::template decompose_into<std::tuple> _associatedData; //Storage for complex types
48 //Serial size of DATA
49 const std::size_t _serialSize;
50
52 struct Iterator {
53 //Iterator tags
54 using iterator_category = std::random_access_iterator_tag;
55 using pType = Particle<T,PARTICLETYPE>;
56 //Constructor
57 Iterator(ParticleSystem<T,PARTICLETYPE>* pSystemPtr, std::size_t iParticle)
58 : _pSystemPtr(pSystemPtr), _iParticle(iParticle) {}
59 //Reference operator
60 pType operator*() { return _pSystemPtr->get(_iParticle); } //is called for "auto p : particleSystem"
61 // Prefix increment
62 Iterator& operator++() { _iParticle++; return *this; }
63 // Postfix increment
64 Iterator operator++(int) { Iterator tmp = *this; ++(*this); return tmp; }
65 //Comparison operators
66 friend bool operator== (const Iterator& a, const Iterator& b) { return a._iParticle == b._iParticle; };
67 friend bool operator!= (const Iterator& a, const Iterator& b) { return a._iParticle != b._iParticle; };
68 private:
70 std::size_t _iParticle;
71 };
72
73public:
74 static_assert(PARTICLETYPE::d == 2 || PARTICLETYPE::d == 3, "Only D=2 and D=3 are supported");
75
78
80 ParticleSystem( std::size_t count );
81
83 ParticleSystem( std::size_t count,
84 typename associatedTypes::template decompose_into<std::tuple> associatedData );
85
86 //Iterator instantiation
87 Iterator begin() { return Iterator(this,0); }
88 Iterator end() { return Iterator(this,size()); }
89
91 template<typename PCONDITION=conditions::all_particles>
92 constexpr std::size_t size();
93
95 template<typename PCONDITION=conditions::all_particles>
96 constexpr std::size_t size(int globiC);
97
99 template<bool boundsCheck=false>
101
103 void addDynamics(std::shared_ptr<dynamics::ParticleDynamics<T,PARTICLETYPE>>& dynamicsSPtr );
104
106 template <typename DYNAMICS, typename ...Args>
107 void defineDynamics(Args&& ...args);
108
110 void extend();
111
113 void swapParticles(std::size_t iP, std::size_t jP);
114
116 void process( std::size_t p0, std::size_t p1, T timeStepSize, unsigned iDyn=0 );
117
119 void process(T timeStepSize, unsigned iDyn=0);
120
122 void update();
123
125 auto& get();
126
128 std::vector<std::shared_ptr<dynamics::ParticleDynamics<T,PARTICLETYPE>>>& getDynamicsVector();
129
131 template<bool boundsCheck=false>
132 Particle<T,PARTICLETYPE> get(std::size_t iParticle);
133
135 Particle<T,PARTICLETYPE> operator[](std::size_t iParticle);
136
138 template <typename GROUP, typename FIELD>
139 auto& getFieldD();
140
142 template <typename GROUP, typename FIELD>
143 auto getFieldPointer( std::size_t iParticle );
144
146 template<typename TYPE>
147 auto& getAssociatedData();
148
150 std::size_t getSerialSize() const;
151
153 void print();
154
156 void checkForErrors();
157};
158
159
160} //namespace particles
161
162} //namespace olb
163
164
165#endif
Container is a std::vector inspired data wrapper that allows for simple content manipulation of its o...
Definition container.h:44
Storage for dynamic field groups (Prototype for ParticleSystem)
void process(std::size_t p0, std::size_t p1, T timeStepSize, unsigned iDyn=0)
Upate/process particle quantities on a subset (mostly local equivalent to collide)
auto & get()
Expose container.
Particle< T, PARTICLETYPE > operator[](std::size_t iParticle)
Create and return particle with operator[].
void swapParticles(std::size_t iP, std::size_t jP)
Swap particles by index.
std::vector< std::shared_ptr< dynamics::ParticleDynamics< T, PARTICLETYPE > > > & getDynamicsVector()
Expose dynamics vector.
dynamics::ParticleDynamics< T, PARTICLETYPE > * getDynamics(unsigned iDyn=0)
Get specific dynamics (optional boundsCheck via .at())
void checkForErrors()
Check for erroes.
void update()
Update particles (equivalent to stream())
constexpr std::size_t size()
Size of ParticleSystem.
void print()
Print relevant infos.
void defineDynamics(Args &&...args)
Define dynamics (factory method)
auto & getAssociatedData()
Get associated data by specifying data type.
void extend()
Extend particle system by one particle.
void addDynamics(std::shared_ptr< dynamics::ParticleDynamics< T, PARTICLETYPE > > &dynamicsSPtr)
Add dynamics (from shared_pointer of dynamics)
ParticleSystem()
Default constructor.
auto getFieldPointer(std::size_t iParticle)
Get FieldPointer by GROUP (or base of GROUP) and FIELD for specific iParticle.
std::size_t getSerialSize() const
Get serial size of dynamic fields group.
auto & getFieldD()
Get whole Field by GROUP (or base of GROUP) and FIELD.
Top level namespace for all of OpenLB.
Plain wrapper for list of types.
Definition meta.h:276