-
Notifications
You must be signed in to change notification settings - Fork 16
/
ACELECTRIC.cpp
234 lines (211 loc) · 7.8 KB
/
ACELECTRIC.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
/*
* ACELECTRONIC.cpp
*
* Created on: Aug 1, 2011
* Author: tony
*/
#include "ACELECTRIC.h"
#include "KERNEL.h"
#include "math.h"
namespace std {
AC_ELECTRIC::AC_ELECTRIC(STORAGE *store,SOLVE_BASE *solve):AC_BASE(store,solve) {
// TODO Auto-generated constructor stub
}
AC_ELECTRIC::~AC_ELECTRIC() {
// TODO Auto-generated destructor stub
}
void AC_ELECTRIC::doit()
{
int ly2=0; //!initial zeroing of variable
int kind_p1 = 2;
int ini_kind_p2=kind_p1%2+1;// !Gives the alternative value to kind_p2 of kind_p1
int ncn = store->ncn,ncm = store->ncm,ncl=store->ncl;
for (int lz = 1;lz<=ncl;lz++)
for (int ly = 1;ly<=ncm;ly++)
for (int lx = 1;lx<=ncn;lx++)
{
size_t j1 = lx + (ly-1)*ncn +(lz-1)*ncn*ncm;
j1--;
//if(store->cells[j1].nc[kind_p1-1] > 0)
if ((kind_p1 == 1)?(store->nc_k1[j1]>0):(store->nc_k2[j1]>0))
{
//c ! if the cell is not empty, then
//c ! loop over it and over neighboring
//c ! cells
int lx2 = lx+1;
if(lx2<=ncn)
celij(j1,j1+1,kind_p1,ini_kind_p2,ly2); //!East
int ly2 = ly+1;
if(ly2<=ncm)
{
celij(j1,j1+ncn,kind_p1,ini_kind_p2,ly2); //!North
lx2 = lx-1;
if(lx2>=1) celij(j1,j1+ncn-1,kind_p1,ini_kind_p2,ly2); //!N-West
lx2 = lx+1;
if(lx2<=ncn) celij(j1,j1+ncn+1,kind_p1,ini_kind_p2,ly2); //!N-East
}
//c -- Cells in the next XY sheet --
int lz2=lz+1;
if(lz2<=ncl)
{
// !- Same row -
celij(j1,j1+ncn*ncm,kind_p1,ini_kind_p2,ly2); //!Up
lx2=lx-1;
if(lx2>=1) celij(j1,j1+ncn*ncm-1,kind_p1,ini_kind_p2,ly2); //!Up & West
lx2=lx+1;
if(lx2<=ncn) celij(j1,j1+ncn*ncm+1,kind_p1,ini_kind_p2,ly2); //!Up & East
// !- Next row -
ly2=ly+1;
if(ly2<=ncm)
{
celij(j1,j1+ncn*ncm+ncn,kind_p1,ini_kind_p2,ly2); //!Up & North
lx2=lx-1;
if(lx2>=1)
celij(j1,j1+ncn*ncm+ncn-1,kind_p1,ini_kind_p2,ly2); //!Up & North-West
lx2=lx+1;
if(lx2<=ncn)
celij(j1,j1+ncn*ncm+ncn+1,kind_p1,ini_kind_p2,ly2); //!Up & North-East
}
// !- Previous row -
ly2=ly-1;
if(ly2>=1)
{
celij(j1,j1+ncn*ncm-ncn,kind_p1,ini_kind_p2,ly2); //!Up & South
lx2=lx-1;
if(lx2>=1) celij(j1,j1+ncn*ncm-ncn-1,kind_p1,ini_kind_p2,ly2); //!Up & SouthWest
lx2=lx+1;
if(lx2<=ncn) celij(j1,j1+ncn*ncm-ncn+1,kind_p1,ini_kind_p2,ly2); //!Up & SouthEast
}
}
}
}
for (size_t j1 = 0;j1<store->nx;j1++)
if ((kind_p1 == 1)?(store->nc_k1[j1]>0):(store->nc_k2[j1]>0))
self(j1,kind_p1,ini_kind_p2);
return;
}
void AC_ELECTRIC::self(int j1,int kind_p1,int ini_kind_p2)
{
int kind_p2 = 2;
vector<size_t>::iterator itjstart = ((kind_p2 == 1)?(store->ibox_k1[j1].begin()):(store->ibox_k2[j1].begin()));
vector<size_t>::iterator iti=((kind_p1 == 1)?(store->ibox_k1[j1].begin()):(store->ibox_k2[j1].begin()));
for(;iti!=((kind_p1 == 1)?(store->ibox_k1[j1].end()):(store->ibox_k2[j1].end()));++iti)
{
size_t i;
i=*iti;
if(kind_p1 == kind_p2) itjstart++;
vector<size_t>::iterator itj;
for (itj = itjstart;itj!=((kind_p2 == 1)?(store->ibox_k1[j1].end()):(store->ibox_k2[j1].end()));++itj)
{
size_t j;
j=*itj;
double drx = store->xp[i] - store->xp[j];
double dry = (store->dim == 3)?(store->yp[i] - store->yp[j]):0;
double drz = store->zp[i] - store->zp[j];
double rr2 = drx*drx + dry*dry + drz*drz;
solve->kernel_func->kernel(drx,dry,drz,i,j,j1,j1,rr2);
solve->kernel_correction_func->kernel_correction(i,j);
if(rr2 < 4 * store->h * store->h && rr2 > 1.e-18)
{
if (i_ELE_part == 1)
{
double ubi[3],ubj[3];
store->GetUxB(ubi,i);
store->GetUxB(ubj,j);
double temp[3];
temp[0] = ubi[0]/(store->rho[i]*store->rho[i]) + ubj[0]/(store->rho[j]*store->rho[j]);
temp[1] = ubi[1]/(store->rho[i]*store->rho[i]) + ubj[1]/(store->rho[j]*store->rho[j]);
temp[2] = ubi[2]/(store->rho[i]*store->rho[i]) + ubj[2]/(store->rho[j]*store->rho[j]);
store->dUxB[i]+=store->rho[i]*store->pm[j]*(temp[0]*store->frxi+temp[1]*store->fryi+temp[2]*store->frzi);
store->dUxB[j]+=-store->rho[j]*store->pm[i]*(temp[0]*store->frxj+temp[1]*store->fryj+temp[2]*store->frzj);
}
else if (i_ELE_part == 2)
{
double index;
index = 4 / (store->rho[i] + store->rho[j]);
index = index * store->frxi*drx+store->fryi*dry+store->frzi*drz / (rr2 + 0.01*store->h*store->h);
store->m_pSolver->Add_A(i, i, index * store->pm[j]);
store->m_pSolver->Add_A(i, j, -index * store->pm[j]);
store->m_pSolver->Add_A(j, j, index * store->pm[i]);
store->m_pSolver->Add_A(j, i, -index * store->pm[i]);
}
else
{
double index;
index=(store->Phi[i]/store->rho[i]+store->Phi[j]/store->rho[j]);
store->GPx[i]+=store->pm[j]*index*store->frxi;
store->GPy[i]+=store->pm[j]*index*store->fryi;
store->GPz[i]+=store->pm[j]*index*store->frzi;
store->GPx[j]+=-store->pm[i]*index*store->frxj;
store->GPy[j]+=-store->pm[i]*index*store->fryj;
store->GPz[j]+=-store->pm[i]*index*store->frzj;
}
}
}
}
}
void AC_ELECTRIC::celij(int j1,int j2,int kind_p1,int ini_kind_p2,int ly2)
{
double kind_p2 = 2;
if((kind_p2 == 1)?(store->nc_k1[j2]>0):(store->nc_k2[j2]>0))
{
vector<size_t>::iterator iti=((kind_p1 == 1)?(store->ibox_k1[j1].begin()):(store->ibox_k2[j1].begin()));
for(;iti!=((kind_p1 == 1)?(store->ibox_k1[j1].end()):(store->ibox_k2[j1].end()));++iti)
{
size_t i;
i = *iti;
vector<size_t>::iterator itj=((kind_p2 == 1)?(store->ibox_k1[j2].begin()):(store->ibox_k2[j2].begin()));
for (;itj!=((kind_p2 == 1)?(store->ibox_k1[j2].end()):(store->ibox_k2[j2].end()));++itj)
{
size_t j;
j = *itj;
double drx = store->xp[i] - store->xp[j];
double dry = (store->dim == 3)?(store->yp[i] - store->yp[j]):0;
double drz = store->zp[i] - store->zp[j];
double rr2 = drx*drx + dry*dry + drz*drz;
if(rr2 < 4 * store->h * store->h && rr2 > 1.e-18)
{
solve->kernel_func->kernel(drx,dry,drz,i,j,j1,j1,rr2);
solve->kernel_correction_func->kernel_correction(i,j);
if(rr2 < 4 * store->h * store->h && rr2 > 1.e-18)
{
if (i_ELE_part == 1)
{
double ubi[3],ubj[3];
store->GetUxB(ubi,i);
store->GetUxB(ubj,j);
double temp[3];
temp[0] = ubi[0]/(store->rho[i]*store->rho[i]) + ubj[0]/(store->rho[j]*store->rho[j]);
temp[1] = ubi[1]/(store->rho[i]*store->rho[i]) + ubj[1]/(store->rho[j]*store->rho[j]);
temp[2] = ubi[2]/(store->rho[i]*store->rho[i]) + ubj[2]/(store->rho[j]*store->rho[j]);
store->dUxB[i]+=store->rho[i]*store->pm[j]*(temp[0]*store->frxi+temp[1]*store->fryi+temp[2]*store->frzi);
store->dUxB[j]+=-store->rho[j]*store->pm[i]*(temp[0]*store->frxj+temp[1]*store->fryj+temp[2]*store->frzj);
}
else if (i_ELE_part == 2)
{
double index;
index = 4 / (store->rho[i] + store->rho[j]);
index = index * store->frxi*drx+store->fryi*dry+store->frzi*drz / (rr2 + 0.01*store->h*store->h);
store->m_pSolver->Add_A(i, i, index * store->pm[j]);
store->m_pSolver->Add_A(i, j, -index * store->pm[j]);
store->m_pSolver->Add_A(j, j, index * store->pm[i]);
store->m_pSolver->Add_A(j, i, -index * store->pm[i]);
}
else
{
double index;
index=(store->Phi[i]/store->rho[i]+store->Phi[j]/store->rho[j]);
store->GPx[i]+=store->pm[j]*index*store->frxi;
store->GPy[i]+=store->pm[j]*index*store->fryi;
store->GPz[i]+=store->pm[j]*index*store->frzi;
store->GPx[j]+=-store->pm[i]*index*store->frxj;
store->GPy[j]+=-store->pm[i]*index*store->fryj;
store->GPz[j]+=-store->pm[i]*index*store->frzj;
}
}
}
}
}
}
}
} /* namespace std */