IProductWRTDerivBase.cpp 69.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
///////////////////////////////////////////////////////////////////////////////
//
// File: IProductWRTDerivBase.cpp
//
// 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: IProductWRTDerivBase operator implementations
//
///////////////////////////////////////////////////////////////////////////////

#include <Collections/Operator.h>
#include <Collections/Collection.h>
#include <Collections/IProduct.h>

40 41
using namespace std;

42 43 44
namespace Nektar {
namespace Collections {

Chris Cantwell's avatar
Chris Cantwell committed
45 46 47 48 49 50 51 52 53 54 55
using LibUtilities::eSegment;
using LibUtilities::eQuadrilateral;
using LibUtilities::eTriangle;
using LibUtilities::eHexahedron;
using LibUtilities::eTetrahedron;
using LibUtilities::ePrism;
using LibUtilities::ePyramid;

/**
 * @brief Inner product WRT deriv base operator using standard matrix approach
 */
56
class IProductWRTDerivBase_StdMat : public Operator
57
{
Chris Cantwell's avatar
Chris Cantwell committed
58 59 60 61
    public:
        OPERATOR_CREATE(IProductWRTDerivBase_StdMat)

        virtual ~IProductWRTDerivBase_StdMat()
62 63 64
        {
        }

Chris Cantwell's avatar
Chris Cantwell committed
65 66 67 68 69 70
        virtual void operator()(
                const Array<OneD, const NekDouble> &entry0,
                      Array<OneD,       NekDouble> &entry1,
                      Array<OneD,       NekDouble> &entry2,
                      Array<OneD,       NekDouble> &entry3,
                      Array<OneD,       NekDouble> &wsp)
71
        {
Chris Cantwell's avatar
Chris Cantwell committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85
            int nPhys = m_stdExp->GetTotPoints();
            int ntot = m_numElmt*nPhys;
            int nmodes = m_stdExp->GetNcoeffs();
            Array<OneD, Array<OneD, const NekDouble> > in(3);
            Array<OneD, NekDouble> output;
            Array<OneD, Array<OneD, NekDouble> > tmp(3);

            in[0] = entry0; in[1] = entry1;
            in[2] = entry2;

            output = (m_coordim == 3)? entry3: (m_coordim == 2)?
                entry2: entry1;

            for(int i = 0; i < m_dim; ++i)
86
            {
Chris Cantwell's avatar
Chris Cantwell committed
87
                tmp[i] = wsp + i*ntot;
88 89
            }

Chris Cantwell's avatar
Chris Cantwell committed
90 91 92 93 94 95 96 97 98 99 100
            // calculate dx/dxi in[0] + dy/dxi in[1] + dz/dxi in[2]
            for(int i = 0; i < m_dim; ++i)
            {
                Vmath::Vmul (ntot,m_derivFac[i],1, in[0],1,
                             tmp[i],1);
                for(int j = 1; j < m_coordim; ++j)
                {
                    Vmath::Vvtvp (ntot,m_derivFac[i +j*m_dim],1,
                                  in[j],1, tmp[i], 1, tmp[i],1);
                }
            }
101

Chris Cantwell's avatar
Chris Cantwell committed
102
            // calculate Iproduct WRT Std Deriv
103

Chris Cantwell's avatar
Chris Cantwell committed
104 105 106 107 108 109 110
            // First component
            Vmath::Vmul(ntot,m_jac,1,tmp[0],1,tmp[0],1);
            Blas::Dgemm('N', 'N', m_iProdWRTStdDBase[0]->GetRows(),
                        m_numElmt,m_iProdWRTStdDBase[0]->GetColumns(),
                        1.0, m_iProdWRTStdDBase[0]->GetRawPtr(),
                        m_iProdWRTStdDBase[0]->GetRows(),
                        tmp[0].get(), nPhys, 0.0,
111
                        output.get(), nmodes);
Chris Cantwell's avatar
Chris Cantwell committed
112 113 114 115 116 117 118 119 120 121 122 123

            // Other components
            for(int i = 1; i < m_dim; ++i)
            {
                Vmath::Vmul(ntot,m_jac,1,tmp[i],1,tmp[i],1);
                Blas::Dgemm('N', 'N', m_iProdWRTStdDBase[i]->GetRows(),
                            m_numElmt,m_iProdWRTStdDBase[i]->GetColumns(),
                            1.0, m_iProdWRTStdDBase[i]->GetRawPtr(),
                            m_iProdWRTStdDBase[i]->GetRows(),
                            tmp[i].get(), nPhys, 1.0,
                            output.get(), nmodes);
            }
124
        }
Chris Cantwell's avatar
Chris Cantwell committed
125

126 127 128 129 130 131 132 133 134
        virtual void operator()(
                      int                           dir,
                const Array<OneD, const NekDouble> &input,
                      Array<OneD,       NekDouble> &output,
                      Array<OneD,       NekDouble> &wsp)
        {
            ASSERTL0(false, "Not valid for this operator.");
        }

Chris Cantwell's avatar
Chris Cantwell committed
135 136 137 138 139 140 141 142 143 144 145 146
    protected:
        Array<OneD, DNekMatSharedPtr>   m_iProdWRTStdDBase;
        Array<TwoD, const NekDouble>    m_derivFac;
        Array<OneD, const NekDouble>    m_jac;
        int                             m_dim;
        int                             m_coordim;

    private:
        IProductWRTDerivBase_StdMat(
                vector<StdRegions::StdExpansionSharedPtr> pCollExp,
                CoalescedGeomDataSharedPtr                pGeomData)
            : Operator(pCollExp, pGeomData)
147
        {
Chris Cantwell's avatar
Chris Cantwell committed
148 149
            LibUtilities::PointsKeyVector PtsKey = m_stdExp->GetPointsKeys();
            m_dim = PtsKey.size();
150
            m_coordim = pCollExp[0]->GetCoordim();
Chris Cantwell's avatar
Chris Cantwell committed
151 152 153 154 155 156 157

            int nqtot  = m_stdExp->GetTotPoints();
            int nmodes = m_stdExp->GetNcoeffs();

            // set up a IProductWRTDerivBase StdMat.
            m_iProdWRTStdDBase = Array<OneD, DNekMatSharedPtr>(m_dim);
            for(int i = 0; i < m_dim; ++i)
158
            {
Chris Cantwell's avatar
Chris Cantwell committed
159 160 161 162 163 164 165 166 167 168 169 170
                Array<OneD, NekDouble> tmp(nqtot),tmp1(nmodes);
                m_iProdWRTStdDBase[i] = MemoryManager<DNekMat>
                                            ::AllocateSharedPtr(nmodes,nqtot);
                for(int j = 0; j < nqtot; ++j)
                {
                    Vmath::Zero(nqtot,tmp,1);
                    tmp[j] = 1.0;
                    m_stdExp->IProductWRTDerivBase(i,tmp,tmp1);
                    Vmath::Vcopy(nmodes, &tmp1[0],1,
                                 &(m_iProdWRTStdDBase[i]->GetPtr())[0]
                                     + j*nmodes, 1);
                }
171
            }
Chris Cantwell's avatar
Chris Cantwell committed
172 173 174
            m_derivFac = pGeomData->GetDerivFactors(pCollExp);
            m_jac      = pGeomData->GetJac(pCollExp);
            m_wspSize = m_dim*nqtot*m_numElmt;
175 176 177
        }
};

Chris Cantwell's avatar
Chris Cantwell committed
178
/// Factory initialisation for the IProductWRTDerivBase_StdMat operators
179 180
OperatorKey IProductWRTDerivBase_StdMat::m_typeArr[] = {
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
181 182 183
        OperatorKey(eSegment,       eIProductWRTDerivBase, eStdMat, false),
        IProductWRTDerivBase_StdMat::create,
        "IProductWRTDerivBase_StdMat_Seg"),
184
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
185 186 187
        OperatorKey(eTriangle,      eIProductWRTDerivBase, eStdMat, false),
        IProductWRTDerivBase_StdMat::create,
        "IProductWRTDerivBase_StdMat_Tri"),
188
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
189 190 191
        OperatorKey(eTriangle,      eIProductWRTDerivBase, eStdMat, true),
        IProductWRTDerivBase_StdMat::create,
        "IProductWRTDerivBase_StdMat_NodalTri"),
192
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
193 194 195
        OperatorKey(eQuadrilateral, eIProductWRTDerivBase, eStdMat, false),
        IProductWRTDerivBase_StdMat::create,
        "IProductWRTDerivBase_StdMat_Quad"),
196
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
197 198 199
        OperatorKey(eTetrahedron,   eIProductWRTDerivBase, eStdMat, false),
        IProductWRTDerivBase_StdMat::create,
        "IProductWRTDerivBase_StdMat_Tet"),
200
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
201 202 203
        OperatorKey(eTetrahedron,   eIProductWRTDerivBase, eStdMat, true),
        IProductWRTDerivBase_StdMat::create,
        "IProductWRTDerivBase_StdMat_NodalTet"),
204
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
205 206 207
        OperatorKey(ePyramid,       eIProductWRTDerivBase, eStdMat, false),
        IProductWRTDerivBase_StdMat::create,
        "IProductWRTDerivBase_StdMat_Pyr"),
208
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
209 210 211
        OperatorKey(ePrism,         eIProductWRTDerivBase, eStdMat, false),
        IProductWRTDerivBase_StdMat::create,
        "IProductWRTDerivBase_StdMat_Prism"),
212
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
213 214 215
        OperatorKey(ePrism,         eIProductWRTDerivBase, eStdMat, true),
        IProductWRTDerivBase_StdMat::create,
        "IProductWRTDerivBase_StdMat_NodalPrism"),
216
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
217 218 219
        OperatorKey(eHexahedron,    eIProductWRTDerivBase, eStdMat, false),
        IProductWRTDerivBase_StdMat::create,
        "IProductWRTDerivBase_StdMat_Hex")
220 221
};

222

Chris Cantwell's avatar
Chris Cantwell committed
223 224 225
/**
 * @brief Inner product WRT deriv base operator using element-wise operation
 */
226
class IProductWRTDerivBase_IterPerExp : public Operator
227
{
Chris Cantwell's avatar
Chris Cantwell committed
228 229 230 231
    public:
        OPERATOR_CREATE(IProductWRTDerivBase_IterPerExp)

        virtual ~IProductWRTDerivBase_IterPerExp()
232 233 234
        {
        }

Chris Cantwell's avatar
Chris Cantwell committed
235 236 237 238 239 240
        virtual void operator()(
                const Array<OneD, const NekDouble> &entry0,
                      Array<OneD, NekDouble> &entry1,
                      Array<OneD, NekDouble> &entry2,
                      Array<OneD, NekDouble> &entry3,
                      Array<OneD, NekDouble> &wsp)
241
        {
Chris Cantwell's avatar
Chris Cantwell committed
242 243 244 245 246 247 248 249 250 251 252 253 254 255
            unsigned int nPhys  = m_stdExp->GetTotPoints();
            unsigned int ntot   = m_numElmt*nPhys;
            unsigned int nmodes = m_stdExp->GetNcoeffs();
            unsigned int nmax   = max(ntot,m_numElmt*nmodes);
            Array<OneD, Array<OneD, const NekDouble> > in(3);
            Array<OneD, NekDouble> output, tmp1;
            Array<OneD, Array<OneD, NekDouble> > tmp(3);

            in[0] = entry0; in[1] = entry1; in[2] = entry2;

            output = (m_coordim == 3)? entry3: (m_coordim == 2)?
                entry2: entry1;

            for(int i = 0; i < m_dim; ++i)
256
            {
Chris Cantwell's avatar
Chris Cantwell committed
257
                tmp[i] = wsp + i*nmax;
258 259
            }

Chris Cantwell's avatar
Chris Cantwell committed
260 261 262 263 264 265 266 267 268 269 270
            // calculate dx/dxi in[0] + dy/dxi in[2] + dz/dxi in[3]
            for(int i = 0; i < m_dim; ++i)
            {
                Vmath::Vmul (ntot,m_derivFac[i],1, in[0],1,
                             tmp[i],1);
                for(int j = 1; j < m_coordim; ++j)
                {
                    Vmath::Vvtvp (ntot,m_derivFac[i +j*m_dim],1,
                                  in[j],1, tmp[i], 1, tmp[i],1);
                }
            }
271

Chris Cantwell's avatar
Chris Cantwell committed
272 273 274
            // calculate Iproduct WRT Std Deriv
            // first component
            Vmath::Vmul(ntot,m_jac,1,tmp[0],1,tmp[0],1);
275 276
            for(int n = 0; n < m_numElmt; ++n)
            {
Chris Cantwell's avatar
Chris Cantwell committed
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
                m_stdExp->IProductWRTDerivBase(0,tmp[0]+n*nPhys,
                                               tmp1 = output + n*nmodes);
            }

            // other components
            for(int i = 1; i < m_dim; ++i)
            {
                // multiply by Jacobian
                Vmath::Vmul(ntot,m_jac,1,tmp[i],1,tmp[i],1);
                for(int n = 0; n < m_numElmt; ++n)
                {
                    m_stdExp->IProductWRTDerivBase(i,tmp[i]+n*nPhys,tmp[0]);
                    Vmath::Vadd(nmodes,tmp[0],1,output+n*nmodes,1,
                                tmp1 = output+n*nmodes,1);
                }
292 293
            }
        }
Chris Cantwell's avatar
Chris Cantwell committed
294

295 296 297 298 299 300 301 302 303
        virtual void operator()(
                      int                           dir,
                const Array<OneD, const NekDouble> &input,
                      Array<OneD,       NekDouble> &output,
                      Array<OneD,       NekDouble> &wsp)
        {
            ASSERTL0(false, "Not valid for this operator.");
        }

Chris Cantwell's avatar
Chris Cantwell committed
304 305 306 307 308 309 310 311 312 313 314 315 316 317
    protected:
        Array<TwoD, const NekDouble>    m_derivFac;
        Array<OneD, const NekDouble>    m_jac;
        int                             m_dim;
        int                             m_coordim;

    private:
        IProductWRTDerivBase_IterPerExp(
                vector<StdRegions::StdExpansionSharedPtr> pCollExp,
                CoalescedGeomDataSharedPtr                pGeomData)
            : Operator(pCollExp, pGeomData)
        {
            LibUtilities::PointsKeyVector PtsKey = m_stdExp->GetPointsKeys();
            m_dim      = PtsKey.size();
Douglas Serson's avatar
Douglas Serson committed
318
            m_coordim  = pCollExp[0]->GetCoordim();
Chris Cantwell's avatar
Chris Cantwell committed
319 320 321 322 323 324 325

            int nqtot  = m_stdExp->GetTotPoints();

            m_derivFac = pGeomData->GetDerivFactors(pCollExp);
            m_jac      = pGeomData->GetJac(pCollExp);
            m_wspSize  = m_dim*nqtot*m_numElmt;
        }
326
};
327

Chris Cantwell's avatar
Chris Cantwell committed
328
/// Factory initialisation for the IProductWRTDerivBase_IterPerExp operators
329 330
OperatorKey IProductWRTDerivBase_IterPerExp::m_typeArr[] = {
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
331 332 333
        OperatorKey(eSegment,       eIProductWRTDerivBase, eIterPerExp,false),
        IProductWRTDerivBase_IterPerExp::create,
        "IProductWRTDerivBase_IterPerExp_Seg"),
334
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
335 336 337
        OperatorKey(eTriangle,      eIProductWRTDerivBase, eIterPerExp,false),
        IProductWRTDerivBase_IterPerExp::create,
        "IProductWRTDerivBase_IterPerExp_Tri"),
338
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
339 340 341
        OperatorKey(eTriangle,      eIProductWRTDerivBase, eIterPerExp,true),
        IProductWRTDerivBase_IterPerExp::create,
        "IProductWRTDerivBase_IterPerExp_NodalTri"),
342
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
343 344 345
        OperatorKey(eQuadrilateral, eIProductWRTDerivBase, eIterPerExp,false),
        IProductWRTDerivBase_IterPerExp::create,
        "IProductWRTDerivBase_IterPerExp_Quad"),
346
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
347 348 349
        OperatorKey(eTetrahedron,   eIProductWRTDerivBase, eIterPerExp,false),
        IProductWRTDerivBase_IterPerExp::create,
        "IProductWRTDerivBase_IterPerExp_Tet"),
350
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
351 352 353
        OperatorKey(eTetrahedron,   eIProductWRTDerivBase, eIterPerExp,true),
        IProductWRTDerivBase_IterPerExp::create,
        "IProductWRTDerivBase_IterPerExp_NodalTet"),
354
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
355 356 357
        OperatorKey(ePyramid,       eIProductWRTDerivBase, eIterPerExp,false),
        IProductWRTDerivBase_IterPerExp::create,
        "IProductWRTDerivBase_IterPerExp_Pyr"),
358
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
359 360 361
        OperatorKey(ePrism,         eIProductWRTDerivBase, eIterPerExp,false),
        IProductWRTDerivBase_IterPerExp::create,
        "IProductWRTDerivBase_IterPerExp_Prism"),
362
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
363 364 365
        OperatorKey(ePrism,         eIProductWRTDerivBase, eIterPerExp,true),
        IProductWRTDerivBase_IterPerExp::create,
        "IProductWRTDerivBase_IterPerExp_NodalPrism"),
366
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
367 368 369
        OperatorKey(eHexahedron,    eIProductWRTDerivBase, eIterPerExp,false),
        IProductWRTDerivBase_IterPerExp::create,
        "IProductWRTDerivBase_IterPerExp_Hex")
370 371 372
};


Chris Cantwell's avatar
Chris Cantwell committed
373
/**
374 375
 * @brief Inner product WRT deriv base operator using LocalRegions
 * implementation.
Chris Cantwell's avatar
Chris Cantwell committed
376
 */
377 378
class IProductWRTDerivBase_NoCollection : public Operator
{
Chris Cantwell's avatar
Chris Cantwell committed
379 380 381 382
    public:
        OPERATOR_CREATE(IProductWRTDerivBase_NoCollection)

        virtual ~IProductWRTDerivBase_NoCollection()
383 384 385
        {
        }

Chris Cantwell's avatar
Chris Cantwell committed
386 387 388 389 390 391
        virtual void operator()(
                const Array<OneD, const NekDouble> &entry0,
                      Array<OneD, NekDouble> &entry1,
                      Array<OneD, NekDouble> &entry2,
                      Array<OneD, NekDouble> &entry3,
                      Array<OneD, NekDouble> &wsp)
392
        {
Chris Cantwell's avatar
Chris Cantwell committed
393 394 395 396 397 398 399 400 401 402 403
            unsigned int nmodes = m_expList[0]->GetNcoeffs();
            unsigned int nPhys  = m_expList[0]->GetTotPoints();
            Array<OneD, NekDouble> tmp(nmodes),tmp1;

            Array<OneD, Array<OneD, const NekDouble> > in(3);
            Array<OneD, NekDouble> output;
            in[0] = entry0; in[1] = entry1; in[2] = entry2;

            output = (m_coordim == 3)? entry3: (m_coordim == 2)?
                entry2: entry1;

404 405
            for(int n = 0; n < m_numElmt; ++n)
            {
Chris Cantwell's avatar
Chris Cantwell committed
406 407 408 409
                m_expList[n]->IProductWRTDerivBase(0,
                                                   in[0] + n * nPhys,
                                                   tmp1 = output + n * nmodes);
            }
410

Chris Cantwell's avatar
Chris Cantwell committed
411 412 413 414 415 416 417 418 419
            for(int i = 1; i < m_dim; ++i)
            {
                for(int n = 0; n < m_numElmt; ++n)
                {
                    m_expList[n]->IProductWRTDerivBase(i,in[i]+n*nPhys,tmp);

                    Vmath::Vadd(nmodes,tmp,1,output+n*nmodes,1,
                                tmp1 = output+n*nmodes,1);
                }
420 421
            }
        }
Chris Cantwell's avatar
Chris Cantwell committed
422

423 424 425 426 427 428 429 430 431
        virtual void operator()(
                      int                           dir,
                const Array<OneD, const NekDouble> &input,
                      Array<OneD,       NekDouble> &output,
                      Array<OneD,       NekDouble> &wsp)
        {
            ASSERTL0(false, "Not valid for this operator.");
        }

Chris Cantwell's avatar
Chris Cantwell committed
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
    protected:
        int                                         m_dim;
        int                                         m_coordim;
        vector<StdRegions::StdExpansionSharedPtr>   m_expList;

    private:
        IProductWRTDerivBase_NoCollection(
                vector<StdRegions::StdExpansionSharedPtr> pCollExp,
                CoalescedGeomDataSharedPtr                pGeomData)
            : Operator(pCollExp, pGeomData)
        {
            m_expList = pCollExp;
            m_dim     = pCollExp[0]->GetNumBases();
            m_coordim = pCollExp[0]->GetCoordim();
        }
447 448
};

Chris Cantwell's avatar
Chris Cantwell committed
449
/// Factory initialisation for the IProductWRTDerivBase_NoCollection operators
450 451
OperatorKey IProductWRTDerivBase_NoCollection::m_typeArr[] = {
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
452 453 454
        OperatorKey(eSegment,       eIProductWRTDerivBase, eNoCollection,false),
        IProductWRTDerivBase_NoCollection::create,
        "IProductWRTDerivBase_NoCollection_Seg"),
455
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
456 457 458
        OperatorKey(eTriangle,      eIProductWRTDerivBase, eNoCollection,false),
        IProductWRTDerivBase_NoCollection::create,
        "IProductWRTDerivBase_NoCollection_Tri"),
459
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
460 461 462
        OperatorKey(eTriangle,      eIProductWRTDerivBase, eNoCollection,true),
        IProductWRTDerivBase_NoCollection::create,
        "IProductWRTDerivBase_NoCollection_NodalTri"),
463
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
464 465 466
        OperatorKey(eQuadrilateral, eIProductWRTDerivBase, eNoCollection,false),
        IProductWRTDerivBase_NoCollection::create,
        "IProductWRTDerivBase_NoCollection_Quad"),
467
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
468 469 470
        OperatorKey(eTetrahedron,   eIProductWRTDerivBase, eNoCollection,false),
        IProductWRTDerivBase_NoCollection::create,
        "IProductWRTDerivBase_NoCollection_Tet"),
471
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
472 473 474
        OperatorKey(eTetrahedron,   eIProductWRTDerivBase, eNoCollection,true),
        IProductWRTDerivBase_NoCollection::create,
        "IProductWRTDerivBase_NoCollection_NodalTet"),
475
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
476 477 478
        OperatorKey(ePyramid,       eIProductWRTDerivBase, eNoCollection,false),
        IProductWRTDerivBase_NoCollection::create,
        "IProductWRTDerivBase_NoCollection_Pyr"),
479
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
480 481 482
        OperatorKey(ePrism,         eIProductWRTDerivBase, eNoCollection,false),
        IProductWRTDerivBase_NoCollection::create,
        "IProductWRTDerivBase_NoCollection_Prism"),
483
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
484 485 486
        OperatorKey(ePrism,         eIProductWRTDerivBase, eNoCollection,true),
        IProductWRTDerivBase_NoCollection::create,
        "IProductWRTDerivBase_NoCollection_NodalPrism"),
487
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
488 489 490
        OperatorKey(eHexahedron,    eIProductWRTDerivBase, eNoCollection,false),
        IProductWRTDerivBase_NoCollection::create,
        "IProductWRTDerivBase_NoCollection_Hex")
491 492 493
};


Chris Cantwell's avatar
Chris Cantwell committed
494
/**
495 496
 * @brief Inner product WRT deriv base operator using sum-factorisation
 * (Segment)
Chris Cantwell's avatar
Chris Cantwell committed
497
 */
498 499
class IProductWRTDerivBase_SumFac_Seg : public Operator
{
Chris Cantwell's avatar
Chris Cantwell committed
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
    public:
        OPERATOR_CREATE(IProductWRTDerivBase_SumFac_Seg)

        virtual ~IProductWRTDerivBase_SumFac_Seg()
        {
        }

        virtual void operator()(
                const Array<OneD, const NekDouble> &input,
                      Array<OneD,       NekDouble> &output,
                      Array<OneD,       NekDouble> &output1,
                      Array<OneD,       NekDouble> &output2,
                      Array<OneD,       NekDouble> &wsp)
        {

            Vmath::Vmul(m_numElmt*m_nquad0, m_jac, 1, input, 1, wsp, 1);
            Vmath::Vmul(m_numElmt*m_nquad0, &m_derivFac[0][0], 1,
                                            &wsp[0],           1,
                                            &wsp[0],           1);

            // out = B0*in;
            Blas::Dgemm('T', 'N', m_nmodes0, m_numElmt, m_nquad0,
                        1.0, m_derbase0.get(), m_nquad0,
                        &wsp[0], m_nquad0, 0.0,
                        &output[0], m_nmodes0);
        }

527 528 529 530 531 532 533 534 535
        virtual void operator()(
                      int                           dir,
                const Array<OneD, const NekDouble> &input,
                      Array<OneD,       NekDouble> &output,
                      Array<OneD,       NekDouble> &wsp)
        {
            ASSERTL0(false, "Not valid for this operator.");
        }

Chris Cantwell's avatar
Chris Cantwell committed
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
    protected:
        const int                       m_nquad0;
        const int                       m_nmodes0;
        Array<OneD, const NekDouble>    m_jac;
        Array<OneD, const NekDouble>    m_derbase0;
        Array<TwoD, const NekDouble>    m_derivFac;

    private:
        IProductWRTDerivBase_SumFac_Seg(
                vector<StdRegions::StdExpansionSharedPtr> pCollExp,
                CoalescedGeomDataSharedPtr                pGeomData)
            : Operator  (pCollExp, pGeomData),
              m_nquad0  (m_stdExp->GetNumPoints(0)),
              m_nmodes0 (m_stdExp->GetBasisNumModes(0)),
              m_derbase0(m_stdExp->GetBasis(0)->GetDbdata())
        {
            m_wspSize = m_numElmt*m_nquad0;
            m_derivFac = pGeomData->GetDerivFactors(pCollExp);
            m_jac = pGeomData->GetJacWithStdWeights(pCollExp);
        }
556 557
};

Chris Cantwell's avatar
Chris Cantwell committed
558
/// Factory initialisation for the IProductWRTDerivBase_SumFac_Seg operator
559
OperatorKey IProductWRTDerivBase_SumFac_Seg::m_type = GetOperatorFactory().
Chris Cantwell's avatar
Chris Cantwell committed
560 561 562 563
    RegisterCreatorFunction(
        OperatorKey(eSegment, eIProductWRTDerivBase, eSumFac, false),
        IProductWRTDerivBase_SumFac_Seg::create,
        "IProductWRTDerivBase_SumFac_Seg");
564 565


Chris Cantwell's avatar
Chris Cantwell committed
566 567 568
/**
 * @brief Inner product WRT deriv base operator using sum-factorisation (Quad)
 */
569 570
class IProductWRTDerivBase_SumFac_Quad : public Operator
{
Chris Cantwell's avatar
Chris Cantwell committed
571 572 573 574 575 576 577 578 579 580 581 582 583
    public:
        OPERATOR_CREATE(IProductWRTDerivBase_SumFac_Quad)

        virtual ~IProductWRTDerivBase_SumFac_Quad()
        {
        }

        virtual void operator()(
                const Array<OneD, const NekDouble> &entry0,
                      Array<OneD, NekDouble> &entry1,
                      Array<OneD, NekDouble> &entry2,
                      Array<OneD, NekDouble> &entry3,
                      Array<OneD, NekDouble> &wsp)
584
        {
Chris Cantwell's avatar
Chris Cantwell committed
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601
            unsigned int nPhys  = m_stdExp->GetTotPoints();
            unsigned int ntot   = m_numElmt*nPhys;
            unsigned int nmodes = m_stdExp->GetNcoeffs();
            unsigned int nmax   = max(ntot,m_numElmt*nmodes);
            Array<OneD, Array<OneD, const NekDouble> > in(3);
            Array<OneD, NekDouble> output, wsp1;
            Array<OneD, Array<OneD, NekDouble> > tmp(2);

            in[0] = entry0; in[1] = entry1; in[2] = entry2;

            output = (m_coordim == 2)? entry2: entry3;

            tmp[0] = wsp; tmp[1] = wsp + nmax;
            wsp1   = wsp + 2*nmax;

            // calculate dx/dxi in[0] + dy/dxi in[1]
            for(int i = 0; i < 2; ++i)
602
            {
Chris Cantwell's avatar
Chris Cantwell committed
603 604
                Vmath::Vmul (ntot,m_derivFac[i],1, in[0],1,
                             tmp[i],1);
Douglas Serson's avatar
Douglas Serson committed
605
                for(int j = 1; j < 2; ++j)
Chris Cantwell's avatar
Chris Cantwell committed
606 607 608 609
                {
                    Vmath::Vvtvp (ntot,m_derivFac[i +j*2],1,
                                  in[j],1, tmp[i], 1, tmp[i],1);
                }
610
            }
Chris Cantwell's avatar
Chris Cantwell committed
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626

            // Iproduct wrt derivative of base 0
            QuadIProduct(false, m_colldir1,m_numElmt,
                         m_nquad0,   m_nquad1,
                         m_nmodes0,  m_nmodes1,
                         m_derbase0, m_base1,
                         m_jac, tmp[0], output, wsp1);

            // Iproduct wrt derivative of base 1
            QuadIProduct(m_colldir0, false, m_numElmt,
                         m_nquad0,   m_nquad1,
                         m_nmodes0,  m_nmodes1,
                         m_base0, m_derbase1,
                         m_jac, tmp[1],  tmp[0], wsp1);

            Vmath::Vadd(m_numElmt*nmodes,tmp[0],1,output,1,output,1);
627 628
        }

629 630 631 632 633 634 635 636 637
        virtual void operator()(
                      int                           dir,
                const Array<OneD, const NekDouble> &input,
                      Array<OneD,       NekDouble> &output,
                      Array<OneD,       NekDouble> &wsp)
        {
            ASSERTL0(false, "Not valid for this operator.");
        }

Chris Cantwell's avatar
Chris Cantwell committed
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
    protected:
        const int                       m_nquad0;
        const int                       m_nquad1;
        const int                       m_nmodes0;
        const int                       m_nmodes1;
        const bool                      m_colldir0;
        const bool                      m_colldir1;
        int                             m_coordim;
        Array<TwoD, const NekDouble>    m_derivFac;
        Array<OneD, const NekDouble>    m_jac;
        Array<OneD, const NekDouble>    m_base0;
        Array<OneD, const NekDouble>    m_base1;
        Array<OneD, const NekDouble>    m_derbase0;
        Array<OneD, const NekDouble>    m_derbase1;

    private:
        IProductWRTDerivBase_SumFac_Quad(
                vector<StdRegions::StdExpansionSharedPtr> pCollExp,
                CoalescedGeomDataSharedPtr                pGeomData)
            : Operator(pCollExp, pGeomData),
              m_nquad0  (m_stdExp->GetNumPoints(0)),
              m_nquad1  (m_stdExp->GetNumPoints(1)),
              m_nmodes0 (m_stdExp->GetBasisNumModes(0)),
              m_nmodes1 (m_stdExp->GetBasisNumModes(1)),
              m_colldir0(m_stdExp->GetBasis(0)->Collocation()),
              m_colldir1(m_stdExp->GetBasis(1)->Collocation()),
              m_base0   (m_stdExp->GetBasis(0)->GetBdata()),
              m_base1   (m_stdExp->GetBasis(1)->GetBdata()),
              m_derbase0(m_stdExp->GetBasis(0)->GetDbdata()),
              m_derbase1(m_stdExp->GetBasis(1)->GetDbdata())
        {
            LibUtilities::PointsKeyVector PtsKey = m_stdExp->GetPointsKeys();
Douglas Serson's avatar
Douglas Serson committed
670
            m_coordim  = pCollExp[0]->GetCoordim();
Chris Cantwell's avatar
Chris Cantwell committed
671 672 673 674 675 676

            m_derivFac = pGeomData->GetDerivFactors(pCollExp);
            m_jac      = pGeomData->GetJacWithStdWeights(pCollExp);
            m_wspSize  = 4 * m_numElmt * (max(m_nquad0*m_nquad1,
                                              m_nmodes0*m_nmodes1));
        }
677
};
678

Chris Cantwell's avatar
Chris Cantwell committed
679
/// Factory initialisation for the IProductWRTDerivBase_SumFac_Quad operator
680 681
OperatorKey IProductWRTDerivBase_SumFac_Quad::m_type =
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
682
        OperatorKey(eQuadrilateral, eIProductWRTDerivBase, eSumFac, false),
683 684 685 686
        IProductWRTDerivBase_SumFac_Quad::create,
        "IProductWRTDerivBase_IterPerExp_Quad");


Chris Cantwell's avatar
Chris Cantwell committed
687 688 689
/**
 * @brief Inner product WRT deriv base operator using sum-factorisation (Tri)
 */
690 691
class IProductWRTDerivBase_SumFac_Tri : public Operator
{
Chris Cantwell's avatar
Chris Cantwell committed
692 693 694 695
    public:
        OPERATOR_CREATE(IProductWRTDerivBase_SumFac_Tri)

        virtual ~IProductWRTDerivBase_SumFac_Tri()
696
        {
Chris Cantwell's avatar
Chris Cantwell committed
697
        }
698

Spencer Sherwin's avatar
Spencer Sherwin committed
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
    /** 
     * This method calculates:
     *
     * \f[ (d\phi/dx,in[0]) + (d\phi/dy,in[1])  \f]
     *
     * which can be represented in terms of local cartesian
     * derivaties as:
     * 
     * \f[ ((d\phi/d\xi_0\, d\xi_0/dx +
     *       d\phi/d\xi_1\, d\xi_1/dx),in[0]) + \f]
     * 
     * \f[ ((d\phi/d\xi_0\, d\xi_0/dy +
     *       d\phi/d\xi_1\, d\xi_1/dy),in[1]) + \f]
     *  
     * where we note that
     *
     * \f[ d\phi/d\xi_0 =  d\phi/d\eta_0\, d\eta_0/d\xi_0 = 
     *        d\phi/d\eta_0 2/(1-\eta_1) \f]
     *
     * \f[ d\phi/d\xi_1  = d\phi/d\eta_1\, d\eta_1/d\xi_1 + 
     *   d\phi/d\eta_1\, d\eta_1/d\xi_1 = d\phi/d\eta_0 (1+\eta_0)/(1-\eta_1)
     *   + d\phi/d\eta_1 \f]
     *
     *  and so the full inner products are
     *     
     * \f[ (d\phi/dx,in[0]) + (dphi/dy,in[1]) = 
     *   (d\phi/d\eta_0, ((2/(1-\eta_1) (d\xi_0/dx in[0] + d\xi_0/dy in[1])
     *    + (1-\eta_0)/(1-\eta_1) (d\xi_1/dx in[0]+d\xi_1/dy in[1]))
     *    + (d\phi/d\eta_1, (d\xi_1/dx in[0] + d\xi_1/dy in[1])) \f]
     *
     */
    virtual void operator()(
Chris Cantwell's avatar
Chris Cantwell committed
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752
                const Array<OneD, const NekDouble> &entry0,
                      Array<OneD, NekDouble>       &entry1,
                      Array<OneD, NekDouble>       &entry2,
                      Array<OneD, NekDouble>       &entry3,
                      Array<OneD, NekDouble>       &wsp)
        {
            unsigned int nPhys  = m_stdExp->GetTotPoints();
            unsigned int ntot   = m_numElmt*nPhys;
            unsigned int nmodes = m_stdExp->GetNcoeffs();
            unsigned int nmax   = max(ntot,m_numElmt*nmodes);
            Array<OneD, Array<OneD, const NekDouble> > in(3);
            Array<OneD, NekDouble> output, wsp1;
            Array<OneD, Array<OneD, NekDouble> > tmp(2);

            in[0] = entry0; in[1] = entry1; in[2] = entry2;

            output = (m_coordim == 2)? entry2: entry3;

            tmp[0] = wsp; tmp[1] = wsp + nmax;
            wsp1   = wsp + 2*nmax;

            for(int i = 0; i < 2; ++i)
753
            {
Chris Cantwell's avatar
Chris Cantwell committed
754 755
                Vmath::Vmul (ntot,m_derivFac[i],1, in[0],1, tmp[i],1);

Douglas Serson's avatar
Douglas Serson committed
756
                for(int j = 1; j < 2; ++j)
Chris Cantwell's avatar
Chris Cantwell committed
757 758 759 760
                {
                    Vmath::Vvtvp (ntot,m_derivFac[i +j*2],1,
                                  in[j],1, tmp[i], 1, tmp[i],1);
                }
761 762
            }

Chris Cantwell's avatar
Chris Cantwell committed
763 764 765 766 767 768
            // Multiply by factor: 2/(1-z1)
            for (int i = 0; i < m_numElmt; ++i)
            {
                // scale tmp[0] by geometric factor: 2/(1-z1)
                Vmath::Vmul(nPhys,&m_fac0[0],1,tmp[0].get()+i*nPhys,1,
                            tmp[0].get()+i*nPhys,1);
769

Chris Cantwell's avatar
Chris Cantwell committed
770 771 772 773
                // scale tmp[1] by geometric factor (1+z0)/(1-z1)
                Vmath::Vvtvp(nPhys,&m_fac1[0],1,tmp[1].get()+i*nPhys,1,
                             tmp[0].get()+i*nPhys,1,tmp[0].get()+i*nPhys,1);
            }
774

Chris Cantwell's avatar
Chris Cantwell committed
775 776 777 778 779 780 781 782 783 784 785
            // Iproduct wrt derivative of base 0
            TriIProduct(m_sortTopVertex, m_numElmt, m_nquad0, m_nquad1,
                        m_nmodes0,  m_nmodes1, m_derbase0, m_base1,
                        m_jac, tmp[0], output, wsp1);

            // Iproduct wrt derivative of base 1
            TriIProduct(m_sortTopVertex, m_numElmt, m_nquad0, m_nquad1,
                        m_nmodes0,  m_nmodes1, m_base0, m_derbase1,
                        m_jac, tmp[1], tmp[0], wsp1);

            Vmath::Vadd(m_numElmt*nmodes,tmp[0],1,output,1,output,1);
786
        }
Chris Cantwell's avatar
Chris Cantwell committed
787

788 789 790 791 792 793 794 795 796
        virtual void operator()(
                      int                           dir,
                const Array<OneD, const NekDouble> &input,
                      Array<OneD,       NekDouble> &output,
                      Array<OneD,       NekDouble> &wsp)
        {
            ASSERTL0(false, "Not valid for this operator.");
        }

Chris Cantwell's avatar
Chris Cantwell committed
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829
    protected:
        const int                       m_nquad0;
        const int                       m_nquad1;
        const int                       m_nmodes0;
        const int                       m_nmodes1;
        const bool                      m_colldir0;
        const bool                      m_colldir1;
        int                             m_coordim;
        Array<TwoD, const NekDouble>    m_derivFac;
        Array<OneD, const NekDouble>    m_jac;
        Array<OneD, const NekDouble>    m_base0;
        Array<OneD, const NekDouble>    m_base1;
        Array<OneD, const NekDouble>    m_derbase0;
        Array<OneD, const NekDouble>    m_derbase1;
        Array<OneD, NekDouble>          m_fac0;
        Array<OneD, NekDouble>          m_fac1;
        bool                            m_sortTopVertex;

    private:
        IProductWRTDerivBase_SumFac_Tri(
                vector<StdRegions::StdExpansionSharedPtr> pCollExp,
                CoalescedGeomDataSharedPtr                pGeomData)
            : Operator(pCollExp, pGeomData),
              m_nquad0  (m_stdExp->GetNumPoints(0)),
              m_nquad1  (m_stdExp->GetNumPoints(1)),
              m_nmodes0 (m_stdExp->GetBasisNumModes(0)),
              m_nmodes1 (m_stdExp->GetBasisNumModes(1)),
              m_colldir0(m_stdExp->GetBasis(0)->Collocation()),
              m_colldir1(m_stdExp->GetBasis(1)->Collocation()),
              m_base0   (m_stdExp->GetBasis(0)->GetBdata()),
              m_base1   (m_stdExp->GetBasis(1)->GetBdata()),
              m_derbase0(m_stdExp->GetBasis(0)->GetDbdata()),
              m_derbase1(m_stdExp->GetBasis(1)->GetDbdata())
830
        {
Chris Cantwell's avatar
Chris Cantwell committed
831
            LibUtilities::PointsKeyVector PtsKey = m_stdExp->GetPointsKeys();
Douglas Serson's avatar
Douglas Serson committed
832
            m_coordim  = pCollExp[0]->GetCoordim();
833

Chris Cantwell's avatar
Chris Cantwell committed
834 835 836 837
            m_derivFac = pGeomData->GetDerivFactors(pCollExp);
            m_jac      = pGeomData->GetJacWithStdWeights(pCollExp);
            m_wspSize  = 4 * m_numElmt * (max(m_nquad0*m_nquad1,
                                              m_nmodes0*m_nmodes1));
838

Chris Cantwell's avatar
Chris Cantwell committed
839 840
            if(m_stdExp->GetBasis(0)->GetBasisType()
                    == LibUtilities::eModified_A)
841
            {
Chris Cantwell's avatar
Chris Cantwell committed
842 843 844 845 846
                m_sortTopVertex = true;
            }
            else
            {
                m_sortTopVertex = false;
847
            }
848

Chris Cantwell's avatar
Chris Cantwell committed
849 850 851 852 853 854 855 856
            const Array<OneD, const NekDouble>& z0
                                            = m_stdExp->GetBasis(0)->GetZ();
            const Array<OneD, const NekDouble>& z1
                                            = m_stdExp->GetBasis(1)->GetZ();

            m_fac0 = Array<OneD, NekDouble>(m_nquad0*m_nquad1);
            // set up geometric factor: 2/(1-z1)
            for (int i = 0; i < m_nquad0; ++i)
857
            {
Chris Cantwell's avatar
Chris Cantwell committed
858 859 860 861 862 863 864 865 866 867 868 869 870 871
                for(int j = 0; j < m_nquad1; ++j)
                {
                    m_fac0[i+j*m_nquad0] = 2.0/(1-z1[j]);
                }
            }

            m_fac1 = Array<OneD, NekDouble>(m_nquad0*m_nquad1);
            // set up geometric factor: (1+z0)/(1-z1)
            for (int i = 0; i < m_nquad0; ++i)
            {
                for(int j = 0; j < m_nquad1; ++j)
                {
                    m_fac1[i+j*m_nquad0] = (1+z0[i])/(1-z1[j]);
                }
872 873
            }
        }
874 875
};

Chris Cantwell's avatar
Chris Cantwell committed
876
/// Factory initialisation for the IProductWRTDerivBase_SumFac_Tri operator
877 878
OperatorKey IProductWRTDerivBase_SumFac_Tri::m_type =
    GetOperatorFactory().RegisterCreatorFunction(
Chris Cantwell's avatar
Chris Cantwell committed
879
        OperatorKey(eTriangle, eIProductWRTDerivBase, eSumFac,false),
880 881 882
        IProductWRTDerivBase_SumFac_Tri::create,
        "IProductWRTDerivBase_IterPerExp_Tri");

Chris Cantwell's avatar
Chris Cantwell committed
883 884 885 886

/**
 * @brief Inner product WRT deriv base operator using sum-factorisation (Hex)
 */
887 888
class IProductWRTDerivBase_SumFac_Hex : public Operator
{
Chris Cantwell's avatar
Chris Cantwell committed
889 890 891 892
    public:
        OPERATOR_CREATE(IProductWRTDerivBase_SumFac_Hex)

        virtual ~IProductWRTDerivBase_SumFac_Hex()
893 894 895
        {
        }

Chris Cantwell's avatar
Chris Cantwell committed
896 897 898 899 900 901
        virtual void operator()(
                const Array<OneD, const NekDouble> &entry0,
                      Array<OneD, NekDouble>       &entry1,
                      Array<OneD, NekDouble>       &entry2,
                      Array<OneD, NekDouble>       &entry3,
                      Array<OneD, NekDouble>       &wsp)
902
        {
Chris Cantwell's avatar
Chris Cantwell committed
903 904 905 906 907 908 909 910 911 912 913 914 915 916
            unsigned int nPhys  = m_stdExp->GetTotPoints();
            unsigned int ntot   = m_numElmt*nPhys;
            unsigned int nmodes = m_stdExp->GetNcoeffs();
            unsigned int nmax  = max(ntot,m_numElmt*nmodes);
            Array<OneD, Array<OneD, const NekDouble> > in(3);
            Array<OneD, NekDouble> output, wsp1;
            Array<OneD, Array<OneD, NekDouble> > tmp(3);

            in[0] = entry0; in[1] = entry1;
            in[2] = entry2;

            output =  entry3;

            for(int i = 0; i < 3; ++i)
917
            {
Chris Cantwell's avatar
Chris Cantwell committed
918
                tmp[i] = wsp + i*nmax;
919
            }
Chris Cantwell's avatar
Chris Cantwell committed
920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954

            // calculate dx/dxi in[0] + dy/dxi in[1] + dz/dxi in[2]
            for(int i = 0; i < 3; ++i)
            {
                Vmath::Vmul (ntot,m_derivFac[i],1, in[0],1,
                             tmp[i],1);
                for(int j = 1; j < 3; ++j)
                {
                    Vmath::Vvtvp (ntot,m_derivFac[i+3*j],1,
                                  in[j],1, tmp[i], 1, tmp[i],1);
                }
            }

            wsp1   = wsp + 3*nmax;

            // calculate Iproduct WRT Std Deriv
            HexIProduct(false,m_colldir1,m_colldir2, m_numElmt,
                        m_nquad0,   m_nquad1,  m_nquad2,
                        m_nmodes0,  m_nmodes1, m_nmodes2,
                        m_derbase0, m_base1,   m_base2,
                        m_jac,tmp[0],output,wsp1);

            HexIProduct(m_colldir0,false,m_colldir2, m_numElmt,
                        m_nquad0,  m_nquad1,   m_nquad2,
                        m_nmodes0, m_nmodes1,  m_nmodes2,
                        m_base0,   m_derbase1, m_base2,
                        m_jac,tmp[1],tmp[0],wsp1);
            Vmath::Vadd(m_numElmt*nmodes,tmp[0],1,output,1,output,1);

            HexIProduct(m_colldir0,m_colldir1,false, m_numElmt,
                        m_nquad0,  m_nquad1,  m_nquad2,
                        m_nmodes0, m_nmodes1, m_nmodes2,
                        m_base0,   m_base1,   m_derbase2,
                        m_jac,tmp[2],tmp[0],wsp1);
            Vmath::Vadd(m_numElmt*nmodes,tmp[0],1,output,1,output,1);
955 956
        }

957 958 959 960 961 962 963 964 965
        virtual void operator()(
                      int                           dir,
                const Array<OneD, const NekDouble> &input,
                      Array<OneD,       NekDouble> &output,
                      Array<OneD,       NekDouble> &wsp)
        {
            ASSERTL0(false, "Not valid for this operator.");
        }

Chris Cantwell's avatar
Chris Cantwell committed
966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011
    protected:
        const int                       m_nquad0;
        const int                       m_nquad1;
        const int                       m_nquad2;
        const int                       m_nmodes0;
        const int                       m_nmodes1;
        const int                       m_nmodes2;
        const bool                      m_colldir0;
        const bool                      m_colldir1;
        const bool                      m_colldir2;
        Array<OneD, const NekDouble>    m_jac;
        Array<OneD, const NekDouble>    m_base0;
        Array<OneD, const NekDouble>    m_base1;
        Array<OneD, const NekDouble>    m_base2;
        Array<OneD, const NekDouble>    m_derbase0;
        Array<OneD, const NekDouble>    m_derbase1;
        Array<OneD, const NekDouble>    m_derbase2;
        Array<TwoD, const NekDouble>    m_derivFac;

    private:
        IProductWRTDerivBase_SumFac_Hex(
                vector<StdRegions::StdExpansionSharedPtr> pCollExp,
                CoalescedGeomDataSharedPtr                pGeomData)
            : Operator  (pCollExp, pGeomData),
              m_nquad0  (m_stdExp->GetNumPoints(0)),
              m_nquad1  (m_stdExp->GetNumPoints(1)),
              m_nquad2  (m_stdExp->GetNumPoints(2)),
              m_nmodes0 (m_stdExp->GetBasisNumModes(0)),
              m_nmodes1 (m_stdExp->GetBasisNumModes(1)),
              m_nmodes2 (m_stdExp->GetBasisNumModes(2)),
              m_colldir0(m_stdExp->GetBasis(0)->Collocation()),
              m_colldir1(m_stdExp->GetBasis(1)->Collocation()),
              m_colldir2(m_stdExp->GetBasis(2)->Collocation()),
              m_base0   (m_stdExp->GetBasis(0)->GetBdata()),
              m_base1   (m_stdExp->GetBasis(1)->GetBdata()),
              m_base2   (m_stdExp->GetBasis(2)->GetBdata()),
              m_derbase0(m_stdExp->GetBasis(0)->GetDbdata()),
              m_derbase1(m_stdExp->GetBasis(1)->GetDbdata()),
              m_derbase2(m_stdExp->GetBasis(2)->GetDbdata())

        {
            m_jac      = pGeomData->GetJacWithStdWeights(pCollExp);
            m_wspSize  = 6 * m_numElmt * (max(m_nquad0*m_nquad1*m_nquad2,
                                              m_nmodes0*m_nmodes1*m_nmodes2));
            m_derivFac = pGeomData->GetDerivFactors(pCollExp);
        }
1012
};
1013

Chris Cantwell's avatar
Chris Cantwell committed
1014
/// Factory initialisation for the IProductWRTDerivBase_SumFac_Hex operator
1015
OperatorKey IProductWRTDerivBase_SumFac_Hex::m_type = GetOperatorFactory().
Chris Cantwell's avatar
Chris Cantwell committed
1016 1017 1018 1019
    RegisterCreatorFunction(
        OperatorKey(eHexahedron, eIProductWRTDerivBase, eSumFac, false),
        IProductWRTDerivBase_SumFac_Hex::create,
        "IProductWRTDerivBase_SumFac_Hex");
1020 1021


Chris Cantwell's avatar
Chris Cantwell committed
1022 1023 1024
/**
 * @brief Inner product WRT deriv base operator using sum-factorisation (Tet)
 */
1025 1026
class IProductWRTDerivBase_SumFac_Tet : public Operator
{
Chris Cantwell's avatar
Chris Cantwell committed
1027 1028 1029
    public:
        OPERATOR_CREATE(IProductWRTDerivBase_SumFac_Tet)

Spencer Sherwin's avatar
Spencer Sherwin committed
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083

        /**
         * This method calculates:
         *
         * \f[ (d\phi/dx,in[0]) + (d\phi/dy,in[1]) + (d\phi/dz,in[2]) \f]
         *
         * which can be represented in terms of local cartesian
         * derivaties as:
         * 
         * \f[ ((d\phi/d\xi_0\, d\xi_0/dx +
         *       d\phi/d\xi_1\, d\xi_1/dx + 
         *       d\phi/d\xi_2\, d\xi_2/dx),in[0]) + \f]
         * 
         * \f[ ((d\phi/d\xi_0\, d\xi_0/dy +
         *       d\phi/d\xi_1\, d\xi_1/dy + 
         *       d\phi/d\xi_2\, d\xi_2/dy),in[1]) + \f]
         *  
         * \f[ ((d\phi/d\xi_0\, d\xi_0/dz +
         *       d\phi/d\xi_1\, d\xi_1/dz + 
         *       d\phi/d\xi_2\, d\xi_2/dz),in[2]) \, \f]
         *
         * where we note that
         *
         * \f[ d\phi/d\xi_0 = d\phi/d\eta_0 4/((1-\eta_1)(1-\eta_2)) /f]
         * 
         * \f[ d\phi/d\xi_1 =  d\phi/d\eta_0 2(1+\eta_0)/((1-\eta_1)(1-\eta_2))
         *       +  d\phi/d\eta_1 2/(1-\eta_2) \f]
         *
         * \f[ d\phi/d\xi_2  = d\phi/d\eta_0 2(1+\eta_0)/((1-\eta_1)(1-\eta_2))
         *      +   d\phi/d\eta_1 (1+\eta_1)/(1-\eta_2)  + d\phi/d\eta_2 \f]
         *
         *  and so the full inner products are
         * 
         * \f[ (d\phi/dx,in[0]) + (d\phi/dy,in[1]) + (d\phi/dz,in[2]) = \f]
         * 
         * \f[ (d\phi/d\eta_0, fac0 (tmp0 + fac1(tmp1 + tmp2)))
         *      + (d\phi/d\eta_1, fac2 (tmp1 + fac3 tmp2))
         *      + (d\phi/d\eta_2, tmp2) \f]
         *
         *  where 
         * 
         * \f[ \begin{array}{lcl} 
         *    tmp0 &=& (d\xi_0/dx in[0] + d\xi_0/dy in[1] + d\xi_0/dz in[2]) \\
         *    tmp1 &=& (d\xi_1/dx in[0] + d\xi_1/dy in[1] + d\xi_1/dz in[2]) \\
         *    tmp2 &=& (d\xi_2/dx in[0] + d\xi_2/dy in[1] + d\xi_2/dz in[2])
         *   \end{array} \f]
         * 
         * \f[  \begin{array}{lcl}
         *    fac0 &= & 4/((1-\eta_1)(1-\eta_2)) \\
         *    fac1 &= & (1+\eta_0)/2 \\
         *    fac2 &= & 2/(1-\eta_2) \\
         *    fac3 &= & (1+\eta_1)/2  \end{array} \f]
         *
         */
Chris Cantwell's avatar
Chris Cantwell committed
1084 1085 1086 1087 1088 1089
        virtual void operator()(
                const Array<OneD, const NekDouble> &entry0,
                      Array<OneD, NekDouble>       &entry1,
                      Array<OneD, NekDouble>       &entry2,
                      Array<OneD, NekDouble>       &entry3,
                      Array<OneD, NekDouble>       &wsp)
1090
        {
Chris Cantwell's avatar
Chris Cantwell committed
1091 1092 1093 1094 1095 1096 1097
            unsigned int nPhys  = m_stdExp->GetTotPoints();
            unsigned int ntot   = m_numElmt*nPhys;
            unsigned int nmodes = m_stdExp->GetNcoeffs();
            unsigned int nmax  = max(ntot,m_numElmt*nmodes);
            Array<OneD, Array<OneD, const NekDouble> > in(3);
            Array<OneD, NekDouble> output, wsp1;
            Array<OneD, Array<OneD, NekDouble> > tmp(3);
1098

Chris Cantwell's avatar
Chris Cantwell committed
1099 1100
            in[0] = entry0; in[1] = entry1;
            in[2] = entry2;
1101

Chris Cantwell's avatar
Chris Cantwell committed
1102 1103 1104
            output =  entry3;

            for(int i = 0; i < 3; ++i)
1105
            {
Chris Cantwell's avatar
Chris Cantwell committed
1106
                tmp[i] = wsp + i*nmax;
1107 1108
            }

Chris Cantwell's avatar
Chris Cantwell committed
1109 1110 1111 1112 1113 1114 1115 1116 1117
            for(int i = 0; i < 3; ++i)
            {
                Vmath::Vmul (ntot,m_derivFac[i],1, in[0],1,tmp[i],1);
                for(int j = 1; j < 3; ++j)
                {
                    Vmath::Vvtvp (ntot,m_derivFac[i+3*j],1,
                                  in[j],1, tmp[i], 1, tmp[i],1);
                }
            }
1118

Chris Cantwell's avatar
Chris Cantwell committed
1119
            wsp1   = wsp + 3*nmax;
1120

Chris Cantwell's avatar
Chris Cantwell committed
1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144
            // Sort into eta factors
            for (int i = 0; i < m_numElmt; ++i)
            {
                // add tmp[1] + tmp[2]
                Vmath::Vadd(nPhys, tmp[1].get() + i*nPhys, 1,
                                   tmp[2].get() + i*nPhys, 1,
                                   wsp1.get(),             1);

                // scale wsp1 by fac1 and add to tmp0
                Vmath::Vvtvp(nPhys,&m_fac1[0],1,wsp1.get(),1,
                             tmp[0].get()+i*nPhys,1,tmp[0].get()+i*nPhys,1);

                // scale tmp[0] by fac0
                Vmath::Vmul(nPhys,&m_fac0[0],1,tmp[0].get()+i*nPhys,1,
                            tmp[0].get()+i*nPhys,1);

                // scale tmp[2] by fac3 and add to tmp1
                Vmath::Vvtvp(nPhys,&m_fac3[0],1,tmp[2].get()+i*nPhys,1,
                             tmp[1].get()+i*nPhys,1,tmp[1].get()+i*nPhys,1);

                // scale tmp[1] by fac2
                Vmath::Vmul(nPhys,&m_fac2[0],1,tmp[1].get()+i*nPhys,1,
                            tmp[1].get()+i*nPhys,1);
            }
1145 1146


Chris Cantwell's avatar
Chris Cantwell committed
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
            // calculate Iproduct WRT Std Deriv
            TetIProduct(m_sortTopEdge, m_numElmt,
                        m_nquad0,   m_nquad1,  m_nquad2,
                        m_nmodes0,  m_nmodes1, m_nmodes2,
                        m_derbase0, m_base1,   m_base2,
                        m_jac,tmp[0],output,wsp1);

            TetIProduct(m_sortTopEdge, m_numElmt,
                        m_nquad0,  m_nquad1,   m_nquad2,
                        m_nmodes0, m_nmodes1,  m_nmodes2,
                        m_base0,   m_derbase1, m_base2,
                        m_jac,tmp[1],tmp[0],wsp1);
            Vmath::Vadd(m_numElmt*nmodes,tmp[0],1,output,1,output,1);

            TetIProduct(m_sortTopEdge, m_numElmt,
                        m_nquad0,  m_nquad1,  m_nquad2,
                        m_nmodes0, m_nmodes1, m_nmodes2,
                        m_base0,   m_base1,   m_derbase2,
                        m_jac,tmp[2],tmp[0],wsp1);
            Vmath::Vadd(m_numElmt*nmodes,tmp[0],1,output,1,output,1);
1167 1168
        }

1169 1170 1171 1172 1173 1174 1175 1176 1177
        virtual void operator()(
                      int                           dir,
                const Array<OneD, const NekDouble> &input,
                      Array<OneD,       NekDouble> &output,
                      Array<OneD,       NekDouble> &wsp)
        {
            ASSERTL0(false, "Not valid for this operator.");
        }

Chris Cantwell's avatar
Chris Cantwell committed
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
    protected:
        const int                       m_nquad0;
        const int                       m_nquad1;
        const int                       m_nquad2;
        const int                       m_nmodes0;
        const int                       m_nmodes1;
        const int                       m_nmodes2;
        Array<OneD, const NekDouble>    m_jac;
        Array<OneD, const NekDouble>    m_base0;
        Array<OneD, const NekDouble>    m_base1;
        Array<OneD, const NekDouble>    m_base2;
        Array<OneD, const NekDouble>    m_derbase0;
        Array<OneD, const NekDouble>    m_derbase1;
        Array<OneD, const NekDouble>    m_derbase2;
        Array<TwoD, const NekDouble>    m_derivFac;
        Array<OneD, NekDouble>          m_fac0;
        Array<OneD, NekDouble>          m_fac1;
        Array<OneD, NekDouble>          m_fac2;
        Array<OneD, NekDouble>          m_fac3;
        bool                            m_sortTopEdge;

    private:
        IProductWRTDerivBase_SumFac_Tet(
                vector<StdRegions::StdExpansionSharedPtr> pCollExp,
                CoalescedGeomDataSharedPtr                pGeomData)
            : Operator  (pCollExp, pGeomData),
              m_nquad0  (m_stdExp->GetNumPoints(0)),
              m_nquad1  (m_stdExp->GetNumPoints(1)),
              m_nquad2  (m_stdExp->GetNumPoints(2)),
              m_nmodes0 (m_stdExp->GetBasisNumModes(0)),
              m_nmodes1 (m_stdExp->GetBasisNumModes(1)),
              m_nmodes2 (m_stdExp->GetBasisNumModes(2)),
              m_base0   (m_stdExp->GetBasis(0)->GetBdata()),
              m_base1   (m_stdExp->GetBasis(1)->GetBdata()),
              m_base2   (m_stdExp->GetBasis(2)->GetBdata()),
              m_derbase0(m_stdExp->GetBasis(0)->GetDbdata()),
              m_derbase1(m_stdExp->GetBasis(1)->GetDbdata()),
              m_derbase2(m_stdExp->GetBasis(2)->GetDbdata())
1216 1217

        {
Chris Cantwell's avatar
Chris Cantwell committed
1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236
            m_jac      = pGeomData->GetJacWithStdWeights(pCollExp);
            m_wspSize  = 6 * m_numElmt * (max(m_nquad0*m_nquad1*m_nquad2,
                                              m_nmodes0*m_nmodes1*m_nmodes2));
            m_derivFac = pGeomData->GetDerivFactors(pCollExp);


            const Array<OneD, const NekDouble>& z0
                                            = m_stdExp->GetBasis(0)->GetZ();
            const Array<OneD, const NekDouble>& z1
                                            = m_stdExp->GetBasis(1)->GetZ();
            const Array<OneD, const NekDouble>& z2
                                            = m_stdExp->GetBasis(2)->GetZ();

            m_fac0 = Array<OneD, NekDouble>(m_nquad0*m_nquad1*m_nquad2);
            m_fac1 = Array<OneD, NekDouble>(m_nquad0*m_nquad1*m_nquad2);
            m_fac2 = Array<OneD, NekDouble>(m_nquad0*m_nquad1*m_nquad2);
            m_fac3 = Array<OneD, NekDouble>(m_nquad0*m_nquad1*m_nquad2);
            // calculate 2.0/((1-eta_1)(1-eta_2))
            for (int i = 0; i < m_nquad0; ++i)
1237
            {
Chris Cantwell's avatar
Chris Cantwell committed
1238
                for(int j = 0; j < m_nquad1; ++j)
1239
                {
Chris Cantwell's avatar
Chris Cantwell committed
1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251
                    for(int k = 0; k < m_nquad2; ++k)
                    {

                        m_fac0[i + j*m_nquad0 + k*m_nquad0*m_nquad1]
                               = 4.0/((1-z1[j])*(1-z2[k]));
                        m_fac1[i + j*m_nquad0 + k*m_nquad0*m_nquad1]
                               = (1+z0[i])*0.5;
                        m_fac2[i + j*m_nquad0 + k*m_nquad0*m_nquad1]
                               = 2.0/(1-z2[k]);
                        m_fac3[i + j*m_nquad0 + k*m_nquad0*m_nquad1]
                               = (1+z1[j])*0.5;
                    }
1252 1253
                }
            }
1254

Chris Cantwell's avatar
Chris Cantwell committed
1255 1256 1257 1258 1259 1260 1261 1262 1263
            if(m_stdExp->GetBasis(0)->GetBasisType()
                    == LibUtilities::eModified_A)
            {
                m_sortTopEdge = true;
            }
            else
            {
                m_sortTopEdge = false;
            }
1264

Chris Cantwell's avatar
Chris Cantwell committed
1265
        }
1266 1267
};

Chris Cantwell's avatar
Chris Cantwell committed
1268
/// Factory initialisation for the IProductWRTDerivBase_SumFac_Tet operator
1269
OperatorKey IProductWRTDerivBase_SumFac_Tet::m_type = GetOperatorFactory().
Chris Cantwell's avatar
Chris Cantwell committed
1270 1271 1272 1273
    RegisterCreatorFunction(
        OperatorKey(eTetrahedron, eIProductWRTDerivBase, eSumFac,false),
        IProductWRTDerivBase_SumFac_Tet::create,
        "IProductWRTDerivBase_SumFac_Tet");
1274 1275


Chris Cantwell's avatar
Chris Cantwell committed
1276 1277 1278
/**
 * @brief Inner product WRT deriv base operator using sum-factorisation (Prism)
 */
1279 1280
class IProductWRTDerivBase_SumFac_Prism : public Operator
{
Chris Cantwell's avatar
Chris Cantwell committed
1281 1282 1283 1284
    public:
        OPERATOR_CREATE(IProductWRTDerivBase_SumFac_Prism)

        virtual ~IProductWRTDerivBase_SumFac_Prism()
1285 1286 1287
        {
        }

Spencer Sherwin's avatar
Spencer Sherwin committed
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333
    /**
     * This method calculates:
     *
     * \f[ (d\phi/dx,in[0]) + (d\phi/dy,in[1]) + (d\phi/dz,in[2]) \f]
     *
     * which can be represented in terms of local cartesian
     * derivaties as:
     * 
     * \f[ ((d\phi/d\xi_0\, d\xi_0/dx +
     *       d\phi/d\xi_1\, d\xi_1/dx + 
     *       d\phi/d\xi_2\, d\xi_2/dx),in[0]) + \f]
     * 
     * \f[ ((d\phi/d\xi_0\, d\xi_0/dy +
     *       d\phi/d\xi_1\, d\xi_1/dy + 
     *       d\phi/d\xi_2\, d\xi_2/dy),in[1]) + \f]
     *  
     * \f[ ((d\phi/d\xi_0\, d\xi_0/dz +
     *       d\phi/d\xi_1\, d\xi_1/dz + 
     *       d\phi/d\xi_2\, d\xi_2/dz),in[2]) \, \f]
     *
     * where we note that
     *
     *  \f[ d\phi/d\xi_0  =
     *            d\phi/d\eta_0 d\eta_0/d\xi_0 = d\phi/d\eta_0 2/(1-\eta_2) \f]
     *
     *  \f[ d\phi/d\xi_2  =
     *            d\phi/d\eta_0 d\eta_0/d\xi_2 + d\phi/d\eta_2 d\eta_2/d\xi_2 =
     *            d\phi/d\eta_0 (1+\eta_0)/(1-\eta_2) + d\phi/d\eta_2 \f]
     *
     *
     *  and so the full inner products are
     * 
     * \f[ (d\phi/dx,in[0]) + (d\phi/dy,in[1]) + (d\phi/dz,in[2]) = \f]
     * 
     * \f[ (d\phi/d\eta_0, ((2/(1-\eta_2) (d\xi_0/dx in[0] + d\xi_0/dy in[1]
     *              + d\xi_0/dz in[2])
     *              + (1-\eta_0)/(1-\eta_2) (d\xi_2/dx in[0] + d\xi_2/dy in[1]
     *              + d\xi_2/dz in[2] )) +  \f]
     *
     * \f[ (d\phi/d\eta_1, (d\xi_1/dx in[0] + d\xi_1/dy in[1]
     *                + d\xi_1/dz in[2])) +  \f]
     *
     * \f[ (d\phi/d\eta_2, (d\xi_2/dx in[0] + d\xi_2/dy in[1]
     *               + d\xi_2/dz in[2])) \f]
     *
     */
Chris Cantwell's avatar
Chris Cantwell committed
1334 1335 1336 1337 1338 1339
        virtual void operator()(
                const Array<OneD, const NekDouble> &entry0,
                      Array<OneD, NekDouble>       &entry1,
                      Array<OneD, NekDouble>       &entry2,
                      Array<OneD, NekDouble>       &entry3,
                      Array<OneD, NekDouble>       &wsp)
1340
        {
Chris Cantwell's avatar
Chris Cantwell committed
1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354
            unsigned int nPhys  = m_stdExp->GetTotPoints();
            unsigned int ntot   = m_numElmt*nPhys;
            unsigned int nmodes = m_stdExp->GetNcoeffs();
            unsigned int nmax  = max(ntot,m_numElmt*nmodes);
            Array<OneD, Array<OneD, const NekDouble> > in(3);
            Array<OneD, NekDouble> output, wsp1;
            Array<OneD, Array<OneD, NekDouble> > tmp(3);

            in[0] = entry0; in[1] = entry1;
            in[2] = entry2;

            output =  entry3;

            for(int i = 0; i < 3; ++i)
1355
            {
Chris Cantwell's avatar
Chris Cantwell committed
1356
                tmp[i] = wsp + i*nmax;
1357 1358
            }

Chris Cantwell's avatar
Chris Cantwell committed
1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369
            for(int i = 0; i < 3; ++i)
            {
                Vmath::Vmul (ntot,m_derivFac[i],1, in[0],1,
                             tmp[i],1);
                for(int j = 1; j < 3; ++j)
                {
                    Vmath::Vvtvp (ntot,m_derivFac[i+3*j],1,
                                  in[j],1, tmp[i], 1, tmp[i],1);
                }
            }
            wsp1   = wsp + 3*nmax;
1370

Chris Cantwell's avatar
Chris Cantwell committed
1371 1372 1373 1374 1375 1376
            // Sort into eta factors
            for (int i = 0; i < m_numElmt; ++i)
            {
                // scale tmp[0] by fac0
                Vmath::Vmul(nPhys,&m_fac0[0],1,tmp[0].get()+i*nPhys,1,
                            tmp[0].get()+i*nPhys,1);
1377

Chris Cantwell's avatar
Chris Cantwell committed
1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402
                // scale tmp[2] by fac1 and add to tmp0
                Vmath::Vvtvp(nPhys,&m_fac1[0],1,tmp[2].get()+i*nPhys,1,
                             tmp[0].get()+i*nPhys,1,tmp[0].get()+i*nPhys,1);
            }

            // calculate Iproduct WRT Std Deriv
            PrismIProduct(m_sortTopVertex, m_numElmt,
                        m_nquad0,   m_nquad1,  m_nquad2,
                        m_nmodes0,  m_nmodes1, m_nmodes2,
                        m_derbase0, m_base1,   m_base2,
                        m_jac,tmp[0],output,wsp1);

            PrismIProduct(m_sortTopVertex, m_numElmt,
                        m_nquad0,  m_nquad1,   m_nquad2,
                        m_nmodes0, m_nmodes1,  m_nmodes2,
                        m_base0,   m_derbase1, m_base2,
                        m_jac,tmp[1],tmp[0],wsp1);
            Vmath::Vadd(m_numElmt*nmodes,tmp[0],1,output,1,output,1);

            PrismIProduct(m_sortTopVertex, m_numElmt,
                        m_nquad0,  m_nquad1,  m_nquad2,
                        m_nmodes0, m_nmodes1, m_nmodes2,
                        m_base0,   m_base1,   m_derbase2,
                        m_jac,tmp[2],tmp[0],wsp1);
            Vmath::Vadd(m_numElmt*nmodes,tmp[0],1,output,1,output,1);
1403 1404
        }

1405 1406 1407 1408 1409 1410 1411 1412 1413
        virtual void operator()(
                      int                           dir,
                const Array<OneD, const NekDouble> &input,
                      Array<OneD,       NekDouble> &output,
                      Array<OneD,       NekDouble> &wsp)
        {
            ASSERTL0(false, "Not valid for this operator.");
        }

1414

Chris Cantwell's avatar
Chris Cantwell committed
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450
    protected:
        const int                       m_nquad0;
        const int                       m_nquad1;
        const int                       m_nquad2;
        const int                       m_nmodes0;
        const int                       m_nmodes1;
        const int                       m_nmodes2;
        Array<OneD, const NekDouble>    m_jac;
        Array<OneD, const NekDouble>    m_base0;
        Array<OneD, const NekDouble>    m_base1;
        Array<OneD, const NekDouble>    m_base2;
        Array<OneD, const NekDouble>    m_derbase0;
        Array<OneD, const NekDouble>    m_derbase1;
        Array<OneD, const NekDouble>    m_derbase2;
        Array<TwoD, const NekDouble>    m_derivFac;
        Array<OneD, NekDouble>          m_fac0;
        Array<OneD, NekDouble>          m_fac1;
        bool                            m_sortTopVertex;

    private:
        IProductWRTDerivBase_SumFac_Prism(
                vector<StdRegions::StdExpansionSharedPtr> pCollExp,
                CoalescedGeomDataSharedPtr                pGeomData)
            : Operator  (pCollExp, pGeomData),
              m_nquad0  (m_stdExp->GetNumPoints(0)),
              m_nquad1  (m_stdExp->GetNumPoints(1)),
              m_nquad2  (m_stdExp->GetNumPoints(2)),
              m_nmodes0 (m_stdExp->GetBasisNumModes(0)),
              m_nmodes1 (m_stdExp->GetBasisNumModes(1)),
              m_nmodes2 (m_stdExp->GetBasisNumModes(2)),
              m_base0   (m_stdExp->GetBasis(0)->GetBdata()),
              m_base1   (m_stdExp->GetBasis(1)->GetBdata()),
              m_base2   (m_stdExp->GetBasis(2)->GetBdata()),
              m_derbase0(m_stdExp->GetBasis(0)->GetDbdata()),
              m_derbase1(m_stdExp->GetBasis(1)->GetDbdata()),
              m_derbase2(m_stdExp->GetBasis(2)->GetDbdata())
1451 1452

        {
Chris Cantwell's avatar
Chris Cantwell committed
1453 1454 1455 1456 1457 1458 1459
            m_jac      = pGeomData->GetJacWithStdWeights(pCollExp);
            m_wspSize  = 6 * m_numElmt * (max(m_nquad0*m_nquad1*m_nquad2,
                                              m_nmodes0*m_nmodes1*m_nmodes2));
            m_derivFac = pGeomData->GetDerivFactors(pCollExp);

            if(m_stdExp->GetBasis(0)->GetBasisType()
                    == LibUtilities::eModified_A)
1460
            {
Chris Cantwell's avatar
Chris Cantwell committed
1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474
                m_sortTopVertex = true;
            }
            else
            {
                m_sortTopVertex = false;
            }

            const Array<OneD, const NekDouble>& z0
                                            = m_stdExp->GetBasis(0)->GetZ();
            const Array<OneD, const NekDouble>& z2
                                            = m_stdExp->GetBasis(2)->GetZ();

            m_fac0 = Array<OneD, NekDouble>(m_nquad0*m_nquad1*m_nquad2);
            m_fac1 = Array<OneD, NekDouble>(m_nquad0*m_nquad1*m_nquad2);
1475

Chris Cantwell's avatar
Chris Cantwell committed
1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489
            for (int i = 0; i < m_nquad0; ++i)
            {
                for(int j = 0; j < m_nquad1; ++j)
                {
                    for(int k = 0; k < m_nquad2; ++k)
                    {
                        // set up geometric factor: 2/(1-z1)
                        m_fac0[i + j*m_nquad0 + k*m_nquad0*m_nquad1]
                               = 2.0/(1-z2[k]);
                        // set up geometric factor: (1+z0)/(1-z1)
                        m_fac1[i + j*m_nquad0 + k*m_nquad0*m_nquad1]
                               = (1+z0[i])/(1-z2[k]);

                    }
1490 1491 1492
                }
            }
        }
1493 1494
};

Chris Cantwell's avatar
Chris Cantwell committed
1495
/// Factory initialisation for the IProductWRTDerivBase_SumFac_Prism operator
1496
OperatorKey IProductWRTDerivBase_SumFac_Prism::m_type = GetOperatorFactory().
Chris Cantwell's avatar
Chris Cantwell committed
1497 1498 1499 1500
    RegisterCreatorFunction(
        OperatorKey(ePrism, eIProductWRTDerivBase, eSumFac, false),
        IProductWRTDerivBase_SumFac_Prism::create,
        "IProductWRTDerivBase_SumFac_Prism");
1501

1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515


/**
 * @brief Inner product WRT deriv base operator using sum-factorisation (Pyr)
 */
class IProductWRTDerivBase_SumFac_Pyr : public Operator
{
    public:
        OPERATOR_CREATE(IProductWRTDerivBase_SumFac_Pyr)

        virtual ~IProductWRTDerivBase_SumFac_Pyr()
        {
        }

Spencer Sherwin's avatar
Spencer Sherwin committed
1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570

    /**
     * This method calculates:
     *
     * \f[ (d\phi/dx,in[0]) + (d\phi/dy,in[1]) + (d\phi/dz,in[2]) \f]
     *
     * which can be represented in terms of local cartesian
     * derivaties as:
     * 
     * \f[ ((d\phi/d\xi_0\, d\xi_0/dx +
     *       d\phi/d\xi_1\, d\xi_1/dx + 
     *       d\phi/d\xi_2\, d\xi_2/dx),in[0]) + \f]
     * 
     * \f[ ((d\phi/d\xi_0\, d\xi_0/dy +
     *       d\phi/d\xi_1\, d\xi_1/dy + 
     *       d\phi/d\xi_2\, d\xi_2/dy),in[1]) + \f]
     *  
     * \f[ ((d\phi/d\xi_0\, d\xi_0/dz +
     *       d\phi/d\xi_1\, d\xi_1/dz + 
     *       d\phi/d\xi_2\, d\xi_2/dz),in[2]) \, \f]
     *
     * where we note that
     *
     * \f[ d\phi/d\xi_0  =
     *            d\phi/d\eta_0\, d\eta_0/d\xi_0 = 
     *            d\phi/d\eta_0\, 2/(1-\eta_2). \f]
     *
     *  \f[ d\phi/d\xi_1  =
     *            d\phi/d\eta_1\, d\eta_1/d\xi_1 = 
     *            d\phi/d\eta_1\, 2/(1-\eta_2) \f]
     *
     *  \f[ d\phi/d\xi_2  =
     *          d\phi/d\eta_0\, d\eta_0/d\xi_2 + 
     *          d\phi/d\eta_1\, d\eta_1/d\xi_2 +
     *          d\phi/d\eta_2\, d\eta_2/d\xi_2 =
     *          d\phi/d\eta_0 (1+\eta_0)/(1-\eta_2) +
     *          d\phi/d\eta_1 (1+\eta_1)/(1-\eta_2) + d\phi/d\eta_2 \f]
     *
     *  and so the full inner products are
     * 
     * \f[ (d\phi/dx,in[0]) + (d\phi/dy,in[1]) + (d\phi/dz,in[2]) = \f]
     * 
     * \f[ (d\phi/d\eta_0, ((2/(1-\eta_2) (d\xi_0/dx in[0] + 
     *      d\xi_0/dy in[1] + 
     *     (1-\eta_0)/(1-\eta_2) (d\xi_2/dx in[0] + d\xi_2/dy in[1]
     *                               + d\xi_2/dz in[2] )) + \f]
     * \f[ (d\phi/d\eta_1, ((2/(1-\eta_2) (d\xi_1/dx in[0] +
     *      d\xi_0/dy in[1] + d\xi_0/dz in[2]) +