OpenLB 1.7
Loading...
Searching...
No Matches
contactFunctions.h
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/*
25 * This file contains functions used for the particle-wall and particle-particle contact force calculation.
26*/
27
28#ifndef CONTACT_FUNCTIONS_H
29#define CONTACT_FUNCTIONS_H
30
31namespace olb {
32
33namespace particles {
34
35namespace contact {
36
37template <typename T>
38constexpr T evalEffectiveYoungModulus(T E1, T E2, T nu1, T nu2)
39{
40 const T denominator = (1 - nu1 * nu1) / E1 + (1 - nu2 * nu2) / E2;
41 return T {1} / denominator;
42}
43
45template <typename T>
46constexpr T evalDampingFactor(const T coefficientOfRestitution,
47 const T initialRelativeVelocityMagnitude)
48{
49 // This case should never happen, but could for example due to initial conditions
50 if (initialRelativeVelocityMagnitude <= 0) {
51 return 0;
52 }
53 return 1.5 * (1 - coefficientOfRestitution) *
54 (11 - coefficientOfRestitution) / (1 + 9 * coefficientOfRestitution) /
55 initialRelativeVelocityMagnitude;
56}
57
58template <typename T, typename PARTICLETYPE>
60 T const physDeltaX)
61{
62 constexpr unsigned D = PARTICLETYPE::d;
63
64 if constexpr (particles::access::providesContactMaterial<PARTICLETYPE>()) {
65 constexpr T factor = []() {
66 static_assert(D == 2 || D == 3, "Only D=2 and D=3 are supported");
67 // TODO: Use with c++20
68 //return T{0.5} * (D == 3 ? std::numbers::sqrt3_v<T> : std::numbers::sqrt2_v<T>);
69 return T {0.5} * (D == 3 ? 1.7320508075688772935 : 1.4142135623730950488);
70 }();
71 return factor * physDeltaX +
73 }
74 else {
75 return T {0};
76 }
77
78 __builtin_unreachable();
79}
80
81template <typename T>
82T evalCircumRadius(T const contactDetectionDistance, T const circumRadius,
83 T const epsilon)
84{
85 return circumRadius - epsilon + util::max(epsilon, contactDetectionDistance);
86}
87
88template <typename T, typename PARTICLETYPE>
89T evalCircumRadius(Particle<T, PARTICLETYPE>& particle, T const physDeltaX,
90 T const circumRadius, T const epsilon)
91{
92 const T contactDetectionDistance =
93 evalContactDetectionDistance(particle, physDeltaX);
94 return evalCircumRadius(contactDetectionDistance, circumRadius, epsilon);
95}
96
97template <typename T, typename PARTICLETYPE>
98T evalCircumRadius(Particle<T, PARTICLETYPE>& particle, T const physDeltaX)
99{
100 using namespace descriptors;
101 auto sIndicator = particle.template getField<SURFACE, SINDICATOR>();
102 return evalCircumRadius(particle, physDeltaX, sIndicator->getCircumRadius(),
103 sIndicator->getEpsilon());
104}
105
106template <typename CONTACTTYPE>
107void cleanContacts(std::vector<CONTACTTYPE>& contacts)
108{
109 contacts.erase(std::remove_if(contacts.begin(), contacts.end(),
110 [](const CONTACTTYPE& contact) {
111 return contact.isEmpty();
112 }),
113 contacts.end());
114}
115
116template <typename CONTACTTYPE>
117void resetResponsibleRank(CONTACTTYPE& contact)
118{
119 contact.setResponsibleRank(std::numeric_limits<int>::max());
120}
121
122template <typename CONTACTTYPE>
123bool isResponsibleRankSet(CONTACTTYPE& contact)
124{
125 return contact.getResponsibleRank() < std::numeric_limits<int>::max();
126}
127
128} // namespace contact
129} // namespace particles
130} // namespace olb
131#endif
T getEnlargementForContact(Particle< T, PARTICLETYPE > particle)
void cleanContacts(std::vector< CONTACTTYPE > &contacts)
void resetResponsibleRank(CONTACTTYPE &contact)
bool isResponsibleRankSet(CONTACTTYPE &contact)
T evalCircumRadius(T const contactDetectionDistance, T const circumRadius, T const epsilon)
constexpr T evalEffectiveYoungModulus(T E1, T E2, T nu1, T nu2)
T evalContactDetectionDistance(Particle< T, PARTICLETYPE > &particle, T const physDeltaX)
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 > max(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
Definition pack.h:130
Top level namespace for all of OpenLB.