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

#include <TestLaplacian.hpp>

Inheritance diagram for TestLaplacian< TData >:
[legend]

Public Member Functions

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

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 TestLaplacian< TData >

Definition at line 47 of file TestLaplacian.hpp.

Constructor & Destructor Documentation

◆ TestLaplacian()

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

Member Function Documentation

◆ ExpectedSolution()

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

Definition at line 153 of file TestLaplacian.hpp.

154 {
155 // Calculate expected result from Nektar++.
156 const unsigned int numComp = this->fixt_in->GetNumComponents() *
157 this->fixt_in->GetNumHomoModes();
158 const size_t ncoeffs =
159 this->fixt_explist->GetNcoeffs() / this->fixt_in->GetNumHomoModes();
160
161 // Set up diffusion coefficient.
163 if (this->fixt_explist->GetCoordim(0) == 1)
164 {
165 factors[StdRegions::eFactorLambda] = 0.0;
166 }
167 else if (this->fixt_explist->GetCoordim(0) == 2)
168 {
169 factors[StdRegions::eFactorLambda] = 0.0;
173 }
174 else
175 {
183 }
184
185 Array<OneD, TData> incoeffs = this->fixt_in->ToArray();
186 Array<OneD, TData> outcoeffs(numComp * ncoeffs);
188
189 // The weak z-Laplacian of a 3DH1 field is (beta k)^2 M on each Fourier
190 // mode, so the reference transforms to wave space, applies a plane-wise
191 // Helmholtz carrying that lambda, and transforms back. The operator
192 // reaches the same result by another route, the mass matrix applied to
193 // minus the second z-derivative, so this is a genuine cross-check.
194 auto homoExpList =
195 std::dynamic_pointer_cast<MultiRegions::ExpListHomogeneous1D>(
196 this->fixt_explist);
197 const unsigned int nhomo = this->fixt_in->GetNumHomoModes();
198 const bool wave = homoExpList && nhomo > 1;
199
200 Array<OneD, NekDouble> lambdaK(nhomo, 0.0);
201 if (wave)
202 {
203 const NekDouble beta = 2.0 * M_PI / homoExpList->GetHomoLen();
204 for (unsigned int p = 0; p < nhomo; ++p)
205 {
206 const NekDouble betaK =
207 beta *
208 homoExpList->m_transposition->GetK(static_cast<int>(p));
209 lambdaK[p] = betaK * betaK;
210 }
211
212 HomogeneousTrans(homoExpList, ncoeffs, incoeffs, true);
213 }
214
215 for (unsigned int i = 0; i < numComp; ++i)
216 {
217 // The planes of a component are consecutive, so i % nhomo picks
218 // the Fourier mode this slice carries.
219 if (wave)
220 {
221 factors[StdRegions::eFactorLambda] = lambdaK[i % nhomo];
222 }
223
224 size_t e = 0;
225 size_t offset = i * ncoeffs;
226 for (const auto &block : this->fixt_expected->GetBlocks())
227 {
228 auto nmTot = this->fixt_explist->GetExp(e)->GetNcoeffs();
229 for (size_t el = 0; el < block.GetNumElements(); ++el)
230 {
232 wave ? StdRegions::eHelmholtz : StdRegions::eLaplacian,
233 this->fixt_explist->GetExp(e)->DetShapeType(),
234 *(this->fixt_explist->GetExp(e)), factors,
235 m_varDiffHelper.ForElement(this->fixt_explist, e));
236 if (m_varDiffHelper.field &&
237 this->fixt_explist->GetShapeDimension() == 1)
238 {
239 m_varDiffHelper.ApplySegment(
240 this->fixt_explist, e, incoeffs + offset,
241 tmp = outcoeffs + offset, 0.0);
242 }
243 else
244 {
245 this->fixt_explist->GetExp(e)->GeneralMatrixOp(
246 incoeffs + offset, tmp = outcoeffs + offset, mkey);
247 }
248 e++;
249 offset += nmTot;
250 }
251 }
252 }
253
254 if (wave)
255 {
256 HomogeneousTrans(homoExpList, ncoeffs, outcoeffs, false);
257 }
258
259 this->fixt_expected->template CopyArray<NektarSpaces::HostSpace>(
260 outcoeffs);
261 }
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.
std::vector< TData > m_diffCoeff
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::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, Nektar::StdRegions::eLaplacian, 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(), TestLaplacian< TData >::HomogeneousTrans(), TestLaplacian< TData >::m_diffCoeff, TestLaplacian< TData >::m_varDiffHelper, and Nektar::LibUtilities::Field< TData, TState >::ToArray().

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

◆ HomogeneousTrans()

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

268 {
269 const unsigned int nhomo = this->fixt_in->GetNumHomoModes();
270 const size_t nPerComp = ncoeffs * nhomo;
271
272 Array<OneD, NekDouble> in(nPerComp);
273 Array<OneD, NekDouble> out(nPerComp);
274
275 for (unsigned int c = 0; c < this->fixt_in->GetNumComponents(); ++c)
276 {
277 const size_t base = c * nPerComp;
278 for (size_t j = 0; j < nPerComp; ++j)
279 {
280 in[j] = static_cast<NekDouble>(coeffs[base + j]);
281 }
282
283 homoExpList->Homogeneous1DTrans(static_cast<int>(nPerComp), in, out,
284 forwards);
285
286 for (size_t j = 0; j < nPerComp; ++j)
287 {
288 coeffs[base + j] = static_cast<TData>(out[j]);
289 }
290 }
291 }
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 TestLaplacian< TData >::ExpectedSolution().

◆ RunTestCase()

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

Definition at line 136 of file TestLaplacian.hpp.

137 {
139 this->session->GetVariables());
140 if (m_varDiffHelper.field)
141 {
142 op->SetVarDiffCoeff(*m_varDiffHelper.field);
143 // Updating after SetVarDiffCoeff checks the Field is borrowed.
144 m_varDiffHelper.CopyToField();
145 }
146 else
147 {
148 op->SetDiffCoeff(m_diffCoeff);
149 }
150 op->Apply(*this->fixt_in, *this->fixt_out);
151 }
static std::shared_ptr< LaplacianOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Create a weak-Laplacian operator through the operator and block-operator factories.
LibUtilities::SessionReaderSharedPtr session
Definition TestOp.hpp:440

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

◆ SetTestCase()

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

Definition at line 52 of file TestLaplacian.hpp.

53 {
54 // Set initial conditions.
55 for (unsigned int blk = 0; blk < this->fixt_in->GetBlocks().size();
56 ++blk)
57 {
58 auto &block = this->fixt_in->GetBlocks()[blk];
59 auto inptr =
60 block.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
61 for (unsigned int n = 0; n < this->fixt_in->GetNumComponents() *
62 this->fixt_in->GetNumHomoModes();
63 ++n)
64 {
65 for (size_t el = 0, cnt = 0; el < block.GetNumElements(); ++el)
66 {
67 for (unsigned int coeff = 0; coeff < block.GetNumData();
68 ++coeff, ++cnt)
69 {
70 inptr[cnt] = coeff;
71 }
72 }
73 inptr += block.CompSize();
74 }
75 }
76
77 // Set up diffusion coefficient.
78 const auto dim = this->fixt_explist->GetShapeDimension();
79 const auto coordDim = this->fixt_explist->GetCoordim(0);
80 const auto nDiffCoeff = coordDim * (coordDim + 1) / 2;
81 m_diffCoeff.resize(nDiffCoeff);
82
83 // Set up (isotropic) diffusion coefficient.
84 if (coordDim == 1)
85 {
86 m_diffCoeff[0] = 1.0; // D00
87 }
88 else if (coordDim == 2)
89 {
90 if (dim == 1)
91 {
92 m_diffCoeff[0] = 1.0; // D00
93 m_diffCoeff[2] = 1.0; // D11
94 }
95 else
96 {
97 m_diffCoeff[0] = 2.0; // D00
98 m_diffCoeff[2] = 3.0; // D11
99 }
100 }
101 else
102 {
103 if (dim == 1)
104 {
105 m_diffCoeff[0] = 1.0; // D00
106 m_diffCoeff[2] = 1.0; // D11
107 m_diffCoeff[5] = 1.0; // D22
108 }
109 else
110 {
111 m_diffCoeff[0] = 2.0; // D00
112 m_diffCoeff[2] = 3.0; // D11
113 m_diffCoeff[5] = 4.0; // D22
114 }
115 }
116
117 // Set up variable diffusion coefficient. The Field keeps the initial
118 // values; RunTestCase copies the scaled ones in after borrowing it.
119 if (varDiffCoeff)
120 {
121 m_varDiffHelper.Initialise(this->fixt_explist,
122 this->fixt_in->GetNumHomoModes());
123 for (auto &component : m_varDiffHelper.values)
124 {
125 for (unsigned int p = 0; p < component.size(); ++p)
126 {
127 component[p] *= 1.25;
128 }
129 }
130 }
131
132 // Compute expected solution.
134 }
std::vector< BlockAccessor< TData, TState > > & GetBlocks()
Get BlockAccessors for the field.

References el, TestLaplacian< 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(), TestLaplacian< TData >::m_diffCoeff, and TestLaplacian< TData >::m_varDiffHelper.

Member Data Documentation

◆ m_diffCoeff

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

◆ m_varDiffHelper

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