Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read neutron rate output file #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/runtests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: CI

on:
push:
branches:
- master
pull_request:

jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- "1.x"
os:
- ubuntu-latest
arch:
- x64

steps:
- uses: actions/checkout@v4

- uses: julia-actions/setup-julia@latest

- uses: julia-actions/cache@v1

- name: Add FuseRegistry
run: |
rm -rf ~/.julia/registries/FuseRegistry
julia -e 'using Pkg; Pkg.Registry.add(RegistrySpec(url="https://github.com/ProjectTorreyPines/FuseRegistry.jl.git")); Pkg.Registry.add("General"); Pkg.Registry.update()'

- name: Replace [email protected] with https in Package.toml files
run: |
find ~/.julia/registries/FuseRegistry -type f -name 'Package.toml' -exec sed -i 's|[email protected]:|https://project-torrey-pines:${{secrets.PTP_READ_TOKEN}}@github.com/|g' {} +

- name: Install dependencies
run: |
julia -e '
using Pkg
Pkg.develop(PackageSpec(path=pwd()))
Pkg.instantiate()
'

- uses: julia-actions/julia-buildpkg@v1

- uses: julia-actions/julia-runtest@v1
31 changes: 22 additions & 9 deletions src/outputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ Base.@kwdef mutable struct RABBIToutput
torqdepo_data::Union{Array{<:Real},Missing} = missing
rho_data::Union{Vector{<:Real},Missing} = missing
time_data::Union{Vector{<:Real},Missing} = missing
nrate_data::Union{Array{<:Real}, Missing} = missing

end

function read_outputs(path::String; filename::String ="run")
struct_len = 4
result_path = abspath(joinpath(path, "$filename/beam1/rtfi_result_oav.bin"))
nrate_path = abspath(joinpath(path, "$filename/rtfi_nrate_oav.bin"))

output = RABBIToutput()

function read_and_reshape(f, element_count; dims)
data = Float64[struct_unpack(read(f, struct_len)) for _ in 1:element_count]
return reshape(data, dims)
end

open(string(result_path), "r") do f
seekend(f)
Expand All @@ -28,11 +35,6 @@ function read_outputs(path::String; filename::String ="run")
output.time_data = Float64[struct_unpack(read(f, struct_len)) for _ in 1:ntime]
output.rho_data = Float64[struct_unpack(read(f, struct_len)) for _ in 1:nrho]

function read_and_reshape(f, element_count; dims)
data = Float64[struct_unpack(read(f, struct_len)) for _ in 1:element_count]
return reshape(data, dims)
end

bdens_data = read_and_reshape(f, nrho * ntime, dims=(nrho, ntime))
press_data = read_and_reshape(f, nrho * ntime, dims=(nrho, ntime))
output.powe_data = read_and_reshape(f, nrho * ntime, dims=(nrho, ntime))
Expand Down Expand Up @@ -61,11 +63,22 @@ function read_outputs(path::String; filename::String ="run")
dArea = read_and_reshape(f, nrho * ntime, dims=(nrho, ntime))
output.torqdepo_data = read_and_reshape(f, nrho * nv * ntime, dims=(nrho, ntime, nv))
torqjxb_data = read_and_reshape(f, nrho * nv * ntime, dims=(nrho, ntime, nv))

return output


break
end
end
end
end

open(string(nrate_path), "r") do f
seekstart(f)

nrho = length(output.rho_data)
ntime = length(output.time_data)
while !eof(f)
output.nrate_data = read_and_reshape(f, nrho * ntime, dims = (nrho, ntime))
end
end

return output

end
2 changes: 2 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[deps]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Binary file added test/run/beam1/rtfi_result_oav.bin
Binary file not shown.
Binary file added test/run/rtfi_nrate_oav.bin
Binary file not shown.
17 changes: 17 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using RABBIT
using Test

@testset "RABBIT" begin

works = try
output = RABBIT.read_outputs(@__DIR__)
@test isapprox(output.powe_data[:,1][1], 208692, rtol=0.10)
@test isapprox(output.powi_data[:,1][1], 482856, rtol=0.10)
@test isapprox(output.torqdepo_data[:, :, 1][1], 0.20518352, rtol=0.10)
@test isapprox(output.nrate_data[:, :, 1][1], 29.10558, rtol=0.10)
true
catch
false
end
@test works==true
end
Loading