From e90b43d50617103f13d1000150fa71c4a40f8bb4 Mon Sep 17 00:00:00 2001 From: "Vasco C. B. Ferreira" Date: Thu, 30 Jul 2026 16:06:22 +0200 Subject: [PATCH] Several f0s cases added, to be tested --- nufi/fields.h | 52 +++++++++++++++++++++++++++++++++++++---------- nufi/parameters.h | 9 ++++++-- 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/nufi/fields.h b/nufi/fields.h index 51364ed..9ab0a82 100644 --- a/nufi/fields.h +++ b/nufi/fields.h @@ -35,21 +35,51 @@ inline double f0(const double x, const double v, const double eps = Parameters::EPS; const double k = Parameters::WAVE_NR; - double result; + const double factor = Parameters::F0_FACTOR; + + auto maxwell = [factor](double u, double v = 0, double v_th = 1) { + return 1 / v_th * factor * + std::exp(-0.5 * (u - v) * (u - v) / (v_th * v_th)); + }; double prefactor; - double gaussian; + double computed_max; + double result; switch (f0_type) { - case 0: - prefactor = Parameters::F0_FACTOR * (1.0 + eps * std::cos(k * x)); - gaussian = v * v * std::exp(-0.5 * v * v); - result = prefactor * gaussian; - case 1: - // test - prefactor = Parameters::F0_FACTOR * (1.0 + eps * std::cos(k * x)); - gaussian = v * v * std::exp(-0.5 * v * v); - result = prefactor * gaussian; + case 0: // two-stream + { + computed_max = maxwell(v); + prefactor = (1.0 + eps * std::cos(k * x)) * v * v; + result = prefactor * computed_max; + break; + } + case 1: // Landau-damping + { + computed_max = maxwell(v); + prefactor = (1.0 + eps * std::cos(k * x)); + result = prefactor * computed_max; + break; + } + case 2: // Maxwellian + { + result = maxwell(v); + break; + } + case 3: // Bump-on tail + { + const double beam_density = 0.05; + const double beam_v_th = 0.2; + const double beam_v = 3; + const double alpha = beam_density / (1 - beam_density); + + const double beam_max = maxwell(v, beam_v, beam_v_th); + computed_max = maxwell(v); + result = (1 - alpha) * computed_max + alpha * beam_max; + break; + } + default: + throw std::invalid_argument("Invalid f0_type"); } return result; diff --git a/nufi/parameters.h b/nufi/parameters.h index 2b0439f..4e81530 100644 --- a/nufi/parameters.h +++ b/nufi/parameters.h @@ -23,10 +23,15 @@ constexpr double V_DOMAIN_RIGHT = 10.; constexpr unsigned int NV = 128; constexpr double DV = std::abs(V_DOMAIN_RIGHT - V_DOMAIN_LEFT) / NV; -constexpr size_t f0_TYPE = 0; // for switch case +// f0_TYPE: +// 0 -> twos-stream +// 1 -> landau-damping +// 2 -> maxwellian +// 3 -> bump-on-tail +constexpr size_t f0_TYPE = 3; // deal.ii options -constexpr unsigned int GLOBAL_REFINEMENT = 6; +constexpr unsigned int GLOBAL_REFINEMENT = 7; constexpr unsigned int FE_DEGREE = 3; constexpr unsigned int CONVERGENCE_ITERATIONS = 5000; constexpr double CONVERGENCE_LIMIT = 1e-8;