XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
diag_f0_df.hpp
Go to the documentation of this file.
1 #ifndef DIAG_F0_DF_HPP
2 #define DIAG_F0_DF_HPP
3 
4 #include "sml.hpp"
5 #include "grid.hpp"
6 #include "plasma.hpp"
7 #include "diagnostic.hpp"
8 
9 class DiagF0DF : public Diagnostic{
10 
11  std::vector<std::string> source_names;
12 
13  View<double****, CLayout, HostType> pv_grid;
14  View<double****, CLayout, HostType> pv_ptl;
15 
16  int tindex_period; // Saving this for tindex backwards compatibility
17 
18  // Returns number of sources that have been recorded since the last write.
19  int n_active_sources() const{
20  return source_names.size();
21  }
22 
23  // Adds a new active source (i.e., recorded since the last write)
24  void add_active_source(const std::string& new_source_name){
25  source_names.push_back(new_source_name);
26  }
27 
29  source_names.clear();
30  }
31 
32  public:
33 
34  enum{
35  Volume=0,
40  N
41  };
42 
44 
45  void init(NLReader::NamelistReader& nlr, const Simulation<DeviceType> &sml, const Grid<DeviceType>& grid, const Plasma& plasma, int f_source_period){
46  tindex_period = f_source_period;
47 
48  bool is_on_default = (plasma.f0_grid() && !sml.is_XGCa); // On by default for total-f XGC1
49  int period_default = (sml.is_XGCa ? 10 : 1);
50 
51  nlr.use_namelist("diag_param");
52  bool is_on = nlr.get<bool>("diag_f0_df_on", is_on_default);
53  int period = nlr.get<int>("diag_f0_df_period", period_default);
54 
55  if (is_on){
56  std::string name = "diagnosis.fsource";
57  Diagnostic::init(name, period);
58 
59  int n_initial_sources = 1; // This view is resized as needed
60  pv_grid = View<double****, CLayout, HostType>("diag_f0_df_pv_grid", n_initial_sources, plasma.n_nonadiabatic_species, grid.nnode, N);
61 
62 #ifdef USE_GPU
63  int nthreads = 1;
64 #else
65  int nthreads = get_num_cpu_threads();
66 #endif
67  pv_ptl = View<double****, CLayout, HostType>("diag_f0_df_pv_ptl", nthreads, plasma.n_nonadiabatic_species, grid.nnode, N);
68  }
69  }
70 
71  void set_ptl_baseline(const Simulation<DeviceType>& sml, const Grid<DeviceType>& grid,
73  const VelocityGrid& vgrid, const DomainDecomposition<DeviceType>& pol_decomp);
74 
77  const VelocityGrid& vgrid, const DomainDecomposition<DeviceType>& pol_decomp);
78 
79  void port1(const DomainDecomposition<DeviceType>& pol_decomp, const Grid<DeviceType>& grid, const VelocityGrid& vgrid,
80  Plasma& plasma, const VGridDistribution<HostType>& f0_f_h, const VGridDistribution<HostType>& f0_df0g_h, std::string source_name);
81 
82  void write(const Simulation<DeviceType> &sml, const Grid<DeviceType>& grid,
84  Plasma& plasma);
85 };
86 
87 #endif
Definition: diag_f0_df.hpp:39
void port1(const DomainDecomposition< DeviceType > &pol_decomp, const Grid< DeviceType > &grid, const VelocityGrid &vgrid, Plasma &plasma, const VGridDistribution< HostType > &f0_f_h, const VGridDistribution< HostType > &f0_df0g_h, std::string source_name)
Definition: diag_f0_df.cpp:313
void clear_active_sources()
Definition: diag_f0_df.hpp:28
void write(const Simulation< DeviceType > &sml, const Grid< DeviceType > &grid, const MagneticField< DeviceType > &magnetic_field, Plasma &plasma)
Definition: diag_f0_df.cpp:3
int n_active_sources() const
Definition: diag_f0_df.hpp:19
T get(const string &param, const T default_val, int val_ind=0)
Definition: NamelistReader.hpp:373
Definition: diag_f0_df.hpp:9
bool f0_grid() const
Definition: plasma.hpp:202
void set_ptl_baseline(const Simulation< DeviceType > &sml, const Grid< DeviceType > &grid, const MagneticField< DeviceType > &magnetic_field, Plasma &plasma, const VelocityGrid &vgrid, const DomainDecomposition< DeviceType > &pol_decomp)
Definition: diag_f0_df.cpp:290
Definition: velocity_grid.hpp:8
Definition: sml.hpp:8
static constexpr bool is_XGCa
Equivalent to the preprocessor flag for now.
Definition: sml.hpp:17
subroutine plasma(grid, itr, p, dene_out, deni_out, Te_out, Ti_out, Vparai_out)
Calculate the plasma density, temperature, and parallel velocity for a point in triangle itr using pl...
Definition: neutral_totalf.F90:1224
Definition: NamelistReader.hpp:193
Definition: magnetic_field.hpp:12
Definition: diag_f0_df.hpp:37
void init(NLReader::NamelistReader &nlr, const Simulation< DeviceType > &sml, const Grid< DeviceType > &grid, const Plasma &plasma, int f_source_period)
Definition: diag_f0_df.hpp:45
void init(const std::string &name, int period, int first_step=-1)
Definition: diagnostic.hpp:46
bool is_on
Definition: diagnostic.hpp:20
Definition: diag_f0_df.hpp:40
void use_namelist(const string &namelist)
Definition: NamelistReader.hpp:355
void calculate_ptl_change(const Simulation< DeviceType > &sml, const Grid< DeviceType > &grid, const MagneticField< DeviceType > &magnetic_field, Plasma &plasma, const VelocityGrid &vgrid, const DomainDecomposition< DeviceType > &pol_decomp)
Definition: diag_f0_df.cpp:303
int n_nonadiabatic_species
Number of nonadiabatic species.
Definition: plasma.hpp:90
Definition: diag_f0_df.hpp:36
View< double ****, CLayout, HostType > pv_ptl
Definition: diag_f0_df.hpp:14
Definition: diag_f0_df.hpp:35
Definition: magnetic_field.F90:1
int get_num_cpu_threads()
Definition: globals.hpp:17
Definition: plasma.hpp:13
Definition: diagnostic.hpp:10
View< double ****, CLayout, HostType > pv_grid
Definition: diag_f0_df.hpp:13
int tindex_period
Definition: diag_f0_df.hpp:16
std::vector< std::string > source_names
Definition: diag_f0_df.hpp:11
int nnode
Number of grid nodes.
Definition: grid.hpp:159
void add_active_source(const std::string &new_source_name)
Definition: diag_f0_df.hpp:24
DiagF0DF()
Definition: diag_f0_df.hpp:43
Definition: diag_f0_df.hpp:38