Loading...
Searching...
No Matches
viscosity_interpolation.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "grid/grid_types.hpp"
5
7
8/// @brief Helper class for interpolation of purely radially dependent viscosity profiles.
9///
10/// Requires as input the already radially interpolated profile on a 2D grid (layout: (local_subdomain_id, r)).
11/// Such a grid can be initialized using functions like
12/// - \ref terra::shell::interpolate_radial_profile_into_subdomains
13/// - \ref terra::shell::interpolate_radial_profile_into_subdomains_from_csv
14/// - \ref terra::shell::interpolate_constant_radial_profile
15///
16/// If requested, the viscosity can be scaled by 1.0 / reference_viscosity and also clamped to some upper and lower
17/// bounds.
18template < typename ScalarType >
20{
21 public:
22 /// @brief Creates an interpolator class.
23 ///
24 /// The order is: first clamping, then scaling by the inverse of the reference.
25 ///
26 /// @param radial_viscosity_profile see class description
27 /// @param reference_viscosity the resulting profile is scaled by 1.0 / reference_viscosity
28 /// @param viscosity_lower_bound lower bound for clamping
29 /// @param viscosity_upper_bound upper bound for clamping
31 const grid::Grid2DDataScalar< ScalarType >& radial_viscosity_profile,
32 const ScalarType& reference_viscosity = 1.0,
33 const ScalarType& viscosity_lower_bound = std::numeric_limits< ScalarType >::lowest(),
34 const ScalarType& viscosity_upper_bound = std::numeric_limits< ScalarType >::max() )
35 : radial_viscosity_profile_( radial_viscosity_profile )
36 , reference_viscosity_( reference_viscosity )
37 , one_over_reference_viscosity_( 1.0 / reference_viscosity_ )
38 , viscosity_lower_bound_( viscosity_lower_bound )
39 , viscosity_upper_bound_( viscosity_upper_bound )
40 {}
41
42 /// @brief Runs a kernel to interpolate the viscosity profile into a full grid.
44 {
45 data_ = dst_grid;
46 Kokkos::parallel_for(
47 "viscosity_interpolation",
48 Kokkos::MDRangePolicy(
49 { 0, 0, 0, 0 },
50 { dst_grid.extent( 0 ), dst_grid.extent( 1 ), dst_grid.extent( 2 ), dst_grid.extent( 3 ) } ),
51 *this );
52 Kokkos::fence();
53 }
54
55 /// @brief Call `interpolate()` to run this kernel.
56 KOKKOS_INLINE_FUNCTION
57 void operator()( const int local_subdomain_id, const int x, const int y, const int r ) const
58 {
59 auto visc = radial_viscosity_profile_( local_subdomain_id, r );
60
61 if ( visc < viscosity_lower_bound_ )
62 {
63 visc = viscosity_lower_bound_;
64 }
65
66 if ( visc > viscosity_upper_bound_ )
67 {
68 visc = viscosity_upper_bound_;
69 }
70
71 data_( local_subdomain_id, x, y, r ) = one_over_reference_viscosity_ * visc;
72 }
73
74 private:
75 grid::Grid2DDataScalar< ScalarType > radial_viscosity_profile_;
76 ScalarType reference_viscosity_;
77 ScalarType one_over_reference_viscosity_;
78 ScalarType viscosity_lower_bound_;
79 ScalarType viscosity_upper_bound_;
80
82};
83
84} // namespace terra::geophysics::viscosity
Helper class for interpolation of purely radially dependent viscosity profiles.
Definition viscosity_interpolation.hpp:20
void operator()(const int local_subdomain_id, const int x, const int y, const int r) const
Call interpolate() to run this kernel.
Definition viscosity_interpolation.hpp:57
RadialProfileViscosityInterpolator(const grid::Grid2DDataScalar< ScalarType > &radial_viscosity_profile, const ScalarType &reference_viscosity=1.0, const ScalarType &viscosity_lower_bound=std::numeric_limits< ScalarType >::lowest(), const ScalarType &viscosity_upper_bound=std::numeric_limits< ScalarType >::max())
Creates an interpolator class.
Definition viscosity_interpolation.hpp:30
void interpolate(const grid::Grid4DDataScalar< ScalarType > &dst_grid)
Runs a kernel to interpolate the viscosity profile into a full grid.
Definition viscosity_interpolation.hpp:43
Definition viscosity_interpolation.hpp:6
Kokkos::View< ScalarType ****, Layout > Grid4DDataScalar
Definition grid_types.hpp:25
Kokkos::View< ScalarType **, Layout > Grid2DDataScalar
Definition grid_types.hpp:19