OpenLB 1.7
Loading...
Searching...
No Matches
particleCreatorHelperFunctions.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2021 Nicolas Hafen, Jan E. Marquardt, 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_CREATOR_HELPER_FUNCTIONS_H
25#define PARTICLE_CREATOR_HELPER_FUNCTIONS_H
26
27namespace olb {
28
29namespace particles {
30
31namespace creators {
32
34
35template<typename PARTICLETYPE, bool ROTATION_IS_OPTIONAL=false>
37{
38 using namespace descriptors;
39
40 static_assert(ROTATION_IS_OPTIONAL || PARTICLETYPE::template providesNested<SURFACE,ROT_MATRIX>(),
41 "A rotation matrix is necessary but not provided.");
42}
43
45template<typename T, typename PARTICLETYPE, bool ROTATION_IS_OPTIONAL=false>
47 ParticleSystem<T,PARTICLETYPE>& particleSystem,
48 std::size_t idxParticle, std::size_t idxSurface,
49 const Vector<T,PARTICLETYPE::d>& position,
50 T density,
52 const Vector<T,PARTICLETYPE::d>& velocity)
53{
54 particles::creators::checkForErrors<PARTICLETYPE,ROTATION_IS_OPTIONAL>();
55
56 using namespace descriptors;
57 constexpr unsigned D = PARTICLETYPE::d;
58 typedef SmoothIndicatorF<T,T,D,true> SIndicatorBaseType;
59
60 //Retrieve smart pointer from particleSystem
61 auto& vectorOfIndicators = particleSystem.template getAssociatedData<
62 std::vector<std::unique_ptr<SIndicatorBaseType>>>();
63 auto sIndicatorPtr = vectorOfIndicators.at( idxSurface ).get();
64
65 //Initialize fields (Seems to be necessary for clang-1000.10.44.4 but not for gcc)
66 dynamics::initializeParticle<T,PARTICLETYPE>(particleSystem.get().data(), idxParticle);
67
68 //Calculate moment of inertia and mass
70 if constexpr(D==3) {
71 for (unsigned iD=0; iD<D; ++iD) {
72 momentOfInertia[iD] = sIndicatorPtr->calcMofiAndMass(density)[iD];
73 }
74 }
75 else {
76 momentOfInertia[0] = sIndicatorPtr->calcMofiAndMass(density)[0];
77 }
78
79 //Set values
80 auto particle = particleSystem.get( idxParticle );
81 particle.template setField<GENERAL,POSITION>( position );
82 particle.template setField<SURFACE,SINDICATOR>( sIndicatorPtr );
83 access::setDensity(particle, density);
84 particle.template setField<MOBILITY,VELOCITY>( velocity );
85 particle.template setField<PHYSPROPERTIES,MOFI>( utilities::dimensions::convert<D>::serialize_rotation(momentOfInertia) );
86
87 auto angle = util::degreeToRadian(angleInDegree);
88 particle.template setField<SURFACE,ANGLE>( utilities::dimensions::convert<D>::serialize_rotation(angle) );
89 if constexpr ( PARTICLETYPE::template providesNested<SURFACE,ROT_MATRIX>() ) {
90 const Vector<T,utilities::dimensions::convert<D>::matrix> rotationMatrix = util::calculateRotationMatrix<T,D>(
92 particle.template setField<SURFACE,ROT_MATRIX>( rotationMatrix );
93 }
94
96 return particle;
97}
98
100template<typename T, typename PARTICLETYPE>
102 ParticleSystem<T,PARTICLETYPE>& particleSystem, std::size_t idxSurface,
103 const Vector<T,PARTICLETYPE::d>& position, T density=0.,
106{
107 //Retrieve new index
108 std::size_t idxParticle = particleSystem.size();
109
110 //Initialize particle address
111 particleSystem.extend();
112
114 setResolvedObject( particleSystem, idxParticle, idxSurface, position, density, angleInDegree, velocity );
115
117 return particleSystem.get(idxParticle);
118}
119
120
122
124template<typename T, typename PARTICLETYPE>
126 ParticleSystem<T,PARTICLETYPE>& particleSystem,
127 std::size_t idxParticle,
128 const Vector<T,PARTICLETYPE::d>& position,
129 T radius, T density,
130 const Vector<T,PARTICLETYPE::d>& velocity,
131 T shapeFactor = T{1})
132{
133 using namespace descriptors;
134 using namespace access;
135 constexpr unsigned D = PARTICLETYPE::d;
137
138 //Initialize fields (Seems to be necessary for clang-1000.10.44.4 but not for gcc)
139 particles::dynamics::initializeParticle<T,PARTICLETYPE>(
140 particleSystem.get().data(), idxParticle);
141
142 //Set values
143 auto particle = particleSystem.get( idxParticle );
144 particle.template setField<GENERAL,POSITION>( position );
145 particle.template setField<MOBILITY,VELOCITY>( velocity );
146 particle.template setField<PHYSPROPERTIES,RADIUS>( radius );
147 access::setDensity(particle, density, shapeFactor);
148
149 //Calculate moment of inertia and mass
150 Vector<T,Drot> momentOfInertia;
151 T mass = access::getMass(particle, shapeFactor);
152
153 //Calculate moment of inertia and mass
154 if constexpr(D==3) {
155 momentOfInertia = Vector<T,Drot>(2./5.*mass*radius*radius);
156 } else {
157 momentOfInertia[0] = 0.5*mass*radius*radius;
158 }
159
160 particle.template setField<PHYSPROPERTIES,MOFI>( utilities::dimensions::convert<D>::serialize_rotation(momentOfInertia) );
161
163 return particle;
164}
165
167template<typename T, typename PARTICLETYPE>
169 ParticleSystem<T,PARTICLETYPE>& particleSystem,
170 const Vector<T,PARTICLETYPE::d>& position, T radius, T density=0.,
172{
173 //Retrieve new index
174 std::size_t idxParticle = particleSystem.size();
175
176 //Initialize particle address
177 particleSystem.extend();
178
180 setSubgridObject( particleSystem, idxParticle, position, radius, density,velocity );
181
183 return particleSystem.get(idxParticle);
184}
185
186
187
188
189
190} //namespace creators
191
192} //namespace particles
193
194} //namespace olb
195
196#endif
Plain old scalar vector.
Definition vector.h:47
auto & get()
Expose container.
constexpr std::size_t size()
Size of ParticleSystem.
void extend()
Extend particle system by one particle.
void setDensity(Particle< T, PARTICLETYPE > particle, T density, T shapeFactor=T{1})
T getMass(Particle< T, PARTICLETYPE > particle, T shapeFactor=T{1})
ParallelParticleLocator addResolvedObject(SuperParticleSystem< T, PARTICLETYPE > &sParticleSystem, std::size_t idxSurface, const Vector< T, PARTICLETYPE::d > &position, T density=0., const Vector< T, utilities::dimensions::convert< PARTICLETYPE::d >::rotation > &angleInDegree=Vector< T, utilities::dimensions::convert< PARTICLETYPE::d >::rotation >(0.), const Vector< T, PARTICLETYPE::d > &velocity=Vector< T, PARTICLETYPE::d >(0.), const Vector< bool, PARTICLETYPE::d > &periodicity=Vector< T, PARTICLETYPE::d >(false))
Particle< T, PARTICLETYPE > setSubgridObject(ParticleSystem< T, PARTICLETYPE > &particleSystem, std::size_t idxParticle, const Vector< T, PARTICLETYPE::d > &position, T radius, T density, const Vector< T, PARTICLETYPE::d > &velocity, T shapeFactor=T{1})
Set new particle (and return particle object)
void setResolvedObject(ParticleSystem< T, PARTICLETYPE > &particleSystem, std::size_t idxParticle, std::size_t idxSurface, const Vector< T, 2 > &position, T density, T angle, const Vector< T, 2 > &velocity)
Particle< T, PARTICLETYPE > addSubgridObject(ParticleSystem< T, PARTICLETYPE > &particleSystem, const Vector< T, PARTICLETYPE::d > &position, T radius, T density=0., const Vector< T, PARTICLETYPE::d > &velocity=Vector< T, PARTICLETYPE::d >(0.))
Add subgrid object as new particle (and return particle object)
decltype(Vector< decltype(util::sqrt(T())), D >()) degreeToRadian(const Vector< T, D > &angle)
Top level namespace for all of OpenLB.
std::conditional_t< D==2, SmoothIndicatorF2D< T, T, PARTICLE >, SmoothIndicatorF3D< T, T, PARTICLE > > SmoothIndicatorF
Definition aliases.h:278
Converts dimensions by deriving from given cartesian dimension D.