Nektar++
Loading...
Searching...
No Matches
TestHOutflowBndCond.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: TestHOutflowBndCond.cpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Unit tests of the high-order outflow boundary condition.
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#define BOOST_TEST_MODULE TestHOutflowBndCond
36
37// Boost.Test pulls in windows.h, whose min/max macros break tinysimd.
38#define NOMINMAX
39#include <boost/test/included/unit_test.hpp>
40
41#include <algorithm>
42#include <array>
43#include <cmath>
44#include <cstdlib>
45#include <cstring>
46
48
52
57
58using namespace Nektar;
59using namespace Nektar::detail;
60
62{
64 {
65#ifdef NEKTAR_USE_MPI
66 int argc = boost::unit_test::framework::master_test_suite().argc;
67 char **argv = boost::unit_test::framework::master_test_suite().argv;
68 MPI_Init(&argc, &argv);
69#endif
70 }
71
73 {
74#ifdef NEKTAR_USE_MPI
75 MPI_Finalize();
76#endif
77 }
78};
79
81
82namespace
83{
84template <unsigned int NDIM>
85void CheckPointFormula(const std::array<double, NDIM> &u,
86 const std::array<double, NDIM * NDIM> &gradient,
87 const std::array<double, NDIM> &normal,
88 const std::array<double, NDIM> &fb, const double kinvis,
89 const double theta, const double alpha1,
90 const double alpha2, const double U0, const double delta)
91{
92 double pressure = 0.0, divergence = 0.0;
93 std::array<double, NDIM> energyMinusFb{}, velocityFlux{};
94
95 HOutflowPressureKernel<NektarSpaces::Serial, NDIM>(
96 1, 1, u.data(), gradient.data(), normal.data(), fb.data(), kinvis, 1.0,
97 theta, alpha1, alpha2, U0, delta, &pressure, energyMinusFb.data(),
98 &divergence, 0);
99
100 double un = 0.0, u2 = 0.0, nGradUn = 0.0, expectedDiv = 0.0;
101 for (unsigned int d = 0; d < NDIM; ++d)
102 {
103 un += normal[d] * u[d];
104 u2 += u[d] * u[d];
105 expectedDiv += gradient[d * NDIM + d];
106 for (unsigned int j = 0; j < NDIM; ++j)
107 {
108 nGradUn += normal[d] * gradient[d * NDIM + j] * normal[j];
109 }
110 }
111 const double S0 = 0.5 * (1.0 - std::tanh(un / (U0 * delta)));
112 const double k1 = 0.5 * (theta + alpha2);
113 const double k2 = 0.5 * (1.0 - theta + alpha1);
114 double energyNormal = 0.0;
115 for (unsigned int d = 0; d < NDIM; ++d)
116 {
117 const double expectedEnergy =
118 (k1 * u2 * normal[d] + k2 * un * u[d]) * S0 - fb[d];
119 BOOST_TEST(energyMinusFb[d] == expectedEnergy,
120 boost::test_tools::tolerance(1.0e-13));
121 energyNormal += normal[d] * expectedEnergy;
122 }
123 const double expectedPressure = kinvis * nGradUn - energyNormal;
124 BOOST_TEST(divergence == expectedDiv,
125 boost::test_tools::tolerance(1.0e-13));
126 BOOST_TEST(pressure == expectedPressure,
127 boost::test_tools::tolerance(1.0e-13));
128
129 HOutflowVelocityKernel<NektarSpaces::Serial, NDIM>(
130 1, 1, &pressure, normal.data(), energyMinusFb.data(), &divergence,
131 kinvis, velocityFlux.data(), 0);
132 for (unsigned int d = 0; d < NDIM; ++d)
133 {
134 const double expected =
135 ((pressure - kinvis * expectedDiv) * normal[d] + energyMinusFb[d]) /
136 kinvis;
137 BOOST_TEST(velocityFlux[d] == expected,
138 boost::test_tools::tolerance(1.0e-13));
139 }
140}
141
142// Whether a boundary condition is part of the high-order outflow condition.
143bool IsHOutflow(const SpatialDomains::BoundaryConditionShPtr &condition)
144{
145 return StringUtils::IEquals(condition->GetUserDefined(), "HOutflow");
146}
147
148// Load the session given after `--` on the command line, as
149// `-- <ExecSpace> <Implementation> <Session.xml>`.
151{
152 const auto &suite = boost::unit_test::framework::master_test_suite();
153
154 const std::string execStr(suite.argv[1]);
155 const std::string implStr(suite.argv[2]);
156 const std::string meshName(suite.argv[3]);
157
158 int argc = 4;
159 char **argv = new char *[argc + 1];
160 argv[0] = strdup("TestHOutflowBndCond");
161 argv[1] = strdup(meshName.c_str());
162 argv[2] = strdup(("--opExecSpace=" + execStr).c_str());
163 argv[3] = strdup(("--opImpl=" + implStr).c_str());
164 argv[argc] = nullptr;
165
167 session->InitSession();
168
169 for (int i = 0; i < argc; ++i)
170 {
171 free(argv[i]);
172 }
173 delete[] argv;
174
175 return session;
176}
177
178// Set @p reference to interleave width 1 and @p interleaved to @p
179// interleaveWidth, and fill both with the same non-zero values, which are
180// returned in the layout of ToVector().
181std::vector<double> FillAtTwoWidths(
184 const unsigned int interleaveWidth)
185{
186 reference.Initialize<NektarSpaces::HostSpace>(0.0);
187 interleaved.Initialize<NektarSpaces::HostSpace>(0.0);
188 // The storage is zero, so it need not be reshaped.
189 interleaved.SetInterleaveWidth(interleaveWidth);
190
191 std::vector<double> initialValues(reference.ToVector<double>().size());
192 for (std::size_t i = 0; i < initialValues.size(); ++i)
193 {
194 initialValues[i] = 1.0 + 1.0e-3 * i;
195 }
196 reference.CopyVector<NektarSpaces::HostSpace>(initialValues);
197 interleaved.CopyVector<NektarSpaces::HostSpace>(initialValues);
198 return initialValues;
199}
200
201// Check that @p interleaved is still at @p interleaveWidth and holds the values
202// of
203// @p reference to within @p tolerance, and that the operator changed them
204// from @p initialValues.
205void CheckAtTwoWidths(
208 const unsigned int interleaveWidth,
209 const std::vector<double> &initialValues, const double tolerance)
210{
211 for (auto &block : interleaved.GetBlocks())
212 {
213 BOOST_TEST(block.GetInterleaveWidth() == interleaveWidth);
214 }
215
216 const auto referenceValues = reference.ToVector<double>();
217 const auto interleavedValues = interleaved.ToVector<double>();
218 BOOST_REQUIRE_EQUAL(interleavedValues.size(), referenceValues.size());
219 double maxChange = 0.0;
220 for (std::size_t i = 0; i < referenceValues.size(); ++i)
221 {
222 maxChange = std::max(maxChange,
223 std::abs(referenceValues[i] - initialValues[i]));
224 BOOST_TEST(std::abs(interleavedValues[i] - referenceValues[i]) <=
225 tolerance);
226 }
227 BOOST_TEST(maxChange > 1.0e-2);
228}
229} // namespace
230
231BOOST_AUTO_TEST_SUITE(TestHOutflowBndCond)
232
233BOOST_AUTO_TEST_CASE(outgoing_2d_default_parameters_nonzero_fb)
234{
235 CheckPointFormula<2>({1.25, -0.2}, {0.3, -0.4, 0.1, -0.15}, {1.0, 0.0},
236 {0.17, -0.08}, 0.025, 1.0, 0.0, 0.0, 1.0, 1.0 / 20.0);
237}
238
239BOOST_AUTO_TEST_CASE(backflow_2d_nondefault_energy_parameters)
240{
241 CheckPointFormula<2>({-0.6, 0.7}, {-0.2, 0.35, -0.45, 0.25}, {1.0, 0.0},
242 {-0.11, 0.09}, 0.04, 0.35, 0.4, 0.2, 1.7, 0.12);
243}
244
245BOOST_AUTO_TEST_CASE(backflow_3d_divergence_term)
246{
247 CheckPointFormula<3>({-0.35, 0.4, -0.15},
248 {0.2, -0.1, 0.3, -0.25, 0.15, 0.05, 0.4, -0.2, -0.3},
249 {0.0, 1.0, 0.0}, {0.03, -0.07, 0.12}, 0.015, 0.8, 0.1,
250 0.25, 0.9, 0.08);
251}
252
253// The pressure condition on a boundary region of two elements, through the
254// operator: a linear velocity field, whose gradient is exact, is extracted
255// onto the region and the Dirichlet pressure coefficients are compared with
256// the Dong formula evaluated from the analytic velocity at the boundary
257// points. Unlike the tests above, this checks the extraction and the block
258// layout of the boundary data, with the velocity at interleave width 1 and at
259// the interleave width of the execution space.
260BOOST_AUTO_TEST_CASE(build_boundary_element_data_manufactured_multi_element)
261{
262 const auto &suite = boost::unit_test::framework::master_test_suite();
263 if (suite.argc < 4)
264 {
265 // Run without a session, for the tests above only.
266 return;
267 }
268
269 auto session = CreateSession();
271 auto velocityExpList =
273 session, graph, "u", true, false, Collections::eNoCollection);
274 auto pressureExpList =
276 session, graph, "p", true, false, Collections::eNoCollection);
277 velocityExpList->SetDataWarehouse();
278 pressureExpList->SetDataWarehouse();
279
280 const std::vector<std::string> velocityComponents = {"u", "v"};
281 const std::vector<std::string> pressureComponents = {"p"};
282 const auto velocityPhysBlocks =
284 velocityExpList,
285 MultiRegions::UnitInterleaveWidths(velocityExpList));
286
287 // A linear velocity field, whose gradient PhysDerivOp reproduces to
288 // rounding error.
290 "manufactured velocity", velocityPhysBlocks, velocityComponents, 1);
291 velocity.Initialize<NektarSpaces::HostSpace>(0.0);
292 for (unsigned int blk = 0; blk < velocity.GetBlocks().size(); ++blk)
293 {
294 auto &velocityBlock = velocity.GetBlocks()[blk];
295 auto velocityPtr =
296 velocityBlock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
297 auto collection = GetCollection(velocityExpList, blk);
298 const auto &expansions = collection.GetExpVector();
299 for (unsigned int e = 0; e < expansions.size(); ++e)
300 {
301 Array<OneD, double> x(velocityBlock.GetNumData());
302 Array<OneD, double> y(velocityBlock.GetNumData());
303 Array<OneD, double> z(velocityBlock.GetNumData(), 0.0);
304 expansions[e]->GetCoords(x, y, z);
305 for (unsigned int p = 0; p < velocityBlock.GetNumData(); ++p)
306 {
307 const auto id = e * velocityBlock.GetNumData() + p;
308 velocityPtr[id] = 2.0 * x[p] + 3.0 * y[p] + 1.0;
309 velocityPtr[velocityBlock.CompSize() + id] =
310 -x[p] + 4.0 * y[p] - 2.0;
311 }
312 }
313 }
314
315 constexpr double kinvis = 0.3;
316 constexpr double scale = 1.0;
317 constexpr double fb0 = 0.1, fb1 = -0.2;
318
319 auto op =
320 HOutflowBndCondOp<double>::Create(pressureExpList, pressureComponents);
321 op->SetVelocityContext(velocityExpList, velocityComponents);
322 op->SetKinvis(kinvis);
323 op->SetScale(scale);
324
325 // The Dong pressure condition from the analytic velocity at the points
326 // of the region, projected and mapped onto the pressure coefficients.
327 const auto &bndExpansions = pressureExpList->GetBndCondExpansions();
328 const auto &bndConditions = pressureExpList->GetBndConditions();
329 const auto &localToGlobal = pressureExpList->GetLocalToGlobalMap();
330 const auto &coeffMap = localToGlobal->GetBndCondCoeffsToLocalCoeffsMap();
331 const auto &coeffSign = localToGlobal->GetBndCondCoeffsToLocalCoeffsSign();
332 const bool signChange = localToGlobal->GetSignChange();
333
334 Array<OneD, double> expectedCoeffs(pressureExpList->GetNcoeffs(), 0.0);
335 unsigned int bndCoeffOffset = 0;
336 bool foundRegion = false;
337 for (unsigned int n = 0; n < bndExpansions.size(); ++n)
338 {
339 auto bndExp = bndExpansions[n];
340 if (bndConditions[n]->GetBoundaryConditionType() ==
342 IsHOutflow(bndConditions[n]))
343 {
344 foundRegion = true;
345 const auto npts = bndExp->GetTotPoints();
346 Array<OneD, double> x(npts), y(npts), z(npts, 0.0);
347 bndExp->GetCoords(x, y, z);
349 pressureExpList->GetBoundaryNormals(n, normals);
350
351 Array<OneD, double> expectedPhys(npts, 0.0);
352 for (unsigned int p = 0; p < npts; ++p)
353 {
354 const double ux = 2.0 * x[p] + 3.0 * y[p] + 1.0;
355 const double uy = -x[p] + 4.0 * y[p] - 2.0;
356 const double u[2] = {ux, uy};
357 const double grad[2][2] = {{2.0, 3.0}, {-1.0, 4.0}};
358 const double nrm[2] = {normals[0][p], normals[1][p]};
359 const double fb[2] = {fb0, fb1};
360
361 double un = 0.0, u2 = 0.0, nGradUn = 0.0;
362 for (unsigned int d = 0; d < 2; ++d)
363 {
364 un += nrm[d] * u[d];
365 u2 += u[d] * u[d];
366 for (unsigned int j = 0; j < 2; ++j)
367 {
368 nGradUn += nrm[d] * grad[d][j] * nrm[j];
369 }
370 }
371 const double S0 = 0.5 * (1.0 - std::tanh(un / (1.0 * 0.05)));
372 const double k1 = 0.5 * (1.0 + 0.0);
373 const double k2 = 0.5 * (1.0 - 1.0 + 0.0);
374 double energyNormal = 0.0;
375 for (unsigned int d = 0; d < 2; ++d)
376 {
377 const double value =
378 (k1 * u2 * nrm[d] + k2 * un * u[d]) * S0 - fb[d];
379 energyNormal += nrm[d] * value;
380 }
381 expectedPhys[p] = kinvis * nGradUn - energyNormal;
382 }
383
384 Array<OneD, double> bndCoeffsOut(bndExp->GetNcoeffs(), 0.0);
385 bndExp->FwdTrans(expectedPhys, bndCoeffsOut);
386 for (unsigned int c = 0; c < bndExp->GetNcoeffs(); ++c)
387 {
388 const auto bndCoeff = bndCoeffOffset + c;
389 const auto localCoeff = coeffMap[bndCoeff];
390 expectedCoeffs[localCoeff] =
391 (signChange ? coeffSign[bndCoeff] : 1.0) * bndCoeffsOut[c];
392 }
393 }
394 bndCoeffOffset += bndExp->GetNcoeffs();
395 }
396 BOOST_REQUIRE_MESSAGE(foundRegion,
397 "No HOutflow pressure Dirichlet region found in "
398 "the extraction test fixture.");
399
401 "expected pressure coeffs",
403 pressureExpList,
404 MultiRegions::UnitInterleaveWidths(pressureExpList)),
405 pressureComponents, 1);
406 expected.Initialize<NektarSpaces::HostSpace>(0.0);
407 for (unsigned int blk = 0; blk < expected.GetBlocks().size(); ++blk)
408 {
409 auto &expectedBlock = expected.GetBlocks()[blk];
410 auto expectedPtr =
411 expectedBlock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
412 auto collection = GetCollection(pressureExpList, blk);
413 const auto &expansions = collection.GetExpVector();
414 for (unsigned int e = 0; e < expansions.size(); ++e)
415 {
416 const auto offset =
417 pressureExpList->GetCoeff_Offset(expansions[e]->GetElmtId());
418 std::copy(expectedCoeffs.begin() + offset,
419 expectedCoeffs.begin() + offset +
420 expectedBlock.GetNumData(),
421 expectedPtr + e * expectedBlock.GetNumData());
422 }
423 }
424
425 const auto expectedValues = expected.ToVector<double>();
426 const auto maxExpected =
427 *std::max_element(expectedValues.begin(), expectedValues.end(),
428 [](const double lhs, const double rhs) {
429 return std::abs(lhs) < std::abs(rhs);
430 });
431 BOOST_TEST(std::abs(maxExpected) > 0.1);
432
433 // The velocity at interleave width 1 and at the interleave width of the
434 // execution space. The operator gathers it into fields at its width,
435 // whose width changes from one update to the next.
436 const auto execSpace =
438 const unsigned int interleaveWidth =
439 NektarSpaces::GetVectorWidth<double>(execSpace);
441 "pressure coeffs",
443 pressureExpList,
444 MultiRegions::UnitInterleaveWidths(pressureExpList)),
445 pressureComponents, 1);
446 for (const unsigned int velocityWidth : {1u, interleaveWidth, 1u})
447 {
448 velocity.ReshapeStorage(velocityWidth, execSpace);
449 op->UpdatePressure(velocity);
450 pressureCoeffs.Initialize<NektarSpaces::HostSpace>(0.0);
451 op->GetPressureDirichletOp()->Apply(pressureCoeffs);
452
453 const auto actualValues = pressureCoeffs.ToVector<double>();
454 BOOST_REQUIRE_EQUAL(actualValues.size(), expectedValues.size());
455 for (std::size_t i = 0; i < actualValues.size(); ++i)
456 {
457 BOOST_CHECK_MESSAGE(std::abs(actualValues[i] - expectedValues[i]) <
458 2.5e-10,
459 "velocity at width " << velocityWidth);
460 }
461 }
462}
463
464// The pressure coefficients set, and the velocity forcing added, in a field at
465// the interleave width of the execution space match those in the same field at
466// interleave width 1, and the fields keep their widths. Each field is applied
467// to twice, the widths alternating. The velocity forcing follows the pressure
468// as it stands when the velocity condition is applied.
469BOOST_AUTO_TEST_CASE(apply_interleaved_matches_width_one)
470{
471 const auto &suite = boost::unit_test::framework::master_test_suite();
472 if (suite.argc < 4)
473 {
474 // Run without a session, for the tests above only.
475 return;
476 }
477
478 auto session = CreateSession();
480 auto velocityExpList =
482 session, graph, "u", true, false, Collections::eNoCollection);
483 auto pressureExpList =
485 session, graph, "p", true, false, Collections::eNoCollection);
486 velocityExpList->SetDataWarehouse();
487 pressureExpList->SetDataWarehouse();
488
489 const std::vector<std::string> velocityComponents = {"u", "v"};
490 const std::vector<std::string> pressureComponents = {"p"};
491
492 // An outflow velocity, u . n = 2 on the regions, so that S0 = 0, and a
493 // solved pressure varying along them.
495 "outflow velocity",
497 velocityExpList,
498 MultiRegions::UnitInterleaveWidths(velocityExpList)),
499 velocityComponents, 1);
500 velocity.Initialize<NektarSpaces::HostSpace>(0.0);
501 for (auto &velocityBlock : velocity.GetBlocks())
502 {
503 auto velocityPtr =
504 velocityBlock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
505 const size_t nPoints =
506 velocityBlock.GetNumElements() * velocityBlock.GetNumData();
507 for (unsigned int d = 0; d < velocityComponents.size(); ++d)
508 {
509 std::fill(velocityPtr + d * velocityBlock.CompSize(),
510 velocityPtr + d * velocityBlock.CompSize() + nPoints,
511 -2.0);
512 }
513 }
515 "solved pressure",
517 pressureExpList,
518 MultiRegions::UnitInterleaveWidths(pressureExpList)),
519 pressureComponents, 1);
520 pressure.Initialize<NektarSpaces::HostSpace>(0.0);
521 for (unsigned int blk = 0; blk < pressure.GetBlocks().size(); ++blk)
522 {
523 auto &pressureBlock = pressure.GetBlocks()[blk];
524 auto pressurePtr =
525 pressureBlock.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
526 auto collection = GetCollection(pressureExpList, blk);
527 const auto &expansions = collection.GetExpVector();
528 for (unsigned int e = 0; e < expansions.size(); ++e)
529 {
530 Array<OneD, double> x(pressureBlock.GetNumData());
531 Array<OneD, double> y(pressureBlock.GetNumData());
532 Array<OneD, double> z(pressureBlock.GetNumData(), 0.0);
533 expansions[e]->GetCoords(x, y, z);
534 for (unsigned int p = 0; p < pressureBlock.GetNumData(); ++p)
535 {
536 pressurePtr[e * pressureBlock.GetNumData() + p] =
537 1.0 + x[p] + 2.0 * y[p];
538 }
539 }
540 }
541
542 constexpr double kinvis = 0.3;
543 auto op =
544 HOutflowBndCondOp<double>::Create(pressureExpList, pressureComponents);
545 op->SetVelocityContext(velocityExpList, velocityComponents);
546 op->SetKinvis(kinvis);
547 op->UpdatePressure(velocity);
548
549 const unsigned int interleaveWidth = NektarSpaces::GetVectorWidth<double>(
551
552 // The vertex shared by the two regions is set from both, on the device
553 // in either order, with values equal up to the rounding of the velocity
554 // gradient.
555 const auto pressureCoeffBlocks =
557 pressureExpList,
558 MultiRegions::UnitInterleaveWidths(pressureExpList));
560 "pressure coeffs at width 1", pressureCoeffBlocks, pressureComponents,
561 1);
563 "interleaved pressure coeffs", pressureCoeffBlocks, pressureComponents,
564 1);
565 const auto pressureInitialValues = FillAtTwoWidths(
566 pressureReference, pressureInterleaved, interleaveWidth);
567 auto pressureOp = op->GetPressureDirichletOp();
568 for (unsigned int pass = 0; pass < 2; ++pass)
569 {
570 pressureOp->Apply(pressureReference);
571 pressureOp->Apply(pressureInterleaved);
572 }
573 CheckAtTwoWidths(pressureReference, pressureInterleaved, interleaveWidth,
574 pressureInitialValues, 1.0e-12);
575
576 // The velocity forcing sums the contributions to the shared vertex
577 // before adding them, so both widths agree exactly.
578 op->SetPressure(pressure);
579 const auto velocityCoeffBlocks =
581 velocityExpList,
582 MultiRegions::UnitInterleaveWidths(velocityExpList));
584 "velocity coeffs at width 1", velocityCoeffBlocks, velocityComponents,
585 1);
587 "interleaved velocity coeffs", velocityCoeffBlocks, velocityComponents,
588 1);
589 const auto velocityInitialValues = FillAtTwoWidths(
590 velocityReference, velocityInterleaved, interleaveWidth);
591 auto velocityOp = op->GetVelocityNeumannOp();
592 for (unsigned int pass = 0; pass < 2; ++pass)
593 {
594 velocityOp->Apply(velocityReference);
595 velocityOp->Apply(velocityInterleaved);
596 }
597 CheckAtTwoWidths(velocityReference, velocityInterleaved, interleaveWidth,
598 velocityInitialValues, 0.0);
599
600 // The velocity condition computes the flux from the pressure as it
601 // stands when it is applied: refilling the pressure in place, without
602 // setting it again, changes the forcing, and restoring the pressure
603 // restores the forcing.
604 auto addToPressure = [&](const double shift) {
605 for (auto &pressureBlock : pressure.GetBlocks())
606 {
607 auto pressurePtr =
608 pressureBlock
609 .template GetPtr<NektarSpaces::HostSpace, ReadWrite>();
610 const size_t nPoints =
611 pressureBlock.GetNumElements() * pressureBlock.GetNumData();
612 for (size_t p = 0; p < nPoints; ++p)
613 {
614 pressurePtr[p] += shift;
615 }
616 }
617 };
618 auto applyVelocity = [&]() {
620 "velocity forcing", velocityCoeffBlocks, velocityComponents, 1);
622 velocityOp->Apply(forcing);
623 return forcing.ToVector<double>();
624 };
625 const auto forcing = applyVelocity();
626 addToPressure(0.5);
627 const auto shiftedForcing = applyVelocity();
628 addToPressure(-0.5);
629 const auto restoredForcing = applyVelocity();
630 BOOST_REQUIRE_EQUAL(shiftedForcing.size(), forcing.size());
631 BOOST_REQUIRE_EQUAL(restoredForcing.size(), forcing.size());
632 double maxShiftChange = 0.0, maxRestoredChange = 0.0;
633 for (std::size_t i = 0; i < forcing.size(); ++i)
634 {
635 maxShiftChange =
636 std::max(maxShiftChange, std::abs(shiftedForcing[i] - forcing[i]));
637 maxRestoredChange = std::max(maxRestoredChange,
638 std::abs(restoredForcing[i] - forcing[i]));
639 }
640 BOOST_TEST(maxShiftChange > 1.0e-2);
641 BOOST_TEST(maxRestoredChange <= 1.0e-12);
642}
643
644BOOST_AUTO_TEST_SUITE_END()
LibUtilities::SessionReaderSharedPtr session
SpatialDomains::MeshGraphSharedPtr graph
BOOST_TEST_GLOBAL_CONFIGURATION(GlobalConfiguration)
int64_t id
std::vector< NekDouble > grad
static std::shared_ptr< HOutflowBndCondOp< TData > > Create(const MultiRegions::ExpListSharedPtr &pressureExpansionList, const std::vector< std::string > &pressureComponents, const std::string &execStr="")
A Field represents expansion data to be operated on.
void CopyVector(const std::vector< TDataIn, Alloc > &array)
Templated copy method. This method copies data from a std::vector laid out as ToVector() returns it,...
void ReshapeStorage(const unsigned int &interleaveWidth, const std::string &execSpace)
std::vector< BlockAccessor< TData, TState > > & GetBlocks()
Get BlockAccessors for the field.
std::vector< TDataOut, Alloc > ToVector()
Copy the data to a std::vector, component by component and element by element, without padding,...
void Initialize(const TData val, const unsigned int streamID=0)
Templated initialize method: set every entry to val, but the padding, which is zero.
void SetInterleaveWidth(const unsigned int &interleaveWidth)
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
Common base class of the operator family interfaces: holds the expansion list, component names and da...
Definition Operator.hpp:100
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
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true, SpatialDomains::MeshGraphSharedPtr partitionedGraph=nullptr)
std::shared_ptr< SessionReader > SessionReaderSharedPtr
LibUtilities::SessionReaderSharedPtr CreateSession()
template std::vector< BlockAttributes< FieldState::Coeff > > GetBlockAttributes< double, FieldState::Coeff >(const MultiRegions::ExpListSharedPtr explist, const std::vector< unsigned int > &interleave_widths)
template std::vector< BlockAttributes< FieldState::Phys > > GetBlockAttributes< double, FieldState::Phys >(const MultiRegions::ExpListSharedPtr explist, const std::vector< unsigned int > &interleave_widths)
Collections::Collection GetCollection(MultiRegions::ExpListSharedPtr expansionList, unsigned int block_idx)
std::shared_ptr< BoundaryConditionBase > BoundaryConditionShPtr
Definition Conditions.h:251
bool IEquals(std::string_view a, std::string_view b)
std::vector< double > d(NPUPPER *NPUPPER)
BOOST_AUTO_TEST_CASE(TestCanGetRawPtr)