From 13615a68dd1803438fc15fcaede801ddb196c027 Mon Sep 17 00:00:00 2001 From: "Ziyi (Francis) Yin" Date: Fri, 3 Mar 2023 17:02:33 -0500 Subject: [PATCH 1/2] set up initial state --- src/FlowAD/Operators/jutulModeling.jl | 8 ++------ src/FlowAD/Types/jutulState.jl | 4 ++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/FlowAD/Operators/jutulModeling.jl b/src/FlowAD/Operators/jutulModeling.jl index 5210e54..14d253b 100644 --- a/src/FlowAD/Operators/jutulModeling.jl +++ b/src/FlowAD/Operators/jutulModeling.jl @@ -22,14 +22,10 @@ function (S::jutulModeling{D, T})(LogTransmissibilities::AbstractVector{T}, f::j model.models.Reservoir.domain.grid.trans .= Transmissibilities parameters[:Reservoir][:Transmissibilities] = Transmissibilities - if isnothing(state0) - state0 = state0_ - else - state0 = dict(state0) - end + isnothing(state0) || (state0_[:Reservoir] = get_Reservoir_state(state0)) ### simulation - sim, config = setup_reservoir_simulator(model, state0, parameters); + sim, config = setup_reservoir_simulator(model, state0_, parameters); states, report = simulate!(sim, tstep, forces = forces, config = config, max_timestep_cuts = 1000, info_level=info_level); output = jutulStates(states) return output diff --git a/src/FlowAD/Types/jutulState.jl b/src/FlowAD/Types/jutulState.jl index 50bb37b..ae27018 100644 --- a/src/FlowAD/Types/jutulState.jl +++ b/src/FlowAD/Types/jutulState.jl @@ -35,6 +35,10 @@ Pressure(state::jutulSimpleState) = state.state[:Pressure] Saturations(state::jutulSimpleOrMultiModelStates) = vcat([Saturations(state.states[i]) for i = 1:get_nt(state)]...) Pressure(state::jutulSimpleOrMultiModelStates) = vcat([Pressure(state.states[i]) for i = 1:get_nt(state)]...) +get_Reservoir_state(state::jutulState) = state.state[:Reservoir] +get_Reservoir_state(state::jutulSimpleState) = state.state +get_Reservoir_state(state::jutulSimpleOrMultiModelStates) = get_Reservoir_state(state.states[end]) + get_nt(state::jutulSimpleOrMultiModelStates) = length(state.states) get_nn(state::jutulSimpleOrMultiModelState) = length(Saturations(state)) get_nn(state::jutulSimpleOrMultiModelStates) = get_nn(state.states[1]) From 4e9b8011c36587c57afc52b4a82dc5cbaf28d3c2 Mon Sep 17 00:00:00 2001 From: "Ziyi (Francis) Yin" Date: Wed, 8 Mar 2023 13:22:50 -0500 Subject: [PATCH 2/2] add test --- test/test_jutulModeling.jl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/test/test_jutulModeling.jl b/test/test_jutulModeling.jl index 6d46638..6511bc1 100644 --- a/test/test_jutulModeling.jl +++ b/test/test_jutulModeling.jl @@ -20,7 +20,20 @@ end states = S(x, q1) for i = 1:length(states.states) exist_co2 = sum(Saturations(states.states[i]) .* states.states[i].state[:PhaseMassDensities][1,:] .* model.ϕ) * prod(model.d) - inj_co2 = JutulDarcyAD.ρCO2 * q.irate * JutulDarcyAD.day * sum(tstep[1:i]) + inj_co2 = JutulDarcyAD.ρCO2 * q.irate * JutulDarcyAD.day * sum(S.tstep[1:i]) @test isapprox(exist_co2, inj_co2) rtol=1e-3 end end + +@testset "Test mass conservation for well modeling, different injection rates" begin + states = S(x, q) + pre_co2 = sum(Saturations(states.states[end]) .* states.states[end].state[:Reservoir][:PhaseMassDensities][1,:] .* model.ϕ) * prod(model.d) + q2 = jutulForce(q.irate * 0.5, q.loc) + S.tstep ./= 2 + states_end = S(x, q2; state0=states) + for i = 1:length(states_end.states) + exist_co2 = sum(Saturations(states_end.states[i]) .* states_end.states[i].state[:Reservoir][:PhaseMassDensities][1,:] .* model.ϕ) * prod(model.d) + inj_co2 = JutulDarcyAD.ρCO2 * q2.irate * JutulDarcyAD.day * sum(S.tstep[1:i]) + @test isapprox(exist_co2-pre_co2, inj_co2) rtol=1e-3 + end +end