-
Notifications
You must be signed in to change notification settings - Fork 51
/
Cabana_Grid_LocalMesh.hpp
817 lines (729 loc) · 31.1 KB
/
Cabana_Grid_LocalMesh.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
/****************************************************************************
* Copyright (c) 2018-2023 by the Cabana authors *
* All rights reserved. *
* *
* This file is part of the Cabana library. Cabana is distributed under a *
* BSD 3-clause license. For the licensing terms see the LICENSE file in *
* the top-level directory. *
* *
* SPDX-License-Identifier: BSD-3-Clause *
****************************************************************************/
/*!
\file Cabana_Grid_LocalMesh.hpp
\brief Local mesh
*/
#ifndef CABANA_GRID_LOCALMESH_HPP
#define CABANA_GRID_LOCALMESH_HPP
#include <Cabana_Grid_LocalGrid.hpp>
#include <Cabana_Grid_Types.hpp>
#include <Cabana_Utils.hpp> // FIXME: remove after next release.
#include <Kokkos_Core.hpp>
namespace Cabana
{
namespace Grid
{
//---------------------------------------------------------------------------//
// Forward declaration of local mesh.
template <class MemorySpace, class MeshType>
class LocalMesh;
//---------------------------------------------------------------------------//
//! Local mesh partial specialization for uniform mesh.
template <class Scalar, class MemorySpace, std::size_t NumSpaceDim>
class LocalMesh<MemorySpace, UniformMesh<Scalar, NumSpaceDim>>
{
public:
//! Mesh type.
using mesh_type = UniformMesh<Scalar, NumSpaceDim>;
//! Scalar type for geometric operations.
using scalar_type = Scalar;
//! Spatial dimension.
static constexpr std::size_t num_space_dim = NumSpaceDim;
// FIXME: extracting the self type for backwards compatibility with previous
// template on DeviceType. Should simply be MemorySpace after next release.
//! Memory space.
using memory_space = typename MemorySpace::memory_space;
// FIXME: replace warning with memory space assert after next release.
static_assert(
Cabana::Impl::deprecated( Kokkos::is_device<MemorySpace>() ) );
//! Default device type.
using device_type [[deprecated]] = typename memory_space::device_type;
//! Default execution space.
using execution_space = typename memory_space::execution_space;
//! Default constructor.
LocalMesh() = default;
//! Constructor.
LocalMesh( const LocalGrid<UniformMesh<Scalar, num_space_dim>>& local_grid )
{
const auto& global_grid = local_grid.globalGrid();
const auto& global_mesh = global_grid.globalMesh();
// Get the cell size.
for ( std::size_t d = 0; d < num_space_dim; ++d )
_cell_size[d] = global_mesh.cellSize( d );
// Compute face area.
if ( 3 == num_space_dim )
{
_face_area[Dim::I] = _cell_size[Dim::J] * _cell_size[Dim::K];
_face_area[Dim::J] = _cell_size[Dim::I] * _cell_size[Dim::K];
_face_area[Dim::K] = _cell_size[Dim::I] * _cell_size[Dim::J];
}
else if ( 2 == num_space_dim )
{
_face_area[Dim::I] = _cell_size[Dim::J];
_face_area[Dim::J] = _cell_size[Dim::I];
}
// Compute cell volume.
_cell_volume = 1.0;
for ( std::size_t d = 0; d < num_space_dim; ++d )
_cell_volume *= _cell_size[d];
// Compute the owned low corner
for ( std::size_t d = 0; d < num_space_dim; ++d )
_own_low_corner[d] = global_mesh.lowCorner( d ) +
_cell_size[d] * global_grid.globalOffset( d );
// Compute the owned high corner
for ( std::size_t d = 0; d < num_space_dim; ++d )
_own_high_corner[d] =
global_mesh.lowCorner( d ) +
_cell_size[d] * ( global_grid.globalOffset( d ) +
global_grid.ownedNumCell( d ) );
// Compute the ghosted low corner
for ( std::size_t d = 0; d < num_space_dim; ++d )
_ghost_low_corner[d] = lowCorner( Own(), d ) -
local_grid.haloCellWidth() * _cell_size[d];
// Compute the ghosted high corner
for ( std::size_t d = 0; d < num_space_dim; ++d )
_ghost_high_corner[d] = highCorner( Own(), d ) +
local_grid.haloCellWidth() * _cell_size[d];
// Periodicity
for ( std::size_t d = 0; d < num_space_dim; ++d )
_periodic[d] = global_grid.isPeriodic( d );
// Determine if a block is on the low or high boundaries.
for ( std::size_t d = 0; d < num_space_dim; ++d )
{
_boundary_lo[d] = global_grid.onLowBoundary( d );
_boundary_hi[d] = global_grid.onHighBoundary( d );
}
}
//! Determine if the mesh is periodic in the given dimension.
KOKKOS_INLINE_FUNCTION
bool isPeriodic( const int dim ) const { return _periodic[dim]; }
//! Determine if this block is on a low boundary in the given dimension.
KOKKOS_INLINE_FUNCTION
bool onLowBoundary( const int dim ) const { return _boundary_lo[dim]; }
//! Determine if this block is on a high boundary in the given dimension.
KOKKOS_INLINE_FUNCTION
bool onHighBoundary( const int dim ) const { return _boundary_hi[dim]; }
//! Get the physical coordinate of the low corner of the owned local grid.
//! \param dim Spatial dimension.
KOKKOS_INLINE_FUNCTION
Scalar lowCorner( Own, const int dim ) const
{
return _own_low_corner[dim];
}
//! Get the physical coordinate of the low corner of the local grid
//! including ghosts.
//! \param dim Spatial dimension.
KOKKOS_INLINE_FUNCTION
Scalar lowCorner( Ghost, const int dim ) const
{
return _ghost_low_corner[dim];
}
//! Get the physical coordinate of the high corner of the owned local grid.
//! \param dim Spatial dimension.
KOKKOS_INLINE_FUNCTION
Scalar highCorner( Own, const int dim ) const
{
return _own_high_corner[dim];
}
//! Get the physical coordinate of the high corner of the local grid
//! including ghosts.
//! \param dim Spatial dimension.
KOKKOS_INLINE_FUNCTION
Scalar highCorner( Ghost, const int dim ) const
{
return _ghost_high_corner[dim];
}
//! Get the extent of a given dimension.
template <typename Decomposition>
KOKKOS_FUNCTION Scalar extent( Decomposition d, const int dim ) const
{
return highCorner( d, dim ) - lowCorner( d, dim );
}
//! Get the coordinates of a Cell given the local index.
//! Local indexing is relative to the ghosted decomposition of the mesh
//! block, which correlates directly to local index spaces associated with
//! the block.
template <class Integer>
KOKKOS_INLINE_FUNCTION void coordinates( Cell,
const Integer index[num_space_dim],
Scalar x[num_space_dim] ) const
{
for ( std::size_t d = 0; d < num_space_dim; ++d )
x[d] = _ghost_low_corner[d] +
( Scalar( index[d] ) + Scalar( 0.5 ) ) * _cell_size[d];
}
//! Get the coordinates of a Node given the local index.
//! Local indexing is relative to the ghosted decomposition of the mesh
//! block, which correlates directly to local index spaces associated with
//! the block.
template <class Integer>
KOKKOS_INLINE_FUNCTION void coordinates( Node,
const Integer index[num_space_dim],
Scalar x[num_space_dim] ) const
{
for ( std::size_t d = 0; d < num_space_dim; ++d )
x[d] = _ghost_low_corner[d] + Scalar( index[d] ) * _cell_size[d];
}
//! Get the coordinates of a Face given the local index.
//! Local indexing is relative to the ghosted decomposition of the mesh
//! block, which correlates directly to local index spaces associated with
//! the block.
template <int Dir, class Integer>
KOKKOS_INLINE_FUNCTION void coordinates( Face<Dir>,
const Integer index[num_space_dim],
Scalar x[num_space_dim] ) const
{
static_assert( Dir < num_space_dim, "Face dimension out of bounds" );
for ( std::size_t d = 0; d < num_space_dim; ++d )
if ( Dir == d )
x[d] =
_ghost_low_corner[d] + Scalar( index[d] ) * _cell_size[d];
else
x[d] = _ghost_low_corner[d] +
( Scalar( index[d] ) + Scalar( 0.5 ) ) * _cell_size[d];
}
//! Get the coordinates of an Edge given the local index.
//! Local indexing is relative to the ghosted decomposition of the mesh
//! block, which correlates directly to local index spaces associated with
//! the block.
template <int Dir, class Integer, std::size_t NSD = num_space_dim>
KOKKOS_INLINE_FUNCTION std::enable_if_t<3 == NSD, void>
coordinates( Edge<Dir>, const Integer index[3], Scalar x[3] ) const
{
for ( std::size_t d = 0; d < 3; ++d )
if ( Dir == d )
x[d] = _ghost_low_corner[d] +
( Scalar( index[d] ) + Scalar( 0.5 ) ) * _cell_size[d];
else
x[d] =
_ghost_low_corner[d] + Scalar( index[d] ) * _cell_size[d];
}
//! Get the measure of a Node at the given index.
//! Local indexing is relative to the ghosted decomposition of the mesh
//! block and correlates directly to local index spaces associated with the
//! block.
template <class Integer>
KOKKOS_INLINE_FUNCTION Scalar measure( Node,
const Integer[num_space_dim] ) const
{
return 0.0;
}
//! Get the measure of an Edge at the given index.
//! Local indexing is relative to the ghosted decomposition of the mesh
//! block and correlates directly to local index spaces associated with the
//! block.
template <int Dir, class Integer, std::size_t NSD = num_space_dim>
KOKKOS_INLINE_FUNCTION std::enable_if_t<3 == NSD, Scalar>
measure( Edge<Dir>, const Integer[3] ) const
{
return _cell_size[Dir];
}
//! Get the measure of a Face at the given index.
//! Local indexing is relative to the ghosted decomposition of the mesh
//! block and correlates directly to local index spaces associated with the
//! block.
template <int Dir, class Integer>
KOKKOS_INLINE_FUNCTION Scalar measure( Face<Dir>,
const Integer[num_space_dim] ) const
{
static_assert( Dir < num_space_dim, "Face dimension out of bounds" );
return _face_area[Dir];
}
//! Get the measure of a Cell at the given index.
//! Local indexing is relative to the ghosted decomposition of the mesh
//! block and correlates directly to local index spaces associated with the
//! block.
template <class Integer>
KOKKOS_INLINE_FUNCTION Scalar measure( Cell,
const Integer[num_space_dim] ) const
{
return _cell_volume;
}
private:
Kokkos::Array<Scalar, num_space_dim> _cell_size;
Kokkos::Array<Scalar, num_space_dim> _face_area;
Scalar _cell_volume;
Kokkos::Array<Scalar, num_space_dim> _own_low_corner;
Kokkos::Array<Scalar, num_space_dim> _own_high_corner;
Kokkos::Array<Scalar, num_space_dim> _ghost_low_corner;
Kokkos::Array<Scalar, num_space_dim> _ghost_high_corner;
Kokkos::Array<bool, num_space_dim> _periodic;
Kokkos::Array<bool, num_space_dim> _boundary_lo;
Kokkos::Array<bool, num_space_dim> _boundary_hi;
};
//---------------------------------------------------------------------------//
//! Global mesh partial specialization for non-uniform mesh.
template <class Scalar, class MemorySpace, std::size_t NumSpaceDim>
class LocalMesh<MemorySpace, NonUniformMesh<Scalar, NumSpaceDim>>
{
public:
//! Mesh type.
using mesh_type = NonUniformMesh<Scalar, NumSpaceDim>;
//! Scalar type for geometric operations.
using scalar_type = Scalar;
//! Spatial dimension.
static constexpr std::size_t num_space_dim = NumSpaceDim;
// FIXME: extracting the self type for backwards compatibility with previous
// template on DeviceType. Should simply be MemorySpace after next release.
//! Memory space.
using memory_space = typename MemorySpace::memory_space;
// FIXME: replace warning with memory space assert after next release.
static_assert(
Cabana::Impl::deprecated( Kokkos::is_device<MemorySpace>() ) );
//! Default device type.
using device_type [[deprecated]] = typename memory_space::device_type;
//! Default execution space.
using execution_space = typename memory_space::execution_space;
//! Constructor.
LocalMesh(
const LocalGrid<NonUniformMesh<Scalar, num_space_dim>>& local_grid )
{
const auto& global_grid = local_grid.globalGrid();
const auto& global_mesh = global_grid.globalMesh();
// Compute the owned low corner.
for ( std::size_t d = 0; d < num_space_dim; ++d )
_own_low_corner[d] =
global_mesh.nonUniformEdge( d )[global_grid.globalOffset( d )];
// Compute the owned high corner
for ( std::size_t d = 0; d < num_space_dim; ++d )
_own_high_corner[d] =
global_mesh.nonUniformEdge( d )[global_grid.globalOffset( d ) +
global_grid.ownedNumCell( d )];
// Compute the ghosted low corner
for ( std::size_t d = 0; d < num_space_dim; ++d )
{
// Interior domain case.
if ( !global_grid.onLowBoundary( d ) )
{
_ghost_low_corner[d] = global_mesh.nonUniformEdge(
d )[global_grid.globalOffset( d ) -
local_grid.haloCellWidth()];
}
// Periodic boundary. Use cells on other side of boundary to
// generate geometry.
else if ( global_grid.isPeriodic( d ) )
{
int nedge = global_mesh.nonUniformEdge( d ).size();
_ghost_low_corner[d] =
global_mesh.nonUniformEdge( d ).front() -
( global_mesh.nonUniformEdge( d ).back() -
global_mesh.nonUniformEdge(
d )[nedge - local_grid.haloCellWidth() - 1] );
}
// In the non-periodic boundary case we extrapolate halo cells to
// have the same width as the boundary cell.
else
{
Scalar dx = global_mesh.nonUniformEdge( d )[1] -
global_mesh.nonUniformEdge( d )[0];
_ghost_low_corner[d] = global_mesh.nonUniformEdge( d ).front() -
dx * local_grid.haloCellWidth();
}
}
// Compute the ghosted high corner
for ( std::size_t d = 0; d < num_space_dim; ++d )
{
// Interior domain case.
if ( !global_grid.onHighBoundary( d ) )
{
_ghost_high_corner[d] = global_mesh.nonUniformEdge(
d )[global_grid.globalOffset( d ) +
global_grid.ownedNumCell( d ) +
local_grid.haloCellWidth()];
}
// Periodic boundary. Use cells on other side of boundary to
// generate geometry.
else if ( global_grid.isPeriodic( d ) )
{
_ghost_high_corner[d] =
global_mesh.nonUniformEdge( d ).back() +
( global_mesh.nonUniformEdge(
d )[local_grid.haloCellWidth()] -
global_mesh.nonUniformEdge( d ).front() );
}
// In the non-periodic boundary case we extrapolate halo cells to
// have the same width as the boundary cell.
else
{
int nedge = global_mesh.nonUniformEdge( d ).size();
Scalar dx = global_mesh.nonUniformEdge( d )[nedge - 1] -
global_mesh.nonUniformEdge( d )[nedge - 2];
_ghost_high_corner[d] = global_mesh.nonUniformEdge( d ).back() +
dx * local_grid.haloCellWidth();
}
}
// Get the node index spaces.
auto owned_nodes_local =
local_grid.indexSpace( Own(), Node(), Local() );
auto ghosted_nodes_local =
local_grid.indexSpace( Ghost(), Node(), Local() );
auto owned_nodes_global =
local_grid.indexSpace( Own(), Node(), Global() );
for ( std::size_t d = 0; d < num_space_dim; ++d )
{
// Allocate edges on the device for this dimension.
const auto& global_edge = global_mesh.nonUniformEdge( d );
int nedge = ghosted_nodes_local.extent( d );
int nedge_global = global_edge.size();
_local_edges[d] = Kokkos::View<Scalar*, MemorySpace>(
Kokkos::ViewAllocateWithoutInitializing( "local_edges" ),
nedge );
// Compute edges on the host.
auto edge_mirror = Kokkos::create_mirror_view( Kokkos::HostSpace(),
_local_edges[d] );
// Compute the owned edges.
for ( int n = owned_nodes_local.min( d );
n < owned_nodes_local.max( d ); ++n )
{
edge_mirror( n ) = global_edge[owned_nodes_global.min( d ) + n -
owned_nodes_local.min( d )];
}
// Compute the lower boundary edges.
if ( !global_grid.onLowBoundary( d ) )
{
// Interior block gets edges from neighbors.
for ( int n = 0; n < owned_nodes_local.min( d ); ++n )
{
edge_mirror( n ) =
global_edge[owned_nodes_global.min( d ) + n -
owned_nodes_local.min( d )];
}
}
else if ( global_grid.isPeriodic( d ) )
{
// Periodic boundary block gets edges from neighbor on
// opposite side of boundary.
for ( int n = 0; n < owned_nodes_local.min( d ); ++n )
{
edge_mirror( n ) =
global_edge.front() - global_edge.back() +
global_edge[global_edge.size() - 1 -
local_grid.haloCellWidth() + n];
}
}
else
{
// Non-periodic boundary block extrapolates edges using
// boundary cell width.
for ( int n = 0; n < owned_nodes_local.min( d ); ++n )
{
Scalar dx = global_edge[1] - global_edge[0];
edge_mirror( n ) = global_edge.front() -
( owned_nodes_local.min( d ) - n ) * dx;
}
}
// Compute the upper boundary edges.
if ( !global_grid.onHighBoundary( d ) )
{
// Interior block gets edges from neighbors.
for ( int n = owned_nodes_local.max( d );
n < ghosted_nodes_local.max( d ); ++n )
{
edge_mirror( n ) =
global_edge[owned_nodes_global.min( d ) + n -
owned_nodes_local.min( d )];
}
}
else if ( global_grid.isPeriodic( d ) )
{
// Periodic boundary block gets edges from neighbor on
// opposite side of boundary.
for ( int n = 0; n < ghosted_nodes_local.max( d ) -
owned_nodes_local.max( d );
++n )
{
edge_mirror( owned_nodes_local.max( d ) + n ) =
global_edge.back() + global_edge[n] -
global_edge.front();
}
}
else
{
// Non-periodic boundary block extrapolates edges using
// boundary cell width.
for ( int n = owned_nodes_local.max( d );
n < ghosted_nodes_local.max( d ); ++n )
{
Scalar dx = global_edge[nedge_global - 1] -
global_edge[nedge_global - 2];
edge_mirror( n ) =
global_edge.back() +
( n - owned_nodes_local.max( d ) + 1 ) * dx;
}
}
// Copy edges to the device.
Kokkos::deep_copy( _local_edges[d], edge_mirror );
}
// Periodicity
for ( std::size_t d = 0; d < num_space_dim; ++d )
_periodic[d] = global_grid.isPeriodic( d );
// Determine if a block is on the low or high boundaries.
for ( std::size_t d = 0; d < num_space_dim; ++d )
{
_boundary_lo[d] = global_grid.onLowBoundary( d );
_boundary_hi[d] = global_grid.onHighBoundary( d );
}
}
//! Determine if the mesh is periodic in the given dimension.
//! \param dim Spatial dimension.
KOKKOS_INLINE_FUNCTION
bool isPeriodic( const int dim ) const { return _periodic[dim]; }
//! Determine if this block is on a low boundary in the given dimension.
//! \param dim Spatial dimension.
KOKKOS_INLINE_FUNCTION
bool onLowBoundary( const int dim ) const { return _boundary_lo[dim]; }
//! Determine if this block is on a high boundary in the given dimension.
//! \param dim Spatial dimension.
KOKKOS_INLINE_FUNCTION
bool onHighBoundary( const int dim ) const { return _boundary_hi[dim]; }
//! Get the physical coordinate of the low corner of the owned local grid.
//! \param dim Spatial dimension.
KOKKOS_INLINE_FUNCTION
Scalar lowCorner( Own, const int dim ) const
{
return _own_low_corner[dim];
}
//! Get the physical coordinate of the low corner of the local grid
//! including ghosts.
//! \param dim Spatial dimension.
KOKKOS_INLINE_FUNCTION
Scalar lowCorner( Ghost, const int dim ) const
{
return _ghost_low_corner[dim];
}
//! Get the physical coordinate of the high corner of the owned local grid.
//! \param dim Spatial dimension.
KOKKOS_INLINE_FUNCTION
Scalar highCorner( Own, const int dim ) const
{
return _own_high_corner[dim];
}
//! Get the physical coordinate of the high corner of the local grid
//! including ghosts.
//! \param dim Spatial dimension.
KOKKOS_INLINE_FUNCTION
Scalar highCorner( Ghost, const int dim ) const
{
return _ghost_high_corner[dim];
}
//! Get the physical length of the local grid of the given decomposition.
//! \param d Decomposition: Own or Ghost
//! \param dim Spatial dimension.
template <typename Decomposition>
KOKKOS_FUNCTION Scalar extent( Decomposition d, const int dim ) const
{
return highCorner( d, dim ) - lowCorner( d, dim );
}
/*!
Get the coordinates of a Cell given the local index.
\param index %Array of local indices relative to the
ghosted decomposition of the mesh block, which correlates directly to
local index spaces associated with the block.
\param x Calculated Cell position
*/
template <class Integer>
KOKKOS_INLINE_FUNCTION void coordinates( Cell,
const Integer index[num_space_dim],
Scalar x[num_space_dim] ) const
{
for ( std::size_t d = 0; d < num_space_dim; ++d )
x[d] = ( _local_edges[d]( index[d] + 1 ) +
_local_edges[d]( index[d] ) ) /
Scalar( 2.0 );
}
/*!
Get the coordinates of a Node given the local index.
\param index %Array of local indices relative to the
ghosted decomposition of the mesh block.
\param x Calculated Node position
*/
template <class Integer>
KOKKOS_INLINE_FUNCTION void coordinates( Node,
const Integer index[num_space_dim],
Scalar x[num_space_dim] ) const
{
for ( std::size_t d = 0; d < num_space_dim; ++d )
x[d] = _local_edges[d]( index[d] );
}
/*!
Get the coordinates of a Face given the local index.
\param index %Array of local indices relative to the
ghosted decomposition of the mesh block.
\param x Calculated Face position
*/
template <int Dir, class Integer>
KOKKOS_INLINE_FUNCTION void coordinates( Face<Dir>,
const Integer index[num_space_dim],
Scalar x[num_space_dim] ) const
{
static_assert( Dir < num_space_dim, "Face dimension out of bounds" );
for ( std::size_t d = 0; d < num_space_dim; ++d )
if ( Dir == d )
x[d] = _local_edges[d]( index[d] );
else
x[d] = ( _local_edges[d]( index[d] + 1 ) +
_local_edges[d]( index[d] ) ) /
Scalar( 2.0 );
}
/*!
Get the coordinates of a Edge given the local index.
\param index %Array of local indices relative to the
ghosted decomposition of the mesh block.
\param x Calculated Edge position
*/
template <int Dir, class Integer, std::size_t NSD = num_space_dim>
KOKKOS_INLINE_FUNCTION std::enable_if_t<3 == NSD, void>
coordinates( Edge<Dir>, const Integer index[3], Scalar x[3] ) const
{
for ( std::size_t d = 0; d < 3; ++d )
if ( Dir == d )
x[d] = ( _local_edges[d]( index[d] + 1 ) +
_local_edges[d]( index[d] ) ) /
Scalar( 2.0 );
else
x[d] = _local_edges[d]( index[d] );
}
/*!
Get the measure of a Node.
*/
template <class Integer>
KOKKOS_INLINE_FUNCTION Scalar measure( Node,
const Integer[num_space_dim] ) const
{
return 0.0;
}
/*!
Get the measure of a 3d Edge given the local index.
\param index %Array of local indices relative to the
ghosted decomposition of the mesh block
*/
template <int Dir, class Integer, std::size_t NSD = num_space_dim>
KOKKOS_INLINE_FUNCTION std::enable_if_t<3 == NSD, Scalar>
measure( Edge<Dir>, const Integer index[3] ) const
{
return _local_edges[Dir][index[Dir] + 1] -
_local_edges[Dir][index[Dir]];
}
/*!
Get the measure of an 3d I-Face given the local index.
\param index %Array of local indices relative to the
ghosted decomposition of the mesh block
*/
template <class Integer, std::size_t NSD = num_space_dim>
KOKKOS_INLINE_FUNCTION std::enable_if_t<3 == NSD, Scalar>
measure( Face<Dim::I>, const Integer index[3] ) const
{
return measure( Edge<Dim::J>(), index ) *
measure( Edge<Dim::K>(), index );
}
/*!
Get the measure of a 3d J-Face given the local index.
\param index %Array of local indices relative to the
ghosted decomposition of the mesh block
*/
template <class Integer, std::size_t NSD = num_space_dim>
KOKKOS_INLINE_FUNCTION std::enable_if_t<3 == NSD, Scalar>
measure( Face<Dim::J>, const Integer index[3] ) const
{
return measure( Edge<Dim::I>(), index ) *
measure( Edge<Dim::K>(), index );
}
/*!
Get the measure of a 3d K-Face given the local index.
\param index %Array of local indices relative to the
ghosted decomposition of the mesh block
*/
template <class Integer, std::size_t NSD = num_space_dim>
KOKKOS_INLINE_FUNCTION std::enable_if_t<3 == NSD, Scalar>
measure( Face<Dim::K>, const Integer index[3] ) const
{
return measure( Edge<Dim::I>(), index ) *
measure( Edge<Dim::J>(), index );
}
/*!
Get the measure of a 2d I-Face given the local index.
\param index %Array of local indices relative to the
ghosted decomposition of the mesh block
*/
template <class Integer, std::size_t NSD = num_space_dim>
KOKKOS_INLINE_FUNCTION std::enable_if_t<2 == NSD, Scalar>
measure( Face<Dim::I>, const Integer index[2] ) const
{
return _local_edges[Dim::J][index[Dim::J] + 1] -
_local_edges[Dim::J][index[Dim::J]];
}
/*!
Get the measure of a 2d J-Face given the local index.
\param index %Array of local indices relative to the
ghosted decomposition of the mesh block
*/
template <class Integer, std::size_t NSD = num_space_dim>
KOKKOS_INLINE_FUNCTION std::enable_if_t<2 == NSD, Scalar>
measure( Face<Dim::J>, const Integer index[2] ) const
{
return _local_edges[Dim::I][index[Dim::I] + 1] -
_local_edges[Dim::I][index[Dim::I]];
}
/*!
Get the measure of a Cell given the local index.
\param index %Array of local indices relative to the
ghosted decomposition of the mesh block
*/
template <class Integer>
KOKKOS_INLINE_FUNCTION Scalar
measure( Cell, const Integer index[num_space_dim] ) const
{
Scalar m = 1.0;
for ( std::size_t d = 0; d < num_space_dim; ++d )
m *= _local_edges[d][index[d] + 1] - _local_edges[d][index[d]];
return m;
}
private:
Kokkos::Array<Scalar, num_space_dim> _own_low_corner;
Kokkos::Array<Scalar, num_space_dim> _own_high_corner;
Kokkos::Array<Scalar, num_space_dim> _ghost_low_corner;
Kokkos::Array<Scalar, num_space_dim> _ghost_high_corner;
Kokkos::Array<Kokkos::View<Scalar*, MemorySpace>, num_space_dim>
_local_edges;
Kokkos::Array<bool, num_space_dim> _periodic;
Kokkos::Array<bool, num_space_dim> _boundary_lo;
Kokkos::Array<bool, num_space_dim> _boundary_hi;
};
//---------------------------------------------------------------------------//
/*!
\brief Creation function for local mesh.
\return Shared pointer to a LocalMesh.
*/
template <class MemorySpace, class MeshType>
LocalMesh<MemorySpace, MeshType>
createLocalMesh( const LocalGrid<MeshType>& local_grid )
{
return LocalMesh<MemorySpace, MeshType>( local_grid );
}
//---------------------------------------------------------------------------//
} // namespace Grid
} // namespace Cabana
namespace Cajita
{
//! \cond Deprecated
template <class Device, class MeshType>
using LocalMesh CAJITA_DEPRECATED = Cabana::Grid::LocalMesh<Device, MeshType>;
// Device cannot be deduced.
template <class Device, class... Args>
CAJITA_DEPRECATED auto createLocalMesh( Args&&... args )
{
return Cabana::Grid::createLocalMesh<Device>(
std::forward<Args>( args )... );
}
//! \endcond
} // namespace Cajita
#endif // end CABANA_GRID_LOCALMESH_HPP