XGC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
flux_surface_average.hpp
Go to the documentation of this file.
1 #ifndef FLUX_SURFACE_AVERAGE_HPP
2 #define FLUX_SURFACE_AVERAGE_HPP
3 
4 #include "my_subview.hpp"
5 
6 extern "C" void convert_grid_2_001d_wrap(double* input, double* output);
7 extern "C" void convert_001d_2_grid_wrap(double* input, double* output);
8 
9 extern "C" int get_grid_npsi_surf();
10 
11 // Apply flux-surface average on closed flux surfaces. Values on open surfaces are set to zero.
12 // The flux surface average function is currently in fortran,
13 // so the input must first be copied from device memory if using GPU
14 // Temporary arrays are passed as arguments to avoid reallocation if used repeatedly.
15 template<class Device>
16 void flux_surface_average(const View<double*, CLayout, Device>& input_view, View<double*, CLayout, HostType>& tmp, View<double*, CLayout, HostType>& tmp00_surf){
17  Kokkos::deep_copy(tmp, input_view);
18  convert_grid_2_001d_wrap(tmp.data(),tmp00_surf.data());
19  convert_001d_2_grid_wrap(tmp00_surf.data(),tmp.data());
20  Kokkos::deep_copy(input_view, tmp);
21 }
22 
23 // Apply flux-surface average without providing temporary arrays
24 template<class Device>
25 void flux_surface_average(const View<double*, CLayout, Device>& input_view){
26 
27  // Use these temporary host arrays
28  View<double*, CLayout, HostType> tmp00_surf(NoInit("tmp00_surf"),get_grid_npsi_surf());
29  View<double*, CLayout, HostType> tmp(NoInit("tmp"), input_view.layout());
30 
31  flux_surface_average(input_view, tmp, tmp00_surf);
32 }
33 
34 // Apply flux-surface average on a collection of fields. Contiguous dimension of the input view
35 // must be the node index.
36 template<class Device>
37 void flux_surface_average(const View<double**, CLayout, Device>& input_view){
38  // Infer problem size
39  int n_arrays = input_view.extent(0);
40  int n_nodes = input_view.extent(1);
41 
42  // Use these temporary host arrays
43  View<double*, CLayout, HostType> tmp00_surf(NoInit("tmp00_surf"),get_grid_npsi_surf());
44  View<double*, CLayout, HostType> tmp(NoInit("tmp"), n_nodes);
45 
46  for(int i=0; i<n_arrays; i++){
47  auto one_field = my_subview(input_view,i);
48  flux_surface_average(one_field, tmp, tmp00_surf);
49  }
50 }
51 
52 #endif
int get_grid_npsi_surf()
Kokkos::View< T *, Kokkos::LayoutRight, Device > my_subview(const Kokkos::View< T ****, Kokkos::LayoutRight, Device > &view, int i, int j, int k)
Definition: my_subview.hpp:8
subroutine convert_grid_2_001d_wrap(v2d, v1d)
Definition: search.F90:3238
subroutine convert_001d_2_grid_wrap(v1d, v2d)
Definition: search.F90:2782
Kokkos::ViewAllocateWithoutInitializing NoInit
Definition: space_settings.hpp:68
void flux_surface_average(const View< double *, CLayout, Device > &input_view, View< double *, CLayout, HostType > &tmp, View< double *, CLayout, HostType > &tmp00_surf)
Definition: flux_surface_average.hpp:16