Skip to content

Commit

Permalink
Merge pull request #93 from sintefmath/dev
Browse files Browse the repository at this point in the history
Fix for submodels with varying equations
  • Loading branch information
moyner authored Aug 31, 2024
2 parents 11e27bd + 986fffb commit e354cc8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 28 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.36"
version = "0.2.37"

[deps]
AlgebraicMultigrid = "2169fc97-5a83-5252-b627-83903c6c433c"
Expand Down
4 changes: 4 additions & 0 deletions src/conservation/conservation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ flux_type(c::ConservationLaw) = c.flux_type

discretization(e::ConservationLaw) = e.flow_discretization

function subequation(eq::ConservationLaw{C, T, FT, N}, subr, M) where {C, T, FT, N}
disc = subdiscretization(discretization(eq), subr, M)
return ConservationLaw(disc, C, N, flux = eq.flux_type)
end

function update_equation_in_entity!(eq_buf::AbstractVector{T_e}, self_cell, state, state0, eq::ConservationLaw, model, Δt, ldisc = local_discretization(eq, self_cell)) where T_e
# Compute accumulation term
Expand Down
9 changes: 8 additions & 1 deletion src/dd/submodels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ function submodel(model::SimulationModel, p_i::AbstractVector; context = model.c
transfer_vars!(new_model.primary_variables, model.primary_variables)
transfer_vars!(new_model.secondary_variables, model.secondary_variables)
transfer_vars!(new_model.parameters, model.parameters)
transfer_vars!(new_model.equations, model.equations)
subr = physical_representation(d_l)
for (k, eq) in model.equations
new_model.equations[k] = subequation(eq, subr, M)
end

new_data_domain = new_model.data_domain
old_data_domain = model.data_domain
Expand Down Expand Up @@ -155,6 +158,10 @@ function subvariable(var::Pair, map)
return Pair(label, subvariable(var, map))
end

function subequation(eq, subr, map)
return eq
end

partition_variable_slice(v::AbstractVector, partition) = v[partition]
partition_variable_slice(v::AbstractMatrix, partition) = v[:, partition]
partition_variable_slice(v, partition) = v
39 changes: 13 additions & 26 deletions src/simulator/simulator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,15 @@ end
simulate(sim::JutulSimulator, timesteps::AbstractVector; kwarg...) = simulate!(sim, timesteps; kwarg...)

"""
simulate!(sim::JutulSimulator, timesteps::AbstractVector; forces = nothing,
config = nothing,
initialize = true,
restart = nothing,
state0 = nothing,
parameters = nothing,
kwarg...)
simulate!(sim::JutulSimulator, timesteps::AbstractVector;
forces = nothing,
config = nothing,
initialize = true,
restart = nothing,
state0 = nothing,
parameters = nothing,
kwarg...
)
Non-allocating (or perhaps less allocating) version of [`simulate!`](@ref).
Expand Down Expand Up @@ -211,34 +213,20 @@ function simulate!(sim::JutulSimulator, timesteps::AbstractVector;
subrep = JUTUL_OUTPUT_TYPE()
subrep[:ministeps] = rep
subrep[:total_time] = t_step

if step_done

if begin
lastrep = rep[end]
if haskey(lastrep, :stopnow) && lastrep[:stopnow]
true
else
false
end end

lastrep = rep[end]
if get(lastrep, :stopnow, false)
# Something inside the solver told us to stop.
subrep[:output_time] = 0.0
push!(reports, subrep)
stopnow = true

else

@tic "output" store_output!(states, reports, step_no, sim, config, subrep, substates = substates)

end

else

subrep[:output_time] = 0.0
push!(reports, subrep)

end

t_elapsed += t_step + subrep[:output_time]

if early_termination
Expand All @@ -249,7 +237,6 @@ function simulate!(sim::JutulSimulator, timesteps::AbstractVector;
if stopnow
break
end

end
states, reports = retrieve_output!(sim, states, reports, config, n_solved)
final_simulation_message(sim, p, rec, t_elapsed, reports, timesteps, config, start_date, early_termination)
Expand Down Expand Up @@ -302,7 +289,7 @@ function solve_timestep!(sim, dT, forces, max_its, config;
# Onto the next one
done = true
break
elseif haskey(s, :stopnow) && s[:stopnow]
elseif get(s, :stopnow, false)
done = true
break
else
Expand Down

2 comments on commit e354cc8

@moyner
Copy link
Member Author

@moyner moyner commented on e354cc8 Aug 31, 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/114255

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.37 -m "<description of version>" e354cc8fb27b82120203aa95ab952cf45e459b06
git push origin v0.2.37

Please sign in to comment.