24#ifndef PARTICLE_CONTACT_HH
25#define PARTICLE_CONTACT_HH
34template <
typename T,
unsigned D,
bool CONVEX>
35ParticleContactArbitraryFromOverlapVolume<
36 T, D, CONVEX>::ParticleContactArbitraryFromOverlapVolume()
38 std::array<std::size_t, 2>())
41template <
typename T,
unsigned D,
bool CONVEX>
44 const std::array<std::size_t, 2>& particleIDs)
50template <
typename T,
unsigned D,
bool CONVEX>
61 newContact[0] = pc.
isNew();
65template <
typename T,
unsigned D,
bool CONVEX>
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);
80template <
typename T,
unsigned D,
bool CONVEX>
81constexpr const std::array<std::size_t, 2>&
87template <
typename T,
unsigned D,
bool CONVEX>
88constexpr const std::array<PhysR<T, D>, 2>&
92 return particlePositions;
95template <
typename T,
unsigned D,
bool CONVEX>
100 particlePositions = positions;
101 particlePositionUpdated[0] =
true;
104template <
typename T,
unsigned D,
bool CONVEX>
107 const std::size_t&
id)
const
110 return particlePositions[0];
112 return particlePositions[1];
115template <
typename T,
unsigned D,
bool CONVEX>
118 const PhysR<T, D>& position,
const std::size_t&
id)
120 particlePositions[id] = position;
121 particlePositionUpdated[0] =
true;
124template <
typename T,
unsigned D,
bool CONVEX>
129 responsibleRank[0] = rank;
132template <
typename T,
unsigned D,
bool CONVEX>
137 return responsibleRank[0];
140template <
typename T,
unsigned D,
bool CONVEX>
147template <
typename T,
unsigned D,
bool CONVEX>
154template <
typename T,
unsigned D,
bool CONVEX>
159 return dampingFactor[0];
162template <
typename T,
unsigned D,
bool CONVEX>
165 const T newDampingFactor)
167 dampingFactor[0] = newDampingFactor;
170template <
typename T,
unsigned D,
bool CONVEX>
173 const T coefficientOfRestitution,
174 const T initialRelativeVelocityMagnitude)
177 coefficientOfRestitution, initialRelativeVelocityMagnitude));
180template <
typename T,
unsigned D,
bool CONVEX>
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();
188 particlePositionUpdated[0] =
false;
191template <
typename T,
unsigned D,
bool CONVEX>
197 positionInsideTheContact);
200template <
typename T,
unsigned D,
bool CONVEX>
205 this->max += increaseBy;
206 this->min -= increaseBy;
209template <
typename T,
unsigned D,
bool CONVEX>
217 newContact[0] = newContact[0] && pc.
isNew();
220 for (
unsigned iD = 0; iD < D; ++iD) {
227 particlePositionUpdated[0] =
238template <
typename T,
unsigned D,
bool CONVEX>
242 for (
unsigned iD = 0; iD < D; ++iD) {
243 if (min[iD] > max[iD]) {
250template <
typename T,
unsigned D,
bool CONVEX>
254 return newContact[0];
257template <
typename T,
unsigned D,
bool CONVEX>
259 const bool newContact)
261 this->newContact[0] = newContact;
264template <
typename T,
unsigned D,
bool CONVEX>
266 T, D, CONVEX>::isParticlePositionUpdated()
const
268 return particlePositionUpdated[0];
271template <
typename T,
unsigned D,
bool CONVEX>
273 T, D, CONVEX>::setParticlePositionUpdated(
bool updated)
275 particlePositionUpdated[0] = updated;
278template <
typename T,
unsigned D,
bool CONVEX>
289 newContact[0] = pc.
isNew();
295template <
typename T,
unsigned D,
bool CONVEX>
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);
312template <
typename T,
unsigned D,
bool CONVEX>
315 T, D, CONVEX>::processWithCommunicatables(F f)
323 auto communicatableParticlePositionUpdated =
328 return f(communicatablePositions, communicatableMin, communicatableMax,
329 communicatableIDs, communicatableDamping,
330 communicatableParticlePositionUpdated, communicatableIsNew,
334template <
typename T,
unsigned D,
bool CONVEX>
336 std::uint8_t* buffer)
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);
347 communicatableMin.serialize(this->indicesDim, &buffer[serialIdx]);
349 communicatableMax.serialize(this->indicesDim, &buffer[serialIdx]);
351 communicatableIDs.serialize(this->indicesPart, &buffer[serialIdx]);
352 serialIdx += communicatableDamping.serialize(this->indicesSingle,
354 serialIdx += communicatableParticlePositionUpdated.serialize(
355 this->indicesSingle, &buffer[serialIdx]);
356 serialIdx += communicatableIsNew.serialize(this->indicesSingle,
358 serialIdx += communicatableRank.serialize(this->indicesSingle,
365template <
typename T,
unsigned D,
bool CONVEX>
368 std::uint8_t* buffer)
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);
379 communicatableMin.deserialize(this->indicesDim, &buffer[serialIdx]);
381 communicatableMax.deserialize(this->indicesDim, &buffer[serialIdx]);
382 serialIdx += communicatableIDs.deserialize(this->indicesPart,
384 serialIdx += communicatableDamping.deserialize(this->indicesSingle,
386 serialIdx += communicatableParticlePositionUpdated.deserialize(
387 this->indicesSingle, &buffer[serialIdx]);
388 serialIdx += communicatableIsNew.deserialize(this->indicesSingle,
390 serialIdx += communicatableRank.deserialize(this->indicesSingle,
397template <
typename T,
unsigned D,
bool CONVEX>
403 if (rank == responsibleRank[0]) {
404 clout <<
"Min=" << this->min <<
", Max=" << this->max << std::endl;
405 clout <<
"IDs=" << this->ids <<
", DampingFactor=" << dampingFactor[0]
407 clout <<
"Positions=" << particlePositions << std::endl;
class for marking output with some text
void setMultiOutput(bool b)
enable message output for all MPI processes, disabled by default
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....
cpu::simd::Pack< T > min(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
cpu::simd::Pack< T > max(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
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.
void print()
Print relevant quantities.
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.
ParticleContactArbitraryFromOverlapVolume()
Constructor.
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.