-
Notifications
You must be signed in to change notification settings - Fork 0
/
fmm2d_ada.cpp
179 lines (164 loc) · 5.48 KB
/
fmm2d_ada.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
/*
* File: fmm2d_ada.cpp
* Author: euklid
*
* Created on August 27, 2015, 6:39 PM
*/
#include "fmm2d_ada.h"
#include "cell2d.h"
#include "tree2d_ada.h"
FMM2D_ADA::FMM2D_ADA(const std::vector<Element*>& src_elements,
const std::vector<Element*>& tgt_elements,
unsigned int exp_terms,
unsigned int loc_terms,
unsigned int max_cell_elements,
bool src_eq_tgt)
: FMM2D(src_elements,
tgt_elements,
exp_terms,
loc_terms,
max_cell_elements,
src_eq_tgt)
{}
void FMM2D_ADA::build_tree()
{
if(m_tree)
{
delete m_tree;
}
m_tree = new Tree2D_Ada;
std::pair<double,Point> bounding_box = get_bounding_cube(m_elements);
Cell2D* root = new Cell2D(bounding_box.first, bounding_box.second);
root->set_father(0);
root->set_source_elements(m_src_elements);
root->set_target_elements(m_tgt_elements);
m_tree->set_root(root);
std::cout << "Building tree ..." << std::endl;
m_tree->build_tree(m_max_cell_elements,1);
std::cout << "Tree built." << std::endl;
}
void FMM2D_ADA::moment_to_element_downward_pass(Cell* const target)
{
std::vector<Cell*> list3 = target->get_list(2);
unsigned int num_list_elements = list3.size();
if(!num_list_elements) return;
std::vector<Element*> const & tgt_elements = target->get_target_elements();
unsigned int num_tgt_elements = tgt_elements.size();
for(unsigned int i = 0; i<num_tgt_elements; i++)
{
Element* t = tgt_elements[i];
double contrib = 0;
for(unsigned int j = 0; j< num_list_elements; j++)
{
contrib += m_kernel->M2element_cmp(list3[j]->get_moments_cmp(),
list3[j]->get_center(),
*t).real;
}
t->set_target_value(t->get_target_value() + contrib);
}
}
void FMM2D_ADA::add_locals_list4(Cell * const target)
{
std::vector<Cell*> list4 = target->get_list(3);
unsigned int num_list_elements = list4.size();
if(!num_list_elements) return;
std::vector<complex_t> loc_exps = target->get_local_exps_cmp();
if(!loc_exps.size())
{
loc_exps.resize(m_loc_terms,0);
}
for(unsigned int i = 0; i<num_list_elements; i++)
{
std::vector<Element*> const & other_cell_el = list4[i]->get_source_elements();
std::vector<complex_t> summand_loc_exps =
m_kernel->calc_local_exp_cmp(other_cell_el,
target->get_center(),
m_loc_terms);
add_moments(summand_loc_exps,loc_exps);
}
target->set_local_exps_cmp(loc_exps);
}
void FMM2D_ADA::downward_pass()
{
init_precond();
Tree_Iterator *it = m_tree->downward_iterator();
std::cout << "Downward pass started ..." << std::endl;
Cell* cur_cell;
while(it->has_next())
{
cur_cell = it->next();
if(cur_cell->get_level() > 1) break;
if(cur_cell->get_target_elements().empty()) continue;
#ifdef DEBUG
std::cout << "Downward pass: " << cur_cell->debug_info() << std::endl;
#endif
// move moments to local expansion for list 2 (interaction list)
m2l_downward_pass(cur_cell);
// L2L only from level 2 on!
if (cur_cell->is_leaf())
{
// go through neighbor list 1
direct_downward_pass(cur_cell);
// moment to element, list 3
moment_to_element_downward_pass(cur_cell);
// create local expansions about center of cur_cell for list 4 elements
add_locals_list4(cur_cell);
// evaluate local expansion in center of current cell for each
// element
evaluate_far_interactions(cur_cell);
}
}
// there are no level 2 cells
if(cur_cell->get_level() < 2)
{
delete it;
std::cout << "Downward pass finished." << std::endl;
return;
}
//reached lvl 3 or higher --> use additionally L2L
while(1)
{
if(cur_cell->get_target_elements().empty())
{
// skip this and go to next if available
if(it->has_next())
{
cur_cell = it->next();
continue;
}
else //last element, leave loop
{
break;
}
}
#ifdef DEBUG
std::cout << "Downward pass: " << cur_cell->debug_info() << std::endl;
#endif
// move moments to local expansion for list 2 (interaction list)
m2l_downward_pass(cur_cell);
// L2L
l2l_downward_pass(cur_cell);
if (cur_cell->is_leaf())
{
// go through neighbor list 1
direct_downward_pass(cur_cell);
// moment to element, list 3
moment_to_element_downward_pass(cur_cell);
// create local expansions about center of cur_cell for list 4 elements
add_locals_list4(cur_cell);
// evaluate local expansion in center of current cell for each
// element
evaluate_far_interactions(cur_cell);
}
if(it->has_next())
{
cur_cell = it->next();
}
else //last element, leave loop
{
break;
}
}
std::cout << "Downward pass finished." << std::endl;
delete it;
}