Skip to content

Commit

Permalink
Fix reduced calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
autocorr committed Sep 27, 2022
1 parent 77a25d5 commit 4a6ae07
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Jadex"
uuid = "302b6ea9-03d1-47d0-b3e6-7bc5ec1c11d5"
authors = ["Brian Svoboda <[email protected]> and contributors"]
version = "0.3.0"
version = "0.3.1"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand All @@ -15,8 +15,8 @@ RecursiveFactorization = "f2c3362d-daeb-58d1-803e-2bc74f2840b4"
[compat]
CSV = "0.10"
DataFrames = "1"
LoopVectorization = "0.12"
Interpolations = "0.14"
LoopVectorization = "0.12"
RecursiveFactorization = "0.2"
julia = "1.7"

Expand Down
5 changes: 4 additions & 1 deletion src/readdata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ end

struct Transitions{F <: Real}
n::Int # number of radiative transitions
id::Vector{Int} # transition ID
iupp::Vector{Int} # upper state
ilow::Vector{Int} # lower state
aeinst::Vector{F} # Einstein A
Expand Down Expand Up @@ -151,13 +152,15 @@ function parse_transitions(lines, levels::EnergyLevels)
work_lines = strip_trailing_fields.(work_lines, 6)
types = [Int, Int, Int, Float64, Float64, Float64]
df = parse_table(work_lines, types)
sort!(df, :Column6) # E_up, low to high
id = df.Column1
iupp = df.Column2
ilow = df.Column3
aeinst = df.Column4
spfreq = df.Column5
eup = df.Column6
xnu = levels.eterm[iupp] .- levels.eterm[ilow]
Transitions(ntran, iupp, ilow, aeinst, spfreq, eup, xnu)
Transitions(ntran, id, iupp, ilow, aeinst, spfreq, eup, xnu)
end


Expand Down
9 changes: 4 additions & 5 deletions src/solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ function solve_rate_eq_reduced!(xpop, yrate, nr)
# Create reduced matrix and add normalized contributions from outside
# levels.
Yr = Y[1:nr+1,1:nr+1] # slicing copies
@inbounds for j = 1:nr, i = 1:nr, k = nr+1:nlev
@turbo for j = 1:nr, i = 1:nr, k = nr+1:nlev
Yr[i,j] += abs(Y[k,j] * Y[i,k] / Y[k,k])
end
# Allocate or create views for reduced RHS and level populations.
Expand All @@ -305,7 +305,7 @@ function solve_rate_eq_reduced!(xpop, yrate, nr)
# Compute cascade for higher excitation lines. This is not accessed
# efficiently, but it appears fixed by the problem (total population
# from all higher states to a given lower state).
@inbounds for k = nr+1:nlev
@turbo for k = nr+1:nlev
xtot = zero(dtype)
for j = 1:nr
xtot += xpop[j] * Y[k,j]
Expand Down Expand Up @@ -521,14 +521,13 @@ fills the beam (i.e., a beam filling fraction of 1).
T_R = \frac{c^2}{2 k \nu^2} \left( I^\mathrm{em}_\nu - I^\mathrm{bg}_\nu \right)
```
"""
function calc_radiation_temperature(
xnu::F, tex::F, τl::F, intens_bg::F) where F <: Real
function calc_radiation_temperature(xnu, tex, τl, intens_bg)
# Black-body intensity in temperature units at the given excitation
# temperature.
bnutex = THC * xnu^3 * (inv expm1)(FK * xnu / tex)
# Emergent intensity
ftau = exp(-τl)
intens_em = intens_bg * ftau + bnutex * (F(1) - ftau)
intens_em = intens_bg * ftau + bnutex * (one(ftau) - ftau)
# Calculate radiation temperature
t_rad = FK / (THC * xnu * xnu) * (intens_em - intens_bg)
t_rad
Expand Down
2 changes: 1 addition & 1 deletion test/profile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function profile_big_grid()
collect(range(0.5, 2.0, N)), # linewidth
[1, 2], # transitions
)
println("Number of threads: $(nthreads())")
@info "Number of threads: $(nthreads())"
@profile begin
rungrid(mol, params...; escprob=rdf.escprob, bg=rdf.bg)
end
Expand Down
2 changes: 1 addition & 1 deletion test/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const RADEX_COLLIDERS = Dict(
const ZERO_DENSITY = Dict(c => 0.0 for c in keys(RADEX_COLLIDERS))


function get_radex_results(name, tkin, density, cdmol, linewidth=1.0, fmin=0.0,
function get_radex_results(name, tkin, density, cdmol, linewidth=1.0; fmin=0.0,
fmax=1e9, geometry=1)
@assert in(geometry, [1,2,3])
molfile = joinpath(DATADIR, "$name.dat")
Expand Down

2 comments on commit 4a6ae07

@autocorr
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/68430

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.1 -m "<description of version>" 4a6ae079fc610f93dbb111c5777c7d081aed3e08
git push origin v0.3.1

Please sign in to comment.