OpenLB 1.7
Loading...
Searching...
No Matches
wallContact.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 WALL_CONTACT_HH
25#define WALL_CONTACT_HH
26
27#include "wallContact.h"
28
29namespace olb {
30namespace particles {
31namespace contact {
32
33template <typename T, unsigned D, bool CONVEX>
34WallContactArbitraryFromOverlapVolume<
35 T, D, CONVEX>::WallContactArbitraryFromOverlapVolume()
36 : WallContactArbitraryFromOverlapVolume<T, D, CONVEX>(std::size_t(),
37 unsigned())
38{}
39
40template <typename T, unsigned D, bool CONVEX>
42 T, D, CONVEX>::WallContactArbitraryFromOverlapVolume(std::size_t particleID,
43 unsigned wallID)
44 : particleID(std::array<std::size_t, 1>({particleID}))
45 , wallID(std::array<unsigned, 1>({wallID}))
46
47{
48 resetMinMax();
49}
50
51template <typename T, unsigned D, bool CONVEX>
55{
56 min = contact.min;
57 max = contact.max;
58 particleID[0] = contact.particleID[0];
59 wallID[0] = contact.wallID[0];
60 particlePosition = contact.particlePosition;
61 particlePositionUpdated[0] = contact.isParticlePositionUpdated();
62 dampingFactor[0] = contact.getDampingFactor();
63 newContact[0] = contact.isNew();
64 responsibleRank[0] = contact.getResponsibleRank();
65}
66
67template <typename T, unsigned D, bool CONVEX>
71{
72 min = std::move(contact.min);
73 max = std::move(contact.max);
74 particleID = std::move(contact.particleID);
75 wallID = std::move(contact.wallID);
76 particlePosition = std::move(contact.particlePosition);
77 particlePositionUpdated = std::move(contact.particlePositionUpdated);
78 dampingFactor = std::move(contact.dampingFactor);
79 newContact = std::move(contact.newContact);
80 responsibleRank = std::move(contact.responsibleRank);
81}
82
83template <typename T, unsigned D, bool CONVEX>
84constexpr const std::size_t&
86{
87 return this->particleID[0];
88}
89
90template <typename T, unsigned D, bool CONVEX>
91constexpr unsigned
93{
94 return this->wallID[0];
95}
96
97template <typename T, unsigned D, bool CONVEX>
98constexpr const PhysR<T, D>&
103
104template <typename T, unsigned D, bool CONVEX>
105constexpr void
107 const PhysR<T, D>& position)
108{
109 particlePosition = position;
110 particlePositionUpdated[0] = true;
111}
112
113template <typename T, unsigned D, bool CONVEX>
114constexpr void
116 const int& rank)
117{
118 responsibleRank[0] = rank;
119}
120
121template <typename T, unsigned D, bool CONVEX>
122constexpr const int&
124{
125 return responsibleRank[0];
126}
127
128template <typename T, unsigned D, bool CONVEX>
129constexpr const PhysR<T, D>&
134
135template <typename T, unsigned D, bool CONVEX>
136constexpr const PhysR<T, D>&
141
142template <typename T, unsigned D, bool CONVEX>
143constexpr T
148
149template <typename T, unsigned D, bool CONVEX>
150constexpr void
152 const T newDampingFactor)
153{
154 dampingFactor[0] = newDampingFactor;
155}
156
157template <typename T, unsigned D, bool CONVEX>
160 const T coefficientOfRestitution,
161 const T initialRelativeVelocityMagnitude)
162{
164 coefficientOfRestitution, initialRelativeVelocityMagnitude));
165}
166
167template <typename T, unsigned D, bool CONVEX>
168constexpr void
170{
171 for (unsigned iD = 0; iD < D; ++iD) {
172 min[iD] = std::numeric_limits<olb::BaseType<T>>::max();
173 max[iD] = -std::numeric_limits<olb::BaseType<T>>::max();
174 }
175 particlePositionUpdated[0] = false;
176}
177
178template <typename T, unsigned D, bool CONVEX>
179constexpr void
181 const PhysR<T, D>& positionInsideTheContact)
182{
183 particles::contact::updateMinMax(this->min, this->max,
184 positionInsideTheContact);
185}
186
187template <typename T, unsigned D, bool CONVEX>
188constexpr void
190 const Vector<T, D>& increaseBy)
191{
192 this->max += increaseBy;
193 this->min -= increaseBy;
194}
195
196template <typename T, unsigned D, bool CONVEX>
199{
200 if (particleID[0] == contact.particleID[0] &&
201 wallID[0] == contact.wallID[0]) {
202 newContact[0] = newContact[0] && contact.isNew();
203
204 // Determine bounding box of combined overlap area
205 for (unsigned iD = 0; iD < D; ++iD) {
206 min[iD] = util::min(min[iD], contact.min[iD]);
207 max[iD] = util::max(max[iD], contact.max[iD]);
208 }
209 // The damping factors should be either the same or one is -1 and the other has the correct value which is > 0
210 dampingFactor[0] = util::max(dampingFactor[0], contact.getDampingFactor());
211 responsibleRank[0] =
212 util::min(responsibleRank[0], contact.getResponsibleRank());
213 particlePositionUpdated[0] =
214 particlePositionUpdated[0] || contact.isParticlePositionUpdated();
215 if (!particlePositionUpdated[0] && contact.isParticlePositionUpdated()) {
216 particlePosition = contact.getParticlePosition();
217 }
218
219 // Ignore second contact by resetting it
220 contact.resetMinMax();
221 }
222}
223
224template <typename T, unsigned D, bool CONVEX>
225constexpr bool
227{
228 for (unsigned iD = 0; iD < D; ++iD) {
229 if (min[iD] > max[iD]) {
230 return true;
231 }
232 }
233 return false;
234}
235
236template <typename T, unsigned D, bool CONVEX>
237constexpr bool
239{
240 return newContact[0];
241}
242
243template <typename T, unsigned D, bool CONVEX>
245 const bool newContact)
246{
247 this->newContact[0] = newContact;
248}
249
250template <typename T, unsigned D, bool CONVEX>
251constexpr bool
253 const
254{
255 return particlePositionUpdated[0];
256}
257
258template <typename T, unsigned D, bool CONVEX>
259constexpr void
261 bool updated)
262{
263 particlePositionUpdated[0] = updated;
264}
265
266template <typename T, unsigned D, bool CONVEX>
270{
271 min = contact.min;
272 max = contact.max;
273 particleID[0] = contact.particleID[0];
274 wallID[0] = contact.wallID[0];
275 particlePosition = contact.particlePosition;
276 particlePositionUpdated[0] = contact.isParticlePositionUpdated();
277 dampingFactor[0] = contact.getDampingFactor();
278 newContact[0] = contact.isNew();
279 responsibleRank[0] = contact.getResponsibleRank();
280
281 return *this;
282}
283
284template <typename T, unsigned D, bool CONVEX>
288{
289 min = std::move(contact.min);
290 max = std::move(contact.max);
291 particleID = std::move(contact.particleID);
292 wallID = std::move(contact.wallID);
293 particlePosition = std::move(contact.particlePosition);
294 particlePositionUpdated = std::move(contact.particlePositionUpdated);
295 dampingFactor = std::move(contact.dampingFactor);
296 newContact = std::move(contact.newContact);
297 responsibleRank = std::move(contact.responsibleRank);
298
299 return *this;
300}
301
302template <typename T, unsigned D, bool CONVEX>
303template <typename F>
304std::size_t
306 F f)
307{
308 //Create communicatables
309 auto communicatablePosition = ConcreteCommunicatable(particlePosition);
310 auto communicatableMin = ConcreteCommunicatable(min);
311 auto communicatableMax = ConcreteCommunicatable(max);
312 auto communicatableID = ConcreteCommunicatable(particleID);
313 auto communicatableMaterial = ConcreteCommunicatable(wallID);
314 auto communicatableDamping = ConcreteCommunicatable(dampingFactor);
315 auto communicatableParticlePositionUpdated =
316 ConcreteCommunicatable(particlePositionUpdated);
317 auto communicatableIsNew = ConcreteCommunicatable(newContact);
318 auto communicatableRank = ConcreteCommunicatable(responsibleRank);
319
320 return f(communicatablePosition, communicatableMin, communicatableMax,
321 communicatableID, communicatableMaterial, communicatableDamping,
322 communicatableParticlePositionUpdated, communicatableIsNew,
323 communicatableRank);
324}
325
326template <typename T, unsigned D, bool CONVEX>
328 std::uint8_t* buffer)
329{
330 return processWithCommunicatables(
331 [&](auto& communicatablePosition, auto& communicatableMin,
332 auto& communicatableMax, auto& communicatableID,
333 auto& communicatableMaterial, auto& communicatableDamping,
334 auto& communicatableParticlePositionUpdated,
335 auto& communicatableIsNew, auto& communicatableRank) {
336 std::size_t serialIdx =
337 communicatablePosition.serialize(this->indicesDim, buffer);
338 serialIdx +=
339 communicatableMin.serialize(this->indicesDim, &buffer[serialIdx]);
340 serialIdx +=
341 communicatableMax.serialize(this->indicesDim, &buffer[serialIdx]);
342 serialIdx +=
343 communicatableID.serialize(this->indicesSingle, &buffer[serialIdx]);
344 serialIdx += communicatableMaterial.serialize(this->indicesSingle,
345 &buffer[serialIdx]);
346 serialIdx += communicatableDamping.serialize(this->indicesSingle,
347 &buffer[serialIdx]);
348 serialIdx += communicatableParticlePositionUpdated.serialize(
349 this->indicesSingle, &buffer[serialIdx]);
350 serialIdx += communicatableIsNew.serialize(this->indicesSingle,
351 &buffer[serialIdx]);
352 serialIdx += communicatableRank.serialize(this->indicesSingle,
353 &buffer[serialIdx]);
354
355 return serialIdx;
356 });
357}
358
359template <typename T, unsigned D, bool CONVEX>
361 std::uint8_t* buffer)
362{
363 return processWithCommunicatables(
364 [&](auto& communicatablePosition, auto& communicatableMin,
365 auto& communicatableMax, auto& communicatableID,
366 auto& communicatableMaterial, auto& communicatableDamping,
367 auto& communicatableParticlePositionUpdated,
368 auto& communicatableIsNew, auto& communicatableRank) {
369 std::size_t serialIdx =
370 communicatablePosition.deserialize(this->indicesDim, buffer);
371 serialIdx +=
372 communicatableMin.deserialize(this->indicesDim, &buffer[serialIdx]);
373 serialIdx +=
374 communicatableMax.deserialize(this->indicesDim, &buffer[serialIdx]);
375 serialIdx += communicatableID.deserialize(this->indicesSingle,
376 &buffer[serialIdx]);
377 serialIdx += communicatableMaterial.deserialize(this->indicesSingle,
378 &buffer[serialIdx]);
379 serialIdx += communicatableDamping.deserialize(this->indicesSingle,
380 &buffer[serialIdx]);
381 serialIdx += communicatableParticlePositionUpdated.deserialize(
382 this->indicesSingle, &buffer[serialIdx]);
383 serialIdx += communicatableIsNew.deserialize(this->indicesSingle,
384 &buffer[serialIdx]);
385 serialIdx += communicatableRank.deserialize(this->indicesSingle,
386 &buffer[serialIdx]);
387
388 return serialIdx;
389 });
390}
391
392template <typename T, unsigned D, bool CONVEX>
394{
395 OstreamManager clout(std::cout, "WallContact");
396 clout.setMultiOutput(true);
397#ifdef PARALLEL_MODE_MPI
398 int rank = singleton::mpi().getRank();
399 if (rank == responsibleRank[0]) {
400#endif
401 clout << "Min=" << this->min << ", Max=" << this->max << std::endl;
402 clout << "particle ID=" << this->particleID[0]
403 << ", wall ID=" << this->wallID[0]
404 << ", DampingFactor=" << dampingFactor[0] << std::endl;
405 clout << "Position=" << particlePosition << std::endl;
406#ifdef PARALLEL_MODE_MPI
407 }
408#endif
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.
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.
constexpr bool isParticlePositionUpdated() const
Returns if the particle position is up-to-date.
constexpr void setResponsibleRank(const int &rank)
Set processor that is responsible for contact treatment.
constexpr void setDampingFactor(const T dampingFactor)
Set damping factor for contact.
constexpr void setParticlePosition(const PhysR< T, D > &particlePosition)
Set particle position.
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...
constexpr const std::size_t & getParticleID() const
Read access to particle ID.
constexpr const PhysR< T, D > & getMin() const
Read access to min.
constexpr T getDampingFactor() const
Read access to damping factor.
std::size_t serialize(std::uint8_t *buffer)
Serialize contact data.
constexpr void resetMinMax()
Reset min and max to default values.
constexpr unsigned getWallID() const
Read access to wall matreial.
constexpr const int & getResponsibleRank() const
Read access to the responsible rank.
constexpr const PhysR< T, D > & getParticlePosition() const
Return particle position.
WallContactArbitraryFromOverlapVolume< T, D, CONVEX > & operator=(const WallContactArbitraryFromOverlapVolume< T, D, CONVEX > &contact)
Copy assignment.
constexpr bool isEmpty() const
Returns if contact holds data.
constexpr const PhysR< T, D > & getMax() const
Read access to max.
std::size_t deserialize(std::uint8_t *buffer)
Deserialize contact data and save in object.
constexpr void combineWith(WallContactArbitraryFromOverlapVolume< T, D, CONVEX > &contact)
Combining two contacts, if the particle IDs are the same.
constexpr bool isNew() const
Returns if the contact is a new contact.
constexpr void increaseMinMax(const Vector< T, D > &increaseBy)
Increase bounding box size.
constexpr void updateMinMax(const PhysR< T, D > &positionInsideTheContact)
Update min and max with given position inside the contact.