StdHexExp.cpp 82.3 KB
Newer Older
Mike Kirby's avatar
Mike Kirby committed
1
2
///////////////////////////////////////////////////////////////////////////////
//
Sophia Han's avatar
Sophia Han committed
3
// File StdHexExp.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
// Description: Heaxhedral methods
//
///////////////////////////////////////////////////////////////////////////////

#include <StdRegions/StdHexExp.h>

38
39
40
41
#ifdef max
#undef max
#endif

Mike Kirby's avatar
Mike Kirby committed
42
43
44
45
46
namespace Nektar
{
    namespace StdRegions
    {

47
48
49
50
51
52
53
54
        StdHexExp::StdHexExp()
        {
        }


        StdHexExp::StdHexExp(const LibUtilities::BasisKey &Ba,
                        const LibUtilities::BasisKey &Bb,
                        const LibUtilities::BasisKey &Bc):
55
56
            StdExpansion(Ba.GetNumModes()*Bb.GetNumModes()*Bc.GetNumModes(), 3,
                                                   Ba, Bb, Bc),
57
58
            StdExpansion3D(Ba.GetNumModes()*Bb.GetNumModes()*Bc.GetNumModes(),
                           Ba, Bb, Bc)
59
        {
Mike Kirby's avatar
Mike Kirby committed
60
61
        }

62
63
64
65

        StdHexExp::StdHexExp(const  LibUtilities::BasisKey &Ba,
                        const  LibUtilities::BasisKey &Bb,
                        const  LibUtilities::BasisKey &Bc,
66
67
                        NekDouble *coeffs,
                        NekDouble *phys)
68
        {
Mike Kirby's avatar
Mike Kirby committed
69
70
        }

71

Mike Kirby's avatar
Mike Kirby committed
72
        StdHexExp::StdHexExp(const StdHexExp &T):
73
            StdExpansion(T),
Peter Vos's avatar
Peter Vos committed
74
            StdExpansion3D(T)
Mike Kirby's avatar
Mike Kirby committed
75
76
77
        {
        }

78

Mike Kirby's avatar
Mike Kirby committed
79
        StdHexExp::~StdHexExp()
80
81
        {
        }
Mike Kirby's avatar
Mike Kirby committed
82

83
84
85
86
87
88
89
        bool StdHexExp::v_IsBoundaryInteriorExpansion()
        {
            return (m_base[0]->GetBasisType() == LibUtilities::eModified_A) &&
                   (m_base[1]->GetBasisType() == LibUtilities::eModified_A) &&
                   (m_base[2]->GetBasisType() == LibUtilities::eModified_A);
        }

Peter Vos's avatar
Peter Vos committed
90

91
92
93
        ///////////////////////////////
        /// Differentiation Methods
        ///////////////////////////////
94
        /**
95
96
         * For Hexahedral region can use the PhysTensorDeriv function defined
         * under StdExpansion. Following tenserproduct:
97
         */
98
99
100
101
        void StdHexExp::v_PhysDeriv(const Array<OneD, const NekDouble>& inarray,
                                  Array<OneD, NekDouble> &out_d0,
                                  Array<OneD, NekDouble> &out_d1,
                                  Array<OneD, NekDouble> &out_d2)
102
        {
103
            PhysTensorDeriv(inarray, out_d0, out_d1, out_d2);
104
        }
Peter Vos's avatar
Peter Vos committed
105
106


107
        /**
108
109
110
111
         * @param   dir         Direction in which to compute derivative.
         *                      Valid values are 0, 1, 2.
         * @param   inarray     Input array.
         * @param   outarray    Output array.
112
         */
113
114
115
        void StdHexExp::v_PhysDeriv(const int dir,
                               const Array<OneD, const NekDouble>& inarray,
                                     Array<OneD,       NekDouble>& outarray)
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
            switch(dir)
            {
            case 0:
                {
                    PhysDeriv(inarray, outarray, NullNekDouble1DArray,
                              NullNekDouble1DArray);
                }
                break;
            case 1:
                {
                    PhysDeriv(inarray, NullNekDouble1DArray, outarray,
                              NullNekDouble1DArray);
                }
                break;
            case 2:
                {
                    PhysDeriv(inarray, NullNekDouble1DArray,
                              NullNekDouble1DArray, outarray);
                }
                break;
            default:
                {
                    ASSERTL1(false,"input dir is out of range");
                }
                break;
            }
        }
144

145
        void StdHexExp::v_StdPhysDeriv(
146
147
148
149
            const Array<OneD, const NekDouble> &inarray,
                  Array<OneD,       NekDouble> &out_d0,
                  Array<OneD,       NekDouble> &out_d1,
                  Array<OneD,       NekDouble> &out_d2)
150
        {
151
            StdHexExp::v_PhysDeriv(inarray, out_d0, out_d1, out_d2);
152
153
154
        }


155
156
157
158
159
160
161
        void StdHexExp::v_StdPhysDeriv(const int dir,
                               const Array<OneD, const NekDouble>& inarray,
                                     Array<OneD,       NekDouble>& outarray)
        {
            StdHexExp::v_PhysDeriv(dir, inarray, outarray);
        }

162
        /**
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
         * Backward transformation is three dimensional tensorial expansion
         * \f$ u (\xi_{1i}, \xi_{2j}, \xi_{3k})
         *  = \sum_{p=0}^{Q_x} \psi_p^a (\xi_{1i})
         *  \lbrace { \sum_{q=0}^{Q_y} \psi_{q}^a (\xi_{2j})
         *    \lbrace { \sum_{r=0}^{Q_z} \hat u_{pqr} \psi_{r}^a (\xi_{3k})
         *    \rbrace}
         *  \rbrace}. \f$
         * And sumfactorizing step of the form is as:\\
         * \f$ f_{r} (\xi_{3k})
         * = \sum_{r=0}^{Q_z} \hat u_{pqr} \psi_{r}^a (\xi_{3k}),\\
         * g_{p} (\xi_{2j}, \xi_{3k})
         * = \sum_{r=0}^{Q_y} \psi_{p}^a (\xi_{2j}) f_{r} (\xi_{3k}),\\
         * u(\xi_{1i}, \xi_{2j}, \xi_{3k})
         * = \sum_{p=0}^{Q_x} \psi_{p}^a (\xi_{1i}) g_{p} (\xi_{2j}, \xi_{3k}).
         * \f$
         *
         * @param   inarray     ?
         * @param   outarray    ?
181
         */
182
183
184
        void StdHexExp::v_BwdTrans(
                                const Array<OneD, const NekDouble>& inarray,
                                      Array<OneD, NekDouble> &outarray)
185
        {
186
187
188
            ASSERTL1( (m_base[1]->GetBasisType() != LibUtilities::eOrtho_B)  ||
                      (m_base[1]->GetBasisType() != LibUtilities::eModified_B),
                      "Basis[1] is not a general tensor type");
189

190
191
192
            ASSERTL1( (m_base[2]->GetBasisType() != LibUtilities::eOrtho_C) ||
                      (m_base[2]->GetBasisType() != LibUtilities::eModified_C),
                      "Basis[2] is not a general tensor type");
193

194
195
            if(m_base[0]->Collocation() && m_base[1]->Collocation()
                    && m_base[2]->Collocation())
196
            {
197
198
199
200
                Vmath::Vcopy(m_base[0]->GetNumPoints()
                                * m_base[1]->GetNumPoints()
                                * m_base[2]->GetNumPoints(),
                             inarray, 1, outarray, 1);
201
202
            }
            else
203
204
205
206
            {
                StdHexExp::BwdTrans_SumFac(inarray,outarray);
            }
        }
207
208


209
210
211
212
213
214
215
216
217
        /**
         *
         */
        void StdHexExp::v_BwdTrans_SumFac(const Array<OneD, const NekDouble>& inarray,
                                         Array<OneD, NekDouble> &outarray)
        {
            Array<OneD, NekDouble> wsp(m_base[0]->GetNumPoints()*
                                       m_base[2]->GetNumModes()*
                                       (m_base[1]->GetNumModes() + m_base[1]->GetNumPoints())); // FIX THIS
218

219
220
221
222
223
            BwdTrans_SumFacKernel(m_base[0]->GetBdata(),
                                    m_base[1]->GetBdata(),
                                    m_base[2]->GetBdata(),
                                    inarray,outarray,wsp,true,true,true);
        }
224
225


226
227
228
229
230
231
232
233
234
235
236
237
238
        /**
         * @param   base0       x-dirn basis matrix
         * @param   base1       y-dirn basis matrix
         * @param   base2       z-dirn basis matrix
         * @param   inarray     Input vector of modes.
         * @param   outarray    Output vector of physical space data.
         * @param   wsp         Workspace of size Q_x*P_z*(P_y+Q_y)
         * @param   doCheckCollDir0     Check for collocation of basis.
         * @param   doCheckCollDir1     Check for collocation of basis.
         * @param   doCheckCollDir2     Check for collocation of basis.
         * @todo    Account for some directions being collocated. See
         *          StdQuadExp as an example.
         */
239
        void StdHexExp::v_BwdTrans_SumFacKernel(
240
241
242
243
244
245
246
247
248
                    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)
249
        {
250
251
252
253
254
255
            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();
256

257
258
259
260
            // Check if using collocation, if requested.
            bool colldir0 = doCheckCollDir0?(m_base[0]->Collocation()):false;
            bool colldir1 = doCheckCollDir1?(m_base[1]->Collocation()):false;
            bool colldir2 = doCheckCollDir2?(m_base[2]->Collocation()):false;
Peter Vos's avatar
Peter Vos committed
261

262
263
264
            // If collocation in all directions, Physical values at quadrature
            // points is just a copy of the modes.
            if(colldir0 && colldir1 && colldir2)
Peter Vos's avatar
Peter Vos committed
265
            {
266
                Vmath::Vcopy(m_ncoeffs,inarray.get(),1,outarray.get(),1);
Peter Vos's avatar
Peter Vos committed
267
            }
268
            else
269
            {
270
271
272
                // Check sufficiently large workspace.
                ASSERTL1(wsp.num_elements()>=nquad0*nmodes2*(nmodes1+nquad1),
                         "Workspace size is not sufficient");
273

274
275
                // Assign second half of workspace for 2nd DGEMM operation.
                Array<OneD, NekDouble> wsp2 = wsp + nquad0*nmodes1*nmodes2;
Mike Kirby's avatar
Mike Kirby committed
276

277
278
279
280
281
282
283
284
285
286
287
288
289
                // BwdTrans in each direction using DGEMM
                Blas::Dgemm('T','T', nmodes1*nmodes2, nquad0, nmodes0,
                            1.0, &inarray[0],   nmodes0,
                                 base0.get(),   nquad0,
                            0.0, &wsp[0],       nmodes1*nmodes2);
                Blas::Dgemm('T','T', nquad0*nmodes2,  nquad1, nmodes1,
                            1.0, &wsp[0],       nmodes1,
                                 base1.get(),   nquad1,
                            0.0, &wsp2[0],      nquad0*nmodes2);
                Blas::Dgemm('T','T', nquad0*nquad1,   nquad2, nmodes2,
                            1.0, &wsp2[0],      nmodes2,
                                 base2.get(),   nquad2,
                            0.0, &outarray[0],  nquad0*nquad1);
290
291
            }
        }
Mike Kirby's avatar
Mike Kirby committed
292

Sophia Han's avatar
Sophia Han committed
293

294
        /**
295
296
297
298
299
300
301
         * Solves the system
         * \f$ \mathbf{B^{\top}WB\hat{u}}=\mathbf{B^{\top}Wu^{\delta}} \f$
         *
         * @param   inarray     array of physical quadrature points to be
         *                      transformed, \f$ \mathbf{u^{\delta}} \f$.
         * @param   outarray    array of expansion coefficients,
         *                      \f$ \mathbf{\hat{u}} \f$.
302
         */
303
304
305
        void StdHexExp::v_FwdTrans(
                    const Array<OneD, const NekDouble>& inarray,
                          Array<OneD, NekDouble> &outarray)
306
        {
307
308
309
310
311
            // If using collocation expansion, coefficients match physical
            // data points so just do a direct copy.
            if( (m_base[0]->Collocation())
                    &&(m_base[1]->Collocation())
                    &&(m_base[2]->Collocation()) )
312
            {
313
                Vmath::Vcopy(GetNcoeffs(), &inarray[0], 1, &outarray[0], 1);
314
            }
315
            else
316
            {
317
318
                // Compute B^TWu
                IProductWRTBase(inarray,outarray);
319

320
                // get Mass matrix inverse
321
                StdMatrixKey      masskey(eInvMass,DetShapeType(),*this);
322
                DNekMatSharedPtr matsys = GetStdMatrix(masskey);
323

324
325
326
                // copy inarray in case inarray == outarray
                DNekVec in (m_ncoeffs,outarray);
                DNekVec out(m_ncoeffs,outarray,eWrapper);
327

328
329
                // Solve for coefficients.
                out = (*matsys)*in;
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
        /**
         * \f$
         * \begin{array}{rcl}
         * I_{pqr} = (\phi_{pqr}, u)_{\delta} & = &
         * \sum_{i=0}^{nq_0} \sum_{j=0}^{nq_1} \sum_{k=0}^{nq_2}
         * \psi_{p}^{a}(\xi_{1i}) \psi_{q}^{a}(\xi_{2j}) \psi_{r}^{a}(\xi_{3k})
         * w_i w_j w_k u(\xi_{1,i} \xi_{2,j} \xi_{3,k})
         *
         * J_{i,j,k}\\ & = & \sum_{i=0}^{nq_0} \psi_p^a(\xi_{1,i})
         *                   \sum_{j=0}^{nq_1} \psi_{q}^a(\xi_{2,j})
         *                   \sum_{k=0}^{nq_2} \psi_{r}^a
         *                   u(\xi_{1i},\xi_{2j},\xi_{3k}) J_{i,j,k}
         * \end{array} \f$ \n
         * where
         * \f$ \phi_{pqr} (\xi_1 , \xi_2 , \xi_3)
         *  = \psi_p^a( \xi_1) \psi_{q}^a(\xi_2) \psi_{r}^a(\xi_3) \f$ \n
         * which can be implemented as \n
         * \f$f_{r} (\xi_{3k})
         *  = \sum_{k=0}^{nq_3} \psi_{r}^a u(\xi_{1i},\xi_{2j}, \xi_{3k})
         * J_{i,j,k} = {\bf B_3 U}   \f$ \n
         * \f$ g_{q} (\xi_{3k})
         *  = \sum_{j=0}^{nq_1} \psi_{q}^a(\xi_{2j}) f_{r}(\xi_{3k})
         *  = {\bf B_2 F}  \f$ \n
         * \f$ (\phi_{pqr}, u)_{\delta}
         *  = \sum_{k=0}^{nq_0} \psi_{p}^a (\xi_{3k})  g_{q} (\xi_{3k})
         *  = {\bf B_1 G} \f$
         *
         * @param   inarray     ?
         * @param   outarray    ?
         */
        void StdHexExp::v_IProductWRTBase(
365
366
                const Array<OneD, const NekDouble> &inarray,
                      Array<OneD,       NekDouble> &outarray)
367
        {
368
369
370
            if(m_base[0]->Collocation() && 
               m_base[1]->Collocation() && 
               m_base[2]->Collocation())
371
372
            {
                MultiplyByQuadratureMetric(inarray,outarray);
373
            }
374
375
376
            else
            {
                StdHexExp::v_IProductWRTBase_SumFac(inarray,outarray);
377
            }
Mike Kirby's avatar
Mike Kirby committed
378
        }
379
380

        /**
381
         * Implementation of the local matrix inner product operation.
382
         */
383
384
        void StdHexExp::v_IProductWRTBase_MatOp(const Array<OneD, const NekDouble>& inarray,
                                               Array<OneD, NekDouble> &outarray)
385
        {
386
            int nq = GetTotPoints();
387
            StdMatrixKey      iprodmatkey(eIProductWRTBase,DetShapeType(),*this);
388
            DNekMatSharedPtr  iprodmat = GetStdMatrix(iprodmatkey);
389

390
391
            Blas::Dgemv('N',m_ncoeffs,nq,1.0,iprodmat->GetPtr().get(),
                        m_ncoeffs, inarray.get(), 1, 0.0, outarray.get(), 1);
392
        }
393

394
        /**
395
         * Implementation of the sum-factorization inner product operation.
396
         */
397
398
399
        void StdHexExp::v_IProductWRTBase_SumFac(
            const Array<OneD, const NekDouble>& inarray,
                  Array<OneD, NekDouble> &outarray)
400
        {
401
402
403
404
405
            int    nquad0 = m_base[0]->GetNumPoints();
            int    nquad1 = m_base[1]->GetNumPoints();
            int    nquad2 = m_base[2]->GetNumPoints();
            int    order0 = m_base[0]->GetNumModes();
            int    order1 = m_base[1]->GetNumModes();
406

407
            Array<OneD, NekDouble> tmp(inarray.num_elements());
408
409
            Array<OneD, NekDouble> wsp(nquad0*nquad1*(nquad2+order0) + 
                                       order0*order1*nquad2);
410

411
            MultiplyByQuadratureMetric(inarray,tmp);
412

413
414
415
416
417
            StdHexExp::IProductWRTBase_SumFacKernel(m_base[0]->GetBdata(),
                                         m_base[1]->GetBdata(),
                                         m_base[2]->GetBdata(),
                                         tmp,outarray,wsp,true,true,true);
        }
418
419


420
        /**
421
422
         * Implementation of the sum-factorisation inner product operation.
         * @todo    Implement cases where only some directions are collocated.
423
         */
424
        void StdHexExp::v_IProductWRTBase_SumFacKernel(const Array<OneD, const NekDouble>& base0,
425
426
427
428
429
430
431
432
                                                     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)
433
        {
434
435
436
437
438
439
            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();
440

441
442
443
            bool colldir0 = doCheckCollDir0?(m_base[0]->Collocation()):false;
            bool colldir1 = doCheckCollDir1?(m_base[1]->Collocation()):false;
            bool colldir2 = doCheckCollDir2?(m_base[2]->Collocation()):false;
444

445
            if(colldir0 && colldir1 && colldir2)
446
            {
447
448
449
450
451
452
                Vmath::Vcopy(m_ncoeffs,inarray.get(),1,outarray.get(),1);
            }
            else
            {               
                ASSERTL1(wsp.num_elements() >= nmodes0*nquad2*(nquad1+nmodes1),
                         "Insufficient workspace size");
453

454
455
                Array<OneD, NekDouble> tmp0 = wsp;
                Array<OneD, NekDouble> tmp1 = wsp + nmodes0*nquad1*nquad2;
456

457
458
459
460
                Blas::Dgemm('T', 'N', nquad1*nquad2, nmodes0, nquad0,
                            1.0, inarray.get(),  nquad0,
                                 base0.get(),    nquad0,
                            0.0, tmp0.get(),     nquad1*nquad2);
461

462
463
464
465
                Blas::Dgemm('T', 'N', nquad2*nmodes0, nmodes1, nquad1,
                            1.0, tmp0.get(),     nquad1,
                                 base1.get(),    nquad1,
                            0.0, tmp1.get(),     nquad2*nmodes0);
466

467
468
469
470
                Blas::Dgemm('T', 'N', nmodes0*nmodes1, nmodes2, nquad2,
                            1.0, tmp1.get(),     nquad2,
                                 base2.get(),    nquad2,
                            0.0, outarray.get(), nmodes0*nmodes1);
471
            }
472
        }
473

474
475
476
477

        void StdHexExp::v_IProductWRTDerivBase(const int dir,
                const Array<OneD, const NekDouble>& inarray,
                Array<OneD, NekDouble> & outarray)
478
        {
479
480
            StdHexExp::IProductWRTDerivBase_SumFac(dir,inarray,outarray);
        }
481
482


483
484
485
486
487
        void StdHexExp::v_IProductWRTDerivBase_MatOp(const int dir,
                                                    const Array<OneD, const NekDouble>& inarray,
                                                    Array<OneD, NekDouble> &outarray)
        {
            ASSERTL0((dir==0)||(dir==1)||(dir==2),"input dir is out of range");
488

489
490
            int nq = GetTotPoints();
            MatrixType mtype;
491

492
            switch (dir)
493
            {
494
495
496
497
498
499
500
501
502
                case 0:
                    mtype = eIProductWRTDerivBase0;
                    break;
                case 1:
                    mtype = eIProductWRTDerivBase1;
                    break;
                case 2:
                    mtype = eIProductWRTDerivBase2;
                    break;
503
504
            }

505
            StdMatrixKey      iprodmatkey(mtype,DetShapeType(),*this);
506
            DNekMatSharedPtr  iprodmat = GetStdMatrix(iprodmatkey);
507

508
509
            Blas::Dgemv('N',m_ncoeffs,nq,1.0,iprodmat->GetPtr().get(),
                        m_ncoeffs, inarray.get(), 1, 0.0, outarray.get(), 1);
510
511
        }

512
513
514
515

        void StdHexExp::v_IProductWRTDerivBase_SumFac(const int dir,
                                                     const Array<OneD, const NekDouble>& inarray,
                                                     Array<OneD, NekDouble> &outarray)
516
        {
517
            ASSERTL0((dir==0)||(dir==1)||(dir==2),"input dir is out of range");
518

519
520
521
522
            int    nquad1 = m_base[1]->GetNumPoints();
            int    nquad2 = m_base[2]->GetNumPoints();
            int    order0 = m_base[0]->GetNumModes();
            int    order1 = m_base[1]->GetNumModes();
523

524
525
526
527
528
            // If outarray > inarray then no need for temporary storage.
            Array<OneD, NekDouble> tmp = outarray;
            if (outarray.num_elements() < inarray.num_elements())
            {
                tmp = Array<OneD, NekDouble>(inarray.num_elements());
529
            }
530
531
532
533
534
535
536
537
538

            // Need workspace for sumfackernel though
            Array<OneD, NekDouble> wsp(order0*nquad2*(nquad1+order1));

            // multiply by integration constants
            MultiplyByQuadratureMetric(inarray,tmp);

            // perform sum-factorisation
            switch (dir)
539
            {
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
                case 0:
                    IProductWRTBase_SumFacKernel(m_base[0]->GetDbdata(),
                                                 m_base[1]->GetBdata(),
                                                 m_base[2]->GetBdata(),
                                                 tmp,outarray,wsp,
                                                 false,true,true);
                    break;
                case 1:
                    IProductWRTBase_SumFacKernel(m_base[0]->GetBdata(),
                                                 m_base[1]->GetDbdata(),
                                                 m_base[2]->GetBdata(),
                                                 tmp,outarray,wsp,
                                                 true,false,true);
                    break;
                case 2:
                    IProductWRTBase_SumFacKernel(m_base[0]->GetBdata(),
                                                 m_base[1]->GetBdata(),
                                                 m_base[2]->GetDbdata(),
                                                 tmp,outarray,wsp,
                                                 true,true,false);
                    break;
561
562
563
            }
        }

564
565
        void StdHexExp::v_LocCoordToLocCollapsed(const Array<OneD, const NekDouble>& xi,
                                      Array<OneD, NekDouble>& eta)
566
        {
567
568
569
            eta[0] = xi[0];
            eta[1] = xi[1];
            eta[2] = xi[2];
570
        }
571
                                          
572
573
574
575
576
        /**
         * @note for hexahedral expansions _base[0] (i.e. p) modes run fastest.
         */
        void StdHexExp::v_FillMode(const int mode,
                                Array<OneD, NekDouble> &outarray)
577
        {
578
579
580
581
            int    i,j;
            int   nquad0 = m_base[0]->GetNumPoints();
            int   nquad1 = m_base[1]->GetNumPoints();
            int   nquad2 = m_base[2]->GetNumPoints();
582

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

587
588
589
590
591
            int   btmp0 = m_base[0]->GetNumModes();
            int   btmp1 = m_base[1]->GetNumModes();
            int   mode2 = mode/(btmp0*btmp1);
            int   mode1 = (mode-mode2*btmp0*btmp1)/btmp0;
            int   mode0 = (mode-mode2*btmp0*btmp1)%btmp0;
592

593
594
595
596
597
598
599
600
            ASSERTL2(mode2 == (int)floor((1.0*mode)/(btmp0*btmp1)),
                     "Integer Truncation not Equiv to Floor");
            ASSERTL2(mode1 == (int)floor((1.0*mode-mode2*btmp0*btmp1)
                                /(btmp0*btmp1)),
                     "Integer Truncation not Equiv to Floor");
            ASSERTL2(m_ncoeffs <= mode,
                     "calling argument mode is larger than total expansion "
                     "order");
601

602
            for(i = 0; i < nquad1*nquad2; ++i)
603
            {
604
                Vmath::Vcopy(nquad0,(NekDouble *)(base0.get() + mode0*nquad0),1,
605
606
                             &outarray[0]+i*nquad0, 1);
            }
607

608
            for(j = 0; j < nquad2; ++j)
609
            {
610
611
                for(i = 0; i < nquad0; ++i)
                {
612
                    Vmath::Vmul(nquad1,(NekDouble *)(base1.get() + mode1*nquad1),1,
613
614
615
                                &outarray[0]+i+j*nquad0*nquad1, nquad0,
                                &outarray[0]+i+j*nquad0*nquad1, nquad0);
                }
616
            }
617
618

            for(i = 0; i < nquad2; i++)
619
            {
620
621
                Blas::Dscal(nquad0*nquad1,base2[mode2*nquad2+i],
                            &outarray[0]+i*nquad0*nquad1,1);
622
            }
623
        }
624

625

626
        int StdHexExp::v_GetNverts() const
627
        {
628
629
            return 8;
        }
630

631

632
633
634
635
        int StdHexExp::v_GetNedges() const
        {
            return 12;
        }
636

637

638
639
640
641
        int StdHexExp::v_GetNfaces() const
        {
            return 6;
        }
642

643

644
        LibUtilities::ShapeType StdHexExp::v_DetShapeType() const
645
        {
646
            return LibUtilities::eHexahedron;
647
        };
648

649

650
651
        int StdHexExp::v_NumBndryCoeffs() const
        {
652
653
654
655
656
657
658
659
660
661
662
663
664
665
            ASSERTL1(GetBasisType(0) == LibUtilities::eModified_A ||
                     GetBasisType(0) == LibUtilities::eGLL_Lagrange,
                     "BasisType is not a boundary interior form");
            ASSERTL1(GetBasisType(1) == LibUtilities::eModified_A ||
                     GetBasisType(1) == LibUtilities::eGLL_Lagrange,
                     "BasisType is not a boundary interior form");
            ASSERTL1(GetBasisType(2) == LibUtilities::eModified_A ||
                     GetBasisType(2) == LibUtilities::eGLL_Lagrange,
                     "BasisType is not a boundary interior form");

            int nmodes0 = m_base[0]->GetNumModes();
            int nmodes1 = m_base[1]->GetNumModes();
            int nmodes2 = m_base[2]->GetNumModes();

666
667
668
669
670
            return ( 2*( nmodes0*nmodes1 + nmodes0*nmodes2
                        + nmodes1*nmodes2)
                     - 4*( nmodes0 + nmodes1 + nmodes2 ) + 8 );
        }

Sergey Yakovlev's avatar
Sergey Yakovlev committed
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
        int StdHexExp::v_NumDGBndryCoeffs() const
        {
            ASSERTL1(GetBasisType(0) == LibUtilities::eModified_A ||
                     GetBasisType(0) == LibUtilities::eGLL_Lagrange,
                     "BasisType is not a boundary interior form");
            ASSERTL1(GetBasisType(1) == LibUtilities::eModified_A ||
                     GetBasisType(1) == LibUtilities::eGLL_Lagrange,
                     "BasisType is not a boundary interior form");
            ASSERTL1(GetBasisType(2) == LibUtilities::eModified_A ||
                     GetBasisType(2) == LibUtilities::eGLL_Lagrange,
                     "BasisType is not a boundary interior form");

            int nmodes0 = m_base[0]->GetNumModes();
            int nmodes1 = m_base[1]->GetNumModes();
            int nmodes2 = m_base[2]->GetNumModes();

            return  2*( nmodes0*nmodes1 + nmodes0*nmodes2
                        + nmodes1*nmodes2 );
        }
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706

        int StdHexExp::v_GetEdgeNcoeffs(const int i) const
        {
            ASSERTL2((i >= 0)&&(i <= 11),"edge id is out of range");

            if((i == 0)||(i == 2)||(i == 8)||(i == 10))
            {
                return  GetBasisNumModes(0);
            }
            else if((i == 1)||(i == 3)||(i == 9)||(i == 11))
            {
                return  GetBasisNumModes(1);
            }
            else
            {
                return GetBasisNumModes(2);
            }
707
708
        }

709
710
711
712
713
        int StdHexExp::v_GetTotalEdgeIntNcoeffs() const
        {
	  return 4*(GetBasisNumModes(0)+GetBasisNumModes(1)+GetBasisNumModes(2));
	}

714

715
716
        int StdHexExp::v_GetFaceNcoeffs(const int i) const
        {
717
718
719
720
721
722
723
724
725
726
727
728
729
            ASSERTL2((i >= 0) && (i <= 5), "face id is out of range");
            if((i == 0) || (i == 5))
            {
                return GetBasisNumModes(0)*GetBasisNumModes(1);
            }
            else if((i == 1) || (i == 3))
            {
                return GetBasisNumModes(0)*GetBasisNumModes(2);
            }
            else
            {
                return GetBasisNumModes(1)*GetBasisNumModes(2);
            }
730
731
        }

732

733
734
        int StdHexExp::v_GetFaceIntNcoeffs(const int i) const
        {
735
736
737
738
739
740
741
742
743
744
745
746
747
748
            ASSERTL2((i >= 0) && (i <= 5), "face id is out of range");
            if((i == 0) || (i == 5))
            {
                return (GetBasisNumModes(0)-2)*(GetBasisNumModes(1)-2);
            }
            else if((i == 1) || (i == 3))
            {
                return (GetBasisNumModes(0)-2)*(GetBasisNumModes(2)-2);
            }
            else
            {
                return (GetBasisNumModes(1)-2)*(GetBasisNumModes(2)-2);
            }

749
750
        }

751
752
753
754
755
756
757
        int StdHexExp::v_GetTotalFaceIntNcoeffs() const
        {
	    return 2*((GetBasisNumModes(0)-2)*(GetBasisNumModes(1)-2)+
	              (GetBasisNumModes(0)-2)*(GetBasisNumModes(2)-2)+
		      (GetBasisNumModes(1)-2)*(GetBasisNumModes(2)-2));
	}

758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
        int StdHexExp::v_GetFaceNumPoints(const int i) const
        {
            ASSERTL2(i >= 0 && i <= 5, "face id is out of range");
            
            if (i == 0 || i == 5)
            {
                return m_base[0]->GetNumPoints()*
                       m_base[1]->GetNumPoints();
            }
            else if (i == 1 || i == 3)
            {
                return m_base[0]->GetNumPoints()*
                       m_base[2]->GetNumPoints();
            }
            else
            {
                return m_base[1]->GetNumPoints()*
                       m_base[2]->GetNumPoints();
            }
        }
778

779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
        LibUtilities::PointsKey StdHexExp::v_GetFacePointsKey(
            const int i, const int j) const
        {
            ASSERTL2(i >= 0 && i <= 5, "face id is out of range");
            ASSERTL2(j == 0 || j == 1, "face direction is out of range");
            
            if (i == 0 || i == 5)
            {
                return m_base[j]->GetPointsKey();
            }
            else if (i == 1 || i == 3)
            {
                return m_base[2*j]->GetPointsKey();
            }
            else
            {
                return m_base[j+1]->GetPointsKey();
            }
        }

799
800
801
802
        int StdHexExp::v_CalcNumberOfCoefficients(const std::vector<unsigned int> &nummodes, int &modes_offset)
        {
            int nmodes = nummodes[modes_offset]*nummodes[modes_offset+1]*nummodes[modes_offset+2];
            modes_offset += 3;
803

804
805
806
            return nmodes;
        }

807

808
809
810
811
812
813
        const LibUtilities::BasisKey StdHexExp::v_DetFaceBasisKey(
            const int i, const int k) const
        {
            ASSERTL2(i >= 0 && i <= 6, "face id is out of range");
            ASSERTL2(k >= 0 && k <= 1, "basis key id is out of range");
            
Dave Moxey's avatar
Dave Moxey committed
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
            //temporary solution, need to add conditions based on face id
            //also need to add check of the points type
            switch(i)
            {
                case 0:
                case 5:
                    switch(k)
                    {
                        case 0:
                            return GetBasis(0)->GetBasisKey();
                            break;
                        case 1:
                            return GetBasis(1)->GetBasisKey();
                            break;
                    }
                    break;
                case 1:
                case 3:
                    switch(k)
                    {
                        case 0:
                            return GetBasis(0)->GetBasisKey();
                            break;
                        case 1:
                            return GetBasis(2)->GetBasisKey();
                            break;
                    }
                    break;
                case 2:
                case 4:
                    switch(k)
                    {
                        case 0:
                            return GetBasis(1)->GetBasisKey();
                            break;
                        case 1:
                            return GetBasis(2)->GetBasisKey();
                            break;
                    }
                    break;
            }
            
            // Should never get here.
            return LibUtilities::NullBasisKey;
858
859
        }

860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
        LibUtilities::BasisType StdHexExp::v_GetEdgeBasisType(const int i) const
        {
            ASSERTL2((i >= 0)&&(i <= 11),"edge id is out of range");

            if((i == 0)||(i == 2)||(i==8)||(i==10))
            {
                return  GetBasisType(0);
            }
            else if((i == 1)||(i == 3)||(i == 9)||(i == 11))
            {
                return  GetBasisType(1);
            }
            else
            {
                return GetBasisType(2);
            }
        }

        void StdHexExp::v_GetCoords( Array<OneD, NekDouble> & xi_x,
                                Array<OneD, NekDouble> & xi_y,
                                Array<OneD, NekDouble> & xi_z)
        {
            Array<OneD, const NekDouble> eta_x = m_base[0]->GetZ();
            Array<OneD, const NekDouble> eta_y = m_base[1]->GetZ();
            Array<OneD, const NekDouble> eta_z = m_base[2]->GetZ();
            int Qx = GetNumPoints(0);
            int Qy = GetNumPoints(1);
            int Qz = GetNumPoints(2);

            // Convert collapsed coordinates into cartesian coordinates:
            // eta --> xi
            for( int k = 0; k < Qz; ++k ) {
                for( int j = 0; j < Qy; ++j ) {
                    for( int i = 0; i < Qx; ++i ) {
                        int s = i + Qx*(j + Qy*k);
                        xi_x[s] = eta_x[i];
                        xi_y[s] = eta_y[j];
                        xi_z[s] = eta_z[k];

                    }
                }
            }
        }


905
        /**
906
         * Only for basis type Modified_A or GLL_LAGRANGE in all directions.
907
         */
908
909
        void StdHexExp::v_GetFaceToElementMap(
            const int                  fid,
910
            const Orientation          faceOrient,
911
912
913
914
            Array<OneD, unsigned int> &maparray,
            Array<OneD,          int> &signarray,
            int                        nummodesA,
            int                        nummodesB)
915
        {
916
917
918
919
            int i,j;
            const int nummodes0 = m_base[0]->GetNumModes();
            const int nummodes1 = m_base[1]->GetNumModes();
            const int nummodes2 = m_base[2]->GetNumModes();
920
            
921
922
923
924
            ASSERTL1(GetEdgeBasisType(0) == GetEdgeBasisType(1) &&
                     GetEdgeBasisType(0) == GetEdgeBasisType(2),
                     "Method only implemented if BasisType is indentical in "
                     "all directions");
925
926
927
928
            ASSERTL1(GetEdgeBasisType(0) == LibUtilities::eModified_A ||
                     GetEdgeBasisType(0) == LibUtilities::eGLL_Lagrange,
                     "Method only implemented for Modified_A or GLL_Lagrange BasisType");
                        
929
            if (nummodesA == -1)
930
            {
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
                switch(fid)
                {
                    case 0:
                    case 5:
                        nummodesA = nummodes0;
                        nummodesB = nummodes1;
                        break;
                    case 1:
                    case 3:
                        nummodesA = nummodes0;
                        nummodesB = nummodes2;
                        break;
                    case 2:
                    case 4:
                        nummodesA = nummodes1;
                        nummodesB = nummodes2;
                        break;
                }
949
            }
950
951
952
            
            
            bool modified = GetEdgeBasisType(0) == LibUtilities::eModified_A;
953
            int nFaceCoeffs = nummodesA*nummodesB;
954
            
955
956
957
958
            if(maparray.num_elements() != nFaceCoeffs)
            {
                maparray = Array<OneD, unsigned int>(nFaceCoeffs);
            }
959
            
960
961
962
963
964
965
966
967
            if(signarray.num_elements() != nFaceCoeffs)
            {
                signarray = Array<OneD, int>(nFaceCoeffs,1);
            }
            else
            {
                fill( signarray.get() , signarray.get()+nFaceCoeffs, 1 );
            }
968
            
969
            Array<OneD, int> arrayindx(nFaceCoeffs);
970
            
971
            for(i = 0; i < nummodesB; i++)
972
            {
973
974
                for(j = 0; j < nummodesA; j++)
                {
975
                    if( faceOrient < 9 )
976
977
978
979
980
981
982
983
984
                    {
                        arrayindx[i*nummodesA+j] = i*nummodesA+j;
                    }
                    else
                    {
                        arrayindx[i*nummodesA+j] = j*nummodesB+i;
                    }
                }
            }
985
            
986
987
988
            int offset = 0;
            int jump1 = 1;
            int jump2 = 1;
989
            
990
991
            switch(fid)
            {
992
                case 5:
993
                {
994
995
996
997
998
999
1000
1001
1002
                    if (modified)
                    {
                        offset = nummodes0*nummodes1;
                    }
                    else
                    {
                        offset = (nummodes2-1)*nummodes0*nummodes1;
                        jump1 = nummodes0;
                    }
1003
                }
1004
                case 0:
1005
1006
1007
                {
                    jump1 = nummodes0;
                }
1008
1009
                    break;
                case 3:
1010
                {
1011
1012
1013
1014
1015
1016
1017
1018
1019
                    if (modified)
                    {
                        offset = nummodes0;
                    }
                    else
                    {
                        offset = nummodes0*(nummodes1-1);
                        jump1 = nummodes0*nummodes1;
                    }
1020
                }
1021
                case 1:
1022
1023
1024
                {
                    jump1 = nummodes0*nummodes1;
                }
1025
1026
                    break;
                case 2:
1027
                {
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
                    if (modified)
                    {
                        offset = 1;
                    }
                    else
                    {
                        offset = nummodes0-1;
                        jump1 = nummodes0*nummodes1;
                        jump2 = nummodes0;
                        
                    }
1039
                }
1040
                case 4:
1041
                {
1042
1043
                    jump1 = nummodes0*nummodes1;
                    jump2 = nummodes0;
1044
                }
1045
1046
1047
                    break;
                default:
                    ASSERTL0(false,"fid must be between 0 and 5");
1048
            }
1049
            
1050
            for(i = 0; i < nummodesB; i++)
1051
            {
1052
                for(j = 0; j < nummodesA; j++)
1053
                {
1054
                    maparray[ arrayindx[i*nummodesA+j] ]
1055
                    = i*jump1 + j*jump2 + offset;
1056
1057
                }
            }
1058
1059
1060
            
            
            
1061
            if( (faceOrient==6) || (faceOrient==8) ||
1062
               (faceOrient==11) || (faceOrient==12) )
1063
            {
1064
                if(faceOrient<9)
1065
                {
1066
                    if (modified)
1067
                    {
1068
                        for(i = 3; i < nummodesB; i+=2)
1069
                        {
1070
1071
1072
1073
                            for(j = 0; j < nummodesA; j++)
                            {
                                signarray[ arrayindx[i*nummodesA+j] ] *= -1;
                            }
1074
                        }
1075
1076
                        
                        for(i = 0; i < nummodesA; i++)
1077
                        {
1078
1079
                            swap( maparray[i] , maparray[i+nummodesA] );
                            swap( signarray[i] , signarray[i+nummodesA] );
1080
                        }
1081
                        
1082
                    }
1083
                    else
1084
                    {
1085
1086
1087
1088
1089
1090
1091
                        for(i = 0; i < nummodesA; i++)
                        {
                            for(j = 0; j < nummodesB/2; j++)
                            {
                                swap( maparray[i + j*nummodesA],
                                     maparray[i+nummodesA*nummodesB
                                              -nummodesA -j*nummodesA] );
1092
1093
1094
                                swap( signarray[i + j*nummodesA],
                                     signarray[i+nummodesA*nummodesB
                                              -nummodesA -j*nummodesA]);
1095
1096
                            }
                        }
1097
1098
                    }
                }
1099
1100
                else
                {
1101
                    if (modified)
1102
                    {
1103
                        for(i = 0; i < nummodesB; i++)
1104
                        {
1105
1106
1107
1108
                            for(j = 3; j < nummodesA; j+=2)
                            {
                                signarray[ arrayindx[i*nummodesA+j] ] *= -1;
                            }
1109
                        }
1110
1111
1112
1113
1114
                        
                        for(i = 0; i < nummodesB; i++)
                        {
                            swap( maparray[i] , maparray[i+nummodesB] );
                            swap( signarray[i] , signarray[i+nummodesB] );
1115
                        }
1116
                        
1117
                    }
1118
                    else
1119
                    {
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
                        for(i = 0; i < nummodesA; i++)
                        {
                            for(j = 0; j < nummodesB/2; j++)
                            {
                                swap( maparray[i*nummodesB + j],
                                     maparray[i*nummodesB + nummodesB -1 -j]);
                                swap( signarray[i*nummodesB + j],
                                     signarray[i*nummodesB + nummodesB -1 -j]);
                            }
                        }
1130
1131
                    }
                }
1132
            }
1133
            
1134
            if( (faceOrient==7) || (faceOrient==8) ||
1135
               (faceOrient==10) || (faceOrient==12) )
1136
            {
1137
                if(faceOrient<9)
1138
                {
1139
                    if (modified)
1140
                    {
1141
                        for(i = 0; i < nummodesB; i++)
1142
                        {
1143
1144
1145
1146
1147
1148
1149
                            for(j = 3; j < nummodesA; j+=2)
                            {
                                signarray[ arrayindx[i*nummodesA+j] ] *= -1;
                            }
                        }
                        
                        for(i = 0; i < nummodesB; i++)
1150
                        {
1151
1152
1153
1154
                            swap( maparray[i*nummodesA],
                                 maparray[i*nummodesA+1]);
                            swap( signarray[i*nummodesA],
                                 signarray[i*nummodesA+1]);
1155
1156
                        }
                    }