source: src/units/particle/linked_cell_list.cpp@ 09e5c8

Last change on this file since 09e5c8 was 09e5c8, checked in by Julian Iseringhausen <isering@…>, 13 years ago

Fixed global bounds error.

  • Property mode set to 100644
File size: 5.5 KB
Line 
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
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"
33#include "units/particle/linked_cell_list.hpp"
34#include "mg.hpp"
35
36using namespace VMG;
37
38Particle::LinkedCellList::LinkedCellList(std::list<Particle>& particles,
39 const int& near_field_cells, const Grid& grid)
40{
41 std::list<Particle>::iterator iter;
42 Index index_global, index_local;
43 LocalIndices local = grid.Local();
44
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 * vmg - a versatile multigrid solver
53 * Copyright (C) 2012 Institute for Numerical Simulation, University of Bonn
54 *
55 * vmg is free software: you can redistribute it and/or modify
56 * it under the terms of the GNU General Public License as published by
57 * the Free Software Foundation, either version 3 of the License, or
58 * (at your option) any later version.
59 *
60 * vmg is distributed in the hope that it will be useful,
61 * but WITHOUT ANY WARRANTY; without even the implied warranty of
62 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
63 * GNU General Public License for more details.
64 *
65 * You should have received a copy of the GNU General Public License
66 * along with this program. If not, see <http://www.gnu.org/licenses/>.
67 */
68
69 /**
70 * @file global_grid_partitioning.hpp
71 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
72 * @date Thu May 19 14:02:46 2011
73 *
74 * @brief Class to store global grid partitioning.
75 *
76 */
77
78 for (int i=0; i<3; ++i) {
79
80 if (local.HaloSize1()[i] > 0) {
81 local.HaloBegin1()[i] = 0;
82 local.HaloEnd1()[i] = near_field_cells+1;
83 local.HaloSize1()[i] = near_field_cells+1;
84 local.Begin()[i] = near_field_cells+1;
85 local.End()[i] = local.Begin()[i] + local.Size()[i];
86 local.SizeTotal()[i] = local.Size()[i] +
87 local.HaloEnd1()[i] - local.HaloBegin1()[i] +
88 local.HaloEnd2()[i] - local.HaloBegin2()[i];
89 }else {
90 local.Begin()[i] = 0;
91 local.End()[i] = local.Size()[i];
92 }
93
94 if (local.HaloSize2()[i] > 0) {
95 local.HaloBegin2()[i] = local.End()[i];
96 local.HaloEnd2()[i] = local.HaloBegin2()[i] + near_field_cells+1;
97 local.HaloSize2()[i] = near_field_cells+1;
98 local.SizeTotal()[i] = local.Size()[i] +
99 local.HaloEnd1()[i] - local.HaloBegin1()[i] +
100 local.HaloEnd2()[i] - local.HaloBegin2()[i];
101 }
102 }
103
104 SetGridSize(grid.Global(), local, grid.Extent());
105
106 for (iter=particles.begin(); iter!=particles.end(); ++iter)
107 AddParticle(&(*iter));
108}
109
110Particle::LinkedCellList::~LinkedCellList()
111{
112 ClearHalo();
113}
114
115void Particle::LinkedCellList::AddParticle(Particle* p)
116{
117 const Index global_index = global.GlobalBegin() + (p->Pos() - Extent().Begin()) / Extent().MeshWidth();
118 const Index local_index = global_index - Global().LocalBegin() + Local().Begin();
119
120 assert(local_index.IsInBounds(Local().Begin(), Local().End()));
121 (*this)(local_index).push_back(p);
122}
123
124void Particle::LinkedCellList::AddParticleToHalo(const vmg_float* x, const vmg_float& q)
125{
126 const Index global_index = Global().GlobalBegin() + ((Vector(x) - Extent().Begin()) / Extent().MeshWidth()).Floor();
127 const Index local_index = global_index - Global().LocalBegin() + Local().Begin();
128
129 assert(local_index.IsInBounds(0, Local().SizeTotal()));
130 assert((local_index[0] >= Local().HaloBegin1()[0] && local_index[0] < Local().HaloEnd1()[0]) ||
131 (local_index[1] >= Local().HaloBegin1()[1] && local_index[1] < Local().HaloEnd1()[1]) ||
132 (local_index[2] >= Local().HaloBegin1()[2] && local_index[2] < Local().HaloEnd1()[2]) ||
133 (local_index[0] >= Local().HaloBegin2()[0] && local_index[0] < Local().HaloEnd2()[0]) ||
134 (local_index[1] >= Local().HaloBegin2()[1] && local_index[1] < Local().HaloEnd2()[1]) ||
135 (local_index[2] >= Local().HaloBegin2()[2] && local_index[2] < Local().HaloEnd2()[2]));
136
137 (*this)(local_index).push_back(new Particle(x, q));
138}
139
140void Particle::LinkedCellList::ClearHalo()
141{
142 Grid::iterator g_iter;
143 std::list<Particle*>::iterator p_iter;
144
145 for (int i=0; i<3; ++i) {
146
147 for (g_iter = Iterators().Halo1()[i].Begin(); g_iter != Iterators().Halo1()[i].End(); ++g_iter)
148 for (p_iter = (*this)(*g_iter).begin(); p_iter!=(*this)(*g_iter).end(); ++p_iter)
149 delete *p_iter;
150
151 for (g_iter = Iterators().Halo2()[i].Begin(); g_iter != Iterators().Halo2()[i].End(); ++g_iter)
152 for (p_iter = (*this)(*g_iter).begin(); p_iter!=(*this)(*g_iter).end(); ++p_iter)
153 delete *p_iter;
154
155 }
156}
Note: See TracBrowser for help on using the repository browser.