Skip to content

Commit

Permalink
Allow HW alpha and kappa to be specified via physical params.
Browse files Browse the repository at this point in the history
  • Loading branch information
oparry-ukaea committed Feb 21, 2024
1 parent ee31225 commit d7c46dc
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 26 deletions.
14 changes: 7 additions & 7 deletions solvers/H3LAPD/EquationSystems/DriftReducedSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@ void DriftReducedSystem::load_params() {
m_session->LoadParameter("particle_num_write_particle_steps",
m_num_write_particle_steps, 0);
m_part_timestep = m_timestep / m_num_part_substeps;

// Compute some properties derived from params
m_Bmag = std::sqrt(m_B[0] * m_B[0] + m_B[1] * m_B[1] + m_B[2] * m_B[2]);
m_b_unit = std::vector<NekDouble>(m_graph->GetSpaceDimension());
for (auto idim = 0; idim < m_b_unit.size(); idim++) {
m_b_unit[idim] = (m_Bmag > 0) ? m_B[idim] / m_Bmag : 0.0;
}
}

/**
Expand Down Expand Up @@ -443,13 +450,6 @@ void DriftReducedSystem::v_InitObject(bool create_field) {
// Load parameters
load_params();

// Compute some properties derived from params
m_Bmag = std::sqrt(m_B[0] * m_B[0] + m_B[1] * m_B[1] + m_B[2] * m_B[2]);
m_b_unit = std::vector<NekDouble>(m_graph->GetSpaceDimension());
for (auto idim = 0; idim < m_b_unit.size(); idim++) {
m_b_unit[idim] = (m_Bmag > 0) ? m_B[idim] / m_Bmag : 0.0;
}

// Tell UnsteadySystem to only integrate a subset of fields in time
// (Ignore fields that don't have a time derivative)
m_intVariables.resize(m_int_fld_names.size());
Expand Down
9 changes: 6 additions & 3 deletions solvers/H3LAPD/EquationSystems/HW2Din3DSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ void HW2Din3DSystem::explicit_time_int(
* @brief Read base class params then extra params required for 2D-in-3D HW.
*/
void HW2Din3DSystem::load_params() {
HWSystem::load_params();
DriftReducedSystem::load_params();

// alpha
m_session->LoadParameter("HW_alpha", m_alpha, 2);
// alpha (required)
m_session->LoadParameter("HW_alpha", m_alpha);

// kappa (required)
m_session->LoadParameter("HW_kappa", m_kappa);
}

/**
Expand Down
61 changes: 52 additions & 9 deletions solvers/H3LAPD/EquationSystems/HW3DSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ void HW3DSystem::calc_par_dyn_term(
// Use diffusion object to calculate second deriv of phi-n in z direction
m_diffusion->Diffuse(1, m_diff_fields, m_diff_in_arr, m_diff_out_arr);
// Multiply by constants to compute term
Vmath::Smul(npts, m_omega_ce / m_nu_ei, m_diff_out_arr[0], 1, m_par_dyn_term,
1);
Vmath::Smul(npts, m_alpha, m_diff_out_arr[0], 1, m_par_dyn_term, 1);
}

/**
Expand Down Expand Up @@ -134,15 +133,60 @@ void HW3DSystem::get_flux_vector_diff(
* @brief Read base class params then extra params required for 2D-in-3D HW.
*/
void HW3DSystem::load_params() {
HWSystem::load_params();
DriftReducedSystem::load_params();
// Diffusion type
m_session->LoadSolverInfo("DiffusionType", m_diff_type, "LDG");

// ω_ce (required)
m_session->LoadParameter("HW_omega_ce", m_omega_ce);
// physical constants
const NekDouble e = 1.6e-19;

// If electron-ion collision freq. and cyclotron freq were passed,
// use them to set alpha
if (m_session->DefinesParameter("HW_omega_ce") &&
m_session->DefinesParameter("HW_nu_ei")) {

/// ν_ei (Electron-ion collision frequency)
NekDouble nu_ei;
m_session->LoadParameter("HW_nu_ei", nu_ei);
/// Cyclotron frequency for electrons
NekDouble omega_ce;
m_session->LoadParameter("HW_omega_ce", omega_ce);
m_alpha = omega_ce / nu_ei;
} else {
// Otherwise expect
// physical params with defaults
NekDouble mi;
m_session->LoadParameter("mi", mi, 2 * 1.67e-27);
// params that user must supply
NekDouble n0;
m_session->LoadParameter("n0", n0);
NekDouble T0;
m_session->LoadParameter("T0", T0);
NekDouble Z;
m_session->LoadParameter("Z", Z);
NekDouble log_lambda = 31 - 0.5 * std::log(n0) + std::log(T0);
NekDouble eta = 5.2e-5 * Z * log_lambda / std::pow(T0, 1.5);
NekDouble w_ci = e * m_Bmag / mi;
m_alpha = T0 / n0 / e / eta / w_ci;
}

// ν_ei (required)
m_session->LoadParameter("HW_nu_ei", m_nu_ei);
// If kappa wasn't supplied directly, require "n0", "T0", "lambda_q"
if (m_session->DefinesParameter("HW_kappa")) {
m_session->LoadParameter("HW_kappa", m_kappa);
} else {
// physical params with defaults
NekDouble mi;
m_session->LoadParameter("mi", mi, 2 * 1.67e-27);
// params that user must supply
NekDouble lambda_q;
m_session->LoadParameter("lambda_q", lambda_q);
NekDouble n0;
m_session->LoadParameter("n0", n0);
NekDouble T0;
m_session->LoadParameter("T0", T0);
NekDouble rho_s0 = std::sqrt(mi * T0 / e / m_Bmag);
m_kappa = rho_s0 / lambda_q;
}
}

/**
Expand Down Expand Up @@ -172,8 +216,7 @@ void HW3DSystem::v_InitObject(bool DeclareField) {
m_diag_growth_rates_recorder =
std::make_shared<GrowthRatesRecorder<MultiRegions::DisContField>>(
m_session, 3, m_discont_fields["ne"], m_discont_fields["w"],
m_discont_fields["phi"], GetNpoints(), m_omega_ce / m_nu_ei,
m_kappa);
m_discont_fields["phi"], GetNpoints(), m_alpha, m_kappa);
}
}

Expand Down
5 changes: 0 additions & 5 deletions solvers/H3LAPD/EquationSystems/HW3DSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ class HW3DSystem : virtual public HWSystem {
// Diffusion object
SU::DiffusionSharedPtr m_diffusion;

/// Electron-ion collision frequency
NekDouble m_nu_ei;
/// Cyclotron frequency for electrons
NekDouble m_omega_ce;

// Array for storage of parallel dynamics term
Array<OneD, NekDouble> m_par_dyn_term;

Expand Down
4 changes: 2 additions & 2 deletions solvers/H3LAPD/EquationSystems/HWSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ class HWSystem : virtual public DriftReducedSystem {
get_phi_solve_rhs(const Array<OneD, const Array<OneD, NekDouble>> &inarray,
Array<OneD, NekDouble> &rhs) override final;

void load_params() override;

virtual void v_InitObject(bool DeclareField) override;

virtual bool v_PostIntegrate(int step) override final;
Expand All @@ -55,6 +53,8 @@ class HWSystem : virtual public DriftReducedSystem {
bool m_diag_growth_rates_recording_enabled;
/// Bool to enable/disable mass recordings
bool m_diag_mass_recording_enabled;
/// Hasegawa-Wakatani α
NekDouble m_alpha;
/// Hasegawa-Wakatani κ
NekDouble m_kappa;
};
Expand Down

0 comments on commit d7c46dc

Please sign in to comment.