source: src/base/linked_cell_list.cpp@ 64ba929

Last change on this file since 64ba929 was dfed1c, checked in by Julian Iseringhausen <isering@…>, 14 years ago

Major vmg update.

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

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/**
2 * @file linked_cell_list.cpp
3 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
4 * @date Mon Nov 21 13:27:22 2011
5 *
6 * @brief A linked cell list implementation.
7 *
8 */
9
10#ifdef HAVE_CONFIG_H
11#include <config.h>
12#endif
13
14#include "base/linked_cell_list.hpp"
15#include "comm/comm.hpp"
16#include "mg.hpp"
17
18using namespace VMG;
19
20Particle::LinkedCellList::LinkedCellList(const std::list<Particle>& particles,
21 const int& near_field_cells, const Grid& grid)
22{
23 std::list<Particle>::const_iterator iter;
24 Index index_global, index_local;
25 LocalIndices local = grid.Local();
26
27 local.BoundaryBegin1() = local.BoundaryEnd1() = 0;
28 local.BoundaryBegin2() = local.BoundaryEnd2() = 0;
29
30 for (int i=0; i<3; ++i) {
31
32 if (local.HasHalo1()[i]) {
33 local.HaloBegin1()[i] = 0;
34 local.HaloEnd1()[i] = near_field_cells+1;
35 local.Begin()[i] = near_field_cells+1;
36 local.End()[i] = local.Begin()[i] + local.Size()[i];
37 local.SizeTotal()[i] = local.Size()[i] +
38 local.HaloEnd1()[i] - local.HaloBegin1()[i] +
39 local.HaloEnd2()[i] - local.HaloBegin2()[i];
40 }
41
42 if (local.HasHalo2()[i]) {
43 local.HaloBegin2()[i] = local.End()[i];
44 local.HaloEnd2()[i] = local.HaloBegin2()[i] + near_field_cells+1;
45 local.SizeTotal()[i] = local.Size()[i] +
46 local.HaloEnd1()[i] - local.HaloBegin1()[i] +
47 local.HaloEnd2()[i] - local.HaloBegin2()[i];
48 }
49 }
50
51 SetGridSize(grid.Global(), local, grid.Extent());
52
53 for (iter=particles.begin(); iter!=particles.end(); ++iter)
54 AddParticle(*iter);
55}
56
57void Particle::LinkedCellList::AddParticle(const Particle& p)
58{
59 const Index global_index = (p.Pos() - Extent().Begin()) / Extent().MeshWidth();
60 const Index local_index = global_index - Global().BeginLocal() + Local().Begin();
61
62 if (local_index.IsInBounds(Local().Begin(), Local().End()))
63 (*this)(local_index).push_back(Particle(p.Pos(), p.Charge(), 0.0, 0.0, p.Rank(), p.Index()));
64 else
65 not_my_particles.push_back(Particle(p.Pos(), p.Charge(), 0.0, 0.0, p.Rank(), p.Index()));
66}
67
68void Particle::LinkedCellList::AddParticleToComplete(const vmg_float* pos, const vmg_float& charge,
69 const vmg_float& pot, const vmg_float* force,
70 const int& rank, const int& index)
71{
72 const Index global_index = (Vector(pos) - Extent().Begin()) / Extent().MeshWidth();
73 const Index local_index = global_index - Global().BeginLocal() + Local().Begin();
74
75 if (local_index.IsInBounds(0, Local().SizeTotal()))
76 (*this)(local_index).push_back(Particle(pos, charge, pot, force, rank, index));
77 else
78 not_my_particles.push_back(Particle(pos, charge, pot, force, rank, index));
79}
80
81void Particle::LinkedCellList::AddParticleToComplete(const Vector& pos, const vmg_float& charge,
82 const vmg_float& pot, const Vector& force,
83 const int& rank, const int& index)
84{
85 const Index global_index = (pos - Extent().Begin()) / Extent().MeshWidth();
86 const Index local_index = global_index - Global().BeginLocal() + Local().Begin();
87
88 if (local_index.IsInBounds(0, Local().SizeTotal()))
89 (*this)(local_index).push_back(Particle(pos, charge, pot, force, rank, index));
90 else
91 not_my_particles.push_back(Particle(pos, charge, pot, force, rank, index));
92}
93
94void Particle::LinkedCellList::AddParticleToComplete(const vmg_float* pos, const vmg_float& charge)
95{
96 const Index global_index = (Vector(pos) - Extent().Begin()) / Extent().MeshWidth();
97 const Index local_index = global_index - Global().BeginLocal() + Local().Begin();
98
99 if (local_index.IsInBounds(0, Local().SizeTotal()))
100 (*this)(local_index).push_back(Particle(pos, charge));
101 else
102 not_my_particles.push_back(Particle(pos, charge));
103}
Note: See TracBrowser for help on using the repository browser.