OpenLB 1.7
Loading...
Searching...
No Matches
magneticForceFromHField3D.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018 Marie-Luise Maier
3 * E-mail contact: info@openlb.net
4 * The most recent release of OpenLB can be downloaded at
5 * <http://www.openlb.net/>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public
18 * License along with this program; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23#ifndef MagneticForceFromHField3D_HH
24#define MagneticForceFromHField3D_HH
25
26#include "utilities/omath.h"
27#include <vector>
29
30#ifndef M_PI
31#define M_PI 3.14159265358979323846
32#endif
33
34namespace olb {
35
36/*
37template<typename T, template<typename U> class PARTICLETYPE, typename DESCRIPTOR>
38MagneticForceFromHField3D<T, PARTICLETYPE, DESCRIPTOR>::MagneticForceFromHField3D(
39 SuperLattice<T, DESCRIPTOR>& sLattice,
40 SuperLatticeField3D<T,DESCRIPTOR>& sLatticeHField, T Mp, T scale) :
41 Force3D<T, PARTICLETYPE>(), _sLattice(sLattice), _sLatticeHField(
42 sLatticeHField), _Mp(Mp), _scale(scale) {
43}
44
45template<typename T, template<typename U> class PARTICLETYPE, typename DESCRIPTOR>
46void MagneticForceFromHField3D<T, PARTICLETYPE, DESCRIPTOR>::applyForce(
47 typename std::deque<PARTICLETYPE<T> >::iterator p, int pInt,
48 ParticleSystem3D<T, PARTICLETYPE>& pSys) {
49
50 // vacuum permeability
51 T mu_0 = 4. * M_PI * 1.e-7;
52 T Vp = 4. / 3. * M_PI * util::pow(p->getRad(), 3);
53 T physLatticeLength =
54 _sLattice.getCuboidGeometry().get(p->getCuboid()).getDeltaR();
55
56 int glob = p->getCuboid();
57 int latticePos[3] = { 0, 0, 0 };
58 _sLattice.getCuboidGeometry().get(p->getCuboid()).getLatticeR(latticePos,
59 &p->getPos()[0]);
60
61 T H[3] = { T(), T(), T() };
62 T HXplus[3] = { T(), T(), T() };
63 T HYplus[3] = { T(), T(), T() };
64 T HZplus[3] = { T(), T(), T() };
65
66 int X[4] = { glob, latticePos[0], latticePos[1], latticePos[2] };
67
68 int Xplus[4] = { glob, latticePos[0] + 1, latticePos[1], latticePos[2] };
69 int Yplus[4] = { glob, latticePos[0], latticePos[1] + 1, latticePos[2] };
70 int Zplus[4] = { glob, latticePos[0], latticePos[1], latticePos[2] + 1 };
71
72 T gradHx[3] = { T(), T(), T() };
73 T gradHy[3] = { T(), T(), T() };
74 T gradHz[3] = { T(), T(), T() };
75 T modGradH[3] = { T(), T(), T() };
76
77 _sLatticeHField(H, X);
78 _sLatticeHField(HXplus, Xplus);
79 _sLatticeHField(HYplus, Yplus);
80 _sLatticeHField(HZplus, Zplus);
81
82 if (!(util::nearZero(H[0]) && util::nearZero(H[1]) && util::nearZero(H[2]))) {
83 Vector<T, 3> M(H[0], H[1], H[2]);
84 M.normalize();
85 M[0] *= _Mp;
86 M[1] *= _Mp;
87 M[2] *= _Mp;
88
89 gradHx[0] = (HXplus[0] - H[0]) / physLatticeLength;
90 gradHx[1] = (HXplus[1] - H[1]) / physLatticeLength;
91 gradHx[2] = (HXplus[2] - H[2]) / physLatticeLength;
92
93 gradHy[0] = (HYplus[0] - H[0]) / physLatticeLength;
94 gradHy[1] = (HYplus[1] - H[1]) / physLatticeLength;
95 gradHy[2] = (HYplus[2] - H[2]) / physLatticeLength;
96
97 gradHz[0] = (HZplus[0] - H[0]) / physLatticeLength;
98 gradHz[1] = (HZplus[1] - H[1]) / physLatticeLength;
99 gradHz[2] = (HZplus[2] - H[2]) / physLatticeLength;
100
101 // modGradH = (M \cdot \nabla) H
102 modGradH[0] = M[0] * gradHx[0] + M[1] * gradHy[0] + M[2] * gradHz[0];
103 modGradH[1] = M[0] * gradHx[1] + M[1] * gradHy[1] + M[2] * gradHz[1];
104 modGradH[2] = M[0] * gradHx[2] + M[1] * gradHy[2] + M[2] * gradHz[2];
105
106 if (modGradH[0] > T() || modGradH[1] > T() || modGradH[2] > T()) {
107 std::cout << "without scale: modGradH[0] " << Vp * mu_0 * modGradH[0]
108 << "modGradH[1] " << Vp * mu_0 * modGradH[1] << "modGradH[2] "
109 << Vp * mu_0 * modGradH[2] << std::endl;
110 }
111 p->getForce()[0] += Vp * mu_0 * modGradH[0] * _scale;
112 p->getForce()[1] += Vp * mu_0 * modGradH[1] * _scale;
113 p->getForce()[2] += Vp * mu_0 * modGradH[2] * _scale;
114 }
115}
116*/
117
118}
119#endif
Top level namespace for all of OpenLB.