diff --git a/apps/gkyl_vlasov_priv.h b/apps/gkyl_vlasov_priv.h index 5e48ab492..66534db05 100644 --- a/apps/gkyl_vlasov_priv.h +++ b/apps/gkyl_vlasov_priv.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -51,6 +53,7 @@ #include #include #include +#include #include #include #include @@ -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 }; @@ -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 @@ -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) }; diff --git a/apps/vm_species_bgk.c b/apps/vm_species_bgk.c index 55442f5d5..910e28c94 100644 --- a/apps/vm_species_bgk.c +++ b/apps/vm_species_bgk.c @@ -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) @@ -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); } @@ -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, + // &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); @@ -100,7 +135,6 @@ 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); @@ -108,6 +142,17 @@ vm_species_bgk_release(const struct gkyl_vlasov_app *app, const struct vm_bgk_co 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); } diff --git a/apps/vm_species_moment.c b/apps/vm_species_moment.c index 2136f000d..ec029431b 100644 --- a/apps/vm_species_moment.c +++ b/apps/vm_species_moment.c @@ -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; @@ -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); + } } diff --git a/regression/rt_neut_sr_bgk_sod_shock_1x1v_p2.c b/regression/rt_neut_sr_bgk_sod_shock_1x1v_p2.c new file mode 100644 index 000000000..965af4143 --- /dev/null +++ b/regression/rt_neut_sr_bgk_sod_shock_1x1v_p2.c @@ -0,0 +1,184 @@ +#include +#include +#include + +#include +#include +#include + +struct free_stream_ctx { + double charge; // charge + double mass; // mass + double vt; // thermal velocity + double Lx; // size of the box +}; + +static inline double sq(double x) { return x*x; } + +static inline double +maxwellian(double n, double v, double u, double vth) +{ + double v2 = (v - u)*(v - u); + return n/sqrt(2*M_PI*vth*vth)*exp(-v2/(2*vth*vth)); +} + +static inline double +maxwelljuttner1D(double n, double px, double ux, double T) +{ + + // Set the normalization + double K1; + if (T == 1.0){ + K1 = 0.601907230197235; + } else { + K1 = 0.495079105512939; + } + + // All constants = 1 (c, m0, kb) + double gamma = 1.0/sqrt(1.0 - ux*ux); + return n/(2*K1)*exp(-(gamma/T)*(sqrt(1 + px*px) - ux*px )); +} + +void +evalDistFunc(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +{ + struct free_stream_ctx *app = ctx; + double x = xn[0], v = xn[1]; + if (x<0.5) + fout[0] = maxwelljuttner1D(1.0, v, 0.0, 1.0); //maxwellian(1.0, v, 0.0, 1.0); + else + fout[0] = maxwelljuttner1D(0.125, v, 0.0, sqrt(0.1/0.125)); //maxwellian(0.125, v, 0.0, sqrt(0.1/0.125)); +} + +void +evalNu(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +{ + struct free_stream_ctx *app = ctx; + double x = xn[0], v = xn[1]; + fout[0] = 100.0; +} + +struct free_stream_ctx +create_ctx(void) +{ + struct free_stream_ctx ctx = { + .mass = 1.0, + .charge = 1.0, + .vt = 1.0, + .Lx = 1.0, + }; + return ctx; +} + +int +main(int argc, char **argv) +{ + struct gkyl_app_args app_args = parse_app_args(argc, argv); + + int NX = APP_ARGS_CHOOSE(app_args.xcells[0], 128); + int NV = APP_ARGS_CHOOSE(app_args.vcells[0], 32); //16 + + if (app_args.trace_mem) { + gkyl_cu_dev_mem_debug_set(true); + gkyl_mem_debug_set(true); + } + struct free_stream_ctx ctx = create_ctx(); // context for init functions + + // electrons + struct gkyl_vlasov_species neut = { + .name = "neut", + .model_id = GKYL_MODEL_SR, + .charge = ctx.charge, .mass = ctx.mass, + .lower = { -10.0*ctx.vt}, + .upper = { 10.0*ctx.vt}, + .cells = { NV }, + + .ctx = &ctx, + .init = evalDistFunc, + + .collisions = { + .collision_id = GKYL_BGK_COLLISIONS, + + .ctx = &ctx, + .self_nu = evalNu, + }, + + //.num_diag_moments = 2, + //.diag_moments = { "M0", "M1i" }, //, "Pressure" + .num_diag_moments = 1, + .diag_moments = { "SRFiveMoments" }, + }; + + // VM app + struct gkyl_vm vm = { + .name = "neut_sr_bgk_sod_shock_1x1v_p2", + + .cdim = 1, .vdim = 1, + .lower = { 0.0 }, + .upper = { ctx.Lx }, + .cells = { NX }, + .poly_order = 2, + .basis_type = app_args.basis_type, + + .num_periodic_dir = 0, + .periodic_dirs = { }, + + .num_species = 1, + .species = { neut }, + .skip_field = true, + + .use_gpu = app_args.use_gpu, + }; + + // create app object + gkyl_vlasov_app *app = gkyl_vlasov_app_new(&vm); + + // start, end and initial time-step + double tcurr = 0.0, tend = 0.1; + double dt = tend-tcurr; + + // initialize simulation + gkyl_vlasov_app_apply_ic(app, tcurr); + + gkyl_vlasov_app_write(app, tcurr, 0); + gkyl_vlasov_app_calc_mom(app); gkyl_vlasov_app_write_mom(app, tcurr, 0); + + long step = 1, num_steps = app_args.num_steps; + while ((tcurr < tend) && (step <= num_steps)) { + printf("Taking time-step at t = %g ...", tcurr); + struct gkyl_update_status status = gkyl_vlasov_update(app, dt); + printf(" dt = %g\n", status.dt_actual); + + if (!status.success) { + printf("** Update method failed! Aborting simulation ....\n"); + break; + } + tcurr += status.dt_actual; + dt = status.dt_suggested; + step += 1; + } + + gkyl_vlasov_app_write(app, tcurr, 1); + gkyl_vlasov_app_calc_mom(app); gkyl_vlasov_app_write_mom(app, tcurr, 1); + gkyl_vlasov_app_stat_write(app); + + // fetch simulation statistics + struct gkyl_vlasov_stat stat = gkyl_vlasov_app_stat(app); + + // simulation complete, free app + gkyl_vlasov_app_release(app); + + printf("\n"); + printf("Number of update calls %ld\n", stat.nup); + printf("Number of forward-Euler calls %ld\n", stat.nfeuler); + printf("Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); + if (stat.nstage_2_fail > 0) { + printf("Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); + printf("Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); + } + printf("Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); + printf("Species RHS calc took %g secs\n", stat.species_rhs_tm); + printf("Updates took %g secs\n", stat.total_tm); + + return 0; +} diff --git a/regression/rt_vlasov_bgk_sr_relax_1x1v_p2.c b/regression/rt_vlasov_bgk_sr_relax_1x1v_p2.c new file mode 100644 index 000000000..1f0b7019d --- /dev/null +++ b/regression/rt_vlasov_bgk_sr_relax_1x1v_p2.c @@ -0,0 +1,189 @@ +#include +#include +#include + +#include +#include +#include + +struct free_stream_ctx { + double charge; // charge + double mass; // mass + double vt; // thermal velocity + double Lx; // size of the box +}; + +static inline double sq(double x) { return x*x; } + +static inline double +bump_maxwellian(double n, double vx, double ux, double vt, double bA, double bU, double bS, double bVt) +{ + double v2 = (vx-ux)*(vx-ux); + double bv2 = (vx-bU)*(vx-bU); + return n/sqrt(2*M_PI*vt*vt)*exp(-v2/(2*vt*vt)) + n/sqrt(2*M_PI*bVt*bVt)*exp(-bv2/(2*bVt*bVt))*(bA*bA)/(bv2 + bS*bS); +} + +void +evalDistFuncSquare(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +{ + struct free_stream_ctx *app = ctx; + double x = xn[0], v = xn[1]; + if(v>-1.0 && v<1.0) { + fout[0] = 0.5; + } else { + fout[0] = 0.0; + } +} + +void +evalDistFuncBump(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +{ + struct free_stream_ctx *app = ctx; + double x = xn[0], v = xn[1]; + fout[0] = bump_maxwellian(1.0, v, 0.0, 1.0/3.0, sqrt(0.1), 4*sqrt(0.25/3), 0.12, 1.0); +} + +void +evalNu(double t, const double * GKYL_RESTRICT xn, double* GKYL_RESTRICT fout, void *ctx) +{ + fout[0] = 0.01; +} + +struct free_stream_ctx +create_ctx(void) +{ + struct free_stream_ctx ctx = { + .mass = 1.0, + .charge = 0.0, + .vt = 1.0/3.0, + .Lx = 1.0 + }; + return ctx; +} + +int +main(int argc, char **argv) +{ + struct gkyl_app_args app_args = parse_app_args(argc, argv); + + if (app_args.trace_mem) { + gkyl_cu_dev_mem_debug_set(true); + gkyl_mem_debug_set(true); + } + struct free_stream_ctx ctx = create_ctx(); // context for init functions + + // electrons + struct gkyl_vlasov_species square = { + .name = "square", + .model_id = GKYL_MODEL_SR, + .charge = ctx.charge, .mass = ctx.mass, + .lower = { -8.0 * ctx.vt}, + .upper = { 8.0 * ctx.vt}, + .cells = { 48 }, + + .ctx = &ctx, + .init = evalDistFuncSquare, + + .collisions = { + .collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + }, + + //.num_diag_moments = 3, + //.diag_moments = { "M0", "M1i", "M2" }, + }; + + struct gkyl_vlasov_species bump = { + .name = "bump", + .model_id = GKYL_MODEL_SR, + .charge = ctx.charge, .mass = ctx.mass, + .lower = { -8.0 * ctx.vt}, + .upper = { 8.0 * ctx.vt}, + .cells = { 48 }, + + .ctx = &ctx, + .init = evalDistFuncBump, + + .collisions = { + .collision_id = GKYL_BGK_COLLISIONS, + .self_nu = evalNu, + }, + + //.num_diag_moments = 3, + //.diag_moments = { "M0", "M1i", "M2" }, + }; + + // VM app + struct gkyl_vm vm = { + .name = "vlasov_bgk_sr_relax_1x1v_p2", + + .cdim = 1, .vdim = 1, + .lower = { 0.0 }, + .upper = { ctx.Lx }, + .cells = { 2 }, + .poly_order = 2, + .basis_type = app_args.basis_type, + .cfl_frac = 0.6, + + .num_periodic_dir = 1, + .periodic_dirs = { 0 }, + + .num_species = 2, + .species = { square, bump }, + .skip_field = true, + + .use_gpu = app_args.use_gpu, + }; + + // create app object + gkyl_vlasov_app *app = gkyl_vlasov_app_new(&vm); + + // start, end and initial time-step + double tcurr = 0.0, tend = 500.0; + double dt = tend-tcurr; + + // initialize simulation + gkyl_vlasov_app_apply_ic(app, tcurr); + + gkyl_vlasov_app_write(app, tcurr, 0); + //gkyl_vlasov_app_calc_mom(app); gkyl_vlasov_app_write_mom(app, tcurr, 0); + + long step = 1, num_steps = app_args.num_steps; + while ((tcurr < tend) && (step <= num_steps)) { + printf("Taking time-step at t = %g ...", tcurr); + struct gkyl_update_status status = gkyl_vlasov_update(app, dt); + printf(" dt = %g\n", status.dt_actual); + + if (!status.success) { + printf("** Update method failed! Aborting simulation ....\n"); + break; + } + tcurr += status.dt_actual; + dt = status.dt_suggested; + step += 1; + } + + gkyl_vlasov_app_write(app, tcurr, 1); + //gkyl_vlasov_app_calc_mom(app); gkyl_vlasov_app_write_mom(app, tcurr, 1); + gkyl_vlasov_app_stat_write(app); + + // fetch simulation statistics + struct gkyl_vlasov_stat stat = gkyl_vlasov_app_stat(app); + + // simulation complete, free app + gkyl_vlasov_app_release(app); + + printf("\n"); + printf("Number of update calls %ld\n", stat.nup); + printf("Number of forward-Euler calls %ld\n", stat.nfeuler); + printf("Number of RK stage-2 failures %ld\n", stat.nstage_2_fail); + if (stat.nstage_2_fail > 0) { + printf("Max rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[1]); + printf("Min rel dt diff for RK stage-2 failures %g\n", stat.stage_2_dt_diff[0]); + } + printf("Number of RK stage-3 failures %ld\n", stat.nstage_3_fail); + printf("Species RHS calc took %g secs\n", stat.species_rhs_tm); + printf("Updates took %g secs\n", stat.total_tm); + + return 0; +} diff --git a/unit/ctest_bgk_sr.c b/unit/ctest_bgk_sr.c deleted file mode 100644 index 2c06a4cb3..000000000 --- a/unit/ctest_bgk_sr.c +++ /dev/null @@ -1,339 +0,0 @@ -#include "gkyl_array.h" -#include "gkyl_util.h" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// allocate array (filled with zeros) -static struct gkyl_array * -mkarr(long nc, long size) -{ - struct gkyl_array *a = gkyl_array_new(GKYL_DOUBLE, nc, size); - return a; -} - -struct skin_ghost_ranges -{ - struct gkyl_range lower_skin[GKYL_MAX_DIM]; - struct gkyl_range lower_ghost[GKYL_MAX_DIM]; - - struct gkyl_range upper_skin[GKYL_MAX_DIM]; - struct gkyl_range upper_ghost[GKYL_MAX_DIM]; -}; - -// Create ghost and skin sub-ranges given a parent range -static void -skin_ghost_ranges_init(struct skin_ghost_ranges *sgr, - const struct gkyl_range *parent, const int *ghost) -{ - int ndim = parent->ndim; - - for (int d = 0; d < ndim; ++d){ - gkyl_skin_ghost_ranges(&sgr->lower_skin[d], &sgr->lower_ghost[d], - d, GKYL_LOWER_EDGE, parent, ghost); - gkyl_skin_ghost_ranges(&sgr->upper_skin[d], &sgr->upper_ghost[d], - d, GKYL_UPPER_EDGE, parent, ghost); - } -} - -void -eval_M0(double t, const double *xn, double *restrict fout, void *ctx) -{ - double x = xn[0]; - fout[0] = 1.0; -} - -void -eval_M1i_1v(double t, const double *xn, double *restrict fout, void *ctx) -{ - double x = xn[0]; - fout[0] = 0.5; // 0.5; -} - -void -eval_M2_1v(double t, const double *xn, double *restrict fout, void *ctx) -{ - double T = 1.0; - double x = xn[0]; - fout[0] = T; -} - - -// waterbag distribution -void -evalFunc(double t, const double *xn, double *restrict fout, void *ctx) -{ - double x = xn[0], vx = xn[1]; - fout[0] = 0.0; - if (vx < 2.0 && vx > 0.0) - fout[0] = 1.0; -} - -// Collision distribution all phase space -void -evalFunc_nu(double t, const double *xn, double *restrict fout, void *ctx) -{ - double x = xn[0], vx = xn[1]; - // calculate nu, assumed constant - double dt = 0.01; - double nu_all = 1.0; - double nudt = nu_all * dt; - fout[0] = nudt; -} - -// Collision conf space -void -evalFunc_nu_conf(double t, const double *xn, double *restrict fout, void *ctx) -{ - double x = xn[0]; - // calculate nu, assumed constant - double dt = 0.01; - double nu_all = 1.0; - double nudt = nu_all * dt; - fout[0] = nudt; -} - -void -test_1x1v(int poly_order) -{ - double lower[] = {0.1, -10.0}, upper[] = {1.0, 10.0}; - int cells[] = {2, 320}; // 1000 - int vdim = 1, cdim = 1; - int ndim = cdim + vdim; - - double confLower[] = {lower[0]}, confUpper[] = {upper[0]}; - double velLower[] = {lower[1]}, velUpper[] = {upper[1]}; - int confCells[] = {cells[0]}; - int velCells[] = {cells[1]}; - - // grids - struct gkyl_rect_grid grid; - gkyl_rect_grid_init(&grid, ndim, lower, upper, cells); - struct gkyl_rect_grid confGrid; - gkyl_rect_grid_init(&confGrid, cdim, confLower, confUpper, confCells); - struct gkyl_rect_grid vel_grid; - gkyl_rect_grid_init(&vel_grid, vdim, velLower, velUpper, velCells); - - // velocity range - int velGhost[] = {0}; - struct gkyl_range velLocal, velLocal_ext; - gkyl_create_grid_ranges(&vel_grid, velGhost, &velLocal_ext, &velLocal); - - // basis functions - struct gkyl_basis basis, confBasis, velBasis; - gkyl_cart_modal_serendip(&basis, ndim, poly_order); - gkyl_cart_modal_serendip(&confBasis, cdim, poly_order); - gkyl_cart_modal_serendip(&velBasis, vdim, poly_order); - - int confGhost[] = {1}; - struct gkyl_range confLocal, confLocal_ext; - gkyl_create_grid_ranges(&confGrid, confGhost, &confLocal_ext, &confLocal); - struct skin_ghost_ranges confSkin_ghost; - skin_ghost_ranges_init(&confSkin_ghost, &confLocal_ext, confGhost); - - int ghost[] = {confGhost[0], 0}; - struct gkyl_range local, local_ext; - gkyl_create_grid_ranges(&grid, ghost, &local_ext, &local); - struct skin_ghost_ranges skin_ghost; - skin_ghost_ranges_init(&skin_ghost, &local_ext, ghost); - - // create moment arrays - struct gkyl_array *m0, *m1i, *m2; - m0 = mkarr(confBasis.num_basis, confLocal_ext.volume); - m1i = mkarr(vdim * confBasis.num_basis, confLocal_ext.volume); - m2 = mkarr(confBasis.num_basis, confLocal_ext.volume); - struct gkyl_array *m0_original, *m1i_original, *m2_original; - m0_original = mkarr(confBasis.num_basis, confLocal_ext.volume); - m1i_original = mkarr(vdim * confBasis.num_basis, confLocal_ext.volume); - m2_original = mkarr(confBasis.num_basis, confLocal_ext.volume); - - gkyl_proj_on_basis *proj_m0 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, 1, eval_M0, NULL); - gkyl_proj_on_basis *proj_m1i = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, vdim, eval_M1i_1v, NULL); - gkyl_proj_on_basis *proj_m2 = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, 1, eval_M2_1v, NULL); - - gkyl_proj_on_basis_advance(proj_m0, 0.0, &confLocal, m0); - gkyl_proj_on_basis_advance(proj_m1i, 0.0, &confLocal, m1i); - gkyl_proj_on_basis_advance(proj_m2, 0.0, &confLocal, m2); - - // build the p_over_gamma - struct gkyl_array *p_over_gamma; - p_over_gamma = mkarr(vdim * velBasis.num_basis, velLocal.volume); - - // build gamma - struct gkyl_array *gamma; - gamma = mkarr(velBasis.num_basis, velLocal.volume); - - // build gamma_inv - struct gkyl_array *gamma_inv; - gamma_inv = mkarr(velBasis.num_basis, velLocal.volume); - - // Make GammaV2, GammaV, GammaV_inv - gkyl_calc_sr_vars_init_p_vars(&vel_grid, &velBasis, &velLocal, - p_over_gamma, gamma, gamma_inv); - - // create distribution function array - struct gkyl_array *distf; - distf = mkarr(basis.num_basis, local_ext.volume); - struct gkyl_array *distf_mj; - distf_mj = mkarr(basis.num_basis, local_ext.volume); - struct gkyl_array *bgk_out; - bgk_out = mkarr(basis.num_basis, local_ext.volume); - struct gkyl_array *nudt; - nudt = mkarr(basis.num_basis, local_ext.volume); - struct gkyl_array *nudt_conf; - nudt_conf = mkarr(confBasis.num_basis, confLocal_ext.volume); - struct gkyl_array *cflfreq; - cflfreq = mkarr(basis.num_basis, local_ext.volume); - - // projection updater to compute mj - gkyl_proj_mj_on_basis *proj_mj = gkyl_proj_mj_on_basis_new(&grid, - &confBasis, &basis, poly_order + 1); - - gkyl_proj_on_basis *projDistf = gkyl_proj_on_basis_new(&grid, &basis, - poly_order + 1, 1, evalFunc, NULL); - - gkyl_proj_on_basis *projnu = gkyl_proj_on_basis_new(&grid, &basis, - poly_order + 1, 1, evalFunc_nu, NULL); - - gkyl_proj_on_basis *projnu_conf = gkyl_proj_on_basis_new(&confGrid, &confBasis, - poly_order + 1, 1, evalFunc_nu_conf, NULL); - - // create the bgk operator structure - gkyl_bgk_collisions *bgk_obj = gkyl_bgk_collisions_new(&confBasis, &basis, false); - - // create the waterbag distribution for distf - gkyl_proj_on_basis_advance(projDistf, 0.0, &local, distf); - - // Create correction object and moments object - gkyl_mj_moments *mj_moms = gkyl_mj_moments_new(&grid, &confBasis, - &basis, &confLocal, &velLocal, confLocal.volume, confLocal_ext.volume, - p_over_gamma, gamma, gamma_inv, false); - gkyl_correct_mj *corr_mj = gkyl_correct_mj_new(&grid, &confBasis, - &basis, &confLocal, &confLocal_ext, &velLocal, p_over_gamma, gamma, gamma_inv, false); - - // Compute the original moments (of f_waterbag), save them for later comparison - gkyl_mj_moments_advance(mj_moms, distf, m0, m1i, m2, &local, &confLocal); - gkyl_array_clear(m0_original, 0.0); - gkyl_array_clear(m1i_original, 0.0); - gkyl_array_clear(m2_original, 0.0); - gkyl_array_accumulate(m0_original, 1.0, m0); - gkyl_array_accumulate(m1i_original, 1.0, m1i); - gkyl_array_accumulate(m2_original, 1.0, m2); - - // create the collision frequency matrix - gkyl_proj_on_basis_advance(projnu, 0.0, &local, nudt); - - // create the collision frequency matrix in conf spade - gkyl_proj_on_basis_advance(projnu_conf, 0.0, &confLocal, nudt_conf); - - // timeloop evolving partial_t(f) = -nu(f-f^mj) - for (int i = 0; i < 301; ++i) - { - - // write distribution function to file - char fname[1024]; - if (i == 300 || i == 100 || i == 0) - { - sprintf(fname, "ctest_bgk_sr_1x1v_p%d_time_%03d.gkyl", poly_order, i); - gkyl_grid_sub_array_write(&grid, &local, distf, fname); - } - - // calculate the moments of the dist (n, vb, T -> m0, m1i, m2) - gkyl_mj_moments_advance(mj_moms, distf, m0, m1i, m2, &local, &confLocal); - - // Update the dist_mj using the moments - gkyl_proj_mj_on_basis_fluid_stationary_frame_mom(proj_mj, &local, &confLocal, m0, m1i, m2, distf_mj); - - // correct the mj distribution m0 (n) Moment - // gkyl_correct_mj_fix_m0(corr_mj, p_over_gamma, distf_mj, m0, m1i, &local, &confLocal); - - // correct all moments - gkyl_correct_mj_fix(corr_mj, distf_mj, m0, m1i, m2, &local, &confLocal, poly_order); - - // calculate nu*f^mj, - // gkyl_dg_mul_op_range(basis, 0, distf_mj, 0, nudt, 0, distf_mj, &local); - gkyl_dg_mul_conf_phase_op_range(&confBasis, &basis, - distf_mj, nudt_conf, distf_mj, &confLocal, &local); - - // calculate the BGK contribution - gkyl_bgk_collisions_advance(bgk_obj, - &confLocal, &local, - nudt_conf, distf_mj, distf, - bgk_out, cflfreq); - - // update f with the BGK operation (Forward Euler update) - // f^j+1 = f^j + out; out = -dt*nu*(f - f^mj) - struct gkyl_range_iter piter; - gkyl_range_iter_init(&piter, &local); - while (gkyl_range_iter_next(&piter)){ - long ploc = gkyl_range_idx(&local, piter.idx); - double *out_d = gkyl_array_fetch(bgk_out, ploc); - double *fv = gkyl_array_fetch(distf, ploc); - - // Add out_d to the evolving distribution function - array_acc1(basis.num_basis, fv, 1., out_d); - } - } - gkyl_correct_mj_release(corr_mj); - gkyl_mj_moments_release(mj_moms); - - // values to compare at index (1, 17) [remember, lower-left index is (1,1)] - double p2_vals[] = {0.1656333899823638, -1.57246950256639e-17, - 0.146961492792848, -9.802279035466299e-18, 4.479617143823178e-17, - 0.05558727357585599, 4.814166767741567e-17, -1.575372718994952e-18}; - - const double *fv = gkyl_array_cfetch(distf, gkyl_range_idx(&local_ext, (int[2]){1, 16})); - - if (poly_order == 2) - for (int i = 0; i < basis.num_basis; ++i) - TEST_CHECK(gkyl_compare_double(p2_vals[i], fv[i], 1e-12)); - - - // release memory for moment data object - gkyl_array_release(m0); - gkyl_array_release(m1i); - gkyl_array_release(m2); - gkyl_array_release(distf); - gkyl_array_release(distf_mj); - gkyl_array_release(bgk_out); - gkyl_array_release(nudt); - gkyl_array_release(nudt_conf); - gkyl_array_release(cflfreq); - gkyl_proj_mj_on_basis_release(proj_mj); - gkyl_proj_on_basis_release(projDistf); - gkyl_proj_on_basis_release(projnu); - gkyl_proj_on_basis_release(projnu_conf); - gkyl_proj_on_basis_release(proj_m0); - gkyl_proj_on_basis_release(proj_m1i); - gkyl_proj_on_basis_release(proj_m2); - gkyl_array_release(p_over_gamma); - gkyl_array_release(gamma); - gkyl_array_release(gamma_inv); - gkyl_bgk_collisions_release(bgk_obj); -} - -// special note, the p1 basis does not function -void test_1x1v_p2() { test_1x1v(2); } - -TEST_LIST = { - {"test_1x1v_p2", test_1x1v_p2}, - {NULL, NULL}, -}; diff --git a/unit/ctest_proj_mj_on_basis.c b/unit/ctest_proj_mj_on_basis.c index f6e377ffc..c2db738fe 100644 --- a/unit/ctest_proj_mj_on_basis.c +++ b/unit/ctest_proj_mj_on_basis.c @@ -266,7 +266,7 @@ test_1x1v_no_drift(int poly_order) // correct the mj distribution m0 Moment gkyl_correct_mj *corr_mj = gkyl_correct_mj_new(&grid, &confBasis, &basis, &confLocal, &confLocal_ext, &velLocal, p_over_gamma, gamma, gamma_inv, false); - gkyl_correct_mj_fix_m0(corr_mj, distf, m0, m1i, &local, &confLocal); + gkyl_correct_mj_fix_n_stationary(corr_mj, distf, m0, m1i, &local, &confLocal); // values to compare at index (1, 17) [remember, lower-left index is (1,1)] double p1_vals[] = {5.3918752026566863e-01, -1.0910243387206232e-17, -6.0196985297046972e-02, @@ -397,7 +397,7 @@ test_1x1v(int poly_order) // correct the mj distribution m0 Moment gkyl_correct_mj *corr_mj = gkyl_correct_mj_new(&grid, &confBasis, &basis, &confLocal, &confLocal_ext, &velLocal, p_over_gamma, gamma, gamma_inv, false); - gkyl_correct_mj_fix_m0(corr_mj, distf, m0, m1i, &local, &confLocal); + gkyl_correct_mj_fix_n_stationary(corr_mj, distf, m0, m1i, &local, &confLocal); // test accuracy of the projection: gkyl_mj_moments *mj_moms = gkyl_mj_moments_new(&grid, &confBasis, @@ -530,7 +530,7 @@ test_1x2v(int poly_order) // correct the mj distribution m0 Moment gkyl_correct_mj *corr_mj = gkyl_correct_mj_new(&grid, &confBasis, &basis, &confLocal, &confLocal_ext, &velLocal, p_over_gamma, gamma, gamma_inv, false); - gkyl_correct_mj_fix_m0(corr_mj, distf, m0, m1i, &local, &confLocal); + gkyl_correct_mj_fix_n_stationary(corr_mj, distf, m0, m1i, &local, &confLocal); // values to compare at index (1, 9, 9) [remember, lower-left index is (1,1,1)] double p2_vals[] = {1.7020667884226476e-01, -7.7674914557148726e-18, -3.9516229859383111e-03, @@ -660,7 +660,7 @@ test_1x3v(int poly_order) // correct the mj distribution m0 Moment gkyl_correct_mj *corr_mj = gkyl_correct_mj_new(&grid, &confBasis, &basis, &confLocal, &confLocal_ext, &velLocal, p_over_gamma, gamma, gamma_inv, false); - gkyl_correct_mj_fix_m0(corr_mj, distf, m0, m1i, &local, &confLocal); + gkyl_correct_mj_fix_n_stationary(corr_mj, distf, m0, m1i, &local, &confLocal); // values to compare at index (1, 9, 9, 9) [remember, lower-left index is (1,1,1,1)] double p2_vals[] = {1.6326923473662415e-02, -2.7779798362812092e-19, -5.7251397678571113e-06, diff --git a/zero/correct_mj.c b/zero/correct_mj.c index 2ba556cae..0a10664f5 100644 --- a/zero/correct_mj.c +++ b/zero/correct_mj.c @@ -39,9 +39,9 @@ gkyl_correct_mj_new(const struct gkyl_rect_grid *grid, .GammaV2 = 0, .GammaV_inv = 0}; // updated moment calculator for sr N and N*vb moments - up->m0calc = gkyl_dg_updater_moment_new(grid, conf_basis, + up->ncalc = gkyl_dg_updater_moment_new(grid, conf_basis, phase_basis, conf_range, vel_range, GKYL_MODEL_SR, &sr_inp, "M0", 0, 1, use_gpu); - up->m1icalc = gkyl_dg_updater_moment_new(grid, conf_basis, + up->vbicalc = gkyl_dg_updater_moment_new(grid, conf_basis, phase_basis, conf_range, vel_range, GKYL_MODEL_SR, &sr_inp, "M1i", 0, 1, use_gpu); up->num_ratio = gkyl_array_new(GKYL_DOUBLE, conf_basis->num_basis, conf_local_ext_ncells); @@ -53,18 +53,18 @@ gkyl_correct_mj_new(const struct gkyl_rect_grid *grid, up->mem = gkyl_dg_bin_op_mem_new(conf_local_ncells, conf_basis->num_basis); // Moment memory - up->m0 = gkyl_array_new(GKYL_DOUBLE, conf_basis->num_basis, conf_local_ext_ncells); - up->m1i = gkyl_array_new(GKYL_DOUBLE, vdim * conf_basis->num_basis, conf_local_ext_ncells); - up->m2 = gkyl_array_new(GKYL_DOUBLE, conf_basis->num_basis, conf_local_ext_ncells); + up->n_stationary = gkyl_array_new(GKYL_DOUBLE, conf_basis->num_basis, conf_local_ext_ncells); + up->vbi = gkyl_array_new(GKYL_DOUBLE, vdim * conf_basis->num_basis, conf_local_ext_ncells); + up->T_stationary = gkyl_array_new(GKYL_DOUBLE, conf_basis->num_basis, conf_local_ext_ncells); // Create a copy for differences (d) and differences of differences (dd) - up->dm0 = gkyl_array_new(GKYL_DOUBLE, conf_basis->num_basis, conf_local_ext_ncells); - up->dm1i = gkyl_array_new(GKYL_DOUBLE, vdim * conf_basis->num_basis, conf_local_ext_ncells); - up->dm2 = gkyl_array_new(GKYL_DOUBLE, conf_basis->num_basis, conf_local_ext_ncells); + up->dn = gkyl_array_new(GKYL_DOUBLE, conf_basis->num_basis, conf_local_ext_ncells); + up->dvbi = gkyl_array_new(GKYL_DOUBLE, vdim * conf_basis->num_basis, conf_local_ext_ncells); + up->dT = gkyl_array_new(GKYL_DOUBLE, conf_basis->num_basis, conf_local_ext_ncells); - up->ddm0 = gkyl_array_new(GKYL_DOUBLE, conf_basis->num_basis, conf_local_ext_ncells); - up->ddm1i = gkyl_array_new(GKYL_DOUBLE, vdim * conf_basis->num_basis, conf_local_ext_ncells); - up->ddm2 = gkyl_array_new(GKYL_DOUBLE, conf_basis->num_basis, conf_local_ext_ncells); + up->ddn = gkyl_array_new(GKYL_DOUBLE, conf_basis->num_basis, conf_local_ext_ncells); + up->ddvbi = gkyl_array_new(GKYL_DOUBLE, vdim * conf_basis->num_basis, conf_local_ext_ncells); + up->ddT = gkyl_array_new(GKYL_DOUBLE, conf_basis->num_basis, conf_local_ext_ncells); // Make mj moms stucture up->mj_moms = gkyl_mj_moments_new(grid, conf_basis, phase_basis, @@ -79,17 +79,17 @@ gkyl_correct_mj_new(const struct gkyl_rect_grid *grid, } void -gkyl_correct_mj_fix_m0(gkyl_correct_mj *cmj, +gkyl_correct_mj_fix_n_stationary(gkyl_correct_mj *cmj, struct gkyl_array *fout, - const struct gkyl_array *m0, const struct gkyl_array *m1i, + const struct gkyl_array *n, const struct gkyl_array *vbi, const struct gkyl_range *phase_local, const struct gkyl_range *conf_local) { // vdim int vdim = cmj->phase_basis.ndim - cmj->conf_basis.ndim; // compute the sr moments - gkyl_dg_updater_moment_advance(cmj->m0calc, phase_local, conf_local, fout, cmj->num_ratio); - gkyl_dg_updater_moment_advance(cmj->m1icalc, phase_local, conf_local, fout, cmj->num_vb); + gkyl_dg_updater_moment_advance(cmj->ncalc, phase_local, conf_local, fout, cmj->num_ratio); + gkyl_dg_updater_moment_advance(cmj->vbicalc, phase_local, conf_local, fout, cmj->num_vb); // isolate vb by dividing N*vb by N for (int d = 0; d < vdim; ++d) @@ -102,45 +102,40 @@ gkyl_correct_mj_fix_m0(gkyl_correct_mj *cmj, // calculate the stationary density, n0 = gamma*(N - vb dot Nvb) gkyl_array_clear_range(cmj->vb_dot_nvb, 0.0, conf_local); - gkyl_array_clear_range(cmj->n_minus_vb_dot_nvb, 0.0, conf_local); - gkyl_array_accumulate_range(cmj->n_minus_vb_dot_nvb, 1.0, cmj->num_ratio, conf_local); + gkyl_array_set(cmj->n_minus_vb_dot_nvb, 1.0, cmj->num_ratio); gkyl_dg_dot_product_op_range(cmj->conf_basis,cmj->vb_dot_nvb,cmj->V_drift,cmj->num_vb, conf_local); gkyl_array_accumulate_range(cmj->n_minus_vb_dot_nvb, -1.0, cmj->vb_dot_nvb, conf_local); gkyl_dg_mul_op_range(cmj->conf_basis,0,cmj->num_ratio,0,cmj->gamma,0,cmj->n_minus_vb_dot_nvb, conf_local); // compute number density ratio: num_ratio = n/n0 gkyl_dg_div_op_range(cmj->mem, cmj->conf_basis, 0, cmj->num_ratio, - 0, m0, 0, cmj->num_ratio, conf_local); + 0, n, 0, cmj->num_ratio, conf_local); // rescale distribution function gkyl_dg_mul_conf_phase_op_range(&cmj->conf_basis, &cmj->phase_basis, fout, cmj->num_ratio, fout, conf_local, phase_local); - // Hand back rescaled m0: - gkyl_array_clear_range(cmj->m0, 0.0, conf_local); - gkyl_array_accumulate_range(cmj->m0, 1.0, cmj->num_ratio, conf_local); + // Hand back rescaled n: + gkyl_array_set(cmj->n_stationary, 1.0, cmj->num_ratio); } void gkyl_correct_mj_fix(gkyl_correct_mj *cmj, struct gkyl_array *distf_mj, - const struct gkyl_array *m0_corr, const struct gkyl_array *m1i_corr, const struct gkyl_array *m2_corr, + const struct gkyl_array *n_target, const struct gkyl_array *vbi_target, const struct gkyl_array *T_target, const struct gkyl_range *phase_local, const struct gkyl_range *conf_local, int poly_order) { int vdim = cmj->phase_basis.ndim - cmj->conf_basis.ndim; // Copy the intial moments for m*_corr -> m* - gkyl_array_clear_range(cmj->m0, 0.0, conf_local); - gkyl_array_accumulate_range(cmj->m0, 1.0, m0_corr, conf_local); - gkyl_array_clear_range(cmj->m1i, 0.0, conf_local); - gkyl_array_accumulate_range(cmj->m1i, 1.0, m1i_corr, conf_local); - gkyl_array_clear_range(cmj->m2, 0.0, conf_local); - gkyl_array_accumulate_range(cmj->m2, 1.0, m2_corr, conf_local); + gkyl_array_set(cmj->n_stationary, 1.0, n_target); + gkyl_array_set(cmj->vbi, 1.0, vbi_target); + gkyl_array_set(cmj->T_stationary, 1.0, T_target); // 0. Project the MJ with the intially correct moments gkyl_proj_mj_on_basis_fluid_stationary_frame_mom(cmj->proj_mj, phase_local, - conf_local, m0_corr, m1i_corr, m2_corr, distf_mj); + conf_local, n_target, vbi_target, T_target, distf_mj); // tolerance of the iterative scheme double tol = 1e-12; @@ -161,27 +156,24 @@ gkyl_correct_mj_fix(gkyl_correct_mj *cmj, { // 1. Calculate the new moments - // calculate the moments of the dist (n, vb, T -> m0, m1i, m2) - gkyl_mj_moments_advance(cmj->mj_moms, distf_mj, cmj->m0, cmj->m1i, cmj->m2, phase_local, conf_local); + // calculate the moments of the dist (n, vb, T -> n, vbi, T) + gkyl_mj_moments_advance(cmj->mj_moms, distf_mj, cmj->n_stationary, cmj->vbi, cmj->T_stationary, phase_local, conf_local); // a. Calculate ddMi^(k+1) = Mi_corr - Mi_new - // ddm0 = m0_corr - m0; + // ddn = n_target - n; // Compute out = out + a*inp. Returns out. - gkyl_array_clear_range(cmj->ddm0, 0.0, conf_local); - gkyl_array_accumulate_range(cmj->ddm0, -1.0, cmj->m0, conf_local); - gkyl_array_accumulate_range(cmj->ddm0, 1.0, m0_corr, conf_local); - gkyl_array_clear_range(cmj->ddm1i, 0.0, conf_local); - gkyl_array_accumulate_range(cmj->ddm1i, -1.0, cmj->m1i, conf_local); - gkyl_array_accumulate_range(cmj->ddm1i, 1.0, m1i_corr, conf_local); - gkyl_array_clear_range(cmj->ddm2, 0.0, conf_local); - gkyl_array_accumulate_range(cmj->ddm2, -1.0, cmj->m2, conf_local); - gkyl_array_accumulate_range(cmj->ddm2, 1.0, m2_corr, conf_local); - - // b. Calculate dMi^(k+1) = dM0^k + ddMi^(k+1) | where dM0^0 = 0 - // dm_new = dm_old + ddm0; - gkyl_array_accumulate_range(cmj->dm0, 1.0, cmj->ddm0, conf_local); - gkyl_array_accumulate_range(cmj->dm1i, 1.0, cmj->ddm1i, conf_local); - gkyl_array_accumulate_range(cmj->dm2, 1.0, cmj->ddm2, conf_local); + gkyl_array_set(cmj->ddn, -1.0, cmj->n_stationary); + gkyl_array_accumulate(cmj->ddn, 1.0, n_target); + gkyl_array_set(cmj->ddvbi, -1.0, cmj->vbi); + gkyl_array_accumulate(cmj->ddvbi, 1.0, vbi_target); + gkyl_array_set(cmj->ddT, -1.0, cmj->T_stationary); + gkyl_array_accumulate(cmj->ddT, 1.0, T_target); + + // b. Calculate dMi^(k+1) = dn^k + ddMi^(k+1) | where dn^0 = 0 + // dm_new = dm_old + ddn; + gkyl_array_accumulate(cmj->dn, 1.0, cmj->ddn); + gkyl_array_accumulate(cmj->dvbi, 1.0, cmj->ddvbi); + gkyl_array_accumulate(cmj->dT, 1.0, cmj->ddT); // End the iteration early if all moments converge if ((cmj->niter % 1) == 0){ @@ -195,40 +187,37 @@ gkyl_correct_mj_fix(gkyl_correct_mj *cmj, gkyl_range_iter_init(&biter, conf_local); while (gkyl_range_iter_next(&biter)){ long midx = gkyl_range_idx(conf_local, biter.idx); - const double *m0_local = gkyl_array_cfetch(cmj->m0, midx); - const double *m1i_local = gkyl_array_cfetch(cmj->m1i, midx); - const double *m2_local = gkyl_array_cfetch(cmj->m2, midx); - const double *m0_original_local = gkyl_array_cfetch(m0_corr, midx); - const double *m1i_original_local = gkyl_array_cfetch(m1i_corr, midx); - const double *m2_original_local = gkyl_array_cfetch(m2_corr, midx); - cmj->error_n = fmax(fabs(m0_local[0] - m0_original_local[0]),fabs(cmj->error_n)); - cmj->error_vb[0] = fmax(fabs(m1i_local[0] - m1i_original_local[0]),fabs(cmj->error_vb[0])); - cmj->error_T = fmax(fabs(m2_local[0] - m2_original_local[0]),fabs(cmj->error_T)); + const double *n_local = gkyl_array_cfetch(cmj->n_stationary, midx); + const double *vbi_local = gkyl_array_cfetch(cmj->vbi, midx); + const double *T_local = gkyl_array_cfetch(cmj->T_stationary, midx); + const double *n_original_local = gkyl_array_cfetch(n_target, midx); + const double *vbi_original_local = gkyl_array_cfetch(vbi_target, midx); + const double *T_original_local = gkyl_array_cfetch(T_target, midx); + cmj->error_n = fmax(fabs(n_local[0] - n_original_local[0]),fabs(cmj->error_n)); + cmj->error_vb[0] = fmax(fabs(vbi_local[0] - vbi_original_local[0]),fabs(cmj->error_vb[0])); + cmj->error_T = fmax(fabs(T_local[0] - T_original_local[0]),fabs(cmj->error_T)); if (vdim > 1) - cmj->error_vb[1] = fmax(fabs(m1i_local[poly_order + 1] - m1i_original_local[poly_order + 1]),fabs(cmj->error_vb[1])); + cmj->error_vb[1] = fmax(fabs(vbi_local[poly_order + 1] - vbi_original_local[poly_order + 1]),fabs(cmj->error_vb[1])); if (vdim > 2) - cmj->error_vb[2] = fmax(fabs(m1i_local[2 * (poly_order + 1)] - m1i_original_local[2 * (poly_order + 1)]),fabs(cmj->error_vb[2])); + cmj->error_vb[2] = fmax(fabs(vbi_local[2 * (poly_order + 1)] - vbi_original_local[2 * (poly_order + 1)]),fabs(cmj->error_vb[2])); } } - // c. Calculate M0^(k+1) = M^k + dM^(k+1) - // m0 = m0_corr + dm_new; - gkyl_array_clear_range(cmj->m0, 0.0, conf_local); - gkyl_array_accumulate_range(cmj->m0, 1.0, m0_corr, conf_local); - gkyl_array_accumulate_range(cmj->m0, 1.0, cmj->dm0, conf_local); - gkyl_array_clear_range(cmj->m1i, 0.0, conf_local); - gkyl_array_accumulate_range(cmj->m1i, 1.0, m1i_corr, conf_local); - gkyl_array_accumulate_range(cmj->m1i, 1.0, cmj->dm1i, conf_local); - gkyl_array_clear_range(cmj->m2, 0.0, conf_local); - gkyl_array_accumulate_range(cmj->m2, 1.0, m2_corr, conf_local); - gkyl_array_accumulate_range(cmj->m2, 1.0, cmj->dm2, conf_local); + // c. Calculate n^(k+1) = M^k + dM^(k+1) + // n = n_target + dm_new; + gkyl_array_set(cmj->n_stationary, 1.0, n_target); + gkyl_array_accumulate(cmj->n_stationary, 1.0, cmj->dn); + gkyl_array_set(cmj->vbi, 1.0, vbi_target); + gkyl_array_accumulate(cmj->vbi, 1.0, cmj->dvbi); + gkyl_array_set(cmj->T_stationary, 1.0, T_target); + gkyl_array_accumulate(cmj->T_stationary, 1.0, cmj->dT); // 2. Update the dist_mj using the corrected moments gkyl_proj_mj_on_basis_fluid_stationary_frame_mom(cmj->proj_mj, phase_local, - conf_local, cmj->m0, cmj->m1i, cmj->m2, distf_mj); + conf_local, cmj->n_stationary, cmj->vbi, cmj->T_stationary, distf_mj); - // 3. Correct the M0 moment to fix the asymptotically approximated MJ function - gkyl_correct_mj_fix_m0(cmj, distf_mj, cmj->m0, cmj->m1i, phase_local, conf_local); + // 3. Correct the n moment to fix the asymptotically approximated MJ function + gkyl_correct_mj_fix_n_stationary(cmj, distf_mj, cmj->n_stationary, cmj->vbi, phase_local, conf_local); cmj->niter += 1; } @@ -239,22 +228,11 @@ gkyl_correct_mj_fix(gkyl_correct_mj *cmj, cmj->status = 1; // If the algorithm fails (density fails to converge)! - // Project the distribution function with the basic moments and correct m0 - gkyl_mj_moments_advance(cmj->mj_moms, distf_mj, cmj->m0, cmj->m1i, cmj->m2, phase_local, conf_local); - double diff = 0.0; - struct gkyl_range_iter biter; - gkyl_range_iter_init(&biter, conf_local); - while (gkyl_range_iter_next(&biter)){ - long midx = gkyl_range_idx(conf_local, biter.idx); - const double *m0_corr_local = gkyl_array_cfetch(m0_corr, midx); - const double *m0_local = gkyl_array_cfetch(cmj->m0, midx); - if (diff < (m0_local[0] - m0_corr_local[0])) - diff = fabs(m0_local[0] - m0_corr_local[0]); - } - if (fabs(diff) > 1e-10){ + // Project the distribution function with the basic moments and correct n + if (cmj->status == 1){ gkyl_proj_mj_on_basis_fluid_stationary_frame_mom(cmj->proj_mj, phase_local, - conf_local, m0_corr, m1i_corr, m2_corr, distf_mj); - gkyl_correct_mj_fix_m0(cmj, distf_mj, cmj->m0, cmj->m1i, phase_local, conf_local); + conf_local, n_target, vbi_target, T_target, distf_mj); + gkyl_correct_mj_fix_n_stationary(cmj, distf_mj, n_target, vbi_target, phase_local, conf_local); } } @@ -262,9 +240,9 @@ void gkyl_correct_mj_release(gkyl_correct_mj *cmj) { - // gkyl_mom_calc_release(cmj->m0calc); - gkyl_dg_updater_moment_release(cmj->m0calc); - gkyl_dg_updater_moment_release(cmj->m1icalc); + // gkyl_mom_calc_release(cmj->ncalc); + gkyl_dg_updater_moment_release(cmj->ncalc); + gkyl_dg_updater_moment_release(cmj->vbicalc); gkyl_array_release(cmj->num_ratio); gkyl_array_release(cmj->vb_dot_nvb); gkyl_array_release(cmj->n_minus_vb_dot_nvb); @@ -273,15 +251,15 @@ gkyl_correct_mj_release(gkyl_correct_mj *cmj) gkyl_array_release(cmj->gamma); gkyl_dg_bin_op_mem_release(cmj->mem); - gkyl_array_release(cmj->m0); - gkyl_array_release(cmj->m1i); - gkyl_array_release(cmj->m2); - gkyl_array_release(cmj->dm0); - gkyl_array_release(cmj->dm1i); - gkyl_array_release(cmj->dm2); - gkyl_array_release(cmj->ddm0); - gkyl_array_release(cmj->ddm1i); - gkyl_array_release(cmj->ddm2); + gkyl_array_release(cmj->n_stationary); + gkyl_array_release(cmj->vbi); + gkyl_array_release(cmj->T_stationary); + gkyl_array_release(cmj->dn); + gkyl_array_release(cmj->dvbi); + gkyl_array_release(cmj->dT); + gkyl_array_release(cmj->ddn); + gkyl_array_release(cmj->ddvbi); + gkyl_array_release(cmj->ddT); gkyl_mj_moments_release(cmj->mj_moms); gkyl_proj_mj_on_basis_release(cmj->proj_mj); diff --git a/zero/gkyl_correct_mj.h b/zero/gkyl_correct_mj.h index 40ad4504d..c47f8054d 100644 --- a/zero/gkyl_correct_mj.h +++ b/zero/gkyl_correct_mj.h @@ -16,9 +16,12 @@ typedef struct gkyl_correct_mj gkyl_correct_mj; * @param conf_basis Conf space basis functions * @param phase_basis Phase space basis functions * @param conf_range configuration space range + * @param conf_range_ext Number of cells in local extended config- * @param vel_range velocity space range - * @param conf_local_cells Number of cells in local config-space - * @param conf_local_ext_cells Number of cells in local extended config-space + * @param p_over_gamma sr quantitiy: velocity + * @param gamma sr quantitiy: gamma + * @param gamma_inv sr quantitiy: 1/gamma + * @param use_gpu bool for gpu useage */ gkyl_correct_mj *gkyl_correct_mj_new(const struct gkyl_rect_grid *grid, const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, @@ -27,39 +30,37 @@ gkyl_correct_mj *gkyl_correct_mj_new(const struct gkyl_rect_grid *grid, bool use_gpu); /** - * Fix the Maxwell-Juttner so that it's moments match desired m0 moment. + * Fix the Maxwell-Juttner so that it's moments match desired n_stationary moment. * * @param cmj MJ correction updater - * @param p_over_gamma velocity array * @param fout Distribution function to fix (modified in-place) - * @param m0 Desired lab-frame number density - * @param m1i specified velocity of f in the stationary frame + * @param n_stationary Desired lab-frame number density + * @param vbi specified velocity of f in the stationary frame * @param phase_local Local phase-space range * @param conf_local Local configuration space range */ -void gkyl_correct_mj_fix_m0(gkyl_correct_mj *cmj, +void gkyl_correct_mj_fix_n_stationary(gkyl_correct_mj *cmj, struct gkyl_array *fout, - const struct gkyl_array *m0, const struct gkyl_array *m1i, + const struct gkyl_array *n_stationary, const struct gkyl_array *vbi, const struct gkyl_range *phase_local, const struct gkyl_range *conf_local); /** * Fix the Maxwell-Juttner so that it's moments match desired moments. * NOTE: If this algorithm fails, the returns the original distribution function - * with only the m0 moment corrected (i.e. runs: gkyl_correct_mj_fix_m0()) + * with only the n_stationary moment corrected (i.e. runs: gkyl_correct_mj_fix_n_stationary()) * * @param cmj MJ correction updater * @param fout Distribution function to fix (modified in-place) - * @param m0 Desired lab-frame number density - * @param m1i Desired lab-frame velocity - * @param m2 Desired lab-frame temperature + * @param n_stationary Desired lab-frame number density + * @param vbi Desired lab-frame velocity + * @param T_stationary Desired lab-frame temperature * @param phase_local Local phase-space range * @param conf_local Local configuration space range - * @param vel_basis Vel space basis functions - * @param vel_grid Vel-Grid on which updater lives + * @param poly_order */ void gkyl_correct_mj_fix(gkyl_correct_mj *cmj, struct gkyl_array *fout, - const struct gkyl_array *m0, const struct gkyl_array *m1i, const struct gkyl_array *m2, + const struct gkyl_array *n_stationary, const struct gkyl_array *vbi, const struct gkyl_array *T_stationary, const struct gkyl_range *phase_local, const struct gkyl_range *conf_local, int poly_order); diff --git a/zero/gkyl_correct_mj_priv.h b/zero/gkyl_correct_mj_priv.h index 68973355a..03c992caa 100644 --- a/zero/gkyl_correct_mj_priv.h +++ b/zero/gkyl_correct_mj_priv.h @@ -10,8 +10,8 @@ struct gkyl_correct_mj struct gkyl_rect_grid grid; struct gkyl_basis conf_basis, phase_basis; - struct gkyl_dg_updater_moment *m0calc; - struct gkyl_dg_updater_moment *m1icalc; + struct gkyl_dg_updater_moment *ncalc; + struct gkyl_dg_updater_moment *vbicalc; struct gkyl_array *num_ratio; struct gkyl_array *num_vb; struct gkyl_array *V_drift; @@ -20,9 +20,9 @@ struct gkyl_correct_mj struct gkyl_array *n_minus_vb_dot_nvb; struct gkyl_dg_bin_op_mem *mem; - struct gkyl_array *m0, *m1i, *m2; - struct gkyl_array *dm0, *dm1i, *dm2; - struct gkyl_array *ddm0, *ddm1i, *ddm2; + struct gkyl_array *n_stationary, *vbi, *T_stationary; + struct gkyl_array *dn, *dvbi, *dT; + struct gkyl_array *ddn, *ddvbi, *ddT; struct gkyl_mj_moments *mj_moms; struct gkyl_proj_mj_on_basis *proj_mj; diff --git a/zero/gkyl_mj_moments.h b/zero/gkyl_mj_moments.h index 1d0a1a5a5..fc41d0ca0 100644 --- a/zero/gkyl_mj_moments.h +++ b/zero/gkyl_mj_moments.h @@ -9,8 +9,7 @@ typedef struct gkyl_mj_moments gkyl_mj_moments; /** - * Create new updater to correct a Maxwellian to match specified - * moments. + * Create new updater to compute the moments. * * @param grid Grid on which updater lives * @param conf_basis Conf space basis functions @@ -19,6 +18,10 @@ typedef struct gkyl_mj_moments gkyl_mj_moments; * @param vel_range velocity space range * @param conf_local_cells Number of cells in local config-space * @param conf_local_ext_cells Number of cells in local extended config-space + * @param p_over_gamma sr quantitiy: velocity + * @param gamma sr quantitiy: gamma + * @param gamma_inv sr quantitiy: 1/gamma + * @param use_gpu bool for gpu useage */ gkyl_mj_moments *gkyl_mj_moments_new(const struct gkyl_rect_grid *grid, const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, @@ -28,23 +31,20 @@ gkyl_mj_moments *gkyl_mj_moments_new(const struct gkyl_rect_grid *grid, bool use_gpu); /** - * Update the m0, m1, and m2 moments (n, vb, T) moments of an arbitary sr + * Update the n_stationary, vb, and T_stationary moments (n, vb, T) moments of an arbitary sr * distribution so they are ready as inputs to the mj routine * * @param cmj Maxwell-Juttner correction updater - * @param p_over_gamma velocity array - * @param gamma array - * @param gamma_inv array - * @param fout Distribution function to fix (modified in-place) - * @param m0 Desired number density - * @param m1i Desired velocity - * @param m2 Desired Temperature + * @param fin Distribution function + * @param n_stationary Desired number density + * @param vb Desired velocity + * @param T_stationary Desired Temperature * @param phase_local Local phase-space range * @param conf_local Local configuration space range */ void gkyl_mj_moments_advance(gkyl_mj_moments *cmj, - struct gkyl_array *fout, - struct gkyl_array *m0, struct gkyl_array *m1i, struct gkyl_array *m2, + const struct gkyl_array *fin, + struct gkyl_array *n_stationary, struct gkyl_array *vb, struct gkyl_array *T_stationary, const struct gkyl_range *phase_local, const struct gkyl_range *conf_local); /** diff --git a/zero/gkyl_mj_moments_priv.h b/zero/gkyl_mj_moments_priv.h new file mode 100644 index 000000000..42f53ddaa --- /dev/null +++ b/zero/gkyl_mj_moments_priv.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include +#include + + +struct gkyl_mj_moments +{ + struct gkyl_rect_grid grid; + struct gkyl_basis conf_basis, phase_basis; + + // struct gkyl_mom_calc *ncalc; + struct gkyl_dg_updater_moment *ncalc; + struct gkyl_dg_updater_moment *vbicalc; + struct gkyl_dg_updater_moment *Pcalc; + struct gkyl_array *num_ratio; + struct gkyl_array *num_vb; + struct gkyl_array *vb_dot_nvb; + struct gkyl_array *n_minus_vb_dot_nvb; + struct gkyl_array *V_drift; + struct gkyl_array *gamma; + struct gkyl_array *GammaV2; + struct gkyl_array *Gamma_inv; + struct gkyl_array *pressure; + struct gkyl_array *temperature; + + struct gkyl_dg_bin_op_mem *mem; +}; \ No newline at end of file diff --git a/zero/gkyl_proj_mj_on_basis.h b/zero/gkyl_proj_mj_on_basis.h index 6ea66a340..af3498640 100644 --- a/zero/gkyl_proj_mj_on_basis.h +++ b/zero/gkyl_proj_mj_on_basis.h @@ -28,16 +28,15 @@ gkyl_proj_mj_on_basis* gkyl_proj_mj_on_basis_new( * lab-frame moments to compute the projection of mj on basis * functions. * - * @param pob Project on basis updater to run + * @param proj_on_basis Project on basis updater to run * @param phase_rng Phase-space range * @param conf_rng Config-space range * @param n Number density moment in the stationary fluid frame * @param v velocity of the fluid relative to the lab-frame * @param T Temperature in the fluid rest frame - * @param f_mj Output mj */ -void gkyl_proj_mj_on_basis_fluid_stationary_frame_mom(const gkyl_proj_mj_on_basis *pob, +void gkyl_proj_mj_on_basis_fluid_stationary_frame_mom(const gkyl_proj_mj_on_basis *proj_on_basis, const struct gkyl_range *phase_range, const struct gkyl_range *conf_range, const struct gkyl_array *n_stationary_frame, const struct gkyl_array *vel_stationary_frame, const struct gkyl_array *T_stationary_frame, struct gkyl_array *f_mj); diff --git a/zero/mj_moments.c b/zero/mj_moments.c index dddd55101..d0e166382 100644 --- a/zero/mj_moments.c +++ b/zero/mj_moments.c @@ -8,33 +8,11 @@ #include #include #include +#include #include #include #include -struct gkyl_mj_moments -{ - struct gkyl_rect_grid grid; - struct gkyl_basis conf_basis, phase_basis; - - // struct gkyl_mom_calc *m0calc; - struct gkyl_dg_updater_moment *m0calc; - struct gkyl_dg_updater_moment *m1icalc; - struct gkyl_dg_updater_moment *m2calc; - struct gkyl_array *num_ratio; - struct gkyl_array *num_vb; - struct gkyl_array *vb_dot_nvb; - struct gkyl_array *n_minus_vb_dot_nvb; - struct gkyl_array *V_drift; - struct gkyl_array *gamma; - struct gkyl_array *GammaV2; - struct gkyl_array *Gamma_inv; - struct gkyl_array *pressure; - struct gkyl_array *temperature; - - struct gkyl_dg_bin_op_mem *mem; -}; - gkyl_mj_moments * gkyl_mj_moments_new(const struct gkyl_rect_grid *grid, const struct gkyl_basis *conf_basis, const struct gkyl_basis *phase_basis, @@ -68,26 +46,36 @@ gkyl_mj_moments_new(const struct gkyl_rect_grid *grid, .GammaV2 = up->GammaV2, .GammaV_inv = up->Gamma_inv}; // updated moment calculator for sr N and N*vb moments - up->m0calc = gkyl_dg_updater_moment_new(grid, conf_basis, + up->ncalc = gkyl_dg_updater_moment_new(grid, conf_basis, phase_basis, conf_range, vel_range, GKYL_MODEL_SR, &sr_inp, "M0", 0, 1, use_gpu); - up->m1icalc = gkyl_dg_updater_moment_new(grid, conf_basis, + up->vbicalc = gkyl_dg_updater_moment_new(grid, conf_basis, phase_basis, conf_range, vel_range, GKYL_MODEL_SR, &sr_inp, "M1i", 0, 1, use_gpu); - up->m2calc = gkyl_dg_updater_moment_new(grid, conf_basis, + up->Pcalc = gkyl_dg_updater_moment_new(grid, conf_basis, phase_basis, conf_range, vel_range, GKYL_MODEL_SR, &sr_inp, "Pressure", 0, 1, use_gpu); return up; } void gkyl_mj_moments_advance(gkyl_mj_moments *cmj, - struct gkyl_array *fout, - struct gkyl_array *m0, struct gkyl_array *m1i, struct gkyl_array *m2, + const struct gkyl_array *fout, + struct gkyl_array *n, struct gkyl_array *vbi, struct gkyl_array *T, const struct gkyl_range *phase_local, const struct gkyl_range *conf_local) { +//gkyl_mj_moments_advance(gkyl_mj_moments *cmj, +// const struct gkyl_range *phase_local, const struct gkyl_range *conf_local, +// const struct gkyl_array *fout, struct gkyl_array *sr_five_moms) +//{ + int vdim = cmj->phase_basis.ndim - cmj->conf_basis.ndim; + // grab the arrays from the larger array object + //double *n = sr_five_moms; + //double *vbi = &sr_five_moms[cmj->conf_basis.num_basis*conf_local.volume]; + //double *T = &sr_five_moms[(1+vdim)*cmj->conf_basis.num_basis*conf_local.volume]; + // compute the sr moments, lab frame and - gkyl_dg_updater_moment_advance(cmj->m0calc, phase_local, conf_local, fout, cmj->num_ratio); - gkyl_dg_updater_moment_advance(cmj->m1icalc, phase_local, conf_local, fout, cmj->num_vb); + gkyl_dg_updater_moment_advance(cmj->ncalc, phase_local, conf_local, fout, cmj->num_ratio); + gkyl_dg_updater_moment_advance(cmj->vbicalc, phase_local, conf_local, fout, cmj->num_vb); // (vb = /) isolate vb by dividing by for (int d = 0; d < vdim; ++d) @@ -107,12 +95,11 @@ gkyl_mj_moments_advance(gkyl_mj_moments *cmj, conf_local, cmj->V_drift, cmj->Gamma_inv); // compute the pressure moment (stationary frame) - gkyl_dg_updater_moment_advance(cmj->m2calc, phase_local, conf_local, fout, cmj->pressure); + gkyl_dg_updater_moment_advance(cmj->Pcalc, phase_local, conf_local, fout, cmj->pressure); // (n = gamma*(N - vb dot NVb)) Lorentz transform to our fluid-stationary density gkyl_array_clear_range(cmj->vb_dot_nvb, 0.0, conf_local); - gkyl_array_clear_range(cmj->n_minus_vb_dot_nvb, 0.0, conf_local); - gkyl_array_accumulate_range(cmj->n_minus_vb_dot_nvb, 1.0, cmj->num_ratio, conf_local); + gkyl_array_set(cmj->n_minus_vb_dot_nvb, 1.0, cmj->num_ratio); gkyl_dg_dot_product_op_range(cmj->conf_basis,cmj->vb_dot_nvb,cmj->V_drift,cmj->num_vb, conf_local); gkyl_array_accumulate_range(cmj->n_minus_vb_dot_nvb, -1.0, cmj->vb_dot_nvb, conf_local); gkyl_dg_mul_op_range(cmj->conf_basis,0,cmj->num_ratio,0,cmj->gamma,0,cmj->n_minus_vb_dot_nvb, conf_local); @@ -121,23 +108,20 @@ gkyl_mj_moments_advance(gkyl_mj_moments *cmj, gkyl_dg_div_op_range(cmj->mem, cmj->conf_basis, 0, cmj->temperature, 0, cmj->pressure, 0, cmj->num_ratio, conf_local); - // Save the outputs to m0 m1i m2 (for n vb T): - gkyl_array_clear_range(m0, 0.0, conf_local); - gkyl_array_clear_range(m1i, 0.0, conf_local); - gkyl_array_clear_range(m2, 0.0, conf_local); - gkyl_array_accumulate_range(m0, 1.0, cmj->num_ratio, conf_local); - gkyl_array_accumulate_range(m1i, 1.0, cmj->V_drift, conf_local); - gkyl_array_accumulate_range(m2, 1.0, cmj->temperature, conf_local); + // Save the outputs to n vbi T (for n vb T): + gkyl_array_set(n, 1.0, cmj->num_ratio); + gkyl_array_set(vbi, 1.0, cmj->V_drift); + gkyl_array_set(T, 1.0, cmj->temperature); } void gkyl_mj_moments_release(gkyl_mj_moments *cmj) { - // gkyl_mom_calc_release(cmj->m0calc); - gkyl_dg_updater_moment_release(cmj->m0calc); - gkyl_dg_updater_moment_release(cmj->m1icalc); - gkyl_dg_updater_moment_release(cmj->m2calc); + // gkyl_mom_calc_release(cmj->ncalc); + gkyl_dg_updater_moment_release(cmj->ncalc); + gkyl_dg_updater_moment_release(cmj->vbicalc); + gkyl_dg_updater_moment_release(cmj->Pcalc); gkyl_array_release(cmj->num_ratio); gkyl_array_release(cmj->num_vb); gkyl_array_release(cmj->vb_dot_nvb);