OpenLB 1.7
Loading...
Searching...
No Matches
particleContact.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2021 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_CONTACT_HH
25#define PARTICLE_CONTACT_HH
26
27#include "particleContact.h"
29
30namespace olb {
31namespace particles {
32namespace contact {
33
34template <typename T, unsigned D, bool CONVEX>
35ParticleContactArbitraryFromOverlapVolume<
36 T, D, CONVEX>::ParticleContactArbitraryFromOverlapVolume()
38 std::array<std::size_t, 2>())
39{}
40
41template <typename T, unsigned D, bool CONVEX>
44 const std::array<std::size_t, 2>& particleIDs)
45 : ids(sortParticleIDs(particleIDs))
46{
48}
49
50template <typename T, unsigned D, bool CONVEX>
54{
55 min = pc.getMin();
56 max = pc.getMax();
57 ids = pc.getIDs();
58 particlePositions = pc.getParticlePositions();
59 particlePositionUpdated[0] = pc.isParticlePositionUpdated();
60 dampingFactor[0] = pc.getDampingFactor();
61 newContact[0] = pc.isNew();
62 responsibleRank[0] = pc.getResponsibleRank();
63}
64
65template <typename T, unsigned D, bool CONVEX>
69{
70 min = std::move(pc.min);
71 max = std::move(pc.max);
72 ids = std::move(pc.ids);
73 particlePositions = std::move(pc.particlePositions);
74 particlePositionUpdated = std::move(pc.particlePositionUpdated);
75 dampingFactor = std::move(pc.dampingFactor);
76 newContact = std::move(pc.newContact);
77 responsibleRank = std::move(pc.responsibleRank);
78}
79
80template <typename T, unsigned D, bool CONVEX>
81constexpr const std::array<std::size_t, 2>&
86
87template <typename T, unsigned D, bool CONVEX>
88constexpr const std::array<PhysR<T, D>, 2>&
94
95template <typename T, unsigned D, bool CONVEX>
96constexpr void
98 const std::array<PhysR<T, D>, 2>& positions)
99{
100 particlePositions = positions;
101 particlePositionUpdated[0] = true;
102}
103
104template <typename T, unsigned D, bool CONVEX>
105constexpr const PhysR<T, D>&
107 const std::size_t& id) const
108{
109 if (id == ids[0]) {
110 return particlePositions[0];
111 }
112 return particlePositions[1];
113}
114
115template <typename T, unsigned D, bool CONVEX>
116constexpr void
118 const PhysR<T, D>& position, const std::size_t& id)
119{
120 particlePositions[id] = position;
121 particlePositionUpdated[0] = true;
122}
123
124template <typename T, unsigned D, bool CONVEX>
125constexpr void
127 const int& rank)
128{
129 responsibleRank[0] = rank;
130}
131
132template <typename T, unsigned D, bool CONVEX>
133constexpr const int&
135 const
136{
137 return responsibleRank[0];
138}
139
140template <typename T, unsigned D, bool CONVEX>
141constexpr const PhysR<T, D>&
146
147template <typename T, unsigned D, bool CONVEX>
148constexpr const PhysR<T, D>&
153
154template <typename T, unsigned D, bool CONVEX>
155constexpr const T
157 const
158{
159 return dampingFactor[0];
160}
161
162template <typename T, unsigned D, bool CONVEX>
163constexpr void
165 const T newDampingFactor)
166{
167 dampingFactor[0] = newDampingFactor;
168}
169
170template <typename T, unsigned D, bool CONVEX>
173 const T coefficientOfRestitution,
174 const T initialRelativeVelocityMagnitude)
175{
177 coefficientOfRestitution, initialRelativeVelocityMagnitude));
178}
179
180template <typename T, unsigned D, bool CONVEX>
181constexpr void
183{
184 for (unsigned iD = 0; iD < D; ++iD) {
185 min[iD] = std::numeric_limits<olb::BaseType<T>>::max();
186 max[iD] = -std::numeric_limits<olb::BaseType<T>>::max();
187 }
188 particlePositionUpdated[0] = false;
189}
190
191template <typename T, unsigned D, bool CONVEX>
192constexpr void
194 const PhysR<T, D>& positionInsideTheContact)
195{
196 particles::contact::updateMinMax(this->min, this->max,
197 positionInsideTheContact);
198}
199
200template <typename T, unsigned D, bool CONVEX>
201constexpr void
203 const Vector<T, D>& increaseBy)
204{
205 this->max += increaseBy;
206 this->min -= increaseBy;
207}
208
209template <typename T, unsigned D, bool CONVEX>
210constexpr void
213{
216 ids)) {
217 newContact[0] = newContact[0] && pc.isNew();
218
219 // Determine bounding box of combined overlap area
220 for (unsigned iD = 0; iD < D; ++iD) {
221 min[iD] = util::min(min[iD], pc.getMin()[iD]);
222 max[iD] = util::max(max[iD], pc.getMax()[iD]);
223 }
224 // The damping factors should be either the same or one is -1 and the other has the correct value which is > 0
225 dampingFactor[0] = util::max(dampingFactor[0], pc.getDampingFactor());
226 responsibleRank[0] = util::min(responsibleRank[0], pc.getResponsibleRank());
227 particlePositionUpdated[0] =
228 particlePositionUpdated[0] || pc.isParticlePositionUpdated();
229 if (!particlePositionUpdated[0] && pc.isParticlePositionUpdated()) {
230 particlePositions = pc.getParticlePositions();
231 }
232
233 // Ignore second contact by resetting it
234 pc.resetMinMax();
235 }
236}
237
238template <typename T, unsigned D, bool CONVEX>
239constexpr bool
241{
242 for (unsigned iD = 0; iD < D; ++iD) {
243 if (min[iD] > max[iD]) {
244 return true;
245 }
246 }
247 return false;
248}
249
250template <typename T, unsigned D, bool CONVEX>
251constexpr bool
253{
254 return newContact[0];
255}
256
257template <typename T, unsigned D, bool CONVEX>
259 const bool newContact)
260{
261 this->newContact[0] = newContact;
262}
263
264template <typename T, unsigned D, bool CONVEX>
266 T, D, CONVEX>::isParticlePositionUpdated() const
267{
268 return particlePositionUpdated[0];
269}
270
271template <typename T, unsigned D, bool CONVEX>
273 T, D, CONVEX>::setParticlePositionUpdated(bool updated)
274{
275 particlePositionUpdated[0] = updated;
276}
277
278template <typename T, unsigned D, bool CONVEX>
282{
283 min = pc.getMin();
284 max = pc.getMax();
285 ids = pc.getIDs();
286 particlePositions = pc.getParticlePositions();
287 particlePositionUpdated[0] = pc.isParticlePositionUpdated();
288 dampingFactor[0] = pc.getDampingFactor();
289 newContact[0] = pc.isNew();
290 responsibleRank[0] = pc.getResponsibleRank();
291
292 return *this;
293}
294
295template <typename T, unsigned D, bool CONVEX>
299{
300 min = std::move(pc.min);
301 max = std::move(pc.max);
302 ids = std::move(pc.ids);
303 particlePositions = std::move(pc.particlePositions);
304 particlePositionUpdated = std::move(pc.particlePositionUpdated);
305 dampingFactor = std::move(pc.dampingFactor);
306 newContact = std::move(pc.newContact);
307 responsibleRank = std::move(pc.responsibleRank);
308
309 return *this;
310}
311
312template <typename T, unsigned D, bool CONVEX>
313template <typename F>
315 T, D, CONVEX>::processWithCommunicatables(F f)
316{
317 //Create communicatables
318 auto communicatablePositions = ConcreteCommunicatable(particlePositions);
319 auto communicatableMin = ConcreteCommunicatable(min);
320 auto communicatableMax = ConcreteCommunicatable(max);
321 auto communicatableIDs = ConcreteCommunicatable(ids);
322 auto communicatableDamping = ConcreteCommunicatable(dampingFactor);
323 auto communicatableParticlePositionUpdated =
324 ConcreteCommunicatable(particlePositionUpdated);
325 auto communicatableIsNew = ConcreteCommunicatable(newContact);
326 auto communicatableRank = ConcreteCommunicatable(responsibleRank);
327
328 return f(communicatablePositions, communicatableMin, communicatableMax,
329 communicatableIDs, communicatableDamping,
330 communicatableParticlePositionUpdated, communicatableIsNew,
331 communicatableRank);
332}
333
334template <typename T, unsigned D, bool CONVEX>
336 std::uint8_t* buffer)
337{
338 return processWithCommunicatables(
339 [&](auto& communicatablePositions, auto& communicatableMin,
340 auto& communicatableMax, auto& communicatableIDs,
341 auto& communicatableDamping,
342 auto& communicatableParticlePositionUpdated,
343 auto& communicatableIsNew, auto& communicatableRank) {
344 std::size_t serialIdx =
345 communicatablePositions.serialize(this->indicesPart, buffer);
346 serialIdx +=
347 communicatableMin.serialize(this->indicesDim, &buffer[serialIdx]);
348 serialIdx +=
349 communicatableMax.serialize(this->indicesDim, &buffer[serialIdx]);
350 serialIdx +=
351 communicatableIDs.serialize(this->indicesPart, &buffer[serialIdx]);
352 serialIdx += communicatableDamping.serialize(this->indicesSingle,
353 &buffer[serialIdx]);
354 serialIdx += communicatableParticlePositionUpdated.serialize(
355 this->indicesSingle, &buffer[serialIdx]);
356 serialIdx += communicatableIsNew.serialize(this->indicesSingle,
357 &buffer[serialIdx]);
358 serialIdx += communicatableRank.serialize(this->indicesSingle,
359 &buffer[serialIdx]);
360
361 return serialIdx;
362 });
363}
364
365template <typename T, unsigned D, bool CONVEX>
366std::size_t
368 std::uint8_t* buffer)
369{
370 return processWithCommunicatables(
371 [&](auto& communicatablePositions, auto& communicatableMin,
372 auto& communicatableMax, auto& communicatableIDs,
373 auto& communicatableDamping,
374 auto& communicatableParticlePositionUpdated,
375 auto& communicatableIsNew, auto& communicatableRank) {
376 std::size_t serialIdx =
377 communicatablePositions.deserialize(this->indicesPart, buffer);
378 serialIdx +=
379 communicatableMin.deserialize(this->indicesDim, &buffer[serialIdx]);
380 serialIdx +=
381 communicatableMax.deserialize(this->indicesDim, &buffer[serialIdx]);
382 serialIdx += communicatableIDs.deserialize(this->indicesPart,
383 &buffer[serialIdx]);
384 serialIdx += communicatableDamping.deserialize(this->indicesSingle,
385 &buffer[serialIdx]);
386 serialIdx += communicatableParticlePositionUpdated.deserialize(
387 this->indicesSingle, &buffer[serialIdx]);
388 serialIdx += communicatableIsNew.deserialize(this->indicesSingle,
389 &buffer[serialIdx]);
390 serialIdx += communicatableRank.deserialize(this->indicesSingle,
391 &buffer[serialIdx]);
392
393 return serialIdx;
394 });
395}
396
397template <typename T, unsigned D, bool CONVEX>
399{
400 OstreamManager clout(std::cout, "ParticleContact");
401 clout.setMultiOutput(true);
402 int rank = singleton::mpi().getRank();
403 if (rank == responsibleRank[0]) {
404 clout << "Min=" << this->min << ", Max=" << this->max << std::endl;
405 clout << "IDs=" << this->ids << ", DampingFactor=" << dampingFactor[0]
406 << std::endl;
407 clout << "Positions=" << particlePositions << std::endl;
408 }
409 clout.setMultiOutput(false);
410}
411
412} // namespace contact
413} // namespace particles
414} // namespace olb
415#endif
class for marking output with some text
void setMultiOutput(bool b)
enable message output for all MPI processes, disabled by default
Plain old scalar vector.
Definition vector.h:47
int getRank() const
Returns the process ID.
std::array< std::size_t, 2 > sortParticleIDs(const std::array< std::size_t, 2 > &ids)
bool particleContactConsistsOfIDs(PARTICLECONTACTTYPE &particleContact, const std::array< size_t, 2 > &ids)
void updateMinMax(PhysR< T, D > &min, PhysR< T, D > &max, const PhysR< T, D > &pos)
constexpr T evalDampingFactor(const T coefficientOfRestitution, const T initialRelativeVelocityMagnitude)
Calculates the damping factor according to Carvalho & Martins (2019) (10.1016/j.mechmachtheory....
MpiManager & mpi()
cpu::simd::Pack< T > min(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
Definition pack.h:124
cpu::simd::Pack< T > max(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
Definition pack.h:130
Top level namespace for all of OpenLB.
An object holding data for a contact which is described analog to Nassauer and Kuna (2013)
constexpr void setDampingFactor(const T dampingFactor)
Set damping factor for contact.
constexpr const std::array< std::size_t, 2 > & getIDs() const
Read access to particle IDs.
constexpr void increaseMinMax(const Vector< T, D > &increaseBy)
Increase bounding box size.
constexpr const PhysR< T, D > & getParticlePosition(const std::size_t &id) const
Return particle position.
constexpr void setParticlePositions(const std::array< PhysR< T, D >, 2 > &positions)
Set particle positions.
constexpr bool isNew() const
Returns if the contact is a new contact.
constexpr void updateMinMax(const PhysR< T, D > &positionInsideTheContact)
Update min and max with given position inside the contact.
constexpr const int & getResponsibleRank() const
Read access to the responsible rank.
constexpr void setDampingFactorFromInitialVelocity(const T coefficientOfRestitution, const T initialRelativeVelocityMagnitude)
Set damping factor from the magnitude of the initial relative impact velocity in direction of contact...
ParticleContactArbitraryFromOverlapVolume< T, D, CONVEX > & operator=(const ParticleContactArbitraryFromOverlapVolume< T, D, CONVEX > &pc)
Copy assignment.
constexpr bool isParticlePositionUpdated() const
Returns if the particle position is up-to-date.
constexpr void setParticlePosition(const PhysR< T, D > &position, const std::size_t &id)
Set position of specific particle.
constexpr const std::array< PhysR< T, D >, 2 > & getParticlePositions() const
Read access to particle positions.
constexpr const PhysR< T, D > & getMax() const
Read access to max.
constexpr bool isEmpty() const
Returns if contact holds data.
std::size_t deserialize(std::uint8_t *buffer)
Deserialize contact data and save in object.
constexpr const PhysR< T, D > & getMin() const
Read access to min.
constexpr void combineWith(ParticleContactArbitraryFromOverlapVolume< T, D, CONVEX > &pc)
Combining two contacts, if the particle ids are the same.
constexpr const T getDampingFactor() const
Read access to damping factor.
constexpr void resetMinMax()
Reset min and max to default values.
std::size_t serialize(std::uint8_t *buffer)
Serialize contact data.
constexpr void setResponsibleRank(const int &rank)
Set processor that is responsible for contact treatment.