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

#include <TestFwdTrans.hpp>

Inheritance diagram for TestFwdTrans< TData >:
[legend]

Public Member Functions

 TestFwdTrans ()=default
 
void SetTestCase ()
 
void RunTestCase (const std::string &method)
 
void ExpectedSolution ()
 
- Public Member Functions inherited from TestLinearSolver< TData >
 TestLinearSolver ()=default
 
virtual ~TestLinearSolver ()=default
 
void Configure ()
 Read the session, build the expansion list and allocate the fields the test cases work on.
 
bool Compare (TData tol)
 Compare the computed field to the expected one, with absolute tolerance tol. The two must have the same blocks and components; their interleave widths may differ.
 

Protected Attributes

unsigned int m_coordDim
 
- Protected Attributes inherited from TestLinearSolver< TData >
std::string m_meshName = ""
 
SessionReaderSharedPtr m_session
 
ExpListSharedPtr m_expList
 
Field< TData, FieldState::Phys > m_in
 
Field< TData, FieldState::Coeff > m_out
 
Field< TData, FieldState::Coeff > m_expected
 

Additional Inherited Members

- Protected Member Functions inherited from TestLinearSolver< TData >
void SetSession ()
 
void SetExpList ()
 
void SetFixture ()
 

Detailed Description

template<typename TData>
class TestFwdTrans< TData >

Definition at line 46 of file TestFwdTrans.hpp.

Constructor & Destructor Documentation

◆ TestFwdTrans()

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

Member Function Documentation

◆ ExpectedSolution()

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

Definition at line 173 of file TestFwdTrans.hpp.

174 {
175 // Calculate expected result from Nektar++.
176 const unsigned int numComp =
177 this->m_in.GetNumComponents() * this->m_in.GetNumHomoModes();
178 const size_t nphys = this->m_expList->GetTotPoints();
179 const size_t ncoeffs = this->m_expList->GetNcoeffs();
180 const auto &variables = this->m_session->GetVariables();
181
182 // Setup input/output arrays
183 Array<OneD, TData> inphys = this->m_in.ToArray();
184 Array<OneD, TData> outcoeffs(numComp * ncoeffs, 0.0);
185
186 // Solve each component separately
188 for (unsigned int n = 0; n < numComp; ++n)
189 {
191 this->m_session, graph, variables[n % variables.size()], true,
193 Array<OneD, TData> inphysVar = inphys + n * nphys;
194 Array<OneD, TData> outcoeffsVar = outcoeffs + n * ncoeffs;
195 expListVar->FwdTrans(inphysVar, outcoeffsVar);
196 }
197
198 // Copy solution back
199 this->m_expected.template CopyArray<NektarSpaces::HostSpace>(outcoeffs);
200 }
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 GetNumHomoModes() const
Gets the number of homogeneous modes.
unsigned int GetNumComponents() const
Gets the number of components for a vector field.
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)
Field< TData, FieldState::Phys > m_in
ExpListSharedPtr m_expList
SessionReaderSharedPtr m_session
Field< TData, FieldState::Coeff > m_expected

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::Collections::eNoCollection, Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), Nektar::LibUtilities::Field< TData, TState >::GetNumHomoModes(), graph, TestLinearSolver< TData >::m_expected, TestLinearSolver< TData >::m_expList, TestLinearSolver< TData >::m_in, TestLinearSolver< TData >::m_session, Nektar::SpatialDomains::MeshGraphIO::Read(), and Nektar::LibUtilities::Field< TData, TState >::ToArray().

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

◆ RunTestCase()

template<typename TData >
void TestFwdTrans< TData >::RunTestCase ( const std::string &  method)
inline

Definition at line 146 of file TestFwdTrans.hpp.

147 {
148 std::string execStr(GlobalConfiguration::ExecStr());
149 std::string implStr(GlobalConfiguration::ImplStr());
150
151 // reshape this->m_in
152 if (implStr == "SumFac" || execStr == "AVX")
153 {
154 this->m_in.ReshapeStorage(
155 NektarSpaces::GetVectorWidth<TData>(execStr), execStr);
157 NektarSpaces::GetVectorWidth<TData>(execStr));
158 }
159
160 auto op = FwdTransOp<TData>::Create(this->m_expList,
161 this->m_session->GetVariables());
162 auto precon = PreconOp<TData>::Create(
163 this->m_expList, this->m_session->GetVariables(), "Diagonal");
164 auto linsolve = LinearSolverOp<TData>::Create(
165 this->m_expList, this->m_session->GetVariables(), method);
166 linsolve->SetVerboseOutput(true);
167 op->SetLinearSolver(linsolve);
168 op->SetPrecon(precon);
169 op->UpdatePrecon();
170 op->Apply(this->m_in, this->m_out);
171 }
void ReshapeStorage(const unsigned int &interleaveWidth, const std::string &execSpace)
void SetInterleaveWidth(const unsigned int &interleaveWidth)
Field< TData, FieldState::Coeff > m_out

References TestLinearSolver< TData >::m_expList, TestLinearSolver< TData >::m_in, TestLinearSolver< TData >::m_out, TestLinearSolver< TData >::m_session, Nektar::LibUtilities::Field< TData, TState >::ReshapeStorage(), and Nektar::LibUtilities::Field< TData, TState >::SetInterleaveWidth().

◆ SetTestCase()

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

Definition at line 51 of file TestFwdTrans.hpp.

52 {
53 // Set initial conditions.
54 const unsigned int numComp =
55 this->m_in.GetNumComponents() * this->m_in.GetNumHomoModes();
56 const size_t nphys = this->m_expList->GetTotPoints();
57 m_coordDim = this->m_expList->GetCoordim(0);
58
59 Array<OneD, TData> x(nphys, 0.0);
60 Array<OneD, TData> y(nphys, 0.0);
61 Array<OneD, TData> z(nphys, 0.0);
62 Array<OneD, TData> fce(numComp * nphys, 0.0);
63 this->m_expList->GetCoords(x, y, z);
64
65 if (this->m_session->DefinesFunction("Forcing"))
66 {
67 for (unsigned int n = 0; n < numComp; ++n)
68 {
69 auto func = this->m_session->GetFunction(
70 "Forcing", n % this->m_session->GetVariables().size());
71 Array<OneD, TData> fceVar = fce + n * nphys;
72 func->Evaluate(x, y, z, fceVar);
73 }
74 }
75
76 for (unsigned int blk = 0; blk < this->m_in.GetBlocks().size(); ++blk)
77 {
78 auto &block = this->m_in.GetBlocks()[blk];
79 auto inptr =
80 block.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
81 for (unsigned int n = 0; n < numComp; ++n)
82 {
83 auto xptr = x.data();
84 auto yptr = y.data();
85 auto zptr = z.data();
86 auto fceptr = fce.data() + n * nphys;
87
88 for (size_t el = 0, cnt = 0; el < block.GetNumElements(); ++el)
89 {
90 for (unsigned int phys = 0; phys < block.GetNumData();
91 ++phys, ++cnt)
92 {
93 if (this->m_session->DefinesFunction("Forcing"))
94 {
95 inptr[cnt] = *(fceptr++);
96 }
97 else
98 {
99 inptr[cnt] = 1.0 + n;
100 if (m_coordDim == 1)
101 {
102 for (unsigned int p = 1; p < 4; ++p)
103 {
104 inptr[cnt] +=
105 (n + 1) * p * std::pow(*xptr, p);
106 }
107 xptr++;
108 }
109 else if (m_coordDim == 2)
110 {
111 for (unsigned int p = 1; p < 4; ++p)
112 {
113 inptr[cnt] += (n + 1) * p *
114 std::pow(*xptr, p) *
115 std::pow(*yptr, p);
116 }
117 xptr++;
118 yptr++;
119 }
120 else
121 {
122 for (unsigned int p = 1; p < 4; ++p)
123 {
124 inptr[cnt] +=
125 (n + 1) * p * std::pow(*xptr, p) *
126 std::pow(*yptr, p) * std::pow(*zptr, p);
127 }
128 xptr++;
129 yptr++;
130 zptr++;
131 }
132 }
133 }
134 }
135
136 inptr += block.CompSize();
137 }
138 }
139
140 this->m_out.template Initialize<NektarSpaces::HostSpace>(0.0);
141
142 // Compute expected solution.
144 }
SpatialDomains::Geometry * el
std::vector< BlockAccessor< TData, TState > > & GetBlocks()
Get BlockAccessors for the field.
unsigned int m_coordDim
void ExpectedSolution()
std::vector< double > p(NPUPPER)

References el, TestFwdTrans< TData >::ExpectedSolution(), Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), Nektar::LibUtilities::Field< TData, TState >::GetNumHomoModes(), TestFwdTrans< TData >::m_coordDim, TestLinearSolver< TData >::m_expList, TestLinearSolver< TData >::m_in, TestLinearSolver< TData >::m_out, and TestLinearSolver< TData >::m_session.

Member Data Documentation

◆ m_coordDim

template<typename TData >
unsigned int TestFwdTrans< TData >::m_coordDim
protected

Definition at line 203 of file TestFwdTrans.hpp.

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