Nektar++
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
TestNeumann< TData > Class Template Reference

#include <TestNeumann.hpp>

Inheritance diagram for TestNeumann< TData >:
[legend]

Public Member Functions

 TestNeumann ()=default
 
void SetTestCase (const double time=0.0)
 
void RunTestCase (const double time=0.0)
 
void ExpectedSolution (const double time=0.0)
 
bool CompareSurfaceIntegral (const double tol)
 
- Public Member Functions inherited from TestOp< TData, FieldState::Coeff, FieldState::Coeff, MultiRegions::ContField >
 TestOp ()=default
 
virtual ~TestOp ()
 
void Configure (void)
 
void Configure3DH1 (const unsigned int nhomo=1)
 
void Configure3DH2 (const unsigned int nhomoY=1, const unsigned int nhomoZ=1)
 
void SetSession (void)
 
void SetExpList (void)
 
void SetExpList3DH1 (const unsigned int nhomo=1)
 
void SetExpList3DH2 (const unsigned int nhomoY=1, const unsigned int nhomoZ=1)
 
virtual void SetFixture (const unsigned int nhomo)
 
virtual bool Compare (TData tol)
 Compare this field to another field, with absolute tolerance tol. The two must have the same blocks and components; their interleave widths may differ.
 

Protected Attributes

std::vector< TData > surfaceIntegral
 
std::vector< double > expectedSurfaceIntegral
 
std::string excludedUserDefinedType = ""
 
bool isExcludedAfterUse = false
 
- Protected Attributes inherited from TestOp< TData, FieldState::Coeff, FieldState::Coeff, MultiRegions::ContField >
std::string meshName
 
Field< TData, stateIn > * fixt_in
 
Field< TData, stateOut > * fixt_out
 
Field< TData, stateIn > * fixt_out_2
 
Field< TData, stateOut > * fixt_expected
 
std::shared_ptr< MultiRegions::ExpList > fixt_explist
 
LibUtilities::SessionReaderSharedPtr session
 

Additional Inherited Members

- Static Public Member Functions inherited from TestOp< TData, FieldState::Coeff, FieldState::Coeff, MultiRegions::ContField >
static void MixInterleaveWidths (TField &field)
 Put the blocks of field at alternating interleave widths, the execution space's vector width on even blocks and 1 on odd ones, reshaping the data in place: a field whose blocks differ in width, for an operator that must read any mix, such as the trace flux, which addresses each trace at the width of the element block it lies in. On Serial every width is 1 and nothing changes.
 

Detailed Description

template<typename TData>
class TestNeumann< TData >

Definition at line 48 of file TestNeumann.hpp.

Constructor & Destructor Documentation

◆ TestNeumann()

template<typename TData >
TestNeumann< TData >::TestNeumann ( )
default

Member Function Documentation

◆ CompareSurfaceIntegral()

template<typename TData >
bool TestNeumann< TData >::CompareSurfaceIntegral ( const double  tol)
inline

Definition at line 167 of file TestNeumann.hpp.

168 {
169 if (surfaceIntegral.size() != expectedSurfaceIntegral.size())
170 {
171 std::cout << "Mismatch of number of components." << std::endl;
172 return false;
173 }
174
175 bool match = true;
176 for (size_t nc = 0; nc < surfaceIntegral.size(); ++nc)
177 {
178 const double expected = expectedSurfaceIntegral[nc];
179 const double error = std::abs(surfaceIntegral[nc] - expected);
180 if (error > tol * std::max(1.0, std::abs(expected)))
181 {
182 std::cout << "Surface integral of component " << nc << ": "
183 << surfaceIntegral[nc] << ", expected " << expected
184 << std::endl;
185 match = false;
186 }
187 }
188 return match;
189 }
std::vector< double > expectedSurfaceIntegral
std::vector< TData > surfaceIntegral

References TestNeumann< TData >::expectedSurfaceIntegral, and TestNeumann< TData >::surfaceIntegral.

◆ ExpectedSolution()

template<typename TData >
void TestNeumann< TData >::ExpectedSolution ( const double  time = 0.0)
inline

Definition at line 98 of file TestNeumann.hpp.

99 {
100 // Get variables
101 auto variables = this->fixt_explist->GetSession()->GetVariables();
102 unsigned int nvars = variables.size();
103
104 // Get number of components
105 unsigned int ncomp = this->fixt_in->GetNumComponents();
106 unsigned int ncoeffs = this->fixt_explist->GetNcoeffs();
107 Array<OneD, double> outcoeffs(ncomp * ncoeffs, 0.0);
108
109 ASSERTL0(nvars == ncomp,
110 "Number of components and number fields in "
111 "session file must be equal. Instead they are Ncomp = " +
112 std::to_string(ncomp) + " and Nfields = " +
113 std::to_string(nvars) + ", respectively.")
114
115 // Impose Neumann BCs for each component
116 Array<OneD, double> tmp;
117 expectedSurfaceIntegral.assign(ncomp, 0.0);
118 for (unsigned int nc = 0; nc < ncomp; ++nc)
119 {
120 // Setup dedicated explist for each variable to evaluate correct BCs
121 MultiRegions::ContField bcfield(this->fixt_explist->GetSession(),
122 this->fixt_explist->GetGraph(),
123 variables[nc], true, false,
125
126 // Update BC for this variable, leave out the regions excluded
127 // from the operator, and impose
128 bcfield.EvaluateBoundaryConditions(time, variables[nc]);
129 const auto &bndConditions = bcfield.GetBndConditions();
130 const auto &bndExpansions = bcfield.GetBndCondExpansions();
131 for (unsigned int n = 0; n < bndExpansions.size(); ++n)
132 {
133 if (!excludedUserDefinedType.empty() &&
134 StringUtils::IEquals(bndConditions[n]->GetUserDefined(),
136 {
137 Vmath::Zero(bndExpansions[n]->GetNcoeffs(),
138 bndExpansions[n]->UpdateCoeffs(), 1);
139 }
140 else if (bndConditions[n]->GetBoundaryConditionType() ==
142 {
143 // The value of a point region is held in its
144 // coefficients, that of any other region at its points.
145 if (bndExpansions[n]->GetShapeDimension() == 0)
146 {
148 Vmath::Vsum(bndExpansions[n]->GetNcoeffs(),
149 bndExpansions[n]->GetCoeffs(), 1);
150 }
151 else
152 {
154 bndExpansions[n]->Integral(
155 bndExpansions[n]->GetPhys());
156 }
157 }
158 }
159 bcfield.ImposeNeumannConditions(tmp = outcoeffs + nc * ncoeffs);
160 }
161 this->fixt_expected->template CopyArray<NektarSpaces::HostSpace>(
162 outcoeffs);
163 }
#define ASSERTL0(condition, msg)
unsigned int GetNumComponents() const
Gets the number of components for a vector field.
This class is the abstraction of a global continuous two- dimensional spectral/hp element expansion w...
Definition ContField.h:60
std::string excludedUserDefinedType
bool IEquals(std::string_view a, std::string_view b)
T Vsum(int n, const T *x, const int incx)
Subtract return sum(x)
Definition Vmath.hpp:611
void Zero(int n, T *x, const int incx)
Zero vector.
Definition Vmath.hpp:275

References ASSERTL0, Nektar::SpatialDomains::eNeumann, Nektar::Collections::eNoCollection, Nektar::MultiRegions::ExpList::EvaluateBoundaryConditions(), TestNeumann< TData >::excludedUserDefinedType, TestNeumann< TData >::expectedSurfaceIntegral, TestOp< TData, FieldState::Coeff, FieldState::Coeff, MultiRegions::ContField >::fixt_expected, TestOp< TData, FieldState::Coeff, FieldState::Coeff, MultiRegions::ContField >::fixt_explist, TestOp< TData, FieldState::Coeff, FieldState::Coeff, MultiRegions::ContField >::fixt_in, Nektar::MultiRegions::ExpList::GetBndCondExpansions(), Nektar::MultiRegions::ExpList::GetBndConditions(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), Nektar::StringUtils::IEquals(), Nektar::MultiRegions::ExpList::ImposeNeumannConditions(), Vmath::Vsum(), and Vmath::Zero().

Referenced by TestNeumann< TData >::SetTestCase().

◆ RunTestCase()

template<typename TData >
void TestNeumann< TData >::RunTestCase ( const double  time = 0.0)
inline

Definition at line 63 of file TestNeumann.hpp.

64 {
65 std::string execStr = Operator<TData>::GetOpExecSpace(this->session);
66
67 if (execStr == "AVX" || execStr == "Device")
68 {
70 NektarSpaces::GetVectorWidth<TData>(execStr));
71 }
72
74 this->session->GetVariables());
75 if (!excludedUserDefinedType.empty())
76 {
78 {
79 op->UpdateBndCoeffs(time);
80 }
81 op->ExcludeUserDefinedType(excludedUserDefinedType);
82 }
83 op->UpdateBndCoeffs(time);
84 op->Apply(*this->fixt_out);
85
86 // The surface integral is summed in the memory space of the
87 // execution space, and read back here.
88 const size_t nComp = this->session->GetVariables().size();
89 LibUtilities::MemoryRegion<TData> data("Neumann surface integral",
90 nComp, eHostPinned);
91 data.template Initialize<NektarSpaces::HostSpace>(TData{0});
92 op->AddNeumannSurfaceIntegral(data);
93 auto dataPtr =
94 data.template GetPtr<NektarSpaces::HostSpace, ReadOnly>();
95 surfaceIntegral.assign(dataPtr, dataPtr + nComp);
96 }
void SetInterleaveWidth(const unsigned int &interleaveWidth)
A MemoryRegion represents a memory region.
static std::shared_ptr< NeuBndCondOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="")
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
bool isExcludedAfterUse

References Nektar::MultiRegions::NeuBndCondOp< TData >::Create(), Nektar::eHostPinned, TestNeumann< TData >::excludedUserDefinedType, TestOp< TData, FieldState::Coeff, FieldState::Coeff, MultiRegions::ContField >::fixt_explist, TestOp< TData, FieldState::Coeff, FieldState::Coeff, MultiRegions::ContField >::fixt_out, Nektar::MultiRegions::Operator< TData >::GetOpExecSpace(), TestNeumann< TData >::isExcludedAfterUse, TestOp< TData, FieldState::Coeff, FieldState::Coeff, MultiRegions::ContField >::session, Nektar::LibUtilities::Field< TData, TState >::SetInterleaveWidth(), and TestNeumann< TData >::surfaceIntegral.

◆ SetTestCase()

template<typename TData >
void TestNeumann< TData >::SetTestCase ( const double  time = 0.0)
inline

Definition at line 54 of file TestNeumann.hpp.

55 {
56 // Set initial conditions.
57 this->fixt_out->template Initialize<NektarSpaces::HostSpace>(0.0);
58
59 // Compute expected solution.
60 ExpectedSolution(time);
61 }
void ExpectedSolution(const double time=0.0)

References TestNeumann< TData >::ExpectedSolution(), and TestOp< TData, FieldState::Coeff, FieldState::Coeff, MultiRegions::ContField >::fixt_out.

Member Data Documentation

◆ excludedUserDefinedType

template<typename TData >
std::string TestNeumann< TData >::excludedUserDefinedType = ""
protected

◆ expectedSurfaceIntegral

template<typename TData >
std::vector<double> TestNeumann< TData >::expectedSurfaceIntegral
protected

◆ isExcludedAfterUse

template<typename TData >
bool TestNeumann< TData >::isExcludedAfterUse = false
protected

Definition at line 199 of file TestNeumann.hpp.

Referenced by TestNeumann< TData >::RunTestCase().

◆ surfaceIntegral

template<typename TData >
std::vector<TData> TestNeumann< TData >::surfaceIntegral
protected