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

Sr bgk operator #320

Merged
merged 4 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 31 additions & 3 deletions apps/gkyl_vlasov_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <gkyl_array_rio.h>
#include <gkyl_bc_basic.h>
#include <gkyl_bgk_collisions.h>
#include <gkyl_correct_mj.h>
#include <gkyl_dg_advection.h>
#include <gkyl_dg_bin_ops.h>
#include <gkyl_dg_calc_em_vars.h>
Expand All @@ -40,6 +41,7 @@
#include <gkyl_eval_on_nodes.h>
#include <gkyl_ghost_surf_calc.h>
#include <gkyl_hyper_dg.h>
#include <gkyl_mj_moments.h>
#include <gkyl_mom_bcorr_lbo_vlasov.h>
#include <gkyl_mom_calc.h>
#include <gkyl_mom_calc_bcorr.h>
Expand All @@ -51,6 +53,7 @@
#include <gkyl_prim_lbo_type.h>
#include <gkyl_prim_lbo_vlasov.h>
#include <gkyl_proj_maxwellian_on_basis.h>
#include <gkyl_proj_mj_on_basis.h>
#include <gkyl_proj_on_basis.h>
#include <gkyl_range.h>
#include <gkyl_rect_decomp.h>
Expand All @@ -73,6 +76,7 @@ static const char *const valid_moment_names[] = {
"M3i",
"M3ijk",
"FiveMoments",
"SRFiveMoments", // relativistic moments n, vb, P
"Integrated", // this is an internal flag, not for passing to moment type
};

Expand All @@ -93,6 +97,15 @@ struct vm_species_moment {

struct gkyl_array *marr; // array to moment data
struct gkyl_array *marr_host; // host copy (same as marr if not on GPUs)

struct gkyl_mj_moments *mj_moms;
const char *nm; // Moment name
struct gkyl_array *n;
struct gkyl_array *vbi;
struct gkyl_array *T;
int vdim;
int num_basis;
bool is_sr_five_moments;
};

// forward declare species struct
Expand Down Expand Up @@ -143,12 +156,27 @@ struct vm_bgk_collisions {
struct gkyl_array *nu_init; // Array for initial collisionality when using Spitzer updater
struct gkyl_spitzer_coll_freq* spitzer_calc; // Updater for Spitzer collisionality if computing Spitzer value

struct vm_species_moment moms; // moments needed in BGK (single array includes Zeroth, First, and Second moment)

struct gkyl_array *fmax;
struct gkyl_array *nu_fmax;

struct gkyl_proj_maxwellian_on_basis *proj_max; // Maxwellian projection object
enum gkyl_model_id model_id;

// organization of the different models for BGK collisions
union {
// special relativistic Vlasov-Maxwell model
struct {
struct gkyl_proj_mj_on_basis *proj_mj; // Maxwell-Juttner projection object
struct gkyl_correct_mj *corr_mj; // Maxwell-Juttner correction object
struct gkyl_mj_moments *mj_moms;// Maxwell-Juttner moments object
struct gkyl_array *n_stationary, *vb, *T_stationary;
};
// non-relativistic vlasov model
struct {
struct vm_species_moment moms; // moments needed in BGK (single array includes Zeroth, First, and Second moment)
struct gkyl_proj_maxwellian_on_basis *proj_max; // Maxwellian projection object
};
};

struct gkyl_bgk_collisions *up_bgk; // BGK updater (also computes stable timestep)
};

Expand Down
63 changes: 54 additions & 9 deletions apps/vm_species_bgk.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,29 @@ vm_species_bgk_init(struct gkyl_vlasov_app *app, struct vm_species *s, struct vm
if (app->use_gpu)
bgk->nu_sum_host = mkarr(false, app->confBasis.num_basis, app->local_ext.volume);

// allocate moments needed for BGK collisions update
vm_species_moment_init(app, s, &bgk->moms, "FiveMoments");

bgk->proj_max = gkyl_proj_maxwellian_on_basis_new(&s->grid, &app->confBasis, &app->basis,
app->poly_order+1, app->use_gpu);
bgk->model_id = s->model_id;

if (bgk->model_id == GKYL_MODEL_SR) {

bgk->n_stationary = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume);
bgk->vb = mkarr(app->use_gpu, app->vdim * app->confBasis.num_basis, app->local_ext.volume);
bgk->T_stationary = mkarr(app->use_gpu, app->confBasis.num_basis, app->local_ext.volume);

bgk->mj_moms = gkyl_mj_moments_new(&s->grid, &app->confBasis,
&app->basis, &app->local, &s->local_vel, app->local.volume, app->local_ext.volume,
s->p_over_gamma, s->gamma, s->gamma_inv, false);
bgk->proj_mj = gkyl_proj_mj_on_basis_new(&s->grid, &app->confBasis, &app->basis,app->poly_order+1);
bgk->corr_mj = gkyl_correct_mj_new(&s->grid, &app->confBasis,
&app->basis, &app->local, &app->local_ext, &s->local_vel, s->p_over_gamma, s->gamma, s->gamma_inv, false);
// Correct the distribution function
}
else {
// allocate moments needed for BGK collisions update
vm_species_moment_init(app, s, &bgk->moms, "FiveMoments");
bgk->proj_max = gkyl_proj_maxwellian_on_basis_new(&s->grid, &app->confBasis, &app->basis,
app->poly_order+1, app->use_gpu);
}
bgk->fmax = mkarr(app->use_gpu, app->basis.num_basis, s->local_ext.volume);
bgk->nu_fmax = mkarr(app->use_gpu, app->basis.num_basis, s->local_ext.volume);
// BGK updater (also computes stable timestep)
Expand All @@ -61,7 +79,12 @@ vm_species_bgk_moms(gkyl_vlasov_app *app, const struct vm_species *species,
struct timespec wst = gkyl_wall_clock();

// compute needed moments
vm_species_moment_calc(&bgk->moms, species->local, app->local, fin);
if (bgk->model_id == GKYL_MODEL_SR) {
gkyl_mj_moments_advance(bgk->mj_moms, fin, bgk->n_stationary, bgk->vb, bgk->T_stationary, &species->local, &app->local);
}
else {
vm_species_moment_calc(&bgk->moms, species->local, app->local, fin);
}

app->stat.species_coll_mom_tm += gkyl_time_diff_now_sec(wst);
}
Expand All @@ -75,8 +98,20 @@ vm_species_bgk_rhs(gkyl_vlasov_app *app, const struct vm_species *species,
gkyl_array_clear(bgk->nu_fmax, 0.0);

// Obtain self-collisions nu*fmax
gkyl_proj_maxwellian_on_basis_lab_mom(bgk->proj_max, &species->local, &app->local,
bgk->moms.marr, bgk->fmax);
if (bgk->model_id == GKYL_MODEL_SR) {

// Compute MJ via the moments
gkyl_proj_mj_on_basis_fluid_stationary_frame_mom(bgk->proj_mj, &species->local, &app->local,
bgk->n_stationary, bgk->vb, bgk->T_stationary, bgk->fmax);
gkyl_correct_mj_fix_n_stationary(bgk->corr_mj, bgk->fmax, bgk->n_stationary, bgk->vb,
&species->local, &app->local);
//gkyl_correct_mj_fix(bgk->corr_mj, bgk->fmax, bgk->n_stationary, bgk->vb, bgk->T_stationary,
johnson452 marked this conversation as resolved.
Show resolved Hide resolved
// &species->local, &app->local, app->poly_order);
}
else {
gkyl_proj_maxwellian_on_basis_lab_mom(bgk->proj_max, &species->local, &app->local,
bgk->moms.marr, bgk->fmax);
}
gkyl_dg_mul_conf_phase_op_range(&app->confBasis, &app->basis, bgk->fmax,
bgk->self_nu, bgk->fmax, &app->local, &species->local);
gkyl_array_accumulate(bgk->nu_fmax, 1.0, bgk->fmax);
Expand All @@ -100,14 +135,24 @@ vm_species_bgk_release(const struct gkyl_vlasov_app *app, const struct vm_bgk_co
gkyl_array_release(bgk->nu_sum_host);
}

vm_species_moment_release(app, &bgk->moms);

if (bgk->normNu) {
gkyl_array_release(bgk->norm_nu);
gkyl_array_release(bgk->nu_init);
gkyl_spitzer_coll_freq_release(bgk->spitzer_calc);
}

gkyl_proj_maxwellian_on_basis_release(bgk->proj_max);
if (bgk->model_id == GKYL_MODEL_SR){
gkyl_proj_mj_on_basis_release(bgk->proj_mj);
gkyl_correct_mj_release(bgk->corr_mj);
gkyl_mj_moments_release(bgk->mj_moms);
gkyl_array_release(bgk->n_stationary);
gkyl_array_release(bgk->vb);
gkyl_array_release(bgk->T_stationary);
}
else {
vm_species_moment_release(app, &bgk->moms);
gkyl_proj_maxwellian_on_basis_release(bgk->proj_max);
}
gkyl_bgk_collisions_release(bgk->up_bgk);
}
61 changes: 49 additions & 12 deletions apps/vm_species_moment.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,40 @@ vm_species_moment_init(struct gkyl_vlasov_app *app, struct vm_species *s,
assert(is_moment_name_valid(nm));

bool is_integrated = strcmp(nm, "Integrated") == 0;
sm->nm = nm;
sm->vdim = app->vdim;
int num_mom;
sm->is_sr_five_moments = strcmp("SRFiveMoments", nm) == 0;

if (s->model_id == GKYL_MODEL_SR) {
struct gkyl_mom_vlasov_sr_auxfields sr_inp = {.p_over_gamma = s->p_over_gamma,
.gamma = s->gamma, .gamma_inv = s->gamma_inv, .V_drift = s->V_drift,
.GammaV2 = s->GammaV2, .GammaV_inv = s->GammaV_inv};
sm->mcalc = gkyl_dg_updater_moment_new(&s->grid, &app->confBasis,
&app->basis, &app->local, &s->local_vel, s->model_id, &sr_inp,
nm, is_integrated, s->info.mass, app->use_gpu);
if (sm->is_sr_five_moments){
sm->n = mkarr(false, app->confBasis.num_basis, app->local_ext.volume);
sm->vbi = mkarr(false, app->vdim*app->confBasis.num_basis, app->local_ext.volume);
sm->T = mkarr(false, app->confBasis.num_basis, app->local_ext.volume);
sm->mj_moms = gkyl_mj_moments_new(&s->grid, &app->confBasis,
&app->basis, &app->local, &s->local_vel, app->local.volume, app->local_ext.volume,
s->p_over_gamma, s->gamma, s->gamma_inv, false);
sm->num_basis = app->confBasis.num_basis;
num_mom = 2 + sm->vdim;
}
else {
struct gkyl_mom_vlasov_sr_auxfields sr_inp = {.p_over_gamma = s->p_over_gamma,
.gamma = s->gamma, .gamma_inv = s->gamma_inv, .V_drift = s->V_drift,
.GammaV2 = s->GammaV2, .GammaV_inv = s->GammaV_inv};
sm->mcalc = gkyl_dg_updater_moment_new(&s->grid, &app->confBasis,
&app->basis, &app->local, &s->local_vel, s->model_id, &sr_inp,
nm, is_integrated, s->info.mass, 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,
nm, is_integrated, s->info.mass, app->use_gpu);
nm, is_integrated, s->info.mass, app->use_gpu);
num_mom = gkyl_dg_updater_moment_num_mom(sm->mcalc);
}

int num_mom = gkyl_dg_updater_moment_num_mom(sm->mcalc);

if (is_integrated) {
sm->marr = mkarr(app->use_gpu, num_mom, app->local_ext.volume);
sm->marr_host = sm->marr;
Expand All @@ -48,16 +64,37 @@ vm_species_moment_calc(const struct vm_species_moment *sm,
const struct gkyl_range phase_rng, const struct gkyl_range conf_rng,
const struct gkyl_array *fin)
{
gkyl_dg_updater_moment_advance(sm->mcalc, &phase_rng, &conf_rng, fin, sm->marr);
if (sm->is_sr_five_moments) {
//gkyl_mj_moments_advance(sm->mj_moms, &phase_rng, &conf_rng, fin, sm->marr);
gkyl_mj_moments_advance(sm->mj_moms, fin, sm->n, sm->vbi, sm->T, &phase_rng, &conf_rng);

// Save the outputs to n vbi T:
gkyl_array_set_offset(sm->marr, 1.0, sm->n, 0*sm->num_basis);
gkyl_array_set_offset(sm->marr, 1.0, sm->vbi, 1*sm->num_basis);
gkyl_array_set_offset(sm->marr, 1.0, sm->T, (1 + sm->vdim)*sm->num_basis);
}
else {
gkyl_dg_updater_moment_advance(sm->mcalc, &phase_rng, &conf_rng, fin, sm->marr);
}
}

// release memory for moment data object
void
vm_species_moment_release(const struct gkyl_vlasov_app *app, const struct vm_species_moment *sm)
{
if (app->use_gpu)
if (app->use_gpu) {
gkyl_array_release(sm->marr_host);
}

gkyl_dg_updater_moment_release(sm->mcalc);
gkyl_array_release(sm->marr);

if(sm->is_sr_five_moments) {
gkyl_mj_moments_release(sm->mj_moms);
gkyl_array_release(sm->n);
gkyl_array_release(sm->vbi);
gkyl_array_release(sm->T);
}
else {
gkyl_dg_updater_moment_release(sm->mcalc);
}
}
Loading
Loading