Loading...
Searching...
No Matches
shell/bit_masks.hpp
Go to the documentation of this file.
1
2
3#pragma once
4#include <Kokkos_UnorderedMap.hpp>
5
7
9
10/// \ref FlagLike that indicates boundary types for the thick spherical shell.
11enum class ShellBoundaryFlag : uint8_t
12{
13 NO_FLAG = 0,
14 INNER = 1 << 0,
15 BOUNDARY = 1 << 1,
16 CMB = BOUNDARY | ( 1 << 2 ),
17 SURFACE = BOUNDARY | ( 1 << 3 ),
19};
20
22
23/// \ref FlagLike that indicates the type of boundary condition
24enum class BoundaryConditionFlag : uint8_t
25{
26 NEUMANN = 0, // not sure we need this one, implemented as teat_boundary == false in operators
27 DIRICHLET = 1,
28 FREESLIP = 2,
29};
30
36
38
39/// @brief Retrieve the boundary condition flag that is associated with a location in the shell
40/// e.g. SURFACE -> DIRICHLET
41KOKKOS_INLINE_FUNCTION
43{
44 for ( int i = 0; i < 2; ++i ) // might become larger for more bc types
45 {
46 if ( bcs[i].sbf == sbf )
47 return bcs[i].bcf;
48 }
50}
51
52/// @brief Set the boundary condition flag that is associated with a location in the shell
53/// e.g. SURFACE -> DIRICHLET
54KOKKOS_INLINE_FUNCTION
56{
57 for ( auto& [_sbf, _bcf] : bcs ) // might become larger for more bc types
58 {
59 if ( _sbf == sbf )
60 {
61 _bcf = bcf;
62 }
63 }
64}
65
66/// @brief Retrieve the ShellBoundary flag associated with a certain boundary condition type/flag
67KOKKOS_INLINE_FUNCTION
69{
70 for ( int i = 0; i < 2; ++i ) // might become larger for more bc types
71 {
72 if ( bcs[i].bcf == bcf )
73 return bcs[i].sbf;
74 }
76}
77
78/// @brief Set up mask data for a distributed shell domain.
79/// The mask encodes boundary information for each grid node.
80/// @param domain Distributed shell domain.
81/// @return Mask data grid.
83{
85 grid::shell::allocate_scalar_grid< ShellBoundaryFlag >( "mask_data_shell_boundary", domain );
86
87 auto tmp_data_for_global_subdomain_indices =
88 grid::shell::allocate_scalar_grid< int64_t >( "tmp_data_for_global_subdomain_indices", domain );
89
92
93 // Setting boundary flags.
94 // First set all nodes to inner.
95 // Then overwrite for outer and inner subdomains if the nodes are at the actual boundary.
96
97 Kokkos::parallel_for(
98 "set_boundary_flags",
99 Kokkos::MDRangePolicy(
100 { 0, 0, 0, 0 },
101 { mask_data.extent( 0 ), mask_data.extent( 1 ), mask_data.extent( 2 ), mask_data.extent( 3 ) } ),
102 KOKKOS_LAMBDA( const int local_subdomain_id, const int x, const int y, const int r ) {
103 mask_data( local_subdomain_id, x, y, r ) = ShellBoundaryFlag::INNER;
104 } );
105
106 const int num_radial_subdomains = domain.domain_info().num_subdomains_in_radial_direction();
107
108 for ( const auto& [subdomain_info, data] : domain.subdomains() )
109 {
110 const auto& [local_subdomain_id, neighborhood] = data;
111
112 if ( subdomain_info.subdomain_r() == 0 )
113 {
114 Kokkos::parallel_for(
115 "set_boundary_flags",
116 Kokkos::MDRangePolicy( { 0, 0 }, { mask_data.extent( 1 ), mask_data.extent( 2 ) } ),
117 KOKKOS_LAMBDA( const int x, const int y ) {
118 mask_data( local_subdomain_id, x, y, 0 ) = ShellBoundaryFlag::CMB;
119 } );
120 }
121
122 if ( subdomain_info.subdomain_r() == num_radial_subdomains - 1 )
123 {
124 Kokkos::parallel_for(
125 "set_boundary_flags",
126 Kokkos::MDRangePolicy( { 0, 0 }, { mask_data.extent( 1 ), mask_data.extent( 2 ) } ),
127 KOKKOS_LAMBDA( const int x, const int y ) {
128 mask_data( local_subdomain_id, x, y, mask_data.extent( 3 ) - 1 ) = ShellBoundaryFlag::SURFACE;
129 } );
130 }
131 }
132
133 Kokkos::fence();
134
135 return mask_data;
136}
137
138} // namespace terra::grid::shell
Send and receive buffers for all process-local subdomain boundaries.
Definition communication.hpp:56
Parallel data structure organizing the thick spherical shell metadata for distributed (MPI parallel) ...
Definition spherical_shell.hpp:2498
const std::map< SubdomainInfo, std::tuple< LocalSubdomainIdx, SubdomainNeighborhood > > & subdomains() const
Definition spherical_shell.hpp:2580
const DomainInfo & domain_info() const
Returns a const reference.
Definition spherical_shell.hpp:2577
int num_subdomains_in_radial_direction() const
Definition spherical_shell.hpp:849
Concept for types that behave like bitmask flags.
Definition bit_masking.hpp:17
Definition shell/bit_masks.hpp:8
void set_boundary_condition_flag(BoundaryConditions &bcs, ShellBoundaryFlag sbf, BoundaryConditionFlag bcf)
Set the boundary condition flag that is associated with a location in the shell e....
Definition shell/bit_masks.hpp:55
BoundaryConditionMapping[2] BoundaryConditions
Definition shell/bit_masks.hpp:37
ShellBoundaryFlag
FlagLike that indicates boundary types for the thick spherical shell.
Definition shell/bit_masks.hpp:12
Grid4DDataScalar< ShellBoundaryFlag > setup_boundary_mask_data(const DistributedDomain &domain)
Set up mask data for a distributed shell domain. The mask encodes boundary information for each grid ...
Definition shell/bit_masks.hpp:82
ShellBoundaryFlag get_shell_boundary_flag(const BoundaryConditions bcs, BoundaryConditionFlag bcf)
Retrieve the ShellBoundary flag associated with a certain boundary condition type/flag.
Definition shell/bit_masks.hpp:68
BoundaryConditionFlag get_boundary_condition_flag(const BoundaryConditions bcs, ShellBoundaryFlag sbf)
Retrieve the boundary condition flag that is associated with a location in the shell e....
Definition shell/bit_masks.hpp:42
BoundaryConditionFlag
FlagLike that indicates the type of boundary condition
Definition shell/bit_masks.hpp:25
Kokkos::View< ScalarType ****, Layout > Grid4DDataScalar
Definition grid_types.hpp:25
Definition shell/bit_masks.hpp:32
BoundaryConditionFlag bcf
Definition shell/bit_masks.hpp:34
ShellBoundaryFlag sbf
Definition shell/bit_masks.hpp:33