Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Energy Conserving P2 Can-pb Colls Fix #491

Merged
merged 16 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/gkyl_vlasov_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ static const char *const valid_moment_names[] = {
// of the LTE (local thermodynamic equilibrium) distribution
// Note: in relativity V_drift is the bulk four-velocity (GammaV, GammaV*V_drift)
"Integrated", // this is an internal flag, not for passing to moment type
"MEnergy", // this is for the canonical-pb species only**
};

// check if name of moment is valid or not
Expand Down
2 changes: 0 additions & 2 deletions apps/vlasov.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ gkyl_vlasov_app_new(struct gkyl_vm *vm)
}
}


// Set the appropriate update function for taking a single time step
// If we have implicit fluid-EM coupling or implicit BGK collisions,
// we perform a first-order operator split and treat those terms implicitly.
Expand Down Expand Up @@ -851,7 +850,6 @@ comm_reduce_app_stat(const gkyl_vlasov_app* app,
global->niter_self_bgk_corr[s] = l_red_bgk_corr[s];
}


enum {
TOTAL_TM, RK3_TM, FL_EM_TM,
INIT_SPECIES_TM, INIT_FLUID_SPECIES_TM, INIT_FIELD_TM,
Expand Down
1 change: 1 addition & 0 deletions apps/vm_species.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ vm_species_apply_bc(gkyl_vlasov_app *app, const struct vm_species *species, stru
app->stat.species_bc_tm += gkyl_time_diff_now_sec(wst);
}


void
vm_species_calc_L2(gkyl_vlasov_app *app, double tm, const struct vm_species *species)
{
Expand Down
4 changes: 4 additions & 0 deletions apps/vm_species_lte.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ vm_species_lte_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct vm
.conf_range = &app->local,
.conf_range_ext = &app->local_ext,
.vel_range = &s->local_vel,
.phase_range = &s->local,
.gamma = s->gamma,
.gamma_inv = s->gamma_inv,
.h_ij_inv = s->h_ij_inv,
.det_h = s->det_h,
.hamil = s->hamil,
.model_id = s->model_id,
.use_gpu = app->use_gpu,
};
Expand All @@ -43,10 +45,12 @@ vm_species_lte_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct vm
.conf_range = &app->local,
.conf_range_ext = &app->local_ext,
.vel_range = &s->local_vel,
.phase_range = &s->local,
.gamma = s->gamma,
.gamma_inv = s->gamma_inv,
.h_ij_inv = s->h_ij_inv,
.det_h = s->det_h,
.hamil = s->hamil,
.model_id = s->model_id,
.use_gpu = app->use_gpu,
.max_iter = max_iter,
Expand Down
15 changes: 12 additions & 3 deletions apps/vm_species_moment.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <assert.h>
#include <gkyl_mom_canonical_pb.h>
#include <gkyl_vlasov_priv.h>

// initialize species moment object
Expand All @@ -22,10 +23,12 @@ vm_species_moment_init(struct gkyl_vlasov_app *app, struct vm_species *s,
.conf_range = &app->local,
.conf_range_ext = &app->local_ext,
.vel_range = &s->local_vel,
.phase_range = &s->local,
.gamma = s->gamma,
.gamma_inv = s->gamma_inv,
.h_ij_inv = s->h_ij_inv,
.det_h = s->det_h,
.hamil = s->hamil,
.model_id = s->model_id,
.use_gpu = app->use_gpu,
};
Expand All @@ -37,14 +40,20 @@ vm_species_moment_init(struct gkyl_vlasov_app *app, struct vm_species *s,
if (s->model_id == GKYL_MODEL_SR) {
struct gkyl_mom_vlasov_sr_auxfields sr_inp = {.gamma = s->gamma};
sm->mcalc = gkyl_dg_updater_moment_new(&s->grid, &app->confBasis,
&app->basis, &app->local, &s->local_vel, s->model_id, &sr_inp,
&app->basis, &app->local, &s->local_vel, &s->local, s->model_id, &sr_inp,
nm, is_integrated, app->use_gpu);
num_mom = gkyl_dg_updater_moment_num_mom(sm->mcalc);
}
} else if (s->model_id == GKYL_MODEL_CANONICAL_PB && (strcmp(nm, "MEnergy") == 0 || strcmp(nm, "Integrated") == 0)) {
struct gkyl_mom_canonical_pb_auxfields can_pb_inp = {.hamil = s->hamil};
sm->mcalc = gkyl_dg_updater_moment_new(&s->grid, &app->confBasis,
&app->basis, &app->local, &s->local_vel, &s->local, s->model_id, &can_pb_inp,
nm, is_integrated, app->use_gpu);
num_mom = gkyl_dg_updater_moment_num_mom(sm->mcalc);
}
else {
// No auxiliary fields for moments if not SR
sm->mcalc = gkyl_dg_updater_moment_new(&s->grid, &app->confBasis,
&app->basis, &app->local, &s->local_vel, s->model_id, 0,
&app->basis, &app->local, &s->local_vel, &s->local, s->model_id, 0,
nm, is_integrated, app->use_gpu);
num_mom = gkyl_dg_updater_moment_num_mom(sm->mcalc);
}
Expand Down
4 changes: 4 additions & 0 deletions apps/vm_species_projection.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ vm_species_projection_init(struct gkyl_vlasov_app *app, struct vm_species *s,
.conf_range = &app->local,
.conf_range_ext = &app->local_ext,
.vel_range = &s->local_vel,
.phase_range = &s->local,
.gamma = s->gamma,
.gamma_inv = s->gamma_inv,
.h_ij_inv = s->h_ij_inv,
.det_h = s->det_h,
.hamil = s->hamil,
.model_id = s->model_id,
.use_gpu = app->use_gpu,
};
Expand All @@ -73,10 +75,12 @@ vm_species_projection_init(struct gkyl_vlasov_app *app, struct vm_species *s,
.conf_range = &app->local,
.conf_range_ext = &app->local_ext,
.vel_range = &s->local_vel,
.phase_range = &s->local,
.gamma = s->gamma,
.gamma_inv = s->gamma_inv,
.h_ij_inv = s->h_ij_inv,
.det_h = s->det_h,
.hamil = s->hamil,
.model_id = s->model_id,
.use_gpu = app->use_gpu,
.max_iter = max_iter,
Expand Down
21 changes: 7 additions & 14 deletions kernels/canonical_pb/canonical_pb_vars_pressure_1x_ser_p1.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#include <gkyl_canonical_pb_kernels.h>
#include <gkyl_binop_mul_ser.h>
GKYL_CU_DH void canonical_pb_vars_pressure_1x_ser_p1(const double *h_ij_inv, const double *M2_ij, const double *v_j, const double *nv_i, double* GKYL_RESTRICT d_Jv_P)
GKYL_CU_DH void canonical_pb_vars_pressure_1x_ser_p1(const double *h_ij_inv, const double *MEnergy, const double *v_j, const double *nv_i, double* GKYL_RESTRICT d_Jv_P)
{
// h_ij_inv: Input volume expansion of the inverse metric tensor.
// [Hxx, Hxy, Hxz,
// Hxy, Hyy, Hyz,
// Hxz, Hyz, Hzz]
// M2_ij: Input volume expansion of the M2_ij moment.
// [M2xx, M2xy, M2xz,
// M2xy, M2yy, M2yz,
// M2xz, M2yz, M2zz]
// MEnergy: Input volume expansion of the MEnergy moment.
// v_j: Input volume expansion of V_drift.
// [vx, vy, vz]
// nv_i: Input volume expansion of M1i = N*Vdrift.
Expand All @@ -20,23 +17,19 @@ GKYL_CU_DH void canonical_pb_vars_pressure_1x_ser_p1(const double *h_ij_inv, con

const double *Vx = &v_j[0];

const double *M2xx = &M2_ij[0];
const double *energy = &MEnergy[0];

const double *Hxx = &h_ij_inv[0];

// h^{ij}M2_ij
double Hxx_M2xx[2] = {0.0};
binop_mul_1d_ser_p1(Hxx, M2xx, Hxx_M2xx);

// h^{ij}*nv_i*v_j
double Hxx_M1x[2] = {0.0};
double Hxx_M1x_Vx[2] = {0.0};
binop_mul_1d_ser_p1(Hxx, NVx, Hxx_M1x);
binop_mul_1d_ser_p1(Hxx_M1x, Vx, Hxx_M1x_Vx);

d_Jv_P[0] = 0.0;
d_Jv_P[0] += Hxx_M2xx[0] - Hxx_M1x_Vx[0];
d_Jv_P[1] = 0.0;
d_Jv_P[1] += Hxx_M2xx[1] - Hxx_M1x_Vx[1];
d_Jv_P[0] = 2.0*energy[0];
d_Jv_P[0] += - Hxx_M1x_Vx[0];
d_Jv_P[1] = 2.0*energy[1];
d_Jv_P[1] += - Hxx_M1x_Vx[1];

}
25 changes: 9 additions & 16 deletions kernels/canonical_pb/canonical_pb_vars_pressure_1x_ser_p2.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#include <gkyl_canonical_pb_kernels.h>
#include <gkyl_binop_mul_ser.h>
GKYL_CU_DH void canonical_pb_vars_pressure_1x_ser_p2(const double *h_ij_inv, const double *M2_ij, const double *v_j, const double *nv_i, double* GKYL_RESTRICT d_Jv_P)
GKYL_CU_DH void canonical_pb_vars_pressure_1x_ser_p2(const double *h_ij_inv, const double *MEnergy, const double *v_j, const double *nv_i, double* GKYL_RESTRICT d_Jv_P)
{
// h_ij_inv: Input volume expansion of the inverse metric tensor.
// [Hxx, Hxy, Hxz,
// Hxy, Hyy, Hyz,
// Hxz, Hyz, Hzz]
// M2_ij: Input volume expansion of the M2_ij moment.
// [M2xx, M2xy, M2xz,
// M2xy, M2yy, M2yz,
// M2xz, M2yz, M2zz]
// MEnergy: Input volume expansion of the MEnergy moment.
// v_j: Input volume expansion of V_drift.
// [vx, vy, vz]
// nv_i: Input volume expansion of M1i = N*Vdrift.
Expand All @@ -20,25 +17,21 @@ GKYL_CU_DH void canonical_pb_vars_pressure_1x_ser_p2(const double *h_ij_inv, con

const double *Vx = &v_j[0];

const double *M2xx = &M2_ij[0];
const double *energy = &MEnergy[0];

const double *Hxx = &h_ij_inv[0];

// h^{ij}M2_ij
double Hxx_M2xx[3] = {0.0};
binop_mul_1d_ser_p2(Hxx, M2xx, Hxx_M2xx);

// h^{ij}*nv_i*v_j
double Hxx_M1x[3] = {0.0};
double Hxx_M1x_Vx[3] = {0.0};
binop_mul_1d_ser_p2(Hxx, NVx, Hxx_M1x);
binop_mul_1d_ser_p2(Hxx_M1x, Vx, Hxx_M1x_Vx);

d_Jv_P[0] = 0.0;
d_Jv_P[0] += Hxx_M2xx[0] - Hxx_M1x_Vx[0];
d_Jv_P[1] = 0.0;
d_Jv_P[1] += Hxx_M2xx[1] - Hxx_M1x_Vx[1];
d_Jv_P[2] = 0.0;
d_Jv_P[2] += Hxx_M2xx[2] - Hxx_M1x_Vx[2];
d_Jv_P[0] = 2.0*energy[0];
d_Jv_P[0] += - Hxx_M1x_Vx[0];
d_Jv_P[1] = 2.0*energy[1];
d_Jv_P[1] += - Hxx_M1x_Vx[1];
d_Jv_P[2] = 2.0*energy[2];
d_Jv_P[2] += - Hxx_M1x_Vx[2];

}
53 changes: 19 additions & 34 deletions kernels/canonical_pb/canonical_pb_vars_pressure_2x_ser_p1.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#include <gkyl_canonical_pb_kernels.h>
#include <gkyl_binop_mul_ser.h>
GKYL_CU_DH void canonical_pb_vars_pressure_2x_ser_p1(const double *h_ij_inv, const double *M2_ij, const double *v_j, const double *nv_i, double* GKYL_RESTRICT d_Jv_P)
GKYL_CU_DH void canonical_pb_vars_pressure_2x_ser_p1(const double *h_ij_inv, const double *MEnergy, const double *v_j, const double *nv_i, double* GKYL_RESTRICT d_Jv_P)
{
// h_ij_inv: Input volume expansion of the inverse metric tensor.
// [Hxx, Hxy, Hxz,
// Hxy, Hyy, Hyz,
// Hxz, Hyz, Hzz]
// M2_ij: Input volume expansion of the M2_ij moment.
// [M2xx, M2xy, M2xz,
// M2xy, M2yy, M2yz,
// M2xz, M2yz, M2zz]
// MEnergy: Input volume expansion of the MEnergy moment.
// v_j: Input volume expansion of V_drift.
// [vx, vy, vz]
// nv_i: Input volume expansion of M1i = N*Vdrift.
Expand All @@ -22,24 +19,12 @@ GKYL_CU_DH void canonical_pb_vars_pressure_2x_ser_p1(const double *h_ij_inv, con
const double *Vx = &v_j[0];
const double *Vy = &v_j[4];

const double *M2xx = &M2_ij[0];
const double *M2xy = &M2_ij[4];
const double *M2yy = &M2_ij[8];
const double *energy = &MEnergy[0];

const double *Hxx = &h_ij_inv[0];
const double *Hxy = &h_ij_inv[4];
const double *Hyy = &h_ij_inv[8];

// h^{ij}M2_ij
double Hxx_M2xx[4] = {0.0};
binop_mul_2d_ser_p1(Hxx, M2xx, Hxx_M2xx);

double Hxy_M2xy[4] = {0.0};
binop_mul_2d_ser_p1(Hxy, M2xy, Hxy_M2xy);

double Hyy_M2yy[4] = {0.0};
binop_mul_2d_ser_p1(Hyy, M2yy, Hyy_M2yy);

// h^{ij}*nv_i*v_j
double Hxx_M1x[4] = {0.0};
double Hxx_M1x_Vx[4] = {0.0};
Expand All @@ -56,21 +41,21 @@ GKYL_CU_DH void canonical_pb_vars_pressure_2x_ser_p1(const double *h_ij_inv, con
binop_mul_2d_ser_p1(Hyy, NVy, Hyy_M1y);
binop_mul_2d_ser_p1(Hyy_M1y, Vy, Hyy_M1y_Vy);

d_Jv_P[0] = 0.0;
d_Jv_P[0] += Hxx_M2xx[0] - Hxx_M1x_Vx[0];
d_Jv_P[0] += (Hxy_M2xy[0] - Hxy_M1x_Vy[0])*2.0;
d_Jv_P[0] += Hyy_M2yy[0] - Hyy_M1y_Vy[0];
d_Jv_P[1] = 0.0;
d_Jv_P[1] += Hxx_M2xx[1] - Hxx_M1x_Vx[1];
d_Jv_P[1] += (Hxy_M2xy[1] - Hxy_M1x_Vy[1])*2.0;
d_Jv_P[1] += Hyy_M2yy[1] - Hyy_M1y_Vy[1];
d_Jv_P[2] = 0.0;
d_Jv_P[2] += Hxx_M2xx[2] - Hxx_M1x_Vx[2];
d_Jv_P[2] += (Hxy_M2xy[2] - Hxy_M1x_Vy[2])*2.0;
d_Jv_P[2] += Hyy_M2yy[2] - Hyy_M1y_Vy[2];
d_Jv_P[3] = 0.0;
d_Jv_P[3] += Hxx_M2xx[3] - Hxx_M1x_Vx[3];
d_Jv_P[3] += (Hxy_M2xy[3] - Hxy_M1x_Vy[3])*2.0;
d_Jv_P[3] += Hyy_M2yy[3] - Hyy_M1y_Vy[3];
d_Jv_P[0] = 2.0*energy[0];
d_Jv_P[0] += - Hxx_M1x_Vx[0];
d_Jv_P[0] += (- Hxy_M1x_Vy[0])*2.0;
d_Jv_P[0] += - Hyy_M1y_Vy[0];
d_Jv_P[1] = 2.0*energy[1];
d_Jv_P[1] += - Hxx_M1x_Vx[1];
d_Jv_P[1] += (- Hxy_M1x_Vy[1])*2.0;
d_Jv_P[1] += - Hyy_M1y_Vy[1];
d_Jv_P[2] = 2.0*energy[2];
d_Jv_P[2] += - Hxx_M1x_Vx[2];
d_Jv_P[2] += (- Hxy_M1x_Vy[2])*2.0;
d_Jv_P[2] += - Hyy_M1y_Vy[2];
d_Jv_P[3] = 2.0*energy[3];
d_Jv_P[3] += - Hxx_M1x_Vx[3];
d_Jv_P[3] += (- Hxy_M1x_Vy[3])*2.0;
d_Jv_P[3] += - Hyy_M1y_Vy[3];

}
Loading
Loading