Nektar++
Loading...
Searching...
No Matches
StdMatDataWarehouseDef.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: StdMatDataWarehouseDef.hpp
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:
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#pragma once
36
38
53
54#if defined(_MSC_VER)
55#undef max
56#undef min
57#endif
58
59namespace Nektar::StdRegions
60{
61
62template <typename MemSpace, typename TData>
64 const StdMatKey<TData> &stdMatKey)
65{
66 using namespace Nektar::LibUtilities;
67
68 const auto shapeType = stdMatKey.m_shapeType;
69 const auto bkey = stdMatKey.m_basisKeys;
70 const auto stdMatType = stdMatKey.m_stdMatType;
71 const auto nodaltype = stdMatKey.m_nodalType;
72 const auto &nq = stdMatKey.m_nq;
73
74 StdExpansionSharedPtr stdExp = nullptr;
75
76 switch (shapeType)
77 {
78 case ePoint:
79 {
81 break;
82 }
83 case eSegment:
84 {
86 break;
87 }
88 case eTriangle:
89 {
90 stdExp =
92 break;
93 }
94 case eNodalTri:
95 {
97 bkey[0], bkey[1], nodaltype);
98 break;
99 }
100 case eQuadrilateral:
101 {
102 stdExp =
104 break;
105 }
106 case eTetrahedron:
107 {
109 bkey[0], bkey[1], bkey[2]);
110 break;
111 }
112 case eNodalTet:
113 {
115 bkey[0], bkey[1], bkey[2], nodaltype);
116 break;
117 }
118 case ePyramid:
119 {
121 bkey[0], bkey[1], bkey[2]);
122 break;
123 }
124 case eNodalPyr:
125 {
127 bkey[0], bkey[1], bkey[2], nodaltype);
128 break;
129 }
130 case ePrism:
131 {
133 bkey[0], bkey[1], bkey[2]);
134 break;
135 }
136 case eNodalPrism:
137 {
139 bkey[0], bkey[1], bkey[2], nodaltype);
140 break;
141 }
142 case eHexahedron:
143 {
145 bkey[0], bkey[1], bkey[2]);
146 break;
147 }
148 default:
149 break;
150 }
151
152 const auto dimension = stdExp->GetShapeDimension();
153 const auto nqTot = stdExp->GetTotPoints();
154 const auto nmTot = stdExp->GetNcoeffs();
155
156 switch (stdMatType)
157 {
158 case eBwdTransStdMat:
159 {
160 Array<OneD, double> tmp(nmTot), t;
161 Array<OneD, double> mat(nmTot * nqTot);
162 for (unsigned int i = 0; i < nmTot; ++i)
163 {
164 Vmath::Zero(nmTot, tmp, 1);
165 tmp[i] = 1.0;
166 stdExp->BwdTrans(tmp, t = mat + i * nqTot);
167 }
168
169 return MemoryRegion<TData>::template FromArray<MemSpace>(mat);
170 }
171 break;
173 {
174 Array<OneD, double> tmp(nmTot), t(nqTot);
175 Array<OneD, double> mat(nmTot * nqTot);
176 for (unsigned int i = 0; i < nmTot; ++i)
177 {
178 Vmath::Zero(nmTot, tmp, 1);
179 tmp[i] = 1.0;
180 stdExp->BwdTrans(tmp, t);
181 // copy to mat with stride nmTot
182 Vmath::Vcopy(nqTot, &t[0], 1, &mat[i], nmTot);
183 }
184
185 return MemoryRegion<TData>::template FromArray<MemSpace>(mat);
186 }
187 break;
188 case ePhysDerivStdMat:
189 {
190 Array<OneD, double> tmp(nqTot), t;
191 Array<OneD, double> mat(dimension * nqTot * nqTot);
192 for (unsigned int d = 0; d < dimension; ++d)
193 {
194 for (unsigned int i = 0; i < nqTot; ++i)
195 {
196 Vmath::Zero(nqTot, tmp, 1);
197 tmp[i] = 1.0;
198 stdExp->PhysDeriv(d, tmp,
199 t = mat + d * nqTot * nqTot + i * nqTot);
200 }
201 }
202
203 return MemoryRegion<TData>::template FromArray<MemSpace>(mat);
204 }
205 break;
207 {
208 Array<OneD, double> tmp(nqTot), t(nqTot);
209 Array<OneD, double> mat(dimension * nqTot * nqTot);
210 for (unsigned int d = 0; d < dimension; ++d)
211 {
212 for (unsigned int i = 0; i < nqTot; ++i)
213 {
214 Vmath::Zero(nqTot, tmp, 1);
215 tmp[i] = 1.0;
216 stdExp->PhysDeriv(d, tmp, t);
217 // copy to mat with stride nqTot
218 Vmath::Vcopy(nqTot, &t[0], 1, &mat[i + d * nqTot * nqTot],
219 nqTot);
220 }
221 }
222
223 return MemoryRegion<TData>::template FromArray<MemSpace>(mat);
224 }
225 break;
226 case eDerivStdMat:
227 {
228 Array<OneD, double> tmp0(nmTot), t;
229 Array<OneD, double> tmp1(nqTot);
230 Array<OneD, double> mat(dimension * nqTot * nmTot);
231 for (unsigned int d = 0; d < dimension; ++d)
232 {
233 for (unsigned int i = 0; i < nmTot; ++i)
234 {
235 Vmath::Zero(nmTot, tmp0, 1);
236 tmp0[i] = 1.0;
237 stdExp->BwdTrans(tmp0, tmp1);
238 stdExp->PhysDeriv(d, tmp1,
239 t = mat + d * nqTot * nmTot + i * nqTot);
240 }
241 }
242
243 return MemoryRegion<TData>::template FromArray<MemSpace>(mat);
244 }
245 break;
247 {
248 Array<OneD, double> tmp0(nmTot), t(nqTot);
249 Array<OneD, double> tmp1(nqTot);
250 Array<OneD, double> mat(dimension * nqTot * nmTot);
251 for (unsigned int d = 0; d < dimension; ++d)
252 {
253 for (unsigned int i = 0; i < nmTot; ++i)
254 {
255 Vmath::Zero(nmTot, tmp0, 1);
256 tmp0[i] = 1.0;
257 stdExp->BwdTrans(tmp0, tmp1);
258 stdExp->PhysDeriv(d, tmp1, t);
259 // copy to mat with stride nqTot
260 Vmath::Vcopy(nqTot, &t[0], 1, &mat[i + d * nqTot * nmTot],
261 nmTot);
262 }
263 }
264
265 return MemoryRegion<TData>::template FromArray<MemSpace>(mat);
266 }
267 break;
269 {
270 Array<OneD, double> tmp(nqTot), t;
271 Array<OneD, double> mat(nmTot * nqTot);
272 for (unsigned int i = 0; i < nqTot; ++i)
273 {
274 Vmath::Zero(nqTot, tmp, 1);
275 tmp[i] = 1.0;
276 stdExp->IProductWRTBase(tmp, t = mat + i * nmTot);
277 }
278
279 return MemoryRegion<TData>::template FromArray<MemSpace>(mat);
280 }
281 break;
283 {
284 Array<OneD, double> tmp(nqTot), t(nmTot);
285 Array<OneD, double> mat(nmTot * nqTot);
286 for (unsigned int i = 0; i < nqTot; ++i)
287 {
288 Vmath::Zero(nqTot, tmp, 1);
289 tmp[i] = 1.0;
290 stdExp->IProductWRTBase(tmp, t);
291 // copy to mat with stride nqTot
292 Vmath::Vcopy(nmTot, &t[0], 1, &mat[i], nqTot);
293 }
294
295 return MemoryRegion<TData>::template FromArray<MemSpace>(mat);
296 }
297 break;
299 {
300 Array<OneD, double> tmp(nqTot), t;
301 Array<OneD, double> mat(dimension * nmTot * nqTot);
302 for (unsigned int d = 0; d < dimension; ++d)
303 {
304 for (unsigned int i = 0; i < nqTot; ++i)
305 {
306 Vmath::Zero(nqTot, tmp, 1);
307 tmp[i] = 1.0;
308 stdExp->IProductWRTDerivBase(
309 d, tmp, t = mat + d * nmTot * nqTot + i * nmTot);
310 }
311 }
312
313 return MemoryRegion<TData>::template FromArray<MemSpace>(mat);
314 }
315 break;
317 {
318 Array<OneD, double> tmp(nqTot), t(nmTot);
319 Array<OneD, double> mat(dimension * nmTot * nqTot);
320 for (unsigned int d = 0; d < dimension; ++d)
321 {
322 for (unsigned int i = 0; i < nqTot; ++i)
323 {
324 Vmath::Zero(nqTot, tmp, 1);
325 tmp[i] = 1.0;
326 stdExp->IProductWRTDerivBase(d, tmp, t);
327 // copy to mat with stride nqTot
328 Vmath::Vcopy(nmTot, &t[0], 1, &mat[i + d * nmTot * nqTot],
329 nqTot);
330 }
331 }
332
333 return MemoryRegion<TData>::template FromArray<MemSpace>(mat);
334 }
335 break;
337 {
338 const auto nmTot = stdExp->GetTotPoints();
339 const auto nqTot =
340 std::accumulate(nq.begin(), nq.end(), 1, std::multiplies());
341 Array<OneD, double> tmp(nmTot), t;
342 Array<OneD, double> mat(nmTot * nqTot);
343 for (unsigned int i = 0; i < nmTot; ++i)
344 {
345 Vmath::Zero(nmTot, tmp, 1);
346 tmp[i] = 1.0;
347
348 if (stdExp->GetShapeDimension() == 1)
349 {
350 // In keys
351 const PointsKey &inkey0 =
352 stdExp->GetBasis(0)->GetPointsKey();
353
354 // Out keys
355 const PointsKey outkey0(
356 nq[0], stdExp->GetBasis(0)->GetPointsType());
357
358 Interp1D(inkey0, tmp, outkey0, t = mat + i * nqTot);
359 }
360 else if (stdExp->GetShapeDimension() == 2)
361 {
362 // In keys
363 const PointsKey &inkey0 =
364 stdExp->GetBasis(0)->GetPointsKey();
365 const PointsKey &inkey1 =
366 stdExp->GetBasis(1)->GetPointsKey();
367
368 // Out keys
369 const PointsKey outkey0(
370 nq[0], stdExp->GetBasis(0)->GetPointsType());
371 const PointsKey outkey1(
372 nq[1], stdExp->GetBasis(1)->GetPointsType());
373
374 Interp2D(inkey0, inkey1, tmp, outkey0, outkey1,
375 t = mat + i * nqTot);
376 }
377 else if (stdExp->GetShapeDimension() == 3)
378 {
379 // In keys
380 const PointsKey &inkey0 =
381 stdExp->GetBasis(0)->GetPointsKey();
382 const PointsKey &inkey1 =
383 stdExp->GetBasis(1)->GetPointsKey();
384 const PointsKey &inkey2 =
385 stdExp->GetBasis(2)->GetPointsKey();
386
387 // Out keys
388 const PointsKey outkey0(
389 nq[0], stdExp->GetBasis(0)->GetPointsType());
390 const PointsKey outkey1(
391 nq[1], stdExp->GetBasis(1)->GetPointsType());
392 const PointsKey outkey2(
393 nq[2], stdExp->GetBasis(2)->GetPointsType());
394
395 Interp3D(inkey0, inkey1, inkey2, tmp, outkey0, outkey1,
396 outkey2, t = mat + i * nqTot);
397 }
398 }
399
400 return MemoryRegion<TData>::template FromArray<MemSpace>(mat);
401 }
402 break;
404 {
405 const auto nmTot = stdExp->GetTotPoints();
406 const auto nqTot =
407 std::accumulate(nq.begin(), nq.end(), 1, std::multiplies());
408 Array<OneD, double> tmp(nmTot), t(nqTot);
409 Array<OneD, double> mat(nmTot * nqTot);
410 for (unsigned int i = 0; i < nmTot; ++i)
411 {
412 Vmath::Zero(nmTot, tmp, 1);
413 tmp[i] = 1.0;
414
415 if (stdExp->GetShapeDimension() == 1)
416 {
417 // In keys
418 const PointsKey &inkey0 =
419 stdExp->GetBasis(0)->GetPointsKey();
420
421 // Out keys
422 const PointsKey outkey0(
423 nq[0], stdExp->GetBasis(0)->GetPointsType());
424
425 Interp1D(inkey0, tmp, outkey0, t);
426 // Copy to mat with stride nmTot
427 Vmath::Vcopy(nqTot, &t[0], 1, &mat[i], nmTot);
428 }
429 else if (stdExp->GetShapeDimension() == 2)
430 {
431 // In keys
432 const PointsKey &inkey0 =
433 stdExp->GetBasis(0)->GetPointsKey();
434 const PointsKey &inkey1 =
435 stdExp->GetBasis(1)->GetPointsKey();
436
437 // Out keys
438 const PointsKey outkey0(
439 nq[0], stdExp->GetBasis(0)->GetPointsType());
440 const PointsKey outkey1(
441 nq[1], stdExp->GetBasis(1)->GetPointsType());
442
443 Interp2D(inkey0, inkey1, tmp, outkey0, outkey1, t);
444 // Copy to mat with stride nmTot
445 Vmath::Vcopy(nqTot, &t[0], 1, &mat[i], nmTot);
446 }
447 else if (stdExp->GetShapeDimension() == 3)
448 {
449 // In keys
450 const PointsKey &inkey0 =
451 stdExp->GetBasis(0)->GetPointsKey();
452 const PointsKey &inkey1 =
453 stdExp->GetBasis(1)->GetPointsKey();
454 const PointsKey &inkey2 =
455 stdExp->GetBasis(2)->GetPointsKey();
456
457 // Out keys
458 const PointsKey outkey0(
459 nq[0], stdExp->GetBasis(0)->GetPointsType());
460 const PointsKey outkey1(
461 nq[1], stdExp->GetBasis(1)->GetPointsType());
462 const PointsKey outkey2(
463 nq[2], stdExp->GetBasis(2)->GetPointsType());
464
465 Interp3D(inkey0, inkey1, inkey2, tmp, outkey0, outkey1,
466 outkey2, t);
467 // Copy to mat with stride nmTot
468 Vmath::Vcopy(nqTot, &t[0], 1, &mat[i], nmTot);
469 }
470 }
471
472 return MemoryRegion<TData>::template FromArray<MemSpace>(mat);
473 }
474 break;
476 {
477 // Reverse of ePhysInterpStdMat: input lives on the "fine" (nq)
478 // grid, output on the native (basisKeys) grid, via
479 // PhysGalerkinProject{1,2,3}D instead of Interp{1,2,3}D.
480 const auto nmTot = stdExp->GetTotPoints();
481 const auto nqTot =
482 std::accumulate(nq.begin(), nq.end(), 1, std::multiplies());
483 Array<OneD, double> tmp(nqTot), t;
484 Array<OneD, double> mat(nqTot * nmTot);
485 for (unsigned int i = 0; i < nqTot; ++i)
486 {
487 Vmath::Zero(nqTot, tmp, 1);
488 tmp[i] = 1.0;
489
490 if (stdExp->GetShapeDimension() == 1)
491 {
492 // In (fine) keys
493 const LibUtilities::PointsKey inkey0(
494 nq[0], stdExp->GetBasis(0)->GetPointsType());
495
496 // Out (native) keys
497 const LibUtilities::PointsKey &outkey0 =
498 stdExp->GetBasis(0)->GetPointsKey();
499
500 LibUtilities::PhysGalerkinProject1D(inkey0, tmp, outkey0,
501 t = mat + i * nmTot);
502 }
503 else if (stdExp->GetShapeDimension() == 2)
504 {
505 // In (fine) keys
506 const LibUtilities::PointsKey inkey0(
507 nq[0], stdExp->GetBasis(0)->GetPointsType());
508 const LibUtilities::PointsKey inkey1(
509 nq[1], stdExp->GetBasis(1)->GetPointsType());
510
511 // Out (native) keys
512 const LibUtilities::PointsKey &outkey0 =
513 stdExp->GetBasis(0)->GetPointsKey();
514 const LibUtilities::PointsKey &outkey1 =
515 stdExp->GetBasis(1)->GetPointsKey();
516
517 LibUtilities::PhysGalerkinProject2D(inkey0, inkey1, tmp,
518 outkey0, outkey1,
519 t = mat + i * nmTot);
520 }
521 else if (stdExp->GetShapeDimension() == 3)
522 {
523 // In (fine) keys
524 const LibUtilities::PointsKey inkey0(
525 nq[0], stdExp->GetBasis(0)->GetPointsType());
526 const LibUtilities::PointsKey inkey1(
527 nq[1], stdExp->GetBasis(1)->GetPointsType());
528 const LibUtilities::PointsKey inkey2(
529 nq[2], stdExp->GetBasis(2)->GetPointsType());
530
531 // Out (native) keys
532 const LibUtilities::PointsKey &outkey0 =
533 stdExp->GetBasis(0)->GetPointsKey();
534 const LibUtilities::PointsKey &outkey1 =
535 stdExp->GetBasis(1)->GetPointsKey();
536 const LibUtilities::PointsKey &outkey2 =
537 stdExp->GetBasis(2)->GetPointsKey();
538
540 inkey0, inkey1, inkey2, tmp, outkey0, outkey1, outkey2,
541 t = mat + i * nmTot);
542 }
543 }
544
545 return MemoryRegion<TData>::template FromArray<MemSpace>(mat);
546 }
547 break;
549 {
550 const auto nmTot = stdExp->GetTotPoints();
551 const auto nqTot =
552 std::accumulate(nq.begin(), nq.end(), 1, std::multiplies());
553 Array<OneD, double> tmp(nqTot), t(nmTot);
554 Array<OneD, double> mat(nqTot * nmTot);
555 for (unsigned int i = 0; i < nqTot; ++i)
556 {
557 Vmath::Zero(nqTot, tmp, 1);
558 tmp[i] = 1.0;
559
560 if (stdExp->GetShapeDimension() == 1)
561 {
562 // In (fine) keys
563 const LibUtilities::PointsKey inkey0(
564 nq[0], stdExp->GetBasis(0)->GetPointsType());
565
566 // Out (native) keys
567 const LibUtilities::PointsKey &outkey0 =
568 stdExp->GetBasis(0)->GetPointsKey();
569
570 LibUtilities::PhysGalerkinProject1D(inkey0, tmp, outkey0,
571 t);
572 // Copy to mat with stride nqTot
573 Vmath::Vcopy(nmTot, &t[0], 1, &mat[i], nqTot);
574 }
575 else if (stdExp->GetShapeDimension() == 2)
576 {
577 // In (fine) keys
578 const LibUtilities::PointsKey inkey0(
579 nq[0], stdExp->GetBasis(0)->GetPointsType());
580 const LibUtilities::PointsKey inkey1(
581 nq[1], stdExp->GetBasis(1)->GetPointsType());
582
583 // Out (native) keys
584 const LibUtilities::PointsKey &outkey0 =
585 stdExp->GetBasis(0)->GetPointsKey();
586 const LibUtilities::PointsKey &outkey1 =
587 stdExp->GetBasis(1)->GetPointsKey();
588
589 LibUtilities::PhysGalerkinProject2D(inkey0, inkey1, tmp,
590 outkey0, outkey1, t);
591 // Copy to mat with stride nqTot
592 Vmath::Vcopy(nmTot, &t[0], 1, &mat[i], nqTot);
593 }
594 else if (stdExp->GetShapeDimension() == 3)
595 {
596 // In (fine) keys
597 const LibUtilities::PointsKey inkey0(
598 nq[0], stdExp->GetBasis(0)->GetPointsType());
599 const LibUtilities::PointsKey inkey1(
600 nq[1], stdExp->GetBasis(1)->GetPointsType());
601 const LibUtilities::PointsKey inkey2(
602 nq[2], stdExp->GetBasis(2)->GetPointsType());
603
604 // Out (native) keys
605 const LibUtilities::PointsKey &outkey0 =
606 stdExp->GetBasis(0)->GetPointsKey();
607 const LibUtilities::PointsKey &outkey1 =
608 stdExp->GetBasis(1)->GetPointsKey();
609 const LibUtilities::PointsKey &outkey2 =
610 stdExp->GetBasis(2)->GetPointsKey();
611
612 LibUtilities::PhysGalerkinProject3D(inkey0, inkey1, inkey2,
613 tmp, outkey0, outkey1,
614 outkey2, t);
615 // Copy to mat with stride nqTot
616 Vmath::Vcopy(nmTot, &t[0], 1, &mat[i], nqTot);
617 }
618 }
619
620 return MemoryRegion<TData>::template FromArray<MemSpace>(mat);
621 }
622 break;
623 case eMassStdMat:
624 {
625 StdMatrixKey mkey(eMass, stdExp->DetShapeType(), *stdExp);
626 Array<OneD, double> tmp(nmTot), t;
627 Array<OneD, double> mat(nmTot * nmTot);
628 for (unsigned int i = 0; i < nmTot; ++i)
629 {
630 Vmath::Zero(nmTot, tmp, 1);
631 tmp[i] = 1.0;
632 stdExp->MassMatrixOp(tmp, t = mat + i * nmTot, mkey);
633 }
634
635 return MemoryRegion<TData>::template FromArray<MemSpace>(mat);
636 }
637 break;
639 {
640 StdMatrixKey mkey(eMass, stdExp->DetShapeType(), *stdExp);
641 Array<OneD, double> tmp(nmTot), t(nmTot);
642 Array<OneD, double> mat(nmTot * nmTot);
643 for (unsigned int i = 0; i < nmTot; ++i)
644 {
645 Vmath::Zero(nmTot, tmp, 1);
646 tmp[i] = 1.0;
647 stdExp->MassMatrixOp(tmp, t, mkey);
648 // copy to mat with stride nmTot
649 Vmath::Vcopy(nmTot, &t[0], 1, &mat[i], nmTot);
650 }
651
652 return MemoryRegion<TData>::template FromArray<MemSpace>(mat);
653 }
654 break;
655 case eInvMassStdMat:
656 {
657 StdMatrixKey mkey(eInvMass, stdExp->DetShapeType(), *stdExp);
658 const auto &InvMass = stdExp->GetStdMatrix(mkey);
659 Array<OneD, double> mat(nmTot * nmTot);
660 std::copy_n(InvMass->GetRawPtr(), nmTot * nmTot, mat.data());
661
662 return MemoryRegion<TData>::template FromArray<MemSpace>(mat);
663 }
664 break;
666 {
667 StdMatrixKey mkey(eInvMass, stdExp->DetShapeType(), *stdExp);
668 const auto &InvMass = stdExp->GetStdMatrix(mkey);
669 Array<OneD, double> mat(nmTot * nmTot);
670
671 // copy to mat with stride nmTot
672 for (unsigned int i = 0; i < nmTot; ++i)
673 {
674 Vmath::Vcopy(nmTot, &InvMass->GetRawPtr()[i * nmTot], 1,
675 &mat[i], nmTot);
676 }
677 return MemoryRegion<TData>::template FromArray<MemSpace>(mat);
678 }
679 break;
680 case eNodalToModal:
681 {
682 StdMatrixKey Nkey(eInvNBasisTrans, stdExp->DetShapeType(), *stdExp,
684 NullVarFactorsMap, nodaltype);
685 auto vdmMat = stdExp->GetStdMatrix(Nkey);
686
687 auto vdm = MemoryRegion<TData>(nmTot * nmTot);
688 auto vdmptr =
689 vdm.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
690 unsigned int cnt = 0;
691 for (unsigned int i = 0; i < nmTot; ++i)
692 {
693 for (unsigned int j = 0; j < nmTot; ++j, ++cnt)
694 {
695 vdmptr[cnt] = vdmMat->GetValue(i, j);
696 }
697 }
698 return vdm;
699 }
700 break;
701 case eModalToNodal:
702 {
703 StdMatrixKey Nkey(eNBasisTrans, stdExp->DetShapeType(), *stdExp,
705 NullVarFactorsMap, nodaltype);
706 auto vdmMat = stdExp->GetStdMatrix(Nkey);
707
708 auto vdm = MemoryRegion<TData>(nmTot * nmTot);
709 auto vdmptr =
710 vdm.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
711 unsigned int cnt = 0;
712 for (unsigned int i = 0; i < nmTot; ++i)
713 {
714 for (unsigned int j = 0; j < nmTot; ++j, ++cnt)
715 {
716 vdmptr[cnt] = vdmMat->GetValue(i, j);
717 }
718 }
719 return vdm;
720 }
721 break;
723 {
724 StdMatrixKey Nkey(eInvNBasisTrans, stdExp->DetShapeType(), *stdExp,
726 NullVarFactorsMap, nodaltype);
727 auto vdmMat = stdExp->GetStdMatrix(Nkey);
728
729 auto vdm = MemoryRegion<TData>(nmTot * nmTot);
730 auto vdmptr =
731 vdm.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
732 unsigned int cnt = 0;
733 for (unsigned int i = 0; i < nmTot; ++i)
734 {
735 for (unsigned int j = 0; j < nmTot; ++j, ++cnt)
736 {
737 vdmptr[cnt] = vdmMat->GetValue(j, i);
738 }
739 }
740 return vdm;
741 }
742 break;
744 {
745 const auto nBoundaryDofs = stdExp->NumBndryCoeffs();
746 const auto nInteriorDofs = nmTot - nBoundaryDofs;
747 StdMatrixKey mkey(eMass, stdExp->DetShapeType(), *stdExp);
748 const auto &InvMassInterior =
749 stdExp->GetStdStaticCondMatrix(mkey)->GetBlock(1, 1);
750 Array<OneD, double> mat(InvMassInterior->GetStorageSize());
751 std::copy_n(InvMassInterior->GetRawPtr(),
752 nInteriorDofs * nInteriorDofs, mat.data());
753
754 return MemoryRegion<TData>::template FromArray<MemSpace>(mat);
755 }
756 break;
758 {
759 const auto nBoundaryDofs = stdExp->NumBndryCoeffs();
760 const auto nInteriorDofs = nmTot - nBoundaryDofs;
761 StdMatrixKey mkey(eMass, stdExp->DetShapeType(), *stdExp);
762 const auto &InvMassInterior =
763 stdExp->GetStdStaticCondMatrix(mkey)->GetBlock(1, 1);
764 InvMassInterior->Transpose();
765 Array<OneD, double> mat(InvMassInterior->GetStorageSize());
766 std::copy_n(InvMassInterior->GetRawPtr(),
767 nInteriorDofs * nInteriorDofs, mat.data());
768
769 return MemoryRegion<TData>::template FromArray<MemSpace>(mat);
770 }
771 break;
773 {
774 StdMatrixKey mkey(eInvMass, stdExp->DetShapeType(), *stdExp);
775 const auto &invMass = stdExp->GetStdMatrix(mkey);
776 Array<OneD, double> diag(nmTot);
777 for (unsigned int i = 0; i < nmTot; ++i)
778 {
779 diag[i] = invMass->GetValue(i, i);
780 }
781
782 return MemoryRegion<TData>::template FromArray<MemSpace>(diag);
783 }
784 break;
786 {
787 // Column j is B M^{-1} applied to row j of B: the backward
788 // transform of the inverse mass times the modes' values at
789 // point j. Stored column-major; the matrix is symmetric.
790 StdMatrixKey mkey(eInvMass, stdExp->DetShapeType(), *stdExp);
791 const auto &invMass = stdExp->GetStdMatrix(mkey);
792 Array<OneD, double> tmp(nmTot), bmat(nmTot * nqTot), t;
793 for (unsigned int i = 0; i < nmTot; ++i)
794 {
795 Vmath::Zero(nmTot, tmp, 1);
796 tmp[i] = 1.0;
797 stdExp->BwdTrans(tmp, t = bmat + i * nqTot);
798 }
799 Array<OneD, double> coef(nmTot), mat(nqTot * nqTot);
800 for (unsigned int j = 0; j < nqTot; ++j)
801 {
802 for (unsigned int r = 0; r < nmTot; ++r)
803 {
804 double sum = 0.0;
805 for (unsigned int c = 0; c < nmTot; ++c)
806 {
807 sum += invMass->GetValue(r, c) * bmat[c * nqTot + j];
808 }
809 coef[r] = sum;
810 }
811 stdExp->BwdTrans(coef, t = mat + j * nqTot);
812 }
813
814 return MemoryRegion<TData>::template FromArray<MemSpace>(mat);
815 }
816 break;
817 default:
818 NEKERROR(ErrorUtil::efatal, "invalid StdMat requested.");
819 return MemoryRegion<TData>(0);
820 break;
821 }
822}
823
824} // namespace Nektar::StdRegions
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
std::map< int64_t, double > sum
A MemoryRegion represents a memory region.
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.
LibUtilities::MemoryRegion< TData > Create(const StdMatKey< TData > &stdMatKey)
LibUtilities::ShapeType m_shapeType
std::vector< LibUtilities::BasisKey > m_basisKeys
std::vector< unsigned int > m_nq
LibUtilities::PointsType m_nodalType
void PhysGalerkinProject3D(const BasisKey &fbasis0, const BasisKey &fbasis1, const BasisKey &fbasis2, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, const BasisKey &tbasis1, const BasisKey &tbasis2, Array< OneD, NekDouble > &to)
void PhysGalerkinProject1D(const BasisKey &fbasis0, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, Array< OneD, NekDouble > &to)
void Interp1D(const BasisKey &fbasis0, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, Array< OneD, NekDouble > &to)
this function interpolates a 1D function evaluated at the quadrature points of the basis fbasis0 to ...
Definition Interp.cpp:47
void Interp3D(const BasisKey &fbasis0, const BasisKey &fbasis1, const BasisKey &fbasis2, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, const BasisKey &tbasis1, const BasisKey &tbasis2, Array< OneD, NekDouble > &to)
this function interpolates a 3D function evaluated at the quadrature points of the 3D basis,...
Definition Interp.cpp:162
void Interp2D(const BasisKey &fbasis0, const BasisKey &fbasis1, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, const BasisKey &tbasis1, Array< OneD, NekDouble > &to)
this function interpolates a 2D function evaluated at the quadrature points of the 2D basis,...
Definition Interp.cpp:101
void PhysGalerkinProject2D(const BasisKey &fbasis0, const BasisKey &fbasis1, const Array< OneD, const NekDouble > &from, const BasisKey &tbasis0, const BasisKey &tbasis1, Array< OneD, NekDouble > &to)
std::shared_ptr< StdExpansion > StdExpansionSharedPtr
static VarFactorsMap NullVarFactorsMap
static ConstFactorMap NullConstFactorMap
static VarCoeffMap NullVarCoeffMap
void Zero(int n, T *x, const int incx)
Zero vector.
Definition Vmath.hpp:275
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition Vmath.hpp:828