Loading...
Searching...
No Matches
gca_elements_collector.hpp
Go to the documentation of this file.
1
2#pragma once
3
5#include "dense/vec.hpp"
9#include "grid/grid_types.hpp"
11#include "linalg/operator.hpp"
12#include "linalg/vector.hpp"
13#include "linalg/vector_q1.hpp"
14
17
18namespace terra::linalg::solvers {
19
20KOKKOS_INLINE_FUNCTION
21int map_to_coarse_element( const int fine_cell, const int level_range )
22{
23 int coarse_cell = fine_cell;
24 for ( int l = 0; l < level_range; ++l )
25 {
26 coarse_cell = Kokkos::floor( coarse_cell / 2 );
27 }
28 return coarse_cell;
29}
30
31template < typename ScalarT >
33{
34 public:
35 using ScalarType = ScalarT;
36
37 private:
39
40 // fine grid coefficient
42
43 // coarsest grid boolean field for elements on which a GCA hierarchy has to be built
45
46 const int level_range_;
47
48 public:
50 const grid::shell::DistributedDomain& fine_domain,
52 const int level_range,
54 : fine_domain_( fine_domain )
55 , k_( k )
56 , GCAElements_( GCAElements )
57 , level_range_( level_range )
58 {
59 Kokkos::parallel_for(
60 "evaluate coefficient gradient", grid::shell::local_domain_md_range_policy_cells( fine_domain_ ), *this );
61 }
62
63 KOKKOS_INLINE_FUNCTION void
64 operator()( const int local_subdomain_id, const int x_cell, const int y_cell, const int r_cell ) const
65 {
66 dense::Vec< ScalarT, 6 > k[num_wedges_per_hex_cell];
67 terra::fe::wedge::extract_local_wedge_scalar_coefficients( k, local_subdomain_id, x_cell, y_cell, r_cell, k_ );
68
69 constexpr auto num_quad_points = fe::wedge::quadrature::quad_felippa_1x1_num_quad_points;
70
71 dense::Vec< ScalarT, 3 > quad_points[num_quad_points];
72 ScalarT quad_weights[num_quad_points];
73
75
76 for ( int wedge = 0; wedge < num_wedges_per_hex_cell; wedge++ )
77 {
78 const auto qp = quad_points[0];
79
80 dense::Vec< ScalarType, 3 > k_grad_eval = { 0 };
81 for ( int j = 0; j < num_nodes_per_wedge; j++ )
82 {
83 k_grad_eval = k_grad_eval + terra::fe::wedge::grad_shape( j, qp ) * k[wedge]( j );
84 }
85 auto k_grad_norm = k_grad_eval.norm();
86 if ( k_grad_norm > 10 )
87 {
88 // Todo: map to parent coarsest element
89 int x_cell_coarsest = map_to_coarse_element( x_cell, level_range_ );
90 int y_cell_coarsest = map_to_coarse_element( y_cell, level_range_ );
91 int r_cell_coarsest = map_to_coarse_element( r_cell, level_range_ );
92
93 GCAElements_( local_subdomain_id, x_cell_coarsest, y_cell_coarsest, r_cell_coarsest ) = 1;
94 }
95 }
96 }
97};
98} // namespace terra::linalg::solvers
Parallel data structure organizing the thick spherical shell metadata for distributed (MPI parallel) ...
Definition spherical_shell.hpp:2498
Definition gca_elements_collector.hpp:33
GCAElementsCollector(const grid::shell::DistributedDomain &fine_domain, const grid::Grid4DDataScalar< ScalarType > &k, const int level_range, grid::Grid4DDataScalar< ScalarType > GCAElements)
Definition gca_elements_collector.hpp:49
void operator()(const int local_subdomain_id, const int x_cell, const int y_cell, const int r_cell) const
Definition gca_elements_collector.hpp:64
ScalarT ScalarType
Definition gca_elements_collector.hpp:35
constexpr void quad_felippa_1x1_quad_points(dense::Vec< T, 3 >(&quad_points)[quad_felippa_1x1_num_quad_points])
Definition wedge/quadrature/quadrature.hpp:36
constexpr int quad_felippa_1x1_num_quad_points
Definition wedge/quadrature/quadrature.hpp:32
constexpr int num_wedges_per_hex_cell
Definition kernel_helpers.hpp:5
void extract_local_wedge_scalar_coefficients(dense::Vec< T, 6 >(&local_coefficients)[2], const int local_subdomain_id, const int x_cell, const int y_cell, const int r_cell, const grid::Grid4DDataScalar< T > &global_coefficients)
Extracts the local vector coefficients for the two wedges of a hex cell from the global coefficient v...
Definition kernel_helpers.hpp:306
constexpr int num_nodes_per_wedge
Definition kernel_helpers.hpp:7
constexpr dense::Vec< T, 3 > grad_shape(const int node_idx, const T xi, const T eta, const T zeta)
Gradient of the full shape function:
Definition integrands.hpp:228
Kokkos::MDRangePolicy< Kokkos::Rank< 4 > > local_domain_md_range_policy_cells(const DistributedDomain &distributed_domain)
Definition spherical_shell.hpp:2668
Kokkos::View< ScalarType ****, Layout > Grid4DDataScalar
Definition grid_types.hpp:25
Definition block_preconditioner_2x2.hpp:7
int map_to_coarse_element(const int fine_cell, const int level_range)
Definition gca_elements_collector.hpp:21
Definition vec.hpp:9
T norm() const
Definition vec.hpp:76