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 if(newContact[0] == pc.
isNew()) {
218 newContact[0] = newContact[0] && pc.
isNew();
221 for (
unsigned iD = 0; iD < D; ++iD) {
228 particlePositionUpdated[0] =
243 newContact[0] = newContact[0] && pc.
isNew();
251template <
typename T,
unsigned D,
bool CONVEX>
255 for (
unsigned iD = 0; iD < D; ++iD) {
256 if (min[iD] > max[iD]) {
263template <
typename T,
unsigned D,
bool CONVEX>
267 return newContact[0];
270template <
typename T,
unsigned D,
bool CONVEX>
272 const bool newContact)
274 this->newContact[0] = newContact;
277template <
typename T,
unsigned D,
bool CONVEX>
279 T, D, CONVEX>::isParticlePositionUpdated()
const
281 return particlePositionUpdated[0];
284template <
typename T,
unsigned D,
bool CONVEX>
286 T, D, CONVEX>::setParticlePositionUpdated(
bool updated)
288 particlePositionUpdated[0] = updated;
291template <
typename T,
unsigned D,
bool CONVEX>
302 newContact[0] = pc.
isNew();
308template <
typename T,
unsigned D,
bool CONVEX>
313 min = std::move(pc.min);
314 max = std::move(pc.max);
315 ids = std::move(pc.ids);
316 particlePositions = std::move(pc.particlePositions);
317 particlePositionUpdated = std::move(pc.particlePositionUpdated);
318 dampingFactor = std::move(pc.dampingFactor);
319 newContact = std::move(pc.newContact);
320 responsibleRank = std::move(pc.responsibleRank);
325template <
typename T,
unsigned D,
bool CONVEX>
328 T, D, CONVEX>::processWithCommunicatables(F f)
336 auto communicatableParticlePositionUpdated =
341 return f(communicatablePositions, communicatableMin, communicatableMax,
342 communicatableIDs, communicatableDamping,
343 communicatableParticlePositionUpdated, communicatableIsNew,
347template <
typename T,
unsigned D,
bool CONVEX>
349 std::uint8_t* buffer)
351 return processWithCommunicatables(
352 [&](
auto& communicatablePositions,
auto& communicatableMin,
353 auto& communicatableMax,
auto& communicatableIDs,
354 auto& communicatableDamping,
355 auto& communicatableParticlePositionUpdated,
356 auto& communicatableIsNew,
auto& communicatableRank) {
357 std::size_t serialIdx =
358 communicatablePositions.serialize(this->indicesPart, buffer);
360 communicatableMin.serialize(this->indicesDim, &buffer[serialIdx]);
362 communicatableMax.serialize(this->indicesDim, &buffer[serialIdx]);
364 communicatableIDs.serialize(this->indicesPart, &buffer[serialIdx]);
365 serialIdx += communicatableDamping.serialize(this->indicesSingle,
367 serialIdx += communicatableParticlePositionUpdated.serialize(
368 this->indicesSingle, &buffer[serialIdx]);
369 serialIdx += communicatableIsNew.serialize(this->indicesSingle,
371 serialIdx += communicatableRank.serialize(this->indicesSingle,
378template <
typename T,
unsigned D,
bool CONVEX>
381 std::uint8_t* buffer)
383 return processWithCommunicatables(
384 [&](
auto& communicatablePositions,
auto& communicatableMin,
385 auto& communicatableMax,
auto& communicatableIDs,
386 auto& communicatableDamping,
387 auto& communicatableParticlePositionUpdated,
388 auto& communicatableIsNew,
auto& communicatableRank) {
389 std::size_t serialIdx =
390 communicatablePositions.deserialize(this->indicesPart, buffer);
392 communicatableMin.deserialize(this->indicesDim, &buffer[serialIdx]);
394 communicatableMax.deserialize(this->indicesDim, &buffer[serialIdx]);
395 serialIdx += communicatableIDs.deserialize(this->indicesPart,
397 serialIdx += communicatableDamping.deserialize(this->indicesSingle,
399 serialIdx += communicatableParticlePositionUpdated.deserialize(
400 this->indicesSingle, &buffer[serialIdx]);
401 serialIdx += communicatableIsNew.deserialize(this->indicesSingle,
403 serialIdx += communicatableRank.deserialize(this->indicesSingle,
410template <
typename T,
unsigned D,
bool CONVEX>
416 if (rank == responsibleRank[0]) {
417 clout <<
"Min=" << this->min <<
", Max=" << this->max << std::endl;
418 clout <<
"IDs=" << this->ids <<
", DampingFactor=" << dampingFactor[0]
420 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....
Top level namespace for all of OpenLB.
constexpr T max(const ScalarVector< T, D, IMPL > &v)
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.