35#define BOOST_TEST_MODULE TestHOPressureBndCond
39#include <boost/test/included/unit_test.hpp>
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);
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>...]");
91 const std::string execStr(suite.argv[1]);
92 const std::string implStr(suite.argv[2]);
93 const int nSessionFiles = suite.argc - 3;
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)
100 argv[i + 1] = strdup(suite.argv[i + 3]);
102 argv[nSessionFiles + 1] = strdup((
"--opExecSpace=" + execStr).c_str());
103 argv[nSessionFiles + 2] = strdup((
"--opImpl=" + implStr).c_str());
104 argv[argc] =
nullptr;
109 for (
int i = 0; i < argc; ++i)
118std::vector<std::string> GetVelocityComponents(
const unsigned int nDim)
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};
137template <
typename Gradient>
138std::vector<double> BuildExpectedBoundaryContribution(
140 const unsigned int nDim, Gradient gradient,
141 const bool requireHOPTag =
false)
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();
154 unsigned int bndCoeffOffset = 0;
155 for (
unsigned int n = 0; n < bndExpansions.size(); ++n)
157 auto bndExp = bndExpansions[n];
158 const bool selected =
159 requireHOPTag ? IsTaggedHOPressure(bndConditions[n])
160 : bndConditions[n]->GetBoundaryConditionType() ==
164 const auto npts = bndExp->GetTotPoints();
166 bndExp->GetCoords(x, y, z);
168 for (
unsigned int d = 0;
d < nDim; ++
d)
172 for (
unsigned int p = 0;
p < npts; ++
p)
174 const auto value = gradient(x[p], y[p], z[p]);
175 for (
unsigned int d = 0;
d < nDim; ++
d)
177 vectorFlux[
d][
p] = value[
d];
182 bndExp->NormVectorIProductWRTBase(vectorFlux, bndCoeffs);
183 for (
unsigned int c = 0;
c < bndExp->GetNcoeffs(); ++
c)
185 const auto bndCoeff = bndCoeffOffset +
c;
186 const auto localCoeff = coeffMap[bndCoeff];
187 expectedCoeffs[localCoeff] +=
188 (signChange ? coeffSign[bndCoeff] : 1.0) * bndCoeffs[c];
191 bndCoeffOffset += bndExp->GetNcoeffs();
194 const std::vector<std::string> pressureComponents = {
"p"};
196 "expected Poisson RHS",
199 MultiRegions::UnitInterleaveWidths(pressureExpList)),
200 pressureComponents, 1);
202 for (
unsigned int blk = 0; blk < expected.GetBlocks().size(); ++blk)
204 auto &expectedBlock = expected.GetBlocks()[blk];
206 expectedBlock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
208 const auto &expansions = collection.GetExpVector();
209 for (
unsigned int e = 0;
e < expansions.size(); ++
e)
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());
219 return expected.ToVector<
double>();
224void CheckNeumannVelocityBoundaryFlux(
const bool isWeak)
227 if (!
session->DefinesParameter(
"HOPNeumannVelocityTest"))
232 auto velocityExpList =
235 auto pressureExpList =
238 velocityExpList->SetDataWarehouse();
239 pressureExpList->SetDataWarehouse();
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 =
247 MultiRegions::UnitInterleaveWidths(velocityExpList));
252 MultiRegions::UnitInterleaveWidths(pressureExpList)),
253 pressureComponents, 1);
255 "explicit contribution", velocityPhysBlocks, velocityComponents, 1);
257 "velocity", velocityPhysBlocks, velocityComponents, 1);
259 "implicit predictor", velocityPhysBlocks, velocityComponents, 1);
265 for (
unsigned int blk = 0; blk < predictor.GetBlocks().size(); ++blk)
267 auto &rhsBlock = rhs.GetBlocks()[blk];
268 auto &predictorBlock = predictor.GetBlocks()[blk];
270 rhsBlock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
273 .template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
274 for (
unsigned int d = 0;
d < nDim; ++
d)
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(),
284 static constexpr double time = 0.4;
285 static constexpr double scale = 2.5;
288 op->SetVelocityContext(velocityExpList, velocityComponents);
289 BOOST_TEST(op->HasNonDirichletVelocity());
296 std::array<double, 3> expectedFlux = {scale * (0.1 - time), scale * 0.06,
300 op->UpdateWeak(rhs, velocity, predictor);
301 expectedFlux = {-scale * time, -scale * (0.2 - 0.06), 0.0};
305 op->UpdateWithAcceleration(rhs, velocity, predictor);
307 op->Apply(poissonRhs);
309 const auto actualValues = poissonRhs.ToVector<
double>();
310 const auto expectedValues = BuildExpectedBoundaryContribution(
311 pressureExpList, nDim,
312 [&expectedFlux](
const double,
const double,
const double) {
315 BOOST_REQUIRE_EQUAL(actualValues.size(), expectedValues.size());
316 double maxDifference = 0.0;
317 for (std::size_t i = 0; i < actualValues.size(); ++i)
319 maxDifference = std::max(maxDifference,
320 std::abs(actualValues[i] - expectedValues[i]));
322 BOOST_TEST(maxDifference < 2.5e-11);
327 BOOST_CHECK_THROW(op->UpdateWeak(noRhs, velocity, predictor),
333 op->UpdateWithAcceleration(noRhs, velocity, predictor),
340BOOST_AUTO_TEST_SUITE(TestHOPressureBndCond)
344 auto session = CreateSession();
346 auto pressureExpList =
349 pressureExpList->SetDataWarehouse();
351 const std::vector<std::string> pressureComponents = {
"p"};
356 MultiRegions::UnitInterleaveWidths(pressureExpList)),
357 pressureComponents, 1);
360 auto before = rhs.
ToVector<
double>();
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)
370 BOOST_TEST(after[i] == before[i]);
376 auto session = CreateSession();
378 auto velocityExpList =
381 auto pressureExpList =
384 velocityExpList->SetDataWarehouse();
385 pressureExpList->SetDataWarehouse();
387 const auto velocityComponents =
388 GetVelocityComponents(
graph->GetMeshDimension());
389 const std::vector<std::string> pressureComponents = {
"p"};
395 MultiRegions::UnitInterleaveWidths(pressureExpList)),
396 pressureComponents, 1);
401 MultiRegions::UnitInterleaveWidths(velocityExpList)),
402 velocityComponents, 1);
407 MultiRegions::UnitInterleaveWidths(velocityExpList)),
408 velocityComponents, 1);
414 auto before = rhs.
ToVector<
double>();
418 op->SetVelocityContext(velocityExpList, velocityComponents);
420 op->Update(boundaryRhs, velocity);
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)
427 BOOST_TEST(after[i] == before[i]);
433 auto session = CreateSession();
434 if (
session->DefinesParameter(
"KovaLam"))
439 auto velocityExpList =
442 auto pressureExpList =
445 velocityExpList->SetDataWarehouse();
446 pressureExpList->SetDataWarehouse();
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 =
454 MultiRegions::UnitInterleaveWidths(velocityExpList));
460 MultiRegions::UnitInterleaveWidths(pressureExpList)),
461 pressureComponents, 1);
463 "HOPressure boundary RHS", velocityPhysBlocks, velocityComponents, 1);
465 "manufactured velocity", velocityPhysBlocks, velocityComponents, 1);
469 for (
unsigned int blk = 0; blk < velocity.
GetBlocks().size(); ++blk)
471 auto &velocityBlock = velocity.
GetBlocks()[blk];
472 auto &rhsBlock = boundaryRhs.
GetBlocks()[blk];
474 velocityBlock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
476 rhsBlock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
478 const auto &expansions = collection.GetExpVector();
480 for (
unsigned int e = 0; e < expansions.size(); ++e)
485 expansions[e]->GetCoords(x, y, z);
486 for (
unsigned int p = 0; p < velocityBlock.GetNumData(); ++p)
488 const auto id = e * velocityBlock.GetNumData() + p;
489 const double x2 = x[p] * x[p];
490 const double y2 = y[p] * y[p];
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;
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;
523 op->SetVelocityContext(velocityExpList, velocityComponents);
524 static constexpr double contributionScale = 2.5;
526 op->SetScale(contributionScale);
528 const auto expectedValues = BuildExpectedBoundaryContribution(
529 pressureExpList, nDim,
530 [nDim](
const double x,
const double y,
const double z) {
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};
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)};
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);
546 BOOST_TEST(std::abs(maxExpected) > 0.1);
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 = {
559 {interleaveWidth, interleaveWidth},
560 {interleaveWidth, 1},
561 {1, interleaveWidth},
563 for (
const auto &[velocityWidth, rhsWidth] : widths)
568 op->Update(boundaryRhs, velocity);
569 op->Apply(poissonRhs);
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)
576 std::abs(actualValues[i] - expectedValues[i]) < 2.5e-10,
577 "velocity at width " << velocityWidth <<
", rhs at width "
585 auto session = CreateSession();
586 if (
session->DefinesParameter(
"KovaLam"))
591 auto velocityExpList =
594 auto pressureExpList =
597 velocityExpList->SetDataWarehouse();
598 pressureExpList->SetDataWarehouse();
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 =
606 MultiRegions::UnitInterleaveWidths(velocityExpList));
611 MultiRegions::UnitInterleaveWidths(pressureExpList)),
612 pressureComponents, 1);
614 "velocity", velocityPhysBlocks, velocityComponents, 1);
616 "implicit predictor", velocityPhysBlocks, velocityComponents, 1);
621 for (
unsigned int blk = 0; blk < predictor.
GetBlocks().size(); ++blk)
623 auto &predictorBlock = predictor.
GetBlocks()[blk];
626 .template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
627 for (
unsigned int d = 0; d < nDim; ++d)
629 std::fill(predictorPtr + d * predictorBlock.CompSize(),
630 predictorPtr + (d + 1) * predictorBlock.CompSize(),
635 static constexpr double time = 0.4;
636 static constexpr double scale = 2.5;
639 op->SetVelocityContext(velocityExpList, velocityComponents);
645 op->UpdateWithAcceleration(rhs, velocity, predictor);
646 op->Apply(poissonRhs);
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)
656 value[d] = scale * (d + 1) * (0.1 - time);
660 BOOST_REQUIRE_EQUAL(actualValues.size(), expectedValues.size());
661 double maxDifference = 0.0;
662 for (std::size_t i = 0; i < actualValues.size(); ++i)
664 maxDifference = std::max(maxDifference,
665 std::abs(actualValues[i] - expectedValues[i]));
667 BOOST_TEST(maxDifference < 2.5e-11);
675 auto session = CreateSession();
676 if (
session->DefinesParameter(
"KovaLam"))
681 auto velocityExpList =
684 auto pressureExpList =
687 velocityExpList->SetDataWarehouse();
688 pressureExpList->SetDataWarehouse();
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 =
696 MultiRegions::UnitInterleaveWidths(velocityExpList));
697 const auto pressureCoeffBlocks =
700 MultiRegions::UnitInterleaveWidths(pressureExpList));
702 "velocity", velocityPhysBlocks, velocityComponents, 1);
704 "implicit predictor", velocityPhysBlocks, velocityComponents, 1);
707 for (
unsigned int blk = 0; blk < predictor.
GetBlocks().size(); ++blk)
709 auto &predictorBlock = predictor.
GetBlocks()[blk];
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)
717 std::fill(predictorPtr + d * predictorBlock.CompSize(),
718 predictorPtr + d * predictorBlock.CompSize() + nPoints,
726 "Poisson RHS at width 1", pressureCoeffBlocks, pressureComponents, 1);
728 "interleaved Poisson RHS", pressureCoeffBlocks, pressureComponents, 1);
731 const unsigned int interleaveWidth = NektarSpaces::GetVectorWidth<double>(
735 std::vector<double> initialValues(reference.
ToVector<
double>().size());
736 for (std::size_t i = 0; i < initialValues.size(); ++i)
738 initialValues[i] = 1.0 + 1.0e-3 * i;
743 constexpr double time = 0.4;
744 constexpr double scale = 2.5;
747 op->SetVelocityContext(velocityExpList, velocityComponents);
753 op->UpdateWithAcceleration(rhs, velocity, predictor);
754 for (
unsigned int pass = 0; pass < 2; ++pass)
756 op->Apply(reference);
757 op->Apply(interleaved);
760 for (
auto &block : interleaved.
GetBlocks())
762 BOOST_TEST(block.GetInterleaveWidth() == interleaveWidth);
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)
771 maxForcing = std::max(maxForcing,
772 std::abs(referenceValues[i] - initialValues[i]));
773 BOOST_TEST(interleavedValues[i] == referenceValues[i]);
775 BOOST_TEST(maxForcing > 1.0e-2);
780 auto session = CreateSession();
781 if (!
session->DefinesParameter(
"KovaLam"))
787 auto velocityExpList =
790 auto pressureExpList =
793 velocityExpList->SetDataWarehouse();
794 pressureExpList->SetDataWarehouse();
796 const std::vector<std::string> velocityComponents = {
"u",
"v"};
797 const std::vector<std::string> pressureComponents = {
"p"};
798 const auto velocityPhysBlocks =
801 MultiRegions::UnitInterleaveWidths(velocityExpList));
807 MultiRegions::UnitInterleaveWidths(pressureExpList)),
808 pressureComponents, 1);
810 "Kovasznay boundary RHS", velocityPhysBlocks, velocityComponents, 1);
812 "Kovasznay velocity", velocityPhysBlocks, velocityComponents, 1);
814 const double lambda =
session->GetParameter(
"KovaLam");
815 const double kinvis =
session->GetParameter(
"Kinvis");
816 const double waveNumber = 2.0 * std::acos(-1.0);
819 for (
unsigned int blk = 0; blk < velocity.
GetBlocks().size(); ++blk)
821 auto &velocityBlock = velocity.
GetBlocks()[blk];
822 auto &rhsBlock = boundaryRhs.
GetBlocks()[blk];
824 velocityBlock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
826 rhsBlock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
828 const auto &expansions = collection.GetExpVector();
830 for (
unsigned int e = 0; e < expansions.size(); ++e)
835 expansions[e]->GetCoords(x, y, z);
836 for (
unsigned int p = 0; p < velocityBlock.GetNumData(); ++p)
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]);
843 velocityPtr[
id] = 1.0 - exponential * cosine;
844 velocityPtr[velocityBlock.CompSize() +
id] =
845 -(lambda / waveNumber) * exponential * sine;
849 rhsPtr[
id] = -lambda * exponential * cosine +
850 lambda * exponential * exponential;
851 rhsPtr[rhsBlock.CompSize() +
id] =
852 -(lambda * lambda / waveNumber) * exponential * sine;
860 op->SetVelocityContext(velocityExpList, velocityComponents);
861 op->SetKinvis(kinvis);
862 op->Update(boundaryRhs, velocity);
863 op->Apply(poissonRhs);
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)
875 auto bndExp = bndExpansions[n];
876 if (bndConditions[n]->GetBoundaryConditionType() ==
879 const auto npts = bndExp->GetTotPoints();
881 bndExp->GetCoords(x, y, z);
885 for (
unsigned int p = 0; p < npts; ++p)
887 pressureGradient[0][p] =
888 lambda * std::exp(-2.0 * lambda * x[p]);
892 bndExp->NormVectorIProductWRTBase(pressureGradient, bndCoeffs);
893 for (
unsigned int c = 0; c < bndExp->GetNcoeffs(); ++c)
895 const auto bndCoeff = bndCoeffOffset + c;
896 const auto localCoeff = coeffMap[bndCoeff];
897 expectedCoeffs[localCoeff] +=
898 (signChange ? coeffSign[bndCoeff] : 1.0) * bndCoeffs[c];
901 bndCoeffOffset += bndExp->GetNcoeffs();
905 "expected Kovasznay Poisson RHS",
908 MultiRegions::UnitInterleaveWidths(pressureExpList)),
909 pressureComponents, 1);
911 for (
unsigned int blk = 0; blk < expected.
GetBlocks().size(); ++blk)
913 auto &expectedBlock = expected.
GetBlocks()[blk];
915 expectedBlock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
917 const auto &expansions = collection.GetExpVector();
918 for (
unsigned int e = 0; e < expansions.size(); ++e)
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());
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)
935 maxDifference = std::max(maxDifference,
936 std::abs(actualValues[i] - expectedValues[i]));
938 BOOST_TEST(maxDifference < 1.0e-6);
953 auto session = CreateSession();
954 if (!
session->DefinesParameter(
"KovaLam"))
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)
965 velocityExpLists.push_back(
970 auto pressureExpList =
973 velocityExpLists[0]->SetDataWarehouse();
974 pressureExpList->SetDataWarehouse();
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();
983 velocityExpLists[0]->GetCoords(x, y, z);
984 std::vector<Array<OneD, double>> discreteVelocity;
985 for (
unsigned int d = 0; d < velocityComponents.size(); ++d)
988 for (
size_t p = 0; p < nq; ++p)
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]);
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());
1002 const auto velocityPhysBlocks =
1004 velocityExpLists[0],
1005 MultiRegions::UnitInterleaveWidths(velocityExpLists[0]));
1010 MultiRegions::UnitInterleaveWidths(pressureExpList)),
1011 pressureComponents, 1);
1013 "velocity", velocityPhysBlocks, velocityComponents, 1);
1015 "implicit predictor", velocityPhysBlocks, velocityComponents, 1);
1019 for (
unsigned int blk = 0; blk < predictor.
GetBlocks().size(); ++blk)
1021 auto &predictorBlock = predictor.
GetBlocks()[blk];
1024 .template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
1026 const auto &expansions = collection.GetExpVector();
1027 for (
unsigned int e = 0; e < expansions.size(); ++e)
1030 velocityExpLists[0]->GetPhys_Offset(expansions[e]->GetElmtId());
1031 for (
unsigned int d = 0; d < velocityComponents.size(); ++d)
1033 std::copy_n(discreteVelocity[d].begin() + offset,
1034 predictorBlock.GetNumData(),
1035 predictorPtr + d * predictorBlock.CompSize() +
1036 e * predictorBlock.GetNumData());
1042 static constexpr double scale = 1.5e4;
1044 pressureComponents);
1045 op->SetVelocityContext(velocityExpLists[0], velocityComponents);
1047 op->SetScale(scale);
1050 op->UpdateWithAcceleration(rhs, velocity, predictor);
1051 op->Apply(poissonRhs);
1053 double maxValue = 0.0;
1054 for (
const auto value : poissonRhs.
ToVector<
double>())
1056 maxValue = std::max(maxValue, std::abs(value));
1058 BOOST_TEST(maxValue < 1.0e-8);
1063 auto session = CreateSession();
1064 if (!
session->DefinesParameter(
"HOPSelectionTest"))
1069 auto velocityExpList =
1072 auto pressureExpList =
1075 velocityExpList->SetDataWarehouse();
1076 pressureExpList->SetDataWarehouse();
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 =
1084 MultiRegions::UnitInterleaveWidths(velocityExpList));
1090 MultiRegions::UnitInterleaveWidths(pressureExpList)),
1091 pressureComponents, 1);
1093 "HOPressure boundary RHS", velocityPhysBlocks, velocityComponents, 1);
1095 "manufactured velocity", velocityPhysBlocks, velocityComponents, 1);
1099 for (
unsigned int blk = 0; blk < velocity.
GetBlocks().size(); ++blk)
1101 auto &velocityBlock = velocity.
GetBlocks()[blk];
1102 auto &rhsBlock = boundaryRhs.
GetBlocks()[blk];
1104 velocityBlock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
1106 rhsBlock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
1108 const auto &expansions = collection.GetExpVector();
1110 for (
unsigned int e = 0; e < expansions.size(); ++e)
1115 expansions[e]->GetCoords(x, y, z);
1116 for (
unsigned int p = 0; p < velocityBlock.GetNumData(); ++p)
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;
1136 pressureComponents);
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);
1147 const auto actualValues = poissonRhs.
ToVector<
double>();
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};
1158 BOOST_REQUIRE_EQUAL(actualValues.size(), expectedValues.size());
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);
1165 BOOST_TEST(std::abs(maxExpected) > 0.1);
1167 for (std::size_t i = 0; i < actualValues.size(); ++i)
1169 BOOST_TEST(std::abs(actualValues[i] - expectedValues[i]) < 2.5e-10);
1178 CheckNeumannVelocityBoundaryFlux(
false);
1187 CheckNeumannVelocityBoundaryFlux(
true);
1195 auto session = CreateSession();
1196 if (!
session->DefinesParameter(
"HOPQuadratureThrowsTest"))
1201 auto velocityExpList =
1204 auto pressureExpList =
1207 velocityExpList->SetDataWarehouse();
1208 pressureExpList->SetDataWarehouse();
1210 const auto velocityComponents =
1211 GetVelocityComponents(
graph->GetMeshDimension());
1212 const std::vector<std::string> pressureComponents = {
"p"};
1215 pressureComponents);
1216 BOOST_CHECK_EXCEPTION(
1217 op->SetVelocityContext(velocityExpList, velocityComponents),
1220 return std::string(error.what())
1221 .find(
"share their quadrature points") !=
1226BOOST_AUTO_TEST_SUITE_END()
LibUtilities::SessionReaderSharedPtr session
SpatialDomains::MeshGraphSharedPtr graph
BOOST_TEST_GLOBAL_CONFIGURATION(GlobalConfiguration)
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...
static std::string GetOpExecSpace(std::shared_ptr< LibUtilities::SessionReader > session, const bool warn=true)
Return the execution space name ("opExecSpace") for an operator.
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
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)