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

#include <TestLinearSolver.hpp>

Inheritance diagram for TestLinearSolver< TData >:
[legend]

Public Member Functions

 TestLinearSolver ()=default
 
virtual ~TestLinearSolver ()=default
 
void Configure ()
 Read the session, build the expansion list and allocate the fields the test cases work on.
 
bool Compare (TData tol)
 Compare the computed field to the expected one, with absolute tolerance tol. The two must have the same blocks and components; their interleave widths may differ.
 

Protected Member Functions

void SetSession ()
 
void SetExpList ()
 
void SetFixture ()
 

Protected Attributes

std::string m_meshName = ""
 
SessionReaderSharedPtr m_session
 
ExpListSharedPtr m_expList
 
Field< TData, FieldState::Phys > m_in
 
Field< TData, FieldState::Coeff > m_out
 
Field< TData, FieldState::Coeff > m_expected
 

Detailed Description

template<typename TData>
class TestLinearSolver< TData >

A test fixture holding the session, expansion list and fields that the linear system operators are exercised on: a physical space input, a coefficient space output, and the coefficient space result the operator is expected to produce.

The fixture constructor (destructor) is called before (after) each call to the BOOST_FIXTURE_TEST_CASE(<test name>, <fixture>) macro.

See "Single test case fixture" on the Boost.Test documentation for more details: https://www.boost.org/doc/libs/1_82_0/libs/test/doc/html/boost_test/tests_organization/fixtures/case.html

Definition at line 82 of file TestLinearSolver.hpp.

Constructor & Destructor Documentation

◆ TestLinearSolver()

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

◆ ~TestLinearSolver()

template<typename TData >
virtual TestLinearSolver< TData >::~TestLinearSolver ( )
virtualdefault

Member Function Documentation

◆ Compare()

template<typename TData >
bool TestLinearSolver< TData >::Compare ( TData  tol)
inline

Compare the computed field to the expected one, with absolute tolerance tol. The two must have the same blocks and components; their interleave widths may differ.

Returns
bool

Definition at line 106 of file TestLinearSolver.hpp.

107 {
108 auto rank = m_session->GetComm()->GetRank();
109
111 {
112 std::cout << "Mismatch of number of components." << std::endl;
113 return false;
114 }
115
117 {
118 std::cout << "Mismatch of number of homogeneous modes."
119 << std::endl;
120 return false;
121 }
122
123 if (m_expected.GetBlocks().size() != m_out.GetBlocks().size())
124 {
125 std::cout << "Mismatch of block size." << std::endl;
126 return false;
127 }
128
129 // ToVector() returns every component element by element, whatever
130 // the interleave width of each block, and leaves the fields as they
131 // are.
132 const std::vector<TData> out = m_out.template ToVector<TData>();
133 const std::vector<TData> expected =
134 m_expected.template ToVector<TData>();
135 const size_t compSize =
137
138 bool isMatch = true;
139
140 if (rank == 0)
141 {
142 printf("#elm #pts output expected "
143 "difference\n");
144 }
145 size_t blkOffset = 0;
146 for (unsigned int blk = 0; blk < m_out.GetBlocks().size(); ++blk)
147 {
148 const auto &outBlock = m_out.GetBlocks()[blk];
149 const auto &expBlock = m_expected.GetBlocks()[blk];
150 if ((outBlock.GetNumElements() != expBlock.GetNumElements()) ||
151 (outBlock.GetNumData() != expBlock.GetNumData()))
152 {
153 std::cout << "Mismatch of block structure." << std::endl;
154 return false;
155 }
156 const size_t nElmts = outBlock.GetNumElements();
157 const unsigned int nPts = outBlock.GetNumData();
158
159 for (unsigned int n = 0;
161 {
162 const TData *outptr = out.data() + n * compSize + blkOffset;
163 const TData *expptr =
164 expected.data() + n * compSize + blkOffset;
165 size_t MisMatchcnt = 0, total = 0;
166
167 for (size_t el = 0, cnt = 0; el < nElmts; ++el)
168 {
169 for (unsigned int pts = 0; pts < nPts; ++pts, ++cnt)
170 {
171 if (std::isnan(outptr[cnt]) ||
172 std::isinf(outptr[cnt]) ||
173 std::abs(outptr[cnt] - expptr[cnt]) > tol)
174 {
175 printf("%04lu %04u %20.16f %20.16f %20.16f\n", el,
176 pts, outptr[cnt], expptr[cnt],
177 std::abs(outptr[cnt] - expptr[cnt]));
178 MisMatchcnt++;
179 }
180 total++;
181 }
182 }
183
184 if (MisMatchcnt)
185 {
186 std::cout << "Number of mismatches in component " << n
187 << " on block " << blk << " is " << MisMatchcnt
188 << " out of " << total << " on rank: " << rank
189 << std::endl;
190 isMatch = false;
191 }
192 }
193 blkOffset += nElmts * nPts;
194 }
195
196 return isMatch;
197 }
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.
Field< TData, FieldState::Coeff > m_out
SessionReaderSharedPtr m_session
Field< TData, FieldState::Coeff > m_expected
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 el, Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), Nektar::LibUtilities::Field< TData, TState >::GetNumHomoModes(), TestLinearSolver< TData >::m_expected, TestLinearSolver< TData >::m_out, TestLinearSolver< TData >::m_session, and rank.

◆ Configure()

template<typename TData >
void TestLinearSolver< TData >::Configure ( void  )
inline

Read the session, build the expansion list and allocate the fields the test cases work on.

Definition at line 92 of file TestLinearSolver.hpp.

References TestLinearSolver< TData >::SetExpList(), TestLinearSolver< TData >::SetFixture(), and TestLinearSolver< TData >::SetSession().

◆ SetExpList()

template<typename TData >
void TestLinearSolver< TData >::SetExpList ( )
inlineprotected

Definition at line 233 of file TestLinearSolver.hpp.

234 {
236
238 m_session, graph, "u", true, false, Collections::eNoCollection);
239 m_expList->SetDataWarehouse();
240 }
SpatialDomains::MeshGraphSharedPtr graph
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)
ExpListSharedPtr m_expList

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::Collections::eNoCollection, graph, TestLinearSolver< TData >::m_expList, TestLinearSolver< TData >::m_session, and Nektar::SpatialDomains::MeshGraphIO::Read().

Referenced by TestLinearSolver< TData >::Configure(), and TestLinearADRSolve< TData >::Configure().

◆ SetFixture()

template<typename TData >
void TestLinearSolver< TData >::SetFixture ( )
inlineprotected

Definition at line 242 of file TestLinearSolver.hpp.

243 {
244 const unsigned int ncomp = m_session->GetVariables().size();
245 auto inBlockAttr = GetBlockAttributes<TData, FieldState::Phys>(
246 m_expList, MultiRegions::UnitInterleaveWidths(m_expList));
247 auto outBlockAttr = GetBlockAttributes<TData, FieldState::Coeff>(
248 m_expList, MultiRegions::UnitInterleaveWidths(m_expList));
249
250 m_in = Field<TData, FieldState::Phys>("f_in", inBlockAttr, ncomp, 1);
251 m_out =
252 Field<TData, FieldState::Coeff>("f_out", outBlockAttr, ncomp, 1);
253 m_expected = Field<TData, FieldState::Coeff>("f_expected", outBlockAttr,
254 ncomp, 1);
255 }
A Field represents expansion data to be operated on.
Field< TData, FieldState::Phys > m_in

References TestLinearSolver< TData >::m_expected, TestLinearSolver< TData >::m_expList, TestLinearSolver< TData >::m_in, TestLinearSolver< TData >::m_out, and TestLinearSolver< TData >::m_session.

Referenced by TestLinearSolver< TData >::Configure(), and TestLinearADRSolve< TData >::Configure().

◆ SetSession()

template<typename TData >
void TestLinearSolver< TData >::SetSession ( )
inlineprotected

Definition at line 207 of file TestLinearSolver.hpp.

208 {
209 std::string execStr(GlobalConfiguration::ExecStr());
210 std::string implStr(GlobalConfiguration::ImplStr());
211
212 BOOST_TEST_MESSAGE("Creating input and output fields");
213
214 // Construct a fake command-line argument array to be fed to
215 // Session::Reader::CreateInstance. The first element stands for
216 // the name of the executable which, in our case, doesn't matter.
217 int argc = 4;
218 char **argv = new char *[argc];
219 argv[0] = strdup("exe_name");
220 argv[1] = strdup(m_meshName.data());
221 argv[2] = strdup(("--opExecSpace=" + execStr).c_str());
222 argv[3] = strdup(("--opImpl=" + implStr).c_str());
223
225
226 for (int i = 0; i < argc; ++i)
227 {
228 free(argv[i]);
229 }
230 delete[] argv;
231 }
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.

References Nektar::LibUtilities::SessionReader::CreateInstance(), TestLinearSolver< TData >::m_meshName, and TestLinearSolver< TData >::m_session.

Referenced by TestLinearSolver< TData >::Configure(), and TestLinearADRSolve< TData >::Configure().

Member Data Documentation

◆ m_expected

template<typename TData >
Field<TData, FieldState::Coeff> TestLinearSolver< TData >::m_expected
protected

◆ m_expList

template<typename TData >
ExpListSharedPtr TestLinearSolver< TData >::m_expList
protected

◆ m_in

template<typename TData >
Field<TData, FieldState::Phys> TestLinearSolver< TData >::m_in
protected

◆ m_meshName

template<typename TData >
std::string TestLinearSolver< TData >::m_meshName = ""
protected

Definition at line 200 of file TestLinearSolver.hpp.

Referenced by TestLinearSolver< TData >::SetSession().

◆ m_out

template<typename TData >
Field<TData, FieldState::Coeff> TestLinearSolver< TData >::m_out
protected

◆ m_session

template<typename TData >
SessionReaderSharedPtr TestLinearSolver< TData >::m_session
protected