Skip to content

Commit

Permalink
Merge pull request #436 from ammarhakim/moment_source_rewrite_braginskii
Browse files Browse the repository at this point in the history
Adding back in all the Braginskii work
  • Loading branch information
JonathanGorard authored Jul 29, 2024
2 parents 829d9fe + 535311f commit 5074fd1
Show file tree
Hide file tree
Showing 16 changed files with 1,994 additions and 24 deletions.
5 changes: 5 additions & 0 deletions apps/gkyl_moment.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <gkyl_app.h>
#include <gkyl_comm.h>
#include <gkyl_moment_braginskii.h>
#include <gkyl_mp_scheme.h>
#include <gkyl_util.h>
#include <gkyl_wave_prop.h>
Expand All @@ -18,6 +19,7 @@ struct gkyl_moment_species {
enum gkyl_wave_limiter limiter; // limiter to use
enum gkyl_wave_split_type split_type; // edge splitting to use

enum gkyl_braginskii_type type_brag; // which Braginskii equations
bool has_grad_closure; // has gradient-based closure (only for 10 moment)

bool has_friction; // Run with frictional sources.
Expand Down Expand Up @@ -159,6 +161,9 @@ struct gkyl_moment {

bool has_nT_sources;

bool has_braginskii; // has Braginskii transport
double coll_fac; // multiplicative collisionality factor for Braginskii

// this should not be set by typical user-facing code but only by
// higher-level drivers
bool has_low_inp; // should one use low-level inputs?
Expand Down
22 changes: 16 additions & 6 deletions apps/gkyl_moment_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <gkyl_kep_scheme.h>
#include <gkyl_mhd_src.h>
#include <gkyl_moment.h>
#include <gkyl_moment_braginskii.h>
#include <gkyl_moment_em_coupling.h>
#include <gkyl_mp_scheme.h>
#include <gkyl_range.h>
Expand All @@ -34,6 +35,8 @@
#include <gkyl_wave_geom.h>
#include <gkyl_wave_prop.h>
#include <gkyl_wv_apply_bc.h>
#include <gkyl_wv_euler.h>
#include <gkyl_wv_iso_euler.h>
#include <gkyl_wv_maxwell.h>
#include <gkyl_wv_mhd.h>
#include <gkyl_wv_ten_moment.h>
Expand All @@ -46,6 +49,7 @@ struct moment_species {

double k0; // closure parameter (default is 0.0, used by 10 moment)
bool has_grad_closure; // has gradient-based closure (only for 10 moment)
enum gkyl_braginskii_type type_brag; // which Braginskii equations

bool has_friction; // Run with frictional sources.
bool use_explicit_friction; // Use an explicit (SSP-RK3) solver for integrating frictional sources.
Expand Down Expand Up @@ -178,16 +182,19 @@ struct moment_field {

// Source data
struct moment_coupling {
// grid for braginskii variables (braginskii variables located at cell nodes)
// grid for braginskii variables (braginskii variables located at cell nodes)
struct gkyl_rect_grid non_ideal_grid;
// local, local-ext ranges for braginskii variables (loop over nodes)
// local, local-ext ranges for braginskii variables (loop over nodes)
struct gkyl_range non_ideal_local, non_ideal_local_ext;

// Gradient-based closure solver (if present)
gkyl_ten_moment_grad_closure *grad_closure_slvr[GKYL_MAX_SPECIES];
// array for stable time-step from non-ideal terms
// Gradient-based closure solver (if present)
struct gkyl_ten_moment_grad_closure *grad_closure_slvr[GKYL_MAX_SPECIES];
// Braginskii solver (if present)
struct gkyl_moment_braginskii *brag_slvr;

// array for stable time-step from non-ideal terms
struct gkyl_array *non_ideal_cflrate[GKYL_MAX_SPECIES];
// array for non-ideal variables (heat-flux tensor)
// array for non-ideal variables (heat-flux tensor)
struct gkyl_array *non_ideal_vars[GKYL_MAX_SPECIES];
// array for storing RHS of each species from non-ideal term updates (gradient-based closure)
struct gkyl_array *pr_rhs[GKYL_MAX_SPECIES];
Expand Down Expand Up @@ -215,6 +222,9 @@ struct gkyl_moment_app {
// should shock-hybrid scheme be used when using KEP?
bool use_hybrid_flux_kep;

bool has_braginskii; // has Braginskii transport
double coll_fac; // multiplicative collisionality factor for Braginskii

int num_periodic_dir; // number of periodic directions
int periodic_dirs[3]; // list of periodic directions
int nghost[3]; // number of ghost-cells in each direction
Expand Down
37 changes: 37 additions & 0 deletions apps/mom_coupling.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,36 @@ moment_coupling_init(const struct gkyl_moment_app *app, struct moment_coupling *
src->grad_closure_slvr[i] = gkyl_ten_moment_grad_closure_new(grad_closure_inp);
}
}

// check if braginskii terms are present
if (app->has_braginskii) {
struct gkyl_moment_braginskii_inp brag_inp = {
.grid = &app->grid,
.nfluids = app->num_species,
.epsilon0 = app->field.epsilon0,
// Check for multiplicative collisionality factor, default is 1.0
.coll_fac = app->coll_fac == 0 ? 1.0 : app->coll_fac,
};
for (int i=0; i<app->num_species; ++i) {
// Braginskii coefficients depend on pressure and coefficient to obtain
// pressure is different for different equation systems (gasGamma, vt, Tr(P))
double p_fac = 1.0;
if (app->species[i].eqn_type == GKYL_EQN_EULER) {
p_fac = gkyl_wv_euler_gas_gamma(app->species[i].equation);
}
else if (app->species[i].eqn_type == GKYL_EQN_ISO_EULER) {
p_fac = gkyl_wv_iso_euler_vt(app->species[i].equation);
}
brag_inp.param[i] = (struct gkyl_moment_braginskii_data) {
.type_eqn = app->species[i].eqn_type,
.type_brag = app->species[i].type_brag,
.charge = app->species[i].charge,
.mass = app->species[i].mass,
.p_fac = p_fac,
};
}
src->brag_slvr = gkyl_moment_braginskii_new(brag_inp);
}
}

// update sources: 'nstrang' is 0 for the first Strang step and 1 for
Expand Down Expand Up @@ -165,6 +195,13 @@ moment_coupling_update(gkyl_moment_app *app, struct moment_coupling *src,
}
}

if (app->has_braginskii) {
gkyl_moment_braginskii_advance(src->brag_slvr,
src->non_ideal_local_ext, app->local,
fluids, app->field.f[sidx[nstrang]],
src->non_ideal_cflrate, src->non_ideal_vars, src->pr_rhs);
}

if (app->field.proj_app_current)
gkyl_fv_proj_advance(app->field.proj_app_current, tcurr, &app->local, app->field.app_current);
if ((app->field.proj_app_current) && (app->field.use_explicit_em_coupling)){
Expand Down
4 changes: 4 additions & 0 deletions apps/mom_species.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ moment_species_init(const struct gkyl_moment *mom, const struct gkyl_moment_spec
sp->k0 = mom_sp->equation->type == GKYL_EQN_TEN_MOMENT ? gkyl_wv_ten_moment_k0(mom_sp->equation) : 0.0;
// check if we are running with gradient-based closure
sp->has_grad_closure = mom_sp->has_grad_closure == 0 ? 0 : mom_sp->has_grad_closure;
// check if we are running with Braginskii transport and fetch Braginskii type
if (app->has_braginskii) {
sp->type_brag = mom_sp->type_brag;
}

if (mom_sp->has_friction) {
sp->has_friction = true;
Expand Down
4 changes: 4 additions & 0 deletions apps/moment.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ gkyl_moment_app_new(struct gkyl_moment *mom)
moment_field_init(mom, &mom->field, app, &app->field);
}

// Are we running with Braginskii transport?
app->has_braginskii = mom->has_braginskii;
app->coll_fac = mom->coll_fac;

int ns = app->num_species = mom->num_species;
// allocate space to store species objects
app->species = ns>0 ? gkyl_malloc(sizeof(struct moment_species[ns])) : 0;
Expand Down
Loading

0 comments on commit 5074fd1

Please sign in to comment.