-
Notifications
You must be signed in to change notification settings - Fork 1
/
Level.cpp
150 lines (130 loc) · 4.52 KB
/
Level.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
#include "veritas.hpp"
#include "Settings.hpp"
#include "Level.hpp"
#include "Rectangle.hpp"
Level::Level(int particleType, int depth, Settings &settings) : x_size(settings.GetXSize(settings.maxDepth - depth)), p_size(settings.GetPSize(settings.maxDepth - depth, particleType)), depth(depth), particleType(particleType), settings(settings), EMSolver(NULL) {
chargeL.resize(settings.x_size_finest, 0.0);
energyL.resize(settings.p_size_finest[particleType], 0.0);
currentL.resize(settings.x_size_finest, 0.0);
}
void Level::FCTTimeStep(double timestep,int step,int subStep) {
//pragma omp parallel for schedule(guided)
for (unsigned int i = 0; i < rectangles.size(); i++) {
rectangles[i]->FCTTimeStep(timestep,step,subStep);
}
}
void Level::InterpolateRhoAndJToFinestMesh(std::vector<double> &charge, std::vector<double> &J) {
CollectRhoAndJ();
unsigned int iloop = settings.x_size_finest;
#pragma ivdep
for (unsigned int i = 0; i < iloop; i++) {
charge[i] += chargeL[i];
J[i] += currentL[i];
}
}
void Level::InterpolateEnergyToFinestMesh(std::vector<double> &energy) {
CollectEnergy();
unsigned int iloop = settings.p_size_finest[particleType];
#pragma ivdep
for (unsigned int i = 0; i < iloop; i++) {
energy[i] += energyL[i];
}
}
void Level::CollectRhoAndJ() {
unsigned int iloop = rectangles.size();
for (unsigned int i = 0; i < iloop; i++) {
rectangles[i]->CalculateRhoAndJ();
}
std::fill(chargeL.begin(), chargeL.end(), 0.0);
std::fill(currentL.begin(), currentL.end(), 0.0);
//no omp
for (unsigned int i = 0; i < iloop; i++) {
int shift = rectangles[i]->x_pos;
unsigned int jloop = rectangles[i]->chargeR.size();
#pragma ivdep
for (unsigned int j = 0; j < jloop; j++) {
int rtb = (int)rectangles[i]->relativeToBottom;
chargeL[shift * rtb + j] += rectangles[i]->chargeR[j];
currentL[shift * rtb + j] += rectangles[i]->currentR[j];
}
}
}
void Level::CollectEnergy() {
for (unsigned int i = 0; i < rectangles.size(); i++) {
rectangles[i]->CalculateEnergy();
}
std::fill(energyL.begin(), energyL.end(), 0.0);
for (auto &r: rectangles) {
int shift = r->p_pos;
int rtb = r->relativeToBottom;
for (unsigned int i = 0; i < r->energyR.size(); i++) {
energyL[shift * rtb + i] += r->energyR[i];
}
}
}
void Level::SetFieldSolver(const std::shared_ptr<EMFieldSolver> &solver) {
EMSolver = solver;
for (auto &r: rectangles) {
r->SetFieldSolver(EMSolver);
}
}
void Level::PushData(int updateType,int val) {
switch (updateType) {
case 0:
for (auto &r: rectangles) {
r->UpdateInterriorPoints(val);
}
break;
case 1:
for (auto &r: rectangles) {
r->UpdateSameLevelBoundaries(val);
}
break;
case 2:
for (auto &r: rectangles) {
r->UpdateDifferentLevelBoundaries(val);
}
break;
case 3:
for (auto &r: rectangles) {
r->UpdateCornerPoints(val);
}
break;
case 4:
for (auto &r: rectangles) {
r->CalculateSameBoundaryC();
}
break;
case 5:
for (auto &r: rectangles) {
r->CalculateDifferentBoundaryC();
}
break;
case 6:
for (auto &r: rectangles) {
r->UpdateSameBoundaryC();
}
break;
}
}
void Level::GetDataFromSameLevel(const std::unique_ptr<Level> &level) {
for (unsigned int i = 0; i < level->rectangles.size(); i++) {
for (unsigned int j = 0; j < rectangles.size(); j++) {
level->rectangles[i]->GetDataFromSameLevelRectangle(rectangles[j]);
}
}
}
void Level::GetDataFromCoarserLevel(const std::unique_ptr<Level> &level) {
for (unsigned int i = 0; i < level->rectangles.size(); i++) {
for (unsigned int j = 0; j < rectangles.size(); j++) {
level->rectangles[i]->GetDataFromCoarseLevelRectangle(rectangles[j]);
}
}
}
void Level::GetDataFromCoarseNewLevel(const std::unique_ptr<Level> &level) {
for (unsigned int i = 0; i < level->rectangles.size(); i++) {
for (unsigned int j = 0; j < rectangles.size(); j++) {
level->rectangles[i]->GetDataFromCoarseNewLevelRectangle(rectangles[j]);
}
}
}