OpenLB 1.7
Loading...
Searching...
No Matches
pLattice.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2015 Thomas Henn
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 PLATTICE_H_
25#define PLATTICE_H_
26
27#include "sortAlgorithms.h"
28
29namespace olb {
30
31template<typename T, template<typename U> class PARTICLETYPE>
32class PLattice : public ContactDetection<T, PARTICLETYPE> {
33public:
34 PLattice(ParticleSystem3D<T, PARTICLETYPE>& pSys, T overlap, T spacing);
35
36 void sort();
37 int getMatches(int pInt,
38 std::vector<std::pair<size_t, T> >& matches);
39
40private:
42
43
44 std::vector<T> _physPos, _physExtend;
45 std::vector<int> _intExtend;
46 T _overlap;
47 T _spacing;
48
49 std::vector<std::vector<std::vector<std::list<int>> > > _pLattice;
50
51};
52
53template<typename T, template<typename U> class PARTICLETYPE>
55{
56 //std::cout << "calling NanoflannContact.generate()" << std::endl;
57 return new PLattice(pSys,_overlap, _spacing);
58}
59
60template<typename T, template<typename U> class PARTICLETYPE>
62 T overlap, T spacing)
63 : ContactDetection<T, PARTICLETYPE>(pSys, "PLattice"),
64 _physPos(3, T()),
65 _physExtend(3, T()),
66 _intExtend(3, 0),
67 _overlap(overlap),
68 _spacing(spacing)
69{
70
71 _physPos = this->_pSys.getPhysPos();
72 _physExtend = this->_pSys.getPhysExtend();
73
74 int intOverlap = util::ceil(overlap / _spacing);
75 std::cout << "intOverlap: " << intOverlap << std::endl;
76 for (int i = 0; i < 3; i++) {
77 _physPos[i] -= overlap;
78 _intExtend[i] = util::ceil(_physExtend[i] / _spacing + 2 * intOverlap + 1);
79 std::cout << "intExtend[" << i << "]: " << _physExtend[i] << std::endl;
80 }
81
82 std::cout << "intOverlap: " << intOverlap << std::endl;
83
84 _pLattice.resize(_intExtend[0]);
85 for (int iX = 0; iX < _intExtend[0]; ++iX) {
86 _pLattice[iX].resize(_intExtend[1]);
87 for (int iY = 0; iY < _intExtend[1]; ++iY) {
88 _pLattice[iX][iY].resize(_intExtend[2]);
89 for (int iZ = 0; iZ < _intExtend[2]; ++iZ) {
90 }
91 }
92 }
93// cout << "intExtend " << _intExtend[0] << " "<< _intExtend[1] << " "<< _intExtend[2] << " " << std::endl;
94}
95
96template<typename T, template<typename U> class PARTICLETYPE>
98{
99// _pLattice.clear();
100 for (int i = 0; i < _intExtend[0]; i++) {
101 for (int j = 0; j < _intExtend[1]; j++) {
102 for (int k = 0; k < _intExtend[2]; k++) {
103 _pLattice[i][j][k].clear();
104 }
105 }
106 }
107
108 std::vector<T> pos(3, T());
109 for (unsigned int i = 0; i < this->_pSys.sizeInclShadow(); i++) {
110 pos = this->_pSys[i].getPos();
111#if OLB_DEBUG
112 int aa = (pos[0] - _physPos[0]) / _spacing;
113 int bb = (pos[1] - _physPos[1]) / _spacing;
114 int cc = (pos[2] - _physPos[2]) / _spacing;
115
116 OLB_PRECONDITION( aa >= 0);
117 OLB_PRECONDITION( bb >= 0);
118 OLB_PRECONDITION( cc >= 0);
119 OLB_PRECONDITION( aa < _intExtend[0]);
120 OLB_PRECONDITION( bb < _intExtend[1]);
121 OLB_PRECONDITION( cc < _intExtend[2]);
122#endif
123
124 _pLattice[(int) util::floor((pos[0] - _physPos[0]) / _spacing)][(int) util::floor(
125 (pos[1] - _physPos[1]) / _spacing)][(int) util::floor(
126 (pos[2] - _physPos[2]) / _spacing)].push_back(i);
127 }
128
129 int iX = 0, iY = 0, iZ = 0;
130 int x = 0, y = 0, z = 0;
131 for (unsigned int s = 0; s < this->_pSys.size(); s++) {
132 pos = this->_pSys[s].getPos();
133 iX = util::floor((pos[0] - _physPos[0]) / _spacing);
134 iY = util::floor((pos[1] - _physPos[1]) / _spacing);
135 iZ = util::floor((pos[2] - _physPos[2]) / _spacing);
136 //
137 if (_pLattice[iX][iY][iZ].back() != -1) {
138
139 int a = 1, b = 1, c = 1;
140 int d = -1, e = -1, f = -1;
141 if (iX <= 0) {
142 d = 0;
143 }
144 if (iY <= 0) {
145 e = 0;
146 }
147 if (iZ <= 0) {
148 f = 0;
149 }
150 if (iX >= _intExtend[0]) {
151 a = 0;
152 }
153 if (iY >= _intExtend[1]) {
154 b = 0;
155 }
156 if (iZ >= _intExtend[2]) {
157 c = 0;
158 }
159
160 typename std::list<int>::iterator it;
161 for (int i = d; i <= a; i++) {
162 for (int j = e; j <= b; j++) {
163 for (int k = f; k <= c; k++) {
164 if (i != 0 || j != 0 || k != 0) {
165 it = _pLattice[iX + i][iY + j][iZ + k].begin();
166 int size = _pLattice[iX + i][iY + j][iZ + k].size();
167 for (int lauf = 0; lauf < size; lauf++, it++) {
168 if (*it != -1) {
169 pos = this->_pSys[*it].getPos();
170 T rad = this->_pSys[*it].getRad();
171 x = util::floor((pos[0] - _physPos[0] - i * rad) / _spacing);
172 y = util::floor((pos[1] - _physPos[1] - j * rad) / _spacing);
173 z = util::floor((pos[2] - _physPos[2] - k * rad) / _spacing);
174 if (x != iX || y != iY || z != iZ) {
175 _pLattice[iX][iY][iZ].push_back(*it);
176 }
177 }
178 }
179 }
180 }
181 }
182 }
183 _pLattice[iX][iY][iZ].push_back(-1);
184 }
185 }
186}
187
188template<typename T, template<typename U> class PARTICLETYPE>
190 std::vector<std::pair<size_t, T> >& matches)
191{
192 matches.clear();
193 PARTICLETYPE<T>& p = this->_pSys[pInt];
194 int iX = util::floor((p.getPos()[0] - _physPos[0]) / _spacing);
195 int iY = util::floor((p.getPos()[1] - _physPos[1]) / _spacing);
196 int iZ = util::floor((p.getPos()[2] - _physPos[2]) / _spacing);
197
198 typename std::list<int>::iterator it = _pLattice[iX][iY][iZ].begin();
199 std::vector<T>& pos = p.getPos();
200 for (; it != _pLattice[iX][iY][iZ].end(); ++it) {
201 if (*it != -1) {
202 std::vector<T>& pos2 = this->_pSys[*it].getPos();
203 matches.push_back(
204 std::make_pair<size_t, T>(
205 *it,
206 util::pow(pos[0] - pos2[0], 2) + util::pow(pos[1] - pos2[1], 2)
207 + util::pow(pos[2] - pos2[2], 2)));
208 }
209 }
210 return matches.size();
211}
212
213} // namespace olb
214
215#endif
ParticleSystem3D< T, PARTICLETYPE > & _pSys
int getMatches(int pInt, std::vector< std::pair< size_t, T > > &matches)
Definition pLattice.h:189
PLattice(ParticleSystem3D< T, PARTICLETYPE > &pSys, T overlap, T spacing)
Definition pLattice.h:61
void sort()
Definition pLattice.h:97
ADf< T, DIM > ceil(const ADf< T, DIM > &a)
Definition aDiff.h:900
ADf< T, DIM > floor(const ADf< T, DIM > &a)
Definition aDiff.h:869
cpu::simd::Pack< T > pow(cpu::simd::Pack< T > base, cpu::simd::Pack< T > exp)
Definition pack.h:112
Top level namespace for all of OpenLB.
#define OLB_PRECONDITION(COND)
Definition olbDebug.h:46