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

#include <TestHelmSolve.hpp>

Inheritance diagram for TestHelmSolve< TData >:
[legend]

Public Member Functions

 TestHelmSolve ()=default
 
void SetTestCase ()
 
void RunTestCase (const std::string &method)
 
void RepeatSolve ()
 Solve again with the current output as the initial guess.
 
void SetGlobalSysSolnInfo (const std::string &property, const std::string &value)
 Set a GLOBALSYSSOLNINFO property for the first variable only, which the linear solver applies to all variables solved together.
 
unsigned int GetNiterations ()
 
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
 
TData m_lambda
 
std::vector< TData > m_diffCoeff
 
std::shared_ptr< HelmSolveOp< TData > > m_op
 
std::shared_ptr< LinearSolverOp< TData > > m_linsolve
 
- 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 TestHelmSolve< TData >

Definition at line 46 of file TestHelmSolve.hpp.

Constructor & Destructor Documentation

◆ TestHelmSolve()

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

Member Function Documentation

◆ ExpectedSolution()

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

Definition at line 225 of file TestHelmSolve.hpp.

226 {
227 // Calculate expected result from Nektar++.
228 const unsigned int numComp =
229 this->m_in.GetNumComponents() * this->m_in.GetNumHomoModes();
230 const size_t nphys = this->m_expList->GetTotPoints();
231 const size_t ncoeffs = this->m_expList->GetNcoeffs();
232 const auto &variables = this->m_session->GetVariables();
233
234 // Setup input/output arrays
235 Array<OneD, TData> inphys = this->m_in.ToArray();
236 Array<OneD, TData> outcoeffs(numComp * ncoeffs, 0.0);
237
238 // Set lambda as constant coefficient
241
242 // Set up diffusion coefficient.
243 if (m_coordDim == 2)
244 {
248 }
249 else if (m_coordDim == 3)
250 {
257 }
258
259 // Solve each component separately
261 for (unsigned int n = 0; n < numComp; ++n)
262 {
264 this->m_session, graph, variables[n % variables.size()], true,
266 Array<OneD, TData> inphysVar = inphys + n * nphys;
267 Array<OneD, TData> outcoeffsVar = outcoeffs + n * ncoeffs;
268 expListVar->HelmSolve(inphysVar, outcoeffsVar, factors);
269 }
270
271 // Copy solution back
272 this->m_expected.template CopyArray<NektarSpaces::HostSpace>(outcoeffs);
273 }
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)
unsigned int m_coordDim
std::vector< TData > m_diffCoeff
Field< TData, FieldState::Phys > m_in
ExpListSharedPtr m_expList
SessionReaderSharedPtr m_session
Field< TData, FieldState::Coeff > m_expected
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, TestHelmSolve< TData >::m_coordDim, TestHelmSolve< TData >::m_diffCoeff, TestLinearSolver< TData >::m_expected, TestLinearSolver< TData >::m_expList, TestLinearSolver< TData >::m_in, TestHelmSolve< TData >::m_lambda, TestLinearSolver< TData >::m_session, Nektar::SpatialDomains::MeshGraphIO::Read(), and Nektar::LibUtilities::Field< TData, TState >::ToArray().

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

◆ GetNiterations()

template<typename TData >
unsigned int TestHelmSolve< TData >::GetNiterations ( )
inline

Definition at line 220 of file TestHelmSolve.hpp.

221 {
222 return m_linsolve->GetNiterations();
223 }
std::shared_ptr< LinearSolverOp< TData > > m_linsolve

References TestHelmSolve< TData >::m_linsolve.

◆ RepeatSolve()

template<typename TData >
void TestHelmSolve< TData >::RepeatSolve ( )
inline

Solve again with the current output as the initial guess.

Definition at line 204 of file TestHelmSolve.hpp.

205 {
206 m_op->Apply(this->m_in, this->m_out);
207 }
std::shared_ptr< HelmSolveOp< TData > > m_op
Field< TData, FieldState::Coeff > m_out

References TestLinearSolver< TData >::m_in, TestHelmSolve< TData >::m_op, and TestLinearSolver< TData >::m_out.

◆ RunTestCase()

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

Definition at line 172 of file TestHelmSolve.hpp.

173 {
174 std::string execStr(GlobalConfiguration::ExecStr());
175 std::string implStr(GlobalConfiguration::ImplStr());
176
177 // reshape this->m_in
178 if (implStr == "SumFac" || execStr == "AVX")
179 {
180 this->m_in.ReshapeStorage(
181 NektarSpaces::GetVectorWidth<TData>(execStr), execStr);
183 NektarSpaces::GetVectorWidth<TData>(execStr));
184 }
185
186 m_op = HelmSolveOp<TData>::Create(this->m_expList,
187 this->m_session->GetVariables());
188 auto precon = PreconOp<TData>::Create(
189 this->m_expList, this->m_session->GetVariables(), "Diagonal");
191 this->m_expList, this->m_session->GetVariables(), method);
192 m_linsolve->SetVerboseOutput(true);
193 m_op->SetLambda(m_lambda);
194 m_op->SetDiffCoeff(m_diffCoeff);
195 m_op->SetLinearSolver(m_linsolve);
196 m_op->SetPrecon(precon);
197 m_op->UpdatePrecon();
198 m_op->Apply(this->m_in, this->m_out);
199 }
void ReshapeStorage(const unsigned int &interleaveWidth, const std::string &execSpace)
void SetInterleaveWidth(const unsigned int &interleaveWidth)

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

◆ SetGlobalSysSolnInfo()

template<typename TData >
void TestHelmSolve< TData >::SetGlobalSysSolnInfo ( const std::string &  property,
const std::string &  value 
)
inline

Set a GLOBALSYSSOLNINFO property for the first variable only, which the linear solver applies to all variables solved together.

Definition at line 213 of file TestHelmSolve.hpp.

215 {
216 this->m_session->SetGlobalSysSolnInfo(
217 this->m_session->GetVariables()[0], property, value);
218 }

References TestLinearSolver< TData >::m_session.

◆ SetTestCase()

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

Definition at line 51 of file TestHelmSolve.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 // Get lambda from this->m_session or default to 10.0
143 m_lambda = this->m_session->DefinesParameter("Lambda")
144 ? this->m_session->GetParameter("Lambda")
145 : 10.0;
146
147 // Set up diffusion coefficient.
148 const auto nDiffCoeff = m_coordDim * (m_coordDim + 1) / 2;
149 m_diffCoeff.resize(nDiffCoeff);
150
151 // Set up (isotropic) diffusion coefficient.
152 if (m_coordDim == 1)
153 {
154 m_diffCoeff[0] = 1.0; // D00
155 }
156 else if (m_coordDim == 2)
157 {
158 m_diffCoeff[0] = 2.0; // D00
159 m_diffCoeff[2] = 3.0; // D11
160 }
161 else
162 {
163 m_diffCoeff[0] = 2.0; // D00
164 m_diffCoeff[2] = 3.0; // D11
165 m_diffCoeff[5] = 4.0; // D22
166 }
167
168 // Compute expected solution.
170 }
SpatialDomains::Geometry * el
std::vector< BlockAccessor< TData, TState > > & GetBlocks()
Get BlockAccessors for the field.
std::vector< double > p(NPUPPER)

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

Member Data Documentation

◆ m_coordDim

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

◆ m_diffCoeff

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

◆ m_lambda

template<typename TData >
TData TestHelmSolve< TData >::m_lambda
protected

◆ m_linsolve

template<typename TData >
std::shared_ptr<LinearSolverOp<TData> > TestHelmSolve< TData >::m_linsolve
protected

◆ m_op

template<typename TData >
std::shared_ptr<HelmSolveOp<TData> > TestHelmSolve< TData >::m_op
protected