6 #include <Kokkos_Core.hpp>
7 #include <Kokkos_DualView.hpp>
42 namespace Convergence{
78 template<
class Device>
84 int gri = cs.
s.h_view(isp, mesh_ind).grid_index;
86 for (
int index_i = 0; index_i<cvg.
mesh_z.extent(2); index_i++){
87 double mesh_z2 = cvg.
mesh_z(mesh_ind,gri,index_i)*cvg.
mesh_z(mesh_ind,gri,index_i);
88 for (
int index_j = 0; index_j<cvg.
mesh_r.extent(2); index_j++){
89 double mesh_r2 = cvg.
mesh_r(mesh_ind,gri,index_j)*cvg.
mesh_r(mesh_ind,gri,index_j);
90 double vpic_dfc = (cs.
pdf_np1.h_view(mesh_ind,isp,index_i,index_j) - cs.
pdf_n.h_view(mesh_ind,isp,index_i,index_j)) * cvg.
vol_h(mesh_ind,gri,index_j);
93 vpic_dw += vpic_dfc*(mesh_z2 + mesh_r2);
94 vpic_dp += vpic_dfc*cvg.
mesh_z(mesh_ind,gri,index_i);
98 dw = vpic_dw*cs.
s.h_view(isp,mesh_ind).mass;
99 dp = vpic_dp*cs.
s.h_view(isp,mesh_ind).mass;
100 dn_n = std::abs(vpic_dn/cs.
s.h_view(isp,mesh_ind).dens);
105 template<
class Device>
110 for (
int spi = 0; spi<col_spall.
n(); spi++){
111 w_sum += col_spall.
s.h_view(spi,mesh_ind).ens;
112 p_sum += col_spall.
s.h_view(spi,mesh_ind).mom;
113 min_p_thres = std::min( col_spall.
s.h_view(spi,mesh_ind).mass*col_spall.
s.h_view(spi,mesh_ind).dens*sqrt(col_spall.
s.h_view(spi,mesh_ind).numeric_vth2),
118 template<
class Device>
125 for (
int spi = 0; spi<col_spall.
n(); spi++){
128 eval(spi, mesh_ind, col_vgrids, col_spall,dw,dp,dn_n);
136 values_are_all_finite = (std::isfinite(
dw_sum) && std::isfinite(
dp_sum) && std::isfinite(
dn_n_max));
142 double mass_use = (col_spall.
s.h_view(0,mesh_ind).is_electron ? col_spall.
s.h_view(1,mesh_ind).mass : col_spall.
s.h_view(0,mesh_ind).mass);
143 mom_exit_ok = std::abs(
dp_sum)/(std::max(std::abs(
p_sum),1e-3*mass_use*col_spall.
s.h_view(0,mesh_ind).dens)) <= 1.0e-7;
152 template<
class Device>
159 Kokkos::View<double***,Device>
fhalf;
160 Kokkos::View<double***,Device>
dfdr;
161 Kokkos::View<double***,Device>
dfdz;
162 Kokkos::View<double****,Device>
EDs;
163 Kokkos::View<double******,Device>
M_ab;
164 Kokkos::View<double*****,Device>
M_s;
169 fhalf(
"fhalf",mb_n_nodes,nvz-1,nvr-1),
170 dfdr(
"dfdr",mb_n_nodes,nvz-1,nvr-1),
171 dfdz(
"dfdz",mb_n_nodes,nvz-1,nvr-1),
172 EDs(
"EDs",mb_n_nodes,nvz-1,nvr-1,
ED::N),
173 M_s(
"M_s",mb_n_nodes,n_vgrids, (nvr-1)*(nvz-1),
ED::N, nvr-1),
174 M_ab(
"M_ab",mb_n_nodes,n_vgrids, n_vgrids-1, (nvr-1)*(nvz-1), 3, (nvr-1)*(nvz-1)),
178 int mat_loc[16] = {4,5,7,8,
183 for (
int i=0;i<16;i++)
193 template<
class Device>
229 if(nlr.
present(
"col_pout")) outer_psi_bound *= magnetic_field.
psi_norm();
242 int default_batch_size = 64;
244 int default_batch_size = 1;
246 std::string linalg_backend_str;
249 batch_size = nlr.
get<
int>(
"mesh_batch_size", default_batch_size);
250 linalg_backend_str = nlr.
get<std::string>(
"collisions_solver",
"lapack");
255 linalg_backend_str =
"lapack";
264 diag_on = nlr.
get<
bool>(
"diag_col_convergence_stat_on",
false);
267 io_stream = std::make_shared<XGC_IO_Stream>();
270 io_stream->Open(
"xgc.col_conv_status.bp", mode);
276 int plasma_nspecies = nlr.
get<
int>(
"ptl_nsp",1);
279 int sml_special = nlr.
get<
int>(
"sml_special", 0);
280 bool sml_electron_on = nlr.
get<
bool>(
"sml_electron_on",
false);
281 if(sml_special==4) sml_electron_on =
false;
282 if(sml_electron_on) plasma_nspecies += 1;
286 int default_batch_size = 64;
288 int default_batch_size = 1;
290 int col_grid_batch_size;
293 col_grid_batch_size = nlr.
get<
int>(
"mesh_batch_size", default_batch_size);
295 col_grid_batch_size = default_batch_size;
298 double device_col_GB_per_vertex = plasma_nspecies*std::max(plasma_nspecies-1,1)*(vgrid.
nvp*vgrid.
nmu)*(vgrid.
nvp*vgrid.
nmu)*8*
BYTES_TO_GB;
299 double gpu_memory_usage = (col_grid_batch_size*device_col_GB_per_vertex);
303 return memory_prediction;
310 static KOKKOS_INLINE_FUNCTION
double get_maxw_fac(
double mesh_dr,
double mesh_r,
double numeric_vth2) ;
319 static KOKKOS_INLINE_FUNCTION
void LU_matrix_ftn(
int mesh_ind,
int gri,
int grj,
int spi,
int cell_i,
int cell_j,
const CollisionVelocityGrids<Device>& col_vgrids,
int mprl_col,
int mat_pos,
double coeff1,
double coeff2,
const TmpColData<Device>& tcd,
const Kokkos::View<int**,Device>& index_map_LU_d,
typename Collisions::GridMatrix<Device>::values_array_t LU_values);
331 static KOKKOS_INLINE_FUNCTION
void E_and_D_s(
int idx,
int mb_n_nodes,
int nvrm1,
int nvzm1,
const TmpColData<Device>& tcd,
int gri) ;
352 void collision(std::vector<
Species<DeviceType>> &all_species,
const Moments& moments,
const DomainDecomposition<DeviceType>& pol_decomp,
const View<bool*, HostType>& in_range,
bool symmetric_f,
const VGridDistribution<HostType>& f0_f,
VGridDistribution<HostType>& df_out,
double dt, View<int*,CLayout,HostType>& converged_all, View<double*,CLayout,HostType>& node_cost)
const;
double min_p_thres
Definition: col_grid.hpp:67
double inpsi
Boundary condition used in a few spots.
Definition: magnetic_field.hpp:43
Definition: col_grid_matrix.hpp:23
double w_sum
Definition: col_grid.hpp:65
int nmu
n points in mu (not including zero)
Definition: velocity_grid.hpp:13
int nvp
n points in parallel velocity (not including zero)
Definition: velocity_grid.hpp:9
Kokkos::View< double ******, Device > M_ab
Definition: col_grid.hpp:163
static KOKKOS_INLINE_FUNCTION void LU_matrix_ftn(int mesh_ind, int gri, int grj, int spi, int cell_i, int cell_j, const CollisionVelocityGrids< Device > &col_vgrids, int mprl_col, int mat_pos, double coeff1, double coeff2, const TmpColData< Device > &tcd, const Kokkos::View< int **, Device > &index_map_LU_d, typename Collisions::GridMatrix< Device >::values_array_t LU_values)
Definition: col_grid.tpp:865
int batch_size
Definition: col_grid.hpp:198
T get(const string ¶m, const T default_val, int val_ind=0)
Definition: NamelistReader.hpp:373
constexpr double BYTES_TO_GB
Definition: constants.hpp:12
Kokkos::View< Convergence::Status *, HostType > core(CollisionVelocityGrids< Device > &col_vgrids, CollisionSpecies< Device > &col_spall, TmpColData< Device > &tcd, int mb_n_nodes) const
Definition: col_grid.tpp:150
Kokkos::View< double *****, Device > M_s
Definition: col_grid.hpp:164
Definition: col_grid.hpp:194
Kokkos::DualView< double ****, Kokkos::LayoutRight, Device > pdf_np1
Definition: col_species.hpp:88
Definition: velocity_grid.hpp:8
void set(int mesh_ind, const CollisionSpecies< Device > &col_spall)
Definition: col_grid.hpp:106
bool present(const string ¶m)
Definition: NamelistReader.hpp:363
Definition: col_grid.hpp:47
Kokkos::View< double ***, Device > fhalf
Definition: col_grid.hpp:159
Status
Definition: col_grid.hpp:46
Definition: col_grid.hpp:52
void collision(std::vector< Species< DeviceType >> &all_species, const Moments &moments, const DomainDecomposition< DeviceType > &pol_decomp, const View< bool *, HostType > &in_range, bool symmetric_f, const VGridDistribution< HostType > &f0_f, VGridDistribution< HostType > &df_out, double dt, View< int *, CLayout, HostType > &converged_all, View< double *, CLayout, HostType > &node_cost) const
Definition: col_grid.tpp:22
Collisions::LinAlgBackend labackend
Definition: col_grid.hpp:200
double p_sum
Definition: col_grid.hpp:66
Kokkos::View< value_type ***, Kokkos::LayoutRight, Device, Kokkos::MemoryTraits< Kokkos::Unmanaged >> values_array_t
Definition: col_grid_matrix.hpp:31
Kokkos::View< double ***, Device > gammac_spall
Definition: col_grid.hpp:156
Definition: NamelistReader.hpp:193
Definition: magnetic_field.hpp:13
Definition: moments.hpp:13
bool en_exit_ok
Definition: col_grid.hpp:74
Definition: col_grid.hpp:30
Kokkos::DualView< CollisionSpeciesScalars **, Device > s
Definition: col_species.hpp:85
double dn_n_max
Definition: col_grid.hpp:72
CollisionGrid()
Definition: col_grid.hpp:216
int ginkgo_max_iterations
Definition: col_grid.hpp:203
double inner_psi_bound
Inner psi bound; collisions skipped below this.
Definition: col_grid.hpp:205
KOKKOS_INLINE_FUNCTION double psi_norm() const
Definition: magnetic_field.tpp:62
Definition: col_vgrids.hpp:13
void core_delta_init(int mb_n_nodes, int gri, int grj, int spi, CollisionVelocityGrids< Device > &col_vgrids, const CollisionSpecies< Device > &col_spall) const
Definition: col_grid.tpp:804
View< double *, Device > get_numeric_v_thermal_equil(int mb_n_nodes, int spi, int grj, const CollisionVelocityGrids< Device > &col_vgrids, const CollisionSpecies< Device > &col_spall) const
Definition: col_grid.tpp:772
static KOKKOS_INLINE_FUNCTION void E_and_D_ab(int idx, int mb_n_nodes, int nvrm1, int nvzm1, const CollisionVelocityGrids< Device > &col_vgrids, const TmpColData< Device > &tcd, int gri, int grj)
Definition: col_grid.tpp:542
Definition: col_grid.hpp:48
Definition: col_grid.hpp:153
void LU_matrix(int mb_n_nodes, int gri, int grj, int spi, const CollisionVelocityGrids< Device > &col_vgrids, const TmpColData< Device > &tcd, Collisions::GridMatrix< Device > *const mtx) const
Definition: col_grid.tpp:910
const int vpic_inner_iter_max
Definition: col_grid.hpp:40
static KOKKOS_INLINE_FUNCTION void E_and_D_s(int idx, int mb_n_nodes, int nvrm1, int nvzm1, const TmpColData< Device > &tcd, int gri)
Definition: col_grid.tpp:711
View< double ***, CLayout, HostType > mesh_r
Definition: col_vgrids.hpp:20
void core_init(int isp, int mesh_ind, const CollisionVelocityGrids< Device > &col_vgrids, const CollisionSpecies< Device > &col_spall) const
Definition: col_grid.tpp:369
double dw_sum
Definition: col_grid.hpp:70
double outpsi
Boundary condition used in a few spots.
Definition: magnetic_field.hpp:44
Kokkos::DualView< double ****, Kokkos::LayoutRight, Device > pdf_n
Definition: col_species.hpp:87
void use_namelist(const string &namelist)
Definition: NamelistReader.hpp:355
Definition: col_grid.hpp:63
Definition: col_grid.hpp:32
Definition: memory_prediction.hpp:4
void eval(int isp, int mesh_ind, const CollisionVelocityGrids< Device > &cvg, const CollisionSpecies< Device > &cs, double &dw, double &dp, double &dn_n) const
Definition: col_grid.hpp:79
void E_and_D(int mb_n_nodes, int gri, int grj, const CollisionVelocityGrids< Device > &col_vgrids, TmpColData< Device > &tcd) const
Definition: col_grid.tpp:504
Definition: col_grid.hpp:49
Kokkos::View< double ***, Device > dfdz
Definition: col_grid.hpp:161
double outer_psi_bound
Outer psi bound; collisions skipped above this.
Definition: col_grid.hpp:206
void picard_loop(int vpic_inner_iter_max, const CollisionVelocityGrids< Device > &col_vgrids, CollisionSpecies< Device > &col_spall, TmpColData< Device > &tcd, int mb_n_nodes, Kokkos::View< Convergence::Status *, HostType > &convergence_status, Kokkos::View< Convergence::Moments *, HostType > &moments) const
Definition: col_grid.tpp:252
View< int *, CLayout, HostType > n_subcycles
Number of subcycles for each vertex.
Definition: col_grid.hpp:211
Definition: col_grid.hpp:35
double ginkgo_residual_reduction
Definition: col_grid.hpp:202
static KOKKOS_INLINE_FUNCTION void angle_avg_s(int idx, int mb_n_nodes, int nvrm1, int nvzm1, const CollisionVelocityGrids< Device > &col_vgrids, const TmpColData< Device > &tcd, int gri)
Definition: col_grid.tpp:595
bool dens_exit_ok
Definition: col_grid.hpp:73
bool namelist_present(const string &namelist)
Definition: NamelistReader.hpp:351
Definition: col_grid.hpp:31
View< double ***, CLayout, HostType > mesh_z
Definition: col_vgrids.hpp:21
XGC_IO_Mode
Definition: xgc_io.hpp:17
Kokkos::View< double ****, Device > EDs
Definition: col_grid.hpp:162
Definition: col_grid.hpp:33
Definition: col_grid.hpp:54
Definition: magnetic_field.F90:1
LinAlgBackend
Definition: col_grid_matrix.hpp:221
int n() const
Definition: col_species.hpp:181
Definition: col_grid.hpp:51
Kokkos::View< double ***, Device > dfdr
Definition: col_grid.hpp:160
static KOKKOS_INLINE_FUNCTION void angle_avg_ab(int idx, int mb_n_nodes, int nvrm1, int nvzm1, const CollisionVelocityGrids< Device > &col_vgrids, const TmpColData< Device > &tcd, int gri, int grj)
Definition: col_grid.tpp:434
int start_step
starting step for collisions; should be part of step trigger
Definition: col_grid.hpp:208
bool mom_exit_ok
Definition: col_grid.hpp:75
View< double ***, CLayout, HostType > vol_h
Definition: col_vgrids.hpp:23
Definition: species.hpp:75
static MemoryPrediction estimate_memory_usage(NLReader::NamelistReader &nlr)
Definition: col_grid.hpp:274
CollisionGrid(NLReader::NamelistReader &nlr, const MagneticField< DeviceType > &magnetic_field, const Grid< DeviceType > &grid, bool overwrite_existing_files)
Definition: col_grid.hpp:219
std::shared_ptr< XGC_IO_Stream > io_stream
Definition: col_grid.hpp:214
Definition: col_species.hpp:81
Kokkos::DualView< int[4][4], Device > mat_pos_rel_indx
Definition: col_grid.hpp:157
void angle_avg(int mb_n_nodes, int gri, int grj, CollisionVelocityGrids< Device > &col_vgrids, TmpColData< Device > &tcd) const
Definition: col_grid.tpp:416
bool is_okay(Status convergence_status)
Definition: col_grid.hpp:57
Definition: col_grid.hpp:53
double dp_sum
Definition: col_grid.hpp:71
void f_df(int mb_n_nodes, const CollisionVelocityGrids< Device > &col_vgrids, const CollisionSpecies< Device > &col_spall, int spi, int grj, TmpColData< Device > &tcd) const
Definition: col_grid.tpp:660
Kokkos::ViewAllocateWithoutInitializing NoInit
Definition: space_settings.hpp:68
static KOKKOS_INLINE_FUNCTION double get_maxw_fac(double mesh_dr, double mesh_r, double numeric_vth2)
Definition: col_grid.tpp:756
Definition: col_grid.hpp:50
bool evaluate_conservation(int mesh_ind, const CollisionVelocityGrids< Device > &col_vgrids, const CollisionSpecies< Device > &col_spall, bool &values_are_all_finite)
Definition: col_grid.hpp:119
bool diag_on
Definition: col_grid.hpp:213
Definition: col_grid.hpp:34
int max_n_subcycles
Maximum number of subcycles that may be attempted.
Definition: col_grid.hpp:210