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

Interior penalty diffusion, redesign against legacy. More...

#include <TestDiffusionIP.hpp>

Inheritance diagram for TestDiffusionIP< TData >:
[legend]

Public Member Functions

 TestDiffusionIP ()=default
 
void SetTestCase ()
 
void RunTestCase ()
 
void ExpectedSolution ()
 
void GetFluxCons (const int nDim, const Array< OneD, Array< OneD, TData > > &inarray, const TensorOfArray3D< TData > &qfield, TensorOfArray3D< TData > &viscousTensor, Array< OneD, int > &nonZeroIndex, const Array< OneD, Array< OneD, TData > > &normal)
 Isotropic unit viscous tensor, matching m_diffCoeff.
 
void GetFluxConsTrace (const int nDim, const Array< OneD, Array< OneD, TData > > &inarray, const TensorOfArray3D< TData > &qfield, TensorOfArray3D< TData > &outarray, Array< OneD, int > &nonZeroIndex, const Array< OneD, Array< OneD, TData > > &normal)
 The same flux on a trace, where it is already contracted with the normal.
 
void GetSymmFluxCons (const int nDim, const Array< OneD, Array< OneD, TData > > &inaverg, const Array< OneD, Array< OneD, TData > > &inarray, TensorOfArray3D< TData > &outarray, Array< OneD, int > &nonZeroIndex, const Array< OneD, Array< OneD, TData > > &normal)
 Symmetric flux for the interior penalty form.
 
void SpecialBndTreat (Array< OneD, Array< OneD, TData > > &consvar)
 Boundary fix-up hook. A scalar diffusion has nothing to correct - it exists for the compressible solver, which resets the energy at a wall - but DiffusionIP calls it unconditionally, so it has to be bound.
 
- 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.
 

Static Public Member Functions

static void SetAllNonZero (const unsigned n, Array< OneD, int > &nonZeroIndex)
 Mark every variable as carrying a non-zero flux.
 
- 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.
 

Public Attributes

std::vector< TData > m_diffCoeff
 

Additional Inherited Members

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

Interior penalty diffusion, redesign against legacy.

Mirrors the AdvectionWeakDG fixture. The value of having it is that diffusion previously had no operator-level test at all: its only cover was the solver regression cases, which report an L2 error against an exact solution and so say only that something is wrong, not where. This compares the operator's output pointwise against the legacy operator applied to the same field, which is what makes a discrepancy locatable.

Definition at line 61 of file TestDiffusionIP.hpp.

Constructor & Destructor Documentation

◆ TestDiffusionIP()

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

Member Function Documentation

◆ ExpectedSolution()

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

Definition at line 154 of file TestDiffusionIP.hpp.

155 {
156 unsigned numComp = this->fixt_in->GetNumComponents();
157 size_t nphys = this->fixt_explist->GetTotPoints();
159 "InteriorPenalty", "InteriorPenalty");
160 // DiffusionIP does not use m_fluxVector at all. It calls three
161 // separate functors, and leaving any of them unset is a
162 // bad_function_call at apply time rather than at setup. The third is
163 // the symmetric flux, which is where the symmetrising terms hook in.
164 diffObject->SetDiffusionFluxCons(&TestDiffusionIP::GetFluxCons, this);
165 diffObject->SetDiffusionFluxConsTrace(
167 diffObject->SetDiffusionSymmFluxCons(&TestDiffusionIP::GetSymmFluxCons,
168 this);
169 diffObject->SetSpecialBndTreat(&TestDiffusionIP::SpecialBndTreat, this);
170
171 // Scalars, not conservative variables; identical to what
172 // UnsteadyDiffusion now does, so this fixture and the legacy solver
173 // agree on what the reference semantics are.
174 std::static_pointer_cast<SolverUtils::DiffusionIP>(diffObject)
175 ->SetScalarAveraging(true);
176
178 numComp);
179
180 std::vector<std::string> variables = this->session->GetVariables();
182 ASSERTL0(variables.size() >= numComp,
183 "numComp is larger than the number of variables");
184
185 for (unsigned i = 0; i < numComp; ++i)
186 {
187 // in case of orthogonal expansions reset expansion info for legacy
188 // code to work
189 if (!this->fixt_explist->GetExp(0)->IsBoundaryInteriorExpansion())
190 {
191 graph->ResetExpansionInfoToModified(variables[i]);
192 }
193 exp[i] =
195 this->session, graph, variables[i], true, true,
197 }
198
199 diffObject->InitObject(this->session, exp);
200
202 Array<OneD, TData> out(nphys * numComp, 0.0);
203
204 Array<OneD, Array<OneD, TData>> inarray(numComp);
205 Array<OneD, Array<OneD, TData>> outarray(numComp);
206
207 for (unsigned i = 0; i < numComp; ++i)
208 {
209 inarray[i] = Array<OneD, TData>(nphys, 0.0);
210 for (size_t j = 0; j < nphys; j++)
211 {
212 inarray[i][j] = in[i * nphys + j];
213 }
214 outarray[i] = Array<OneD, TData>(nphys, 0.0);
215 }
216
217 diffObject->Diffuse(numComp, exp, inarray, outarray);
218
219 for (unsigned i = 0; i < numComp; ++i)
220 {
221 for (size_t j = 0; j < nphys; ++j)
222 {
223 out[i * nphys + j] = outarray[i][j];
224 }
225 }
226
227 this->fixt_expected->template CopyArray<NektarSpaces::HostSpace>(out);
228 }
#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 GetFluxConsTrace(const int nDim, const Array< OneD, Array< OneD, TData > > &inarray, const TensorOfArray3D< TData > &qfield, TensorOfArray3D< TData > &outarray, Array< OneD, int > &nonZeroIndex, const Array< OneD, Array< OneD, TData > > &normal)
The same flux on a trace, where it is already contracted with the normal.
void GetSymmFluxCons(const int nDim, const Array< OneD, Array< OneD, TData > > &inaverg, const Array< OneD, Array< OneD, TData > > &inarray, TensorOfArray3D< TData > &outarray, Array< OneD, int > &nonZeroIndex, const Array< OneD, Array< OneD, TData > > &normal)
Symmetric flux for the interior penalty form.
void GetFluxCons(const int nDim, const Array< OneD, Array< OneD, TData > > &inarray, const TensorOfArray3D< TData > &qfield, TensorOfArray3D< TData > &viscousTensor, Array< OneD, int > &nonZeroIndex, const Array< OneD, Array< OneD, TData > > &normal)
Isotropic unit viscous tensor, matching m_diffCoeff.
void SpecialBndTreat(Array< OneD, Array< OneD, TData > > &consvar)
Boundary fix-up hook. A scalar diffusion has nothing to correct - it exists for the compressible solv...
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
DiffusionFactory & GetDiffusionFactory()
Definition Diffusion.cpp:39

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::GetDiffusionFactory(), TestDiffusionIP< TData >::GetFluxCons(), TestDiffusionIP< TData >::GetFluxConsTrace(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), TestDiffusionIP< TData >::GetSymmFluxCons(), graph, Nektar::SpatialDomains::MeshGraphIO::Read(), TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::session, TestDiffusionIP< TData >::SpecialBndTreat(), and Nektar::LibUtilities::Field< TData, TState >::ToArray().

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

◆ GetFluxCons()

template<typename TData >
void TestDiffusionIP< TData >::GetFluxCons ( const int  nDim,
const Array< OneD, Array< OneD, TData > > &  inarray,
const TensorOfArray3D< TData > &  qfield,
TensorOfArray3D< TData > &  viscousTensor,
Array< OneD, int > &  nonZeroIndex,
const Array< OneD, Array< OneD, TData > > &  normal 
)
inline

Isotropic unit viscous tensor, matching m_diffCoeff.

Serves both the volume and the trace hook: with a constant unit diffusivity the flux is the gradient itself either side of a trace, so there is nothing to distinguish them.

Definition at line 247 of file TestDiffusionIP.hpp.

253 {
254 const unsigned nConvectiveFields = qfield[0].size();
255 const unsigned nPts = qfield[0][0].size();
256
257 // Which variables have a non-zero viscous flux. For a scalar it is
258 // all of them; the compressible solver leaves density out, which is
259 // why the hook exists. Leaving it empty is not neutral - DiffusionIP
260 // loops over it to decide what to write, so an unset one produces a
261 // silent zero rather than an error.
262 SetAllNonZero(nConvectiveFields, nonZeroIndex);
263
264 for (int j = 0; j < nDim; ++j)
265 {
266 for (unsigned i = 0; i < nConvectiveFields; ++i)
267 {
268 Vmath::Vcopy(nPts, qfield[j][i], 1, viscousTensor[j][i], 1);
269 }
270 }
271 }
static void SetAllNonZero(const unsigned n, Array< OneD, int > &nonZeroIndex)
Mark every variable as carrying a non-zero flux.
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition Vmath.hpp:828

References TestDiffusionIP< TData >::SetAllNonZero(), and Vmath::Vcopy().

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

◆ GetFluxConsTrace()

template<typename TData >
void TestDiffusionIP< TData >::GetFluxConsTrace ( const int  nDim,
const Array< OneD, Array< OneD, TData > > &  inarray,
const TensorOfArray3D< TData > &  qfield,
TensorOfArray3D< TData > &  outarray,
Array< OneD, int > &  nonZeroIndex,
const Array< OneD, Array< OneD, TData > > &  normal 
)
inline

The same flux on a trace, where it is already contracted with the normal.

So the output has one direction rather than nDim - which is the whole difference between this and GetFluxCons(), and why the reference implementation in NavierStokesCFE binds a different instantiation of its flux function here rather than the same one. Binding the volume form in this slot indexes the output past its first direction, and the failure surfaces well inside SolverUtils rather than at the binding.

Definition at line 284 of file TestDiffusionIP.hpp.

290 {
291 const unsigned nConvectiveFields = qfield[0].size();
292 const unsigned nPts = qfield[0][0].size();
293
294 SetAllNonZero(nConvectiveFields, nonZeroIndex);
295
296 for (unsigned i = 0; i < nConvectiveFields; ++i)
297 {
298 Vmath::Zero(nPts, outarray[0][i], 1);
299 for (int j = 0; j < nDim; ++j)
300 {
301 Vmath::Vvtvp(nPts, qfield[j][i], 1, normal[j], 1,
302 outarray[0][i], 1, outarray[0][i], 1);
303 }
304 }
305 }
void Vvtvp(int n, const T *w, const int incw, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
vvtvp (vector times vector plus vector): z = w*x + y
Definition Vmath.hpp:368
void Zero(int n, T *x, const int incx)
Zero vector.
Definition Vmath.hpp:275

References TestDiffusionIP< TData >::SetAllNonZero(), Vmath::Vvtvp(), and Vmath::Zero().

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

◆ GetSymmFluxCons()

template<typename TData >
void TestDiffusionIP< TData >::GetSymmFluxCons ( const int  nDim,
const Array< OneD, Array< OneD, TData > > &  inaverg,
const Array< OneD, Array< OneD, TData > > &  inarray,
TensorOfArray3D< TData > &  outarray,
Array< OneD, int > &  nonZeroIndex,
const Array< OneD, Array< OneD, TData > > &  normal 
)
inline

Symmetric flux for the interior penalty form.

With unit isotropic diffusivity this is the jump carried into each coordinate direction weighted by the trace normal. Kept separate from GetFluxCons() because it is the term the symmetrising work varies, and having it as its own hook is what lets that be exercised here.

Definition at line 315 of file TestDiffusionIP.hpp.

321 {
322 const unsigned nConvectiveFields = inarray.size();
323 const unsigned nPts = inarray[0].size();
324
325 SetAllNonZero(nConvectiveFields, nonZeroIndex);
326
327 for (int j = 0; j < nDim; ++j)
328 {
329 for (unsigned i = 0; i < nConvectiveFields; ++i)
330 {
331 Vmath::Vmul(nPts, inarray[i], 1, normal[j], 1, outarray[j][i],
332 1);
333 }
334 }
335 }
void Vmul(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x*y.
Definition Vmath.hpp:74

References TestDiffusionIP< TData >::SetAllNonZero(), and Vmath::Vmul().

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

◆ RunTestCase()

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

Definition at line 121 of file TestDiffusionIP.hpp.

122 {
123 // Legacy DiffusionIP loads IPPenaltyCoeff and never applies it - its
124 // production penalty is p^2 times the reciprocal length and nothing
125 // else - where the redesign multiplies the coefficient in. The
126 // redesign's default is 1 precisely so the two coincide, but this
127 // test should not depend on a default staying put: pin it, so the
128 // comparison means the same operator whatever the defaults become.
129 TData one = 1.0;
130 this->session->SetParameter("IPPenaltyCoeff", one);
131
132 this->fixt_explist->SetDataWarehouse();
133 this->fixt_explist->GetTrace()->SetDataWarehouse();
134
135 auto DiffusionOp = DiffusionIPOp<TData>::Create(
136 this->fixt_explist, this->session->GetVariables());
137
139 this->fixt_explist, this->session->GetVariables());
140
141 auto traceFluxOp = SolverCore::TraceFluxOp<TData>::Create(
142 this->fixt_explist, this->session->GetVariables(),
143 "DiffusionScalarIPTraceFlux");
144
145 volFluxOp->SetDiffCoeff(m_diffCoeff);
146 traceFluxOp->SetDiffCoeff(m_diffCoeff);
147
148 DiffusionOp->SetVolumeFluxOp(volFluxOp);
149 DiffusionOp->SetTraceFluxOp(traceFluxOp);
150
151 DiffusionOp->Apply(*this->fixt_in, *this->fixt_out);
152 }
static std::shared_ptr< DiffusionScalarVolFluxOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="")
std::vector< TData > m_diffCoeff

References Nektar::DiffusionScalarVolFluxOp< TData >::Create(), 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, TestDiffusionIP< TData >::m_diffCoeff, and TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::session.

◆ SetAllNonZero()

template<typename TData >
static void TestDiffusionIP< TData >::SetAllNonZero ( const unsigned  n,
Array< OneD, int > &  nonZeroIndex 
)
inlinestatic

Mark every variable as carrying a non-zero flux.

Definition at line 231 of file TestDiffusionIP.hpp.

232 {
233 nonZeroIndex = Array<OneD, int>(n);
234 for (unsigned i = 0; i < n; ++i)
235 {
236 nonZeroIndex[i] = i;
237 }
238 }

Referenced by TestDiffusionIP< TData >::GetFluxCons(), TestDiffusionIP< TData >::GetFluxConsTrace(), and TestDiffusionIP< TData >::GetSymmFluxCons().

◆ SetTestCase()

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

Definition at line 67 of file TestDiffusionIP.hpp.

68 {
69 // Set initial conditions from the quadrature point coordinates, which
70 // do not move when the mesh is partitioned, so serial and parallel
71 // runs start from the same field. Quadratic, so the second derivative
72 // the operator takes is not identically zero.
73 for (unsigned blk = 0, eid = 0; blk < this->fixt_in->GetBlocks().size();
74 ++blk)
75 {
76 auto &block = this->fixt_in->GetBlocks()[blk];
77 auto inptr =
78 block.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
79
80 const auto ndim = this->fixt_explist->GetCoordim(0);
81
82 for (unsigned n = 0; n < this->fixt_in->GetNumComponents() *
83 this->fixt_in->GetNumHomoModes();
84 ++n)
85 {
86 for (size_t el = 0, cnt = 0; el < block.GetNumElements(); ++el)
87 {
88 auto coords =
89 this->fixt_explist->GetExp(eid + el)->GetCoords();
90
91 for (unsigned phys = 0; phys < block.GetNumData();
92 ++phys, ++cnt)
93 {
94 TData v = 1.0 + TData(n);
95 for (unsigned d = 0; d < ndim; ++d)
96 {
97 const TData x = coords[d][phys];
98 v += TData(d + 1) * x + 0.5 * x * x;
99 }
100 inptr[cnt] = v;
101 }
102 }
103 inptr += block.CompSize();
104 }
105
106 eid += block.GetNumElements();
107 }
108
109 // Isotropic unit diffusivity, which is what the legacy flux vector
110 // below applies too.
111 const unsigned nDim = this->fixt_explist->GetCoordim(0);
112 m_diffCoeff.assign(nDim * (nDim + 1) / 2, TData(0.0));
113 for (unsigned d = 0; d < nDim; ++d)
114 {
115 m_diffCoeff[d * (d + 3) / 2] = TData(1.0);
116 }
117
119 }
SpatialDomains::Geometry * el
std::vector< BlockAccessor< TData, TState > > & GetBlocks()
Get BlockAccessors for the field.
unsigned int GetNumHomoModes() const
Gets the number of homogeneous modes.
std::vector< double > d(NPUPPER *NPUPPER)

References el, TestDiffusionIP< TData >::ExpectedSolution(), TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_explist, TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::DisContField >::fixt_in, Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), Nektar::LibUtilities::Field< TData, TState >::GetNumHomoModes(), and TestDiffusionIP< TData >::m_diffCoeff.

◆ SpecialBndTreat()

template<typename TData >
void TestDiffusionIP< TData >::SpecialBndTreat ( Array< OneD, Array< OneD, TData > > &  consvar)
inline

Boundary fix-up hook. A scalar diffusion has nothing to correct - it exists for the compressible solver, which resets the energy at a wall - but DiffusionIP calls it unconditionally, so it has to be bound.

Definition at line 340 of file TestDiffusionIP.hpp.

342 {
343 }

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

Member Data Documentation

◆ m_diffCoeff

template<typename TData >
std::vector<TData> TestDiffusionIP< TData >::m_diffCoeff