200 const std::vector<std::string> &components,
207 unsigned int block = 0;
209 unsigned int trace = 0;
212 std::map<int, VolumeFace> faceOwner;
214 const auto volumeBlocks =
215 MultiRegions::GetBlockAttributes<TData, FieldState::Phys>(
216 volumeExpList, MultiRegions::UnitInterleaveWidths(volumeExpList));
217 for (
unsigned int blk = 0; blk < volumeBlocks.size(); ++blk)
220 const auto &expansions = collection.GetExpVector();
221 for (
unsigned int e = 0;
e < expansions.size(); ++
e)
223 for (
unsigned int t = 0; t < expansions[
e]->GetNtraces(); ++t)
225 faceOwner[expansions[
e]->GetGeom()->GetTid(t)] = {
226 blk,
e, t, expansions[
e]};
235 unsigned int,
unsigned int,
unsigned int,
unsigned int>;
239 unsigned int ownerBlock = 0;
240 size_t ownerElmt = 0;
241 int ownerGeomId = -1;
242 size_t bcElmtFlat = 0;
244 std::vector<int> idmap;
248 std::vector<MatchedFace> faces;
249 unsigned int traceId = 0;
250 unsigned int volumeBlock = 0;
251 unsigned int bcBlock = 0;
255 std::map<BucketKey, BucketBuild> bucketBuild;
257 const auto bcBlocks =
258 bcExpList->GetNumElmts() == 0
259 ? std::vector<LibUtilities::BlockAttributes<FieldState::Phys>>{}
260 : MultiRegions::GetBlockAttributes<TData, FieldState::Phys>(
261 bcExpList, MultiRegions::UnitInterleaveWidths(bcExpList));
262 for (
unsigned int blk = 0; blk < bcBlocks.size(); ++blk)
265 const auto &expansions = collection.GetExpVector();
266 for (
unsigned int e = 0;
e < expansions.size(); ++
e)
268 const auto bcElmt = expansions[
e];
270 faceOwner.find(bcElmt->GetGeom()->GetGlobalID());
271 if (ownerIt == faceOwner.end())
275 const auto &owner = ownerIt->second;
276 const auto orient = owner.expansion->GetTraceOrient(owner.trace);
287 std::vector<int> idmap;
289 if (bcElmt->GetNumBases() > 1)
291 int id0 = 0, id1 = 1;
297 const int nq0 = bcElmt->GetNumPoints(id0);
298 const int nq1 = bcElmt->GetNumPoints(id1);
299 nDst =
static_cast<size_t>(nq0) *
static_cast<size_t>(nq1);
302 owner.expansion->GetTraceBasisKey(owner.trace, 0)
305 owner.expansion->GetTraceBasisKey(owner.trace, 1)
307 useGLL = ownerNq0 != nq0 || ownerNq1 != nq1;
314 owner.expansion->ReOrientTracePhysMap(orient, map, nq0, nq1,
316 idmap.assign(&map[0], &map[0] + nDst);
320 const int nq0 = bcElmt->GetNumPoints(0);
321 nDst =
static_cast<size_t>(nq0);
322 useGLL = owner.expansion->GetTraceBasisKey(owner.trace)
323 .GetNumPoints() != nq0;
326 for (
size_t q = 0; q < nDst; ++q)
328 idmap[q] =
static_cast<int>(
333 const unsigned int nm0 = owner.expansion->GetBasisNumModes(0);
334 const unsigned int nm1 = owner.expansion->GetNumBases() > 1
335 ? owner.expansion->GetBasisNumModes(1)
337 const unsigned int nm2 = owner.expansion->GetNumBases() > 2
338 ? owner.expansion->GetBasisNumModes(2)
340 BucketKey key{owner.expansion->DetShapeType(),
347 auto &build = bucketBuild[key];
348 build.traceId = owner.trace;
349 build.volumeBlock = owner.block;
354 ASSERTL1(build.faces.empty() || build.useGLL == useGLL,
355 "Elements of one bucket disagree on the trace points "
357 build.useGLL = useGLL;
360 face.ownerBlock = owner.block;
361 face.ownerElmt = owner.elmt;
362 face.ownerGeomId = owner.expansion->GetGeom()->GetGlobalID();
364 face.idmap = std::move(idmap);
365 build.faces.push_back(std::move(face));
369 m_buckets.reserve(bucketBuild.size());
370 const auto meshGraph =
graph ?
graph : volumeExpList->GetGraph();
371 ASSERTL0(meshGraph,
"PhysTraceExtractBndCond needs a mesh graph: pass "
372 "one when volumeExpList has none.");
373 const auto &volumeExpansionInfo =
374 meshGraph->GetExpansionInfo(components[0]);
378 const unsigned int nComp = components.size();
379 const auto makeBlock =
380 [nComp](
const std::string &name,
389 for (
auto &[key, build] : bucketBuild)
394 for (
const auto &face : build.faces)
396 const auto info = volumeExpansionInfo.find(face.ownerGeomId);
397 ASSERTL1(info != volumeExpansionInfo.end(),
398 "No expansion for a volume element of the boundary.");
399 restrictedInfo.emplace(*info);
402 auto restrictedExpList =
404 volumeExpList->GetSession(), restrictedInfo,
false);
405 restrictedExpList->SetDataWarehouse();
407 const auto restrictedBlocks =
408 MultiRegions::GetBlockAttributes<TData, FieldState::Phys>(
410 MultiRegions::UnitInterleaveWidths(restrictedExpList));
414 ASSERTL0(restrictedBlocks.size() == 1,
415 "The elements of a bucket must form one block.");
420 const size_t nElmts = build.faces.size();
422 const size_t nElmtsWithPadding =
423 ((nElmts + vectorWidth - 1) / vectorWidth) * vectorWidth;
425 nElmts, nElmtsWithPadding,
static_cast<unsigned int>(build.nDst),
429 makeBlock(
"PhysTraceExtractBndCondVolume", restrictedBlocks[0]),
430 makeBlock(
"PhysTraceExtractBndCondTrace", traceBlockAttr));
431 bucket.
traceId = build.traceId;
433 bucket.
bcBlock = build.bcBlock;
435 bucket.
nDst = build.nDst;
438 components, execStr);
441 bucket.
op->SetUseGLLTracePoints(
true);
445 std::map<int, size_t> geomIdToPos;
447 auto restrictedCollection =
449 const auto &restrictedExpansions =
450 restrictedCollection.GetExpVector();
451 for (
size_t p = 0; p < restrictedExpansions.size(); ++p)
453 geomIdToPos[restrictedExpansions[p]->GetGeom()->GetGlobalID()] =
460 bucket.
nVolume = restrictedBlocks[0].GetNumData();
463 "The elements of a bucket differ in their number of points "
464 "from those of their volume block.");
468 for (
const auto &face : build.faces)
470 const auto pos = geomIdToPos.at(face.ownerGeomId);
472 for (
size_t q = 0; q < bucket.
nDst; ++q)
475 face.bcElmtFlat * bucket.
nDst +
476 static_cast<size_t>(face.idmap[q]);
480 m_buckets.push_back(std::move(bucket));
483 std::set<unsigned int> streamSet;
484 for (
const auto &bucket : m_buckets)
486 streamSet.insert(bucket.volumeBlock + 1);
487 streamSet.insert(bucket.bcBlock + 1);
489 m_blockStreams.assign(streamSet.begin(), streamSet.end());
497 const unsigned int nComp =
out.GetNumComponents();
499 "PhysTraceExtractBndCond does not support homogeneous fields.");
501 (m_buckets.empty() ||
502 m_buckets[0].volumePhys.GetNumComponents() >= nComp),
503 "PhysTraceExtractBndCond: the input field must have at least "
504 "as many components as the output field, which has at most the "
505 "number it was built for.");
509 JoinStreams<ExecSpace>(m_opStreamID, m_blockStreams);
511 for (
auto &bucket : m_buckets)
515 auto &srcBlock =
in.GetBlocks()[bucket.volumeBlock];
521 const unsigned int width = srcBlock.GetInterleaveWidth();
522 if (bucket.gatherIndex.count(width) == 0)
524 BuildGatherIndex(bucket, width);
525 BuildScatterIndex(bucket, width);
527 bucket.volumePhys.template SetInterleaveWidth<TData>(width);
528 bucket.tracePhys.template SetInterleaveWidth<TData>(width);
531 srcBlock.template GetPtr<MemSpace, ReadOnly>(m_opStreamID);
532 auto volumePtr = bucket.volumePhys.template GetPtr<MemSpace, WriteOnly>(
534 auto &gatherIndex = bucket.gatherIndex.at(width);
536 gatherIndex.template GetPtr<MemSpace, ReadOnly>(m_opStreamID);
538 for (
unsigned int comp = 0; comp < nComp; ++comp)
540 CGBndCondGatherKernel<ExecSpace>(
541 gatherIndex.size(), gatherIdx,
542 srcPtr + comp * srcBlock.CompSize(),
543 volumePtr + comp * bucket.volumePhys.CompSize(), m_opStreamID);
547 bucket.op->ExtractTrace(bucket.traceId, bucket.volumePhys,
548 bucket.tracePhys, 0, 0);
550 auto &outBlock =
out.GetBlocks()[bucket.bcBlock];
552 ASSERTL0(outBlock.GetInterleaveWidth() == 1,
553 "PhysTraceExtractBndCond writes a boundary field at "
554 "interleave width 1 only.");
556 outBlock.template GetPtr<MemSpace, WriteOnly>(m_opStreamID);
558 bucket.tracePhys.template GetPtr<MemSpace, ReadOnly>(m_opStreamID);
559 auto &scatterIndex = bucket.scatterIndex.at(width);
560 auto traceIdx = scatterIndex.trace.template GetPtr<MemSpace, ReadOnly>(
563 scatterIndex.boundary.template GetPtr<MemSpace, ReadOnly>(
566 for (
unsigned int comp = 0; comp < nComp; ++comp)
568 CGBndCondGatherScatterKernel<ExecSpace>(
569 scatterIndex.trace.size(), traceIdx, boundaryIdx,
570 tracePtr + comp * bucket.tracePhys.CompSize(),
571 outPtr + comp * outBlock.CompSize(), m_opStreamID);
577 ReleaseStreams<ExecSpace>(m_opStreamID, m_blockStreams);