Skip to content

Quarter-five-spot example

The quarter-five-spot is a standard test problem that simulates 1/4 of the five spot well pattern by assuming axial symmetry. The problem contains an injector in one corner and the producer in the opposing corner, with a significant volume of fluids injected into the domain.

julia
using JutulDarcy, Jutul
nx = 50;

Setup

We define a function that, for a given porosity field, computes a solution with an estimated permeability field. For assumptions and derivation of the specific form of the Kozeny-Carman relation used in this example, see Lie, Knut-Andreas. An introduction to reservoir simulation using MATLAB/GNU Octave: User guide for the MATLAB Reservoir Simulation Toolbox (MRST). Cambridge University Press, 2019, Section 2.5.2

julia
function perm_kozeny_carman(Φ)
    return ((Φ^3)*(1e-5)^2)/(0.81*72*(1-Φ)^2);
end

function simulate_qfs(porosity = 0.2)
    Dx = 1000.0
    Dz = 10.0
    Darcy = 9.869232667160130e-13
    Darcy, bar, kg, meter, Kelvin, day, sec = si_units(:darcy, :bar, :kilogram, :meter, :Kelvin, :day, :second)

    mesh = CartesianMesh((nx, nx, 1), (Dx, Dx, Dz))
    K = perm_kozeny_carman.(porosity)
    domain = reservoir_domain(mesh, permeability = K, porosity = porosity)
    Inj = setup_vertical_well(domain, 1, 1, name = :Injector);
    Prod = setup_vertical_well(domain, nx, nx, name = :Producer);
    phases = (LiquidPhase(), VaporPhase())
    rhoLS = 1000.0*kg/meter^3
    rhoGS = 700.0*kg/meter^3
    rhoS = [rhoLS, rhoGS]
    sys = ImmiscibleSystem(phases, reference_densities = rhoS)
    model, parameters = setup_reservoir_model(domain, sys, wells = [Inj, Prod])
    c = [1e-6/bar, 1e-6/bar]
    ρ = ConstantCompressibilityDensities(p_ref = 150*bar, density_ref = rhoS, compressibility = c)
    kr = BrooksCoreyRelativePermeabilities(sys, [2.0, 2.0])
    replace_variables!(model, PhaseMassDensities = ρ, RelativePermeabilities = kr);

    state0 = setup_reservoir_state(model, Pressure = 150*bar, Saturations = [1.0, 0.0])
    dt = repeat([30.0]*day, 12*10)
    dt = vcat([0.1, 1.0, 10.0], dt)
    inj_rate = Dx*Dx*Dz*0.2/sum(dt) # 1 PVI if average porosity is 0.2

    rate_target = TotalRateTarget(inj_rate)
    I_ctrl = InjectorControl(rate_target, [0.0, 1.0], density = rhoGS)
    bhp_target = BottomHolePressureTarget(50*bar)
    P_ctrl = ProducerControl(bhp_target)
    controls = Dict()
    controls[:Injector] = I_ctrl
    controls[:Producer] = P_ctrl
    forces = setup_reservoir_forces(model, control = controls)
    return simulate_reservoir(state0, model, dt, parameters = parameters, forces = forces)
end
simulate_qfs (generic function with 2 methods)

Simulate base case

This will give the solution with uniform porosity of 0.2.

julia
ws, states, report_time = simulate_qfs();
Jutul: Simulating 9 years, 44.69 weeks as 123 report steps
╭────────────────┬───────────┬───────────────┬──────────╮
 Iteration type   Avg/step   Avg/ministep     Total 
 123 steps  141 ministeps  (wasted) 
├────────────────┼───────────┼───────────────┼──────────┤
 Newton         │    3.3252 │       2.90071 │  409 (0) │
 Linearization  │   4.47154 │       3.90071 │  550 (0) │
 Linear solver  │   10.2358 │       8.92908 │ 1259 (0) │
 Precond apply  │   20.4715 │       17.8582 │ 2518 (0) │
╰────────────────┴───────────┴───────────────┴──────────╯
╭───────────────┬────────┬────────────┬────────╮
 Timing type      Each    Relative   Total 
     ms  Percentage       s 
├───────────────┼────────┼────────────┼────────┤
 Properties    │ 0.2478 │     5.55 % │ 0.1014 │
 Equations     │ 0.1927 │     5.81 % │ 0.1060 │
 Assembly      │ 0.2772 │     8.35 % │ 0.1525 │
 Linear solve  │ 0.2886 │     6.47 % │ 0.1180 │
 Linear setup  │ 1.8335 │    41.07 % │ 0.7499 │
 Precond apply │ 0.1971 │    27.18 % │ 0.4963 │
 Update        │ 0.0755 │     1.69 % │ 0.0309 │
 Convergence   │ 0.0669 │     2.02 % │ 0.0368 │
 Input/Output  │ 0.0330 │     0.25 % │ 0.0046 │
 Other         │ 0.0718 │     1.61 % │ 0.0294 │
├───────────────┼────────┼────────────┼────────┤
 Total         │ 4.4642 │   100.00 % │ 1.8258 │
╰───────────────┴────────┴────────────┴────────╯

Plot the solution of the base case

We observe a radial flow pattern initially, before coning occurs near the producer well once the fluid has reached the opposite corner. The uniform permeability and porosity gives axial symmetry at x=y.

julia
using GLMakie
to_2d(x) = reshape(vec(x), nx, nx)
get_sat(state) = to_2d(state[:Saturations][2, :])
nt = length(report_time)
fig = Figure()
h = nothing
ax = Axis(fig[1, 1])
h = contourf!(ax, get_sat(states[nt÷3]))
ax = Axis(fig[1, 2])
h = contourf!(ax, get_sat(states[nt]))
Colorbar(fig[1, end+1], h)
fig

Create 10 realizations

We create a small set of realizations of the same model, with porosity that is uniformly varying between 0.05 and 0.3. This is not especially sophisticated geostatistics - for a more realistic approach, take a look at GeoStats.jl. The main idea is to get significantly different flow patterns as the porosity and permeability changes.

julia
N = 10
saturations = []
wells = []
report_step = nt
for i = 1:N
    poro = 0.05 .+ 0.25*rand(Float64, (nx*nx))
    ws_i, states_i, rt = simulate_qfs(poro)
    push!(wells, ws_i)
    push!(saturations, get_sat(states_i[report_step]))
end
Jutul: Simulating 9 years, 44.69 weeks as 123 report steps
╭────────────────┬───────────┬───────────────┬─────────────╮
 Iteration type   Avg/step   Avg/ministep        Total 
 123 steps  250 ministeps     (wasted) 
├────────────────┼───────────┼───────────────┼─────────────┤
 Newton         │   10.9187 │         5.372 │   1343 (15) │
 Linearization  │   12.9512 │         6.372 │   1593 (16) │
 Linear solver  │    53.878 │        26.508 │  6627 (114) │
 Precond apply  │   107.756 │        53.016 │ 13254 (228) │
╰────────────────┴───────────┴───────────────┴─────────────╯
╭───────────────┬────────┬────────────┬────────╮
 Timing type      Each    Relative   Total 
     ms  Percentage       s 
├───────────────┼────────┼────────────┼────────┤
 Properties    │ 0.2536 │     4.26 % │ 0.3405 │
 Equations     │ 0.2241 │     4.47 % │ 0.3570 │
 Assembly      │ 0.2869 │     5.72 % │ 0.4570 │
 Linear solve  │ 0.4064 │     6.83 % │ 0.5458 │
 Linear setup  │ 2.2315 │    37.52 % │ 2.9969 │
 Precond apply │ 0.1866 │    30.97 % │ 2.4737 │
 Update        │ 0.0857 │     1.44 % │ 0.1152 │
 Convergence   │ 0.3553 │     7.09 % │ 0.5660 │
 Input/Output  │ 0.0304 │     0.10 % │ 0.0076 │
 Other         │ 0.0946 │     1.59 % │ 0.1271 │
├───────────────┼────────┼────────────┼────────┤
 Total         │ 5.9469 │   100.00 % │ 7.9868 │
╰───────────────┴────────┴────────────┴────────╯
Jutul: Simulating 9 years, 44.69 weeks as 123 report steps
╭────────────────┬───────────┬───────────────┬──────────╮
 Iteration type   Avg/step   Avg/ministep     Total 
 123 steps  160 ministeps  (wasted) 
├────────────────┼───────────┼───────────────┼──────────┤
 Newton         │    4.5935 │       3.53125 │  565 (0) │
 Linearization  │   5.89431 │       4.53125 │  725 (0) │
 Linear solver  │   22.5528 │       17.3375 │ 2774 (0) │
 Precond apply  │   45.1057 │        34.675 │ 5548 (0) │
╰────────────────┴───────────┴───────────────┴──────────╯
╭───────────────┬────────┬────────────┬────────╮
 Timing type      Each    Relative   Total 
     ms  Percentage       s 
├───────────────┼────────┼────────────┼────────┤
 Properties    │ 0.2538 │     4.32 % │ 0.1434 │
 Equations     │ 0.2210 │     4.82 % │ 0.1602 │
 Assembly      │ 0.4723 │    10.30 % │ 0.3424 │
 Linear solve  │ 0.4082 │     6.94 % │ 0.2306 │
 Linear setup  │ 2.2319 │    37.95 % │ 1.2610 │
 Precond apply │ 0.1873 │    31.27 % │ 1.0389 │
 Update        │ 0.0843 │     1.43 % │ 0.0476 │
 Convergence   │ 0.0746 │     1.63 % │ 0.0541 │
 Input/Output  │ 0.0358 │     0.17 % │ 0.0057 │
 Other         │ 0.0687 │     1.17 % │ 0.0388 │
├───────────────┼────────┼────────────┼────────┤
 Total         │ 5.8811 │   100.00 % │ 3.3228 │
╰───────────────┴────────┴────────────┴────────╯
Jutul: Simulating 9 years, 44.69 weeks as 123 report steps
╭────────────────┬───────────┬───────────────┬──────────╮
 Iteration type   Avg/step   Avg/ministep     Total 
 123 steps  148 ministeps  (wasted) 
├────────────────┼───────────┼───────────────┼──────────┤
 Newton         │   3.80488 │       3.16216 │  468 (0) │
 Linearization  │   5.00813 │       4.16216 │  616 (0) │
 Linear solver  │   16.5447 │         13.75 │ 2035 (0) │
 Precond apply  │   33.0894 │          27.5 │ 4070 (0) │
╰────────────────┴───────────┴───────────────┴──────────╯
╭───────────────┬────────┬────────────┬────────╮
 Timing type      Each    Relative   Total 
     ms  Percentage       s 
├───────────────┼────────┼────────────┼────────┤
 Properties    │ 0.2506 │     4.61 % │ 0.1173 │
 Equations     │ 0.2117 │     5.13 % │ 0.1304 │
 Assembly      │ 0.2802 │     6.79 % │ 0.1726 │
 Linear solve  │ 0.3788 │     6.98 % │ 0.1773 │
 Linear setup  │ 2.2487 │    41.41 % │ 1.0524 │
 Precond apply │ 0.1882 │    30.15 % │ 0.7662 │
 Update        │ 0.0808 │     1.49 % │ 0.0378 │
 Convergence   │ 0.0727 │     1.76 % │ 0.0448 │
 Input/Output  │ 0.0401 │     0.23 % │ 0.0059 │
 Other         │ 0.0781 │     1.44 % │ 0.0365 │
├───────────────┼────────┼────────────┼────────┤
 Total         │ 5.4299 │   100.00 % │ 2.5412 │
╰───────────────┴────────┴────────────┴────────╯
Jutul: Simulating 9 years, 44.69 weeks as 123 report steps
╭────────────────┬───────────┬───────────────┬──────────╮
 Iteration type   Avg/step   Avg/ministep     Total 
 123 steps  146 ministeps  (wasted) 
├────────────────┼───────────┼───────────────┼──────────┤
 Newton         │   3.79675 │       3.19863 │  467 (0) │
 Linearization  │   4.98374 │       4.19863 │  613 (0) │
 Linear solver  │   13.0488 │       10.9932 │ 1605 (0) │
 Precond apply  │   26.0976 │       21.9863 │ 3210 (0) │
╰────────────────┴───────────┴───────────────┴──────────╯
╭───────────────┬────────┬────────────┬────────╮
 Timing type      Each    Relative   Total 
     ms  Percentage       s 
├───────────────┼────────┼────────────┼────────┤
 Properties    │ 0.2516 │     5.06 % │ 0.1175 │
 Equations     │ 0.2179 │     5.75 % │ 0.1336 │
 Assembly      │ 0.2840 │     7.50 % │ 0.1741 │
 Linear solve  │ 0.3179 │     6.39 % │ 0.1485 │
 Linear setup  │ 2.1906 │    44.05 % │ 1.0230 │
 Precond apply │ 0.1889 │    26.11 % │ 0.6063 │
 Update        │ 0.0814 │     1.64 % │ 0.0380 │
 Convergence   │ 0.0704 │     1.86 % │ 0.0431 │
 Input/Output  │ 0.0346 │     0.22 % │ 0.0051 │
 Other         │ 0.0707 │     1.42 % │ 0.0330 │
├───────────────┼────────┼────────────┼────────┤
 Total         │ 4.9725 │   100.00 % │ 2.3222 │
╰───────────────┴────────┴────────────┴────────╯
Jutul: Simulating 9 years, 44.69 weeks as 123 report steps
╭────────────────┬───────────┬───────────────┬──────────╮
 Iteration type   Avg/step   Avg/ministep     Total 
 123 steps  154 ministeps  (wasted) 
├────────────────┼───────────┼───────────────┼──────────┤
 Newton         │   4.12195 │       3.29221 │  507 (0) │
 Linearization  │   5.37398 │       4.29221 │  661 (0) │
 Linear solver  │   18.3089 │       14.6234 │ 2252 (0) │
 Precond apply  │   36.6179 │       29.2468 │ 4504 (0) │
╰────────────────┴───────────┴───────────────┴──────────╯
╭───────────────┬────────┬────────────┬────────╮
 Timing type      Each    Relative   Total 
     ms  Percentage       s 
├───────────────┼────────┼────────────┼────────┤
 Properties    │ 0.2523 │     4.48 % │ 0.1279 │
 Equations     │ 0.2204 │     5.10 % │ 0.1457 │
 Assembly      │ 0.2865 │     6.63 % │ 0.1894 │
 Linear solve  │ 0.3818 │     6.78 % │ 0.1936 │
 Linear setup  │ 2.2223 │    39.45 % │ 1.1267 │
 Precond apply │ 0.1874 │    29.56 % │ 0.8441 │
 Update        │ 0.0859 │     1.52 % │ 0.0435 │
 Convergence   │ 0.0749 │     1.73 % │ 0.0495 │
 Input/Output  │ 0.6386 │     3.44 % │ 0.0983 │
 Other         │ 0.0731 │     1.30 % │ 0.0371 │
├───────────────┼────────┼────────────┼────────┤
 Total         │ 5.6327 │   100.00 % │ 2.8558 │
╰───────────────┴────────┴────────────┴────────╯
Jutul: Simulating 9 years, 44.69 weeks as 123 report steps
╭────────────────┬───────────┬───────────────┬──────────╮
 Iteration type   Avg/step   Avg/ministep     Total 
 123 steps  147 ministeps  (wasted) 
├────────────────┼───────────┼───────────────┼──────────┤
 Newton         │   3.80488 │       3.18367 │  468 (0) │
 Linearization  │       5.0 │       4.18367 │  615 (0) │
 Linear solver  │   12.3577 │       10.3401 │ 1520 (0) │
 Precond apply  │   24.7154 │       20.6803 │ 3040 (0) │
╰────────────────┴───────────┴───────────────┴──────────╯
╭───────────────┬────────┬────────────┬────────╮
 Timing type      Each    Relative   Total 
     ms  Percentage       s 
├───────────────┼────────┼────────────┼────────┤
 Properties    │ 0.2517 │     5.04 % │ 0.1178 │
 Equations     │ 0.2174 │     5.71 % │ 0.1337 │
 Assembly      │ 0.2825 │     7.43 % │ 0.1738 │
 Linear solve  │ 0.3216 │     6.43 % │ 0.1505 │
 Linear setup  │ 2.2508 │    45.03 % │ 1.0534 │
 Precond apply │ 0.1910 │    24.82 % │ 0.5806 │
 Update        │ 0.0831 │     1.66 % │ 0.0389 │
 Convergence   │ 0.0749 │     1.97 % │ 0.0461 │
 Input/Output  │ 0.0400 │     0.25 % │ 0.0059 │
 Other         │ 0.0823 │     1.65 % │ 0.0385 │
├───────────────┼────────┼────────────┼────────┤
 Total         │ 4.9980 │   100.00 % │ 2.3391 │
╰───────────────┴────────┴────────────┴────────╯
Jutul: Simulating 9 years, 44.69 weeks as 123 report steps
╭────────────────┬───────────┬───────────────┬─────────────╮
 Iteration type   Avg/step   Avg/ministep        Total 
 123 steps  277 ministeps     (wasted) 
├────────────────┼───────────┼───────────────┼─────────────┤
 Newton         │   13.1626 │       5.84477 │  1619 (525) │
 Linearization  │   15.4146 │       6.84477 │  1896 (560) │
 Linear solver  │   25.1138 │       11.1516 │  3089 (599) │
 Precond apply  │   50.2276 │       22.3032 │ 6178 (1198) │
╰────────────────┴───────────┴───────────────┴─────────────╯
╭───────────────┬────────┬────────────┬────────╮
 Timing type      Each    Relative   Total 
     ms  Percentage       s 
├───────────────┼────────┼────────────┼────────┤
 Properties    │ 0.2464 │     6.25 % │ 0.3990 │
 Equations     │ 0.2103 │     6.24 % │ 0.3987 │
 Assembly      │ 0.2811 │     8.35 % │ 0.5330 │
 Linear solve  │ 0.2650 │     6.72 % │ 0.4290 │
 Linear setup  │ 1.9031 │    48.25 % │ 3.0812 │
 Precond apply │ 0.1919 │    18.57 % │ 1.1856 │
 Update        │ 0.0785 │     1.99 % │ 0.1272 │
 Convergence   │ 0.0730 │     2.17 % │ 0.1385 │
 Input/Output  │ 0.0320 │     0.14 % │ 0.0089 │
 Other         │ 0.0523 │     1.33 % │ 0.0847 │
├───────────────┼────────┼────────────┼────────┤
 Total         │ 3.9442 │   100.00 % │ 6.3857 │
╰───────────────┴────────┴────────────┴────────╯
Jutul: Simulating 9 years, 44.69 weeks as 123 report steps
╭────────────────┬───────────┬───────────────┬────────────╮
 Iteration type   Avg/step   Avg/ministep       Total 
 123 steps  216 ministeps    (wasted) 
├────────────────┼───────────┼───────────────┼────────────┤
 Newton         │   8.69106 │       4.94907 │  1069 (45) │
 Linearization  │   10.4472 │       5.94907 │  1285 (48) │
 Linear solver  │   33.0976 │       18.8472 │ 4071 (174) │
 Precond apply  │   66.1951 │       37.6944 │ 8142 (348) │
╰────────────────┴───────────┴───────────────┴────────────╯
╭───────────────┬────────┬────────────┬────────╮
 Timing type      Each    Relative   Total 
     ms  Percentage       s 
├───────────────┼────────┼────────────┼────────┤
 Properties    │ 0.2504 │     4.91 % │ 0.2676 │
 Equations     │ 0.2155 │     5.08 % │ 0.2769 │
 Assembly      │ 0.2814 │     6.63 % │ 0.3616 │
 Linear solve  │ 0.3485 │     6.83 % │ 0.3726 │
 Linear setup  │ 2.2400 │    43.88 % │ 2.3945 │
 Precond apply │ 0.1882 │    28.08 % │ 1.5320 │
 Update        │ 0.0810 │     1.59 % │ 0.0866 │
 Convergence   │ 0.0743 │     1.75 % │ 0.0955 │
 Input/Output  │ 0.0345 │     0.14 % │ 0.0075 │
 Other         │ 0.0577 │     1.13 % │ 0.0616 │
├───────────────┼────────┼────────────┼────────┤
 Total         │ 5.1042 │   100.00 % │ 5.4564 │
╰───────────────┴────────┴────────────┴────────╯
Jutul: Simulating 9 years, 44.69 weeks as 123 report steps
╭────────────────┬───────────┬───────────────┬──────────╮
 Iteration type   Avg/step   Avg/ministep     Total 
 123 steps  150 ministeps  (wasted) 
├────────────────┼───────────┼───────────────┼──────────┤
 Newton         │    3.9187 │       3.21333 │  482 (0) │
 Linearization  │   5.13821 │       4.21333 │  632 (0) │
 Linear solver  │   17.8943 │       14.6733 │ 2201 (0) │
 Precond apply  │   35.7886 │       29.3467 │ 4402 (0) │
╰────────────────┴───────────┴───────────────┴──────────╯
╭───────────────┬────────┬────────────┬────────╮
 Timing type      Each    Relative   Total 
     ms  Percentage       s 
├───────────────┼────────┼────────────┼────────┤
 Properties    │ 0.2497 │     4.51 % │ 0.1203 │
 Equations     │ 0.2149 │     5.09 % │ 0.1358 │
 Assembly      │ 0.2816 │     6.67 % │ 0.1780 │
 Linear solve  │ 0.3978 │     7.18 % │ 0.1917 │
 Linear setup  │ 2.2609 │    40.83 % │ 1.0898 │
 Precond apply │ 0.1873 │    30.89 % │ 0.8244 │
 Update        │ 0.0806 │     1.46 % │ 0.0389 │
 Convergence   │ 0.0734 │     1.74 % │ 0.0464 │
 Input/Output  │ 0.0394 │     0.22 % │ 0.0059 │
 Other         │ 0.0790 │     1.43 % │ 0.0381 │
├───────────────┼────────┼────────────┼────────┤
 Total         │ 5.5380 │   100.00 % │ 2.6693 │
╰───────────────┴────────┴────────────┴────────╯
Jutul: Simulating 9 years, 44.69 weeks as 123 report steps
╭────────────────┬───────────┬───────────────┬────────────╮
 Iteration type   Avg/step   Avg/ministep       Total 
 123 steps  176 ministeps    (wasted) 
├────────────────┼───────────┼───────────────┼────────────┤
 Newton         │   5.86992 │       4.10227 │   722 (60) │
 Linearization  │   7.30081 │       5.10227 │   898 (64) │
 Linear solver  │    12.935 │       9.03977 │  1591 (60) │
 Precond apply  │   25.8699 │       18.0795 │ 3182 (120) │
╰────────────────┴───────────┴───────────────┴────────────╯
╭───────────────┬────────┬────────────┬────────╮
 Timing type      Each    Relative   Total 
     ms  Percentage       s 
├───────────────┼────────┼────────────┼────────┤
 Properties    │ 0.2459 │     5.70 % │ 0.1775 │
 Equations     │ 0.2457 │     7.09 % │ 0.2207 │
 Assembly      │ 0.2795 │     8.06 % │ 0.2510 │
 Linear solve  │ 0.2530 │     5.86 % │ 0.1826 │
 Linear setup  │ 2.0737 │    48.08 % │ 1.4972 │
 Precond apply │ 0.1928 │    19.70 % │ 0.6134 │
 Update        │ 0.0777 │     1.80 % │ 0.0561 │
 Convergence   │ 0.0712 │     2.05 % │ 0.0639 │
 Input/Output  │ 0.0354 │     0.20 % │ 0.0062 │
 Other         │ 0.0629 │     1.46 % │ 0.0454 │
├───────────────┼────────┼────────────┼────────┤
 Total         │ 4.3132 │   100.00 % │ 3.1141 │
╰───────────────┴────────┴────────────┴────────╯

Plot the oil rate at the producer over the ensemble

julia
using Statistics
fig = Figure()
ax = Axis(fig[1, 1])
for i = 1:N
    ws = wells[i]
    q = -ws[:Producer][:orat]
    lines!(ax, report_time, q)
end
xlims!(ax, [mean(report_time), report_time[end]])
ylims!(ax, 0, 0.0075)
fig

Plot the average saturation over the ensemble

julia
avg = mean(saturations)
fig = Figure()
h = nothing
ax = Axis(fig[1, 1])
h = contourf!(ax, avg)
fig

Plot the isocontour lines over the ensemble

julia
fig = Figure()
h = nothing
ax = Axis(fig[1, 1])
for s in saturations
    contour!(ax, s, levels = 0:0.1:1)
end
fig

Example on GitHub

If you would like to run this example yourself, it can be downloaded from the JutulDarcy.jl GitHub repository as a script, or as a Jupyter Notebook

This example took 47.713557802 seconds to complete.

This page was generated using Literate.jl.