forked from pcoulier/hbemfun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bemxfer3d.cpp
271 lines (251 loc) · 10.7 KB
/
bemxfer3d.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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#include "eltdef.h"
#include "bemcollpoints.h"
#include "gausspw.h"
#include "shapefun.h"
#include "bemnormal.h"
#include "greeneval3d.h"
#include "greenrotate3d.h"
#include "boundaryrec3d.h"
#include <math.h>
#include <new>
using namespace std;
inline double sign(const double& a)
{
if (a==0.0) return 1.0;
else return (a>0.0 ? 1.0 : -1.0);
}
inline double sqr(const double& a)
{
return a*a;
}
//======================================================================
// THREE-DIMENSIONAL BOUNDARY ELEMENT INTEGRATION
//======================================================================
void bemxfer3d(const double* const Nod,const unsigned int& nNod,
const double* const Elt,const unsigned int& iElt,
const unsigned int& nElt, const unsigned int* const EltCollIndex,
const double* const Rec, const unsigned int nRec,
bool* const boundaryRec,
double* const URe, double* const UIm,
double* const TRe, double* const TIm,
const bool UmatOut,
const bool TmatOut,
const unsigned int& nDof, const unsigned int& nRecDof,
const unsigned int* const TypeID,const unsigned int* const nKeyOpt,
const char* const* TypeName, const char* const* TypeKeyOpts,
const unsigned int& nEltType,
const void* const* const greenPtr, const unsigned int& nGrSet,
const bool& ugCmplx, const bool& tgCmplx)
{
// ELEMENT PROPERTIES
const unsigned int EltType = (unsigned int)(Elt[nElt+iElt]);
unsigned int Parent;
unsigned int nEltNod;
unsigned int nEltColl;
unsigned int ShapeTypeN;
unsigned int ShapeTypeM;
unsigned int EltDim;
unsigned int AxiSym;
unsigned int Periodic;
unsigned int nGauss;
unsigned int nEltDiv;
unsigned int nGaussSing;
unsigned int nEltDivSing;
eltdef(EltType,TypeID,TypeName,TypeKeyOpts,nKeyOpt,nEltType,Parent,nEltNod,
nEltColl,ShapeTypeN,ShapeTypeM,EltDim,AxiSym,Periodic,nGauss,nEltDiv,
nGaussSing,nEltDivSing);
// NUMBER OF GAUSSIAN POINTS
unsigned int nXi;
if (Parent == 1) nXi=nGauss;
else if (Parent == 2) nXi=nEltDiv*nEltDiv*nGauss*nGauss;
int NodIndex;
unsigned int NodID;
double* const EltNod =new(nothrow) double[3*nEltNod];
if (EltNod==0) throw("Out of memory.");
// DETERMINE COORDINATES OF ELEMENT NODES (OF ELEMENT IELT)
for (unsigned int iEltNod=0; iEltNod<nEltNod; iEltNod++)
{
NodID=(unsigned int)(Elt[(2+iEltNod)*nElt+iElt]);
BemNodeIndex(Nod,nNod,NodID,NodIndex);
EltNod[0*nEltNod+iEltNod]=Nod[1*nNod+NodIndex];
EltNod[1*nEltNod+iEltNod]=Nod[2*nNod+NodIndex];
EltNod[2*nEltNod+iEltNod]=Nod[3*nNod+NodIndex];
}
// DETERMINE SAMPLE POINTS FOR THE ELEMENT TYPE (NumGauss * NumEltDiv).
double* const xi=new(nothrow) double[2*nXi];
if (xi==0) throw("Out of memory.");
double* const H=new(nothrow) double[nXi];
if (H==0) throw("Out of memory.");
if (Parent == 1) gausspwtri(nGauss,xi,H);
else gausspw2D(nEltDiv,nGauss,xi,H);
// SHAPE FUNCTIONS IN THE SAMPLE POINTS
double* const N=new(nothrow) double[nXi*nEltNod];
if (N==0) throw("Out of memory.");
double* const M=new(nothrow) double[nXi*nEltColl];
if (M==0) throw("Out of memory.");
double* const dN=new(nothrow) double[2*nXi*nEltNod];
if (dN==0) throw("Out of memory.");
double* const nat=new(nothrow) double[6*nXi];
if (nat==0) throw("Out of memory.");
double* const Jac=new(nothrow) double[nXi];
if (Jac==0) throw("Out of memory.");
double* const xiCart=new(nothrow) double[3*nXi];
if (xiCart==0) throw("Out of memory.");
double* const normal=new(nothrow) double[3*nXi];
if (normal==0) throw("Out of memory.");
shapefun(ShapeTypeN,nXi,xi,N);
shapefun(ShapeTypeM,nXi,xi,M);
shapederiv(ShapeTypeN,nXi,xi,dN);
shapenatcoord(dN,nEltNod,nXi,EltNod,nat,EltDim);
jacobian(nat,nXi,Jac,EltDim);
bemnormal(nat,nXi,EltDim,normal);
// NODAL COORDINATES
for (unsigned int icomp=0; icomp<3*nXi; icomp++) xiCart[icomp]=0.0;
for (unsigned int iXi=0; iXi<nXi; iXi++)
{
for (unsigned int iEltNod=0; iEltNod<nEltNod; iEltNod++)
{
xiCart[3*iXi+0]+=N[nEltNod*iXi+iEltNod]*EltNod[0*nEltNod+iEltNod];
xiCart[3*iXi+1]+=N[nEltNod*iXi+iEltNod]*EltNod[1*nEltNod+iEltNod];
xiCart[3*iXi+2]+=N[nEltNod*iXi+iEltNod]*EltNod[2*nEltNod+iEltNod];
}
}
double* const UgrRe=new(nothrow) double[5*nGrSet];
if (UgrRe==0) throw("Out of memory.");
double* const UgrIm=new(nothrow) double[5*nGrSet];
if (UgrIm==0) throw("Out of memory.");
double* const TgrRe=new(nothrow) double[10*nGrSet];
if (TgrRe==0) throw("Out of memory.");
double* const TgrIm=new(nothrow) double[10*nGrSet];
if (TgrIm==0) throw("Out of memory.");
double* const Tgr0Re=0;
double* const Tgr0Im=0;
double* const UXiRe=new(nothrow) double[9*nGrSet];
if (UXiRe==0) throw("Out of memory.");
double* const UXiIm=new(nothrow) double[9*nGrSet];
if (UXiIm==0) throw("Out of memory.");
double* const TXiRe=new(nothrow) double[9*nGrSet];
if (TXiRe==0) throw("Out of memory.");
double* const TXiIm=new(nothrow) double[9*nGrSet];
if (TXiIm==0) throw("Out of memory.");
double* const TXi0Re=0;
double* const TXi0Im=0;
// INITIALIZE INTERPOLATION OF GREEN'S FUNCTION
unsigned int r1=0;
unsigned int r2=1;
bool extrapFlag=false;
double* const interpr=new(nothrow) double[2];
if (interpr==0) throw("Out of memory.");
unsigned int z1=0;
unsigned int z2=1;
double* const interpz=new(nothrow) double[2];
if (interpz==0) throw("Out of memory.");
unsigned int zs1=0;
for (unsigned int iComp=0; iComp<9*nGrSet;iComp++)
{
UXiRe[iComp]=0.0;
UXiIm[iComp]=0.0;
TXiRe[iComp]=0.0;
TXiIm[iComp]=0.0;
}
for (unsigned int iRec=0; iRec<nRec; iRec++)
{
if (!(boundaryRec[iRec])) // If receiver not on interface
{
for (unsigned int iXi=0; iXi<nXi; iXi++)
{
const double Xdiff=xiCart[3*iXi+0]-Rec[0*nRec+iRec];
const double Ydiff=xiCart[3*iXi+1]-Rec[1*nRec+iRec];
const double Zdiff=xiCart[3*iXi+2]-Rec[2*nRec+iRec];
const double xiR=sqrt(Xdiff*Xdiff + Ydiff*Ydiff);
const double xiTheta=atan2(Ydiff,Xdiff);
const double xiZ=Zdiff;
// EVALUATE GREEN'S FUNCTION
const bool tg0Cmplx=false;
const unsigned int zPos=2;
greeneval3d(greenPtr,nGrSet,ugCmplx,tgCmplx,tg0Cmplx,xiR,xiZ,r1,r2,
z1,z2,zs1,interpr,interpz,extrapFlag,UmatOut,TmatOut,Rec,nRec,
iRec,zPos,UgrRe,UgrIm,TgrRe,TgrIm,Tgr0Re,Tgr0Im);
greenrotate3d(normal,iXi,xiTheta,nGrSet,ugCmplx,tgCmplx,tg0Cmplx,
UgrRe,UgrIm,TgrRe,TgrIm,Tgr0Re,Tgr0Im,UXiRe,UXiIm,
TXiRe,TXiIm,TXi0Re,TXi0Im,UmatOut,TmatOut);
// SUM UP RESULTS, FOR ALL COLLOCATION POINTS
for (unsigned int iEltColl=0; iEltColl<nEltColl; iEltColl++)
{
double sumutil=H[iXi]*M[nEltColl*iXi+iEltColl]*Jac[iXi];
unsigned int rowBeg=3*iRec;
unsigned int colBeg=3*EltCollIndex[iEltColl];
for (unsigned int iGrSet=0; iGrSet<nGrSet; iGrSet++)
{
const unsigned int ind0 =nRecDof*nDof*iGrSet;
URe[ind0+nRecDof*(colBeg+0)+rowBeg+0] += sumutil*UXiRe[9*iGrSet+0]; // ugxx
URe[ind0+nRecDof*(colBeg+1)+rowBeg+0] += sumutil*UXiRe[9*iGrSet+1]; // ugxy
URe[ind0+nRecDof*(colBeg+2)+rowBeg+0] += sumutil*UXiRe[9*iGrSet+2]; // ugxz
URe[ind0+nRecDof*(colBeg+0)+rowBeg+1] += sumutil*UXiRe[9*iGrSet+3]; // ugyx
URe[ind0+nRecDof*(colBeg+1)+rowBeg+1] += sumutil*UXiRe[9*iGrSet+4]; // ugyy
URe[ind0+nRecDof*(colBeg+2)+rowBeg+1] += sumutil*UXiRe[9*iGrSet+5]; // ugyz
URe[ind0+nRecDof*(colBeg+0)+rowBeg+2] += sumutil*UXiRe[9*iGrSet+6]; // ugzx
URe[ind0+nRecDof*(colBeg+1)+rowBeg+2] += sumutil*UXiRe[9*iGrSet+7]; // ugzy
URe[ind0+nRecDof*(colBeg+2)+rowBeg+2] += sumutil*UXiRe[9*iGrSet+8]; // ugzz
if (ugCmplx)
{
UIm[ind0+nRecDof*(colBeg+0)+rowBeg+0] += sumutil*UXiIm[9*iGrSet+0];
UIm[ind0+nRecDof*(colBeg+1)+rowBeg+0] += sumutil*UXiIm[9*iGrSet+1];
UIm[ind0+nRecDof*(colBeg+2)+rowBeg+0] += sumutil*UXiIm[9*iGrSet+2];
UIm[ind0+nRecDof*(colBeg+0)+rowBeg+1] += sumutil*UXiIm[9*iGrSet+3];
UIm[ind0+nRecDof*(colBeg+1)+rowBeg+1] += sumutil*UXiIm[9*iGrSet+4];
UIm[ind0+nRecDof*(colBeg+2)+rowBeg+1] += sumutil*UXiIm[9*iGrSet+5];
UIm[ind0+nRecDof*(colBeg+0)+rowBeg+2] += sumutil*UXiIm[9*iGrSet+6];
UIm[ind0+nRecDof*(colBeg+1)+rowBeg+2] += sumutil*UXiIm[9*iGrSet+7];
UIm[ind0+nRecDof*(colBeg+2)+rowBeg+2] += sumutil*UXiIm[9*iGrSet+8];
}
if (TmatOut)
{
TRe[ind0+nRecDof*(colBeg+0)+rowBeg+0] += sumutil*TXiRe[9*iGrSet+0]; // txx
TRe[ind0+nRecDof*(colBeg+1)+rowBeg+0] += sumutil*TXiRe[9*iGrSet+1]; // txy
TRe[ind0+nRecDof*(colBeg+2)+rowBeg+0] += sumutil*TXiRe[9*iGrSet+2]; // txz
TRe[ind0+nRecDof*(colBeg+0)+rowBeg+1] += sumutil*TXiRe[9*iGrSet+3]; // tyx
TRe[ind0+nRecDof*(colBeg+1)+rowBeg+1] += sumutil*TXiRe[9*iGrSet+4]; // tyy
TRe[ind0+nRecDof*(colBeg+2)+rowBeg+1] += sumutil*TXiRe[9*iGrSet+5]; // tyz
TRe[ind0+nRecDof*(colBeg+0)+rowBeg+2] += sumutil*TXiRe[9*iGrSet+6]; // tzx
TRe[ind0+nRecDof*(colBeg+1)+rowBeg+2] += sumutil*TXiRe[9*iGrSet+7]; // tzy
TRe[ind0+nRecDof*(colBeg+2)+rowBeg+2] += sumutil*TXiRe[9*iGrSet+8]; // tzz
if (tgCmplx)
{
TIm[ind0+nRecDof*(colBeg+0)+rowBeg+0] += sumutil*TXiIm[9*iGrSet+0];
TIm[ind0+nRecDof*(colBeg+1)+rowBeg+0] += sumutil*TXiIm[9*iGrSet+1];
TIm[ind0+nRecDof*(colBeg+2)+rowBeg+0] += sumutil*TXiIm[9*iGrSet+2];
TIm[ind0+nRecDof*(colBeg+0)+rowBeg+1] += sumutil*TXiIm[9*iGrSet+3];
TIm[ind0+nRecDof*(colBeg+1)+rowBeg+1] += sumutil*TXiIm[9*iGrSet+4];
TIm[ind0+nRecDof*(colBeg+2)+rowBeg+1] += sumutil*TXiIm[9*iGrSet+5];
TIm[ind0+nRecDof*(colBeg+0)+rowBeg+2] += sumutil*TXiIm[9*iGrSet+6];
TIm[ind0+nRecDof*(colBeg+1)+rowBeg+2] += sumutil*TXiIm[9*iGrSet+7];
TIm[ind0+nRecDof*(colBeg+2)+rowBeg+2] += sumutil*TXiIm[9*iGrSet+8];
}
}
}
}
}
}
}
delete [] EltNod;
delete [] xi;
delete [] H;
delete [] N;
delete [] M;
delete [] dN;
delete [] nat;
delete [] Jac;
delete [] normal;
delete [] xiCart;
delete [] interpr;
delete [] interpz;
delete [] UgrRe;
delete [] UgrIm;
delete [] TgrRe;
delete [] TgrIm;
delete [] UXiRe;
delete [] UXiIm;
delete [] TXiRe;
delete [] TXiIm;
}