From a6bdda9a98750e72d89f5be35ee6150ed1529769 Mon Sep 17 00:00:00 2001 From: John Omotani Date: Thu, 17 Oct 2024 22:52:47 +0100 Subject: [PATCH 1/5] Copy updated moments.electron.ppar into fvec_out - electron ppar evolves Previously the `electron_ppar` in the ion/neutral `scratch_pdf` struct was never updated when using the implicit electron solve (`implicit_electron_ppar = true`). --- moment_kinetics/src/time_advance.jl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/moment_kinetics/src/time_advance.jl b/moment_kinetics/src/time_advance.jl index b9d85420d..57ac3167e 100644 --- a/moment_kinetics/src/time_advance.jl +++ b/moment_kinetics/src/time_advance.jl @@ -3530,7 +3530,17 @@ end nl_solver_params.electron_advance, max_electron_pdf_iterations, max_electron_sim_time; ion_dt=dt) + + # Update `fvec_out.electron_ppar` with the new electron pressure + begin_r_z_region() + fvec_out_electron_ppar = fvec_out.electron_ppar + moments_electron_ppar = moments.electron.ppar + @loop_r_z ir iz begin + fvec_out_electron_ppar[iz,ir] = moments_electron_ppar[iz,ir] + end + success = (electron_success == "") + elseif advance.electron_conduction success = implicit_braginskii_conduction!(fvec_out, fvec_in, moments, z, r, dt, z_spectral, composition, collisions, From 692244f1ebc555fab00ff7c2c0ab0048b1dea0af Mon Sep 17 00:00:00 2001 From: John Omotani Date: Fri, 18 Oct 2024 09:18:08 +0100 Subject: [PATCH 2/5] Kinetic electron example in periodic z-domain Maybe useful for testing. --- ...tails-compressed-z4-PareschiRusso2222.toml | 152 ++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 examples/kinetic-electrons/nonuniform_periodic_split3_kinetic-coarse-tails-compressed-z4-PareschiRusso2222.toml diff --git a/examples/kinetic-electrons/nonuniform_periodic_split3_kinetic-coarse-tails-compressed-z4-PareschiRusso2222.toml b/examples/kinetic-electrons/nonuniform_periodic_split3_kinetic-coarse-tails-compressed-z4-PareschiRusso2222.toml new file mode 100644 index 000000000..0a18a3aba --- /dev/null +++ b/examples/kinetic-electrons/nonuniform_periodic_split3_kinetic-coarse-tails-compressed-z4-PareschiRusso2222.toml @@ -0,0 +1,152 @@ +[evolve_moments] +parallel_pressure = true +density = true +moments_conservation = true +parallel_flow = true + +[reactions] +electron_ionization_frequency = 0.0 +ionization_frequency = 0.5 +charge_exchange_frequency = 0.75 + +[r] +ngrid = 1 +nelement = 1 + +[z] +ngrid = 5 +discretization = "gausslegendre_pseudospectral" +nelement = 32 +#nelement_local = 4 +bc = "periodic" +element_spacing_option = "compressed_4" + +[vpa] +ngrid = 6 +discretization = "gausslegendre_pseudospectral" +nelement = 31 +L = 30.0 +element_spacing_option = "coarse_tails" +bc = "zero" + +[vz] +ngrid = 6 +discretization = "gausslegendre_pseudospectral" +nelement = 31 +L = 36.0 +element_spacing_option = "coarse_tails" +bc = "zero" + +[composition] +T_e = 0.2 +electron_physics = "kinetic_electrons" +n_ion_species = 1 +n_neutral_species = 1 + +[ion_species_1] +initial_temperature = 0.2 +initial_density = 1.0 + +[z_IC_ion_species_1] +initialization_option = "sinusoid" +density_amplitude = 0.0 #0.2 +temperature_amplitude = 0.3 +density_phase = 0.0 +upar_amplitude = 0.0 #0.1 +temperature_phase = 1.0 +upar_phase = 2.0 + +[vpa_IC_ion_species_1] +initialization_option = "gaussian" +density_amplitude = 1.0 +temperature_amplitude = 0.0 +density_phase = 0.0 +upar_amplitude = 0.0 +temperature_phase = 0.0 +upar_phase = 0.0 + +[neutral_species_1] +initial_temperature = 0.2 +initial_density = 1.0 + +[z_IC_neutral_species_1] +initialization_option = "sinusoid" +temperature_amplitude = 0.0 +density_amplitude = 0.0 +density_phase = 0.0 +upar_amplitude = 0.0 +temperature_phase = 0.0 +upar_phase = 0.0 + +[vz_IC_neutral_species_1] +initialization_option = "gaussian" +density_amplitude = 1.0 +temperature_amplitude = 0.0 +density_phase = 0.0 +upar_amplitude = 0.0 +temperature_phase = 0.0 +upar_phase = 0.0 + +[krook_collisions] +use_krook = true + +[timestepping] +type = "PareschiRusso2(2,2,2)" +implicit_electron_advance = false +implicit_electron_ppar = true +implicit_ion_advance = false +implicit_vpa_advection = false +nstep = 100000 +dt = 1.0e-5 +nwrite = 1000 +nwrite_dfns = 1000 +steady_state_residual = true +converged_residual_value = 1.0e-3 + +#write_after_fixed_step_count = true +#nstep = 1 +#nwrite = 1 +#nwrite_dfns = 1 + +[electron_timestepping] +nstep = 5000000 +#nstep = 1 +dt = 2.0e-8 +#maximum_dt = 1.0e-8 +nwrite = 10 #10000 +nwrite_dfns = 10 #100000 +#type = "SSPRK4" +type = "Fekete4(3)" +rtol = 1.0e-3 +atol = 1.0e-14 +minimum_dt = 1.0e-9 +decrease_dt_iteration_threshold = 100 +increase_dt_iteration_threshold = 20 +cap_factor_ion_dt = 5.0 +initialization_residual_value = 2.5 +converged_residual_value = 1.0e-2 + +#debug_io = 1 + +[nonlinear_solver] +nonlinear_max_iterations = 100 +rtol = 1.0e-6 #1.0e-8 +atol = 1.0e-14 #1.0e-16 +linear_restart = 5 +preconditioner_update_interval = 100 + +[ion_numerical_dissipation] +#vpa_dissipation_coefficient = 1.0e-1 +#vpa_dissipation_coefficient = 1.0e-2 +#vpa_dissipation_coefficient = 1.0e-3 +force_minimum_pdf_value = 0.0 + +[electron_numerical_dissipation] +#vpa_dissipation_coefficient = 2.0 +force_minimum_pdf_value = 0.0 + +[neutral_numerical_dissipation] +#vz_dissipation_coefficient = 1.0e-1 +#vz_dissipation_coefficient = 1.0e-2 +#vz_dissipation_coefficient = 1.0e-3 +force_minimum_pdf_value = 0.0 From 8f3c67510f33da6fbc14a80d0c62e83eb99ea5d0 Mon Sep 17 00:00:00 2001 From: John Omotani Date: Sat, 19 Oct 2024 10:59:27 +0100 Subject: [PATCH 3/5] Restrict some status printouts to rank-0 --- moment_kinetics/src/electron_kinetic_equation.jl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/moment_kinetics/src/electron_kinetic_equation.jl b/moment_kinetics/src/electron_kinetic_equation.jl index 61380097b..7359576e2 100644 --- a/moment_kinetics/src/electron_kinetic_equation.jl +++ b/moment_kinetics/src/electron_kinetic_equation.jl @@ -1029,7 +1029,7 @@ function electron_backward_euler!(scratch, pdf, moments, phi, collisions, compos end if nl_solver_params.solves_since_precon_update[] ≥ nl_solver_params.preconditioner_update_interval -println("recalculating precon") +global_rank[] == 0 && println("recalculating precon") nl_solver_params.solves_since_precon_update[] = 0 nl_solver_params.precon_dt[] = t_params.dt[] @@ -1335,26 +1335,26 @@ println("recalculating precon") if t_params.dt[] < t_params.previous_dt[] # Had to decrease timestep on the first step to get convergence, # so start next ion timestep with the decreased value. - print("decreasing previous_dt due to failures ", t_params.previous_dt[]) + global_rank[] == 0 && print("decreasing previous_dt due to failures ", t_params.previous_dt[]) t_params.previous_dt[] = t_params.dt[] - println(" -> ", t_params.previous_dt[]) + global_rank[] == 0 && println(" -> ", t_params.previous_dt[]) #elseif nl_solver_params.max_linear_iterations_this_step[] > max(0.4 * nl_solver_params.nonlinear_max_iterations, 5) elseif nl_solver_params.max_linear_iterations_this_step[] > t_params.decrease_dt_iteration_threshold # Step succeeded, but took a lot of iterations so decrease initial # step size. - print("decreasing previous_dt due to iteration count ", t_params.previous_dt[]) + global_rank[] == 0 && print("decreasing previous_dt due to iteration count ", t_params.previous_dt[]) t_params.previous_dt[] /= t_params.max_increase_factor - println(" -> ", t_params.previous_dt[]) + global_rank[] == 0 && println(" -> ", t_params.previous_dt[]) #elseif nl_solver_params.max_linear_iterations_this_step[] < max(0.1 * nl_solver_params.nonlinear_max_iterations, 2) elseif nl_solver_params.max_linear_iterations_this_step[] < t_params.increase_dt_iteration_threshold && (ion_dt === nothing || t_params.previous_dt[] < t_params.cap_factor_ion_dt * ion_dt) # Only took a few iterations, so increase initial step size. - print("increasing previous_dt due to iteration count ", t_params.previous_dt[]) + global_rank[] == 0 && print("increasing previous_dt due to iteration count ", t_params.previous_dt[]) if ion_dt === nothing t_params.previous_dt[] *= t_params.max_increase_factor else t_params.previous_dt[] = min(t_params.previous_dt[] * t_params.max_increase_factor, t_params.cap_factor_ion_dt * ion_dt) end - println(" -> ", t_params.previous_dt[]) + global_rank[] == 0 && println(" -> ", t_params.previous_dt[]) end end From ee6cdecb0e10b3aa90b10deb3e3721f3d3ad561b Mon Sep 17 00:00:00 2001 From: John Omotani Date: Wed, 23 Oct 2024 11:11:14 +0100 Subject: [PATCH 4/5] Update the kinetic electron test with fixed electron_ppar update --- .../test/kinetic_electron_tests.jl | 148 +++++++++--------- 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/moment_kinetics/test/kinetic_electron_tests.jl b/moment_kinetics/test/kinetic_electron_tests.jl index 723da1be2..6a41a2c2f 100644 --- a/moment_kinetics/test/kinetic_electron_tests.jl +++ b/moment_kinetics/test/kinetic_electron_tests.jl @@ -108,13 +108,13 @@ kinetic_input["timestepping"] = OptionsDict("type" => "PareschiRusso2(2,2,2)", ) kinetic_input["electron_timestepping"] = OptionsDict("nstep" => 5000000, - "dt" => 5.0e-6, + "dt" => 2.0e-5, "nwrite" => 10000, "nwrite_dfns" => 100000, "decrease_dt_iteration_threshold" => 5000, "increase_dt_iteration_threshold" => 0, "cap_factor_ion_dt" => 10.0, - "initialization_residual_value" => 1.0e10, + "initialization_residual_value" => 1.0e0, "converged_residual_value" => 1.0e-1, ) @@ -122,7 +122,7 @@ kinetic_input["nonlinear_solver"] = OptionsDict("nonlinear_max_iterations" => 10 "rtol" => 1.0e-8, "atol" => 1.0e-14, "linear_restart" => 5, - "preconditioner_update_interval" => 100, + "preconditioner_update_interval" => 1000, ) @@ -172,94 +172,94 @@ function run_test() # Regression test # Benchmark data generated in serial on Linux - expected_Ez = [-0.5990683230706185 -0.604849806235434; - -0.4944296396481284 -0.49739671491727844; - -0.30889032954504736 -0.30924318765687464; - -0.2064830747303776 -0.20682475071884582; - -0.21232457328748663 -0.21299072376949116; - -0.18233875912042674 -0.18256905463006085; - -0.16711429522309232 -0.1673112962636778; - -0.16920776495088916 -0.1693227707158167; - -0.1629417555658927 -0.16304933113558318; - -0.16619150334079993 -0.16629539618289285; - -0.15918194883360942 -0.1592799009526323; - -0.14034706409006803 -0.140437217833422; - -0.12602184032280567 -0.12610387949683538; - -0.10928716440800472 -0.10935785133612701; - -0.07053969674257217 -0.07058573063123225; - -0.0249577746169536 -0.024974174596810936; - -2.8327303308330514e-15 -1.441401377024236e-10; - 0.024957774616960776 0.02497417427570905; - 0.07053969674257636 0.07058572965952663; - 0.10928716440799909 0.10935785264749627; - 0.1260218403227975 0.12610388283669527; - 0.1403470640900294 0.1404372197714126; - 0.1591819488336015 0.15927992284761766; - 0.16619150334082114 0.1662953275454769; - 0.16294175556587748 0.1630489871826757; - 0.16920776495090983 0.1693233489685909; - 0.1671142952230893 0.16731075590341918; - 0.1823387591204167 0.1825740389953209; - 0.21232457328753865 0.21297925141919793; - 0.20648307473037922 0.20682690396901446; - 0.3088903295450278 0.30925854110074175; - 0.4944296396481271 0.49731601862961966; - 0.5990683230705801 0.6046564647413697] - expected_vthe = [27.08102229345079 27.08346736523219; - 27.087730258479823 27.089003820908527; - 27.091898844901323 27.09181784480061; - 27.092455021687254 27.092742387764524; - 27.09350739287911 27.094148133125078; - 27.093817059011126 27.093889601910092; - 27.09443981315218 27.094610141036807; - 27.09484177005478 27.094996783801374; - 27.094985914811055 27.0950626278904; - 27.095122128675094 27.09525702879687; - 27.09536357532887 27.09548558966323; - 27.095582117080163 27.095716810823177; - 27.09568783962135 27.09578276803757; - 27.0957775472326 27.095878610625554; - 27.095909169276535 27.09600041573683; - 27.095978269355648 27.096074922150624; - 27.095988166679223 27.096080134292468; - 27.095978269713978 27.096074922508883; - 27.095909171602027 27.096000418062378; - 27.09577755035281 27.095878613746088; - 27.095687838236376 27.095782766652857; - 27.09558211622511 27.095716809968053; - 27.09536353456768 27.09548554890375; - 27.095122105596843 27.095257005693973; - 27.094986093051983 27.09506280663278; - 27.094841563692096 27.094996577040796; - 27.094439553087433 27.094609881510113; - 27.093813728418613 27.09388627063591; - 27.093489818175936 27.094130555874184; - 27.09246140309467 27.092748772044477; - 27.09185903467811 27.09177803239964; - 27.08774827015981 27.089021820036553; - 27.081240668889404 27.0836857414255] + expected_Ez = [-0.5990683230706185 -1.136483186157602; + -0.4944296396481284 -0.9873296990705788; + -0.30889032954504736 -0.6694380824928302; + -0.2064830747303776 -0.4471331690708596; + -0.21232457328748663 -0.423069171542538; + -0.18233875912042674 -0.3586467595624931; + -0.16711429522309232 -0.3018272987758344; + -0.16920776495088916 -0.27814384649305496; + -0.1629417555658927 -0.26124630661090814; + -0.16619150334079993 -0.2572789330163811; + -0.15918194883360942 -0.23720078037362732; + -0.14034706409006803 -0.20520396656341475; + -0.12602184032280567 -0.1827016549071128; + -0.10928716440800472 -0.15808919669899502; + -0.07053969674257217 -0.10137753767917096; + -0.0249577746169536 -0.0358411459260082; + -2.8327303308330514e-15 -2.0803303361189427e-5; + 0.024957774616960776 0.03584490974053962; + 0.07053969674257636 0.1013692898656727; + 0.10928716440799909 0.15807862358546687; + 0.1260218403227975 0.18263049748179466; + 0.1403470640900294 0.20516566362571026; + 0.1591819488336015 0.23711236692241613; + 0.16619150334082114 0.257126146434857; + 0.16294175556587748 0.2609881259705107; + 0.16920776495090983 0.2778978154805798; + 0.1671142952230893 0.3015349192528757; + 0.1823387591204167 0.3585291689672981; + 0.21232457328753865 0.4231179549656996; + 0.20648307473037922 0.44816400221269476; + 0.3088903295450278 0.6716787105435247; + 0.4944296396481271 0.9861165590258743; + 0.5990683230705801 1.1300034111861956] + expected_vthe = [22.64555285302391 22.485481713141688; + 23.763411647653097 23.63281883616836; + 25.26907160117684 25.181703459470448; + 26.17920352818247 26.12461016686916; + 26.514772631426933 26.476018852279974; + 26.798783188585713 26.774387562937218; + 27.202255545479264 27.203662204308202; + 27.50424749120107 27.527732850637264; + 27.630498656270504 27.6642323848215; + 27.748483758260697 27.79134809261204; + 27.933760382468346 27.990808336620802; + 28.08611508251559 28.153978618442775; + 28.14959662643782 28.221734439130564; + 28.207730844115044 28.283677711828023; + 28.28567669896009 28.36634261525836; + 28.32728392065335 28.410489883644782; + 28.331064506972027 28.41437629072209; + 28.32729968986601 28.41050992096321; + 28.285678151542136 28.366352683865195; + 28.207765527709956 28.28373408727703; + 28.149604559462947 28.221771261090687; + 28.086248527111163 28.154158507899695; + 27.933979289064936 27.991103719847732; + 27.74906125092813 27.792046191405188; + 27.631210333523736 27.66508092926101; + 27.505479130159543 27.529115937508752; + 27.20422756527604 27.20578114592589; + 26.801712351383053 26.77740066591359; + 26.517644511297203 26.478915386575462; + 26.18176436913143 26.127099000267552; + 25.26635932097994 25.178676836919877; + 23.756593489029708 23.625697695979085; + 22.64390166090378 22.48400980852866] if expected_Ez == nothing # Error: no expected input provided println("data tested would be: Ez=", Ez) @test false else - @test isapprox(Ez, expected_Ez, rtol=1.0e-7, atol=1.0e-9) + @test elementwise_isapprox(Ez, expected_Ez, rtol=0.0, atol=2.0e-6) end if expected_vthe == nothing # Error: no expected input provided println("data tested would be: vthe=", vthe) @test false else - @test isapprox(vthe, expected_vthe, rtol=2.0e-9, atol=0.0) + @test elementwise_isapprox(vthe, expected_vthe, rtol=1.0e-6, atol=0.0) end # Iteration counts are fairly inconsistent, but it's good to check that they at # least don't unexpectedly increase by an order of magnitude. # Expected iteration count is from a serial run on Linux. - expected_electron_advance_linear_iterations = 11394 - @test electron_advance_linear_iterations < 2.0 * expected_electron_advance_linear_iterations - if !(electron_advance_linear_iterations < 2.0 * expected_electron_advance_linear_iterations) + expected_electron_advance_linear_iterations = 49307 + @test electron_advance_linear_iterations < 2 * expected_electron_advance_linear_iterations + if !(electron_advance_linear_iterations < 2 * expected_electron_advance_linear_iterations) println("electron_advance_linear_iterations=$electron_advance_linear_iterations was greater than twice the expected $expected_electron_advance_linear_iterations.") end end From 1b3662a36745f6002c7875228f8e501dda08f1a3 Mon Sep 17 00:00:00 2001 From: John Omotani Date: Wed, 13 Nov 2024 20:53:49 +0000 Subject: [PATCH 5/5] Increase timeout for parallel tests job Updated kinetic electron test takes a bit longer, so just increase the maximum allowed time for the job. --- .github/workflows/parallel_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/parallel_test.yml b/.github/workflows/parallel_test.yml index 5441dcc82..c767cc6b1 100644 --- a/.github/workflows/parallel_test.yml +++ b/.github/workflows/parallel_test.yml @@ -10,7 +10,7 @@ permissions: jobs: test-ubuntu: runs-on: ubuntu-latest - timeout-minutes: 150 + timeout-minutes: 180 steps: - uses: actions/checkout@v4