StdExpansion3D.cpp 21.1 KB
Newer Older
Mike Kirby's avatar
Mike Kirby committed
1
2
///////////////////////////////////////////////////////////////////////////////
//
3
// File StdExpansion3D.cpp
Mike Kirby's avatar
Mike Kirby committed
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
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
31
//
Mike Kirby's avatar
Mike Kirby committed
32
33
34
35
36
37
38
39
// Description: Daughter of StdExpansion. This class contains routine
// which are common to 3D expansion. Typically this inolves physiocal
// space operations.
//
///////////////////////////////////////////////////////////////////////////////

#include <StdRegions/StdExpansion3D.h>

40
41
42
43
#ifdef max
#undef max
#endif

Mike Kirby's avatar
Mike Kirby committed
44
45
namespace Nektar
{
46
    namespace StdRegions
Mike Kirby's avatar
Mike Kirby committed
47
    {
48
        StdExpansion3D::StdExpansion3D()
49
50
        {
        }
51
52
53
54
55
56
        
        StdExpansion3D::StdExpansion3D(int                           numcoeffs, 
                                       const LibUtilities::BasisKey &Ba,
                                       const LibUtilities::BasisKey &Bb, 
                                       const LibUtilities::BasisKey &Bc) :
            StdExpansion(numcoeffs,3,Ba,Bb,Bc)
57
        {
58
        }
59

60
61
62
63
64
65
66
67
        StdExpansion3D::StdExpansion3D(const StdExpansion3D &T):
            StdExpansion(T)
        {
        }
        
        StdExpansion3D::~StdExpansion3D()
        {
        }
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
        void StdExpansion3D::PhysTensorDeriv(
            const Array<OneD, const NekDouble> &inarray,
                  Array<OneD,       NekDouble> &out_dx,
                  Array<OneD,       NekDouble> &out_dy,
                  Array<OneD,       NekDouble> &out_dz)
        {
            const int nquad0 = m_base[0]->GetNumPoints();
            const int nquad1 = m_base[1]->GetNumPoints();
            const int nquad2 = m_base[2]->GetNumPoints();

            Array<OneD, NekDouble> wsp(nquad0*nquad1*nquad2);
            
            // copy inarray to wsp in case inarray is used as outarray
            Vmath::Vcopy(nquad0*nquad1*nquad2, &inarray[0], 1, &wsp[0], 1);
            
            if (out_dx.num_elements() > 0)
            {
                NekDouble  *D0 = &((m_base[0]->GetD())->GetPtr())[0];

87
88
                Blas::Dgemm('N','N', nquad0,nquad1*nquad2,nquad0,1.0,
                            D0,nquad0,&wsp[0],nquad0,0.0,&out_dx[0],nquad0);
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
            }

            if (out_dy.num_elements() > 0) 
            {
                NekDouble   *D1 = &((m_base[1]->GetD())->GetPtr())[0];
                for (int j = 0; j < nquad2; ++j)
                {
                    Blas::Dgemm('N', 'T', nquad0, nquad1,      nquad1,
                                1.0, &wsp[j*nquad0*nquad1],    nquad0,
                                D1,                            nquad1,
                                0.0, &out_dy[j*nquad0*nquad1], nquad0);
                }
            }

            if (out_dz.num_elements() > 0) 
            {
                NekDouble     *D2 = &((m_base[2]->GetD())->GetPtr())[0];

107
108
109
                Blas::Dgemm('N','T',nquad0*nquad1,nquad2,nquad2,1.0,
                            &wsp[0],nquad0*nquad1,D2,nquad2,0.0,&out_dz[0],
                            nquad0*nquad1);
110
111
            }
        }
Peter Vos's avatar
Peter Vos committed
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
        void StdExpansion3D::BwdTrans_SumFacKernel(
            const Array<OneD, const NekDouble>& base0,
            const Array<OneD, const NekDouble>& base1,
            const Array<OneD, const NekDouble>& base2,
            const Array<OneD, const NekDouble>& inarray,
                  Array<OneD,       NekDouble>& outarray,
                  Array<OneD,       NekDouble>& wsp,
            bool                                doCheckCollDir0,
            bool                                doCheckCollDir1,
            bool                                doCheckCollDir2)
        {
            v_BwdTrans_SumFacKernel(base0, base1, base2, inarray, outarray, wsp, doCheckCollDir0, doCheckCollDir1, doCheckCollDir2);
        }

        void StdExpansion3D::IProductWRTBase_SumFacKernel(
                const Array<OneD, const NekDouble>& base0,
                const Array<OneD, const NekDouble>& base1,
                const Array<OneD, const NekDouble>& base2,
                const Array<OneD, const NekDouble>& inarray,
                      Array<OneD, NekDouble> &outarray,
                      Array<OneD, NekDouble> &wsp,
                bool doCheckCollDir0,
                bool doCheckCollDir1,
                bool doCheckCollDir2)
        {
            v_IProductWRTBase_SumFacKernel(base0, base1, base2, inarray, outarray, wsp, doCheckCollDir0, doCheckCollDir1, doCheckCollDir2);
        }

141
142
143
        NekDouble StdExpansion3D::v_PhysEvaluate(
            const Array<OneD, const NekDouble> &coords, 
            const Array<OneD, const NekDouble> &physvals)
Chris Cantwell's avatar
Chris Cantwell committed
144
        {
145
            Array<OneD, NekDouble> eta = Array<OneD, NekDouble>(3);
Chris Cantwell's avatar
Chris Cantwell committed
146
            Array<OneD, DNekMatSharedPtr>  I(3);
147

148
149
150
151
152
153
154
            WARNINGL2(coords[0] >= -1,"coord[0] < -1");
            WARNINGL2(coords[0] <=  1,"coord[0] >  1");
            WARNINGL2(coords[1] >= -1,"coord[1] < -1");
            WARNINGL2(coords[1] <=  1,"coord[1] >  1");
            WARNINGL2(coords[2] >= -1,"coord[2] < -1");
            WARNINGL2(coords[2] <=  1,"coord[2] >  1");

155
156
157
            // Obtain local collapsed corodinate from 
            // cartesian coordinate. 
            LocCoordToLocCollapsed(coords,eta);
Chris Cantwell's avatar
Chris Cantwell committed
158

159
            // Get Lagrange interpolants. 
Chris Cantwell's avatar
Chris Cantwell committed
160
161
            I[0] = m_base[0]->GetI(eta);
            I[1] = m_base[1]->GetI(eta+1);
162
            I[2] = m_base[2]->GetI(eta+2);
163

Chris Cantwell's avatar
Chris Cantwell committed
164
165
            return v_PhysEvaluate(I,physvals);
        }
166
167
168
169

        NekDouble StdExpansion3D::v_PhysEvaluate(
            const Array<OneD, DNekMatSharedPtr > &I, 
            const Array<OneD, const NekDouble> &physvals)
170
        {
171
172
173
174
175
176
177
178
179
180
            NekDouble  value;
            
            int Qx = m_base[0]->GetNumPoints();
            int Qy = m_base[1]->GetNumPoints();
            int Qz = m_base[2]->GetNumPoints();
            
            Array<OneD, NekDouble> sumFactorization_qr = Array<OneD, NekDouble>(Qy*Qz);
            Array<OneD, NekDouble> sumFactorization_r  = Array<OneD, NekDouble>(Qz);
            
            // Lagrangian interpolation matrix
181
            NekDouble *interpolatingNodes = 0;
182
183
            
            // Interpolate first coordinate direction
184
            interpolatingNodes = &I[0]->GetPtr()[0];
Chris Cantwell's avatar
Chris Cantwell committed
185
186
187

            Blas::Dgemv('T',Qx,Qy*Qz,1.0,&physvals[0],Qx,&interpolatingNodes[0], 1, 0.0, &sumFactorization_qr[0], 1);

188
            // Interpolate in second coordinate direction
189
            interpolatingNodes = &I[1]->GetPtr()[0];
Chris Cantwell's avatar
Chris Cantwell committed
190
191
192

            Blas::Dgemv('T',Qy,Qz,1.0,&sumFactorization_qr[0],Qy,&interpolatingNodes[0],1,0.0,&sumFactorization_r[0], 1);

193
            // Interpolate in third coordinate direction
194
            interpolatingNodes = &I[2]->GetPtr()[0];
195
196
197
198
199
            value = Blas::Ddot(Qz, interpolatingNodes, 1, &sumFactorization_r[0], 1);
            
            return value;
        }
        
200
201
202
203
204
205
206
207
208
209
210

        /**
         * @param   inarray     Input coefficients.
         * @param   output      Output coefficients.
         * @param   mkey        Matrix key
         */
        void StdExpansion3D::v_LaplacianMatrixOp_MatFree(
                const Array<OneD, const NekDouble> &inarray,
                      Array<OneD,NekDouble> &outarray,
                const StdRegions::StdMatrixKey &mkey)
        {
Chris Cantwell's avatar
Chris Cantwell committed
211
212
            if ( mkey.GetNVarCoeff() == 0 &&
                !mkey.ConstFactorExists(eFactorSVVCutoffRatio))
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
            {
                // This implementation is only valid when there are no
                // coefficients associated to the Laplacian operator
                int nqtot = GetTotPoints();

                const Array<OneD, const NekDouble>& base0  = m_base[0]->GetBdata();
                const Array<OneD, const NekDouble>& base1  = m_base[1]->GetBdata();
                const Array<OneD, const NekDouble>& base2  = m_base[2]->GetBdata();

                // Allocate temporary storage
                Array<OneD,NekDouble> wsp0(7*nqtot);
                Array<OneD,NekDouble> wsp1(wsp0+nqtot);

                if(!(m_base[0]->Collocation() && m_base[1]->Collocation() &&
                     m_base[2]->Collocation()))
                {
                    // LAPLACIAN MATRIX OPERATION
                    // wsp0 = u       = B   * u_hat
                    // wsp1 = du_dxi1 = D_xi1 * wsp0 = D_xi1 * u
                    // wsp2 = du_dxi2 = D_xi2 * wsp0 = D_xi2 * u
                    BwdTrans_SumFacKernel(base0,base1,base2,inarray,wsp0,wsp1,true,true,true);
                    LaplacianMatrixOp_MatFree_Kernel(wsp0,outarray,wsp1);
                }
                else
                {
                    LaplacianMatrixOp_MatFree_Kernel(inarray,outarray,wsp1);
                }
            }
            else
            {
                StdExpansion::LaplacianMatrixOp_MatFree_GenericImpl(inarray,outarray,mkey);
            }
        }


        void StdExpansion3D::v_HelmholtzMatrixOp_MatFree(
                const Array<OneD, const NekDouble> &inarray,
                      Array<OneD,NekDouble> &outarray,
                const StdRegions::StdMatrixKey &mkey)
        {
            if(mkey.GetNVarCoeff() == 0)
            {
255
256
                using std::max;

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
                int nquad0  = m_base[0]->GetNumPoints();
                int nquad1  = m_base[1]->GetNumPoints();
                int nquad2  = m_base[2]->GetNumPoints();
                int nmodes0 = m_base[0]->GetNumModes();
                int nmodes1 = m_base[1]->GetNumModes();
                int nmodes2 = m_base[2]->GetNumModes();
                int wspsize = max(nquad0*nmodes2*(nmodes1+nquad1),
                                  nquad0*nquad1*(nquad2+nmodes0)+
                                  nmodes0*nmodes1*nquad2);

                NekDouble lambda  = mkey.GetConstFactor(StdRegions::eFactorLambda);

                const Array<OneD, const NekDouble>& base0 = m_base[0]->GetBdata ();
                const Array<OneD, const NekDouble>& base1 = m_base[1]->GetBdata ();
                const Array<OneD, const NekDouble>& base2 = m_base[2]->GetBdata ();
                Array<OneD,NekDouble> wsp0(8*wspsize);
                Array<OneD,NekDouble> wsp1(wsp0+1*wspsize);
                Array<OneD,NekDouble> wsp2(wsp0+2*wspsize);

                if(!(m_base[0]->Collocation() && m_base[1]->Collocation() &&
                     m_base[2]->Collocation()))
                {
                    // MASS MATRIX OPERATION
                    // The following is being calculated:
                    // wsp0     = B   * u_hat = u
                    // wsp1     = W   * wsp0
                    // outarray = B^T * wsp1  = B^T * W * B * u_hat = M * u_hat
                    BwdTrans_SumFacKernel           (base0,base1,base2,inarray,
                                                     wsp0,wsp2,true,true,true);
                    MultiplyByQuadratureMetric      (wsp0,wsp1);
                    IProductWRTBase_SumFacKernel    (base0,base1,base2,wsp1,
                                                     outarray,wsp2,true,true,true);
                    LaplacianMatrixOp_MatFree_Kernel(wsp0,wsp1,wsp2);
                }
                else
                {
                    // specialised implementation for the classical spectral
                    // element method
                    MultiplyByQuadratureMetric      (inarray,outarray);
                    LaplacianMatrixOp_MatFree_Kernel(inarray,wsp1,wsp2);
                }

                // outarray = lambda * outarray + wsp1
                //          = (lambda * M + L ) * u_hat
                Vmath::Svtvp(m_ncoeffs,lambda,&outarray[0],1,&wsp1[0],1,
                             &outarray[0],1);
            }
            else
            {
                StdExpansion::HelmholtzMatrixOp_MatFree_GenericImpl(inarray,outarray,mkey);
            }

        }

Chris Cantwell's avatar
Chris Cantwell committed
311
312
        const NormalVector & StdExpansion3D::v_GetSurfaceNormal(
                const int id) const
313
        {
314
            return v_GetFaceNormal(id);
315
        }
316
        
317
318
319
320
321
        const NormalVector & StdExpansion3D::v_GetFaceNormal(const int face) const
        {
            std::map<int, NormalVector>::const_iterator x;
            x = m_faceNormals.find(face);
            ASSERTL0 (x != m_faceNormals.end(),
322
                      "face normal not computed.");
323
324
            return x->second;
        }
325

326
327
328
329
330
331
332
333
334
335
        NekDouble StdExpansion3D::v_Integral(
            const Array<OneD, const NekDouble>& inarray)
        {
            const int nqtot = GetTotPoints();
            Array<OneD, NekDouble> tmp(GetTotPoints());
            MultiplyByStdQuadratureMetric(inarray, tmp);
            return Vmath::Vsum(nqtot, tmp, 1);
        }
        
        
336
337
338
339
340
341
342
343
344
        void StdExpansion3D::v_NegateFaceNormal(const int face)
        {
            m_negatedNormals[face] = true;
            for (int i = 0; i < GetCoordim(); ++i)
            {
                Vmath::Neg(m_faceNormals[face][i].num_elements(), 
                           m_faceNormals[face][i], 1);
            }
        }
345
346
347
348
349
350

        bool StdExpansion3D::v_FaceNormalNegated(const int face)
        {
            return m_negatedNormals[face];
        }

351
352
353
354
355
        LibUtilities::BasisKey EvaluateQuadFaceBasisKey(
            const int                     facedir,
            const LibUtilities::BasisType faceDirBasisType,
            const int                     numpoints,
            const int                     nummodes)
356
        {
357

358
359
            switch(faceDirBasisType)
            {
360
361
362
363
364
365
366
367
368
                case LibUtilities::eModified_A:
                {
                    const LibUtilities::PointsKey pkey(
                        numpoints, LibUtilities::eGaussLobattoLegendre);
                    return LibUtilities::BasisKey(
                        LibUtilities::eModified_A, nummodes, pkey);
                }
                case LibUtilities::eModified_B:
                case LibUtilities::eModified_C:
369
                {
370
371
372
373
                    const LibUtilities::PointsKey pkey(
                        numpoints+1, LibUtilities::eGaussLobattoLegendre);
                    return LibUtilities::BasisKey(
                        LibUtilities::eModified_A, nummodes, pkey);
374
                }
375
                case LibUtilities::eGLL_Lagrange:
376
                {
377
378
379
380
                    const LibUtilities::PointsKey pkey(
                        numpoints, LibUtilities::eGaussLobattoLegendre);
                    return LibUtilities::BasisKey(
                        LibUtilities::eGLL_Lagrange, nummodes, pkey);
381
                }
382
                case LibUtilities::eOrtho_A:
383
                {
384
385
386
387
                    const LibUtilities::PointsKey pkey(
                        numpoints, LibUtilities::eGaussLobattoLegendre);
                    return LibUtilities::BasisKey(
                        LibUtilities::eOrtho_A, nummodes, pkey);
388
                }
389
390
                case LibUtilities::eOrtho_B:
                case LibUtilities::eOrtho_C:
391
                {
392
393
394
395
                    const LibUtilities::PointsKey pkey(
                        numpoints+1, LibUtilities::eGaussLobattoLegendre);
                    return LibUtilities::BasisKey(
                        LibUtilities::eOrtho_A, nummodes, pkey);
396
                }
397
                default:
398
                {
399
400
                    ASSERTL0(false, "expansion type unknown");
                    break;
401
402
403
404
                }
            }

            // Keep things happy by returning a value.
405
            return LibUtilities::NullBasisKey;
406
407
        }

408
409
410
411
412
        LibUtilities::BasisKey EvaluateTriFaceBasisKey(
            const int                     facedir,
            const LibUtilities::BasisType faceDirBasisType,
            const int                     numpoints,
            const int                     nummodes)
413
414
415
        {
            switch(faceDirBasisType)
            {
416
                case LibUtilities::eModified_A:
417
                {
418
419
420
421
                    const LibUtilities::PointsKey pkey(
                        numpoints, LibUtilities::eGaussLobattoLegendre);
                    return LibUtilities::BasisKey(
                        LibUtilities::eModified_A, nummodes, pkey);
422
                }
423
424
                case LibUtilities::eModified_B:
                case LibUtilities::eModified_C:
425
                case LibUtilities::eModifiedPyr_C:
426
427
428
                {
                    switch (facedir)
                    {
429
430
431
432
433
434
435
436
437
                        case 0:
                        {
                            const LibUtilities::PointsKey pkey(
                                numpoints+1,
                                LibUtilities::eGaussLobattoLegendre);
                            return LibUtilities::BasisKey(
                                LibUtilities::eModified_A, nummodes, pkey);
                        }
                        case 1:
438
                        {
439
440
441
//                            const LibUtilities::PointsKey pkey(
//                                numpoints+1,
//                                LibUtilities::eGaussLobattoLegendre);
442
                            const LibUtilities::PointsKey pkey(
443
444
	 			numpoints, 	
				LibUtilities::eGaussRadauMAlpha1Beta0);
445
446
                            return LibUtilities::BasisKey(
                                LibUtilities::eModified_B, nummodes, pkey);
447
                        }
448
                        default:
449
                        {
450

451
452
                            ASSERTL0(false,"invalid value to flag");
                            break;
453
454
455
                        }
                    }
                }
456
457

                case LibUtilities::eGLL_Lagrange:
458
459
460
                {
                    switch (facedir)
                    {
461
462
463
464
465
466
467
468
469
                        case 0:
                        {
                            const LibUtilities::PointsKey pkey(
                                numpoints,
                                LibUtilities::eGaussLobattoLegendre);
                            return LibUtilities::BasisKey(
                                LibUtilities::eOrtho_A, nummodes, pkey);
                        }
                        case 1:
470
                        {
471
472
473
474
475
                            const LibUtilities::PointsKey pkey(
                                numpoints,
                                LibUtilities::eGaussRadauMAlpha1Beta0);
                            return LibUtilities::BasisKey(
                                LibUtilities::eOrtho_B, nummodes, pkey);
476
                        }
477
                        default:
478
                        {
479
480
                            ASSERTL0(false,"invalid value to flag");
                            break;
481
482
483
                        }
                    }
                }
484
485
486
487

                case LibUtilities::eOrtho_A:
                case LibUtilities::eOrtho_B:
                case LibUtilities::eOrtho_C:
488
                case LibUtilities::eOrthoPyr_C:
489
490
491
                {
                    switch (facedir)
                    {
492
                        case 0:
493
                        {
494
495
496
497
498
                            const LibUtilities::PointsKey pkey(
                                numpoints,
                                LibUtilities::eGaussLobattoLegendre);
                            return LibUtilities::BasisKey(
                                LibUtilities::eOrtho_A, nummodes, pkey);
499
                        }
500
                        case 1:
501
                        {
502
503
504
505
506
                            const LibUtilities::PointsKey pkey(
                                numpoints,
                                LibUtilities::eGaussRadauMAlpha1Beta0);
                            return LibUtilities::BasisKey(
                                LibUtilities::eOrtho_B, nummodes, pkey);
507
                        }
508
509
510
511
                        default:
                        {
                            ASSERTL0(false,"invalid value to flag");
                            break;
512
                        }
513
514
515
516
517
518
                    }
                }
                default:
                {
                    ASSERTL0(false,"expansion type unknown");
                    break;
519
520
                }
            }
521

522
523
524
            // Keep things happy by returning a value.
            return LibUtilities::NullBasisKey; 
        }
525
    }//end namespace
Mike Kirby's avatar
Mike Kirby committed
526
}//end namespace