XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ascii_plots.hpp
Go to the documentation of this file.
1 #ifndef ASCII_PLOTS_HPP
2 #define ASCII_PLOTS_HPP
3 
4 #include "rz_bounds.hpp"
5 
6 template<typename F>
7 void ascii_contour_plot(const RZBounds& bounds, F func){
8  int nx = 80;
9  int ny = 40;
10  double dr = bounds.get_r_width()/nx;
11  double dz = bounds.get_z_width()/ny;
12  printf("\n");
13  std::vector<int> prevrow(nx+1,-1);
14  for (int j=ny;j>=0;j--){
15  printf("\n");
16  int prevnum = -1;
17  for (int i=0;i<=nx;i++){
18  double r = bounds.min_r + i*dr;
19  double z = bounds.min_z + j*dz;
20 
21  // Get value of function
22  double val = func(r, z);
23 
24  // Assume the user has normalized the function to (0.0,10.0)
25  int num = val;
26 
27  num += 48; // Shift so val=0.0 results in char 0
28 
29  // Allow values outside from 33 (!) to 125 (})
30  num = std::max(33,std::min(num,125));
31 
32  char mychar = num;
33  if (prevnum!=num || prevrow[i]!=num) printf("%c",mychar);
34  else printf(" ");
35  prevnum = num;
36  prevrow[i] = num;
37  }
38  }
39  printf("\n");
40  printf("xlims: [%1.1e, %1.1e]; ylims: [%1.1e, %1.1e]\n", bounds.min_r, bounds.max_r, bounds.min_z, bounds.max_z);
41  printf("\n");
42 }
43 
44 #endif
void ascii_contour_plot(const RZBounds &bounds, F func)
Definition: ascii_plots.hpp:7
Definition: rz_bounds.hpp:4
double max_z
Definition: rz_bounds.hpp:8
double min_r
Definition: rz_bounds.hpp:5
KOKKOS_INLINE_FUNCTION double get_z_width() const
Definition: rz_bounds.hpp:28
KOKKOS_INLINE_FUNCTION double get_r_width() const
Definition: rz_bounds.hpp:24
double min_z
Definition: rz_bounds.hpp:7
double max_r
Definition: rz_bounds.hpp:6