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, const View<double*, CLayout, HostType>& output_view, const View<double*, CLayout, HostType>& tmp00_surf){
17  Kokkos::deep_copy(output_view, input_view);
18  convert_grid_2_001d_wrap(output_view.data(),tmp00_surf.data());
19  convert_001d_2_grid_wrap(tmp00_surf.data(),output_view.data());
20 }
21 
22 // Apply flux-surface average on closed flux surfaces. Values on open surfaces are set to zero.
23 // The flux surface average function is currently in fortran,
24 // so the input must first be copied from device memory if using GPU
25 // Temporary arrays are passed as arguments to avoid reallocation if used repeatedly.
26 template<class Device>
27 void flux_surface_average_in_place(const View<double*, CLayout, Device>& input_view, View<double*, CLayout, HostType>& tmp, View<double*, CLayout, HostType>& tmp00_surf){
28  Kokkos::deep_copy(tmp, input_view);
29  convert_grid_2_001d_wrap(tmp.data(),tmp00_surf.data());
30  convert_001d_2_grid_wrap(tmp00_surf.data(),tmp.data());
31  Kokkos::deep_copy(input_view, tmp);
32 }
33 
34 // Apply flux-surface average without providing temporary arrays
35 template<class Device>
36 void flux_surface_average_in_place(const View<double*, CLayout, Device>& input_view){
37 
38  // Use these temporary host arrays
39  View<double*, CLayout, HostType> tmp00_surf(NoInit("tmp00_surf"),get_grid_npsi_surf());
40  View<double*, CLayout, HostType> tmp(NoInit("tmp"), input_view.layout());
41 
42  flux_surface_average_in_place(input_view, tmp, tmp00_surf);
43 }
44 
45 // Apply flux-surface average on a collection of fields. Contiguous dimension of the input view
46 // must be the node index.
47 template<class Device>
48 void flux_surface_average_in_place(const View<double**, CLayout, Device>& input_view){
49  // Infer problem size
50  int n_arrays = input_view.extent(0);
51  int n_nodes = input_view.extent(1);
52 
53  // Use these temporary host arrays
54  View<double*, CLayout, HostType> tmp00_surf(NoInit("tmp00_surf"),get_grid_npsi_surf());
55  View<double*, CLayout, HostType> tmp(NoInit("tmp"), n_nodes);
56 
57  for(int i=0; i<n_arrays; i++){
58  auto one_field = my_subview(input_view,i);
59  flux_surface_average_in_place(one_field, tmp, tmp00_surf);
60  }
61 }
62 
63 #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:3105
void flux_surface_average(const View< double *, CLayout, Device > &input_view, const View< double *, CLayout, HostType > &output_view, const View< double *, CLayout, HostType > &tmp00_surf)
Definition: flux_surface_average.hpp:16
void flux_surface_average_in_place(const View< double *, CLayout, Device > &input_view, View< double *, CLayout, HostType > &tmp, View< double *, CLayout, HostType > &tmp00_surf)
Definition: flux_surface_average.hpp:27
subroutine convert_001d_2_grid_wrap(v1d, v2d)
Definition: search.F90:2649
Kokkos::ViewAllocateWithoutInitializing NoInit
Definition: space_settings.hpp:68