Cabana 0.8.0-dev
 
Loading...
Searching...
No Matches
Cabana_Grid_GlobalGrid.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_GLOBALGRID_HPP
17#define CABANA_GRID_GLOBALGRID_HPP
18
21#include <Cabana_Grid_Types.hpp>
22
23#include <array>
24#include <memory>
25
26#include <mpi.h>
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 GlobalGrid( MPI_Comm comm,
55 const std::shared_ptr<GlobalMesh<MeshType>>& global_mesh,
56 const std::array<bool, num_space_dim>& periodic,
57 const BlockPartitioner<num_space_dim>& partitioner );
58
59 // Destructor.
61
64 MPI_Comm comm() const;
65
68
70 bool isPeriodic( const int dim ) const;
71
74 bool onLowBoundary( const int dim ) const;
75
78 bool onHighBoundary( const int dim ) const;
79
82 int dimNumBlock( const int dim ) const;
83
85 int totalNumBlock() const;
86
89 int dimBlockId( const int dim ) const;
90
92 int blockId() const;
93
101 int blockRank( const std::array<int, num_space_dim>& ijk ) const;
102
110 template <std::size_t NSD = num_space_dim>
111 std::enable_if_t<3 == NSD, int> blockRank( const int i, const int j,
112 const int k ) const;
113
121 template <std::size_t NSD = num_space_dim>
122 std::enable_if_t<2 == NSD, int> blockRank( const int i, const int j ) const;
123
126 int globalNumEntity( Cell, const int dim ) const;
129 int globalNumEntity( Node, const int dim ) const;
132 int globalNumEntity( Face<Dim::I>, const int dim ) const;
135 int globalNumEntity( Face<Dim::J>, const int dim ) const;
136
139 template <std::size_t NSD = num_space_dim>
140 std::enable_if_t<3 == NSD, int> globalNumEntity( Face<Dim::K>,
141 const int dim ) const;
144 template <std::size_t NSD = num_space_dim>
145 std::enable_if_t<3 == NSD, int> globalNumEntity( Edge<Dim::I>,
146 const int dim ) const;
149 template <std::size_t NSD = num_space_dim>
150 std::enable_if_t<3 == NSD, int> globalNumEntity( Edge<Dim::J>,
151 const int dim ) const;
154 template <std::size_t NSD = num_space_dim>
155 std::enable_if_t<3 == NSD, int> globalNumEntity( Edge<Dim::K>,
156 const int dim ) const;
157
160 int ownedNumCell( const int dim ) const;
161
165 int globalOffset( const int dim ) const;
166
171 void setNumCellAndOffset( const std::array<int, num_space_dim>& num_cell,
172 const std::array<int, num_space_dim>& offset );
173
174 private:
175 std::shared_ptr<MPI_Comm> _cart_comm_ptr;
176 std::shared_ptr<GlobalMesh<MeshType>> _global_mesh;
177 std::array<bool, num_space_dim> _periodic;
178 std::array<int, num_space_dim> _ranks_per_dim;
179 std::array<int, num_space_dim> _cart_rank;
180 std::array<int, num_space_dim> _owned_num_cell;
181 std::array<int, num_space_dim> _global_cell_offset;
182 std::array<bool, num_space_dim> _boundary_lo;
183 std::array<bool, num_space_dim> _boundary_hi;
184};
185
186//---------------------------------------------------------------------------//
187// Creation function.
188//---------------------------------------------------------------------------//
197template <class MeshType>
198std::shared_ptr<GlobalGrid<MeshType>>
199createGlobalGrid( MPI_Comm comm,
200 const std::shared_ptr<GlobalMesh<MeshType>>& global_mesh,
201 const std::array<bool, MeshType::num_space_dim>& periodic,
203{
204 return std::make_shared<GlobalGrid<MeshType>>( comm, global_mesh, periodic,
205 partitioner );
206}
207
216template <class Scalar, std::size_t NumSpaceDim>
217std::shared_ptr<GlobalGrid<SparseMesh<Scalar, NumSpaceDim>>> createGlobalGrid(
218 MPI_Comm comm,
219 const std::shared_ptr<GlobalMesh<SparseMesh<Scalar, NumSpaceDim>>>&
220 global_mesh,
222 periodic,
224 partitioner )
225{
226 for ( long unsigned int d = 0; d < NumSpaceDim; ++d )
227 if ( periodic[d] )
228 std::runtime_error(
229 "Sparse grid doesn't support periodic BC so far!" );
230 return std::make_shared<GlobalGrid<SparseMesh<Scalar, NumSpaceDim>>>(
231 comm, global_mesh, periodic, partitioner );
232}
233
234//---------------------------------------------------------------------------//
235
236} // namespace Grid
237} // namespace Cabana
238
239//---------------------------------------------------------------------------//
240// Template implementation
241//---------------------------------------------------------------------------//
242
243#include <Cabana_Grid_GlobalGrid_impl.hpp>
244
245//---------------------------------------------------------------------------//
246
247#endif // end CABANA_GRID_GLOBALGRID_HPP
std::shared_ptr< GlobalGrid< MeshType > > createGlobalGrid(MPI_Comm comm, const std::shared_ptr< GlobalMesh< MeshType > > &global_mesh, const std::array< bool, MeshType::num_space_dim > &periodic, const BlockPartitioner< MeshType::num_space_dim > &partitioner)
Create a global grid.
Definition Cabana_Grid_GlobalGrid.hpp:199
Multi-node grid partitioner.
Grid type tags.
Block partitioner base class.
Definition Cabana_Grid_Partitioner.hpp:37
std::enable_if_t< 3==NSD, int > blockRank(const int i, const int j, const int k) 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:197
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
std::enable_if_t< 2==NSD, int > blockRank(const int i, const int j) 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:210
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
std::enable_if_t< 3==NSD, int > globalNumEntity(Edge< Dim::K >, const int dim) const
Get the global number of entities in a given dimension.
Definition Cabana_Grid_GlobalGrid_impl.hpp:293
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
int globalNumEntity(Node, const int dim) const
Get the global number of entities in a given dimension.
Definition Cabana_Grid_GlobalGrid_impl.hpp:227
MeshType mesh_type
Mesh type.
Definition Cabana_Grid_GlobalGrid.hpp:42
int globalNumEntity(Face< Dim::I >, const int dim) const
Get the global number of entities in a given dimension.
Definition Cabana_Grid_GlobalGrid_impl.hpp:240
std::enable_if_t< 3==NSD, int > globalNumEntity(Edge< Dim::J >, const int dim) const
Get the global number of entities in a given dimension.
Definition Cabana_Grid_GlobalGrid_impl.hpp:282
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
std::enable_if_t< 3==NSD, int > globalNumEntity(Edge< Dim::I >, const int dim) const
Get the global number of entities in a given dimension.
Definition Cabana_Grid_GlobalGrid_impl.hpp:271
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
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
std::enable_if_t< 3==NSD, int > globalNumEntity(Face< Dim::K >, const int dim) const
Get the global number of entities in a given dimension.
Definition Cabana_Grid_GlobalGrid_impl.hpp:260
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
int globalNumEntity(Face< Dim::J >, const int dim) const
Get the global number of entities in a given dimension.
Definition Cabana_Grid_GlobalGrid_impl.hpp:249
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
Sparse mesh tag.
Definition Cabana_Grid_Types.hpp:253
static constexpr std::size_t num_space_dim
Number of spatial dimensions.
Definition Cabana_Grid_Types.hpp:258