12#ifndef CABANA_GRID_GLOBALGRID_IMPL_HPP
13#define CABANA_GRID_GLOBALGRID_IMPL_HPP
25template <
class MeshType>
28 const std::array<bool, num_space_dim>& periodic,
30 : _global_mesh( global_mesh )
31 , _periodic( periodic )
34 std::array<int, num_space_dim> global_num_cell;
36 global_num_cell[d] = _global_mesh->globalNumCell( d );
40 std::array<int, num_space_dim> periodic_dims;
42 periodic_dims[d] = _periodic[d];
45 int reorder_cart_ranks = 1;
48 auto ranks_per_dim_copy = _ranks_per_dim.data();
49 auto periodic_dims_copy = periodic_dims.data();
53 [
comm, num_space_dim_copy, ranks_per_dim_copy, periodic_dims_copy,
56 auto p = std::make_unique<MPI_Comm>();
57 MPI_Cart_create(
comm, num_space_dim_copy, ranks_per_dim_copy,
58 periodic_dims_copy, reorder_cart_ranks, p.get() );
70 MPI_Comm_rank( this->
comm(), &linear_rank );
76 _global_cell_offset );
81 _boundary_lo[d] = ( 0 == _cart_rank[d] );
82 _boundary_hi[d] = ( _ranks_per_dim[d] - 1 == _cart_rank[d] );
88template <
class MeshType>
89GlobalGrid<MeshType>::~GlobalGrid()
95template <
class MeshType>
98 return *_cart_comm_ptr;
103template <
class MeshType>
106 return *_global_mesh;
111template <
class MeshType>
114 return _periodic[dim];
119template <
class MeshType>
122 return _boundary_lo[dim];
127template <
class MeshType>
130 return _boundary_hi[dim];
135template <
class MeshType>
138 return _ranks_per_dim[dim];
143template <
class MeshType>
147 MPI_Comm_size( this->comm(), &comm_size );
153template <
class MeshType>
156 return _cart_rank[dim];
161template <
class MeshType>
165 MPI_Comm_rank( this->comm(), &comm_rank );
173template <
class MeshType>
175 const std::array<int, num_space_dim>& ijk )
const
181 if ( !_periodic[d] && ( ijk[d] < 0 || _ranks_per_dim[d] <= ijk[d] ) )
186 MPI_Cart_rank( this->comm(), ijk.data(), &lr );
194template <
class MeshType>
195template <std::
size_t NSD>
196std::enable_if_t<3 == NSD, int>
199 std::array<int, 3> cr = { i, j, k };
207template <
class MeshType>
208template <std::
size_t NSD>
209std::enable_if_t<2 == NSD, int>
212 std::array<int, 2> cr = { i, j };
218template <
class MeshType>
221 return _global_mesh->globalNumCell( dim );
226template <
class MeshType>
231 if ( _periodic[dim] )
239template <
class MeshType>
248template <
class MeshType>
257template <
class MeshType>
258template <std::
size_t NSD>
259std::enable_if_t<3 == NSD, int>
268template <
class MeshType>
269template <std::
size_t NSD>
270std::enable_if_t<3 == NSD, int>
279template <
class MeshType>
280template <std::
size_t NSD>
281std::enable_if_t<3 == NSD, int>
290template <
class MeshType>
291template <std::
size_t NSD>
292std::enable_if_t<3 == NSD, int>
301template <
class MeshType>
304 return _owned_num_cell[dim];
310template <
class MeshType>
313 return _global_cell_offset[dim];
319template <
class MeshType>
321 const std::array<int, num_space_dim>& num_cell,
322 const std::array<int, num_space_dim>& offset )
324 std::copy( std::begin( num_cell ), std::end( num_cell ),
325 std::begin( _owned_num_cell ) );
326 std::copy( std::begin( offset ), std::end( offset ),
327 std::begin( _global_cell_offset ) );
Block partitioner base class.
Definition Cabana_Grid_Partitioner.hpp:37
virtual void ownedCellInfo(MPI_Comm cart_comm, const std::array< int, num_space_dim > &global_cells_per_dim, std::array< int, num_space_dim > &owned_num_cell, std::array< int, num_space_dim > &global_cell_offset) const =0
Get the owned number of cells and global cell offset of the current MPI rank.
virtual std::array< int, num_space_dim > ranksPerDimension(MPI_Comm comm, const std::array< int, num_space_dim > &global_cells_per_dim) const =0
Get the number of MPI ranks in each dimension of the grid.
bool onLowBoundary(const int dim) const
Determine if this block is on a low boundary in this dimension.
Definition Cabana_Grid_GlobalGrid_impl.hpp:120
int globalOffset(const int dim) const
Get the global offset in a given dimension. This is where our block starts in the global indexing sch...
Definition Cabana_Grid_GlobalGrid_impl.hpp:311
const GlobalMesh< MeshType > & globalMesh() const
Get the global mesh data.
Definition Cabana_Grid_GlobalGrid_impl.hpp:104
MPI_Comm comm() const
Get the communicator. This communicator was generated with a Cartesian topology.
Definition Cabana_Grid_GlobalGrid_impl.hpp:96
int dimBlockId(const int dim) const
Get the id of this block in a given dimension.
Definition Cabana_Grid_GlobalGrid_impl.hpp:154
int totalNumBlock() const
Get the total number of blocks.
Definition Cabana_Grid_GlobalGrid_impl.hpp:144
bool isPeriodic(const int dim) const
Get whether a given dimension is periodic.
Definition Cabana_Grid_GlobalGrid_impl.hpp:112
int blockId() const
Get the id of this block.
Definition Cabana_Grid_GlobalGrid_impl.hpp:162
int ownedNumCell(const int dim) const
Get the owned number of cells in a given dimension of this block.
Definition Cabana_Grid_GlobalGrid_impl.hpp:302
int dimNumBlock(const int dim) const
Get the number of blocks in each dimension in the global mesh.
Definition Cabana_Grid_GlobalGrid_impl.hpp:136
GlobalGrid(MPI_Comm comm, const std::shared_ptr< GlobalMesh< MeshType > > &global_mesh, const std::array< bool, num_space_dim > &periodic, const BlockPartitioner< num_space_dim > &partitioner)
Constructor.
Definition Cabana_Grid_GlobalGrid_impl.hpp:26
int blockRank(const std::array< int, num_space_dim > &ijk) const
Get the MPI rank of a block with the given indices. If the rank is out of bounds and the boundary is ...
Definition Cabana_Grid_GlobalGrid_impl.hpp:174
bool onHighBoundary(const int dim) const
Determine if this block is on a high boundary in this dimension.
Definition Cabana_Grid_GlobalGrid_impl.hpp:128
static constexpr std::size_t num_space_dim
Spatial dimension.
Definition Cabana_Grid_GlobalGrid.hpp:45
int globalNumEntity(Cell, const int dim) const
Get the global number of entities in a given dimension.
Definition Cabana_Grid_GlobalGrid_impl.hpp:219
void setNumCellAndOffset(const std::array< int, num_space_dim > &num_cell, const std::array< int, num_space_dim > &offset)
Set number of cells and offset of local part of the grid. Make sure these are consistent across all r...
Definition Cabana_Grid_GlobalGrid_impl.hpp:320
Global mesh partial specialization for uniform mesh.
Definition Cabana_Grid_GlobalMesh.hpp:49
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
Mesh node tag.
Definition Cabana_Grid_Types.hpp:56