Nektar++
Loading...
Searching...
No Matches
StdTriExp.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: StdTriExp.cpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Triangle routines built upon StdExpansion2D
32//
33///////////////////////////////////////////////////////////////////////////////
34
38#include <StdRegions/StdSegExp.h> // for StdSegExp, etc
40
41using namespace std;
45
46namespace Nektar::StdRegions
47{
48// Declaration of scalar routine
52
54 const LibUtilities::BasisKey &Bb)
55 : StdExpansion(LibUtilities::StdTriData::getNumberOfCoefficients(
56 Ba.GetNumModes(), Bb.GetNumModes()),
57 2, Ba, Bb),
58 StdExpansion2D(LibUtilities::StdTriData::getNumberOfCoefficients(
59 Ba.GetNumModes(), Bb.GetNumModes()),
60 Ba, Bb)
61{
62 ASSERTL0(Ba.GetNumModes() <= Bb.GetNumModes(),
63 "order in 'a' direction is higher than order "
64 "in 'b' direction");
65
66 // cache integration weights for future use
67 m_weights.push_back(m_base[0]->GetW());
68
69 StdFacKey w1key(eWeights1, Bb);
70 // get weights[1] from manager where points are rescaled
71 m_weights.push_back(GetStdFac(w1key));
72}
73
74//-----------------------------
75// Differentiation Methods
76//-----------------------------
77/**
78 * \brief Calculate the derivative of the physical points.
79 *
80 * \f$ \frac{\partial u}{\partial x_1} = \left .
81 * \frac{2.0}{1-\eta_2} \frac{\partial u}{\partial d\eta_1}
82 * \right |_{\eta_2}\f$
83 *
84 * \f$ \frac{\partial u}{\partial x_2} = \left .
85 * \frac{1+\eta_1}{1-\eta_2} \frac{\partial u}{\partial d\eta_1}
86 * \right |_{\eta_2} + \left . \frac{\partial u}{\partial d\eta_2}
87 * \right |_{\eta_1} \f$
88 */
92 [[maybe_unused]] Array<OneD, NekDouble> &out_d2)
93{
94 int i;
95 int nquad0 = m_base[0]->GetNumPoints();
96 int nquad1 = m_base[1]->GetNumPoints();
97 Array<OneD, NekDouble> wsp(std::max(nquad0, nquad1));
98
99 const Array<OneD, const NekDouble> &z0 = m_base[0]->GetZ();
100 const Array<OneD, const NekDouble> &z1 = m_base[1]->GetZ();
101
102 // set up geometric factor: 2/(1-z1)
103 Vmath::Sadd(nquad1, -1.0, z1, 1, wsp, 1);
104 Vmath::Sdiv(nquad1, -2.0, wsp, 1, wsp, 1);
105
106 if (out_d0.size() > 0)
107 {
108 PhysTensorDeriv(inarray, out_d0, out_d1);
109
110 for (i = 0; i < nquad1; ++i)
111 {
112 Vmath::Smul(nquad0, wsp[i], &out_d0[0] + i * nquad0, 1,
113 &out_d0[0] + i * nquad0, 1);
114 }
115
116 // if no d1 required do not need to calculate both deriv
117 if (out_d1.size() > 0)
118 {
119 // set up geometric factor: (1+z0)/2
120 Vmath::Sadd(nquad0, 1.0, z0, 1, wsp, 1);
121 Vmath::Smul(nquad0, 0.5, wsp, 1, wsp, 1);
122
123 for (i = 0; i < nquad1; ++i)
124 {
125 Vmath::Vvtvp(nquad0, &wsp[0], 1, &out_d0[0] + i * nquad0, 1,
126 &out_d1[0] + i * nquad0, 1,
127 &out_d1[0] + i * nquad0, 1);
128 }
129 }
130 }
131 else if (out_d1.size() > 0)
132 {
133 Array<OneD, NekDouble> diff0(nquad0 * nquad1);
134 PhysTensorDeriv(inarray, diff0, out_d1);
135
136 for (i = 0; i < nquad1; ++i)
137 {
138 Vmath::Smul(nquad0, wsp[i], &diff0[0] + i * nquad0, 1,
139 &diff0[0] + i * nquad0, 1);
140 }
141
142 Vmath::Sadd(nquad0, 1.0, z0, 1, wsp, 1);
143 Vmath::Smul(nquad0, 0.5, wsp, 1, wsp, 1);
144
145 for (i = 0; i < nquad1; ++i)
146 {
147 Vmath::Vvtvp(nquad0, &wsp[0], 1, &diff0[0] + i * nquad0, 1,
148 &out_d1[0] + i * nquad0, 1, &out_d1[0] + i * nquad0,
149 1);
150 }
151 }
152}
153
154//---------------------------------------
155// Transforms
156//---------------------------------------
157
158/**
159 * \brief Backward tranform for triangular elements
160 *
161 * @note 'q' (base[1]) runs fastest in this element.
162 */
164 Array<OneD, NekDouble> &outarray)
165{
168 "Basis[1] is not of general tensor type");
169
170 const Array<OneD, const NekDouble> base0 = m_base[0]->GetBdata();
171 const Array<OneD, const NekDouble> base1 = m_base[1]->GetBdata();
172
173 int nquad0 = m_base[0]->GetNumPoints();
174 int nquad1 = m_base[1]->GetNumPoints();
175 int nmodes0 = m_base[0]->GetNumModes();
176 int nmodes1 = m_base[1]->GetNumModes();
177
178 std::vector<vec_t, tinysimd::allocator<vec_t>> wsp0(nmodes0);
179 bool isModified = (m_base[0]->GetBasisType() == LibUtilities::eModified_A);
180
181// Swith statment using boost_pp and macros. This unfolls intwo a
182// nested swtich statement where the outer swtich statement runs
183// from SMIN to SMAX for modal order and the inner switch
184// statemets run from the outer value of the case to 2*SMAX for
185// the quadrature order. If you want to see it unwrapped compile
186// in verbose mode and add --preprocess to the c++ command.
187// Default case
188#undef BWDTRANS_DEF
189#define BWDTRANS_DEF \
190 BwdTransTriKernel<false>(nmodes0, nmodes1, nquad0, nquad1, isModified, \
191 base0.data(), base1.data(), wsp0.data(), \
192 (const vec_t *)inarray.data(), \
193 (vec_t *)outarray.data())
194
195// Inner loop case over quarature points
196#undef BWDTRANS_Q
197#define BWDTRANS_Q(r, i) \
198 case NQ(i): \
199 BwdTransTriKernel<false>(NM(i), NM(i), NQ(i), NQ_M1(i), isModified, \
200 base0.data(), base1.data(), wsp0.data(), \
201 (const vec_t *)inarray.data(), \
202 (vec_t *)outarray.data()); \
203 break;
204
205// outer loop case over modes
206#undef BWDTRANS_M
207#define BWDTRANS_M(r, i) \
208 case NM(i): \
209 { \
210 switch (nquad0) \
211 { \
212 BOOST_PP_FOR_##r((NM(i), NM_P1(i), BOOST_PP_MUL(2, NM(i))), \
213 STDLEV2TEST1, STDLEV2UPDATE1, BWDTRANS_Q) default \
214 : BWDTRANS_DEF; \
215 break; \
216 } \
217 } \
218 break;
219
220 // templated cases on equi-ordered modes and standard quad
221 // usage where quad order goes from mode order to 2(*mode
222 // order)
223 if ((nmodes0 == nmodes1) && (nquad0 == nquad1 + 1))
224 {
225 switch (nmodes0)
226 {
227 BOOST_PP_FOR((SMIN, 0, SMAX), STDLEV2TEST, STDLEV2UPDATE,
229 default:
231 break;
232 }
233 }
234 else
235 {
237 }
238}
239
241 const Array<OneD, const NekDouble> &inarray,
242 Array<OneD, NekDouble> &outarray)
243{
244 int i, j;
245 int npoints[2] = {m_base[0]->GetNumPoints(), m_base[1]->GetNumPoints()};
246 int nmodes[2] = {m_base[0]->GetNumModes(), m_base[1]->GetNumModes()};
247
248 fill(outarray.data(), outarray.data() + m_ncoeffs, 0.0);
249
250 Array<OneD, NekDouble> physEdge[3];
251 Array<OneD, NekDouble> coeffEdge[3];
252 for (i = 0; i < 3; i++)
253 {
254 physEdge[i] = Array<OneD, NekDouble>(npoints[i != 0]);
255 coeffEdge[i] = Array<OneD, NekDouble>(nmodes[i != 0]);
256 }
257
258 for (i = 0; i < npoints[0]; i++)
259 {
260 physEdge[0][i] = inarray[i];
261 }
262
263 for (i = 0; i < npoints[1]; i++)
264 {
265 physEdge[1][i] = inarray[npoints[0] - 1 + i * npoints[0]];
266 physEdge[2][i] =
267 inarray[(npoints[1] - 1) * npoints[0] - i * npoints[0]];
268 }
269
270 StdSegExpSharedPtr segexp[2] = {
272 m_base[0]->GetBasisKey()),
274 m_base[1]->GetBasisKey())};
275
277 Array<OneD, int> signArray;
279
280 for (i = 0; i < 3; i++)
281 {
282 segexp[i != 0]->FwdTransBndConstrained(physEdge[i], coeffEdge[i]);
283
284 GetTraceToElementMap(i, mapArray, signArray);
285 for (j = 0; j < nmodes[i != 0]; j++)
286 {
287 sign = (NekDouble)signArray[j];
288 outarray[mapArray[j]] = sign * coeffEdge[i][j];
289 }
290 }
291
294
295 StdMatrixKey masskey(eMass, DetShapeType(), *this);
296 MassMatrixOp(outarray, tmp0, masskey);
297 v_IProductWRTBase(inarray, tmp1);
298
299 Vmath::Vsub(m_ncoeffs, tmp1, 1, tmp0, 1, tmp1, 1);
300
301 // get Mass matrix inverse (only of interior DOF)
302 // use block (1,1) of the static condensed system
303 // note: this block alreay contains the inverse matrix
304 DNekMatSharedPtr matsys =
305 (m_stdStaticCondMatrixManager[masskey])->GetBlock(1, 1);
306
307 int nBoundaryDofs = v_NumBndryCoeffs();
308 int nInteriorDofs = m_ncoeffs - nBoundaryDofs;
309
310 Array<OneD, NekDouble> rhs(nInteriorDofs);
311 Array<OneD, NekDouble> result(nInteriorDofs);
312
313 v_GetInteriorMap(mapArray);
314
315 for (i = 0; i < nInteriorDofs; i++)
316 {
317 rhs[i] = tmp1[mapArray[i]];
318 }
319
320 Blas::Gemv('N', nInteriorDofs, nInteriorDofs, 1.0, &(matsys->GetPtr())[0],
321 nInteriorDofs, rhs.data(), 1, 0.0, result.data(), 1);
322
323 for (i = 0; i < nInteriorDofs; i++)
324 {
325 outarray[mapArray[i]] = result[i];
326 }
327}
328
329//---------------------------------------
330// Inner product functions
331//---------------------------------------
332/** \brief Inner product of \a inarray over region with respect to the
333 * expansion basis (this)->m_base[0] and return in \a outarray
334 *
335 * @param base0 - An array containing the values of the basis in the
336 * 0-direction at the quarature poitns
337 * @param base1 - An array containing the values of the basis in the
338 * 1-direction at the quarature poitns
339 * @param inarray - Array of values evaluated at the physical
340 * quadrature points
341 * @param outarray the values of the inner product with respect to
342 * each basis over region will be stored in the array \a outarray as
343 * output of the function
344 * @param jac - An array of size 1 if not deformed or the number of
345 * quadrature points if deformed holding the values of the jacobian
346 * @param Deformed - a bool identifying if the inner product is to be
347 * treated as a deformed or regular integration which just relates to
348 * how the \param jac array is treated
349 */
351 const Array<OneD, const NekDouble> &base0,
352 const Array<OneD, const NekDouble> &base1,
353 const Array<OneD, const NekDouble> &inarray,
355 const bool Deformed, [[maybe_unused]] const bool CollDir0,
356 [[maybe_unused]] const bool CollDir1)
357{
358 int nquad0 = m_base[0]->GetNumPoints();
359 int nquad1 = m_base[1]->GetNumPoints();
360 int order0 = m_base[0]->GetNumModes();
361 int order1 = m_base[1]->GetNumModes();
362
363 const bool isModified =
364 (m_base[0]->GetBasisType() == LibUtilities::eModified_A);
365
366 std::vector<vec_t, tinysimd::allocator<vec_t>> wsp0(nquad1);
367
368 // Swith statment using boost_pp and macros. This unfolls intwo a
369 // nested swtich statement where the outer swtich statement runs
370 // from SMIN to SMAX for modal order and the inner switch
371 // statemets run from the outer value of the case to 2*SMAX for
372 // the quadrature order. If you want to see it unwrapped compile
373 // in verbose mode and add --preprocess to the c++ command.
374 if (Deformed)
375 {
376 // Default case
377#undef IPRODUCTWRTBASE_DEF
378#define IPRODUCTWRTBASE_DEF \
379 IProductTriKernel<false, false, true>( \
380 order0, order1, nquad0, nquad1, isModified, \
381 (const vec_t *)inarray.data(), base0.data(), base1.data(), \
382 m_weights[0].data(), m_weights[1].data(), (const vec_t *)jac.data(), \
383 (vec_t *)wsp0.data(), (vec_t *)outarray.data())
384
385 // Inner loop case over quarature points
386#undef IPRODUCTWRTBASE_Q
387#define IPRODUCTWRTBASE_Q(r, i) \
388 case NQ(i): \
389 IProductTriKernel<false, false, true>( \
390 NM(i), NM(i), NQ(i), NQ_M1(i), isModified, \
391 (const vec_t *)inarray.data(), base0.data(), base1.data(), \
392 m_weights[0].data(), m_weights[1].data(), \
393 (const vec_t *)jac.data(), (vec_t *)wsp0.data(), \
394 (vec_t *)outarray.data()); \
395 break;
396
397 // outer loop case over modes
398#undef IPRODUCTWRTBASE_M
399#define IPRODUCTWRTBASE_M(r, i) \
400 case NM(i): \
401 { \
402 switch (nquad0) \
403 { \
404 BOOST_PP_FOR_##r((NM(i), NM_P1(i), BOOST_PP_MUL(2, NM(i))), \
405 STDLEV2TEST1, STDLEV2UPDATE1, \
406 IPRODUCTWRTBASE_Q) default : IPRODUCTWRTBASE_DEF; \
407 break; \
408 } \
409 } \
410 break;
411
412 // templated cases on equi-ordered modes and standard quad usage
413 // where quad order goes from mode order to 2(*mode order)
414 if ((order0 == order1) && (nquad0 == nquad1 + 1))
415 {
416 switch (order0)
417 {
418 BOOST_PP_FOR((SMIN, 0, SMAX), STDLEV2TEST, STDLEV2UPDATE,
420 default:
422 break;
423 }
424 }
425 else
426 {
428 }
429 }
430 else // non-deformed case
431 {
432 // Default case
433#undef IPRODUCTWRTBASE_DEF
434#define IPRODUCTWRTBASE_DEF \
435 IProductTriKernel<false, false, false>( \
436 order0, order1, nquad0, nquad1, isModified, \
437 (const vec_t *)inarray.data(), base0.data(), base1.data(), \
438 m_weights[0].data(), m_weights[1].data(), (const vec_t *)jac.data(), \
439 (vec_t *)wsp0.data(), (vec_t *)outarray.data())
440
441 // Inner loop case over quarature points
442#undef IPRODUCTWRTBASE_Q
443#define IPRODUCTWRTBASE_Q(r, i) \
444 case NQ(i): \
445 IProductTriKernel<false, false, false>( \
446 NM(i), NM(i), NQ(i), NQ_M1(i), isModified, \
447 (const vec_t *)inarray.data(), base0.data(), base1.data(), \
448 m_weights[0].data(), m_weights[1].data(), \
449 (const vec_t *)jac.data(), (vec_t *)wsp0.data(), \
450 (vec_t *)outarray.data()); \
451 break;
452
453 // outer loop case over modes
454#undef IPRODUCTWRTBASE_M
455#define IPRODUCTWRTBASE_M(r, i) \
456 case NM(i): \
457 { \
458 switch (nquad0) \
459 { \
460 BOOST_PP_FOR_##r((NM(i), NM_P1(i), BOOST_PP_MUL(2, NM(i))), \
461 STDLEV2TEST1, STDLEV2UPDATE1, \
462 IPRODUCTWRTBASE_Q) default : IPRODUCTWRTBASE_DEF; \
463 break; \
464 } \
465 } \
466 break;
467
468 // templated cases on equi-ordered modes and standard quad usage
469 // where quad order goes from mode order to 2(*mode order)
470 if ((order0 == order1) && (nquad0 == nquad1 + 1))
471 {
472 switch (order0)
473 {
474 BOOST_PP_FOR((SMIN, 0, SMAX), STDLEV2TEST, STDLEV2UPDATE,
476 default:
478 break;
479 }
480 }
481 else
482 {
484 }
485 }
486}
487
489 const int dir, const Array<OneD, const NekDouble> &inarray,
490 Array<OneD, NekDouble> &outarray)
491{
492 int nquad0 = m_base[0]->GetNumPoints();
493 int nquad1 = m_base[1]->GetNumPoints();
494 int nqtot = nquad0 * nquad1;
495 Array<OneD, NekDouble> tmpQuad(nqtot);
496
497 // multiply by 2/(1-z1)
498 StdFacKey fackey(eTwoOverOneMinusZ1, m_base[1]->GetBasisKey());
500 for (int i = 0; i < nquad1; ++i)
501 {
502 Vmath::Smul(nquad0, gfac[i], &inarray[0] + i * nquad0, 1,
503 &tmpQuad[0] + i * nquad0, 1);
504 }
505
506 const Array<OneD, const NekDouble> one(1, 1.0);
507 switch (dir)
508 {
509 case 0:
510 v_IProductWRTBaseKernel(m_base[0]->GetDbdata(),
511 m_base[1]->GetBdata(), tmpQuad, outarray,
512 one, false);
513 break;
514 case 1:
515 {
517
518 // multiply by 0.5*(1-z0)
519 StdFacKey fackey1(eHalfMultOnePlusZ0, m_base[0]->GetBasisKey());
520 gfac = GetStdFac(fackey1);
521 for (int i = 0; i < nquad1; ++i)
522 {
523 Vmath::Vmul(nquad0, &gfac[0], 1, &tmpQuad[0] + i * nquad0, 1,
524 &tmpQuad[0] + i * nquad0, 1);
525 }
526
527 v_IProductWRTBaseKernel(m_base[0]->GetDbdata(),
528 m_base[1]->GetBdata(), tmpQuad, tmpCoeff,
529 one, false);
530
531 v_IProductWRTBaseKernel(m_base[0]->GetBdata(),
532 m_base[1]->GetDbdata(), inarray, outarray,
533 one, false);
534
535 Vmath::Vadd(m_ncoeffs, &tmpCoeff[0], 1, &outarray[0], 1,
536 &outarray[0], 1);
537 break;
538 }
539 default:
540 {
541 ASSERTL1(false, "input dir is out of range");
542 break;
543 }
544 }
545}
546
547//---------------------------------------
548// Evaluation functions
549//---------------------------------------
550
553{
554 NekDouble d1 = 1. - xi[1];
555 if (fabs(d1) < NekConstants::kNekZeroTol)
556 {
557 if (d1 >= 0.)
558 {
560 }
561 else
562 {
564 }
565 }
566 eta[0] = 2. * (1. + xi[0]) / d1 - 1.0;
567 eta[1] = xi[1];
568}
569
572{
573 xi[0] = (1.0 + eta[0]) * (1.0 - eta[1]) * 0.5 - 1.0;
574 xi[1] = eta[1];
575}
576
577void StdTriExp::v_FillMode(const int mode, Array<OneD, NekDouble> &outarray)
578{
579 int i, m;
580 int nquad0 = m_base[0]->GetNumPoints();
581 int nquad1 = m_base[1]->GetNumPoints();
582 int order0 = m_base[0]->GetNumModes();
583 int order1 = m_base[1]->GetNumModes();
584 int mode0 = 0;
585 Array<OneD, const NekDouble> base0 = m_base[0]->GetBdata();
586 Array<OneD, const NekDouble> base1 = m_base[1]->GetBdata();
587
588 ASSERTL2(mode <= m_ncoeffs, "calling argument mode is larger than "
589 "total expansion order");
590
591 m = order1;
592 for (i = 0; i < order0; ++i, m += order1 - i)
593 {
594 if (m > mode)
595 {
596 mode0 = i;
597 break;
598 }
599 }
600
601 // deal with top vertex mode in modified basis
602 if (mode == 1 && m_base[0]->GetBasisType() == LibUtilities::eModified_A)
603 {
604 Vmath::Fill(nquad0 * nquad1, 1.0, outarray, 1);
605 }
606 else
607 {
608 for (i = 0; i < nquad1; ++i)
609 {
610 Vmath::Vcopy(nquad0, (NekDouble *)(base0.data() + mode0 * nquad0),
611 1, &outarray[0] + i * nquad0, 1);
612 }
613 }
614
615 for (i = 0; i < nquad0; ++i)
616 {
617 Vmath::Vmul(nquad1, (NekDouble *)(base1.data() + mode * nquad1), 1,
618 &outarray[0] + i, nquad0, &outarray[0] + i, nquad0);
619 }
620}
621
623 const Array<OneD, const NekDouble> &coords, int mode)
624{
626 LocCoordToLocCollapsed(coords, coll);
627
628 // From mode we need to determine mode0 and mode1 in the (p,q)
629 // direction. mode1 can be directly inferred from mode.
630 const int nm1 = m_base[1]->GetNumModes();
631 const double c = 1 + 2 * nm1;
632 const int mode0 = floor(0.5 * (c - sqrt(c * c - 8 * mode)));
633
634 if (mode == 1 && m_base[0]->GetBasisType() == LibUtilities::eModified_A)
635 {
636 // Account for collapsed vertex.
637 return StdExpansion::BaryEvaluateBasis<1>(coll[1], 1);
638 }
639 else
640 {
641 return StdExpansion::BaryEvaluateBasis<0>(coll[0], mode0) *
642 StdExpansion::BaryEvaluateBasis<1>(coll[1], mode);
643 }
644}
645
647 const Array<OneD, NekDouble> &coord,
648 const Array<OneD, const NekDouble> &inarray,
649 std::array<NekDouble, 3> &firstOrderDerivs)
650{
651 // Collapse coordinates
652 Array<OneD, NekDouble> coll(2, 0.0);
653 LocCoordToLocCollapsed(coord, coll);
654
655 // If near singularity do the old interpolation matrix method
656 if ((1 - coll[1]) < 1e-5)
657 {
658 int totPoints = GetTotPoints();
659 Array<OneD, NekDouble> EphysDeriv0(totPoints), EphysDeriv1(totPoints);
660 v_PhysDeriv(inarray, EphysDeriv0, EphysDeriv1, NullNekDouble1DArray);
661
663 I[0] = GetBase()[0]->GetI(coll);
664 I[1] = GetBase()[1]->GetI(coll + 1);
665
666 firstOrderDerivs[0] = PhysEvaluate(I, EphysDeriv0);
667 firstOrderDerivs[1] = PhysEvaluate(I, EphysDeriv1);
668 return PhysEvaluate(I, inarray);
669 }
670
671 // set up geometric factor: 2.0/(1.0-z1)
672 NekDouble fac0 = 2 / (1 - coll[1]);
673
674 NekDouble val = BaryTensorDeriv(coll, inarray, firstOrderDerivs);
675
676 // Copy d0 into temp for d1
677 NekDouble temp;
678 temp = firstOrderDerivs[0];
679
680 // Multiply by geometric factor
681 firstOrderDerivs[0] = firstOrderDerivs[0] * fac0;
682
683 // set up geometric factor: (1+z0)/(1-z1)
684 NekDouble fac1 = fac0 * (coll[0] + 1) / 2;
685
686 // Multiply out_d0 by geometric factor and add to out_d1
687 firstOrderDerivs[1] += fac1 * temp;
688
689 return val;
690}
691
693{
694 return 3;
695}
696
698{
699 return 3;
700}
701
706
708{
710 "BasisType is not a boundary interior form");
712 "BasisType is not a boundary interior form");
713
714 return 3 + (GetBasisNumModes(0) - 2) + 2 * (GetBasisNumModes(1) - 2);
715}
716
718{
720 "BasisType is not a boundary interior form");
722 "BasisType is not a boundary interior form");
723
724 return GetBasisNumModes(0) + 2 * GetBasisNumModes(1);
725}
726
727int StdTriExp::v_GetTraceNcoeffs(const int i) const
728{
729 ASSERTL2(i >= 0 && i <= 2, "edge id is out of range");
730
731 if (i == 0)
732 {
733 return GetBasisNumModes(0);
734 }
735 else
736 {
737 return GetBasisNumModes(1);
738 }
739}
740
742{
743 ASSERTL2(i >= 0 && i <= 2, "edge id is out of range");
744
745 if (i == 0)
746 {
747 return GetBasisNumModes(0) - 2;
748 }
749 else
750 {
751 return GetBasisNumModes(1) - 2;
752 }
753}
754
755int StdTriExp::v_GetTraceNumPoints(const int i) const
756{
757 ASSERTL2((i >= 0) && (i <= 2), "edge id is out of range");
758
759 if (i == 0)
760 {
761 return GetNumPoints(0);
762 }
763 else
764 {
765 return GetNumPoints(1);
766 }
767}
768
770 const std::vector<unsigned int> &nummodes, int &modes_offset)
771{
773 nummodes[modes_offset], nummodes[modes_offset + 1]);
774 modes_offset += 2;
775
776 return nmodes;
777}
778
780 Array<OneD, NekDouble> &coords_1,
781 [[maybe_unused]] Array<OneD, NekDouble> &coords_2)
782{
783 Array<OneD, const NekDouble> z0 = m_base[0]->GetZ();
784 Array<OneD, const NekDouble> z1 = m_base[1]->GetZ();
785 int nq0 = GetNumPoints(0);
786 int nq1 = GetNumPoints(1);
787 int i, j;
788
789 for (i = 0; i < nq1; ++i)
790 {
791 for (j = 0; j < nq0; ++j)
792 {
793 coords_0[i * nq0 + j] = (1 + z0[j]) * (1 - z1[i]) / 2.0 - 1.0;
794 }
795 Vmath::Fill(nq0, z1[i], &coords_1[0] + i * nq0, 1);
796 }
797}
798
800{
801 return m_base[0]->GetBasisType() == LibUtilities::eModified_A &&
802 m_base[1]->GetBasisType() == LibUtilities::eModified_B;
803}
804
806 const int i, [[maybe_unused]] const int j,
807 [[maybe_unused]] bool UseGLL) const
808{
809 ASSERTL2(i >= 0 && i <= 2, "edge id is out of range");
810
811 // Get basiskey (0 or 1) according to edge id i
812 int dir = (i != 0);
813
814 switch (m_base[dir]->GetBasisType())
815 {
818 {
819 switch (m_base[dir]->GetPointsType())
820 {
824 {
825 return m_base[dir]->GetBasisKey();
826 }
827 break;
828 default:
829 {
831 "Unexpected points distribution " +
833 [m_base[dir]->GetPointsType()] +
834 " in StdTriExp::v_GetTraceBasisKey");
835 }
836 }
837 }
838 break;
840 {
841 switch (m_base[dir]->GetPointsType())
842 {
846 {
848 m_base[dir]->GetNumModes(),
849 m_base[dir]->GetPointsKey());
850 }
851 break;
853 {
855 m_base[dir]
856 ->GetBasisKey()
857 .GetPointsKey()
858 .GetNumPoints() +
859 1,
862 m_base[dir]->GetNumModes(),
863 pkey);
864 }
865 break;
866 case LibUtilities::eGaussRadauMAlpha1Beta0:
867 {
869 m_base[dir]
870 ->GetBasisKey()
871 .GetPointsKey()
872 .GetNumPoints() +
873 1,
876 m_base[dir]->GetNumModes(),
877 pkey);
878 }
879 break;
880 // Currently this does not increase the points by
881 // 1 since when using this quadrature we are
882 // presuming it is already been increased by one
883 // when comopared to
884 // GaussRadauMAlpha1Beta0. Currently used in the
885 // GJP option
886 //
887 // Note have put down it back to numpoints +1 to
888 // test for use on tri faces and GJP.
890 {
892 m_base[dir]
893 ->GetBasisKey()
894 .GetPointsKey()
895 .GetNumPoints() +
896 1,
899 m_base[dir]->GetNumModes(),
900 pkey);
901 }
902 break;
904 {
906 m_base[dir]
907 ->GetBasisKey()
908 .GetPointsKey()
909 .GetNumPoints() +
910 1,
913 m_base[dir]->GetNumModes(),
914 pkey);
915 }
916 break;
917 default:
918 {
920 "Unexpected points distribution " +
922 [m_base[dir]->GetPointsType()] +
923 " in StdTriExp::v_GetTraceBasisKey");
924 }
925 }
926 }
927 break;
929 {
930 switch (m_base[dir]->GetPointsType())
931 {
932 // The edge keeps the element's own points, as a
933 // quadrilateral's edge does.
936 {
938 m_base[dir]->GetNumModes(),
939 m_base[dir]->GetPointsKey());
940 }
941 break;
942 // On a Gauss rule the edge's nodal basis is the one through
943 // Gauss points, collocated with the rule when the mode and
944 // point counts agree.
946 {
948 m_base[dir]->GetNumModes(),
949 m_base[dir]->GetPointsKey());
950 }
951 break;
952 default:
953 {
955 "Unexpected points distribution " +
957 [m_base[dir]->GetPointsType()] +
958 " in StdTriExp::v_GetTraceBasisKey");
959 }
960 }
961 }
962 break;
964 {
965 switch (m_base[dir]->GetPointsType())
966 {
969 {
971 m_base[dir]->GetNumModes(),
972 m_base[dir]->GetPointsKey());
973 }
974 break;
976 {
978 m_base[dir]
979 ->GetBasisKey()
980 .GetPointsKey()
981 .GetNumPoints() +
982 1,
985 m_base[dir]->GetNumModes(),
986 pkey);
987 }
988 break;
989 case LibUtilities::eGaussRadauMAlpha1Beta0:
990 {
992 m_base[dir]
993 ->GetBasisKey()
994 .GetPointsKey()
995 .GetNumPoints() +
996 1,
999 m_base[dir]->GetNumModes(),
1000 pkey);
1001 }
1002 break;
1003 // A Gauss rule in the collapsed direction: the edge takes
1004 // Gauss-Legendre points of the same count, as a quadrilateral's
1005 // edge does and as a tetrahedron's face does for a
1006 // Gauss-Jacobi rule, so the edge points coincide with the
1007 // element's where the rule is Gauss-Legendre; its nodal basis
1008 // is the one through Gauss points.
1011 {
1013 m_base[dir]
1014 ->GetBasisKey()
1015 .GetPointsKey()
1016 .GetNumPoints(),
1019 m_base[dir]->GetNumModes(),
1020 pkey);
1021 }
1022 break;
1023 default:
1024 {
1026 "Unexpected points distribution " +
1028 [m_base[dir]->GetPointsType()] +
1029 " in StdTriExp::v_GetTraceBasisKey");
1030 }
1031 }
1032 }
1033 break;
1034 default:
1035 {
1037 "Information not available to set edge key");
1038 }
1039 }
1041}
1042
1043//--------------------------
1044// Mappings
1045//--------------------------
1046
1047int StdTriExp::v_GetVertexMap(const int localVertexId, bool useCoeffPacking)
1048{
1051 "Mapping not defined for this type of basis");
1052
1053 int localDOF = 0;
1054 if (useCoeffPacking == true)
1055 {
1056 switch (localVertexId)
1057 {
1058 case 0:
1059 {
1060 localDOF = 0;
1061 break;
1062 }
1063 case 1:
1064 {
1065 localDOF = 1;
1066 break;
1067 }
1068 case 2:
1069 {
1070 localDOF = m_base[1]->GetNumModes();
1071 break;
1072 }
1073 default:
1074 {
1075 ASSERTL0(false, "eid must be between 0 and 2");
1076 break;
1077 }
1078 }
1079 }
1080 else // follow book format for vertex indexing.
1081 {
1082 switch (localVertexId)
1083 {
1084 case 0:
1085 {
1086 localDOF = 0;
1087 break;
1088 }
1089 case 1:
1090 {
1091 localDOF = m_base[1]->GetNumModes();
1092 break;
1093 }
1094 case 2:
1095 {
1096 localDOF = 1;
1097 break;
1098 }
1099 default:
1100 {
1101 ASSERTL0(false, "eid must be between 0 and 2");
1102 break;
1103 }
1104 }
1105 }
1106
1107 return localDOF;
1108}
1109
1111{
1114 "Expansion not of a proper type");
1115
1116 int i, j;
1117 int cnt = 0;
1118 int nummodes0, nummodes1;
1119 int startvalue;
1120 if (outarray.size() != GetNcoeffs() - NumBndryCoeffs())
1121 {
1123 }
1124
1125 nummodes0 = m_base[0]->GetNumModes();
1126 nummodes1 = m_base[1]->GetNumModes();
1127
1128 startvalue = 2 * nummodes1;
1129
1130 for (i = 0; i < nummodes0 - 2; i++)
1131 {
1132 for (j = 0; j < nummodes1 - 3 - i; j++)
1133 {
1134 outarray[cnt++] = startvalue + j;
1135 }
1136 startvalue += nummodes1 - 2 - i;
1137 }
1138}
1139
1141{
1144 "Expansion not of expected type");
1145 int i;
1146 int cnt;
1147 int nummodes0, nummodes1;
1148 int value;
1149
1150 if (outarray.size() != NumBndryCoeffs())
1151 {
1153 }
1154
1155 nummodes0 = m_base[0]->GetNumModes();
1156 nummodes1 = m_base[1]->GetNumModes();
1157
1158 value = 2 * nummodes1 - 1;
1159 for (i = 0; i < value; i++)
1160 {
1161 outarray[i] = i;
1162 }
1163 cnt = value;
1164
1165 for (i = 0; i < nummodes0 - 2; i++)
1166 {
1167 outarray[cnt++] = value;
1168 value += nummodes1 - 2 - i;
1169 }
1170}
1171
1172void StdTriExp::v_GetTraceCoeffMap(const unsigned int eid,
1173 Array<OneD, unsigned int> &maparray)
1174{
1175
1178 "Mapping not defined for this type of basis");
1179
1180 ASSERTL1(eid < 3, "eid must be between 0 and 2");
1181
1182 int i;
1183 int order0 = m_base[0]->GetNumModes();
1184 int order1 = m_base[1]->GetNumModes();
1185 int numModes = (eid == 0) ? order0 : order1;
1186
1187 if (maparray.size() != numModes)
1188 {
1189 maparray = Array<OneD, unsigned int>(numModes);
1190 }
1191
1192 switch (eid)
1193 {
1194 case 0:
1195 {
1196 int cnt = 0;
1197 for (i = 0; i < numModes; cnt += order1 - i, ++i)
1198 {
1199 maparray[i] = cnt;
1200 }
1201 break;
1202 }
1203 case 1:
1204 {
1205 maparray[0] = order1;
1206 maparray[1] = 1;
1207 for (i = 2; i < numModes; i++)
1208 {
1209 maparray[i] = order1 - 1 + i;
1210 }
1211 break;
1212 }
1213 case 2:
1214 {
1215 for (i = 0; i < numModes; i++)
1216 {
1217 maparray[i] = i;
1218 }
1219 break;
1220 }
1221 default:
1222 ASSERTL0(false, "eid must be between 0 and 2");
1223 break;
1224 }
1225}
1226
1228 const int eid, Array<OneD, unsigned int> &maparray,
1229 Array<OneD, int> &signarray, const Orientation edgeOrient)
1230{
1233 "Mapping not defined for this type of basis");
1234 int i;
1235 const int nummodes1 = m_base[1]->GetNumModes();
1236 const int nEdgeIntCoeffs = GetTraceNcoeffs(eid) - 2;
1237
1238 if (maparray.size() != nEdgeIntCoeffs)
1239 {
1240 maparray = Array<OneD, unsigned int>(nEdgeIntCoeffs);
1241 }
1242
1243 if (signarray.size() != nEdgeIntCoeffs)
1244 {
1245 signarray = Array<OneD, int>(nEdgeIntCoeffs, 1);
1246 }
1247 else
1248 {
1249 fill(signarray.data(), signarray.data() + nEdgeIntCoeffs, 1);
1250 }
1251
1252 switch (eid)
1253 {
1254 case 0:
1255 {
1256 int cnt = 2 * nummodes1 - 1;
1257 for (i = 0; i < nEdgeIntCoeffs; cnt += nummodes1 - 2 - i, ++i)
1258 {
1259 maparray[i] = cnt;
1260 }
1261 break;
1262 }
1263 case 1:
1264 {
1265 for (i = 0; i < nEdgeIntCoeffs; i++)
1266 {
1267 maparray[i] = nummodes1 + 1 + i;
1268 }
1269 break;
1270 }
1271 case 2:
1272 {
1273 for (i = 0; i < nEdgeIntCoeffs; i++)
1274 {
1275 maparray[i] = 2 + i;
1276 }
1277 break;
1278 }
1279 default:
1280 {
1281 ASSERTL0(false, "eid must be between 0 and 2");
1282 break;
1283 }
1284 }
1285
1286 if (edgeOrient == eBackwards)
1287 {
1288 for (i = 1; i < nEdgeIntCoeffs; i += 2)
1289 {
1290 signarray[i] = -1;
1291 }
1292 }
1293}
1294
1295//---------------------------------------
1296// Wrapper functions
1297//---------------------------------------
1298
1300{
1301
1302 MatrixType mtype = mkey.GetMatrixType();
1303
1304 DNekMatSharedPtr Mat;
1305
1306 switch (mtype)
1307 {
1309 {
1310 int nq0, nq1, nq;
1311
1312 nq0 = m_base[0]->GetNumPoints();
1313 nq1 = m_base[1]->GetNumPoints();
1314
1315 // take definition from key
1317 {
1318 nq = (int)mkey.GetConstFactor(eFactorConst);
1319 }
1320 else
1321 {
1322 nq = max(nq0, nq1);
1323 }
1324
1327 Array<OneD, NekDouble> coll(2);
1329 Array<OneD, NekDouble> tmp(nq0);
1330
1331 Mat = MemoryManager<DNekMat>::AllocateSharedPtr(neq, nq0 * nq1);
1332 int cnt = 0;
1333
1334 for (int i = 0; i < nq; ++i)
1335 {
1336 for (int j = 0; j < nq - i; ++j, ++cnt)
1337 {
1338 coords[cnt] = Array<OneD, NekDouble>(2);
1339 coords[cnt][0] = -1.0 + 2 * j / (NekDouble)(nq - 1);
1340 coords[cnt][1] = -1.0 + 2 * i / (NekDouble)(nq - 1);
1341 }
1342 }
1343
1344 for (int i = 0; i < neq - 1; ++i)
1345 {
1346 LocCoordToLocCollapsed(coords[i], coll);
1347
1348 I[0] = m_base[0]->GetI(coll);
1349 I[1] = m_base[1]->GetI(coll + 1);
1350
1351 // interpolate first coordinate direction
1352 for (int j = 0; j < nq1; ++j)
1353 {
1354 NekDouble fac = (I[1]->GetPtr())[j];
1355 Vmath::Smul(nq0, fac, I[0]->GetPtr(), 1, tmp, 1);
1356
1357 Vmath::Vcopy(nq0, &tmp[0], 1,
1358 Mat->GetRawPtr() + j * nq0 * neq + i, neq);
1359 }
1360 }
1361
1362 // evaluate top vertex as average of all interpolation
1363 // along collapsed coordinates at singular vertex
1364 coll[1] = 1.0;
1365 I[1] = m_base[1]->GetI(coll + 1);
1366
1367 // interpolate first coordinate direction
1368 for (int j = 0; j < nq1; ++j)
1369 {
1370 NekDouble fac = (I[1]->GetPtr())[j] / ((NekDouble)nq0);
1371
1372 Vmath::Fill(nq0, fac,
1373 Mat->GetRawPtr() + j * nq0 * neq + neq - 1, neq);
1374 }
1375
1376 break;
1377 }
1378 case ePhysInterpToGLL:
1379 {
1380 int nq0, nq1, nq;
1381
1382 nq0 = m_base[0]->GetNumPoints();
1383 nq1 = m_base[1]->GetNumPoints();
1384
1385 // take definition from key
1387 {
1388 nq = (int)mkey.GetConstFactor(eFactorConst);
1389 }
1390 else
1391 {
1392 nq = max(nq0, nq1);
1393 }
1394
1396 Array<OneD, NekDouble> coords(2);
1397 Array<OneD, NekDouble> coll(2);
1399 Array<OneD, NekDouble> tmp(nq0);
1400
1401 Mat = MemoryManager<DNekMat>::AllocateSharedPtr(neq, nq0 * nq1);
1402
1404
1406 LibUtilities::PointsManager()[key]->GetPoints(x, y);
1407
1408 // set up nodal points in a similar mannger to equispaced
1409 // points startign at bottom and working upwards left to
1410 // right
1411
1412 int row = 0;
1413 // First Vertex
1414 coords[0] = x[0];
1415 coords[1] = y[0];
1416 LocCoordToLocCollapsed(coords, coll);
1417
1418 I[0] = m_base[0]->GetI(coll);
1419 I[1] = m_base[1]->GetI(coll + 1);
1420
1421 // interpolate first coordinate direction
1422 for (int j = 0; j < nq1; ++j)
1423 {
1424 NekDouble fac = (I[1]->GetPtr())[j];
1425 Vmath::Smul(nq0, fac, I[0]->GetPtr(), 1, tmp, 1);
1426
1427 Vmath::Vcopy(nq0, &tmp[0], 1,
1428 Mat->GetRawPtr() + j * nq0 * neq + row, neq);
1429 }
1430 row++;
1431
1432 // First edge
1433 for (int i = 0; i < nq - 2; ++i)
1434 {
1435 coords[0] = x[3 + i];
1436 coords[1] = y[3 + i];
1437 LocCoordToLocCollapsed(coords, coll);
1438
1439 I[0] = m_base[0]->GetI(coll);
1440 I[1] = m_base[1]->GetI(coll + 1);
1441
1442 // interpolate first coordinate direction
1443 for (int j = 0; j < nq1; ++j)
1444 {
1445 NekDouble fac = (I[1]->GetPtr())[j];
1446 Vmath::Smul(nq0, fac, I[0]->GetPtr(), 1, tmp, 1);
1447
1448 Vmath::Vcopy(nq0, &tmp[0], 1,
1449 Mat->GetRawPtr() + j * nq0 * neq + row, neq);
1450 }
1451 row++;
1452 }
1453
1454 // Second Vertex
1455 coords[0] = x[1];
1456 coords[1] = y[1];
1457 LocCoordToLocCollapsed(coords, coll);
1458
1459 I[0] = m_base[0]->GetI(coll);
1460 I[1] = m_base[1]->GetI(coll + 1);
1461
1462 // interpolate first coordinate direction
1463 for (int j = 0; j < nq1; ++j)
1464 {
1465 NekDouble fac = (I[1]->GetPtr())[j];
1466 Vmath::Smul(nq0, fac, I[0]->GetPtr(), 1, tmp, 1);
1467
1468 Vmath::Vcopy(nq0, &tmp[0], 1,
1469 Mat->GetRawPtr() + j * nq0 * neq + row, neq);
1470 }
1471 row++;
1472
1473 int cnt = 0;
1474 // other edges and interior
1475 for (int i = 0; i < nq - 2; ++i)
1476 {
1477
1478 // edge 3 (reversing counter-clockwise ordering)
1479 coords[0] = x[3 * (nq - 1) - i - 1];
1480 coords[1] = y[3 * (nq - 1) - i - 1];
1481 // coords[0] = x[3 + 2*(nq-2)+i]; coords[1] = y[3 + 2*(nq-2)+i];
1482 LocCoordToLocCollapsed(coords, coll);
1483
1484 I[0] = m_base[0]->GetI(coll);
1485 I[1] = m_base[1]->GetI(coll + 1);
1486
1487 // interpolate first coordinate direction
1488 for (int j = 0; j < nq1; ++j)
1489 {
1490 NekDouble fac = (I[1]->GetPtr())[j];
1491 Vmath::Smul(nq0, fac, I[0]->GetPtr(), 1, tmp, 1);
1492
1493 Vmath::Vcopy(nq0, &tmp[0], 1,
1494 Mat->GetRawPtr() + j * nq0 * neq + row, neq);
1495 }
1496 row++;
1497
1498 for (int j = 0; j < nq - 3 - i; ++j)
1499 {
1500 coords[0] = x[3 * (nq - 1) + cnt];
1501 coords[1] = y[3 * (nq - 1) + cnt];
1502 LocCoordToLocCollapsed(coords, coll);
1503
1504 I[0] = m_base[0]->GetI(coll);
1505 I[1] = m_base[1]->GetI(coll + 1);
1506
1507 // interpolate first coordinate direction
1508 for (int j = 0; j < nq1; ++j)
1509 {
1510 NekDouble fac = (I[1]->GetPtr())[j];
1511 Vmath::Smul(nq0, fac, I[0]->GetPtr(), 1, tmp, 1);
1512
1513 Vmath::Vcopy(nq0, &tmp[0], 1,
1514 Mat->GetRawPtr() + j * nq0 * neq + row,
1515 neq);
1516 }
1517 row++;
1518 cnt++;
1519 }
1520
1521 // edge 2
1522 coords[0] = x[3 + (nq - 2) + i];
1523 coords[1] = y[3 + (nq - 2) + i];
1524 LocCoordToLocCollapsed(coords, coll);
1525
1526 I[0] = m_base[0]->GetI(coll);
1527 I[1] = m_base[1]->GetI(coll + 1);
1528
1529 // interpolate first coordinate direction
1530 for (int j = 0; j < nq1; ++j)
1531 {
1532 NekDouble fac = (I[1]->GetPtr())[j];
1533 Vmath::Smul(nq0, fac, I[0]->GetPtr(), 1, tmp, 1);
1534
1535 Vmath::Vcopy(nq0, &tmp[0], 1,
1536 Mat->GetRawPtr() + j * nq0 * neq + row, neq);
1537 }
1538 row++;
1539 }
1540
1541 // evaluate top vertex as average of all interpolation
1542 // along collapsed coordinates at singular vertex
1543 coll[1] = 1.0;
1544 I[1] = m_base[1]->GetI(coll + 1);
1545
1546 // interpolate first coordinate direction
1547 for (int j = 0; j < nq1; ++j)
1548 {
1549 NekDouble fac = (I[1]->GetPtr())[j] / ((NekDouble)nq0);
1550
1551 Vmath::Fill(nq0, fac,
1552 Mat->GetRawPtr() + j * nq0 * neq + neq - 1, neq);
1553 }
1554
1555 break;
1556 }
1557 case eEquiSpacedToPhys:
1558 {
1559 int nm0 = m_base[0]->GetNumPoints();
1560 int nm1 = m_base[1]->GetNumPoints();
1561 int neq;
1562
1563 // take definition from key
1565 {
1566 neq = (int)mkey.GetConstFactor(eFactorConst);
1567 }
1568 else
1569 {
1570 neq = max(nm0, nm1);
1571 }
1572
1573 // set up an exansion with the same number of modes as neq;
1575 m_base[0]->GetPointsKey());
1577 m_base[1]->GetPointsKey());
1578
1579 StdTriExp Exp2D(ba, bb);
1580 int ncoeffs = Exp2D.GetNcoeffs();
1581
1582 // Get hold of equispaced to coeff matrix
1583 ConstFactorMap cmap;
1584 cmap[eFactorConst] = neq;
1585 StdMatrixKey Ikey(eEquiSpacedToCoeffs, DetShapeType(), *this, cmap);
1586 DNekMatSharedPtr intmat = Exp2D.GetStdMatrix(Ikey);
1587
1588 int nqtot = GetTotPoints();
1589
1590 // generate a matrix
1591 Mat = MemoryManager<DNekMat>::AllocateSharedPtr(nqtot, ncoeffs);
1592 NekDouble *ptr = Mat->GetRawPtr();
1593
1594 Array<OneD, NekDouble> qmode(nqtot);
1595
1596 // Get first mode at quadrature points
1597 Exp2D.FillMode(0, qmode);
1598
1599 // first part of matrix-matrix multiply intiailising out matrix
1600 for (int j = 0; j < ncoeffs; ++j)
1601 {
1602 NekDouble val = (*intmat)(0, j);
1603 Vmath::Smul(nqtot, val, qmode.data(), 1, ptr + j * nqtot, 1);
1604 }
1605
1606 for (int i = 1; i < ncoeffs; ++i)
1607 {
1608 // Get mode at quadrature points
1609 Exp2D.FillMode(i, qmode);
1610
1611 for (int j = 0; j < ncoeffs; ++j)
1612 {
1613 NekDouble val = (*intmat)(i, j);
1614 Vmath::Svtvp(nqtot, val, qmode.data(), 1, ptr + j * nqtot,
1615 1, ptr + j * nqtot, 1);
1616 }
1617 }
1618 }
1619 break;
1620 default:
1621 {
1623 break;
1624 }
1625 }
1626
1627 return Mat;
1628}
1629
1631{
1632 return v_GenMatrix(mkey);
1633}
1634
1635//---------------------------------------
1636// Operator evaluation functions
1637//---------------------------------------
1638
1640 Array<OneD, NekDouble> &outarray,
1641 const StdMatrixKey &mkey)
1642{
1643 StdExpansion::MassMatrixOp_MatFree(inarray, outarray, mkey);
1644}
1645
1647 Array<OneD, NekDouble> &outarray,
1648 const StdMatrixKey &mkey)
1649{
1650 StdTriExp::v_LaplacianMatrixOp_MatFree(inarray, outarray, mkey);
1651}
1652
1653void StdTriExp::v_LaplacianMatrixOp(const int k1, const int k2,
1654 const Array<OneD, const NekDouble> &inarray,
1655 Array<OneD, NekDouble> &outarray,
1656 const StdMatrixKey &mkey)
1657{
1658 StdExpansion::LaplacianMatrixOp_MatFree(k1, k2, inarray, outarray, mkey);
1659}
1660
1662 const Array<OneD, const NekDouble> &inarray,
1663 Array<OneD, NekDouble> &outarray,
1664 const StdMatrixKey &mkey)
1665{
1666 StdExpansion::WeakDerivMatrixOp_MatFree(i, inarray, outarray, mkey);
1667}
1668
1670 Array<OneD, NekDouble> &outarray,
1671 const StdMatrixKey &mkey)
1672{
1673 StdTriExp::v_HelmholtzMatrixOp_MatFree(inarray, outarray, mkey);
1674}
1675
1677 const StdMatrixKey &mkey)
1678{
1679 int qa = m_base[0]->GetNumPoints();
1680 int qb = m_base[1]->GetNumPoints();
1681 int nmodes_a = m_base[0]->GetNumModes();
1682 int nmodes_b = m_base[1]->GetNumModes();
1683
1684 // Declare orthogonal basis.
1687
1690 StdTriExp OrthoExp(Ba, Bb);
1691
1692 Array<OneD, NekDouble> orthocoeffs(OrthoExp.GetNcoeffs());
1693
1694 // project onto physical space.
1695 OrthoExp.FwdTrans(array, orthocoeffs);
1696
1697 if (mkey.ConstFactorExists(
1698 eFactorSVVPowerKerDiffCoeff)) // Rodrigo's power kern
1699 {
1701 NekDouble SvvDiffCoeff =
1704
1705 int cnt = 0;
1706 for (int j = 0; j < nmodes_a; ++j)
1707 {
1708 for (int k = 0; k < nmodes_b - j; ++k, ++cnt)
1709 {
1710 NekDouble fac = std::max(
1711 pow((1.0 * j) / (nmodes_a - 1), cutoff * nmodes_a),
1712 pow((1.0 * k) / (nmodes_b - 1), cutoff * nmodes_b));
1713
1714 orthocoeffs[cnt] *= (SvvDiffCoeff * fac);
1715 }
1716 }
1717 }
1718 else if (mkey.ConstFactorExists(
1719 eFactorSVVDGKerDiffCoeff)) // Rodrigo/mansoor's DG kernel
1720 {
1723 int max_ab = max(nmodes_a - kSVVDGFiltermodesmin,
1724 nmodes_b - kSVVDGFiltermodesmin);
1725 max_ab = max(max_ab, 0);
1726 max_ab = min(max_ab, kSVVDGFiltermodesmax - kSVVDGFiltermodesmin);
1727
1728 int cnt = 0;
1729 for (int j = 0; j < nmodes_a; ++j)
1730 {
1731 for (int k = 0; k < nmodes_b - j; ++k, ++cnt)
1732 {
1733 int maxjk = max(j, k);
1734 maxjk = min(maxjk, kSVVDGFiltermodesmax - 1);
1735
1736 orthocoeffs[cnt] *= SvvDiffCoeff * kSVVDGFilter[max_ab][maxjk];
1737 }
1738 }
1739 }
1740 else
1741 {
1742 NekDouble SvvDiffCoeff = mkey.GetConstFactor(eFactorSVVDiffCoeff);
1743
1744 int cutoff = (int)(mkey.GetConstFactor(eFactorSVVCutoffRatio) *
1745 min(nmodes_a, nmodes_b));
1746
1747 NekDouble epsilon = 1.0;
1748 int nmodes = min(nmodes_a, nmodes_b);
1749
1750 int cnt = 0;
1751
1752 // apply SVV filter (JEL)
1753 for (int j = 0; j < nmodes_a; ++j)
1754 {
1755 for (int k = 0; k < nmodes_b - j; ++k)
1756 {
1757 if (j + k >= cutoff)
1758 {
1759 orthocoeffs[cnt] *=
1760 (SvvDiffCoeff *
1761 exp(-(j + k - nmodes) * (j + k - nmodes) /
1762 ((NekDouble)((j + k - cutoff + epsilon) *
1763 (j + k - cutoff + epsilon)))));
1764 }
1765 else
1766 {
1767 orthocoeffs[cnt] *= 0.0;
1768 }
1769 cnt++;
1770 }
1771 }
1772 }
1773
1774 // backward transform to physical space
1775 OrthoExp.BwdTrans(orthocoeffs, array);
1776}
1777
1779 const Array<OneD, const NekDouble> &inarray,
1780 Array<OneD, NekDouble> &outarray)
1781{
1782 int n_coeffs = inarray.size();
1783 int nquad0 = m_base[0]->GetNumPoints();
1784 int nquad1 = m_base[1]->GetNumPoints();
1785 Array<OneD, NekDouble> coeff(n_coeffs);
1786 int nqtot = nquad0 * nquad1;
1787 Array<OneD, NekDouble> phys_tmp(nqtot, 0.0);
1788
1789 int nmodes0 = m_base[0]->GetNumModes();
1790 int nmodes1 = m_base[1]->GetNumModes();
1791
1792 // The orthogonal expansion is built on this expansion's own points, so
1793 // that the collapsed direction keeps its Gauss-Radau quadrature.
1794 const LibUtilities::PointsKey Pkey0 = m_base[0]->GetPointsKey();
1795 const LibUtilities::PointsKey Pkey1 = m_base[1]->GetPointsKey();
1796
1797 LibUtilities::BasisKey bortho0(LibUtilities::eOrtho_A, nmodes0, Pkey0);
1798 LibUtilities::BasisKey bortho1(LibUtilities::eOrtho_B, nmodes1, Pkey1);
1799
1800 StdRegions::StdTriExpSharedPtr OrthoTriExp =
1802 bortho1);
1803
1804 BwdTrans(inarray, phys_tmp);
1805 OrthoTriExp->FwdTrans(phys_tmp, coeff);
1806
1807 // Remove every mode whose total degree reaches numMin. The orthogonal
1808 // coefficients are stored with p outermost and q < nmodes1 - p, so the
1809 // degree of a mode is p + q.
1810 for (int p = 0, mode = 0; p < nmodes0; ++p)
1811 {
1812 for (int q = 0; q < nmodes1 - p; ++q, ++mode)
1813 {
1814 if (p + q >= numMin)
1815 {
1816 coeff[mode] = 0.0;
1817 }
1818 }
1819 }
1820
1821 OrthoTriExp->BwdTrans(coeff, phys_tmp);
1822 FwdTrans(phys_tmp, outarray);
1823}
1824
1825//---------------------------------------
1826// Private helper functions
1827//---------------------------------------
1828
1830 Array<OneD, int> &conn, [[maybe_unused]] bool standard)
1831{
1832 int np1 = m_base[0]->GetNumPoints();
1833 int np2 = m_base[1]->GetNumPoints();
1834 int np = max(np1, np2);
1835
1836 conn = Array<OneD, int>(3 * (np - 1) * (np - 1));
1837
1838 int row = 0;
1839 int rowp1 = 0;
1840 int cnt = 0;
1841 for (int i = 0; i < np - 1; ++i)
1842 {
1843 rowp1 += np - i;
1844 for (int j = 0; j < np - i - 2; ++j)
1845 {
1846 conn[cnt++] = row + j;
1847 conn[cnt++] = row + j + 1;
1848 conn[cnt++] = rowp1 + j;
1849
1850 conn[cnt++] = rowp1 + j + 1;
1851 conn[cnt++] = rowp1 + j;
1852 conn[cnt++] = row + j + 1;
1853 }
1854
1855 conn[cnt++] = row + np - i - 2;
1856 conn[cnt++] = row + np - i - 1;
1857 conn[cnt++] = rowp1 + np - i - 2;
1858
1859 row += np - i;
1860 }
1861}
1862} // namespace Nektar::StdRegions
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
#define ASSERTL2(condition, msg)
Assert Level 2 – Debugging which is used FULLDEBUG compilation mode. This level assert is designed to...
#define sign(a, b)
return the sign(b)*a
Definition Polylib.cpp:47
#define BWDTRANS_M(r, i)
#define IPRODUCTWRTBASE_DEF
#define BWDTRANS_DEF
#define IPRODUCTWRTBASE_M(r, i)
#define STDLEV2TEST(r, state)
#define STDLEV2UPDATE(r, state)
Describes the specification for a Basis.
Definition Basis.h:45
int GetNumModes() const
Returns the order of the basis.
Definition Basis.h:74
Defines a specification for a set of points.
Definition Points.h:50
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
void PhysTensorDeriv(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray_d0, Array< OneD, NekDouble > &outarray_d1)
Calculate the 2D derivative in the local tensor/collapsed coordinate at the physical points.
void v_IProductWRTBase(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray) override
Calculate the inner product of inarray with respect to the basis B=base0*base1 and put into outarray.
NekDouble BaryTensorDeriv(const Array< OneD, NekDouble > &coord, const Array< OneD, const NekDouble > &inarray, std::array< NekDouble, 3 > &firstOrderDerivs)
void v_PhysDeriv(const int dir, const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray) override
Calculate the derivative of the physical points in a given direction.
The base class for all shapes.
virtual void v_LaplacianMatrixOp_MatFree(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, const StdMatrixKey &mkey)
int GetNcoeffs(void) const
This function returns the total number of coefficients used in the expansion.
int GetTotPoints() const
This function returns the total number of quadrature points used in the element.
void FillMode(const int mode, Array< OneD, NekDouble > &outarray)
This function fills the array outarray with the mode-th mode of the expansion.
void WeakDerivMatrixOp_MatFree(const int i, const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, const StdMatrixKey &mkey)
LibUtilities::BasisType GetBasisType(const int dir) const
This function returns the type of basis used in the dir direction.
DNekMatSharedPtr GetStdMatrix(const StdMatrixKey &mkey)
void LocCoordToLocCollapsed(const Array< OneD, const NekDouble > &xi, Array< OneD, NekDouble > &eta)
Convert local cartesian coordinate xi into local collapsed coordinates eta.
void MassMatrixOp(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, const StdMatrixKey &mkey)
virtual void v_HelmholtzMatrixOp_MatFree(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, const StdMatrixKey &mkey)
const Array< OneD, const LibUtilities::BasisSharedPtr > & GetBase() const
This function gets the shared point to basis.
DNekMatSharedPtr CreateGeneralMatrix(const StdMatrixKey &mkey)
this function generates the mass matrix
void LaplacianMatrixOp_MatFree(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, const StdMatrixKey &mkey)
NekDouble PhysEvaluate(const Array< OneD, const NekDouble > &coords, const Array< OneD, const NekDouble > &physvals)
This function evaluates the expansion at a single (arbitrary) point of the domain.
void GetTraceToElementMap(const int tid, Array< OneD, unsigned int > &maparray, Array< OneD, int > &signarray, Orientation traceOrient=eForwards, int P=-1, int Q=-1)
LibUtilities::ShapeType DetShapeType() const
This function returns the shape of the expansion domain.
void BwdTrans(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray)
This function performs the Backward transformation from coefficient space to physical space.
int GetTraceNcoeffs(const int i) const
This function returns the number of expansion coefficients belonging to the i-th trace.
LibUtilities::PointsType GetPointsType(const int dir) const
This function returns the type of quadrature points used in the dir direction.
void FwdTrans(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray)
LibUtilities::NekManager< StdMatrixKey, DNekBlkMat, StdMatrixKey::opLess > m_stdStaticCondMatrixManager
int GetNumPoints(const int dir) const
This function returns the number of quadrature points in the dir direction.
Array< OneD, const NekDouble > GetStdFac(const StdFacKey &mkey)
int GetBasisNumModes(const int dir) const
This function returns the number of expansion modes in the dir direction.
Array< OneD, LibUtilities::BasisSharedPtr > m_base
std::vector< Array< OneD, const NekDouble > > m_weights
void MassMatrixOp_MatFree(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, const StdMatrixKey &mkey)
MatrixType GetMatrixType() const
NekDouble GetConstFactor(const ConstFactorType &factor) const
bool ConstFactorExists(const ConstFactorType &factor) const
void v_WeakDerivMatrixOp(const int i, const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, const StdMatrixKey &mkey) override
int v_GetTraceNumPoints(const int i) const override
void v_BwdTrans(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray) override
Backward tranform for triangular elements.
void v_IProductWRTDerivBase(const int dir, const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray) override
void v_LocCollapsedToLocCoord(const Array< OneD, const NekDouble > &eta, Array< OneD, NekDouble > &xi) override
void v_GetCoords(Array< OneD, NekDouble > &coords_x, Array< OneD, NekDouble > &coords_y, Array< OneD, NekDouble > &coords_z) override
int v_CalcNumberOfCoefficients(const std::vector< unsigned int > &nummodes, int &modes_offset) override
const LibUtilities::BasisKey v_GetTraceBasisKey(const int i, const int j, bool UseGLL=false) const override
void v_GetSimplexEquiSpacedConnectivity(Array< OneD, int > &conn, bool standard=true) override
void v_MassMatrixOp(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, const StdMatrixKey &mkey) override
void v_GetBoundaryMap(Array< OneD, unsigned int > &outarray) override
int v_GetNtraces() const final
void v_StdPhysDeriv(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &out_d0, Array< OneD, NekDouble > &out_d1, Array< OneD, NekDouble > &out_d2=NullNekDouble1DArray) override
Calculate the derivative of the physical points.
Definition StdTriExp.cpp:89
void v_GetTraceInteriorToElementMap(const int eid, Array< OneD, unsigned int > &maparray, Array< OneD, int > &signarray, const Orientation edgeOrient=eForwards) override
int v_GetVertexMap(int localVertexId, bool useCoeffPacking=false) override
DNekMatSharedPtr v_CreateStdMatrix(const StdMatrixKey &mkey) override
DNekMatSharedPtr v_GenMatrix(const StdMatrixKey &mkey) override
int v_GetTraceNcoeffs(const int i) const override
void v_GetTraceCoeffMap(const unsigned int traceid, Array< OneD, unsigned int > &maparray) override
bool v_IsBoundaryInteriorExpansion() const override
void v_FillMode(const int mode, Array< OneD, NekDouble > &outarray) override
void v_ReduceOrderCoeffs(int numMin, const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray) override
void v_FwdTransBndConstrained(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray) override
LibUtilities::ShapeType v_DetShapeType() const override
int v_GetTraceIntNcoeffs(const int i) const override
int v_NumDGBndryCoeffs() const override
void v_LocCoordToLocCollapsed(const Array< OneD, const NekDouble > &xi, Array< OneD, NekDouble > &eta) override
NekDouble v_PhysEvaluateBasis(const Array< OneD, const NekDouble > &coords, int mode) final
void v_HelmholtzMatrixOp(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, const StdMatrixKey &mkey) override
NekDouble v_PhysEvalFirstDeriv(const Array< OneD, NekDouble > &coord, const Array< OneD, const NekDouble > &inarray, std::array< NekDouble, 3 > &firstOrderDerivs) override
void v_GetInteriorMap(Array< OneD, unsigned int > &outarray) override
int v_GetNverts() const final
void v_LaplacianMatrixOp(const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, const StdMatrixKey &mkey) override
void v_IProductWRTBaseKernel(const Array< OneD, const NekDouble > &base0, const Array< OneD, const NekDouble > &base1, const Array< OneD, const NekDouble > &inarray, Array< OneD, NekDouble > &outarray, const Array< OneD, NekDouble > &jac, const bool Deformed, const bool CollDir0=false, const bool CollDir1=false) override
Inner product of inarray over region with respect to the expansion basis (this)->m_base[0] and return...
void v_SVVLaplacianFilter(Array< OneD, NekDouble > &array, const StdMatrixKey &mkey) override
int v_NumBndryCoeffs() const override
static void Gemv(const char &trans, const int &m, const int &n, const double &alpha, const double *a, const int &lda, const double *x, const int &incx, const double &beta, double *y, const int &incy)
BLAS level 2: Matrix vector multiply y = alpha A x plus beta y where A[m x n].
Definition Blas.hpp:111
constexpr int getNumberOfCoefficients(int Na, int Nb)
static const BasisKey NullBasisKey(eNoBasisType, 0, NullPointsKey)
Defines a null basis with no type or points.
const std::string kPointsTypeStr[]
PointsManagerT & PointsManager(void)
@ eGaussRadauMLegendre
1D Gauss-Radau-Legendre quadrature points, pinned at x=-1
Definition PointsType.h:47
@ eGaussLegendreWithMP
1D Gauss-Legendre quadrature points with additional x=-1 and x=1 end points
Definition PointsType.h:95
@ eNodalTriElec
2D Nodal Electrostatic Points on a Triangle
Definition PointsType.h:81
@ eGaussGaussAlpha1Beta0
1D Gauss-Jacobi quadrature points,
Definition PointsType.h:100
@ eGaussLobattoLegendre
1D Gauss-Lobatto-Legendre quadrature points
Definition PointsType.h:51
@ eGaussLegendreWithM
1D Gauss-Legendre quadrature points with additional x=-1 point
Definition PointsType.h:97
@ ePolyEvenlySpaced
1D Evenly-spaced points using Lagrange polynomial
Definition PointsType.h:73
@ eGaussGaussLegendre
1D Gauss-Gauss-Legendre quadrature points
Definition PointsType.h:46
@ eModified_B
Principle Modified Functions .
Definition BasisType.h:49
@ eGauss_Lagrange
Lagrange Polynomials using the Gauss points.
Definition BasisType.h:57
@ eOrtho_A
Principle Orthogonal Functions .
Definition BasisType.h:42
@ eGLL_Lagrange
Lagrange for SEM basis .
Definition BasisType.h:56
@ eOrtho_B
Principle Orthogonal Functions .
Definition BasisType.h:44
@ eModified_A
Principle Modified Functions .
Definition BasisType.h:48
static const NekDouble kNekZeroTol
const int kSVVDGFiltermodesmin
tinysimd::scalarT< double > vec_t
const int kSVVDGFiltermodesmax
const NekDouble kSVVDGFilter[9][11]
std::shared_ptr< StdTriExp > StdTriExpSharedPtr
Definition StdTriExp.h:177
std::map< ConstFactorType, NekDouble > ConstFactorMap
std::shared_ptr< StdSegExp > StdSegExpSharedPtr
Definition StdSegExp.h:182
static Array< OneD, NekDouble > NullNekDouble1DArray
std::shared_ptr< DNekMat > DNekMatSharedPtr
void Vmul(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x*y.
Definition Vmath.hpp:74
void Svtvp(int n, const T alpha, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Svtvp (scalar times vector plus vector): z = alpha*x + y.
Definition Vmath.hpp:398
void Vvtvp(int n, const T *w, const int incw, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
vvtvp (vector times vector plus vector): z = w*x + y
Definition Vmath.hpp:368
void Vadd(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Add vector z = x+y.
Definition Vmath.hpp:182
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
Definition Vmath.hpp:102
void Sdiv(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha/x.
Definition Vmath.hpp:156
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition Vmath.hpp:56
void Sadd(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Add vector y = alpha + x.
Definition Vmath.hpp:196
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition Vmath.hpp:828
void Vsub(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Subtract vector z = x-y.
Definition Vmath.hpp:222
STL namespace.
scalarT< T > max(scalarT< T > lhs, scalarT< T > rhs)
Definition scalar.hpp:304
scalarT< T > min(scalarT< T > lhs, scalarT< T > rhs)
Definition scalar.hpp:299
scalarT< T > sqrt(scalarT< T > in)
Definition scalar.hpp:289