-
Notifications
You must be signed in to change notification settings - Fork 0
/
cell.cpp
252 lines (212 loc) · 4.95 KB
/
cell.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#include "cell.h"
#include <sstream>
Cell::Cell(unsigned int dimension, double size, Point const & center) :
m_dim(dimension),
m_center(center),
m_has_grid_pos(false),
m_size(size),
m_leaf_block_start_pos(-1),
m_leaf_number(-1)
{
#if DEBUG
assert(m_size > 0);
#endif
m_grid_pos = Point(dimension);
}
Cell::~Cell() {}
const std::vector<Element *> &Cell::get_source_elements() const
{
return m_src_elements;
}
void Cell::set_source_elements(const std::vector<Element *> &el)
{
#if DEBUG
for(int i = 0; i< el.size(); i++)
{
assert(el[i]->get_type() & Element::SOURCE);
}
#endif
m_src_elements = el;
}
const std::vector<Element *> &Cell::get_target_elements() const
{
return m_target_elements;
}
void Cell::set_target_elements(const std::vector<Element *> &el)
{
#if DEBUG
for(int i = 0; i< el.size(); i++)
{
assert(el[i]->get_type() & Element::TARGET);
}
#endif
m_target_elements = el;
}
const std::vector<Element*> Cell::get_elements() const
{
std::vector<Element*> elements(m_src_elements);
elements.insert(elements.end(),m_target_elements.begin(),m_target_elements.end());
return elements;
}
unsigned int Cell::number_of_elements() const
{
return m_src_elements.size() + m_target_elements.size();
}
Cell * const Cell::get_father() const
{
return m_father;
}
void Cell::set_father(Cell * father)
{
m_father = father;
}
std::vector<Cell*> const & Cell::get_children() const
{
return m_children;
}
unsigned int Cell::get_id() const
{
return m_id;
}
void Cell::set_id(unsigned int index)
{
m_id = index;
}
unsigned int Cell::get_dimension() const
{
return m_dim;
}
Point const & Cell::get_center() const
{
return m_center;
}
void Cell::set_center(Point const & center)
{
m_center = center;
}
const std::vector<double> & Cell::get_moments() const
{
return m_moments;
}
const std::vector<complex_t>& Cell::get_moments_cmp() const
{
return m_moments_cmp;
}
bool Cell::is_leaf() const
{
return m_children.empty();
}
void Cell::set_level(unsigned int lvl)
{
m_level = lvl;
}
unsigned int Cell::get_level() const
{
return m_level;
}
const double Cell::get_size() const
{
return m_size;
}
void Cell::set_moments(std::vector<double> const & moments)
{
m_moments = moments;
}
void Cell::set_moments_cmp(std::vector<complex_t> const & moments_cmp)
{
m_moments_cmp = moments_cmp;
}
void Cell::init_empty_lists(unsigned int num_lists)
{
m_lists = std::vector<std::map<unsigned int, Cell*> >(num_lists,std::map<unsigned int, Cell*>());
}
void Cell::add_to_list(Cell* const cell, unsigned int list_number)
{
#if DEBUG
assert(m_lists.size() > list_number);
#endif
m_lists[list_number].insert(std::make_pair(cell->get_id(),cell));
}
std::vector<Cell*> Cell::get_list(unsigned int list_number) const
{
#if DEBUG
assert(list_number < m_lists.size());
#endif
std::vector<Cell*> linearized_list;
std::map<unsigned int, Cell*> const & sel_list = m_lists.at(list_number);
std::map<unsigned int, Cell*>::const_iterator it = sel_list.begin();
for(; it != sel_list.end(); ++it)
{
linearized_list.push_back(it->second);
}
return linearized_list;
}
std::vector<unsigned int> Cell::get_list_ids(unsigned int list_number) const
{
#if DEBUG
assert(list_number < m_lists.size());
#endif
std::vector<unsigned int> linearized_list_ids;
std::map<unsigned int, Cell*> const & sel_list = m_lists.at(list_number);
std::map<unsigned int, Cell*>::const_iterator it = sel_list.begin();
for(; it != sel_list.end(); ++it)
{
linearized_list_ids.push_back(it->first);
}
return linearized_list_ids;
}
bool Cell::has_level_grid_position() const
{
return m_has_grid_pos;
}
const Point &Cell::get_level_grid_position() const
{
return m_grid_pos;
}
void Cell::set_level_grid_position(const Point &grid_pos)
{
#if DEBUG
assert(grid_pos.get_dimension() == m_dim);
#endif
m_grid_pos = grid_pos;
m_has_grid_pos = true;
}
const std::vector<double> & Cell::get_local_exps() const
{
return m_local_exps;
}
const std::vector<complex_t> & Cell::get_local_exps_cmp() const
{
return m_local_exps_cmp;
}
void Cell::set_local_exps(std::vector<double> const & local_exps)
{
m_local_exps = local_exps;
}
void Cell::set_local_exps_cmp(std::vector<complex_t> const & local_exps_cmp)
{
m_local_exps_cmp = local_exps_cmp;
}
void Cell::set_leaf_block_start_pos(int leaf_block_start_pos)
{
m_leaf_block_start_pos = leaf_block_start_pos;
}
int Cell::get_leaf_block_start_pos() const
{
return m_leaf_block_start_pos;
}
int Cell::get_leaf_number() const
{
return m_leaf_number;
}
void Cell::set_leaf_number(int leaf_number)
{
m_leaf_number = leaf_number;
}
std::string Cell::debug_info() const
{
std::stringstream sstr;
sstr << "Cell(id:" <<m_id<<", lvl:"<<m_level <<
", pos:" << m_grid_pos << ((is_leaf())?", lf":", fa") << ")";
return sstr.str();
}