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

#include <TestHelmholtz.hpp>

Inheritance diagram for TestHelmholtz< TData >:
[legend]

Public Member Functions

 TestHelmholtz ()=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.
 

Protected Attributes

VariableDiffusion< TData > m_varDiffHelper
 
TData m_lambda
 
std::vector< TData > m_diffCoeff
 
- 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
 

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.
 

Detailed Description

template<typename TData>
class TestHelmholtz< TData >

Definition at line 49 of file TestHelmholtz.hpp.

Constructor & Destructor Documentation

◆ TestHelmholtz()

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

Member Function Documentation

◆ ExpectedSolution()

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

Definition at line 173 of file TestHelmholtz.hpp.

174 {
175 // Calculate expected result from Nektar++.
176 const unsigned int numComp = this->fixt_in->GetNumComponents() *
177 this->fixt_in->GetNumHomoModes();
178 const size_t ncoeffs =
179 this->fixt_explist->GetNcoeffs() / this->fixt_in->GetNumHomoModes();
180
181 // Set up diffusion coefficient.
183 if (this->fixt_explist->GetCoordim(0) == 1)
184 {
186 }
187 else if (this->fixt_explist->GetCoordim(0) == 2)
188 {
193 }
194 else
195 {
203 }
204
205 Array<OneD, TData> incoeffs = this->fixt_in->ToArray();
206 Array<OneD, TData> outcoeffs(numComp * ncoeffs);
208
209 // The weak z-Laplacian of a 3DH1 field is (beta k)^2 M on each Fourier
210 // mode, which rides the existing lambda: the reference transforms to
211 // wave space, applies a plane-wise Helmholtz with lambda + (beta k)^2,
212 // and transforms back. The operator reaches the same result by another
213 // route, the mass matrix applied to minus the second z-derivative, so
214 // this is a genuine cross-check.
215 auto homoExpList =
216 std::dynamic_pointer_cast<MultiRegions::ExpListHomogeneous1D>(
217 this->fixt_explist);
218 const unsigned int nhomo = this->fixt_in->GetNumHomoModes();
219 const bool wave = homoExpList && nhomo > 1;
220
221 Array<OneD, NekDouble> lambdaK(nhomo, 0.0);
222 if (wave)
223 {
224 const NekDouble beta = 2.0 * M_PI / homoExpList->GetHomoLen();
225 for (unsigned int p = 0; p < nhomo; ++p)
226 {
227 const NekDouble betaK =
228 beta *
229 homoExpList->m_transposition->GetK(static_cast<int>(p));
230 lambdaK[p] = m_lambda + betaK * betaK;
231 }
232
233 HomogeneousTrans(homoExpList, ncoeffs, incoeffs, true);
234 }
235
236 for (unsigned int i = 0; i < numComp; ++i)
237 {
238 // The planes of a component are consecutive, so i % nhomo picks
239 // the Fourier mode this slice carries.
240 if (wave)
241 {
242 factors[StdRegions::eFactorLambda] = lambdaK[i % nhomo];
243 }
244
245 size_t e = 0;
246 size_t offset = i * ncoeffs;
247 for (const auto &block : this->fixt_expected->GetBlocks())
248 {
249 auto nmTot = this->fixt_explist->GetExp(e)->GetNcoeffs();
250 for (size_t el = 0; el < block.GetNumElements(); ++el)
251 {
254 this->fixt_explist->GetExp(e)->DetShapeType(),
255 *(this->fixt_explist->GetExp(e)), factors,
256 m_varDiffHelper.ForElement(this->fixt_explist, e));
257 if (m_varDiffHelper.field &&
258 this->fixt_explist->GetShapeDimension() == 1)
259 {
260 m_varDiffHelper.ApplySegment(
261 this->fixt_explist, e, incoeffs + offset,
262 tmp = outcoeffs + offset, m_lambda);
263 }
264 else
265 {
266 this->fixt_explist->GetExp(e)->GeneralMatrixOp(
267 incoeffs + offset, tmp = outcoeffs + offset, mkey);
268 }
269 e++;
270 offset += nmTot;
271 }
272 }
273 }
274
275 if (wave)
276 {
277 HomogeneousTrans(homoExpList, ncoeffs, outcoeffs, false);
278 }
279
280 this->fixt_expected->template CopyArray<NektarSpaces::HostSpace>(
281 outcoeffs);
282 }
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
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::vector< TData > m_diffCoeff
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)
StdRegions::ConstFactorMap factors

References Nektar::LibUtilities::beta, Nektar::StdRegions::eFactorCoeffD00, Nektar::StdRegions::eFactorCoeffD01, Nektar::StdRegions::eFactorCoeffD02, Nektar::StdRegions::eFactorCoeffD11, Nektar::StdRegions::eFactorCoeffD12, Nektar::StdRegions::eFactorCoeffD22, Nektar::StdRegions::eFactorLambda, Nektar::StdRegions::eHelmholtz, el, 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(), TestHelmholtz< TData >::HomogeneousTrans(), TestHelmholtz< TData >::m_diffCoeff, TestHelmholtz< TData >::m_lambda, TestHelmholtz< TData >::m_varDiffHelper, and Nektar::LibUtilities::Field< TData, TState >::ToArray().

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

◆ HomogeneousTrans()

template<typename TData >
void TestHelmholtz< 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 286 of file TestHelmholtz.hpp.

289 {
290 const unsigned int nhomo = this->fixt_in->GetNumHomoModes();
291 const size_t nPerComp = ncoeffs * nhomo;
292
293 Array<OneD, NekDouble> in(nPerComp);
294 Array<OneD, NekDouble> out(nPerComp);
295
296 for (unsigned int c = 0; c < this->fixt_in->GetNumComponents(); ++c)
297 {
298 const size_t base = c * nPerComp;
299 for (size_t j = 0; j < nPerComp; ++j)
300 {
301 in[j] = static_cast<NekDouble>(coeffs[base + j]);
302 }
303
304 homoExpList->Homogeneous1DTrans(static_cast<int>(nPerComp), in, out,
305 forwards);
306
307 for (size_t j = 0; j < nPerComp; ++j)
308 {
309 coeffs[base + j] = static_cast<TData>(out[j]);
310 }
311 }
312 }
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 TestHelmholtz< TData >::ExpectedSolution().

◆ RunTestCase()

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

Definition at line 155 of file TestHelmholtz.hpp.

156 {
158 this->session->GetVariables());
159 op->SetLambda(m_lambda);
160 if (m_varDiffHelper.field)
161 {
162 op->SetVarDiffCoeff(*m_varDiffHelper.field);
163 // Updating after SetVarDiffCoeff checks the Field is borrowed.
164 m_varDiffHelper.CopyToField();
165 }
166 else
167 {
168 op->SetDiffCoeff(m_diffCoeff);
169 }
170 op->Apply(*this->fixt_in, *this->fixt_out);
171 }
static std::shared_ptr< HelmholtzOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Create a weak-Helmholtz operator through the operator and block-operator factories.
LibUtilities::SessionReaderSharedPtr session
Definition TestOp.hpp:440

References Nektar::MultiRegions::HelmholtzOp< 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, TestHelmholtz< TData >::m_diffCoeff, TestHelmholtz< TData >::m_lambda, TestHelmholtz< TData >::m_varDiffHelper, and TestOp< TData, FieldState::Coeff, FieldState::Coeff >::session.

◆ SetTestCase()

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

Definition at line 54 of file TestHelmholtz.hpp.

55 {
56 // Set initial conditions.
57 for (unsigned int blk = 0; blk < this->fixt_in->GetBlocks().size();
58 ++blk)
59 {
60 auto &block = this->fixt_in->GetBlocks()[blk];
61 auto inptr =
62 block.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
63 const unsigned int nhomo = this->fixt_in->GetNumHomoModes();
64
65 for (unsigned int n = 0;
66 n < this->fixt_in->GetNumComponents() * nhomo; ++n)
67 {
68 // The planes of a component are consecutive, so n % nhomo is
69 // the plane this slice sits on. Giving it a single Fourier
70 // mode along z is what exercises the z terms at all: a
71 // profile flat in z carries only the k = 0 mode, where they
72 // vanish, and the test would pass without them.
73 const TData zfac =
74 (nhomo == 1)
75 ? TData(1.0)
76 : static_cast<TData>(std::cos(
77 2.0 * M_PI * static_cast<double>(n % nhomo) /
78 static_cast<double>(nhomo)));
79
80 for (size_t el = 0, cnt = 0; el < block.GetNumElements(); ++el)
81 {
82 for (unsigned int coeff = 0; coeff < block.GetNumData();
83 ++coeff, ++cnt)
84 {
85 inptr[cnt] = coeff * zfac;
86 }
87 }
88 inptr += block.CompSize();
89 }
90 }
91
92 // Get lambda from this->session or default to 10.0
93 m_lambda = this->session->DefinesParameter("Lambda")
94 ? this->session->GetParameter("Lambda")
95 : 10.0;
96
97 // Set up diffusion coefficient.
98 const auto dim = this->fixt_explist->GetShapeDimension();
99 const auto coordDim = this->fixt_explist->GetCoordim(0);
100 const auto nDiffCoeff = coordDim * (coordDim + 1) / 2;
101 m_diffCoeff.resize(nDiffCoeff);
102
103 if (coordDim == 1)
104 {
105 m_diffCoeff[0] = 1.0; // D00
106 }
107 else if (coordDim == 2)
108 {
109 if (dim == 1)
110 {
111 m_diffCoeff[0] = 1.0; // D00
112 m_diffCoeff[2] = 1.0; // D11
113 }
114 else
115 {
116 m_diffCoeff[0] = 2.0; // D00
117 m_diffCoeff[2] = 3.0; // D11
118 }
119 }
120 else
121 {
122 if (dim == 1)
123 {
124 m_diffCoeff[0] = 1.0; // D00
125 m_diffCoeff[2] = 1.0; // D11
126 m_diffCoeff[5] = 1.0; // D22
127 }
128 else
129 {
130 m_diffCoeff[0] = 2.0; // D00
131 m_diffCoeff[2] = 3.0; // D11
132 m_diffCoeff[5] = 4.0; // D22
133 }
134 }
135
136 // Set up variable diffusion coefficient. The Field keeps the initial
137 // values; RunTestCase copies the scaled ones in after borrowing it.
138 if (varDiffCoeff)
139 {
140 m_varDiffHelper.Initialise(this->fixt_explist,
141 this->fixt_in->GetNumHomoModes());
142 for (auto &component : m_varDiffHelper.values)
143 {
144 for (unsigned int p = 0; p < component.size(); ++p)
145 {
146 component[p] *= 1.25;
147 }
148 }
149 }
150
151 // Compute expected solution.
153 }
std::vector< BlockAccessor< TData, TState > > & GetBlocks()
Get BlockAccessors for the field.

References el, TestHelmholtz< TData >::ExpectedSolution(), 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(), TestHelmholtz< TData >::m_diffCoeff, TestHelmholtz< TData >::m_lambda, TestHelmholtz< TData >::m_varDiffHelper, and TestOp< TData, FieldState::Coeff, FieldState::Coeff >::session.

Member Data Documentation

◆ m_diffCoeff

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

◆ m_lambda

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

◆ m_varDiffHelper

template<typename TData >
VariableDiffusion<TData> TestHelmholtz< TData >::m_varDiffHelper
protected