Skip to content

Commit e354cc8

Browse files
authored
Merge pull request #93 from sintefmath/dev
Fix for submodels with varying equations
2 parents 11e27bd + 986fffb commit e354cc8

File tree

4 files changed

+26
-28
lines changed

4 files changed

+26
-28
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Jutul"
22
uuid = "2b460a1a-8a2b-45b2-b125-b5c536396eb9"
33
authors = ["Olav Møyner <[email protected]>"]
4-
version = "0.2.36"
4+
version = "0.2.37"
55

66
[deps]
77
AlgebraicMultigrid = "2169fc97-5a83-5252-b627-83903c6c433c"

src/conservation/conservation.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ flux_type(c::ConservationLaw) = c.flux_type
1010

1111
discretization(e::ConservationLaw) = e.flow_discretization
1212

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

1418
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
1519
# Compute accumulation term

src/dd/submodels.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ function submodel(model::SimulationModel, p_i::AbstractVector; context = model.c
2727
transfer_vars!(new_model.primary_variables, model.primary_variables)
2828
transfer_vars!(new_model.secondary_variables, model.secondary_variables)
2929
transfer_vars!(new_model.parameters, model.parameters)
30-
transfer_vars!(new_model.equations, model.equations)
30+
subr = physical_representation(d_l)
31+
for (k, eq) in model.equations
32+
new_model.equations[k] = subequation(eq, subr, M)
33+
end
3134

3235
new_data_domain = new_model.data_domain
3336
old_data_domain = model.data_domain
@@ -155,6 +158,10 @@ function subvariable(var::Pair, map)
155158
return Pair(label, subvariable(var, map))
156159
end
157160

161+
function subequation(eq, subr, map)
162+
return eq
163+
end
164+
158165
partition_variable_slice(v::AbstractVector, partition) = v[partition]
159166
partition_variable_slice(v::AbstractMatrix, partition) = v[:, partition]
160167
partition_variable_slice(v, partition) = v

src/simulator/simulator.jl

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,15 @@ end
123123
simulate(sim::JutulSimulator, timesteps::AbstractVector; kwarg...) = simulate!(sim, timesteps; kwarg...)
124124

125125
"""
126-
simulate!(sim::JutulSimulator, timesteps::AbstractVector; forces = nothing,
127-
config = nothing,
128-
initialize = true,
129-
restart = nothing,
130-
state0 = nothing,
131-
parameters = nothing,
132-
kwarg...)
126+
simulate!(sim::JutulSimulator, timesteps::AbstractVector;
127+
forces = nothing,
128+
config = nothing,
129+
initialize = true,
130+
restart = nothing,
131+
state0 = nothing,
132+
parameters = nothing,
133+
kwarg...
134+
)
133135
134136
Non-allocating (or perhaps less allocating) version of [`simulate!`](@ref).
135137
@@ -211,34 +213,20 @@ function simulate!(sim::JutulSimulator, timesteps::AbstractVector;
211213
subrep = JUTUL_OUTPUT_TYPE()
212214
subrep[:ministeps] = rep
213215
subrep[:total_time] = t_step
214-
215216
if step_done
216-
217-
if begin
218-
lastrep = rep[end]
219-
if haskey(lastrep, :stopnow) && lastrep[:stopnow]
220-
true
221-
else
222-
false
223-
end end
224-
217+
lastrep = rep[end]
218+
if get(lastrep, :stopnow, false)
219+
# Something inside the solver told us to stop.
225220
subrep[:output_time] = 0.0
226221
push!(reports, subrep)
227222
stopnow = true
228-
229223
else
230-
231224
@tic "output" store_output!(states, reports, step_no, sim, config, subrep, substates = substates)
232-
233225
end
234-
235226
else
236-
237227
subrep[:output_time] = 0.0
238228
push!(reports, subrep)
239-
240229
end
241-
242230
t_elapsed += t_step + subrep[:output_time]
243231

244232
if early_termination
@@ -249,7 +237,6 @@ function simulate!(sim::JutulSimulator, timesteps::AbstractVector;
249237
if stopnow
250238
break
251239
end
252-
253240
end
254241
states, reports = retrieve_output!(sim, states, reports, config, n_solved)
255242
final_simulation_message(sim, p, rec, t_elapsed, reports, timesteps, config, start_date, early_termination)
@@ -302,7 +289,7 @@ function solve_timestep!(sim, dT, forces, max_its, config;
302289
# Onto the next one
303290
done = true
304291
break
305-
elseif haskey(s, :stopnow) && s[:stopnow]
292+
elseif get(s, :stopnow, false)
306293
done = true
307294
break
308295
else

0 commit comments

Comments
 (0)