53{
54
55 std::vector < std::pair<size_t, T> > ret_matches;
56 pSys.getDetection()->getMatches(pInt, ret_matches);
57
58
59 PARTICLETYPE<T>* p2 = NULL;
60 typename std::vector<std::pair<size_t, T> >::iterator it =
61 ret_matches.begin();
62
63 Vector<T, 3> dMom_1 = Vector<T, 3>((p->getMoment()));
64 if (
norm(dMom_1) > std::numeric_limits<T>::epsilon()) {
65 T m_p1 = p->getMagnetisation();
66
67 for (; it != ret_matches.end(); it++) {
68 if (it->second >= std::numeric_limits < T > ::epsilon()) {
69
70 p2 = &pSys[it->first];
71
72
73
74
75
76 Vector<T, 3> dMom_2((p2->getMoment()));
77 if (
norm(dMom_2) > std::numeric_limits<T>::epsilon()) {
78 T m_p2 = p2->getMagnetisation();
79
80
81 T m_i_scaleFactor =
norm(dMom_1);
82 T m_j_scaleFactor =
norm(dMom_2);
83
84
85 Vector<T, 3> n_i(dMom_1);
87 Vector<T, 3> n_j(dMom_2);
89
90
91 T mu_0 = 4 *
M_PI * 1.e-7;
92 T mu_i = 4. / 3 *
M_PI *
util::pow(p->getRad(), 3) * m_p1 * m_i_scaleFactor ;
93 T mu_j = 4. / 3 *
M_PI *
util::pow(p2->getRad(), 3) * m_p2 * m_j_scaleFactor ;
94
95
96 Vector<T, 3> r_ij;
97
98 r_ij[0] = p->getPos()[0] - p2->getPos()[0];
99 r_ij[1] = p->getPos()[1] - p2->getPos()[1];
100 r_ij[2] = p->getPos()[2] - p2->getPos()[2];
101
102
104
105
106 Vector<T, 3> t_ij(r_ij);
108
109
110 Vector<T, 3> mi = {n_i};
111 mi *= mu_i;
112 Vector<T, 3> mj = {n_j};
113 mj *= mu_j;
114 Vector<T, 3> rn = {r_ij};
115 rn *= -1. ;
118 Vector<T, 3> force = mj * (mi * rn) + mi * (mj * rn) + rn * (mi * mj) - 5 * rn * (mi * rn) * (mj * rn) ;
119 force *= scalar_termF;
120
121
122
123 T scalar_termT = - (mu_0 * mu_i * mu_j) / (4 *
M_PI *
util::pow(r, 3));
126 torque *= scalar_termT;
127
128
129 if ((p2->getRad() + p->getRad()) >=
util::sqrt(it->second)) {
131 torque *= 0;
133 }
134
135 p->getTorque()[0] += 0.5 * torque[0] * _scaleT;
136 p->getTorque()[1] += 0.5 * torque[1] * _scaleT;
137 p->getTorque()[2] += 0.5 * torque[2] * _scaleT;
138 p->getForce()[0] -= 0.5 * force[0] * _scale ;
139 p->getForce()[1] -= 0.5 * force[1] * _scale ;
140 p->getForce()[2] -= 0.5 * force[2] * _scale ;
141 p2->getTorque()[0] -= 0.5 * torque[0] * _scaleT;
142 p2->getTorque()[1] -= 0.5 * torque[1] * _scaleT;
143 p2->getTorque()[2] -= 0.5 * torque[2] * _scaleT;
144 p2->getForce()[0] += 0.5 * force[0] * _scale ;
145 p2->getForce()[1] += 0.5 * force[1] * _scale ;
146 p2->getForce()[2] += 0.5 * force[2] * _scale ;
147
148 }
149
150 }
151 }
152 }
153}
cpu::simd::Pack< T > sqrt(cpu::simd::Pack< T > value)
cpu::simd::Pack< T > pow(cpu::simd::Pack< T > base, cpu::simd::Pack< T > exp)
constexpr T norm(const ScalarVector< T, D, IMPL > &a)
Euclidean vector norm.
constexpr Vector< T, 3 > crossProduct3D(const ScalarVector< T, 3, IMPL > &a, const ScalarVector< T, 3, IMPL_ > &b) any_platform
constexpr Vector< T, D > normalize(const ScalarVector< T, D, IMPL > &a, T scale=T{1})