Skip to content

Commit

Permalink
Merge pull request #78 from mabarnes/update-plotting
Browse files Browse the repository at this point in the history
More plot options, runtime plots, unnormalized pdf plots
  • Loading branch information
johnomotani authored Mar 27, 2023
2 parents a08c064 + 52c30df commit 413b3f6
Show file tree
Hide file tree
Showing 18 changed files with 925 additions and 191 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/debug_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ jobs:
- uses: mpi4py/setup-mpi@v1
with:
mpi: 'openmpi'
- uses: actions/setup-python@v2
- uses: julia-actions/setup-julia@v1
with:
version: '1.7'
arch: x64
- uses: julia-actions/julia-buildpkg@v1
env:
# Use the system Python for PyCall - avoids library linking error on macOS
PYTHON: "${{ env.pythonLocation }}/bin/python"
- name: Test examples
run: |
pip3 install --user matplotlib
julia --project -e 'ENV["JULIA_MPI_BINARY"]="system"; using Pkg; Pkg.build("MPI"; verbose=true)'
# Need to use openmpi so that the following arguments work:
# * `--mca rmaps_base_oversubscribe 1` allows oversubscription (more processes
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ jobs:
with:
version: '1'
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
run: |
pip3 install --user matplotlib
julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- name: Build and deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Authenticate with GitHub Actions token
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ jobs:

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: julia-actions/setup-julia@v1
with:
version: '1.7'
arch: x64
- uses: julia-actions/julia-buildpkg@v1
env:
# Use the system Python for PyCall - avoids library linking error on macOS
PYTHON: "${{ env.pythonLocation }}/bin/python"
- name: Test examples
run: |
pip3 install --user matplotlib
julia --project -O3 -e 'using moment_kinetics; for (root, dirs, files) in walkdir("examples") for file in files if endswith(file, ".toml") println(joinpath(root, file)); run_moment_kinetics(joinpath(root, file)) end end end'
5 changes: 5 additions & 0 deletions .github/workflows/longtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@ jobs:

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: julia-actions/setup-julia@v1
with:
version: '1.7'
arch: x64
- uses: julia-actions/julia-buildpkg@v1
env:
# Use the system Python for PyCall - avoids library linking error on macOS
PYTHON: "${{ env.pythonLocation }}/bin/python"
# The following is copied and simplified from
# https://github.com/julia-actions/julia-runtest/blob/master/action.yml
# in order to pass customised arguments to `Pkg.test()`
#
- run: |
pip3 install --user matplotlib
julia --check-bounds=yes --color=yes --depwarn=yes --inline=yes --project=@. -e 'import Pkg; Pkg.test(; coverage = :true, test_args=["--long"])'
shell: bash
5 changes: 5 additions & 0 deletions .github/workflows/parallel_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ jobs:
- uses: mpi4py/setup-mpi@v1
with:
mpi: 'openmpi'
- uses: actions/setup-python@v2
- uses: julia-actions/setup-julia@v1
with:
version: '1.7'
arch: x64
- uses: julia-actions/julia-buildpkg@v1
env:
# Use the system Python for PyCall - avoids library linking error on macOS
PYTHON: "${{ env.pythonLocation }}/bin/python"
- run: |
pip3 install --user matplotlib
julia --project -e 'ENV["JULIA_MPI_BINARY"]="system"; using Pkg; Pkg.build("MPI"; verbose=true)'
julia -O3 --check-bounds=no precompile.jl --debug 1
# Need to use openmpi so that the following arguments work:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ jobs:

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: julia-actions/setup-julia@v1
with:
version: '1.7'
arch: x64
- uses: julia-actions/julia-buildpkg@v1
env:
# Use the system Python for PyCall - avoids library linking error on macOS
PYTHON: "${{ env.pythonLocation }}/bin/python"
- run: |
pip3 install --user matplotlib
- uses: julia-actions/julia-runtest@v1
50 changes: 34 additions & 16 deletions Manifest.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is machine-generated - editing it directly is not advised

julia_version = "1.7.0"
julia_version = "1.7.2"
manifest_format = "2.0"

[[deps.AbstractFFTs]]
Expand Down Expand Up @@ -50,9 +50,9 @@ version = "0.1.1"

[[deps.Cairo_jll]]
deps = ["Artifacts", "Bzip2_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "JLLWrappers", "LZO_jll", "Libdl", "Pixman_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Zlib_jll", "libpng_jll"]
git-tree-sha1 = "f2202b55d816427cd385a9a4f3ffb226bee80f99"
git-tree-sha1 = "4b859a208b2397a7a623a03449e4636bdb17bcf2"
uuid = "83423d85-b0ee-5818-9007-b63ccbeb887a"
version = "1.16.1+0"
version = "1.16.1+1"

[[deps.ChainRulesCore]]
deps = ["Compat", "LinearAlgebra", "SparseArrays"]
Expand Down Expand Up @@ -324,9 +324,9 @@ version = "0.21.0+0"

[[deps.Glib_jll]]
deps = ["Artifacts", "Gettext_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Libiconv_jll", "Libmount_jll", "PCRE_jll", "Pkg", "Zlib_jll"]
git-tree-sha1 = "7bf67e9a481712b3dbe9cb3dac852dc4b1162e02"
git-tree-sha1 = "a32d672ac2c967f3deb8a81d828afc739c838a06"
uuid = "7746bdde-850d-59dc-9ae8-88ece973131d"
version = "2.68.3+0"
version = "2.68.3+2"

[[deps.Glob]]
git-tree-sha1 = "4df9f7e06108728ebf00a0a11edee4b29a482bb2"
Expand Down Expand Up @@ -358,9 +358,9 @@ version = "0.9.17"

[[deps.HarfBuzz_jll]]
deps = ["Artifacts", "Cairo_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "Graphite2_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Pkg"]
git-tree-sha1 = "8a954fed8ac097d5be04921d595f741115c1b2ad"
git-tree-sha1 = "129acf094d168394e80ee1dc4bc06ec835e510a3"
uuid = "2e76f6c2-a576-52d4-95c1-20adfe4de566"
version = "2.8.1+0"
version = "2.8.1+1"

[[deps.IJulia]]
deps = ["Base64", "Conda", "Dates", "InteractiveUtils", "JSON", "Libdl", "Markdown", "MbedTLS", "Pkg", "Printf", "REPL", "Random", "SoftGlobalScope", "Test", "UUIDs", "ZMQ"]
Expand Down Expand Up @@ -440,6 +440,12 @@ git-tree-sha1 = "f6250b16881adf048549549fba48b1161acdac8c"
uuid = "c1c5ebd0-6772-5130-a774-d5fcae4a789d"
version = "3.100.1+0"

[[deps.LERC_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "bf36f528eec6634efc60d7ec062008f171071434"
uuid = "88015f11-f218-50d7-93a8-a6af411a945d"
version = "3.0.0+1"

[[deps.LZO_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "e5b909bcf985c5e2605737d2ce278ed791b89be6"
Expand Down Expand Up @@ -517,10 +523,10 @@ uuid = "4b2f31a3-9ecc-558c-b454-b3730dcb73e9"
version = "2.35.0+0"

[[deps.Libtiff_jll]]
deps = ["Artifacts", "JLLWrappers", "JpegTurbo_jll", "Libdl", "Pkg", "Zlib_jll", "Zstd_jll"]
git-tree-sha1 = "340e257aada13f95f98ee352d316c3bed37c8ab9"
deps = ["Artifacts", "JLLWrappers", "JpegTurbo_jll", "LERC_jll", "Libdl", "Pkg", "Zlib_jll", "Zstd_jll"]
git-tree-sha1 = "c9551dd26e31ab17b86cbd00c2ede019c08758eb"
uuid = "89763e89-9b03-5906-acba-b20f662cd828"
version = "4.3.0+0"
version = "4.3.0+1"

[[deps.Libuuid_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
Expand Down Expand Up @@ -647,9 +653,9 @@ uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"

[[deps.Ogg_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "7937eda4681660b4d6aeeecc2f7e1c81c8ee4e2f"
git-tree-sha1 = "887579a3eb005446d514ab7aeac5d1d027658b8f"
uuid = "e7412a2a-1a6e-54c0-be00-318e2571c051"
version = "1.3.5+0"
version = "1.3.5+1"

[[deps.OpenBLAS_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
Expand Down Expand Up @@ -761,11 +767,23 @@ version = "0.5.0"
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[deps.PyCall]]
deps = ["Conda", "Dates", "Libdl", "LinearAlgebra", "MacroTools", "Serialization", "VersionParsing"]
git-tree-sha1 = "53b8b07b721b77144a0fbbbc2675222ebf40a02d"
uuid = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
version = "1.94.1"

[[deps.PyPlot]]
deps = ["Colors", "LaTeXStrings", "PyCall", "Sockets", "Test", "VersionParsing"]
git-tree-sha1 = "f9d953684d4d21e947cb6d642db18853d43cb027"
uuid = "d330b81b-6aea-500a-939a-2ce795aea3ee"
version = "2.11.0"

[[deps.Qt5Base_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Fontconfig_jll", "Glib_jll", "JLLWrappers", "Libdl", "Libglvnd_jll", "OpenSSL_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libxcb_jll", "Xorg_xcb_util_image_jll", "Xorg_xcb_util_keysyms_jll", "Xorg_xcb_util_renderutil_jll", "Xorg_xcb_util_wm_jll", "Zlib_jll", "xkbcommon_jll"]
git-tree-sha1 = "ad368663a5e20dbb8d6dc2fddeefe4dae0781ae8"
git-tree-sha1 = "c6c0f690d0cc7caddb74cef7aa847b824a16b256"
uuid = "ea2cea3b-5b76-57ae-a6ef-0a8af62496e1"
version = "5.15.3+0"
version = "5.15.3+1"

[[deps.QuadGK]]
deps = ["DataStructures", "LinearAlgebra"]
Expand Down Expand Up @@ -1189,9 +1207,9 @@ version = "1.0.20+0"

[[deps.libvorbis_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Ogg_jll", "Pkg"]
git-tree-sha1 = "c45f4e40e7aafe9d086379e5578947ec8b95a8fb"
git-tree-sha1 = "b910cb81ef3fe6e78bf6acee440bda86fd6ae00c"
uuid = "f27f6e37-5d2b-51aa-960f-b287f2bc3b7a"
version = "1.3.7+0"
version = "1.3.7+1"

[[deps.nghttp2_jll]]
deps = ["Artifacts", "Libdl"]
Expand Down
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
PackageCompiler = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
Expand Down
3 changes: 2 additions & 1 deletion debug_test/sound_wave_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ test_input_chebyshev_split_2_moments =
test_input_chebyshev_split_3_moments =
merge(test_input_chebyshev_split_2_moments,
Dict("run_name" => "chebyshev_pseudospectral_split_3_moments",
"evolve_moments_parallel_pressure" => true))
"evolve_moments_parallel_pressure" => true,
"runtime_plots" => true))


"""
Expand Down
20 changes: 17 additions & 3 deletions src/analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ end

"""
"""
function analyze_moments_data(density, parallel_flow, parallel_pressure, parallel_heat_flux, ntime, n_species, nz, z_wgts, Lz)
function analyze_moments_data(density, parallel_flow, parallel_pressure, thermal_speed,
parallel_heat_flux, ntime, n_species, nz, z_wgts, Lz)
print("Analyzing velocity moments data...")
density_fldline_avg = allocate_float(n_species, ntime)
for is 1:n_species
Expand All @@ -49,6 +50,12 @@ function analyze_moments_data(density, parallel_flow, parallel_pressure, paralle
ppar_fldline_avg[is,i] = field_line_average(view(parallel_pressure,:,is,i), z_wgts, Lz)
end
end
vth_fldline_avg = allocate_float(n_species, ntime)
for is 1:n_species
for i 1:ntime
vth_fldline_avg[is,i] = field_line_average(view(thermal_speed,:,is,i), z_wgts, Lz)
end
end
qpar_fldline_avg = allocate_float(n_species, ntime)
for is 1:n_species
for i 1:ntime
Expand Down Expand Up @@ -76,6 +83,13 @@ function analyze_moments_data(density, parallel_flow, parallel_pressure, paralle
@. delta_ppar[iz,is,:] = parallel_pressure[iz,is,:] - ppar_fldline_avg[is,:]
end
end
# delta_vth = vth_s - <vth_s> is the fluctuating thermal_speed
delta_vth = allocate_float(nz,n_species,ntime)
for is 1:n_species
for iz 1:nz
@. delta_vth[iz,is,:] = thermal_speed[iz,is,:] - vth_fldline_avg[is,:]
end
end
# delta_qpar = qpar_s - <qpar_s> is the fluctuating parallel heat flux
delta_qpar = allocate_float(nz,n_species,ntime)
for is 1:n_species
Expand All @@ -84,8 +98,8 @@ function analyze_moments_data(density, parallel_flow, parallel_pressure, paralle
end
end
println("done.")
return density_fldline_avg, upar_fldline_avg, ppar_fldline_avg, qpar_fldline_avg,
delta_density, delta_upar, delta_ppar, delta_qpar
return density_fldline_avg, upar_fldline_avg, ppar_fldline_avg, vth_fldline_avg, qpar_fldline_avg,
delta_density, delta_upar, delta_ppar, delta_vth, delta_qpar
end

"""
Expand Down
27 changes: 21 additions & 6 deletions src/file_io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ end
open the necessary output files
"""
function setup_file_io(output_dir, run_name, vpa, z, r, composition,
collisions, evolve_ppar)
collisions, evolve_density, evolve_upar, evolve_ppar)
begin_serial_region()
@serial_region begin
# Only read/write from first process in each 'block'
Expand All @@ -69,7 +69,7 @@ function setup_file_io(output_dir, run_name, vpa, z, r, composition,
mom_io = open_output_file(out_prefix, "moments_vs_t")
fields_io = open_output_file(out_prefix, "fields_vs_t")
cdf = setup_netcdf_io(out_prefix, r, z, vpa, composition, collisions,
evolve_ppar)
evolve_density, evolve_upar, evolve_ppar)
#return ios(ff_io, mom_io, fields_io), cdf
return ios(mom_io, fields_io), cdf
end
Expand Down Expand Up @@ -110,11 +110,11 @@ function define_dimensions!(fid, nvpa, nz, nr, n_species, n_ion_species=nothing,
end

"""
define_static_variables!(vpa,vperp,z,r,composition,collisions,evolve_ppar)
define_static_variables!(vpa,vperp,z,r,composition,collisions,evolve_density,evolve_upar,evolve_ppar)
Define static (i.e. time-independent) variables for an output file.
"""
function define_static_variables!(fid,vpa,z,r,composition,collisions,evolve_ppar)
function define_static_variables!(fid,vpa,z,r,composition,collisions,evolve_density,evolve_upar,evolve_ppar)
# create and write the "r" variable to file
varname = "r"
attributes = Dict("description" => "radial coordinate")
Expand Down Expand Up @@ -168,6 +168,20 @@ function define_static_variables!(fid,vpa,z,r,composition,collisions,evolve_ppar
vartype = mk_float
var = defVar(fid, varname, vartype, dims, attrib=attributes)
var[:] = collisions.charge_exchange
# create and write the "evolve_density" variable to file
varname = "evolve_density"
attributes = Dict("description" => "flag indicating if the density is separately evolved")
vartype = mk_int
dims = ("n_species",)
var = defVar(fid, varname, vartype, dims, attrib=attributes)
var[:] = evolve_density
# create and write the "evolve_upar" variable to file
varname = "evolve_upar"
attributes = Dict("description" => "flag indicating if the parallel flow is separately evolved")
vartype = mk_int
dims = ("n_species",)
var = defVar(fid, varname, vartype, dims, attrib=attributes)
var[:] = evolve_upar
# create and write the "evolve_ppar" variable to file
varname = "evolve_ppar"
attributes = Dict("description" => "flag indicating if the parallel pressure is separately evolved")
Expand Down Expand Up @@ -240,7 +254,8 @@ end
"""
setup file i/o for netcdf
"""
function setup_netcdf_io(prefix, r, z, vpa, composition, collisions, evolve_ppar)
function setup_netcdf_io(prefix, r, z, vpa, composition, collisions, evolve_density,
evolve_upar, evolve_ppar)
# the netcdf file will be given by output_dir/run_name with .cdf appended
filename = string(prefix,".cdf")
# if a netcdf file with the requested name already exists, remove it
Expand All @@ -253,7 +268,7 @@ function setup_netcdf_io(prefix, r, z, vpa, composition, collisions, evolve_ppar
define_dimensions!(fid, vpa.n, z.n, r.n, composition.n_species,
composition.n_ion_species, composition.n_neutral_species)
### create and write static variables to file ###
define_static_variables!(fid,vpa,z,r,composition,collisions,evolve_ppar)
define_static_variables!(fid,vpa,z,r,composition,collisions,evolve_density,evolve_upar,evolve_ppar)
### create variables for time-dependent quantities and store them ###
### in a struct for later access ###
cdf_time, cdf_f, cdf_phi, cdf_density, cdf_upar, cdf_ppar, cdf_qpar, cdf_vth =
Expand Down
14 changes: 13 additions & 1 deletion src/input_structs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct time_input
use_semi_lagrange::Bool
n_rk_stages::mk_int
split_operators::Bool
runtime_plots::Bool
end

"""
Expand Down Expand Up @@ -261,6 +262,8 @@ struct pp_input
plot_upar0_vs_t::Bool
# if plot_ppar0_vs_t = true, create plots of species ppar(z0) vs time
plot_ppar0_vs_t::Bool
# if plot_vth0_vs_t = true, create plots of species vth(z0) vs time
plot_vth0_vs_t::Bool
# if plot_qpar0_vs_t = true, create plots of species qpar(z0) vs time
plot_qpar0_vs_t::Bool
# if plot_dens_vs_z_t = true, create plot of species density vs z and time
Expand All @@ -275,8 +278,17 @@ struct pp_input
animate_dens_vs_z::Bool
# if animate_upar_vs_z = true, create animation of species parallel flow vs z at different time slices
animate_upar_vs_z::Bool
# if animate_f_vs_z_vpa = true, create animation of f(z,vpa) at different time slices
# if animate_ppar_vs_z = true, create animation of species parallel pressure vs z at different time slices
animate_ppar_vs_z::Bool
# if animate_vth_vs_z = true, create animation of species thermal speed vs z at different time slices
animate_vth_vs_z::Bool
# if animate_qpar_vs_z = true, create animation of species parallel heat flux vs z at different time slices
animate_qpar_vs_z::Bool
# if animate_f_vs_vpa_z = true, create animation of f(z,vpa) at different time slices
animate_f_vs_vpa_z::Bool
# if animate_f_unnormalized = true, create animation of
# f_unnorm(v_parallel_unnorm,z) at different time slices
animate_f_unnormalized::Bool
# if animate_f_vs_z_vpa0 = true, create animation of f(z,vpa0) at different time slices
animate_f_vs_vpa0_z::Bool
# if animate_f_vs_z0_vpa = true, create animation of f(z0,vpa) at different time slices
Expand Down
Loading

0 comments on commit 413b3f6

Please sign in to comment.