Skip to content

Commit

Permalink
Merge pull request #56 from sintefmath/dev
Browse files Browse the repository at this point in the history
2D interpolators, improved composite support, fast constant spacing interpolation
  • Loading branch information
moyner authored Feb 25, 2024
2 parents de6710b + e417ceb commit 7d82c82
Show file tree
Hide file tree
Showing 16 changed files with 390 additions and 83 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Jutul"
uuid = "2b460a1a-8a2b-45b2-b125-b5c536396eb9"
authors = ["Olav Møyner <[email protected]>"]
version = "0.2.23"
version = "0.2.24"

[deps]
AlgebraicMultigrid = "2169fc97-5a83-5252-b627-83903c6c433c"
Expand Down
58 changes: 49 additions & 9 deletions ext/JutulMakieExt/interactive_3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,21 +174,34 @@ function plot_interactive_impl(grid, states;
if length(datakeys) == 0
error("No plottable properties found.")
end
nstates = length(states)

initial_prop = datakeys[1]
state_index = Observable{Int64}(1)
function generate_title(base, ix)
if length(base) == 0
return "Step $(ix[])/$nstates"
else
return "$base step $(ix[])/$nstates"
end
end
fig_title = Observable{String}(generate_title(title, state_index))
row_index = Observable{Int64}(1)
prop_name = Observable{Any}(initial_prop)
transform_name = Observable{String}(transform)
lims = Observable(limits[initial_prop])
menu = Menu(fig, options = datakeys, prompt = initial_prop)
menu_2 = Menu(fig, options = get_valid_rows("$initial_prop"), prompt = "1", width = 60)

nstates = length(states)

function change_index(ix)
tmp = max(min(ix, nstates), 1)
sl_x.selected_index = tmp
function change_index(ix; update_slider = true)
tmp = clamp(ix, 1, nstates)
if update_slider
sl_x.selected_index = tmp
end
state_index[] = tmp
fig_title[] = generate_title(title, state_index)
lims[] = get_limits(menu_cscale.selection[], state_index.val, prop_name.val, row_index.val, states, transform_name[])
return tmp
end

Expand Down Expand Up @@ -216,17 +229,17 @@ function plot_interactive_impl(grid, states;
# point = sl_x.value
on(sl_x.selected_index) do n
val = sl_x.selected_index.val
state_index[] = val
change_index(val, update_slider = false)
end
is_3d = size(pts, 2) == 3
ax_pos = fig[2, 1:3]
if is_3d
ax = Axis3(ax_pos, title = title, aspect = aspect, zreversed = z_is_depth)
ax = Axis3(ax_pos, title = fig_title, aspect = aspect, zreversed = z_is_depth)
if free_cam
Camera3D(ax.scene)
end
else
ax = Axis(ax_pos, title = title)
ax = Axis(ax_pos, title = fig_title)
end
cell_buffer = zeros(number_of_cells(grid))
# Selection of data
Expand Down Expand Up @@ -281,8 +294,8 @@ function plot_interactive_impl(grid, states;
lims[] = get_limits(menu_cscale.selection[], state_index.val, prop_name.val, nextn, states, transform_name[])
end
# Top row
fig[1, :] = top_layout = GridLayout(tellwidth = false)
N_top = 0
fig[1, :] = top_layout = GridLayout(2, 1, tellwidth = false)
N_top = 1

# Alpha map selector
genlabel(l) = Label(fig, l, font = :bold)
Expand Down Expand Up @@ -450,6 +463,33 @@ function plot_interactive_impl(grid, states;
end
N_top += 1

N_mid = 1
top_layout[2, N_mid] = genlabel("View")
N_mid += 1
menu_view = Menu(
top_layout[2, N_mid],
options = ["Default", "XZ", "YZ", "XY"]
)
N_mid += 1
on(menu_view.selection) do s
if s == "XZ"
az = 0.5π
el = 0.0
elseif s == "YZ"
az = 0
el = 0.0
elseif s == "XY"
az = -0.5π
el = 0.5π
elseif s == "Default"
az = 1.275π
el = 0.125π
end
ax.azimuth[] = az
ax.elevation[] = el
end


function loopy()
start = state_index.val
if start == nstates
Expand Down
16 changes: 10 additions & 6 deletions ext/JutulMakieExt/performance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function Jutul.plot_cumulative_solve!(f, allreports, dt = nothing, names = nothi
axis_arg = NamedTuple(),
x_is_time = true,
legend = true,
ministeps = false,
title = nothing,
scatter_points = true,
kwarg...
Expand All @@ -79,8 +80,11 @@ function Jutul.plot_cumulative_solve!(f, allreports, dt = nothing, names = nothi
if first(allreports) isa AbstractDict && haskey(first(allreports), :ministeps)
allreports = [allreports]
end
if ministeps
allreports = map(Jutul.reports_to_ministep_reports, allreports)
end
if isnothing(dt)
dt = report_timesteps(first(allreports))
dt = map(report_timesteps, allreports)
end
r_rep = map(x -> timing_breakdown(x, reduce = false), allreports)
if use_time
Expand Down Expand Up @@ -108,13 +112,13 @@ function Jutul.plot_cumulative_solve!(f, allreports, dt = nothing, names = nothi
ax = Axis(f; xlabel = xl, title = tit, ylabel = yl, axis_arg...)
if cumulative
get_data = x -> cumsum(vcat(0, F(x)))
t = cumsum(vcat(0, dt))/(3600*24*365)
t = map(dt -> cumsum(vcat(0, dt))/(3600*24*365), dt)
else
get_data = x -> F(x)
t = cumsum(dt)/(3600*24*365)
t = map(dt -> cumsum(dt)/(3600*24*365), dt)
end
if !x_is_time
t = eachindex(t)
t = map(t -> eachindex(t), dt)
end
names_missing = isnothing(names)
if names_missing
Expand All @@ -127,14 +131,14 @@ function Jutul.plot_cumulative_solve!(f, allreports, dt = nothing, names = nothi
c = colors[mod(i-1, n_rep)+1]
data_i = get_data(r_rep[i])
push!(alldata, data_i)
lines!(ax, t, data_i,
lines!(ax, t[i], data_i,
label = names[i],
linewidth = linewidth,
color = c,
linestyle = get_linestyle(i);
kwarg...)
if scatter_points
scatter!(ax, t, data_i, color = c)
scatter!(ax, t[i], data_i, color = c)
end
end
if length(r_rep) > 1 && !names_missing && legend
Expand Down
34 changes: 34 additions & 0 deletions src/composite/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,37 @@ function update_primary_variable!(state, p::Pair{Symbol, V}, state_symbol, model
m = composite_submodel(model, label)
update_primary_variable!(state, var, state_symbol, m, dx, w)
end

function set_variable_internal!(vars, model::CompositeModel; kwarg...)
for (k, v) in kwarg
if v isa Pair
# "Right" format for a composite model.
delete_variable!(model, k)
vars[k] = v
else
if haskey(vars, k)
vars[k]::Pair
oldkey, = vars[k]
else
oldkey = missing
end
if ismissing(oldkey)
mkeys = keys(model.system.systems)
if length(mkeys) == 1
oldkey = only(mkeys)
else
throw(ArgumentError("$k is not present in model.\nFor a composite model, this must be specified as a Pair with key as one of $mkeys.\nExample: $k = Pair(:$(first(mkeys)), var)"))
end
end
v::JutulVariables
delete_variable!(model, k)
vars[k] = Pair(oldkey, v)
end
end
end

function get_dependencies(svar::Pair, model::CompositeModel)
k, var = svar
models = model.extra[:models]
return get_dependencies(var, models[k])
end
12 changes: 11 additions & 1 deletion src/core_types/core_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,15 @@ function Base.show(io::IO, t::MIME"text/plain", model::SimulationModel)
end
if f == :secondary_variables
print(io, "\n")
is_pair = pvar isa Pair
if is_pair
pl, pvar = pvar
pl = " ($pl)"
else
pl = ""
end
print_t = Base.typename(typeof(pvar)).wrapper
print(io, " -> $print_t as evaluator")
print(io, " -> $print_t as evaluator$pl")
end
print(io, "\n")
#end
Expand Down Expand Up @@ -414,6 +421,9 @@ function Base.show(io::IO, t::MIME"text/plain", model::SimulationModel)
print(io, "\n")
elseif f == :output_variables
print(io, " $(join(p, ", "))\n\n")
elseif f == :extra
print(io, " $(typeof(p)) with keys: $(keys(p))")
print(io, "\n")
else
print(io, " ")
print(io, p)
Expand Down
5 changes: 5 additions & 0 deletions src/dd/submodels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ Get subvariable of Jutul variable
"""
subvariable(var, map) = var

function subvariable(var::Pair, map)
label, var = var
return Pair(label, subvariable(var, map))
end

partition_variable_slice(v::AbstractVector, partition) = v[partition]
partition_variable_slice(v::AbstractMatrix, partition) = v[:, partition]
partition_variable_slice(v, partition) = v
Loading

4 comments on commit 7d82c82

@moyner
Copy link
Member Author

@moyner moyner commented on 7d82c82 Feb 25, 2024

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 created: JuliaRegistries/General/101633

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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.2.24 -m "<description of version>" 7d82c82007abe9f0ecd70fcba82e026e4481217f
git push origin v0.2.24

@moyner
Copy link
Member Author

@moyner moyner commented on 7d82c82 Feb 25, 2024

Choose a reason for hiding this comment

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

@JuliaRegistrator register

Release notes:

Changes

  • Improvements for composite system
  • Improvements to plotting
  • 2D interpolation support
  • Faster interpolation when spacing is constant

@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/101633

Tagging

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.2.24 -m "<description of version>" 7d82c82007abe9f0ecd70fcba82e026e4481217f
git push origin v0.2.24

Please sign in to comment.