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

#include <TestPoissonSolve.hpp>

Inheritance diagram for TestPoissonSolve< TData >:
[legend]

Public Member Functions

 TestPoissonSolve ()=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
 
std::vector< TData > m_diffCoeff
 
- 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 TestPoissonSolve< TData >

Definition at line 47 of file TestPoissonSolve.hpp.

Constructor & Destructor Documentation

◆ TestPoissonSolve()

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

Member Function Documentation

◆ ExpectedSolution()

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

Definition at line 196 of file TestPoissonSolve.hpp.

197 {
198 // Calculate expected result from Nektar++.
199 const unsigned int numComp =
200 this->m_in.GetNumComponents() * this->m_in.GetNumHomoModes();
201 const size_t nphys = this->m_expList->GetTotPoints();
202 const size_t ncoeffs = this->m_expList->GetNcoeffs();
203 const auto &variables = this->m_session->GetVariables();
204
205 // Setup input/output arrays
206 Array<OneD, TData> inphys = this->m_in.ToArray();
207 Array<OneD, TData> outcoeffs(numComp * ncoeffs, 0.0);
208
209 // Set lambda as constant coefficient
212
213 // Set up diffusion coefficient.
214 if (m_coordDim == 2)
215 {
219 }
220 else if (m_coordDim == 3)
221 {
228 }
229
230 // Solve each component separately
232 for (unsigned int n = 0; n < numComp; ++n)
233 {
235 this->m_session, graph, variables[n % variables.size()], true,
237 Array<OneD, TData> inphysVar = inphys + n * nphys;
238 Array<OneD, TData> outcoeffsVar = outcoeffs + n * ncoeffs;
239 expListVar->HelmSolve(inphysVar, outcoeffsVar, factors);
240 }
241
242 // Copy solution back
243 this->m_expected.template CopyArray<NektarSpaces::HostSpace>(outcoeffs);
244 }
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
std::vector< TData > m_diffCoeff
std::map< ConstFactorType, NekDouble > ConstFactorMap
StdRegions::ConstFactorMap factors

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::StdRegions::eFactorCoeffD00, Nektar::StdRegions::eFactorCoeffD01, Nektar::StdRegions::eFactorCoeffD02, Nektar::StdRegions::eFactorCoeffD11, Nektar::StdRegions::eFactorCoeffD12, Nektar::StdRegions::eFactorCoeffD22, Nektar::StdRegions::eFactorLambda, Nektar::Collections::eNoCollection, Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), Nektar::LibUtilities::Field< TData, TState >::GetNumHomoModes(), graph, TestPoissonSolve< TData >::m_coordDim, TestPoissonSolve< TData >::m_diffCoeff, 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 TestPoissonSolve< TData >::SetTestCase().

◆ RunTestCase()

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

Definition at line 168 of file TestPoissonSolve.hpp.

169 {
170 std::string execStr(GlobalConfiguration::ExecStr());
171 std::string implStr(GlobalConfiguration::ImplStr());
172
173 // reshape this->m_in
174 if (implStr == "SumFac" || execStr == "AVX")
175 {
176 this->m_in.ReshapeStorage(
177 NektarSpaces::GetVectorWidth<TData>(execStr), execStr);
179 NektarSpaces::GetVectorWidth<TData>(execStr));
180 }
181
183 this->m_expList, this->m_session->GetVariables());
184 auto precon = PreconOp<TData>::Create(
185 this->m_expList, this->m_session->GetVariables(), "Diagonal");
186 auto linsolve = LinearSolverOp<TData>::Create(
187 this->m_expList, this->m_session->GetVariables(), method);
188 linsolve->SetVerboseOutput(true);
189 op->SetDiffCoeff(m_diffCoeff);
190 op->SetLinearSolver(linsolve);
191 op->SetPrecon(precon);
192 op->UpdatePrecon();
193 op->Apply(this->m_in, this->m_out);
194 }
void ReshapeStorage(const unsigned int &interleaveWidth, const std::string &execSpace)
void SetInterleaveWidth(const unsigned int &interleaveWidth)
Field< TData, FieldState::Coeff > m_out

References TestPoissonSolve< TData >::m_diffCoeff, 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 TestPoissonSolve< TData >::SetTestCase ( )
inline

Definition at line 52 of file TestPoissonSolve.hpp.

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

References el, TestPoissonSolve< TData >::ExpectedSolution(), Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), Nektar::LibUtilities::Field< TData, TState >::GetNumHomoModes(), TestPoissonSolve< TData >::m_coordDim, TestPoissonSolve< TData >::m_diffCoeff, 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 TestPoissonSolve< TData >::m_coordDim
protected

◆ m_diffCoeff

template<typename TData >
std::vector<TData> TestPoissonSolve< TData >::m_diffCoeff
protected