Nektar++
Loading...
Searching...
No Matches
TestPhysTraceExtract.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: TestPhysTraceExtract.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
36
38
40#include <LocalRegions/TriExp.h>
41
42using namespace Nektar;
43using namespace Nektar::LibUtilities;
44using namespace Nektar::MultiRegions;
45
46template <typename TData>
48 : public TestOp<TData, FieldState::Phys, FieldState::Phys>
49{
50public:
52
53 /**
54 * @brief Build the session, expansion list and fields.
55 *
56 * @param useGLLTracePoints Extract onto the Gauss-Lobatto trace
57 * points rather than the element's own;
58 * see PhysTraceExtractOp::
59 * SetUseGLLTracePoints(). It sizes the
60 * storage, so it is fixed here rather
61 * than at the call to the operator.
62 */
63 void Configure(const bool useGLLTracePoints = false)
64 {
65 m_useGLLTracePoints = useGLLTracePoints;
66 this->SetSession();
67 this->SetExpList();
68 this->fixt_explist->SetDataWarehouse();
69 SetFixture(1);
70 }
71
72 void SetFixture(const unsigned int nhomo) override
73 {
74 auto nin = this->session->GetVariables().size();
75 auto nout = this->session->GetVariables().size();
76 auto inblockAttr = GetBlockAttributes<TData, FieldState::Phys>(
77 this->fixt_explist,
78 MultiRegions::UnitInterleaveWidths(this->fixt_explist));
79 auto outblockAttr = GetLocTraceBlockAttributes<TData, FieldState::Phys>(
81
82 auto f_in =
83 Field<TData, FieldState::Phys>("f_in", inblockAttr, nin, nhomo);
84 auto f_out =
85 Field<TData, FieldState::Phys>("f_out", outblockAttr, nout, nhomo);
86
87 auto f_expected = Field<TData, FieldState::Phys>(
88 "f_expected", outblockAttr, nout, nhomo);
89 this->fixt_in = new Field<TData, FieldState::Phys>(std::move(f_in));
90 this->fixt_out = new Field<TData, FieldState::Phys>(std::move(f_out));
91 this->fixt_expected =
92 new Field<TData, FieldState::Phys>(std::move(f_expected));
93 }
94
96 {
97 // Set initial conditions.
98 for (unsigned blk = 0; blk < this->fixt_in->GetBlocks().size(); ++blk)
99 {
100 auto &block = this->fixt_in->GetBlocks()[blk];
101 auto inptr =
102 block.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
103
104 for (unsigned n = 0; n < this->fixt_in->GetNumComponents() *
105 this->fixt_in->GetNumHomoModes();
106 ++n)
107 {
108 for (size_t el = 0, cnt = 0; el < block.GetNumElements(); ++el)
109 {
110 for (unsigned phys = 0; phys < block.GetNumData();
111 ++phys, ++cnt)
112 {
113 inptr[cnt] = phys + n;
114 }
115 }
116 inptr += block.CompSize();
117 }
118 }
119
120 // Compute expected solution.
122 }
123
124 void RunTestCase(bool nonCollocated = false)
125 {
127 this->fixt_explist, this->session->GetVariables());
128
130 {
131 op->SetUseGLLTracePoints(true);
132 }
133
134 if (nonCollocated)
135 {
136 op->SetIsCollocated(false);
137 }
138
139 op->Apply(*this->fixt_in, *this->fixt_out);
140 }
141
142 void RunTestCaseExtractTrace(bool nonCollocated = false)
143 {
145 this->fixt_explist, this->session->GetVariables());
146
148 {
149 op->SetUseGLLTracePoints(true);
150 }
151
152 if (nonCollocated)
153 {
154 op->SetIsCollocated(false);
155 }
156
157 // This test case will only run on problems of fixed p and same shape
158 auto exp = this->fixt_explist->GetExp(0);
159 switch (exp->DetShapeType())
160 {
163 {
164 op->ExtractTrace(2, *this->fixt_in, *this->fixt_out, 0);
165 auto pts = exp->GetTraceBasisKey(2).GetNumPoints();
166 op->ExtractTrace(1, *this->fixt_in, *this->fixt_out, pts);
167 pts += exp->GetTraceBasisKey(1).GetNumPoints();
168 op->ExtractTrace(0, *this->fixt_in, *this->fixt_out, pts);
169 }
170 break;
172 {
173 op->ExtractTrace(3, *this->fixt_in, *this->fixt_out, 0);
174 auto pts = exp->GetTraceBasisKey(3).GetNumPoints();
175 op->ExtractTrace(1, *this->fixt_in, *this->fixt_out, pts);
176 pts += exp->GetTraceBasisKey(1).GetNumPoints();
177 op->ExtractTrace(0, *this->fixt_in, *this->fixt_out, pts);
178 pts += exp->GetTraceBasisKey(0).GetNumPoints();
179 op->ExtractTrace(2, *this->fixt_in, *this->fixt_out, pts);
180 }
181 break;
184 {
185 op->ExtractTrace(3, *this->fixt_in, *this->fixt_out, 0);
186 auto pts = exp->GetTraceBasisKey(3, 0).GetNumPoints() *
187 exp->GetTraceBasisKey(3, 1).GetNumPoints();
188 op->ExtractTrace(2, *this->fixt_in, *this->fixt_out, pts);
189 pts += exp->GetTraceBasisKey(2, 0).GetNumPoints() *
190 exp->GetTraceBasisKey(2, 1).GetNumPoints();
191 op->ExtractTrace(1, *this->fixt_in, *this->fixt_out, pts);
192 pts += exp->GetTraceBasisKey(1, 0).GetNumPoints() *
193 exp->GetTraceBasisKey(1, 1).GetNumPoints();
194 op->ExtractTrace(0, *this->fixt_in, *this->fixt_out, pts);
195 }
196 break;
201 {
202 op->ExtractTrace(4, *this->fixt_in, *this->fixt_out, 0);
203 auto pts = exp->GetTraceBasisKey(4, 0).GetNumPoints() *
204 exp->GetTraceBasisKey(4, 1).GetNumPoints();
205 op->ExtractTrace(2, *this->fixt_in, *this->fixt_out, pts);
206 pts += exp->GetTraceBasisKey(2, 0).GetNumPoints() *
207 exp->GetTraceBasisKey(2, 1).GetNumPoints();
208 op->ExtractTrace(1, *this->fixt_in, *this->fixt_out, pts);
209 pts += exp->GetTraceBasisKey(1, 0).GetNumPoints() *
210 exp->GetTraceBasisKey(1, 1).GetNumPoints();
211 op->ExtractTrace(3, *this->fixt_in, *this->fixt_out, pts);
212 pts += exp->GetTraceBasisKey(3, 0).GetNumPoints() *
213 exp->GetTraceBasisKey(3, 1).GetNumPoints();
214 op->ExtractTrace(0, *this->fixt_in, *this->fixt_out, pts);
215 }
216 break;
218 {
219 op->ExtractTrace(4, *this->fixt_in, *this->fixt_out, 0);
220 auto pts = exp->GetTraceBasisKey(4, 0).GetNumPoints() *
221 exp->GetTraceBasisKey(4, 1).GetNumPoints();
222 op->ExtractTrace(2, *this->fixt_in, *this->fixt_out, pts);
223 pts += exp->GetTraceBasisKey(2, 0).GetNumPoints() *
224 exp->GetTraceBasisKey(2, 1).GetNumPoints();
225 op->ExtractTrace(1, *this->fixt_in, *this->fixt_out, pts);
226 pts += exp->GetTraceBasisKey(1, 0).GetNumPoints() *
227 exp->GetTraceBasisKey(1, 1).GetNumPoints();
228 op->ExtractTrace(3, *this->fixt_in, *this->fixt_out, pts);
229 pts += exp->GetTraceBasisKey(3, 0).GetNumPoints() *
230 exp->GetTraceBasisKey(3, 1).GetNumPoints();
231 op->ExtractTrace(0, *this->fixt_in, *this->fixt_out, pts);
232 pts += exp->GetTraceBasisKey(0, 0).GetNumPoints() *
233 exp->GetTraceBasisKey(0, 1).GetNumPoints();
234 op->ExtractTrace(5, *this->fixt_in, *this->fixt_out, pts);
235 }
236 break;
237 default:
238 NEKERROR(ErrorUtil::efatal, "Shape not set up ");
239 break;
240 }
241 }
242
243 /**
244 * @brief Build the trace expansion on the Gauss-Lobatto trace points.
245 *
246 * @details
247 * The counterpart of Expansion::GetLocTraceExp() for the variant the
248 * operator is being asked for, so that the legacy GetTracePhysVals()
249 * below interpolates onto the same points the operator writes. Only a
250 * three-dimensional element has anything to choose: a triangle already
251 * hands its collapsed edges a Gauss-Lobatto basis with the extra point.
252 *
253 * @param expPtr Element whose trace is wanted.
254 * @param traceid Trace of that element.
255 *
256 * @return The trace expansion on the Gauss-Lobatto points.
257 */
259 const LocalRegions::ExpansionSharedPtr &expPtr, const unsigned traceid)
260 {
261 if (expPtr->GetShapeDimension() < 3)
262 {
263 return expPtr->GetLocTraceExp(traceid);
264 }
265
266 auto geom = expPtr->GetGeom();
267 auto faceGeom = geom->GetFace(traceid);
268 const auto Ba = expPtr->GetTraceBasisKey(traceid, 0, true);
269 const auto Bb = expPtr->GetTraceBasisKey(traceid, 1, true);
270
271 if (faceGeom->GetNumVerts() == 3)
272 {
274 Ba, Bb, geom->GetFace(traceid));
275 }
276
278 Ba, Bb, geom->GetFace(traceid));
279 }
280
282 {
283 const unsigned numComp = this->fixt_in->GetNumComponents();
284
285 auto inblockAttr = GetBlockAttributes<TData, FieldState::Phys>(
286 this->fixt_explist,
287 MultiRegions::UnitInterleaveWidths(this->fixt_explist));
288
289 size_t eid = 0;
290 for (unsigned blk = 0; blk < inblockAttr.size(); ++blk)
291 {
292 auto numElmts = inblockAttr[blk].GetNumElements();
293 auto numElmtsPad = inblockAttr[blk].GetNumElementsWithPadding();
294 auto numData = inblockAttr[blk].GetNumData();
295
296 auto inptr =
297 this->fixt_in->GetBlocks()[blk]
298 .template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
299
300 auto outptr =
301 this->fixt_expected->GetBlocks()[blk]
302 .template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
303
304 Array<OneD, TData> outphys(
305 this->fixt_expected->GetBlocks()[blk].GetNumData() / 2);
306
307 for (unsigned nc = 0; nc < numComp; ++nc)
308 {
309 unsigned physoffset = 0;
310 unsigned ntrace = 0;
311 for (unsigned e = 0; e < numElmts; ++e)
312 {
313 auto expPtr = this->fixt_explist->GetExp(eid + e);
314 Array<OneD, double> indata(numData, inptr + physoffset);
315
316 auto Shape = expPtr->DetShapeType();
317
318 // set up local trace expansions
319 auto nface = expPtr->GetNtraces();
320 std::vector<LocalRegions::ExpansionSharedPtr> TraceExp;
321 TraceExp.resize(nface);
322 if (Shape != LibUtilities::Seg) // ignore Segs since
323 // method does not exist
324 {
325 for (unsigned t = 0; t < nface; ++t)
326 {
327 TraceExp[t] = m_useGLLTracePoints
328 ? GLLTraceExp(expPtr, t)
329 : expPtr->GetLocTraceExp(t);
330 }
331 }
332 ntrace = 0;
333
334 switch (Shape)
335 {
337 {
338 expPtr->GetTracePhysVals(0, expPtr, indata, outphys,
340 outptr[0] = outphys[0];
341 expPtr->GetTracePhysVals(1, expPtr, indata, outphys,
343 outptr[1] = outphys[0];
344 outptr += 2;
345 ntrace = 2;
346 }
347 break;
349 {
350 // edge 3
351 auto npts = TraceExp[3]->GetTotPoints();
352 expPtr->GetTracePhysVals(3, TraceExp[3], indata,
353 outphys,
355 std::copy(outphys.data(), outphys.data() + npts,
356 outptr);
357
358 // edge 1
359 expPtr->GetTracePhysVals(1, TraceExp[1], indata,
360 outphys,
362 std::copy(outphys.data(), outphys.data() + npts,
363 outptr + npts);
364
365 outptr += 2 * npts;
366 ntrace = 2 * npts;
367
368 // edge 0
369 npts = TraceExp[0]->GetTotPoints();
370 expPtr->GetTracePhysVals(0, TraceExp[0], indata,
371 outphys,
373 std::copy(outphys.data(), outphys.data() + npts,
374 outptr);
375 outptr += npts;
376 ntrace += npts;
377
378 // edge 2
379 expPtr->GetTracePhysVals(2, TraceExp[2], indata,
380 outphys,
382 std::copy(outphys.data(), outphys.data() + npts,
383 outptr);
384 outptr += npts;
385 ntrace += npts;
386 }
387 break;
390 {
391 // edge 2
392 auto npts = TraceExp[2]->GetTotPoints();
393 expPtr->GetTracePhysVals(2, TraceExp[2], indata,
394 outphys,
396 std::copy(outphys.data(), outphys.data() + npts,
397 outptr);
398
399 // edge 1
400 expPtr->GetTracePhysVals(1, TraceExp[1], indata,
401 outphys,
403 std::copy(outphys.data(), outphys.data() + npts,
404 outptr + npts);
405
406 outptr += 2 * npts;
407 ntrace = 2 * npts;
408
409 // edge 0
410 npts = TraceExp[0]->GetTotPoints();
411 expPtr->GetTracePhysVals(0, TraceExp[0], indata,
412 outphys,
414 std::copy(outphys.data(), outphys.data() + npts,
415 outptr);
416 outptr += npts;
417 ntrace += npts;
418 }
419 break;
425 {
426 auto npts = TraceExp[2]->GetTotPoints();
427 // face 4
428 expPtr->GetTracePhysVals(
429 4, TraceExp[4], indata, outphys,
431 std::copy(outphys.data(), outphys.data() + npts,
432 outptr);
433 outptr += npts;
434 ntrace += npts;
435
436 // face 2
437 expPtr->GetTracePhysVals(
438 2, TraceExp[2], indata, outphys,
440 std::copy(outphys.data(), outphys.data() + npts,
441 outptr);
442 outptr += npts;
443 ntrace += npts;
444
445 // face 1
446 npts = TraceExp[1]->GetTotPoints();
447 expPtr->GetTracePhysVals(
448 1, TraceExp[1], indata, outphys,
450 std::copy(outphys.data(), outphys.data() + npts,
451 outptr);
452 outptr += npts;
453 ntrace += npts;
454
455 // face 3
456 expPtr->GetTracePhysVals(
457 3, TraceExp[3], indata, outphys,
459 std::copy(outphys.data(), outphys.data() + npts,
460 outptr);
461 outptr += npts;
462 ntrace += npts;
463
464 // face 0
465 npts = TraceExp[0]->GetTotPoints();
466 expPtr->GetTracePhysVals(
467 0, TraceExp[0], indata, outphys,
469 std::copy(outphys.data(), outphys.data() + npts,
470 outptr);
471 outptr += npts;
472 ntrace += npts;
473
474 if (Shape == LibUtilities::Hex)
475 {
476 // face 5
477 expPtr->GetTracePhysVals(
478 5, TraceExp[5], indata, outphys,
480 std::copy(outphys.data(), outphys.data() + npts,
481 outptr);
482 outptr += npts;
483 ntrace += npts;
484 }
485 }
486 break;
489 {
490 auto npts = TraceExp[2]->GetTotPoints();
491 // face 3
492 expPtr->GetTracePhysVals(
493 3, TraceExp[3], indata, outphys,
495 std::copy(outphys.data(), outphys.data() + npts,
496 outptr);
497 outptr += npts;
498 ntrace += npts;
499
500 // face 2
501 expPtr->GetTracePhysVals(
502 2, TraceExp[2], indata, outphys,
504 std::copy(outphys.data(), outphys.data() + npts,
505 outptr);
506 outptr += npts;
507 ntrace += npts;
508
509 // face 1
510 npts = TraceExp[1]->GetTotPoints();
511 expPtr->GetTracePhysVals(
512 1, TraceExp[1], indata, outphys,
514 std::copy(outphys.data(), outphys.data() + npts,
515 outptr);
516 outptr += npts;
517 ntrace += npts;
518
519 // face 0
520 npts = TraceExp[0]->GetTotPoints();
521 expPtr->GetTracePhysVals(
522 0, TraceExp[0], indata, outphys,
524 std::copy(outphys.data(), outphys.data() + npts,
525 outptr);
526 outptr += npts;
527 ntrace += npts;
528 }
529 break;
530 default:
532 "Need to define shape details");
533 break;
534 }
535 physoffset += numData;
536 }
537 inptr += numData * numElmtsPad;
538 outptr +=
539 ntrace * (numElmtsPad - numElmts); // offset for padded case
540 }
541 eid += numElmts;
542 }
543 }
544
545protected:
546 /// Whether the fields are sized for, and the operator asked for, the
547 /// Gauss-Lobatto trace points rather than the element's own; set by
548 /// Configure().
550
551private:
552};
553
554// clang-format off
555#if defined(NEKTAR_ENABLE_SINGLE_PRECISION)
556#define TESTFLOAT(type, filename) \
557 class type##float : public TestPhysTraceExtract<float> \
558 { \
559 public: \
560 type##float() \
561 { \
562 meshName = filename; \
563 } \
564 };
565#else
566#define TESTFLOAT(type, filename)
567#endif
568#if defined(NEKTAR_ENABLE_DOUBLE_PRECISION)
569#define TESTDOUBLE(type, filename) \
570 class type : public TestPhysTraceExtract<double> \
571 { \
572 public: \
573 type() \
574 { \
575 meshName = filename; \
576 } \
577 };
578#else
579#define TESTDOUBLE(type, filename)
580#endif
581#define TEST(type, filename) \
582 TESTFLOAT(type, filename) \
583 TESTDOUBLE(type, filename)
584// clang-format on
585
586TEST(Seg, "run/segment.xml")
587
588TEST(SegGaussPts, "run/segment_gausspts.xml")
589
590TEST(Quad, "run/square.xml")
591
592TEST(QuadVarP, "run/square_varp.xml")
593
594TEST(QuadGaussPts, "run/square_gausspts.xml")
595
596TEST(Tri, "run/tri.xml")
597
598TEST(TriVarP, "run/tri_varp.xml")
599
600TEST(TriNodal, "run/tri_nodal.xml")
601
602TEST(SquareAllElements, "run/square_all_elements.xml")
603
604TEST(Hex, "run/hex.xml")
605
606TEST(HexFixedP, "run/hex_fixedp.xml")
607
608TEST(HexVarP, "run/hex_varp.xml")
609
610TEST(Prism, "run/prism.xml")
611
612TEST(PrismFixedP, "run/prism_fixedp.xml")
613
614TEST(PrismVarP, "run/prism_varp.xml")
615
616TEST(Pyr, "run/pyr.xml")
617
618TEST(PyrVarP, "run/pyr_varp.xml")
619
620TEST(PyrNodal, "run/pyr_nodal.xml")
621
622TEST(Tet, "run/tet.xml")
623
624TEST(TetVarP, "run/tet_varp.xml")
625
626TEST(TetNodal, "run/tet_nodal.xml")
627
628TEST(CubePrismHex, "run/cube_prismhex.xml")
629
630TEST(CubeAllElements, "run/cube_all_elements.xml")
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Public interface of the PhysTraceExtract element operator, which interpolates a volume physical-space...
#define TEST(type, filename)
SpatialDomains::Geometry * el
A Field represents expansion data to be operated on.
std::vector< BlockAccessor< TData, TState > > & GetBlocks()
Get BlockAccessors for the field.
unsigned int GetNumHomoModes() const
Gets the number of homogeneous modes.
unsigned int GetNumComponents() const
Gets the number of components for a vector field.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
static std::shared_ptr< PhysTraceExtractOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Create a trace extraction operator through the operator and block-operator factories.
std::shared_ptr< MultiRegions::ExpList > fixt_explist
Definition TestOp.hpp:439
LibUtilities::SessionReaderSharedPtr session
Definition TestOp.hpp:440
void RunTestCase(bool nonCollocated=false)
void Configure(const bool useGLLTracePoints=false)
Build the session, expansion list and fields.
bool m_useGLLTracePoints
Whether the fields are sized for, and the operator asked for, the Gauss-Lobatto trace points rather t...
LocalRegions::ExpansionSharedPtr GLLTraceExp(const LocalRegions::ExpansionSharedPtr &expPtr, const unsigned traceid)
Build the trace expansion on the Gauss-Lobatto trace points.
TestPhysTraceExtract()=default
void SetFixture(const unsigned int nhomo) override
void RunTestCaseExtractTrace(bool nonCollocated=false)
std::shared_ptr< Expansion > ExpansionSharedPtr
Definition Expansion.h:66