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

#include <TestExpression.hpp>

Inheritance diagram for TestExpression< TData >:
[legend]

Public Member Functions

 TestExpression ()=default
 
void SetTestCase ()
 
void RunTestCase ()
 
void ExpectedSolution ()
 
- Public Member Functions inherited from TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::ContField >
 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

TData m_time
 
TData m_scale
 
- Protected Attributes inherited from TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::ContField >
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::Phys, FieldState::Phys, MultiRegions::ContField >
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 TestExpression< TData >

Definition at line 45 of file TestExpression.hpp.

Constructor & Destructor Documentation

◆ TestExpression()

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

Member Function Documentation

◆ ExpectedSolution()

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

Definition at line 112 of file TestExpression.hpp.

113 {
114 // Get number of variables and quadrature points
115 const unsigned int nVariables = this->session->GetVariables().size();
116 const size_t nphys = this->fixt_explist->GetTotPoints();
117
118 // Initialise array storage for forcing evaluation
119 Array<OneD, TData> fce(nVariables * nphys);
120
121 // Get coordinate data for function evaluation
122 Array<OneD, TData> x(nphys, 0.0);
123 Array<OneD, TData> y(nphys, 0.0);
124 Array<OneD, TData> z(nphys, 0.0);
125 this->fixt_explist->GetCoords(x, y, z);
126
127 // Copy this->fixt_in into NektarArray
128 Array<OneD, TData> inphys = this->fixt_in->ToArray();
129
130 // Gather fielddata (coordinates, time and EVARS)
131 std::vector<Array<OneD, const TData>> fielddata;
132 fielddata.push_back(x);
133 fielddata.push_back(y);
134 fielddata.push_back(z);
135 fielddata.push_back(Array<OneD, TData>(nphys, m_time));
136 for (unsigned int i = 0; i < nVariables; ++i)
137 {
138 fielddata.push_back(inphys + i * nphys);
139 }
140
141 // Evaluate function from this->session file
142 if (this->session->DefinesFunction("Forcing"))
143 {
144 // Evaluate function for each component
145 for (unsigned int i = 0; i < nVariables; ++i)
146 {
147 // Create reference to storage per variable
148 Array<OneD, TData> fce_var = fce + i * nphys;
149
150 // Get and evaluate function
151 auto func = this->session->GetFunction("Forcing", i);
152 func->Evaluate(fielddata, fce_var);
153
154 // Multiply by scalar and add to input data
155 Vmath::Smul(nphys, m_scale, fce_var, 1, fce_var, 1);
156 }
157 this->fixt_expected->template CopyArray<NektarSpaces::HostSpace>(
158 fce);
159 }
160 }
Nektar::Array< Nektar::OneD, TDataOut > ToArray()
Copy the data to a Nektar::Array, component by component and element by element, without padding,...
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
Definition Vmath.hpp:102

References TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::ContField >::fixt_expected, TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::ContField >::fixt_explist, TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::ContField >::fixt_in, TestExpression< TData >::m_scale, TestExpression< TData >::m_time, TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::ContField >::session, Vmath::Smul(), and Nektar::LibUtilities::Field< TData, TState >::ToArray().

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

◆ RunTestCase()

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

Definition at line 87 of file TestExpression.hpp.

88 {
89 std::string execStr = Operator<TData>::GetOpExecSpace(this->session);
90
91 // reshape this->fixt_in
92 if (execStr == "AVX")
93 {
95 NektarSpaces::GetVectorWidth<TData>(execStr), execStr);
96 }
97
99 this->session->GetVariables());
100 op->SetTime(m_time);
101 op->SetScale(m_scale);
102 std::vector<LibUtilities::EquationSharedPtr> expressions;
103 const auto numfields = this->session->GetVariables().size();
104 for (int nf = 0; nf < numfields; ++nf)
105 {
106 expressions.push_back(this->session->GetFunction("Forcing", nf));
107 }
108 op->SetExpressions(expressions);
109 op->Apply(*this->fixt_in, *this->fixt_out);
110 }
void ReshapeStorage(const unsigned int &interleaveWidth, const std::string &execSpace)
static std::shared_ptr< ExpressionOp< TData > > Create(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const std::string &execStr="", const std::string &implStr="")
Create an Expression operator through the two-stage element-operator factory and initialise its defau...
static std::string GetOpExecSpace(std::shared_ptr< LibUtilities::SessionReader > session, const bool warn=true)
Return the execution space name ("opExecSpace") for an operator.
Definition Operator.hpp:190

References Nektar::MultiRegions::ExpressionOp< TData >::Create(), TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::ContField >::fixt_explist, TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::ContField >::fixt_in, TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::ContField >::fixt_out, Nektar::MultiRegions::Operator< TData >::GetOpExecSpace(), TestExpression< TData >::m_scale, TestExpression< TData >::m_time, Nektar::LibUtilities::Field< TData, TState >::ReshapeStorage(), and TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::ContField >::session.

◆ SetTestCase()

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

Definition at line 51 of file TestExpression.hpp.

52 {
53 // Set initial conditions.
54 for (unsigned int blk = 0; blk < this->fixt_in->GetBlocks().size();
55 ++blk)
56 {
57 auto &block = this->fixt_in->GetBlocks()[blk];
58 auto inptr =
59 block.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
60 for (unsigned int n = 0; n < this->fixt_in->GetNumComponents() *
61 this->fixt_in->GetNumHomoModes();
62 ++n)
63 {
64 for (size_t el = 0, cnt = 0; el < block.GetNumElements(); ++el)
65 {
66 for (unsigned int phys = 0; phys < block.GetNumData();
67 ++phys, ++cnt)
68 {
69 inptr[cnt] = 1.0 + n;
70 }
71 }
72 inptr += block.CompSize();
73 }
74 }
75 // Set both to zero such that adding the forcing gives the same result
76 this->fixt_out->template Initialize<NektarSpaces::HostSpace>(0.0);
77 this->fixt_expected->template Initialize<NektarSpaces::HostSpace>(0.0);
78
79 // Define time and scalar
80 m_time = 0.1;
81 m_scale = 2.0;
82
83 // Compute expected solution.
85 }
SpatialDomains::Geometry * el
std::vector< BlockAccessor< TData, TState > > & GetBlocks()
Get BlockAccessors for the field.
unsigned int GetNumHomoModes() const
Gets the number of homogeneous modes.
unsigned int GetNumComponents() const
Gets the number of components for a vector field.

References el, TestExpression< TData >::ExpectedSolution(), TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::ContField >::fixt_expected, TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::ContField >::fixt_in, TestOp< TData, FieldState::Phys, FieldState::Phys, MultiRegions::ContField >::fixt_out, Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), Nektar::LibUtilities::Field< TData, TState >::GetNumHomoModes(), TestExpression< TData >::m_scale, and TestExpression< TData >::m_time.

Member Data Documentation

◆ m_scale

template<typename TData >
TData TestExpression< TData >::m_scale
protected

◆ m_time

template<typename TData >
TData TestExpression< TData >::m_time
protected