Nektar++
Loading...
Searching...
No Matches
Classes | Macros | Functions
TestHOPressureBndCond.cpp File Reference
#include <boost/test/included/unit_test.hpp>
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <utility>
#include <vector>
#include <LibUtilities/BasicUtils/SessionReader.h>
#include <MultiRegions/ContField.h>
#include <SpatialDomains/MeshGraphIO.h>
#include <IncNavierStokesSolverRedesign/BoundaryConditions/HOPressureBndCond/HOPressureBndCondOp.hpp>
#include <LibUtilities/Backends/Backends.hpp>
#include <LibUtilities/BasicUtils/Field/Field.hpp>
#include <LibUtilities/BasicUtils/StringUtils.hpp>

Go to the source code of this file.

Classes

struct  GlobalConfiguration
 

Macros

#define BOOST_TEST_MODULE   TestHOPressureBndCond
 
#define NOMINMAX
 

Functions

 BOOST_TEST_GLOBAL_CONFIGURATION (GlobalConfiguration)
 
 BOOST_AUTO_TEST_CASE (factory_create_and_empty_apply_preserves_rhs)
 
 BOOST_AUTO_TEST_CASE (update_then_apply_zero_contribution_preserves_rhs)
 
 BOOST_AUTO_TEST_CASE (update_then_apply_manufactured_boundary_flux)
 
 BOOST_AUTO_TEST_CASE (update_then_apply_acceleration_boundary_flux)
 
 BOOST_AUTO_TEST_CASE (update_then_apply_interleaved_matches_width_one)
 
 BOOST_AUTO_TEST_CASE (update_then_apply_kovasznay_boundary_flux)
 
 BOOST_AUTO_TEST_CASE (update_then_apply_kovasznay_discrete_boundary_velocity)
 
 BOOST_AUTO_TEST_CASE (update_then_apply_selection_respects_hop_tag)
 
 BOOST_AUTO_TEST_CASE (update_then_apply_neumann_velocity_boundary_flux)
 
 BOOST_AUTO_TEST_CASE (update_weak_then_apply_neumann_velocity_boundary_flux)
 
 BOOST_AUTO_TEST_CASE (set_velocity_context_throws_for_different_quadrature)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   TestHOPressureBndCond

Definition at line 35 of file TestHOPressureBndCond.cpp.

◆ NOMINMAX

#define NOMINMAX

Definition at line 38 of file TestHOPressureBndCond.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/11]

BOOST_AUTO_TEST_CASE ( factory_create_and_empty_apply_preserves_rhs  )

Definition at line 342 of file TestHOPressureBndCond.cpp.

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);
358 rhs.Initialize<NektarSpaces::HostSpace>(1.25);
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}
LibUtilities::SessionReaderSharedPtr session
SpatialDomains::MeshGraphSharedPtr graph
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.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true, SpatialDomains::MeshGraphSharedPtr partitionedGraph=nullptr)
LibUtilities::SessionReaderSharedPtr CreateSession()
template std::vector< BlockAttributes< FieldState::Coeff > > GetBlockAttributes< double, FieldState::Coeff >(const MultiRegions::ExpListSharedPtr explist, const std::vector< unsigned int > &interleave_widths)

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::HOPressureBndCondOp< TData >::Create(), Nektar::Collections::eNoCollection, Nektar::MultiRegions::GetBlockAttributes< double, FieldState::Coeff >(), graph, Nektar::LibUtilities::Field< TData, TState >::Initialize(), Nektar::SpatialDomains::MeshGraphIO::Read(), session, and Nektar::LibUtilities::Field< TData, TState >::ToVector().

◆ BOOST_AUTO_TEST_CASE() [2/11]

BOOST_AUTO_TEST_CASE ( set_velocity_context_throws_for_different_quadrature  )

Definition at line 1193 of file TestHOPressureBndCond.cpp.

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}

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::HOPressureBndCondOp< TData >::Create(), Nektar::Collections::eNoCollection, graph, Nektar::SpatialDomains::MeshGraphIO::Read(), and session.

◆ BOOST_AUTO_TEST_CASE() [3/11]

BOOST_AUTO_TEST_CASE ( update_then_apply_acceleration_boundary_flux  )

Definition at line 583 of file TestHOPressureBndCond.cpp.

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}
std::vector< TDataOut, Alloc > ToVector()
Copy the data to a std::vector, component by component and element by element, without padding,...
template std::vector< BlockAttributes< FieldState::Phys > > GetBlockAttributes< double, FieldState::Phys >(const MultiRegions::ExpListSharedPtr explist, const std::vector< unsigned int > &interleave_widths)
std::vector< double > d(NPUPPER *NPUPPER)

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::HOPressureBndCondOp< TData >::Create(), Nektar::Collections::eNoCollection, Nektar::MultiRegions::GetBlockAttributes< double, FieldState::Coeff >(), Nektar::MultiRegions::GetBlockAttributes< double, FieldState::Phys >(), Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), graph, Nektar::LibUtilities::Field< TData, TState >::Initialize(), Nektar::SpatialDomains::MeshGraphIO::Read(), session, and Nektar::LibUtilities::Field< TData, TState >::ToVector().

◆ BOOST_AUTO_TEST_CASE() [4/11]

BOOST_AUTO_TEST_CASE ( update_then_apply_interleaved_matches_width_one  )

Definition at line 673 of file TestHOPressureBndCond.cpp.

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}
Common base class of the operator family interfaces: holds the expansion list, component names and da...
Definition Operator.hpp:100

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::LibUtilities::Field< TData, TState >::CopyVector(), Nektar::HOPressureBndCondOp< TData >::Create(), Nektar::Collections::eNoCollection, Nektar::MultiRegions::GetBlockAttributes< double, FieldState::Coeff >(), Nektar::MultiRegions::GetBlockAttributes< double, FieldState::Phys >(), Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), graph, Nektar::LibUtilities::Field< TData, TState >::Initialize(), Nektar::SpatialDomains::MeshGraphIO::Read(), session, Nektar::LibUtilities::Field< TData, TState >::SetInterleaveWidth(), and Nektar::LibUtilities::Field< TData, TState >::ToVector().

◆ BOOST_AUTO_TEST_CASE() [5/11]

BOOST_AUTO_TEST_CASE ( update_then_apply_kovasznay_boundary_flux  )

Definition at line 778 of file TestHOPressureBndCond.cpp.

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}
int64_t id
Collections::Collection GetCollection(MultiRegions::ExpListSharedPtr expansionList, unsigned int block_idx)
std::vector< double > p(NPUPPER)

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::HOPressureBndCondOp< TData >::Create(), Nektar::SpatialDomains::eNeumann, Nektar::Collections::eNoCollection, Nektar::MultiRegions::GetBlockAttributes< double, FieldState::Coeff >(), Nektar::MultiRegions::GetBlockAttributes< double, FieldState::Phys >(), Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::MultiRegions::GetCollection(), graph, id, Nektar::LibUtilities::Field< TData, TState >::Initialize(), Nektar::SpatialDomains::MeshGraphIO::Read(), session, and Nektar::LibUtilities::Field< TData, TState >::ToVector().

◆ BOOST_AUTO_TEST_CASE() [6/11]

BOOST_AUTO_TEST_CASE ( update_then_apply_kovasznay_discrete_boundary_velocity  )

Definition at line 951 of file TestHOPressureBndCond.cpp.

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}
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
STL namespace.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::HOPressureBndCondOp< TData >::Create(), Nektar::Collections::eNoCollection, Nektar::MultiRegions::GetBlockAttributes< double, FieldState::Coeff >(), Nektar::MultiRegions::GetBlockAttributes< double, FieldState::Phys >(), Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::MultiRegions::GetCollection(), graph, Nektar::LibUtilities::Field< TData, TState >::Initialize(), Nektar::SpatialDomains::MeshGraphIO::Read(), session, and Nektar::LibUtilities::Field< TData, TState >::ToVector().

◆ BOOST_AUTO_TEST_CASE() [7/11]

BOOST_AUTO_TEST_CASE ( update_then_apply_manufactured_boundary_flux  )

Definition at line 431 of file TestHOPressureBndCond.cpp.

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}
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

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::HOPressureBndCondOp< TData >::Create(), Nektar::Collections::eNoCollection, Nektar::MultiRegions::GetBlockAttributes< double, FieldState::Coeff >(), Nektar::MultiRegions::GetBlockAttributes< double, FieldState::Phys >(), Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::MultiRegions::GetCollection(), Nektar::MultiRegions::Operator< TData >::GetOpExecSpace(), graph, id, Nektar::LibUtilities::Field< TData, TState >::Initialize(), Nektar::SpatialDomains::MeshGraphIO::Read(), Nektar::LibUtilities::Field< TData, TState >::ReshapeStorage(), session, and Nektar::LibUtilities::Field< TData, TState >::ToVector().

◆ BOOST_AUTO_TEST_CASE() [8/11]

BOOST_AUTO_TEST_CASE ( update_then_apply_neumann_velocity_boundary_flux  )

Definition at line 1176 of file TestHOPressureBndCond.cpp.

1177{
1178 CheckNeumannVelocityBoundaryFlux(false);
1179}

◆ BOOST_AUTO_TEST_CASE() [9/11]

BOOST_AUTO_TEST_CASE ( update_then_apply_selection_respects_hop_tag  )

Definition at line 1061 of file TestHOPressureBndCond.cpp.

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}

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::HOPressureBndCondOp< TData >::Create(), Nektar::Collections::eNoCollection, Nektar::MultiRegions::GetBlockAttributes< double, FieldState::Coeff >(), Nektar::MultiRegions::GetBlockAttributes< double, FieldState::Phys >(), Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::MultiRegions::GetCollection(), graph, id, Nektar::LibUtilities::Field< TData, TState >::Initialize(), Nektar::SpatialDomains::MeshGraphIO::Read(), session, and Nektar::LibUtilities::Field< TData, TState >::ToVector().

◆ BOOST_AUTO_TEST_CASE() [10/11]

BOOST_AUTO_TEST_CASE ( update_then_apply_zero_contribution_preserves_rhs  )

Definition at line 374 of file TestHOPressureBndCond.cpp.

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
410 rhs.Initialize<NektarSpaces::HostSpace>(1.25);
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}

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::HOPressureBndCondOp< TData >::Create(), Nektar::Collections::eNoCollection, Nektar::MultiRegions::GetBlockAttributes< double, FieldState::Coeff >(), Nektar::MultiRegions::GetBlockAttributes< double, FieldState::Phys >(), graph, Nektar::LibUtilities::Field< TData, TState >::Initialize(), Nektar::SpatialDomains::MeshGraphIO::Read(), session, and Nektar::LibUtilities::Field< TData, TState >::ToVector().

◆ BOOST_AUTO_TEST_CASE() [11/11]

BOOST_AUTO_TEST_CASE ( update_weak_then_apply_neumann_velocity_boundary_flux  )

Definition at line 1185 of file TestHOPressureBndCond.cpp.

1186{
1187 CheckNeumannVelocityBoundaryFlux(true);
1188}

◆ BOOST_TEST_GLOBAL_CONFIGURATION()

BOOST_TEST_GLOBAL_CONFIGURATION ( GlobalConfiguration  )