Nektar++
Loading...
Searching...
No Matches
Typedefs | Functions
Nektar::FieldStorageUnitTests Namespace Reference

Typedefs

using PhysField = LibUtilities::Field< double, FieldState::Phys >
 

Functions

 BOOST_AUTO_TEST_CASE (TestMoveAssignOntoAllocatedRegion)
 Move assignment onto a region that already holds storage takes over the right-hand side's storage and leaves the right-hand side empty.
 
 BOOST_AUTO_TEST_CASE (TestSelfMoveAssign)
 Move assignment of a region to itself keeps its storage and values; freeing the old storage first must not free the storage being assigned.
 
 BOOST_AUTO_TEST_CASE (TestMoveAssignOntoMovedFromRegion)
 A region emptied by being moved from can be assigned again.
 
static PhysField MakeField (const size_t nelmt, const unsigned int ndata, const unsigned int ncomp, const double val)
 A field of nelmt elements with ndata points each, every value set to val; Initialize() allocates the field's contiguous storage.
 
 BOOST_AUTO_TEST_CASE (TestFieldMoveAssignOntoAllocatedField)
 Move assignment onto a field that already holds contiguous storage takes over the right-hand side's storage and blocks.
 
 BOOST_AUTO_TEST_CASE (TestFieldSelfMoveAssign)
 Move assignment of a field to itself keeps its storage and values.
 
template<FieldState TState>
static std::vector< double > InitializedValues (LibUtilities::Field< double, TState > &field, const double val)
 The entries Initialize(val) gives field, in storage order: val in its elements and zero in its padding. Within a component, entry i belongs to lane i % width of element group i / (ndata * width).
 
template<FieldState TState>
static void RunMultiFieldColumns ()
 The columns of a MultiField lie one after the other in their segment's storage, and a column moved out of the set keeps that storage alive.
 
 BOOST_AUTO_TEST_CASE (TestMultiFieldColumnsCoeff)
 
 BOOST_AUTO_TEST_CASE (TestMultiFieldColumnsPhys)
 
 BOOST_AUTO_TEST_CASE (TestFieldInitializeInterleavedPadding)
 Initialize() leaves the padding zero at an interleave width above one, where an element group holds both elements and padding: a partly padded group followed by a wholly padded one, a block without padding, and a partly padded last group.
 

Typedef Documentation

◆ PhysField

Definition at line 49 of file TestFieldStorage.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/8]

Nektar::FieldStorageUnitTests::BOOST_AUTO_TEST_CASE ( TestFieldInitializeInterleavedPadding  )

Initialize() leaves the padding zero at an interleave width above one, where an element group holds both elements and padding: a partly padded group followed by a wholly padded one, a block without padding, and a partly padded last group.

Definition at line 253 of file TestFieldStorage.cpp.

254{
255 const std::vector<BlockAttributes<FieldState::Phys>> attr = {
256 {5, 16, 3, 8}, {8, 8, 2, 8}, {11, 16, 2, 8}};
257 PhysField field(attr, 2, 1);
258 field.Initialize<HostSpace>(3.0);
259
260 const auto values = InitializedValues(field, 3.0);
261 BOOST_REQUIRE_EQUAL(values.size(), field.size());
262 for (size_t blk = 0, i = 0; blk < field.GetBlocks().size(); ++blk)
263 {
264 auto &block = field.GetBlocks()[blk];
265 const double *ptr = block.GetPtr<HostSpace, ReadOnly>();
266 for (size_t k = 0; k < block.CompSize() * field.GetNumComponents();
267 ++k, ++i)
268 {
269 BOOST_CHECK_EQUAL(ptr[k], values[i]);
270 }
271 }
272}
static std::vector< double > InitializedValues(LibUtilities::Field< double, TState > &field, const double val)
The entries Initialize(val) gives field, in storage order: val in its elements and zero in its paddin...
LibUtilities::Field< double, FieldState::Phys > PhysField

References InitializedValues().

◆ BOOST_AUTO_TEST_CASE() [2/8]

Nektar::FieldStorageUnitTests::BOOST_AUTO_TEST_CASE ( TestFieldMoveAssignOntoAllocatedField  )

Move assignment onto a field that already holds contiguous storage takes over the right-hand side's storage and blocks.

Definition at line 126 of file TestFieldStorage.cpp.

127{
128 PhysField lhs = MakeField(4, 8, 2, 1.0);
129 PhysField rhs = MakeField(6, 8, 3, 2.0);
130 const double *rhsPtr = rhs.GetBlocks()[0].GetPtr<HostSpace, ReadOnly>();
131
132 lhs = std::move(rhs);
133
134 BOOST_CHECK_EQUAL(lhs.GetNumComponents(), 3);
135 BOOST_CHECK_EQUAL(lhs.size(), 6 * 8 * 3);
136 const double *lhsPtr = lhs.GetBlocks()[0].GetPtr<HostSpace, ReadOnly>();
137 BOOST_CHECK_EQUAL(lhsPtr, rhsPtr);
138 for (size_t i = 0; i < lhs.size(); ++i)
139 {
140 BOOST_CHECK_EQUAL(lhsPtr[i], 2.0);
141 }
142}
std::vector< BlockAccessor< TData, TState > > & GetBlocks()
Get BlockAccessors for the field.
static PhysField MakeField(const size_t nelmt, const unsigned int ndata, const unsigned int ncomp, const double val)
A field of nelmt elements with ndata points each, every value set to val; Initialize() allocates the ...

References Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), Nektar::LibUtilities::Field< TData, TState >::GetNumComponents(), MakeField(), and Nektar::LibUtilities::Field< TData, TState >::size().

◆ BOOST_AUTO_TEST_CASE() [3/8]

Nektar::FieldStorageUnitTests::BOOST_AUTO_TEST_CASE ( TestFieldSelfMoveAssign  )

Move assignment of a field to itself keeps its storage and values.

Definition at line 145 of file TestFieldStorage.cpp.

146{
147 PhysField field = MakeField(4, 8, 2, 3.0);
148 const double *before = field.GetBlocks()[0].GetPtr<HostSpace, ReadOnly>();
149
150 PhysField &alias = field;
151 field = std::move(alias);
152
153 BOOST_CHECK_EQUAL(field.size(), 4 * 8 * 2);
154 const double *after = field.GetBlocks()[0].GetPtr<HostSpace, ReadOnly>();
155 BOOST_CHECK_EQUAL(after, before);
156 for (size_t i = 0; i < field.size(); ++i)
157 {
158 BOOST_CHECK_EQUAL(after[i], 3.0);
159 }
160}

References MakeField().

◆ BOOST_AUTO_TEST_CASE() [4/8]

Nektar::FieldStorageUnitTests::BOOST_AUTO_TEST_CASE ( TestMoveAssignOntoAllocatedRegion  )

Move assignment onto a region that already holds storage takes over the right-hand side's storage and leaves the right-hand side empty.

Definition at line 53 of file TestFieldStorage.cpp.

54{
56 lhs.Initialize<HostSpace>(1.0);
58 rhs.Initialize<HostSpace>(2.0);
59 const double *rhsPtr = rhs.GetPtr<HostSpace, ReadOnly>();
60
61 lhs = std::move(rhs);
62
63 BOOST_CHECK_EQUAL(lhs.size(), 16);
64 BOOST_CHECK_EQUAL(rhs.size(), 0);
65 const double *lhsPtr = lhs.GetPtr<HostSpace, ReadOnly>();
66 BOOST_CHECK_EQUAL(lhsPtr, rhsPtr);
67 for (size_t i = 0; i < lhs.size(); ++i)
68 {
69 BOOST_CHECK_EQUAL(lhsPtr[i], 2.0);
70 }
71}
A MemoryRegion represents a memory region.

References Nektar::LibUtilities::MemoryRegion< TData >::GetPtr(), Nektar::LibUtilities::MemoryRegion< TData >::Initialize(), and Nektar::LibUtilities::MemoryRegion< TData >::size().

◆ BOOST_AUTO_TEST_CASE() [5/8]

Nektar::FieldStorageUnitTests::BOOST_AUTO_TEST_CASE ( TestMoveAssignOntoMovedFromRegion  )

A region emptied by being moved from can be assigned again.

Definition at line 94 of file TestFieldStorage.cpp.

95{
97 a.Initialize<HostSpace>(5.0);
98 MemoryRegion<double> b(std::move(a));
99
101 c.Initialize<HostSpace>(7.0);
102 a = std::move(c);
103
104 BOOST_CHECK_EQUAL(a.size(), 6);
105 BOOST_CHECK_EQUAL(b.size(), 4);
106 const double *aPtr = a.GetPtr<HostSpace, ReadOnly>();
107 const double *bPtr = b.GetPtr<HostSpace, ReadOnly>();
108 BOOST_CHECK_EQUAL(aPtr[5], 7.0);
109 BOOST_CHECK_EQUAL(bPtr[3], 5.0);
110}

◆ BOOST_AUTO_TEST_CASE() [6/8]

Nektar::FieldStorageUnitTests::BOOST_AUTO_TEST_CASE ( TestMultiFieldColumnsCoeff  )

Definition at line 239 of file TestFieldStorage.cpp.

240{
241 RunMultiFieldColumns<FieldState::Coeff>();
242}

◆ BOOST_AUTO_TEST_CASE() [7/8]

Nektar::FieldStorageUnitTests::BOOST_AUTO_TEST_CASE ( TestMultiFieldColumnsPhys  )

Definition at line 244 of file TestFieldStorage.cpp.

245{
246 RunMultiFieldColumns<FieldState::Phys>();
247}

◆ BOOST_AUTO_TEST_CASE() [8/8]

Nektar::FieldStorageUnitTests::BOOST_AUTO_TEST_CASE ( TestSelfMoveAssign  )

Move assignment of a region to itself keeps its storage and values; freeing the old storage first must not free the storage being assigned.

Definition at line 75 of file TestFieldStorage.cpp.

76{
77 MemoryRegion<double> region(8);
78 region.Initialize<HostSpace>(3.0);
79 const double *before = region.GetPtr<HostSpace, ReadOnly>();
80
81 MemoryRegion<double> &alias = region;
82 region = std::move(alias);
83
84 BOOST_CHECK_EQUAL(region.size(), 8);
85 const double *after = region.GetPtr<HostSpace, ReadOnly>();
86 BOOST_CHECK_EQUAL(after, before);
87 for (size_t i = 0; i < region.size(); ++i)
88 {
89 BOOST_CHECK_EQUAL(after[i], 3.0);
90 }
91}

References Nektar::LibUtilities::MemoryRegion< TData >::GetPtr(), Nektar::LibUtilities::MemoryRegion< TData >::Initialize(), and Nektar::LibUtilities::MemoryRegion< TData >::size().

◆ InitializedValues()

template<FieldState TState>
static std::vector< double > Nektar::FieldStorageUnitTests::InitializedValues ( LibUtilities::Field< double, TState > &  field,
const double  val 
)
static

The entries Initialize(val) gives field, in storage order: val in its elements and zero in its padding. Within a component, entry i belongs to lane i % width of element group i / (ndata * width).

Definition at line 166 of file TestFieldStorage.cpp.

168{
169 std::vector<double> values;
170 for (auto &block : field.GetBlocks())
171 {
172 const unsigned int width = block.GetInterleaveWidth();
173 const unsigned int ndata = block.GetNumData();
174 for (unsigned int n = 0;
175 n < field.GetNumComponents() * field.GetNumHomoModes(); ++n)
176 {
177 for (size_t i = 0; i < block.CompSize(); ++i)
178 {
179 const size_t e = (i / (ndata * width)) * width + i % width;
180 values.push_back(e < block.GetNumElements() ? val : 0.0);
181 }
182 }
183 }
184 return values;
185}

Referenced by BOOST_AUTO_TEST_CASE(), and RunMultiFieldColumns().

◆ MakeField()

static PhysField Nektar::FieldStorageUnitTests::MakeField ( const size_t  nelmt,
const unsigned int  ndata,
const unsigned int  ncomp,
const double  val 
)
static

A field of nelmt elements with ndata points each, every value set to val; Initialize() allocates the field's contiguous storage.

Definition at line 114 of file TestFieldStorage.cpp.

116{
117 std::vector<BlockAttributes<FieldState::Phys>> attr{
118 BlockAttributes<FieldState::Phys>(nelmt, nelmt, ndata, 1)};
119 PhysField field(attr, ncomp, 1);
120 field.Initialize<HostSpace>(val);
121 return field;
122}
A block means a group of elements of identical shape, basis and order. BlockAttributes stores the mos...
Definition Block.hpp:50

Referenced by BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ RunMultiFieldColumns()

template<FieldState TState>
static void Nektar::FieldStorageUnitTests::RunMultiFieldColumns ( )
static

The columns of a MultiField lie one after the other in their segment's storage, and a column moved out of the set keeps that storage alive.

Definition at line 189 of file TestFieldStorage.cpp.

190{
191 const std::vector<BlockAttributes<TState>> attr = {{4, 8, 2, 1},
192 {3, 4, 5, 1}};
193 const std::vector<std::string> comps = {"u", "v"};
194
195 LibUtilities::Field<double, TState> column;
196 const double *columnPtr = nullptr;
197 {
198 LibUtilities::MultiField<double, TState> X("X", attr, comps, 2);
199 X.ResizeNumField(2);
200 X[0].template Initialize<HostSpace>(1.0);
201 X[1].template Initialize<HostSpace>(2.0);
202
203 // Pointers taken outside BOOST_CHECK_EQUAL: the comma in the template
204 // arguments of GetPtr would split the macro's arguments.
205 const size_t fieldSize = X.GetFieldSize();
206 const double *base =
207 X[0].GetBlocks()[0].template GetPtr<HostSpace, ReadOnly>();
208 const double *block1 =
209 X[0].GetBlocks()[1].template GetPtr<HostSpace, ReadOnly>();
210 const double *column1 =
211 X[1].GetBlocks()[0].template GetPtr<HostSpace, ReadOnly>();
212 BOOST_CHECK_EQUAL(block1,
213 base + X[0].GetBlocks()[0].CompSize() * comps.size());
214 BOOST_CHECK_EQUAL(column1, base + fieldSize);
215 const auto ones = InitializedValues(X[0], 1.0);
216 const auto twos = InitializedValues(X[1], 2.0);
217 BOOST_REQUIRE_EQUAL(ones.size(), X[0].size());
218 for (size_t i = 0; i < X[0].size(); ++i)
219 {
220 BOOST_CHECK_EQUAL(base[i], ones[i]);
221 BOOST_CHECK_EQUAL(base[fieldSize + i], twos[i]);
222 }
223
224 columnPtr = base + fieldSize;
225 column = std::move(X[1]);
226 }
227
228 // The set is gone; the moved column still holds its place and values.
229 const double *movedPtr =
230 column.GetBlocks()[0].template GetPtr<HostSpace, ReadOnly>();
231 BOOST_CHECK_EQUAL(movedPtr, columnPtr);
232 const auto twos = InitializedValues(column, 2.0);
233 for (size_t i = 0; i < column.size(); ++i)
234 {
235 BOOST_CHECK_EQUAL(columnPtr[i], twos[i]);
236 }
237}
static double X[NNODE]
const Array< OneD, NekDouble > base(3, 0.0)

References Nektar::LibUtilities::Field< TData, TState >::GetBlocks(), InitializedValues(), Nektar::LibUtilities::Field< TData, TState >::size(), and X.