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

#include <TestAvgAssmbScatr.hpp>

Inheritance diagram for TestAvgAssmbScatr< TData >:
[legend]

Public Member Functions

 TestAvgAssmbScatr ()=default
 
void SetTestCase ()
 Fill the input from the element centroids, which a partition does not change, set the expected solution to the legacy average and create the operator.
 
void ReshapeInput ()
 Reshape the input to the interleave width of the execution space.
 
bool RunTestCase ()
 Average the input in place into the output, and return whether the average keeps the interleave width of the input.
 
void RunTestCaseTwice ()
 Average the input once into the expected solution and that once more into the output, which must then equal the expected solution.
 
void RunTestCaseContinuous ()
 Average the continuous legacy average, which must be left unchanged.
 
void RunTestCaseReuseFirst ()
 First of two inputs to one operator: the continuous legacy average at interleave width 1, averaged in place in the output, which must be left unchanged.
 
void RunTestCaseReuseSecond ()
 Second of two inputs to the same operator: the discontinuous input at the interleave width of the execution space, averaged into the output, which must equal the legacy average.
 
void ExpectedSolution ()
 Set the expected solution to AvgAssemble() then GlobalToLocal() of the input, per component.
 
- Public Member Functions inherited from TestOp< TData, FieldState::Coeff, FieldState::Coeff, 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.
 

Public Attributes

std::shared_ptr< AvgAssmbScatrOp< TData > > fixt_op
 Operator under test, created once per test case.
 

Additional Inherited Members

- Static Public Member Functions inherited from TestOp< TData, FieldState::Coeff, FieldState::Coeff, 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.
 
- Protected Attributes inherited from TestOp< TData, FieldState::Coeff, FieldState::Coeff, 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
 

Detailed Description

template<typename TData>
class TestAvgAssmbScatr< TData >

Definition at line 63 of file TestAvgAssmbScatr.hpp.

Constructor & Destructor Documentation

◆ TestAvgAssmbScatr()

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

Member Function Documentation

◆ ExpectedSolution()

template<typename TData >
void TestAvgAssmbScatr< TData >::ExpectedSolution ( )
inline

Set the expected solution to AvgAssemble() then GlobalToLocal() of the input, per component.

Definition at line 190 of file TestAvgAssmbScatr.hpp.

191 {
192 std::vector<std::string> variables = this->session->GetVariables();
193 std::vector<std::shared_ptr<MultiRegions::ContField>> contfields;
195 unsigned int numComp = this->fixt_in->GetNumComponents();
196
197 for (auto &variable : variables)
198 {
199 contfields.push_back(
201 this->session, graph, variable, true, false,
203 }
204
205 size_t ncoeffs = this->fixt_explist->GetNcoeffs();
206 Array<OneD, double> incoeffs = this->fixt_in->ToArray();
207 Array<OneD, double> outcoeffs(numComp * ncoeffs);
208
209 for (unsigned int i = 0; i < variables.size(); ++i)
210 {
212 auto map = contfields[i]->GetLocalToGlobalMap();
213 map->AvgAssemble(incoeffs + i * ncoeffs,
214 tmp = outcoeffs + i * ncoeffs);
215 map->GlobalToLocal(outcoeffs + i * ncoeffs,
216 tmp = outcoeffs + i * ncoeffs);
217 }
218 this->fixt_expected->template CopyArray<NektarSpaces::HostSpace>(
219 outcoeffs);
220 }
SpatialDomains::MeshGraphSharedPtr graph
Nektar::Array< Nektar::OneD, TDataOut > ToArray()
Copy the data to a Nektar::Array, component by component and element by element, without padding,...
unsigned int GetNumComponents() const
Gets the number of components for a vector field.
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true, SpatialDomains::MeshGraphSharedPtr partitionedGraph=nullptr)
std::shared_ptr< MultiRegions::ExpList > fixt_explist
Definition TestOp.hpp:439

References Nektar::Collections::eNoCollection, TestOp< TData, FieldState::Coeff, FieldState::Coeff, ContField >::fixt_expected, TestOp< TData, FieldState::Coeff, FieldState::Coeff, ContField >::fixt_explist, TestOp< TData, FieldState::Coeff, FieldState::Coeff, ContField >::fixt_in, Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), graph, Nektar::SpatialDomains::MeshGraphIO::Read(), TestOp< TData, FieldState::Coeff, FieldState::Coeff, ContField >::session, and Nektar::LibUtilities::Field< TData, TState >::ToArray().

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

◆ ReshapeInput()

template<typename TData >
void TestAvgAssmbScatr< TData >::ReshapeInput ( )
inline

Reshape the input to the interleave width of the execution space.

Definition at line 124 of file TestAvgAssmbScatr.hpp.

125 {
126 std::string execStr = Operator<TData>::GetOpExecSpace(this->session);
127 if (execStr == "AVX")
128 {
129 this->fixt_in->ReshapeStorage(
130 NektarSpaces::GetVectorWidth<TData>(execStr), execStr);
131 }
132 }
void ReshapeStorage(const unsigned int &interleaveWidth, const std::string &execSpace)
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 TestOp< TData, FieldState::Coeff, FieldState::Coeff, ContField >::fixt_in, Nektar::MultiRegions::Operator< TData >::GetOpExecSpace(), Nektar::LibUtilities::Field< TData, TState >::ReshapeStorage(), and TestOp< TData, FieldState::Coeff, FieldState::Coeff, ContField >::session.

Referenced by TestAvgAssmbScatr< TData >::RunTestCase(), TestAvgAssmbScatr< TData >::RunTestCaseContinuous(), TestAvgAssmbScatr< TData >::RunTestCaseReuseSecond(), and TestAvgAssmbScatr< TData >::RunTestCaseTwice().

◆ RunTestCase()

template<typename TData >
bool TestAvgAssmbScatr< TData >::RunTestCase ( )
inline

Average the input in place into the output, and return whether the average keeps the interleave width of the input.

Definition at line 136 of file TestAvgAssmbScatr.hpp.

137 {
138 ReshapeInput();
139 const auto inInterleaveWidths = this->fixt_in->GetInterleaveWidth();
140
141 fixt_op->Apply(*this->fixt_in);
142 this->fixt_out->template Copy<NektarSpaces::HostSpace>(*this->fixt_in);
143
144 return this->fixt_in->GetInterleaveWidth() == inInterleaveWidths;
145 }
std::vector< unsigned int > GetInterleaveWidth(void) const
void ReshapeInput()
Reshape the input to the interleave width of the execution space.
std::shared_ptr< AvgAssmbScatrOp< TData > > fixt_op
Operator under test, created once per test case.

References TestOp< TData, FieldState::Coeff, FieldState::Coeff, ContField >::fixt_in, TestOp< TData, FieldState::Coeff, FieldState::Coeff, ContField >::fixt_out, Nektar::LibUtilities::Field< TData, TState >::GetInterleaveWidth(), and TestAvgAssmbScatr< TData >::ReshapeInput().

◆ RunTestCaseContinuous()

template<typename TData >
void TestAvgAssmbScatr< TData >::RunTestCaseContinuous ( )
inline

Average the continuous legacy average, which must be left unchanged.

Definition at line 160 of file TestAvgAssmbScatr.hpp.

161 {
162 this->fixt_in->template Copy<NektarSpaces::HostSpace>(
163 *this->fixt_expected);
164 ReshapeInput();
165 fixt_op->Apply(*this->fixt_in);
166 this->fixt_out->template Copy<NektarSpaces::HostSpace>(*this->fixt_in);
167 }

References TestOp< TData, FieldState::Coeff, FieldState::Coeff, ContField >::fixt_expected, TestOp< TData, FieldState::Coeff, FieldState::Coeff, ContField >::fixt_in, TestOp< TData, FieldState::Coeff, FieldState::Coeff, ContField >::fixt_out, and TestAvgAssmbScatr< TData >::ReshapeInput().

◆ RunTestCaseReuseFirst()

template<typename TData >
void TestAvgAssmbScatr< TData >::RunTestCaseReuseFirst ( )
inline

First of two inputs to one operator: the continuous legacy average at interleave width 1, averaged in place in the output, which must be left unchanged.

Definition at line 172 of file TestAvgAssmbScatr.hpp.

173 {
174 this->fixt_out->template Copy<NektarSpaces::HostSpace>(
175 *this->fixt_expected);
176 fixt_op->Apply(*this->fixt_out);
177 }

References TestOp< TData, FieldState::Coeff, FieldState::Coeff, ContField >::fixt_expected, and TestOp< TData, FieldState::Coeff, FieldState::Coeff, ContField >::fixt_out.

◆ RunTestCaseReuseSecond()

template<typename TData >
void TestAvgAssmbScatr< TData >::RunTestCaseReuseSecond ( )
inline

Second of two inputs to the same operator: the discontinuous input at the interleave width of the execution space, averaged into the output, which must equal the legacy average.

Definition at line 182 of file TestAvgAssmbScatr.hpp.

183 {
184 ReshapeInput();
185 fixt_op->Apply(*this->fixt_in, *this->fixt_out);
186 }

References TestOp< TData, FieldState::Coeff, FieldState::Coeff, ContField >::fixt_in, TestOp< TData, FieldState::Coeff, FieldState::Coeff, ContField >::fixt_out, and TestAvgAssmbScatr< TData >::ReshapeInput().

◆ RunTestCaseTwice()

template<typename TData >
void TestAvgAssmbScatr< TData >::RunTestCaseTwice ( )
inline

Average the input once into the expected solution and that once more into the output, which must then equal the expected solution.

Definition at line 149 of file TestAvgAssmbScatr.hpp.

150 {
151 ReshapeInput();
152 fixt_op->Apply(*this->fixt_in);
153 this->fixt_expected->template Copy<NektarSpaces::HostSpace>(
154 *this->fixt_in);
155 fixt_op->Apply(*this->fixt_in);
156 this->fixt_out->template Copy<NektarSpaces::HostSpace>(*this->fixt_in);
157 }

References TestOp< TData, FieldState::Coeff, FieldState::Coeff, ContField >::fixt_expected, TestOp< TData, FieldState::Coeff, FieldState::Coeff, ContField >::fixt_in, TestAvgAssmbScatr< TData >::fixt_op, TestOp< TData, FieldState::Coeff, FieldState::Coeff, ContField >::fixt_out, and TestAvgAssmbScatr< TData >::ReshapeInput().

◆ SetTestCase()

template<typename TData >
void TestAvgAssmbScatr< TData >::SetTestCase ( )
inline

Fill the input from the element centroids, which a partition does not change, set the expected solution to the legacy average and create the operator.

Definition at line 76 of file TestAvgAssmbScatr.hpp.

77 {
78 for (unsigned int blk = 0; blk < this->fixt_in->GetBlocks().size();
79 ++blk)
80 {
81 auto &block = this->fixt_in->GetBlocks()[blk];
82 auto collection =
84 const auto &expansions = collection.GetExpVector();
85 auto inptr =
86 block.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
87 for (unsigned int nc = 0; nc < this->fixt_in->GetNumComponents();
88 ++nc)
89 {
90 for (size_t el = 0, cnt = 0; el < expansions.size(); ++el)
91 {
92 const auto npts = expansions[el]->GetTotPoints();
93 Array<OneD, NekDouble> x(npts, 0.0), y(npts, 0.0),
94 z(npts, 0.0);
95 expansions[el]->GetCoords(x, y, z);
96 double cx = 0.0, cy = 0.0, cz = 0.0;
97 for (int q = 0; q < npts; ++q)
98 {
99 cx += x[q];
100 cy += y[q];
101 cz += z[q];
102 }
103 cx /= npts;
104 cy /= npts;
105 cz /= npts;
106 for (unsigned int coeff = 0; coeff < block.GetNumData();
107 ++coeff, ++cnt)
108 {
109 inptr[cnt] =
110 AvgAssmbScatrTestFn<TData>(cx, cy, cz, coeff, nc);
111 }
112 }
113 inptr += block.CompSize();
114 }
115 }
116
118
120 this->session->GetVariables());
121 }
SpatialDomains::Geometry * el
std::vector< BlockAccessor< TData, TState > > & GetBlocks()
Get BlockAccessors for the field.
static std::shared_ptr< AvgAssmbScatrOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="")
Create an averaging assemble-scatter operator through the operator factory.
void ExpectedSolution()
Set the expected solution to AvgAssemble() then GlobalToLocal() of the input, per component.
Collections::Collection GetCollection(MultiRegions::ExpListSharedPtr expansionList, unsigned int block_idx)

References Nektar::MultiRegions::AvgAssmbScatrOp< TData >::Create(), el, TestAvgAssmbScatr< TData >::ExpectedSolution(), TestOp< TData, FieldState::Coeff, FieldState::Coeff, ContField >::fixt_explist, TestOp< TData, FieldState::Coeff, FieldState::Coeff, ContField >::fixt_in, TestAvgAssmbScatr< TData >::fixt_op, Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::MultiRegions::GetCollection(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), and TestOp< TData, FieldState::Coeff, FieldState::Coeff, ContField >::session.

Member Data Documentation

◆ fixt_op

template<typename TData >
std::shared_ptr<AvgAssmbScatrOp<TData> > TestAvgAssmbScatr< TData >::fixt_op

Operator under test, created once per test case.

Definition at line 71 of file TestAvgAssmbScatr.hpp.

Referenced by TestAvgAssmbScatr< TData >::RunTestCaseTwice(), and TestAvgAssmbScatr< TData >::SetTestCase().