4 #define VELOCITY_SPACE_DIMENSION 2
9 #include <Kokkos_Core.hpp>
12 #include <petscversion.h>
14 #include <petscdmplex.h>
16 #include "petscdmswarm.h"
20 #if !defined(PETSC_USE_STRICT_PETSCERRORCODE) && !defined(PETSC_SUCCESS)
21 #define PETSC_SUCCESS 0
41 Kokkos::View<DMObjects*, Kokkos::LayoutRight, HostType>
obj;
46 Kokkos::resize(
obj, 0);
51 for (
int id = 0;
id <
dm_len;
id++){
52 DMDestroy(&
obj(
id).dm);
53 MatDestroy(&
obj(
id).MM);
62 for (
int id = 0;
id <
dm_len;
id++){
63 obj(
id).dm = original.
obj(
id).dm;
64 obj(
id).MM = original.
obj(
id).MM;
69 if (
this == &original){
75 for (
int id = 0;
id <
dm_len;
id++){
76 obj(
id).dm = original.
obj(
id).dm;
77 obj(
id).MM = original.
obj(
id).MM;
100 PetscInt order,
const PetscInt Nspecies,
101 const PetscReal vPara_min,
const PetscReal vPara_max,
102 const PetscInt nvp,
const PetscReal vPerp_min,
103 const PetscReal vPerp_max,
const PetscInt nmu)
105 int element_order_shift = (order > 0) ? order : 1;
106 const PetscInt num_vPara = 2*nvp/element_order_shift + 1;
107 const PetscInt num_vPerp = nmu/element_order_shift + 1;
116 PetscReal lo[2], hi[2];
117 cells[0] = num_vPara - 1;
118 cells[1] = num_vPerp - 1;
124 PetscFunctionBeginUser;
126 std::string order_str = std::to_string(order);
127 ierr = PetscOptionsSetValue(NULL,
"-petscspace_degree", order_str.c_str());CHKERRQ(ierr);
132 DMBoundaryType periodicity[2] = {DM_BOUNDARY_NONE, DM_BOUNDARY_NONE};
133 PetscBool interpolate = PETSC_TRUE;
135 for (
int id = 0;
id <
dm_len;
id++){
136 PetscInt petsc_zero=0.0;
137 ierr = DMPlexCreateBoxMesh(PETSC_COMM_SELF, dim, PETSC_FALSE, cells, lo, hi, periodicity, interpolate, petsc_zero, PETSC_FALSE, &
obj(
id).dm);CHKERRQ(ierr);
138 ierr = PetscObjectSetName((PetscObject)
obj(
id).dm,
"Potential Grid");CHKERRQ(ierr);
139 if (
id ==
dm_len - 1) {ierr = DMViewFromOptions(
obj(
id).dm, NULL,
"-dm_view");CHKERRQ(ierr);}
140 ierr = DMSetFromOptions(
obj(
id).dm);CHKERRQ(ierr);
141 ierr = PetscFECreateDefault(PETSC_COMM_SELF, dim, Nspecies, PETSC_FALSE,
"", PETSC_DECIDE, &fe);CHKERRQ(ierr);
142 ierr = PetscFESetFromOptions(fe);CHKERRQ(ierr);
143 ierr = PetscObjectSetName((PetscObject)fe,
"fe");CHKERRQ(ierr);
144 ierr = DMSetField(
obj(
id).dm,
field, NULL, (PetscObject)fe);CHKERRQ(ierr);
145 ierr = DMCreateDS(
obj(
id).dm);CHKERRQ(ierr);
146 ierr = PetscFEDestroy(&fe);CHKERRQ(ierr);
148 ierr = DMCreateMassMatrix(
obj(
id).dm,
obj(
id).dm, &
obj(
id).MM);CHKERRQ(ierr);
162 PetscFunctionBeginUser;
164 for (
int id = 0;
id <
dm_len;
id++){
165 if(
obj(
id).dm != NULL){
166 ierr = DMDestroy(&
obj(
id).dm);CHKERRQ(ierr);
169 if(
obj(
id).MM != NULL){
170 ierr = MatDestroy(&
obj(
id).MM);CHKERRQ(ierr);
180 int order,
const int Nspecies,
181 const double vPara_min,
const double vPara_max,
182 const int nvp,
const double vPerp_min,
183 const double vPerp_max,
const int nmu){
186 CHKERRABORT(PETSC_COMM_SELF,ierr);
193 CHKERRABORT(PETSC_COMM_SELF,ierr);
#define VELOCITY_SPACE_DIMENSION
Definition: DM_wrapper.hpp:4
#define PETSC_SUCCESS
Definition: DM_wrapper.hpp:21
subroutine field(fld, t, rz_outside)
Calculate field of a given point using interpolation funtions This is for the equilibrium and RMP mag...
Definition: magnetic_field.F90:24
logical false
Definition: module.F90:102
Definition: DM_wrapper.hpp:26
Mat MM
PETSc mass matrix object for the velocity grid when pseudo-inverse is used.
Definition: DM_wrapper.hpp:28
DM dm
PETSc DM mesh object representing the velocity grid when pseudo-inverse is used.
Definition: DM_wrapper.hpp:27
Definition: DM_wrapper.hpp:34
PetscErrorCode initialize_pseudo_inverse_interpolation_petsc(int nthreads, PetscInt order, const PetscInt Nspecies, const PetscReal vPara_min, const PetscReal vPara_max, const PetscInt nvp, const PetscReal vPerp_min, const PetscReal vPerp_max, const PetscInt nmu)
Definition: DM_wrapper.hpp:99
int dm_len
Number of PETSc mesh objects to store.
Definition: DM_wrapper.hpp:40
DMWrapper()
Definition: DM_wrapper.hpp:43
bool is_owner
Definition: DM_wrapper.hpp:39
~DMWrapper()
Definition: DM_wrapper.hpp:49
void destroy_DM()
Definition: DM_wrapper.hpp:190
DMWrapper(const DMWrapper &original)
Definition: DM_wrapper.hpp:58
Kokkos::View< DMObjects *, Kokkos::LayoutRight, HostType > obj
Stores number of threads DMObjects.
Definition: DM_wrapper.hpp:41
PetscErrorCode destroy_DM_petsc()
Definition: DM_wrapper.hpp:160
void initialize_pseudo_inverse_interpolation(int nthreads, int order, const int Nspecies, const double vPara_min, const double vPara_max, const int nvp, const double vPerp_min, const double vPerp_max, const int nmu)
Definition: DM_wrapper.hpp:179
DMWrapper & operator=(const DMWrapper &original)
Definition: DM_wrapper.hpp:68