From 6e595148b46e17ff8a23a0276c709582f12ae4a7 Mon Sep 17 00:00:00 2001 From: phskak Date: Fri, 11 Feb 2022 10:31:16 +0000 Subject: [PATCH] -Add new input deck option 'two_stream_neutral' that is an explicitly quasineutral version of the two_stream deck. -The usual momentum conservation relation is only valid if the plasma is quasineutral (because the implied neutralising species would gain/lose significant momentum) -Now momentum conservation seems to be working as expected. --- example_decks/two_stream_neutral.deck | 3 + src/user_interaction/ic_module.f90 | 162 ++++++++++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 example_decks/two_stream_neutral.deck diff --git a/example_decks/two_stream_neutral.deck b/example_decks/two_stream_neutral.deck new file mode 100644 index 0000000..5f23e7c --- /dev/null +++ b/example_decks/two_stream_neutral.deck @@ -0,0 +1,3 @@ +&control + problem = 'two_stream_neutral' +/ diff --git a/src/user_interaction/ic_module.f90 b/src/user_interaction/ic_module.f90 index b9d7f5d..9c6d259 100644 --- a/src/user_interaction/ic_module.f90 +++ b/src/user_interaction/ic_module.f90 @@ -27,6 +27,8 @@ SUBROUTINE custom_problem_setup(deck_state, problem) SELECT CASE (TRIM(problem)) CASE('two_stream') CALL two_stream_setup(deck_state) + CASE('two_stream_neutral') + CALL two_stream_neutral_setup(deck_state) CASE('one_stream') CALL one_stream_setup(deck_state) CASE('drift_kin_default') @@ -164,6 +166,166 @@ SUBROUTINE two_stream_setup(deck_state) END SUBROUTINE two_stream_setup + SUBROUTINE two_stream_neutral_setup(deck_state) + + INTEGER, INTENT(IN) :: deck_state + REAL(num), PARAMETER :: v_drift = 0.2_num * c + REAL(num), PARAMETER :: v_therm = 0.01_num * c + REAL(num), PARAMETER :: v_pert = 0.1_num * v_therm + REAL(num), PARAMETER :: n0 = 8e11 + INTEGER, PARAMETER :: ppc = 16 + REAL(num) :: gamma_drift, temp_x, omega + INTEGER :: ix + TYPE(particle_species), POINTER :: current_species + + IF (deck_state == c_ds_first) THEN + ! Set control variables here + nx_global = 64 + ny_global = 4 + nz_global = 4 + x_min = 0.0_num + x_max = 2.0_num * pi + y_min = x_min + ! Could do (x_max * ny_global) / nx_global, but be wary of compilers + ! which don't obey precedence implied by parentheses by default + ! (e.g. Intel) + y_max = x_max * REAL(ny_global, num) / REAL(nx_global, num) + z_min = x_min + z_max = x_max * REAL(nz_global, num) / REAL(nx_global, num) + + ! Plasma frequency + omega = SQRT(n0 * q0 * q0 / epsilon0 / m0) + t_end = 30.0_num / omega + stdout_frequency = 10 + + ! dt_multiplier = 0.5 + + + ! Need to set-up species here + NULLIFY(current_species) + CALL setup_species(current_species, 'Right') + + ! mass -- MANDATORY + current_species%mass = 1.1_num * m0 + + ! charge -- MANDATORY + current_species%charge = -1.0_num * q0 + + ! npart_per_cell + current_species%npart_per_cell = ppc + + ! MANDATORY + NULLIFY(current_species) + CALL setup_species(current_species, 'Left') + + ! mass -- MANDATORY + current_species%mass = 1.0_num * m0 + + ! charge -- MANDATORY + current_species%charge = -1.0_num * q0 + + ! npart_per_cell + current_species%npart_per_cell = ppc + + NULLIFY(current_species) + CALL setup_species(current_species, 'Balance') + + ! mass -- MANDATORY + current_species%mass = 100 * m0 + + ! charge -- MANDATORY + current_species%charge = 1.0_num * q0 + + ! npart_per_cell + current_species%npart_per_cell = ppc + + RETURN + END IF + + ! Calculate gamma_drift + ! Strictly should be function of x, but vpert << vdrift + gamma_drift = 1.0_num / SQRT(1.0_num - (v_drift / c)**2) + + ! Calculate (1 DoF) temperature + temp_x = v_therm**2 * m0 / kb + + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + ! Species + + ! MANDATORY (Is the NULLIFY mandatory?) + NULLIFY(current_species) + CALL setup_species(current_species, 'Right') + + ! density + current_species%density = n0 + + ! drift_x + ! Add on perturbation to seed instability + DO ix = 1-ng, nx+ng + current_species%drift(ix,:,:,1) = gamma_drift * current_species%mass & + * (v_drift + v_pert * SIN(3.0_num * x(ix))) + END DO + + ! temp_x + current_species%temp(:,:,:,1) = temp_x + + IF (explicit_pic) THEN + current_species%is_implicit = .FALSE. + ELSE + current_species%is_implicit = .TRUE. + END IF + + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + ! MANDATORY + NULLIFY(current_species) + CALL setup_species(current_species, 'Left') + + ! density + current_species%density = n0 + + ! drift_x + ! Add on perturbation to seed instability + DO ix = 1-ng, nx+ng + current_species%drift(ix,:,:,1) = gamma_drift * current_species%mass & + * (-v_drift + v_pert * SIN(3.0_num * x(ix))) + END DO + + ! temp_x + current_species%temp(:,:,:,1) = temp_x + + IF (explicit_pic) THEN + current_species%is_implicit = .FALSE. + ELSE + current_species%is_implicit = .TRUE. + END IF + + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + ! MANDATORY + NULLIFY(current_species) + CALL setup_species(current_species, 'Balance') + + ! density + current_species%density = 2.0_num * n0 + + ! drift_x + DO ix = 1-ng, nx+ng + current_species%drift(ix,:,:,1) = 0.0_num + END DO + + ! temp_x + current_species%temp(:,:,:,1) = temp_x + + IF (explicit_pic) THEN + current_species%is_implicit = .FALSE. + ELSE + current_species%is_implicit = .TRUE. + END IF + + + END SUBROUTINE two_stream_neutral_setup SUBROUTINE em_wave_setup(deck_state)