Nektar++
Loading...
Searching...
No Matches
CGBndCondMapBuilder.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: CGBndCondMapBuilder.hpp
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: Shared boundary-coefficient map construction for continuous
32// Galerkin (CG) boundary condition operators (Dirichlet lifting, Neumann weak
33// forcing). Both operators need to map a compact per-boundary-condition-type
34// coefficient array onto the (block-partitioned) domain coefficient array,
35// bucketed by device/host execution block and split by sign-changed dofs.
36// This builder captures that shared bucketing/sorting logic so it is
37// implemented and tested in exactly one place.
38//
39///////////////////////////////////////////////////////////////////////////////
40
41#pragma once
42
43#include <algorithm>
44#include <string>
45#include <tuple>
46#include <vector>
47
49
52
54{
55
56// Result of BuildCGBndCondRegions(): boundary-region bookkeeping shared by
57// the Dirichlet and Neumann constructors, needed afterwards to build the
58// compact-to-domain coefficient maps via BuildCGBndCondCoeffMaps().
59template <typename TData> struct CGBndCondRegions
60{
61 // isTypeByRegion[i][nc]: whether component nc of boundary region i has
62 // the boundary condition type this operator cares about.
63 std::vector<std::vector<bool>> isTypeByRegion;
64
65 // Number of boundary expansion coefficients for *every* region (matching
66 // or not), matching BuildCGBndCondCoeffMaps()'s numBcExpCoeffs, since the
67 // running offset there must account for skipped regions too.
68 std::vector<size_t> numBcExpCoeffs;
69
70 // Total number of matching boundary coefficients across all regions, for
71 // a single component.
73};
74
75// Shared per-boundary-region setup for a CG boundary condition operator
76// (Dirichlet lifting, Neumann weak forcing): for every boundary region with
77// at least one matching component, builds the boundary expansion list, the
78// phys/coeff workspace fields, and the ExpressionOp that evaluates the
79// boundary condition equations into them. What counts as a "match" and what
80// type-specific operator turns the evaluated boundary values into boundary
81// coefficients (FwdTransBCOp, IProductWRTBaseOp, ...) is supplied by the
82// caller, since that is the one part that genuinely differs between
83// Dirichlet and Neumann.
84//
85// - isMatch(bc) returns whether a BoundaryCondition is the type this
86// operator cares about (e.g. a dynamic_pointer_cast check).
87// - onMatchedRegion(bcExpList) is invoked once per matching region, right
88// after the shared workspace/ExpressionOp setup for that region (so
89// ordering matches wspPhys/wspCoeffs/expressionOps), letting the caller
90// build its own type-specific projection operator and any bookkeeping that
91// depends on bcExpList (e.g. Dirichlet's m_dirNumCoeffs, Neumann's
92// m_neuNumCoeffs/m_neuIsPoint).
93template <typename ExecSpace, typename TData, typename IsMatchFn,
94 typename OnMatchedRegionFn>
96 const MultiRegions::ExpListSharedPtr &expansionList,
97 const std::vector<std::string> &components,
100 const std::string &wspLabel,
102 std::vector<LibUtilities::Field<TData, FieldState::Coeff>> &wspCoeffs,
103 std::vector<std::shared_ptr<ExpressionOp<TData>>> &expressionOps,
104 bool &hasTimeDependentBndCoeffs, IsMatchFn &&isMatch,
105 OnMatchedRegionFn &&onMatchedRegion)
106{
107 using MemSpace = typename ExecSpace::memory_space;
108 const unsigned int nComp = components.size();
109
110 auto session = expansionList->GetSession();
111 auto graph = expansionList->GetGraph();
112 unsigned int nhomo = 1;
113 session->LoadParameter("HomModesZ", nhomo, 1);
114
116
117 for (auto &it : bregions)
118 {
119 auto regionId = it.first;
120 auto collectionIter = bconditions.find(regionId);
121
122 ASSERTL1(collectionIter != bconditions.end(),
123 "Unable to locate collection " + std::to_string(regionId));
124
126 (*collectionIter).second;
127
128 // Note use just the first component as we are just looking for the
129 // boundary expansion list
130 auto conditionMapIter = bndCondMap->find(components[0]);
131
132 ASSERTL1(conditionMapIter != bndCondMap->end(),
133 "Unable to locate condition map.");
134
135 SpatialDomains::BoundaryConditionShPtr bc = (*conditionMapIter).second;
136
137 // Create boundary condition expansion
138 auto bcExpList =
140 session, *(it.second), graph, true, components[0], false,
141 bc->GetComm(), Collections::eNoImpType);
142
143 // Set data warehouse for device support operators
144 bcExpList->SetDataWarehouse();
145
146 // Save number of coefficients
147 result.numBcExpCoeffs.push_back(bcExpList->GetNcoeffs());
148
149 // Check if any component has a matching condition
150 bool hasMatch = false;
151 std::vector<bool> isMatchComp(nComp);
152 for (unsigned int nc = 0; nc < nComp; nc++)
153 {
154 auto cndMapIter = bndCondMap->find(components[nc]);
155 bc = (*cndMapIter).second;
156 bool tmp = isMatch(bc);
157
158 isMatchComp[nc] = tmp;
159 hasMatch = hasMatch || tmp;
160 hasTimeDependentBndCoeffs =
161 hasTimeDependentBndCoeffs || (tmp && bc->IsTimeDependent());
162 }
163
164 result.isTypeByRegion.push_back(isMatchComp);
165
166 // Skip, if no matching condition in this boundary region
167 if (!hasMatch)
168 {
169 continue;
170 }
171
172 // Create fields for evaluating BCs into, at width 1: their
173 // coefficients are copied out block by block as contiguous elements.
174 const auto ones = MultiRegions::UnitInterleaveWidths(bcExpList);
175 auto blocks_phys =
176 MultiRegions::GetBlockAttributes<TData, FieldState::Phys>(bcExpList,
177 ones);
179 wspLabel + " phys", blocks_phys, nComp, nhomo));
180 auto blocks_coeffs =
181 MultiRegions::GetBlockAttributes<TData, FieldState::Coeff>(
182 bcExpList, ones);
184 wspLabel + " coeff", blocks_coeffs, nComp, nhomo));
185
186 // Compute number of boundary coefficients.
187 for (unsigned int blk = 0; blk < blocks_coeffs.size(); ++blk)
188 {
189 const auto ncoeff = blocks_coeffs[blk].GetNumData();
190 const auto nelmt = blocks_coeffs[blk].GetNumElements();
191 result.numBndCoeffCompSize += nelmt * ncoeff;
192 }
193
194 // Initialize memory regions
195 wspPhys.back().template Initialize<MemSpace>(0.0);
196 wspCoeffs.back().template Initialize<MemSpace>(0.0);
197
198 // Create operators for this boundary condition
199 expressionOps.push_back(ExpressionOp<TData>::Create(
200 bcExpList, components, ExecSpace::name));
201 expressionOps.back()->SetComponentMask(isMatchComp);
202
203 // Gather equations for each field/component
204 std::vector<LibUtilities::EquationSharedPtr> listOfEquations;
205 for (unsigned int nc = 0; nc < nComp; nc++)
206 {
207 auto cndMapIter = bndCondMap->find(components[nc]);
208 bc = (*cndMapIter).second;
209 listOfEquations.push_back(bc->GetEquation());
210 }
211
212 // Set boundary conditions for each component in this boundary region
213 expressionOps.back()->SetExpressions(listOfEquations);
214
215 onMatchedRegion(bcExpList);
216 }
217
218 return result;
219}
220
221// The maps of CGBndCondCoeffMaps that BuildCGBndCondCoeffMaps() uploads:
222// - Full: map, sign, bndCoeff and bndCoeffSrc, which hold every entry, for
223// a consumer setting the targets (Dirichlet);
224// - UniqueAndGroups: the unique* and group* maps, which partition the same
225// entries, for a consumer adding into the targets (Neumann).
226// The per-block, per-component offsets and counts are filled for both.
228{
229 Full,
231};
232
233// Result of BuildCGBndCondCoeffMaps(): everything needed by v_Apply()/
234// v_UpdateBndCoeffs() to scatter a compact per-component boundary coefficient
235// array into the (block-partitioned) domain coefficient array. Only the maps
236// of the CGBndCondCoeffMapSet requested are filled; the others are empty.
237template <typename TData> struct CGBndCondCoeffMaps
238{
239 bool anySignChange = false;
240 std::vector<bool> signChange;
241
242 // One entry per execution block, per matching boundary trace coefficient
243 // -- including any local coefficient target written by more than one
244 // trace piece (a domain corner where two matching-type edges of the same
245 // element meet). bndCoeffSrc holds, for each block, the device-resident
246 // gather index used to populate bndCoeff[blk] directly from the compact
247 // per-component boundary coefficient array (see CGBndCondGatherKernel)
248 // -- kept device-resident so v_UpdateBndCoeffs() never needs to
249 // round-trip through host memory.
250 //
251 // Safe as-is for a "set" consumer (Dirichlet), where two trace pieces
252 // writing the same target are (at worst) a harmless last-write-wins race
253 // -- both are independent evaluations of the same boundary condition at
254 // the same point. A scatter-ADD consumer (Neumann) must NOT use this
255 // array directly, since summing every entry would double-count a
256 // duplicated target's contribution; use uniqueMap + groupTarget below
257 // instead, which partition this same set of entries so every
258 // contribution is counted exactly once.
259 std::vector<LibUtilities::MemoryRegion<size_t>> map;
260 std::vector<LibUtilities::MemoryRegion<TData>> sign;
261 std::vector<LibUtilities::MemoryRegion<TData>> bndCoeff;
262 std::vector<LibUtilities::MemoryRegion<size_t>> bndCoeffSrc;
263
264 // The unique-target subset of map/sign/bndCoeff/bndCoeffSrc above --
265 // every target here is written by exactly one entry, so a scatter-ADD
266 // consumer can add it with a plain, non-atomic store. Duplicate-target
267 // entries excluded here are folded into the "grouped" arrays below
268 // instead, one group per duplicated target: group g's contributing
269 // entries are the CSR slice [groupOffset[blk][g], groupOffset[blk][g +
270 // 1]) into groupSrc/groupSign/groupValue (groupOffset[blk] therefore has
271 // numGroups + 1 entries). Summing a group locally and writing it with one
272 // more non-atomic store accounts for the remaining (rare) duplicated
273 // contributions -- together, uniqueMap and the groups cover every entry
274 // in map exactly once, without ever racing an atomic_add.
275 std::vector<LibUtilities::MemoryRegion<size_t>> uniqueMap;
276 std::vector<LibUtilities::MemoryRegion<TData>> uniqueSign;
277 std::vector<LibUtilities::MemoryRegion<TData>> uniqueBndCoeff;
278 std::vector<LibUtilities::MemoryRegion<size_t>> uniqueBndCoeffSrc;
279
280 std::vector<LibUtilities::MemoryRegion<size_t>> groupTarget;
281 std::vector<LibUtilities::MemoryRegion<size_t>> groupOffset;
282 std::vector<LibUtilities::MemoryRegion<size_t>> groupSrc;
283 std::vector<LibUtilities::MemoryRegion<TData>> groupSign;
284 std::vector<LibUtilities::MemoryRegion<TData>> groupValue;
285
286 // Indexed [block][component].
287 std::vector<std::vector<size_t>> compOffsets;
288 std::vector<std::vector<size_t>> compCounts;
289 std::vector<std::vector<size_t>> compUniqueOffsets;
290 std::vector<std::vector<size_t>> compUniqueCounts;
291 // Indexed [block][component], counting groups (not underlying entries).
292 std::vector<std::vector<size_t>> compGroupOffsets;
293 std::vector<std::vector<size_t>> compGroupCounts;
294};
295
296// Build the compact-boundary-coefficient-to-domain-coefficient maps for a CG
297// boundary condition operator (Dirichlet or Neumann).
298//
299// - isTypeByRegion[i][nc] indicates whether component nc of boundary region i
300// has the boundary condition type this operator cares about.
301// - numBcExpCoeffs[i] is the number of boundary expansion coefficients for
302// boundary region i (for *every* region, matching or not, since the
303// running offset must account for skipped regions too).
304// - numBndCoeffCompSize is the total number of matching boundary coefficients
305// across all regions, for a single component.
306// - mapSet selects the maps uploaded to the memory space of ExecSpace: those
307// the caller uses.
308// - perComponent(nc, assmbMap, domainBlocks, blockBound) is invoked once per
309// field component after the shared per-component map/sign bucketing has
310// been computed, so that callers needing extra information from the same
311// assembly map (e.g. Dirichlet's local-dir-dofs and parallel-dir-sign
312// bookkeeping) do not need to reconstruct it.
313template <typename ExecSpace, typename TData, typename PerComponentFn>
315 const MultiRegions::ExpListSharedPtr &expansionList,
316 const std::vector<std::string> &components,
318 const std::vector<std::vector<bool>> &isTypeByRegion,
319 const std::vector<size_t> &numBcExpCoeffs, size_t numBndCoeffCompSize,
320 const CGBndCondCoeffMapSet mapSet, PerComponentFn &&perComponent)
321{
322 using MemSpace = typename ExecSpace::memory_space;
323 const unsigned int nComp = components.size();
324
326
327 auto domainBlocks =
328 MultiRegions::GetBlockAttributes<TData, FieldState::Coeff>(
329 expansionList, MultiRegions::UnitInterleaveWidths(expansionList));
330 std::vector<size_t> blockBound(domainBlocks.size());
331 size_t bound = 0;
332 for (unsigned int blk = 0; blk < domainBlocks.size(); ++blk)
333 {
334 const auto &block = domainBlocks[blk];
335 const auto ncoeff = block.GetNumData();
336 const auto nelmt = block.GetNumElements();
337 bound += nelmt * ncoeff;
338 blockBound[blk] = bound;
339 }
340
341 // Collect the compact type-to-full-boundary coefficient index map for
342 // one component. Boundary coefficients themselves are dynamic and are
343 // filled in by the caller's v_UpdateBndCoeffs().
344 std::vector<size_t> index(numBndCoeffCompSize);
345 std::vector<std::vector<size_t>> typeIndexByComp(nComp);
346 size_t bndcnt = 0, cnt = 0;
347 for (unsigned int i = 0; i < bregions.size(); ++i)
348 {
349 auto nBndExpCoeff = numBcExpCoeffs[i];
350
351 if (std::any_of(isTypeByRegion[i].begin(), isTypeByRegion[i].end(),
352 [](bool b) { return b; }))
353 {
354 for (size_t j = 0; j < nBndExpCoeff; ++j)
355 {
356 index[bndcnt + j] = cnt + j;
357 }
358 for (unsigned int nc = 0; nc < nComp; ++nc)
359 {
360 if (isTypeByRegion[i][nc])
361 {
362 for (size_t j = 0; j < nBndExpCoeff; ++j)
363 {
364 typeIndexByComp[nc].push_back(bndcnt + j);
365 }
366 }
367 }
368 bndcnt += nBndExpCoeff;
369 }
370 cnt += nBndExpCoeff;
371 }
372
373 ASSERTL1(bndcnt == numBndCoeffCompSize,
374 "The component size does not match the number of coefficients "
375 "for all boundary conditions of this type.")
376
377 result.signChange.resize(nComp, false);
378 result.compOffsets.assign(domainBlocks.size(),
379 std::vector<size_t>(nComp, 0));
380 result.compCounts.assign(domainBlocks.size(),
381 std::vector<size_t>(nComp, 0));
382 result.compUniqueOffsets.assign(domainBlocks.size(),
383 std::vector<size_t>(nComp, 0));
384 result.compUniqueCounts.assign(domainBlocks.size(),
385 std::vector<size_t>(nComp, 0));
386 result.compGroupOffsets.assign(domainBlocks.size(),
387 std::vector<size_t>(nComp, 0));
388 result.compGroupCounts.assign(domainBlocks.size(),
389 std::vector<size_t>(nComp, 0));
390
391 // Full set of entries (Dirichlet's view) -- every matching boundary
392 // trace coefficient, including duplicated targets.
393 std::vector<std::vector<size_t>> mapBlockByBlk(domainBlocks.size());
394 std::vector<std::vector<TData>> signBlockByBlk(domainBlocks.size());
395 std::vector<std::vector<size_t>> bndCoeffSrcBlockByBlk(domainBlocks.size());
396
397 // The same entries, partitioned into a unique-target subset and
398 // duplicate-target groups (Neumann's view) -- see
399 // CGBndCondCoeffMaps::uniqueMap/groupTarget for what these hold and why.
400 std::vector<std::vector<size_t>> uniqueMapBlockByBlk(domainBlocks.size());
401 std::vector<std::vector<TData>> uniqueSignBlockByBlk(domainBlocks.size());
402 std::vector<std::vector<size_t>> uniqueBndCoeffSrcBlockByBlk(
403 domainBlocks.size());
404
405 std::vector<std::vector<size_t>> groupTargetByBlk(domainBlocks.size());
406 std::vector<std::vector<size_t>> groupOffsetByBlk(domainBlocks.size());
407 std::vector<std::vector<size_t>> groupSrcByBlk(domainBlocks.size());
408 std::vector<std::vector<TData>> groupSignByBlk(domainBlocks.size());
409
410 auto expContField =
411 std::dynamic_pointer_cast<MultiRegions::ContField>(expansionList);
412 ASSERTL0(expContField, "A continuous boundary condition operator needs a "
413 "continuous expansion list.");
414
415 for (unsigned int nc = 0; nc < nComp; ++nc)
416 {
417 // Use the assembly map of this component's variable, not that of
418 // the expansion list's own variable: the components can have
419 // different boundary conditions, and so different Dirichlet degrees
420 // of freedom and boundary-to-local maps and signs read below. The
421 // lookup shares or builds each variable's map only once.
423 expContField->GetLocalToGlobalMap(components[nc]);
424 auto &sign = assmbMap->GetBndCondCoeffsToLocalCoeffsSign();
425 auto &map = assmbMap->GetBndCondCoeffsToLocalCoeffsMap();
426 result.signChange[nc] = assmbMap->GetSignChange();
427
428 std::vector<std::tuple<size_t, size_t>> mapReordered;
429 mapReordered.reserve(typeIndexByComp[nc].size());
430 for (size_t idx : typeIndexByComp[nc])
431 {
432 mapReordered.push_back(std::make_tuple(idx, map[index[idx]]));
433 }
434 std::sort(mapReordered.begin(), mapReordered.end(),
435 [](std::tuple<size_t, size_t> const &t1,
436 std::tuple<size_t, size_t> const &t2) {
437 return std::tie(std::get<1>(t1), std::get<0>(t1)) <
438 std::tie(std::get<1>(t2), std::get<0>(t2));
439 });
440
441 std::vector<std::vector<size_t>> blockIndices(domainBlocks.size());
442 size_t cursor = 0;
443 for (unsigned int blk = 0; blk < domainBlocks.size(); ++blk)
444 {
445 while (cursor < mapReordered.size() &&
446 std::get<1>(mapReordered[cursor]) < blockBound[blk])
447 {
448 blockIndices[blk].push_back(cursor);
449 cursor++;
450 }
451 }
452
453 for (unsigned int blk = 0; blk < domainBlocks.size(); ++blk)
454 {
455 const size_t offset = (blk == 0) ? 0 : blockBound[blk - 1];
456 const size_t compOffset = mapBlockByBlk[blk].size();
457 const size_t compUniqueOffset = uniqueMapBlockByBlk[blk].size();
458 const size_t compGroupOffset = groupTargetByBlk[blk].size();
459 result.compOffsets[blk][nc] = compOffset;
460 result.compUniqueOffsets[blk][nc] = compUniqueOffset;
461 result.compGroupOffsets[blk][nc] = compGroupOffset;
462
463 const auto &blkIdx = blockIndices[blk];
464 mapBlockByBlk[blk].reserve(compOffset + blkIdx.size());
465 signBlockByBlk[blk].reserve(compOffset + blkIdx.size());
466 bndCoeffSrcBlockByBlk[blk].reserve(compOffset + blkIdx.size());
467 uniqueMapBlockByBlk[blk].reserve(compUniqueOffset + blkIdx.size());
468 uniqueSignBlockByBlk[blk].reserve(compUniqueOffset + blkIdx.size());
469 uniqueBndCoeffSrcBlockByBlk[blk].reserve(compUniqueOffset +
470 blkIdx.size());
471
472 // blkIdx is sorted by target local coefficient index, so any
473 // duplicate targets -- two boundary trace pieces of the same
474 // element sharing a vertex/edge -- form a contiguous run. Every
475 // entry always goes into the full map/sign/bndCoeffSrc (below);
476 // a run of length 1 (the overwhelming majority) additionally
477 // goes into the unique-target arrays, while longer runs are
478 // folded into one "group" entry instead, so a scatter-ADD
479 // consumer can sum their contributions locally and write them
480 // once, rather than racing an atomic_add.
481 size_t pos = 0;
482 while (pos < blkIdx.size())
483 {
484 const size_t target = std::get<1>(mapReordered[blkIdx[pos]]);
485 size_t runEnd = pos + 1;
486 while (runEnd < blkIdx.size() &&
487 std::get<1>(mapReordered[blkIdx[runEnd]]) == target)
488 {
489 ++runEnd;
490 }
491
492 for (size_t r = pos; r < runEnd; ++r)
493 {
494 const size_t idx = blkIdx[r];
495 mapBlockByBlk[blk].push_back(target - offset);
496 signBlockByBlk[blk].push_back(
497 result.signChange[nc]
498 ? sign[index[std::get<0>(mapReordered[idx])]]
499 : static_cast<TData>(1));
500 bndCoeffSrcBlockByBlk[blk].push_back(
501 std::get<0>(mapReordered[idx]) +
502 nc * numBndCoeffCompSize);
503 }
504
505 if (runEnd - pos == 1)
506 {
507 const size_t idx = blkIdx[pos];
508 uniqueMapBlockByBlk[blk].push_back(target - offset);
509 uniqueSignBlockByBlk[blk].push_back(
510 result.signChange[nc]
511 ? sign[index[std::get<0>(mapReordered[idx])]]
512 : static_cast<TData>(1));
513 uniqueBndCoeffSrcBlockByBlk[blk].push_back(
514 std::get<0>(mapReordered[idx]) +
515 nc * numBndCoeffCompSize);
516 }
517 else
518 {
519 groupTargetByBlk[blk].push_back(target - offset);
520 groupOffsetByBlk[blk].push_back(groupSrcByBlk[blk].size());
521 for (size_t r = pos; r < runEnd; ++r)
522 {
523 const size_t idx = blkIdx[r];
524 groupSignByBlk[blk].push_back(
525 result.signChange[nc]
526 ? sign[index[std::get<0>(mapReordered[idx])]]
527 : static_cast<TData>(1));
528 groupSrcByBlk[blk].push_back(
529 std::get<0>(mapReordered[idx]) +
530 nc * numBndCoeffCompSize);
531 }
532 }
533
534 pos = runEnd;
535 }
536
537 result.compCounts[blk][nc] = mapBlockByBlk[blk].size() - compOffset;
538 result.compUniqueCounts[blk][nc] =
539 uniqueMapBlockByBlk[blk].size() - compUniqueOffset;
540 result.compGroupCounts[blk][nc] =
541 groupTargetByBlk[blk].size() - compGroupOffset;
542 }
543 result.anySignChange = result.anySignChange || result.signChange[nc];
544
545 perComponent(nc, assmbMap, domainBlocks, blockBound);
546 }
547
548 const bool isFull = (mapSet == CGBndCondCoeffMapSet::Full);
549 if (isFull)
550 {
551 result.map.reserve(domainBlocks.size());
552 result.bndCoeff.reserve(domainBlocks.size());
553 result.bndCoeffSrc.reserve(domainBlocks.size());
554 if (result.anySignChange)
555 {
556 result.sign.reserve(domainBlocks.size());
557 }
558 }
559 else
560 {
561 result.uniqueMap.reserve(domainBlocks.size());
562 result.uniqueBndCoeff.reserve(domainBlocks.size());
563 result.uniqueBndCoeffSrc.reserve(domainBlocks.size());
564 result.groupTarget.reserve(domainBlocks.size());
565 result.groupOffset.reserve(domainBlocks.size());
566 result.groupSrc.reserve(domainBlocks.size());
567 result.groupValue.reserve(domainBlocks.size());
568 if (result.anySignChange)
569 {
570 result.uniqueSign.reserve(domainBlocks.size());
571 result.groupSign.reserve(domainBlocks.size());
572 }
573 }
574 for (unsigned int blk = 0; blk < domainBlocks.size(); ++blk)
575 {
576 ASSERTL1(mapBlockByBlk[blk].size() == bndCoeffSrcBlockByBlk[blk].size(),
577 "Mismatch between map and boundary coefficient sizes.");
578 if (isFull)
579 {
580 result.map.push_back(
582 MemSpace, size_t>(mapBlockByBlk[blk]));
583 // bndCoeff[blk] is populated in full by CGBndCondGatherKernel on
584 // every UpdateBndCoeffs() call, so it does not need a zeroed
585 // starting value here.
586 result.bndCoeff.emplace_back(bndCoeffSrcBlockByBlk[blk].size());
587 result.bndCoeffSrc.push_back(
589 MemSpace, size_t>(bndCoeffSrcBlockByBlk[blk]));
590 if (result.anySignChange)
591 {
592 result.sign.push_back(
594 MemSpace, TData>(signBlockByBlk[blk]));
595 }
596 }
597 else
598 {
599 result.uniqueMap.push_back(
601 MemSpace, size_t>(uniqueMapBlockByBlk[blk]));
602 // uniqueBndCoeff[blk] is populated in full by
603 // CGBndCondGatherKernel on every UpdateBndCoeffs() call, same as
604 // bndCoeff above.
605 result.uniqueBndCoeff.emplace_back(
606 uniqueBndCoeffSrcBlockByBlk[blk].size());
607 result.uniqueBndCoeffSrc.push_back(
609 MemSpace, size_t>(uniqueBndCoeffSrcBlockByBlk[blk]));
610 if (result.anySignChange)
611 {
612 result.uniqueSign.push_back(
614 MemSpace, TData>(uniqueSignBlockByBlk[blk]));
615 }
616
617 // Close off the group CSR with a trailing sentinel (the total
618 // number of grouped contributions), so group g's slice is always
619 // [groupOffset[g], groupOffset[g + 1]).
620 groupOffsetByBlk[blk].push_back(groupSrcByBlk[blk].size());
621
622 result.groupTarget.push_back(
624 MemSpace, size_t>(groupTargetByBlk[blk]));
625 result.groupOffset.push_back(
627 MemSpace, size_t>(groupOffsetByBlk[blk]));
628 result.groupSrc.push_back(
630 MemSpace, size_t>(groupSrcByBlk[blk]));
631 // groupValue[blk] is gathered in full by CGBndCondGatherKernel on
632 // every UpdateBndCoeffs() call, same as bndCoeff above.
633 result.groupValue.emplace_back(groupSrcByBlk[blk].size());
634 if (result.anySignChange)
635 {
636 result.groupSign.push_back(
638 MemSpace, TData>(groupSignByBlk[blk]));
639 }
640 }
641 }
642
643 return result;
644}
645
646} // namespace Nektar::MultiRegions::detail
#define ASSERTL0(condition, msg)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Public interface of the Expression operator, which evaluates analytical expressions at the quadrature...
#define sign(a, b)
return the sign(b)*a
Definition Polylib.cpp:47
LibUtilities::SessionReaderSharedPtr session
SpatialDomains::MeshGraphSharedPtr graph
A Field represents expansion data to be operated on.
A MemoryRegion represents a memory region.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
Whole-field interface of the Expression operator: evaluates one analytical expression per field compo...
CGBndCondRegions< TData > BuildCGBndCondRegions(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const SpatialDomains::BoundaryRegionCollection &bregions, const SpatialDomains::BoundaryConditionCollection &bconditions, const std::string &wspLabel, std::vector< LibUtilities::Field< TData, FieldState::Phys > > &wspPhys, std::vector< LibUtilities::Field< TData, FieldState::Coeff > > &wspCoeffs, std::vector< std::shared_ptr< ExpressionOp< TData > > > &expressionOps, bool &hasTimeDependentBndCoeffs, IsMatchFn &&isMatch, OnMatchedRegionFn &&onMatchedRegion)
CGBndCondCoeffMaps< TData > BuildCGBndCondCoeffMaps(const MultiRegions::ExpListSharedPtr &expansionList, const std::vector< std::string > &components, const SpatialDomains::BoundaryRegionCollection &bregions, const std::vector< std::vector< bool > > &isTypeByRegion, const std::vector< size_t > &numBcExpCoeffs, size_t numBndCoeffCompSize, const CGBndCondCoeffMapSet mapSet, PerComponentFn &&perComponent)
NEK_DEVICE_KERNEL void const TData *NEK_RESTRICT const TData *NEK_RESTRICT const size_t nelmt
std::shared_ptr< AssemblyMapCG > AssemblyMapCGSharedPtr
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
std::map< int, BoundaryRegionShPtr > BoundaryRegionCollection
Definition Conditions.h:249
std::shared_ptr< BoundaryConditionBase > BoundaryConditionShPtr
Definition Conditions.h:251
std::map< int, BoundaryConditionMapShPtr > BoundaryConditionCollection
Definition Conditions.h:258
std::shared_ptr< BoundaryConditionMap > BoundaryConditionMapShPtr
Definition Conditions.h:257
std::vector< LibUtilities::MemoryRegion< size_t > > groupOffset
std::vector< std::vector< size_t > > compUniqueOffsets
std::vector< LibUtilities::MemoryRegion< TData > > uniqueBndCoeff
std::vector< LibUtilities::MemoryRegion< size_t > > uniqueMap
std::vector< LibUtilities::MemoryRegion< TData > > groupSign
std::vector< LibUtilities::MemoryRegion< size_t > > map
std::vector< LibUtilities::MemoryRegion< size_t > > bndCoeffSrc
std::vector< std::vector< size_t > > compGroupCounts
std::vector< std::vector< size_t > > compOffsets
std::vector< LibUtilities::MemoryRegion< size_t > > uniqueBndCoeffSrc
std::vector< LibUtilities::MemoryRegion< TData > > sign
std::vector< LibUtilities::MemoryRegion< TData > > uniqueSign
std::vector< LibUtilities::MemoryRegion< TData > > bndCoeff
std::vector< LibUtilities::MemoryRegion< TData > > groupValue
std::vector< std::vector< size_t > > compUniqueCounts
std::vector< LibUtilities::MemoryRegion< size_t > > groupSrc
std::vector< std::vector< size_t > > compGroupOffsets
std::vector< LibUtilities::MemoryRegion< size_t > > groupTarget
std::vector< std::vector< size_t > > compCounts
std::vector< std::vector< bool > > isTypeByRegion