Cabana 0.8.0-dev
 
Loading...
Searching...
No Matches
Cabana_Grid_LocalGrid.hpp
Go to the documentation of this file.
1/****************************************************************************
2 * Copyright (c) 2018-2023 by the Cabana authors *
3 * All rights reserved. *
4 * *
5 * This file is part of the Cabana library. Cabana is distributed under a *
6 * BSD 3-clause license. For the licensing terms see the LICENSE file in *
7 * the top-level directory. *
8 * *
9 * SPDX-License-Identifier: BSD-3-Clause *
10 ****************************************************************************/
11
16#ifndef CABANA_GRID_LOCALGRID_HPP
17#define CABANA_GRID_LOCALGRID_HPP
18
21#include <Cabana_Grid_Types.hpp>
22
23#include <array>
24#include <memory>
25#include <type_traits>
26#include <vector>
27
28namespace Cabana
29{
30namespace Grid
31{
32//---------------------------------------------------------------------------//
37template <class MeshType>
39{
40 public:
42 using mesh_type = MeshType;
43
45 static constexpr std::size_t num_space_dim = mesh_type::num_space_dim;
46
54 LocalGrid( const std::shared_ptr<GlobalGrid<MeshType>>& global_grid,
55 const int halo_cell_width );
56
58 const GlobalGrid<MeshType>& globalGrid() const;
59
62
64 int haloCellWidth() const;
65
68 int totalNumCell( const int d ) const;
69
80 int neighborRank( const std::array<int, num_space_dim>& off_ijk ) const;
81
92 template <std::size_t NSD = num_space_dim>
93 std::enable_if_t<3 == NSD, int>
94 neighborRank( const int off_i, const int off_j, const int off_k ) const;
95
106 template <std::size_t NSD = num_space_dim>
107 std::enable_if_t<2 == NSD, int> neighborRank( const int off_i,
108 const int off_j ) const;
109
119 template <class DecompositionTag, class EntityType, class IndexType>
120 IndexSpace<num_space_dim> indexSpace( DecompositionTag t1, EntityType t2,
121 IndexType t3 ) const;
122
135 template <class DecompositionTag, class EntityType>
137 sharedIndexSpace( DecompositionTag t1, EntityType t2,
138 const std::array<int, num_space_dim>& off_ijk,
139 const int halo_width = -1 ) const;
140
156 template <class DecompositionTag, class EntityType,
157 std::size_t NSD = num_space_dim>
158 std::enable_if_t<3 == NSD, IndexSpace<3>>
159 sharedIndexSpace( DecompositionTag t1, EntityType t2, const int off_i,
160 const int off_j, const int off_k,
161 const int halo_width = -1 ) const;
162
178 template <class DecompositionTag, class EntityType,
179 std::size_t NSD = num_space_dim>
180 std::enable_if_t<2 == NSD, IndexSpace<2>>
181 sharedIndexSpace( DecompositionTag t1, EntityType t2, const int off_i,
182 const int off_j, const int halo_width = -1 ) const;
183
201 template <class DecompositionTag, class EntityType>
203 boundaryIndexSpace( DecompositionTag t1, EntityType t2,
204 const std::array<int, num_space_dim>& off_ijk,
205 const int halo_width = -1 ) const;
206
224 template <class DecompositionTag, class EntityType,
225 std::size_t NSD = num_space_dim>
226 std::enable_if_t<3 == NSD, IndexSpace<3>>
227 boundaryIndexSpace( DecompositionTag t1, EntityType t2, const int off_i,
228 const int off_j, const int off_k,
229 const int halo_width = -1 ) const;
230
248 template <class DecompositionTag, class EntityType,
249 std::size_t NSD = num_space_dim>
250 std::enable_if_t<2 == NSD, IndexSpace<2>>
251 boundaryIndexSpace( DecompositionTag t1, EntityType t2, const int off_i,
252 const int off_j, const int halo_width = -1 ) const;
253
254 private:
255 // Helper functions
256 template <class OwnedIndexSpace>
257 auto getBound( OwnedIndexSpace owned_space, const int upper_lower,
258 const std::array<int, num_space_dim>& off_ijk,
259 const int lower_shift, const int upper_shift ) const;
260 template <int Dir, class OwnedIndexSpace>
261 auto getBound( OwnedIndexSpace owned_space, const int upper_lower,
262 const std::array<int, num_space_dim>& off_ijk,
263 const int lower_shift_dir, const int lower_shift,
264 const int upper_shift_dir, const int upper_shift ) const;
265
266 // 3D and 2D entity types
267 IndexSpace<num_space_dim> indexSpaceImpl( Own, Cell, Local ) const;
268 IndexSpace<num_space_dim> indexSpaceImpl( Ghost, Cell, Local ) const;
269 IndexSpace<num_space_dim> indexSpaceImpl( Own, Cell, Global ) const;
270
271 IndexSpace<num_space_dim> indexSpaceImpl( Own, Node, Local ) const;
272 IndexSpace<num_space_dim> indexSpaceImpl( Ghost, Node, Local ) const;
273 IndexSpace<num_space_dim> indexSpaceImpl( Own, Node, Global ) const;
274
275 IndexSpace<num_space_dim> indexSpaceImpl( Own, Face<Dim::I>, Local ) const;
277 Local ) const;
278 IndexSpace<num_space_dim> indexSpaceImpl( Own, Face<Dim::I>, Global ) const;
279
280 IndexSpace<num_space_dim> indexSpaceImpl( Own, Face<Dim::J>, Local ) const;
282 Local ) const;
283 IndexSpace<num_space_dim> indexSpaceImpl( Own, Face<Dim::J>, Global ) const;
284
285 // 3D-only entity types.
286 template <std::size_t NSD = num_space_dim>
287 std::enable_if_t<3 == NSD, IndexSpace<3>> indexSpaceImpl( Own, Face<Dim::K>,
288 Local ) const;
289
290 template <std::size_t NSD = num_space_dim>
291 std::enable_if_t<3 == NSD, IndexSpace<3>>
292 indexSpaceImpl( Ghost, Face<Dim::K>, Local ) const;
293
294 template <std::size_t NSD = num_space_dim>
295 std::enable_if_t<3 == NSD, IndexSpace<3>> indexSpaceImpl( Own, Face<Dim::K>,
296 Global ) const;
297
298 template <std::size_t NSD = num_space_dim>
299 std::enable_if_t<3 == NSD, IndexSpace<3>> indexSpaceImpl( Own, Edge<Dim::I>,
300 Local ) const;
301
302 template <std::size_t NSD = num_space_dim>
303 std::enable_if_t<3 == NSD, IndexSpace<3>>
304 indexSpaceImpl( Ghost, Edge<Dim::I>, Local ) const;
305
306 template <std::size_t NSD = num_space_dim>
307 std::enable_if_t<3 == NSD, IndexSpace<3>> indexSpaceImpl( Own, Edge<Dim::I>,
308 Global ) const;
309
310 template <std::size_t NSD = num_space_dim>
311 std::enable_if_t<3 == NSD, IndexSpace<3>> indexSpaceImpl( Own, Edge<Dim::J>,
312 Local ) const;
313
314 template <std::size_t NSD = num_space_dim>
315 std::enable_if_t<3 == NSD, IndexSpace<3>>
316 indexSpaceImpl( Ghost, Edge<Dim::J>, Local ) const;
317
318 template <std::size_t NSD = num_space_dim>
319 std::enable_if_t<3 == NSD, IndexSpace<3>> indexSpaceImpl( Own, Edge<Dim::J>,
320 Global ) const;
321
322 template <std::size_t NSD = num_space_dim>
323 std::enable_if_t<3 == NSD, IndexSpace<3>> indexSpaceImpl( Own, Edge<Dim::K>,
324 Local ) const;
325
326 template <std::size_t NSD = num_space_dim>
327 std::enable_if_t<3 == NSD, IndexSpace<3>>
328 indexSpaceImpl( Ghost, Edge<Dim::K>, Local ) const;
329
330 template <std::size_t NSD = num_space_dim>
331 std::enable_if_t<3 == NSD, IndexSpace<3>> indexSpaceImpl( Own, Edge<Dim::K>,
332 Global ) const;
333
334 // 3D and 2D entity types.
336 sharedIndexSpaceImpl( Own, Cell,
337 const std::array<int, num_space_dim>& off_ijk,
338 const int halo_width = -1 ) const;
339
341 sharedIndexSpaceImpl( Ghost, Cell,
342 const std::array<int, num_space_dim>& off_ijk,
343 const int halo_width = -1 ) const;
344
346 sharedIndexSpaceImpl( Own, Node,
347 const std::array<int, num_space_dim>& off_ijk,
348 const int halo_width = -1 ) const;
349
351 sharedIndexSpaceImpl( Ghost, Node,
352 const std::array<int, num_space_dim>& off_ijk,
353 const int halo_width = -1 ) const;
354
356 sharedIndexSpaceImpl( Own, Face<Dim::I>,
357 const std::array<int, num_space_dim>& off_ijk,
358 const int halo_width = -1 ) const;
359
361 sharedIndexSpaceImpl( Ghost, Face<Dim::I>,
362 const std::array<int, num_space_dim>& off_ijk,
363 const int halo_width = -1 ) const;
364
366 sharedIndexSpaceImpl( Own, Face<Dim::J>,
367 const std::array<int, num_space_dim>& off_ijk,
368 const int halo_width = -1 ) const;
369
371 sharedIndexSpaceImpl( Ghost, Face<Dim::J>,
372 const std::array<int, num_space_dim>& off_ijk,
373 const int halo_width = -1 ) const;
374
375 // 3D-only entity types
376 template <std::size_t NSD = num_space_dim>
377 std::enable_if_t<3 == NSD, IndexSpace<3>>
378 sharedIndexSpaceImpl( Own, Face<Dim::K>, const std::array<int, 3>& off_ijk,
379 const int halo_width = -1 ) const;
380
381 template <std::size_t NSD = num_space_dim>
382 std::enable_if_t<3 == NSD, IndexSpace<3>>
383 sharedIndexSpaceImpl( Ghost, Face<Dim::K>,
384 const std::array<int, 3>& off_ijk,
385 const int halo_width = -1 ) const;
386
387 template <std::size_t NSD = num_space_dim>
388 std::enable_if_t<3 == NSD, IndexSpace<3>>
389 sharedIndexSpaceImpl( Own, Edge<Dim::I>, const std::array<int, 3>& off_ijk,
390 const int halo_width = -1 ) const;
391
392 template <std::size_t NSD = num_space_dim>
393 std::enable_if_t<3 == NSD, IndexSpace<3>>
394 sharedIndexSpaceImpl( Ghost, Edge<Dim::I>,
395 const std::array<int, 3>& off_ijk,
396 const int halo_width = -1 ) const;
397
398 template <std::size_t NSD = num_space_dim>
399 std::enable_if_t<3 == NSD, IndexSpace<3>>
400 sharedIndexSpaceImpl( Own, Edge<Dim::J>, const std::array<int, 3>& off_ijk,
401 const int halo_width = -1 ) const;
402
403 template <std::size_t NSD = num_space_dim>
404 std::enable_if_t<3 == NSD, IndexSpace<3>>
405 sharedIndexSpaceImpl( Ghost, Edge<Dim::J>,
406 const std::array<int, 3>& off_ijk,
407 const int halo_width = -1 ) const;
408
409 template <std::size_t NSD = num_space_dim>
410 std::enable_if_t<3 == NSD, IndexSpace<3>>
411 sharedIndexSpaceImpl( Own, Edge<Dim::K>, const std::array<int, 3>& off_ijk,
412 const int halo_width = -1 ) const;
413
414 template <std::size_t NSD = num_space_dim>
415 std::enable_if_t<3 == NSD, IndexSpace<3>>
416 sharedIndexSpaceImpl( Ghost, Edge<Dim::K>,
417 const std::array<int, 3>& off_ijk,
418 const int halo_width = -1 ) const;
419
420 // 3D and 2D entity types.
422 boundaryIndexSpaceImpl( Own, Cell,
423 const std::array<int, num_space_dim>& off_ijk,
424 const int halo_width = -1 ) const;
425
427 boundaryIndexSpaceImpl( Ghost, Cell,
428 const std::array<int, num_space_dim>& off_ijk,
429 const int halo_width = -1 ) const;
430
432 boundaryIndexSpaceImpl( Own, Node,
433 const std::array<int, num_space_dim>& off_ijk,
434 const int halo_width = -1 ) const;
435
437 boundaryIndexSpaceImpl( Ghost, Node,
438 const std::array<int, num_space_dim>& off_ijk,
439 const int halo_width = -1 ) const;
440
442 boundaryIndexSpaceImpl( Own, Face<Dim::I>,
443 const std::array<int, num_space_dim>& off_ijk,
444 const int halo_width = -1 ) const;
445
447 boundaryIndexSpaceImpl( Ghost, Face<Dim::I>,
448 const std::array<int, num_space_dim>& off_ijk,
449 const int halo_width = -1 ) const;
450
452 boundaryIndexSpaceImpl( Own, Face<Dim::J>,
453 const std::array<int, num_space_dim>& off_ijk,
454 const int halo_width = -1 ) const;
455
457 boundaryIndexSpaceImpl( Ghost, Face<Dim::J>,
458 const std::array<int, num_space_dim>& off_ijk,
459 const int halo_width = -1 ) const;
460
461 // 3D-only entity types
462 template <std::size_t NSD = num_space_dim>
463 std::enable_if_t<3 == NSD, IndexSpace<3>>
464 boundaryIndexSpaceImpl( Own, Face<Dim::K>,
465 const std::array<int, 3>& off_ijk,
466 const int halo_width = -1 ) const;
467
468 template <std::size_t NSD = num_space_dim>
469 std::enable_if_t<3 == NSD, IndexSpace<3>>
470 boundaryIndexSpaceImpl( Ghost, Face<Dim::K>,
471 const std::array<int, 3>& off_ijk,
472 const int halo_width = -1 ) const;
473
474 template <std::size_t NSD = num_space_dim>
475 std::enable_if_t<3 == NSD, IndexSpace<3>>
476 boundaryIndexSpaceImpl( Own, Edge<Dim::I>,
477 const std::array<int, 3>& off_ijk,
478 const int halo_width = -1 ) const;
479
480 template <std::size_t NSD = num_space_dim>
481 std::enable_if_t<3 == NSD, IndexSpace<3>>
482 boundaryIndexSpaceImpl( Ghost, Edge<Dim::I>,
483 const std::array<int, 3>& off_ijk,
484 const int halo_width = -1 ) const;
485
486 template <std::size_t NSD = num_space_dim>
487 std::enable_if_t<3 == NSD, IndexSpace<3>>
488 boundaryIndexSpaceImpl( Own, Edge<Dim::J>,
489 const std::array<int, 3>& off_ijk,
490 const int halo_width = -1 ) const;
491
492 template <std::size_t NSD = num_space_dim>
493 std::enable_if_t<3 == NSD, IndexSpace<3>>
494 boundaryIndexSpaceImpl( Ghost, Edge<Dim::J>,
495 const std::array<int, 3>& off_ijk,
496 const int halo_width = -1 ) const;
497
498 template <std::size_t NSD = num_space_dim>
499 std::enable_if_t<3 == NSD, IndexSpace<3>>
500 boundaryIndexSpaceImpl( Own, Edge<Dim::K>,
501 const std::array<int, 3>& off_ijk,
502 const int halo_width = -1 ) const;
503
504 template <std::size_t NSD = num_space_dim>
505 std::enable_if_t<3 == NSD, IndexSpace<3>>
506 boundaryIndexSpaceImpl( Ghost, Edge<Dim::K>,
507 const std::array<int, 3>& off_ijk,
508 const int halo_width = -1 ) const;
509
510 // Get the global index space of the local grid.
511 template <class EntityType>
512 IndexSpace<num_space_dim> globalIndexSpace( Own, EntityType ) const;
513
514 // Get the face index space of the local grid.
515 template <int Dir>
516 IndexSpace<num_space_dim> faceIndexSpace( Own, Face<Dir>, Local ) const;
517 template <int Dir>
518 IndexSpace<num_space_dim> faceIndexSpace( Own, Face<Dir>, Global ) const;
519 template <int Dir>
520 IndexSpace<num_space_dim> faceIndexSpace( Ghost, Face<Dir>, Local ) const;
521
522 // Given a relative set of indices of a neighbor get the set of local
523 // face indices shared with that neighbor in the given decomposition.
524 template <int Dir>
526 faceSharedIndexSpace( Own, Face<Dir>,
527 const std::array<int, num_space_dim>& off_ijk,
528 const int halo_width ) const;
529
530 template <int Dir>
532 faceSharedIndexSpace( Ghost, Face<Dir>,
533 const std::array<int, num_space_dim>& off_ijk,
534 const int halo_width ) const;
535
536 // Given the relative offset of a boundary relative to this local grid's
537 // get the set of local Dir-direction face indices shared with that
538 // boundary in the given decomposition.
539 template <int Dir>
541 faceBoundaryIndexSpace( Own, Face<Dir>,
542 const std::array<int, num_space_dim>& off_ijk,
543 const int halo_width ) const;
544
545 template <int Dir>
547 faceBoundaryIndexSpace( Ghost, Face<Dir>,
548 const std::array<int, num_space_dim>& off_ijk,
549 const int halo_width ) const;
550
551 // Get the edge index space of the local grid.
552 template <int Dir, std::size_t NSD = num_space_dim>
553 std::enable_if_t<3 == NSD, IndexSpace<3>> edgeIndexSpace( Own, Edge<Dir>,
554 Local ) const;
555
556 template <int Dir, std::size_t NSD = num_space_dim>
557 std::enable_if_t<3 == NSD, IndexSpace<3>> edgeIndexSpace( Own, Edge<Dir>,
558 Global ) const;
559
560 template <int Dir, std::size_t NSD = num_space_dim>
561 std::enable_if_t<3 == NSD, IndexSpace<3>> edgeIndexSpace( Ghost, Edge<Dir>,
562 Local ) const;
563
564 // Given a relative set of indices of a neighbor get the set of local
565 // edge indices shared with that neighbor in the given decomposition.
566 template <int Dir, std::size_t NSD = num_space_dim>
567 std::enable_if_t<3 == NSD, IndexSpace<3>>
568 edgeSharedIndexSpace( Own, Edge<Dir>, const std::array<int, 3>& off_ijk,
569 const int halo_width ) const;
570
571 template <int Dir, std::size_t NSD = num_space_dim>
572 std::enable_if_t<3 == NSD, IndexSpace<3>>
573 edgeSharedIndexSpace( Ghost, Edge<Dir>, const std::array<int, 3>& off_ijk,
574 const int halo_width ) const;
575
576 // Given the relative offset of a boundary relative to this local grid's
577 // get the set of local Dir-direction edge indices shared with that
578 // boundary in the given decomposition.
579 template <int Dir, std::size_t NSD = num_space_dim>
580 std::enable_if_t<3 == NSD, IndexSpace<3>>
581 edgeBoundaryIndexSpace( Own, Edge<Dir>, const std::array<int, 3>& off_ijk,
582 const int halo_width ) const;
583
584 template <int Dir, std::size_t NSD = num_space_dim>
585 std::enable_if_t<3 == NSD, IndexSpace<3>>
586 edgeBoundaryIndexSpace( Ghost, Edge<Dir>, const std::array<int, 3>& off_ijk,
587 const int halo_width ) const;
588
589 private:
590 std::shared_ptr<GlobalGrid<MeshType>> _global_grid;
591 int _halo_cell_width;
592};
593
594//---------------------------------------------------------------------------//
595// Creation function.
596//---------------------------------------------------------------------------//
605template <class MeshType>
606std::shared_ptr<LocalGrid<MeshType>>
607createLocalGrid( const std::shared_ptr<GlobalGrid<MeshType>>& global_grid,
608 const int halo_cell_width )
609{
610 return std::make_shared<LocalGrid<MeshType>>( global_grid,
611 halo_cell_width );
612}
613
614//---------------------------------------------------------------------------//
615
616} // namespace Grid
617} // namespace Cabana
618
619//---------------------------------------------------------------------------//
620// Template implementations
621//---------------------------------------------------------------------------//
622
623#include <Cabana_Grid_LocalGrid_impl.hpp>
624
625//---------------------------------------------------------------------------//
626
627#endif // end CABANA_GRID_LOCALGRID_HPP
Logical grid indexing.
std::shared_ptr< LocalGrid< MeshType > > createLocalGrid(const std::shared_ptr< GlobalGrid< MeshType > > &global_grid, const int halo_cell_width)
Create a local grid.
Definition Cabana_Grid_LocalGrid.hpp:607
Grid type tags.
Global logical grid.
Definition Cabana_Grid_GlobalGrid.hpp:39
Structured index space.
Definition Cabana_Grid_IndexSpace.hpp:37
MeshType mesh_type
Mesh type.
Definition Cabana_Grid_LocalGrid.hpp:42
IndexSpace< num_space_dim > sharedIndexSpace(DecompositionTag t1, EntityType t2, const std::array< int, num_space_dim > &off_ijk, const int halo_width=-1) const
Given the relative offsets of a neighbor rank relative to this local grid's indices get the set of lo...
std::enable_if_t< 2==NSD, IndexSpace< 2 > > boundaryIndexSpace(DecompositionTag t1, EntityType t2, const int off_i, const int off_j, const int halo_width=-1) const
Given the relative offsets of a boundary relative to this local grid's indices get the set of local e...
IndexSpace< num_space_dim > indexSpace(DecompositionTag t1, EntityType t2, IndexType t3) const
Given a decomposition type, entity type, and index type, get the contiguous set of indices that span ...
std::enable_if_t< 3==NSD, IndexSpace< 3 > > boundaryIndexSpace(DecompositionTag t1, EntityType t2, const int off_i, const int off_j, const int off_k, const int halo_width=-1) const
Given the relative offsets of a boundary relative to this local grid's indices get the set of local e...
int haloCellWidth() const
Get the number of cells in the halo.
Definition Cabana_Grid_LocalGrid_impl.hpp:49
LocalGrid(const std::shared_ptr< GlobalGrid< MeshType > > &global_grid, const int halo_cell_width)
Constructor.
Definition Cabana_Grid_LocalGrid_impl.hpp:22
const GlobalGrid< MeshType > & globalGrid() const
Get the global grid that owns the local grid.
Definition Cabana_Grid_LocalGrid_impl.hpp:33
static constexpr std::size_t num_space_dim
Spatial dimension.
Definition Cabana_Grid_LocalGrid.hpp:45
std::enable_if_t< 3==NSD, IndexSpace< 3 > > sharedIndexSpace(DecompositionTag t1, EntityType t2, const int off_i, const int off_j, const int off_k, const int halo_width=-1) const
Given the relative offsets of a neighbor rank relative to this local grid's indices get the set of lo...
int neighborRank(const std::array< int, num_space_dim > &off_ijk) const
Get the global index of a neighbor given neighbor rank offsets relative to this local grid.
Definition Cabana_Grid_LocalGrid_impl.hpp:66
int totalNumCell(const int d) const
Get the total number of local cells per dimension (owned + halo).
Definition Cabana_Grid_LocalGrid_impl.hpp:57
std::enable_if_t< 2==NSD, IndexSpace< 2 > > sharedIndexSpace(DecompositionTag t1, EntityType t2, const int off_i, const int off_j, const int halo_width=-1) const
Given the relative offsets of a neighbor rank relative to this local grid's indices get the set of lo...
IndexSpace< num_space_dim > boundaryIndexSpace(DecompositionTag t1, EntityType t2, const std::array< int, num_space_dim > &off_ijk, const int halo_width=-1) const
Given the relative offsets of a boundary relative to this local grid's indices get the set of local e...
Core: particle data structures and algorithms.
Definition Cabana_AoSoA.hpp:36
Mesh cell tag.
Definition Cabana_Grid_Types.hpp:49
Mesh edge tag.
Definition Cabana_Grid_Types.hpp:95
Mesh face tag.
Definition Cabana_Grid_Types.hpp:64
Ghosted decomposition tag.
Definition Cabana_Grid_Types.hpp:197
Global index tag.
Definition Cabana_Grid_Types.hpp:215
Local index tag.
Definition Cabana_Grid_Types.hpp:208
Mesh node tag.
Definition Cabana_Grid_Types.hpp:56
Owned decomposition tag.
Definition Cabana_Grid_Types.hpp:190