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

#include <TestLinAdvDiffReaction.hpp>

Inheritance diagram for TestLinAdvDiffReaction< TData >:
[legend]

Public Member Functions

 TestLinAdvDiffReaction ()=default
 
void SetTestCase (const bool varDiffCoeff=false)
 
void RunTestCase ()
 
void ExpectedSolution ()
 
void HomogeneousTrans (const std::shared_ptr< MultiRegions::ExpListHomogeneous1D > &homoExpList, const size_t ncoeffs, Array< OneD, TData > &coeffs, const bool forwards)
 Transform coeffs between physical z and wave space, one component at a time; Homogeneous1DTrans works in NekDouble whatever TData is.
 
- Public Member Functions inherited from TestOp< TData, FieldState::Coeff, FieldState::Coeff >
 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.
 

Private Attributes

VariableDiffusion< TData > m_varDiffHelper
 
unsigned int m_coordDim
 
size_t m_velCompStride = 0
 Step from one velocity component to the next: one plane's points times the number of planes.
 
unsigned int m_nVelComp = 0
 Velocity components: one per coordinate direction, or three on a 3DH1 expansion, whose planes do not count the homogeneous direction.
 
TData m_lambda
 
std::vector< TData > m_diffCoeff
 
Array< OneD, TData > m_vel
 

Additional Inherited Members

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

Definition at line 49 of file TestLinAdvDiffReaction.hpp.

Constructor & Destructor Documentation

◆ TestLinAdvDiffReaction()

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

Member Function Documentation

◆ ExpectedSolution()

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

Definition at line 189 of file TestLinAdvDiffReaction.hpp.

190 {
191 // Calculate expected result from Nektar++
192 const unsigned int numComp = this->fixt_in->GetNumComponents() *
193 this->fixt_in->GetNumHomoModes();
194 const size_t ncoeffs =
195 this->fixt_explist->GetNcoeffs() / this->fixt_in->GetNumHomoModes();
197
200 Array<OneD, TData> incoeffs = this->fixt_in->ToArray();
201 Array<OneD, TData> outcoeffs(numComp * ncoeffs);
202 std::vector<StdRegions::VarCoeffType> velCoeffType = {
205
206 // The weak z-Laplacian of a 3DH1 field is (beta k)^2 M on each
207 // Fourier mode, which rides the existing lambda: the reference
208 // transforms to wave space, applies a plane-wise operator with
209 // lambda - (beta k)^2 -- the reference carries the reaction term as
210 // -lambda M, so the z term enters with the opposite sign to
211 // Helmholtz's -- and transforms back. The operator reaches the same
212 // result by another route, the mass matrix applied to minus the
213 // second z-derivative, so this is a genuine cross-check.
214 //
215 // The advection velocity's through-plane component is zero, so the
216 // operator's z advection contributes nothing to compare against.
217 auto homoExpList =
218 std::dynamic_pointer_cast<MultiRegions::ExpListHomogeneous1D>(
219 this->fixt_explist);
220 const unsigned int nhomo = this->fixt_in->GetNumHomoModes();
221 const bool wave = homoExpList && nhomo > 1;
222
223 Array<OneD, NekDouble> lambdaK(nhomo, 0.0);
224 if (wave)
225 {
226 const NekDouble beta = 2.0 * M_PI / homoExpList->GetHomoLen();
227 for (unsigned int p = 0; p < nhomo; ++p)
228 {
229 const NekDouble betaK =
230 beta *
231 homoExpList->m_transposition->GetK(static_cast<int>(p));
232 lambdaK[p] = m_lambda - betaK * betaK;
233 }
234
235 HomogeneousTrans(homoExpList, ncoeffs, incoeffs, true);
236 }
237
238 for (unsigned int i = 0; i < numComp; ++i)
239 {
240 // The planes of a component are consecutive, so i % nhomo picks
241 // the Fourier mode this slice carries.
242 if (wave)
243 {
244 factors[StdRegions::eFactorLambda] = lambdaK[i % nhomo];
245 }
246
247 size_t e = 0;
248 size_t offset = i * ncoeffs;
249 size_t physoffset = 0;
250
251 for (const auto &block : this->fixt_expected->GetBlocks())
252 {
253 auto nmTot = this->fixt_explist->GetExp(e)->GetNcoeffs();
254 auto nphysloc = this->fixt_explist->GetExp(e)->GetTotPoints();
255
256 for (size_t el = 0; el < block.GetNumElements(); ++el)
257 {
258 // Restrict varcoeffs to size of element
259 auto varcoeffs =
260 m_varDiffHelper.ForElement(this->fixt_explist, e);
261
262 for (unsigned int d = 0; d < m_coordDim; ++d)
263 {
264 // Every plane carries the same velocity, so the
265 // first one stands for all of them here.
266 varcoeffs[velCoeffType[d]] =
267 m_vel + d * m_velCompStride + physoffset;
268 }
269
272 this->fixt_explist->GetExp(e)->DetShapeType(),
273 *(this->fixt_explist->GetExp(e)), factors, varcoeffs);
274
275 if (m_varDiffHelper.field &&
276 this->fixt_explist->GetShapeDimension() == 1)
277 {
278 m_varDiffHelper.ApplySegment(
279 this->fixt_explist, e, incoeffs + offset,
280 tmp = outcoeffs + offset, -m_lambda, varcoeffs);
281 }
282 else
283 {
284 this->fixt_explist->GetExp(e)->GeneralMatrixOp(
285 incoeffs + offset, tmp = outcoeffs + offset, mkey);
286 }
287 e++;
288 offset += nmTot;
289 physoffset += nphysloc;
290 }
291 }
292 }
293
294 if (wave)
295 {
296 HomogeneousTrans(homoExpList, ncoeffs, outcoeffs, false);
297 }
298
299 this->fixt_expected->template CopyArray<NektarSpaces::HostSpace>(
300 outcoeffs);
301 }
SpatialDomains::Geometry * el
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.
VariableDiffusion< TData > m_varDiffHelper
size_t m_velCompStride
Step from one velocity component to the next: one plane's points times the number of planes.
void HomogeneousTrans(const std::shared_ptr< MultiRegions::ExpListHomogeneous1D > &homoExpList, const size_t ncoeffs, Array< OneD, TData > &coeffs, const bool forwards)
Transform coeffs between physical z and wave space, one component at a time; Homogeneous1DTrans works...
std::shared_ptr< MultiRegions::ExpList > fixt_explist
Definition TestOp.hpp:439
@ beta
Gauss Radau pinned at x=-1,.
Definition PointsType.h:59
ConstFactorMap FactorMap
std::vector< double > p(NPUPPER)
std::vector< double > d(NPUPPER *NPUPPER)
StdRegions::ConstFactorMap factors

References Nektar::LibUtilities::beta, Nektar::StdRegions::eFactorLambda, el, Nektar::StdRegions::eLinearAdvectionDiffusionReaction, Nektar::StdRegions::eVarCoeffVelX, Nektar::StdRegions::eVarCoeffVelY, Nektar::StdRegions::eVarCoeffVelZ, TestOp< TData, FieldState::Coeff, FieldState::Coeff >::fixt_expected, TestOp< TData, FieldState::Coeff, FieldState::Coeff >::fixt_explist, TestOp< TData, FieldState::Coeff, FieldState::Coeff >::fixt_in, Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), Nektar::LibUtilities::Field< TData, TState >::GetNumHomoModes(), TestLinAdvDiffReaction< TData >::HomogeneousTrans(), TestLinAdvDiffReaction< TData >::m_coordDim, TestLinAdvDiffReaction< TData >::m_lambda, TestLinAdvDiffReaction< TData >::m_varDiffHelper, TestLinAdvDiffReaction< TData >::m_vel, TestLinAdvDiffReaction< TData >::m_velCompStride, and Nektar::LibUtilities::Field< TData, TState >::ToArray().

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

◆ HomogeneousTrans()

template<typename TData >
void TestLinAdvDiffReaction< TData >::HomogeneousTrans ( const std::shared_ptr< MultiRegions::ExpListHomogeneous1D > &  homoExpList,
const size_t  ncoeffs,
Array< OneD, TData > &  coeffs,
const bool  forwards 
)
inline

Transform coeffs between physical z and wave space, one component at a time; Homogeneous1DTrans works in NekDouble whatever TData is.

Definition at line 305 of file TestLinAdvDiffReaction.hpp.

308 {
309 const unsigned int nhomo = this->fixt_in->GetNumHomoModes();
310 const size_t nPerComp = ncoeffs * nhomo;
311
312 Array<OneD, NekDouble> in(nPerComp);
313 Array<OneD, NekDouble> out(nPerComp);
314
315 for (unsigned int c = 0; c < this->fixt_in->GetNumComponents(); ++c)
316 {
317 const size_t base = c * nPerComp;
318 for (size_t j = 0; j < nPerComp; ++j)
319 {
320 in[j] = static_cast<NekDouble>(coeffs[base + j]);
321 }
322
323 homoExpList->Homogeneous1DTrans(static_cast<int>(nPerComp), in, out,
324 forwards);
325
326 for (size_t j = 0; j < nPerComp; ++j)
327 {
328 coeffs[base + j] = static_cast<TData>(out[j]);
329 }
330 }
331 }
const Array< OneD, NekDouble > base(3, 0.0)
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp TData *NEK_RESTRICT const TData *NEK_RESTRICT in
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t const unsigned int const unsigned int const unsigned int const unsigned int const size_t const TData *NEK_RESTRICT const TData *NEK_RESTRICT const TUseSharedWsp TData *NEK_RESTRICT const TData *NEK_RESTRICT TData *NEK_RESTRICT out

References TestOp< TData, FieldState::Coeff, FieldState::Coeff >::fixt_in, Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), and Nektar::LibUtilities::Field< TData, TState >::GetNumHomoModes().

Referenced by TestLinAdvDiffReaction< TData >::ExpectedSolution().

◆ RunTestCase()

template<typename TData >
void TestLinAdvDiffReaction< TData >::RunTestCase ( )
inline

Definition at line 160 of file TestLinAdvDiffReaction.hpp.

161 {
162 auto advelblockAttr = GetBlockAttributes<TData, FieldState::Phys>(
163 this->fixt_explist,
164 MultiRegions::UnitInterleaveWidths(this->fixt_explist));
165 auto vel =
166 Field<TData, FieldState::Phys>("vel", advelblockAttr, m_nVelComp,
167 this->fixt_in->GetNumHomoModes());
168 vel.template CopyArray<NektarSpaces::HostSpace>(m_vel);
169
171 this->fixt_explist, this->session->GetVariables());
172
173 // seem to have the negative definitio of lambda implemented currently
174 LinADR->SetLambda(-1.0 * m_lambda);
175 if (m_varDiffHelper.field)
176 {
177 LinADR->SetVarDiffCoeff(*m_varDiffHelper.field);
178 // Updating after SetVarDiffCoeff checks the Field is borrowed.
179 m_varDiffHelper.CopyToField();
180 }
181 else
182 {
183 LinADR->SetDiffCoeff(m_diffCoeff);
184 }
185 LinADR->SetAdvVel(vel);
186 LinADR->Apply(*this->fixt_in, *this->fixt_out);
187 }
A Field represents expansion data to be operated on.
static std::shared_ptr< LinAdvDiffReactionOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Create a linearised advection-diffusion-reaction operator through the operator and block-operator fac...
unsigned int m_nVelComp
Velocity components: one per coordinate direction, or three on a 3DH1 expansion, whose planes do not ...
LibUtilities::SessionReaderSharedPtr session
Definition TestOp.hpp:440

References Nektar::MultiRegions::LinAdvDiffReactionOp< TData >::Create(), TestOp< TData, FieldState::Coeff, FieldState::Coeff >::fixt_explist, TestOp< TData, FieldState::Coeff, FieldState::Coeff >::fixt_in, TestOp< TData, FieldState::Coeff, FieldState::Coeff >::fixt_out, Nektar::LibUtilities::Field< TData, TState >::GetNumHomoModes(), TestLinAdvDiffReaction< TData >::m_diffCoeff, TestLinAdvDiffReaction< TData >::m_lambda, TestLinAdvDiffReaction< TData >::m_nVelComp, TestLinAdvDiffReaction< TData >::m_varDiffHelper, TestLinAdvDiffReaction< TData >::m_vel, and TestOp< TData, FieldState::Coeff, FieldState::Coeff >::session.

◆ SetTestCase()

template<typename TData >
void TestLinAdvDiffReaction< TData >::SetTestCase ( const bool  varDiffCoeff = false)
inline

Definition at line 55 of file TestLinAdvDiffReaction.hpp.

56 {
57 // Set initial conditions.
58 for (unsigned int blk = 0; blk < this->fixt_in->GetBlocks().size();
59 ++blk)
60 {
61 auto &block = this->fixt_in->GetBlocks()[blk];
62 auto inptr =
63 block.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
64
65 const unsigned int nhomo = this->fixt_in->GetNumHomoModes();
66
67 for (unsigned int n = 0;
68 n < this->fixt_in->GetNumComponents() * nhomo; ++n)
69 {
70 // The planes of a component are consecutive, so n % nhomo is
71 // the plane this slice sits on. Giving it a single Fourier
72 // mode along z is what exercises the z terms at all: a
73 // profile flat in z carries only the k = 0 mode, where they
74 // vanish, and the test would pass without them.
75 const TData zfac =
76 (nhomo == 1)
77 ? TData(1.0)
78 : static_cast<TData>(std::cos(
79 2.0 * M_PI * static_cast<double>(n % nhomo) /
80 static_cast<double>(nhomo)));
81
82 for (size_t el = 0, cnt = 0; el < block.GetNumElements(); ++el)
83 {
84 for (unsigned int coeff = 0; coeff < block.GetNumData();
85 ++coeff, ++cnt)
86 {
87 inptr[cnt] = coeff * zfac;
88 }
89 }
90 inptr += block.CompSize();
91 }
92 }
93
94 // Get lambda from this->session or default to 10.0
95 m_lambda = this->session->DefinesParameter("Lambda")
96 ? this->session->GetParameter("Lambda")
97 : 10.0;
98
99 // Set up diffusion coefficient.
100 m_coordDim = this->fixt_explist->GetCoordim(0);
101 const auto nDiffCoeff = m_coordDim * (m_coordDim + 1) / 2;
102 m_diffCoeff.resize(nDiffCoeff);
103
104 if (m_coordDim == 1)
105 {
106 m_diffCoeff[0] = 1.0; // D00
107 }
108 else if (m_coordDim == 2)
109 {
110 m_diffCoeff[0] = 1.0; // D00
111 m_diffCoeff[2] = 1.0; // D11
112 }
113 else
114 {
115 m_diffCoeff[0] = 1.0; // D00
116 m_diffCoeff[2] = 1.0; // D11
117 m_diffCoeff[5] = 1.0; // D22
118 }
119
120 // Set advection velocity. The operator reads one velocity per
121 // coordinate direction on every plane, so a component spans them
122 // all; the planes are filled alike here, which is what lets the
123 // plane-wise reference below read any one of them.
124 const unsigned int nhomo = this->fixt_in->GetNumHomoModes();
125 size_t nphys = this->fixt_explist->GetTotPoints() / nhomo;
126 m_velCompStride = nphys * nhomo;
127
128 // A 3DH1 expansion wants a third component along the homogeneous
129 // direction, which its two-dimensional planes do not count. It is
130 // left at zero: the plane-wise reference cannot express the z
131 // advection, so a non-zero one would have nothing to compare with.
132 m_nVelComp = (nhomo == 1) ? m_coordDim : 3u;
135 for (unsigned int d = 1; d < m_coordDim; ++d)
136 {
138 tmp = m_vel + d * m_velCompStride, 1);
139 }
140
141 // Set up variable diffusion coefficient. The Field keeps the initial
142 // values; RunTestCase copies the scaled ones in after borrowing it.
143 if (varDiffCoeff)
144 {
145 m_varDiffHelper.Initialise(this->fixt_explist,
146 this->fixt_in->GetNumHomoModes());
147 for (auto &component : m_varDiffHelper.values)
148 {
149 for (unsigned int p = 0; p < component.size(); ++p)
150 {
151 component[p] *= 1.25;
152 }
153 }
154 }
155
156 // Compute expected solution.
158 }
std::vector< BlockAccessor< TData, TState > > & GetBlocks()
Get BlockAccessors for the field.
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, TestLinAdvDiffReaction< TData >::ExpectedSolution(), Vmath::Fill(), TestOp< TData, FieldState::Coeff, FieldState::Coeff >::fixt_explist, TestOp< TData, FieldState::Coeff, FieldState::Coeff >::fixt_in, Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), Nektar::LibUtilities::Field< TData, TState >::GetNumHomoModes(), TestLinAdvDiffReaction< TData >::m_coordDim, TestLinAdvDiffReaction< TData >::m_diffCoeff, TestLinAdvDiffReaction< TData >::m_lambda, TestLinAdvDiffReaction< TData >::m_nVelComp, TestLinAdvDiffReaction< TData >::m_varDiffHelper, TestLinAdvDiffReaction< TData >::m_vel, TestLinAdvDiffReaction< TData >::m_velCompStride, and TestOp< TData, FieldState::Coeff, FieldState::Coeff >::session.

Member Data Documentation

◆ m_coordDim

template<typename TData >
unsigned int TestLinAdvDiffReaction< TData >::m_coordDim
private

◆ m_diffCoeff

template<typename TData >
std::vector<TData> TestLinAdvDiffReaction< TData >::m_diffCoeff
private

◆ m_lambda

template<typename TData >
TData TestLinAdvDiffReaction< TData >::m_lambda
private

◆ m_nVelComp

template<typename TData >
unsigned int TestLinAdvDiffReaction< TData >::m_nVelComp = 0
private

Velocity components: one per coordinate direction, or three on a 3DH1 expansion, whose planes do not count the homogeneous direction.

Definition at line 341 of file TestLinAdvDiffReaction.hpp.

Referenced by TestLinAdvDiffReaction< TData >::RunTestCase(), and TestLinAdvDiffReaction< TData >::SetTestCase().

◆ m_varDiffHelper

template<typename TData >
VariableDiffusion<TData> TestLinAdvDiffReaction< TData >::m_varDiffHelper
private

◆ m_vel

template<typename TData >
Array<OneD, TData> TestLinAdvDiffReaction< TData >::m_vel
private

◆ m_velCompStride

template<typename TData >
size_t TestLinAdvDiffReaction< TData >::m_velCompStride = 0
private

Step from one velocity component to the next: one plane's points times the number of planes.

Definition at line 338 of file TestLinAdvDiffReaction.hpp.

Referenced by TestLinAdvDiffReaction< TData >::ExpectedSolution(), and TestLinAdvDiffReaction< TData >::SetTestCase().