source: src/units/particle/linked_cell_list.cpp@ 30f2139

Last change on this file since 30f2139 was 30f2139, checked in by Olaf Lenz <olenz@…>, 13 years ago

Merge branch 'p3m-ad-i'

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@2418 5161e1c8-67bf-11de-9fd5-51895aff932f

  • Property mode set to 100755
File size: 4.5 KB
RevLine 
[fcf7f6]1/*
2 * vmg - a versatile multigrid solver
3 * Copyright (C) 2012 Institute for Numerical Simulation, University of Bonn
4 *
5 * vmg is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * vmg is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
[dfed1c]19/**
20 * @file linked_cell_list.cpp
21 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
22 * @date Mon Nov 21 13:27:22 2011
23 *
24 * @brief A linked cell list implementation.
25 *
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31
32#include "comm/comm.hpp"
[f003a9]33#include "units/particle/linked_cell_list.hpp"
[dfed1c]34#include "mg.hpp"
35
36using namespace VMG;
37
[ac6d04]38Particle::LinkedCellList::LinkedCellList(std::list<Particle>& particles,
[dfed1c]39 const int& near_field_cells, const Grid& grid)
40{
[ac6d04]41 std::list<Particle>::iterator iter;
[dfed1c]42 Index index_global, index_local;
43 LocalIndices local = grid.Local();
44
[ac6d04]45 local.BoundaryBegin1() = 0;
46 local.BoundaryEnd1() = 0;
47 local.BoundarySize1() = 0;
48
49 local.BoundaryBegin2() = 0;
50 local.BoundaryEnd2() = 0;
51 local.BoundarySize2() = 0;
52
[716da7]53 local.FinerBegin() = 0;
54 local.FinerEnd() = 0;
55 local.FinerSize() = 0;
[dfed1c]56
57 for (int i=0; i<3; ++i) {
58
[ac6d04]59 if (local.HaloSize1()[i] > 0) {
[dfed1c]60 local.HaloBegin1()[i] = 0;
61 local.HaloEnd1()[i] = near_field_cells+1;
[ac6d04]62 local.HaloSize1()[i] = near_field_cells+1;
[dfed1c]63 local.Begin()[i] = near_field_cells+1;
64 local.End()[i] = local.Begin()[i] + local.Size()[i];
65 local.SizeTotal()[i] = local.Size()[i] +
66 local.HaloEnd1()[i] - local.HaloBegin1()[i] +
67 local.HaloEnd2()[i] - local.HaloBegin2()[i];
[ac6d04]68 }else {
69 local.Begin()[i] = 0;
70 local.End()[i] = local.Size()[i];
[dfed1c]71 }
72
[ac6d04]73 if (local.HaloSize2()[i] > 0) {
[dfed1c]74 local.HaloBegin2()[i] = local.End()[i];
75 local.HaloEnd2()[i] = local.HaloBegin2()[i] + near_field_cells+1;
[ac6d04]76 local.HaloSize2()[i] = near_field_cells+1;
[dfed1c]77 local.SizeTotal()[i] = local.Size()[i] +
78 local.HaloEnd1()[i] - local.HaloBegin1()[i] +
79 local.HaloEnd2()[i] - local.HaloBegin2()[i];
80 }
81 }
82
83 SetGridSize(grid.Global(), local, grid.Extent());
84
85 for (iter=particles.begin(); iter!=particles.end(); ++iter)
[ac6d04]86 AddParticle(&(*iter));
[dfed1c]87}
88
[ac6d04]89Particle::LinkedCellList::~LinkedCellList()
[dfed1c]90{
[ac6d04]91 ClearHalo();
[dfed1c]92}
93
[ac6d04]94void Particle::LinkedCellList::AddParticle(Particle* p)
[dfed1c]95{
[ac6d04]96 const Index global_index = (p->Pos() - Extent().Begin()) / Extent().MeshWidth();
97 const Index local_index = global_index - Global().LocalBegin() + Local().Begin();
[dfed1c]98
[ac6d04]99 assert(local_index.IsInBounds(Local().Begin(), Local().End()));
100 (*this)(local_index).push_back(p);
[dfed1c]101}
102
[ac6d04]103void Particle::LinkedCellList::AddParticleToHalo(const vmg_float* x, const vmg_float& q)
[dfed1c]104{
[716da7]105 const Index global_index = ((Vector(x) - Extent().Begin()) / Extent().MeshWidth()).Floor();
[ac6d04]106 const Index local_index = global_index - Global().LocalBegin() + Local().Begin();
107
108 assert(local_index.IsInBounds(0, Local().SizeTotal()));
109 assert((local_index[0] >= Local().HaloBegin1()[0] && local_index[0] < Local().HaloEnd1()[0]) ||
110 (local_index[1] >= Local().HaloBegin1()[1] && local_index[1] < Local().HaloEnd1()[1]) ||
111 (local_index[2] >= Local().HaloBegin1()[2] && local_index[2] < Local().HaloEnd1()[2]) ||
112 (local_index[0] >= Local().HaloBegin2()[0] && local_index[0] < Local().HaloEnd2()[0]) ||
113 (local_index[1] >= Local().HaloBegin2()[1] && local_index[1] < Local().HaloEnd2()[1]) ||
114 (local_index[2] >= Local().HaloBegin2()[2] && local_index[2] < Local().HaloEnd2()[2]));
115
116 (*this)(local_index).push_back(new Particle(x, q));
[dfed1c]117}
118
[ac6d04]119void Particle::LinkedCellList::ClearHalo()
[dfed1c]120{
[ac6d04]121 Grid::iterator g_iter;
122 std::list<Particle*>::iterator p_iter;
[dfed1c]123
[ac6d04]124 for (int i=0; i<3; ++i) {
125
126 for (g_iter = Iterators().Halo1()[i].Begin(); g_iter != Iterators().Halo1()[i].End(); ++g_iter)
127 for (p_iter = (*this)(*g_iter).begin(); p_iter!=(*this)(*g_iter).end(); ++p_iter)
128 delete *p_iter;
129
130 for (g_iter = Iterators().Halo2()[i].Begin(); g_iter != Iterators().Halo2()[i].End(); ++g_iter)
131 for (p_iter = (*this)(*g_iter).begin(); p_iter!=(*this)(*g_iter).end(); ++p_iter)
132 delete *p_iter;
133
134 }
[dfed1c]135}
Note: See TracBrowser for help on using the repository browser.