-
Notifications
You must be signed in to change notification settings - Fork 4
/
planewavefe.hpp
382 lines (346 loc) · 12.1 KB
/
planewavefe.hpp
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
#ifndef FILE_PLANEWAVEELEMENT_HPP
#define FILE_PLANEWAVEELEMENT_HPP
#include <fem.hpp>
#include "ngsttd.hpp"
#include "scalarmappedfe.hpp"
namespace ngfem
{
template <int D> class PlaneWaveElement : public ScalarMappedElement<D>
{
private:
Vec<D> GetDirection (int i) const;
bool iscomplex = true;
int conj;
double elsize;
double c;
public:
PlaneWaveElement (int andof, int aord, ELEMENT_TYPE aeltype,
Vec<D> ashift = 0, double aelsize = 1, double ac = 1.0,
int aconj = 1)
: ScalarMappedElement<D> (andof, aord, Matrix<> (), aeltype, ashift,
1.0),
elsize (aelsize), c (ac), conj (aconj)
{
;
}
using ScalarMappedElement<D>::CalcMappedDShape;
using ScalarMappedElement<D>::Evaluate;
using ScalarMappedElement<D>::EvaluateGrad;
using ScalarMappedElement<D>::AddGradTrans;
bool ComplexShapes () const override { return true; }
Vec<D> EvaluateGrad (const BaseMappedIntegrationPoint &ip,
BareSliceVector<> x) const override
{
throw Exception ("EvaluateGrad only complex for PW ");
}
void CalcShape (const BaseMappedIntegrationPoint &mip,
BareSliceVector<> shape) const override
{
throw Exception ("CalcShape only complex for PW ");
}
void CalcShape (const BaseMappedIntegrationRule &mir,
BareSliceMatrix<> shape) const override
{
throw Exception ("CalcShape only complex for PW ");
}
void CalcDShape (const BaseMappedIntegrationPoint &mip,
BareSliceMatrix<> dshape) const override
{
throw Exception ("CalcDShape only complex for PW ");
}
void CalcDShape (const BaseMappedIntegrationRule &mir,
BareSliceMatrix<> dshapes) const override
{
throw Exception ("CalcDShape only complex for PW ");
}
void CalcMappedDDShape (const BaseMappedIntegrationPoint &bmip,
BareSliceMatrix<> hddshape) const override
{
throw Exception ("Not implemented for PW ");
}
void CalcShape (const SIMD_BaseMappedIntegrationRule &smir,
BareSliceMatrix<SIMD<double>> shape) const override
{
throw ExceptionNOSIMD ("SIMD - CalcShape not overloaded");
}
void CalcDShape (const SIMD_BaseMappedIntegrationRule &smir,
BareSliceMatrix<SIMD<double>> dshape) const override
{
throw ExceptionNOSIMD ("SIMD - CalcShape not overloaded");
}
NGST_DLL virtual void
Evaluate (const BaseMappedIntegrationRule &mir,
BareSliceVector<Complex> coefs, FlatVector<Complex> vals) const;
NGST_DLL virtual Complex
EvaluateComplex (const BaseMappedIntegrationPoint &mip,
BareSliceVector<Complex> x) const;
void CalcShape (const BaseMappedIntegrationPoint &mip,
BareSliceVector<Complex> shape) const override;
void CalcDShape (const BaseMappedIntegrationPoint &mip,
BareSliceMatrix<Complex> dshape) const;
void CalcDShape (const BaseMappedIntegrationRule &mir,
BareSliceMatrix<Complex> dshapes) const
{
for (size_t i = 0; i < mir.Size (); i++)
CalcDShape (mir[i], dshapes.Cols (i * D, (i + 1) * D));
}
Vec<D> EvaluateGrad (const BaseMappedIntegrationPoint &ip,
BareSliceVector<Complex> x) const
{
throw Exception ("OII");
}
INLINE const FlatMatrixFixWidth<D, Complex>
GetDShapeComplex (const BaseMappedIntegrationPoint &mip,
LocalHeap &lh) const
{
FlatMatrixFixWidth<D, Complex> dshape (this->ndof, lh);
CalcDShape (mip, dshape);
return dshape;
}
virtual Vec<D, Complex>
EvaluateGradComplex (const BaseMappedIntegrationPoint &ip,
BareSliceVector<Complex> x) const;
};
/// Identity
template <int D, typename FEL = PlaneWaveElement<D>>
class DiffOpMappedComplex : public DiffOp<DiffOpMappedComplex<D, FEL>>
{
public:
enum
{
DIM = 1
};
enum
{
DIM_SPACE = D
};
enum
{
DIM_ELEMENT = D
};
enum
{
DIM_DMAT = 1
};
enum
{
DIFFORDER = 0
};
static string Name () { return "Id"; }
static constexpr bool SUPPORT_PML = true;
static const FEL &Cast (const FiniteElement &fel)
{
return static_cast<const FEL &> (fel);
}
static void
GenerateMatrix (const FiniteElement &fel,
const BaseMappedIntegrationPoint &mip,
BareSliceMatrix<double, ColMajor> mat, LocalHeap &lh)
{
throw Exception ("Not implemented for complex DiffOp");
}
static void
GenerateMatrix (const FiniteElement &fel,
const BaseMappedIntegrationPoint &mip,
BareSliceMatrix<Complex, ColMajor> mat, LocalHeap &lh)
{
Cast (fel).CalcShape (mip, mat.Row (0));
}
template <typename MAT>
static void GenerateMatrixIR (const FiniteElement &fel,
const BaseMappedIntegrationRule &mir,
MAT &mat, LocalHeap &lh)
{
Cast (fel).CalcShape (mir, Trans (mat));
}
template <typename MIP, class TVX, class TVY>
static void Apply (const FiniteElement &fel, const MIP &mip, const TVX &x,
TVY &y, LocalHeap &lh)
{
throw Exception ("Not implemented for complex DiffOp");
}
static void
Apply (const FiniteElement &fel, const MappedIntegrationPoint<D, D> &mip,
const BareSliceVector<Complex> &x, FlatVector<Complex> &y,
LocalHeap &lh)
{
y (0) = Cast (fel).EvaluateComplex (mip, x);
}
template <class MIR, class TMY>
static void ApplyIR (const FiniteElement &fel, const MIR &mir,
BareSliceVector<double> x, TMY y, LocalHeap &lh)
{
throw Exception ("Not implemented for complex DiffOp");
}
template <class MIR>
static void
ApplyIR (const FiniteElement &fel, const MIR &mir,
BareSliceVector<Complex> x, SliceMatrix<Complex> y, LocalHeap &lh)
{
Cast (fel).Evaluate (mir, x,
FlatVector<Complex> (mir.Size (), &y (0, 0)));
}
template <typename MIP, class TVX, class TVY>
static void ApplyTrans (const FiniteElement &fel, const MIP &mip,
const TVX &x, TVY &y, LocalHeap &lh)
{
throw Exception ("Not implemented for complex DiffOp");
}
template <typename MIR, class TVX, class TVY>
static void ApplyTransIR (const FiniteElement &fel, const MIR &mir,
const TVX &x, TVY &y, LocalHeap &lh)
{
y.Range (0, DIM * fel.GetNDof ()) = 0.0;
for (size_t i = 0; i < mir.Size (); i++)
{
HeapReset hr (lh);
ApplyTransAdd (fel, mir[i], x.Row (i), y, lh);
}
}
template <typename MIP, class TVX, class TVY>
static void ApplyTransAdd (const FiniteElement &fel, const MIP &mip,
const TVX &x, TVY &y, LocalHeap &lh)
{
HeapReset hr (lh);
typedef typename TVX::TSCAL TSCAL;
FlatMatrixFixHeight<DIM_DMAT, TSCAL> mat (DIM * fel.GetNDof (), lh);
// Cast(fel).CalcShape (mip, mat.Row(0));
GenerateMatrix (fel, mip, mat, lh);
// y.Range (DIM * fel.GetNDof ()) += Trans (mat) * x;
FlatVector<TSCAL> vec (DIM * fel.GetNDof (), lh);
vec = Trans (mat) * x;
y.Range (DIM * fel.GetNDof ()) += vec;
}
};
/// Gradient operator of dimension D
template <int D, typename FEL = PlaneWaveElement<D>>
class DiffOpMappedGradientComplex
: public DiffOp<DiffOpMappedGradientComplex<D, FEL>>
{
public:
enum
{
DIM = 1
};
enum
{
DIM_SPACE = D
};
enum
{
DIM_ELEMENT = D
};
enum
{
DIM_DMAT = D
};
enum
{
DIFFORDER = 1
};
static string Name () { return "grad"; }
static constexpr bool SUPPORT_PML = true;
static const FEL &Cast (const FiniteElement &fel)
{
return static_cast<const FEL &> (fel);
}
template <typename SCALMIP, typename MAT>
static void
GenerateMatrix (const FiniteElement &fel,
const MappedIntegrationPoint<D, D, SCALMIP> &mip,
MAT &&mat, LocalHeap &lh)
{
Cast (fel).CalcDShape (mip, Trans (mat));
}
template <typename MIP, class TVY>
static void
Apply (const FiniteElement &fel, const MIP &mip,
const BareSliceVector<Complex> &x, TVY &&y, LocalHeap &lh)
{
Vec<D, Complex> hv = Cast (fel).EvaluateGradComplex (mip, x);
y = hv;
HeapReset hr (lh);
}
template <typename MIP, class TVX, class TVY>
static void Apply (const FiniteElement &fel, const MIP &mip, const TVX &x,
TVY &&y, LocalHeap &lh)
{
throw Exception ("Not implemented for complex DiffOp ");
}
// using DiffOp<DiffOpMappedGradient<D, FEL> >::ApplyTans;
template <typename MIP, class TVX, class TVY>
static void ApplyTrans (const FiniteElement &fel, const MIP &mip,
const TVX &x, TVY &y, LocalHeap &lh)
{
typedef typename TVX::TSCAL TSCAL;
Vec<D, TSCAL> vx = x;
// auto hv = mip.GetJacobianInverse() * vx;
y.Range (0, fel.GetNDof ())
= Cast (fel).GetDShape (mip, lh) * vx; //* hv;
}
template <typename MIP, class TVX, class TVY>
static void ApplyTransAdd (const FiniteElement &fel, const MIP &mip,
const TVX &x, TVY &y, LocalHeap &lh)
{
throw Exception ("Not implemented for complex DiffOp ");
}
// for complex shapes in lfi, symbolicintegrator.cpp T_CalcFacetVector ->
// diffop_impl.hpp ApplyTrans,ApplyTransIR ->
template <class MIP>
static void ApplyTransAdd (const FiniteElement &fel, const MIP &mip,
FlatVector<Complex> x,
BareSliceVector<Complex> y, LocalHeap &lh)
{
FlatVector<Complex> vec (DIM * fel.GetNDof (), lh);
vec = (Cast (fel).GetDShapeComplex (mip, lh)) * x;
y.Range (DIM * fel.GetNDof ()) += vec;
}
template <typename MIR, class TVX, class TVY>
static void ApplyTransIR (const FiniteElement &fel, const MIR &mir,
const TVX &x, TVY &y, LocalHeap &lh)
{
y.Range (0, DIM * fel.GetNDof ()) = 0.0;
for (size_t i = 0; i < mir.Size (); i++)
{
HeapReset hr (lh);
ApplyTransAdd (fel, mir[i], x.Row (i), y, lh);
}
}
};
template <typename DIFFOP>
class T_DifferentialOperatorC : public T_DifferentialOperator<DIFFOP>
{
// copy past form diffop_impl to fix fast compile missing complex functions
void
Apply (const FiniteElement &bfel, const BaseMappedIntegrationRule &bmir,
BareSliceVector<Complex> x, BareSliceMatrix<Complex> flux,
LocalHeap &lh) const
{
auto fluxsize = flux.AddSize (bmir.Size (), DIFFOP::DIM_DMAT);
const MappedIntegrationRule<DIFFOP::DIM_ELEMENT, DIFFOP::DIM_SPACE> &mir
= static_cast<const MappedIntegrationRule<DIFFOP::DIM_ELEMENT,
DIFFOP::DIM_SPACE> &> (
bmir);
DIFFOP::ApplyIR (bfel, mir, x, fluxsize, lh);
}
void Apply (const FiniteElement &bfel,
const SIMD_BaseMappedIntegrationRule &bmir,
BareSliceVector<Complex> x,
BareSliceMatrix<SIMD<Complex>> flux) const
{
DIFFOP::ApplySIMDIR (bfel, bmir, x, flux);
}
void ApplyTrans (const FiniteElement &bfel,
const BaseMappedIntegrationRule &bmir,
FlatMatrix<Complex> flux, BareSliceVector<Complex> x,
LocalHeap &lh) const
{
const MappedIntegrationRule<DIFFOP::DIM_ELEMENT, DIFFOP::DIM_SPACE> &mir
= static_cast<const MappedIntegrationRule<DIFFOP::DIM_ELEMENT,
DIFFOP::DIM_SPACE> &> (
bmir);
DIFFOP::ApplyTransIR (bfel, mir, flux, x, lh);
}
};
}
#endif