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

#include <TestAdvectionWeakDG.hpp>

Inheritance diagram for TestAdvectionWeakDG< TData >:
[legend]

Public Member Functions

 TestAdvectionWeakDG ()=default
 
void SetTestCase ()
 
void RunTestCase ()
 
void ExpectedSolution ()
 
const Array< OneD, TData > & GetNormalVel ()
 
void GetFluxVector (const Array< OneD, Array< OneD, TData > > &physfield, Array< OneD, Array< OneD, Array< OneD, TData > > > &flux)
 
- Public Member Functions inherited from TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >
 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.
 

Public Attributes

LibUtilities::Field< TData, FieldState::Phys > * fixt_advectVel = nullptr
 
LibUtilities::Field< TData, FieldState::Phys > * fixt_traceAdvVel = nullptr
 
Array< OneD, TData > m_traceAdvVel
 
Array< OneD, TData > m_normalVel
 
Array< OneD, Array< OneD, TData > > m_advectVel
 

Additional Inherited Members

- Static Public Member Functions inherited from TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >
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::Phys, FieldState::Phys, MultiRegions::DisContField >
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 TestAdvectionWeakDG< TData >

Definition at line 51 of file TestAdvectionWeakDG.hpp.

Constructor & Destructor Documentation

◆ TestAdvectionWeakDG()

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

Member Function Documentation

◆ ExpectedSolution()

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

Definition at line 222 of file TestAdvectionWeakDG.hpp.

223 {
224 unsigned numComp = this->fixt_in->GetNumComponents();
225 size_t nphys = this->fixt_explist->GetTotPoints();
226
227 std::string advName;
228 std::string riemName;
229 this->session->LoadSolverInfo("AdvectionType", advName, "WeakDG");
230 auto advObject =
232 advObject->SetFluxVector(&TestAdvectionWeakDG::GetFluxVector, this);
233
234 this->session->LoadSolverInfo("UpwindType", riemName, "Upwind");
235 auto riemannSolver =
237 riemName, this->session);
238 riemannSolver->SetScalar("Vn", &TestAdvectionWeakDG::GetNormalVel,
239 this);
240
242 numComp);
243
244 std::vector<std::string> variables = this->session->GetVariables();
246 ASSERTL0(variables.size() >= numComp,
247 "numComp is larger than the number of variales");
248
249 for (unsigned i = 0; i < numComp; ++i)
250 {
251 // in case of orthogonal expansions reset expansion info for legacy
252 // code to work
253 if (!this->fixt_explist->GetExp(0)->IsBoundaryInteriorExpansion())
254 {
255 graph->ResetExpansionInfoToModified(variables[i]);
256 }
257 exp[i] =
259 this->session, graph, variables[i], true, true,
261 }
262
263 advObject->SetRiemannSolver(riemannSolver);
264 advObject->InitObject(this->session, exp);
265
267 Array<OneD, TData> out(nphys * numComp, 0.0);
268
269 Array<OneD, Array<OneD, TData>> inarray(numComp);
270 Array<OneD, Array<OneD, TData>> outarray(numComp);
271
272 for (unsigned i = 0; i < numComp; ++i)
273 {
274 inarray[i] = Array<OneD, TData>(nphys, 0.0);
275 for (size_t j = 0; j < nphys; j++)
276 {
277 inarray[i][j] = in[i * nphys + j];
278 }
279 outarray[i] = Array<OneD, TData>(nphys, 0.0);
280 }
281
282 advObject->Advect(numComp, exp, m_advectVel, inarray, outarray, 0);
283
284 for (unsigned i = 0; i < numComp; ++i)
285 {
286 for (size_t j = 0; j < nphys; ++j)
287 {
288 out[i * nphys + j] = outarray[i][j];
289 }
290 }
291
292 this->fixt_expected->template CopyArray<NektarSpaces::HostSpace>(out);
293 }
#define ASSERTL0(condition, msg)
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 GetNumComponents() const
Gets the number of components for a vector field.
tBasePtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
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)
void GetFluxVector(const Array< OneD, Array< OneD, TData > > &physfield, Array< OneD, Array< OneD, Array< OneD, TData > > > &flux)
Array< OneD, Array< OneD, TData > > m_advectVel
const Array< OneD, TData > & GetNormalVel()
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
AdvectionFactory & GetAdvectionFactory()
Gets the factory for initialising advection objects.
Definition Advection.cpp:43
RiemannSolverFactory & GetRiemannSolverFactory()

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL0, Nektar::LibUtilities::NekFactoryBase< tKey, tBase, tBasePtr, tParam >::CreateInstance(), Nektar::Collections::eNoCollection, TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_expected, TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_explist, TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_in, Nektar::SolverUtils::GetAdvectionFactory(), TestAdvectionWeakDG< TData >::GetFluxVector(), TestAdvectionWeakDG< TData >::GetNormalVel(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), Nektar::SolverUtils::GetRiemannSolverFactory(), graph, TestAdvectionWeakDG< TData >::m_advectVel, Nektar::SpatialDomains::MeshGraphIO::Read(), TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::session, and Nektar::LibUtilities::Field< TData, TState >::ToArray().

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

◆ GetFluxVector()

template<typename TData >
void TestAdvectionWeakDG< TData >::GetFluxVector ( const Array< OneD, Array< OneD, TData > > &  physfield,
Array< OneD, Array< OneD, Array< OneD, TData > > > &  flux 
)
inline

Definition at line 326 of file TestAdvectionWeakDG.hpp.

328 {
329 ASSERTL1(flux[0].size() == m_advectVel.size(),
330 "Dimension of flux array and velocity array do not match");
331
332 const int nq = this->fixt_explist->GetNpoints();
333
334 for (int i = 0; i < flux.size(); ++i)
335 {
336 for (int j = 0; j < flux[0].size(); ++j)
337 {
338 for (int k = 0; k < nq; ++k)
339 {
340 flux[i][j][k] = physfield[i][k] * m_advectVel[j][k];
341 }
342 }
343 }
344 }
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....

References ASSERTL1, TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_explist, and TestAdvectionWeakDG< TData >::m_advectVel.

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

◆ GetNormalVel()

template<typename TData >
const Array< OneD, TData > & TestAdvectionWeakDG< TData >::GetNormalVel ( )
inline

Definition at line 295 of file TestAdvectionWeakDG.hpp.

296 {
297 const unsigned coordDim = this->fixt_explist->GetCoordim(0);
298 const size_t nTracePts = this->fixt_explist->GetTrace()->GetTotPoints();
299
300 if (m_normalVel.size() == 0)
301 {
302 m_normalVel = Array<OneD, TData>(nTracePts, 0.0);
303 // Gather normals
304 Array<OneD, Array<OneD, TData>> traceNormals(coordDim);
305 for (unsigned i = 0; i < coordDim; ++i)
306 {
307 traceNormals[i] = Array<OneD, TData>(nTracePts, 0.0);
308 }
309
310 this->fixt_explist->GetTrace()->GetNormals(traceNormals);
311
312 // v = (1,1,...), so Vn = n · v = sum_k n_k
313 for (unsigned i = 0; i < coordDim; ++i)
314 {
315 for (size_t j = 0; j < nTracePts; ++j)
316 {
317 m_normalVel[j] +=
318 traceNormals[i][j] * m_traceAdvVel[i * nTracePts + j];
319 }
320 }
321 }
322
323 return m_normalVel;
324 }
Array< OneD, TData > m_traceAdvVel
Array< OneD, TData > m_normalVel

References TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_explist, TestAdvectionWeakDG< TData >::m_normalVel, and TestAdvectionWeakDG< TData >::m_traceAdvVel.

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

◆ RunTestCase()

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

Definition at line 180 of file TestAdvectionWeakDG.hpp.

181 {
182 this->fixt_explist->SetDataWarehouse();
183 this->fixt_explist->GetTrace()->SetDataWarehouse();
184
185 std::string riemName;
186 this->session->LoadSolverInfo("UpwindType", riemName, "Upwind");
187
188 auto AdvectOp = AdvectionWeakDGOp<TData>::Create(
189 this->fixt_explist, this->session->GetVariables());
190 // add prefix to name to match operator definition
191 riemName = "ScalarTraceFlux" + riemName;
192 auto TraceFlux = SolverCore::TraceFluxOp<TData>::Create(
193 this->fixt_explist, this->session->GetVariables(), riemName);
194
195 // Set up trace advection velocity on trace for upwind
196 // solver
197 size_t ncoordim = this->fixt_explist->GetCoordim(0);
199 "traceAdvVel",
201 this->fixt_explist),
202 ncoordim, 1);
203
204 // extract advection trace
205 auto physTraceExtractOp = PhysTraceExtractOp<double>::Create(
207 physTraceExtractOp->Apply(*this->fixt_advectVel, traceAdvVel);
208 // set up average value along trace
209 TraceFlux->SetTraceAdvVel(traceAdvVel);
210
211 // finally append TraceFlux to AdvectOp
212 AdvectOp->SetTraceFlux(TraceFlux);
213
214 auto VolumeFluxOp = LinearAdvVolumeFluxOp<TData>::Create(
215 this->fixt_explist, this->session->GetVariables());
216 VolumeFluxOp->SetAdvVel(*this->fixt_advectVel);
217 AdvectOp->SetVolumeFluxOp(VolumeFluxOp);
218
219 AdvectOp->Apply(*this->fixt_in, *this->fixt_out);
220 }
A Field represents expansion data to be operated on.
std::vector< std::string > GetComponentNames() const
Gets a copy of the components names for a vector field.
static std::shared_ptr< LinearAdvVolumeFluxOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="")
static std::shared_ptr< PhysTraceExtractOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Create a trace extraction operator through the operator and block-operator factories.
LibUtilities::Field< TData, FieldState::Phys > * fixt_advectVel
template std::vector< BlockAttributes< FieldState::Phys > > GetLocTraceBlockAttributes< double, FieldState::Phys >(const MultiRegions::ExpListSharedPtr explist, const unsigned interleave_width, const bool useGLLTracePoints)

References Nektar::LinearAdvVolumeFluxOp< TData >::Create(), Nektar::MultiRegions::PhysTraceExtractOp< TData >::Create(), TestAdvectionWeakDG< TData >::fixt_advectVel, TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_explist, TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_in, TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_out, Nektar::LibUtilities::Field< TData, TState >::GetComponentNames(), Nektar::MultiRegions::GetLocTraceBlockAttributes< double, FieldState::Phys >(), and TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::session.

◆ SetTestCase()

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

Definition at line 58 of file TestAdvectionWeakDG.hpp.

59 {
60
61 // Set initial conditions from the quadrature point coordinates. The
62 // coordinates do not move when the mesh is partitioned, so serial and
63 // parallel runs start from the same field and must finish with the
64 // same one; a value taken from the storage index instead would differ
65 // between rank counts, and its magnitude would grow with the element
66 // count, which is what forced the loose tolerances this test used to
67 // carry.
68 for (unsigned blk = 0, eid = 0; blk < this->fixt_in->GetBlocks().size();
69 ++blk)
70 {
71 auto &block = this->fixt_in->GetBlocks()[blk];
72 auto inptr =
73 block.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
74
75 const auto cdim = this->fixt_explist->GetCoordim(0);
76
77 for (unsigned n = 0; n < this->fixt_in->GetNumComponents() *
78 this->fixt_in->GetNumHomoModes();
79 ++n)
80 {
81 for (size_t el = 0, cnt = 0; el < block.GetNumElements(); ++el)
82 {
83 auto coords =
84 this->fixt_explist->GetExp(eid + el)->GetCoords();
85
86 for (unsigned phys = 0; phys < block.GetNumData();
87 ++phys, ++cnt)
88 {
89 TData v = 1.0 + TData(n);
90 for (unsigned d = 0; d < cdim; ++d)
91 {
92 v += TData(d + 1) * coords[d][phys];
93 }
94 inptr[cnt] = v;
95 }
96 }
97 inptr += block.CompSize();
98 }
99
100 eid += block.GetNumElements();
101 }
102
103 size_t ndim = this->fixt_explist->GetCoordim(0);
104 size_t nphys = this->fixt_explist->GetTotPoints();
105
106 auto blocks_in = GetBlockAttributes<TData, FieldState::Phys>(
107 this->fixt_explist,
108 MultiRegions::UnitInterleaveWidths(this->fixt_explist));
110 "f_advectVel", blocks_in, ndim, 1);
112 std::move(f_advectVel));
113
114 for (unsigned blk = 0; blk < fixt_advectVel->GetBlocks().size(); ++blk)
115 {
116
117 auto &block = fixt_advectVel->GetBlocks()[blk];
118 auto inptr =
119 block.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
120 for (unsigned nc = 0; nc < block.GetNumComponents(); ++nc)
121 {
122 for (size_t el = 0, cnt = 0; el < block.GetNumElements(); ++el)
123 {
124 for (unsigned phys = 0; phys < block.GetNumData();
125 ++phys, ++cnt)
126 {
127 // inptr[cnt] = phys;
128 inptr[cnt] = 1 + nc;
129 }
130 }
131 inptr += block.CompSize();
132 }
133 }
134
135 // offset advection velocities
138 for (int i = 0; i < ndim; ++i)
139 {
140 m_advectVel[i] = tmp + i * nphys;
141 }
142
143 auto blocks_trace = GetBlockAttributes<TData, FieldState::Phys>(
144 this->fixt_explist->GetTrace(),
145 MultiRegions::UnitInterleaveWidths(this->fixt_explist->GetTrace()));
146
148 "f_traceAdvVel", blocks_trace, ndim, 1);
150 std::move(f_traceAdvVel));
151
152 for (unsigned blk = 0; blk < fixt_traceAdvVel->GetBlocks().size();
153 ++blk)
154 {
155
156 auto &block = fixt_traceAdvVel->GetBlocks()[blk];
157 auto inptr =
158 block.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
159 for (unsigned nc = 0; nc < block.GetNumComponents(); ++nc)
160 {
161 for (size_t el = 0, cnt = 0; el < block.GetNumElements(); ++el)
162 {
163 for (unsigned phys = 0; phys < block.GetNumData();
164 ++phys, ++cnt)
165 {
166 // inptr[cnt] = phys;
167 inptr[cnt] = 1 + nc;
168 }
169 }
170 inptr += block.CompSize();
171 }
172 }
173
175
176 // Compute expected solution.
178 }
SpatialDomains::Geometry * el
std::vector< BlockAccessor< TData, TState > > & GetBlocks()
Get BlockAccessors for the field.
unsigned int GetNumHomoModes() const
Gets the number of homogeneous modes.
LibUtilities::Field< TData, FieldState::Phys > * fixt_traceAdvVel
std::vector< double > d(NPUPPER *NPUPPER)

References el, TestAdvectionWeakDG< TData >::ExpectedSolution(), TestAdvectionWeakDG< TData >::fixt_advectVel, TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_explist, TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_in, TestAdvectionWeakDG< TData >::fixt_traceAdvVel, Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), Nektar::LibUtilities::Field< TData, TState >::GetNumHomoModes(), TestAdvectionWeakDG< TData >::m_advectVel, TestAdvectionWeakDG< TData >::m_traceAdvVel, and Nektar::LibUtilities::Field< TData, TState >::ToArray().

Member Data Documentation

◆ fixt_advectVel

template<typename TData >
LibUtilities::Field<TData, FieldState::Phys>* TestAdvectionWeakDG< TData >::fixt_advectVel = nullptr

◆ fixt_traceAdvVel

template<typename TData >
LibUtilities::Field<TData, FieldState::Phys>* TestAdvectionWeakDG< TData >::fixt_traceAdvVel = nullptr

Definition at line 348 of file TestAdvectionWeakDG.hpp.

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

◆ m_advectVel

template<typename TData >
Array<OneD, Array<OneD, TData> > TestAdvectionWeakDG< TData >::m_advectVel

◆ m_normalVel

template<typename TData >
Array<OneD, TData> TestAdvectionWeakDG< TData >::m_normalVel

Definition at line 350 of file TestAdvectionWeakDG.hpp.

Referenced by TestAdvectionWeakDG< TData >::GetNormalVel().

◆ m_traceAdvVel

template<typename TData >
Array<OneD, TData> TestAdvectionWeakDG< TData >::m_traceAdvVel