ParticleFunctions.h 3.76 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//======================================================================================================================
//
//  This file is part of waLBerla. waLBerla is free software: you can
//  redistribute it and/or modify it under the terms of the GNU General Public
//  License as published by the Free Software Foundation, either version 3 of
//  the License, or (at your option) any later version.
//
//  waLBerla is distributed in the hope that it will be useful, but WITHOUT
//  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
//  for more details.
//
//  You should have received a copy of the GNU General Public License along
//  with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>.
//
16
//! \file
17
18
19
20
//! \author Sebastian Eibl <sebastian.eibl@fau.de>
//
//======================================================================================================================

21
22
23
24
25
26
//======================================================================================================================
//
//  THIS FILE IS GENERATED - PLEASE CHANGE THE TEMPLATE !!!
//
//======================================================================================================================

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once

#include <mesa_pd/data/DataTypes.h>

namespace walberla {
namespace mesa_pd {

/**
 * Returns the "surface" velocity at a certain point given in world frame coordinates.
 */
template <typename Accessor>
inline Vec3 getVelocityAtWFPoint(const size_t p_idx, Accessor& ac, const Vec3& wf_pt)
{
   return ac.getLinearVelocity(p_idx) + cross(ac.getAngularVelocity(p_idx), ( wf_pt - ac.getPosition(p_idx) ));
}

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
 * Transformations between world frame (WF) and body frame (BF) coordinates
 */
template <typename Accessor>
inline Vec3 transformPositionFromWFtoBF(const size_t p_idx, Accessor& ac, const Vec3& positionWF)
{
   return ac.getRotation(p_idx).getMatrix().getTranspose() * ( positionWF - ac.getPosition(p_idx)  );
}

template <typename Accessor>
inline Vec3 transformVectorFromWFtoBF(const size_t p_idx, Accessor& ac, const Vec3& vectorWF)
{
   return ac.getRotation(p_idx).getMatrix().getTranspose() * vectorWF;
}

template <typename Accessor>
inline Vec3 transformPositionFromBFtoWF(const size_t p_idx, Accessor& ac, const Vec3& positionBF)
{
   return ac.getPosition(p_idx) + ac.getRotation(p_idx).getMatrix() * positionBF;
}

template <typename Accessor>
inline Vec3 transformVectorFromBFtoWF(const size_t p_idx, Accessor& ac, const Vec3& vectorBF)
{
   return ac.getRotation(p_idx).getMatrix() * vectorBF;
}

70
71
72
73
74
75
/**
 * Force is applied at the center of mass.
 */
template <typename Accessor>
inline void addForceAtomic(const size_t p_idx, Accessor& ac, const Vec3& f)
{
76
77
78
   // Increasing the force and torque on this particle;
   ac.getForceRef(p_idx)[0]  += f[0];;
   ac.getForceRef(p_idx)[1]  += f[1];;
79
80
81
82
83
84
   ac.getForceRef(p_idx)[2]  += f[2];
}

template <typename Accessor>
inline void addForceAtWFPosAtomic(const size_t p_idx, Accessor& ac, const Vec3& f, const Vec3& wf_pt)
{
85
86
87
   // Increasing the force and torque on this particle;
   ac.getForceRef(p_idx)[0]  += f[0];;
   ac.getForceRef(p_idx)[1]  += f[1];;
88
89
   ac.getForceRef(p_idx)[2]  += f[2];

90
91
92
   const auto t = cross(( wf_pt - ac.getPosition(p_idx) ), f);;
   ac.getTorqueRef(p_idx)[0] += t[0];;
   ac.getTorqueRef(p_idx)[1] += t[1];;
93
94
95
   ac.getTorqueRef(p_idx)[2] += t[2];
}

96
97
98
99
100
101
/**
 * Torque is directly applied on the particle.
 */
template <typename Accessor>
inline void addTorqueAtomic(const size_t p_idx, Accessor& ac, const Vec3& t)
{
102
103
104
   // Increasing the torque on this particle;
   ac.getTorqueRef(p_idx)[0]  += t[0];;
   ac.getTorqueRef(p_idx)[1]  += t[1];;
105
106
107
108
   ac.getTorqueRef(p_idx)[2]  += t[2];
}


109
} //namespace mesa_pd
110
} //namespace walberla