Nektar++
Loading...
Searching...
No Matches
TestHOPressureBndCond.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: TestHOPressureBndCond.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 in
21// all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24// 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: Unit tests of the higher-order pressure boundary condition.
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#define BOOST_TEST_MODULE TestHOPressureBndCond
36
37// Boost.Test pulls in windows.h, whose min/max macros break tinysimd.
38#define NOMINMAX
39#include <boost/test/included/unit_test.hpp>
40
41#include <algorithm>
42#include <array>
43#include <cmath>
44#include <cstdlib>
45#include <cstring>
46#include <string>
47#include <utility>
48#include <vector>
49
53
58
59using namespace Nektar;
60
62{
64 {
65#ifdef NEKTAR_USE_MPI
66 int argc = boost::unit_test::framework::master_test_suite().argc;
67 char **argv = boost::unit_test::framework::master_test_suite().argv;
68 MPI_Init(&argc, &argv);
69#endif
70 }
71
73 {
74#ifdef NEKTAR_USE_MPI
75 MPI_Finalize();
76#endif
77 }
78};
79
81
82namespace
83{
85{
86 const auto &suite = boost::unit_test::framework::master_test_suite();
87 BOOST_REQUIRE_MESSAGE(suite.argc >= 4,
88 "Usage: TestHOPressureBndCond -- <ExecSpace> "
89 "<Implementation> <Session.xml> [<Session.xml>...]");
90
91 const std::string execStr(suite.argv[1]);
92 const std::string implStr(suite.argv[2]);
93 const int nSessionFiles = suite.argc - 3;
94
95 int argc = nSessionFiles + 3;
96 char **argv = new char *[argc + 1];
97 argv[0] = strdup("TestHOPressureBndCond");
98 for (int i = 0; i < nSessionFiles; ++i)
99 {
100 argv[i + 1] = strdup(suite.argv[i + 3]);
101 }
102 argv[nSessionFiles + 1] = strdup(("--opExecSpace=" + execStr).c_str());
103 argv[nSessionFiles + 2] = strdup(("--opImpl=" + implStr).c_str());
104 argv[argc] = nullptr;
105
107 session->InitSession();
108
109 for (int i = 0; i < argc; ++i)
110 {
111 free(argv[i]);
112 }
113 delete[] argv;
114
115 return session;
116}
117
118std::vector<std::string> GetVelocityComponents(const unsigned int nDim)
119{
120 const std::vector<std::string> allComponents = {"u", "v", "w"};
121 BOOST_REQUIRE(nDim >= 2 && nDim <= allComponents.size());
122 return {allComponents.begin(), allComponents.begin() + nDim};
123}
124
125// Whether a pressure region takes the higher-order pressure flux: a Neumann
126// condition with USERDEFINEDTYPE="H".
127bool IsTaggedHOPressure(const SpatialDomains::BoundaryConditionShPtr &condition)
128{
129 return condition->GetBoundaryConditionType() == SpatialDomains::eNeumann &&
130 StringUtils::IEquals(condition->GetUserDefined(), "H");
131}
132
133// The expected pressure forcing of the flux gradient(x, y, z) . n on the
134// Neumann pressure regions. With requireHOPTag, only the regions with
135// USERDEFINEDTYPE="H" contribute, for sessions mixing them with other
136// Neumann regions; otherwise every Neumann region does.
137template <typename Gradient>
138std::vector<double> BuildExpectedBoundaryContribution(
139 const MultiRegions::ExpListSharedPtr &pressureExpList,
140 const unsigned int nDim, Gradient gradient,
141 const bool requireHOPTag = false)
142{
143 Array<OneD, double> expectedCoeffs(pressureExpList->GetNcoeffs(), 0.0);
144 const auto &bndExpansions = pressureExpList->GetBndCondExpansions();
145 const auto &bndConditions = pressureExpList->GetBndConditions();
146 auto pressureContField =
147 std::dynamic_pointer_cast<MultiRegions::ContField>(pressureExpList);
148 BOOST_REQUIRE(pressureContField);
149 const auto &localToGlobal = pressureContField->GetLocalToGlobalMap();
150 const auto &coeffMap = localToGlobal->GetBndCondCoeffsToLocalCoeffsMap();
151 const auto &coeffSign = localToGlobal->GetBndCondCoeffsToLocalCoeffsSign();
152 const bool signChange = localToGlobal->GetSignChange();
153
154 unsigned int bndCoeffOffset = 0;
155 for (unsigned int n = 0; n < bndExpansions.size(); ++n)
156 {
157 auto bndExp = bndExpansions[n];
158 const bool selected =
159 requireHOPTag ? IsTaggedHOPressure(bndConditions[n])
160 : bndConditions[n]->GetBoundaryConditionType() ==
161 SpatialDomains::eNeumann;
162 if (selected)
163 {
164 const auto npts = bndExp->GetTotPoints();
165 Array<OneD, double> x(npts), y(npts), z(npts, 0.0);
166 bndExp->GetCoords(x, y, z);
167 Array<OneD, Array<OneD, double>> vectorFlux(nDim);
168 for (unsigned int d = 0; d < nDim; ++d)
169 {
170 vectorFlux[d] = Array<OneD, double>(npts, 0.0);
171 }
172 for (unsigned int p = 0; p < npts; ++p)
173 {
174 const auto value = gradient(x[p], y[p], z[p]);
175 for (unsigned int d = 0; d < nDim; ++d)
176 {
177 vectorFlux[d][p] = value[d];
178 }
179 }
180
181 Array<OneD, double> bndCoeffs(bndExp->GetNcoeffs(), 0.0);
182 bndExp->NormVectorIProductWRTBase(vectorFlux, bndCoeffs);
183 for (unsigned int c = 0; c < bndExp->GetNcoeffs(); ++c)
184 {
185 const auto bndCoeff = bndCoeffOffset + c;
186 const auto localCoeff = coeffMap[bndCoeff];
187 expectedCoeffs[localCoeff] +=
188 (signChange ? coeffSign[bndCoeff] : 1.0) * bndCoeffs[c];
189 }
190 }
191 bndCoeffOffset += bndExp->GetNcoeffs();
192 }
193
194 const std::vector<std::string> pressureComponents = {"p"};
196 "expected Poisson RHS",
198 pressureExpList,
199 MultiRegions::UnitInterleaveWidths(pressureExpList)),
200 pressureComponents, 1);
201 expected.Initialize<NektarSpaces::HostSpace>(0.0);
202 for (unsigned int blk = 0; blk < expected.GetBlocks().size(); ++blk)
203 {
204 auto &expectedBlock = expected.GetBlocks()[blk];
205 auto expectedPtr =
206 expectedBlock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
207 auto collection = GetCollection(pressureExpList, blk);
208 const auto &expansions = collection.GetExpVector();
209 for (unsigned int e = 0; e < expansions.size(); ++e)
210 {
211 const auto offset =
212 pressureExpList->GetCoeff_Offset(expansions[e]->GetElmtId());
213 std::copy(expectedCoeffs.begin() + offset,
214 expectedCoeffs.begin() + offset +
215 expectedBlock.GetNumData(),
216 expectedPtr + e * expectedBlock.GetNumData());
217 }
218 }
219 return expected.ToVector<double>();
220}
221
222// The flux on a region whose velocity is Dirichlet in u and Neumann in v,
223// from UpdateWithAcceleration(), or from UpdateWeak() with isWeak.
224void CheckNeumannVelocityBoundaryFlux(const bool isWeak)
225{
226 auto session = CreateSession();
227 if (!session->DefinesParameter("HOPNeumannVelocityTest"))
228 {
229 return;
230 }
232 auto velocityExpList =
234 session, graph, "u", true, false, Collections::eNoCollection);
235 auto pressureExpList =
237 session, graph, "p", true, false, Collections::eNoCollection);
238 velocityExpList->SetDataWarehouse();
239 pressureExpList->SetDataWarehouse();
240
241 const unsigned int nDim = graph->GetMeshDimension();
242 const auto velocityComponents = GetVelocityComponents(nDim);
243 const std::vector<std::string> pressureComponents = {"p"};
244 const auto velocityPhysBlocks =
246 velocityExpList,
247 MultiRegions::UnitInterleaveWidths(velocityExpList));
249 "Poisson RHS",
251 pressureExpList,
252 MultiRegions::UnitInterleaveWidths(pressureExpList)),
253 pressureComponents, 1);
255 "explicit contribution", velocityPhysBlocks, velocityComponents, 1);
257 "velocity", velocityPhysBlocks, velocityComponents, 1);
259 "implicit predictor", velocityPhysBlocks, velocityComponents, 1);
260
261 poissonRhs.Initialize<NektarSpaces::HostSpace>(0.0);
262 rhs.Initialize<NektarSpaces::HostSpace>(0.0);
263 velocity.Initialize<NektarSpaces::HostSpace>(0.0);
264 predictor.Initialize<NektarSpaces::HostSpace>(0.0);
265 for (unsigned int blk = 0; blk < predictor.GetBlocks().size(); ++blk)
266 {
267 auto &rhsBlock = rhs.GetBlocks()[blk];
268 auto &predictorBlock = predictor.GetBlocks()[blk];
269 auto rhsPtr =
270 rhsBlock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
271 auto predictorPtr =
272 predictorBlock
273 .template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
274 for (unsigned int d = 0; d < nDim; ++d)
275 {
276 std::fill(rhsPtr + d * rhsBlock.CompSize(),
277 rhsPtr + (d + 1) * rhsBlock.CompSize(), 0.03 * (d + 1));
278 std::fill(predictorPtr + d * predictorBlock.CompSize(),
279 predictorPtr + (d + 1) * predictorBlock.CompSize(),
280 0.1 * (d + 1));
281 }
282 }
283
284 static constexpr double time = 0.4;
285 static constexpr double scale = 2.5;
286 auto op = HOPressureBndCondOp<double>::Create(pressureExpList,
287 pressureComponents);
288 op->SetVelocityContext(velocityExpList, velocityComponents);
289 BOOST_TEST(op->HasNonDirichletVelocity());
290 op->SetKinvis(0.0);
291 op->SetTime(time);
292 op->SetScale(scale);
293 // u: scale * (predictor - u_D), with u_D = time; v: scale * rhs. The
294 // weak form leaves out scale * predictor: u: -scale * u_D; v:
295 // -scale * (predictor - rhs).
296 std::array<double, 3> expectedFlux = {scale * (0.1 - time), scale * 0.06,
297 0.0};
298 if (isWeak)
299 {
300 op->UpdateWeak(rhs, velocity, predictor);
301 expectedFlux = {-scale * time, -scale * (0.2 - 0.06), 0.0};
302 }
303 else
304 {
305 op->UpdateWithAcceleration(rhs, velocity, predictor);
306 }
307 op->Apply(poissonRhs);
308
309 const auto actualValues = poissonRhs.ToVector<double>();
310 const auto expectedValues = BuildExpectedBoundaryContribution(
311 pressureExpList, nDim,
312 [&expectedFlux](const double, const double, const double) {
313 return expectedFlux;
314 });
315 BOOST_REQUIRE_EQUAL(actualValues.size(), expectedValues.size());
316 double maxDifference = 0.0;
317 for (std::size_t i = 0; i < actualValues.size(); ++i)
318 {
319 maxDifference = std::max(maxDifference,
320 std::abs(actualValues[i] - expectedValues[i]));
321 }
322 BOOST_TEST(maxDifference < 2.5e-11);
323
325 if (isWeak)
326 {
327 BOOST_CHECK_THROW(op->UpdateWeak(noRhs, velocity, predictor),
329 }
330 else
331 {
332 BOOST_CHECK_THROW(
333 op->UpdateWithAcceleration(noRhs, velocity, predictor),
335 }
336}
337
338} // namespace
339
340BOOST_AUTO_TEST_SUITE(TestHOPressureBndCond)
341
342BOOST_AUTO_TEST_CASE(factory_create_and_empty_apply_preserves_rhs)
343{
344 auto session = CreateSession();
346 auto pressureExpList =
348 session, graph, "p", true, false, Collections::eNoCollection);
349 pressureExpList->SetDataWarehouse();
350
351 const std::vector<std::string> pressureComponents = {"p"};
353 "rhs",
355 pressureExpList,
356 MultiRegions::UnitInterleaveWidths(pressureExpList)),
357 pressureComponents, 1);
359
360 auto before = rhs.ToVector<double>();
361
362 auto op = HOPressureBndCondOp<double>::Create(pressureExpList,
363 pressureComponents);
364 op->Apply(rhs);
365
366 auto after = rhs.ToVector<double>();
367 BOOST_REQUIRE_EQUAL(before.size(), after.size());
368 for (std::size_t i = 0; i < before.size(); ++i)
369 {
370 BOOST_TEST(after[i] == before[i]);
371 }
372}
373
374BOOST_AUTO_TEST_CASE(update_then_apply_zero_contribution_preserves_rhs)
375{
376 auto session = CreateSession();
378 auto velocityExpList =
380 session, graph, "u", true, false, Collections::eNoCollection);
381 auto pressureExpList =
383 session, graph, "p", true, false, Collections::eNoCollection);
384 velocityExpList->SetDataWarehouse();
385 pressureExpList->SetDataWarehouse();
386
387 const auto velocityComponents =
388 GetVelocityComponents(graph->GetMeshDimension());
389 const std::vector<std::string> pressureComponents = {"p"};
390
392 "rhs",
394 pressureExpList,
395 MultiRegions::UnitInterleaveWidths(pressureExpList)),
396 pressureComponents, 1);
398 "boundary rhs",
400 velocityExpList,
401 MultiRegions::UnitInterleaveWidths(velocityExpList)),
402 velocityComponents, 1);
404 "velocity",
406 velocityExpList,
407 MultiRegions::UnitInterleaveWidths(velocityExpList)),
408 velocityComponents, 1);
409
411 boundaryRhs.Initialize<NektarSpaces::HostSpace>(0.0);
412 velocity.Initialize<NektarSpaces::HostSpace>(0.0);
413
414 auto before = rhs.ToVector<double>();
415
416 auto op = HOPressureBndCondOp<double>::Create(pressureExpList,
417 pressureComponents);
418 op->SetVelocityContext(velocityExpList, velocityComponents);
419 op->SetKinvis(1.0);
420 op->Update(boundaryRhs, velocity);
421 op->Apply(rhs);
422
423 auto after = rhs.ToVector<double>();
424 BOOST_REQUIRE_EQUAL(before.size(), after.size());
425 for (std::size_t i = 0; i < before.size(); ++i)
426 {
427 BOOST_TEST(after[i] == before[i]);
428 }
429}
430
431BOOST_AUTO_TEST_CASE(update_then_apply_manufactured_boundary_flux)
432{
433 auto session = CreateSession();
434 if (session->DefinesParameter("KovaLam"))
435 {
436 return;
437 }
439 auto velocityExpList =
441 session, graph, "u", true, false, Collections::eNoCollection);
442 auto pressureExpList =
444 session, graph, "p", true, false, Collections::eNoCollection);
445 velocityExpList->SetDataWarehouse();
446 pressureExpList->SetDataWarehouse();
447
448 const unsigned int nDim = graph->GetMeshDimension();
449 const auto velocityComponents = GetVelocityComponents(nDim);
450 const std::vector<std::string> pressureComponents = {"p"};
451 const auto velocityPhysBlocks =
453 velocityExpList,
454 MultiRegions::UnitInterleaveWidths(velocityExpList));
455
457 "Poisson RHS",
459 pressureExpList,
460 MultiRegions::UnitInterleaveWidths(pressureExpList)),
461 pressureComponents, 1);
463 "HOPressure boundary RHS", velocityPhysBlocks, velocityComponents, 1);
465 "manufactured velocity", velocityPhysBlocks, velocityComponents, 1);
466
467 velocity.Initialize<NektarSpaces::HostSpace>(0.0);
468 boundaryRhs.Initialize<NektarSpaces::HostSpace>(0.0);
469 for (unsigned int blk = 0; blk < velocity.GetBlocks().size(); ++blk)
470 {
471 auto &velocityBlock = velocity.GetBlocks()[blk];
472 auto &rhsBlock = boundaryRhs.GetBlocks()[blk];
473 auto velocityPtr =
474 velocityBlock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
475 auto rhsPtr =
476 rhsBlock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
477 auto collection = GetCollection(velocityExpList, blk);
478 const auto &expansions = collection.GetExpVector();
479
480 for (unsigned int e = 0; e < expansions.size(); ++e)
481 {
482 Array<OneD, double> x(velocityBlock.GetNumData());
483 Array<OneD, double> y(velocityBlock.GetNumData());
484 Array<OneD, double> z(velocityBlock.GetNumData(), 0.0);
485 expansions[e]->GetCoords(x, y, z);
486 for (unsigned int p = 0; p < velocityBlock.GetNumData(); ++p)
487 {
488 const auto id = e * velocityBlock.GetNumData() + p;
489 const double x2 = x[p] * x[p];
490 const double y2 = y[p] * y[p];
491 if (nDim == 2)
492 {
493 // This field is divergence-free and has a non-constant
494 // CurlCurl. The resulting flux is grad(p), where
495 // p = x^3 + x*y^2 + 2*x^2*y.
496 velocityPtr[id] = 2.0 * x[p] * x2 * y[p];
497 velocityPtr[velocityBlock.CompSize() + id] = -3.0 * x2 * y2;
498 rhsPtr[id] = 3.0 * x2 + y2 + x[p] * y[p];
499 rhsPtr[rhsBlock.CompSize() + id] =
500 3.5 * x2 + 2.0 * x[p] * y[p] + 1.5 * y2;
501 }
502 else
503 {
504 // u=(y^2,z^2,x^2) is divergence-free and CurlCurl(u) is
505 // (-2,-2,-2). For nu=1/4 this RHS produces grad(p), where
506 // p=x^2+2*y^2+3*z^2+x*y+y*z+z*x.
507 const double z2 = z[p] * z[p];
508 velocityPtr[id] = y2;
509 velocityPtr[velocityBlock.CompSize() + id] = z2;
510 velocityPtr[2 * velocityBlock.CompSize() + id] = x2;
511 rhsPtr[id] = 2.0 * x[p] + y[p] + z[p] - 0.5;
512 rhsPtr[rhsBlock.CompSize() + id] =
513 x[p] + 4.0 * y[p] + z[p] - 0.5;
514 rhsPtr[2 * rhsBlock.CompSize() + id] =
515 x[p] + y[p] + 6.0 * z[p] - 0.5;
516 }
517 }
518 }
519 }
520
521 auto op = HOPressureBndCondOp<double>::Create(pressureExpList,
522 pressureComponents);
523 op->SetVelocityContext(velocityExpList, velocityComponents);
524 static constexpr double contributionScale = 2.5;
525 op->SetKinvis(0.25);
526 op->SetScale(contributionScale);
527
528 const auto expectedValues = BuildExpectedBoundaryContribution(
529 pressureExpList, nDim,
530 [nDim](const double x, const double y, const double z) {
531 if (nDim == 2)
532 {
533 return std::array<double, 3>{
534 contributionScale * (3.0 * x * x + y * y + 4.0 * x * y),
535 contributionScale * (2.0 * x * y + 2.0 * x * x), 0.0};
536 }
537 return std::array<double, 3>{contributionScale * (2.0 * x + y + z),
538 contributionScale * (x + 4.0 * y + z),
539 contributionScale * (x + y + 6.0 * z)};
540 });
541 const auto maxExpected =
542 *std::max_element(expectedValues.begin(), expectedValues.end(),
543 [](const double lhs, const double rhs) {
544 return std::abs(lhs) < std::abs(rhs);
545 });
546 BOOST_TEST(std::abs(maxExpected) > 0.1);
547
548 // The velocity and the right-hand side at interleave width 1, at the
549 // interleave width of the execution space, and one at each. The
550 // operator gathers them, each at its own width, into fields at the
551 // width of the velocity, whose width changes from one update to the
552 // next.
553 const auto execSpace =
555 const unsigned int interleaveWidth =
556 NektarSpaces::GetVectorWidth<double>(execSpace);
557 const std::vector<std::pair<unsigned int, unsigned int>> widths = {
558 {1, 1},
559 {interleaveWidth, interleaveWidth},
560 {interleaveWidth, 1},
561 {1, interleaveWidth},
562 {1, 1}};
563 for (const auto &[velocityWidth, rhsWidth] : widths)
564 {
565 velocity.ReshapeStorage(velocityWidth, execSpace);
566 boundaryRhs.ReshapeStorage(rhsWidth, execSpace);
567 poissonRhs.Initialize<NektarSpaces::HostSpace>(0.0);
568 op->Update(boundaryRhs, velocity);
569 op->Apply(poissonRhs);
570
571 const auto actualValues = poissonRhs.ToVector<double>();
572 BOOST_REQUIRE_EQUAL(actualValues.size(), expectedValues.size());
573 for (std::size_t i = 0; i < actualValues.size(); ++i)
574 {
575 BOOST_CHECK_MESSAGE(
576 std::abs(actualValues[i] - expectedValues[i]) < 2.5e-10,
577 "velocity at width " << velocityWidth << ", rhs at width "
578 << rhsWidth);
579 }
580 }
581}
582
583BOOST_AUTO_TEST_CASE(update_then_apply_acceleration_boundary_flux)
584{
585 auto session = CreateSession();
586 if (session->DefinesParameter("KovaLam"))
587 {
588 return;
589 }
591 auto velocityExpList =
593 session, graph, "u", true, false, Collections::eNoCollection);
594 auto pressureExpList =
596 session, graph, "p", true, false, Collections::eNoCollection);
597 velocityExpList->SetDataWarehouse();
598 pressureExpList->SetDataWarehouse();
599
600 const unsigned int nDim = graph->GetMeshDimension();
601 const auto velocityComponents = GetVelocityComponents(nDim);
602 const std::vector<std::string> pressureComponents = {"p"};
603 const auto velocityPhysBlocks =
605 velocityExpList,
606 MultiRegions::UnitInterleaveWidths(velocityExpList));
608 "Poisson RHS",
610 pressureExpList,
611 MultiRegions::UnitInterleaveWidths(pressureExpList)),
612 pressureComponents, 1);
614 "velocity", velocityPhysBlocks, velocityComponents, 1);
616 "implicit predictor", velocityPhysBlocks, velocityComponents, 1);
617
618 poissonRhs.Initialize<NektarSpaces::HostSpace>(0.0);
619 velocity.Initialize<NektarSpaces::HostSpace>(0.0);
620 predictor.Initialize<NektarSpaces::HostSpace>(0.0);
621 for (unsigned int blk = 0; blk < predictor.GetBlocks().size(); ++blk)
622 {
623 auto &predictorBlock = predictor.GetBlocks()[blk];
624 auto predictorPtr =
625 predictorBlock
626 .template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
627 for (unsigned int d = 0; d < nDim; ++d)
628 {
629 std::fill(predictorPtr + d * predictorBlock.CompSize(),
630 predictorPtr + (d + 1) * predictorBlock.CompSize(),
631 0.1 * (d + 1));
632 }
633 }
634
635 static constexpr double time = 0.4;
636 static constexpr double scale = 2.5;
637 auto op = HOPressureBndCondOp<double>::Create(pressureExpList,
638 pressureComponents);
639 op->SetVelocityContext(velocityExpList, velocityComponents);
640 op->SetKinvis(0.0);
641 op->SetTime(time);
642 op->SetScale(scale);
643 // Every velocity component is Dirichlet, so rhs is not read.
645 op->UpdateWithAcceleration(rhs, velocity, predictor);
646 op->Apply(poissonRhs);
647
648 // With the acceleration added, the vector flux is
649 // scale * (predictor - u_D) before projection onto the boundary normal.
650 const auto actualValues = poissonRhs.ToVector<double>();
651 const auto expectedValues = BuildExpectedBoundaryContribution(
652 pressureExpList, nDim, [](const double, const double, const double) {
653 std::array<double, 3> value = {0.0, 0.0, 0.0};
654 for (unsigned int d = 0; d < value.size(); ++d)
655 {
656 value[d] = scale * (d + 1) * (0.1 - time);
657 }
658 return value;
659 });
660 BOOST_REQUIRE_EQUAL(actualValues.size(), expectedValues.size());
661 double maxDifference = 0.0;
662 for (std::size_t i = 0; i < actualValues.size(); ++i)
663 {
664 maxDifference = std::max(maxDifference,
665 std::abs(actualValues[i] - expectedValues[i]));
666 }
667 BOOST_TEST(maxDifference < 2.5e-11);
668}
669
670// The forcing added to a field at the interleave width of the execution space
671// matches that added to the same field at interleave width 1, and the field
672// keeps its width. Each field takes the forcing twice, the widths alternating.
673BOOST_AUTO_TEST_CASE(update_then_apply_interleaved_matches_width_one)
674{
675 auto session = CreateSession();
676 if (session->DefinesParameter("KovaLam"))
677 {
678 return;
679 }
681 auto velocityExpList =
683 session, graph, "u", true, false, Collections::eNoCollection);
684 auto pressureExpList =
686 session, graph, "p", true, false, Collections::eNoCollection);
687 velocityExpList->SetDataWarehouse();
688 pressureExpList->SetDataWarehouse();
689
690 const unsigned int nDim = graph->GetMeshDimension();
691 const auto velocityComponents = GetVelocityComponents(nDim);
692 const std::vector<std::string> pressureComponents = {"p"};
693 const auto velocityPhysBlocks =
695 velocityExpList,
696 MultiRegions::UnitInterleaveWidths(velocityExpList));
697 const auto pressureCoeffBlocks =
699 pressureExpList,
700 MultiRegions::UnitInterleaveWidths(pressureExpList));
702 "velocity", velocityPhysBlocks, velocityComponents, 1);
704 "implicit predictor", velocityPhysBlocks, velocityComponents, 1);
705 velocity.Initialize<NektarSpaces::HostSpace>(0.0);
706 predictor.Initialize<NektarSpaces::HostSpace>(0.0);
707 for (unsigned int blk = 0; blk < predictor.GetBlocks().size(); ++blk)
708 {
709 auto &predictorBlock = predictor.GetBlocks()[blk];
710 auto predictorPtr =
711 predictorBlock
712 .template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
713 const size_t nPoints =
714 predictorBlock.GetNumElements() * predictorBlock.GetNumData();
715 for (unsigned int d = 0; d < nDim; ++d)
716 {
717 std::fill(predictorPtr + d * predictorBlock.CompSize(),
718 predictorPtr + d * predictorBlock.CompSize() + nPoints,
719 0.1 * (d + 1));
720 }
721 }
722
723 // The same non-zero right-hand side at interleave width 1 and at the
724 // interleave width of the execution space.
726 "Poisson RHS at width 1", pressureCoeffBlocks, pressureComponents, 1);
728 "interleaved Poisson RHS", pressureCoeffBlocks, pressureComponents, 1);
729 reference.Initialize<NektarSpaces::HostSpace>(0.0);
730 interleaved.Initialize<NektarSpaces::HostSpace>(0.0);
731 const unsigned int interleaveWidth = NektarSpaces::GetVectorWidth<double>(
733 // The storage is zero, so it need not be reshaped.
734 interleaved.SetInterleaveWidth(interleaveWidth);
735 std::vector<double> initialValues(reference.ToVector<double>().size());
736 for (std::size_t i = 0; i < initialValues.size(); ++i)
737 {
738 initialValues[i] = 1.0 + 1.0e-3 * i;
739 }
740 reference.CopyVector<NektarSpaces::HostSpace>(initialValues);
741 interleaved.CopyVector<NektarSpaces::HostSpace>(initialValues);
742
743 constexpr double time = 0.4;
744 constexpr double scale = 2.5;
745 auto op = HOPressureBndCondOp<double>::Create(pressureExpList,
746 pressureComponents);
747 op->SetVelocityContext(velocityExpList, velocityComponents);
748 op->SetKinvis(0.0);
749 op->SetTime(time);
750 op->SetScale(scale);
751 // Every velocity component is Dirichlet, so rhs is not read.
753 op->UpdateWithAcceleration(rhs, velocity, predictor);
754 for (unsigned int pass = 0; pass < 2; ++pass)
755 {
756 op->Apply(reference);
757 op->Apply(interleaved);
758 }
759
760 for (auto &block : interleaved.GetBlocks())
761 {
762 BOOST_TEST(block.GetInterleaveWidth() == interleaveWidth);
763 }
764
765 const auto referenceValues = reference.ToVector<double>();
766 const auto interleavedValues = interleaved.ToVector<double>();
767 BOOST_REQUIRE_EQUAL(interleavedValues.size(), referenceValues.size());
768 double maxForcing = 0.0;
769 for (std::size_t i = 0; i < referenceValues.size(); ++i)
770 {
771 maxForcing = std::max(maxForcing,
772 std::abs(referenceValues[i] - initialValues[i]));
773 BOOST_TEST(interleavedValues[i] == referenceValues[i]);
774 }
775 BOOST_TEST(maxForcing > 1.0e-2);
776}
777
778BOOST_AUTO_TEST_CASE(update_then_apply_kovasznay_boundary_flux)
779{
780 auto session = CreateSession();
781 if (!session->DefinesParameter("KovaLam"))
782 {
783 return;
784 }
785
787 auto velocityExpList =
789 session, graph, "u", true, false, Collections::eNoCollection);
790 auto pressureExpList =
792 session, graph, "p", true, false, Collections::eNoCollection);
793 velocityExpList->SetDataWarehouse();
794 pressureExpList->SetDataWarehouse();
795
796 const std::vector<std::string> velocityComponents = {"u", "v"};
797 const std::vector<std::string> pressureComponents = {"p"};
798 const auto velocityPhysBlocks =
800 velocityExpList,
801 MultiRegions::UnitInterleaveWidths(velocityExpList));
802
804 "Poisson RHS",
806 pressureExpList,
807 MultiRegions::UnitInterleaveWidths(pressureExpList)),
808 pressureComponents, 1);
810 "Kovasznay boundary RHS", velocityPhysBlocks, velocityComponents, 1);
812 "Kovasznay velocity", velocityPhysBlocks, velocityComponents, 1);
813
814 const double lambda = session->GetParameter("KovaLam");
815 const double kinvis = session->GetParameter("Kinvis");
816 const double waveNumber = 2.0 * std::acos(-1.0);
817 velocity.Initialize<NektarSpaces::HostSpace>(0.0);
818 boundaryRhs.Initialize<NektarSpaces::HostSpace>(0.0);
819 for (unsigned int blk = 0; blk < velocity.GetBlocks().size(); ++blk)
820 {
821 auto &velocityBlock = velocity.GetBlocks()[blk];
822 auto &rhsBlock = boundaryRhs.GetBlocks()[blk];
823 auto velocityPtr =
824 velocityBlock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
825 auto rhsPtr =
826 rhsBlock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
827 auto collection = GetCollection(velocityExpList, blk);
828 const auto &expansions = collection.GetExpVector();
829
830 for (unsigned int e = 0; e < expansions.size(); ++e)
831 {
832 Array<OneD, double> x(velocityBlock.GetNumData());
833 Array<OneD, double> y(velocityBlock.GetNumData());
834 Array<OneD, double> z(velocityBlock.GetNumData(), 0.0);
835 expansions[e]->GetCoords(x, y, z);
836 for (unsigned int p = 0; p < velocityBlock.GetNumData(); ++p)
837 {
838 const auto id = e * velocityBlock.GetNumData() + p;
839 const double exponential = std::exp(-lambda * x[p]);
840 const double sine = std::sin(waveNumber * y[p]);
841 const double cosine = std::cos(waveNumber * y[p]);
842
843 velocityPtr[id] = 1.0 - exponential * cosine;
844 velocityPtr[velocityBlock.CompSize() + id] =
845 -(lambda / waveNumber) * exponential * sine;
846
847 // Physical explicit RHS is -u.grad(u). Together with
848 // -nu*CurlCurl(u), this equals grad(p) for Kovasznay flow.
849 rhsPtr[id] = -lambda * exponential * cosine +
850 lambda * exponential * exponential;
851 rhsPtr[rhsBlock.CompSize() + id] =
852 -(lambda * lambda / waveNumber) * exponential * sine;
853 }
854 }
855 }
856
857 poissonRhs.Initialize<NektarSpaces::HostSpace>(0.0);
858 auto op = HOPressureBndCondOp<double>::Create(pressureExpList,
859 pressureComponents);
860 op->SetVelocityContext(velocityExpList, velocityComponents);
861 op->SetKinvis(kinvis);
862 op->Update(boundaryRhs, velocity);
863 op->Apply(poissonRhs);
864
865 Array<OneD, double> expectedCoeffs(pressureExpList->GetNcoeffs(), 0.0);
866 const auto &bndExpansions = pressureExpList->GetBndCondExpansions();
867 const auto &bndConditions = pressureExpList->GetBndConditions();
868 const auto &localToGlobal = pressureExpList->GetLocalToGlobalMap();
869 const auto &coeffMap = localToGlobal->GetBndCondCoeffsToLocalCoeffsMap();
870 const auto &coeffSign = localToGlobal->GetBndCondCoeffsToLocalCoeffsSign();
871 const bool signChange = localToGlobal->GetSignChange();
872 unsigned int bndCoeffOffset = 0;
873 for (unsigned int n = 0; n < bndExpansions.size(); ++n)
874 {
875 auto bndExp = bndExpansions[n];
876 if (bndConditions[n]->GetBoundaryConditionType() ==
878 {
879 const auto npts = bndExp->GetTotPoints();
880 Array<OneD, double> x(npts), y(npts), z(npts, 0.0);
881 bndExp->GetCoords(x, y, z);
882 Array<OneD, Array<OneD, double>> pressureGradient(2);
883 pressureGradient[0] = Array<OneD, double>(npts);
884 pressureGradient[1] = Array<OneD, double>(npts, 0.0);
885 for (unsigned int p = 0; p < npts; ++p)
886 {
887 pressureGradient[0][p] =
888 lambda * std::exp(-2.0 * lambda * x[p]);
889 }
890
891 Array<OneD, double> bndCoeffs(bndExp->GetNcoeffs(), 0.0);
892 bndExp->NormVectorIProductWRTBase(pressureGradient, bndCoeffs);
893 for (unsigned int c = 0; c < bndExp->GetNcoeffs(); ++c)
894 {
895 const auto bndCoeff = bndCoeffOffset + c;
896 const auto localCoeff = coeffMap[bndCoeff];
897 expectedCoeffs[localCoeff] +=
898 (signChange ? coeffSign[bndCoeff] : 1.0) * bndCoeffs[c];
899 }
900 }
901 bndCoeffOffset += bndExp->GetNcoeffs();
902 }
903
905 "expected Kovasznay Poisson RHS",
907 pressureExpList,
908 MultiRegions::UnitInterleaveWidths(pressureExpList)),
909 pressureComponents, 1);
910 expected.Initialize<NektarSpaces::HostSpace>(0.0);
911 for (unsigned int blk = 0; blk < expected.GetBlocks().size(); ++blk)
912 {
913 auto &expectedBlock = expected.GetBlocks()[blk];
914 auto expectedPtr =
915 expectedBlock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
916 auto collection = GetCollection(pressureExpList, blk);
917 const auto &expansions = collection.GetExpVector();
918 for (unsigned int e = 0; e < expansions.size(); ++e)
919 {
920 const auto offset =
921 pressureExpList->GetCoeff_Offset(expansions[e]->GetElmtId());
922 std::copy(expectedCoeffs.begin() + offset,
923 expectedCoeffs.begin() + offset +
924 expectedBlock.GetNumData(),
925 expectedPtr + e * expectedBlock.GetNumData());
926 }
927 }
928
929 const auto actualValues = poissonRhs.ToVector<double>();
930 const auto expectedValues = expected.ToVector<double>();
931 BOOST_REQUIRE_EQUAL(actualValues.size(), expectedValues.size());
932 double maxDifference = 0.0;
933 for (std::size_t i = 0; i < actualValues.size(); ++i)
934 {
935 maxDifference = std::max(maxDifference,
936 std::abs(actualValues[i] - expectedValues[i]));
937 }
938 BOOST_TEST(maxDifference < 1.0e-6);
939}
940
941// The Kovasznay velocity is not representable on the boundary expansion of
942// KovasznayFlowHOPBC2D_SmallTimeStep.xml. A predictor holding its projection
943// onto the continuous expansion, with the Dirichlet velocity imposed as the
944// velocity solve imposes it, is a steady state of the boundary acceleration:
945// without an explicit contribution or viscosity, the flux vanishes.
946// Subtracting the expression of the Dirichlet velocity instead leaves
947// scale * (u_D - u_D,exact) . n, large at the scale of a small time step. With
948// KovasznayFlowHOPBC2D_MixedOrder.xml the pressure is one order below the
949// velocity, and the projection onto the pressure boundary expansion would
950// leave the difference of the two projections instead.
951BOOST_AUTO_TEST_CASE(update_then_apply_kovasznay_discrete_boundary_velocity)
952{
953 auto session = CreateSession();
954 if (!session->DefinesParameter("KovaLam"))
955 {
956 return;
957 }
958
960 const std::vector<std::string> velocityComponents = {"u", "v"};
961 const std::vector<std::string> pressureComponents = {"p"};
962 std::vector<MultiRegions::ContFieldSharedPtr> velocityExpLists;
963 for (const auto &component : velocityComponents)
964 {
965 velocityExpLists.push_back(
967 session, graph, component, true, false,
969 }
970 auto pressureExpList =
972 session, graph, "p", true, false, Collections::eNoCollection);
973 velocityExpLists[0]->SetDataWarehouse();
974 pressureExpList->SetDataWarehouse();
975
976 // The projection of the exact velocity onto the continuous expansion,
977 // whose Dirichlet coefficients are those of the projected Dirichlet
978 // velocity.
979 const double lambda = session->GetParameter("KovaLam");
980 const double waveNumber = 2.0 * std::acos(-1.0);
981 const size_t nq = velocityExpLists[0]->GetTotPoints();
982 Array<OneD, double> x(nq), y(nq), z(nq, 0.0);
983 velocityExpLists[0]->GetCoords(x, y, z);
984 std::vector<Array<OneD, double>> discreteVelocity;
985 for (unsigned int d = 0; d < velocityComponents.size(); ++d)
986 {
987 Array<OneD, double> exact(nq);
988 for (size_t p = 0; p < nq; ++p)
989 {
990 const double exponential = std::exp(-lambda * x[p]);
991 exact[p] = d == 0 ? 1.0 - exponential * std::cos(waveNumber * y[p])
992 : -(lambda / waveNumber) * exponential *
993 std::sin(waveNumber * y[p]);
994 }
995 auto &expList = velocityExpLists[d];
996 expList->EvaluateBoundaryConditions(0.0);
997 expList->FwdTrans(exact, expList->UpdateCoeffs());
998 discreteVelocity.emplace_back(nq, 0.0);
999 expList->BwdTrans(expList->GetCoeffs(), discreteVelocity.back());
1000 }
1001
1002 const auto velocityPhysBlocks =
1004 velocityExpLists[0],
1005 MultiRegions::UnitInterleaveWidths(velocityExpLists[0]));
1007 "Poisson RHS",
1009 pressureExpList,
1010 MultiRegions::UnitInterleaveWidths(pressureExpList)),
1011 pressureComponents, 1);
1013 "velocity", velocityPhysBlocks, velocityComponents, 1);
1015 "implicit predictor", velocityPhysBlocks, velocityComponents, 1);
1016 poissonRhs.Initialize<NektarSpaces::HostSpace>(0.0);
1017 velocity.Initialize<NektarSpaces::HostSpace>(0.0);
1018 predictor.Initialize<NektarSpaces::HostSpace>(0.0);
1019 for (unsigned int blk = 0; blk < predictor.GetBlocks().size(); ++blk)
1020 {
1021 auto &predictorBlock = predictor.GetBlocks()[blk];
1022 auto predictorPtr =
1023 predictorBlock
1024 .template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
1025 auto collection = GetCollection(velocityExpLists[0], blk);
1026 const auto &expansions = collection.GetExpVector();
1027 for (unsigned int e = 0; e < expansions.size(); ++e)
1028 {
1029 const auto offset =
1030 velocityExpLists[0]->GetPhys_Offset(expansions[e]->GetElmtId());
1031 for (unsigned int d = 0; d < velocityComponents.size(); ++d)
1032 {
1033 std::copy_n(discreteVelocity[d].begin() + offset,
1034 predictorBlock.GetNumData(),
1035 predictorPtr + d * predictorBlock.CompSize() +
1036 e * predictorBlock.GetNumData());
1037 }
1038 }
1039 }
1040
1041 // 1 / (gamma dt) of a second-order step of dt = 1e-4.
1042 static constexpr double scale = 1.5e4;
1043 auto op = HOPressureBndCondOp<double>::Create(pressureExpList,
1044 pressureComponents);
1045 op->SetVelocityContext(velocityExpLists[0], velocityComponents);
1046 op->SetKinvis(0.0);
1047 op->SetScale(scale);
1048 // Every velocity component is Dirichlet, so rhs is not read.
1050 op->UpdateWithAcceleration(rhs, velocity, predictor);
1051 op->Apply(poissonRhs);
1052
1053 double maxValue = 0.0;
1054 for (const auto value : poissonRhs.ToVector<double>())
1055 {
1056 maxValue = std::max(maxValue, std::abs(value));
1057 }
1058 BOOST_TEST(maxValue < 1.0e-8);
1059}
1060
1061BOOST_AUTO_TEST_CASE(update_then_apply_selection_respects_hop_tag)
1062{
1063 auto session = CreateSession();
1064 if (!session->DefinesParameter("HOPSelectionTest"))
1065 {
1066 return;
1067 }
1069 auto velocityExpList =
1071 session, graph, "u", true, false, Collections::eNoCollection);
1072 auto pressureExpList =
1074 session, graph, "p", true, false, Collections::eNoCollection);
1075 velocityExpList->SetDataWarehouse();
1076 pressureExpList->SetDataWarehouse();
1077
1078 const unsigned int nDim = graph->GetMeshDimension();
1079 const auto velocityComponents = GetVelocityComponents(nDim);
1080 const std::vector<std::string> pressureComponents = {"p"};
1081 const auto velocityPhysBlocks =
1083 velocityExpList,
1084 MultiRegions::UnitInterleaveWidths(velocityExpList));
1085
1087 "Poisson RHS",
1089 pressureExpList,
1090 MultiRegions::UnitInterleaveWidths(pressureExpList)),
1091 pressureComponents, 1);
1093 "HOPressure boundary RHS", velocityPhysBlocks, velocityComponents, 1);
1095 "manufactured velocity", velocityPhysBlocks, velocityComponents, 1);
1096
1097 velocity.Initialize<NektarSpaces::HostSpace>(0.0);
1098 boundaryRhs.Initialize<NektarSpaces::HostSpace>(0.0);
1099 for (unsigned int blk = 0; blk < velocity.GetBlocks().size(); ++blk)
1100 {
1101 auto &velocityBlock = velocity.GetBlocks()[blk];
1102 auto &rhsBlock = boundaryRhs.GetBlocks()[blk];
1103 auto velocityPtr =
1104 velocityBlock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
1105 auto rhsPtr =
1106 rhsBlock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
1107 auto collection = GetCollection(velocityExpList, blk);
1108 const auto &expansions = collection.GetExpVector();
1109
1110 for (unsigned int e = 0; e < expansions.size(); ++e)
1111 {
1112 Array<OneD, double> x(velocityBlock.GetNumData());
1113 Array<OneD, double> y(velocityBlock.GetNumData());
1114 Array<OneD, double> z(velocityBlock.GetNumData(), 0.0);
1115 expansions[e]->GetCoords(x, y, z);
1116 for (unsigned int p = 0; p < velocityBlock.GetNumData(); ++p)
1117 {
1118 // Same divergence-free, non-constant-CurlCurl field as
1119 // update_then_apply_manufactured_boundary_flux's 2D branch:
1120 // grad(p) for p = x^3 + x*y^2 + 2*x^2*y.
1121 const auto id = e * velocityBlock.GetNumData() + p;
1122 const double x2 = x[p] * x[p];
1123 const double y2 = y[p] * y[p];
1124 velocityPtr[id] = 2.0 * x[p] * x2 * y[p];
1125 velocityPtr[velocityBlock.CompSize() + id] = -3.0 * x2 * y2;
1126 rhsPtr[id] = 3.0 * x2 + y2 + x[p] * y[p];
1127 rhsPtr[rhsBlock.CompSize() + id] =
1128 3.5 * x2 + 2.0 * x[p] * y[p] + 1.5 * y2;
1129 }
1130 }
1131 }
1132
1133 poissonRhs.Initialize<NektarSpaces::HostSpace>(0.0);
1134
1135 auto op = HOPressureBndCondOp<double>::Create(pressureExpList,
1136 pressureComponents);
1137 // Region 1 is a Neumann pressure region without USERDEFINEDTYPE="H",
1138 // with a non-Dirichlet velocity: it does not take the higher-order flux,
1139 // so this does not throw.
1140 op->SetVelocityContext(velocityExpList, velocityComponents);
1141 static constexpr double contributionScale = 2.5;
1142 op->SetKinvis(0.25);
1143 op->SetScale(contributionScale);
1144 op->Update(boundaryRhs, velocity);
1145 op->Apply(poissonRhs);
1146
1147 const auto actualValues = poissonRhs.ToVector<double>();
1148 // Only regions 0 and 2, with USERDEFINEDTYPE="H", contribute; region 1,
1149 // also a Neumann region, contributes nothing.
1150 const auto expectedValues = BuildExpectedBoundaryContribution(
1151 pressureExpList, nDim,
1152 [](const double x, const double y, const double) {
1153 return std::array<double, 3>{
1154 contributionScale * (3.0 * x * x + y * y + 4.0 * x * y),
1155 contributionScale * (2.0 * x * y + 2.0 * x * x), 0.0};
1156 },
1157 /* requireHOPTag */ true);
1158 BOOST_REQUIRE_EQUAL(actualValues.size(), expectedValues.size());
1159
1160 const auto maxExpected =
1161 *std::max_element(expectedValues.begin(), expectedValues.end(),
1162 [](const double lhs, const double rhs) {
1163 return std::abs(lhs) < std::abs(rhs);
1164 });
1165 BOOST_TEST(std::abs(maxExpected) > 0.1);
1166
1167 for (std::size_t i = 0; i < actualValues.size(); ++i)
1168 {
1169 BOOST_TEST(std::abs(actualValues[i] - expectedValues[i]) < 2.5e-10);
1170 }
1171}
1172
1173// On a region whose velocity is Dirichlet in u and Neumann in v, u takes the
1174// acceleration and v none: its flux is formed from rhs. Without rhs, the
1175// update is refused.
1176BOOST_AUTO_TEST_CASE(update_then_apply_neumann_velocity_boundary_flux)
1177{
1178 CheckNeumannVelocityBoundaryFlux(false);
1179}
1180
1181// The same region in the weak pressure form, whose flux leaves out
1182// scale * predictor: u takes the acceleration alone, and v the velocity
1183// predictor - rhs as its boundary velocity. Without rhs, the update is
1184// refused.
1185BOOST_AUTO_TEST_CASE(update_weak_then_apply_neumann_velocity_boundary_flux)
1186{
1187 CheckNeumannVelocityBoundaryFlux(true);
1188}
1189
1190// A velocity and a pressure one order apart with the same quadrature type
1191// do not share their quadrature points, and must be rejected rather than
1192// combined point by point.
1193BOOST_AUTO_TEST_CASE(set_velocity_context_throws_for_different_quadrature)
1194{
1195 auto session = CreateSession();
1196 if (!session->DefinesParameter("HOPQuadratureThrowsTest"))
1197 {
1198 return;
1199 }
1201 auto velocityExpList =
1203 session, graph, "u", true, false, Collections::eNoCollection);
1204 auto pressureExpList =
1206 session, graph, "p", true, false, Collections::eNoCollection);
1207 velocityExpList->SetDataWarehouse();
1208 pressureExpList->SetDataWarehouse();
1209
1210 const auto velocityComponents =
1211 GetVelocityComponents(graph->GetMeshDimension());
1212 const std::vector<std::string> pressureComponents = {"p"};
1213
1214 auto op = HOPressureBndCondOp<double>::Create(pressureExpList,
1215 pressureComponents);
1216 BOOST_CHECK_EXCEPTION(
1217 op->SetVelocityContext(velocityExpList, velocityComponents),
1219 [](const Nektar::ErrorUtil::NekError &error) {
1220 return std::string(error.what())
1221 .find("share their quadrature points") !=
1222 std::string::npos;
1223 });
1224}
1225
1226BOOST_AUTO_TEST_SUITE_END()
LibUtilities::SessionReaderSharedPtr session
SpatialDomains::MeshGraphSharedPtr graph
BOOST_TEST_GLOBAL_CONFIGURATION(GlobalConfiguration)
int64_t id
static std::shared_ptr< HOPressureBndCondOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="")
A Field represents expansion data to be operated on.
void CopyVector(const std::vector< TDataIn, Alloc > &array)
Templated copy method. This method copies data from a std::vector laid out as ToVector() returns it,...
void ReshapeStorage(const unsigned int &interleaveWidth, const std::string &execSpace)
std::vector< BlockAccessor< TData, TState > > & GetBlocks()
Get BlockAccessors for the field.
std::vector< TDataOut, Alloc > ToVector()
Copy the data to a std::vector, component by component and element by element, without padding,...
void Initialize(const TData val, const unsigned int streamID=0)
Templated initialize method: set every entry to val, but the padding, which is zero.
void SetInterleaveWidth(const unsigned int &interleaveWidth)
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
Common base class of the operator family interfaces: holds the expansion list, component names and da...
Definition Operator.hpp:100
static std::string GetOpExecSpace(std::shared_ptr< LibUtilities::SessionReader > session, const bool warn=true)
Return the execution space name ("opExecSpace") for an operator.
Definition Operator.hpp:190
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true, SpatialDomains::MeshGraphSharedPtr partitionedGraph=nullptr)
std::shared_ptr< SessionReader > SessionReaderSharedPtr
LibUtilities::SessionReaderSharedPtr CreateSession()
template std::vector< BlockAttributes< FieldState::Coeff > > GetBlockAttributes< double, FieldState::Coeff >(const MultiRegions::ExpListSharedPtr explist, const std::vector< unsigned int > &interleave_widths)
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
template std::vector< BlockAttributes< FieldState::Phys > > GetBlockAttributes< double, FieldState::Phys >(const MultiRegions::ExpListSharedPtr explist, const std::vector< unsigned int > &interleave_widths)
Collections::Collection GetCollection(MultiRegions::ExpListSharedPtr expansionList, unsigned int block_idx)
std::shared_ptr< BoundaryConditionBase > BoundaryConditionShPtr
Definition Conditions.h:251
bool IEquals(std::string_view a, std::string_view b)
std::vector< double > p(NPUPPER)
std::vector< double > d(NPUPPER *NPUPPER)
BOOST_AUTO_TEST_CASE(TestCanGetRawPtr)