261{
262 const auto &suite = boost::unit_test::framework::master_test_suite();
263 if (suite.argc < 4)
264 {
265
266 return;
267 }
268
271 auto velocityExpList =
274 auto pressureExpList =
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
288
290 "manufactured velocity", velocityPhysBlocks, velocityComponents, 1);
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>();
298 const auto &expansions = collection.GetExpVector();
299 for (
unsigned int e = 0;
e < expansions.size(); ++
e)
300 {
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 =
321 op->SetVelocityContext(velocityExpList, velocityComponents);
322 op->SetKinvis(kinvis);
323 op->SetScale(scale);
324
325
326
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
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();
347 bndExp->GetCoords(x, y, z);
349 pressureExpList->GetBoundaryNormals(n, normals);
350
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 {
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
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);
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>();
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
434
435
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);
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}
std::vector< NekDouble > grad
static std::string GetOpExecSpace(std::shared_ptr< LibUtilities::SessionReader > session, const bool warn=true)
Return the execution space name ("opExecSpace") for an operator.