ExpList.h 88 KB
Newer Older
1
2
///////////////////////////////////////////////////////////////////////////////
//
3
// File ExpList.h
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
//
// 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.
//
// Description: Expansion list top class definition
//
///////////////////////////////////////////////////////////////////////////////

Spencer Sherwin's avatar
   
Spencer Sherwin committed
36
37
#ifndef NEKTAR_LIBS_MULTIREGIONS_EXPLIST_H
#define NEKTAR_LIBS_MULTIREGIONS_EXPLIST_H
38

39
#include <LibUtilities/Communication/Transposition.h>
40
#include <LibUtilities/Communication/Comm.h>
41
#include <LibUtilities/BasicUtils/SessionReader.h>
42
#include <SpatialDomains/MeshGraph.h>
43
#include <LocalRegions/Expansion.h>
44
45
46
#include <Collections/Collection.h>
#include <MultiRegions/MultiRegionsDeclspec.h>
#include <MultiRegions/MultiRegions.hpp>
47
#include <MultiRegions/GlobalMatrix.h>
Peter Vos's avatar
Peter Vos committed
48
#include <MultiRegions/GlobalMatrixKey.h>
49
#include <MultiRegions/GlobalOptimizationParameters.h>
50
#include <MultiRegions/AssemblyMap/AssemblyMap.h>
51
#include <boost/enable_shared_from_this.hpp>
52
#include <tinyxml.h>
53

54
55
namespace Nektar
{
Joe Frazier's avatar
Joe Frazier committed
56
    namespace MultiRegions
57
    {
58
        // Forward declarations
59
        class GlobalLinSys;
60
61
        class AssemblyMapDG;

62
63
64
        class AssemblyMapCG;
        class GlobalLinSysKey;
        class GlobalMatrix;
65

66
        enum Direction
67
68
69
70
71
72
73
        {
            eX,
            eY,
            eZ,
            eS,
            eN
        };
Andrew Comerford's avatar
Andrew Comerford committed
74
75
76
77
78
79
80
81
82
83

        enum ExpansionType
        {
            e0D,
            e1D,
            e2D,
            e3DH1D,
            e3DH2D,
            e3D,
            eNoType
84
        };       
85
86
        
        MultiRegions::Direction const DirCartesianMap[] =
87
88
89
90
91
        {
            eX,
            eY,
            eZ
        }; 
92
    
93
94
        /// A map between global matrix keys and their associated block
        /// matrices.
95
        typedef std::map<GlobalMatrixKey,DNekScalBlkMatSharedPtr> BlockMatrixMap;
96
        /// A shared pointer to a BlockMatrixMap.
97
        typedef boost::shared_ptr<BlockMatrixMap> BlockMatrixMapShPtr;
98
                   
99

100
        /// Base class for all multi-elemental spectral/hp expansions.
101
        class ExpList: public boost::enable_shared_from_this<ExpList>
Joe Frazier's avatar
Joe Frazier committed
102
103
        {
        public:
104
            /// The default constructor.
105
            MULTI_REGIONS_EXPORT ExpList();
106
            
107
            /// The default constructor.
108
            MULTI_REGIONS_EXPORT ExpList(
Chris Cantwell's avatar
Chris Cantwell committed
109
                    const LibUtilities::SessionReaderSharedPtr &pSession);
110
111
112

            /// The default constructor.
            MULTI_REGIONS_EXPORT ExpList(
Chris Cantwell's avatar
Chris Cantwell committed
113
114
                    const LibUtilities::SessionReaderSharedPtr &pSession,
                    const SpatialDomains::MeshGraphSharedPtr &pGraph);
115
116
117
118
119
120
            
            /// Constructor copying only elements defined in eIds.
            MULTI_REGIONS_EXPORT ExpList(
                const ExpList &in,
                const std::vector<unsigned int> &eIDs,
                const bool DeclareCoeffPhysArrays = true);
121

122
            /// The copy constructor.
Daniele de Grazia's avatar
Daniele de Grazia committed
123
124
125
            MULTI_REGIONS_EXPORT ExpList(
                const ExpList &in,
                const bool DeclareCoeffPhysArrays = true);
Peter Vos's avatar
Peter Vos committed
126

127
            /// The default destructor.
128
            MULTI_REGIONS_EXPORT virtual ~ExpList();
129
            
130
131
            /// Returns the total number of local degrees of freedom
            /// \f$N_{\mathrm{eof}}=\sum_{e=1}^{{N_{\mathrm{el}}}}N^{e}_m\f$.
132
            inline int GetNcoeffs(void) const;
Spencer Sherwin's avatar
Spencer Sherwin committed
133
134
135
            
            /// Returns the total number of local degrees of freedom
            /// for element eid
136
            MULTI_REGIONS_EXPORT int GetNcoeffs(const int eid) const;
137

Andrew Comerford's avatar
Andrew Comerford committed
138
139
140
141
142
            /// Returns the type of the expansion
            MULTI_REGIONS_EXPORT ExpansionType GetExpType(void);
            
            /// Returns the type of the expansion
            MULTI_REGIONS_EXPORT void SetExpType(ExpansionType Type);
143
    
144
145
            /// Evaulates the maximum number of modes in the elemental basis
            /// order over all elements
146
            inline int EvalBasisNumModesMax(void) const;
147
148
149

            /// Returns the vector of the number of modes in the elemental
            /// basis order over all elements.
Daniele de Grazia's avatar
Daniele de Grazia committed
150
151
            MULTI_REGIONS_EXPORT const Array<OneD,int>
                EvalBasisNumModesMaxPerExp(void) const;
152
153
154

            /// Returns the total number of quadrature points #m_npoints
            /// \f$=Q_{\mathrm{tot}}\f$.
155
            inline int GetTotPoints(void) const;
156

Sehun Chun's avatar
Sehun Chun committed
157
158
            /// Returns the total number of quadrature points for eid's element
            /// \f$=Q_{\mathrm{tot}}\f$.
159
            inline int GetTotPoints(const int eid) const;
160
            
161
162
            /// Returns the total number of quadrature points #m_npoints
            /// \f$=Q_{\mathrm{tot}}\f$.
163
            inline int GetNpoints(void) const;
164

165
166
167
168
            
            /// Returns the total number of qudature points scaled by
            /// the factor scale on each 1D direction
            inline int Get1DScaledTotPoints(const NekDouble scale) const;
169
            
170
171
            /// Sets the wave space to the one of the possible configuration
            /// true or false
172
            inline void SetWaveSpace(const bool wavespace);
173
            
174
            
175
176
177
            ///Set Modified Basis for the stability analysis
            inline void SetModifiedBasis(const bool modbasis);
            
178
179
            /// Set the \a i th value of \a m_phys to value \a val
            inline void SetPhys(int i, NekDouble val);
180
            
181
            /// This function returns the third direction expansion condition,
182
            /// which can be in wave space (coefficient) or not
183
184
            /// It is stored in the variable m_WaveSpace.
            inline bool GetWaveSpace(void) const;
185
            
186
            /// Fills the array #m_phys
187
            inline void SetPhys(const Array<OneD, const NekDouble> &inarray);
188

189
190
191
            /// Sets the array #m_phys
            inline void SetPhysArray(Array<OneD, NekDouble> &inarray);

192
193
194
            /// This function manually sets whether the array of physical
            /// values \f$\boldsymbol{u}_l\f$ (implemented as #m_phys) is
            /// filled or not.
195
            inline void SetPhysState(const bool physState);
196
197
198
199

            /// This function indicates whether the array of physical values
            /// \f$\boldsymbol{u}_l\f$ (implemented as #m_phys) is filled or
            /// not.
200
            inline bool GetPhysState(void) const;
201
202
203

            /// This function integrates a function \f$f(\boldsymbol{x})\f$
            /// over the domain consisting of all the elements of the expansion.
204
            MULTI_REGIONS_EXPORT NekDouble PhysIntegral (void);
205

206
207
            /// This function integrates a function \f$f(\boldsymbol{x})\f$
            /// over the domain consisting of all the elements of the expansion.
Daniele de Grazia's avatar
Daniele de Grazia committed
208
209
210
            MULTI_REGIONS_EXPORT NekDouble PhysIntegral(
                const Array<OneD,
                const NekDouble> &inarray);
211

212
213
214
            /// This function calculates the inner product of a function
            /// \f$f(\boldsymbol{x})\f$ with respect to all \emph{local}
            /// expansion modes \f$\phi_n^e(\boldsymbol{x})\f$.
215
            inline void   IProductWRTBase_IterPerExp(
Daniele de Grazia's avatar
Daniele de Grazia committed
216
217
                const Array<OneD, const NekDouble> &inarray,
                      Array<OneD,       NekDouble> &outarray);
218

219
220
            ///
            inline void IProductWRTBase(
Daniele de Grazia's avatar
Daniele de Grazia committed
221
222
223
                const Array<OneD, const NekDouble> &inarray,
                      Array<OneD,       NekDouble> &outarray,
                      CoeffState coeffstate = eLocal);
224
225
226
227
228

            /// This function calculates the inner product of a function
            /// \f$f(\boldsymbol{x})\f$ with respect to the derivative (in
            /// direction \param dir) of all \emph{local} expansion modes
            /// \f$\phi_n^e(\boldsymbol{x})\f$.
Daniele de Grazia's avatar
Daniele de Grazia committed
229
230
231
232
            MULTI_REGIONS_EXPORT void   IProductWRTDerivBase
                (const int dir,
                 const Array<OneD, const NekDouble> &inarray,
                       Array<OneD,       NekDouble> &outarray);
233

234
235
236
237
238
239
240
241
            /// This function calculates the inner product of a function
            /// \f$f(\boldsymbol{x})\f$ with respect to the derivative (in
            /// direction \param dir) of all \emph{local} expansion modes
            /// \f$\phi_n^e(\boldsymbol{x})\f$.
            MULTI_REGIONS_EXPORT void   IProductWRTDerivBase
                (const Array<OneD, const Array<OneD, NekDouble> > &inarray,
                 Array<OneD,       NekDouble> &outarray);

242
243
244
            /// This function elementally evaluates the forward transformation
            /// of a function \f$u(\boldsymbol{x})\f$ onto the global
            /// spectral/hp expansion.
Daniele de Grazia's avatar
Daniele de Grazia committed
245
246
247
248
            inline void  FwdTrans_IterPerExp (
                const Array<OneD,
                const NekDouble> &inarray,
                      Array<OneD,NekDouble> &outarray);
249

250
            ///
Daniele de Grazia's avatar
Daniele de Grazia committed
251
252
253
254
255
            inline void FwdTrans(
                const Array<OneD,
                const NekDouble> &inarray,
                      Array<OneD,       NekDouble> &outarray,
                      CoeffState coeffstate = eLocal);
256
257
258

            /// This function elementally mulplies the coefficient space of
            /// Sin my the elemental inverse of the mass matrix.
259
            MULTI_REGIONS_EXPORT void  MultiplyByElmtInvMass (
Daniele de Grazia's avatar
Daniele de Grazia committed
260
261
262
                 const Array<OneD,
                 const NekDouble> &inarray,
                 Array<OneD,       NekDouble> &outarray);
263

264
265
            ///
            inline void MultiplyByInvMassMatrix(
Daniele de Grazia's avatar
Daniele de Grazia committed
266
267
268
                const Array<OneD,const NekDouble> &inarray,
                      Array<OneD,      NekDouble> &outarray,
                      CoeffState coeffstate = eLocal);
269
270
271

            /// Smooth a field across elements
            inline void SmoothField(Array<OneD,NekDouble> &field);
272

273
274
            /// Solve helmholtz problem
            inline void HelmSolve(
Daniele de Grazia's avatar
Daniele de Grazia committed
275
276
277
278
279
280
281
                const Array<OneD, const NekDouble> &inarray,
                      Array<OneD,       NekDouble> &outarray,
                const FlagList &flags,
                const StdRegions::ConstFactorMap &factors,
                const StdRegions::VarCoeffMap &varcoeff =
                                StdRegions::NullVarCoeffMap,
                const Array<OneD, const NekDouble> &dirForcing =
282
                NullNekDouble1DArray,
283
284
                const bool PhysSpaceForcing = true);
            
285
            /// Solve Advection Diffusion Reaction
286
            inline void LinearAdvectionDiffusionReactionSolve(
Daniele de Grazia's avatar
Daniele de Grazia committed
287
                const Array<OneD, Array<OneD, NekDouble> > &velocity,
288
289
290
                       const Array<OneD, const NekDouble> &inarray,
                       Array<OneD, NekDouble> &outarray,
                       const NekDouble lambda,
291
                       CoeffState coeffstate = eLocal, 
292
293
294
295
                       const Array<OneD, const NekDouble>&
                       dirForcing = NullNekDouble1DArray);


296
            /// Solve Advection Diffusion Reaction
297
            inline void LinearAdvectionReactionSolve(
Daniele de Grazia's avatar
Daniele de Grazia committed
298
299
300
301
302
303
304
                const Array<OneD, Array<OneD, NekDouble> > &velocity,
                const Array<OneD, const NekDouble> &inarray,
                      Array<OneD, NekDouble> &outarray,
                const NekDouble lambda,
                      CoeffState coeffstate = eLocal,
                const Array<OneD, const NekDouble>&
                      dirForcing = NullNekDouble1DArray);
305

306
            ///
307
            MULTI_REGIONS_EXPORT void FwdTrans_BndConstrained(
Daniele de Grazia's avatar
Daniele de Grazia committed
308
309
                const Array<OneD, const NekDouble> &inarray,
                      Array<OneD,       NekDouble> &outarray);
310
311
312
313


            /// This function elementally evaluates the backward transformation
            /// of the global spectral/hp element expansion.
Daniele de Grazia's avatar
Daniele de Grazia committed
314
315
316
            inline void BwdTrans_IterPerExp (
                const Array<OneD, const NekDouble> &inarray,
                      Array<OneD,NekDouble> &outarray);
317

318
            ///
Daniele de Grazia's avatar
Daniele de Grazia committed
319
320
321
322
323
            inline void BwdTrans (
                const Array<OneD,
                const NekDouble> &inarray,
                      Array<OneD,NekDouble> &outarray,
                      CoeffState coeffstate = eLocal);
324
325
326

            /// This function calculates the coordinates of all the elemental
            /// quadrature points \f$\boldsymbol{x}_i\f$.
Daniele de Grazia's avatar
Daniele de Grazia committed
327
328
329
330
            inline void GetCoords(
                Array<OneD, NekDouble> &coord_0,
                Array<OneD, NekDouble> &coord_1 = NullNekDouble1DArray,
                Array<OneD, NekDouble> &coord_2 = NullNekDouble1DArray);
331
332
            
            // Homogeneous transforms
Daniele de Grazia's avatar
Daniele de Grazia committed
333
334
335
336
337
338
            inline void HomogeneousFwdTrans(
                const Array<OneD, const NekDouble> &inarray,
                      Array<OneD, NekDouble> &outarray,
                      CoeffState coeffstate = eLocal,
                bool Shuff = true,
                bool UnShuff = true);
339
            
Daniele de Grazia's avatar
Daniele de Grazia committed
340
341
342
343
344
345
            inline void HomogeneousBwdTrans(
                const Array<OneD, const NekDouble> &inarray,
                      Array<OneD, NekDouble> &outarray,
                      CoeffState coeffstate = eLocal,
                bool Shuff = true,
                bool UnShuff = true);
346
            
Daniele de Grazia's avatar
Daniele de Grazia committed
347
348
349
350
351
            inline void DealiasedProd(
                const Array<OneD, NekDouble> &inarray1,
                const Array<OneD, NekDouble> &inarray2,
                      Array<OneD, NekDouble> &outarray,
                      CoeffState coeffstate = eLocal);
352
353
354
355
356
357
358

            inline void DealiasedDotProd(
                const Array<OneD, Array<OneD, NekDouble> > &inarray1,
                const Array<OneD, Array<OneD, NekDouble> > &inarray2,
                      Array<OneD, Array<OneD, NekDouble> > &outarray,
                      CoeffState coeffstate = eLocal);

Daniele de Grazia's avatar
Daniele de Grazia committed
359
360
361
362
            inline void GetBCValues(
                      Array<OneD, NekDouble> &BndVals,
                const Array<OneD, NekDouble> &TotField,
                int BndID);
363
            
Daniele de Grazia's avatar
Daniele de Grazia committed
364
365
366
367
368
            inline void NormVectorIProductWRTBase(
                Array<OneD, const NekDouble> &V1,
                Array<OneD, const NekDouble> &V2,
                Array<OneD, NekDouble> &outarray,
                int BndID);
369
            
370
371
372
373
            inline void NormVectorIProductWRTBase(
                Array<OneD, Array<OneD, NekDouble> > &V,
                Array<OneD, NekDouble> &outarray);
            
374
            /// Apply geometry information to each expansion.
375
            MULTI_REGIONS_EXPORT void ApplyGeomInfo();
Chris Cantwell's avatar
Chris Cantwell committed
376

377
            /// Reset geometry information and reset matrices
378
379
380
381
            MULTI_REGIONS_EXPORT void Reset()
            {
                v_Reset();
            }
382

383
            void WriteTecplotHeader(std::ostream &outfile,
384
                                    std::string var = "")
385
            {
386
                v_WriteTecplotHeader(outfile, var);
387
            }
Chris Cantwell's avatar
Chris Cantwell committed
388

389
            void WriteTecplotZone(
390
                std::ostream &outfile,
391
                int expansion = -1)
392
            {
393
                v_WriteTecplotZone(outfile, expansion);
394
395
            }

396
            void WriteTecplotField(std::ostream &outfile,
397
                                   int expansion = -1)
398
            {
399
                v_WriteTecplotField(outfile, expansion);
400
            }
Chris Cantwell's avatar
Chris Cantwell committed
401

402
            void WriteTecplotConnectivity(std::ostream &outfile,
403
                                          int expansion = -1)
404
            {
405
                v_WriteTecplotConnectivity(outfile, expansion);
406
            }
Spencer Sherwin's avatar
... ?    
Spencer Sherwin committed
407

408
409
            MULTI_REGIONS_EXPORT void WriteVtkHeader(std::ostream &outfile);
            MULTI_REGIONS_EXPORT void WriteVtkFooter(std::ostream &outfile);
410

411
            void WriteVtkPieceHeader(std::ostream &outfile, int expansion,
412
                                     int istrip = 0)
413
            {
414
                v_WriteVtkPieceHeader(outfile, expansion, istrip);
415
416
            }

Daniele de Grazia's avatar
Daniele de Grazia committed
417
            MULTI_REGIONS_EXPORT void WriteVtkPieceFooter(
418
                std::ostream &outfile,
Daniele de Grazia's avatar
Daniele de Grazia committed
419
                int expansion);
420

Daniele de Grazia's avatar
Daniele de Grazia committed
421
            void WriteVtkPieceData  (
422
                std::ostream &outfile,
Daniele de Grazia's avatar
Daniele de Grazia committed
423
424
                int expansion,
                std::string var = "v")
425
426
427
            {
                v_WriteVtkPieceData(outfile, expansion, var);
            }
Chris Cantwell's avatar
Chris Cantwell committed
428

429
430
431
            /// This function returns the dimension of the coordinates of the
            /// element \a eid.
            // inline
432
            MULTI_REGIONS_EXPORT int GetCoordim(int eid);
433
434

            /// Set the \a i th coefficiient in \a m_coeffs to value \a val
435
            inline void SetCoeff(int i, NekDouble val);
436
            
437
            /// Set the \a i th coefficiient in  #m_coeffs to value \a val
438
            inline void SetCoeffs(int i, NekDouble val);
439

440
441
442
            /// Set the  #m_coeffs array to inarray
            inline void SetCoeffsArray(Array<OneD, NekDouble> &inarray);

443
444
445
            /// This function returns (a reference to) the array
            /// \f$\boldsymbol{\hat{u}}_l\f$ (implemented as #m_coeffs)
            /// containing all local expansion coefficients.
446
            inline const Array<OneD, const NekDouble> &GetCoeffs() const;
447

448
            /// Impose Dirichlet Boundary Conditions onto Array
Daniele de Grazia's avatar
Daniele de Grazia committed
449
450
            inline void ImposeDirichletConditions(
                Array<OneD,NekDouble>& outarray);
451

452

453
454
            /// Fill Bnd Condition expansion from the values stored in expansion
            inline void FillBndCondFromField(void);
455

456
457
458
            /// Fill Bnd Condition expansion in nreg from the values stored in expansion
            inline void FillBndCondFromField(const int nreg);

459
460
461
            /// Gathers the global coefficients \f$\boldsymbol{\hat{u}}_g\f$
            /// from the local coefficients \f$\boldsymbol{\hat{u}}_l\f$.
            // inline
462
            MULTI_REGIONS_EXPORT inline void LocalToGlobal(bool useComm = true);
463

464
465
            MULTI_REGIONS_EXPORT inline void LocalToGlobal(
                const Array<OneD, const NekDouble> &inarray,
466
467
                Array<OneD,NekDouble> &outarray,
                bool useComm = true);
468
469
470
471
472
473
474

            /// Scatters from the global coefficients
            /// \f$\boldsymbol{\hat{u}}_g\f$ to the local coefficients
            /// \f$\boldsymbol{\hat{u}}_l\f$.
            // inline
            MULTI_REGIONS_EXPORT inline void GlobalToLocal(void);

475
476
477
            /**
             * This operation is evaluated as:
             * \f{tabbing}
Chris Cantwell's avatar
Chris Cantwell committed
478
479
             * \hspace{1cm}  \= Do \= $e=$  $1, N_{\mathrm{el}}$ \\
             * \> \> Do \= $i=$  $0,N_m^e-1$ \\
480
             * \> \> \> $\boldsymbol{\hat{u}}^{e}[i] = \mbox{sign}[e][i] \cdot
Chris Cantwell's avatar
Chris Cantwell committed
481
482
             * \boldsymbol{\hat{u}}_g[\mbox{map}[e][i]]$ \\
             * \> \> continue \\
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
             * \> continue
             * \f}
             * where \a map\f$[e][i]\f$ is the mapping array and \a
             * sign\f$[e][i]\f$ is an array of similar dimensions ensuring the
             * correct modal connectivity between the different elements (both
             * these arrays are contained in the data member #m_locToGloMap). This
             * operation is equivalent to the scatter operation
             * \f$\boldsymbol{\hat{u}}_l=\mathcal{A}\boldsymbol{\hat{u}}_g\f$,
             * where \f$\mathcal{A}\f$ is the
             * \f$N_{\mathrm{eof}}\times N_{\mathrm{dof}}\f$ permutation matrix.
             *
             * @param   inarray     An array of size \f$N_\mathrm{dof}\f$
             *                      containing the global degrees of freedom
             *                      \f$\boldsymbol{x}_g\f$.
             * @param   outarray    The resulting local degrees of freedom
             *                      \f$\boldsymbol{x}_l\f$ will be stored in this
             *                      array of size \f$N_\mathrm{eof}\f$.
             */
501
502
503
            MULTI_REGIONS_EXPORT inline void GlobalToLocal(
                const Array<OneD, const NekDouble> &inarray,
                Array<OneD,NekDouble> &outarray);
504

505
            /// Get the \a i th value  (coefficient) of #m_coeffs
506
            inline NekDouble GetCoeff(int i);
507
508

            /// Get the \a i th value  (coefficient) of #m_coeffs
509
            inline NekDouble GetCoeffs(int i);
510
511
512
513
514
515

            /// This function returns (a reference to) the array
            /// \f$\boldsymbol{u}_l\f$ (implemented as #m_phys) containing the
            /// function \f$u^{\delta}(\boldsymbol{x})\f$ evaluated at the
            /// quadrature points.
            // inline
Daniele de Grazia's avatar
Daniele de Grazia committed
516
517
            MULTI_REGIONS_EXPORT const Array<OneD, const NekDouble>
                &GetPhys()  const;
518
519
520

            /// This function calculates the \f$L_\infty\f$ error of the global
            /// spectral/hp element approximation.
521
522
523
            MULTI_REGIONS_EXPORT NekDouble Linf (
                const Array<OneD, const NekDouble> &inarray,
                const Array<OneD, const NekDouble> &soln = NullNekDouble1DArray);
524

Spencer Sherwin's avatar
Spencer Sherwin committed
525
526
            /// This function calculates the \f$L_2\f$ error with
            /// respect to soln of the global
527
            /// spectral/hp element approximation.
528
529
530
            NekDouble L2(
                const Array<OneD, const NekDouble> &inarray,
                const Array<OneD, const NekDouble> &soln = NullNekDouble1DArray)
531
            {
532
                return v_L2(inarray, soln);
533
            }
534

535
536
537
538
539
540
541
            /// Calculates the \f$H^1\f$ error of the global spectral/hp
            /// element approximation.
            MULTI_REGIONS_EXPORT NekDouble H1 (
                const Array<OneD, const NekDouble> &inarray,
                const Array<OneD, const NekDouble> &soln = NullNekDouble1DArray);
            
            NekDouble Integral (const Array<OneD, const NekDouble> &inarray)
542
543
544
545
            {
                return v_Integral(inarray);
            }

546
547
            /// This function calculates the energy associated with
            /// each one of the modesof a 3D homogeneous nD expansion
548
            Array<OneD, const NekDouble> HomogeneousEnergy (void)
549
550
551
            {
                return v_HomogeneousEnergy();
            }
552
553
554
555
556
557
558
559

            /// This function sets the Spectral Vanishing Viscosity 
            /// in homogeneous1D expansion. 
            void SetHomo1DSpecVanVisc(Array<OneD, NekDouble> visc)
            {
                v_SetHomo1DSpecVanVisc(visc);
            }

560
561
562
563
            /// This function returns a vector containing the wave
            /// numbers in z-direction associated
            /// with the 3D homogenous expansion. Required if a
            /// parellelisation is applied in the Fourier direction
564
            Array<OneD, const unsigned int> GetZIDs(void)
565
566
567
            {
                return v_GetZIDs();
            }
568
569

            /// This function returns the transposition class
Daniele de Grazia's avatar
Daniele de Grazia committed
570
            /// associaed with the homogeneous expansion.
571
572
573
574
            LibUtilities::TranspositionSharedPtr GetTransposition(void)
            {
                return v_GetTransposition();
            }
575
            
Daniele de Grazia's avatar
Daniele de Grazia committed
576
577
578
579
580
581
582
            /// This function returns the Width of homogeneous direction
            /// associaed with the homogeneous expansion.
            NekDouble GetHomoLen(void)
            {
                return v_GetHomoLen();
            }
            
583
584
585
586
            /// This function returns a vector containing the wave
            /// numbers in y-direction associated
            /// with the 3D homogenous expansion. Required if a
            /// parellelisation is applied in the Fourier direction
587
            Array<OneD, const unsigned int> GetYIDs(void)
588
589
590
            {
                return v_GetYIDs();
            }
591
592
593
594
595

            /// This function interpolates the physical space points in
            /// \a inarray to \a outarray using the same points defined in the
            /// expansion but where the number of points are rescaled
            /// by \a 1DScale
Daniele de Grazia's avatar
Daniele de Grazia committed
596
597
598
599
            void PhysInterp1DScaled(
                const NekDouble scale,
                const Array<OneD, NekDouble> &inarray,
                      Array<OneD, NekDouble>  &outarray)
600
601
602
603
604
605
606
607
            {
                v_PhysInterp1DScaled(scale, inarray,outarray);                
            }

            /// This function Galerkin projects the physical space points in
            /// \a inarray to \a outarray where inarray is assumed to
            /// be defined in the expansion but where the number of
            /// points are rescaled by \a 1DScale
Daniele de Grazia's avatar
Daniele de Grazia committed
608
609
610
611
            void PhysGalerkinProjection1DScaled(
                const NekDouble scale,
                const Array<OneD, NekDouble> &inarray,
                      Array<OneD, NekDouble> &outarray)
612
613
614
615
            {
                v_PhysGalerkinProjection1DScaled(scale, inarray, outarray);
            } 

616
            /// This function returns the number of elements in the expansion.
617
            inline int GetExpSize(void);
618

619

620
621
622
623
624
625
626
627
            /// This function returns the number of elements in the
            /// expansion which may be different for a homogeoenous extended
            /// expansionp.
            inline int GetNumElmts(void)
            {
                return v_GetNumElmts();
            }

628
            /// This function returns the vector of elements in the expansion.
629
630
            inline const boost::shared_ptr<LocalRegions::ExpansionVector>
                    GetExp() const;
631

632
633
            /// This function returns (a shared pointer to) the local elemental
            /// expansion of the \f$n^{\mathrm{th}}\f$ element.
634
            inline LocalRegions::ExpansionSharedPtr& GetExp(int n) const;
635

636
637
            /// This function returns (a shared pointer to) the local elemental
            /// expansion containing the arbitrary point given by \a gloCoord.
638
            MULTI_REGIONS_EXPORT LocalRegions::ExpansionSharedPtr& GetExp(
Daniele de Grazia's avatar
Daniele de Grazia committed
639
                const Array<OneD, const NekDouble> &gloCoord);
640

641
642
643
            /** This function returns the index of the local elemental
             * expansion containing the arbitrary point given by \a gloCoord.
             **/
Daniele de Grazia's avatar
Daniele de Grazia committed
644
645
            MULTI_REGIONS_EXPORT int GetExpIndex(
                const Array<OneD, const NekDouble> &gloCoord,
646
647
                NekDouble tol = 0.0,
                bool returnNearestElmt = false);
648
649
650
651
652
653

            /** This function returns the index and the Local
             * Cartesian Coordinates \a locCoords of the local
             * elemental expansion containing the arbitrary point
             * given by \a gloCoords.
             **/ 
654
655
            MULTI_REGIONS_EXPORT int GetExpIndex(
                const Array<OneD, const NekDouble> &gloCoords, 
656
657
658
                Array<OneD, NekDouble>       &locCoords,
                NekDouble tol = 0.0,
                bool returnNearestElmt = false);
659

660
661
            /// Get the start offset position for a global list of #m_coeffs
            /// correspoinding to element n.
662
            inline int GetCoeff_Offset(int n) const;
663
664
665

            /// Get the start offset position for a global list of m_phys
            /// correspoinding to element n.
666
            inline int GetPhys_Offset(int n) const;
667
668
669

            /// Get the element id associated with the n th
            /// consecutive block of data in  #m_phys and #m_coeffs
670
            inline int GetOffset_Elmt_Id(int n) const;
671
672
673
674

            /// This function returns (a reference to) the array
            /// \f$\boldsymbol{\hat{u}}_l\f$ (implemented as #m_coeffs)
            /// containing all local expansion coefficients.
675
            inline Array<OneD, NekDouble> &UpdateCoeffs();
676
677
678
679
680

            /// This function returns (a reference to) the array
            /// \f$\boldsymbol{u}_l\f$ (implemented as #m_phys) containing the
            /// function \f$u^{\delta}(\boldsymbol{x})\f$ evaluated at the
            /// quadrature points.
681
            inline Array<OneD, NekDouble> &UpdatePhys();
682

Daniele de Grazia's avatar
Daniele de Grazia committed
683
684
685
            inline void PhysDeriv(
                Direction edir,
                const Array<OneD, const NekDouble> &inarray,
686
687
                      Array<OneD, NekDouble> &out_d);    
        
688
689
690
            /// This function discretely evaluates the derivative of a function
            /// \f$f(\boldsymbol{x})\f$ on the domain consisting of all
            /// elements of the expansion.
Daniele de Grazia's avatar
Daniele de Grazia committed
691
692
693
694
695
            inline void PhysDeriv(
                const Array<OneD, const NekDouble> &inarray,
                      Array<OneD, NekDouble> &out_d0,
                      Array<OneD, NekDouble> &out_d1 = NullNekDouble1DArray,
                      Array<OneD, NekDouble> &out_d2 = NullNekDouble1DArray);
696
            
Daniele de Grazia's avatar
Daniele de Grazia committed
697
698
699
700
            inline void PhysDeriv(
                const int dir,
                const Array<OneD, const NekDouble> &inarray,
                      Array<OneD, NekDouble> &out_d);
Douglas Serson's avatar
Douglas Serson committed
701
702
703
704
705

            inline void CurlCurl(
                Array<OneD, Array<OneD, NekDouble> > &Vel,
                Array<OneD, Array<OneD, NekDouble> > &Q);

706
            // functions associated with DisContField
Daniele de Grazia's avatar
Daniele de Grazia committed
707
708
            inline const Array<OneD, const  boost::shared_ptr<ExpList> >
                &GetBndCondExpansions();
709
            
710
            inline boost::shared_ptr<ExpList> &UpdateBndCondExpansion(int i);
711
            
712
            inline void Upwind(
Daniele de Grazia's avatar
Daniele de Grazia committed
713
714
715
716
                const Array<OneD, const Array<OneD,       NekDouble> > &Vec,
                const Array<OneD,                   const NekDouble>   &Fwd,
                const Array<OneD,                   const NekDouble>   &Bwd,
                      Array<OneD,                         NekDouble>   &Upwind);
717
718

            inline void Upwind(
Daniele de Grazia's avatar
Daniele de Grazia committed
719
720
721
722
                const Array<OneD, const NekDouble> &Vn,
                const Array<OneD, const NekDouble> &Fwd,
                const Array<OneD, const NekDouble> &Bwd,
                      Array<OneD,       NekDouble> &Upwind);
723
            
724
725
726
727
728
            /**
             * Return a reference to the trace space associated with this
             * expansion list.
             */
            inline boost::shared_ptr<ExpList> &GetTrace();
729
            
730
            inline boost::shared_ptr<AssemblyMapDG> &GetTraceMap(void);
731
            
Dave Moxey's avatar
Dave Moxey committed
732
            inline const Array<OneD, const int> &GetTraceBndMap(void);
733

734
            inline void GetNormals(Array<OneD, Array<OneD, NekDouble> > &normals);
735

736
            inline void AddTraceIntegral(
Daniele de Grazia's avatar
Daniele de Grazia committed
737
738
739
                const Array<OneD, const NekDouble> &Fx,
                const Array<OneD, const NekDouble> &Fy,
                Array<OneD, NekDouble> &outarray);
740

741
            inline void AddTraceIntegral(
Daniele de Grazia's avatar
Daniele de Grazia committed
742
743
                const Array<OneD, const NekDouble> &Fn,
                      Array<OneD, NekDouble> &outarray);
744

745
            inline void AddFwdBwdTraceIntegral(
Daniele de Grazia's avatar
Daniele de Grazia committed
746
747
748
                const Array<OneD, const NekDouble> &Fwd,
                const Array<OneD, const NekDouble> &Bwd,
                      Array<OneD, NekDouble> &outarray);
749

Daniele de Grazia's avatar
Daniele de Grazia committed
750
751
752
            inline void GetFwdBwdTracePhys(
                Array<OneD,NekDouble> &Fwd,
                Array<OneD,NekDouble> &Bwd);
753

754
            inline void GetFwdBwdTracePhys(
Daniele de Grazia's avatar
Daniele de Grazia committed
755
756
757
                const Array<OneD,const NekDouble> &field,
                      Array<OneD,NekDouble> &Fwd,
                      Array<OneD,NekDouble> &Bwd);
758

759
            inline const std::vector<bool> &GetLeftAdjacentFaces(void) const;
760
            
Daniele de Grazia's avatar
Daniele de Grazia committed
761
            inline void ExtractTracePhys(Array<OneD,NekDouble> &outarray);
762

763
            inline void ExtractTracePhys(
Daniele de Grazia's avatar
Daniele de Grazia committed
764
765
                const Array<OneD, const NekDouble> &inarray,
                      Array<OneD,NekDouble> &outarray);
766

Daniele de Grazia's avatar
Daniele de Grazia committed
767
768
            inline const Array<OneD, const SpatialDomains::
                BoundaryConditionShPtr>& GetBndConditions();
769

Daniele de Grazia's avatar
Daniele de Grazia committed
770
771
            inline Array<OneD, SpatialDomains::
                BoundaryConditionShPtr>& UpdateBndConditions();
772

773
            inline void EvaluateBoundaryConditions(
774
775
776
777
                const NekDouble   time      = 0.0,
                const std::string varName   = "",
                const             NekDouble = NekConstants::kNekUnsetDouble,
                const             NekDouble = NekConstants::kNekUnsetDouble);
778
779
780
781
782

            // Routines for continous matrix solution
            /// This function calculates the result of the multiplication of a
            /// matrix of type specified by \a mkey with a vector given by \a
            /// inarray.
Daniele de Grazia's avatar
Daniele de Grazia committed
783
784
785
786
787
            inline void GeneralMatrixOp(
                const GlobalMatrixKey             &gkey,
                const Array<OneD,const NekDouble> &inarray,
                      Array<OneD,      NekDouble> &outarray,
                      CoeffState coeffstate = eLocal);
788

Chris Cantwell's avatar
Chris Cantwell committed
789
            MULTI_REGIONS_EXPORT void GeneralMatrixOp_IterPerExp(
Daniele de Grazia's avatar
Daniele de Grazia committed
790
791
792
                const GlobalMatrixKey      &gkey,
                const Array<OneD,const NekDouble> &inarray,
                      Array<OneD,      NekDouble> &outarray);
793

794
            inline void SetUpPhysNormals();
795

796
            inline void GetBoundaryToElmtMap(Array<OneD, int> &ElmtID,
797
                                             Array<OneD,int> &EdgeID);
798
799
            
            inline void GetBndElmtExpansion(int i,
800
801
                            boost::shared_ptr<ExpList> &result,
                            const bool DeclareCoeffPhysArrays = true);
802
803
804
805
806
            
            inline void ExtractElmtToBndPhys(int i,
                            Array<OneD, NekDouble> &elmt,
                            Array<OneD, NekDouble> &boundary);
            
807
808
809
            inline void ExtractPhysToBndElmt(int i,
                            const Array<OneD, const NekDouble> &phys,
                            Array<OneD, NekDouble> &bndElmt);
Douglas Serson's avatar
Douglas Serson committed
810
811
812
813

            inline void ExtractPhysToBnd(int i,
                            const Array<OneD, const NekDouble> &phys,
                            Array<OneD, NekDouble> &bnd);
814
            
815
816
            inline void GetBoundaryNormals(int i,
                            Array<OneD, Array<OneD, NekDouble> > &normals);
817

818
            MULTI_REGIONS_EXPORT void  GeneralGetFieldDefinitions(
Daniele de Grazia's avatar
Daniele de Grazia committed
819
820
821
822
823
824
                std::vector<LibUtilities::FieldDefinitionsSharedPtr> &fielddef,
                int NumHomoDir = 0,
                Array<OneD, LibUtilities::BasisSharedPtr> &HomoBasis =
                    LibUtilities::NullBasisSharedPtr1DArray,
                std::vector<NekDouble> &HomoLen =
                    LibUtilities::NullNekDoubleVector,
825
                bool  homoStrips = false,
826
827
                std::vector<unsigned int> &HomoSIDs =
                    LibUtilities::NullUnsignedIntVector,
Daniele de Grazia's avatar
Daniele de Grazia committed
828
829
830
831
                std::vector<unsigned int> &HomoZIDs =
                    LibUtilities::NullUnsignedIntVector,
                std::vector<unsigned int> &HomoYIDs =
                    LibUtilities::NullUnsignedIntVector);
832
            
833

834
835
836
837
838
            const NekOptimize::GlobalOptParamSharedPtr &GetGlobalOptParam(void)
            {
                return m_globalOptParam;
            }

839
            std::map<int, RobinBCInfoSharedPtr> GetRobinBCInfo()
840
841
842
            {
                return v_GetRobinBCInfo();
            }
843

844
            void GetPeriodicEntities(
Dave Moxey's avatar
Dave Moxey committed
845
                PeriodicMap &periodicVerts,
846
847
                PeriodicMap &periodicEdges,
                PeriodicMap &periodicFaces = NullPeriodicMap)
848
            {
849
                v_GetPeriodicEntities(periodicVerts, periodicEdges, periodicFaces);
850
851
            }

852
            std::vector<LibUtilities::FieldDefinitionsSharedPtr>
853
854
855
856
857
858
                GetFieldDefinitions()
            {
                return v_GetFieldDefinitions();
            }


859
            void GetFieldDefinitions(std::vector<LibUtilities::FieldDefinitionsSharedPtr> &fielddef)
860
861
862
863
864
865
866
867
            {
                v_GetFieldDefinitions(fielddef);
            }



            /// Append the element data listed in elements
            /// fielddef->m_ElementIDs onto fielddata
Daniele de Grazia's avatar
Daniele de Grazia committed
868
869
870
            void AppendFieldData(
                LibUtilities::FieldDefinitionsSharedPtr &fielddef,
                std::vector<NekDouble> &fielddata)
871
872
873
            {
                v_AppendFieldData(fielddef,fielddata);
            }
874

875
876
877
            
            /// Append the data in coeffs listed in elements
            /// fielddef->m_ElementIDs onto fielddata
Daniele de Grazia's avatar
Daniele de Grazia committed
878
879
880
881
            void AppendFieldData(
                LibUtilities::FieldDefinitionsSharedPtr &fielddef,
                std::vector<NekDouble> &fielddata,
                Array<OneD, NekDouble> &coeffs)
882
883
884
885
            {
                v_AppendFieldData(fielddef,fielddata,coeffs);
            }

886
887
888
889
890

            /** \brief Extract the data in fielddata into the coeffs
             * using the basic ExpList Elemental expansions rather
             * than planes in homogeneous case
             */ 
891
            MULTI_REGIONS_EXPORT void ExtractElmtDataToCoeffs(
Daniele de Grazia's avatar
Daniele de Grazia committed
892
893
894
895
                LibUtilities::FieldDefinitionsSharedPtr &fielddef,
                std::vector<NekDouble> &fielddata,
                std::string &field,
                Array<OneD, NekDouble> &coeffs);
896
            
897

898
899
900
901
902
            /** \brief Extract the data from fromField using
             * fromExpList the coeffs using the basic ExpList
             * Elemental expansions rather than planes in homogeneous
             * case
             */ 
Daniele de Grazia's avatar
Daniele de Grazia committed
903
904
905
906
            MULTI_REGIONS_EXPORT  void ExtractCoeffsToCoeffs(
                const boost::shared_ptr<ExpList> &fromExpList,
                const Array<OneD, const NekDouble> &fromCoeffs,
                      Array<OneD, NekDouble> &toCoeffs);
907
908
            
            
909
            //Extract data in fielddata into the m_coeffs_list for the 3D stability analysis (base flow is 2D)
Chris Cantwell's avatar
Chris Cantwell committed
910
            MULTI_REGIONS_EXPORT void ExtractDataToCoeffs(
Daniele de Grazia's avatar
Daniele de Grazia committed
911
912
913
914
                LibUtilities::FieldDefinitionsSharedPtr &fielddef,
                std::vector<NekDouble> &fielddata,
                std::string &field,
                Array<OneD, NekDouble> &coeffs);
915
            
916

917
918
919
920
921
            /// Returns a shared pointer to the current object.
            boost::shared_ptr<ExpList> GetSharedThisPtr()
            {
                return shared_from_this();
            }
922

923
            /// Returns the session object
924
            boost::shared_ptr<LibUtilities::SessionReader> GetSession() const
925
926
927
928
            {
                return m_session;
            }

929
930
931
932
933
934
            /// Returns the comm object
            boost::shared_ptr<LibUtilities::Comm> GetComm()
            {
                return m_comm;
            }

935
936
937
938
939
            SpatialDomains::MeshGraphSharedPtr GetGraph()
            {
                return m_graph;
            }

940
941
942
            // Wrapper functions for Homogeneous Expansions
            inline LibUtilities::BasisSharedPtr  GetHomogeneousBasis(void)
            {
943
944
945
946
947
948
949
                return v_GetHomogeneousBasis();
            }

            boost::shared_ptr<ExpList> &GetPlane(int n)
            {
                return v_GetPlane(n);
            }
Yan Bao's avatar
Yan Bao committed
950
           
Andrew Comerford's avatar
Andrew Comerford committed
951
952
953
            //expansion type
            ExpansionType m_expType;

Chris Cantwell's avatar
Chris Cantwell committed
954
955
956
            MULTI_REGIONS_EXPORT void CreateCollections(
                    Collections::ImplementationType ImpType
                                                    = Collections::eNoImpType);
957

958
959
            MULTI_REGIONS_EXPORT void ClearGlobalLinSysManager(void);

960
        protected:
961
            boost::shared_ptr<DNekMat> GenGlobalMatrixFull(
Daniele de Grazia's avatar
Daniele de Grazia committed
962
963
                const GlobalLinSysKey &mkey,
                const boost::shared_ptr<AssemblyMapCG> &locToGloMap);
964

965
966
967
            /// Communicator
            LibUtilities::CommSharedPtr m_comm;

968
969
970
            /// Session
            LibUtilities::SessionReaderSharedPtr m_session;

971
972
973
            /// Mesh associated with this expansion list.
            SpatialDomains::MeshGraphSharedPtr m_graph;

974
975
976
977
            /// The total number of local degrees of freedom. #m_ncoeffs
            /// \f$=N_{\mathrm{eof}}=\sum_{e=1}^{{N_{\mathrm{el}}}}N^{e}_l\f$
            int m_ncoeffs;

Spencer Sherwin's avatar
Spencer Sherwin committed
978
979
980
            /** The total number of quadrature points. #m_npoints
             *\f$=Q_{\mathrm{tot}}=\sum_{e=1}^{{N_{\mathrm{el}}}}N^{e}_Q\f$
             **/
981
            int m_npoints;
982
            
Peter Vos's avatar
Peter Vos committed
983
            /**
984
             * \brief Concatenation of all local expansion coefficients.
Peter Vos's avatar
Peter Vos committed
985