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

#include <TestLinearADRSolve.hpp>

Inheritance diagram for TestLinearADRSolve< TData >:
[legend]

Public Member Functions

 TestLinearADRSolve ()=default
 
void Configure (void)
 
void SetTestCase ()
 
void RunTestCase (const std::string &method)
 
void ExpectedSolution ()
 
StdRegions::ConstFactorMap BuildFactors () const
 
StdRegions::VarCoeffMap BuildVarCoeffs (const Array< OneD, TData > &vel) const
 
std::shared_ptr< ContFieldMatrixAccessor > BuildExpectedExpList (const std::string &variable)
 
DNekMatSharedPtr BuildGlobalADRMatrix (const std::string &variable, const Array< OneD, TData > &vel)
 
- 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 Member Functions

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

Protected Attributes

std::string m_preconName = "Diagonal"
 
unsigned int m_coordDim
 
TData m_lambda
 
std::vector< TData > m_diffCoeff
 
Array< OneD, TData > m_vel
 
- 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
 

Detailed Description

template<typename TData>
class TestLinearADRSolve< TData >

Definition at line 56 of file TestLinearADRSolve.hpp.

Constructor & Destructor Documentation

◆ TestLinearADRSolve()

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

Member Function Documentation

◆ BuildExpectedExpList()

template<typename TData >
std::shared_ptr< ContFieldMatrixAccessor > TestLinearADRSolve< TData >::BuildExpectedExpList ( const std::string &  variable)
inline

Definition at line 350 of file TestLinearADRSolve.hpp.

352 {
354
356 this->m_session, graph, variable, true, false,
358 }
SpatialDomains::MeshGraphSharedPtr graph
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)
SessionReaderSharedPtr m_session

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::Collections::eNoCollection, graph, TestLinearSolver< TData >::m_session, and Nektar::SpatialDomains::MeshGraphIO::Read().

Referenced by TestLinearADRSolve< TData >::BuildGlobalADRMatrix().

◆ BuildFactors()

template<typename TData >
StdRegions::ConstFactorMap TestLinearADRSolve< TData >::BuildFactors ( ) const
inline

Definition at line 308 of file TestLinearADRSolve.hpp.

309 {
312
313 if (m_coordDim == 2)
314 {
318 }
319 else if (m_coordDim == 3)
320 {
327 }
328
329 return factors;
330 }
std::vector< TData > m_diffCoeff
std::map< ConstFactorType, NekDouble > ConstFactorMap
StdRegions::ConstFactorMap factors

References Nektar::StdRegions::eFactorCoeffD00, Nektar::StdRegions::eFactorCoeffD01, Nektar::StdRegions::eFactorCoeffD02, Nektar::StdRegions::eFactorCoeffD11, Nektar::StdRegions::eFactorCoeffD12, Nektar::StdRegions::eFactorCoeffD22, Nektar::StdRegions::eFactorLambda, TestLinearADRSolve< TData >::m_coordDim, TestLinearADRSolve< TData >::m_diffCoeff, and TestLinearADRSolve< TData >::m_lambda.

Referenced by TestLinearADRSolve< TData >::BuildGlobalADRMatrix().

◆ BuildGlobalADRMatrix()

template<typename TData >
DNekMatSharedPtr TestLinearADRSolve< TData >::BuildGlobalADRMatrix ( const std::string &  variable,
const Array< OneD, TData > &  vel 
)
inline

Definition at line 360 of file TestLinearADRSolve.hpp.

362 {
363 auto expListVar = BuildExpectedExpList(variable);
364 const size_t nphys = expListVar->GetTotPoints();
365 const size_t ncoeffs = expListVar->GetNcoeffs();
366 Array<OneD, TData> inphys(nphys, 0.0);
367 Array<OneD, TData> outcoeffs(ncoeffs, 0.0);
368
369 auto key = expListVar->LinearAdvectionDiffusionReactionSolve(
370 inphys, outcoeffs, BuildFactors(), BuildVarCoeffs(vel));
371
372 return expListVar->GenGlobalMatrixFull(
373 key, expListVar->GetLocalToGlobalMap());
374 }
StdRegions::ConstFactorMap BuildFactors() const
std::shared_ptr< ContFieldMatrixAccessor > BuildExpectedExpList(const std::string &variable)
StdRegions::VarCoeffMap BuildVarCoeffs(const Array< OneD, TData > &vel) const

References TestLinearADRSolve< TData >::BuildExpectedExpList(), TestLinearADRSolve< TData >::BuildFactors(), and TestLinearADRSolve< TData >::BuildVarCoeffs().

◆ BuildVarCoeffs()

template<typename TData >
StdRegions::VarCoeffMap TestLinearADRSolve< TData >::BuildVarCoeffs ( const Array< OneD, TData > &  vel) const
inline

Definition at line 332 of file TestLinearADRSolve.hpp.

333 {
334 const size_t nphys = this->m_expList->GetTotPoints();
335 StdRegions::VarCoeffMap varcoeffs;
336 std::vector<StdRegions::VarCoeffType> velCoeffType = {
339
340 for (unsigned int d = 0; d < m_coordDim; ++d)
341 {
342 Array<OneD, TData> tmpVel(nphys);
343 Vmath::Vcopy(nphys, vel + d * nphys, 1, tmpVel, 1);
344 varcoeffs[velCoeffType[d]] = tmpVel;
345 }
346
347 return varcoeffs;
348 }
ExpListSharedPtr m_expList
std::map< StdRegions::VarCoeffType, VarCoeffEntry > VarCoeffMap
std::vector< double > d(NPUPPER *NPUPPER)
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition Vmath.hpp:828

References Nektar::StdRegions::eVarCoeffVelX, Nektar::StdRegions::eVarCoeffVelY, Nektar::StdRegions::eVarCoeffVelZ, TestLinearADRSolve< TData >::m_coordDim, TestLinearSolver< TData >::m_expList, and Vmath::Vcopy().

Referenced by TestLinearADRSolve< TData >::BuildGlobalADRMatrix().

◆ Configure()

template<typename TData >
void TestLinearADRSolve< TData >::Configure ( void  )
inline

Definition at line 63 of file TestLinearADRSolve.hpp.

64 {
65 this->SetSession();
66 // Must run before SetExpList(): AssemblyMap reads GlobalSysSoln
67 // when the ContField is constructed. The expansion lists built
68 // later for the expected solution rely on the session state set
69 // here too, so this is the only call needed.
71 this->SetExpList();
72 this->m_expList->SetDataWarehouse();
73 this->SetFixture();
74 }

References TestLinearADRSolve< TData >::ConfigureExpectedSolverInfo(), TestLinearSolver< TData >::m_expList, TestLinearSolver< TData >::SetExpList(), TestLinearSolver< TData >::SetFixture(), and TestLinearSolver< TData >::SetSession().

◆ ConfigureExpectedSolverInfo()

template<typename TData >
void TestLinearADRSolve< TData >::ConfigureExpectedSolverInfo ( )
inlineprotected

Definition at line 377 of file TestLinearADRSolve.hpp.

378 {
379 const auto &variables = this->m_session->GetVariables();
380 std::string iterSolver =
381 this->m_session->DefinesSolverInfo("LinSysIterSolver")
382 ? this->m_session->GetSolverInfo("LinSysIterSolver")
383 : "ConjugateGradient";
384 std::string gmresSolver =
385 iterSolver.find("Loc") != std::string::npos ? "GMRESLoc" : "GMRES";
386
387 if (this->m_session->DefinesSolverInfo("LinSysIterSolver"))
388 {
389 this->m_session->SetSolverInfo("LinSysIterSolver", gmresSolver);
390 }
391 for (const auto &var : variables)
392 {
393 this->m_session->SetGlobalSysSolnInfo(var, "GlobalSysSoln",
394 "IterativeFull");
395 this->m_session->SetGlobalSysSolnInfo(var, "LinSysIterSolver",
396 gmresSolver);
397 }
398 }

References TestLinearSolver< TData >::m_session.

Referenced by TestLinearADRSolve< TData >::Configure().

◆ ExpectedSolution()

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

Definition at line 243 of file TestLinearADRSolve.hpp.

244 {
245 // Calculate expected result from Nektar++.
246 const unsigned int numComp =
247 this->m_in.GetNumComponents() * this->m_in.GetNumHomoModes();
248 const size_t nphys = this->m_expList->GetTotPoints();
249 const size_t ncoeffs = this->m_expList->GetNcoeffs();
250 const auto &variables = this->m_session->GetVariables();
251
252 // Setup input/output arrays
253 Array<OneD, TData> inphys = this->m_in.ToArray();
254 Array<OneD, TData> outcoeffs(numComp * ncoeffs, 0.0);
255
256 // Set lambda as constant coefficient
259
260 // Set up diffusion coefficient.
261 if (m_coordDim == 2)
262 {
266 }
267 else if (m_coordDim == 3)
268 {
275 }
276
277 // Set advection velocities via varcoeffs
278 StdRegions::VarCoeffMap varcoeffs;
279 std::vector<StdRegions::VarCoeffType> velCoeffType = {
282 for (unsigned int d = 0; d < m_coordDim; ++d)
283 {
285 Array<OneD, TData> tmpVel(nphys);
286 Vmath::Vcopy(nphys, m_vel + d * nphys, 1, tmpVel, 1);
287 varcoeffs[velCoeffType[d]] = tmpVel;
288 }
289
291
292 // Solve each component separately.
293 for (unsigned int n = 0; n < numComp; ++n)
294 {
296 this->m_session, graph, variables[n % variables.size()], true,
298 Array<OneD, TData> inphysVar = inphys + n * nphys;
299 Array<OneD, TData> outcoeffsVar = outcoeffs + n * ncoeffs;
300 expListVar->LinearAdvectionDiffusionReactionSolve(
301 inphysVar, outcoeffsVar, factors, varcoeffs);
302 }
303
304 // Copy solution back
305 this->m_expected.template CopyArray<NektarSpaces::HostSpace>(outcoeffs);
306 }
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.
Array< OneD, TData > m_vel
Field< TData, FieldState::Phys > m_in
Field< TData, FieldState::Coeff > m_expected

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::StdRegions::eVarCoeffVelX, Nektar::StdRegions::eVarCoeffVelY, Nektar::StdRegions::eVarCoeffVelZ, Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), Nektar::LibUtilities::Field< TData, TState >::GetNumHomoModes(), graph, TestLinearADRSolve< TData >::m_coordDim, TestLinearADRSolve< TData >::m_diffCoeff, TestLinearSolver< TData >::m_expected, TestLinearSolver< TData >::m_expList, TestLinearSolver< TData >::m_in, TestLinearADRSolve< TData >::m_lambda, TestLinearSolver< TData >::m_session, TestLinearADRSolve< TData >::m_vel, Nektar::SpatialDomains::MeshGraphIO::Read(), Nektar::LibUtilities::Field< TData, TState >::ToArray(), and Vmath::Vcopy().

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

◆ RunTestCase()

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

Definition at line 206 of file TestLinearADRSolve.hpp.

207 {
208 auto advelblockAttr = GetBlockAttributes<TData, FieldState::Phys>(
209 this->m_expList,
210 MultiRegions::UnitInterleaveWidths(this->m_expList));
211 auto vel = Field<TData, FieldState::Phys>("vel", advelblockAttr,
212 m_coordDim, 1);
213 vel.template CopyArray<NektarSpaces::HostSpace>(m_vel);
214
215 std::string execStr(GlobalConfiguration::ExecStr());
216 std::string implStr(GlobalConfiguration::ImplStr());
217
218 // reshape this->m_in
219 if (implStr == "SumFac" || execStr == "AVX")
220 {
221 this->m_in.ReshapeStorage(
222 NektarSpaces::GetVectorWidth<TData>(execStr), execStr);
224 NektarSpaces::GetVectorWidth<TData>(execStr));
225 }
226
227 auto op = LinearADRSolveOp<TData>::Create(
228 this->m_expList, this->m_session->GetVariables());
229 auto precon = PreconOp<TData>::Create(
230 this->m_expList, this->m_session->GetVariables(), m_preconName);
231 auto linsolve = LinearSolverOp<TData>::Create(
232 this->m_expList, this->m_session->GetVariables(), method);
233 linsolve->SetVerboseOutput(true);
234 op->SetLambda(m_lambda);
235 op->SetDiffCoeff(m_diffCoeff);
236 op->SetAdvVel(vel);
237 op->SetLinearSolver(linsolve);
238 op->SetPrecon(precon);
239 op->UpdatePrecon();
240 op->Apply(this->m_in, this->m_out);
241 }
A Field represents expansion data to be operated on.
void ReshapeStorage(const unsigned int &interleaveWidth, const std::string &execSpace)
void SetInterleaveWidth(const unsigned int &interleaveWidth)
Field< TData, FieldState::Coeff > m_out

References TestLinearADRSolve< TData >::m_coordDim, TestLinearADRSolve< TData >::m_diffCoeff, TestLinearSolver< TData >::m_expList, TestLinearSolver< TData >::m_in, TestLinearADRSolve< TData >::m_lambda, TestLinearSolver< TData >::m_out, TestLinearADRSolve< TData >::m_preconName, TestLinearSolver< TData >::m_session, TestLinearADRSolve< TData >::m_vel, Nektar::LibUtilities::Field< TData, TState >::ReshapeStorage(), and Nektar::LibUtilities::Field< TData, TState >::SetInterleaveWidth().

◆ SetTestCase()

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

Definition at line 76 of file TestLinearADRSolve.hpp.

77 {
78 // Set initial conditions.
79 const unsigned int numComp =
80 this->m_in.GetNumComponents() * this->m_in.GetNumHomoModes();
81 const size_t nphys = this->m_expList->GetTotPoints();
82 m_coordDim = this->m_expList->GetCoordim(0);
83
84 Array<OneD, TData> x(nphys, 0.0);
85 Array<OneD, TData> y(nphys, 0.0);
86 Array<OneD, TData> z(nphys, 0.0);
87 Array<OneD, TData> fce(numComp * nphys, 0.0);
88 this->m_expList->GetCoords(x, y, z);
89 this->m_in.template Initialize<NektarSpaces::HostSpace>(0.0);
90
91 if (this->m_session->DefinesFunction("Forcing"))
92 {
93 for (unsigned int n = 0; n < numComp; ++n)
94 {
95 auto func = this->m_session->GetFunction(
96 "Forcing", n % this->m_session->GetVariables().size());
97 Array<OneD, TData> fceVar = fce + n * nphys;
98 func->Evaluate(x, y, z, fceVar);
99 }
100 }
101
102 for (unsigned int blk = 0; blk < this->m_in.GetBlocks().size(); ++blk)
103 {
104 auto &block = this->m_in.GetBlocks()[blk];
105 auto inptr =
106 block.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
107 for (unsigned int n = 0; n < numComp; ++n)
108 {
109 auto xptr = x.data();
110 auto yptr = y.data();
111 auto zptr = z.data();
112 auto fceptr = fce.data() + n * nphys;
113
114 for (size_t el = 0, cnt = 0; el < block.GetNumElements(); ++el)
115 {
116 for (unsigned int phys = 0; phys < block.GetNumData();
117 ++phys, ++cnt)
118 {
119 if (this->m_session->DefinesFunction("Forcing"))
120 {
121 inptr[cnt] = *(fceptr++);
122 }
123 else
124 {
125 inptr[cnt] = 1.0 + n;
126 if (m_coordDim == 1)
127 {
128 for (unsigned int p = 1; p < 4; ++p)
129 {
130 inptr[cnt] +=
131 (n + 1) * p * std::pow(*xptr, p);
132 }
133 xptr++;
134 }
135 else if (m_coordDim == 2)
136 {
137 for (unsigned int p = 1; p < 4; ++p)
138 {
139 inptr[cnt] += (n + 1) * p *
140 std::pow(*xptr, p) *
141 std::pow(*yptr, p);
142 }
143 xptr++;
144 yptr++;
145 }
146 else
147 {
148 for (unsigned int p = 1; p < 4; ++p)
149 {
150 inptr[cnt] +=
151 (n + 1) * p * std::pow(*xptr, p) *
152 std::pow(*yptr, p) * std::pow(*zptr, p);
153 }
154 xptr++;
155 yptr++;
156 zptr++;
157 }
158 }
159 }
160 }
161
162 inptr += block.CompSize();
163 }
164 }
165
166 this->m_out.template Initialize<NektarSpaces::HostSpace>(0.0);
167
168 // Get lambda from this->m_session or default to 10.0
169 m_lambda = this->m_session->DefinesParameter("Lambda")
170 ? this->m_session->GetParameter("Lambda")
171 : 10.0;
172
173 // Set up diffusion coefficient.
174 const auto nDiffCoeff = m_coordDim * (m_coordDim + 1) / 2;
175 m_diffCoeff.resize(nDiffCoeff);
176
177 // Set up (isotropic) diffusion coefficient.
178 if (m_coordDim == 1)
179 {
180 m_diffCoeff[0] = 1.0; // D00
181 }
182 else if (m_coordDim == 2)
183 {
184 m_diffCoeff[0] = 1.0; // D00
185 m_diffCoeff[2] = 1.0; // D11
186 }
187 else
188 {
189 m_diffCoeff[0] = 1.0; // D00
190 m_diffCoeff[2] = 1.0; // D11
191 m_diffCoeff[5] = 1.0; // D22
192 }
193
194 // Set advection velocity
195 m_vel = Array<OneD, TData>(nphys * m_coordDim, 1.0);
197 for (unsigned int d = 1; d < m_coordDim; ++d)
198 {
199 Vmath::Fill(nphys, d + 1.0, tmp = m_vel + d * nphys, 1);
200 }
201
202 // Compute expected solution.
204 }
SpatialDomains::Geometry * el
std::vector< BlockAccessor< TData, TState > > & GetBlocks()
Get BlockAccessors for the field.
std::vector< double > p(NPUPPER)
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition Vmath.hpp:56

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

Member Data Documentation

◆ m_coordDim

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

◆ m_diffCoeff

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

◆ m_lambda

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

◆ m_preconName

template<typename TData >
std::string TestLinearADRSolve< TData >::m_preconName = "Diagonal"
protected

Definition at line 401 of file TestLinearADRSolve.hpp.

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

◆ m_vel

template<typename TData >
Array<OneD, TData> TestLinearADRSolve< TData >::m_vel
protected